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