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.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 f.FriendID, u.Username
  14. FROM friends AS f
  15. RIGHT JOIN users_enable_recommendations AS r
  16. ON r.ID = f.FriendID AND r.Enable = 1
  17. RIGHT JOIN users_main AS u
  18. ON u.ID = f.FriendID
  19. WHERE f.UserID = '$LoggedUser[ID]'
  20. AND f.FriendID = '$FriendID'");
  21. if (!$DB->has_results()) {
  22. echo json_encode(array('status' => 'error', 'response' => 'Not on friend list.'));
  23. error();
  24. }
  25. $Type = strtolower($Type);
  26. $Link = '';
  27. // "a" vs "an", english language is so confusing.
  28. // https://en.wikipedia.org/wiki/English_articles#Distinction_between_a_and_an
  29. $Article = 'a';
  30. switch ($Type) {
  31. case 'torrent':
  32. $Link = "torrents.php?id=$ID";
  33. $DB->query("
  34. SELECT Name
  35. FROM torrents_group
  36. WHERE ID = '$ID'");
  37. break;
  38. case 'artist':
  39. $Article = 'an';
  40. $Link = "artist.php?id=$ID";
  41. $DB->query("
  42. SELECT Name
  43. FROM artists_group
  44. WHERE ArtistID = '$ID'");
  45. break;
  46. case 'collage':
  47. $Link = "collages.php?id=$ID";
  48. $DB->query("
  49. SELECT Name
  50. FROM collages
  51. WHERE ID = '$ID'");
  52. break;
  53. }
  54. list($Name) = $DB->next_record();
  55. $Subject = $LoggedUser['Username'] . " recommended you $Article $Type!";
  56. $Body = $LoggedUser['Username'] . " recommended you the $Type [url=".site_url()."$Link]$Name".'[/url].';
  57. if (!empty($Note)) {
  58. $Body = "$Body\n\n$Note";
  59. }
  60. Misc::send_pm($FriendID, $LoggedUser['ID'], $Subject, $Body);
  61. echo json_encode(array('status' => 'success', 'response' => 'Sent!'));
  62. die();