track.php 2.7 KB
Newer Older
jurgbohn's avatar
jurgbohn committed
1 2
<?php

3
/* GNU FM -- a free network service for sharing your music listening habits
jurgbohn's avatar
jurgbohn committed
4

5
   Copyright (C) 2009 Free Software Foundation, Inc
jurgbohn's avatar
jurgbohn committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

   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/>.

*/

22
require_once('database.php');
clint's avatar
clint committed
23 24 25 26
require_once('templating.php');
require_once('data/sanitize.php');
require_once('data/Server.php');
require_once('data/TagCloud.php');
jurgbohn's avatar
jurgbohn committed
27

28
$track = new Track($_GET['track'], $_GET['artist']);
elleo's avatar
elleo committed
29
$smarty->assign('track', $track);
jurgbohn's avatar
jurgbohn committed
30

31
$album = new Album($track->album_name, $track->artist_name);
elleo's avatar
elleo committed
32
$smarty->assign('album', $album);
clint's avatar
clint committed
33

Jørgen Bøhnsdalen's avatar
Jørgen Bøhnsdalen committed
34 35
try {
	$artist = new Artist($track->artist_name);
36
} catch (Exception $e) {
37
	$smarty->assign('pageheading', 'Artist not found.');
Jørgen Bøhnsdalen's avatar
Jørgen Bøhnsdalen committed
38 39 40 41 42
	$smarty->assign('details', 'The artist ' . $track->artist_name . ' was not found in the database.');
	$smarty->display('error.tpl');
	die();
}

elleo's avatar
elleo committed
43
$smarty->assign('artist', $artist);
44 45
$smarty->assign('flattr_uid', $artist->flattr_uid);
$smarty->assign('url', $track->getURL());
46 47
$smarty->assign('pagetitle', $artist->name . ' : ' . $track->name);

48
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
49
$res = $adodb->GetAll('SELECT * FROM Track WHERE lower(artist_name) = lower(' . $adodb->qstr($track->artist_name) . ') AND lower(name) = lower(' . $adodb->qstr($track->name) . ')');
clint's avatar
clint committed
50

51
$aOtherAlbums = array();
clint's avatar
clint committed
52

53
foreach ($res as &$trow) {
elleo's avatar
elleo committed
54
	if ($trow['album']) {
55
		$aOtherAlbums[] = new Album($trow['album'], $trow['artist']);
56
	}
57
}
clint's avatar
clint committed
58

59
if (isset($this_user) && $this_user->manages($artist->name)) {
60 61 62 63
	$smarty->assign('edit_link', $track->getEditURL());
}


64
if ($track->duration) {
65 66 67
	// Give the duration in MM:SS
	$mins = floor($track->duration / 60);
	$sec = floor($track->duration % 60);
68 69 70 71
	if (strlen($sec) == 1) {
		$sec = '0' . $sec;
	}
	$duration = $mins . ':' . $sec;
72 73
	$smarty->assign('duration', $duration);
}
74

elleo's avatar
elleo committed
75
$smarty->assign('albums', $aOtherAlbums);
clint's avatar
clint committed
76

77 78
$smarty->assign('extra_head_links', array(
		array(
79 80
			'rel'   => 'meta',
			'type'  => 'application/rdf+xml',
81
			'title' => 'Track Metadata',
82
			'href'  => $base_url . '/rdf.php?fmt=xml&page=' . urlencode(str_replace($base_url, '', $track->getURL()))
83 84 85
			)
	));

86
$smarty->assign('headerfile', 'track-header.tpl');
elleo's avatar
elleo committed
87
$smarty->display('track.tpl');