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!') : '');
349 $o .= replace_macros($tpl, array(
350 '$header' => t('Contact Editor'),
351 '$tab_str' => $tab_str,
352 '$submit' => t('Submit'),
353 '$lbl_vis1' => t('Profile Visibility'),
354 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
355 '$lbl_info1' => t('Contact Information / Notes'),
356 '$infedit' => t('Edit contact notes'),
357 '$common_text' => $common_text,
358 '$common_link' => $a->get_baseurl(true) . '/common/loc/' . local_user() . '/' . $contact['id'],
359 '$all_friends' => $all_friends,
360 '$relation_text' => $relation_text,
361 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
362 '$blockunblock' => t('Block/Unblock contact'),
363 '$ignorecont' => t('Ignore contact'),
364 '$lblcrepair' => t("Repair URL settings"),
365 '$lblrecent' => t('View conversations'),
366 '$lblsuggest' => $lblsuggest,
367 '$delete' => t('Delete contact'),
368 '$nettype' => $nettype,
369 '$poll_interval' => contact_poll_interval($contact['priority'],(! $poll_enabled)),
370 '$poll_enabled' => $poll_enabled,
371 '$lastupdtext' => t('Last update:'),
372 '$lost_contact' => $lost_contact,
373 '$updpub' => t('Update public posts'),
374 '$last_update' => $last_update,
375 '$udnow' => t('Update now'),
376 '$profile_select' => contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false)),
377 '$contact_id' => $contact['id'],
378 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
379 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
380 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
381 '$info' => $contact['info'],
382 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
383 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
384 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
385 '$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')),
386 '$photo' => $contact['photo'],
387 '$name' => $contact['name'],
388 '$dir_icon' => $dir_icon,
389 '$alt_text' => $alt_text,
390 '$sparkle' => $sparkle,
395 $arr = array('contact' => $contact,'output' => $o);
397 call_hooks('contact_edit', $arr);
399 return $arr['output'];
408 $_SESSION['return_url'] = $a->query_string;
410 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
414 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
415 $sql_extra = " AND `blocked` = 1 ";
418 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
419 $sql_extra = " AND `hidden` = 1 ";
422 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
423 $sql_extra = " AND `readonly` = 1 ";
426 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
427 $sql_extra = " AND `archive` = 1 ";
431 $sql_extra = " AND `blocked` = 0 ";
433 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
434 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
438 'label' => t('Suggestions'),
439 'url' => $a->get_baseurl(true) . '/suggest',
441 'title' => t('Suggest potential friends'),
444 'label' => t('All Contacts'),
445 'url' => $a->get_baseurl(true) . '/contacts/all',
446 'sel' => ($all) ? 'active' : '',
447 'title' => t('Show all contacts'),
450 'label' => t('Unblocked'),
451 'url' => $a->get_baseurl(true) . '/contacts',
452 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
453 'title' => t('Only show unblocked contacts'),
457 'label' => t('Blocked'),
458 'url' => $a->get_baseurl(true) . '/contacts/blocked',
459 'sel' => ($blocked) ? 'active' : '',
460 'title' => t('Only show blocked contacts'),
464 'label' => t('Ignored'),
465 'url' => $a->get_baseurl(true) . '/contacts/ignored',
466 'sel' => ($ignored) ? 'active' : '',
467 'title' => t('Only show ignored contacts'),
471 'label' => t('Archived'),
472 'url' => $a->get_baseurl(true) . '/contacts/archived',
473 'sel' => ($archived) ? 'active' : '',
474 'title' => t('Only show archived contacts'),
478 'label' => t('Hidden'),
479 'url' => $a->get_baseurl(true) . '/contacts/hidden',
480 'sel' => ($hidden) ? 'active' : '',
481 'title' => t('Only show hidden contacts'),
486 $tab_tpl = get_markup_template('common_tabs.tpl');
487 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
493 $search_hdr = $search;
494 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
497 $sql_extra .= (($searching) ? " AND `name` REGEXP '$search_txt' " : "");
500 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
502 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
505 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
506 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
507 intval($_SESSION['uid']));
509 $a->set_pager_total($r[0]['total']);
510 $total = $r[0]['total'];
514 $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 ",
515 intval($_SESSION['uid']),
516 intval($a->pager['start']),
517 intval($a->pager['itemspage'])
527 case CONTACT_IS_FRIEND:
528 $dir_icon = 'images/lrarrow.gif';
529 $alt_text = t('Mutual Friendship');
531 case CONTACT_IS_FOLLOWER;
532 $dir_icon = 'images/larrow.gif';
533 $alt_text = t('is a fan of yours');
535 case CONTACT_IS_SHARING;
536 $dir_icon = 'images/rarrow.gif';
537 $alt_text = t('you are a fan of');
542 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
543 $url = "redir/{$rr['id']}";
544 $sparkle = ' class="sparkle" ';
553 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
554 'edit_hover' => t('Edit contact'),
555 'photo_menu' => contact_photo_menu($rr),
557 'alt_text' => $alt_text,
558 'dir_icon' => $dir_icon,
559 'thumb' => $rr['thumb'],
560 'name' => $rr['name'],
561 'username' => $rr['name'],
562 'sparkle' => $sparkle,
563 'itemurl' => $rr['url'],
565 'network' => network_to_name($rr['network']),
573 $tpl = get_markup_template("contacts-template.tpl");
574 $o .= replace_macros($tpl, array(
575 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
578 '$search' => $search_hdr,
579 '$desc' => t('Search your contacts'),
580 '$finding' => (($searching) ? t('Finding: ') . "'" . $search . "'" : ""),
581 '$submit' => t('Find'),
583 '$contacts' => $contacts,
584 '$paginate' => paginate($a),