]> git.mxchange.org Git - friendica.git/blob - mod/fsuggest.php
e84a8bd54d3ad552913984dfaf3e46ff9bdd6ce6
[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
14 function fsuggest_post(App $a)
15 {
16         if (!local_user()) {
17                 return;
18         }
19
20         if ($a->argc != 2) {
21                 return;
22         }
23
24         $contact_id = intval($a->argv[1]);
25         if (empty($contact_id)) {
26                 return;
27         }
28
29         $contact = DBA::selectFirst('contact', ['name', 'url', 'request', 'photo'], ['id' => $contact_id, 'uid' => local_user()]);
30         if (!DBA::isResult($contact)) {
31                 notice(L10n::t('Contact not found.') . EOL);
32                 return;
33         }
34
35         $note = Strings::escapeHtml(trim(defaults($_POST, 'note', '')));
36
37         $new_contact = intval($_POST['suggest']);
38         if (empty($new_contact)) {
39                 return;
40         }
41
42         if (!DBA::exists('contact', ['id' => $new_contact])) {
43                 return;
44         }
45
46         $fields = ['uid' => local_user(),'cid' => $contact_id, 'name' => $contact['name'],
47                 'url' => $contact['url'], 'request' => $contact['request'],
48                 'photo' => $contact['photo'], 'note' => $note, 'created' => DateTimeFormat::utcNow()];
49         DBA::insert('fsuggest', $fields);
50
51         Worker::add(PRIORITY_HIGH, 'Notifier', 'suggest', DBA::lastInsertId());
52
53         info(L10n::t('Friend suggestion sent.') . EOL);
54 }
55
56 function fsuggest_content(App $a)
57 {
58         if (! local_user()) {
59                 notice(L10n::t('Permission denied.') . EOL);
60                 return;
61         }
62
63         if ($a->argc != 2) {
64                 return;
65         }
66
67         $contact_id = intval($a->argv[1]);
68
69         $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user()]);
70         if (! DBA::isResult($contact)) {
71                 notice(L10n::t('Contact not found.') . EOL);
72                 return;
73         }
74
75         $o = '<h3>' . L10n::t('Suggest Friends') . '</h3>';
76
77         $o .= '<div id="fsuggest-desc" >' . L10n::t('Suggest a friend for %s', $contact['name']) . '</div>';
78
79         $o .= '<form id="fsuggest-form" action="fsuggest/' . $contact_id . '" method="post" >';
80
81         $o .= ACL::getSuggestContactSelectHTML(
82                 'suggest',
83                 'suggest-select',
84                 ['size' => 4, 'exclude' => $contact_id, 'networks' => 'DFRN_ONLY', 'single' => true]
85         );
86
87
88         $o .= '<div id="fsuggest-submit-wrapper"><input id="fsuggest-submit" type="submit" name="submit" value="' . L10n::t('Submit') . '" /></div>';
89         $o .= '</form>';
90
91         return $o;
92 }