3 require_once('include/Contact.php');
4 require_once('include/socgraph.php');
6 function contacts_init(&$a) {
12 if(($a->argc == 2) && intval($a->argv[1])) {
13 $contact_id = intval($a->argv[1]);
14 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
23 require_once('include/group.php');
24 require_once('include/contact_widgets.php');
26 if(! x($a->page,'aside'))
27 $a->page['aside'] = '';
30 $a->data['contact'] = $r[0];
31 $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array(
32 '$name' => $a->data['contact']['name'],
33 '$photo' => $a->data['contact']['photo']
39 $follow_widget = follow_widget();
42 $groups_widget .= group_side('contacts','group',false,0,$contact_id);
43 $findpeople_widget .= findpeople_widget();
44 $networks_widget .= networks_widget('contacts',$_GET['nets']);
45 $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"),array(
46 '$vcard_widget' => $vcard_widget,
47 '$follow_widget' => $follow_widget,
48 '$groups_widget' => $groups_widget,
49 '$findpeople_widget' => $findpeople_widget,
50 '$networks_widget' => $networks_widget
53 $base = $a->get_baseurl();
54 $tpl = get_markup_template("contacts-head.tpl");
55 $a->page['htmlhead'] .= replace_macros($tpl,array(
56 '$baseurl' => $a->get_baseurl(true),
60 $tpl = get_markup_template("contacts-end.tpl");
61 $a->page['end'] .= replace_macros($tpl,array(
62 '$baseurl' => $a->get_baseurl(true),
69 function contacts_post(&$a) {
74 $contact_id = intval($a->argv[1]);
78 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
83 if(! count($orig_record)) {
84 notice( t('Could not access contact record.') . EOL);
85 goaway($a->get_baseurl(true) . '/contacts');
89 call_hooks('contact_edit_post', $_POST);
91 $profile_id = intval($_POST['profile-assign']);
93 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
98 notice( t('Could not locate selected profile.') . EOL);
103 $hidden = intval($_POST['hidden']);
105 $priority = intval($_POST['poll']);
106 if($priority > 5 || $priority < 0)
109 $info = fix_mce_lf(escape_tags(trim($_POST['info'])));
111 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
112 `hidden` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
121 info( t('Contact updated.') . EOL);
123 notice( t('Failed to update contact record.') . EOL);
125 $r = q("select * from contact where id = %d and uid = %d limit 1",
130 $a->data['contact'] = $r[0];
138 function contacts_content(&$a) {
142 nav_set_selected('contacts');
146 notice( t('Permission denied.') . EOL);
152 $contact_id = intval($a->argv[1]);
158 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
163 if(! count($orig_record)) {
164 notice( t('Could not access contact record.') . EOL);
165 goaway($a->get_baseurl(true) . '/contacts');
166 return; // NOTREACHED
169 if($cmd === 'update') {
171 // pull feed and consume it, which should subscribe to the hub.
172 proc_run('php',"include/poller.php","$contact_id");
173 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
177 if($cmd === 'block') {
178 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
179 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
185 //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
186 info( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
188 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
189 return; // NOTREACHED
192 if($cmd === 'ignore') {
193 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
194 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
200 info( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
202 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
203 return; // NOTREACHED
207 if($cmd === 'archive') {
208 $archived = (($orig_record[0]['archive']) ? 0 : 1);
209 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
215 q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
218 //notice( t('Contact has been ') . (($archived) ? t('archived') : t('unarchived')) . EOL );
219 info( (($archived) ? t('Contact has been archived') : t('Contact has been unarchived')) . EOL );
221 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
222 return; // NOTREACHED
225 if($cmd === 'drop') {
227 require_once('include/Contact.php');
229 terminate_friendship($a->user,$a->contact,$orig_record[0]);
231 contact_remove($orig_record[0]['id']);
232 info( t('Contact has been removed.') . EOL );
233 if(x($_SESSION,'return_url'))
234 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
236 goaway($a->get_baseurl(true) . '/contacts');
237 return; // NOTREACHED
241 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
243 $contact_id = $a->data['contact']['id'];
244 $contact = $a->data['contact'];
246 $editselect = 'exact';
247 if(intval(get_pconfig(local_user(),'system','plaintext')))
248 $editselect = 'none';
250 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
251 '$baseurl' => $a->get_baseurl(true),
252 '$editselect' => $editselect,
254 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
255 '$baseurl' => $a->get_baseurl(true),
256 '$editselect' => $editselect,
259 require_once('include/contact_selectors.php');
261 $tpl = get_markup_template("contact_edit.tpl");
263 switch($contact['rel']) {
264 case CONTACT_IS_FRIEND:
265 $dir_icon = 'images/lrarrow.gif';
266 $relation_text = t('You are mutual friends with %s');
268 case CONTACT_IS_FOLLOWER;
269 $dir_icon = 'images/larrow.gif';
270 $relation_text = t('You are sharing with %s');
273 case CONTACT_IS_SHARING;
274 $dir_icon = 'images/rarrow.gif';
275 $relation_text = t('%s is sharing with you');
281 $relation_text = sprintf($relation_text,$contact['name']);
283 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
284 $url = "redir/{$contact['id']}";
285 $sparkle = ' class="sparkle" ';
288 $url = $contact['url'];
292 $insecure = t('Private communications are not available for this contact.');
294 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
296 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
298 if($contact['last-update'] !== '0000-00-00 00:00:00')
299 $last_update .= ' ' . (($contact['last-update'] == $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
301 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
303 $poll_enabled = (($contact['network'] !== NETWORK_DIASPORA) ? true : false);
305 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network']));
307 $common = count_common_friends(local_user(),$contact['id']);
308 $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
310 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
312 $x = count_all_friends(local_user(), $contact['id']);
313 $all_friends = (($x) ? t('View all contacts') : '');
318 'label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
319 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/block',
321 'title' => t('Toggle Blocked status'),
324 'label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
325 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/ignore',
327 'title' => t('Toggle Ignored status'),
331 'label' => (($contact['archive']) ? t('Unarchive') : t('Archive') ),
332 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/archive',
334 'title' => t('Toggle Archive status'),
337 'label' => t('Repair'),
338 'url' => $a->get_baseurl(true) . '/crepair/' . $contact_id,
340 'title' => t('Advanced Contact Settings'),
343 $tab_tpl = get_markup_template('common_tabs.tpl');
344 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
346 $lost_contact = (($contact['archive'] && $contact['term-date'] != '0000-00-00 00:00:00' && $contact['term-date'] < datetime_convert('','','now')) ? t('Communications lost with this contact!') : '');
348 $o .= replace_macros($tpl,array(
349 '$header' => t('Contact Editor'),
350 '$tab_str' => $tab_str,
351 '$submit' => t('Submit'),
352 '$lbl_vis1' => t('Profile Visibility'),
353 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
354 '$lbl_info1' => t('Contact Information / Notes'),
355 '$infedit' => t('Edit contact notes'),
356 '$common_text' => $common_text,
357 '$common_link' => $a->get_baseurl(true) . '/common/loc/' . local_user() . '/' . $contact['id'],
358 '$all_friends' => $all_friends,
359 '$relation_text' => $relation_text,
360 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
361 '$blockunblock' => t('Block/Unblock contact'),
362 '$ignorecont' => t('Ignore contact'),
363 '$lblcrepair' => t("Repair URL settings"),
364 '$lblrecent' => t('View conversations'),
365 '$lblsuggest' => $lblsuggest,
366 '$delete' => t('Delete contact'),
367 '$nettype' => $nettype,
368 '$poll_interval' => contact_poll_interval($contact['priority'],(! $poll_enabled)),
369 '$poll_enabled' => $poll_enabled,
370 '$lastupdtext' => t('Last update:'),
371 '$lost_contact' => $lost_contact,
372 '$updpub' => t('Update public posts'),
373 '$last_update' => $last_update,
374 '$udnow' => t('Update now'),
375 '$profile_select' => contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false)),
376 '$contact_id' => $contact['id'],
377 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
378 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
379 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
380 '$info' => $contact['info'],
381 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
382 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
383 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
384 '$hidden' => array('hidden', t('Hide this contact from others'), ($contact['hidden'] == 1), t('Replies/likes to your public posts <strong>may</strong> still be visible')),
385 '$photo' => $contact['photo'],
386 '$name' => $contact['name'],
387 '$dir_icon' => $dir_icon,
388 '$alt_text' => $alt_text,
389 '$sparkle' => $sparkle,
394 $arr = array('contact' => $contact,'output' => $o);
396 call_hooks('contact_edit', $arr);
398 return $arr['output'];
407 $_SESSION['return_url'] = $a->query_string;
409 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
413 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
414 $sql_extra = " AND `blocked` = 1 ";
417 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
418 $sql_extra = " AND `hidden` = 1 ";
421 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
422 $sql_extra = " AND `readonly` = 1 ";
425 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
426 $sql_extra = " AND `archive` = 1 ";
430 $sql_extra = " AND `blocked` = 0 ";
432 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
433 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
437 'label' => t('Suggestions'),
438 'url' => $a->get_baseurl(true) . '/suggest',
440 'title' => t('Suggest potential friends'),
443 'label' => t('All Contacts'),
444 'url' => $a->get_baseurl(true) . '/contacts/all',
445 'sel' => ($all) ? 'active' : '',
446 'title' => t('Show all contacts'),
449 'label' => t('Unblocked'),
450 'url' => $a->get_baseurl(true) . '/contacts',
451 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
452 'title' => t('Only show unblocked contacts'),
456 'label' => t('Blocked'),
457 'url' => $a->get_baseurl(true) . '/contacts/blocked',
458 'sel' => ($blocked) ? 'active' : '',
459 'title' => t('Only show blocked contacts'),
463 'label' => t('Ignored'),
464 'url' => $a->get_baseurl(true) . '/contacts/ignored',
465 'sel' => ($ignored) ? 'active' : '',
466 'title' => t('Only show ignored contacts'),
470 'label' => t('Archived'),
471 'url' => $a->get_baseurl(true) . '/contacts/archived',
472 'sel' => ($archived) ? 'active' : '',
473 'title' => t('Only show archived contacts'),
477 'label' => t('Hidden'),
478 'url' => $a->get_baseurl(true) . '/contacts/hidden',
479 'sel' => ($hidden) ? 'active' : '',
480 'title' => t('Only show hidden contacts'),
485 $tab_tpl = get_markup_template('common_tabs.tpl');
486 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
492 $search_hdr = $search;
493 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
496 $sql_extra .= (($searching) ? " AND `name` REGEXP '$search_txt' " : "");
499 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
501 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
504 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
505 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
506 intval($_SESSION['uid']));
508 $a->set_pager_total($r[0]['total']);
509 $total = $r[0]['total'];
513 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
514 intval($_SESSION['uid']),
515 intval($a->pager['start']),
516 intval($a->pager['itemspage'])
526 case CONTACT_IS_FRIEND:
527 $dir_icon = 'images/lrarrow.gif';
528 $alt_text = t('Mutual Friendship');
530 case CONTACT_IS_FOLLOWER;
531 $dir_icon = 'images/larrow.gif';
532 $alt_text = t('is a fan of yours');
534 case CONTACT_IS_SHARING;
535 $dir_icon = 'images/rarrow.gif';
536 $alt_text = t('you are a fan of');
541 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
542 $url = "redir/{$rr['id']}";
543 $sparkle = ' class="sparkle" ';
552 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
553 'edit_hover' => t('Edit contact'),
554 'photo_menu' => contact_photo_menu($rr),
556 'alt_text' => $alt_text,
557 'dir_icon' => $dir_icon,
558 'thumb' => $rr['thumb'],
559 'name' => $rr['name'],
560 'username' => $rr['name'],
561 'sparkle' => $sparkle,
562 'itemurl' => $rr['url'],
564 'network' => network_to_name($rr['network']),
572 $tpl = get_markup_template("contacts-template.tpl");
573 $o .= replace_macros($tpl,array(
574 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
577 '$search' => $search_hdr,
578 '$desc' => t('Search your contacts'),
579 '$finding' => (($searching) ? t('Finding: ') . "'" . $search . "'" : ""),
580 '$submit' => t('Find'),
582 '$contacts' => $contacts,
583 '$paginate' => paginate($a),