user-library.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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('data/Library_page.php');
  16. require_once('data/Artist.php');
  17. require_once('data/Album.php');
  18. require_once('data/Track.php');
  19. if (!isset($_GET['user']) && $logged_in == false) {
  20. displayError("Error", "User not set. You shouldn't be here.");
  21. }
  22. try {
  23. $user = new User($_GET['user']);
  24. } catch (Exception $e) {
  25. displayError("User not found", "User not found, shall I call in a missing persons report?");
  26. }
  27. $submenu = user_menu($user, 'Library');
  28. $smarty->assign('submenu', $submenu);
  29. $page = new Library_page($user);
  30. $smarty->assign('me', $user);
  31. if ($page->section == 'music') {
  32. if (isset($_GET['artist']) && (!isset($_GET['album']) && !isset($_GET['track']))) {
  33. // Music -> Artist name
  34. $page->getAlbums();
  35. $page->getTracks();
  36. $smarty->assign('page', $page);
  37. $smarty->display('user-library-artist.tpl');
  38. } else if ((isset($_GET['artist']) && isset($_GET['album'])) && !isset($_GET['track'])) {
  39. // Music -> Artist name -> Album name
  40. $page->getTracks();
  41. $smarty->assign('page', $page);
  42. $smarty->display('user-library-album.tpl');
  43. } else if ((isset($_GET['artist']) && isset($_GET['track'])) && !isset($_GET['album'])) {
  44. // Music -> Artist name -> Track name
  45. $smarty->assign('page', $page);
  46. $smarty->display('user-library-track.tpl');
  47. } else {
  48. // Music -> Artists
  49. try {
  50. $page->getArtists();
  51. } catch (Exception $e) {
  52. displayError("Error", $e->getMessage());
  53. }
  54. $smarty->assign('page', $page);
  55. $smarty->display('user-library-music.tpl');
  56. }
  57. } else if ($page->section == 'scrobbles') {
  58. if (isset($_POST['removescrobble'])) {
  59. Library::removeScrobble($this_user->uniqueid, $_POST['timestamp'], $_POST['artist'], $_POST['track']);
  60. $nocache = true;
  61. }
  62. $page->getScrobbles($nocache);
  63. $smarty->assign('page', $page);
  64. $smarty->display('user-library-scrobbles.tpl');
  65. } else if ($page->section == 'loved') {
  66. if (isset($_POST['unlove'])) {
  67. $track = new Track($_POST['track'], $_POST['artist']);
  68. $track->unlove($this_user->uniqueid);
  69. $nocache=true;
  70. }
  71. $page->getLovedTracks($nocache);
  72. $smarty->assign('page', $page);
  73. $smarty->display('user-library-loved.tpl');
  74. } else if ($page->section == 'banned') {
  75. if (isset($_POST['unban'])) {
  76. $track = new Track($_POST['track'], $_POST['artist']);
  77. $track->unban($this_user->uniqueid);
  78. $nocache = true;
  79. }
  80. $page->getBannedTracks($nocache);
  81. $smarty->assign('page', $page);
  82. $smarty->display('user-library-banned.tpl');
  83. } else if ($page->section == 'tags') {
  84. if (isset($_POST['trackremovetag'])) {
  85. // remove track tag
  86. $track = new Track($_POST['removetrack'], $_POST['removeartist']);
  87. $track->removeTag($_POST['removetag'], $this_user->uniqueid);
  88. $nocache=true;
  89. } else if (isset($_POST['albumremovetag'])) {
  90. // remove album tag
  91. $album = new Album($_POST['removealbum'], $_POST['removeartist']);
  92. $album->removeTag($_POST['removetag'], $this_user->uniqueid);
  93. $nocache=true;
  94. } else if (isset($_POST['artistremovetag'])) {
  95. // remove artist tag
  96. $artist = new Artist($_POST['removeartist']);
  97. $artist->removeTag($_POST['removetag'], $this_user->uniqueid);
  98. $nocache=true;
  99. }
  100. if (isset($_GET['tag'])) {
  101. // show artists, albums and tracks with this tag
  102. $page->getTaggedArtists($nocache);
  103. $page->getTaggedAlbums($nocache);
  104. $page->getTaggedTracks($nocache);
  105. $smarty->assign('page', $page);
  106. } else {
  107. // Tags
  108. $page->getTags();
  109. $smarty->assign('page', $page);
  110. }
  111. $smarty->display('user-library-tags.tpl');
  112. }