3 require_once('include/Contact.php');
4 require_once('include/socgraph.php');
5 require_once('include/contact_selectors.php');
6 require_once('mod/proxy.php');
8 function contacts_init(&$a) {
14 if(($a->argc == 2) && intval($a->argv[1])) {
15 $contact_id = intval($a->argv[1]);
16 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
25 require_once('include/group.php');
26 require_once('include/contact_widgets.php');
28 if(! x($a->page,'aside'))
29 $a->page['aside'] = '';
32 $a->data['contact'] = $r[0];
33 $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array(
34 '$name' => $a->data['contact']['name'],
35 '$photo' => $a->data['contact']['photo']
41 if (isset($_GET['add']))
42 $follow_widget = follow_widget($_GET['add']);
44 $follow_widget = follow_widget();
47 $groups_widget .= group_side('contacts','group',false,0,$contact_id);
48 $findpeople_widget .= findpeople_widget();
49 $networks_widget .= networks_widget('contacts',$_GET['nets']);
50 $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"),array(
51 '$vcard_widget' => $vcard_widget,
52 '$follow_widget' => $follow_widget,
53 '$groups_widget' => $groups_widget,
54 '$findpeople_widget' => $findpeople_widget,
55 '$networks_widget' => $networks_widget
58 $base = $a->get_baseurl();
59 $tpl = get_markup_template("contacts-head.tpl");
60 $a->page['htmlhead'] .= replace_macros($tpl,array(
61 '$baseurl' => $a->get_baseurl(true),
65 $tpl = get_markup_template("contacts-end.tpl");
66 $a->page['end'] .= replace_macros($tpl,array(
67 '$baseurl' => $a->get_baseurl(true),
74 function contacts_batch_actions(&$a){
75 $contacts_id = $_POST['contact_batch'];
76 if (!is_array($contacts_id)) return;
78 $orig_records = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND `uid` = %d AND `self` = 0",
79 implode(",", $contacts_id),
84 foreach($orig_records as $orig_record) {
85 $contact_id = $orig_record['id'];
86 if (x($_POST, 'contacts_batch_update')) {
87 _contact_update($contact_id);
90 if (x($_POST, 'contacts_batch_block')) {
91 $r = _contact_block($contact_id, $orig_record);
92 if ($r) $count_actions++;
94 if (x($_POST, 'contacts_batch_ignore')) {
95 $r = _contact_ignore($contact_id, $orig_record);
96 if ($r) $count_actions++;
98 if (x($_POST, 'contacts_batch_archive')) {
99 $r = _contact_archive($contact_id, $orig_record);
100 if ($r) $count_actions++;
102 if (x($_POST, 'contacts_batch_drop')) {
103 _contact_drop($contact_id, $orig_record);
107 if ($count_actions>0) {
108 info ( sprintf( tt("%d contact edited.", "%d contacts edited", $count_actions), $count_actions) );
111 if(x($_SESSION,'return_url'))
112 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
114 goaway($a->get_baseurl(true) . '/contacts');
119 function contacts_post(&$a) {
124 if ($a->argv[1]==="batch") {
125 contacts_batch_actions($a);
129 $contact_id = intval($a->argv[1]);
133 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
138 if(! count($orig_record)) {
139 notice( t('Could not access contact record.') . EOL);
140 goaway($a->get_baseurl(true) . '/contacts');
141 return; // NOTREACHED
144 call_hooks('contact_edit_post', $_POST);
146 $profile_id = intval($_POST['profile-assign']);
148 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
153 notice( t('Could not locate selected profile.') . EOL);
158 $hidden = intval($_POST['hidden']);
160 $notify = intval($_POST['notify']);
162 $fetch_further_information = intval($_POST['fetch_further_information']);
164 $ffi_keyword_blacklist = fix_mce_lf(escape_tags(trim($_POST['ffi_keyword_blacklist'])));
166 $priority = intval($_POST['poll']);
167 if($priority > 5 || $priority < 0)
170 $info = fix_mce_lf(escape_tags(trim($_POST['info'])));
172 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
173 `hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d,
174 `ffi_keyword_blacklist` = '%s' WHERE `id` = %d AND `uid` = %d",
180 intval($fetch_further_information),
181 dbesc($ffi_keyword_blacklist),
186 info( t('Contact updated.') . EOL);
188 notice( t('Failed to update contact record.') . EOL);
190 $r = q("select * from contact where id = %d and uid = %d limit 1",
195 $a->data['contact'] = $r[0];
202 function _contact_update($contact_id) {
203 // pull feed and consume it, which should subscribe to the hub.
204 proc_run('php',"include/poller.php","$contact_id");
206 function _contact_block($contact_id, $orig_record) {
207 $blocked = (($orig_record['blocked']) ? 0 : 1);
208 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d",
216 function _contact_ignore($contact_id, $orig_record) {
217 $readonly = (($orig_record['readonly']) ? 0 : 1);
218 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d",
225 function _contact_archive($contact_id, $orig_record) {
226 $archived = (($orig_record['archive']) ? 0 : 1);
227 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d",
233 q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
237 function _contact_drop($contact_id, $orig_record) {
238 require_once('include/Contact.php');
241 terminate_friendship($a->user,$a->contact,$orig_record);
242 contact_remove($orig_record['id']);
246 function contacts_content(&$a) {
250 nav_set_selected('contacts');
254 notice( t('Permission denied.') . EOL);
260 $contact_id = intval($a->argv[1]);
266 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
271 if(! count($orig_record)) {
272 notice( t('Could not access contact record.') . EOL);
273 goaway($a->get_baseurl(true) . '/contacts');
274 return; // NOTREACHED
277 if($cmd === 'update') {
278 _contact_update($contact_id);
279 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
283 if($cmd === 'block') {
284 $r = _contact_block($contact_id, $orig_record[0]);
286 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
287 info((($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')).EOL);
290 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
291 return; // NOTREACHED
294 if($cmd === 'ignore') {
295 $r = _contact_ignore($contact_id, $orig_record[0]);
297 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
298 info((($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')).EOL);
301 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
302 return; // NOTREACHED
306 if($cmd === 'archive') {
307 $r = _contact_archive($contact_id, $orig_record[0]);
309 $archived = (($orig_record[0]['archive']) ? 0 : 1);
310 info((($archived) ? t('Contact has been archived') : t('Contact has been unarchived')).EOL);
313 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
314 return; // NOTREACHED
317 if($cmd === 'drop') {
319 // Check if we should do HTML-based delete confirmation
320 if($_REQUEST['confirm']) {
321 // <form> can't take arguments in its "action" parameter
322 // so add any arguments as hidden inputs
323 $query = explode_querystring($a->query_string);
325 foreach($query['args'] as $arg) {
326 if(strpos($arg, 'confirm=') === false) {
327 $arg_parts = explode('=', $arg);
328 $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
332 $a->page['aside'] = '';
333 return replace_macros(get_markup_template('confirm.tpl'), array(
335 '$message' => t('Do you really want to delete this contact?'),
336 '$extra_inputs' => $inputs,
337 '$confirm' => t('Yes'),
338 '$confirm_url' => $query['base'],
339 '$confirm_name' => 'confirmed',
340 '$cancel' => t('Cancel'),
343 // Now check how the user responded to the confirmation query
344 if($_REQUEST['canceled']) {
345 if(x($_SESSION,'return_url'))
346 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
348 goaway($a->get_baseurl(true) . '/contacts');
351 _contact_drop($contact_id, $orig_record[0]);
352 info( t('Contact has been removed.') . EOL );
353 if(x($_SESSION,'return_url'))
354 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
356 goaway($a->get_baseurl(true) . '/contacts');
357 return; // NOTREACHED
363 $_SESSION['return_url'] = $a->query_string;
365 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
367 $contact_id = $a->data['contact']['id'];
368 $contact = $a->data['contact'];
370 $editselect = 'none';
371 if( feature_enabled(local_user(),'richtext') )
372 $editselect = 'exact';
374 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
375 '$baseurl' => $a->get_baseurl(true),
376 '$editselect' => $editselect,
378 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
379 '$baseurl' => $a->get_baseurl(true),
380 '$editselect' => $editselect,
383 require_once('include/contact_selectors.php');
385 $tpl = get_markup_template("contact_edit.tpl");
387 switch($contact['rel']) {
388 case CONTACT_IS_FRIEND:
389 $dir_icon = 'images/lrarrow.gif';
390 $relation_text = t('You are mutual friends with %s');
392 case CONTACT_IS_FOLLOWER;
393 $dir_icon = 'images/larrow.gif';
394 $relation_text = t('You are sharing with %s');
397 case CONTACT_IS_SHARING;
398 $dir_icon = 'images/rarrow.gif';
399 $relation_text = t('%s is sharing with you');
405 $relation_text = sprintf($relation_text,$contact['name']);
407 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
408 $url = "redir/{$contact['id']}";
409 $sparkle = ' class="sparkle" ';
412 $url = $contact['url'];
416 $insecure = t('Private communications are not available for this contact.');
418 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
420 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
422 if($contact['last-update'] !== '0000-00-00 00:00:00')
423 $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
425 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
427 $poll_enabled = (($contact['network'] !== NETWORK_DIASPORA) ? true : false);
429 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network']));
431 $common = count_common_friends(local_user(),$contact['id']);
432 $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
434 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
436 $x = count_all_friends(local_user(), $contact['id']);
437 $all_friends = (($x) ? t('View all contacts') : '');
442 'label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
443 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/block',
445 'title' => t('Toggle Blocked status'),
448 'label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
449 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/ignore',
451 'title' => t('Toggle Ignored status'),
455 'label' => (($contact['archive']) ? t('Unarchive') : t('Archive') ),
456 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/archive',
458 'title' => t('Toggle Archive status'),
461 'label' => t('Repair'),
462 'url' => $a->get_baseurl(true) . '/crepair/' . $contact_id,
464 'title' => t('Advanced Contact Settings'),
467 $tab_tpl = get_markup_template('common_tabs.tpl');
468 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
470 $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!') : '');
472 $o .= replace_macros($tpl, array(
473 '$header' => t('Contact Editor'),
474 '$tab_str' => $tab_str,
475 '$submit' => t('Submit'),
476 '$lbl_vis1' => t('Profile Visibility'),
477 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
478 '$lbl_info1' => t('Contact Information / Notes'),
479 '$infedit' => t('Edit contact notes'),
480 '$common_text' => $common_text,
481 '$common_link' => $a->get_baseurl(true) . '/common/loc/' . local_user() . '/' . $contact['id'],
482 '$all_friends' => $all_friends,
483 '$relation_text' => $relation_text,
484 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
485 '$blockunblock' => t('Block/Unblock contact'),
486 '$ignorecont' => t('Ignore contact'),
487 '$lblcrepair' => t("Repair URL settings"),
488 '$lblrecent' => t('View conversations'),
489 '$lblsuggest' => $lblsuggest,
490 '$delete' => t('Delete contact'),
491 '$nettype' => $nettype,
492 '$poll_interval' => contact_poll_interval($contact['priority'],(! $poll_enabled)),
493 '$poll_enabled' => $poll_enabled,
494 '$lastupdtext' => t('Last update:'),
495 '$lost_contact' => $lost_contact,
496 '$updpub' => t('Update public posts'),
497 '$last_update' => $last_update,
498 '$udnow' => t('Update now'),
499 '$profile_select' => contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false)),
500 '$contact_id' => $contact['id'],
501 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
502 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
503 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
504 '$info' => $contact['info'],
505 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
506 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
507 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
508 '$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')),
509 '$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
510 '$fetch_further_information' => array('fetch_further_information', t('Fetch further information for feeds'), $contact['fetch_further_information'], t('Fetch further information for feeds'),
511 array('0'=>t('Disabled'), '1'=>t('Fetch information'), '2'=>t('Fetch information and keywords'))),
512 '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
513 '$ffi_keyword_blacklist' => array('ffi_keyword_blacklist', t('Blacklisted keywords'), $contact['ffi_keyword_blacklist'], t('Comma separated list of keywords that should not be converted to hashtags, when "Fetch information and keywords" is selected')),
514 '$photo' => $contact['photo'],
515 '$name' => $contact['name'],
516 '$dir_icon' => $dir_icon,
517 '$alt_text' => $alt_text,
518 '$sparkle' => $sparkle,
523 $arr = array('contact' => $contact,'output' => $o);
525 call_hooks('contact_edit', $arr);
527 return $arr['output'];
536 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
540 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
541 $sql_extra = " AND `blocked` = 1 ";
544 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
545 $sql_extra = " AND `hidden` = 1 ";
548 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
549 $sql_extra = " AND `readonly` = 1 ";
552 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
553 $sql_extra = " AND `archive` = 1 ";
557 $sql_extra = " AND `blocked` = 0 ";
559 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
560 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
564 'label' => t('Suggestions'),
565 'url' => $a->get_baseurl(true) . '/suggest',
567 'title' => t('Suggest potential friends'),
570 'label' => t('All Contacts'),
571 'url' => $a->get_baseurl(true) . '/contacts/all',
572 'sel' => ($all) ? 'active' : '',
573 'title' => t('Show all contacts'),
576 'label' => t('Unblocked'),
577 'url' => $a->get_baseurl(true) . '/contacts',
578 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
579 'title' => t('Only show unblocked contacts'),
583 'label' => t('Blocked'),
584 'url' => $a->get_baseurl(true) . '/contacts/blocked',
585 'sel' => ($blocked) ? 'active' : '',
586 'title' => t('Only show blocked contacts'),
590 'label' => t('Ignored'),
591 'url' => $a->get_baseurl(true) . '/contacts/ignored',
592 'sel' => ($ignored) ? 'active' : '',
593 'title' => t('Only show ignored contacts'),
597 'label' => t('Archived'),
598 'url' => $a->get_baseurl(true) . '/contacts/archived',
599 'sel' => ($archived) ? 'active' : '',
600 'title' => t('Only show archived contacts'),
604 'label' => t('Hidden'),
605 'url' => $a->get_baseurl(true) . '/contacts/hidden',
606 'sel' => ($hidden) ? 'active' : '',
607 'title' => t('Only show hidden contacts'),
612 $tab_tpl = get_markup_template('common_tabs.tpl');
613 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
619 $search_hdr = $search;
620 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
623 $sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') " : "");
626 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
628 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
631 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
632 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
633 intval($_SESSION['uid']));
635 $a->set_pager_total($r[0]['total']);
636 $total = $r[0]['total'];
640 $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 ",
641 intval($_SESSION['uid']),
642 intval($a->pager['start']),
643 intval($a->pager['itemspage'])
653 case CONTACT_IS_FRIEND:
654 $dir_icon = 'images/lrarrow.gif';
655 $alt_text = t('Mutual Friendship');
657 case CONTACT_IS_FOLLOWER;
658 $dir_icon = 'images/larrow.gif';
659 $alt_text = t('is a fan of yours');
661 case CONTACT_IS_SHARING;
662 $dir_icon = 'images/rarrow.gif';
663 $alt_text = t('you are a fan of');
668 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
669 $url = "redir/{$rr['id']}";
670 $sparkle = ' class="sparkle" ';
679 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
680 'edit_hover' => t('Edit contact'),
681 'photo_menu' => contact_photo_menu($rr),
683 'alt_text' => $alt_text,
684 'dir_icon' => $dir_icon,
685 'thumb' => proxy_url($rr['thumb']),
686 'name' => $rr['name'],
687 'username' => $rr['name'],
688 'sparkle' => $sparkle,
689 'itemurl' => $rr['url'],
691 'network' => network_to_name($rr['network']),
699 $tpl = get_markup_template("contacts-template.tpl");
700 $o .= replace_macros($tpl, array(
701 '$baseurl' => $a->get_baseurl(),
702 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
705 '$search' => $search_hdr,
706 '$desc' => t('Search your contacts'),
707 '$finding' => (($searching) ? t('Finding: ') . "'" . $search . "'" : ""),
708 '$submit' => t('Find'),
710 '$contacts' => $contacts,
711 '$contact_drop_confirm' => t('Do you really want to delete this contact?'),
712 '$batch_actions' => array(
713 'contacts_batch_update' => t('Update'),
714 'contacts_batch_block' => t('Block')."/".t("Unblock"),
715 "contacts_batch_ignore" => t('Ignore')."/".t("Unignore"),
716 "contacts_batch_archive" => t('Archive')."/".t("Unarchive"),
717 "contacts_batch_drop" => t('Delete'),
719 '$paginate' => paginate($a),