5 require_once('include/Scrape.php');
6 require_once 'include/Contact.php';
7 require_once 'include/socgraph.php';
8 require_once 'include/contact_selectors.php';
9 require_once 'mod/proxy.php';
10 require_once 'include/Photo.php';
12 function contacts_init(App $a) {
19 if((($a->argc == 2) && intval($a->argv[1])) OR (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) {
20 $contact_id = intval($a->argv[1]);
21 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
25 if (! dbm::is_result($r)) {
30 require_once 'include/group.php';
31 require_once 'include/contact_widgets.php';
33 if ($_GET['nets'] == "all") {
37 if (! x($a->page,'aside')) {
38 $a->page['aside'] = '';
42 $a->data['contact'] = $r[0];
44 if (($a->data['contact']['network'] != "") AND ($a->data['contact']['network'] != NETWORK_DFRN)) {
45 $networkname = format_network_name($a->data['contact']['network'],$a->data['contact']['url']);
50 /// @TODO Add nice spaces
51 $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array(
52 '$name' => htmlentities($a->data['contact']['name']),
53 '$photo' => $a->data['contact']['photo'],
54 '$url' => ($a->data['contact']['network'] == NETWORK_DFRN) ? "redir/".$a->data['contact']['id'] : $a->data['contact']['url'],
55 '$addr' => (($a->data['contact']['addr'] != "") ? ($a->data['contact']['addr']) : ""),
56 '$network_name' => $networkname,
57 '$network' => t('Network:'),
58 '$account_type' => account_type($a->data['contact'])
61 $finpeople_widget = '';
63 $networks_widget = '';
66 $networks_widget .= networks_widget('contacts',$_GET['nets']);
67 if (isset($_GET['add'])) {
68 $follow_widget = follow_widget($_GET['add']);
70 $follow_widget = follow_widget();
73 $findpeople_widget .= findpeople_widget();
76 $groups_widget .= group_side('contacts','group','full',0,$contact_id);
78 $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"),array(
79 '$vcard_widget' => $vcard_widget,
80 '$findpeople_widget' => $findpeople_widget,
81 '$follow_widget' => $follow_widget,
82 '$groups_widget' => $groups_widget,
83 '$networks_widget' => $networks_widget
87 $tpl = get_markup_template("contacts-head.tpl");
88 $a->page['htmlhead'] .= replace_macros($tpl,array(
89 '$baseurl' => App::get_baseurl(true),
93 $tpl = get_markup_template("contacts-end.tpl");
94 $a->page['end'] .= replace_macros($tpl,array(
95 '$baseurl' => App::get_baseurl(true),
102 function contacts_batch_actions(App $a) {
103 $contacts_id = $_POST['contact_batch'];
104 if (!is_array($contacts_id)) return;
106 $orig_records = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND `uid` = %d AND `self` = 0",
107 implode(",", $contacts_id),
112 foreach($orig_records as $orig_record) {
113 $contact_id = $orig_record['id'];
114 if (x($_POST, 'contacts_batch_update')) {
115 _contact_update($contact_id);
118 if (x($_POST, 'contacts_batch_block')) {
119 $r = _contact_block($contact_id, $orig_record);
120 if ($r) $count_actions++;
122 if (x($_POST, 'contacts_batch_ignore')) {
123 $r = _contact_ignore($contact_id, $orig_record);
124 if ($r) $count_actions++;
126 if (x($_POST, 'contacts_batch_archive')) {
127 $r = _contact_archive($contact_id, $orig_record);
128 if ($r) $count_actions++;
130 if (x($_POST, 'contacts_batch_drop')) {
131 _contact_drop($contact_id, $orig_record);
135 if ($count_actions>0) {
136 info ( sprintf( tt("%d contact edited.", "%d contacts edited.", $count_actions), $count_actions) );
139 if (x($_SESSION,'return_url')) {
140 goaway('' . $_SESSION['return_url']);
149 function contacts_post(App $a) {
151 if (! local_user()) {
155 if ($a->argv[1]==="batch") {
156 contacts_batch_actions($a);
160 $contact_id = intval($a->argv[1]);
165 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
170 if (! count($orig_record)) {
171 notice( t('Could not access contact record.') . EOL);
173 return; // NOTREACHED
176 call_hooks('contact_edit_post', $_POST);
178 $profile_id = intval($_POST['profile-assign']);
180 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
184 if (! dbm::is_result($r)) {
185 notice( t('Could not locate selected profile.') . EOL);
190 $hidden = intval($_POST['hidden']);
192 $notify = intval($_POST['notify']);
194 $fetch_further_information = intval($_POST['fetch_further_information']);
196 $ffi_keyword_blacklist = escape_tags(trim($_POST['ffi_keyword_blacklist']));
198 $priority = intval($_POST['poll']);
199 if($priority > 5 || $priority < 0)
202 $info = escape_tags(trim($_POST['info']));
204 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
205 `hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d,
206 `ffi_keyword_blacklist` = '%s' WHERE `id` = %d AND `uid` = %d",
212 intval($fetch_further_information),
213 dbesc($ffi_keyword_blacklist),
218 info( t('Contact updated.') . EOL);
220 notice( t('Failed to update contact record.') . EOL);
222 $r = q("select * from contact where id = %d and uid = %d limit 1",
226 if($r && dbm::is_result($r))
227 $a->data['contact'] = $r[0];
234 function _contact_update($contact_id) {
235 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
241 if ($uid != local_user())
244 if ($r[0]["network"] == NETWORK_OSTATUS) {
245 $result = new_contact($uid, $r[0]["url"], false);
247 if ($result['success'])
248 $r = q("UPDATE `contact` SET `subhub` = 1 WHERE `id` = %d",
249 intval($contact_id));
251 // pull feed and consume it, which should subscribe to the hub.
252 proc_run(PRIORITY_HIGH, "include/onepoll.php", $contact_id, "force");
255 function _contact_update_profile($contact_id) {
256 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
262 if ($uid != local_user())
265 $data = Probe::uri($r[0]["url"], "", 0, false);
267 // "Feed" or "Unknown" is mostly a sign of communication problems
268 if ((in_array($data["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) AND ($data["network"] != $r[0]["network"]))
271 $updatefields = array("name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm",
272 "poco", "network", "alias");
275 if ($data["network"] == NETWORK_OSTATUS) {
276 $result = new_contact($uid, $data["url"], false);
278 if ($result['success'])
279 $update["subhub"] = true;
282 foreach($updatefields AS $field)
283 if (isset($data[$field]) AND ($data[$field] != ""))
284 $update[$field] = $data[$field];
286 $update["nurl"] = normalise_link($data["url"]);
290 if (isset($data["priority"]) AND ($data["priority"] != 0))
291 $query = "`priority` = ".intval($data["priority"]);
293 foreach($update AS $key => $value) {
297 $query .= "`".$key."` = '".dbesc($value)."'";
303 $r = q("UPDATE `contact` SET $query WHERE `id` = %d AND `uid` = %d",
308 // Update the entry in the contact table
309 update_contact_avatar($data['photo'], local_user(), $contact_id);
311 // Update the entry in the gcontact table
312 update_gcontact_from_probe($data["url"]);
315 function _contact_block($contact_id, $orig_record) {
316 $blocked = (($orig_record['blocked']) ? 0 : 1);
317 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d",
325 function _contact_ignore($contact_id, $orig_record) {
326 $readonly = (($orig_record['readonly']) ? 0 : 1);
327 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d",
334 function _contact_archive($contact_id, $orig_record) {
335 $archived = (($orig_record['archive']) ? 0 : 1);
336 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d",
342 q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
346 function _contact_drop($contact_id, $orig_record) {
349 terminate_friendship($a->user,$a->contact,$orig_record);
350 contact_remove($orig_record['id']);
354 function contacts_content(App $a) {
358 nav_set_selected('contacts');
361 if (! local_user()) {
362 notice( t('Permission denied.') . EOL);
368 $contact_id = intval($a->argv[1]);
374 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
379 if(! count($orig_record)) {
380 notice( t('Could not access contact record.') . EOL);
382 return; // NOTREACHED
385 if($cmd === 'update') {
386 _contact_update($contact_id);
387 goaway('contacts/' . $contact_id);
391 if($cmd === 'updateprofile') {
392 _contact_update_profile($contact_id);
393 goaway('crepair/' . $contact_id);
397 if($cmd === 'block') {
398 $r = _contact_block($contact_id, $orig_record[0]);
400 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
401 info((($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')).EOL);
404 goaway('contacts/' . $contact_id);
405 return; // NOTREACHED
408 if($cmd === 'ignore') {
409 $r = _contact_ignore($contact_id, $orig_record[0]);
411 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
412 info((($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')).EOL);
415 goaway('contacts/' . $contact_id);
416 return; // NOTREACHED
420 if($cmd === 'archive') {
421 $r = _contact_archive($contact_id, $orig_record[0]);
423 $archived = (($orig_record[0]['archive']) ? 0 : 1);
424 info((($archived) ? t('Contact has been archived') : t('Contact has been unarchived')).EOL);
427 goaway('contacts/' . $contact_id);
428 return; // NOTREACHED
431 if($cmd === 'drop') {
433 // Check if we should do HTML-based delete confirmation
434 if($_REQUEST['confirm']) {
435 // <form> can't take arguments in its "action" parameter
436 // so add any arguments as hidden inputs
437 $query = explode_querystring($a->query_string);
439 foreach($query['args'] as $arg) {
440 if(strpos($arg, 'confirm=') === false) {
441 $arg_parts = explode('=', $arg);
442 $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
446 $a->page['aside'] = '';
448 return replace_macros(get_markup_template('contact_drop_confirm.tpl'), array(
449 '$header' => t('Drop contact'),
450 '$contact' => _contact_detail_for_template($orig_record[0]),
452 '$message' => t('Do you really want to delete this contact?'),
453 '$extra_inputs' => $inputs,
454 '$confirm' => t('Yes'),
455 '$confirm_url' => $query['base'],
456 '$confirm_name' => 'confirmed',
457 '$cancel' => t('Cancel'),
460 // Now check how the user responded to the confirmation query
461 if ($_REQUEST['canceled']) {
462 if (x($_SESSION,'return_url')) {
463 goaway('' . $_SESSION['return_url']);
470 _contact_drop($contact_id, $orig_record[0]);
471 info( t('Contact has been removed.') . EOL );
472 if (x($_SESSION,'return_url')) {
473 goaway('' . $_SESSION['return_url']);
478 return; // NOTREACHED
480 if ($cmd === 'posts') {
481 return contact_posts($a, $contact_id);
487 $_SESSION['return_url'] = $a->query_string;
489 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
491 $contact_id = $a->data['contact']['id'];
492 $contact = $a->data['contact'];
494 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
495 '$baseurl' => App::get_baseurl(true),
497 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
498 '$baseurl' => App::get_baseurl(true),
501 require_once 'include/contact_selectors.php';
503 $tpl = get_markup_template("contact_edit.tpl");
505 switch($contact['rel']) {
506 case CONTACT_IS_FRIEND:
507 $dir_icon = 'images/lrarrow.gif';
508 $relation_text = t('You are mutual friends with %s');
510 case CONTACT_IS_FOLLOWER;
511 $dir_icon = 'images/larrow.gif';
512 $relation_text = t('You are sharing with %s');
515 case CONTACT_IS_SHARING;
516 $dir_icon = 'images/rarrow.gif';
517 $relation_text = t('%s is sharing with you');
523 if(!in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
526 $relation_text = sprintf($relation_text,htmlentities($contact['name']));
528 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
529 $url = "redir/{$contact['id']}";
530 $sparkle = ' class="sparkle" ';
533 $url = $contact['url'];
537 $insecure = t('Private communications are not available for this contact.');
539 $last_update = (($contact['last-update'] <= NULL_DATE)
541 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
543 if ($contact['last-update'] > NULL_DATE) {
544 $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
546 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
548 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
550 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network'], $contact["url"]));
552 //$common = count_common_friends(local_user(),$contact['id']);
553 //$common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
555 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
557 //$x = count_all_friends(local_user(), $contact['id']);
558 //$all_friends = (($x) ? t('View all contacts') : '');
561 $tab_str = contacts_tab($a, $contact_id, 2);
563 $lost_contact = (($contact['archive'] && $contact['term-date'] > NULL_DATE && $contact['term-date'] < datetime_convert('','','now')) ? t('Communications lost with this contact!') : '');
565 if ($contact['network'] == NETWORK_FEED) {
566 $fetch_further_information = array('fetch_further_information', t('Fetch further information for feeds'), $contact['fetch_further_information'], t('Fetch further information for feeds'),
567 array('0'=>t('Disabled'), '1'=>t('Fetch information'), '2'=>t('Fetch information and keywords')));
569 if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2)))
570 $poll_interval = contact_poll_interval($contact['priority'],(! $poll_enabled));
572 if ($contact['network'] == NETWORK_DFRN)
573 $profile_select = contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false));
575 if (in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS)) AND
576 ($contact['rel'] == CONTACT_IS_FOLLOWER))
577 $follow = App::get_baseurl(true)."/follow?url=".urlencode($contact["url"]);
579 // Load contactact related actions like hide, suggest, delete and others
580 $contact_actions = contact_actions($contact);
583 $o .= replace_macros($tpl, array(
584 //'$header' => t('Contact Editor'),
585 '$header' => t("Contact"),
586 '$tab_str' => $tab_str,
587 '$submit' => t('Submit'),
588 '$lbl_vis1' => t('Profile Visibility'),
589 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
590 '$lbl_info1' => t('Contact Information / Notes'),
591 '$infedit' => t('Edit contact notes'),
592 '$common_text' => $common_text,
593 '$common_link' => 'common/loc/' . local_user() . '/' . $contact['id'],
594 '$all_friends' => $all_friends,
595 '$relation_text' => $relation_text,
596 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
597 '$blockunblock' => t('Block/Unblock contact'),
598 '$ignorecont' => t('Ignore contact'),
599 '$lblcrepair' => t("Repair URL settings"),
600 '$lblrecent' => t('View conversations'),
601 '$lblsuggest' => $lblsuggest,
602 //'$delete' => t('Delete contact'),
603 '$nettype' => $nettype,
604 '$poll_interval' => $poll_interval,
605 '$poll_enabled' => $poll_enabled,
606 '$lastupdtext' => t('Last update:'),
607 '$lost_contact' => $lost_contact,
608 '$updpub' => t('Update public posts'),
609 '$last_update' => $last_update,
610 '$udnow' => t('Update now'),
611 '$follow' => $follow,
612 '$follow_text' => t("Connect/Follow"),
613 '$profile_select' => $profile_select,
614 '$contact_id' => $contact['id'],
615 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
616 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
617 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
618 '$info' => $contact['info'],
619 '$cinfo' => array('info', '', $contact['info'], ''),
620 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
621 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
622 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
623 '$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')),
624 '$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
625 '$fetch_further_information' => $fetch_further_information,
626 '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
627 '$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')),
628 '$photo' => $contact['photo'],
629 '$name' => htmlentities($contact['name']),
630 '$dir_icon' => $dir_icon,
631 '$alt_text' => $alt_text,
632 '$sparkle' => $sparkle,
634 '$profileurllabel' => t('Profile URL'),
635 '$profileurl' => $contact['url'],
636 '$account_type' => account_type($contact),
637 '$location' => bbcode($contact["location"]),
638 '$location_label' => t("Location:"),
639 '$xmpp' => bbcode($contact["xmpp"]),
640 '$xmpp_label' => t("XMPP:"),
641 '$about' => bbcode($contact["about"], false, false),
642 '$about_label' => t("About:"),
643 '$keywords' => $contact["keywords"],
644 '$keywords_label' => t("Tags:"),
645 '$contact_action_button' => t("Actions"),
646 '$contact_actions' => $contact_actions,
647 '$contact_status' => t("Status"),
648 '$contact_settings_label' => t('Contact Settings'),
649 '$contact_profile_label' => t("Profile"),
653 $arr = array('contact' => $contact,'output' => $o);
655 call_hooks('contact_edit', $arr);
657 return $arr['output'];
666 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
670 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
671 $sql_extra = " AND `blocked` = 1 ";
674 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
675 $sql_extra = " AND `hidden` = 1 ";
678 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
679 $sql_extra = " AND `readonly` = 1 ";
682 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
683 $sql_extra = " AND `archive` = 1 ";
687 $sql_extra = " AND `blocked` = 0 ";
689 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
690 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
694 'label' => t('Suggestions'),
697 'title' => t('Suggest potential friends'),
698 'id' => 'suggestions-tab',
702 'label' => t('All Contacts'),
703 'url' => 'contacts/all',
704 'sel' => ($all) ? 'active' : '',
705 'title' => t('Show all contacts'),
706 'id' => 'showall-tab',
710 'label' => t('Unblocked'),
712 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
713 'title' => t('Only show unblocked contacts'),
714 'id' => 'showunblocked-tab',
719 'label' => t('Blocked'),
720 'url' => 'contacts/blocked',
721 'sel' => ($blocked) ? 'active' : '',
722 'title' => t('Only show blocked contacts'),
723 'id' => 'showblocked-tab',
728 'label' => t('Ignored'),
729 'url' => 'contacts/ignored',
730 'sel' => ($ignored) ? 'active' : '',
731 'title' => t('Only show ignored contacts'),
732 'id' => 'showignored-tab',
737 'label' => t('Archived'),
738 'url' => 'contacts/archived',
739 'sel' => ($archived) ? 'active' : '',
740 'title' => t('Only show archived contacts'),
741 'id' => 'showarchived-tab',
746 'label' => t('Hidden'),
747 'url' => 'contacts/hidden',
748 'sel' => ($hidden) ? 'active' : '',
749 'title' => t('Only show hidden contacts'),
750 'id' => 'showhidden-tab',
756 $tab_tpl = get_markup_template('common_tabs.tpl');
757 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
763 $search_hdr = $search;
764 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
767 $sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') " : "");
770 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
772 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
775 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
776 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
777 intval($_SESSION['uid']));
778 if (dbm::is_result($r)) {
779 $a->set_pager_total($r[0]['total']);
780 $total = $r[0]['total'];
783 $sql_extra3 = unavailable_networks();
785 $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 ",
786 intval($_SESSION['uid']),
787 intval($a->pager['start']),
788 intval($a->pager['itemspage'])
793 if (dbm::is_result($r)) {
794 foreach ($r as $rr) {
795 $contacts[] = _contact_detail_for_template($rr);
799 $tpl = get_markup_template("contacts-template.tpl");
800 $o .= replace_macros($tpl, array(
801 '$baseurl' => z_root(),
802 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
805 '$search' => $search_hdr,
806 '$desc' => t('Search your contacts'),
807 '$finding' => (($searching) ? sprintf(t('Results for: %s'),$search) : ""),
808 '$submit' => t('Find'),
810 '$contacts' => $contacts,
811 '$contact_drop_confirm' => t('Do you really want to delete this contact?'),
813 '$batch_actions' => array(
814 'contacts_batch_update' => t('Update'),
815 'contacts_batch_block' => t('Block')."/".t("Unblock"),
816 "contacts_batch_ignore" => t('Ignore')."/".t("Unignore"),
817 "contacts_batch_archive" => t('Archive')."/".t("Unarchive"),
818 "contacts_batch_drop" => t('Delete'),
820 '$h_batch_actions' => t('Batch Actions'),
821 '$paginate' => paginate($a),
829 * @brief List of pages for the Contact TabBar
831 * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
834 * @param int $contact_id The ID of the contact
835 * @param int $active_tab 1 if tab should be marked as active
837 * @return array with with contact TabBar data
839 function contacts_tab($a, $contact_id, $active_tab) {
843 'label'=>t('Status'),
844 'url' => "contacts/".$contact_id."/posts",
845 'sel' => (($active_tab == 1)?'active':''),
846 'title' => t('Status Messages and Posts'),
847 'id' => 'status-tab',
851 'label'=>t('Profile'),
852 'url' => "contacts/".$contact_id,
853 'sel' => (($active_tab == 2)?'active':''),
854 'title' => t('Profile Details'),
855 'id' => 'status-tab',
860 // Show this tab only if there is visible friend list
861 $x = count_all_friends(local_user(), $contact_id);
863 $tabs[] = array('label'=>t('Contacts'),
864 'url' => "allfriends/".$contact_id,
865 'sel' => (($active_tab == 3)?'active':''),
866 'title' => t('View all contacts'),
867 'id' => 'allfriends-tab',
870 // Show this tab only if there is visible common friend list
871 $common = count_common_friends(local_user(),$contact_id);
873 $tabs[] = array('label'=>t('Common Friends'),
874 'url' => "common/loc/".local_user()."/".$contact_id,
875 'sel' => (($active_tab == 4)?'active':''),
876 'title' => t('View all common friends'),
877 'id' => 'common-loc-tab',
880 $tabs[] = array('label' => t('Advanced'),
881 'url' => 'crepair/' . $contact_id,
882 'sel' => (($active_tab == 5)?'active':''),
883 'title' => t('Advanced Contact Settings'),
884 'id' => 'advanced-tab',
887 $tab_tpl = get_markup_template('common_tabs.tpl');
888 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
893 function contact_posts($a, $contact_id) {
895 $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id));
898 $a->page['aside'] = "";
899 profile_load($a, "", 0, get_contact_details_by_url($contact["url"]));
903 $tab_str = contacts_tab($a, $contact_id, 1);
907 $o .= posts_from_contact_url($a, $contact["url"]);
912 function _contact_detail_for_template($rr){
915 case CONTACT_IS_FRIEND:
916 $dir_icon = 'images/lrarrow.gif';
917 $alt_text = t('Mutual Friendship');
919 case CONTACT_IS_FOLLOWER;
920 $dir_icon = 'images/larrow.gif';
921 $alt_text = t('is a fan of yours');
923 case CONTACT_IS_SHARING;
924 $dir_icon = 'images/rarrow.gif';
925 $alt_text = t('you are a fan of');
930 if(($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) {
931 $url = "redir/{$rr['id']}";
932 $sparkle = ' class="sparkle" ';
940 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
941 'edit_hover' => t('Edit contact'),
942 'photo_menu' => contact_photo_menu($rr),
944 'alt_text' => $alt_text,
945 'dir_icon' => $dir_icon,
946 'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB),
947 'name' => htmlentities($rr['name']),
948 'username' => htmlentities($rr['name']),
949 'account_type' => account_type($rr),
950 'sparkle' => $sparkle,
951 'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']),
953 'network' => network_to_name($rr['network'], $rr['url']),
959 * @brief Gives a array with actions which can performed to a given contact
961 * This includes actions like e.g. 'block', 'hide', 'archive', 'delete' and others
963 * @param array $contact Data about the Contact
964 * @return array with contact related actions
966 function contact_actions($contact) {
968 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
969 $contact_action = array();
971 // Provide friend suggestion only for Friendica contacts
972 if($contact['network'] === NETWORK_DFRN) {
973 $contact_actions['suggest'] = array(
974 'label' => t('Suggest friends'),
975 'url' => 'fsuggest/' . $contact['id'],
983 $contact_actions['update'] = array(
984 'label' => t('Update now'),
985 'url' => 'contacts/' . $contact['id'] . '/update',
992 $contact_actions['block'] = array(
993 'label' => (intval($contact['blocked']) ? t('Unblock') : t('Block') ),
994 'url' => 'contacts/' . $contact['id'] . '/block',
995 'title' => t('Toggle Blocked status'),
996 'sel' => (intval($contact['blocked']) ? 'active' : ''),
997 'id' => 'toggle-block',
1000 $contact_actions['ignore'] = array(
1001 'label' => (intval($contact['readonly']) ? t('Unignore') : t('Ignore') ),
1002 'url' => 'contacts/' . $contact['id'] . '/ignore',
1003 'title' => t('Toggle Ignored status'),
1004 'sel' => (intval($contact['readonly']) ? 'active' : ''),
1005 'id' => 'toggle-ignore',
1008 $contact_actions['archive'] = array(
1009 'label' => (intval($contact['archive']) ? t('Unarchive') : t('Archive') ),
1010 'url' => 'contacts/' . $contact['id'] . '/archive',
1011 'title' => t('Toggle Archive status'),
1012 'sel' => (intval($contact['archive']) ? 'active' : ''),
1013 'id' => 'toggle-archive',
1016 $contact_actions['delete'] = array(
1017 'label' => t('Delete'),
1018 'url' => 'contacts/' . $contact['id'] . '/drop',
1019 'title' => t('Delete contact'),
1024 return $contact_actions;