3 require_once('include/Contact.php');
4 require_once('include/socgraph.php');
5 require_once('include/contact_selectors.php');
6 require_once('include/Scrape.php');
7 require_once('mod/proxy.php');
8 require_once('include/Photo.php');
10 function contacts_init(&$a) {
16 if((($a->argc == 2) && intval($a->argv[1])) OR (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) {
17 $contact_id = intval($a->argv[1]);
18 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
27 require_once('include/group.php');
28 require_once('include/contact_widgets.php');
30 if ($_GET['nets'] == "all")
33 if(! x($a->page,'aside'))
34 $a->page['aside'] = '';
37 $a->data['contact'] = $r[0];
39 if (($a->data['contact']['network'] != "") AND ($a->data['contact']['network'] != NETWORK_DFRN)) {
40 $networkname = format_network_name($a->data['contact']['network'],$a->data['contact']['url']);
44 $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array(
45 '$name' => htmlentities($a->data['contact']['name']),
46 '$photo' => $a->data['contact']['photo'],
47 '$url' => ($a->data['contact']['network'] == NETWORK_DFRN) ? "redir/".$a->data['contact']['id'] : $a->data['contact']['url'],
48 '$addr' => (($a->data['contact']['addr'] != "") ? ($a->data['contact']['addr']) : ""),
49 '$network_name' => $networkname,
50 '$network' => t('Network:'),
51 'account_type' => (($a->data['contact']['forum'] || $a->data['contact']['prv']) ? t('Forum') : '')
53 $finpeople_widget = '';
55 $networks_widget = '';
59 $networks_widget .= networks_widget('contacts',$_GET['nets']);
60 if (isset($_GET['add']))
61 $follow_widget = follow_widget($_GET['add']);
63 $follow_widget = follow_widget();
65 $findpeople_widget .= findpeople_widget();
68 $groups_widget .= group_side('contacts','group','full',0,$contact_id);
70 $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"),array(
71 '$vcard_widget' => $vcard_widget,
72 '$findpeople_widget' => $findpeople_widget,
73 '$follow_widget' => $follow_widget,
74 '$groups_widget' => $groups_widget,
75 '$networks_widget' => $networks_widget
79 $tpl = get_markup_template("contacts-head.tpl");
80 $a->page['htmlhead'] .= replace_macros($tpl,array(
81 '$baseurl' => $a->get_baseurl(true),
85 $tpl = get_markup_template("contacts-end.tpl");
86 $a->page['end'] .= replace_macros($tpl,array(
87 '$baseurl' => $a->get_baseurl(true),
94 function contacts_batch_actions(&$a){
95 $contacts_id = $_POST['contact_batch'];
96 if (!is_array($contacts_id)) return;
98 $orig_records = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND `uid` = %d AND `self` = 0",
99 implode(",", $contacts_id),
104 foreach($orig_records as $orig_record) {
105 $contact_id = $orig_record['id'];
106 if (x($_POST, 'contacts_batch_update')) {
107 _contact_update($contact_id);
110 if (x($_POST, 'contacts_batch_block')) {
111 $r = _contact_block($contact_id, $orig_record);
112 if ($r) $count_actions++;
114 if (x($_POST, 'contacts_batch_ignore')) {
115 $r = _contact_ignore($contact_id, $orig_record);
116 if ($r) $count_actions++;
118 if (x($_POST, 'contacts_batch_archive')) {
119 $r = _contact_archive($contact_id, $orig_record);
120 if ($r) $count_actions++;
122 if (x($_POST, 'contacts_batch_drop')) {
123 _contact_drop($contact_id, $orig_record);
127 if ($count_actions>0) {
128 info ( sprintf( tt("%d contact edited.", "%d contacts edited.", $count_actions), $count_actions) );
131 if(x($_SESSION,'return_url'))
132 goaway('' . $_SESSION['return_url']);
139 function contacts_post(&$a) {
144 if ($a->argv[1]==="batch") {
145 contacts_batch_actions($a);
149 $contact_id = intval($a->argv[1]);
153 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
158 if(! count($orig_record)) {
159 notice( t('Could not access contact record.') . EOL);
161 return; // NOTREACHED
164 call_hooks('contact_edit_post', $_POST);
166 $profile_id = intval($_POST['profile-assign']);
168 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
173 notice( t('Could not locate selected profile.') . EOL);
178 $hidden = intval($_POST['hidden']);
180 $notify = intval($_POST['notify']);
182 $fetch_further_information = intval($_POST['fetch_further_information']);
184 $ffi_keyword_blacklist = fix_mce_lf(escape_tags(trim($_POST['ffi_keyword_blacklist'])));
186 $priority = intval($_POST['poll']);
187 if($priority > 5 || $priority < 0)
190 $info = fix_mce_lf(escape_tags(trim($_POST['info'])));
192 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
193 `hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d,
194 `ffi_keyword_blacklist` = '%s' WHERE `id` = %d AND `uid` = %d",
200 intval($fetch_further_information),
201 dbesc($ffi_keyword_blacklist),
206 info( t('Contact updated.') . EOL);
208 notice( t('Failed to update contact record.') . EOL);
210 $r = q("select * from contact where id = %d and uid = %d limit 1",
215 $a->data['contact'] = $r[0];
222 function _contact_update($contact_id) {
223 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
229 if ($uid != local_user())
232 if ($r[0]["network"] == NETWORK_OSTATUS) {
233 $result = new_contact($uid, $r[0]["url"], false);
235 if ($result['success'])
236 $r = q("UPDATE `contact` SET `subhub` = 1 WHERE `id` = %d",
237 intval($contact_id));
239 // pull feed and consume it, which should subscribe to the hub.
240 proc_run('php',"include/onepoll.php","$contact_id", "force");
243 function _contact_update_profile($contact_id) {
244 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
250 if ($uid != local_user())
253 $data = probe_url($r[0]["url"]);
255 // "Feed" or "Unknown" is mostly a sign of communication problems
256 if ((in_array($data["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) AND ($data["network"] != $r[0]["network"]))
259 $updatefields = array("name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm",
260 "poco", "network", "alias");
263 if ($data["network"] == NETWORK_OSTATUS) {
264 $result = new_contact($uid, $data["url"], false);
266 if ($result['success'])
267 $update["subhub"] = true;
270 foreach($updatefields AS $field)
271 if (isset($data[$field]) AND ($data[$field] != ""))
272 $update[$field] = $data[$field];
274 $update["nurl"] = normalise_link($data["url"]);
278 if (isset($data["priority"]) AND ($data["priority"] != 0))
279 $query = "`priority` = ".intval($data["priority"]);
281 foreach($update AS $key => $value) {
285 $query .= "`".$key."` = '".dbesc($value)."'";
291 $r = q("UPDATE `contact` SET $query WHERE `id` = %d AND `uid` = %d",
296 // Update the entry in the contact table
297 update_contact_avatar($data['photo'], local_user(), $contact_id);
299 // Update the entry in the gcontact table
300 update_gcontact_from_probe($data["url"]);
303 function _contact_block($contact_id, $orig_record) {
304 $blocked = (($orig_record['blocked']) ? 0 : 1);
305 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d",
313 function _contact_ignore($contact_id, $orig_record) {
314 $readonly = (($orig_record['readonly']) ? 0 : 1);
315 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d",
322 function _contact_archive($contact_id, $orig_record) {
323 $archived = (($orig_record['archive']) ? 0 : 1);
324 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d",
330 q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
334 function _contact_drop($contact_id, $orig_record) {
337 terminate_friendship($a->user,$a->contact,$orig_record);
338 contact_remove($orig_record['id']);
342 function contacts_content(&$a) {
346 nav_set_selected('contacts');
350 notice( t('Permission denied.') . EOL);
356 $contact_id = intval($a->argv[1]);
362 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
367 if(! count($orig_record)) {
368 notice( t('Could not access contact record.') . EOL);
370 return; // NOTREACHED
373 if($cmd === 'update') {
374 _contact_update($contact_id);
375 goaway('contacts/' . $contact_id);
379 if($cmd === 'updateprofile') {
380 _contact_update_profile($contact_id);
381 goaway('crepair/' . $contact_id);
385 if($cmd === 'block') {
386 $r = _contact_block($contact_id, $orig_record[0]);
388 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
389 info((($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')).EOL);
392 goaway('contacts/' . $contact_id);
393 return; // NOTREACHED
396 if($cmd === 'ignore') {
397 $r = _contact_ignore($contact_id, $orig_record[0]);
399 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
400 info((($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')).EOL);
403 goaway('contacts/' . $contact_id);
404 return; // NOTREACHED
408 if($cmd === 'archive') {
409 $r = _contact_archive($contact_id, $orig_record[0]);
411 $archived = (($orig_record[0]['archive']) ? 0 : 1);
412 info((($archived) ? t('Contact has been archived') : t('Contact has been unarchived')).EOL);
415 goaway('contacts/' . $contact_id);
416 return; // NOTREACHED
419 if($cmd === 'drop') {
421 // Check if we should do HTML-based delete confirmation
422 if($_REQUEST['confirm']) {
423 // <form> can't take arguments in its "action" parameter
424 // so add any arguments as hidden inputs
425 $query = explode_querystring($a->query_string);
427 foreach($query['args'] as $arg) {
428 if(strpos($arg, 'confirm=') === false) {
429 $arg_parts = explode('=', $arg);
430 $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
434 $a->page['aside'] = '';
436 return replace_macros(get_markup_template('contact_drop_confirm.tpl'), array(
437 '$contact' => _contact_detail_for_template($orig_record[0]),
439 '$message' => t('Do you really want to delete this contact?'),
440 '$extra_inputs' => $inputs,
441 '$confirm' => t('Yes'),
442 '$confirm_url' => $query['base'],
443 '$confirm_name' => 'confirmed',
444 '$cancel' => t('Cancel'),
447 // Now check how the user responded to the confirmation query
448 if($_REQUEST['canceled']) {
449 if(x($_SESSION,'return_url'))
450 goaway('' . $_SESSION['return_url']);
455 _contact_drop($contact_id, $orig_record[0]);
456 info( t('Contact has been removed.') . EOL );
457 if(x($_SESSION,'return_url'))
458 goaway('' . $_SESSION['return_url']);
461 return; // NOTREACHED
463 if($cmd === 'posts') {
464 return contact_posts($a, $contact_id);
470 $_SESSION['return_url'] = $a->query_string;
472 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
474 $contact_id = $a->data['contact']['id'];
475 $contact = $a->data['contact'];
477 $editselect = 'none';
478 if( feature_enabled(local_user(),'richtext') )
479 $editselect = 'exact';
481 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
482 '$baseurl' => $a->get_baseurl(true),
483 '$editselect' => $editselect,
485 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
486 '$baseurl' => $a->get_baseurl(true),
487 '$editselect' => $editselect,
490 require_once('include/contact_selectors.php');
492 $tpl = get_markup_template("contact_edit.tpl");
494 switch($contact['rel']) {
495 case CONTACT_IS_FRIEND:
496 $dir_icon = 'images/lrarrow.gif';
497 $relation_text = t('You are mutual friends with %s');
499 case CONTACT_IS_FOLLOWER;
500 $dir_icon = 'images/larrow.gif';
501 $relation_text = t('You are sharing with %s');
504 case CONTACT_IS_SHARING;
505 $dir_icon = 'images/rarrow.gif';
506 $relation_text = t('%s is sharing with you');
512 if(!in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
515 $relation_text = sprintf($relation_text,htmlentities($contact['name']));
517 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
518 $url = "redir/{$contact['id']}";
519 $sparkle = ' class="sparkle" ';
522 $url = $contact['url'];
526 $insecure = t('Private communications are not available for this contact.');
528 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
530 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
532 if($contact['last-update'] !== '0000-00-00 00:00:00')
533 $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
535 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
537 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
539 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network'], $contact["url"]));
541 //$common = count_common_friends(local_user(),$contact['id']);
542 //$common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
544 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
546 //$x = count_all_friends(local_user(), $contact['id']);
547 //$all_friends = (($x) ? t('View all contacts') : '');
550 $tab_str = contacts_tab($a, $contact_id, 2);
552 $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!') : '');
554 if ($contact['network'] == NETWORK_FEED)
555 $fetch_further_information = array('fetch_further_information', t('Fetch further information for feeds'), $contact['fetch_further_information'], t('Fetch further information for feeds'),
556 array('0'=>t('Disabled'), '1'=>t('Fetch information'), '2'=>t('Fetch information and keywords')));
558 if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2)))
559 $poll_interval = contact_poll_interval($contact['priority'],(! $poll_enabled));
561 if ($contact['network'] == NETWORK_DFRN)
562 $profile_select = contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false));
564 if (in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS)) AND
565 ($contact['rel'] == CONTACT_IS_FOLLOWER))
566 $follow = $a->get_baseurl(true)."/follow?url=".urlencode($contact["url"]);
568 // Load contactact related actions like hide, suggest, delete and others
569 $contact_actions = contact_actions($contact);
572 $o .= replace_macros($tpl, array(
573 //'$header' => t('Contact Editor'),
574 '$header' => t("Contact"),
575 '$tab_str' => $tab_str,
576 '$submit' => t('Submit'),
577 '$lbl_vis1' => t('Profile Visibility'),
578 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
579 '$lbl_info1' => t('Contact Information / Notes'),
580 '$infedit' => t('Edit contact notes'),
581 '$common_text' => $common_text,
582 '$common_link' => 'common/loc/' . local_user() . '/' . $contact['id'],
583 '$all_friends' => $all_friends,
584 '$relation_text' => $relation_text,
585 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
586 '$blockunblock' => t('Block/Unblock contact'),
587 '$ignorecont' => t('Ignore contact'),
588 '$lblcrepair' => t("Repair URL settings"),
589 '$lblrecent' => t('View conversations'),
590 '$lblsuggest' => $lblsuggest,
591 //'$delete' => t('Delete contact'),
592 '$nettype' => $nettype,
593 '$poll_interval' => $poll_interval,
594 '$poll_enabled' => $poll_enabled,
595 '$lastupdtext' => t('Last update:'),
596 '$lost_contact' => $lost_contact,
597 '$updpub' => t('Update public posts'),
598 '$last_update' => $last_update,
599 '$udnow' => t('Update now'),
600 '$follow' => $follow,
601 '$follow_text' => t("Connect/Follow"),
602 '$profile_select' => $profile_select,
603 '$contact_id' => $contact['id'],
604 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
605 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
606 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
607 '$info' => $contact['info'],
608 '$cinfo' => array('info', '', $contact['info'], ''),
609 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
610 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
611 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
612 '$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')),
613 '$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
614 '$fetch_further_information' => $fetch_further_information,
615 '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
616 '$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')),
617 '$photo' => $contact['photo'],
618 '$name' => htmlentities($contact['name']),
619 '$dir_icon' => $dir_icon,
620 '$alt_text' => $alt_text,
621 '$sparkle' => $sparkle,
623 '$profileurllabel' => t('Profile URL'),
624 '$profileurl' => $contact['url'],
625 'account_type' => (($contact['forum'] || $contact['prv']) ? t('Forum') : ''),
626 '$location' => bbcode($contact["location"]),
627 '$location_label' => t("Location:"),
628 '$about' => bbcode($contact["about"], false, false),
629 '$about_label' => t("About:"),
630 '$keywords' => $contact["keywords"],
631 '$keywords_label' => t("Tags:"),
632 '$contact_action_button' => t("Actions"),
633 '$contact_actions' => $contact_actions,
634 '$contact_status' => t("Status"),
635 '$contact_settings_label' => t('Contact Settings'),
636 '$contact_profile_label' => t("Profile"),
640 $arr = array('contact' => $contact,'output' => $o);
642 call_hooks('contact_edit', $arr);
644 return $arr['output'];
653 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
657 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
658 $sql_extra = " AND `blocked` = 1 ";
661 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
662 $sql_extra = " AND `hidden` = 1 ";
665 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
666 $sql_extra = " AND `readonly` = 1 ";
669 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
670 $sql_extra = " AND `archive` = 1 ";
674 $sql_extra = " AND `blocked` = 0 ";
676 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
677 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
681 'label' => t('Suggestions'),
684 'title' => t('Suggest potential friends'),
685 'id' => 'suggestions-tab',
689 'label' => t('All Contacts'),
690 'url' => 'contacts/all',
691 'sel' => ($all) ? 'active' : '',
692 'title' => t('Show all contacts'),
693 'id' => 'showall-tab',
697 'label' => t('Unblocked'),
699 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
700 'title' => t('Only show unblocked contacts'),
701 'id' => 'showunblocked-tab',
706 'label' => t('Blocked'),
707 'url' => 'contacts/blocked',
708 'sel' => ($blocked) ? 'active' : '',
709 'title' => t('Only show blocked contacts'),
710 'id' => 'showblocked-tab',
715 'label' => t('Ignored'),
716 'url' => 'contacts/ignored',
717 'sel' => ($ignored) ? 'active' : '',
718 'title' => t('Only show ignored contacts'),
719 'id' => 'showignored-tab',
724 'label' => t('Archived'),
725 'url' => 'contacts/archived',
726 'sel' => ($archived) ? 'active' : '',
727 'title' => t('Only show archived contacts'),
728 'id' => 'showarchived-tab',
733 'label' => t('Hidden'),
734 'url' => 'contacts/hidden',
735 'sel' => ($hidden) ? 'active' : '',
736 'title' => t('Only show hidden contacts'),
737 'id' => 'showhidden-tab',
743 $tab_tpl = get_markup_template('common_tabs.tpl');
744 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
750 $search_hdr = $search;
751 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
754 $sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') " : "");
757 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
759 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
762 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
763 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
764 intval($_SESSION['uid']));
766 $a->set_pager_total($r[0]['total']);
767 $total = $r[0]['total'];
770 $sql_extra3 = unavailable_networks();
772 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 $sql_extra3 ORDER BY `name` ASC LIMIT %d , %d ",
773 intval($_SESSION['uid']),
774 intval($a->pager['start']),
775 intval($a->pager['itemspage'])
782 $contacts[] = _contact_detail_for_template($rr);
786 $tpl = get_markup_template("contacts-template.tpl");
787 $o .= replace_macros($tpl, array(
788 '$baseurl' => z_root(),
789 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
792 '$search' => $search_hdr,
793 '$desc' => t('Search your contacts'),
794 '$finding' => (($searching) ? sprintf(t('Results for: %s'),$search) : ""),
795 '$submit' => t('Find'),
797 '$contacts' => $contacts,
798 '$contact_drop_confirm' => t('Do you really want to delete this contact?'),
800 '$batch_actions' => array(
801 'contacts_batch_update' => t('Update'),
802 'contacts_batch_block' => t('Block')."/".t("Unblock"),
803 "contacts_batch_ignore" => t('Ignore')."/".t("Unignore"),
804 "contacts_batch_archive" => t('Archive')."/".t("Unarchive"),
805 "contacts_batch_drop" => t('Delete'),
807 '$h_batch_actions' => t('Batch Actions'),
808 '$paginate' => paginate($a),
816 * @brief List of pages for the Contact TabBar
818 * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
821 * @param int $contact_id The ID of the contact
822 * @param int $active_tab 1 if tab should be marked as active
824 * @return array with with contact TabBar data
826 function contacts_tab($a, $contact_id, $active_tab) {
830 'label'=>t('Status'),
831 'url' => "contacts/".$contact_id."/posts",
832 'sel' => (($active_tab == 1)?'active':''),
833 'title' => t('Status Messages and Posts'),
834 'id' => 'status-tab',
838 'label'=>t('Profile'),
839 'url' => "contacts/".$contact_id,
840 'sel' => (($active_tab == 2)?'active':''),
841 'title' => t('Profile Details'),
842 'id' => 'status-tab',
847 // Show this tab only if there is visible friend list
848 $x = count_all_friends(local_user(), $contact_id);
850 $tabs[] = array('label'=>t('Contacts'),
851 'url' => "allfriends/".$contact_id,
852 'sel' => (($active_tab == 3)?'active':''),
853 'title' => t('View all contacts'),
854 'id' => 'allfriends-tab',
857 // Show this tab only if there is visible common friend list
858 $common = count_common_friends(local_user(),$contact_id);
860 $tabs[] = array('label'=>t('Common Friends'),
861 'url' => "common/loc/".local_user()."/".$contact_id,
862 'sel' => (($active_tab == 4)?'active':''),
863 'title' => t('View all common friends'),
864 'id' => 'common-loc-tab',
867 $tabs[] = array('label' => t('Advanced'),
868 'url' => 'crepair/' . $contact_id,
869 'sel' => (($active_tab == 5)?'active':''),
870 'title' => t('Advanced Contact Settings'),
871 'id' => 'advanced-tab',
874 $tab_tpl = get_markup_template('common_tabs.tpl');
875 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
880 function contact_posts($a, $contact_id) {
882 $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id));
885 $a->page['aside'] = "";
886 profile_load($a, "", 0, get_contact_details_by_url($contact["url"]));
890 $tab_str = contacts_tab($a, $contact_id, 1);
894 $r = q("SELECT `id` FROM `item` WHERE `contact-id` = %d LIMIT 1", intval($contact_id));
896 $o .= posts_from_contact($a, $contact_id);
897 elseif ($contact["url"]) {
898 $r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
899 dbesc(normalise_link($contact["url"])));
901 if ($r[0]["id"] <> 0)
902 $o .= posts_from_gcontact($a, $r[0]["id"]);
908 function _contact_detail_for_template($rr){
913 case CONTACT_IS_FRIEND:
914 $dir_icon = 'images/lrarrow.gif';
915 $alt_text = t('Mutual Friendship');
917 case CONTACT_IS_FOLLOWER;
918 $dir_icon = 'images/larrow.gif';
919 $alt_text = t('is a fan of yours');
921 case CONTACT_IS_SHARING;
922 $dir_icon = 'images/rarrow.gif';
923 $alt_text = t('you are a fan of');
928 if(($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) {
929 $url = "redir/{$rr['id']}";
930 $sparkle = ' class="sparkle" ';
937 //test if contact is a forum page
938 if (isset($rr['forum']) OR isset($rr['prv']))
939 $community = ($rr['forum'] OR $rr['prv']);
943 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
944 'edit_hover' => t('Edit contact'),
945 'photo_menu' => contact_photo_menu($rr),
947 'alt_text' => $alt_text,
948 'dir_icon' => $dir_icon,
949 'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB),
950 'name' => htmlentities($rr['name']),
951 'username' => htmlentities($rr['name']),
952 'account_type' => ($community ? t('Forum') : ''),
953 'sparkle' => $sparkle,
954 'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']),
956 'network' => network_to_name($rr['network'], $rr['url']),
962 * @brief Gives a array with actions which can performed to a given contact
964 * This includes actions like e.g. 'block', 'hide', 'archive', 'delete' and others
966 * @param array $contact Data about the Contact
967 * @return array with contact related actions
969 function contact_actions($contact) {
971 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
972 $contact_action = array();
974 // Provide friend suggestion only for Friendica contacts
975 if($contact['network'] === NETWORK_DFRN) {
976 $contact_actions['suggest'] = array(
977 'label' => t('Suggest friends'),
978 'url' => 'fsuggest/' . $contact['id'],
986 $contact_actions['update'] = array(
987 'label' => t('Update now'),
988 'url' => 'contacts/' . $contact['id'] . '/update',
995 $contact_actions['block'] = array(
996 'label' => (intval($contact['blocked']) ? t('Unblock') : t('Block') ),
997 'url' => 'contacts/' . $contact['id'] . '/block',
998 'title' => t('Toggle Blocked status'),
999 'sel' => (intval($contact['blocked']) ? 'active' : ''),
1000 'id' => 'toggle-block',
1003 $contact_actions['ignore'] = array(
1004 'label' => (intval($contact['readonly']) ? t('Unignore') : t('Ignore') ),
1005 'url' => 'contacts/' . $contact['id'] . '/ignore',
1006 'title' => t('Toggle Ignored status'),
1007 'sel' => (intval($contact['readonly']) ? 'active' : ''),
1008 'id' => 'toggle-ignore',
1011 $contact_actions['archive'] = array(
1012 'label' => (intval($contact['archive']) ? t('Unarchive') : t('Archive') ),
1013 'url' => 'contacts/' . $contact['id'] . '/archive',
1014 'title' => t('Toggle Archive status'),
1015 'sel' => (intval($contact['archive']) ? 'active' : ''),
1016 'id' => 'toggle-archive',
1019 $contact_actions['delete'] = array(
1020 'label' => t('Delete'),
1021 'url' => 'contacts/' . $contact['id'] . '/drop',
1022 'title' => t('Delete contact'),
1027 return $contact_actions;