Commit 7c271921 authored by Mike Sheldon's avatar Mike Sheldon

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

parents 9f23a5c3 9fd411d7
......@@ -9,9 +9,11 @@ RewriteRule ^user/([^/]+)/stats/?$ user-stats.php?user=$1 [NC,QSA]
RewriteRule ^user/([^/]+)/station/?$ user-station.php?user=$1 [NC,QSA]
RewriteRule ^user/([^/]+)/recommended/?$ user-recommended.php?user=$1 [NC,QSA]
RewriteRule ^artist/([^/]+)/track/([^/]+)/edit/?$ track-add.php?artist=$1&track=$2 [NC,QSA]
RewriteRule ^artist/([^/]+)/track/([^/]+)/tag/?$ track-tag.php?artist=$1&track=$2 [NC,QSA]
RewriteRule ^artist/([^/]+)/track/([^/]+)/?$ track.php?artist=$1&track=$2 [NC,QSA]
RewriteRule ^artist/([^/]+)/album/([^/]+)/track/add/?$ track-add.php?artist=$1&album=$2 [NC,QSA]
RewriteRule ^artist/([^/]+)/album/([^/]+)/track/([^/]+)/edit/?$ track-add.php?artist=$1&album=$2&track=$3 [NC,QSA]
RewriteRule ^artist/([^/]+)/album/([^/]+)/track/([^/]+)/tag/?$ track-tag.php?artist=$1&album=$2&track=$3 [NC,QSA]
RewriteRule ^artist/([^/]+)/album/([^/]+)/track/([^/]+)/?$ track.php?artist=$1&album=$2&track=$3 [NC,QSA]
RewriteRule ^artist/([^/]+)/album/add/?$ album-add.php?artist=$1 [NC,QSA]
RewriteRule ^artist/([^/]+)/album/([^/]+)/?$ album.php?artist=$1&album=$2 [NC,QSA]
......
......@@ -24,23 +24,12 @@ require_once('xml.php');
class TrackXML {
public static function addTags($userid, $artist, $album, $track, $tags) {
global $adodb;
$tags = explode(',', strtolower($tags));
foreach ($tags as $tag) {
$tag = trim($tag);
if (strlen($tag) == 0) {
continue;
}
try {
$adodb->Execute('INSERT INTO Tags VALUES ('
. $adodb->qstr($tag) . ', '
. $adodb->qstr($artist) . ', '
. $adodb->qstr($album) . ', '
. $adodb->qstr($track) . ', '
. $userid . ')');
} catch (Exception $e) {}
public static function addTags($userid, $artist, $album, $trackName, $tags) {
try {
$track = new Track($trackName, $artist);
$track->addTags($tags, $userid);
} catch (Exception $e) {
return(XML::error('failed', '7', 'Invalid resource specified'));
}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
......
......@@ -378,15 +378,29 @@ class Server {
}
static function getTrackURL($artist, $album, $track) {
static function getTrackURL($artist, $album, $track, $component = '') {
global $friendly_urls, $base_url;
if ($friendly_urls && $album) {
return $base_url . '/artist/' . rewrite_encode($artist) . '/album/' . rewrite_encode($album) . '/track/' . rewrite_encode($track);
} else if ($friendly_urls) {
return $base_url . '/artist/' . rewrite_encode($artist) . '/track/' . rewrite_encode($track);
if($friendly_urls) {
$trackurl = $base_url . '/artist/' . rewrite_encode($artist);
if($album) {
$trackurl .= '/album/' . rewrite_encode($album);
}
$trackurl .= '/track/' . rewrite_encode($track);
if($component) {
$trackurl .= '/' . $component;
}
} else {
return $base_url . '/track.php?artist=' . urlencode($artist) . '&album=' . urlencode($album) . '&track=' . urlencode($track);
if($component) {
$trackurl = $base_url . '/track-' . $component . '.php?artist=' . urlencode($artist)
. '&album=' . urlencode($album) . '&track=' . urlencode($track);
} else {
$trackurl = $baseurl . '/track.php?artist=' . urlencode($artist)
. '&album=' . urlencode($album) . '&track=' . urlencode($track);
}
}
return $trackurl;
}
static function getTrackEditURL($artist, $album, $track) {
......
......@@ -252,8 +252,8 @@ class Track {
}
}
function getURL() {
return Server::getTrackURL($this->artist_name, $this->album_name, $this->name);
function getURL($component = '') {
return Server::getTrackURL($this->artist_name, $this->album_name, $this->name, $component);
}
function getEditURL() {
......@@ -297,4 +297,29 @@ class Track {
}
}
/**
* Add a list of tags to a track
*
* @param string $tags A comma-separated list of tags
* @param int $userid The user adding these tags
*/
function addTags($tags, $userid) {
global $adodb;
$tags = explode(',', strtolower($tags));
foreach($tags as $tag) {
$tag = trim($tag);
if(strlen($tag) == 0) {
continue;
}
try {
$adodb->Execute('INSERT INTO Tags VALUES ('
. $adodb->qstr($tag) . ','
. $adodb->qstr($this->artist_name) . ', '
. $adodb->qstr($this->album_name) . ', '
. $adodb->qstr($this->name) . ', '
. $userid . ')');
} catch (Exception $e) {}
}
}
}
{include file='header.tpl'}
<div about="{$track->id|escape:'html':'UTF-8'}" typeof="mo:Track" class="haudio">
{if !empty($tagcloud)}
<h3 style='text-align: center; clear: left;'>{t}Popular tags other people used to describe this track{/t}</h3>
<ul class="tagcloud">
{section name=i loop=$tagcloud}
<li style='font-size:{$tagcloud[i].size}'><a href='/tag/{$tagcloud[i].tag|urlencode}' title='{t uses=$tagcloud[i].count}This tag was used %1 times{/t}' rel='tag'>{$tagcloud[i].tag}</a></li>
{/section}
</ul>
{/if}
{if !empty($mytags)}
<h3 style='text-align: center; clear: left;'>{t}Tags you've used for this track{/t}</h3>
<ul class="tagcloud">
{section name=i loop=$mytags}
<li>{$mytags[i].tag},</li>
{/section}
</ul>
{/if}
<br />
<form action='' method='post'>
<b><label for='tags'>{t}Add tags:{/t}</label></b><br />
<br />
<input type='text' name='tags' id='tags' /><br />
<br />
<input type='submit' name='tag' id='tag' value='{t}Tag{/t}' />
</form>
{literal}
<script type='text/javascript'>
$(document).ready(function(){
$("#tags").placeholdr({placeholderText: "{/literal}{t}e.g. guitar, violin, female vocals, piano{/t}{literal}"});
});
</script>
{/literal}
<br />
</div>
{include file='footer.tpl'}
......@@ -59,7 +59,16 @@
<p style='padding-left: 1em;'><b><a href='{$track->streamurl}'>{t}Download track{/t}</a></b></p>
{/if}
{/if}
{if !empty($tagcloud)}
<h3 style='text-align: center; clear: left;'>{t}Tags used to describe this track{/t}</h3>
<ul class="tagcloud">
{section name=i loop=$tagcloud}
<li style='font-size:{$tagcloud[i].size}'><a href='/tag/{$tagcloud[i].tag|urlencode}' title='{t uses=$tagcloud[i].count}This tag was used %1 times{/t}' rel='tag'>{$tagcloud[i].tag}</a></li>
{/section}
</ul>
{/if}
<br />
</div>
{include file='footer.tpl'}
<?php
/* GNU FM -- a free network service for sharing your music listening habits
Copyright (C) 2012 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 track_menu($track, $active_page) {
global $this_user;
$submenu = array(
array('name' => _('Overview'), 'url' => $track->getURL()),
array('name' => _('Tag'), 'url' => $track->getURL('tag')),
);
foreach($submenu as &$item) {
$item['active'] = ($item['name'] == $active_page);
}
return $submenu;
}
<?php
/* GNU FM -- a free network service for sharing your music listening habits
Copyright (C) 2012 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('database.php');
require_once('templating.php');
require_once('data/TagCloud.php');
require_once('track-menu.php');
if ($logged_in == false) {
$smarty->assign('pageheading', 'Log in required');
$smarty->assign('details', 'You need to log in to tag tracks.');
$smarty->display('error.tpl');
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->name, 'track');
$smarty->assign('tagcloud', $tagCloud);
} catch(Exception $e) {
$tagCloud = array();
}
$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');
......@@ -24,6 +24,7 @@ require_once('templating.php');
require_once('data/sanitize.php');
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);
......@@ -81,7 +82,16 @@ $smarty->assign('extra_head_links', array(
'title' => 'Track Metadata',
'href' => $base_url . '/rdf.php?fmt=xml&page=' . urlencode(str_replace($base_url, '', $track->getURL()))
)
));
));
try {
$tagCloud = TagCloud::generateTagCloud('Tags', 'tag', 10, $track->name, 'track');
} catch ( Exception $e) {
$tagCloud = array();
}
$smarty->assign('tagcloud', $tagCloud);
$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