]> git.mxchange.org Git - friendica.git/blob - mod/fsuggest.php
Merge pull request #3883 from zeroadam/Issue-#3878
[friendica.git] / mod / fsuggest.php
1 <?php
2
3 use Friendica\App;
4 use Friendica\Core\Worker;
5 use Friendica\Database\DBM;
6
7 function fsuggest_post(App $a) {
8
9         if (! local_user()) {
10                 return;
11         }
12
13         if ($a->argc != 2) {
14                 return;
15         }
16
17         $contact_id = intval($a->argv[1]);
18
19         $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
20                 intval($contact_id),
21                 intval(local_user())
22         );
23         if (! DBM::is_result($r)) {
24                 notice( t('Contact not found.') . EOL);
25                 return;
26         }
27         $contact = $r[0];
28
29         $new_contact = intval($_POST['suggest']);
30
31         $hash = random_string();
32
33         $note = escape_tags(trim($_POST['note']));
34
35         if($new_contact) {
36                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
37                         intval($new_contact),
38                         intval(local_user())
39                 );
40                 if (DBM::is_result($r)) {
41
42                         $x = q("INSERT INTO `fsuggest` ( `uid`,`cid`,`name`,`url`,`request`,`photo`,`note`,`created`)
43                                 VALUES ( %d, %d, '%s','%s','%s','%s','%s','%s')",
44                                 intval(local_user()),
45                                 intval($contact_id),
46                                 dbesc($r[0]['name']),
47                                 dbesc($r[0]['url']),
48                                 dbesc($r[0]['request']),
49                                 dbesc($r[0]['photo']),
50                                 dbesc($hash),
51                                 dbesc(datetime_convert())
52                         );
53                         $r = q("SELECT `id` FROM `fsuggest` WHERE `note` = '%s' AND `uid` = %d LIMIT 1",
54                                 dbesc($hash),
55                                 intval(local_user())
56                         );
57                         if (DBM::is_result($r)) {
58                                 $fsuggest_id = $r[0]['id'];
59                                 q("UPDATE `fsuggest` SET `note` = '%s' WHERE `id` = %d AND `uid` = %d",
60                                         dbesc($note),
61                                         intval($fsuggest_id),
62                                         intval(local_user())
63                                 );
64                                 Worker::add(PRIORITY_HIGH, 'notifier', 'suggest', $fsuggest_id);
65                         }
66
67                         info( t('Friend suggestion sent.') . EOL);
68                 }
69
70         }
71
72
73 }
74
75
76
77 function fsuggest_content(App $a) {
78
79         require_once('include/acl_selectors.php');
80
81         if (! local_user()) {
82                 notice( t('Permission denied.') . EOL);
83                 return;
84         }
85
86         if($a->argc != 2)
87                 return;
88
89         $contact_id = intval($a->argv[1]);
90
91         $r = q("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( t('Contact not found.') . EOL);
97                 return;
98         }
99         $contact = $r[0];
100
101         $o = '<h3>' . t('Suggest Friends') . '</h3>';
102
103         $o .= '<div id="fsuggest-desc" >' . sprintf( 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 .= contact_selector('suggest','suggest-select', false,
108                 array('size' => 4, 'exclude' => $contact_id, 'networks' => 'DFRN_ONLY', 'single' => true));
109
110
111         $o .= '<div id="fsuggest-submit-wrapper"><input id="fsuggest-submit" type="submit" name="submit" value="' . t('Submit') . '" /></div>';
112         $o .= '</form>';
113
114         return $o;
115 }