]> git.mxchange.org Git - friendica.git/blob - mod/fsuggest.php
Move Composer autoload require out of boot.php
[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
26         $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
27                 intval($contact_id),
28                 intval(local_user())
29         );
30         if (! DBA::isResult($r)) {
31                 notice(L10n::t('Contact not found.') . EOL);
32                 return;
33         }
34         $contact = $r[0];
35
36         $new_contact = intval($_POST['suggest']);
37
38         $hash = Strings::getRandomHex();
39
40         $note = Strings::escapeHtml(trim(defaults($_POST, 'note', '')));
41
42         if ($new_contact) {
43                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
44                         intval($new_contact),
45                         intval(local_user())
46                 );
47                 if (DBA::isResult($r)) {
48                         $x = q("INSERT INTO `fsuggest` ( `uid`,`cid`,`name`,`url`,`request`,`photo`,`note`,`created`)
49                                 VALUES ( %d, %d, '%s','%s','%s','%s','%s','%s')",
50                                 intval(local_user()),
51                                 intval($contact_id),
52                                 DBA::escape($r[0]['name']),
53                                 DBA::escape($r[0]['url']),
54                                 DBA::escape($r[0]['request']),
55                                 DBA::escape($r[0]['photo']),
56                                 DBA::escape($hash),
57                                 DBA::escape(DateTimeFormat::utcNow())
58                         );
59                         $r = q("SELECT `id` FROM `fsuggest` WHERE `note` = '%s' AND `uid` = %d LIMIT 1",
60                                 DBA::escape($hash),
61                                 intval(local_user())
62                         );
63                         if (DBA::isResult($r)) {
64                                 $fsuggest_id = $r[0]['id'];
65                                 q("UPDATE `fsuggest` SET `note` = '%s' WHERE `id` = %d AND `uid` = %d",
66                                         DBA::escape($note),
67                                         intval($fsuggest_id),
68                                         intval(local_user())
69                                 );
70                                 Worker::add(PRIORITY_HIGH, 'Notifier', 'suggest', $fsuggest_id);
71                         }
72
73                         info(L10n::t('Friend suggestion sent.') . EOL);
74                 }
75         }
76 }
77
78 function fsuggest_content(App $a)
79 {
80         if (! local_user()) {
81                 notice(L10n::t('Permission denied.') . EOL);
82                 return;
83         }
84
85         if ($a->argc != 2) {
86                 return;
87         }
88
89         $contact_id = intval($a->argv[1]);
90
91         $r = q(
92                 "SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
93                 intval($contact_id),
94                 intval(local_user())
95         );
96         if (! DBA::isResult($r)) {
97                 notice(L10n::t('Contact not found.') . EOL);
98                 return;
99         }
100         $contact = $r[0];
101
102         $o = '<h3>' . L10n::t('Suggest Friends') . '</h3>';
103
104         $o .= '<div id="fsuggest-desc" >' . L10n::t('Suggest a friend for %s', $contact['name']) . '</div>';
105
106         $o .= '<form id="fsuggest-form" action="fsuggest/' . $contact_id . '" method="post" >';
107
108         $o .= ACL::getSuggestContactSelectHTML(
109                 'suggest',
110                 'suggest-select',
111                 ['size' => 4, 'exclude' => $contact_id, 'networks' => 'DFRN_ONLY', 'single' => true]
112         );
113
114
115         $o .= '<div id="fsuggest-submit-wrapper"><input id="fsuggest-submit" type="submit" name="submit" value="' . L10n::t('Submit') . '" /></div>';
116         $o .= '</form>';
117
118         return $o;
119 }