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