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