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;
10 require_once 'include/Contact.php';
11 require_once 'include/contact_selectors.php';
12 require_once 'mod/proxy.php';
13 require_once 'include/Photo.php';
15 function contacts_init(App $a) {
22 if((($a->argc == 2) && intval($a->argv[1])) || (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) {
23 $contact_id = intval($a->argv[1]);
24 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
28 if (! DBM::is_result($r)) {
33 require_once 'include/group.php';
34 require_once 'include/contact_widgets.php';
36 if ($_GET['nets'] == "all") {
40 if (! x($a->page,'aside')) {
41 $a->page['aside'] = '';
45 $a->data['contact'] = $r[0];
47 if (($a->data['contact']['network'] != "") && ($a->data['contact']['network'] != NETWORK_DFRN)) {
48 $networkname = format_network_name($a->data['contact']['network'],$a->data['contact']['url']);
53 /// @TODO Add nice spaces
54 $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array(
55 '$name' => htmlentities($a->data['contact']['name']),
56 '$photo' => $a->data['contact']['photo'],
57 '$url' => ($a->data['contact']['network'] == NETWORK_DFRN) ? "redir/".$a->data['contact']['id'] : $a->data['contact']['url'],
58 '$addr' => (($a->data['contact']['addr'] != "") ? ($a->data['contact']['addr']) : ""),
59 '$network_name' => $networkname,
60 '$network' => t('Network:'),
61 '$account_type' => account_type($a->data['contact'])
64 $finpeople_widget = '';
66 $networks_widget = '';
69 $networks_widget .= networks_widget('contacts',$_GET['nets']);
70 if (isset($_GET['add'])) {
71 $follow_widget = follow_widget($_GET['add']);
73 $follow_widget = follow_widget();
76 $findpeople_widget .= findpeople_widget();
79 $groups_widget .= group_side('contacts','group','full',0,$contact_id);
81 $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"),array(
82 '$vcard_widget' => $vcard_widget,
83 '$findpeople_widget' => $findpeople_widget,
84 '$follow_widget' => $follow_widget,
85 '$groups_widget' => $groups_widget,
86 '$networks_widget' => $networks_widget
89 $base = System::baseUrl();
90 $tpl = get_markup_template("contacts-head.tpl");
91 $a->page['htmlhead'] .= replace_macros($tpl,array(
92 '$baseurl' => System::baseUrl(true),
96 $tpl = get_markup_template("contacts-end.tpl");
97 $a->page['end'] .= replace_macros($tpl,array(
98 '$baseurl' => System::baseUrl(true),
105 function contacts_batch_actions(App $a) {
106 $contacts_id = $_POST['contact_batch'];
107 if (!is_array($contacts_id)) return;
109 $orig_records = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND `uid` = %d AND `self` = 0",
110 implode(",", $contacts_id),
115 foreach($orig_records as $orig_record) {
116 $contact_id = $orig_record['id'];
117 if (x($_POST, 'contacts_batch_update')) {
118 _contact_update($contact_id);
121 if (x($_POST, 'contacts_batch_block')) {
122 $r = _contact_block($contact_id, $orig_record);
123 if ($r) $count_actions++;
125 if (x($_POST, 'contacts_batch_ignore')) {
126 $r = _contact_ignore($contact_id, $orig_record);
127 if ($r) $count_actions++;
129 if (x($_POST, 'contacts_batch_archive')) {
130 $r = _contact_archive($contact_id, $orig_record);
131 if ($r) $count_actions++;
133 if (x($_POST, 'contacts_batch_drop')) {
134 _contact_drop($contact_id, $orig_record);
138 if ($count_actions>0) {
139 info ( sprintf( tt("%d contact edited.", "%d contacts edited.", $count_actions), $count_actions) );
142 if (x($_SESSION,'return_url')) {
143 goaway('' . $_SESSION['return_url']);
152 function contacts_post(App $a) {
154 if (! local_user()) {
158 if ($a->argv[1]==="batch") {
159 contacts_batch_actions($a);
163 $contact_id = intval($a->argv[1]);
168 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
173 if (! count($orig_record)) {
174 notice( t('Could not access contact record.') . EOL);
176 return; // NOTREACHED
179 call_hooks('contact_edit_post', $_POST);
181 $profile_id = intval($_POST['profile-assign']);
183 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
187 if (! DBM::is_result($r)) {
188 notice( t('Could not locate selected profile.') . EOL);
193 $hidden = intval($_POST['hidden']);
195 $notify = intval($_POST['notify']);
197 $fetch_further_information = intval($_POST['fetch_further_information']);
199 $ffi_keyword_blacklist = escape_tags(trim($_POST['ffi_keyword_blacklist']));
201 $priority = intval($_POST['poll']);
202 if($priority > 5 || $priority < 0)
205 $info = escape_tags(trim($_POST['info']));
207 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
208 `hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d,
209 `ffi_keyword_blacklist` = '%s' WHERE `id` = %d AND `uid` = %d",
215 intval($fetch_further_information),
216 dbesc($ffi_keyword_blacklist),
221 info( t('Contact updated.') . EOL);
223 notice( t('Failed to update contact record.') . EOL);
225 $r = q("select * from contact where id = %d and uid = %d limit 1",
229 if($r && DBM::is_result($r))
230 $a->data['contact'] = $r[0];
237 function _contact_update($contact_id) {
238 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
244 if ($uid != local_user())
247 if ($r[0]["network"] == NETWORK_OSTATUS) {
248 $result = new_contact($uid, $r[0]["url"], false, $r[0]["network"]);
250 if ($result['success'])
251 $r = q("UPDATE `contact` SET `subhub` = 1 WHERE `id` = %d",
252 intval($contact_id));
254 // pull feed and consume it, which should subscribe to the hub.
255 Worker::add(PRIORITY_HIGH, "OnePoll", $contact_id, "force");
258 function _contact_update_profile($contact_id) {
259 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
265 if ($uid != local_user())
268 $data = Probe::uri($r[0]["url"], "", 0, false);
270 // "Feed" or "Unknown" is mostly a sign of communication problems
271 if ((in_array($data["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) && ($data["network"] != $r[0]["network"]))
274 $updatefields = array("name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm",
275 "poco", "network", "alias");
278 if ($data["network"] == NETWORK_OSTATUS) {
279 $result = new_contact($uid, $data["url"], false);
281 if ($result['success'])
282 $update["subhub"] = true;
285 foreach($updatefields AS $field)
286 if (isset($data[$field]) && ($data[$field] != ""))
287 $update[$field] = $data[$field];
289 $update["nurl"] = normalise_link($data["url"]);
293 if (isset($data["priority"]) && ($data["priority"] != 0))
294 $query = "`priority` = ".intval($data["priority"]);
296 foreach($update AS $key => $value) {
300 $query .= "`".$key."` = '".dbesc($value)."'";
306 $r = q("UPDATE `contact` SET $query WHERE `id` = %d AND `uid` = %d",
311 // Update the entry in the contact table
312 update_contact_avatar($data['photo'], local_user(), $contact_id, true);
314 // Update the entry in the gcontact table
315 GlobalContact::updateFromProbe($data["url"]);
318 function _contact_block($contact_id, $orig_record) {
319 $blocked = (($orig_record['blocked']) ? 0 : 1);
320 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d",
328 function _contact_ignore($contact_id, $orig_record) {
329 $readonly = (($orig_record['readonly']) ? 0 : 1);
330 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d",
337 function _contact_archive($contact_id, $orig_record) {
338 $archived = (($orig_record['archive']) ? 0 : 1);
339 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d",
345 q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
349 function _contact_drop($contact_id, $orig_record) {
352 $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
353 WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
354 intval($a->user['uid'])
356 if (!DBM::is_result($r)) {
360 $self = ""; // Unused parameter
361 terminate_friendship($r[0], $self, $orig_record);
362 contact_remove($orig_record['id']);
366 function contacts_content(App $a) {
370 nav_set_selected('contacts');
373 if (! local_user()) {
374 notice( t('Permission denied.') . EOL);
380 $contact_id = intval($a->argv[1]);
386 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
391 if(! count($orig_record)) {
392 notice( t('Could not access contact record.') . EOL);
394 return; // NOTREACHED
397 if($cmd === 'update') {
398 _contact_update($contact_id);
399 goaway('contacts/' . $contact_id);
403 if($cmd === 'updateprofile') {
404 _contact_update_profile($contact_id);
405 goaway('crepair/' . $contact_id);
409 if($cmd === 'block') {
410 $r = _contact_block($contact_id, $orig_record[0]);
412 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
413 info((($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')).EOL);
416 goaway('contacts/' . $contact_id);
417 return; // NOTREACHED
420 if($cmd === 'ignore') {
421 $r = _contact_ignore($contact_id, $orig_record[0]);
423 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
424 info((($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')).EOL);
427 goaway('contacts/' . $contact_id);
428 return; // NOTREACHED
432 if($cmd === 'archive') {
433 $r = _contact_archive($contact_id, $orig_record[0]);
435 $archived = (($orig_record[0]['archive']) ? 0 : 1);
436 info((($archived) ? t('Contact has been archived') : t('Contact has been unarchived')).EOL);
439 goaway('contacts/' . $contact_id);
440 return; // NOTREACHED
443 if($cmd === 'drop') {
445 // Check if we should do HTML-based delete confirmation
446 if($_REQUEST['confirm']) {
447 // <form> can't take arguments in its "action" parameter
448 // so add any arguments as hidden inputs
449 $query = explode_querystring($a->query_string);
451 foreach($query['args'] as $arg) {
452 if(strpos($arg, 'confirm=') === false) {
453 $arg_parts = explode('=', $arg);
454 $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
458 $a->page['aside'] = '';
460 return replace_macros(get_markup_template('contact_drop_confirm.tpl'), array(
461 '$header' => t('Drop contact'),
462 '$contact' => _contact_detail_for_template($orig_record[0]),
464 '$message' => t('Do you really want to delete this contact?'),
465 '$extra_inputs' => $inputs,
466 '$confirm' => t('Yes'),
467 '$confirm_url' => $query['base'],
468 '$confirm_name' => 'confirmed',
469 '$cancel' => t('Cancel'),
472 // Now check how the user responded to the confirmation query
473 if ($_REQUEST['canceled']) {
474 if (x($_SESSION,'return_url')) {
475 goaway('' . $_SESSION['return_url']);
482 _contact_drop($contact_id, $orig_record[0]);
483 info( t('Contact has been removed.') . EOL );
484 if (x($_SESSION,'return_url')) {
485 goaway('' . $_SESSION['return_url']);
490 return; // NOTREACHED
492 if ($cmd === 'posts') {
493 return contact_posts($a, $contact_id);
499 $_SESSION['return_url'] = $a->query_string;
501 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
503 $contact_id = $a->data['contact']['id'];
504 $contact = $a->data['contact'];
506 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
507 '$baseurl' => System::baseUrl(true),
509 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
510 '$baseurl' => System::baseUrl(true),
513 require_once 'include/contact_selectors.php';
515 $tpl = get_markup_template("contact_edit.tpl");
517 switch($contact['rel']) {
518 case CONTACT_IS_FRIEND:
519 $dir_icon = 'images/lrarrow.gif';
520 $relation_text = t('You are mutual friends with %s');
522 case CONTACT_IS_FOLLOWER;
523 $dir_icon = 'images/larrow.gif';
524 $relation_text = t('You are sharing with %s');
527 case CONTACT_IS_SHARING;
528 $dir_icon = 'images/rarrow.gif';
529 $relation_text = t('%s is sharing with you');
535 if(!in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
538 $relation_text = sprintf($relation_text,htmlentities($contact['name']));
540 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
541 $url = "redir/{$contact['id']}";
542 $sparkle = ' class="sparkle" ';
545 $url = $contact['url'];
549 $insecure = t('Private communications are not available for this contact.');
551 $last_update = (($contact['last-update'] <= NULL_DATE)
553 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
555 if ($contact['last-update'] > NULL_DATE) {
556 $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
558 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
560 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
562 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network'], $contact["url"]));
564 //$common = GlobalContact::countCommonFriends(local_user(),$contact['id']);
565 //$common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
567 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
569 //$x = GlobalContact::countAllFriends(local_user(), $contact['id']);
570 //$all_friends = (($x) ? t('View all contacts') : '');
573 $tab_str = contacts_tab($a, $contact_id, 2);
575 $lost_contact = (($contact['archive'] && $contact['term-date'] > NULL_DATE && $contact['term-date'] < datetime_convert('','','now')) ? t('Communications lost with this contact!') : '');
577 if ($contact['network'] == NETWORK_FEED) {
578 $fetch_further_information = array('fetch_further_information', t('Fetch further information for feeds'), $contact['fetch_further_information'], t('Fetch further information for feeds'),
579 array('0'=>t('Disabled'), '1'=>t('Fetch information'), '2'=>t('Fetch information and keywords')));
581 if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2)))
582 $poll_interval = contact_poll_interval($contact['priority'],(! $poll_enabled));
584 if ($contact['network'] == NETWORK_DFRN)
585 $profile_select = contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false));
587 if (in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS))) {
588 if ($contact['rel'] == CONTACT_IS_FOLLOWER) {
589 $follow = System::baseUrl(true)."/follow?url=".urlencode($contact["url"]);
590 $follow_text = t("Connect/Follow");
591 } elseif ($contact['rel'] == CONTACT_IS_FRIEND) {
592 $follow = System::baseUrl(true)."/unfollow?url=".urlencode($contact["url"]);
593 $follow_text = t("Disconnect/Unfollow");
597 // Load contactact related actions like hide, suggest, delete and others
598 $contact_actions = contact_actions($contact);
601 $o .= replace_macros($tpl, array(
602 //'$header' => t('Contact Editor'),
603 '$header' => t("Contact"),
604 '$tab_str' => $tab_str,
605 '$submit' => t('Submit'),
606 '$lbl_vis1' => t('Profile Visibility'),
607 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
608 '$lbl_info1' => t('Contact Information / Notes'),
609 '$lbl_info2' => t('Their personal note'),
610 '$reason' => trim(notags($contact['reason'])),
611 '$infedit' => t('Edit contact notes'),
612 '$common_text' => $common_text,
613 '$common_link' => 'common/loc/' . local_user() . '/' . $contact['id'],
614 '$all_friends' => $all_friends,
615 '$relation_text' => $relation_text,
616 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
617 '$blockunblock' => t('Block/Unblock contact'),
618 '$ignorecont' => t('Ignore contact'),
619 '$lblcrepair' => t("Repair URL settings"),
620 '$lblrecent' => t('View conversations'),
621 '$lblsuggest' => $lblsuggest,
622 //'$delete' => t('Delete contact'),
623 '$nettype' => $nettype,
624 '$poll_interval' => $poll_interval,
625 '$poll_enabled' => $poll_enabled,
626 '$lastupdtext' => t('Last update:'),
627 '$lost_contact' => $lost_contact,
628 '$updpub' => t('Update public posts'),
629 '$last_update' => $last_update,
630 '$udnow' => t('Update now'),
631 '$follow' => $follow,
632 '$follow_text' => $follow_text,
633 '$profile_select' => $profile_select,
634 '$contact_id' => $contact['id'],
635 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
636 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
637 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
638 '$info' => $contact['info'],
639 '$cinfo' => array('info', '', $contact['info'], ''),
640 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
641 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
642 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
643 '$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')),
644 '$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
645 '$fetch_further_information' => $fetch_further_information,
646 '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
647 '$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')),
648 '$photo' => $contact['photo'],
649 '$name' => htmlentities($contact['name']),
650 '$dir_icon' => $dir_icon,
651 '$alt_text' => $alt_text,
652 '$sparkle' => $sparkle,
654 '$profileurllabel' => t('Profile URL'),
655 '$profileurl' => $contact['url'],
656 '$account_type' => account_type($contact),
657 '$location' => bbcode($contact["location"]),
658 '$location_label' => t("Location:"),
659 '$xmpp' => bbcode($contact["xmpp"]),
660 '$xmpp_label' => t("XMPP:"),
661 '$about' => bbcode($contact["about"], false, false),
662 '$about_label' => t("About:"),
663 '$keywords' => $contact["keywords"],
664 '$keywords_label' => t("Tags:"),
665 '$contact_action_button' => t("Actions"),
666 '$contact_actions' => $contact_actions,
667 '$contact_status' => t("Status"),
668 '$contact_settings_label' => t('Contact Settings'),
669 '$contact_profile_label' => t("Profile"),
673 $arr = array('contact' => $contact,'output' => $o);
675 call_hooks('contact_edit', $arr);
677 return $arr['output'];
686 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
690 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
691 $sql_extra = " AND `blocked` = 1 ";
694 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
695 $sql_extra = " AND `hidden` = 1 ";
698 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
699 $sql_extra = " AND `readonly` = 1 ";
702 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
703 $sql_extra = " AND `archive` = 1 ";
707 $sql_extra = " AND `blocked` = 0 ";
709 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
710 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
714 'label' => t('Suggestions'),
717 'title' => t('Suggest potential friends'),
718 'id' => 'suggestions-tab',
722 'label' => t('All Contacts'),
723 'url' => 'contacts/all',
724 'sel' => ($all) ? 'active' : '',
725 'title' => t('Show all contacts'),
726 'id' => 'showall-tab',
730 'label' => t('Unblocked'),
732 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
733 'title' => t('Only show unblocked contacts'),
734 'id' => 'showunblocked-tab',
739 'label' => t('Blocked'),
740 'url' => 'contacts/blocked',
741 'sel' => ($blocked) ? 'active' : '',
742 'title' => t('Only show blocked contacts'),
743 'id' => 'showblocked-tab',
748 'label' => t('Ignored'),
749 'url' => 'contacts/ignored',
750 'sel' => ($ignored) ? 'active' : '',
751 'title' => t('Only show ignored contacts'),
752 'id' => 'showignored-tab',
757 'label' => t('Archived'),
758 'url' => 'contacts/archived',
759 'sel' => ($archived) ? 'active' : '',
760 'title' => t('Only show archived contacts'),
761 'id' => 'showarchived-tab',
766 'label' => t('Hidden'),
767 'url' => 'contacts/hidden',
768 'sel' => ($hidden) ? 'active' : '',
769 'title' => t('Only show hidden contacts'),
770 'id' => 'showhidden-tab',
776 $tab_tpl = get_markup_template('common_tabs.tpl');
777 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
783 $search_hdr = $search;
784 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
787 $sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') " : "");
790 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
792 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
795 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
796 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
797 intval($_SESSION['uid']));
798 if (DBM::is_result($r)) {
799 $a->set_pager_total($r[0]['total']);
800 $total = $r[0]['total'];
803 $sql_extra3 = unavailable_networks();
805 $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 ",
806 intval($_SESSION['uid']),
807 intval($a->pager['start']),
808 intval($a->pager['itemspage'])
813 if (DBM::is_result($r)) {
814 foreach ($r as $rr) {
815 $contacts[] = _contact_detail_for_template($rr);
819 $tpl = get_markup_template("contacts-template.tpl");
820 $o .= replace_macros($tpl, array(
821 '$baseurl' => System::baseUrl(),
822 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
825 '$search' => $search_hdr,
826 '$desc' => t('Search your contacts'),
827 '$finding' => (($searching) ? sprintf(t('Results for: %s'),$search) : ""),
828 '$submit' => t('Find'),
830 '$contacts' => $contacts,
831 '$contact_drop_confirm' => t('Do you really want to delete this contact?'),
833 '$batch_actions' => array(
834 'contacts_batch_update' => t('Update'),
835 'contacts_batch_block' => t('Block')."/".t("Unblock"),
836 "contacts_batch_ignore" => t('Ignore')."/".t("Unignore"),
837 "contacts_batch_archive" => t('Archive')."/".t("Unarchive"),
838 "contacts_batch_drop" => t('Delete'),
840 '$h_batch_actions' => t('Batch Actions'),
841 '$paginate' => paginate($a),
849 * @brief List of pages for the Contact TabBar
851 * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
854 * @param int $contact_id The ID of the contact
855 * @param int $active_tab 1 if tab should be marked as active
857 * @return array with with contact TabBar data
859 function contacts_tab($a, $contact_id, $active_tab) {
863 'label'=>t('Status'),
864 'url' => "contacts/".$contact_id."/posts",
865 'sel' => (($active_tab == 1)?'active':''),
866 'title' => t('Status Messages and Posts'),
867 'id' => 'status-tab',
871 'label'=>t('Profile'),
872 'url' => "contacts/".$contact_id,
873 'sel' => (($active_tab == 2)?'active':''),
874 'title' => t('Profile Details'),
875 'id' => 'profile-tab',
880 // Show this tab only if there is visible friend list
881 $x = GlobalContact::countAllFriends(local_user(), $contact_id);
883 $tabs[] = array('label'=>t('Contacts'),
884 'url' => "allfriends/".$contact_id,
885 'sel' => (($active_tab == 3)?'active':''),
886 'title' => t('View all contacts'),
887 'id' => 'allfriends-tab',
890 // Show this tab only if there is visible common friend list
891 $common = GlobalContact::countCommonFriends(local_user(), $contact_id);
893 $tabs[] = array('label'=>t('Common Friends'),
894 'url' => "common/loc/".local_user()."/".$contact_id,
895 'sel' => (($active_tab == 4)?'active':''),
896 'title' => t('View all common friends'),
897 'id' => 'common-loc-tab',
900 $tabs[] = array('label' => t('Advanced'),
901 'url' => 'crepair/' . $contact_id,
902 'sel' => (($active_tab == 5)?'active':''),
903 'title' => t('Advanced Contact Settings'),
904 'id' => 'advanced-tab',
907 $tab_tpl = get_markup_template('common_tabs.tpl');
908 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
913 function contact_posts($a, $contact_id) {
915 $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id));
918 $a->page['aside'] = "";
919 profile_load($a, "", 0, get_contact_details_by_url($contact["url"]));
923 $tab_str = contacts_tab($a, $contact_id, 1);
927 $o .= posts_from_contact_url($a, $contact["url"]);
932 function _contact_detail_for_template($rr){
935 case CONTACT_IS_FRIEND:
936 $dir_icon = 'images/lrarrow.gif';
937 $alt_text = t('Mutual Friendship');
939 case CONTACT_IS_FOLLOWER;
940 $dir_icon = 'images/larrow.gif';
941 $alt_text = t('is a fan of yours');
943 case CONTACT_IS_SHARING;
944 $dir_icon = 'images/rarrow.gif';
945 $alt_text = t('you are a fan of');
950 if(($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) {
951 $url = "redir/{$rr['id']}";
952 $sparkle = ' class="sparkle" ';
960 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
961 'edit_hover' => t('Edit contact'),
962 'photo_menu' => contact_photo_menu($rr),
964 'alt_text' => $alt_text,
965 'dir_icon' => $dir_icon,
966 'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB),
967 'name' => htmlentities($rr['name']),
968 'username' => htmlentities($rr['name']),
969 'account_type' => account_type($rr),
970 'sparkle' => $sparkle,
971 'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']),
973 'network' => network_to_name($rr['network'], $rr['url']),
979 * @brief Gives a array with actions which can performed to a given contact
981 * This includes actions like e.g. 'block', 'hide', 'archive', 'delete' and others
983 * @param array $contact Data about the Contact
984 * @return array with contact related actions
986 function contact_actions($contact) {
988 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
989 $contact_action = array();
991 // Provide friend suggestion only for Friendica contacts
992 if($contact['network'] === NETWORK_DFRN) {
993 $contact_actions['suggest'] = array(
994 'label' => t('Suggest friends'),
995 'url' => 'fsuggest/' . $contact['id'],
1003 $contact_actions['update'] = array(
1004 'label' => t('Update now'),
1005 'url' => 'contacts/' . $contact['id'] . '/update',
1012 $contact_actions['block'] = array(
1013 'label' => (intval($contact['blocked']) ? t('Unblock') : t('Block') ),
1014 'url' => 'contacts/' . $contact['id'] . '/block',
1015 'title' => t('Toggle Blocked status'),
1016 'sel' => (intval($contact['blocked']) ? 'active' : ''),
1017 'id' => 'toggle-block',
1020 $contact_actions['ignore'] = array(
1021 'label' => (intval($contact['readonly']) ? t('Unignore') : t('Ignore') ),
1022 'url' => 'contacts/' . $contact['id'] . '/ignore',
1023 'title' => t('Toggle Ignored status'),
1024 'sel' => (intval($contact['readonly']) ? 'active' : ''),
1025 'id' => 'toggle-ignore',
1028 $contact_actions['archive'] = array(
1029 'label' => (intval($contact['archive']) ? t('Unarchive') : t('Archive') ),
1030 'url' => 'contacts/' . $contact['id'] . '/archive',
1031 'title' => t('Toggle Archive status'),
1032 'sel' => (intval($contact['archive']) ? 'active' : ''),
1033 'id' => 'toggle-archive',
1036 $contact_actions['delete'] = array(
1037 'label' => t('Delete'),
1038 'url' => 'contacts/' . $contact['id'] . '/drop',
1039 'title' => t('Delete contact'),
1044 return $contact_actions;