3 require_once('include/Contact.php');
4 require_once('include/socgraph.php');
6 function contacts_init(&$a) {
12 if(($a->argc == 2) && intval($a->argv[1])) {
13 $contact_id = intval($a->argv[1]);
14 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
23 require_once('include/group.php');
24 require_once('include/contact_widgets.php');
26 if(! x($a->page,'aside'))
27 $a->page['aside'] = '';
30 $a->data['contact'] = $r[0];
31 $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array(
32 '$name' => $a->data['contact']['name'],
33 '$photo' => $a->data['contact']['photo']
39 $follow_widget = follow_widget();
42 $groups_widget .= group_side('contacts','group',false,0,$contact_id);
43 $findpeople_widget .= findpeople_widget();
44 $networks_widget .= networks_widget('contacts',$_GET['nets']);
45 $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"),array(
46 '$vcard_widget' => $vcard_widget,
47 '$follow_widget' => $follow_widget,
48 '$groups_widget' => $groups_widget,
49 '$findpeople_widget' => $findpeople_widget,
50 '$networks_widget' => $networks_widget
53 $base = $a->get_baseurl();
54 $tpl = get_markup_template("contacts-head.tpl");
55 $a->page['htmlhead'] .= replace_macros($tpl,array(
56 '$baseurl' => $a->get_baseurl(true),
60 $tpl = get_markup_template("contacts-end.tpl");
61 $a->page['end'] .= replace_macros($tpl,array(
62 '$baseurl' => $a->get_baseurl(true),
69 function contacts_post(&$a) {
74 $contact_id = intval($a->argv[1]);
78 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
83 if(! count($orig_record)) {
84 notice( t('Could not access contact record.') . EOL);
85 goaway($a->get_baseurl(true) . '/contacts');
89 call_hooks('contact_edit_post', $_POST);
91 $profile_id = intval($_POST['profile-assign']);
93 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
98 notice( t('Could not locate selected profile.') . EOL);
103 $hidden = intval($_POST['hidden']);
105 $priority = intval($_POST['poll']);
106 if($priority > 5 || $priority < 0)
109 $info = fix_mce_lf(escape_tags(trim($_POST['info'])));
111 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
112 `hidden` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
121 info( t('Contact updated.') . EOL);
123 notice( t('Failed to update contact record.') . EOL);
125 $r = q("select * from contact where id = %d and uid = %d limit 1",
130 $a->data['contact'] = $r[0];
138 function contacts_content(&$a) {
142 nav_set_selected('contacts');
146 notice( t('Permission denied.') . EOL);
152 $contact_id = intval($a->argv[1]);
158 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
163 if(! count($orig_record)) {
164 notice( t('Could not access contact record.') . EOL);
165 goaway($a->get_baseurl(true) . '/contacts');
166 return; // NOTREACHED
169 if($cmd === 'update') {
171 // pull feed and consume it, which should subscribe to the hub.
172 proc_run('php',"include/poller.php","$contact_id");
173 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
177 if($cmd === 'block') {
178 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
179 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
185 //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
186 info( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
188 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
189 return; // NOTREACHED
192 if($cmd === 'ignore') {
193 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
194 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
200 info( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
202 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
203 return; // NOTREACHED
207 if($cmd === 'archive') {
208 $archived = (($orig_record[0]['archive']) ? 0 : 1);
209 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
215 //notice( t('Contact has been ') . (($archived) ? t('archived') : t('unarchived')) . EOL );
216 info( (($archived) ? t('Contact has been archived') : t('Contact has been unarchived')) . EOL );
218 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
219 return; // NOTREACHED
222 if($cmd === 'drop') {
224 require_once('include/Contact.php');
226 terminate_friendship($a->user,$a->contact,$orig_record[0]);
228 contact_remove($orig_record[0]['id']);
229 info( t('Contact has been removed.') . EOL );
230 if(x($_SESSION,'return_url'))
231 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
233 goaway($a->get_baseurl(true) . '/contacts');
234 return; // NOTREACHED
238 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
240 $contact_id = $a->data['contact']['id'];
241 $contact = $a->data['contact'];
243 $editselect = 'exact';
244 if(intval(get_pconfig(local_user(),'system','plaintext')))
245 $editselect = 'none';
247 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
248 '$baseurl' => $a->get_baseurl(true),
249 '$editselect' => $editselect,
251 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
252 '$baseurl' => $a->get_baseurl(true),
253 '$editselect' => $editselect,
256 require_once('include/contact_selectors.php');
258 $tpl = get_markup_template("contact_edit.tpl");
260 switch($contact['rel']) {
261 case CONTACT_IS_FRIEND:
262 $dir_icon = 'images/lrarrow.gif';
263 $relation_text = t('You are mutual friends with %s');
265 case CONTACT_IS_FOLLOWER;
266 $dir_icon = 'images/larrow.gif';
267 $relation_text = t('You are sharing with %s');
270 case CONTACT_IS_SHARING;
271 $dir_icon = 'images/rarrow.gif';
272 $relation_text = t('%s is sharing with you');
278 $relation_text = sprintf($relation_text,$contact['name']);
280 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
281 $url = "redir/{$contact['id']}";
282 $sparkle = ' class="sparkle" ';
285 $url = $contact['url'];
289 $insecure = t('Private communications are not available for this contact.');
291 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
293 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
295 if($contact['last-update'] !== '0000-00-00 00:00:00')
296 $last_update .= ' ' . (($contact['last-update'] == $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
298 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
300 $poll_enabled = (($contact['network'] !== NETWORK_DIASPORA) ? true : false);
302 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network']));
304 $common = count_common_friends(local_user(),$contact['id']);
305 $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
307 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
309 $x = count_all_friends(local_user(), $contact['id']);
310 $all_friends = (($x) ? t('View all contacts') : '');
315 'label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
316 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/block',
318 'title' => t('Toggle Blocked status'),
321 'label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
322 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/ignore',
324 'title' => t('Toggle Ignored status'),
328 'label' => (($contact['archive']) ? t('Unarchive') : t('Archive') ),
329 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/archive',
331 'title' => t('Toggle Archive status'),
334 'label' => t('Repair'),
335 'url' => $a->get_baseurl(true) . '/crepair/' . $contact_id,
337 'title' => t('Advanced Contact Settings'),
340 $tab_tpl = get_markup_template('common_tabs.tpl');
341 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
343 $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!') : '');
345 $o .= replace_macros($tpl,array(
346 '$header' => t('Contact Editor'),
347 '$tab_str' => $tab_str,
348 '$submit' => t('Submit'),
349 '$lbl_vis1' => t('Profile Visibility'),
350 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
351 '$lbl_info1' => t('Contact Information / Notes'),
352 '$infedit' => t('Edit contact notes'),
353 '$common_text' => $common_text,
354 '$common_link' => $a->get_baseurl(true) . '/common/loc/' . local_user() . '/' . $contact['id'],
355 '$all_friends' => $all_friends,
356 '$relation_text' => $relation_text,
357 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
358 '$blockunblock' => t('Block/Unblock contact'),
359 '$ignorecont' => t('Ignore contact'),
360 '$lblcrepair' => t("Repair URL settings"),
361 '$lblrecent' => t('View conversations'),
362 '$lblsuggest' => $lblsuggest,
363 '$delete' => t('Delete contact'),
364 '$nettype' => $nettype,
365 '$poll_interval' => contact_poll_interval($contact['priority'],(! $poll_enabled)),
366 '$poll_enabled' => $poll_enabled,
367 '$lastupdtext' => t('Last update:'),
368 '$lost_contact' => $lost_contact,
369 '$updpub' => t('Update public posts'),
370 '$last_update' => $last_update,
371 '$udnow' => t('Update now'),
372 '$profile_select' => contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false)),
373 '$contact_id' => $contact['id'],
374 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
375 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
376 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
377 '$info' => $contact['info'],
378 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
379 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
380 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
381 '$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')),
382 '$photo' => $contact['photo'],
383 '$name' => $contact['name'],
384 '$dir_icon' => $dir_icon,
385 '$alt_text' => $alt_text,
386 '$sparkle' => $sparkle,
391 $arr = array('contact' => $contact,'output' => $o);
393 call_hooks('contact_edit', $arr);
395 return $arr['output'];
404 $_SESSION['return_url'] = $a->query_string;
406 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
410 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
411 $sql_extra = " AND `blocked` = 1 ";
414 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
415 $sql_extra = " AND `hidden` = 1 ";
418 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
419 $sql_extra = " AND `readonly` = 1 ";
422 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
423 $sql_extra = " AND `archive` = 1 ";
427 $sql_extra = " AND `blocked` = 0 ";
429 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
430 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
434 'label' => t('Suggestions'),
435 'url' => $a->get_baseurl(true) . '/suggest',
437 'title' => t('Suggest potential friends'),
440 'label' => t('All Contacts'),
441 'url' => $a->get_baseurl(true) . '/contacts/all',
442 'sel' => ($all) ? 'active' : '',
443 'title' => t('Show all contacts'),
446 'label' => t('Unblocked'),
447 'url' => $a->get_baseurl(true) . '/contacts',
448 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
449 'title' => t('Only show unblocked contacts'),
453 'label' => t('Blocked'),
454 'url' => $a->get_baseurl(true) . '/contacts/blocked',
455 'sel' => ($blocked) ? 'active' : '',
456 'title' => t('Only show blocked contacts'),
460 'label' => t('Ignored'),
461 'url' => $a->get_baseurl(true) . '/contacts/ignored',
462 'sel' => ($ignored) ? 'active' : '',
463 'title' => t('Only show ignored contacts'),
467 'label' => t('Archived'),
468 'url' => $a->get_baseurl(true) . '/contacts/archived',
469 'sel' => ($archived) ? 'active' : '',
470 'title' => t('Only show archived contacts'),
474 'label' => t('Hidden'),
475 'url' => $a->get_baseurl(true) . '/contacts/hidden',
476 'sel' => ($hidden) ? 'active' : '',
477 'title' => t('Only show hidden contacts'),
482 $tab_tpl = get_markup_template('common_tabs.tpl');
483 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
489 $search_hdr = $search;
490 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
493 $sql_extra .= (($searching) ? " AND `name` REGEXP '$search_txt' " : "");
496 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
498 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
501 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
502 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
503 intval($_SESSION['uid']));
505 $a->set_pager_total($r[0]['total']);
506 $total = $r[0]['total'];
510 $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 ",
511 intval($_SESSION['uid']),
512 intval($a->pager['start']),
513 intval($a->pager['itemspage'])
523 case CONTACT_IS_FRIEND:
524 $dir_icon = 'images/lrarrow.gif';
525 $alt_text = t('Mutual Friendship');
527 case CONTACT_IS_FOLLOWER;
528 $dir_icon = 'images/larrow.gif';
529 $alt_text = t('is a fan of yours');
531 case CONTACT_IS_SHARING;
532 $dir_icon = 'images/rarrow.gif';
533 $alt_text = t('you are a fan of');
538 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
539 $url = "redir/{$rr['id']}";
540 $sparkle = ' class="sparkle" ';
549 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
550 'edit_hover' => t('Edit contact'),
551 'photo_menu' => contact_photo_menu($rr),
553 'alt_text' => $alt_text,
554 'dir_icon' => $dir_icon,
555 'thumb' => $rr['thumb'],
556 'name' => $rr['name'],
557 'username' => $rr['name'],
558 'sparkle' => $sparkle,
559 'itemurl' => $rr['url'],
561 'network' => network_to_name($rr['network']),
569 $tpl = get_markup_template("contacts-template.tpl");
570 $o .= replace_macros($tpl,array(
571 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
574 '$search' => $search_hdr,
575 '$desc' => t('Search your contacts'),
576 '$finding' => (($searching) ? t('Finding: ') . "'" . $search . "'" : ""),
577 '$submit' => t('Find'),
579 '$contacts' => $contacts,
580 '$paginate' => paginate($a),