git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

artist-manage.php 2.74 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
<?php

/* GNU FM -- a free network service for sharing your music listening habits

   Copyright (C) 2009 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/sanitize.php');
require_once('data/Server.php');
require_once('data/TagCloud.php');

try {
29
	$artist = new Artist($_GET['artist']);
30
} catch (Exception $e) {
31
	displayError("Artist not found", "The artist {$_GET['artist']} was not found in the database.");
32 33
}

34
if (!isset($this_user) || !$this_user->manages($artist->name)) {
35
	displayError("Permission denied", "You don't have permission to edit this artist's details.");
36 37
}

38 39
if (isset($_POST['submit'])) {
	$artist->setBiographySummary($_POST['bio_summary']);
40
	$artist->setBiography($_POST['bio_content']);
41
	if (!empty($_POST['homepage']) && !preg_match('/^[a-z0-9\+\.\-]+\:/i', $_POST['homepage'])) {
42
		$errors[] = 'Home page must be a valid URL';
43
	} else if (!empty($_POST['homepage']) && preg_match('/\s/', $_POST['homepage'])) {
44 45 46 47
		$errors[] = 'Home page must be a URL, as such it cannot contain whitespace.';
	} else {
		$artist->setHomepage($_POST['homepage']);
	}
48 49 50

	if (!empty($_POST['image']) && !preg_match('/^[a-z0-9\+\.\-]+\:/i', $_POST['image'])) {
		$errors[] = 'Image must be a valid URL';
51
	} else if (!empty($_POST['image']) && preg_match('/\s/', $_POST['image'])) {
52 53 54 55 56
		$errors[] = 'Image must be a URL, as such it cannot contain whitespace.';
	} else {
		$artist->setImage($_POST['image']);
	}

57
	$artist->setFlattr($_POST['flattr_uid']);
58 59

	if ($errors) {
60 61 62 63 64
		$smarty->assign('errors', $errors);
	} else {
		// If the editing was successful send the user back to the view page
		header('Location: ' . $artist->getURL());
	}
65 66
}

67 68 69
$smarty->assign('name', $artist->name);
$smarty->assign('id', $artist->id);
$smarty->assign('bio_summary', $artist->bio_summary);
70
$smarty->assign('bio_content', $artist->bio_content);
71
$smarty->assign('homepage', $artist->homepage);
72
$smarty->assign('image', $artist->image_medium);
73
$smarty->assign('flattr_uid', $artist->flattr_uid);
74
$smarty->assign('pageheading', 'Managing ' . $artist->name);
75

76
$smarty->display('artist-manage.tpl');