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