4 use Friendica\Network\Probe;
6 require_once 'include/Contact.php';
7 require_once 'include/socgraph.php';
8 require_once 'include/contact_selectors.php';
9 require_once 'include/probe.php';
10 require_once 'mod/proxy.php';
11 require_once 'include/Photo.php';
13 function contacts_init(App $a) {
20 if((($a->argc == 2) && intval($a->argv[1])) OR (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) {
21 $contact_id = intval($a->argv[1]);
22 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
26 if (! dbm::is_result($r)) {
31 require_once 'include/group.php';
32 require_once 'include/contact_widgets.php';
34 if ($_GET['nets'] == "all") {
38 if (! x($a->page,'aside')) {
39 $a->page['aside'] = '';
43 $a->data['contact'] = $r[0];
45 if (($a->data['contact']['network'] != "") AND ($a->data['contact']['network'] != NETWORK_DFRN)) {
46 $networkname = format_network_name($a->data['contact']['network'],$a->data['contact']['url']);
51 /// @TODO Add nice spaces
52 $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array(
53 '$name' => htmlentities($a->data['contact']['name']),
54 '$photo' => $a->data['contact']['photo'],
55 '$url' => ($a->data['contact']['network'] == NETWORK_DFRN) ? "redir/".$a->data['contact']['id'] : $a->data['contact']['url'],
56 '$addr' => (($a->data['contact']['addr'] != "") ? ($a->data['contact']['addr']) : ""),
57 '$network_name' => $networkname,
58 '$network' => t('Network:'),
59 '$account_type' => account_type($a->data['contact'])
62 $finpeople_widget = '';
64 $networks_widget = '';
67 $networks_widget .= networks_widget('contacts',$_GET['nets']);
68 if (isset($_GET['add'])) {
69 $follow_widget = follow_widget($_GET['add']);
71 $follow_widget = follow_widget();
74 $findpeople_widget .= findpeople_widget();
77 $groups_widget .= group_side('contacts','group','full',0,$contact_id);
79 $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"),array(
80 '$vcard_widget' => $vcard_widget,
81 '$findpeople_widget' => $findpeople_widget,
82 '$follow_widget' => $follow_widget,
83 '$groups_widget' => $groups_widget,
84 '$networks_widget' => $networks_widget
88 $tpl = get_markup_template("contacts-head.tpl");
89 $a->page['htmlhead'] .= replace_macros($tpl,array(
90 '$baseurl' => App::get_baseurl(true),
94 $tpl = get_markup_template("contacts-end.tpl");
95 $a->page['end'] .= replace_macros($tpl,array(
96 '$baseurl' => App::get_baseurl(true),
103 function contacts_batch_actions(App $a) {
104 $contacts_id = $_POST['contact_batch'];
105 if (!is_array($contacts_id)) return;
107 $orig_records = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND `uid` = %d AND `self` = 0",
108 implode(",", $contacts_id),
113 foreach($orig_records as $orig_record) {
114 $contact_id = $orig_record['id'];
115 if (x($_POST, 'contacts_batch_update')) {
116 _contact_update($contact_id);
119 if (x($_POST, 'contacts_batch_block')) {
120 $r = _contact_block($contact_id, $orig_record);
121 if ($r) $count_actions++;
123 if (x($_POST, 'contacts_batch_ignore')) {
124 $r = _contact_ignore($contact_id, $orig_record);
125 if ($r) $count_actions++;
127 if (x($_POST, 'contacts_batch_archive')) {
128 $r = _contact_archive($contact_id, $orig_record);
129 if ($r) $count_actions++;
131 if (x($_POST, 'contacts_batch_drop')) {
132 _contact_drop($contact_id, $orig_record);
136 if ($count_actions>0) {
137 info ( sprintf( tt("%d contact edited.", "%d contacts edited.", $count_actions), $count_actions) );
140 if (x($_SESSION,'return_url')) {
141 goaway('' . $_SESSION['return_url']);
150 function contacts_post(App $a) {
152 if (! local_user()) {
156 if ($a->argv[1]==="batch") {
157 contacts_batch_actions($a);
161 $contact_id = intval($a->argv[1]);
166 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
171 if (! count($orig_record)) {
172 notice( t('Could not access contact record.') . EOL);
174 return; // NOTREACHED
177 call_hooks('contact_edit_post', $_POST);
179 $profile_id = intval($_POST['profile-assign']);
181 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
185 if (! dbm::is_result($r)) {
186 notice( t('Could not locate selected profile.') . EOL);
191 $hidden = intval($_POST['hidden']);
193 $notify = intval($_POST['notify']);
195 $fetch_further_information = intval($_POST['fetch_further_information']);
197 $ffi_keyword_blacklist = escape_tags(trim($_POST['ffi_keyword_blacklist']));
199 $priority = intval($_POST['poll']);
200 if($priority > 5 || $priority < 0)
203 $info = escape_tags(trim($_POST['info']));
205 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
206 `hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d,
207 `ffi_keyword_blacklist` = '%s' WHERE `id` = %d AND `uid` = %d",
213 intval($fetch_further_information),
214 dbesc($ffi_keyword_blacklist),
219 info( t('Contact updated.') . EOL);
221 notice( t('Failed to update contact record.') . EOL);
223 $r = q("select * from contact where id = %d and uid = %d limit 1",
227 if($r && dbm::is_result($r))
228 $a->data['contact'] = $r[0];
235 function _contact_update($contact_id) {
236 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
242 if ($uid != local_user())
245 if ($r[0]["network"] == NETWORK_OSTATUS) {
246 $result = new_contact($uid, $r[0]["url"], false);
248 if ($result['success'])
249 $r = q("UPDATE `contact` SET `subhub` = 1 WHERE `id` = %d",
250 intval($contact_id));
252 // pull feed and consume it, which should subscribe to the hub.
253 proc_run(PRIORITY_HIGH, "include/onepoll.php", $contact_id, "force");
256 function _contact_update_profile($contact_id) {
257 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
263 if ($uid != local_user())
266 $data = Probe::uri($r[0]["url"], "", 0, false);
268 // "Feed" or "Unknown" is mostly a sign of communication problems
269 if ((in_array($data["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) AND ($data["network"] != $r[0]["network"]))
272 $updatefields = array("name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm",
273 "poco", "network", "alias");
276 if ($data["network"] == NETWORK_OSTATUS) {
277 $result = new_contact($uid, $data["url"], false);
279 if ($result['success'])
280 $update["subhub"] = true;
283 foreach($updatefields AS $field)
284 if (isset($data[$field]) AND ($data[$field] != ""))
285 $update[$field] = $data[$field];
287 $update["nurl"] = normalise_link($data["url"]);
291 if (isset($data["priority"]) AND ($data["priority"] != 0))
292 $query = "`priority` = ".intval($data["priority"]);
294 foreach($update AS $key => $value) {
298 $query .= "`".$key."` = '".dbesc($value)."'";
304 $r = q("UPDATE `contact` SET $query WHERE `id` = %d AND `uid` = %d",
309 // Update the entry in the contact table
310 update_contact_avatar($data['photo'], local_user(), $contact_id, true);
312 // Update the entry in the gcontact table
313 update_gcontact_from_probe($data["url"]);
316 function _contact_block($contact_id, $orig_record) {
317 $blocked = (($orig_record['blocked']) ? 0 : 1);
318 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d",
326 function _contact_ignore($contact_id, $orig_record) {
327 $readonly = (($orig_record['readonly']) ? 0 : 1);
328 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d",
335 function _contact_archive($contact_id, $orig_record) {
336 $archived = (($orig_record['archive']) ? 0 : 1);
337 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d",
343 q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
347 function _contact_drop($contact_id, $orig_record) {
350 terminate_friendship($a->user,$a->contact,$orig_record);
351 contact_remove($orig_record['id']);
355 function contacts_content(App $a) {
359 nav_set_selected('contacts');
362 if (! local_user()) {
363 notice( t('Permission denied.') . EOL);
369 $contact_id = intval($a->argv[1]);
375 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
380 if(! count($orig_record)) {
381 notice( t('Could not access contact record.') . EOL);
383 return; // NOTREACHED
386 if($cmd === 'update') {
387 _contact_update($contact_id);
388 goaway('contacts/' . $contact_id);
392 if($cmd === 'updateprofile') {
393 _contact_update_profile($contact_id);
394 goaway('crepair/' . $contact_id);
398 if($cmd === 'block') {
399 $r = _contact_block($contact_id, $orig_record[0]);
401 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
402 info((($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')).EOL);
405 goaway('contacts/' . $contact_id);
406 return; // NOTREACHED
409 if($cmd === 'ignore') {
410 $r = _contact_ignore($contact_id, $orig_record[0]);
412 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
413 info((($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')).EOL);
416 goaway('contacts/' . $contact_id);
417 return; // NOTREACHED
421 if($cmd === 'archive') {
422 $r = _contact_archive($contact_id, $orig_record[0]);
424 $archived = (($orig_record[0]['archive']) ? 0 : 1);
425 info((($archived) ? t('Contact has been archived') : t('Contact has been unarchived')).EOL);
428 goaway('contacts/' . $contact_id);
429 return; // NOTREACHED
432 if($cmd === 'drop') {
434 // Check if we should do HTML-based delete confirmation
435 if($_REQUEST['confirm']) {
436 // <form> can't take arguments in its "action" parameter
437 // so add any arguments as hidden inputs
438 $query = explode_querystring($a->query_string);
440 foreach($query['args'] as $arg) {
441 if(strpos($arg, 'confirm=') === false) {
442 $arg_parts = explode('=', $arg);
443 $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
447 $a->page['aside'] = '';
449 return replace_macros(get_markup_template('contact_drop_confirm.tpl'), array(
450 '$header' => t('Drop contact'),
451 '$contact' => _contact_detail_for_template($orig_record[0]),
453 '$message' => t('Do you really want to delete this contact?'),
454 '$extra_inputs' => $inputs,
455 '$confirm' => t('Yes'),
456 '$confirm_url' => $query['base'],
457 '$confirm_name' => 'confirmed',
458 '$cancel' => t('Cancel'),
461 // Now check how the user responded to the confirmation query
462 if ($_REQUEST['canceled']) {
463 if (x($_SESSION,'return_url')) {
464 goaway('' . $_SESSION['return_url']);
471 _contact_drop($contact_id, $orig_record[0]);
472 info( t('Contact has been removed.') . EOL );
473 if (x($_SESSION,'return_url')) {
474 goaway('' . $_SESSION['return_url']);
479 return; // NOTREACHED
481 if ($cmd === 'posts') {
482 return contact_posts($a, $contact_id);
488 $_SESSION['return_url'] = $a->query_string;
490 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
492 $contact_id = $a->data['contact']['id'];
493 $contact = $a->data['contact'];
495 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
496 '$baseurl' => App::get_baseurl(true),
498 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
499 '$baseurl' => App::get_baseurl(true),
502 require_once 'include/contact_selectors.php';
504 $tpl = get_markup_template("contact_edit.tpl");
506 switch($contact['rel']) {
507 case CONTACT_IS_FRIEND:
508 $dir_icon = 'images/lrarrow.gif';
509 $relation_text = t('You are mutual friends with %s');
511 case CONTACT_IS_FOLLOWER;
512 $dir_icon = 'images/larrow.gif';
513 $relation_text = t('You are sharing with %s');
516 case CONTACT_IS_SHARING;
517 $dir_icon = 'images/rarrow.gif';
518 $relation_text = t('%s is sharing with you');
524 if(!in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
527 $relation_text = sprintf($relation_text,htmlentities($contact['name']));
529 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
530 $url = "redir/{$contact['id']}";
531 $sparkle = ' class="sparkle" ';
534 $url = $contact['url'];
538 $insecure = t('Private communications are not available for this contact.');
540 $last_update = (($contact['last-update'] <= NULL_DATE)
542 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
544 if ($contact['last-update'] > NULL_DATE) {
545 $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
547 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
549 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
551 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network'], $contact["url"]));
553 //$common = count_common_friends(local_user(),$contact['id']);
554 //$common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
556 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
558 //$x = count_all_friends(local_user(), $contact['id']);
559 //$all_friends = (($x) ? t('View all contacts') : '');
562 $tab_str = contacts_tab($a, $contact_id, 2);
564 $lost_contact = (($contact['archive'] && $contact['term-date'] > NULL_DATE && $contact['term-date'] < datetime_convert('','','now')) ? t('Communications lost with this contact!') : '');
566 if ($contact['network'] == NETWORK_FEED) {
567 $fetch_further_information = array('fetch_further_information', t('Fetch further information for feeds'), $contact['fetch_further_information'], t('Fetch further information for feeds'),
568 array('0'=>t('Disabled'), '1'=>t('Fetch information'), '2'=>t('Fetch information and keywords')));
570 if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2)))
571 $poll_interval = contact_poll_interval($contact['priority'],(! $poll_enabled));
573 if ($contact['network'] == NETWORK_DFRN)
574 $profile_select = contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false));
576 if (in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS)) AND
577 ($contact['rel'] == CONTACT_IS_FOLLOWER))
578 $follow = App::get_baseurl(true)."/follow?url=".urlencode($contact["url"]);
580 // Load contactact related actions like hide, suggest, delete and others
581 $contact_actions = contact_actions($contact);
584 $o .= replace_macros($tpl, array(
585 //'$header' => t('Contact Editor'),
586 '$header' => t("Contact"),
587 '$tab_str' => $tab_str,
588 '$submit' => t('Submit'),
589 '$lbl_vis1' => t('Profile Visibility'),
590 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
591 '$lbl_info1' => t('Contact Information / Notes'),
592 '$infedit' => t('Edit contact notes'),
593 '$common_text' => $common_text,
594 '$common_link' => 'common/loc/' . local_user() . '/' . $contact['id'],
595 '$all_friends' => $all_friends,
596 '$relation_text' => $relation_text,
597 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
598 '$blockunblock' => t('Block/Unblock contact'),
599 '$ignorecont' => t('Ignore contact'),
600 '$lblcrepair' => t("Repair URL settings"),
601 '$lblrecent' => t('View conversations'),
602 '$lblsuggest' => $lblsuggest,
603 //'$delete' => t('Delete contact'),
604 '$nettype' => $nettype,
605 '$poll_interval' => $poll_interval,
606 '$poll_enabled' => $poll_enabled,
607 '$lastupdtext' => t('Last update:'),
608 '$lost_contact' => $lost_contact,
609 '$updpub' => t('Update public posts'),
610 '$last_update' => $last_update,
611 '$udnow' => t('Update now'),
612 '$follow' => $follow,
613 '$follow_text' => t("Connect/Follow"),
614 '$profile_select' => $profile_select,
615 '$contact_id' => $contact['id'],
616 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
617 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
618 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
619 '$info' => $contact['info'],
620 '$cinfo' => array('info', '', $contact['info'], ''),
621 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
622 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
623 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
624 '$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')),
625 '$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
626 '$fetch_further_information' => $fetch_further_information,
627 '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
628 '$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')),
629 '$photo' => $contact['photo'],
630 '$name' => htmlentities($contact['name']),
631 '$dir_icon' => $dir_icon,
632 '$alt_text' => $alt_text,
633 '$sparkle' => $sparkle,
635 '$profileurllabel' => t('Profile URL'),
636 '$profileurl' => $contact['url'],
637 '$account_type' => account_type($contact),
638 '$location' => bbcode($contact["location"]),
639 '$location_label' => t("Location:"),
640 '$xmpp' => bbcode($contact["xmpp"]),
641 '$xmpp_label' => t("XMPP:"),
642 '$about' => bbcode($contact["about"], false, false),
643 '$about_label' => t("About:"),
644 '$keywords' => $contact["keywords"],
645 '$keywords_label' => t("Tags:"),
646 '$contact_action_button' => t("Actions"),
647 '$contact_actions' => $contact_actions,
648 '$contact_status' => t("Status"),
649 '$contact_settings_label' => t('Contact Settings'),
650 '$contact_profile_label' => t("Profile"),
654 $arr = array('contact' => $contact,'output' => $o);
656 call_hooks('contact_edit', $arr);
658 return $arr['output'];
667 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
671 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
672 $sql_extra = " AND `blocked` = 1 ";
675 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
676 $sql_extra = " AND `hidden` = 1 ";
679 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
680 $sql_extra = " AND `readonly` = 1 ";
683 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
684 $sql_extra = " AND `archive` = 1 ";
688 $sql_extra = " AND `blocked` = 0 ";
690 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
691 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
695 'label' => t('Suggestions'),
698 'title' => t('Suggest potential friends'),
699 'id' => 'suggestions-tab',
703 'label' => t('All Contacts'),
704 'url' => 'contacts/all',
705 'sel' => ($all) ? 'active' : '',
706 'title' => t('Show all contacts'),
707 'id' => 'showall-tab',
711 'label' => t('Unblocked'),
713 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
714 'title' => t('Only show unblocked contacts'),
715 'id' => 'showunblocked-tab',
720 'label' => t('Blocked'),
721 'url' => 'contacts/blocked',
722 'sel' => ($blocked) ? 'active' : '',
723 'title' => t('Only show blocked contacts'),
724 'id' => 'showblocked-tab',
729 'label' => t('Ignored'),
730 'url' => 'contacts/ignored',
731 'sel' => ($ignored) ? 'active' : '',
732 'title' => t('Only show ignored contacts'),
733 'id' => 'showignored-tab',
738 'label' => t('Archived'),
739 'url' => 'contacts/archived',
740 'sel' => ($archived) ? 'active' : '',
741 'title' => t('Only show archived contacts'),
742 'id' => 'showarchived-tab',
747 'label' => t('Hidden'),
748 'url' => 'contacts/hidden',
749 'sel' => ($hidden) ? 'active' : '',
750 'title' => t('Only show hidden contacts'),
751 'id' => 'showhidden-tab',
757 $tab_tpl = get_markup_template('common_tabs.tpl');
758 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
764 $search_hdr = $search;
765 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
768 $sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') " : "");
771 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
773 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
776 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
777 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
778 intval($_SESSION['uid']));
779 if (dbm::is_result($r)) {
780 $a->set_pager_total($r[0]['total']);
781 $total = $r[0]['total'];
784 $sql_extra3 = unavailable_networks();
786 $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 ",
787 intval($_SESSION['uid']),
788 intval($a->pager['start']),
789 intval($a->pager['itemspage'])
794 if (dbm::is_result($r)) {
795 foreach ($r as $rr) {
796 $contacts[] = _contact_detail_for_template($rr);
800 $tpl = get_markup_template("contacts-template.tpl");
801 $o .= replace_macros($tpl, array(
802 '$baseurl' => z_root(),
803 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
806 '$search' => $search_hdr,
807 '$desc' => t('Search your contacts'),
808 '$finding' => (($searching) ? sprintf(t('Results for: %s'),$search) : ""),
809 '$submit' => t('Find'),
811 '$contacts' => $contacts,
812 '$contact_drop_confirm' => t('Do you really want to delete this contact?'),
814 '$batch_actions' => array(
815 'contacts_batch_update' => t('Update'),
816 'contacts_batch_block' => t('Block')."/".t("Unblock"),
817 "contacts_batch_ignore" => t('Ignore')."/".t("Unignore"),
818 "contacts_batch_archive" => t('Archive')."/".t("Unarchive"),
819 "contacts_batch_drop" => t('Delete'),
821 '$h_batch_actions' => t('Batch Actions'),
822 '$paginate' => paginate($a),
830 * @brief List of pages for the Contact TabBar
832 * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
835 * @param int $contact_id The ID of the contact
836 * @param int $active_tab 1 if tab should be marked as active
838 * @return array with with contact TabBar data
840 function contacts_tab($a, $contact_id, $active_tab) {
844 'label'=>t('Status'),
845 'url' => "contacts/".$contact_id."/posts",
846 'sel' => (($active_tab == 1)?'active':''),
847 'title' => t('Status Messages and Posts'),
848 'id' => 'status-tab',
852 'label'=>t('Profile'),
853 'url' => "contacts/".$contact_id,
854 'sel' => (($active_tab == 2)?'active':''),
855 'title' => t('Profile Details'),
856 'id' => 'status-tab',
861 // Show this tab only if there is visible friend list
862 $x = count_all_friends(local_user(), $contact_id);
864 $tabs[] = array('label'=>t('Contacts'),
865 'url' => "allfriends/".$contact_id,
866 'sel' => (($active_tab == 3)?'active':''),
867 'title' => t('View all contacts'),
868 'id' => 'allfriends-tab',
871 // Show this tab only if there is visible common friend list
872 $common = count_common_friends(local_user(),$contact_id);
874 $tabs[] = array('label'=>t('Common Friends'),
875 'url' => "common/loc/".local_user()."/".$contact_id,
876 'sel' => (($active_tab == 4)?'active':''),
877 'title' => t('View all common friends'),
878 'id' => 'common-loc-tab',
881 $tabs[] = array('label' => t('Advanced'),
882 'url' => 'crepair/' . $contact_id,
883 'sel' => (($active_tab == 5)?'active':''),
884 'title' => t('Advanced Contact Settings'),
885 'id' => 'advanced-tab',
888 $tab_tpl = get_markup_template('common_tabs.tpl');
889 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
894 function contact_posts($a, $contact_id) {
896 $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id));
899 $a->page['aside'] = "";
900 profile_load($a, "", 0, get_contact_details_by_url($contact["url"]));
904 $tab_str = contacts_tab($a, $contact_id, 1);
908 $o .= posts_from_contact_url($a, $contact["url"]);
913 function _contact_detail_for_template($rr){
916 case CONTACT_IS_FRIEND:
917 $dir_icon = 'images/lrarrow.gif';
918 $alt_text = t('Mutual Friendship');
920 case CONTACT_IS_FOLLOWER;
921 $dir_icon = 'images/larrow.gif';
922 $alt_text = t('is a fan of yours');
924 case CONTACT_IS_SHARING;
925 $dir_icon = 'images/rarrow.gif';
926 $alt_text = t('you are a fan of');
931 if(($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) {
932 $url = "redir/{$rr['id']}";
933 $sparkle = ' class="sparkle" ';
941 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
942 'edit_hover' => t('Edit contact'),
943 'photo_menu' => contact_photo_menu($rr),
945 'alt_text' => $alt_text,
946 'dir_icon' => $dir_icon,
947 'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB),
948 'name' => htmlentities($rr['name']),
949 'username' => htmlentities($rr['name']),
950 'account_type' => account_type($rr),
951 'sparkle' => $sparkle,
952 'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']),
954 'network' => network_to_name($rr['network'], $rr['url']),
960 * @brief Gives a array with actions which can performed to a given contact
962 * This includes actions like e.g. 'block', 'hide', 'archive', 'delete' and others
964 * @param array $contact Data about the Contact
965 * @return array with contact related actions
967 function contact_actions($contact) {
969 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
970 $contact_action = array();
972 // Provide friend suggestion only for Friendica contacts
973 if($contact['network'] === NETWORK_DFRN) {
974 $contact_actions['suggest'] = array(
975 'label' => t('Suggest friends'),
976 'url' => 'fsuggest/' . $contact['id'],
984 $contact_actions['update'] = array(
985 'label' => t('Update now'),
986 'url' => 'contacts/' . $contact['id'] . '/update',
993 $contact_actions['block'] = array(
994 'label' => (intval($contact['blocked']) ? t('Unblock') : t('Block') ),
995 'url' => 'contacts/' . $contact['id'] . '/block',
996 'title' => t('Toggle Blocked status'),
997 'sel' => (intval($contact['blocked']) ? 'active' : ''),
998 'id' => 'toggle-block',
1001 $contact_actions['ignore'] = array(
1002 'label' => (intval($contact['readonly']) ? t('Unignore') : t('Ignore') ),
1003 'url' => 'contacts/' . $contact['id'] . '/ignore',
1004 'title' => t('Toggle Ignored status'),
1005 'sel' => (intval($contact['readonly']) ? 'active' : ''),
1006 'id' => 'toggle-ignore',
1009 $contact_actions['archive'] = array(
1010 'label' => (intval($contact['archive']) ? t('Unarchive') : t('Archive') ),
1011 'url' => 'contacts/' . $contact['id'] . '/archive',
1012 'title' => t('Toggle Archive status'),
1013 'sel' => (intval($contact['archive']) ? 'active' : ''),
1014 'id' => 'toggle-archive',
1017 $contact_actions['delete'] = array(
1018 'label' => t('Delete'),
1019 'url' => 'contacts/' . $contact['id'] . '/drop',
1020 'title' => t('Delete contact'),
1025 return $contact_actions;