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) {
16 if((($a->argc == 2) && intval($a->argv[1])) OR (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) {
17 $contact_id = intval($a->argv[1]);
18 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
27 require_once('include/group.php');
28 require_once('include/contact_widgets.php');
30 if ($_GET['nets'] == "all")
33 if(! x($a->page,'aside'))
34 $a->page['aside'] = '';
37 $a->data['contact'] = $r[0];
39 if (($a->data['contact']['network'] != "") AND ($a->data['contact']['network'] != NETWORK_DFRN)) {
40 $networkname = format_network_name($a->data['contact']['network'],$a->data['contact']['url']);
44 $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array(
45 '$name' => htmlentities($a->data['contact']['name']),
46 '$photo' => $a->data['contact']['photo'],
47 '$url' => ($a->data['contact']['network'] == NETWORK_DFRN) ? z_root()."/redir/".$a->data['contact']['id'] : $a->data['contact']['url'],
48 '$addr' => (($a->data['contact']['addr'] != "") ? ($a->data['contact']['addr']) : ""),
49 '$network_name' => $networkname,
50 '$network' => t('Network:'),
51 'account_type' => (($a->data['contact']['forum'] || $a->data['contact']['prv']) ? t('Forum') : '')
53 $finpeople_widget = '';
55 $networks_widget = '';
59 $networks_widget .= networks_widget('contacts',$_GET['nets']);
60 if (isset($_GET['add']))
61 $follow_widget = follow_widget($_GET['add']);
63 $follow_widget = follow_widget();
65 $findpeople_widget .= findpeople_widget();
68 $groups_widget .= group_side('contacts','group','full',0,$contact_id);
70 $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"),array(
71 '$vcard_widget' => $vcard_widget,
72 '$findpeople_widget' => $findpeople_widget,
73 '$follow_widget' => $follow_widget,
74 '$groups_widget' => $groups_widget,
75 '$networks_widget' => $networks_widget
79 $tpl = get_markup_template("contacts-head.tpl");
80 $a->page['htmlhead'] .= replace_macros($tpl,array(
81 '$baseurl' => $a->get_baseurl(true),
85 $tpl = get_markup_template("contacts-end.tpl");
86 $a->page['end'] .= replace_macros($tpl,array(
87 '$baseurl' => $a->get_baseurl(true),
94 function contacts_batch_actions(&$a){
95 $contacts_id = $_POST['contact_batch'];
96 if (!is_array($contacts_id)) return;
98 $orig_records = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND `uid` = %d AND `self` = 0",
99 implode(",", $contacts_id),
104 foreach($orig_records as $orig_record) {
105 $contact_id = $orig_record['id'];
106 if (x($_POST, 'contacts_batch_update')) {
107 _contact_update($contact_id);
110 if (x($_POST, 'contacts_batch_block')) {
111 $r = _contact_block($contact_id, $orig_record);
112 if ($r) $count_actions++;
114 if (x($_POST, 'contacts_batch_ignore')) {
115 $r = _contact_ignore($contact_id, $orig_record);
116 if ($r) $count_actions++;
118 if (x($_POST, 'contacts_batch_archive')) {
119 $r = _contact_archive($contact_id, $orig_record);
120 if ($r) $count_actions++;
122 if (x($_POST, 'contacts_batch_drop')) {
123 _contact_drop($contact_id, $orig_record);
127 if ($count_actions>0) {
128 info ( sprintf( tt("%d contact edited.", "%d contacts edited", $count_actions), $count_actions) );
131 if(x($_SESSION,'return_url'))
132 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
134 goaway($a->get_baseurl(true) . '/contacts');
139 function contacts_post(&$a) {
144 if ($a->argv[1]==="batch") {
145 contacts_batch_actions($a);
149 $contact_id = intval($a->argv[1]);
153 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
158 if(! count($orig_record)) {
159 notice( t('Could not access contact record.') . EOL);
160 goaway($a->get_baseurl(true) . '/contacts');
161 return; // NOTREACHED
164 call_hooks('contact_edit_post', $_POST);
166 $profile_id = intval($_POST['profile-assign']);
168 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
173 notice( t('Could not locate selected profile.') . EOL);
178 $hidden = intval($_POST['hidden']);
180 $notify = intval($_POST['notify']);
182 $fetch_further_information = intval($_POST['fetch_further_information']);
184 $ffi_keyword_blacklist = fix_mce_lf(escape_tags(trim($_POST['ffi_keyword_blacklist'])));
186 $priority = intval($_POST['poll']);
187 if($priority > 5 || $priority < 0)
190 $info = fix_mce_lf(escape_tags(trim($_POST['info'])));
192 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
193 `hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d,
194 `ffi_keyword_blacklist` = '%s' WHERE `id` = %d AND `uid` = %d",
200 intval($fetch_further_information),
201 dbesc($ffi_keyword_blacklist),
206 info( t('Contact updated.') . EOL);
208 notice( t('Failed to update contact record.') . EOL);
210 $r = q("select * from contact where id = %d and uid = %d limit 1",
215 $a->data['contact'] = $r[0];
222 function _contact_update($contact_id) {
223 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
229 if ($uid != local_user())
232 if ($r[0]["network"] == NETWORK_OSTATUS) {
233 $result = new_contact($uid, $r[0]["url"], false);
235 if ($result['success'])
236 $r = q("UPDATE `contact` SET `subhub` = 1 WHERE `id` = %d",
237 intval($contact_id));
239 // pull feed and consume it, which should subscribe to the hub.
240 proc_run('php',"include/onepoll.php","$contact_id", "force");
243 function _contact_update_profile($contact_id) {
244 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
250 if ($uid != local_user())
253 $data = probe_url($r[0]["url"]);
255 // "Feed" or "Unknown" is mostly a sign of communication problems
256 if ((in_array($data["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) AND ($data["network"] != $r[0]["network"]))
259 $updatefields = array("name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm",
260 "poco", "network", "alias");
263 if ($data["network"] == NETWORK_OSTATUS) {
264 $result = new_contact($uid, $data["url"], false);
266 if ($result['success'])
267 $update["subhub"] = true;
270 foreach($updatefields AS $field)
271 if (isset($data[$field]) AND ($data[$field] != ""))
272 $update[$field] = $data[$field];
274 $update["nurl"] = normalise_link($data["url"]);
278 if (isset($data["priority"]) AND ($data["priority"] != 0))
279 $query = "`priority` = ".intval($data["priority"]);
281 foreach($update AS $key => $value) {
285 $query .= "`".$key."` = '".dbesc($value)."'";
291 $r = q("UPDATE `contact` SET $query WHERE `id` = %d AND `uid` = %d",
296 $photos = import_profile_photo($data['photo'], local_user(), $contact_id);
298 $r = q("UPDATE `contact` SET `photo` = '%s',
308 dbesc(datetime_convert()),
309 dbesc(datetime_convert()),
310 dbesc(datetime_convert()),
316 function _contact_block($contact_id, $orig_record) {
317 $blocked = (($orig_record['blocked']) ? 0 : 1);
318 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d",
326 function _contact_ignore($contact_id, $orig_record) {
327 $readonly = (($orig_record['readonly']) ? 0 : 1);
328 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d",
335 function _contact_archive($contact_id, $orig_record) {
336 $archived = (($orig_record['archive']) ? 0 : 1);
337 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d",
343 q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
347 function _contact_drop($contact_id, $orig_record) {
348 require_once('include/Contact.php');
351 terminate_friendship($a->user,$a->contact,$orig_record);
352 contact_remove($orig_record['id']);
356 function contacts_content(&$a) {
360 nav_set_selected('contacts');
364 notice( t('Permission denied.') . EOL);
370 $contact_id = intval($a->argv[1]);
376 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
381 if(! count($orig_record)) {
382 notice( t('Could not access contact record.') . EOL);
383 goaway($a->get_baseurl(true) . '/contacts');
384 return; // NOTREACHED
387 if($cmd === 'update') {
388 _contact_update($contact_id);
389 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
393 if($cmd === 'updateprofile') {
394 _contact_update_profile($contact_id);
395 goaway($a->get_baseurl(true) . '/crepair/' . $contact_id);
399 if($cmd === 'block') {
400 $r = _contact_block($contact_id, $orig_record[0]);
402 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
403 info((($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')).EOL);
406 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
407 return; // NOTREACHED
410 if($cmd === 'ignore') {
411 $r = _contact_ignore($contact_id, $orig_record[0]);
413 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
414 info((($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')).EOL);
417 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
418 return; // NOTREACHED
422 if($cmd === 'archive') {
423 $r = _contact_archive($contact_id, $orig_record[0]);
425 $archived = (($orig_record[0]['archive']) ? 0 : 1);
426 info((($archived) ? t('Contact has been archived') : t('Contact has been unarchived')).EOL);
429 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
430 return; // NOTREACHED
433 if($cmd === 'drop') {
435 // Check if we should do HTML-based delete confirmation
436 if($_REQUEST['confirm']) {
437 // <form> can't take arguments in its "action" parameter
438 // so add any arguments as hidden inputs
439 $query = explode_querystring($a->query_string);
441 foreach($query['args'] as $arg) {
442 if(strpos($arg, 'confirm=') === false) {
443 $arg_parts = explode('=', $arg);
444 $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
448 $a->page['aside'] = '';
450 return replace_macros(get_markup_template('contact_drop_confirm.tpl'), array(
451 '$contact' => _contact_detail_for_template($orig_record[0]),
453 '$message' => t('Do you really want to delete this contact?'),
454 '$extra_inputs' => $inputs,
455 '$confirm' => t('Yes'),
456 '$confirm_url' => $query['base'],
457 '$confirm_name' => 'confirmed',
458 '$cancel' => t('Cancel'),
461 // Now check how the user responded to the confirmation query
462 if($_REQUEST['canceled']) {
463 if(x($_SESSION,'return_url'))
464 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
466 goaway($a->get_baseurl(true) . '/contacts');
469 _contact_drop($contact_id, $orig_record[0]);
470 info( t('Contact has been removed.') . EOL );
471 if(x($_SESSION,'return_url'))
472 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
474 goaway($a->get_baseurl(true) . '/contacts');
475 return; // NOTREACHED
477 if($cmd === 'posts') {
478 return contact_posts($a, $contact_id);
484 $_SESSION['return_url'] = $a->query_string;
486 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
488 $contact_id = $a->data['contact']['id'];
489 $contact = $a->data['contact'];
491 $editselect = 'none';
492 if( feature_enabled(local_user(),'richtext') )
493 $editselect = 'exact';
495 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
496 '$baseurl' => $a->get_baseurl(true),
497 '$editselect' => $editselect,
499 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
500 '$baseurl' => $a->get_baseurl(true),
501 '$editselect' => $editselect,
504 require_once('include/contact_selectors.php');
506 $tpl = get_markup_template("contact_edit.tpl");
508 switch($contact['rel']) {
509 case CONTACT_IS_FRIEND:
510 $dir_icon = 'images/lrarrow.gif';
511 $relation_text = t('You are mutual friends with %s');
513 case CONTACT_IS_FOLLOWER;
514 $dir_icon = 'images/larrow.gif';
515 $relation_text = t('You are sharing with %s');
518 case CONTACT_IS_SHARING;
519 $dir_icon = 'images/rarrow.gif';
520 $relation_text = t('%s is sharing with you');
526 if(!in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
529 $relation_text = sprintf($relation_text,htmlentities($contact['name']));
531 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
532 $url = "redir/{$contact['id']}";
533 $sparkle = ' class="sparkle" ';
536 $url = $contact['url'];
540 $insecure = t('Private communications are not available for this contact.');
542 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
544 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
546 if($contact['last-update'] !== '0000-00-00 00:00:00')
547 $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
549 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
551 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
553 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network'], $contact["url"]));
555 //$common = count_common_friends(local_user(),$contact['id']);
556 //$common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
558 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
560 //$x = count_all_friends(local_user(), $contact['id']);
561 //$all_friends = (($x) ? t('View all contacts') : '');
564 $tab_str = contacts_tab($a, $contact_id, 2);
566 $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!') : '');
568 if ($contact['network'] == NETWORK_FEED)
569 $fetch_further_information = array('fetch_further_information', t('Fetch further information for feeds'), $contact['fetch_further_information'], t('Fetch further information for feeds'),
570 array('0'=>t('Disabled'), '1'=>t('Fetch information'), '2'=>t('Fetch information and keywords')));
572 if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2)))
573 $poll_interval = contact_poll_interval($contact['priority'],(! $poll_enabled));
575 if ($contact['network'] == NETWORK_DFRN)
576 $profile_select = contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false));
578 if (in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS)) AND
579 ($contact['rel'] == CONTACT_IS_FOLLOWER))
580 $follow = $a->get_baseurl(true)."/follow?url=".urlencode($contact["url"]);
583 $o .= replace_macros($tpl, array(
584 //'$header' => t('Contact Editor'),
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' => $a->get_baseurl(true) . '/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 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
619 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
620 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
621 '$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')),
622 '$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
623 '$fetch_further_information' => $fetch_further_information,
624 '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
625 '$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')),
626 '$photo' => $contact['photo'],
627 '$name' => htmlentities($contact['name']),
628 '$dir_icon' => $dir_icon,
629 '$alt_text' => $alt_text,
630 '$sparkle' => $sparkle,
632 '$profileurllabel' => t('Profile URL'),
633 '$profileurl' => $contact['url'],
634 '$location' => bbcode($contact["location"]),
635 '$location_label' => t("Location:"),
636 '$about' => bbcode($contact["about"], false, false),
637 '$about_label' => t("About:"),
638 '$keywords' => $contact["keywords"],
639 '$keywords_label' => t("Tags:")
643 $arr = array('contact' => $contact,'output' => $o);
645 call_hooks('contact_edit', $arr);
647 return $arr['output'];
656 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
660 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
661 $sql_extra = " AND `blocked` = 1 ";
664 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
665 $sql_extra = " AND `hidden` = 1 ";
668 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
669 $sql_extra = " AND `readonly` = 1 ";
672 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
673 $sql_extra = " AND `archive` = 1 ";
677 $sql_extra = " AND `blocked` = 0 ";
679 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
680 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
684 'label' => t('Suggestions'),
685 'url' => $a->get_baseurl(true) . '/suggest',
687 'title' => t('Suggest potential friends'),
688 'id' => 'suggestions-tab',
692 'label' => t('All Contacts'),
693 'url' => $a->get_baseurl(true) . '/contacts/all',
694 'sel' => ($all) ? 'active' : '',
695 'title' => t('Show all contacts'),
696 'id' => 'showall-tab',
700 'label' => t('Unblocked'),
701 'url' => $a->get_baseurl(true) . '/contacts',
702 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
703 'title' => t('Only show unblocked contacts'),
704 'id' => 'showunblocked-tab',
709 'label' => t('Blocked'),
710 'url' => $a->get_baseurl(true) . '/contacts/blocked',
711 'sel' => ($blocked) ? 'active' : '',
712 'title' => t('Only show blocked contacts'),
713 'id' => 'showblocked-tab',
718 'label' => t('Ignored'),
719 'url' => $a->get_baseurl(true) . '/contacts/ignored',
720 'sel' => ($ignored) ? 'active' : '',
721 'title' => t('Only show ignored contacts'),
722 'id' => 'showignored-tab',
727 'label' => t('Archived'),
728 'url' => $a->get_baseurl(true) . '/contacts/archived',
729 'sel' => ($archived) ? 'active' : '',
730 'title' => t('Only show archived contacts'),
731 'id' => 'showarchived-tab',
736 'label' => t('Hidden'),
737 'url' => $a->get_baseurl(true) . '/contacts/hidden',
738 'sel' => ($hidden) ? 'active' : '',
739 'title' => t('Only show hidden contacts'),
740 'id' => 'showhidden-tab',
746 $tab_tpl = get_markup_template('common_tabs.tpl');
747 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
753 $search_hdr = $search;
754 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
757 $sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') " : "");
760 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
762 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
765 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
766 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
767 intval($_SESSION['uid']));
769 $a->set_pager_total($r[0]['total']);
770 $total = $r[0]['total'];
773 $sql_extra3 = unavailable_networks();
775 $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 ",
776 intval($_SESSION['uid']),
777 intval($a->pager['start']),
778 intval($a->pager['itemspage'])
785 $contacts[] = _contact_detail_for_template($rr);
789 $tpl = get_markup_template("contacts-template.tpl");
790 $o .= replace_macros($tpl, array(
791 '$baseurl' => z_root(),
792 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
795 '$search' => $search_hdr,
796 '$desc' => t('Search your contacts'),
797 '$finding' => (($searching) ? t('Finding: ') . "'" . $search . "'" : ""),
798 '$submit' => t('Find'),
800 '$contacts' => $contacts,
801 '$contact_drop_confirm' => t('Do you really want to delete this contact?'),
803 '$batch_actions' => array(
804 'contacts_batch_update' => t('Update'),
805 'contacts_batch_block' => t('Block')."/".t("Unblock"),
806 "contacts_batch_ignore" => t('Ignore')."/".t("Unignore"),
807 "contacts_batch_archive" => t('Archive')."/".t("Unarchive"),
808 "contacts_batch_drop" => t('Delete'),
810 '$paginate' => paginate($a),
817 function contacts_tab($a, $contact_id, $active_tab) {
821 'label'=>t('Status'),
822 'url' => "contacts/".$contact_id."/posts",
823 'sel' => (($active_tab == 1)?'active':''),
824 'title' => t('Status Messages and Posts'),
825 'id' => 'status-tab',
829 'label'=>t('Profile'),
830 'url' => "contacts/".$contact_id,
831 'sel' => (($active_tab == 2)?'active':''),
832 'title' => t('Profile Details'),
833 'id' => 'status-tab',
838 $x = count_all_friends(local_user(), $contact_id);
840 $tabs[] = array('label'=>t('Contacts'),
841 'url' => "allfriends/".$contact_id,
842 'sel' => (($active_tab == 3)?'active':''),
843 'title' => t('View all contacts'),
844 'id' => 'allfriends-tab',
847 $common = count_common_friends(local_user(),$contact_id);
849 $tabs[] = array('label'=>t('Common Friends'),
850 'url' => "common/loc/".local_user()."/".$contact_id,
851 'sel' => (($active_tab == 4)?'active':''),
852 'title' => t('View all common friends'),
853 'id' => 'common-loc-tab',
856 $tabs[] = array('label' => t('Repair'),
857 'url' => $a->get_baseurl(true) . '/crepair/' . $contact_id,
858 'sel' => (($active_tab == 5)?'active':''),
859 'title' => t('Advanced Contact Settings'),
860 'id' => 'repair-tab',
864 $tabs[] = array('label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
865 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/block',
867 'title' => t('Toggle Blocked status'),
868 'id' => 'toggle-block-tab',
871 $tabs[] = array('label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
872 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/ignore',
874 'title' => t('Toggle Ignored status'),
875 'id' => 'toggle-ignore-tab',
878 $tabs[] = array('label' => (($contact['archive']) ? t('Unarchive') : t('Archive') ),
879 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/archive',
881 'title' => t('Toggle Archive status'),
882 'id' => 'toggle-archive-tab',
885 $tab_tpl = get_markup_template('common_tabs.tpl');
886 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
891 function contact_posts($a, $contact_id) {
893 require_once('include/conversation.php');
895 $r = q("SELECT * FROM `contact` WHERE `id` = %d", intval($contact_id));
898 $a->page['aside'] = "";
899 profile_load($a, "", 0, get_contact_details_by_url($contact["url"]));
902 if(get_config('system', 'old_pager')) {
903 $r = q("SELECT COUNT(*) AS `total` FROM `item`
904 WHERE `item`.`uid` = %d AND `author-link` IN ('%s', '%s')",
905 intval(local_user()),
906 dbesc(normalise_link($contact["url"])),
907 dbesc(str_replace("http://", "https://", $contact["url"])));
909 $a->set_pager_total($r[0]['total']);
912 $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
913 `author-name` AS `name`, `owner-avatar` AS `photo`,
914 `owner-link` AS `url`, `owner-avatar` AS `thumb`
915 FROM `item` FORCE INDEX (uid_contactid_created)
916 WHERE `item`.`uid` = %d AND `contact-id` = %d
917 AND `author-link` IN ('%s', '%s')
918 ORDER BY `item`.`created` DESC LIMIT %d, %d",
919 intval(local_user()),
921 dbesc(normalise_link($contact["url"])),
922 dbesc(str_replace("http://", "https://", $contact["url"])),
923 intval($a->pager['start']),
924 intval($a->pager['itemspage'])
927 $tab_str = contacts_tab($a, $contact_id, 1);
931 $o .= conversation($a,$r,'community',false);
933 if(!get_config('system', 'old_pager')) {
934 $o .= alt_pager($a,count($r));
942 function _contact_detail_for_template($rr){
947 case CONTACT_IS_FRIEND:
948 $dir_icon = 'images/lrarrow.gif';
949 $alt_text = t('Mutual Friendship');
951 case CONTACT_IS_FOLLOWER;
952 $dir_icon = 'images/larrow.gif';
953 $alt_text = t('is a fan of yours');
955 case CONTACT_IS_SHARING;
956 $dir_icon = 'images/rarrow.gif';
957 $alt_text = t('you are a fan of');
962 if(($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) {
963 $url = "redir/{$rr['id']}";
964 $sparkle = ' class="sparkle" ';
971 //test if contact is a forum page
972 if (isset($rr['forum']) OR isset($rr['prv']))
973 $community = ($rr['forum'] OR $rr['prv']);
977 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
978 'edit_hover' => t('Edit contact'),
979 'photo_menu' => contact_photo_menu($rr),
981 'alt_text' => $alt_text,
982 'dir_icon' => $dir_icon,
983 'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB),
984 'name' => htmlentities($rr['name']),
985 'username' => htmlentities($rr['name']),
986 'account_type' => ($community ? t('Forum') : ''),
987 'sparkle' => $sparkle,
988 'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']),
990 'network' => network_to_name($rr['network'], $rr['url']),