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