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") {
35 if (! x($a->page,'aside')) {
36 $a->page['aside'] = '';
40 $a->data['contact'] = $r[0];
42 if (($a->data['contact']['network'] != "") AND ($a->data['contact']['network'] != NETWORK_DFRN)) {
43 $networkname = format_network_name($a->data['contact']['network'],$a->data['contact']['url']);
48 /// @TODO Add nice spaces
49 $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array(
50 '$name' => htmlentities($a->data['contact']['name']),
51 '$photo' => $a->data['contact']['photo'],
52 '$url' => ($a->data['contact']['network'] == NETWORK_DFRN) ? "redir/".$a->data['contact']['id'] : $a->data['contact']['url'],
53 '$addr' => (($a->data['contact']['addr'] != "") ? ($a->data['contact']['addr']) : ""),
54 '$network_name' => $networkname,
55 '$network' => t('Network:'),
56 '$account_type' => account_type($a->data['contact'])
59 $finpeople_widget = '';
61 $networks_widget = '';
64 $networks_widget .= networks_widget('contacts',$_GET['nets']);
65 if (isset($_GET['add'])) {
66 $follow_widget = follow_widget($_GET['add']);
68 $follow_widget = follow_widget();
71 $findpeople_widget .= findpeople_widget();
74 $groups_widget .= group_side('contacts','group','full',0,$contact_id);
76 $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"),array(
77 '$vcard_widget' => $vcard_widget,
78 '$findpeople_widget' => $findpeople_widget,
79 '$follow_widget' => $follow_widget,
80 '$groups_widget' => $groups_widget,
81 '$networks_widget' => $networks_widget
85 $tpl = get_markup_template("contacts-head.tpl");
86 $a->page['htmlhead'] .= replace_macros($tpl,array(
87 '$baseurl' => App::get_baseurl(true),
91 $tpl = get_markup_template("contacts-end.tpl");
92 $a->page['end'] .= replace_macros($tpl,array(
93 '$baseurl' => App::get_baseurl(true),
100 function contacts_batch_actions(App $a) {
101 $contacts_id = $_POST['contact_batch'];
102 if (!is_array($contacts_id)) return;
104 $orig_records = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND `uid` = %d AND `self` = 0",
105 implode(",", $contacts_id),
110 foreach($orig_records as $orig_record) {
111 $contact_id = $orig_record['id'];
112 if (x($_POST, 'contacts_batch_update')) {
113 _contact_update($contact_id);
116 if (x($_POST, 'contacts_batch_block')) {
117 $r = _contact_block($contact_id, $orig_record);
118 if ($r) $count_actions++;
120 if (x($_POST, 'contacts_batch_ignore')) {
121 $r = _contact_ignore($contact_id, $orig_record);
122 if ($r) $count_actions++;
124 if (x($_POST, 'contacts_batch_archive')) {
125 $r = _contact_archive($contact_id, $orig_record);
126 if ($r) $count_actions++;
128 if (x($_POST, 'contacts_batch_drop')) {
129 _contact_drop($contact_id, $orig_record);
133 if ($count_actions>0) {
134 info ( sprintf( tt("%d contact edited.", "%d contacts edited.", $count_actions), $count_actions) );
137 if (x($_SESSION,'return_url')) {
138 goaway('' . $_SESSION['return_url']);
147 function contacts_post(App $a) {
149 if (! local_user()) {
153 if ($a->argv[1]==="batch") {
154 contacts_batch_actions($a);
158 $contact_id = intval($a->argv[1]);
163 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
168 if (! count($orig_record)) {
169 notice( t('Could not access contact record.') . EOL);
171 return; // NOTREACHED
174 call_hooks('contact_edit_post', $_POST);
176 $profile_id = intval($_POST['profile-assign']);
178 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
182 if (! dbm::is_result($r)) {
183 notice( t('Could not locate selected profile.') . EOL);
188 $hidden = intval($_POST['hidden']);
190 $notify = intval($_POST['notify']);
192 $fetch_further_information = intval($_POST['fetch_further_information']);
194 $ffi_keyword_blacklist = fix_mce_lf(escape_tags(trim($_POST['ffi_keyword_blacklist'])));
196 $priority = intval($_POST['poll']);
197 if($priority > 5 || $priority < 0)
200 $info = fix_mce_lf(escape_tags(trim($_POST['info'])));
202 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
203 `hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d,
204 `ffi_keyword_blacklist` = '%s' WHERE `id` = %d AND `uid` = %d",
210 intval($fetch_further_information),
211 dbesc($ffi_keyword_blacklist),
216 info( t('Contact updated.') . EOL);
218 notice( t('Failed to update contact record.') . EOL);
220 $r = q("select * from contact where id = %d and uid = %d limit 1",
224 if($r && dbm::is_result($r))
225 $a->data['contact'] = $r[0];
232 function _contact_update($contact_id) {
233 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
239 if ($uid != local_user())
242 if ($r[0]["network"] == NETWORK_OSTATUS) {
243 $result = new_contact($uid, $r[0]["url"], false);
245 if ($result['success'])
246 $r = q("UPDATE `contact` SET `subhub` = 1 WHERE `id` = %d",
247 intval($contact_id));
249 // pull feed and consume it, which should subscribe to the hub.
250 proc_run(PRIORITY_HIGH, "include/onepoll.php", $contact_id, "force");
253 function _contact_update_profile($contact_id) {
254 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
260 if ($uid != local_user())
263 $data = probe_url($r[0]["url"]);
265 // "Feed" or "Unknown" is mostly a sign of communication problems
266 if ((in_array($data["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) AND ($data["network"] != $r[0]["network"]))
269 $updatefields = array("name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm",
270 "poco", "network", "alias");
273 if ($data["network"] == NETWORK_OSTATUS) {
274 $result = new_contact($uid, $data["url"], false);
276 if ($result['success'])
277 $update["subhub"] = true;
280 foreach($updatefields AS $field)
281 if (isset($data[$field]) AND ($data[$field] != ""))
282 $update[$field] = $data[$field];
284 $update["nurl"] = normalise_link($data["url"]);
288 if (isset($data["priority"]) AND ($data["priority"] != 0))
289 $query = "`priority` = ".intval($data["priority"]);
291 foreach($update AS $key => $value) {
295 $query .= "`".$key."` = '".dbesc($value)."'";
301 $r = q("UPDATE `contact` SET $query WHERE `id` = %d AND `uid` = %d",
306 // Update the entry in the contact table
307 update_contact_avatar($data['photo'], local_user(), $contact_id);
309 // Update the entry in the gcontact table
310 update_gcontact_from_probe($data["url"]);
313 function _contact_block($contact_id, $orig_record) {
314 $blocked = (($orig_record['blocked']) ? 0 : 1);
315 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d",
323 function _contact_ignore($contact_id, $orig_record) {
324 $readonly = (($orig_record['readonly']) ? 0 : 1);
325 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d",
332 function _contact_archive($contact_id, $orig_record) {
333 $archived = (($orig_record['archive']) ? 0 : 1);
334 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d",
340 q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
344 function _contact_drop($contact_id, $orig_record) {
347 terminate_friendship($a->user,$a->contact,$orig_record);
348 contact_remove($orig_record['id']);
352 function contacts_content(App $a) {
356 nav_set_selected('contacts');
359 if (! local_user()) {
360 notice( t('Permission denied.') . EOL);
366 $contact_id = intval($a->argv[1]);
372 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
377 if(! count($orig_record)) {
378 notice( t('Could not access contact record.') . EOL);
380 return; // NOTREACHED
383 if($cmd === 'update') {
384 _contact_update($contact_id);
385 goaway('contacts/' . $contact_id);
389 if($cmd === 'updateprofile') {
390 _contact_update_profile($contact_id);
391 goaway('crepair/' . $contact_id);
395 if($cmd === 'block') {
396 $r = _contact_block($contact_id, $orig_record[0]);
398 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
399 info((($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')).EOL);
402 goaway('contacts/' . $contact_id);
403 return; // NOTREACHED
406 if($cmd === 'ignore') {
407 $r = _contact_ignore($contact_id, $orig_record[0]);
409 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
410 info((($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')).EOL);
413 goaway('contacts/' . $contact_id);
414 return; // NOTREACHED
418 if($cmd === 'archive') {
419 $r = _contact_archive($contact_id, $orig_record[0]);
421 $archived = (($orig_record[0]['archive']) ? 0 : 1);
422 info((($archived) ? t('Contact has been archived') : t('Contact has been unarchived')).EOL);
425 goaway('contacts/' . $contact_id);
426 return; // NOTREACHED
429 if($cmd === 'drop') {
431 // Check if we should do HTML-based delete confirmation
432 if($_REQUEST['confirm']) {
433 // <form> can't take arguments in its "action" parameter
434 // so add any arguments as hidden inputs
435 $query = explode_querystring($a->query_string);
437 foreach($query['args'] as $arg) {
438 if(strpos($arg, 'confirm=') === false) {
439 $arg_parts = explode('=', $arg);
440 $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
444 $a->page['aside'] = '';
446 return replace_macros(get_markup_template('contact_drop_confirm.tpl'), array(
447 '$header' => t('Drop contact'),
448 '$contact' => _contact_detail_for_template($orig_record[0]),
450 '$message' => t('Do you really want to delete this contact?'),
451 '$extra_inputs' => $inputs,
452 '$confirm' => t('Yes'),
453 '$confirm_url' => $query['base'],
454 '$confirm_name' => 'confirmed',
455 '$cancel' => t('Cancel'),
458 // Now check how the user responded to the confirmation query
459 if ($_REQUEST['canceled']) {
460 if (x($_SESSION,'return_url')) {
461 goaway('' . $_SESSION['return_url']);
468 _contact_drop($contact_id, $orig_record[0]);
469 info( t('Contact has been removed.') . EOL );
470 if (x($_SESSION,'return_url')) {
471 goaway('' . $_SESSION['return_url']);
476 return; // NOTREACHED
478 if ($cmd === 'posts') {
479 return contact_posts($a, $contact_id);
485 $_SESSION['return_url'] = $a->query_string;
487 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
489 $contact_id = $a->data['contact']['id'];
490 $contact = $a->data['contact'];
492 $editselect = 'none';
493 if( feature_enabled(local_user(),'richtext') )
494 $editselect = 'exact';
496 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
497 '$baseurl' => App::get_baseurl(true),
498 '$editselect' => $editselect,
500 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
501 '$baseurl' => App::get_baseurl(true),
502 '$editselect' => $editselect,
505 require_once('include/contact_selectors.php');
507 $tpl = get_markup_template("contact_edit.tpl");
509 switch($contact['rel']) {
510 case CONTACT_IS_FRIEND:
511 $dir_icon = 'images/lrarrow.gif';
512 $relation_text = t('You are mutual friends with %s');
514 case CONTACT_IS_FOLLOWER;
515 $dir_icon = 'images/larrow.gif';
516 $relation_text = t('You are sharing with %s');
519 case CONTACT_IS_SHARING;
520 $dir_icon = 'images/rarrow.gif';
521 $relation_text = t('%s is sharing with you');
527 if(!in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
530 $relation_text = sprintf($relation_text,htmlentities($contact['name']));
532 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
533 $url = "redir/{$contact['id']}";
534 $sparkle = ' class="sparkle" ';
537 $url = $contact['url'];
541 $insecure = t('Private communications are not available for this contact.');
543 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
545 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
547 if($contact['last-update'] !== '0000-00-00 00:00:00')
548 $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
550 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
552 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
554 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network'], $contact["url"]));
556 //$common = count_common_friends(local_user(),$contact['id']);
557 //$common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
559 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
561 //$x = count_all_friends(local_user(), $contact['id']);
562 //$all_friends = (($x) ? t('View all contacts') : '');
565 $tab_str = contacts_tab($a, $contact_id, 2);
567 $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!') : '');
569 if ($contact['network'] == NETWORK_FEED)
570 $fetch_further_information = array('fetch_further_information', t('Fetch further information for feeds'), $contact['fetch_further_information'], t('Fetch further information for feeds'),
571 array('0'=>t('Disabled'), '1'=>t('Fetch information'), '2'=>t('Fetch information and keywords')));
573 if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2)))
574 $poll_interval = contact_poll_interval($contact['priority'],(! $poll_enabled));
576 if ($contact['network'] == NETWORK_DFRN)
577 $profile_select = contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false));
579 if (in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS)) AND
580 ($contact['rel'] == CONTACT_IS_FOLLOWER))
581 $follow = App::get_baseurl(true)."/follow?url=".urlencode($contact["url"]);
583 // Load contactact related actions like hide, suggest, delete and others
584 $contact_actions = contact_actions($contact);
587 $o .= replace_macros($tpl, array(
588 //'$header' => t('Contact Editor'),
589 '$header' => t("Contact"),
590 '$tab_str' => $tab_str,
591 '$submit' => t('Submit'),
592 '$lbl_vis1' => t('Profile Visibility'),
593 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
594 '$lbl_info1' => t('Contact Information / Notes'),
595 '$infedit' => t('Edit contact notes'),
596 '$common_text' => $common_text,
597 '$common_link' => 'common/loc/' . local_user() . '/' . $contact['id'],
598 '$all_friends' => $all_friends,
599 '$relation_text' => $relation_text,
600 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
601 '$blockunblock' => t('Block/Unblock contact'),
602 '$ignorecont' => t('Ignore contact'),
603 '$lblcrepair' => t("Repair URL settings"),
604 '$lblrecent' => t('View conversations'),
605 '$lblsuggest' => $lblsuggest,
606 //'$delete' => t('Delete contact'),
607 '$nettype' => $nettype,
608 '$poll_interval' => $poll_interval,
609 '$poll_enabled' => $poll_enabled,
610 '$lastupdtext' => t('Last update:'),
611 '$lost_contact' => $lost_contact,
612 '$updpub' => t('Update public posts'),
613 '$last_update' => $last_update,
614 '$udnow' => t('Update now'),
615 '$follow' => $follow,
616 '$follow_text' => t("Connect/Follow"),
617 '$profile_select' => $profile_select,
618 '$contact_id' => $contact['id'],
619 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
620 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
621 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
622 '$info' => $contact['info'],
623 '$cinfo' => array('info', '', $contact['info'], ''),
624 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
625 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
626 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
627 '$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')),
628 '$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
629 '$fetch_further_information' => $fetch_further_information,
630 '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
631 '$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')),
632 '$photo' => $contact['photo'],
633 '$name' => htmlentities($contact['name']),
634 '$dir_icon' => $dir_icon,
635 '$alt_text' => $alt_text,
636 '$sparkle' => $sparkle,
638 '$profileurllabel' => t('Profile URL'),
639 '$profileurl' => $contact['url'],
640 '$account_type' => account_type($contact),
641 '$location' => bbcode($contact["location"]),
642 '$location_label' => t("Location:"),
643 '$xmpp' => bbcode($contact["xmpp"]),
644 '$xmpp_label' => t("XMPP:"),
645 '$about' => bbcode($contact["about"], false, false),
646 '$about_label' => t("About:"),
647 '$keywords' => $contact["keywords"],
648 '$keywords_label' => t("Tags:"),
649 '$contact_action_button' => t("Actions"),
650 '$contact_actions' => $contact_actions,
651 '$contact_status' => t("Status"),
652 '$contact_settings_label' => t('Contact Settings'),
653 '$contact_profile_label' => t("Profile"),
657 $arr = array('contact' => $contact,'output' => $o);
659 call_hooks('contact_edit', $arr);
661 return $arr['output'];
670 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
674 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
675 $sql_extra = " AND `blocked` = 1 ";
678 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
679 $sql_extra = " AND `hidden` = 1 ";
682 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
683 $sql_extra = " AND `readonly` = 1 ";
686 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
687 $sql_extra = " AND `archive` = 1 ";
691 $sql_extra = " AND `blocked` = 0 ";
693 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
694 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
698 'label' => t('Suggestions'),
701 'title' => t('Suggest potential friends'),
702 'id' => 'suggestions-tab',
706 'label' => t('All Contacts'),
707 'url' => 'contacts/all',
708 'sel' => ($all) ? 'active' : '',
709 'title' => t('Show all contacts'),
710 'id' => 'showall-tab',
714 'label' => t('Unblocked'),
716 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
717 'title' => t('Only show unblocked contacts'),
718 'id' => 'showunblocked-tab',
723 'label' => t('Blocked'),
724 'url' => 'contacts/blocked',
725 'sel' => ($blocked) ? 'active' : '',
726 'title' => t('Only show blocked contacts'),
727 'id' => 'showblocked-tab',
732 'label' => t('Ignored'),
733 'url' => 'contacts/ignored',
734 'sel' => ($ignored) ? 'active' : '',
735 'title' => t('Only show ignored contacts'),
736 'id' => 'showignored-tab',
741 'label' => t('Archived'),
742 'url' => 'contacts/archived',
743 'sel' => ($archived) ? 'active' : '',
744 'title' => t('Only show archived contacts'),
745 'id' => 'showarchived-tab',
750 'label' => t('Hidden'),
751 'url' => 'contacts/hidden',
752 'sel' => ($hidden) ? 'active' : '',
753 'title' => t('Only show hidden contacts'),
754 'id' => 'showhidden-tab',
760 $tab_tpl = get_markup_template('common_tabs.tpl');
761 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
767 $search_hdr = $search;
768 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
771 $sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') " : "");
774 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
776 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
779 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
780 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
781 intval($_SESSION['uid']));
782 if (dbm::is_result($r)) {
783 $a->set_pager_total($r[0]['total']);
784 $total = $r[0]['total'];
787 $sql_extra3 = unavailable_networks();
789 $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 ",
790 intval($_SESSION['uid']),
791 intval($a->pager['start']),
792 intval($a->pager['itemspage'])
797 if (dbm::is_result($r)) {
798 foreach ($r as $rr) {
799 $contacts[] = _contact_detail_for_template($rr);
803 $tpl = get_markup_template("contacts-template.tpl");
804 $o .= replace_macros($tpl, array(
805 '$baseurl' => z_root(),
806 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
809 '$search' => $search_hdr,
810 '$desc' => t('Search your contacts'),
811 '$finding' => (($searching) ? sprintf(t('Results for: %s'),$search) : ""),
812 '$submit' => t('Find'),
814 '$contacts' => $contacts,
815 '$contact_drop_confirm' => t('Do you really want to delete this contact?'),
817 '$batch_actions' => array(
818 'contacts_batch_update' => t('Update'),
819 'contacts_batch_block' => t('Block')."/".t("Unblock"),
820 "contacts_batch_ignore" => t('Ignore')."/".t("Unignore"),
821 "contacts_batch_archive" => t('Archive')."/".t("Unarchive"),
822 "contacts_batch_drop" => t('Delete'),
824 '$h_batch_actions' => t('Batch Actions'),
825 '$paginate' => paginate($a),
833 * @brief List of pages for the Contact TabBar
835 * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
838 * @param int $contact_id The ID of the contact
839 * @param int $active_tab 1 if tab should be marked as active
841 * @return array with with contact TabBar data
843 function contacts_tab($a, $contact_id, $active_tab) {
847 'label'=>t('Status'),
848 'url' => "contacts/".$contact_id."/posts",
849 'sel' => (($active_tab == 1)?'active':''),
850 'title' => t('Status Messages and Posts'),
851 'id' => 'status-tab',
855 'label'=>t('Profile'),
856 'url' => "contacts/".$contact_id,
857 'sel' => (($active_tab == 2)?'active':''),
858 'title' => t('Profile Details'),
859 'id' => 'status-tab',
864 // Show this tab only if there is visible friend list
865 $x = count_all_friends(local_user(), $contact_id);
867 $tabs[] = array('label'=>t('Contacts'),
868 'url' => "allfriends/".$contact_id,
869 'sel' => (($active_tab == 3)?'active':''),
870 'title' => t('View all contacts'),
871 'id' => 'allfriends-tab',
874 // Show this tab only if there is visible common friend list
875 $common = count_common_friends(local_user(),$contact_id);
877 $tabs[] = array('label'=>t('Common Friends'),
878 'url' => "common/loc/".local_user()."/".$contact_id,
879 'sel' => (($active_tab == 4)?'active':''),
880 'title' => t('View all common friends'),
881 'id' => 'common-loc-tab',
884 $tabs[] = array('label' => t('Advanced'),
885 'url' => 'crepair/' . $contact_id,
886 'sel' => (($active_tab == 5)?'active':''),
887 'title' => t('Advanced Contact Settings'),
888 'id' => 'advanced-tab',
891 $tab_tpl = get_markup_template('common_tabs.tpl');
892 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
897 function contact_posts($a, $contact_id) {
899 $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id));
902 $a->page['aside'] = "";
903 profile_load($a, "", 0, get_contact_details_by_url($contact["url"]));
907 $tab_str = contacts_tab($a, $contact_id, 1);
911 $o .= posts_from_contact_url($a, $contact["url"]);
916 function _contact_detail_for_template($rr){
919 case CONTACT_IS_FRIEND:
920 $dir_icon = 'images/lrarrow.gif';
921 $alt_text = t('Mutual Friendship');
923 case CONTACT_IS_FOLLOWER;
924 $dir_icon = 'images/larrow.gif';
925 $alt_text = t('is a fan of yours');
927 case CONTACT_IS_SHARING;
928 $dir_icon = 'images/rarrow.gif';
929 $alt_text = t('you are a fan of');
934 if(($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) {
935 $url = "redir/{$rr['id']}";
936 $sparkle = ' class="sparkle" ';
944 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
945 'edit_hover' => t('Edit contact'),
946 'photo_menu' => contact_photo_menu($rr),
948 'alt_text' => $alt_text,
949 'dir_icon' => $dir_icon,
950 'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB),
951 'name' => htmlentities($rr['name']),
952 'username' => htmlentities($rr['name']),
953 'account_type' => account_type($rr),
954 'sparkle' => $sparkle,
955 'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']),
957 'network' => network_to_name($rr['network'], $rr['url']),
963 * @brief Gives a array with actions which can performed to a given contact
965 * This includes actions like e.g. 'block', 'hide', 'archive', 'delete' and others
967 * @param array $contact Data about the Contact
968 * @return array with contact related actions
970 function contact_actions($contact) {
972 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
973 $contact_action = array();
975 // Provide friend suggestion only for Friendica contacts
976 if($contact['network'] === NETWORK_DFRN) {
977 $contact_actions['suggest'] = array(
978 'label' => t('Suggest friends'),
979 'url' => 'fsuggest/' . $contact['id'],
987 $contact_actions['update'] = array(
988 'label' => t('Update now'),
989 'url' => 'contacts/' . $contact['id'] . '/update',
996 $contact_actions['block'] = array(
997 'label' => (intval($contact['blocked']) ? t('Unblock') : t('Block') ),
998 'url' => 'contacts/' . $contact['id'] . '/block',
999 'title' => t('Toggle Blocked status'),
1000 'sel' => (intval($contact['blocked']) ? 'active' : ''),
1001 'id' => 'toggle-block',
1004 $contact_actions['ignore'] = array(
1005 'label' => (intval($contact['readonly']) ? t('Unignore') : t('Ignore') ),
1006 'url' => 'contacts/' . $contact['id'] . '/ignore',
1007 'title' => t('Toggle Ignored status'),
1008 'sel' => (intval($contact['readonly']) ? 'active' : ''),
1009 'id' => 'toggle-ignore',
1012 $contact_actions['archive'] = array(
1013 'label' => (intval($contact['archive']) ? t('Unarchive') : t('Archive') ),
1014 'url' => 'contacts/' . $contact['id'] . '/archive',
1015 'title' => t('Toggle Archive status'),
1016 'sel' => (intval($contact['archive']) ? 'active' : ''),
1017 'id' => 'toggle-archive',
1020 $contact_actions['delete'] = array(
1021 'label' => t('Delete'),
1022 'url' => 'contacts/' . $contact['id'] . '/drop',
1023 'title' => t('Delete contact'),
1028 return $contact_actions;