Commit 4d6ebecc authored by Mike Sheldon's avatar Mike Sheldon

Merge commit 'refs/merge-requests/51' of git://gitorious.org/foocorp/gnu-fm into merge51

parents 338eb866 4e1ae83e
......@@ -42,9 +42,17 @@ if (!isset($this_user) || !$this_user->manages($artist->name)) {
$edit = false;
if (isset($_GET['album'])) {
$edit = true;
$album = new Album($_GET['album'], $artist->name);
}
try {
$album = new Album($_GET['album'], $artist->name);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Album not found.');
$smarty->assign('details', 'The album ' . $_GET['album'] . ' by artist ' . $artist->name . ' was not found in the database.');
$smarty->display('error.tpl');
die();
}
}
$smarty->assign('artist', $artist);
$smarty->assign('edit', $edit);
......
<?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/>.
*/
function album_menu($album, $active_page) {
global $this_user;
$submenu = array(
array('name' => _('Overview'), 'url' => $album->getURL()),
);
foreach($submenu as &$item) {
$item['active'] = ($item['name'] == $active_page);
}
return $submenu;
}
try {
$album = new Album($_GET['album'], $_GET['artist']);
$smarty->assign('album', $album);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Album not found.');
$smarty->assign('details', 'The album ' . $_GET['album'] . ' by artist ' . $_GET['artist'] . ' was not found in the database.');
$smarty->display('error.tpl');
die();
}
try {
$artist = new Artist($album->artist_name);
$smarty->assign('artist', $artist);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Artist not found.');
$smarty->assign('details', 'The artist ' . $track->artist_name . ' was not found in the database.');
$smarty->display('error.tpl');
die();
}
if (isset($this_user) && $this_user->manages($artist->name)) {
$smarty->assign('edit_link', $album->getEditURL());
$smarty->assign('add_track_link', $album->getAddTrackURL());
}
$smarty->assign('pagetitle', $artist->name . ' : ' . $album->name);
$smarty->assign('headerfile', 'album-header.tpl');
......@@ -19,40 +19,18 @@
*/
require_once('database.php');
require_once('templating.php');
require_once('data/Album.php');
$album = new Album($_GET['album'], $_GET['artist']);
try {
$artist = new Artist($album->artist_name);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Artist not found.');
$smarty->assign('details', 'The artist ' . $track->artist_name . ' was not found in the database.');
$smarty->display('error.tpl');
die();
}
if (isset($this_user) && $this_user->manages($artist->name)) {
$smarty->assign('edit_link', $album->getEditURL());
}
require_once('album-menu.php');
$smarty->assign('name', $album->name);
$smarty->assign('id', $album->id);
$smarty->assign('artist', $artist);
$smarty->assign('album', $album);
$smarty->assign('pagetitle', $artist->name . ' : ' . $album->name);
$aAlbumTracks = $album->getTracks();
if ($aAlbumTracks) {
$smarty->assign('tracks', $aAlbumTracks);
}
if (isset($this_user) && $this_user->manages($artist->name)) {
$smarty->assign('add_track_link', $album->getAddTrackURL());
}
$smarty->assign('extra_head_links', array(
array(
'rel' => 'meta',
......@@ -62,5 +40,4 @@ $smarty->assign('extra_head_links', array(
)
));
$smarty->assign('headerfile', 'album-header.tpl');
$smarty->display('album.tpl');
......@@ -116,15 +116,12 @@ class TrackXML {
}
public static function love($artist, $name, $userid) {
global $adodb;
try {
$res = $adodb->Execute('INSERT INTO Loved_Tracks VALUES ('
. $userid . ', '
. $adodb->qstr($name) . ', '
. $adodb->qstr($artist) . ', '
. time() . ')');
} catch (Exception $e) {}
$track = new Track($name, $artist);
$track->love($userid);
} catch (Exception $e) {
return(XML::error('failed', '7', 'Invalid resource specified'));
}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
......@@ -145,16 +142,16 @@ class TrackXML {
public static function unlove($artist, $name, $userid) {
global $adodb;
try {
$res = $adodb->Execute('DELETE FROM Loved_Tracks WHERE userid=' . $userid . ' AND track=' . $adodb->qstr($name) . ' AND artist=' . $adodb->qstr($artist));
} catch (Exception $e) {}
$track = new Track($name, $artist);
$track->unlove($userid);
} catch (Exception $e) {
return(XML::error('failed', '7', 'Invalid resource specified'));
}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
return $xml;
}
}
......@@ -32,3 +32,21 @@ function artist_menu($artist, $active_page) {
return $submenu;
}
try {
$artist = new Artist($_GET['artist']);
$smarty->assign(artist, $artist);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Artist not found.');
$smarty->assign('details', 'The artist ' . $_GET['artist'] . ' was not found in the database.');
$smarty->display('error.tpl');
die();
}
if (isset($this_user) && $this_user->manages($artist->name)) {
$smarty->assign('manage_link', $artist->getManagementURL());
$smarty->assign('add_album_link', $artist->getAddAlbumURL());
}
$smarty->assign('pagetitle', $artist->name);
$smarty->assign('headerfile', 'artist-header.tpl');
......@@ -33,21 +33,11 @@ if ($logged_in == false) {
die();
}
try {
$artist = new Artist($_GET['artist']);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Artist not found.');
$smarty->assign('details', 'The artist ' . $_GET['artist'] . ' was not found in the database.');
$smarty->display('error.tpl');
die();
}
if ($_POST['tag']) {
$artist->addTags($_POST['tags'], $this_user->uniqueid);
}
$smarty->assign('name', $artist->name);
$smarty->assign('pagetitle', $artist->name);
try {
$tagCloud = TagCloud::generateTagCloud('tags', 'tag', 10, 'artist', $artist->name);
......@@ -61,5 +51,4 @@ $smarty->assign('mytags', $this_user->getTagsForArtist($artist->name));
$submenu = artist_menu($artist, 'Tag');
$smarty->assign('submenu', $submenu);
$smarty->assign('headerfile', 'artist-header.tpl');
$smarty->display('artist-tag.tpl');
......@@ -26,15 +26,6 @@ require_once('data/Server.php');
require_once('data/TagCloud.php');
require_once('artist-menu.php');
try {
$artist = new Artist($_GET['artist']);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Artist not found.');
$smarty->assign('details', 'The artist ' . $_GET['artist'] . ' was not found in the database.');
$smarty->display('error.tpl');
die();
}
$station = 'librefm://artist/' . $artist->name;
if (isset($this_user)) {
$radio_session = $this_user->getRadioSession($station);
......@@ -44,7 +35,6 @@ if (isset($this_user)) {
$smarty->assign('radio_session', $radio_session);
$smarty->assign('name', $artist->name);
$smarty->assign('pagetitle', $artist->name);
$smarty->assign('id', $artist->id);
$smarty->assign('bio_summary', $artist->bio_summary);
$smarty->assign('bio_content', $artist->bio_content);
......@@ -61,11 +51,6 @@ if ($aArtistAlbums) {
$smarty->assign('albums', $aArtistAlbums);
}
if (isset($this_user) && $this_user->manages($artist->name)) {
$smarty->assign('manage_link', $artist->getManagementURL());
$smarty->assign('add_album_link', $artist->getAddAlbumURL());
}
try {
$tagCloud = TagCloud::generateTagCloud('tags', 'tag', 10, 'artist', $artist->name);
$smarty->assign('tagcloud', $tagCloud);
......@@ -76,5 +61,4 @@ try {
$submenu = artist_menu($artist, 'Overview');
$smarty->assign('submenu', $submenu);
$smarty->assign('headerfile', 'artist-header.tpl');
$smarty->display('artist.tpl');
......@@ -40,8 +40,6 @@ class Album {
/**
* Album constructor
*
* @todo throw Exception instead of setting $this->name to 'No such album: $name'
*
* @param string name The name of the album to load
* @param string artist The name of the artist who recorded this album
*/
......@@ -53,7 +51,7 @@ class Album {
. 'lower(artist_name) = lower(' . $adodb->qstr($artist) . ')';
$r = $adodb->CacheGetRow(1200, $this->query);
if (!$r) {
$this->name = 'No such album: ' . $name;
throw new Exception('No such album: ' . $name);
} else {
$row = sanitize($r);
$this->name = $row['name'];
......@@ -179,26 +177,18 @@ class Album {
/**
* Get the top tags for this album, ordered by tag count
*
* @todo Remove throw new Exception when album construct has been changed to throw it
*
* @param int $limit The number of tags to return (default is 10)
* @param int $offset The position of the first tag to return (default is 0)
* @param int $cache Caching period of query in seconds (default is 600)
* @return array Tag details ((tag, freq) .. )
*/
function getTopTags($limit=10, $offset=0, $cache=600) {
if(substr($this->name, 0, 13) == 'No such album') {
throw new Exception('No such album');
}
return Tag::_getTagData($cache, $limit, $offset, null, $this->artist_name, $this->name);
}
/**
* Get a specific user's tags for this album.
*
* @todo Remove throw new Exception when album construct has been changed to throw it
*
* @param int $userid Get tags for this user
* @param int $limit The number of tags to return (default is 10)
* @param int $offset The position of the first tag to return (default is 0)
......@@ -207,10 +197,6 @@ class Album {
*/
function getTags($userid, $limit=10, $offset=0, $cache=600) {
if(isset($userid)) {
if(substr($this->name, 0, 13) == 'No such album') {
throw new Exception('No such album');
}
return Tag::_getTagData($cache, $limit, $offset, $userid, $this->artist_name, $this->name);
}
}
......
......@@ -44,8 +44,6 @@ class Track {
/**
* Track constructor
*
* @todo throw Exception instead of setting $this->name to 'No such track: $name'
* @param string $name The name of the track to load
* @param string $artist The name of the artist who recorded this track
*/
......@@ -58,7 +56,7 @@ class Track {
. 'ORDER BY streamable DESC';
$res = $adodb->CacheGetRow(600, $this->query);
if (!$res) {
$this->name = 'No such track: ' . $name;
throw new Exception('No such track: ' . $name);
} else {
$row = $res;
$this->name = $row['name'];
......@@ -284,26 +282,18 @@ class Track {
/**
* Gets the top tags for this track, ordered by tag count
*
* @todo Remove throw new Exception when track construct has been changed to throw it
*
* @param int $limit The number of tags to return (default is 10)
* @param int $offset The position of the first tag to return (default is 0)
* @param int $cache Caching period of query in seconds (default is 600)
* @return array Tag details ((tag, freq) .. )
*/
function getTopTags($limit=10, $offset=0, $cache=600) {
if(substr($this->name, 0, 13) == 'No such track') {
throw new Exception('No such track');
}
return Tag::_getTagData($cache, $limit, $offset, null, $this->artist_name, null, $this->name);
}
/**
* Get a specific user's tags for this track.
*
* @todo Remove throw new Exception when track construct has been changed to throw it
*
* @param int $userid Get tags for this user
* @param int $limit The number of tags to return (default is 10)
* @param int $offset The position of the first tag to return (default is 0)
......@@ -312,10 +302,6 @@ class Track {
*/
function getTags($userid, $limit=10, $offset=0, $cache=600) {
if(isset($userid)) {
if(substr($this->name, 0, 13) == 'No such track') {
throw new Exception('No such track');
}
return Tag::_getTagData($cache, $limit, $offset, $userid, $this->artist_name, null, $this->name);
}
}
......@@ -345,4 +331,59 @@ class Track {
} catch (Exception $e) {}
}
}
/**
* Love a track
*
* @param int $userid The user loving this track
*/
function love($userid) {
global $adodb;
try {
$adodb->Execute('INSERT INTO Loved_Tracks VALUES ('
. $userid . ', '
. $adodb->qstr($this->name) . ', '
. $adodb->qstr($this->artist_name) . ', '
. time() . ')');
} catch (Exception $e) {}
}
/**
* Unlove a track
*
* @param int $userid The user unloving this track
*/
function unlove($userid) {
global $adodb;
try {
$adodb->Execute('DELETE FROM Loved_Tracks WHERE userid=' . $userid
. ' AND track=' . $adodb->qstr($this->name)
. ' AND artist=' . $adodb->qstr($this->artist_name));
} catch (Exception $e) {}
}
/**
* Check if track has been loved by user
*
* @param int $userid The user we are looking for
* @return bool True if track has been loved by user
*/
function isLoved($userid) {
global $adodb;
try {
$res = $adodb->GetRow('SELECT * FROM Loved_Tracks WHERE userid='
. $userid . ' AND track='
. $adodb->qstr($this->name) . ' AND artist='
. $adodb->qstr($this->artist_name));
} catch (Exception $e) {}
if($res) {
return True;
}
return False;
}
}
<h2 property="dc:title" class="fn" rel="foaf:page" rev="foaf:primaryTopic" resource="">{$track->name|escape:'html':'UTF-8'}{if $edit_link} <a href="{$edit_link}"><small>[{t}Edit{/t}]</small></a>{/if}</h2>
<h2 property="dc:title" class="fn" rel="foaf:page" rev="foaf:primaryTopic" resource="">
<a href="{$artist->getURL()}">{$artist->name|escape:'html':'UTF-8'}</a>
&#8212;
{$track->name|escape:'html':'UTF-8'}
{if $edit_link}
<a href="{$edit_link}"><small>[{t}Edit{/t}]</small></a>
{/if}
</h2>
......@@ -29,10 +29,12 @@
<a about="{$artist->id|escape:'html':'UTF-8'}" typeof="mo:MusicArtist" property="foaf:name" class="url fn org"
rel="foaf:page" rev="foaf:primaryTopic" href="{$artist->getURL()|escape:'html':'UTF-8'}">{$artist->name|escape:'html':'UTF-8'}</a>
</dd>
{if $album}
<dt>{t}Album:{/t}</dt>
<dd rev="mo:track">
<a about="{$album->id|escape:'html':'UTF-8'}" typeof="mo:Record" property="dc:title" class="album"
rel="foaf:page" rev="foaf:primaryTopic" href="{$album->getURL()|escape:'html':'UTF-8'}">{$album->name|escape:'html':'UTF-8'}</a>
{/if}
</dd>
{if $track->mbid != ""}
<dt>MusicBrainz ID:</dt>
......@@ -59,6 +61,18 @@
<p style='padding-left: 1em;'><b><a href='{$track->streamurl}'>{t}Download track{/t}</a></b></p>
{/if}
{/if}
{if $logged_in}
{if $isloved}
<form action='' method='post'>
<input type='submit' name='unlove' id='unlove' value='{t}Unlove this track{/t}' />
</form>
{else}
<form action='' method='post'>
<input type='submit' name='love' id='love' value='{t}Love this track{/t}' />
</form>
{/if}
{/if}
{if !empty($tagcloud)}
<h3 style='text-align: center; clear: left;'>{t}Tags used to describe this track{/t}</h3>
......
......@@ -36,7 +36,14 @@ try {
die();
}
$album = new Album($_GET['album'], $artist->name);
try {
$album = new Album($_GET['album'], $artist->name);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Album not found.');
$smarty->assign('details', 'The album ' . $_GET['album'] . ' by artist ' . $artist->name . ' was not found in the database.');
$smarty->display('error.tpl');
die();
}
if (!isset($this_user) || !$this_user->manages($artist->name)) {
$smarty->assign('pageheading', 'Permission denied');
......@@ -48,7 +55,15 @@ if (!isset($this_user) || !$this_user->manages($artist->name)) {
$edit = false;
if (isset($_GET['track'])) {
$edit = true;
$track = new Track($_GET['track'], $artist->name);
try {
$track = new Track($_GET['track'], $artist->name);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Track not found.');
$smarty->assign('details', 'The track ' . $_GET['track'] . ' by artist ' . $artist->name . ' was not found in the database.');
$smarty->display('error.tpl');
die();
}
}
$smarty->assign('artist', $artist);
......
......@@ -32,3 +32,36 @@ function track_menu($track, $active_page) {
}
return $submenu;
}
// Create Artist, Album and Track objects
try {
$track = new Track($_GET['track'], $_GET['artist']);
$smarty->assign('track', $track);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Track not found.');
$smarty->assign('details', 'The track ' . $_GET['track'] . ' by artist ' . $_GET['artist'] . ' was not found in the database.');
$smarty->display('error.tpl');
die();
}
try {
$album = new Album($track->album_name, $track->artist_name);
$smarty->assign('album', $album);
} catch (Exception $e) {}
try {
$artist = new Artist($track->artist_name);
$smarty->assign('artist', $artist);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Artist not found.');
$smarty->assign('details', 'The artist ' . $track->artist_name . ' was not found in the database.');
$smarty->display('error.tpl');
die();
}
if (isset($this_user) && $this_user->manages($artist->name)) {
$smarty->assign('edit_link', $track->getEditURL());
}
$smarty->assign('pagetitle', $track->artist_name . ' : ' . $track->name);
$smarty->assign('headerfile', 'track-header.tpl');
......@@ -31,23 +31,10 @@ if ($logged_in == false) {
die();
}
try {
$track = new Track($_GET['track'], $_GET['artist']);
$smarty->assign('track', $track);
} catch (Exception $e) {
//TODO Make track throw exception
$smarty->assign('pageheading', 'Track not found.');
$smarty->assign('details', 'The track ' . $_GET['track'] . ' was not found in the database.');
$smarty->display('error.tpl');
die();
}
if($_POST['tag']) {
$track->addTags($_POST['tags'], $this_user->uniqueid);
}
$smarty->assign('pagetitle', $track->artist_name . ' : ' . $track->name);
try {
$tagCloud = TagCloud::generateTagCloud('tags', 'tag', 10, 'track', array($track->name, $track->artist_name));
$smarty->assign('tagcloud', $tagCloud);
......@@ -59,6 +46,4 @@ $smarty->assign('mytags', $track->getTags($this_user->uniqueid, null, null, 0));
$submenu = track_menu($track, 'Tag');
$smarty->assign('submenu', $submenu);
$smarty->assign('headerfile', 'track-header.tpl');
$smarty->display('track-tag.tpl');
......@@ -26,29 +26,8 @@ require_once('data/Server.php');
require_once('data/TagCloud.php');
require_once('track-menu.php');
$track = new Track($_GET['track'], $_GET['artist']);
$smarty->assign('track', $track);
$album = new Album($track->album_name, $track->artist_name);
$smarty->assign('album', $album);
try {
$artist = new Artist($track->artist_name);
} catch (Exception $e) {
$smarty->assign('pageheading', 'Artist not found.');
$smarty->assign('details', 'The artist ' . $track->artist_name . ' was not found in the database.');
$smarty->display('error.tpl');
die();
}
$smarty->assign('artist', $artist);
$smarty->assign('flattr_uid', $artist->flattr_uid);
$smarty->assign('url', $track->getURL());
$smarty->assign('pagetitle', $artist->name . ' : ' . $track->name);
if (isset($this_user) && $this_user->manages($artist->name)) {
$smarty->assign('edit_link', $track->getEditURL());
}
if ($track->duration) {
// Give the duration in MM:SS
......@@ -77,7 +56,16 @@ try {
}
$smarty->assign('tagcloud', $tagCloud);
if ($logged_in) {
if($_POST['love']) {
$track->love($this_user->uniqueid);
}
if($_POST['unlove']) {
$track->unlove($this_user->uniqueid);
}
$smarty->assign('isloved', $track->isLoved($this_user->uniqueid));
}
$submenu = track_menu($track, 'Overview');
$smarty->assign('submenu', $submenu);
$smarty->assign('headerfile', 'track-header.tpl');
$smarty->display('track.tpl');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment