artist-manage.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /* GNU FM -- a free network service for sharing your music listening habits
  3. Copyright (C) 2009 Free Software Foundation, Inc
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Affero General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. require_once('database.php');
  16. require_once('templating.php');
  17. require_once('data/sanitize.php');
  18. require_once('data/Server.php');
  19. require_once('data/TagCloud.php');
  20. try {
  21. $artist = new Artist($_GET['artist']);
  22. } catch (Exception $e) {
  23. displayError("Artist not found", "The artist {$_GET['artist']} was not found in the database.");
  24. }
  25. if (!isset($this_user) || !$this_user->manages($artist->name)) {
  26. displayError("Permission denied", "You don't have permission to edit this artist's details.");
  27. }
  28. if (isset($_POST['submit'])) {
  29. $artist->setBiographySummary($_POST['bio_summary']);
  30. $artist->setBiography($_POST['bio_content']);
  31. if (!empty($_POST['homepage']) && !preg_match('/^[a-z0-9\+\.\-]+\:/i', $_POST['homepage'])) {
  32. $errors[] = 'Home page must be a valid URL';
  33. } else if (!empty($_POST['homepage']) && preg_match('/\s/', $_POST['homepage'])) {
  34. $errors[] = 'Home page must be a URL, as such it cannot contain whitespace.';
  35. } else {
  36. $artist->setHomepage($_POST['homepage']);
  37. }
  38. if (!empty($_POST['image']) && !preg_match('/^[a-z0-9\+\.\-]+\:/i', $_POST['image'])) {
  39. $errors[] = 'Image must be a valid URL';
  40. } else if (!empty($_POST['image']) && preg_match('/\s/', $_POST['image'])) {
  41. $errors[] = 'Image must be a URL, as such it cannot contain whitespace.';
  42. } else {
  43. $artist->setImage($_POST['image']);
  44. }
  45. $artist->setFlattr($_POST['flattr_uid']);
  46. if ($errors) {
  47. $smarty->assign('errors', $errors);
  48. } else {
  49. // If the editing was successful send the user back to the view page
  50. header('Location: ' . $artist->getURL());
  51. }
  52. }
  53. $smarty->assign('name', $artist->name);
  54. $smarty->assign('id', $artist->id);
  55. $smarty->assign('bio_summary', $artist->bio_summary);
  56. $smarty->assign('bio_content', $artist->bio_content);
  57. $smarty->assign('homepage', $artist->homepage);
  58. $smarty->assign('image', $artist->image_medium);
  59. $smarty->assign('flattr_uid', $artist->flattr_uid);
  60. $smarty->assign('pageheading', 'Managing ' . $artist->name);
  61. $smarty->display('artist-manage.tpl');