3 require_once('include/Contact.php');
4 require_once('include/socgraph.php');
5 require_once('include/contact_selectors.php');
6 require_once('include/Scrape.php');
7 require_once('mod/proxy.php');
8 require_once('include/Photo.php');
10 function contacts_init(&$a) {
17 if((($a->argc == 2) && intval($a->argv[1])) OR (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) {
18 $contact_id = intval($a->argv[1]);
19 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
23 if (! dbm::is_result($r)) {
28 require_once('include/group.php');
29 require_once('include/contact_widgets.php');
31 if ($_GET['nets'] == "all")
34 if(! x($a->page,'aside'))
35 $a->page['aside'] = '';
38 $a->data['contact'] = $r[0];
40 if (($a->data['contact']['network'] != "") AND ($a->data['contact']['network'] != NETWORK_DFRN)) {
41 $networkname = format_network_name($a->data['contact']['network'],$a->data['contact']['url']);
45 $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array(
46 '$name' => htmlentities($a->data['contact']['name']),
47 '$photo' => $a->data['contact']['photo'],
48 '$url' => ($a->data['contact']['network'] == NETWORK_DFRN) ? "redir/".$a->data['contact']['id'] : $a->data['contact']['url'],
49 '$addr' => (($a->data['contact']['addr'] != "") ? ($a->data['contact']['addr']) : ""),
50 '$network_name' => $networkname,
51 '$network' => t('Network:'),
52 '$account_type' => account_type($a->data['contact'])
54 $finpeople_widget = '';
56 $networks_widget = '';
60 $networks_widget .= networks_widget('contacts',$_GET['nets']);
61 if (isset($_GET['add']))
62 $follow_widget = follow_widget($_GET['add']);
64 $follow_widget = follow_widget();
66 $findpeople_widget .= findpeople_widget();
69 $groups_widget .= group_side('contacts','group','full',0,$contact_id);
71 $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"),array(
72 '$vcard_widget' => $vcard_widget,
73 '$findpeople_widget' => $findpeople_widget,
74 '$follow_widget' => $follow_widget,
75 '$groups_widget' => $groups_widget,
76 '$networks_widget' => $networks_widget
80 $tpl = get_markup_template("contacts-head.tpl");
81 $a->page['htmlhead'] .= replace_macros($tpl,array(
82 '$baseurl' => App::get_baseurl(true),
86 $tpl = get_markup_template("contacts-end.tpl");
87 $a->page['end'] .= replace_macros($tpl,array(
88 '$baseurl' => App::get_baseurl(true),
95 function contacts_batch_actions(&$a){
96 $contacts_id = $_POST['contact_batch'];
97 if (!is_array($contacts_id)) return;
99 $orig_records = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND `uid` = %d AND `self` = 0",
100 implode(",", $contacts_id),
105 foreach($orig_records as $orig_record) {
106 $contact_id = $orig_record['id'];
107 if (x($_POST, 'contacts_batch_update')) {
108 _contact_update($contact_id);
111 if (x($_POST, 'contacts_batch_block')) {
112 $r = _contact_block($contact_id, $orig_record);
113 if ($r) $count_actions++;
115 if (x($_POST, 'contacts_batch_ignore')) {
116 $r = _contact_ignore($contact_id, $orig_record);
117 if ($r) $count_actions++;
119 if (x($_POST, 'contacts_batch_archive')) {
120 $r = _contact_archive($contact_id, $orig_record);
121 if ($r) $count_actions++;
123 if (x($_POST, 'contacts_batch_drop')) {
124 _contact_drop($contact_id, $orig_record);
128 if ($count_actions>0) {
129 info ( sprintf( tt("%d contact edited.", "%d contacts edited.", $count_actions), $count_actions) );
132 if (x($_SESSION,'return_url')) {
133 goaway('' . $_SESSION['return_url']);
142 function contacts_post(&$a) {
144 if (! local_user()) {
148 if ($a->argv[1]==="batch") {
149 contacts_batch_actions($a);
153 $contact_id = intval($a->argv[1]);
158 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
163 if (! count($orig_record)) {
164 notice( t('Could not access contact record.') . EOL);
166 return; // NOTREACHED
169 call_hooks('contact_edit_post', $_POST);
171 $profile_id = intval($_POST['profile-assign']);
173 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
177 if (! dbm::is_result($r)) {
178 notice( t('Could not locate selected profile.') . EOL);
183 $hidden = intval($_POST['hidden']);
185 $notify = intval($_POST['notify']);
187 $fetch_further_information = intval($_POST['fetch_further_information']);
189 $ffi_keyword_blacklist = fix_mce_lf(escape_tags(trim($_POST['ffi_keyword_blacklist'])));
191 $priority = intval($_POST['poll']);
192 if($priority > 5 || $priority < 0)
195 $info = fix_mce_lf(escape_tags(trim($_POST['info'])));
197 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
198 `hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d,
199 `ffi_keyword_blacklist` = '%s' WHERE `id` = %d AND `uid` = %d",
205 intval($fetch_further_information),
206 dbesc($ffi_keyword_blacklist),
211 info( t('Contact updated.') . EOL);
213 notice( t('Failed to update contact record.') . EOL);
215 $r = q("select * from contact where id = %d and uid = %d limit 1",
219 if($r && dbm::is_result($r))
220 $a->data['contact'] = $r[0];
227 function _contact_update($contact_id) {
228 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
234 if ($uid != local_user())
237 if ($r[0]["network"] == NETWORK_OSTATUS) {
238 $result = new_contact($uid, $r[0]["url"], false);
240 if ($result['success'])
241 $r = q("UPDATE `contact` SET `subhub` = 1 WHERE `id` = %d",
242 intval($contact_id));
244 // pull feed and consume it, which should subscribe to the hub.
245 proc_run(PRIORITY_HIGH, "include/onepoll.php", $contact_id, "force");
248 function _contact_update_profile($contact_id) {
249 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
255 if ($uid != local_user())
258 $data = probe_url($r[0]["url"]);
260 // "Feed" or "Unknown" is mostly a sign of communication problems
261 if ((in_array($data["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) AND ($data["network"] != $r[0]["network"]))
264 $updatefields = array("name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm",
265 "poco", "network", "alias");
268 if ($data["network"] == NETWORK_OSTATUS) {
269 $result = new_contact($uid, $data["url"], false);
271 if ($result['success'])
272 $update["subhub"] = true;
275 foreach($updatefields AS $field)
276 if (isset($data[$field]) AND ($data[$field] != ""))
277 $update[$field] = $data[$field];
279 $update["nurl"] = normalise_link($data["url"]);
283 if (isset($data["priority"]) AND ($data["priority"] != 0))
284 $query = "`priority` = ".intval($data["priority"]);
286 foreach($update AS $key => $value) {
290 $query .= "`".$key."` = '".dbesc($value)."'";
296 $r = q("UPDATE `contact` SET $query WHERE `id` = %d AND `uid` = %d",
301 // Update the entry in the contact table
302 update_contact_avatar($data['photo'], local_user(), $contact_id);
304 // Update the entry in the gcontact table
305 update_gcontact_from_probe($data["url"]);
308 function _contact_block($contact_id, $orig_record) {
309 $blocked = (($orig_record['blocked']) ? 0 : 1);
310 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d",
318 function _contact_ignore($contact_id, $orig_record) {
319 $readonly = (($orig_record['readonly']) ? 0 : 1);
320 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d",
327 function _contact_archive($contact_id, $orig_record) {
328 $archived = (($orig_record['archive']) ? 0 : 1);
329 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d",
335 q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
339 function _contact_drop($contact_id, $orig_record) {
342 terminate_friendship($a->user,$a->contact,$orig_record);
343 contact_remove($orig_record['id']);
347 function contacts_content(&$a) {
351 nav_set_selected('contacts');
354 if (! local_user()) {
355 notice( t('Permission denied.') . EOL);
361 $contact_id = intval($a->argv[1]);
367 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
372 if(! count($orig_record)) {
373 notice( t('Could not access contact record.') . EOL);
375 return; // NOTREACHED
378 if($cmd === 'update') {
379 _contact_update($contact_id);
380 goaway('contacts/' . $contact_id);
384 if($cmd === 'updateprofile') {
385 _contact_update_profile($contact_id);
386 goaway('crepair/' . $contact_id);
390 if($cmd === 'block') {
391 $r = _contact_block($contact_id, $orig_record[0]);
393 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
394 info((($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')).EOL);
397 goaway('contacts/' . $contact_id);
398 return; // NOTREACHED
401 if($cmd === 'ignore') {
402 $r = _contact_ignore($contact_id, $orig_record[0]);
404 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
405 info((($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')).EOL);
408 goaway('contacts/' . $contact_id);
409 return; // NOTREACHED
413 if($cmd === 'archive') {
414 $r = _contact_archive($contact_id, $orig_record[0]);
416 $archived = (($orig_record[0]['archive']) ? 0 : 1);
417 info((($archived) ? t('Contact has been archived') : t('Contact has been unarchived')).EOL);
420 goaway('contacts/' . $contact_id);
421 return; // NOTREACHED
424 if($cmd === 'drop') {
426 // Check if we should do HTML-based delete confirmation
427 if($_REQUEST['confirm']) {
428 // <form> can't take arguments in its "action" parameter
429 // so add any arguments as hidden inputs
430 $query = explode_querystring($a->query_string);
432 foreach($query['args'] as $arg) {
433 if(strpos($arg, 'confirm=') === false) {
434 $arg_parts = explode('=', $arg);
435 $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
439 $a->page['aside'] = '';
441 return replace_macros(get_markup_template('contact_drop_confirm.tpl'), array(
442 '$header' => t('Drop contact'),
443 '$contact' => _contact_detail_for_template($orig_record[0]),
445 '$message' => t('Do you really want to delete this contact?'),
446 '$extra_inputs' => $inputs,
447 '$confirm' => t('Yes'),
448 '$confirm_url' => $query['base'],
449 '$confirm_name' => 'confirmed',
450 '$cancel' => t('Cancel'),
453 // Now check how the user responded to the confirmation query
454 if ($_REQUEST['canceled']) {
455 if (x($_SESSION,'return_url')) {
456 goaway('' . $_SESSION['return_url']);
463 _contact_drop($contact_id, $orig_record[0]);
464 info( t('Contact has been removed.') . EOL );
465 if (x($_SESSION,'return_url')) {
466 goaway('' . $_SESSION['return_url']);
471 return; // NOTREACHED
473 if ($cmd === 'posts') {
474 return contact_posts($a, $contact_id);
480 $_SESSION['return_url'] = $a->query_string;
482 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
484 $contact_id = $a->data['contact']['id'];
485 $contact = $a->data['contact'];
487 $editselect = 'none';
488 if( feature_enabled(local_user(),'richtext') )
489 $editselect = 'exact';
491 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
492 '$baseurl' => App::get_baseurl(true),
493 '$editselect' => $editselect,
495 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
496 '$baseurl' => App::get_baseurl(true),
497 '$editselect' => $editselect,
500 require_once('include/contact_selectors.php');
502 $tpl = get_markup_template("contact_edit.tpl");
504 switch($contact['rel']) {
505 case CONTACT_IS_FRIEND:
506 $dir_icon = 'images/lrarrow.gif';
507 $relation_text = t('You are mutual friends with %s');
509 case CONTACT_IS_FOLLOWER;
510 $dir_icon = 'images/larrow.gif';
511 $relation_text = t('You are sharing with %s');
514 case CONTACT_IS_SHARING;
515 $dir_icon = 'images/rarrow.gif';
516 $relation_text = t('%s is sharing with you');
522 if(!in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
525 $relation_text = sprintf($relation_text,htmlentities($contact['name']));
527 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
528 $url = "redir/{$contact['id']}";
529 $sparkle = ' class="sparkle" ';
532 $url = $contact['url'];
536 $insecure = t('Private communications are not available for this contact.');
538 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
540 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
542 if($contact['last-update'] !== '0000-00-00 00:00:00')
543 $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
545 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
547 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
549 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network'], $contact["url"]));
551 //$common = count_common_friends(local_user(),$contact['id']);
552 //$common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
554 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
556 //$x = count_all_friends(local_user(), $contact['id']);
557 //$all_friends = (($x) ? t('View all contacts') : '');
560 $tab_str = contacts_tab($a, $contact_id, 2);
562 $lost_contact = (($contact['archive'] && $contact['term-date'] != '0000-00-00 00:00:00' && $contact['term-date'] < datetime_convert('','','now')) ? t('Communications lost with this contact!') : '');
564 if ($contact['network'] == NETWORK_FEED)
565 $fetch_further_information = array('fetch_further_information', t('Fetch further information for feeds'), $contact['fetch_further_information'], t('Fetch further information for feeds'),
566 array('0'=>t('Disabled'), '1'=>t('Fetch information'), '2'=>t('Fetch information and keywords')));
568 if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2)))
569 $poll_interval = contact_poll_interval($contact['priority'],(! $poll_enabled));
571 if ($contact['network'] == NETWORK_DFRN)
572 $profile_select = contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false));
574 if (in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS)) AND
575 ($contact['rel'] == CONTACT_IS_FOLLOWER))
576 $follow = App::get_baseurl(true)."/follow?url=".urlencode($contact["url"]);
578 // Load contactact related actions like hide, suggest, delete and others
579 $contact_actions = contact_actions($contact);
582 $o .= replace_macros($tpl, array(
583 //'$header' => t('Contact Editor'),
584 '$header' => t("Contact"),
585 '$tab_str' => $tab_str,
586 '$submit' => t('Submit'),
587 '$lbl_vis1' => t('Profile Visibility'),
588 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
589 '$lbl_info1' => t('Contact Information / Notes'),
590 '$infedit' => t('Edit contact notes'),
591 '$common_text' => $common_text,
592 '$common_link' => 'common/loc/' . local_user() . '/' . $contact['id'],
593 '$all_friends' => $all_friends,
594 '$relation_text' => $relation_text,
595 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
596 '$blockunblock' => t('Block/Unblock contact'),
597 '$ignorecont' => t('Ignore contact'),
598 '$lblcrepair' => t("Repair URL settings"),
599 '$lblrecent' => t('View conversations'),
600 '$lblsuggest' => $lblsuggest,
601 //'$delete' => t('Delete contact'),
602 '$nettype' => $nettype,
603 '$poll_interval' => $poll_interval,
604 '$poll_enabled' => $poll_enabled,
605 '$lastupdtext' => t('Last update:'),
606 '$lost_contact' => $lost_contact,
607 '$updpub' => t('Update public posts'),
608 '$last_update' => $last_update,
609 '$udnow' => t('Update now'),
610 '$follow' => $follow,
611 '$follow_text' => t("Connect/Follow"),
612 '$profile_select' => $profile_select,
613 '$contact_id' => $contact['id'],
614 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
615 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
616 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
617 '$info' => $contact['info'],
618 '$cinfo' => array('info', '', $contact['info'], ''),
619 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
620 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
621 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
622 '$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')),
623 '$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
624 '$fetch_further_information' => $fetch_further_information,
625 '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
626 '$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')),
627 '$photo' => $contact['photo'],
628 '$name' => htmlentities($contact['name']),
629 '$dir_icon' => $dir_icon,
630 '$alt_text' => $alt_text,
631 '$sparkle' => $sparkle,
633 '$profileurllabel' => t('Profile URL'),
634 '$profileurl' => $contact['url'],
635 '$account_type' => account_type($contact),
636 '$location' => bbcode($contact["location"]),
637 '$location_label' => t("Location:"),
638 '$xmpp' => bbcode($contact["xmpp"]),
639 '$xmpp_label' => t("XMPP:"),
640 '$about' => bbcode($contact["about"], false, false),
641 '$about_label' => t("About:"),
642 '$keywords' => $contact["keywords"],
643 '$keywords_label' => t("Tags:"),
644 '$contact_action_button' => t("Actions"),
645 '$contact_actions' => $contact_actions,
646 '$contact_status' => t("Status"),
647 '$contact_settings_label' => t('Contact Settings'),
648 '$contact_profile_label' => t("Profile"),
652 $arr = array('contact' => $contact,'output' => $o);
654 call_hooks('contact_edit', $arr);
656 return $arr['output'];
665 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
669 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
670 $sql_extra = " AND `blocked` = 1 ";
673 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
674 $sql_extra = " AND `hidden` = 1 ";
677 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
678 $sql_extra = " AND `readonly` = 1 ";
681 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
682 $sql_extra = " AND `archive` = 1 ";
686 $sql_extra = " AND `blocked` = 0 ";
688 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
689 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
693 'label' => t('Suggestions'),
696 'title' => t('Suggest potential friends'),
697 'id' => 'suggestions-tab',
701 'label' => t('All Contacts'),
702 'url' => 'contacts/all',
703 'sel' => ($all) ? 'active' : '',
704 'title' => t('Show all contacts'),
705 'id' => 'showall-tab',
709 'label' => t('Unblocked'),
711 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
712 'title' => t('Only show unblocked contacts'),
713 'id' => 'showunblocked-tab',
718 'label' => t('Blocked'),
719 'url' => 'contacts/blocked',
720 'sel' => ($blocked) ? 'active' : '',
721 'title' => t('Only show blocked contacts'),
722 'id' => 'showblocked-tab',
727 'label' => t('Ignored'),
728 'url' => 'contacts/ignored',
729 'sel' => ($ignored) ? 'active' : '',
730 'title' => t('Only show ignored contacts'),
731 'id' => 'showignored-tab',
736 'label' => t('Archived'),
737 'url' => 'contacts/archived',
738 'sel' => ($archived) ? 'active' : '',
739 'title' => t('Only show archived contacts'),
740 'id' => 'showarchived-tab',
745 'label' => t('Hidden'),
746 'url' => 'contacts/hidden',
747 'sel' => ($hidden) ? 'active' : '',
748 'title' => t('Only show hidden contacts'),
749 'id' => 'showhidden-tab',
755 $tab_tpl = get_markup_template('common_tabs.tpl');
756 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
762 $search_hdr = $search;
763 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
766 $sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') " : "");
769 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
771 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
774 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
775 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
776 intval($_SESSION['uid']));
777 if (dbm::is_result($r)) {
778 $a->set_pager_total($r[0]['total']);
779 $total = $r[0]['total'];
782 $sql_extra3 = unavailable_networks();
784 $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 ",
785 intval($_SESSION['uid']),
786 intval($a->pager['start']),
787 intval($a->pager['itemspage'])
792 if (dbm::is_result($r)) {
793 foreach ($r as $rr) {
794 $contacts[] = _contact_detail_for_template($rr);
798 $tpl = get_markup_template("contacts-template.tpl");
799 $o .= replace_macros($tpl, array(
800 '$baseurl' => z_root(),
801 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
804 '$search' => $search_hdr,
805 '$desc' => t('Search your contacts'),
806 '$finding' => (($searching) ? sprintf(t('Results for: %s'),$search) : ""),
807 '$submit' => t('Find'),
809 '$contacts' => $contacts,
810 '$contact_drop_confirm' => t('Do you really want to delete this contact?'),
812 '$batch_actions' => array(
813 'contacts_batch_update' => t('Update'),
814 'contacts_batch_block' => t('Block')."/".t("Unblock"),
815 "contacts_batch_ignore" => t('Ignore')."/".t("Unignore"),
816 "contacts_batch_archive" => t('Archive')."/".t("Unarchive"),
817 "contacts_batch_drop" => t('Delete'),
819 '$h_batch_actions' => t('Batch Actions'),
820 '$paginate' => paginate($a),
828 * @brief List of pages for the Contact TabBar
830 * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
833 * @param int $contact_id The ID of the contact
834 * @param int $active_tab 1 if tab should be marked as active
836 * @return array with with contact TabBar data
838 function contacts_tab($a, $contact_id, $active_tab) {
842 'label'=>t('Status'),
843 'url' => "contacts/".$contact_id."/posts",
844 'sel' => (($active_tab == 1)?'active':''),
845 'title' => t('Status Messages and Posts'),
846 'id' => 'status-tab',
850 'label'=>t('Profile'),
851 'url' => "contacts/".$contact_id,
852 'sel' => (($active_tab == 2)?'active':''),
853 'title' => t('Profile Details'),
854 'id' => 'status-tab',
859 // Show this tab only if there is visible friend list
860 $x = count_all_friends(local_user(), $contact_id);
862 $tabs[] = array('label'=>t('Contacts'),
863 'url' => "allfriends/".$contact_id,
864 'sel' => (($active_tab == 3)?'active':''),
865 'title' => t('View all contacts'),
866 'id' => 'allfriends-tab',
869 // Show this tab only if there is visible common friend list
870 $common = count_common_friends(local_user(),$contact_id);
872 $tabs[] = array('label'=>t('Common Friends'),
873 'url' => "common/loc/".local_user()."/".$contact_id,
874 'sel' => (($active_tab == 4)?'active':''),
875 'title' => t('View all common friends'),
876 'id' => 'common-loc-tab',
879 $tabs[] = array('label' => t('Advanced'),
880 'url' => 'crepair/' . $contact_id,
881 'sel' => (($active_tab == 5)?'active':''),
882 'title' => t('Advanced Contact Settings'),
883 'id' => 'advanced-tab',
886 $tab_tpl = get_markup_template('common_tabs.tpl');
887 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
892 function contact_posts($a, $contact_id) {
894 $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id));
897 $a->page['aside'] = "";
898 profile_load($a, "", 0, get_contact_details_by_url($contact["url"]));
902 $tab_str = contacts_tab($a, $contact_id, 1);
906 $o .= posts_from_contact_url($a, $contact["url"]);
911 function _contact_detail_for_template($rr){
914 case CONTACT_IS_FRIEND:
915 $dir_icon = 'images/lrarrow.gif';
916 $alt_text = t('Mutual Friendship');
918 case CONTACT_IS_FOLLOWER;
919 $dir_icon = 'images/larrow.gif';
920 $alt_text = t('is a fan of yours');
922 case CONTACT_IS_SHARING;
923 $dir_icon = 'images/rarrow.gif';
924 $alt_text = t('you are a fan of');
929 if(($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) {
930 $url = "redir/{$rr['id']}";
931 $sparkle = ' class="sparkle" ';
939 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
940 'edit_hover' => t('Edit contact'),
941 'photo_menu' => contact_photo_menu($rr),
943 'alt_text' => $alt_text,
944 'dir_icon' => $dir_icon,
945 'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB),
946 'name' => htmlentities($rr['name']),
947 'username' => htmlentities($rr['name']),
948 'account_type' => account_type($rr),
949 'sparkle' => $sparkle,
950 'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']),
952 'network' => network_to_name($rr['network'], $rr['url']),
958 * @brief Gives a array with actions which can performed to a given contact
960 * This includes actions like e.g. 'block', 'hide', 'archive', 'delete' and others
962 * @param array $contact Data about the Contact
963 * @return array with contact related actions
965 function contact_actions($contact) {
967 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
968 $contact_action = array();
970 // Provide friend suggestion only for Friendica contacts
971 if($contact['network'] === NETWORK_DFRN) {
972 $contact_actions['suggest'] = array(
973 'label' => t('Suggest friends'),
974 'url' => 'fsuggest/' . $contact['id'],
982 $contact_actions['update'] = array(
983 'label' => t('Update now'),
984 'url' => 'contacts/' . $contact['id'] . '/update',
991 $contact_actions['block'] = array(
992 'label' => (intval($contact['blocked']) ? t('Unblock') : t('Block') ),
993 'url' => 'contacts/' . $contact['id'] . '/block',
994 'title' => t('Toggle Blocked status'),
995 'sel' => (intval($contact['blocked']) ? 'active' : ''),
996 'id' => 'toggle-block',
999 $contact_actions['ignore'] = array(
1000 'label' => (intval($contact['readonly']) ? t('Unignore') : t('Ignore') ),
1001 'url' => 'contacts/' . $contact['id'] . '/ignore',
1002 'title' => t('Toggle Ignored status'),
1003 'sel' => (intval($contact['readonly']) ? 'active' : ''),
1004 'id' => 'toggle-ignore',
1007 $contact_actions['archive'] = array(
1008 'label' => (intval($contact['archive']) ? t('Unarchive') : t('Archive') ),
1009 'url' => 'contacts/' . $contact['id'] . '/archive',
1010 'title' => t('Toggle Archive status'),
1011 'sel' => (intval($contact['archive']) ? 'active' : ''),
1012 'id' => 'toggle-archive',
1015 $contact_actions['delete'] = array(
1016 'label' => t('Delete'),
1017 'url' => 'contacts/' . $contact['id'] . '/drop',
1018 'title' => t('Delete contact'),
1023 return $contact_actions;