BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

add_alias.php 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. #declare(strict_types=1);
  3. authorize();
  4. if (!check_perms('torrents_edit')) {
  5. error(403);
  6. }
  7. $ArtistID = $_POST['artistid'];
  8. $Redirect = $_POST['redirect'];
  9. $AliasName = Artists::normalise_artist_name($_POST['name']);
  10. $DBAliasName = db_string($AliasName);
  11. if (!$Redirect) {
  12. $Redirect = 0;
  13. }
  14. if (!is_number($ArtistID) || !($Redirect === 0 || is_number($Redirect)) || !$ArtistID) {
  15. error(0);
  16. }
  17. if ($AliasName == '') {
  18. error('Blank artist name.');
  19. }
  20. /*
  21. * In the case of foo, who released an album before changing his name to bar and releasing another
  22. * the field shared to make them appear on the same artist page is the ArtistID
  23. * 1. For a normal artist, there'll be one entry, with the ArtistID, the same name as the artist and a 0 redirect
  24. * 2. For Celine Dion (C�line Dion), there's two, same ArtistID, diff Names, one has a redirect to the alias of the first
  25. * 3. For foo, there's two, same ArtistID, diff names, no redirect
  26. */
  27. $DB->query("
  28. SELECT AliasID, ArtistID, Name, Redirect
  29. FROM artists_alias
  30. WHERE Name = '$DBAliasName'");
  31. if ($DB->has_results()) {
  32. while (list($CloneAliasID, $CloneArtistID, $CloneAliasName, $CloneRedirect) = $DB->next_record(MYSQLI_NUM, false)) {
  33. if (!strcasecmp($CloneAliasName, $AliasName)) {
  34. break;
  35. }
  36. }
  37. if ($CloneAliasID) {
  38. if ($ArtistID == $CloneArtistID && $Redirect == 0) {
  39. if ($CloneRedirect != 0) {
  40. $DB->query("
  41. UPDATE artists_alias
  42. SET ArtistID = '$ArtistID', Redirect = 0
  43. WHERE AliasID = '$CloneAliasID'");
  44. Misc::write_log("Redirection for the alias $CloneAliasID ($DBAliasName) for the artist $ArtistID was removed by user $LoggedUser[ID] ($LoggedUser[Username])");
  45. } else {
  46. error('No changes were made as the target alias did not redirect anywhere.');
  47. }
  48. } else {
  49. error('An alias by that name already exists <a href="artist.php?id='.$CloneArtistID.'">here</a>. You can try renaming that artist to this one.');
  50. }
  51. }
  52. }
  53. if (!$CloneAliasID) {
  54. if ($Redirect) {
  55. $DB->query("
  56. SELECT ArtistID, Redirect
  57. FROM artists_alias
  58. WHERE AliasID = $Redirect");
  59. if (!$DB->has_results()) {
  60. error('Cannot redirect to a nonexistent artist alias.');
  61. }
  62. list($FoundArtistID, $FoundRedirect) = $DB->next_record();
  63. if ($ArtistID != $FoundArtistID) {
  64. error('Redirection must target an alias for the current artist.');
  65. }
  66. if ($FoundRedirect != 0) {
  67. $Redirect = $FoundRedirect;
  68. }
  69. }
  70. $DB->query("
  71. INSERT INTO artists_alias
  72. (ArtistID, Name, Redirect, UserID)
  73. VALUES
  74. ($ArtistID, '$DBAliasName', $Redirect, ".$LoggedUser['ID'].')');
  75. $AliasID = $DB->inserted_id();
  76. $DB->query("
  77. SELECT Name
  78. FROM artists_group
  79. WHERE ArtistID = $ArtistID");
  80. list($ArtistName) = $DB->next_record(MYSQLI_NUM, false);
  81. Misc::write_log("The alias $AliasID ($DBAliasName) was added to the artist $ArtistID (".db_string($ArtistName).') by user '.$LoggedUser['ID'].' ('.$LoggedUser['Username'].')');
  82. }
  83. header('Location: '.$_SERVER['HTTP_REFERER']);