3 require_once('include/Contact.php');
4 require_once('include/socgraph.php');
5 require_once('include/contact_selectors.php');
7 function contacts_init(&$a) {
13 if(($a->argc == 2) && intval($a->argv[1])) {
14 $contact_id = intval($a->argv[1]);
15 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
24 require_once('include/group.php');
25 require_once('include/contact_widgets.php');
27 if(! x($a->page,'aside'))
28 $a->page['aside'] = '';
31 $a->data['contact'] = $r[0];
32 $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array(
33 '$name' => $a->data['contact']['name'],
34 '$photo' => $a->data['contact']['photo']
40 $follow_widget = follow_widget();
43 $groups_widget .= group_side('contacts','group',false,0,$contact_id);
44 $findpeople_widget .= findpeople_widget();
45 $networks_widget .= networks_widget('contacts',$_GET['nets']);
46 $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"),array(
47 '$vcard_widget' => $vcard_widget,
48 '$follow_widget' => $follow_widget,
49 '$groups_widget' => $groups_widget,
50 '$findpeople_widget' => $findpeople_widget,
51 '$networks_widget' => $networks_widget
54 $base = $a->get_baseurl();
55 $tpl = get_markup_template("contacts-head.tpl");
56 $a->page['htmlhead'] .= replace_macros($tpl,array(
57 '$baseurl' => $a->get_baseurl(true),
61 $tpl = get_markup_template("contacts-end.tpl");
62 $a->page['end'] .= replace_macros($tpl,array(
63 '$baseurl' => $a->get_baseurl(true),
70 function contacts_post(&$a) {
75 $contact_id = intval($a->argv[1]);
79 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
84 if(! count($orig_record)) {
85 notice( t('Could not access contact record.') . EOL);
86 goaway($a->get_baseurl(true) . '/contacts');
90 call_hooks('contact_edit_post', $_POST);
92 $profile_id = intval($_POST['profile-assign']);
94 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
99 notice( t('Could not locate selected profile.') . EOL);
104 $hidden = intval($_POST['hidden']);
106 $notify = intval($_POST['notify']);
108 $fetch_further_information = intval($_POST['fetch_further_information']);
110 $priority = intval($_POST['poll']);
111 if($priority > 5 || $priority < 0)
114 $info = fix_mce_lf(escape_tags(trim($_POST['info'])));
116 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
117 `hidden` = %d, `notify_new_posts` = %d, `fetch_further_information` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
123 intval($fetch_further_information),
128 info( t('Contact updated.') . EOL);
130 notice( t('Failed to update contact record.') . EOL);
132 $r = q("select * from contact where id = %d and uid = %d limit 1",
137 $a->data['contact'] = $r[0];
145 function contacts_content(&$a) {
149 nav_set_selected('contacts');
153 notice( t('Permission denied.') . EOL);
159 $contact_id = intval($a->argv[1]);
165 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
170 if(! count($orig_record)) {
171 notice( t('Could not access contact record.') . EOL);
172 goaway($a->get_baseurl(true) . '/contacts');
173 return; // NOTREACHED
176 if($cmd === 'update') {
178 // pull feed and consume it, which should subscribe to the hub.
179 proc_run('php',"include/poller.php","$contact_id");
180 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
184 if($cmd === 'block') {
185 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
186 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
192 //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
193 info( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
195 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
196 return; // NOTREACHED
199 if($cmd === 'ignore') {
200 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
201 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
207 info( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
209 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
210 return; // NOTREACHED
214 if($cmd === 'archive') {
215 $archived = (($orig_record[0]['archive']) ? 0 : 1);
216 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
222 q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
225 //notice( t('Contact has been ') . (($archived) ? t('archived') : t('unarchived')) . EOL );
226 info( (($archived) ? t('Contact has been archived') : t('Contact has been unarchived')) . EOL );
228 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
229 return; // NOTREACHED
232 if($cmd === 'drop') {
234 // Check if we should do HTML-based delete confirmation
235 if($_REQUEST['confirm']) {
236 // <form> can't take arguments in its "action" parameter
237 // so add any arguments as hidden inputs
238 $query = explode_querystring($a->query_string);
240 foreach($query['args'] as $arg) {
241 if(strpos($arg, 'confirm=') === false) {
242 $arg_parts = explode('=', $arg);
243 $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
247 $a->page['aside'] = '';
248 return replace_macros(get_markup_template('confirm.tpl'), array(
250 '$message' => t('Do you really want to delete this contact?'),
251 '$extra_inputs' => $inputs,
252 '$confirm' => t('Yes'),
253 '$confirm_url' => $query['base'],
254 '$confirm_name' => 'confirmed',
255 '$cancel' => t('Cancel'),
258 // Now check how the user responded to the confirmation query
259 if($_REQUEST['canceled']) {
260 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
264 require_once('include/Contact.php');
266 terminate_friendship($a->user,$a->contact,$orig_record[0]);
268 contact_remove($orig_record[0]['id']);
269 info( t('Contact has been removed.') . EOL );
270 if(x($_SESSION,'return_url'))
271 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
273 goaway($a->get_baseurl(true) . '/contacts');
274 return; // NOTREACHED
280 $_SESSION['return_url'] = $a->query_string;
282 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
284 $contact_id = $a->data['contact']['id'];
285 $contact = $a->data['contact'];
287 $editselect = 'none';
288 if( feature_enabled(local_user(),'richtext') )
289 $editselect = 'exact';
291 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
292 '$baseurl' => $a->get_baseurl(true),
293 '$editselect' => $editselect,
295 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
296 '$baseurl' => $a->get_baseurl(true),
297 '$editselect' => $editselect,
300 require_once('include/contact_selectors.php');
302 $tpl = get_markup_template("contact_edit.tpl");
304 switch($contact['rel']) {
305 case CONTACT_IS_FRIEND:
306 $dir_icon = 'images/lrarrow.gif';
307 $relation_text = t('You are mutual friends with %s');
309 case CONTACT_IS_FOLLOWER;
310 $dir_icon = 'images/larrow.gif';
311 $relation_text = t('You are sharing with %s');
314 case CONTACT_IS_SHARING;
315 $dir_icon = 'images/rarrow.gif';
316 $relation_text = t('%s is sharing with you');
322 $relation_text = sprintf($relation_text,$contact['name']);
324 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
325 $url = "redir/{$contact['id']}";
326 $sparkle = ' class="sparkle" ';
329 $url = $contact['url'];
333 $insecure = t('Private communications are not available for this contact.');
335 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
337 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
339 if($contact['last-update'] !== '0000-00-00 00:00:00')
340 $last_update .= ' ' . (($contact['last-update'] == $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
342 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
344 $poll_enabled = (($contact['network'] !== NETWORK_DIASPORA) ? true : false);
346 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network']));
348 $common = count_common_friends(local_user(),$contact['id']);
349 $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
351 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
353 $x = count_all_friends(local_user(), $contact['id']);
354 $all_friends = (($x) ? t('View all contacts') : '');
359 'label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
360 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/block',
362 'title' => t('Toggle Blocked status'),
365 'label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
366 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/ignore',
368 'title' => t('Toggle Ignored status'),
372 'label' => (($contact['archive']) ? t('Unarchive') : t('Archive') ),
373 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/archive',
375 'title' => t('Toggle Archive status'),
378 'label' => t('Repair'),
379 'url' => $a->get_baseurl(true) . '/crepair/' . $contact_id,
381 'title' => t('Advanced Contact Settings'),
384 $tab_tpl = get_markup_template('common_tabs.tpl');
385 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
387 $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!') : '');
389 $o .= replace_macros($tpl, array(
390 '$header' => t('Contact Editor'),
391 '$tab_str' => $tab_str,
392 '$submit' => t('Submit'),
393 '$lbl_vis1' => t('Profile Visibility'),
394 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
395 '$lbl_info1' => t('Contact Information / Notes'),
396 '$infedit' => t('Edit contact notes'),
397 '$common_text' => $common_text,
398 '$common_link' => $a->get_baseurl(true) . '/common/loc/' . local_user() . '/' . $contact['id'],
399 '$all_friends' => $all_friends,
400 '$relation_text' => $relation_text,
401 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
402 '$blockunblock' => t('Block/Unblock contact'),
403 '$ignorecont' => t('Ignore contact'),
404 '$lblcrepair' => t("Repair URL settings"),
405 '$lblrecent' => t('View conversations'),
406 '$lblsuggest' => $lblsuggest,
407 '$delete' => t('Delete contact'),
408 '$nettype' => $nettype,
409 '$poll_interval' => contact_poll_interval($contact['priority'],(! $poll_enabled)),
410 '$poll_enabled' => $poll_enabled,
411 '$lastupdtext' => t('Last update:'),
412 '$lost_contact' => $lost_contact,
413 '$updpub' => t('Update public posts'),
414 '$last_update' => $last_update,
415 '$udnow' => t('Update now'),
416 '$profile_select' => contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false)),
417 '$contact_id' => $contact['id'],
418 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
419 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
420 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
421 '$info' => $contact['info'],
422 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
423 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
424 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
425 '$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')),
426 '$notify' => array('notify', t('Notification for new posts'), ($contact['notify_new_posts'] == 1), t('Send a notification of every new post of this contact')),
427 '$fetch_further_information' => array('fetch_further_information', t('Fetch further information for feeds'), ($contact['fetch_further_information'] == 1), t('Fetch further information for feeds')),
428 '$photo' => $contact['photo'],
429 '$name' => $contact['name'],
430 '$dir_icon' => $dir_icon,
431 '$alt_text' => $alt_text,
432 '$sparkle' => $sparkle,
437 $arr = array('contact' => $contact,'output' => $o);
439 call_hooks('contact_edit', $arr);
441 return $arr['output'];
450 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
454 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
455 $sql_extra = " AND `blocked` = 1 ";
458 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
459 $sql_extra = " AND `hidden` = 1 ";
462 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
463 $sql_extra = " AND `readonly` = 1 ";
466 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
467 $sql_extra = " AND `archive` = 1 ";
471 $sql_extra = " AND `blocked` = 0 ";
473 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
474 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
478 'label' => t('Suggestions'),
479 'url' => $a->get_baseurl(true) . '/suggest',
481 'title' => t('Suggest potential friends'),
484 'label' => t('All Contacts'),
485 'url' => $a->get_baseurl(true) . '/contacts/all',
486 'sel' => ($all) ? 'active' : '',
487 'title' => t('Show all contacts'),
490 'label' => t('Unblocked'),
491 'url' => $a->get_baseurl(true) . '/contacts',
492 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
493 'title' => t('Only show unblocked contacts'),
497 'label' => t('Blocked'),
498 'url' => $a->get_baseurl(true) . '/contacts/blocked',
499 'sel' => ($blocked) ? 'active' : '',
500 'title' => t('Only show blocked contacts'),
504 'label' => t('Ignored'),
505 'url' => $a->get_baseurl(true) . '/contacts/ignored',
506 'sel' => ($ignored) ? 'active' : '',
507 'title' => t('Only show ignored contacts'),
511 'label' => t('Archived'),
512 'url' => $a->get_baseurl(true) . '/contacts/archived',
513 'sel' => ($archived) ? 'active' : '',
514 'title' => t('Only show archived contacts'),
518 'label' => t('Hidden'),
519 'url' => $a->get_baseurl(true) . '/contacts/hidden',
520 'sel' => ($hidden) ? 'active' : '',
521 'title' => t('Only show hidden contacts'),
526 $tab_tpl = get_markup_template('common_tabs.tpl');
527 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
533 $search_hdr = $search;
534 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
537 $sql_extra .= (($searching) ? " AND `name` REGEXP '$search_txt' " : "");
540 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
542 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
545 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
546 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
547 intval($_SESSION['uid']));
549 $a->set_pager_total($r[0]['total']);
550 $total = $r[0]['total'];
554 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
555 intval($_SESSION['uid']),
556 intval($a->pager['start']),
557 intval($a->pager['itemspage'])
567 case CONTACT_IS_FRIEND:
568 $dir_icon = 'images/lrarrow.gif';
569 $alt_text = t('Mutual Friendship');
571 case CONTACT_IS_FOLLOWER;
572 $dir_icon = 'images/larrow.gif';
573 $alt_text = t('is a fan of yours');
575 case CONTACT_IS_SHARING;
576 $dir_icon = 'images/rarrow.gif';
577 $alt_text = t('you are a fan of');
582 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
583 $url = "redir/{$rr['id']}";
584 $sparkle = ' class="sparkle" ';
593 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
594 'edit_hover' => t('Edit contact'),
595 'photo_menu' => contact_photo_menu($rr),
597 'alt_text' => $alt_text,
598 'dir_icon' => $dir_icon,
599 'thumb' => $rr['thumb'],
600 'name' => $rr['name'],
601 'username' => $rr['name'],
602 'sparkle' => $sparkle,
603 'itemurl' => $rr['url'],
605 'network' => network_to_name($rr['network']),
613 $tpl = get_markup_template("contacts-template.tpl");
614 $o .= replace_macros($tpl, array(
615 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
618 '$search' => $search_hdr,
619 '$desc' => t('Search your contacts'),
620 '$finding' => (($searching) ? t('Finding: ') . "'" . $search . "'" : ""),
621 '$submit' => t('Find'),
623 '$contacts' => $contacts,
624 '$paginate' => paginate($a),