Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
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.

96 lines
2.4 KiB

  1. <?php
  2. /**
  3. * @file mod/fsuggest.php
  4. */
  5. use Friendica\App;
  6. use Friendica\Core\ACL;
  7. use Friendica\Core\L10n;
  8. use Friendica\Core\Worker;
  9. use Friendica\Database\DBA;
  10. use Friendica\Util\DateTimeFormat;
  11. use Friendica\Util\Strings;
  12. use Friendica\Worker\Delivery;
  13. function fsuggest_post(App $a)
  14. {
  15. if (!local_user()) {
  16. return;
  17. }
  18. if ($a->argc != 2) {
  19. return;
  20. }
  21. $contact_id = intval($a->argv[1]);
  22. if (empty($contact_id)) {
  23. return;
  24. }
  25. // We do query the "uid" as well to ensure that it is our contact
  26. if (!DBA::exists('contact', ['id' => $contact_id, 'uid' => local_user()])) {
  27. notice(L10n::t('Contact not found.') . EOL);
  28. return;
  29. }
  30. $suggest_contact_id = intval($_POST['suggest']);
  31. if (empty($suggest_contact_id)) {
  32. return;
  33. }
  34. // We do query the "uid" as well to ensure that it is our contact
  35. $contact = DBA::selectFirst('contact', ['name', 'url', 'request', 'avatar'], ['id' => $suggest_contact_id, 'uid' => local_user()]);
  36. if (!DBA::isResult($contact)) {
  37. notice(L10n::t('Suggested contact not found.') . EOL);
  38. return;
  39. }
  40. $note = Strings::escapeHtml(trim(defaults($_POST, 'note', '')));
  41. $fields = ['uid' => local_user(),'cid' => $contact_id, 'name' => $contact['name'],
  42. 'url' => $contact['url'], 'request' => $contact['request'],
  43. 'photo' => $contact['avatar'], 'note' => $note, 'created' => DateTimeFormat::utcNow()];
  44. DBA::insert('fsuggest', $fields);
  45. Worker::add(PRIORITY_HIGH, 'Notifier', Delivery::SUGGESTION, DBA::lastInsertId());
  46. info(L10n::t('Friend suggestion sent.') . EOL);
  47. }
  48. function fsuggest_content(App $a)
  49. {
  50. if (! local_user()) {
  51. notice(L10n::t('Permission denied.') . EOL);
  52. return;
  53. }
  54. if ($a->argc != 2) {
  55. return;
  56. }
  57. $contact_id = intval($a->argv[1]);
  58. $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
  59. if (! DBA::isResult($contact)) {
  60. notice(L10n::t('Contact not found.') . EOL);
  61. return;
  62. }
  63. $o = '<h3>' . L10n::t('Suggest Friends') . '</h3>';
  64. $o .= '<div id="fsuggest-desc" >' . L10n::t('Suggest a friend for %s', $contact['name']) . '</div>';
  65. $o .= '<form id="fsuggest-form" action="fsuggest/' . $contact_id . '" method="post" >';
  66. $o .= ACL::getSuggestContactSelectHTML(
  67. 'suggest',
  68. 'suggest-select',
  69. ['size' => 4, 'exclude' => $contact_id, 'networks' => 'DFRN_ONLY', 'single' => true]
  70. );
  71. $o .= '<div id="fsuggest-submit-wrapper"><input id="fsuggest-submit" type="submit" name="submit" value="' . L10n::t('Submit') . '" /></div>';
  72. $o .= '</form>';
  73. return $o;
  74. }