forked from adilson0888/lastfm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
109 lines (88 loc) · 2.73 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/*
get a $xml with the amount of artists requested in $limit parameter
$page of the lastfm library
*/
function getResults($limit = 1, $page = "")
{
$method = "library.getArtists";
$url = getenv("LASTFM_BASEURL") . "api_key=" . getenv("LASTFM_APIKEY") . "&method=$method&user=" . getenv("LASTFM_USER") . "&limit=$limit";
$url .= !empty($page) ? "&page=$page" : "";
$results = file_get_contents($url);
$xml = new SimpleXMLElement($results);
return $xml;
}
/**
*
*/
function getArtistTags($mbid = '')
{
if (strlen($mbid) > 1) {
$method = "artist.getInfo";
$url = getenv("LASTFM_BASEURL") . "api_key=" . getenv("LASTFM_APIKEY") . "&method=" . $method . "&mbid=$mbid";
$results = file_get_contents($url);
$xml = new SimpleXMLElement($results);
$artistInfo = array("tags" => $xml->artist->tags, "summary" => $xml->artist->bio->summary);
} else {
$artistInfo = null;
}
return $artistInfo;
}
function returnArtistTag()
{
ob_start();
$mbid = $_REQUEST["mbid"];
?>
<span style="font-size:11px; line-height:normal">
<?php $artistInfo = getArtistTags($mbid);
foreach ($artistInfo["tags"]->tag as $tag) : ?>
<a href="<?= $tag->url ?>"><?= $tag->name ?></a>
·
<?php endforeach; ?>
</span>
<?php
return ob_end_flush();
}
function getTotalArtists()
{
$xml = getResults();
$totalArtists = $xml->artists["total"];
return $totalArtists;
}
function randomGen($min, $max, $quantity)
{
$numbers = range($min, $max);
shuffle($numbers);
return array_slice($numbers, 0, $quantity);
}
function stripAccents($str)
{
return strtr(utf8_decode($str), utf8_decode('àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ'), 'aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY');
}
function defineSections($totalArtists)
{
$sectionsPercentual = array(
"classics" => 0.05,
"known" => 0.15,
"adventurous" => 0.25,
"wild" => 0.25,
"insane" => 0.30
);
$pageLimit = getenv("LASTFM_PAGELIMIT");
$sectionFim = 1;
$sectionIni = 1;
$sections = array(
"classics" => array(),
"known" => array(),
"adventurous" => array(),
"wild" => array(),
"insane" => array()
);
foreach ($sections as $key => &$value) {
$increment = floor($totalArtists * $sectionsPercentual[$key] / $pageLimit);
$sectionFim += $increment;
$value = array($sectionIni, $sectionFim);
$sectionIni = $sectionFim + 1;
}
return $sections;
}