3 * @file mod/contacts.php
6 use Friendica\Core\System;
7 use Friendica\Core\Worker;
8 use Friendica\Database\DBM;
9 use Friendica\Model\Contact;
10 use Friendica\Model\GContact;
11 use Friendica\Model\Group;
12 use Friendica\Network\Probe;
14 require_once 'include/contact_selectors.php';
15 require_once 'mod/proxy.php';
17 function contacts_init(App $a) {
24 if((($a->argc == 2) && intval($a->argv[1])) || (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) {
25 $contact_id = intval($a->argv[1]);
26 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
30 if (! DBM::is_result($r)) {
35 require_once 'include/contact_widgets.php';
37 if ($_GET['nets'] == "all") {
41 if (! x($a->page,'aside')) {
42 $a->page['aside'] = '';
46 $a->data['contact'] = $r[0];
48 if (($a->data['contact']['network'] != "") && ($a->data['contact']['network'] != NETWORK_DFRN)) {
49 $networkname = format_network_name($a->data['contact']['network'],$a->data['contact']['url']);
54 /// @TODO Add nice spaces
55 $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array(
56 '$name' => htmlentities($a->data['contact']['name']),
57 '$photo' => $a->data['contact']['photo'],
58 '$url' => ($a->data['contact']['network'] == NETWORK_DFRN) ? "redir/".$a->data['contact']['id'] : $a->data['contact']['url'],
59 '$addr' => (($a->data['contact']['addr'] != "") ? ($a->data['contact']['addr']) : ""),
60 '$network_name' => $networkname,
61 '$network' => t('Network:'),
62 '$account_type' => Contact::getAccountType($a->data['contact'])
65 $finpeople_widget = '';
67 $networks_widget = '';
70 $networks_widget .= networks_widget('contacts',$_GET['nets']);
71 if (isset($_GET['add'])) {
72 $follow_widget = follow_widget($_GET['add']);
74 $follow_widget = follow_widget();
77 $findpeople_widget .= findpeople_widget();
80 $groups_widget .= Group::sidebarWidget('contacts','group','full',0,$contact_id);
82 $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"),array(
83 '$vcard_widget' => $vcard_widget,
84 '$findpeople_widget' => $findpeople_widget,
85 '$follow_widget' => $follow_widget,
86 '$groups_widget' => $groups_widget,
87 '$networks_widget' => $networks_widget
90 $base = System::baseUrl();
91 $tpl = get_markup_template("contacts-head.tpl");
92 $a->page['htmlhead'] .= replace_macros($tpl,array(
93 '$baseurl' => System::baseUrl(true),
97 $tpl = get_markup_template("contacts-end.tpl");
98 $a->page['end'] .= replace_macros($tpl,array(
99 '$baseurl' => System::baseUrl(true),
106 function contacts_batch_actions(App $a) {
107 $contacts_id = $_POST['contact_batch'];
108 if (!is_array($contacts_id)) return;
110 $orig_records = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND `uid` = %d AND `self` = 0",
111 implode(",", $contacts_id),
116 foreach($orig_records as $orig_record) {
117 $contact_id = $orig_record['id'];
118 if (x($_POST, 'contacts_batch_update')) {
119 _contact_update($contact_id);
122 if (x($_POST, 'contacts_batch_block')) {
123 $r = _contact_block($contact_id, $orig_record);
124 if ($r) $count_actions++;
126 if (x($_POST, 'contacts_batch_ignore')) {
127 $r = _contact_ignore($contact_id, $orig_record);
128 if ($r) $count_actions++;
130 if (x($_POST, 'contacts_batch_archive')) {
131 $r = _contact_archive($contact_id, $orig_record);
132 if ($r) $count_actions++;
134 if (x($_POST, 'contacts_batch_drop')) {
135 _contact_drop($orig_record);
139 if ($count_actions>0) {
140 info ( sprintf( tt("%d contact edited.", "%d contacts edited.", $count_actions), $count_actions) );
143 if (x($_SESSION,'return_url')) {
144 goaway('' . $_SESSION['return_url']);
153 function contacts_post(App $a) {
155 if (! local_user()) {
159 if ($a->argv[1]==="batch") {
160 contacts_batch_actions($a);
164 $contact_id = intval($a->argv[1]);
169 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
174 if (! count($orig_record)) {
175 notice( t('Could not access contact record.') . EOL);
177 return; // NOTREACHED
180 call_hooks('contact_edit_post', $_POST);
182 $profile_id = intval($_POST['profile-assign']);
184 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
188 if (! DBM::is_result($r)) {
189 notice( t('Could not locate selected profile.') . EOL);
194 $hidden = intval($_POST['hidden']);
196 $notify = intval($_POST['notify']);
198 $fetch_further_information = intval($_POST['fetch_further_information']);
200 $ffi_keyword_blacklist = escape_tags(trim($_POST['ffi_keyword_blacklist']));
202 $priority = intval($_POST['poll']);
203 if($priority > 5 || $priority < 0)
206 $info = escape_tags(trim($_POST['info']));
208 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
209 `hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d,
210 `ffi_keyword_blacklist` = '%s' WHERE `id` = %d AND `uid` = %d",
216 intval($fetch_further_information),
217 dbesc($ffi_keyword_blacklist),
222 info( t('Contact updated.') . EOL);
224 notice( t('Failed to update contact record.') . EOL);
226 $r = q("select * from contact where id = %d and uid = %d limit 1",
230 if($r && DBM::is_result($r))
231 $a->data['contact'] = $r[0];
238 function _contact_update($contact_id) {
239 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
245 if ($uid != local_user())
248 if ($r[0]["network"] == NETWORK_OSTATUS) {
249 $result = new_contact($uid, $r[0]["url"], false, $r[0]["network"]);
251 if ($result['success'])
252 $r = q("UPDATE `contact` SET `subhub` = 1 WHERE `id` = %d",
253 intval($contact_id));
255 // pull feed and consume it, which should subscribe to the hub.
256 Worker::add(PRIORITY_HIGH, "OnePoll", $contact_id, "force");
259 function _contact_update_profile($contact_id) {
260 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
266 if ($uid != local_user())
269 $data = Probe::uri($r[0]["url"], "", 0, false);
271 // "Feed" or "Unknown" is mostly a sign of communication problems
272 if ((in_array($data["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) && ($data["network"] != $r[0]["network"]))
275 $updatefields = array("name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm",
276 "poco", "network", "alias");
279 if ($data["network"] == NETWORK_OSTATUS) {
280 $result = new_contact($uid, $data["url"], false);
282 if ($result['success'])
283 $update["subhub"] = true;
286 foreach($updatefields AS $field)
287 if (isset($data[$field]) && ($data[$field] != ""))
288 $update[$field] = $data[$field];
290 $update["nurl"] = normalise_link($data["url"]);
294 if (isset($data["priority"]) && ($data["priority"] != 0))
295 $query = "`priority` = ".intval($data["priority"]);
297 foreach($update AS $key => $value) {
301 $query .= "`".$key."` = '".dbesc($value)."'";
307 $r = q("UPDATE `contact` SET $query WHERE `id` = %d AND `uid` = %d",
312 // Update the entry in the contact table
313 Contact::updateAvatar($data['photo'], local_user(), $contact_id, true);
315 // Update the entry in the gcontact table
316 GContact::updateFromProbe($data["url"]);
319 function _contact_block($contact_id, $orig_record) {
320 $blocked = (($orig_record['blocked']) ? 0 : 1);
321 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d",
329 function _contact_ignore($contact_id, $orig_record) {
330 $readonly = (($orig_record['readonly']) ? 0 : 1);
331 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d",
338 function _contact_archive($contact_id, $orig_record) {
339 $archived = (($orig_record['archive']) ? 0 : 1);
340 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d",
346 q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
351 function _contact_drop($orig_record)
355 $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
356 WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
357 intval($a->user['uid'])
359 if (!DBM::is_result($r)) {
363 Contact::terminateFriendship($r[0], $orig_record);
364 Contact::remove($orig_record['id']);
368 function contacts_content(App $a) {
372 nav_set_selected('contacts');
375 if (! local_user()) {
376 notice( t('Permission denied.') . EOL);
382 $contact_id = intval($a->argv[1]);
388 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
393 if(! count($orig_record)) {
394 notice( t('Could not access contact record.') . EOL);
396 return; // NOTREACHED
399 if($cmd === 'update') {
400 _contact_update($contact_id);
401 goaway('contacts/' . $contact_id);
405 if($cmd === 'updateprofile') {
406 _contact_update_profile($contact_id);
407 goaway('crepair/' . $contact_id);
411 if($cmd === 'block') {
412 $r = _contact_block($contact_id, $orig_record[0]);
414 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
415 info((($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')).EOL);
418 goaway('contacts/' . $contact_id);
419 return; // NOTREACHED
422 if($cmd === 'ignore') {
423 $r = _contact_ignore($contact_id, $orig_record[0]);
425 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
426 info((($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')).EOL);
429 goaway('contacts/' . $contact_id);
430 return; // NOTREACHED
434 if($cmd === 'archive') {
435 $r = _contact_archive($contact_id, $orig_record[0]);
437 $archived = (($orig_record[0]['archive']) ? 0 : 1);
438 info((($archived) ? t('Contact has been archived') : t('Contact has been unarchived')).EOL);
441 goaway('contacts/' . $contact_id);
442 return; // NOTREACHED
445 if($cmd === 'drop') {
447 // Check if we should do HTML-based delete confirmation
448 if($_REQUEST['confirm']) {
449 // <form> can't take arguments in its "action" parameter
450 // so add any arguments as hidden inputs
451 $query = explode_querystring($a->query_string);
453 foreach($query['args'] as $arg) {
454 if(strpos($arg, 'confirm=') === false) {
455 $arg_parts = explode('=', $arg);
456 $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
460 $a->page['aside'] = '';
462 return replace_macros(get_markup_template('contact_drop_confirm.tpl'), array(
463 '$header' => t('Drop contact'),
464 '$contact' => _contact_detail_for_template($orig_record[0]),
466 '$message' => t('Do you really want to delete this contact?'),
467 '$extra_inputs' => $inputs,
468 '$confirm' => t('Yes'),
469 '$confirm_url' => $query['base'],
470 '$confirm_name' => 'confirmed',
471 '$cancel' => t('Cancel'),
474 // Now check how the user responded to the confirmation query
475 if ($_REQUEST['canceled']) {
476 if (x($_SESSION,'return_url')) {
477 goaway('' . $_SESSION['return_url']);
484 _contact_drop($orig_record[0]);
485 info( t('Contact has been removed.') . EOL );
486 if (x($_SESSION,'return_url')) {
487 goaway('' . $_SESSION['return_url']);
492 return; // NOTREACHED
494 if ($cmd === 'posts') {
495 return contact_posts($a, $contact_id);
501 $_SESSION['return_url'] = $a->query_string;
503 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
505 $contact_id = $a->data['contact']['id'];
506 $contact = $a->data['contact'];
508 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
509 '$baseurl' => System::baseUrl(true),
511 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
512 '$baseurl' => System::baseUrl(true),
515 require_once 'include/contact_selectors.php';
517 $tpl = get_markup_template("contact_edit.tpl");
519 switch($contact['rel']) {
520 case CONTACT_IS_FRIEND:
521 $dir_icon = 'images/lrarrow.gif';
522 $relation_text = t('You are mutual friends with %s');
524 case CONTACT_IS_FOLLOWER;
525 $dir_icon = 'images/larrow.gif';
526 $relation_text = t('You are sharing with %s');
529 case CONTACT_IS_SHARING;
530 $dir_icon = 'images/rarrow.gif';
531 $relation_text = t('%s is sharing with you');
537 if(!in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
540 $relation_text = sprintf($relation_text,htmlentities($contact['name']));
542 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
543 $url = "redir/{$contact['id']}";
544 $sparkle = ' class="sparkle" ';
547 $url = $contact['url'];
551 $insecure = t('Private communications are not available for this contact.');
553 $last_update = (($contact['last-update'] <= NULL_DATE)
555 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
557 if ($contact['last-update'] > NULL_DATE) {
558 $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
560 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
562 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL));
564 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network'], $contact["url"]));
566 //$common = GlobalContact::countCommonFriends(local_user(),$contact['id']);
567 //$common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
569 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
571 //$x = GlobalContact::countAllFriends(local_user(), $contact['id']);
572 //$all_friends = (($x) ? t('View all contacts') : '');
575 $tab_str = contacts_tab($a, $contact_id, 2);
577 $lost_contact = (($contact['archive'] && $contact['term-date'] > NULL_DATE && $contact['term-date'] < datetime_convert('','','now')) ? t('Communications lost with this contact!') : '');
579 if ($contact['network'] == NETWORK_FEED) {
580 $fetch_further_information = array('fetch_further_information',
581 t('Fetch further information for feeds'),
582 $contact['fetch_further_information'],
583 t("Fetch information like preview pictures, title and teaser from the feed item. You can activate this if the feed doesn't contain much text. Keywords are taken from the meta header in the feed item and are posted as hash tags."),
584 array('0' => t('Disabled'),
585 '1' => t('Fetch information'),
586 '3' => t('Fetch keywords'),
587 '2' => t('Fetch information and keywords')));
589 if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL)))
590 $poll_interval = contact_poll_interval($contact['priority'],(! $poll_enabled));
592 if ($contact['network'] == NETWORK_DFRN)
593 $profile_select = contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false));
595 if (in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS))) {
596 if ($contact['rel'] == CONTACT_IS_FOLLOWER) {
597 $follow = System::baseUrl(true)."/follow?url=".urlencode($contact["url"]);
598 $follow_text = t("Connect/Follow");
599 } elseif ($contact['rel'] == CONTACT_IS_FRIEND) {
600 $follow = System::baseUrl(true)."/unfollow?url=".urlencode($contact["url"]);
601 $follow_text = t("Disconnect/Unfollow");
605 // Load contactact related actions like hide, suggest, delete and others
606 $contact_actions = contact_actions($contact);
609 $o .= replace_macros($tpl, array(
610 //'$header' => t('Contact Editor'),
611 '$header' => t("Contact"),
612 '$tab_str' => $tab_str,
613 '$submit' => t('Submit'),
614 '$lbl_vis1' => t('Profile Visibility'),
615 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
616 '$lbl_info1' => t('Contact Information / Notes'),
617 '$lbl_info2' => t('Their personal note'),
618 '$reason' => trim(notags($contact['reason'])),
619 '$infedit' => t('Edit contact notes'),
620 '$common_text' => $common_text,
621 '$common_link' => 'common/loc/' . local_user() . '/' . $contact['id'],
622 '$all_friends' => $all_friends,
623 '$relation_text' => $relation_text,
624 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
625 '$blockunblock' => t('Block/Unblock contact'),
626 '$ignorecont' => t('Ignore contact'),
627 '$lblcrepair' => t("Repair URL settings"),
628 '$lblrecent' => t('View conversations'),
629 '$lblsuggest' => $lblsuggest,
630 //'$delete' => t('Delete contact'),
631 '$nettype' => $nettype,
632 '$poll_interval' => $poll_interval,
633 '$poll_enabled' => $poll_enabled,
634 '$lastupdtext' => t('Last update:'),
635 '$lost_contact' => $lost_contact,
636 '$updpub' => t('Update public posts'),
637 '$last_update' => $last_update,
638 '$udnow' => t('Update now'),
639 '$follow' => $follow,
640 '$follow_text' => $follow_text,
641 '$profile_select' => $profile_select,
642 '$contact_id' => $contact['id'],
643 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
644 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
645 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
646 '$info' => $contact['info'],
647 '$cinfo' => array('info', '', $contact['info'], ''),
648 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
649 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
650 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
651 '$pending' => (($contact['pending']) ? t('Awaiting connection acknowledge') : ''),
652 '$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')),
653 '$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
654 '$fetch_further_information' => $fetch_further_information,
655 '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
656 '$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')),
657 '$photo' => $contact['photo'],
658 '$name' => htmlentities($contact['name']),
659 '$dir_icon' => $dir_icon,
660 '$alt_text' => $alt_text,
661 '$sparkle' => $sparkle,
663 '$profileurllabel' => t('Profile URL'),
664 '$profileurl' => $contact['url'],
665 '$account_type' => Contact::getAccountType($contact),
666 '$location' => bbcode($contact["location"]),
667 '$location_label' => t("Location:"),
668 '$xmpp' => bbcode($contact["xmpp"]),
669 '$xmpp_label' => t("XMPP:"),
670 '$about' => bbcode($contact["about"], false, false),
671 '$about_label' => t("About:"),
672 '$keywords' => $contact["keywords"],
673 '$keywords_label' => t("Tags:"),
674 '$contact_action_button' => t("Actions"),
675 '$contact_actions' => $contact_actions,
676 '$contact_status' => t("Status"),
677 '$contact_settings_label' => t('Contact Settings'),
678 '$contact_profile_label' => t("Profile"),
682 $arr = array('contact' => $contact,'output' => $o);
684 call_hooks('contact_edit', $arr);
686 return $arr['output'];
695 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
699 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
700 $sql_extra = " AND `blocked` = 1 ";
703 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
704 $sql_extra = " AND `hidden` = 1 ";
707 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
708 $sql_extra = " AND `readonly` = 1 ";
711 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
712 $sql_extra = " AND `archive` = 1 ";
716 $sql_extra = " AND `blocked` = 0 ";
718 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
719 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
723 'label' => t('Suggestions'),
726 'title' => t('Suggest potential friends'),
727 'id' => 'suggestions-tab',
731 'label' => t('All Contacts'),
732 'url' => 'contacts/all',
733 'sel' => ($all) ? 'active' : '',
734 'title' => t('Show all contacts'),
735 'id' => 'showall-tab',
739 'label' => t('Unblocked'),
741 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
742 'title' => t('Only show unblocked contacts'),
743 'id' => 'showunblocked-tab',
748 'label' => t('Blocked'),
749 'url' => 'contacts/blocked',
750 'sel' => ($blocked) ? 'active' : '',
751 'title' => t('Only show blocked contacts'),
752 'id' => 'showblocked-tab',
757 'label' => t('Ignored'),
758 'url' => 'contacts/ignored',
759 'sel' => ($ignored) ? 'active' : '',
760 'title' => t('Only show ignored contacts'),
761 'id' => 'showignored-tab',
766 'label' => t('Archived'),
767 'url' => 'contacts/archived',
768 'sel' => ($archived) ? 'active' : '',
769 'title' => t('Only show archived contacts'),
770 'id' => 'showarchived-tab',
775 'label' => t('Hidden'),
776 'url' => 'contacts/hidden',
777 'sel' => ($hidden) ? 'active' : '',
778 'title' => t('Only show hidden contacts'),
779 'id' => 'showhidden-tab',
785 $tab_tpl = get_markup_template('common_tabs.tpl');
786 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
792 $search_hdr = $search;
793 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
796 $sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') " : "");
799 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
801 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
804 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
805 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
806 intval($_SESSION['uid']));
807 if (DBM::is_result($r)) {
808 $a->set_pager_total($r[0]['total']);
809 $total = $r[0]['total'];
812 $sql_extra3 = unavailable_networks();
814 $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 ",
815 intval($_SESSION['uid']),
816 intval($a->pager['start']),
817 intval($a->pager['itemspage'])
822 if (DBM::is_result($r)) {
823 foreach ($r as $rr) {
824 $contacts[] = _contact_detail_for_template($rr);
828 $tpl = get_markup_template("contacts-template.tpl");
829 $o .= replace_macros($tpl, array(
830 '$baseurl' => System::baseUrl(),
831 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
834 '$search' => $search_hdr,
835 '$desc' => t('Search your contacts'),
836 '$finding' => (($searching) ? sprintf(t('Results for: %s'),$search) : ""),
837 '$submit' => t('Find'),
839 '$contacts' => $contacts,
840 '$contact_drop_confirm' => t('Do you really want to delete this contact?'),
842 '$batch_actions' => array(
843 'contacts_batch_update' => t('Update'),
844 'contacts_batch_block' => t('Block')."/".t("Unblock"),
845 "contacts_batch_ignore" => t('Ignore')."/".t("Unignore"),
846 "contacts_batch_archive" => t('Archive')."/".t("Unarchive"),
847 "contacts_batch_drop" => t('Delete'),
849 '$h_batch_actions' => t('Batch Actions'),
850 '$paginate' => paginate($a),
858 * @brief List of pages for the Contact TabBar
860 * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
863 * @param int $contact_id The ID of the contact
864 * @param int $active_tab 1 if tab should be marked as active
866 * @return array with with contact TabBar data
868 function contacts_tab($a, $contact_id, $active_tab) {
872 'label'=>t('Status'),
873 'url' => "contacts/".$contact_id."/posts",
874 'sel' => (($active_tab == 1)?'active':''),
875 'title' => t('Status Messages and Posts'),
876 'id' => 'status-tab',
880 'label'=>t('Profile'),
881 'url' => "contacts/".$contact_id,
882 'sel' => (($active_tab == 2)?'active':''),
883 'title' => t('Profile Details'),
884 'id' => 'profile-tab',
889 // Show this tab only if there is visible friend list
890 $x = GContact::countAllFriends(local_user(), $contact_id);
892 $tabs[] = array('label'=>t('Contacts'),
893 'url' => "allfriends/".$contact_id,
894 'sel' => (($active_tab == 3)?'active':''),
895 'title' => t('View all contacts'),
896 'id' => 'allfriends-tab',
899 // Show this tab only if there is visible common friend list
900 $common = GContact::countCommonFriends(local_user(), $contact_id);
902 $tabs[] = array('label'=>t('Common Friends'),
903 'url' => "common/loc/".local_user()."/".$contact_id,
904 'sel' => (($active_tab == 4)?'active':''),
905 'title' => t('View all common friends'),
906 'id' => 'common-loc-tab',
909 $tabs[] = array('label' => t('Advanced'),
910 'url' => 'crepair/' . $contact_id,
911 'sel' => (($active_tab == 5)?'active':''),
912 'title' => t('Advanced Contact Settings'),
913 'id' => 'advanced-tab',
916 $tab_tpl = get_markup_template('common_tabs.tpl');
917 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
922 function contact_posts($a, $contact_id) {
924 $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id));
927 $a->page['aside'] = "";
928 profile_load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
932 $tab_str = contacts_tab($a, $contact_id, 1);
936 $o .= Contact::getPostsFromUrl($contact["url"]);
941 function _contact_detail_for_template($rr){
944 case CONTACT_IS_FRIEND:
945 $dir_icon = 'images/lrarrow.gif';
946 $alt_text = t('Mutual Friendship');
948 case CONTACT_IS_FOLLOWER;
949 $dir_icon = 'images/larrow.gif';
950 $alt_text = t('is a fan of yours');
952 case CONTACT_IS_SHARING;
953 $dir_icon = 'images/rarrow.gif';
954 $alt_text = t('you are a fan of');
959 if(($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) {
960 $url = "redir/{$rr['id']}";
961 $sparkle = ' class="sparkle" ';
969 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
970 'edit_hover' => t('Edit contact'),
971 'photo_menu' => Contact::photoMenu($rr),
973 'alt_text' => $alt_text,
974 'dir_icon' => $dir_icon,
975 'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB),
976 'name' => htmlentities($rr['name']),
977 'username' => htmlentities($rr['name']),
978 'account_type' => Contact::getAccountType($rr),
979 'sparkle' => $sparkle,
980 'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']),
982 'network' => network_to_name($rr['network'], $rr['url']),
988 * @brief Gives a array with actions which can performed to a given contact
990 * This includes actions like e.g. 'block', 'hide', 'archive', 'delete' and others
992 * @param array $contact Data about the Contact
993 * @return array with contact related actions
995 function contact_actions($contact) {
997 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL));
998 $contact_action = array();
1000 // Provide friend suggestion only for Friendica contacts
1001 if($contact['network'] === NETWORK_DFRN) {
1002 $contact_actions['suggest'] = array(
1003 'label' => t('Suggest friends'),
1004 'url' => 'fsuggest/' . $contact['id'],
1012 $contact_actions['update'] = array(
1013 'label' => t('Update now'),
1014 'url' => 'contacts/' . $contact['id'] . '/update',
1021 $contact_actions['block'] = array(
1022 'label' => (intval($contact['blocked']) ? t('Unblock') : t('Block') ),
1023 'url' => 'contacts/' . $contact['id'] . '/block',
1024 'title' => t('Toggle Blocked status'),
1025 'sel' => (intval($contact['blocked']) ? 'active' : ''),
1026 'id' => 'toggle-block',
1029 $contact_actions['ignore'] = array(
1030 'label' => (intval($contact['readonly']) ? t('Unignore') : t('Ignore') ),
1031 'url' => 'contacts/' . $contact['id'] . '/ignore',
1032 'title' => t('Toggle Ignored status'),
1033 'sel' => (intval($contact['readonly']) ? 'active' : ''),
1034 'id' => 'toggle-ignore',
1037 $contact_actions['archive'] = array(
1038 'label' => (intval($contact['archive']) ? t('Unarchive') : t('Archive') ),
1039 'url' => 'contacts/' . $contact['id'] . '/archive',
1040 'title' => t('Toggle Archive status'),
1041 'sel' => (intval($contact['archive']) ? 'active' : ''),
1042 'id' => 'toggle-archive',
1045 $contact_actions['delete'] = array(
1046 'label' => t('Delete'),
1047 'url' => 'contacts/' . $contact['id'] . '/drop',
1048 'title' => t('Delete contact'),
1053 return $contact_actions;