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];
38 $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array(
39 '$name' => htmlentities($a->data['contact']['name']),
40 '$photo' => $a->data['contact']['photo'],
41 '$url' => ($a->data['contact']['network'] == NETWORK_DFRN) ? $a->get_baseurl()."/redir/".$a->data['contact']['id'] : $a->data['contact']['url']
43 $finpeople_widget = '';
45 $networks_widget = '';
49 $networks_widget .= networks_widget('contacts',$_GET['nets']);
50 if (isset($_GET['add']))
51 $follow_widget = follow_widget($_GET['add']);
53 $follow_widget = follow_widget();
55 $findpeople_widget .= findpeople_widget();
58 if ($a->argv[2] != "posts")
59 $groups_widget .= group_side('contacts','group','full',0,$contact_id);
61 $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"),array(
62 '$vcard_widget' => $vcard_widget,
63 '$findpeople_widget' => $findpeople_widget,
64 '$follow_widget' => $follow_widget,
65 '$groups_widget' => $groups_widget,
66 '$networks_widget' => $networks_widget
69 $base = $a->get_baseurl();
70 $tpl = get_markup_template("contacts-head.tpl");
71 $a->page['htmlhead'] .= replace_macros($tpl,array(
72 '$baseurl' => $a->get_baseurl(true),
76 $tpl = get_markup_template("contacts-end.tpl");
77 $a->page['end'] .= replace_macros($tpl,array(
78 '$baseurl' => $a->get_baseurl(true),
85 function contacts_batch_actions(&$a){
86 $contacts_id = $_POST['contact_batch'];
87 if (!is_array($contacts_id)) return;
89 $orig_records = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND `uid` = %d AND `self` = 0",
90 implode(",", $contacts_id),
95 foreach($orig_records as $orig_record) {
96 $contact_id = $orig_record['id'];
97 if (x($_POST, 'contacts_batch_update')) {
98 _contact_update($contact_id);
101 if (x($_POST, 'contacts_batch_block')) {
102 $r = _contact_block($contact_id, $orig_record);
103 if ($r) $count_actions++;
105 if (x($_POST, 'contacts_batch_ignore')) {
106 $r = _contact_ignore($contact_id, $orig_record);
107 if ($r) $count_actions++;
109 if (x($_POST, 'contacts_batch_archive')) {
110 $r = _contact_archive($contact_id, $orig_record);
111 if ($r) $count_actions++;
113 if (x($_POST, 'contacts_batch_drop')) {
114 _contact_drop($contact_id, $orig_record);
118 if ($count_actions>0) {
119 info ( sprintf( tt("%d contact edited.", "%d contacts edited", $count_actions), $count_actions) );
122 if(x($_SESSION,'return_url'))
123 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
125 goaway($a->get_baseurl(true) . '/contacts');
130 function contacts_post(&$a) {
135 if ($a->argv[1]==="batch") {
136 contacts_batch_actions($a);
140 $contact_id = intval($a->argv[1]);
144 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
149 if(! count($orig_record)) {
150 notice( t('Could not access contact record.') . EOL);
151 goaway($a->get_baseurl(true) . '/contacts');
152 return; // NOTREACHED
155 call_hooks('contact_edit_post', $_POST);
157 $profile_id = intval($_POST['profile-assign']);
159 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
164 notice( t('Could not locate selected profile.') . EOL);
169 $hidden = intval($_POST['hidden']);
171 $notify = intval($_POST['notify']);
173 $fetch_further_information = intval($_POST['fetch_further_information']);
175 $ffi_keyword_blacklist = fix_mce_lf(escape_tags(trim($_POST['ffi_keyword_blacklist'])));
177 $priority = intval($_POST['poll']);
178 if($priority > 5 || $priority < 0)
181 $info = fix_mce_lf(escape_tags(trim($_POST['info'])));
183 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
184 `hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d,
185 `ffi_keyword_blacklist` = '%s' WHERE `id` = %d AND `uid` = %d",
191 intval($fetch_further_information),
192 dbesc($ffi_keyword_blacklist),
197 info( t('Contact updated.') . EOL);
199 notice( t('Failed to update contact record.') . EOL);
201 $r = q("select * from contact where id = %d and uid = %d limit 1",
206 $a->data['contact'] = $r[0];
213 function _contact_update($contact_id) {
214 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
220 if ($uid != local_user())
223 if ($r[0]["network"] == NETWORK_OSTATUS) {
224 $result = new_contact($uid, $r[0]["url"], false);
226 if ($result['success'])
227 $r = q("UPDATE `contact` SET `subhub` = 1 WHERE `id` = %d",
228 intval($contact_id));
230 // pull feed and consume it, which should subscribe to the hub.
231 proc_run('php',"include/onepoll.php","$contact_id", "force");
234 function _contact_update_profile($contact_id) {
235 $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
241 if ($uid != local_user())
244 $data = probe_url($r[0]["url"]);
246 // "Feed" or "Unknown" is mostly a sign of communication problems
247 if ((in_array($data["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) AND ($data["network"] != $r[0]["network"]))
250 $updatefields = array("name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm",
251 "poco", "network", "alias");
254 if ($data["network"] == NETWORK_OSTATUS) {
255 $result = new_contact($uid, $data["url"], false);
257 if ($result['success'])
258 $update["subhub"] = true;
261 foreach($updatefields AS $field)
262 if (isset($data[$field]) AND ($data[$field] != ""))
263 $update[$field] = $data[$field];
265 $update["nurl"] = normalise_link($data["url"]);
269 if (isset($data["priority"]) AND ($data["priority"] != 0))
270 $query = "`priority` = ".intval($data["priority"]);
272 foreach($update AS $key => $value) {
276 $query .= "`".$key."` = '".dbesc($value)."'";
282 $r = q("UPDATE `contact` SET $query WHERE `id` = %d AND `uid` = %d",
287 $photos = import_profile_photo($data['photo'], local_user(), $contact_id);
289 $r = q("UPDATE `contact` SET `photo` = '%s',
299 dbesc(datetime_convert()),
300 dbesc(datetime_convert()),
301 dbesc(datetime_convert()),
307 function _contact_block($contact_id, $orig_record) {
308 $blocked = (($orig_record['blocked']) ? 0 : 1);
309 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d",
317 function _contact_ignore($contact_id, $orig_record) {
318 $readonly = (($orig_record['readonly']) ? 0 : 1);
319 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d",
326 function _contact_archive($contact_id, $orig_record) {
327 $archived = (($orig_record['archive']) ? 0 : 1);
328 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d",
334 q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
338 function _contact_drop($contact_id, $orig_record) {
339 require_once('include/Contact.php');
342 terminate_friendship($a->user,$a->contact,$orig_record);
343 contact_remove($orig_record['id']);
347 function contacts_content(&$a) {
351 nav_set_selected('contacts');
355 notice( t('Permission denied.') . EOL);
361 $contact_id = intval($a->argv[1]);
367 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
372 if(! count($orig_record)) {
373 notice( t('Could not access contact record.') . EOL);
374 goaway($a->get_baseurl(true) . '/contacts');
375 return; // NOTREACHED
378 if($cmd === 'update') {
379 _contact_update($contact_id);
380 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
384 if($cmd === 'updateprofile') {
385 _contact_update_profile($contact_id);
386 goaway($a->get_baseurl(true) . '/crepair/' . $contact_id);
390 if($cmd === 'block') {
391 $r = _contact_block($contact_id, $orig_record[0]);
393 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
394 info((($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')).EOL);
397 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
398 return; // NOTREACHED
401 if($cmd === 'ignore') {
402 $r = _contact_ignore($contact_id, $orig_record[0]);
404 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
405 info((($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')).EOL);
408 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
409 return; // NOTREACHED
413 if($cmd === 'archive') {
414 $r = _contact_archive($contact_id, $orig_record[0]);
416 $archived = (($orig_record[0]['archive']) ? 0 : 1);
417 info((($archived) ? t('Contact has been archived') : t('Contact has been unarchived')).EOL);
420 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
421 return; // NOTREACHED
424 if($cmd === 'drop') {
426 // Check if we should do HTML-based delete confirmation
427 if($_REQUEST['confirm']) {
428 // <form> can't take arguments in its "action" parameter
429 // so add any arguments as hidden inputs
430 $query = explode_querystring($a->query_string);
432 foreach($query['args'] as $arg) {
433 if(strpos($arg, 'confirm=') === false) {
434 $arg_parts = explode('=', $arg);
435 $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
439 $a->page['aside'] = '';
441 return replace_macros(get_markup_template('contact_drop_confirm.tpl'), array(
442 '$contact' => _contact_detail_for_template($orig_record[0]),
444 '$message' => t('Do you really want to delete this contact?'),
445 '$extra_inputs' => $inputs,
446 '$confirm' => t('Yes'),
447 '$confirm_url' => $query['base'],
448 '$confirm_name' => 'confirmed',
449 '$cancel' => t('Cancel'),
452 // Now check how the user responded to the confirmation query
453 if($_REQUEST['canceled']) {
454 if(x($_SESSION,'return_url'))
455 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
457 goaway($a->get_baseurl(true) . '/contacts');
460 _contact_drop($contact_id, $orig_record[0]);
461 info( t('Contact has been removed.') . EOL );
462 if(x($_SESSION,'return_url'))
463 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
465 goaway($a->get_baseurl(true) . '/contacts');
466 return; // NOTREACHED
468 if($cmd === 'posts') {
469 return contact_posts($a, $contact_id);
475 $_SESSION['return_url'] = $a->query_string;
477 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
479 $contact_id = $a->data['contact']['id'];
480 $contact = $a->data['contact'];
482 $editselect = 'none';
483 if( feature_enabled(local_user(),'richtext') )
484 $editselect = 'exact';
486 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
487 '$baseurl' => $a->get_baseurl(true),
488 '$editselect' => $editselect,
490 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
491 '$baseurl' => $a->get_baseurl(true),
492 '$editselect' => $editselect,
495 require_once('include/contact_selectors.php');
497 $tpl = get_markup_template("contact_edit.tpl");
499 switch($contact['rel']) {
500 case CONTACT_IS_FRIEND:
501 $dir_icon = 'images/lrarrow.gif';
502 $relation_text = t('You are mutual friends with %s');
504 case CONTACT_IS_FOLLOWER;
505 $dir_icon = 'images/larrow.gif';
506 $relation_text = t('You are sharing with %s');
509 case CONTACT_IS_SHARING;
510 $dir_icon = 'images/rarrow.gif';
511 $relation_text = t('%s is sharing with you');
517 if(!in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
520 $relation_text = sprintf($relation_text,htmlentities($contact['name']));
522 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
523 $url = "redir/{$contact['id']}";
524 $sparkle = ' class="sparkle" ';
527 $url = $contact['url'];
531 $insecure = t('Private communications are not available for this contact.');
533 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
535 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
537 if($contact['last-update'] !== '0000-00-00 00:00:00')
538 $last_update .= ' ' . (($contact['last-update'] <= $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
540 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
542 $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2));
544 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network'], $contact["url"]));
546 $common = count_common_friends(local_user(),$contact['id']);
547 $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
549 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
551 $x = count_all_friends(local_user(), $contact['id']);
552 $all_friends = (($x) ? t('View all contacts') : '');
555 $tab_str = contact_tabs($a, $contact_id, 2);
557 $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!') : '');
559 if ($contact['network'] == NETWORK_FEED)
560 $fetch_further_information = array('fetch_further_information', t('Fetch further information for feeds'), $contact['fetch_further_information'], t('Fetch further information for feeds'),
561 array('0'=>t('Disabled'), '1'=>t('Fetch information'), '2'=>t('Fetch information and keywords')));
563 if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2)))
564 $poll_interval = contact_poll_interval($contact['priority'],(! $poll_enabled));
566 if ($contact['network'] == NETWORK_DFRN)
567 $profile_select = contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false));
569 if (in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS)) AND
570 ($contact['rel'] == CONTACT_IS_FOLLOWER))
571 $follow = $a->get_baseurl(true)."/follow?url=".urlencode($contact["url"]);
574 $header = $contact["name"];
576 if ($contact["addr"] != "")
577 $header .= " <".$contact["addr"].">";
579 $header .= " (".network_to_name($contact['network'], $contact['url']).")";
581 $o .= replace_macros($tpl, array(
582 //'$header' => t('Contact Editor'),
583 '$header' => htmlentities($header),
584 '$tab_str' => $tab_str,
585 '$submit' => t('Submit'),
586 '$lbl_vis1' => t('Profile Visibility'),
587 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
588 '$lbl_info1' => t('Contact Information / Notes'),
589 '$infedit' => t('Edit contact notes'),
590 '$common_text' => $common_text,
591 '$common_link' => $a->get_baseurl(true) . '/common/loc/' . local_user() . '/' . $contact['id'],
592 '$all_friends' => $all_friends,
593 '$relation_text' => $relation_text,
594 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
595 '$blockunblock' => t('Block/Unblock contact'),
596 '$ignorecont' => t('Ignore contact'),
597 '$lblcrepair' => t("Repair URL settings"),
598 '$lblrecent' => t('View conversations'),
599 '$lblsuggest' => $lblsuggest,
600 '$delete' => t('Delete contact'),
601 '$nettype' => $nettype,
602 '$poll_interval' => $poll_interval,
603 '$poll_enabled' => $poll_enabled,
604 '$lastupdtext' => t('Last update:'),
605 '$lost_contact' => $lost_contact,
606 '$updpub' => t('Update public posts'),
607 '$last_update' => $last_update,
608 '$udnow' => t('Update now'),
609 '$follow' => $follow,
610 '$follow_text' => t("Connect/Follow"),
611 '$profile_select' => $profile_select,
612 '$contact_id' => $contact['id'],
613 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
614 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
615 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
616 '$info' => $contact['info'],
617 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
618 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
619 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
620 '$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')),
621 '$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
622 '$fetch_further_information' => $fetch_further_information,
623 '$ffi_keyword_blacklist' => $contact['ffi_keyword_blacklist'],
624 '$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')),
625 '$photo' => $contact['photo'],
626 '$name' => htmlentities($contact['name']),
627 '$dir_icon' => $dir_icon,
628 '$alt_text' => $alt_text,
629 '$sparkle' => $sparkle,
631 '$profileurllabel' => t('Profile URL'),
632 '$profileurl' => $contact['url'],
633 '$location' => bbcode($contact["location"]),
634 '$location_label' => t("Location:"),
635 '$about' => bbcode($contact["about"], false, false),
636 '$about_label' => t("About:"),
637 '$keywords' => $contact["keywords"],
638 '$keywords_label' => t("Tags:")
642 $arr = array('contact' => $contact,'output' => $o);
644 call_hooks('contact_edit', $arr);
646 return $arr['output'];
655 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
659 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
660 $sql_extra = " AND `blocked` = 1 ";
663 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
664 $sql_extra = " AND `hidden` = 1 ";
667 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
668 $sql_extra = " AND `readonly` = 1 ";
671 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
672 $sql_extra = " AND `archive` = 1 ";
676 $sql_extra = " AND `blocked` = 0 ";
678 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
679 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
683 'label' => t('Suggestions'),
684 'url' => $a->get_baseurl(true) . '/suggest',
686 'title' => t('Suggest potential friends'),
687 'id' => 'suggestions-tab',
691 'label' => t('All Contacts'),
692 'url' => $a->get_baseurl(true) . '/contacts/all',
693 'sel' => ($all) ? 'active' : '',
694 'title' => t('Show all contacts'),
695 'id' => 'showall-tab',
699 'label' => t('Unblocked'),
700 'url' => $a->get_baseurl(true) . '/contacts',
701 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
702 'title' => t('Only show unblocked contacts'),
703 'id' => 'showunblocked-tab',
708 'label' => t('Blocked'),
709 'url' => $a->get_baseurl(true) . '/contacts/blocked',
710 'sel' => ($blocked) ? 'active' : '',
711 'title' => t('Only show blocked contacts'),
712 'id' => 'showblocked-tab',
717 'label' => t('Ignored'),
718 'url' => $a->get_baseurl(true) . '/contacts/ignored',
719 'sel' => ($ignored) ? 'active' : '',
720 'title' => t('Only show ignored contacts'),
721 'id' => 'showignored-tab',
726 'label' => t('Archived'),
727 'url' => $a->get_baseurl(true) . '/contacts/archived',
728 'sel' => ($archived) ? 'active' : '',
729 'title' => t('Only show archived contacts'),
730 'id' => 'showarchived-tab',
735 'label' => t('Hidden'),
736 'url' => $a->get_baseurl(true) . '/contacts/hidden',
737 'sel' => ($hidden) ? 'active' : '',
738 'title' => t('Only show hidden contacts'),
739 'id' => 'showhidden-tab',
745 $tab_tpl = get_markup_template('common_tabs.tpl');
746 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
752 $search_hdr = $search;
753 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
756 $sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt' OR nick REGEXP '$search_txt') " : "");
759 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
761 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
764 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
765 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
766 intval($_SESSION['uid']));
768 $a->set_pager_total($r[0]['total']);
769 $total = $r[0]['total'];
772 $sql_extra3 = unavailable_networks();
774 $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 ",
775 intval($_SESSION['uid']),
776 intval($a->pager['start']),
777 intval($a->pager['itemspage'])
784 $contacts[] = _contact_detail_for_template($rr);
788 $tpl = get_markup_template("contacts-template.tpl");
789 $o .= replace_macros($tpl, array(
790 '$baseurl' => $a->get_baseurl(),
791 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
794 '$search' => $search_hdr,
795 '$desc' => t('Search your contacts'),
796 '$finding' => (($searching) ? t('Finding: ') . "'" . $search . "'" : ""),
797 '$submit' => t('Find'),
799 '$contacts' => $contacts,
800 '$contact_drop_confirm' => t('Do you really want to delete this contact?'),
802 '$batch_actions' => array(
803 'contacts_batch_update' => t('Update'),
804 'contacts_batch_block' => t('Block')."/".t("Unblock"),
805 "contacts_batch_ignore" => t('Ignore')."/".t("Unignore"),
806 "contacts_batch_archive" => t('Archive')."/".t("Unarchive"),
807 "contacts_batch_drop" => t('Delete'),
809 '$paginate' => paginate($a),
816 function contact_tabs($a, $contact_id, $active_tab) {
820 'label'=>t('Status'),
821 'url' => "contacts/".$contact_id."/posts",
822 'sel' => (($active_tab == 1)?'active':''),
823 'title' => t('Status Messages and Posts'),
824 'id' => 'status-tab',
828 'label'=>t('Profile'),
829 'url' => "contacts/".$contact_id,
830 'sel' => (($active_tab == 2)?'active':''),
831 'title' => t('Profile Details'),
832 'id' => 'status-tab',
836 'label' => t('Repair'),
837 'url' => $a->get_baseurl(true) . '/crepair/' . $contact_id,
838 'sel' => (($active_tab == 3)?'active':''),
839 'title' => t('Advanced Contact Settings'),
840 'id' => 'repair-tab',
844 'label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
845 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/block',
847 'title' => t('Toggle Blocked status'),
848 'id' => 'toggle-block-tab',
852 'label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
853 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/ignore',
855 'title' => t('Toggle Ignored status'),
856 'id' => 'toggle-ignore-tab',
860 'label' => (($contact['archive']) ? t('Unarchive') : t('Archive') ),
861 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/archive',
863 'title' => t('Toggle Archive status'),
864 'id' => 'toggle-archive-tab',
868 $tab_tpl = get_markup_template('common_tabs.tpl');
869 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
874 function contact_posts($a, $contact_id) {
876 require_once('include/conversation.php');
878 $r = q("SELECT * FROM `contact` WHERE `id` = %d", intval($contact_id));
881 $a->page['aside'] = "";
882 profile_load($a, "", 0, get_contact_details_by_url($contact["url"]));
885 $r = q("SELECT COUNT(*) AS `total` FROM `item`
886 WHERE `item`.`uid` = %d AND `contact-id` = %d AND `item`.`id` = `item`.`parent`",
887 intval(local_user()), intval($contact_id));
889 $a->set_pager_total($r[0]['total']);
891 $r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
892 `author-name` AS `name`, `owner-avatar` AS `photo`,
893 `owner-link` AS `url`, `owner-avatar` AS `thumb`
894 FROM `item` WHERE `item`.`uid` = %d AND `contact-id` = %d AND `item`.`id` = `item`.`parent`
895 ORDER BY `item`.`created` DESC LIMIT %d, %d",
896 intval(local_user()),
898 intval($a->pager['start']),
899 intval($a->pager['itemspage'])
902 $tab_str = contact_tabs($a, $contact_id, 1);
904 $header = $contact["name"];
906 if ($contact["addr"] != "")
907 $header .= " <".$contact["addr"].">";
909 $header .= " (".network_to_name($contact['network'], $contact['url']).")";
911 $tpl = get_markup_template("section_title.tpl");
912 $o = replace_macros($tpl,array(
913 '$title' => htmlentities($header)
918 $o .= conversation($a,$r,'community',false);
920 if(!get_config('system', 'old_pager')) {
921 $o .= alt_pager($a,count($r));
929 function _contact_detail_for_template($rr){
931 case CONTACT_IS_FRIEND:
932 $dir_icon = 'images/lrarrow.gif';
933 $alt_text = t('Mutual Friendship');
935 case CONTACT_IS_FOLLOWER;
936 $dir_icon = 'images/larrow.gif';
937 $alt_text = t('is a fan of yours');
939 case CONTACT_IS_SHARING;
940 $dir_icon = 'images/rarrow.gif';
941 $alt_text = t('you are a fan of');
946 if(($rr['network'] === NETWORK_DFRN) && ($rr['rel'])) {
947 $url = "redir/{$rr['id']}";
948 $sparkle = ' class="sparkle" ';
957 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
958 'edit_hover' => t('Edit contact'),
959 'photo_menu' => contact_photo_menu($rr),
961 'alt_text' => $alt_text,
962 'dir_icon' => $dir_icon,
963 'thumb' => proxy_url($rr['thumb'], false, PROXY_SIZE_THUMB),
964 'name' => htmlentities($rr['name']),
965 'username' => htmlentities($rr['name']),
966 'sparkle' => $sparkle,
967 'itemurl' => (($rr['addr'] != "") ? $rr['addr'] : $rr['url']),
969 'network' => network_to_name($rr['network'], $rr['url']),