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