We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

user-library.php 4.16 KB
Newer Older
Jonas Haraldsson's avatar
Jonas Haraldsson committed
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
<?php

/* GNU FM -- a free network service for sharing your music listening habits

   Copyright (C) 2013 Free Software Foundation, Inc

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU Affero General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU Affero General Public License for more details.

   You should have received a copy of the GNU Affero General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

require_once('data/Library_page.php');
require_once('data/Artist.php');
require_once('data/Album.php');
require_once('data/Track.php');

if (!isset($_GET['user']) && $logged_in == false) {
28
	displayError("Error", "User not set. You shouldn't be here.");
Jonas Haraldsson's avatar
Jonas Haraldsson committed
29 30 31 32 33
}

try {
	$user = new User($_GET['user']);
} catch (Exception $e) {
Jonas Haraldsson's avatar
typos  
Jonas Haraldsson committed
34
	displayError("User not found", "User not found, shall I call in a missing persons report?");
Jonas Haraldsson's avatar
Jonas Haraldsson committed
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
}

$submenu = user_menu($user, 'Library');
$smarty->assign('submenu', $submenu);

$page = new Library_page($user);
$smarty->assign('me', $user);
if ($page->section == 'music') {
	if (isset($_GET['artist']) && (!isset($_GET['album']) && !isset($_GET['track']))) {
		// Music -> Artist name
		$page->getAlbums();
		$page->getTracks();
		$smarty->assign('page', $page);
		$smarty->display('user-library-artist.tpl');

	} else if ((isset($_GET['artist']) && isset($_GET['album'])) && !isset($_GET['track'])) {
		// Music -> Artist name -> Album name
		$page->getTracks();
		$smarty->assign('page', $page);
		$smarty->display('user-library-album.tpl');

	} else if ((isset($_GET['artist']) && isset($_GET['track'])) && !isset($_GET['album'])) {
		// Music -> Artist name -> Track name
		$smarty->assign('page', $page);
		$smarty->display('user-library-track.tpl');

	} else {
		// Music -> Artists
Jonas Haraldsson's avatar
debug  
Jonas Haraldsson committed
63 64 65
		try {
			$page->getArtists();
		} catch (Exception $e) {
66
			displayError("Error", $e->getMessage());
Jonas Haraldsson's avatar
debug  
Jonas Haraldsson committed
67
		}
Jonas Haraldsson's avatar
Jonas Haraldsson committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
		$smarty->assign('page', $page);
		$smarty->display('user-library-music.tpl');
	}

} else if ($page->section == 'scrobbles') {
	if (isset($_POST['removescrobble'])) {
		Library::removeScrobble($this_user->uniqueid, $_POST['timestamp'], $_POST['artist'], $_POST['track']);
		$nocache = true;
	}
	$page->getScrobbles($nocache);
	$smarty->assign('page', $page);
	$smarty->display('user-library-scrobbles.tpl');

} else if ($page->section == 'loved') {
	if (isset($_POST['unlove'])) {
		$track = new Track($_POST['track'], $_POST['artist']);
		$track->unlove($this_user->uniqueid);
		$nocache=true;
	}
	$page->getLovedTracks($nocache);
	$smarty->assign('page', $page);
	$smarty->display('user-library-loved.tpl');

} else if ($page->section == 'banned') {
Jonas Haraldsson's avatar
Jonas Haraldsson committed
92
	if (isset($_POST['unban'])) {
Jonas Haraldsson's avatar
Jonas Haraldsson committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
		$track = new Track($_POST['track'], $_POST['artist']);
		$track->unban($this_user->uniqueid);
		$nocache = true;
	}
	$page->getBannedTracks($nocache);
	$smarty->assign('page', $page);
	$smarty->display('user-library-banned.tpl');

} else if ($page->section == 'tags') {
	if (isset($_POST['trackremovetag'])) {
		// remove track tag
		$track = new Track($_POST['removetrack'], $_POST['removeartist']);
		$track->removeTag($_POST['removetag'], $this_user->uniqueid);
		$nocache=true;
	} else if (isset($_POST['albumremovetag'])) {
		// remove album tag
		$album = new Album($_POST['removealbum'], $_POST['removeartist']);
		$album->removeTag($_POST['removetag'], $this_user->uniqueid);
		$nocache=true;
	} else if (isset($_POST['artistremovetag'])) {
		// remove artist tag
		$artist = new Artist($_POST['removeartist']);
		$artist->removeTag($_POST['removetag'], $this_user->uniqueid);
		$nocache=true;
	}
	
	if (isset($_GET['tag'])) {
		// show artists, albums and tracks with this tag
		$page->getTaggedArtists($nocache);
		$page->getTaggedAlbums($nocache);
		$page->getTaggedTracks($nocache);
		
		$smarty->assign('page', $page);
	} else {
		// Tags
		$page->getTags();
		$smarty->assign('page', $page);
	}
	$smarty->display('user-library-tags.tpl');
}