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)) {
106 $orig_records = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND `uid` = %d AND `self` = 0",
107 implode(",", $contacts_id),
111 if (!dbm::is_result($orig_records)) {
112 /// @TODO EOL really needed?
113 notice( t('Could not access contact record(s).') . EOL);
115 return; // NOTREACHED
119 foreach ($orig_records as $orig_record) {
120 $contact_id = $orig_record['id'];
121 if (x($_POST, 'contacts_batch_update')) {
122 _contact_update($contact_id);
125 if (x($_POST, 'contacts_batch_block')) {
126 $r = _contact_block($contact_id, $orig_record);
127 if ($r) $count_actions++;
129 if (x($_POST, 'contacts_batch_ignore')) {
130 $r = _contact_ignore($contact_id, $orig_record);
131 if ($r) $count_actions++;
133 if (x($_POST, 'contacts_batch_archive')) {
134 $r = _contact_archive($contact_id, $orig_record);
135 if ($r) $count_actions++;
137 if (x($_POST, 'contacts_batch_drop')) {
138 _contact_drop($contact_id, $orig_record);
143 if ($count_actions > 0) {
144 info ( sprintf( tt("%d contact edited.", "%d contacts edited.", $count_actions), $count_actions) );
147 if (x($_SESSION,'return_url')) {
148 goaway('' . $_SESSION['return_url']);
156 function contacts_post(App $a) {
158 if (! local_user()) {
162 if ($a->argv[1]==="batch") {
163 contacts_batch_actions($a);
167 $contact_id = intval($a->argv[1]);
172 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
177 if (! dbm::is_result($orig_record)) {
178 /// @TODO EOL really needed?
179 notice( t('Could not access contact record.') . EOL);
181 return; // NOTREACHED
184 call_hooks('contact_edit_post', $_POST);
186 $profile_id = intval($_POST['profile-assign']);
188 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
192 if (! dbm::is_result($r)) {
193 notice( t('Could not locate selected profile.') . EOL);
198 $hidden = intval($_POST['hidden']);
200 $notify = intval($_POST['notify']);
202 $fetch_further_information = intval($_POST['fetch_further_information']);
204 $ffi_keyword_blacklist = escape_tags(trim($_POST['ffi_keyword_blacklist']));
206 $priority = intval($_POST['poll']);
208 if ($priority > 5 || $priority < 0) {
212 $info = escape_tags(trim($_POST['info']));
214 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
215 `hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d,
216 `ffi_keyword_blacklist` = '%s' WHERE `id` = %d AND `uid` = %d",
222 intval($fetch_further_information),
223 dbesc($ffi_keyword_blacklist),
227 /// @TODO Decide to use dbm::is_result() here, what does $r include?
229 info( t('Contact updated.') . EOL);
231 notice( t('Failed to update contact record.') . EOL);
234 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
239 if (dbm::is_result($r)) {
240 $a->data['contact'] = $r[0];
248 function _contact_update($contact_id) {
249 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
250 if (!dbm::is_result($r)) {
256 if ($uid != local_user()) {
260 if ($r[0]["network"] == NETWORK_OSTATUS) {
261 $result = new_contact($uid, $r[0]["url"], false);
263 if ($result['success']) {
264 $r = q("UPDATE `contact` SET `subhub` = 1 WHERE `id` = %d",
265 intval($contact_id));
268 // pull feed and consume it, which should subscribe to the hub.
269 proc_run(PRIORITY_HIGH, "include/onepoll.php", $contact_id, "force");
273 function _contact_update_profile($contact_id) {
274 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
275 if (!dbm::is_result($r)) {
281 if ($uid != local_user()) {
285 $data = probe_url($r[0]["url"]);
287 // "Feed" or "Unknown" is mostly a sign of communication problems
288 if ((in_array($data["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) AND ($data["network"] != $r[0]["network"])) {
292 $updatefields = array("name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm",
293 "poco", "network", "alias");
296 if ($data["network"] == NETWORK_OSTATUS) {
297 $result = new_contact($uid, $data["url"], false);
299 if ($result['success']) {
300 $update["subhub"] = true;
304 foreach ($updatefields AS $field) {
305 if (isset($data[$field]) AND ($data[$field] != "")) {
306 $update[$field] = $data[$field];
310 $update["nurl"] = normalise_link($data["url"]);
314 if (isset($data["priority"]) AND ($data["priority"] != 0)) {
315 $query = "`priority` = ".intval($data["priority"]);
318 foreach ($update AS $key => $value) {
323 $query .= "`".$key."` = '".dbesc($value)."'";
330 $r = q("UPDATE `contact` SET $query WHERE `id` = %d AND `uid` = %d",
335 // Update the entry in the contact table
336 update_contact_avatar($data['photo'], local_user(), $contact_id);
338 // Update the entry in the gcontact table
339 update_gcontact_from_probe($data["url"]);
342 function _contact_block($contact_id, $orig_record) {
343 $blocked = (($orig_record['blocked']) ? 0 : 1);
344 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d",
352 function _contact_ignore($contact_id, $orig_record) {
353 $readonly = (($orig_record['readonly']) ? 0 : 1);
354 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d",
361 function _contact_archive($contact_id, $orig_record) {
362 $archived = (($orig_record['archive']) ? 0 : 1);
363 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d",
369 q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
373 function _contact_drop($contact_id, $orig_record) {
376 terminate_friendship($a->user,$a->contact,$orig_record);
377 contact_remove($orig_record['id']);
381 function contacts_content(App $a) {
385 nav_set_selected('contacts');
388 if (! local_user()) {
389 notice( t('Permission denied.') . EOL);
395 $contact_id = intval($a->argv[1]);
402 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
407 if (! dbm::is_result($orig_record)) {
408 notice( t('Could not access contact record.') . EOL);
410 return; // NOTREACHED
413 if ($cmd === 'update') {
414 _contact_update($contact_id);
415 goaway('contacts/' . $contact_id);
419 if ($cmd === 'updateprofile') {
420 _contact_update_profile($contact_id);
421 goaway('crepair/' . $contact_id);
425 if ($cmd === 'block') {
426 $r = _contact_block($contact_id, $orig_record[0]);
427 /// @TODO is $r a database result?
429 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
430 info((($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')).EOL);
433 goaway('contacts/' . $contact_id);
434 return; // NOTREACHED
437 if ($cmd === 'ignore') {
438 $r = _contact_ignore($contact_id, $orig_record[0]);
439 /// @TODO is $r a database result?
441 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
442 info((($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')).EOL);
445 goaway('contacts/' . $contact_id);
446 return; // NOTREACHED
450 if ($cmd === 'archive') {
451 $r = _contact_archive($contact_id, $orig_record[0]);
452 /// @TODO is $r a database result?
454 $archived = (($orig_record[0]['archive']) ? 0 : 1);
455 info((($archived) ? t('Contact has been archived') : t('Contact has been unarchived')).EOL);
458 goaway('contacts/' . $contact_id);
459 return; // NOTREACHED
462 if ($cmd === 'drop') {
464 // Check if we should do HTML-based delete confirmation
465 if ($_REQUEST['confirm']) {
466 // <form> can't take arguments in its "action" parameter
467 // so add any arguments as hidden inputs
468 $query = explode_querystring($a->query_string);
470 foreach ($query['args'] as $arg) {
471 if (strpos($arg, 'confirm=') === false) {
472 $arg_parts = explode('=', $arg);
473 $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
477 $a->page['aside'] = '';
479 return replace_macros(get_markup_template('contact_drop_confirm.tpl'), array(
480 '$header' => t('Drop contact'),
481 '$contact' => _contact_detail_for_template($orig_record[0]),
483 '$message' => t('Do you really want to delete this contact?'),
484 '$extra_inputs' => $inputs,
485 '$confirm' => t('Yes'),
486 '$confirm_url' => $query['base'],
487 '$confirm_name' => 'confirmed',
488 '$cancel' => t('Cancel'),
491 // Now check how the user responded to the confirmation query
492 if ($_REQUEST['canceled']) {
493 if (x($_SESSION,'return_url')) {
494 goaway('' . $_SESSION['return_url']);
500 _contact_drop($contact_id, $orig_record[0]);
501 info( t('Contact has been removed.') . EOL );
502 if (x($_SESSION,'return_url')) {
503 goaway('' . $_SESSION['return_url']);
507 return; // NOTREACHED
509 if ($cmd === 'posts') {
510 return contact_posts($a, $contact_id);
516 $_SESSION['return_url'] = $a->query_string;
518 if ((x($a->data,'contact')) && (is_array($a->data['contact']))) {
520 $contact_id = $a->data['contact']['id'];
521 $contact = $a->data['contact'];
523 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
524 '$baseurl' => App::get_baseurl(true),
526 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
527 '$baseurl' => App::get_baseurl(true),
530 require_once('include/contact_selectors.php');
532 $tpl = get_markup_template("contact_edit.tpl");
534 switch($contact['rel']) {
535 case CONTACT_IS_FRIEND:
536 $dir_icon = 'images/lrarrow.gif';
537 $relation_text = t('You are mutual friends with %s');
539 case CONTACT_IS_FOLLOWER;
540 $dir_icon = 'images/larrow.gif';
541 $relation_text = t('You are sharing with %s');
544 case CONTACT_IS_SHARING;
545 $dir_icon = 'images/rarrow.gif';
546 $relation_text = t('%s is sharing with you');
552 if (!in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
555 $relation_text = sprintf($relation_text,htmlentities($contact['name']));
557 if (($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
558 $url = "redir/{$contact['id']}";
559 $sparkle = ' class="sparkle" ';
562 $url = $contact['url'];
566 $insecure = t('Private communications are not available for this contact.');
568 $last_update = (($contact['last-update'] <= NULL_DATE)
570 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
572 if ($contact['last-update'] !== NULL_DATE) {
573 $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
575 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
577 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
579 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network'], $contact["url"]));
581 //$common = count_common_friends(local_user(),$contact['id']);
582 //$common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
584 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
586 //$x = count_all_friends(local_user(), $contact['id']);
587 //$all_friends = (($x) ? t('View all contacts') : '');
590 $tab_str = contacts_tab($a, $contact_id, 2);
592 $lost_contact = (($contact['archive'] && $contact['term-date'] > NULL_DATE && $contact['term-date'] < datetime_convert('','','now')) ? t('Communications lost with this contact!') : '');
594 if ($contact['network'] == NETWORK_FEED) {
595 $fetch_further_information = array('fetch_further_information', t('Fetch further information for feeds'), $contact['fetch_further_information'], t('Fetch further information for feeds'),
596 array('0'=>t('Disabled'), '1'=>t('Fetch information'), '2'=>t('Fetch information and keywords')));
598 if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2))) {
599 $poll_interval = contact_poll_interval($contact['priority'],(! $poll_enabled));
602 if ($contact['network'] == NETWORK_DFRN) {
603 $profile_select = contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false));
606 if (in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS)) AND
607 ($contact['rel'] == CONTACT_IS_FOLLOWER)) {
608 $follow = App::get_baseurl(true)."/follow?url=".urlencode($contact["url"]);
611 // Load contactact related actions like hide, suggest, delete and others
612 $contact_actions = contact_actions($contact);
614 $o .= replace_macros($tpl, array(
615 //'$header' => t('Contact Editor'),
616 '$header' => t("Contact"),
617 '$tab_str' => $tab_str,
618 '$submit' => t('Submit'),
619 '$lbl_vis1' => t('Profile Visibility'),
620 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
621 '$lbl_info1' => t('Contact Information / Notes'),
622 '$infedit' => t('Edit contact notes'),
623 '$common_text' => $common_text,
624 '$common_link' => 'common/loc/' . local_user() . '/' . $contact['id'],
625 '$all_friends' => $all_friends,
626 '$relation_text' => $relation_text,
627 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
628 '$blockunblock' => t('Block/Unblock contact'),
629 '$ignorecont' => t('Ignore contact'),
630 '$lblcrepair' => t("Repair URL settings"),
631 '$lblrecent' => t('View conversations'),
632 '$lblsuggest' => $lblsuggest,
633 //'$delete' => t('Delete contact'),
634 '$nettype' => $nettype,
635 '$poll_interval' => $poll_interval,
636 '$poll_enabled' => $poll_enabled,
637 '$lastupdtext' => t('Last update:'),
638 '$lost_contact' => $lost_contact,
639 '$updpub' => t('Update public posts'),
640 '$last_update' => $last_update,
641 '$udnow' => t('Update now'),
642 '$follow' => $follow,
643 '$follow_text' => t("Connect/Follow"),
644 '$profile_select' => $profile_select,
645 '$contact_id' => $contact['id'],
646 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
647 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
648 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
649 '$info' => $contact['info'],
650 '$cinfo' => array('info', '', $contact['info'], ''),
651 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
652 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
653 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
654 '$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')),
655 '$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
656 '$fetch_further_information' => $fetch_further_information,
657 '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
658 '$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')),
659 '$photo' => $contact['photo'],
660 '$name' => htmlentities($contact['name']),
661 '$dir_icon' => $dir_icon,
662 '$alt_text' => $alt_text,
663 '$sparkle' => $sparkle,
665 '$profileurllabel' => t('Profile URL'),
666 '$profileurl' => $contact['url'],
667 '$account_type' => account_type($contact),
668 '$location' => bbcode($contact["location"]),
669 '$location_label' => t("Location:"),
670 '$xmpp' => bbcode($contact["xmpp"]),
671 '$xmpp_label' => t("XMPP:"),
672 '$about' => bbcode($contact["about"], false, false),
673 '$about_label' => t("About:"),
674 '$keywords' => $contact["keywords"],
675 '$keywords_label' => t("Tags:"),
676 '$contact_action_button' => t("Actions"),
677 '$contact_actions' => $contact_actions,
678 '$contact_status' => t("Status"),
679 '$contact_settings_label' => t('Contact Settings'),
680 '$contact_profile_label' => t("Profile"),
684 $arr = array('contact' => $contact,'output' => $o);
686 call_hooks('contact_edit', $arr);
688 return $arr['output'];
697 if (($a->argc == 2) && ($a->argv[1] === 'all')) {
700 } elseif (($a->argc == 2) && ($a->argv[1] === 'blocked')) {
701 $sql_extra = " AND `blocked` = 1 ";
703 } elseif (($a->argc == 2) && ($a->argv[1] === 'hidden')) {
704 $sql_extra = " AND `hidden` = 1 ";
706 } elseif (($a->argc == 2) && ($a->argv[1] === 'ignored')) {
707 $sql_extra = " AND `readonly` = 1 ";
709 } elseif (($a->argc == 2) && ($a->argv[1] === 'archived')) {
710 $sql_extra = " AND `archive` = 1 ";
713 $sql_extra = " AND `blocked` = 0 ";
716 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
717 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
721 'label' => t('Suggestions'),
724 'title' => t('Suggest potential friends'),
725 'id' => 'suggestions-tab',
729 'label' => t('All Contacts'),
730 'url' => 'contacts/all',
731 'sel' => ($all) ? 'active' : '',
732 'title' => t('Show all contacts'),
733 'id' => 'showall-tab',
737 'label' => t('Unblocked'),
739 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
740 'title' => t('Only show unblocked contacts'),
741 'id' => 'showunblocked-tab',
746 'label' => t('Blocked'),
747 'url' => 'contacts/blocked',
748 'sel' => ($blocked) ? 'active' : '',
749 'title' => t('Only show blocked contacts'),
750 'id' => 'showblocked-tab',
755 'label' => t('Ignored'),
756 'url' => 'contacts/ignored',
757 'sel' => ($ignored) ? 'active' : '',
758 'title' => t('Only show ignored contacts'),
759 'id' => 'showignored-tab',
764 'label' => t('Archived'),
765 'url' => 'contacts/archived',
766 'sel' => ($archived) ? 'active' : '',
767 'title' => t('Only show archived contacts'),
768 'id' => 'showarchived-tab',
773 'label' => t('Hidden'),
774 'url' => 'contacts/hidden',
775 'sel' => ($hidden) ? 'active' : '',
776 'title' => t('Only show hidden contacts'),
777 'id' => 'showhidden-tab',
783 $tab_tpl = get_markup_template('common_tabs.tpl');
784 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
788 $search_hdr = $search;
789 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
792 $sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') " : "");
795 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
798 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
800 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
801 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
802 intval($_SESSION['uid']));
803 if (dbm::is_result($r)) {
804 $a->set_pager_total($r[0]['total']);
805 $total = $r[0]['total'];
808 $sql_extra3 = unavailable_networks();
810 $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 ",
811 intval($_SESSION['uid']),
812 intval($a->pager['start']),
813 intval($a->pager['itemspage'])
818 if (dbm::is_result($r)) {
819 foreach ($r as $rr) {
820 $contacts[] = _contact_detail_for_template($rr);
824 $tpl = get_markup_template("contacts-template.tpl");
825 $o .= replace_macros($tpl, array(
826 '$baseurl' => z_root(),
827 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
830 '$search' => $search_hdr,
831 '$desc' => t('Search your contacts'),
832 '$finding' => (($searching) ? sprintf(t('Results for: %s'),$search) : ""),
833 '$submit' => t('Find'),
835 '$contacts' => $contacts,
836 '$contact_drop_confirm' => t('Do you really want to delete this contact?'),
838 '$batch_actions' => array(
839 'contacts_batch_update' => t('Update'),
840 'contacts_batch_block' => t('Block')."/".t("Unblock"),
841 "contacts_batch_ignore" => t('Ignore')."/".t("Unignore"),
842 "contacts_batch_archive" => t('Archive')."/".t("Unarchive"),
843 "contacts_batch_drop" => t('Delete'),
845 '$h_batch_actions' => t('Batch Actions'),
846 '$paginate' => paginate($a),
854 * @brief List of pages for the Contact TabBar
856 * Available Pages are 'Status', 'Profile', 'Contacts' and 'Common Friends'
859 * @param int $contact_id The ID of the contact
860 * @param int $active_tab 1 if tab should be marked as active
862 * @return array with with contact TabBar data
864 function contacts_tab($a, $contact_id, $active_tab) {
868 'label'=>t('Status'),
869 'url' => "contacts/".$contact_id."/posts",
870 'sel' => (($active_tab == 1)?'active':''),
871 'title' => t('Status Messages and Posts'),
872 'id' => 'status-tab',
876 'label'=>t('Profile'),
877 'url' => "contacts/".$contact_id,
878 'sel' => (($active_tab == 2)?'active':''),
879 'title' => t('Profile Details'),
880 'id' => 'status-tab',
885 // Show this tab only if there is visible friend list
886 $x = count_all_friends(local_user(), $contact_id);
888 $tabs[] = array('label'=>t('Contacts'),
889 'url' => "allfriends/".$contact_id,
890 'sel' => (($active_tab == 3)?'active':''),
891 'title' => t('View all contacts'),
892 'id' => 'allfriends-tab',
896 // Show this tab only if there is visible common friend list
897 $common = count_common_friends(local_user(),$contact_id);
899 $tabs[] = array('label'=>t('Common Friends'),
900 'url' => "common/loc/".local_user()."/".$contact_id,
901 'sel' => (($active_tab == 4)?'active':''),
902 'title' => t('View all common friends'),
903 'id' => 'common-loc-tab',
907 $tabs[] = array('label' => t('Advanced'),
908 'url' => 'crepair/' . $contact_id,
909 'sel' => (($active_tab == 5)?'active':''),
910 'title' => t('Advanced Contact Settings'),
911 'id' => 'advanced-tab',
914 $tab_tpl = get_markup_template('common_tabs.tpl');
915 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
920 function contact_posts($a, $contact_id) {
922 $r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id));
923 if (dbm::is_result($r)) {
925 $a->page['aside'] = "";
926 profile_load($a, "", 0, get_contact_details_by_url($contact["url"]));
931 $tab_str = contacts_tab($a, $contact_id, 1);
935 $o .= posts_from_contact_url($a, $contact["url"]);
940 function _contact_detail_for_template($rr){
943 case CONTACT_IS_FRIEND:
944 $dir_icon = 'images/lrarrow.gif';
945 $alt_text = t('Mutual Friendship');
947 case CONTACT_IS_FOLLOWER;
948 $dir_icon = 'images/larrow.gif';
949 $alt_text = t('is a fan of yours');
951 case CONTACT_IS_SHARING;
952 $dir_icon = 'images/rarrow.gif';
953 $alt_text = t('you are a fan of');
958 if (($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) {
959 $url = "redir/{$rr['id']}";
960 $sparkle = ' class="sparkle" ';
967 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
968 'edit_hover' => t('Edit contact'),
969 'photo_menu' => contact_photo_menu($rr),
971 'alt_text' => $alt_text,
972 'dir_icon' => $dir_icon,
973 'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB),
974 'name' => htmlentities($rr['name']),
975 'username' => htmlentities($rr['name']),
976 'account_type' => account_type($rr),
977 'sparkle' => $sparkle,
978 'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']),
980 'network' => network_to_name($rr['network'], $rr['url']),
986 * @brief Gives a array with actions which can performed to a given contact
988 * This includes actions like e.g. 'block', 'hide', 'archive', 'delete' and others
990 * @param array $contact Data about the Contact
991 * @return array with contact related actions
993 function contact_actions($contact) {
995 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
996 $contact_action = array();
998 // Provide friend suggestion only for Friendica contacts
999 if ($contact['network'] === NETWORK_DFRN) {
1000 $contact_actions['suggest'] = array(
1001 'label' => t('Suggest friends'),
1002 'url' => 'fsuggest/' . $contact['id'],
1009 if ($poll_enabled) {
1010 $contact_actions['update'] = array(
1011 'label' => t('Update now'),
1012 'url' => 'contacts/' . $contact['id'] . '/update',
1019 $contact_actions['block'] = array(
1020 'label' => (intval($contact['blocked']) ? t('Unblock') : t('Block') ),
1021 'url' => 'contacts/' . $contact['id'] . '/block',
1022 'title' => t('Toggle Blocked status'),
1023 'sel' => (intval($contact['blocked']) ? 'active' : ''),
1024 'id' => 'toggle-block',
1027 $contact_actions['ignore'] = array(
1028 'label' => (intval($contact['readonly']) ? t('Unignore') : t('Ignore') ),
1029 'url' => 'contacts/' . $contact['id'] . '/ignore',
1030 'title' => t('Toggle Ignored status'),
1031 'sel' => (intval($contact['readonly']) ? 'active' : ''),
1032 'id' => 'toggle-ignore',
1035 $contact_actions['archive'] = array(
1036 'label' => (intval($contact['archive']) ? t('Unarchive') : t('Archive') ),
1037 'url' => 'contacts/' . $contact['id'] . '/archive',
1038 'title' => t('Toggle Archive status'),
1039 'sel' => (intval($contact['archive']) ? 'active' : ''),
1040 'id' => 'toggle-archive',
1043 $contact_actions['delete'] = array(
1044 'label' => t('Delete'),
1045 'url' => 'contacts/' . $contact['id'] . '/drop',
1046 'title' => t('Delete contact'),
1051 return $contact_actions;