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(App &$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(App &$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']);
140 function contacts_post(App &$a) {
142 if (! local_user()) {
146 if ($a->argv[1]==="batch") {
147 contacts_batch_actions($a);
151 $contact_id = intval($a->argv[1]);
156 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
161 if (! count($orig_record)) {
162 notice( t('Could not access contact record.') . EOL);
164 return; // NOTREACHED
167 call_hooks('contact_edit_post', $_POST);
169 $profile_id = intval($_POST['profile-assign']);
171 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
175 if (! dbm::is_result($r)) {
176 notice( t('Could not locate selected profile.') . EOL);
181 $hidden = intval($_POST['hidden']);
183 $notify = intval($_POST['notify']);
185 $fetch_further_information = intval($_POST['fetch_further_information']);
187 $ffi_keyword_blacklist = fix_mce_lf(escape_tags(trim($_POST['ffi_keyword_blacklist'])));
189 $priority = intval($_POST['poll']);
190 if($priority > 5 || $priority < 0)
193 $info = fix_mce_lf(escape_tags(trim($_POST['info'])));
195 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
196 `hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d,
197 `ffi_keyword_blacklist` = '%s' WHERE `id` = %d AND `uid` = %d",
203 intval($fetch_further_information),
204 dbesc($ffi_keyword_blacklist),
209 info( t('Contact updated.') . EOL);
211 notice( t('Failed to update contact record.') . EOL);
213 $r = q("select * from contact where id = %d and uid = %d limit 1",
217 if($r && dbm::is_result($r))
218 $a->data['contact'] = $r[0];
225 function _contact_update($contact_id) {
226 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
232 if ($uid != local_user())
235 if ($r[0]["network"] == NETWORK_OSTATUS) {
236 $result = new_contact($uid, $r[0]["url"], false);
238 if ($result['success'])
239 $r = q("UPDATE `contact` SET `subhub` = 1 WHERE `id` = %d",
240 intval($contact_id));
242 // pull feed and consume it, which should subscribe to the hub.
243 proc_run(PRIORITY_HIGH, "include/onepoll.php", $contact_id, "force");
246 function _contact_update_profile($contact_id) {
247 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
253 if ($uid != local_user())
256 $data = probe_url($r[0]["url"]);
258 // "Feed" or "Unknown" is mostly a sign of communication problems
259 if ((in_array($data["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) AND ($data["network"] != $r[0]["network"]))
262 $updatefields = array("name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm",
263 "poco", "network", "alias");
266 if ($data["network"] == NETWORK_OSTATUS) {
267 $result = new_contact($uid, $data["url"], false);
269 if ($result['success'])
270 $update["subhub"] = true;
273 foreach($updatefields AS $field)
274 if (isset($data[$field]) AND ($data[$field] != ""))
275 $update[$field] = $data[$field];
277 $update["nurl"] = normalise_link($data["url"]);
281 if (isset($data["priority"]) AND ($data["priority"] != 0))
282 $query = "`priority` = ".intval($data["priority"]);
284 foreach($update AS $key => $value) {
288 $query .= "`".$key."` = '".dbesc($value)."'";
294 $r = q("UPDATE `contact` SET $query WHERE `id` = %d AND `uid` = %d",
299 // Update the entry in the contact table
300 update_contact_avatar($data['photo'], local_user(), $contact_id);
302 // Update the entry in the gcontact table
303 update_gcontact_from_probe($data["url"]);
306 function _contact_block($contact_id, $orig_record) {
307 $blocked = (($orig_record['blocked']) ? 0 : 1);
308 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d",
316 function _contact_ignore($contact_id, $orig_record) {
317 $readonly = (($orig_record['readonly']) ? 0 : 1);
318 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d",
325 function _contact_archive($contact_id, $orig_record) {
326 $archived = (($orig_record['archive']) ? 0 : 1);
327 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d",
333 q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
337 function _contact_drop($contact_id, $orig_record) {
340 terminate_friendship($a->user,$a->contact,$orig_record);
341 contact_remove($orig_record['id']);
345 function contacts_content(App &$a) {
349 nav_set_selected('contacts');
352 if (! local_user()) {
353 notice( t('Permission denied.') . EOL);
359 $contact_id = intval($a->argv[1]);
365 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
370 if(! count($orig_record)) {
371 notice( t('Could not access contact record.') . EOL);
373 return; // NOTREACHED
376 if($cmd === 'update') {
377 _contact_update($contact_id);
378 goaway('contacts/' . $contact_id);
382 if($cmd === 'updateprofile') {
383 _contact_update_profile($contact_id);
384 goaway('crepair/' . $contact_id);
388 if($cmd === 'block') {
389 $r = _contact_block($contact_id, $orig_record[0]);
391 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
392 info((($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')).EOL);
395 goaway('contacts/' . $contact_id);
396 return; // NOTREACHED
399 if($cmd === 'ignore') {
400 $r = _contact_ignore($contact_id, $orig_record[0]);
402 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
403 info((($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')).EOL);
406 goaway('contacts/' . $contact_id);
407 return; // NOTREACHED
411 if($cmd === 'archive') {
412 $r = _contact_archive($contact_id, $orig_record[0]);
414 $archived = (($orig_record[0]['archive']) ? 0 : 1);
415 info((($archived) ? t('Contact has been archived') : t('Contact has been unarchived')).EOL);
418 goaway('contacts/' . $contact_id);
419 return; // NOTREACHED
422 if($cmd === 'drop') {
424 // Check if we should do HTML-based delete confirmation
425 if($_REQUEST['confirm']) {
426 // <form> can't take arguments in its "action" parameter
427 // so add any arguments as hidden inputs
428 $query = explode_querystring($a->query_string);
430 foreach($query['args'] as $arg) {
431 if(strpos($arg, 'confirm=') === false) {
432 $arg_parts = explode('=', $arg);
433 $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
437 $a->page['aside'] = '';
439 return replace_macros(get_markup_template('contact_drop_confirm.tpl'), array(
440 '$header' => t('Drop contact'),
441 '$contact' => _contact_detail_for_template($orig_record[0]),
443 '$message' => t('Do you really want to delete this contact?'),
444 '$extra_inputs' => $inputs,
445 '$confirm' => t('Yes'),
446 '$confirm_url' => $query['base'],
447 '$confirm_name' => 'confirmed',
448 '$cancel' => t('Cancel'),
451 // Now check how the user responded to the confirmation query
452 if($_REQUEST['canceled']) {
453 if(x($_SESSION,'return_url'))
454 goaway('' . $_SESSION['return_url']);
459 _contact_drop($contact_id, $orig_record[0]);
460 info( t('Contact has been removed.') . EOL );
461 if(x($_SESSION,'return_url'))
462 goaway('' . $_SESSION['return_url']);
465 return; // NOTREACHED
467 if($cmd === 'posts') {
468 return contact_posts($a, $contact_id);
474 $_SESSION['return_url'] = $a->query_string;
476 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
478 $contact_id = $a->data['contact']['id'];
479 $contact = $a->data['contact'];
481 $editselect = 'none';
482 if( feature_enabled(local_user(),'richtext') )
483 $editselect = 'exact';
485 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
486 '$baseurl' => App::get_baseurl(true),
487 '$editselect' => $editselect,
489 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
490 '$baseurl' => App::get_baseurl(true),
491 '$editselect' => $editselect,
494 require_once('include/contact_selectors.php');
496 $tpl = get_markup_template("contact_edit.tpl");
498 switch($contact['rel']) {
499 case CONTACT_IS_FRIEND:
500 $dir_icon = 'images/lrarrow.gif';
501 $relation_text = t('You are mutual friends with %s');
503 case CONTACT_IS_FOLLOWER;
504 $dir_icon = 'images/larrow.gif';
505 $relation_text = t('You are sharing with %s');
508 case CONTACT_IS_SHARING;
509 $dir_icon = 'images/rarrow.gif';
510 $relation_text = t('%s is sharing with you');
516 if(!in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
519 $relation_text = sprintf($relation_text,htmlentities($contact['name']));
521 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
522 $url = "redir/{$contact['id']}";
523 $sparkle = ' class="sparkle" ';
526 $url = $contact['url'];
530 $insecure = t('Private communications are not available for this contact.');
532 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
534 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
536 if($contact['last-update'] !== '0000-00-00 00:00:00')
537 $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
539 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
541 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
543 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network'], $contact["url"]));
545 //$common = count_common_friends(local_user(),$contact['id']);
546 //$common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
548 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
550 //$x = count_all_friends(local_user(), $contact['id']);
551 //$all_friends = (($x) ? t('View all contacts') : '');
554 $tab_str = contacts_tab($a, $contact_id, 2);
556 $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!') : '');
558 if ($contact['network'] == NETWORK_FEED)
559 $fetch_further_information = array('fetch_further_information', t('Fetch further information for feeds'), $contact['fetch_further_information'], t('Fetch further information for feeds'),
560 array('0'=>t('Disabled'), '1'=>t('Fetch information'), '2'=>t('Fetch information and keywords')));
562 if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2)))
563 $poll_interval = contact_poll_interval($contact['priority'],(! $poll_enabled));
565 if ($contact['network'] == NETWORK_DFRN)
566 $profile_select = contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false));
568 if (in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS)) AND
569 ($contact['rel'] == CONTACT_IS_FOLLOWER))
570 $follow = App::get_baseurl(true)."/follow?url=".urlencode($contact["url"]);
572 // Load contactact related actions like hide, suggest, delete and others
573 $contact_actions = contact_actions($contact);
576 $o .= replace_macros($tpl, array(
577 //'$header' => t('Contact Editor'),
578 '$header' => t("Contact"),
579 '$tab_str' => $tab_str,
580 '$submit' => t('Submit'),
581 '$lbl_vis1' => t('Profile Visibility'),
582 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
583 '$lbl_info1' => t('Contact Information / Notes'),
584 '$infedit' => t('Edit contact notes'),
585 '$common_text' => $common_text,
586 '$common_link' => 'common/loc/' . local_user() . '/' . $contact['id'],
587 '$all_friends' => $all_friends,
588 '$relation_text' => $relation_text,
589 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
590 '$blockunblock' => t('Block/Unblock contact'),
591 '$ignorecont' => t('Ignore contact'),
592 '$lblcrepair' => t("Repair URL settings"),
593 '$lblrecent' => t('View conversations'),
594 '$lblsuggest' => $lblsuggest,
595 //'$delete' => t('Delete contact'),
596 '$nettype' => $nettype,
597 '$poll_interval' => $poll_interval,
598 '$poll_enabled' => $poll_enabled,
599 '$lastupdtext' => t('Last update:'),
600 '$lost_contact' => $lost_contact,
601 '$updpub' => t('Update public posts'),
602 '$last_update' => $last_update,
603 '$udnow' => t('Update now'),
604 '$follow' => $follow,
605 '$follow_text' => t("Connect/Follow"),
606 '$profile_select' => $profile_select,
607 '$contact_id' => $contact['id'],
608 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
609 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
610 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
611 '$info' => $contact['info'],
612 '$cinfo' => array('info', '', $contact['info'], ''),
613 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
614 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
615 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
616 '$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')),
617 '$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
618 '$fetch_further_information' => $fetch_further_information,
619 '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
620 '$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')),
621 '$photo' => $contact['photo'],
622 '$name' => htmlentities($contact['name']),
623 '$dir_icon' => $dir_icon,
624 '$alt_text' => $alt_text,
625 '$sparkle' => $sparkle,
627 '$profileurllabel' => t('Profile URL'),
628 '$profileurl' => $contact['url'],
629 '$account_type' => account_type($contact),
630 '$location' => bbcode($contact["location"]),
631 '$location_label' => t("Location:"),
632 '$xmpp' => bbcode($contact["xmpp"]),
633 '$xmpp_label' => t("XMPP:"),
634 '$about' => bbcode($contact["about"], false, false),
635 '$about_label' => t("About:"),
636 '$keywords' => $contact["keywords"],
637 '$keywords_label' => t("Tags:"),
638 '$contact_action_button' => t("Actions"),
639 '$contact_actions' => $contact_actions,
640 '$contact_status' => t("Status"),
641 '$contact_settings_label' => t('Contact Settings'),
642 '$contact_profile_label' => t("Profile"),
646 $arr = array('contact' => $contact,'output' => $o);
648 call_hooks('contact_edit', $arr);
650 return $arr['output'];
659 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
663 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
664 $sql_extra = " AND `blocked` = 1 ";
667 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
668 $sql_extra = " AND `hidden` = 1 ";
671 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
672 $sql_extra = " AND `readonly` = 1 ";
675 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
676 $sql_extra = " AND `archive` = 1 ";
680 $sql_extra = " AND `blocked` = 0 ";
682 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
683 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
687 'label' => t('Suggestions'),
690 'title' => t('Suggest potential friends'),
691 'id' => 'suggestions-tab',
695 'label' => t('All Contacts'),
696 'url' => 'contacts/all',
697 'sel' => ($all) ? 'active' : '',
698 'title' => t('Show all contacts'),
699 'id' => 'showall-tab',
703 'label' => t('Unblocked'),
705 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
706 'title' => t('Only show unblocked contacts'),
707 'id' => 'showunblocked-tab',
712 'label' => t('Blocked'),
713 'url' => 'contacts/blocked',
714 'sel' => ($blocked) ? 'active' : '',
715 'title' => t('Only show blocked contacts'),
716 'id' => 'showblocked-tab',
721 'label' => t('Ignored'),
722 'url' => 'contacts/ignored',
723 'sel' => ($ignored) ? 'active' : '',
724 'title' => t('Only show ignored contacts'),
725 'id' => 'showignored-tab',
730 'label' => t('Archived'),
731 'url' => 'contacts/archived',
732 'sel' => ($archived) ? 'active' : '',
733 'title' => t('Only show archived contacts'),
734 'id' => 'showarchived-tab',
739 'label' => t('Hidden'),
740 'url' => 'contacts/hidden',
741 'sel' => ($hidden) ? 'active' : '',
742 'title' => t('Only show hidden contacts'),
743 'id' => 'showhidden-tab',
749 $tab_tpl = get_markup_template('common_tabs.tpl');
750 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
756 $search_hdr = $search;
757 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
760 $sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') " : "");
763 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
765 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
768 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
769 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
770 intval($_SESSION['uid']));
771 if (dbm::is_result($r)) {
772 $a->set_pager_total($r[0]['total']);
773 $total = $r[0]['total'];
776 $sql_extra3 = unavailable_networks();
778 $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 ",
779 intval($_SESSION['uid']),
780 intval($a->pager['start']),
781 intval($a->pager['itemspage'])
786 if (dbm::is_result($r)) {
787 foreach ($r as $rr) {
788 $contacts[] = _contact_detail_for_template($rr);
792 $tpl = get_markup_template("contacts-template.tpl");
793 $o .= replace_macros($tpl, array(
794 '$baseurl' => z_root(),
795 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
798 '$search' => $search_hdr,
799 '$desc' => t('Search your contacts'),
800 '$finding' => (($searching) ? sprintf(t('Results for: %s'),$search) : ""),
801 '$submit' => t('Find'),
803 '$contacts' => $contacts,
804 '$contact_drop_confirm' => t('Do you really want to delete this contact?'),
806 '$batch_actions' => array(
807 'contacts_batch_update' => t('Update'),
808 'contacts_batch_block' => t('Block')."/".t("Unblock"),
809 "contacts_batch_ignore" => t('Ignore')."/".t("Unignore"),
810 "contacts_batch_archive" => t('Archive')."/".t("Unarchive"),
811 "contacts_batch_drop" => t('Delete'),
813 '$h_batch_actions' => t('Batch Actions'),
814 '$paginate' => paginate($a),
822 * @brief List of pages for the Contact TabBar
824 * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
827 * @param int $contact_id The ID of the contact
828 * @param int $active_tab 1 if tab should be marked as active
830 * @return array with with contact TabBar data
832 function contacts_tab($a, $contact_id, $active_tab) {
836 'label'=>t('Status'),
837 'url' => "contacts/".$contact_id."/posts",
838 'sel' => (($active_tab == 1)?'active':''),
839 'title' => t('Status Messages and Posts'),
840 'id' => 'status-tab',
844 'label'=>t('Profile'),
845 'url' => "contacts/".$contact_id,
846 'sel' => (($active_tab == 2)?'active':''),
847 'title' => t('Profile Details'),
848 'id' => 'status-tab',
853 // Show this tab only if there is visible friend list
854 $x = count_all_friends(local_user(), $contact_id);
856 $tabs[] = array('label'=>t('Contacts'),
857 'url' => "allfriends/".$contact_id,
858 'sel' => (($active_tab == 3)?'active':''),
859 'title' => t('View all contacts'),
860 'id' => 'allfriends-tab',
863 // Show this tab only if there is visible common friend list
864 $common = count_common_friends(local_user(),$contact_id);
866 $tabs[] = array('label'=>t('Common Friends'),
867 'url' => "common/loc/".local_user()."/".$contact_id,
868 'sel' => (($active_tab == 4)?'active':''),
869 'title' => t('View all common friends'),
870 'id' => 'common-loc-tab',
873 $tabs[] = array('label' => t('Advanced'),
874 'url' => 'crepair/' . $contact_id,
875 'sel' => (($active_tab == 5)?'active':''),
876 'title' => t('Advanced Contact Settings'),
877 'id' => 'advanced-tab',
880 $tab_tpl = get_markup_template('common_tabs.tpl');
881 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
886 function contact_posts($a, $contact_id) {
888 $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id));
891 $a->page['aside'] = "";
892 profile_load($a, "", 0, get_contact_details_by_url($contact["url"]));
896 $tab_str = contacts_tab($a, $contact_id, 1);
900 $o .= posts_from_contact_url($a, $contact["url"]);
905 function _contact_detail_for_template($rr){
908 case CONTACT_IS_FRIEND:
909 $dir_icon = 'images/lrarrow.gif';
910 $alt_text = t('Mutual Friendship');
912 case CONTACT_IS_FOLLOWER;
913 $dir_icon = 'images/larrow.gif';
914 $alt_text = t('is a fan of yours');
916 case CONTACT_IS_SHARING;
917 $dir_icon = 'images/rarrow.gif';
918 $alt_text = t('you are a fan of');
923 if(($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) {
924 $url = "redir/{$rr['id']}";
925 $sparkle = ' class="sparkle" ';
933 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
934 'edit_hover' => t('Edit contact'),
935 'photo_menu' => contact_photo_menu($rr),
937 'alt_text' => $alt_text,
938 'dir_icon' => $dir_icon,
939 'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB),
940 'name' => htmlentities($rr['name']),
941 'username' => htmlentities($rr['name']),
942 'account_type' => account_type($rr),
943 'sparkle' => $sparkle,
944 'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']),
946 'network' => network_to_name($rr['network'], $rr['url']),
952 * @brief Gives a array with actions which can performed to a given contact
954 * This includes actions like e.g. 'block', 'hide', 'archive', 'delete' and others
956 * @param array $contact Data about the Contact
957 * @return array with contact related actions
959 function contact_actions($contact) {
961 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
962 $contact_action = array();
964 // Provide friend suggestion only for Friendica contacts
965 if($contact['network'] === NETWORK_DFRN) {
966 $contact_actions['suggest'] = array(
967 'label' => t('Suggest friends'),
968 'url' => 'fsuggest/' . $contact['id'],
976 $contact_actions['update'] = array(
977 'label' => t('Update now'),
978 'url' => 'contacts/' . $contact['id'] . '/update',
985 $contact_actions['block'] = array(
986 'label' => (intval($contact['blocked']) ? t('Unblock') : t('Block') ),
987 'url' => 'contacts/' . $contact['id'] . '/block',
988 'title' => t('Toggle Blocked status'),
989 'sel' => (intval($contact['blocked']) ? 'active' : ''),
990 'id' => 'toggle-block',
993 $contact_actions['ignore'] = array(
994 'label' => (intval($contact['readonly']) ? t('Unignore') : t('Ignore') ),
995 'url' => 'contacts/' . $contact['id'] . '/ignore',
996 'title' => t('Toggle Ignored status'),
997 'sel' => (intval($contact['readonly']) ? 'active' : ''),
998 'id' => 'toggle-ignore',
1001 $contact_actions['archive'] = array(
1002 'label' => (intval($contact['archive']) ? t('Unarchive') : t('Archive') ),
1003 'url' => 'contacts/' . $contact['id'] . '/archive',
1004 'title' => t('Toggle Archive status'),
1005 'sel' => (intval($contact['archive']) ? 'active' : ''),
1006 'id' => 'toggle-archive',
1009 $contact_actions['delete'] = array(
1010 'label' => t('Delete'),
1011 'url' => 'contacts/' . $contact['id'] . '/drop',
1012 'title' => t('Delete contact'),
1017 return $contact_actions;