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