Commit da3ac1b2 authored by Mike Sheldon's avatar Mike Sheldon

Make it possible for artists to edit existing tracks as well as add new ones

parent 525520cc
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteRule ^user/([^/]+)/?$ user-profile.php?user=$1 [B,NC]
RewriteRule ^user/([^/]+)/journal/?$ user-journal.php?user=$1 [B,NC]
RewriteRule ^user/([^/]+)/groups/?$ user-groups.php?user=$1 [B,NC]
RewriteRule ^user/([^/]+)/recent-tracks/?$ user-recent-tracks.php?user=$1 [B,NC,QSA]
RewriteRule ^user/([^/]+)/stats/?$ user-stats.php?user=$1 [B,NC]
RewriteRule ^user/([^/]+)/station/?$ user-station.php?user=$1 [B,NC,QSA]
RewriteRule ^user/([^/]+)/recommended/?$ user-recommended.php?user=$1 [B,NC]
RewriteRule ^artist/([^/]+)/track/([^/]+)/?$ track.php?artist=$1&track=$2 [B,NC]
RewriteRule ^artist/([^/]+)/album/([^/]+)/track/add/?$ track-add.php?artist=$1&album=$2 [B,NC]
RewriteRule ^artist/([^/]+)/album/([^/]+)/track/([^/]+)/?$ track.php?artist=$1&album=$2&track=$3 [B,NC]
RewriteRule ^artist/([^/]+)/album/add/?$ album-add.php?artist=$1 [B,NC]
RewriteRule ^artist/([^/]+)/album/([^/]+)/?$ album.php?artist=$1&album=$2 [B,NC]
RewriteRule ^artist/([^/]+)/?$ artist.php?artist=$1 [B,NC]
RewriteRule ^artist/([^/]+)/manage/?$ artist-manage.php?artist=$1 [B,NC]
RewriteRule ^artist/([^/]+)/tag/?$ artist-tag.php?artist=$1 [B,NC]
RewriteRule ^group/new$ edit_group.php?group=new [B,NC]
RewriteRule ^group/([^/]+)/?$ group.php?group=$1 [B,NC,QSA]
RewriteRule ^group/?$ group.php [B,NC]
RewriteRule ^country/([^/]+)/?$ location.php?country=$1 [B,NC]
RewriteRule ^logout login.php?action=logout [B,NC]
RewriteRule ^user/([^/]+)/?$ user-profile.php?user=$1 [B,NC]
RewriteRule ^user/([^/]+)/journal/?$ user-journal.php?user=$1 [B,NC]
RewriteRule ^user/([^/]+)/groups/?$ user-groups.php?user=$1 [B,NC]
RewriteRule ^user/([^/]+)/recent-tracks/?$ user-recent-tracks.php?user=$1 [B,NC,QSA]
RewriteRule ^user/([^/]+)/stats/?$ user-stats.php?user=$1 [B,NC]
RewriteRule ^user/([^/]+)/station/?$ user-station.php?user=$1 [B,NC,QSA]
RewriteRule ^user/([^/]+)/recommended/?$ user-recommended.php?user=$1 [B,NC]
RewriteRule ^artist/([^/]+)/track/([^/]+)/edit/?$ track-add.php?artist=$1&track=$2 [B,NC]
RewriteRule ^artist/([^/]+)/track/([^/]+)/?$ track.php?artist=$1&track=$2 [B,NC]
RewriteRule ^artist/([^/]+)/album/([^/]+)/track/add/?$ track-add.php?artist=$1&album=$2 [B,NC]
RewriteRule ^artist/([^/]+)/album/([^/]+)/track/([^/]+)/edit/?$ track-add.php?artist=$1&album=$2&track=$3 [B,NC]
RewriteRule ^artist/([^/]+)/album/([^/]+)/track/([^/]+)/?$ track.php?artist=$1&album=$2&track=$3 [B,NC]
RewriteRule ^artist/([^/]+)/album/add/?$ album-add.php?artist=$1 [B,NC]
RewriteRule ^artist/([^/]+)/album/([^/]+)/?$ album.php?artist=$1&album=$2 [B,NC]
RewriteRule ^artist/([^/]+)/?$ artist.php?artist=$1 [B,NC]
RewriteRule ^artist/([^/]+)/manage/?$ artist-manage.php?artist=$1 [B,NC]
RewriteRule ^artist/([^/]+)/tag/?$ artist-tag.php?artist=$1 [B,NC]
RewriteRule ^group/new$ edit_group.php?group=new [B,NC]
RewriteRule ^group/([^/]+)/?$ group.php?group=$1 [B,NC,QSA]
RewriteRule ^group/?$ group.php [B,NC]
RewriteRule ^country/([^/]+)/?$ location.php?country=$1 [B,NC]
RewriteRule ^logout login.php?action=logout [B,NC]
RewriteRule ^listen listen.php
RewriteRule ^music popular.php
RewriteRule ^users users.php
RewriteRule ^tag/([^/]+)/?$ tag.php?tag=$1 [B,NC]
RewriteRule ^tag/([^/]+)/?$ tag.php?tag=$1 [B,NC]
......@@ -211,6 +211,11 @@ class Artist {
return $res;
}
function clearCache() {
global $adodb;
$adodb->CacheFlush($this->query);
}
/**
* Set an artist's biography summary
*
......
......@@ -387,6 +387,17 @@ class Server {
}
}
static function getTrackEditURL($artist, $album, $track) {
global $friendly_urls, $base_url;
if ($friendly_urls && $album) {
return $base_url . '/artist/' . urlencode($artist) . '/album/' . urlencode($album) . '/track/' . urlencode($track) . '/edit';
} elseif ($friendly_urls) {
return $base_url . '/artist/' . urlencode($artist) . '/track/' . urlencode($track) . '/edit';
} else {
return $base_url . '/track-add.php?artist=' . urlencode($artist) . '&album=' . urlencode($album) . '&track=' . urlencode($track);
}
}
static function getTagURL($tag) {
global $friendly_urls, $base_url;
if ($friendly_urls) {
......
......@@ -49,10 +49,11 @@ class Track {
function __construct($name, $artist) {
global $adodb;
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
$res = $adodb->CacheGetRow(600, 'SELECT name, artist_name, album_name, duration, streamable, license, downloadurl, streamurl, mbid FROM Track WHERE '
$this->query = 'SELECT name, artist_name, album_name, duration, streamable, license, downloadurl, streamurl, mbid FROM Track WHERE '
. 'lower(name) = ' . strtolower($adodb->qstr($name)) . ' AND '
. 'lower(artist_name) = ' . strtolower($adodb->qstr($artist))
. 'ORDER BY streamable DESC');
. 'ORDER BY streamable DESC';
$res = $adodb->CacheGetRow(600, $this->query);
if(!$res) {
$this->name = 'No such track: ' . $name;
} else {
......@@ -102,6 +103,11 @@ class Track {
return new Track($name, $artist_name);
}
function clearCache() {
global $adodb;
$adodb->CacheFlush($this->query);
}
/**
* Sets the playcount
*
......@@ -120,6 +126,60 @@ class Track {
$this->_listenercount = $listeners;
}
/**
* Sets the streaming URL
*
* @param string $streamurl The URL pointing to a streamable file
*/
function setStreamURL($streamurl) {
global $adodb;
$adodb->Execute('UPDATE Track SET streamurl=' . $adodb->qstr($streamurl) .
' WHERE artist_name=' . $adodb->qstr($this->artist_name) . ' AND ' .
' name=' . $adodb->qstr($this->name));
$this->clearCache();
}
/**
* Sets the download URL
*
* @param string $downloadurl The URL pointing to a downloadable file
*/
function setDownloadURL($downloadurl) {
global $adodb;
$adodb->Execute('UPDATE Track SET downloadurl=' . $adodb->qstr($downloadurl) .
' WHERE artist_name=' . $adodb->qstr($this->artist_name) . ' AND ' .
' name=' . $adodb->qstr($this->name));
$this->clearCache();
}
/**
* Sets the license
*
* @param string $license A license URL
*/
function setLicense($license) {
global $adodb;
$streamable = 0;
if(is_free_license($license)) {
$streamable = 1;
}
$adodb->Execute('UPDATE Track SET license=' . $adodb->qstr($license) . ', streamable=' . $streamable .
' WHERE artist_name=' . $adodb->qstr($this->artist_name) . ' AND ' .
' name=' . $adodb->qstr($this->name));
if($streamable) {
$adodb->Execute('UPDATE Artist SET streamable=1 WHERE name=' . $adodb->qstr($this->artist_name));
$artist = new Artist($this->artist_name);
$artist->clearCache();
}
$this->clearCache();
}
/**
*
* @return An int indicating the number of times this track has been played
......@@ -179,6 +239,10 @@ class Track {
return Server::getTrackURL($this->artist_name, $this->album_name, $this->name);
}
function getEditURL() {
return Server::getTrackEditURL($this->artist_name, $this->album_name, $this->name);
}
/**
* Retrieve the tags for this track.
*
......
......@@ -29,15 +29,31 @@ require_once('utils/licenses.php');
$artist = new Artist(urldecode($_GET['artist']));
$album = new Album(urldecode($_GET['album']), $artist->name);
$edit = false;
if(isset($_GET['track'])) {
$edit = true;
$track = new Track(urldecode($_GET['track']), $artist->name);
}
$smarty->assign('artist', $artist);
$smarty->assign('pageheading', '<a href="' . $artist->getURL() . '">' . $artist->name . '</a> &mdash; Add Track');
$smarty->assign('edit', $edit);
if($edit) {
$name = $track->name;
$smarty->assign('name', $name);
$smarty->assign('streaming_url', $track->streamurl);
$smarty->assign('pageheading', '<a href="' . $artist->getURL() . '">' . $artist->name . '</a> &mdash; Edit Track');
} else {
$smarty->assign('pageheading', '<a href="' . $artist->getURL() . '">' . $artist->name . '</a> &mdash; Add Track');
}
if (isset($_POST['submit'])) {
if (empty($_POST['name'])) {
$errors[] = 'A track name must be specified.';
if(!$edit) {
if (empty($_POST['name'])) {
$errors[] = 'A track name must be specified.';
}
$name = $_POST['name'];
}
$name = $_POST['name'];
if (empty($_POST['streaming_url'])) {
$errors[] = 'A streaming URL must be specified.';
......@@ -75,12 +91,17 @@ if (isset($_POST['submit'])) {
if($errors) {
$smarty->assign('errors', $errors);
$smarty->assign('image', $image);
$smarty->assign('name', $name);
$smarty->assign('streaming_url', $streaming_url);
} else {
// If the creation was successful send the user back to the view page
$track = Track::create($name, $artist->name, $album->name, $streaming_url, $streaming_url, $license);
if($edit) {
$track->setStreamURL($streaming_url);
$track->setDownloadURL($streaming_url);
$track->setLicense($license);
} else {
$track = Track::create($name, $artist->name, $album->name, $streaming_url, $streaming_url, $license);
}
header('Location: ' . $track->getURL());
}
}
......
......@@ -56,6 +56,11 @@ foreach($res as &$trow) {
}
}
if(isset($this_user) && $this_user->manages($artist->name)) {
$smarty->assign('edit_link', $track->getEditURL());
}
if($track->duration) {
// Give the duration in MM:SS
$mins = floor($track->duration / 60);
......
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