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.

send_recommendation.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. #declare(strict_types=1);
  3. $FriendID = (int) $_POST['friend'];
  4. $Type = $_POST['type'];
  5. $ID = (int) $_POST['id'];
  6. $Note = $_POST['note'];
  7. if (empty($FriendID) || empty($Type) || empty($ID)) {
  8. echo json_encode(array('status' => 'error', 'response' => 'Error.'));
  9. error();
  10. }
  11. // Make sure the recipient is on your friends list and not some random dude.
  12. $DB->query("
  13. SELECT
  14. f.`FriendID`,
  15. u.`Username`
  16. FROM
  17. `friends` AS f
  18. RIGHT JOIN `users_enable_recommendations` AS r
  19. ON
  20. r.`ID` = f.`FriendID` AND r.`Enable` = 1
  21. RIGHT JOIN `users_main` AS u
  22. ON
  23. u.`ID` = f.`FriendID`
  24. WHERE
  25. f.`UserID` = '$LoggedUser[ID]' AND f.`FriendID` = '$FriendID'
  26. ");
  27. if (!$DB->has_results()) {
  28. echo json_encode(array('status' => 'error', 'response' => 'Not on friend list.'));
  29. error();
  30. }
  31. $Type = strtolower($Type);
  32. $Link = '';
  33. // "a" vs "an", english language is so confusing.
  34. // https://en.wikipedia.org/wiki/English_articles#Distinction_between_a_and_an
  35. $Article = 'a';
  36. switch ($Type) {
  37. case 'torrent':
  38. $Link = "torrents.php?id=$ID";
  39. $DB->query("
  40. SELECT
  41. `title`
  42. FROM
  43. `torrents_group`
  44. WHERE
  45. `id` = '$ID'
  46. ");
  47. break;
  48. case 'artist':
  49. $Article = 'an';
  50. $Link = "artist.php?id=$ID";
  51. $DB->query("
  52. SELECT
  53. `Name`
  54. FROM
  55. `artists_group`
  56. WHERE
  57. `ArtistID` = '$ID'
  58. ");
  59. break;
  60. case 'collage':
  61. $Link = "collages.php?id=$ID";
  62. $DB->query("
  63. SELECT
  64. `Name`
  65. FROM
  66. `collages`
  67. WHERE
  68. `ID` = '$ID'
  69. ");
  70. break;
  71. }
  72. list($Name) = $DB->next_record();
  73. $Subject = $LoggedUser['Username'] . " recommended you $Article $Type!";
  74. $Body = $LoggedUser['Username'] . " recommended you the $Type [url=".site_url()."$Link]$Name".'[/url].';
  75. if (!empty($Note)) {
  76. $Body = "$Body\n\n$Note";
  77. }
  78. Misc::send_pm($FriendID, $LoggedUser['ID'], $Subject, $Body);
  79. echo json_encode(array('status' => 'success', 'response' => 'Sent!'));
  80. die();