]> git.mxchange.org Git - friendica.git/blob - mod/fsuggest.php
Move Temporal::convert() to DateTimeFormat::convert()
[friendica.git] / mod / fsuggest.php
1 <?php
2 /**
3  * @file mod/fsuggest.php
4  */
5
6 use Friendica\App;
7 use Friendica\Core\L10n;
8 use Friendica\Core\Worker;
9 use Friendica\Database\DBM;
10 use Friendica\Util\DateTimeFormat;
11
12 function fsuggest_post(App $a)
13 {
14         if (! local_user()) {
15                 return;
16         }
17
18         if ($a->argc != 2) {
19                 return;
20         }
21
22         $contact_id = intval($a->argv[1]);
23
24         $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
25                 intval($contact_id),
26                 intval(local_user())
27         );
28         if (! DBM::is_result($r)) {
29                 notice(L10n::t('Contact not found.') . EOL);
30                 return;
31         }
32         $contact = $r[0];
33
34         $new_contact = intval($_POST['suggest']);
35
36         $hash = random_string();
37
38         $note = escape_tags(trim($_POST['note']));
39
40         if ($new_contact) {
41                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
42                         intval($new_contact),
43                         intval(local_user())
44                 );
45                 if (DBM::is_result($r)) {
46                         $x = q("INSERT INTO `fsuggest` ( `uid`,`cid`,`name`,`url`,`request`,`photo`,`note`,`created`)
47                                 VALUES ( %d, %d, '%s','%s','%s','%s','%s','%s')",
48                                 intval(local_user()),
49                                 intval($contact_id),
50                                 dbesc($r[0]['name']),
51                                 dbesc($r[0]['url']),
52                                 dbesc($r[0]['request']),
53                                 dbesc($r[0]['photo']),
54                                 dbesc($hash),
55                                 dbesc(DateTimeFormat::utcNow())
56                         );
57                         $r = q("SELECT `id` FROM `fsuggest` WHERE `note` = '%s' AND `uid` = %d LIMIT 1",
58                                 dbesc($hash),
59                                 intval(local_user())
60                         );
61                         if (DBM::is_result($r)) {
62                                 $fsuggest_id = $r[0]['id'];
63                                 q("UPDATE `fsuggest` SET `note` = '%s' WHERE `id` = %d AND `uid` = %d",
64                                         dbesc($note),
65                                         intval($fsuggest_id),
66                                         intval(local_user())
67                                 );
68                                 Worker::add(PRIORITY_HIGH, 'Notifier', 'suggest', $fsuggest_id);
69                         }
70
71                         info(L10n::t('Friend suggestion sent.') . EOL);
72                 }
73         }
74 }
75
76 function fsuggest_content(App $a)
77 {
78         require_once 'include/acl_selectors.php';
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 (! DBM::is_result($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 .= contact_selector(
109                 'suggest',
110                 'suggest-select',
111                 ['size' => 4, 'exclude' => $contact_id, 'networks' => 'DFRN_ONLY', 'single' => true],
112                 false
113         );
114
115
116         $o .= '<div id="fsuggest-submit-wrapper"><input id="fsuggest-submit" type="submit" name="submit" value="' . L10n::t('Submit') . '" /></div>';
117         $o .= '</form>';
118
119         return $o;
120 }