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 $o .= '<div class="vcard">';
32 $o .= '<div class="fn">' . $a->data['contact']['name'] . '</div>';
33 $o .= '<div id="profile-photo-wrapper"><img class="photo" style="width: 175px; height: 175px;" src="' . $a->data['contact']['photo'] . '" alt="' . $a->data['contact']['name'] . '" /></div>';
35 $a->page['aside'] .= $o;
39 $a->page['aside'] .= follow_widget();
41 $a->page['aside'] .= group_side('contacts','group',false,0,$contact_id);
43 $a->page['aside'] .= findpeople_widget();
45 $a->page['aside'] .= networks_widget('contacts',$_GET['nets']);
46 $base = $a->get_baseurl();
48 $tpl = get_markup_template("contacts-head.tpl");
49 $a->page['htmlhead'] .= replace_macros($tpl,array(
50 '$baseurl' => $a->get_baseurl(true),
53 $tpl = get_markup_template("contacts-end.tpl");
54 $a->page['end'] .= replace_macros($tpl,array(
55 '$baseurl' => $a->get_baseurl(true),
62 function contacts_post(&$a) {
67 $contact_id = intval($a->argv[1]);
71 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
76 if(! count($orig_record)) {
77 notice( t('Could not access contact record.') . EOL);
78 goaway($a->get_baseurl(true) . '/contacts');
82 call_hooks('contact_edit_post', $_POST);
84 $profile_id = intval($_POST['profile-assign']);
86 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
91 notice( t('Could not locate selected profile.') . EOL);
96 $hidden = intval($_POST['hidden']);
98 $priority = intval($_POST['poll']);
99 if($priority > 5 || $priority < 0)
102 $info = fix_mce_lf(escape_tags(trim($_POST['info'])));
104 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
105 `hidden` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
114 info( t('Contact updated.') . EOL);
116 notice( t('Failed to update contact record.') . EOL);
118 $r = q("select * from contact where id = %d and uid = %d limit 1",
123 $a->data['contact'] = $r[0];
131 function contacts_content(&$a) {
135 nav_set_selected('contacts');
139 notice( t('Permission denied.') . EOL);
145 $contact_id = intval($a->argv[1]);
151 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
156 if(! count($orig_record)) {
157 notice( t('Could not access contact record.') . EOL);
158 goaway($a->get_baseurl(true) . '/contacts');
159 return; // NOTREACHED
162 if($cmd === 'update') {
164 // pull feed and consume it, which should subscribe to the hub.
165 proc_run('php',"include/poller.php","$contact_id");
166 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
170 if($cmd === 'block') {
171 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
172 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
178 //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
179 info( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
181 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
182 return; // NOTREACHED
185 if($cmd === 'ignore') {
186 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
187 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
193 info( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
195 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
196 return; // NOTREACHED
200 if($cmd === 'archive') {
201 $archived = (($orig_record[0]['archive']) ? 0 : 1);
202 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
208 //notice( t('Contact has been ') . (($archived) ? t('archived') : t('unarchived')) . EOL );
209 info( (($archived) ? t('Contact has been archived') : t('Contact has been unarchived')) . EOL );
211 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
212 return; // NOTREACHED
215 if($cmd === 'drop') {
217 require_once('include/Contact.php');
219 terminate_friendship($a->user,$a->contact,$orig_record[0]);
221 contact_remove($orig_record[0]['id']);
222 info( t('Contact has been removed.') . EOL );
223 if(x($_SESSION,'return_url'))
224 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
226 goaway($a->get_baseurl(true) . '/contacts');
227 return; // NOTREACHED
231 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
233 $contact_id = $a->data['contact']['id'];
234 $contact = $a->data['contact'];
236 $editselect = 'exact';
237 if(intval(get_pconfig(local_user(),'system','plaintext')))
238 $editselect = 'none';
240 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
241 '$baseurl' => $a->get_baseurl(true),
242 '$editselect' => $editselect,
244 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
245 '$baseurl' => $a->get_baseurl(true),
246 '$editselect' => $editselect,
249 require_once('include/contact_selectors.php');
251 $tpl = get_markup_template("contact_edit.tpl");
253 switch($contact['rel']) {
254 case CONTACT_IS_FRIEND:
255 $dir_icon = 'images/lrarrow.gif';
256 $relation_text = t('You are mutual friends with %s');
258 case CONTACT_IS_FOLLOWER;
259 $dir_icon = 'images/larrow.gif';
260 $relation_text = t('You are sharing with %s');
263 case CONTACT_IS_SHARING;
264 $dir_icon = 'images/rarrow.gif';
265 $relation_text = t('%s is sharing with you');
271 $relation_text = sprintf($relation_text,$contact['name']);
273 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
274 $url = "redir/{$contact['id']}";
275 $sparkle = ' class="sparkle" ';
278 $url = $contact['url'];
282 $insecure = t('Private communications are not available for this contact.');
284 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
286 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
288 if($contact['last-update'] !== '0000-00-00 00:00:00')
289 $last_update .= ' ' . (($contact['last-update'] == $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
291 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
293 $poll_enabled = (($contact['network'] !== NETWORK_DIASPORA) ? true : false);
295 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network']));
297 $common = count_common_friends(local_user(),$contact['id']);
298 $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
300 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
302 $x = count_all_friends(local_user(), $contact['id']);
303 $all_friends = (($x) ? t('View all contacts') : '');
308 'label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
309 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/block',
311 'title' => t('Toggle Blocked status'),
314 'label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
315 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/ignore',
317 'title' => t('Toggle Ignored status'),
321 'label' => (($contact['archive']) ? t('Unarchive') : t('Archive') ),
322 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/archive',
324 'title' => t('Toggle Archive status'),
327 'label' => t('Repair'),
328 'url' => $a->get_baseurl(true) . '/crepair/' . $contact_id,
330 'title' => t('Advanced Contact Settings'),
333 $tab_tpl = get_markup_template('common_tabs.tpl');
334 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
336 $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!') : '');
338 $o .= replace_macros($tpl,array(
339 '$header' => t('Contact Editor'),
340 '$tab_str' => $tab_str,
341 '$submit' => t('Submit'),
342 '$lbl_vis1' => t('Profile Visibility'),
343 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
344 '$lbl_info1' => t('Contact Information / Notes'),
345 '$infedit' => t('Edit contact notes'),
346 '$common_text' => $common_text,
347 '$common_link' => $a->get_baseurl(true) . '/common/loc/' . local_user() . '/' . $contact['id'],
348 '$all_friends' => $all_friends,
349 '$relation_text' => $relation_text,
350 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
351 '$blockunblock' => t('Block/Unblock contact'),
352 '$ignorecont' => t('Ignore contact'),
353 '$lblcrepair' => t("Repair URL settings"),
354 '$lblrecent' => t('View conversations'),
355 '$lblsuggest' => $lblsuggest,
356 '$delete' => t('Delete contact'),
357 '$nettype' => $nettype,
358 '$poll_interval' => contact_poll_interval($contact['priority'],(! $poll_enabled)),
359 '$poll_enabled' => $poll_enabled,
360 '$lastupdtext' => t('Last update:'),
361 '$lost_contact' => $lost_contact,
362 '$updpub' => t('Update public posts'),
363 '$last_update' => $last_update,
364 '$udnow' => t('Update now'),
365 '$profile_select' => contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false)),
366 '$contact_id' => $contact['id'],
367 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
368 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
369 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
370 '$info' => $contact['info'],
371 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
372 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
373 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
374 '$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')),
375 '$photo' => $contact['photo'],
376 '$name' => $contact['name'],
377 '$dir_icon' => $dir_icon,
378 '$alt_text' => $alt_text,
379 '$sparkle' => $sparkle,
384 $arr = array('contact' => $contact,'output' => $o);
386 call_hooks('contact_edit', $arr);
388 return $arr['output'];
397 $_SESSION['return_url'] = $a->query_string;
399 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
403 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
404 $sql_extra = " AND `blocked` = 1 ";
407 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
408 $sql_extra = " AND `hidden` = 1 ";
411 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
412 $sql_extra = " AND `readonly` = 1 ";
415 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
416 $sql_extra = " AND `archive` = 1 ";
420 $sql_extra = " AND `blocked` = 0 ";
422 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
423 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
427 'label' => t('Suggestions'),
428 'url' => $a->get_baseurl(true) . '/suggest',
430 'title' => t('Suggest potential friends'),
433 'label' => t('All Contacts'),
434 'url' => $a->get_baseurl(true) . '/contacts/all',
435 'sel' => ($all) ? 'active' : '',
436 'title' => t('Show all contacts'),
439 'label' => t('Unblocked'),
440 'url' => $a->get_baseurl(true) . '/contacts',
441 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
442 'title' => t('Only show unblocked contacts'),
446 'label' => t('Blocked'),
447 'url' => $a->get_baseurl(true) . '/contacts/blocked',
448 'sel' => ($blocked) ? 'active' : '',
449 'title' => t('Only show blocked contacts'),
453 'label' => t('Ignored'),
454 'url' => $a->get_baseurl(true) . '/contacts/ignored',
455 'sel' => ($ignored) ? 'active' : '',
456 'title' => t('Only show ignored contacts'),
460 'label' => t('Archived'),
461 'url' => $a->get_baseurl(true) . '/contacts/archived',
462 'sel' => ($archived) ? 'active' : '',
463 'title' => t('Only show archived contacts'),
467 'label' => t('Hidden'),
468 'url' => $a->get_baseurl(true) . '/contacts/hidden',
469 'sel' => ($hidden) ? 'active' : '',
470 'title' => t('Only show hidden contacts'),
475 $tab_tpl = get_markup_template('common_tabs.tpl');
476 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
482 $search_hdr = $search;
483 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
486 $sql_extra .= (($searching) ? " AND `name` REGEXP '$search_txt' " : "");
489 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
491 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
494 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
495 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
496 intval($_SESSION['uid']));
498 $a->set_pager_total($r[0]['total']);
499 $total = $r[0]['total'];
503 $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 ",
504 intval($_SESSION['uid']),
505 intval($a->pager['start']),
506 intval($a->pager['itemspage'])
516 case CONTACT_IS_FRIEND:
517 $dir_icon = 'images/lrarrow.gif';
518 $alt_text = t('Mutual Friendship');
520 case CONTACT_IS_FOLLOWER;
521 $dir_icon = 'images/larrow.gif';
522 $alt_text = t('is a fan of yours');
524 case CONTACT_IS_SHARING;
525 $dir_icon = 'images/rarrow.gif';
526 $alt_text = t('you are a fan of');
531 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
532 $url = "redir/{$rr['id']}";
533 $sparkle = ' class="sparkle" ';
542 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
543 'edit_hover' => t('Edit contact'),
544 'photo_menu' => contact_photo_menu($rr),
546 'alt_text' => $alt_text,
547 'dir_icon' => $dir_icon,
548 'thumb' => $rr['thumb'],
549 'name' => $rr['name'],
550 'username' => $rr['name'],
551 'sparkle' => $sparkle,
552 'itemurl' => $rr['url'],
554 'network' => network_to_name($rr['network']),
562 $tpl = get_markup_template("contacts-template.tpl");
563 $o .= replace_macros($tpl,array(
564 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
567 '$search' => $search_hdr,
568 '$desc' => t('Search your contacts'),
569 '$finding' => (($searching) ? t('Finding: ') . "'" . $search . "'" : ""),
570 '$submit' => t('Find'),
572 '$contacts' => $contacts,
573 '$paginate' => paginate($a),