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 require_once('include/Contact.php');
230 terminate_friendship($a->user,$a->contact,$orig_record[0]);
232 contact_remove($orig_record[0]['id']);
233 info( t('Contact has been removed.') . EOL );
234 if(x($_SESSION,'return_url'))
235 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
237 goaway($a->get_baseurl(true) . '/contacts');
238 return; // NOTREACHED
242 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
244 $contact_id = $a->data['contact']['id'];
245 $contact = $a->data['contact'];
247 $editselect = 'exact';
248 if(intval(get_pconfig(local_user(),'system','plaintext')))
249 $editselect = 'none';
251 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
252 '$baseurl' => $a->get_baseurl(true),
253 '$editselect' => $editselect,
255 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
256 '$baseurl' => $a->get_baseurl(true),
257 '$editselect' => $editselect,
260 require_once('include/contact_selectors.php');
262 $tpl = get_markup_template("contact_edit.tpl");
264 switch($contact['rel']) {
265 case CONTACT_IS_FRIEND:
266 $dir_icon = 'images/lrarrow.gif';
267 $relation_text = t('You are mutual friends with %s');
269 case CONTACT_IS_FOLLOWER;
270 $dir_icon = 'images/larrow.gif';
271 $relation_text = t('You are sharing with %s');
274 case CONTACT_IS_SHARING;
275 $dir_icon = 'images/rarrow.gif';
276 $relation_text = t('%s is sharing with you');
282 $relation_text = sprintf($relation_text,$contact['name']);
284 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
285 $url = "redir/{$contact['id']}";
286 $sparkle = ' class="sparkle" ';
289 $url = $contact['url'];
293 $insecure = t('Private communications are not available for this contact.');
295 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
297 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
299 if($contact['last-update'] !== '0000-00-00 00:00:00')
300 $last_update .= ' ' . (($contact['last-update'] == $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
302 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
304 $poll_enabled = (($contact['network'] !== NETWORK_DIASPORA) ? true : false);
306 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network']));
308 $common = count_common_friends(local_user(),$contact['id']);
309 $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
311 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
313 $x = count_all_friends(local_user(), $contact['id']);
314 $all_friends = (($x) ? t('View all contacts') : '');
319 'label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
320 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/block',
322 'title' => t('Toggle Blocked status'),
325 'label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
326 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/ignore',
328 'title' => t('Toggle Ignored status'),
332 'label' => (($contact['archive']) ? t('Unarchive') : t('Archive') ),
333 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/archive',
335 'title' => t('Toggle Archive status'),
338 'label' => t('Repair'),
339 'url' => $a->get_baseurl(true) . '/crepair/' . $contact_id,
341 'title' => t('Advanced Contact Settings'),
344 $tab_tpl = get_markup_template('common_tabs.tpl');
345 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
347 $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!') : '');
350 '$field_checkbox' => 'field_checkbox.tpl',
352 $includes = set_template_includes($a->theme['template_engine'], $includes);
354 $o .= replace_macros($tpl,$includes + array(
355 '$header' => t('Contact Editor'),
356 '$tab_str' => $tab_str,
357 '$submit' => t('Submit'),
358 '$lbl_vis1' => t('Profile Visibility'),
359 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
360 '$lbl_info1' => t('Contact Information / Notes'),
361 '$infedit' => t('Edit contact notes'),
362 '$common_text' => $common_text,
363 '$common_link' => $a->get_baseurl(true) . '/common/loc/' . local_user() . '/' . $contact['id'],
364 '$all_friends' => $all_friends,
365 '$relation_text' => $relation_text,
366 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
367 '$blockunblock' => t('Block/Unblock contact'),
368 '$ignorecont' => t('Ignore contact'),
369 '$lblcrepair' => t("Repair URL settings"),
370 '$lblrecent' => t('View conversations'),
371 '$lblsuggest' => $lblsuggest,
372 '$delete' => t('Delete contact'),
373 '$nettype' => $nettype,
374 '$poll_interval' => contact_poll_interval($contact['priority'],(! $poll_enabled)),
375 '$poll_enabled' => $poll_enabled,
376 '$lastupdtext' => t('Last update:'),
377 '$lost_contact' => $lost_contact,
378 '$updpub' => t('Update public posts'),
379 '$last_update' => $last_update,
380 '$udnow' => t('Update now'),
381 '$profile_select' => contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false)),
382 '$contact_id' => $contact['id'],
383 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
384 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
385 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
386 '$info' => $contact['info'],
387 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
388 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
389 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
390 '$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')),
391 '$photo' => $contact['photo'],
392 '$name' => $contact['name'],
393 '$dir_icon' => $dir_icon,
394 '$alt_text' => $alt_text,
395 '$sparkle' => $sparkle,
400 $arr = array('contact' => $contact,'output' => $o);
402 call_hooks('contact_edit', $arr);
404 return $arr['output'];
413 $_SESSION['return_url'] = $a->query_string;
415 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
419 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
420 $sql_extra = " AND `blocked` = 1 ";
423 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
424 $sql_extra = " AND `hidden` = 1 ";
427 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
428 $sql_extra = " AND `readonly` = 1 ";
431 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
432 $sql_extra = " AND `archive` = 1 ";
436 $sql_extra = " AND `blocked` = 0 ";
438 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
439 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
443 'label' => t('Suggestions'),
444 'url' => $a->get_baseurl(true) . '/suggest',
446 'title' => t('Suggest potential friends'),
449 'label' => t('All Contacts'),
450 'url' => $a->get_baseurl(true) . '/contacts/all',
451 'sel' => ($all) ? 'active' : '',
452 'title' => t('Show all contacts'),
455 'label' => t('Unblocked'),
456 'url' => $a->get_baseurl(true) . '/contacts',
457 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
458 'title' => t('Only show unblocked contacts'),
462 'label' => t('Blocked'),
463 'url' => $a->get_baseurl(true) . '/contacts/blocked',
464 'sel' => ($blocked) ? 'active' : '',
465 'title' => t('Only show blocked contacts'),
469 'label' => t('Ignored'),
470 'url' => $a->get_baseurl(true) . '/contacts/ignored',
471 'sel' => ($ignored) ? 'active' : '',
472 'title' => t('Only show ignored contacts'),
476 'label' => t('Archived'),
477 'url' => $a->get_baseurl(true) . '/contacts/archived',
478 'sel' => ($archived) ? 'active' : '',
479 'title' => t('Only show archived contacts'),
483 'label' => t('Hidden'),
484 'url' => $a->get_baseurl(true) . '/contacts/hidden',
485 'sel' => ($hidden) ? 'active' : '',
486 'title' => t('Only show hidden contacts'),
491 $tab_tpl = get_markup_template('common_tabs.tpl');
492 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
498 $search_hdr = $search;
499 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
502 $sql_extra .= (($searching) ? " AND `name` REGEXP '$search_txt' " : "");
505 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
507 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
510 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
511 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
512 intval($_SESSION['uid']));
514 $a->set_pager_total($r[0]['total']);
515 $total = $r[0]['total'];
519 $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 ",
520 intval($_SESSION['uid']),
521 intval($a->pager['start']),
522 intval($a->pager['itemspage'])
532 case CONTACT_IS_FRIEND:
533 $dir_icon = 'images/lrarrow.gif';
534 $alt_text = t('Mutual Friendship');
536 case CONTACT_IS_FOLLOWER;
537 $dir_icon = 'images/larrow.gif';
538 $alt_text = t('is a fan of yours');
540 case CONTACT_IS_SHARING;
541 $dir_icon = 'images/rarrow.gif';
542 $alt_text = t('you are a fan of');
547 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
548 $url = "redir/{$rr['id']}";
549 $sparkle = ' class="sparkle" ';
558 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
559 'edit_hover' => t('Edit contact'),
560 'photo_menu' => contact_photo_menu($rr),
562 'alt_text' => $alt_text,
563 'dir_icon' => $dir_icon,
564 'thumb' => $rr['thumb'],
565 'name' => $rr['name'],
566 'username' => $rr['name'],
567 'sparkle' => $sparkle,
568 'itemurl' => $rr['url'],
570 'network' => network_to_name($rr['network']),
578 $tpl = get_markup_template("contacts-template.tpl");
581 '$contact_template' => 'contact_template.tpl',
583 $includes = set_template_includes($a->theme['template_engine'], $includes);
585 $o .= replace_macros($tpl,$includes + array(
586 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
589 '$search' => $search_hdr,
590 '$desc' => t('Search your contacts'),
591 '$finding' => (($searching) ? t('Finding: ') . "'" . $search . "'" : ""),
592 '$submit' => t('Find'),
594 '$contacts' => $contacts,
595 '$paginate' => paginate($a),