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