Library_page.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. <?php
  2. /* GNU FM -- a free network service for sharing your music listening habits
  3. Copyright (C) 2013 Free Software Foundation, Inc
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Affero General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. require_once('templating.php');
  16. require_once('data/Library.php');
  17. require_once('user-menu.php');
  18. /**
  19. * Represents a user's library page.
  20. *
  21. */
  22. class Library_page {
  23. public $user, $section, $menu;
  24. public $artist, $album, $track, $artists_limit, $albums_limit, $tracks_limit;
  25. public $page_number, $next_page, $prev_page;
  26. public $default_artist_image;
  27. public $tagged_artists, $tagged_albums, $tagged_tracks;
  28. /**
  29. * Create new Library page instance
  30. *
  31. * @params User $userobj The User object that owns this library.
  32. */
  33. public function __construct($userobj) {
  34. global $base_url, $theme, $this_user;
  35. $this->user = $userobj;
  36. $this->setSection($_GET['section']);
  37. $this->ownedbyme = $this->user == $this_user;
  38. $this->menu = $this->getMenu();
  39. $this->section_url = $this->getURL($this->section);
  40. $this->artists_limit = 16;
  41. $this->albums_limit = 15;
  42. $this->tracks_limit = 200;
  43. $this->scrobbles_limit = 50;
  44. $this->loved_limit = 50;
  45. $this->banned_limit = 50;
  46. $this->tags_limit = 50;
  47. $this->default_artist_image = "{$base_url}/themes/{$theme}/img/qm160.png";
  48. $this->default_album_image = "{$base_url}/themes/{$theme}/img/qm160.png";
  49. $this->default_track_image = "{$base_url}/themes/{$theme}/img/qm160.png";
  50. $this->default_tag_image = "{$base_url}/themes/{$theme}/img/qm160.png";
  51. // Set properties based on url params
  52. $this->setPageNumber($_GET['page']);
  53. $this->setSortBy($_GET['sortby']);
  54. $this->setSortOrder($_GET['sortorder']);
  55. $this->setStreamable($_GET['streamable']);
  56. $this->setArtist($_GET['artist']);
  57. $this->setAlbum($_GET['album']);
  58. $this->setTrack($_GET['track']);
  59. $this->setTag($_GET['tag']);
  60. $this->getPageURLS();
  61. }
  62. public function setSection($section) {
  63. $this->section = $section ? $section : 'music';
  64. }
  65. public function setPageNumber($page) {
  66. $this->page_number = $page ? $page : 1;
  67. }
  68. public function setSortBy($sortby) {
  69. $this->sortby = $sortby ? $sortby : 'plays';
  70. }
  71. public function setSortOrder($sortorder) {
  72. if ($this->sortby == 'name') {
  73. $this->sortorder = $sortorder ? $sortorder : 'asc';
  74. } else {
  75. $this->sortorder = $sortorder ? $sortorder : 'desc';
  76. }
  77. }
  78. public function setStreamable($streamable) {
  79. $this->streamable = $streamable ? $streamable : False;
  80. }
  81. public function setArtist($artist) {
  82. if ($artist) {
  83. $this->artist = new Artist($artist);
  84. $this->artist_url = Server::getArtistURL($this->artist->name);
  85. $this->artist_library_url = $this->getURL('music', $this->artist->name);
  86. $this->artist_image = $this->artist->image_small ? $this->artist->image_small : $this->default_artist_image;
  87. }
  88. }
  89. public function setAlbum($album) {
  90. if ($album) {
  91. $this->album = new Album($album, $this->artist->name);
  92. $this->album_url = Server::getAlbumURL($this->artist->name, $this->album->name);
  93. $this->album_library_url = $this->getURL('music', $this->artist->name, $this->album->name);
  94. $this->album_image = $this->album->image ? $this->album->image : $this->default_album_image;
  95. }
  96. }
  97. public function setTrack($track) {
  98. if ($track) {
  99. $this->track = new Track($track, $this->artist->name);
  100. $this->track_url = Server::getTrackURL($this->artist->name, null, $this->track->name);
  101. $this->track_library_url = $this->getURL('music', $this->artist->name, null, $this->track->name);
  102. $this->track_image = $this->artist_image;
  103. }
  104. }
  105. public function setTag($tag) {
  106. if ($tag) {
  107. $this->tag_name = $tag;
  108. $this->tag_url = Server::getTagURL($tag);
  109. $this->tag_library_url = $this->getURL('tags', null, null, null, $tag);
  110. $this->tag_image = $this->default_tag_image;
  111. }
  112. }
  113. private function getMenu() {
  114. $submenu = array(
  115. array('name' => _('Music'), 'section' => 'music', 'url' => $this->getURL('music')),
  116. array('name' => _('Scrobbles'), 'section' => 'scrobbles', 'url' => $this->getURL('scrobbles')),
  117. array('name' => _('Loved tracks'), 'section' => 'loved', 'url' => $this->getURL('loved')),
  118. array('name' => _('Banned tracks'), 'section' => 'banned', 'url' => $this->getURL('banned')),
  119. array('name' => _('Tags'), 'section' => 'tags', 'url' => $this->getURL('tags'))
  120. );
  121. foreach ($submenu as &$item) {
  122. $item['active'] = (strtolower($item['section']) == strtolower($this->section));
  123. }
  124. return $submenu;
  125. }
  126. public function getURL($section = null, $artist = null, $album = null, $track = null, $tag = null, $params = null) {
  127. global $friendly_urls, $base_url;
  128. if ($friendly_urls) {
  129. $myurl = $base_url . '/user/' . $this->user->name . '/library/';
  130. if ($section) {
  131. $myurl .= $section . '/';
  132. }
  133. if ($artist) {
  134. $myurl .= rewrite_encode($artist) . '/';
  135. }
  136. if ($album) {
  137. if (!$track) {
  138. $myurl .= rewrite_encode($album) . '/';
  139. }
  140. }
  141. if ($track) {
  142. if ($album) {
  143. $myurl .= rewrite_encode($album) . '/';
  144. } else {
  145. $myurl .= '_/';
  146. }
  147. $myurl .= rewrite_encode($track) . '/';
  148. }
  149. if($tag) {
  150. $myurl .= rewrite_encode($tag) . '/';
  151. }
  152. if($params) {
  153. $myurl .= '?' . $params;
  154. }
  155. } else {
  156. $myurl = $base_url . '/user-library.php?';
  157. $myurl .= 'user=' . rawurlencode($this->user->name);
  158. if ($section) {
  159. $myurl .= '&section=' .rawurlencode($section);
  160. }
  161. if ($artist) {
  162. $myurl .= '&artist=' . rawurlencode($artist);
  163. }
  164. if ($album) {
  165. $myurl .= '&album=' . rawurlencode($album);
  166. }
  167. if ($track) {
  168. $myurl .= '&track=' . rawurlencode($track);
  169. }
  170. if ($tag) {
  171. $myurl .= '&tag=' . rawurlencode($tag);
  172. }
  173. if($params) {
  174. $myurl .= '&' . $params;
  175. }
  176. }
  177. return $myurl;
  178. }
  179. public function getArtists() {
  180. global $adodb;
  181. $offset = ($this->page_number - 1) * $this->artists_limit;
  182. $query = 'SELECT s.artist, a.image_small AS image, COUNT(s.artist) AS freq, COUNT(DISTINCT s.userid) AS listeners, MAX(a.streamable) AS streamable FROM Scrobbles AS s LEFT JOIN Artist AS a ON (s.artist=a.name) WHERE s.userid=?';
  183. $params = array($this->user->uniqueid);
  184. if ($this->streamable) {
  185. $query .= ' AND streamable=1';
  186. }
  187. /* BEGIN temporary limit query to 7 days in the past so we dont melt libre.fm server */
  188. $mytime = (int) time();
  189. $mytime = $mytime - ($mytime % 3600);
  190. $query .= ' AND s.time > ' . ($mytime - (3600 * 24 * 7));
  191. /* END temporary limit */
  192. $query .= ' GROUP BY s.artist, image';
  193. if($this->sortby) {
  194. if($this->sortby == 'name') {
  195. if($this->sortorder == 'desc') {
  196. $query .= ' ORDER BY s.artist DESC, freq DESC';
  197. }else{
  198. $query .= ' ORDER BY s.artist ASC, freq DESC';
  199. }
  200. }else if ($this->sortby == 'plays') {
  201. if($this->sortorder == 'asc') {
  202. $query .= ' ORDER BY freq ASC, s.artist ASC';
  203. }else{
  204. $query .= ' ORDER BY freq DESC, s.artist ASC';
  205. }
  206. }
  207. }else{
  208. $query .= ' ORDER BY freq DESC, s.artist ASC';
  209. }
  210. $query .= ' LIMIT ? OFFSET ?';
  211. $params[] = (int) $this->artists_limit;
  212. $params[] = (int) $offset;
  213. $adodb->SetFetchMode(ADODB_FETCH_ASSOC);
  214. $data = $adodb->CacheGetAll(600, $query, $params);
  215. foreach($data as &$item) {
  216. $item['artistlibraryurl'] = $this->getURL('music', $item['artist']);
  217. $item['artisturl'] = Server::getArtistURL($item['artist']);
  218. if (!$item['image']) {
  219. $item['image'] = $this->default_artist_image;
  220. }
  221. }
  222. $this->artists = $data;
  223. return $data;
  224. }
  225. public function getAlbums() {
  226. //todo sort order
  227. global $adodb;
  228. $offset = ($this->page_number - 1) * $this->albums_limit;
  229. $query = 'SELECT MAX(s.artist) AS artist, MAX(s.album) AS album, MAX(a.image) AS image, COUNT(s.album) AS freq, COUNT(DISTINCT s.userid) AS listeners, MAX(t.streamable) AS streamable FROM Scrobbles AS s LEFT JOIN Scrobble_Track AS st ON (s.stid=st.id) LEFT JOIN Track AS t ON (st.track=t.id) LEFT JOIN Album AS a ON (t.artist_name=a.artist_name AND t.album_name=a.name) WHERE s.album IS NOT NULL AND s.userid=?';
  230. $params = array($this->user->uniqueid);
  231. if ($this->streamable) {
  232. $query .= ' AND t.streamable=1';
  233. }
  234. if ($this->artist->name) {
  235. $query .= ' AND lower(s.artist)=lower(?)';
  236. $params[] = $this->artist->name;
  237. }
  238. $query .= ' GROUP BY lower(s.artist), lower(s.album) ORDER BY freq DESC, lower(s.artist) ASC, lower(s.album) ASC LIMIT ? OFFSET ?';
  239. $params[] = $this->albums_limit;
  240. $params[] = $offset;
  241. $adodb->SetFetchMode(ADODB_FETCH_ASSOC);
  242. $data = $adodb->CacheGetAll(600, $query, $params);
  243. foreach($data as &$item) {
  244. $item['artisturl'] = Server::getArtistURL($item['artist']);
  245. $item['albumurl'] = Server::getAlbumURL($item['artist'], null, $item['album']);
  246. $item['image'] = resolve_external_url($item['image']);
  247. $item['artistlibraryurl'] = $this->getURL('music', $item['artist']);
  248. $item['albumlibraryurl'] = $this->getURL('music', $item['artist'], $item['album']);
  249. if (!$item['image']) {
  250. $item['image'] = $this->default_album_image;
  251. }
  252. }
  253. $this->albums = $data;
  254. return $data;
  255. }
  256. public function getTracks() {
  257. //todo sort order
  258. global $adodb;
  259. $offset = ($this->page_number - 1) * $this->tracks_limit;
  260. $query = 'SELECT MAX(s.artist) AS artist, MAX(s.track) AS track, COUNT(s.track) AS freq, COUNT(DISTINCT s.userid) AS listeners, MAX(tr.streamable) AS streamable, (SELECT 1 FROM Tags AS t WHERE s.artist=t.artist AND s.track=t.track AND s.userid=t.userid LIMIT 1) AS tagged, (SELECT 1 FROM Loved_Tracks AS lt WHERE s.artist=lt.artist AND s.track=lt.track AND s.userid=lt.userid LIMIT 1) AS loved FROM Scrobbles AS s LEFT JOIN Scrobble_Track AS st ON (s.stid=st.id) LEFT JOIN Track AS tr ON (st.track=tr.id) WHERE s.userid=?';
  261. $params = array($this->user->uniqueid);
  262. if ($this->streamable) {
  263. $query .= ' AND tr.streamable=1';
  264. }
  265. if ($this->artist->name) {
  266. $query .= ' AND lower(s.artist)=lower(?)';
  267. $params[] = $this->artist->name;
  268. if ($this->album->name) {
  269. $query .= ' AND lower(s.album)=lower(?)';
  270. $params[] = $this->album->name;
  271. }
  272. }
  273. $query .= ' GROUP BY s.artist, s.track, s.userid ORDER BY freq DESC, s.artist ASC, s.track ASC LIMIT ? OFFSET ?';
  274. $params[] = (int) $this->tracks_limit;
  275. $params[] = (int) $offset;
  276. $adodb->SetFetchMode(ADODB_FETCH_ASSOC);
  277. $data = $adodb->CacheGetAll(600, $query, $params);
  278. foreach($data as &$item) {
  279. $item['artisturl'] = Server::getArtistURL($item['artist']);
  280. $item['trackurl'] = Server::getTrackURL($item['artist'], null, $item['track']);
  281. $item['artistlibraryurl'] = $this->getURL('music', $item['artist']);
  282. $item['tracklibraryurl'] = $this->getURL('music', $item['artist'], null, $item['track']);
  283. }
  284. $this->tracks = $data;
  285. return $data;
  286. }
  287. public function getScrobbles($nocache=false) {
  288. global $adodb;
  289. $cache = $nocache ? 0 : 600;
  290. $offset = ($this->page_number - 1) * $this->scrobbles_limit;
  291. $query = 'SELECT s.artist, s.track, s.time, lt.userid as loved, t.streamable FROM Scrobbles s LEFT JOIN Scrobble_Track st ON (s.stid=st.id) LEFT JOIN Track t ON (st.track=t.id) LEFT JOIN Loved_Tracks lt ON (s.artist=lt.artist AND s.track=lt.track AND s.userid=lt.userid) WHERE s.userid=?';
  292. $params = array($this->user->uniqueid);
  293. if ($this->streamable) {
  294. $query .= ' AND streamable=1';
  295. }
  296. if ($this->artist->name) {
  297. $query .= ' AND s.artist=?';
  298. $params[] = $this->artist->name;
  299. }
  300. $query .= ' ORDER BY time DESC LIMIT ? OFFSET ?';
  301. $params[] = (int) $this->scrobbles_limit;
  302. $params[] = (int) $offset;
  303. $adodb->SetFetchMode(ADODB_FETCH_ASSOC);
  304. $data = $adodb->CacheGetAll($cache, $query, $params);
  305. foreach($data as &$item) {
  306. $item['artisturl'] = Server::getArtistURL($item['artist']);
  307. $item['trackurl'] = Server::getTrackURL($item['artist'], null, $item['track']);
  308. $item['timehuman'] = human_timestamp($item['time']);
  309. $item['artistlibraryurl'] = $this->getURL('music', $item['artist']);
  310. $item['tracklibraryurl'] = $this->getURL('music', $item['artist'], null, $item['track']);
  311. }
  312. $this->scrobbles = $data;
  313. return $data;
  314. }
  315. public function getLovedTracks($nocache=false) {
  316. global $adodb;
  317. $cache = $nocache ? 0 : 600;
  318. $offset = ($this->page_number -1) * $this->loved_limit;
  319. $query = 'SELECT lt.artist, lt.track, max(lt.time) as time, 1 as loved, MAX(t.streamable) AS streamable FROM Loved_Tracks lt LEFT JOIN Track t ON(lt.artist=t.artist_name AND lt.track=t.name) WHERE lt.userid=?';
  320. $params = array($this->user->uniqueid);
  321. if ($streamable) {
  322. $query .= ' AND streamable=1)';
  323. }
  324. if ($this->artist->name) {
  325. $query .= ' AND lt.artist=?';
  326. $params[] = $this->artist->name;
  327. }
  328. $query .= ' GROUP BY lt.artist, lt.track ORDER BY time DESC LIMIT ? OFFSET ?';
  329. $params[] = $this->loved_limit;
  330. $params[] = $offset;
  331. $adodb->SetFetchMode(ADODB_FETCH_ASSOC);
  332. $data = $adodb->CacheGetAll($cache, $query, $params);
  333. foreach($data as &$item) {
  334. $item['artisturl'] = Server::getArtistURL($item['artist']);
  335. $item['trackurl'] = Server::getTrackURL($item['artist'], null, $item['track']);
  336. $item['timehuman'] = human_timestamp($item['time']);
  337. $item['artistlibraryurl'] = $this->getURL('music', $item['artist']);
  338. $item['tracklibraryurl'] = $this->getURL('music', $item['artist'], null, $item['track']);
  339. }
  340. $this->loved_tracks = $data;
  341. return $data;
  342. }
  343. public function getBannedTracks($nocache=false) {
  344. global $adodb;
  345. $cache = $nocache ? 0 : 600;
  346. $offset = ($this->page_number -1) * $this->banned_limit;
  347. $query = 'SELECT bt.artist, bt.track, max(bt.time) as time, 1 as banned, MAX(t.streamable) AS streamable FROM Banned_Tracks bt LEFT JOIN Track t ON(bt.artist=t.artist_name AND bt.track=t.name) WHERE bt.userid=?';
  348. $params = array($this->user->uniqueid);
  349. if ($this->streamable) {
  350. $query .= ' AND streamable=1)';
  351. }
  352. if ($this->artist->name) {
  353. $query .= ' AND bt.artist=?';
  354. $params[] = $this->artist->name;
  355. }
  356. $query .= ' GROUP BY bt.artist, bt.track ORDER BY time DESC LIMIT ? OFFSET ?';
  357. $params[] = $this->banned_limit;
  358. $params[] = $offset;
  359. $adodb->SetFetchMode(ADODB_FETCH_ASSOC);
  360. $data = $adodb->CacheGetAll($cache, $query, $params);
  361. foreach($data as &$item) {
  362. $item['artisturl'] = Server::getArtistURL($item['artist']);
  363. $item['trackurl'] = Server::getTrackURL($item['artist'], null, $item['track']);
  364. $item['timehuman'] = human_timestamp($item['time']);
  365. $item['artistlibraryurl'] = $this->getURL('music', $item['artist']);
  366. $item['tracklibraryurl'] = $this->getURL('music', $item['artist'], null, $item['track']);
  367. }
  368. $this->banned_tracks = $data;
  369. return $data;
  370. }
  371. public function getTags() {
  372. global $adodb;
  373. $offset = ($this->page_number -1) * $this->tags_limit;
  374. $query = 'SELECT t.tag, COUNT(t.tag) AS freq FROM Tags AS t WHERE t.userid=?';
  375. $params = array($this->user->uniqueid);
  376. if ($this->artist->name) {
  377. $query .= ' AND t.artist=?';
  378. $params[] = $this->artist->name;
  379. if ($track) {
  380. $query .= ' AND t.track=?';
  381. $params[] = $this->track->name;
  382. }
  383. }
  384. $query .= ' GROUP BY t.tag ORDER BY freq DESC, t.tag ASC LIMIT ? OFFSET ?';
  385. $params[] = $this->tags_limit;
  386. $params[] = $offset;
  387. $data = $adodb->CacheGetAll(600, $query, $params);
  388. foreach($data as &$item) {
  389. $item['tagurl'] = Server::getTagURL($item['tag']);
  390. $item['taglibraryurl'] = $this->getURL('tags', null, null, null, $item['tag']);
  391. }
  392. $this->tags = $data;
  393. return $data;
  394. }
  395. public function getTaggedArtists($nocache=false) {
  396. global $adodb;
  397. $cache = $nocache ? 0 : 600;
  398. //$offset = ($this->page_number -1) * $this->artists_limit;
  399. $query = 'SELECT t.artist, t.tag, a.streamable, a.image_small as image FROM Tags t LEFT JOIN Artist a ON (t.artist=a.name) WHERE t.track IS NULL AND t.album IS NULL AND t.tag=? AND t.userid=?';
  400. $params = array($this->tag_name, $this->user->uniqueid);
  401. if ($this->streamable) {
  402. $query .= ' AND a.streamable=1';
  403. }
  404. $query .= ' ORDER BY t.artist, a.streamable';
  405. $data = $adodb->CacheGetAll($cache, $query, $params);
  406. foreach($data as &$item) {
  407. $item['artisturl'] = Server::getArtistURL($item['artist']);
  408. $item['artistlibraryurl'] = $this->getURL('music', $item['artist']);
  409. if (!$item['image']) {
  410. $item['image'] = $this->default_artist_image;
  411. }
  412. }
  413. $this->tagged_artists = $data;
  414. return $data;
  415. }
  416. public function getTaggedAlbums($nocache=false) {
  417. global $adodb;
  418. $cache = $nocache ? 0 : 600;
  419. //$offset = ($this->page_number -1) * $this->albums_limit;
  420. $query = 'SELECT t.tag, t.artist, t.album, MAX(tr.streamable) AS streamable, al.image FROM Tags t LEFT JOIN Album al ON (t.artist=al.artist_name AND t.album=al.name) LEFT JOIN Track tr ON (t.artist=tr.artist_name AND t.album=tr.album_name AND tr.streamable=1) WHERE t.track IS NULL AND t.album IS NOT NULL AND t.tag=? AND t.userid=?';
  421. $params = array($this->tag_name, $this->user->uniqueid);
  422. if ($this->streamable) {
  423. $query .= ' AND tr.streamable=1';
  424. }
  425. $query .= ' GROUP BY t.tag, t.artist, t.album, al.image ORDER BY t.artist ASC, t.album ASC';
  426. $data = $adodb->CacheGetAll($cache, $query, $params);
  427. foreach($data as &$item) {
  428. $item['artisturl'] = Server::getArtistURL($item['artist']);
  429. $item['albumurl'] = Server::getAlbumURL($item['artist'], $item['album']);
  430. $item['artistlibraryurl'] = $this->getURL('music', $item['artist']);
  431. $item['albumlibraryurl'] = $this->getURL('music', $item['artist'], $item['album']);
  432. }
  433. $this->tagged_albums = $data;
  434. return $data;
  435. }
  436. public function getTaggedTracks($nocache=false) {
  437. global $adodb;
  438. $cache = $nocache ? 0 : 600;
  439. $offset = ($this->page_number -1) * $this->tags_limit;
  440. $query = 'SELECT t.tag, t.artist, t.track, MAX(tr.streamable) AS streamable FROM Tags t LEFT JOIN Track tr ON (t.artist=tr.artist_name AND t.track=tr.name) WHERE t.track IS NOT NULL AND t.tag=? AND t.userid=?';
  441. $params = array($this->tag_name, $this->user->uniqueid);
  442. if ($this->streamable) {
  443. $query .= ' AND tr.streamable=1';
  444. }
  445. $query .= ' GROUP BY t.tag, t.artist, t.track ORDER BY t.artist ASC, t.track ASC';
  446. $data = $adodb->CacheGetAll($cache, $query, $params);
  447. foreach($data as &$item) {
  448. $item['artisturl'] = Server::getArtistURL($item['artist']);
  449. $item['trackurl'] = Server::getTrackURL($item['artist'], null, $item['track']);
  450. $item['artistlibraryurl'] = $this->getURL('music', $item['artist']);
  451. $item['tracklibraryurl'] = $this->getURL('music', $item['artist'], null, $item['track']);
  452. }
  453. $this->tagged_tracks = $data;
  454. return $data;
  455. }
  456. public function getPageURLS() {
  457. //todo clean up this mess
  458. $gets = $_GET;
  459. $prettygets = array('user' => 1, 'section' => 1, 'artist' => 1, 'album' => 1, 'track' => 1, 'tag' => 1);
  460. $urldiff = array_diff_key($gets, $prettygets);
  461. $page_next_params = $urldiff;
  462. $page_next_params['page'] = (int)$this->page_number + 1;
  463. $page_next_tail = '';
  464. foreach($page_next_params as $k => $v) {
  465. $page_next_tail .= "{$k}={$v}&";
  466. }
  467. $url_page_next = $this->getURL($this->section, $this->artist->name, $this->album->name, $this->track->name, $this->tag_name, $page_next_tail);
  468. $page_prev_params = $urldiff;
  469. $page_prev_params['page'] = ($this->page_number > 1) ? $this->page_number - 1 : 1;
  470. $page_prev_tail = '';
  471. foreach($page_prev_params as $k => $v) {
  472. $page_prev_tail .= "{$k}={$v}&";
  473. }
  474. $url_page_prev = $this->getURL($this->section, $this->artist->name, $this->album->name, $this->track->name, $this->tag_name, $page_prev_tail);
  475. $sort_name_params = $urldiff;
  476. $sort_name_params['sortby'] = 'name';
  477. unset($sort_name_params['page']);
  478. $sort_name_params['sortorder'] = ($this->sortby == 'name' && $sort_name_params['sortorder'] == 'asc') ? 'desc' : 'asc';
  479. $sort_name_tail = '';
  480. foreach($sort_name_params as $k => $v) {
  481. $sort_name_tail .= "{$k}={$v}&";
  482. }
  483. $url_sort_name = $this->getURL($this->section, $this->artist->name, $this->album->name, $this->track->name, $this->tag_name, $sort_name_tail);
  484. $sort_plays_params = $urldiff;
  485. $sort_plays_params['sortby'] = 'plays';
  486. unset($sort_plays_params['page']);
  487. $sort_plays_params['sortorder'] = ($this->sortby == 'plays' && $sort_plays_params['sortorder'] == 'desc') ? 'asc' : 'desc';
  488. $sort_plays_tail = '';
  489. foreach($sort_plays_params as $k => $v) {
  490. $sort_plays_tail .= "{$k}={$v}&";
  491. }
  492. $url_sort_plays = $this->getURL($this->section, $this->artist->name, $this->album->name, $this->track->name, $this->tag_name, $sort_plays_tail);
  493. $streamable_params = $urldiff;
  494. unset($streamable_params['page']);
  495. if ($this->streamable) {
  496. unset($streamable_params['streamable']);
  497. } else {
  498. $streamable_params['streamable'] = true;
  499. }
  500. $streamable_tail = '';
  501. foreach($streamable_params as $k => $v) {
  502. $streamable_tail .= "{$k}={$v}&";
  503. }
  504. $url_streamable = $this->getURL($this->section, $this->artist->name, $this->album->name, $this->track->name, $this->tag_name, $streamable_tail);
  505. $this->urls = array(
  506. 'page_next' => $url_page_next,
  507. 'page_prev' => $url_page_prev,
  508. 'sort_name' => $url_sort_name,
  509. 'sort_count' => $url_sort_plays,
  510. 'streamable' => $url_streamable,
  511. );
  512. //return var_dump(array($urldiff, $this->pageurls));
  513. }
  514. }