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 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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->prepare_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. $DB->exec_prepared_query();
  28. if (!$DB->has_results()) {
  29. echo json_encode(array('status' => 'error', 'response' => 'Not on friend list.'));
  30. error();
  31. }
  32. $Type = strtolower($Type);
  33. $Link = '';
  34. // "a" vs "an", english language is so confusing.
  35. // https://en.wikipedia.org/wiki/English_articles#Distinction_between_a_and_an
  36. $Article = 'a';
  37. switch ($Type) {
  38. case 'torrent':
  39. $Link = "torrents.php?id=$ID";
  40. $DB->query("
  41. SELECT
  42. `title`
  43. FROM
  44. `torrents_group`
  45. WHERE
  46. `id` = '$ID'
  47. ");
  48. break;
  49. case 'artist':
  50. $Article = 'an';
  51. $Link = "artist.php?id=$ID";
  52. $DB->query("
  53. SELECT
  54. `Name`
  55. FROM
  56. `artists_group`
  57. WHERE
  58. `ArtistID` = '$ID'
  59. ");
  60. break;
  61. case 'collage':
  62. $Link = "collages.php?id=$ID";
  63. $DB->query("
  64. SELECT
  65. `Name`
  66. FROM
  67. `collages`
  68. WHERE
  69. `ID` = '$ID'
  70. ");
  71. break;
  72. default:
  73. break;
  74. }
  75. list($Name) = $DB->next_record();
  76. $Subject = $LoggedUser['Username'] . " recommended you $Article $Type!";
  77. $Body = $LoggedUser['Username'] . " recommended you the $Type [url=".site_url()."$Link]$Name".'[/url].';
  78. if (!empty($Note)) {
  79. $Body = "$Body\n\n$Note";
  80. }
  81. Misc::send_pm($FriendID, $LoggedUser['ID'], $Subject, $Body);
  82. echo json_encode(array('status' => 'success', 'response' => 'Sent!'));
  83. die();