]> git.mxchange.org Git - friendica.git/blob - mod/contacts.php
duepuntozero theme
[friendica.git] / mod / contacts.php
1 <?php
2
3 require_once('include/Contact.php');
4
5 function contacts_init(&$a) {
6         require_once('include/group.php');
7         if(! x($a->page,'aside'))
8                 $a->page['aside'] = '';
9         $a->page['aside'] .= group_side();
10
11         if($a->config['register_policy'] != REGISTER_CLOSED)
12                 $a->page['aside'] .= '<div class="side-invite-link-wrapper" id="side-invite-link-wrapper" ><a href="invite" class="side-invite-link" id="side-invite-link">' . t("Invite Friends") . '</a></div>';
13
14         $tpl = load_view_file('view/follow.tpl');
15         $a->page['aside'] .= replace_macros($tpl,array(
16                 '$label' => t('Connect/Follow [profile address]'),
17                 '$hint' => t('Example: bob@example.com, http://example.com/barbara'),
18                 '$follow' => t('Follow')
19         ));
20
21 }
22
23 function contacts_post(&$a) {
24         
25         if(! local_user())
26                 return;
27
28         $contact_id = intval($a->argv[1]);
29         if(! $contact_id)
30                 return;
31
32         $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
33                 intval($contact_id),
34                 intval(local_user())
35         );
36
37         if(! count($orig_record)) {
38                 notice( t('Could not access contact record.') . EOL);
39                 goaway($a->get_baseurl() . '/contacts');
40                 return; // NOTREACHED
41         }
42
43         $profile_id = intval($_POST['profile-assign']);
44         if($profile_id) {
45                 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
46                         intval($profile_id),
47                         intval(local_user())
48                 );
49                 if(! count($r)) {
50                         notice( t('Could not locate selected profile.') . EOL);
51                         return;
52                 }
53         }
54
55
56         $priority = intval($_POST['priority']);
57         if($priority == (-1))
58                 
59         if($priority > 5 || $priority < 0)
60                 $priority = 0;
61
62         $rating = intval($_POST['reputation']);
63         if($rating > 5 || $rating < 0)
64                 $rating = 0;
65
66         $reason = notags(trim($_POST['reason']));
67
68         $info = escape_tags(trim($_POST['info']));
69
70         $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `rating` = %d, `reason` = '%s', `info` = '%s'
71                 WHERE `id` = %d AND `uid` = %d LIMIT 1",
72                 intval($profile_id),
73                 intval($priority),
74                 intval($rating),
75                 dbesc($reason),
76                 dbesc($info),
77                 intval($contact_id),
78                 intval(local_user())
79         );
80         if($r)
81                 notice( t('Contact updated.') . EOL);
82         else
83                 notice( t('Failed to update contact record.') . EOL);
84         return;
85
86 }
87
88
89
90 function contacts_content(&$a) {
91
92         $sort_type = 0;
93         $o = '';
94         $o .= '<script> $(document).ready(function() { $(\'#nav-contacts-link\').addClass(\'nav-selected\'); });</script>';
95
96         $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
97
98         if(! local_user()) {
99                 notice( t('Permission denied.') . EOL);
100                 return;
101         }
102
103         if($a->argc == 3) {
104
105                 $contact_id = intval($a->argv[1]);
106                 if(! $contact_id)
107                         return;
108
109                 $cmd = $a->argv[2];
110
111                 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
112                         intval($contact_id),
113                         intval(local_user())
114                 );
115
116                 if(! count($orig_record)) {
117                         notice( t('Could not access contact record.') . EOL);
118                         goaway($a->get_baseurl() . '/contacts');
119                         return; // NOTREACHED
120                 }
121
122
123                 if($cmd === 'block') {
124                         $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
125                         $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
126                                         intval($blocked),
127                                         intval($contact_id),
128                                         intval(local_user())
129                         );
130                         if($r) {
131                                 notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
132                         }
133                         goaway($a->get_baseurl() . '/contacts/' . $contact_id);
134                         return; // NOTREACHED
135                 }
136
137                 if($cmd === 'ignore') {
138                         $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
139                         $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
140                                         intval($readonly),
141                                         intval($contact_id),
142                                         intval(local_user())
143                         );
144                         if($r) {
145                                 notice( t('Contact has been ') . (($readonly) ? t('ignored') : t('unignored')) . EOL );
146                         }
147                         goaway($a->get_baseurl() . '/contacts/' . $contact_id);
148                         return; // NOTREACHED
149                 }
150
151                 if($cmd === 'drop') {
152
153                         // create an unfollow slap
154
155                         if($orig_record[0]['network'] === 'stat') {
156                                 $tpl = load_view_file('view/follow_slap.tpl');
157                                 $slap = replace_macros($tpl, array(
158                                         '$name' => $a->user['username'],
159                                         '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
160                                         '$photo' => $a->contact['photo'],
161                                         '$thumb' => $a->contact['thumb'],
162                                         '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
163                                         '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(),
164                                         '$title' => '',
165                                         '$type' => 'text',
166                                         '$content' => t('stopped following'),
167                                         '$nick' => $a->user['nickname'],
168                                         '$verb' => ACTIVITY_UNFOLLOW
169                                 ));
170
171                                 if((x($orig_record[0],'notify')) && (strlen($orig_record[0]['notify']))) {
172                                         require_once('include/salmon.php');
173                                         slapper($a->user,$orig_record[0]['notify'],$slap);
174                                 }
175                         }
176
177                         contact_remove($contact_id);
178                         notice( t('Contact has been removed.') . EOL );
179                         goaway($a->get_baseurl() . '/contacts');
180                         return; // NOTREACHED
181                 }
182         }
183
184         if(($a->argc == 2) && intval($a->argv[1])) {
185
186                 $contact_id = intval($a->argv[1]);
187                 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
188                         intval(local_user()),
189                         intval($contact_id)
190                 );
191                 if(! count($r)) {
192                         notice( t('Contact not found.') . EOL);
193                         return;
194                 }
195
196                 $tpl = load_view_file('view/contact_head.tpl');
197                 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
198
199                 require_once('include/contact_selectors.php');
200
201                 $tpl = load_view_file("view/contact_edit.tpl");
202
203                 switch($r[0]['rel']) {
204                         case REL_BUD:
205                                 $dir_icon = 'images/lrarrow.gif';
206                                 $alt_text = t('Mutual Friendship');
207                                 break;
208                         case REL_VIP;
209                                 $dir_icon = 'images/larrow.gif';
210                                 $alt_text = t('is a fan of yours');
211                                 break;
212         
213                         case REL_FAN;
214                                 $dir_icon = 'images/rarrow.gif';
215                                 $alt_text = t('you are a fan of');
216                                 break;
217                         default:
218                                 break;
219                 }
220
221                 if(($r[0]['network'] === 'dfrn') && ($r[0]['rel'])) {
222                         $url = "redir/{$r[0]['id']}";
223                         $sparkle = ' class="sparkle" ';
224                 }
225                 else { 
226                         $url = $r[0]['url'];
227                         $sparkle = '';
228                 }
229
230                 $o .= replace_macros($tpl,array(
231                         '$header' => t('Contact Editor'),
232                         '$visit' => t('Visit $name\'s profile'),
233                         '$blockunblock' => t('Block/Unblock contact'),
234                         '$ignorecont' => t('Ignore contact'),
235                         '$delete' => t('Delete contact'),
236                         '$poll_interval' => contact_poll_interval($r[0]['priority']),
237                         '$lastupdtext' => t('Last updated: '),
238                         '$updpub' => t('Update public posts: '),
239                         '$last_update' => (($r[0]['last-update'] == '0000-00-00 00:00:00') 
240                                 ? t('Never') 
241                                 : datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A')),
242                         '$profile_select' => contact_profile_assign($r[0]['profile-id'],(($r[0]['network'] !== 'dfrn') ? true : false)),
243                         '$contact_id' => $r[0]['id'],
244                         '$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
245                         '$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
246                         '$insecure' => (($r[0]['network'] === 'dfrn') ? '' : load_view_file('view/insecure_net.tpl')),
247                         '$info' => $r[0]['info'],
248                         '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
249                         '$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),
250                         '$rating' => contact_reputation($r[0]['rating']),
251                         '$reason' => $r[0]['reason'],
252                         '$groups' => '', // group_selector(),
253                         '$photo' => $r[0]['photo'],
254                         '$name' => $r[0]['name'],
255                         '$dir_icon' => $dir_icon,
256                         '$alt_text' => $alt_text,
257                         '$sparkle' => $sparkle,
258                         '$url' => $url
259
260                 ));
261
262                 return $o;
263
264         }
265
266
267         if(($a->argc == 2) && ($a->argv[1] === 'all'))
268                 $sql_extra = '';
269         else
270                 $sql_extra = " AND `blocked` = 0 ";
271
272         $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
273
274         $tpl = load_view_file("view/contacts-top.tpl");
275         $o .= replace_macros($tpl,array(
276                 '$header' => t('Contacts'),
277                 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
278                 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
279                 '$search' => $search,
280                 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
281                 '$submit' => t('Find'),
282                 '$cmd' => $a->cmd
283
284
285         )); 
286
287         if($search)
288                 $search = dbesc($search.'*');
289         $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
290
291         $sql_extra2 = ((($sort_type > 0) && ($sort_type <= REL_BUD)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : ''); 
292
293         
294         $r = q("SELECT COUNT(*) AS `total` FROM `contact` 
295                 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
296                 intval($_SESSION['uid']));
297         if(count($r))
298                 $a->set_pager_total($r[0]['total']);
299
300         $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
301                 intval($_SESSION['uid']),
302                 intval($a->pager['start']),
303                 intval($a->pager['itemspage'])
304         );
305
306         if(count($r)) {
307
308                 $tpl = load_view_file("view/contact_template.tpl");
309
310                 foreach($r as $rr) {
311                         if($rr['self'])
312                                 continue;
313
314                         switch($rr['rel']) {
315                                 case REL_BUD:
316                                         $dir_icon = 'images/lrarrow.gif';
317                                         $alt_text = t('Mutual Friendship');
318                                         break;
319                                 case  REL_VIP;
320                                         $dir_icon = 'images/larrow.gif';
321                                         $alt_text = t('is a fan of yours');
322                                         break;
323                                 case REL_FAN;
324                                         $dir_icon = 'images/rarrow.gif';
325                                         $alt_text = t('you are a fan of');
326                                         break;
327                                 default:
328                                         break;
329                         }
330                         if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
331                                 $url = "redir/{$rr['id']}";
332                                 $sparkle = ' class="sparkle" ';
333                         }
334                         else { 
335                                 $url = $rr['url'];
336                                 $sparkle = '';
337                         }
338
339
340                         $o .= replace_macros($tpl, array(
341                                 '$img_hover' => t('Visit ') . $rr['name'] . t('\'s profile'),
342                                 '$edit_hover' => t('Edit contact'),
343                                 '$id' => $rr['id'],
344                                 '$alt_text' => $alt_text,
345                                 '$dir_icon' => $dir_icon,
346                                 '$thumb' => $rr['thumb'], 
347                                 '$name' => $rr['name'],
348                                 '$sparkle' => $sparkle,
349                                 '$url' => $url
350                         ));
351                 }
352                 $o .= '<div id="contact-edit-end"></div>';
353
354         }
355         $o .= paginate($a);
356         return $o;
357 }