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 $a->page['htmlhead'] .= '<script src="' . $a->get_baseurl(true) . '/library/jquery_ac/friendica.complete.js" ></script>';
49 $a->page['htmlhead'] .= <<< EOT
51 <script>$(document).ready(function() {
53 a = $("#contacts-search").autocomplete({
54 serviceUrl: '$base/acl',
58 a.setOptions({ params: { type: 'a' }});
68 function contacts_post(&$a) {
73 $contact_id = intval($a->argv[1]);
77 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
82 if(! count($orig_record)) {
83 notice( t('Could not access contact record.') . EOL);
84 goaway($a->get_baseurl(true) . '/contacts');
88 call_hooks('contact_edit_post', $_POST);
90 $profile_id = intval($_POST['profile-assign']);
92 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
97 notice( t('Could not locate selected profile.') . EOL);
102 $hidden = intval($_POST['hidden']);
104 $priority = intval($_POST['poll']);
105 if($priority > 5 || $priority < 0)
108 $info = fix_mce_lf(escape_tags(trim($_POST['info'])));
110 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
111 `hidden` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
120 info( t('Contact updated.') . EOL);
122 notice( t('Failed to update contact record.') . EOL);
124 $r = q("select * from contact where id = %d and uid = %d limit 1",
129 $a->data['contact'] = $r[0];
137 function contacts_content(&$a) {
141 nav_set_selected('contacts');
145 notice( t('Permission denied.') . EOL);
151 $contact_id = intval($a->argv[1]);
157 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
162 if(! count($orig_record)) {
163 notice( t('Could not access contact record.') . EOL);
164 goaway($a->get_baseurl(true) . '/contacts');
165 return; // NOTREACHED
168 if($cmd === 'update') {
170 // pull feed and consume it, which should subscribe to the hub.
171 proc_run('php',"include/poller.php","$contact_id");
172 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
176 if($cmd === 'block') {
177 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
178 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
184 //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
185 info( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
187 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
188 return; // NOTREACHED
191 if($cmd === 'ignore') {
192 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
193 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
199 info( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
201 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
202 return; // NOTREACHED
206 if($cmd === 'archive') {
207 $archived = (($orig_record[0]['archive']) ? 0 : 1);
208 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
214 //notice( t('Contact has been ') . (($archived) ? t('archived') : t('unarchived')) . EOL );
215 info( (($archived) ? t('Contact has been archived') : t('Contact has been unarchived')) . EOL );
217 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
218 return; // NOTREACHED
221 if($cmd === 'drop') {
223 require_once('include/Contact.php');
225 terminate_friendship($a->user,$a->contact,$orig_record[0]);
227 contact_remove($orig_record[0]['id']);
228 info( t('Contact has been removed.') . EOL );
229 if(x($_SESSION,'return_url'))
230 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
232 goaway($a->get_baseurl(true) . '/contacts');
233 return; // NOTREACHED
237 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
239 $contact_id = $a->data['contact']['id'];
240 $contact = $a->data['contact'];
242 $editselect = 'exact';
243 if(intval(get_pconfig(local_user(),'system','plaintext')))
244 $editselect = 'none';
246 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
247 '$baseurl' => $a->get_baseurl(true),
248 '$editselect' => $editselect,
251 require_once('include/contact_selectors.php');
253 $tpl = get_markup_template("contact_edit.tpl");
255 switch($contact['rel']) {
256 case CONTACT_IS_FRIEND:
257 $dir_icon = 'images/lrarrow.gif';
258 $relation_text = t('You are mutual friends with %s');
260 case CONTACT_IS_FOLLOWER;
261 $dir_icon = 'images/larrow.gif';
262 $relation_text = t('You are sharing with %s');
265 case CONTACT_IS_SHARING;
266 $dir_icon = 'images/rarrow.gif';
267 $relation_text = t('%s is sharing with you');
273 $relation_text = sprintf($relation_text,$contact['name']);
275 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
276 $url = "redir/{$contact['id']}";
277 $sparkle = ' class="sparkle" ';
280 $url = $contact['url'];
284 $insecure = t('Private communications are not available for this contact.');
286 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
288 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
290 if($contact['last-update'] !== '0000-00-00 00:00:00')
291 $last_update .= ' ' . (($contact['last-update'] == $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
293 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
295 $poll_enabled = (($contact['network'] !== NETWORK_DIASPORA) ? true : false);
297 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network']));
299 $common = count_common_friends(local_user(),$contact['id']);
300 $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
302 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
304 $x = count_all_friends(local_user(), $contact['id']);
305 $all_friends = (($x) ? t('View all contacts') : '');
310 'label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
311 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/block',
313 'title' => t('Toggle Blocked status'),
316 'label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
317 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/ignore',
319 'title' => t('Toggle Ignored status'),
323 'label' => (($contact['archive']) ? t('Unarchive') : t('Archive') ),
324 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/archive',
326 'title' => t('Toggle Archive status'),
329 'label' => t('Repair'),
330 'url' => $a->get_baseurl(true) . '/crepair/' . $contact_id,
332 'title' => t('Advanced Contact Settings'),
335 $tab_tpl = get_markup_template('common_tabs.tpl');
336 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
338 $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!') : '');
340 $o .= replace_macros($tpl,array(
341 '$header' => t('Contact Editor'),
342 '$tab_str' => $tab_str,
343 '$submit' => t('Submit'),
344 '$lbl_vis1' => t('Profile Visibility'),
345 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
346 '$lbl_info1' => t('Contact Information / Notes'),
347 '$infedit' => t('Edit contact notes'),
348 '$common_text' => $common_text,
349 '$common_link' => $a->get_baseurl(true) . '/common/loc/' . local_user() . '/' . $contact['id'],
350 '$all_friends' => $all_friends,
351 '$relation_text' => $relation_text,
352 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
353 '$blockunblock' => t('Block/Unblock contact'),
354 '$ignorecont' => t('Ignore contact'),
355 '$lblcrepair' => t("Repair URL settings"),
356 '$lblrecent' => t('View conversations'),
357 '$lblsuggest' => $lblsuggest,
358 '$delete' => t('Delete contact'),
359 '$nettype' => $nettype,
360 '$poll_interval' => contact_poll_interval($contact['priority'],(! $poll_enabled)),
361 '$poll_enabled' => $poll_enabled,
362 '$lastupdtext' => t('Last update:'),
363 '$lost_contact' => $lost_contact,
364 '$updpub' => t('Update public posts'),
365 '$last_update' => $last_update,
366 '$udnow' => t('Update now'),
367 '$profile_select' => contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false)),
368 '$contact_id' => $contact['id'],
369 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
370 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
371 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
372 '$info' => $contact['info'],
373 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
374 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
375 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
376 '$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')),
377 '$photo' => $contact['photo'],
378 '$name' => $contact['name'],
379 '$dir_icon' => $dir_icon,
380 '$alt_text' => $alt_text,
381 '$sparkle' => $sparkle,
386 $arr = array('contact' => $contact,'output' => $o);
388 call_hooks('contact_edit', $arr);
390 return $arr['output'];
399 $_SESSION['return_url'] = $a->query_string;
401 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
405 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
406 $sql_extra = " AND `blocked` = 1 ";
409 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
410 $sql_extra = " AND `hidden` = 1 ";
413 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
414 $sql_extra = " AND `readonly` = 1 ";
417 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
418 $sql_extra = " AND `archive` = 1 ";
422 $sql_extra = " AND `blocked` = 0 ";
424 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
425 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
429 'label' => t('Suggestions'),
430 'url' => $a->get_baseurl(true) . '/suggest',
432 'title' => t('Suggest potential friends'),
435 'label' => t('All Contacts'),
436 'url' => $a->get_baseurl(true) . '/contacts/all',
437 'sel' => ($all) ? 'active' : '',
438 'title' => t('Show all contacts'),
441 'label' => t('Unblocked'),
442 'url' => $a->get_baseurl(true) . '/contacts',
443 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
444 'title' => t('Only show unblocked contacts'),
448 'label' => t('Blocked'),
449 'url' => $a->get_baseurl(true) . '/contacts/blocked',
450 'sel' => ($blocked) ? 'active' : '',
451 'title' => t('Only show blocked contacts'),
455 'label' => t('Ignored'),
456 'url' => $a->get_baseurl(true) . '/contacts/ignored',
457 'sel' => ($ignored) ? 'active' : '',
458 'title' => t('Only show ignored contacts'),
462 'label' => t('Archived'),
463 'url' => $a->get_baseurl(true) . '/contacts/archived',
464 'sel' => ($archived) ? 'active' : '',
465 'title' => t('Only show archived contacts'),
469 'label' => t('Hidden'),
470 'url' => $a->get_baseurl(true) . '/contacts/hidden',
471 'sel' => ($hidden) ? 'active' : '',
472 'title' => t('Only show hidden contacts'),
477 $tab_tpl = get_markup_template('common_tabs.tpl');
478 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
484 $search_hdr = $search;
485 $search = dbesc($search.'*');
487 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
490 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
492 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
495 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
496 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
497 intval($_SESSION['uid']));
499 $a->set_pager_total($r[0]['total']);
500 $total = $r[0]['total'];
505 $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 ",
506 intval($_SESSION['uid']),
507 intval($a->pager['start']),
508 intval($a->pager['itemspage'])
518 case CONTACT_IS_FRIEND:
519 $dir_icon = 'images/lrarrow.gif';
520 $alt_text = t('Mutual Friendship');
522 case CONTACT_IS_FOLLOWER;
523 $dir_icon = 'images/larrow.gif';
524 $alt_text = t('is a fan of yours');
526 case CONTACT_IS_SHARING;
527 $dir_icon = 'images/rarrow.gif';
528 $alt_text = t('you are a fan of');
533 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
534 $url = "redir/{$rr['id']}";
535 $sparkle = ' class="sparkle" ';
544 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
545 'edit_hover' => t('Edit contact'),
546 'photo_menu' => contact_photo_menu($rr),
548 'alt_text' => $alt_text,
549 'dir_icon' => $dir_icon,
550 'thumb' => $rr['thumb'],
551 'name' => $rr['name'],
552 'username' => $rr['name'],
553 'sparkle' => $sparkle,
554 'itemurl' => $rr['url'],
556 'network' => network_to_name($rr['network']),
564 $tpl = get_markup_template("contacts-template.tpl");
565 $o .= replace_macros($tpl,array(
566 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
569 '$search' => $search_hdr,
570 '$desc' => t('Search your contacts'),
571 '$finding' => (strlen($search) ? t('Finding: ') . "'" . $search . "'" : ""),
572 '$submit' => t('Find'),
574 '$contacts' => $contacts,
575 '$paginate' => paginate($a),