Commit 6a82fe3d authored by Mike Sheldon's avatar Mike Sheldon

Make it possible to edit albums

parent e9fc3ed1
......@@ -16,6 +16,7 @@ RewriteRule ^artist/([^/]+)/album/([^/]+)/track/([^/]+)/edit/?$ track-add.php?ar
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/([^/]+)/edit/?$ album-add.php?artist=$1&album=$2 [NC,QSA]
RewriteRule ^artist/([^/]+)/album/([^/]+)/?$ album.php?artist=$1&album=$2 [NC,QSA]
RewriteRule ^artist/([^/]+)/?$ artist.php?artist=$1 [NC,QSA]
RewriteRule ^artist/([^/]+)/manage/?$ artist-manage.php?artist=$1 [NC,QSA]
......
......@@ -39,14 +39,31 @@ if (!isset($this_user) || !$this_user->manages($artist->name)) {
die();
}
$edit = false;
if (isset($_GET['album'])) {
$edit = true;
$album = new Album($_GET['album'], $artist->name);
}
$smarty->assign('artist', $artist);
$smarty->assign('pageheading', '<a href="' . $artist->getURL() . '">' . $artist->name . '</a> &mdash; Add Album');
$smarty->assign('edit', $edit);
if ($edit) {
$name = $album->name;
$smarty->assign('name', $name);
$smarty->assign('image', $album->image);
$smarty->assign('pageheading', '<a href="' . $artist->getURL() . '">' . $artist->name . '</a> &mdash; Edit Album');
} else {
$smarty->assign('pageheading', '<a href="' . $artist->getURL() . '">' . $artist->name . '</a> &mdash; Add Album');
}
if (isset($_POST['submit'])) {
if (empty($_POST['name'])) {
$errors[] = 'An album name must be specified.';
if(!$edit) {
if (empty($_POST['name'])) {
$errors[] = 'An album name must be specified.';
}
$name = $_POST['name'];
}
if (empty($_POST['image'])) {
......@@ -64,8 +81,12 @@ if (isset($_POST['submit'])) {
$smarty->assign('image', $image);
$smarty->assign('name', $_POST['name']);
} else {
if($edit) {
$album->setImage($image);
} else {
$album = Album::create($name, $artist->name, $image);
}
// If the creation was successful send the user back to the view page
$album = Album::create($_POST['name'], $artist->name, $image);
header('Location: ' . $album->getURL());
}
}
......
......@@ -35,6 +35,10 @@ try {
die();
}
if (isset($this_user) && $this_user->manages($artist->name)) {
$smarty->assign('edit_link', $album->getEditURL());
}
$smarty->assign('name', $album->name);
$smarty->assign('id', $album->id);
$smarty->assign('artist', $artist);
......
......@@ -46,10 +46,10 @@ class Album {
function __construct($name, $artist) {
global $adodb;
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
$r = $adodb->CacheGetRow(1200,
'SELECT name, artist_name, mbid, image, releasedate FROM Album WHERE '
$this->query = 'SELECT name, artist_name, mbid, image, releasedate FROM Album WHERE '
. 'lower(name) = lower(' . $adodb->qstr($name) . ') AND '
. 'lower(artist_name) = lower(' . $adodb->qstr($artist) . ')');
. 'lower(artist_name) = lower(' . $adodb->qstr($artist) . ')';
$r = $adodb->CacheGetRow(1200, $this->query);
if (!$r) {
$this->name = 'No such album: ' . $name;
} else {
......@@ -107,6 +107,14 @@ class Album {
$adodb->CacheFlush($this->track_query);
}
/**
* Clear the cache of the album information
*/
function clearCache() {
global $adodb;
$adodb->CacheFlush($this->query);
}
function getPlayCount() {
global $adodb;
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
......@@ -198,6 +206,23 @@ class Album {
}
}
/**
* Set the cover art for this artist.
*
* @param string $image The URL of the image to use.
*/
function setImage($image) {
global $adodb;
$adodb->Execute('UPDATE Album SET image=' . $adodb->qstr($image)
. ' WHERE artist_name = ' . $adodb->qstr($this->artist_name)
. ' AND name = ' . $adodb->qstr($this->name));
$this->clearCache();
}
function getEditURL() {
return Server::getAlbumEditURL($this->artist_name, $this->name);
}
/**
* Return Album Art URL from Wikipedia
* @param string Album
......
......@@ -416,6 +416,15 @@ class Server {
}
}
static function getAlbumEditURL($artist, $album) {
global $friendly_urls, $base_url;
if ($friendly_urls) {
return $base_url . '/artist/' . rewrite_encode($artist) . '/album/' . rewrite_encode($album) . '/edit';
} else {
return $base_url . '/album-add.php?artist=' . urlencode($artist) . '&album=' . urlencode($album);
}
}
static function getTagURL($tag) {
global $friendly_urls, $base_url;
if ($friendly_urls) {
......
......@@ -14,14 +14,18 @@
<form action='' method='post'>
<div><h3><label for='name'>{t}Album Name{/t}</h3>
<div class='formHelp'>{t}The name of the album{/t}</div>
<input type='text' name='name' id='name' value='{$name|escape:'htmlall'}' />
<input type='text' name='name' id='name' {if $edit}disabled{/if} value='{$name|escape:'htmlall'}' />
</div>
<div><h3><label for='image'>{t}Cover Image{/t}</h3>
<div class='formHelp'>{t}Address linking to the album's cover image{/t}</div>
<input type='text' name='image' id='image' value='{$image|escape:'htmlall'}' />
</div>
<br />
<p><input type='submit' name='submit' value='{t}Create Album{/t}' /></p>
{if $edit}
<p><input type='submit' name='submit' value='{t}Edit Album{/t}' /></p>
{else}
<p><input type='submit' name='submit' value='{t}Create Album{/t}' /></p>
{/if}
</form>
</div>
</div>
......
......@@ -5,5 +5,6 @@
</span>
&#8212;
<span class="album" property="dc:title" rel="foaf:page" rev="foaf:primaryTopic" resource="">{$name}</span>
{if $edit_link}<a href="{$edit_link}"><small>[{t}Edit{/t}]</small></a>{/if}
</h2>
......@@ -50,7 +50,6 @@ 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