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 $priority = intval($_POST['poll']);
107 if($priority > 5 || $priority < 0)
110 $info = fix_mce_lf(escape_tags(trim($_POST['info'])));
112 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
113 `hidden` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
122 info( t('Contact updated.') . EOL);
124 notice( t('Failed to update contact record.') . EOL);
126 $r = q("select * from contact where id = %d and uid = %d limit 1",
131 $a->data['contact'] = $r[0];
139 function contacts_content(&$a) {
143 nav_set_selected('contacts');
147 notice( t('Permission denied.') . EOL);
153 $contact_id = intval($a->argv[1]);
159 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
164 if(! count($orig_record)) {
165 notice( t('Could not access contact record.') . EOL);
166 goaway($a->get_baseurl(true) . '/contacts');
167 return; // NOTREACHED
170 if($cmd === 'update') {
172 // pull feed and consume it, which should subscribe to the hub.
173 proc_run('php',"include/poller.php","$contact_id");
174 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
178 if($cmd === 'block') {
179 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
180 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
186 //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
187 info( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
189 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
190 return; // NOTREACHED
193 if($cmd === 'ignore') {
194 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
195 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
201 info( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
203 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
204 return; // NOTREACHED
208 if($cmd === 'archive') {
209 $archived = (($orig_record[0]['archive']) ? 0 : 1);
210 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
216 q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
219 //notice( t('Contact has been ') . (($archived) ? t('archived') : t('unarchived')) . EOL );
220 info( (($archived) ? t('Contact has been archived') : t('Contact has been unarchived')) . EOL );
222 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
223 return; // NOTREACHED
226 if($cmd === 'drop') {
228 // Check if we should do HTML-based delete confirmation
229 if($_REQUEST['confirm']) {
230 // <form> can't take arguments in its "action" parameter
231 // so add any arguments as hidden inputs
232 $query = explode_querystring($a->query_string);
234 foreach($query['args'] as $arg) {
235 if(strpos($arg, 'confirm=') === false) {
236 $arg_parts = explode('=', $arg);
237 $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
241 $a->page['aside'] = '';
242 return replace_macros(get_markup_template('confirm.tpl'), array(
244 '$message' => t('Do you really want to delete this contact?'),
245 '$extra_inputs' => $inputs,
246 '$confirm' => t('Yes'),
247 '$confirm_url' => $query['base'],
248 '$confirm_name' => 'confirmed',
249 '$cancel' => t('Cancel'),
252 // Now check how the user responded to the confirmation query
253 if($_REQUEST['canceled']) {
254 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
258 require_once('include/Contact.php');
260 terminate_friendship($a->user,$a->contact,$orig_record[0]);
262 contact_remove($orig_record[0]['id']);
263 info( t('Contact has been removed.') . EOL );
264 if(x($_SESSION,'return_url'))
265 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
267 goaway($a->get_baseurl(true) . '/contacts');
268 return; // NOTREACHED
274 $_SESSION['return_url'] = $a->query_string;
276 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
278 $contact_id = $a->data['contact']['id'];
279 $contact = $a->data['contact'];
281 $editselect = 'none';
282 if( feature_enabled(local_user(),'richtext') )
283 $editselect = 'exact';
285 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
286 '$baseurl' => $a->get_baseurl(true),
287 '$editselect' => $editselect,
289 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
290 '$baseurl' => $a->get_baseurl(true),
291 '$editselect' => $editselect,
294 require_once('include/contact_selectors.php');
296 $tpl = get_markup_template("contact_edit.tpl");
298 switch($contact['rel']) {
299 case CONTACT_IS_FRIEND:
300 $dir_icon = 'images/lrarrow.gif';
301 $relation_text = t('You are mutual friends with %s');
303 case CONTACT_IS_FOLLOWER;
304 $dir_icon = 'images/larrow.gif';
305 $relation_text = t('You are sharing with %s');
308 case CONTACT_IS_SHARING;
309 $dir_icon = 'images/rarrow.gif';
310 $relation_text = t('%s is sharing with you');
316 $relation_text = sprintf($relation_text,$contact['name']);
318 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
319 $url = "redir/{$contact['id']}";
320 $sparkle = ' class="sparkle" ';
323 $url = $contact['url'];
327 $insecure = t('Private communications are not available for this contact.');
329 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
331 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
333 if($contact['last-update'] !== '0000-00-00 00:00:00')
334 $last_update .= ' ' . (($contact['last-update'] == $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
336 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
338 $poll_enabled = (($contact['network'] !== NETWORK_DIASPORA) ? true : false);
340 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network']));
342 $common = count_common_friends(local_user(),$contact['id']);
343 $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
345 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
347 $x = count_all_friends(local_user(), $contact['id']);
348 $all_friends = (($x) ? t('View all contacts') : '');
353 'label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
354 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/block',
356 'title' => t('Toggle Blocked status'),
359 'label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
360 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/ignore',
362 'title' => t('Toggle Ignored status'),
366 'label' => (($contact['archive']) ? t('Unarchive') : t('Archive') ),
367 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/archive',
369 'title' => t('Toggle Archive status'),
372 'label' => t('Repair'),
373 'url' => $a->get_baseurl(true) . '/crepair/' . $contact_id,
375 'title' => t('Advanced Contact Settings'),
378 $tab_tpl = get_markup_template('common_tabs.tpl');
379 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
381 $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!') : '');
383 $o .= replace_macros($tpl, array(
384 '$header' => t('Contact Editor'),
385 '$tab_str' => $tab_str,
386 '$submit' => t('Submit'),
387 '$lbl_vis1' => t('Profile Visibility'),
388 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
389 '$lbl_info1' => t('Contact Information / Notes'),
390 '$infedit' => t('Edit contact notes'),
391 '$common_text' => $common_text,
392 '$common_link' => $a->get_baseurl(true) . '/common/loc/' . local_user() . '/' . $contact['id'],
393 '$all_friends' => $all_friends,
394 '$relation_text' => $relation_text,
395 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
396 '$blockunblock' => t('Block/Unblock contact'),
397 '$ignorecont' => t('Ignore contact'),
398 '$lblcrepair' => t("Repair URL settings"),
399 '$lblrecent' => t('View conversations'),
400 '$lblsuggest' => $lblsuggest,
401 '$delete' => t('Delete contact'),
402 '$nettype' => $nettype,
403 '$poll_interval' => contact_poll_interval($contact['priority'],(! $poll_enabled)),
404 '$poll_enabled' => $poll_enabled,
405 '$lastupdtext' => t('Last update:'),
406 '$lost_contact' => $lost_contact,
407 '$updpub' => t('Update public posts'),
408 '$last_update' => $last_update,
409 '$udnow' => t('Update now'),
410 '$profile_select' => contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false)),
411 '$contact_id' => $contact['id'],
412 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
413 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
414 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
415 '$info' => $contact['info'],
416 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
417 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
418 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
419 '$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')),
420 '$photo' => $contact['photo'],
421 '$name' => $contact['name'],
422 '$dir_icon' => $dir_icon,
423 '$alt_text' => $alt_text,
424 '$sparkle' => $sparkle,
429 $arr = array('contact' => $contact,'output' => $o);
431 call_hooks('contact_edit', $arr);
433 return $arr['output'];
442 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
446 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
447 $sql_extra = " AND `blocked` = 1 ";
450 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
451 $sql_extra = " AND `hidden` = 1 ";
454 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
455 $sql_extra = " AND `readonly` = 1 ";
458 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
459 $sql_extra = " AND `archive` = 1 ";
463 $sql_extra = " AND `blocked` = 0 ";
465 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
466 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
470 'label' => t('Suggestions'),
471 'url' => $a->get_baseurl(true) . '/suggest',
473 'title' => t('Suggest potential friends'),
476 'label' => t('All Contacts'),
477 'url' => $a->get_baseurl(true) . '/contacts/all',
478 'sel' => ($all) ? 'active' : '',
479 'title' => t('Show all contacts'),
482 'label' => t('Unblocked'),
483 'url' => $a->get_baseurl(true) . '/contacts',
484 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
485 'title' => t('Only show unblocked contacts'),
489 'label' => t('Blocked'),
490 'url' => $a->get_baseurl(true) . '/contacts/blocked',
491 'sel' => ($blocked) ? 'active' : '',
492 'title' => t('Only show blocked contacts'),
496 'label' => t('Ignored'),
497 'url' => $a->get_baseurl(true) . '/contacts/ignored',
498 'sel' => ($ignored) ? 'active' : '',
499 'title' => t('Only show ignored contacts'),
503 'label' => t('Archived'),
504 'url' => $a->get_baseurl(true) . '/contacts/archived',
505 'sel' => ($archived) ? 'active' : '',
506 'title' => t('Only show archived contacts'),
510 'label' => t('Hidden'),
511 'url' => $a->get_baseurl(true) . '/contacts/hidden',
512 'sel' => ($hidden) ? 'active' : '',
513 'title' => t('Only show hidden contacts'),
518 $tab_tpl = get_markup_template('common_tabs.tpl');
519 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
525 $search_hdr = $search;
526 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
529 $sql_extra .= (($searching) ? " AND `name` REGEXP '$search_txt' " : "");
532 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
534 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
537 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
538 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
539 intval($_SESSION['uid']));
541 $a->set_pager_total($r[0]['total']);
542 $total = $r[0]['total'];
546 $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 ",
547 intval($_SESSION['uid']),
548 intval($a->pager['start']),
549 intval($a->pager['itemspage'])
559 case CONTACT_IS_FRIEND:
560 $dir_icon = 'images/lrarrow.gif';
561 $alt_text = t('Mutual Friendship');
563 case CONTACT_IS_FOLLOWER;
564 $dir_icon = 'images/larrow.gif';
565 $alt_text = t('is a fan of yours');
567 case CONTACT_IS_SHARING;
568 $dir_icon = 'images/rarrow.gif';
569 $alt_text = t('you are a fan of');
574 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
575 $url = "redir/{$rr['id']}";
576 $sparkle = ' class="sparkle" ';
585 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
586 'edit_hover' => t('Edit contact'),
587 'photo_menu' => contact_photo_menu($rr),
589 'alt_text' => $alt_text,
590 'dir_icon' => $dir_icon,
591 'thumb' => $rr['thumb'],
592 'name' => $rr['name'],
593 'username' => $rr['name'],
594 'sparkle' => $sparkle,
595 'itemurl' => $rr['url'],
597 'network' => network_to_name($rr['network']),
605 $tpl = get_markup_template("contacts-template.tpl");
606 $o .= replace_macros($tpl, array(
607 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
610 '$search' => $search_hdr,
611 '$desc' => t('Search your contacts'),
612 '$finding' => (($searching) ? t('Finding: ') . "'" . $search . "'" : ""),
613 '$submit' => t('Find'),
615 '$contacts' => $contacts,
616 '$paginate' => paginate($a),