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