4 use Friendica\Core\System;
5 use Friendica\Core\Worker;
6 use Friendica\Database\DBM;
7 use Friendica\Model\GlobalContact;
8 use Friendica\Network\Probe;
9 use Friendica\Object\Contact;
11 require_once 'include/Contact.php';
12 require_once 'include/contact_selectors.php';
13 require_once 'mod/proxy.php';
14 require_once 'include/Photo.php';
16 function contacts_init(App $a) {
23 if((($a->argc == 2) && intval($a->argv[1])) || (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) {
24 $contact_id = intval($a->argv[1]);
25 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
29 if (! DBM::is_result($r)) {
34 require_once 'include/group.php';
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_side('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 update_contact_avatar($data['photo'], local_user(), $contact_id, true);
315 // Update the entry in the gcontact table
316 GlobalContact::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, NETWORK_MAIL2));
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', t('Fetch further information for feeds'), $contact['fetch_further_information'], t('Fetch further information for feeds'),
581 array('0'=>t('Disabled'), '1'=>t('Fetch information'), '2'=>t('Fetch information and keywords')));
583 if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2)))
584 $poll_interval = contact_poll_interval($contact['priority'],(! $poll_enabled));
586 if ($contact['network'] == NETWORK_DFRN)
587 $profile_select = contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false));
589 if (in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS))) {
590 if ($contact['rel'] == CONTACT_IS_FOLLOWER) {
591 $follow = System::baseUrl(true)."/follow?url=".urlencode($contact["url"]);
592 $follow_text = t("Connect/Follow");
593 } elseif ($contact['rel'] == CONTACT_IS_FRIEND) {
594 $follow = System::baseUrl(true)."/unfollow?url=".urlencode($contact["url"]);
595 $follow_text = t("Disconnect/Unfollow");
599 // Load contactact related actions like hide, suggest, delete and others
600 $contact_actions = contact_actions($contact);
603 $o .= replace_macros($tpl, array(
604 //'$header' => t('Contact Editor'),
605 '$header' => t("Contact"),
606 '$tab_str' => $tab_str,
607 '$submit' => t('Submit'),
608 '$lbl_vis1' => t('Profile Visibility'),
609 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
610 '$lbl_info1' => t('Contact Information / Notes'),
611 '$lbl_info2' => t('Their personal note'),
612 '$reason' => trim(notags($contact['reason'])),
613 '$infedit' => t('Edit contact notes'),
614 '$common_text' => $common_text,
615 '$common_link' => 'common/loc/' . local_user() . '/' . $contact['id'],
616 '$all_friends' => $all_friends,
617 '$relation_text' => $relation_text,
618 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
619 '$blockunblock' => t('Block/Unblock contact'),
620 '$ignorecont' => t('Ignore contact'),
621 '$lblcrepair' => t("Repair URL settings"),
622 '$lblrecent' => t('View conversations'),
623 '$lblsuggest' => $lblsuggest,
624 //'$delete' => t('Delete contact'),
625 '$nettype' => $nettype,
626 '$poll_interval' => $poll_interval,
627 '$poll_enabled' => $poll_enabled,
628 '$lastupdtext' => t('Last update:'),
629 '$lost_contact' => $lost_contact,
630 '$updpub' => t('Update public posts'),
631 '$last_update' => $last_update,
632 '$udnow' => t('Update now'),
633 '$follow' => $follow,
634 '$follow_text' => $follow_text,
635 '$profile_select' => $profile_select,
636 '$contact_id' => $contact['id'],
637 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
638 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
639 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
640 '$info' => $contact['info'],
641 '$cinfo' => array('info', '', $contact['info'], ''),
642 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
643 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
644 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
645 '$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')),
646 '$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
647 '$fetch_further_information' => $fetch_further_information,
648 '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
649 '$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')),
650 '$photo' => $contact['photo'],
651 '$name' => htmlentities($contact['name']),
652 '$dir_icon' => $dir_icon,
653 '$alt_text' => $alt_text,
654 '$sparkle' => $sparkle,
656 '$profileurllabel' => t('Profile URL'),
657 '$profileurl' => $contact['url'],
658 '$account_type' => Contact::getAccountType($contact),
659 '$location' => bbcode($contact["location"]),
660 '$location_label' => t("Location:"),
661 '$xmpp' => bbcode($contact["xmpp"]),
662 '$xmpp_label' => t("XMPP:"),
663 '$about' => bbcode($contact["about"], false, false),
664 '$about_label' => t("About:"),
665 '$keywords' => $contact["keywords"],
666 '$keywords_label' => t("Tags:"),
667 '$contact_action_button' => t("Actions"),
668 '$contact_actions' => $contact_actions,
669 '$contact_status' => t("Status"),
670 '$contact_settings_label' => t('Contact Settings'),
671 '$contact_profile_label' => t("Profile"),
675 $arr = array('contact' => $contact,'output' => $o);
677 call_hooks('contact_edit', $arr);
679 return $arr['output'];
688 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
692 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
693 $sql_extra = " AND `blocked` = 1 ";
696 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
697 $sql_extra = " AND `hidden` = 1 ";
700 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
701 $sql_extra = " AND `readonly` = 1 ";
704 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
705 $sql_extra = " AND `archive` = 1 ";
709 $sql_extra = " AND `blocked` = 0 ";
711 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
712 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
716 'label' => t('Suggestions'),
719 'title' => t('Suggest potential friends'),
720 'id' => 'suggestions-tab',
724 'label' => t('All Contacts'),
725 'url' => 'contacts/all',
726 'sel' => ($all) ? 'active' : '',
727 'title' => t('Show all contacts'),
728 'id' => 'showall-tab',
732 'label' => t('Unblocked'),
734 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
735 'title' => t('Only show unblocked contacts'),
736 'id' => 'showunblocked-tab',
741 'label' => t('Blocked'),
742 'url' => 'contacts/blocked',
743 'sel' => ($blocked) ? 'active' : '',
744 'title' => t('Only show blocked contacts'),
745 'id' => 'showblocked-tab',
750 'label' => t('Ignored'),
751 'url' => 'contacts/ignored',
752 'sel' => ($ignored) ? 'active' : '',
753 'title' => t('Only show ignored contacts'),
754 'id' => 'showignored-tab',
759 'label' => t('Archived'),
760 'url' => 'contacts/archived',
761 'sel' => ($archived) ? 'active' : '',
762 'title' => t('Only show archived contacts'),
763 'id' => 'showarchived-tab',
768 'label' => t('Hidden'),
769 'url' => 'contacts/hidden',
770 'sel' => ($hidden) ? 'active' : '',
771 'title' => t('Only show hidden contacts'),
772 'id' => 'showhidden-tab',
778 $tab_tpl = get_markup_template('common_tabs.tpl');
779 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
785 $search_hdr = $search;
786 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
789 $sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') " : "");
792 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
794 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
797 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
798 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
799 intval($_SESSION['uid']));
800 if (DBM::is_result($r)) {
801 $a->set_pager_total($r[0]['total']);
802 $total = $r[0]['total'];
805 $sql_extra3 = unavailable_networks();
807 $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 ",
808 intval($_SESSION['uid']),
809 intval($a->pager['start']),
810 intval($a->pager['itemspage'])
815 if (DBM::is_result($r)) {
816 foreach ($r as $rr) {
817 $contacts[] = _contact_detail_for_template($rr);
821 $tpl = get_markup_template("contacts-template.tpl");
822 $o .= replace_macros($tpl, array(
823 '$baseurl' => System::baseUrl(),
824 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
827 '$search' => $search_hdr,
828 '$desc' => t('Search your contacts'),
829 '$finding' => (($searching) ? sprintf(t('Results for: %s'),$search) : ""),
830 '$submit' => t('Find'),
832 '$contacts' => $contacts,
833 '$contact_drop_confirm' => t('Do you really want to delete this contact?'),
835 '$batch_actions' => array(
836 'contacts_batch_update' => t('Update'),
837 'contacts_batch_block' => t('Block')."/".t("Unblock"),
838 "contacts_batch_ignore" => t('Ignore')."/".t("Unignore"),
839 "contacts_batch_archive" => t('Archive')."/".t("Unarchive"),
840 "contacts_batch_drop" => t('Delete'),
842 '$h_batch_actions' => t('Batch Actions'),
843 '$paginate' => paginate($a),
851 * @brief List of pages for the Contact TabBar
853 * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
856 * @param int $contact_id The ID of the contact
857 * @param int $active_tab 1 if tab should be marked as active
859 * @return array with with contact TabBar data
861 function contacts_tab($a, $contact_id, $active_tab) {
865 'label'=>t('Status'),
866 'url' => "contacts/".$contact_id."/posts",
867 'sel' => (($active_tab == 1)?'active':''),
868 'title' => t('Status Messages and Posts'),
869 'id' => 'status-tab',
873 'label'=>t('Profile'),
874 'url' => "contacts/".$contact_id,
875 'sel' => (($active_tab == 2)?'active':''),
876 'title' => t('Profile Details'),
877 'id' => 'profile-tab',
882 // Show this tab only if there is visible friend list
883 $x = GlobalContact::countAllFriends(local_user(), $contact_id);
885 $tabs[] = array('label'=>t('Contacts'),
886 'url' => "allfriends/".$contact_id,
887 'sel' => (($active_tab == 3)?'active':''),
888 'title' => t('View all contacts'),
889 'id' => 'allfriends-tab',
892 // Show this tab only if there is visible common friend list
893 $common = GlobalContact::countCommonFriends(local_user(), $contact_id);
895 $tabs[] = array('label'=>t('Common Friends'),
896 'url' => "common/loc/".local_user()."/".$contact_id,
897 'sel' => (($active_tab == 4)?'active':''),
898 'title' => t('View all common friends'),
899 'id' => 'common-loc-tab',
902 $tabs[] = array('label' => t('Advanced'),
903 'url' => 'crepair/' . $contact_id,
904 'sel' => (($active_tab == 5)?'active':''),
905 'title' => t('Advanced Contact Settings'),
906 'id' => 'advanced-tab',
909 $tab_tpl = get_markup_template('common_tabs.tpl');
910 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
915 function contact_posts($a, $contact_id) {
917 $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id));
920 $a->page['aside'] = "";
921 profile_load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
925 $tab_str = contacts_tab($a, $contact_id, 1);
929 $o .= Contact::getPostsFromUrl($contact["url"]);
934 function _contact_detail_for_template($rr){
937 case CONTACT_IS_FRIEND:
938 $dir_icon = 'images/lrarrow.gif';
939 $alt_text = t('Mutual Friendship');
941 case CONTACT_IS_FOLLOWER;
942 $dir_icon = 'images/larrow.gif';
943 $alt_text = t('is a fan of yours');
945 case CONTACT_IS_SHARING;
946 $dir_icon = 'images/rarrow.gif';
947 $alt_text = t('you are a fan of');
952 if(($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) {
953 $url = "redir/{$rr['id']}";
954 $sparkle = ' class="sparkle" ';
962 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
963 'edit_hover' => t('Edit contact'),
964 'photo_menu' => Contact::photoMenu($rr),
966 'alt_text' => $alt_text,
967 'dir_icon' => $dir_icon,
968 'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB),
969 'name' => htmlentities($rr['name']),
970 'username' => htmlentities($rr['name']),
971 'account_type' => Contact::getAccountType($rr),
972 'sparkle' => $sparkle,
973 'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']),
975 'network' => network_to_name($rr['network'], $rr['url']),
981 * @brief Gives a array with actions which can performed to a given contact
983 * This includes actions like e.g. 'block', 'hide', 'archive', 'delete' and others
985 * @param array $contact Data about the Contact
986 * @return array with contact related actions
988 function contact_actions($contact) {
990 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
991 $contact_action = array();
993 // Provide friend suggestion only for Friendica contacts
994 if($contact['network'] === NETWORK_DFRN) {
995 $contact_actions['suggest'] = array(
996 'label' => t('Suggest friends'),
997 'url' => 'fsuggest/' . $contact['id'],
1005 $contact_actions['update'] = array(
1006 'label' => t('Update now'),
1007 'url' => 'contacts/' . $contact['id'] . '/update',
1014 $contact_actions['block'] = array(
1015 'label' => (intval($contact['blocked']) ? t('Unblock') : t('Block') ),
1016 'url' => 'contacts/' . $contact['id'] . '/block',
1017 'title' => t('Toggle Blocked status'),
1018 'sel' => (intval($contact['blocked']) ? 'active' : ''),
1019 'id' => 'toggle-block',
1022 $contact_actions['ignore'] = array(
1023 'label' => (intval($contact['readonly']) ? t('Unignore') : t('Ignore') ),
1024 'url' => 'contacts/' . $contact['id'] . '/ignore',
1025 'title' => t('Toggle Ignored status'),
1026 'sel' => (intval($contact['readonly']) ? 'active' : ''),
1027 'id' => 'toggle-ignore',
1030 $contact_actions['archive'] = array(
1031 'label' => (intval($contact['archive']) ? t('Unarchive') : t('Archive') ),
1032 'url' => 'contacts/' . $contact['id'] . '/archive',
1033 'title' => t('Toggle Archive status'),
1034 'sel' => (intval($contact['archive']) ? 'active' : ''),
1035 'id' => 'toggle-archive',
1038 $contact_actions['delete'] = array(
1039 'label' => t('Delete'),
1040 'url' => 'contacts/' . $contact['id'] . '/drop',
1041 'title' => t('Delete contact'),
1046 return $contact_actions;