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_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' => Contact::getAccountType($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($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()));
350 function _contact_drop($orig_record)
354 $r = q("SELECT `contact`.*, `user`.* FROM `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid`
355 WHERE `user`.`uid` = %d AND `contact`.`self` LIMIT 1",
356 intval($a->user['uid'])
358 if (!DBM::is_result($r)) {
362 Contact::terminateFriendship($r[0], $orig_record);
363 Contact::remove($orig_record['id']);
367 function contacts_content(App $a) {
371 nav_set_selected('contacts');
374 if (! local_user()) {
375 notice( t('Permission denied.') . EOL);
381 $contact_id = intval($a->argv[1]);
387 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
392 if(! count($orig_record)) {
393 notice( t('Could not access contact record.') . EOL);
395 return; // NOTREACHED
398 if($cmd === 'update') {
399 _contact_update($contact_id);
400 goaway('contacts/' . $contact_id);
404 if($cmd === 'updateprofile') {
405 _contact_update_profile($contact_id);
406 goaway('crepair/' . $contact_id);
410 if($cmd === 'block') {
411 $r = _contact_block($contact_id, $orig_record[0]);
413 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
414 info((($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')).EOL);
417 goaway('contacts/' . $contact_id);
418 return; // NOTREACHED
421 if($cmd === 'ignore') {
422 $r = _contact_ignore($contact_id, $orig_record[0]);
424 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
425 info((($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')).EOL);
428 goaway('contacts/' . $contact_id);
429 return; // NOTREACHED
433 if($cmd === 'archive') {
434 $r = _contact_archive($contact_id, $orig_record[0]);
436 $archived = (($orig_record[0]['archive']) ? 0 : 1);
437 info((($archived) ? t('Contact has been archived') : t('Contact has been unarchived')).EOL);
440 goaway('contacts/' . $contact_id);
441 return; // NOTREACHED
444 if($cmd === 'drop') {
446 // Check if we should do HTML-based delete confirmation
447 if($_REQUEST['confirm']) {
448 // <form> can't take arguments in its "action" parameter
449 // so add any arguments as hidden inputs
450 $query = explode_querystring($a->query_string);
452 foreach($query['args'] as $arg) {
453 if(strpos($arg, 'confirm=') === false) {
454 $arg_parts = explode('=', $arg);
455 $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
459 $a->page['aside'] = '';
461 return replace_macros(get_markup_template('contact_drop_confirm.tpl'), array(
462 '$header' => t('Drop contact'),
463 '$contact' => _contact_detail_for_template($orig_record[0]),
465 '$message' => t('Do you really want to delete this contact?'),
466 '$extra_inputs' => $inputs,
467 '$confirm' => t('Yes'),
468 '$confirm_url' => $query['base'],
469 '$confirm_name' => 'confirmed',
470 '$cancel' => t('Cancel'),
473 // Now check how the user responded to the confirmation query
474 if ($_REQUEST['canceled']) {
475 if (x($_SESSION,'return_url')) {
476 goaway('' . $_SESSION['return_url']);
483 _contact_drop($orig_record[0]);
484 info( t('Contact has been removed.') . EOL );
485 if (x($_SESSION,'return_url')) {
486 goaway('' . $_SESSION['return_url']);
491 return; // NOTREACHED
493 if ($cmd === 'posts') {
494 return contact_posts($a, $contact_id);
500 $_SESSION['return_url'] = $a->query_string;
502 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
504 $contact_id = $a->data['contact']['id'];
505 $contact = $a->data['contact'];
507 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
508 '$baseurl' => System::baseUrl(true),
510 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
511 '$baseurl' => System::baseUrl(true),
514 require_once 'include/contact_selectors.php';
516 $tpl = get_markup_template("contact_edit.tpl");
518 switch($contact['rel']) {
519 case CONTACT_IS_FRIEND:
520 $dir_icon = 'images/lrarrow.gif';
521 $relation_text = t('You are mutual friends with %s');
523 case CONTACT_IS_FOLLOWER;
524 $dir_icon = 'images/larrow.gif';
525 $relation_text = t('You are sharing with %s');
528 case CONTACT_IS_SHARING;
529 $dir_icon = 'images/rarrow.gif';
530 $relation_text = t('%s is sharing with you');
536 if(!in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
539 $relation_text = sprintf($relation_text,htmlentities($contact['name']));
541 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
542 $url = "redir/{$contact['id']}";
543 $sparkle = ' class="sparkle" ';
546 $url = $contact['url'];
550 $insecure = t('Private communications are not available for this contact.');
552 $last_update = (($contact['last-update'] <= NULL_DATE)
554 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
556 if ($contact['last-update'] > NULL_DATE) {
557 $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
559 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
561 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
563 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network'], $contact["url"]));
565 //$common = GlobalContact::countCommonFriends(local_user(),$contact['id']);
566 //$common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
568 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
570 //$x = GlobalContact::countAllFriends(local_user(), $contact['id']);
571 //$all_friends = (($x) ? t('View all contacts') : '');
574 $tab_str = contacts_tab($a, $contact_id, 2);
576 $lost_contact = (($contact['archive'] && $contact['term-date'] > NULL_DATE && $contact['term-date'] < datetime_convert('','','now')) ? t('Communications lost with this contact!') : '');
578 if ($contact['network'] == NETWORK_FEED) {
579 $fetch_further_information = array('fetch_further_information', t('Fetch further information for feeds'), $contact['fetch_further_information'], t('Fetch further information for feeds'),
580 array('0'=>t('Disabled'), '1'=>t('Fetch information'), '2'=>t('Fetch information and keywords')));
582 if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2)))
583 $poll_interval = contact_poll_interval($contact['priority'],(! $poll_enabled));
585 if ($contact['network'] == NETWORK_DFRN)
586 $profile_select = contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false));
588 if (in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS))) {
589 if ($contact['rel'] == CONTACT_IS_FOLLOWER) {
590 $follow = System::baseUrl(true)."/follow?url=".urlencode($contact["url"]);
591 $follow_text = t("Connect/Follow");
592 } elseif ($contact['rel'] == CONTACT_IS_FRIEND) {
593 $follow = System::baseUrl(true)."/unfollow?url=".urlencode($contact["url"]);
594 $follow_text = t("Disconnect/Unfollow");
598 // Load contactact related actions like hide, suggest, delete and others
599 $contact_actions = contact_actions($contact);
602 $o .= replace_macros($tpl, array(
603 //'$header' => t('Contact Editor'),
604 '$header' => t("Contact"),
605 '$tab_str' => $tab_str,
606 '$submit' => t('Submit'),
607 '$lbl_vis1' => t('Profile Visibility'),
608 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
609 '$lbl_info1' => t('Contact Information / Notes'),
610 '$lbl_info2' => t('Their personal note'),
611 '$reason' => trim(notags($contact['reason'])),
612 '$infedit' => t('Edit contact notes'),
613 '$common_text' => $common_text,
614 '$common_link' => 'common/loc/' . local_user() . '/' . $contact['id'],
615 '$all_friends' => $all_friends,
616 '$relation_text' => $relation_text,
617 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
618 '$blockunblock' => t('Block/Unblock contact'),
619 '$ignorecont' => t('Ignore contact'),
620 '$lblcrepair' => t("Repair URL settings"),
621 '$lblrecent' => t('View conversations'),
622 '$lblsuggest' => $lblsuggest,
623 //'$delete' => t('Delete contact'),
624 '$nettype' => $nettype,
625 '$poll_interval' => $poll_interval,
626 '$poll_enabled' => $poll_enabled,
627 '$lastupdtext' => t('Last update:'),
628 '$lost_contact' => $lost_contact,
629 '$updpub' => t('Update public posts'),
630 '$last_update' => $last_update,
631 '$udnow' => t('Update now'),
632 '$follow' => $follow,
633 '$follow_text' => $follow_text,
634 '$profile_select' => $profile_select,
635 '$contact_id' => $contact['id'],
636 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
637 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
638 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
639 '$info' => $contact['info'],
640 '$cinfo' => array('info', '', $contact['info'], ''),
641 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
642 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
643 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
644 '$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')),
645 '$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
646 '$fetch_further_information' => $fetch_further_information,
647 '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
648 '$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')),
649 '$photo' => $contact['photo'],
650 '$name' => htmlentities($contact['name']),
651 '$dir_icon' => $dir_icon,
652 '$alt_text' => $alt_text,
653 '$sparkle' => $sparkle,
655 '$profileurllabel' => t('Profile URL'),
656 '$profileurl' => $contact['url'],
657 '$account_type' => Contact::getAccountType($contact),
658 '$location' => bbcode($contact["location"]),
659 '$location_label' => t("Location:"),
660 '$xmpp' => bbcode($contact["xmpp"]),
661 '$xmpp_label' => t("XMPP:"),
662 '$about' => bbcode($contact["about"], false, false),
663 '$about_label' => t("About:"),
664 '$keywords' => $contact["keywords"],
665 '$keywords_label' => t("Tags:"),
666 '$contact_action_button' => t("Actions"),
667 '$contact_actions' => $contact_actions,
668 '$contact_status' => t("Status"),
669 '$contact_settings_label' => t('Contact Settings'),
670 '$contact_profile_label' => t("Profile"),
674 $arr = array('contact' => $contact,'output' => $o);
676 call_hooks('contact_edit', $arr);
678 return $arr['output'];
687 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
691 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
692 $sql_extra = " AND `blocked` = 1 ";
695 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
696 $sql_extra = " AND `hidden` = 1 ";
699 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
700 $sql_extra = " AND `readonly` = 1 ";
703 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
704 $sql_extra = " AND `archive` = 1 ";
708 $sql_extra = " AND `blocked` = 0 ";
710 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
711 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
715 'label' => t('Suggestions'),
718 'title' => t('Suggest potential friends'),
719 'id' => 'suggestions-tab',
723 'label' => t('All Contacts'),
724 'url' => 'contacts/all',
725 'sel' => ($all) ? 'active' : '',
726 'title' => t('Show all contacts'),
727 'id' => 'showall-tab',
731 'label' => t('Unblocked'),
733 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
734 'title' => t('Only show unblocked contacts'),
735 'id' => 'showunblocked-tab',
740 'label' => t('Blocked'),
741 'url' => 'contacts/blocked',
742 'sel' => ($blocked) ? 'active' : '',
743 'title' => t('Only show blocked contacts'),
744 'id' => 'showblocked-tab',
749 'label' => t('Ignored'),
750 'url' => 'contacts/ignored',
751 'sel' => ($ignored) ? 'active' : '',
752 'title' => t('Only show ignored contacts'),
753 'id' => 'showignored-tab',
758 'label' => t('Archived'),
759 'url' => 'contacts/archived',
760 'sel' => ($archived) ? 'active' : '',
761 'title' => t('Only show archived contacts'),
762 'id' => 'showarchived-tab',
767 'label' => t('Hidden'),
768 'url' => 'contacts/hidden',
769 'sel' => ($hidden) ? 'active' : '',
770 'title' => t('Only show hidden contacts'),
771 'id' => 'showhidden-tab',
777 $tab_tpl = get_markup_template('common_tabs.tpl');
778 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
784 $search_hdr = $search;
785 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
788 $sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') " : "");
791 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
793 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
796 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
797 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
798 intval($_SESSION['uid']));
799 if (DBM::is_result($r)) {
800 $a->set_pager_total($r[0]['total']);
801 $total = $r[0]['total'];
804 $sql_extra3 = unavailable_networks();
806 $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 ",
807 intval($_SESSION['uid']),
808 intval($a->pager['start']),
809 intval($a->pager['itemspage'])
814 if (DBM::is_result($r)) {
815 foreach ($r as $rr) {
816 $contacts[] = _contact_detail_for_template($rr);
820 $tpl = get_markup_template("contacts-template.tpl");
821 $o .= replace_macros($tpl, array(
822 '$baseurl' => System::baseUrl(),
823 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
826 '$search' => $search_hdr,
827 '$desc' => t('Search your contacts'),
828 '$finding' => (($searching) ? sprintf(t('Results for: %s'),$search) : ""),
829 '$submit' => t('Find'),
831 '$contacts' => $contacts,
832 '$contact_drop_confirm' => t('Do you really want to delete this contact?'),
834 '$batch_actions' => array(
835 'contacts_batch_update' => t('Update'),
836 'contacts_batch_block' => t('Block')."/".t("Unblock"),
837 "contacts_batch_ignore" => t('Ignore')."/".t("Unignore"),
838 "contacts_batch_archive" => t('Archive')."/".t("Unarchive"),
839 "contacts_batch_drop" => t('Delete'),
841 '$h_batch_actions' => t('Batch Actions'),
842 '$paginate' => paginate($a),
850 * @brief List of pages for the Contact TabBar
852 * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
855 * @param int $contact_id The ID of the contact
856 * @param int $active_tab 1 if tab should be marked as active
858 * @return array with with contact TabBar data
860 function contacts_tab($a, $contact_id, $active_tab) {
864 'label'=>t('Status'),
865 'url' => "contacts/".$contact_id."/posts",
866 'sel' => (($active_tab == 1)?'active':''),
867 'title' => t('Status Messages and Posts'),
868 'id' => 'status-tab',
872 'label'=>t('Profile'),
873 'url' => "contacts/".$contact_id,
874 'sel' => (($active_tab == 2)?'active':''),
875 'title' => t('Profile Details'),
876 'id' => 'profile-tab',
881 // Show this tab only if there is visible friend list
882 $x = GlobalContact::countAllFriends(local_user(), $contact_id);
884 $tabs[] = array('label'=>t('Contacts'),
885 'url' => "allfriends/".$contact_id,
886 'sel' => (($active_tab == 3)?'active':''),
887 'title' => t('View all contacts'),
888 'id' => 'allfriends-tab',
891 // Show this tab only if there is visible common friend list
892 $common = GlobalContact::countCommonFriends(local_user(), $contact_id);
894 $tabs[] = array('label'=>t('Common Friends'),
895 'url' => "common/loc/".local_user()."/".$contact_id,
896 'sel' => (($active_tab == 4)?'active':''),
897 'title' => t('View all common friends'),
898 'id' => 'common-loc-tab',
901 $tabs[] = array('label' => t('Advanced'),
902 'url' => 'crepair/' . $contact_id,
903 'sel' => (($active_tab == 5)?'active':''),
904 'title' => t('Advanced Contact Settings'),
905 'id' => 'advanced-tab',
908 $tab_tpl = get_markup_template('common_tabs.tpl');
909 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
914 function contact_posts($a, $contact_id) {
916 $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id));
919 $a->page['aside'] = "";
920 profile_load($a, "", 0, Contact::getDetailsByURL($contact["url"]));
924 $tab_str = contacts_tab($a, $contact_id, 1);
928 $o .= Contact::getPostsFromUrl($contact["url"]);
933 function _contact_detail_for_template($rr){
936 case CONTACT_IS_FRIEND:
937 $dir_icon = 'images/lrarrow.gif';
938 $alt_text = t('Mutual Friendship');
940 case CONTACT_IS_FOLLOWER;
941 $dir_icon = 'images/larrow.gif';
942 $alt_text = t('is a fan of yours');
944 case CONTACT_IS_SHARING;
945 $dir_icon = 'images/rarrow.gif';
946 $alt_text = t('you are a fan of');
951 if(($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) {
952 $url = "redir/{$rr['id']}";
953 $sparkle = ' class="sparkle" ';
961 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
962 'edit_hover' => t('Edit contact'),
963 'photo_menu' => Contact::photoMenu($rr),
965 'alt_text' => $alt_text,
966 'dir_icon' => $dir_icon,
967 'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB),
968 'name' => htmlentities($rr['name']),
969 'username' => htmlentities($rr['name']),
970 'account_type' => Contact::getAccountType($rr),
971 'sparkle' => $sparkle,
972 'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']),
974 'network' => network_to_name($rr['network'], $rr['url']),
980 * @brief Gives a array with actions which can performed to a given contact
982 * This includes actions like e.g. 'block', 'hide', 'archive', 'delete' and others
984 * @param array $contact Data about the Contact
985 * @return array with contact related actions
987 function contact_actions($contact) {
989 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
990 $contact_action = array();
992 // Provide friend suggestion only for Friendica contacts
993 if($contact['network'] === NETWORK_DFRN) {
994 $contact_actions['suggest'] = array(
995 'label' => t('Suggest friends'),
996 'url' => 'fsuggest/' . $contact['id'],
1004 $contact_actions['update'] = array(
1005 'label' => t('Update now'),
1006 'url' => 'contacts/' . $contact['id'] . '/update',
1013 $contact_actions['block'] = array(
1014 'label' => (intval($contact['blocked']) ? t('Unblock') : t('Block') ),
1015 'url' => 'contacts/' . $contact['id'] . '/block',
1016 'title' => t('Toggle Blocked status'),
1017 'sel' => (intval($contact['blocked']) ? 'active' : ''),
1018 'id' => 'toggle-block',
1021 $contact_actions['ignore'] = array(
1022 'label' => (intval($contact['readonly']) ? t('Unignore') : t('Ignore') ),
1023 'url' => 'contacts/' . $contact['id'] . '/ignore',
1024 'title' => t('Toggle Ignored status'),
1025 'sel' => (intval($contact['readonly']) ? 'active' : ''),
1026 'id' => 'toggle-ignore',
1029 $contact_actions['archive'] = array(
1030 'label' => (intval($contact['archive']) ? t('Unarchive') : t('Archive') ),
1031 'url' => 'contacts/' . $contact['id'] . '/archive',
1032 'title' => t('Toggle Archive status'),
1033 'sel' => (intval($contact['archive']) ? 'active' : ''),
1034 'id' => 'toggle-archive',
1037 $contact_actions['delete'] = array(
1038 'label' => t('Delete'),
1039 'url' => 'contacts/' . $contact['id'] . '/drop',
1040 'title' => t('Delete contact'),
1045 return $contact_actions;