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']);
48 function contacts_post(&$a) {
53 $contact_id = intval($a->argv[1]);
57 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
62 if(! count($orig_record)) {
63 notice( t('Could not access contact record.') . EOL);
64 goaway($a->get_baseurl(true) . '/contacts');
68 call_hooks('contact_edit_post', $_POST);
70 $profile_id = intval($_POST['profile-assign']);
72 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
77 notice( t('Could not locate selected profile.') . EOL);
82 $hidden = intval($_POST['hidden']);
84 $priority = intval($_POST['poll']);
85 if($priority > 5 || $priority < 0)
88 $info = fix_mce_lf(escape_tags(trim($_POST['info'])));
90 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
91 `hidden` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
100 info( t('Contact updated.') . EOL);
102 notice( t('Failed to update contact record.') . EOL);
104 $r = q("select * from contact where id = %d and uid = %d limit 1",
109 $a->data['contact'] = $r[0];
117 function contacts_content(&$a) {
121 nav_set_selected('contacts');
125 notice( t('Permission denied.') . EOL);
131 $contact_id = intval($a->argv[1]);
137 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
142 if(! count($orig_record)) {
143 notice( t('Could not access contact record.') . EOL);
144 goaway($a->get_baseurl(true) . '/contacts');
145 return; // NOTREACHED
148 if($cmd === 'update') {
150 // pull feed and consume it, which should subscribe to the hub.
151 proc_run('php',"include/poller.php","$contact_id");
152 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
156 if($cmd === 'block') {
157 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
158 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
164 //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
165 info( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
167 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
168 return; // NOTREACHED
171 if($cmd === 'ignore') {
172 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
173 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
179 info( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
181 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
182 return; // NOTREACHED
186 if($cmd === 'archive') {
187 $archived = (($orig_record[0]['archive']) ? 0 : 1);
188 $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
194 //notice( t('Contact has been ') . (($archived) ? t('archived') : t('unarchived')) . EOL );
195 info( (($archived) ? t('Contact has been archived') : t('Contact has been unarchived')) . EOL );
197 goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
198 return; // NOTREACHED
201 if($cmd === 'drop') {
203 require_once('include/Contact.php');
205 terminate_friendship($a->user,$a->contact,$orig_record[0]);
207 contact_remove($orig_record[0]['id']);
208 info( t('Contact has been removed.') . EOL );
209 if(x($_SESSION,'return_url'))
210 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
212 goaway($a->get_baseurl(true) . '/contacts');
213 return; // NOTREACHED
217 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
219 $contact_id = $a->data['contact']['id'];
220 $contact = $a->data['contact'];
222 $editselect = 'exact';
223 if(intval(get_pconfig(local_user(),'system','plaintext')))
224 $editselect = 'none';
226 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
227 '$baseurl' => $a->get_baseurl(true),
228 '$editselect' => $editselect,
231 require_once('include/contact_selectors.php');
233 $tpl = get_markup_template("contact_edit.tpl");
235 switch($contact['rel']) {
236 case CONTACT_IS_FRIEND:
237 $dir_icon = 'images/lrarrow.gif';
238 $relation_text = t('You are mutual friends with %s');
240 case CONTACT_IS_FOLLOWER;
241 $dir_icon = 'images/larrow.gif';
242 $relation_text = t('You are sharing with %s');
245 case CONTACT_IS_SHARING;
246 $dir_icon = 'images/rarrow.gif';
247 $relation_text = t('%s is sharing with you');
253 $relation_text = sprintf($relation_text,$contact['name']);
255 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
256 $url = "redir/{$contact['id']}";
257 $sparkle = ' class="sparkle" ';
260 $url = $contact['url'];
264 $insecure = t('Private communications are not available for this contact.');
266 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
268 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
270 if($contact['last-update'] !== '0000-00-00 00:00:00')
271 $last_update .= ' ' . (($contact['last-update'] == $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
273 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
275 $poll_enabled = (($contact['network'] !== NETWORK_DIASPORA) ? true : false);
277 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network']));
279 $common = count_common_friends(local_user(),$contact['id']);
280 $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
282 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
284 $x = count_all_friends(local_user(), $contact['id']);
285 $all_friends = (($x) ? t('View all contacts') : '');
290 'label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
291 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/block',
295 'label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
296 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/ignore',
301 'label' => (($contact['archive']) ? t('Unarchive') : t('Archive') ),
302 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/archive',
306 'label' => t('Repair'),
307 'url' => $a->get_baseurl(true) . '/crepair/' . $contact_id,
311 $tab_tpl = get_markup_template('common_tabs.tpl');
312 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
315 $o .= replace_macros($tpl,array(
316 '$header' => t('Contact Editor'),
317 '$tab_str' => $tab_str,
318 '$submit' => t('Submit'),
319 '$lbl_vis1' => t('Profile Visibility'),
320 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
321 '$lbl_info1' => t('Contact Information / Notes'),
322 '$infedit' => t('Edit contact notes'),
323 '$common_text' => $common_text,
324 '$common_link' => $a->get_baseurl(true) . '/common/' . $contact['id'],
325 '$all_friends' => $all_friends,
326 '$relation_text' => $relation_text,
327 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
328 '$blockunblock' => t('Block/Unblock contact'),
329 '$ignorecont' => t('Ignore contact'),
330 '$lblcrepair' => t("Repair URL settings"),
331 '$lblrecent' => t('View conversations'),
332 '$lblsuggest' => $lblsuggest,
333 '$delete' => t('Delete contact'),
334 '$nettype' => $nettype,
335 '$poll_interval' => contact_poll_interval($contact['priority'],(! $poll_enabled)),
336 '$poll_enabled' => $poll_enabled,
337 '$lastupdtext' => t('Last update:'),
338 '$updpub' => t('Update public posts'),
339 '$last_update' => $last_update,
340 '$udnow' => t('Update now'),
341 '$profile_select' => contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false)),
342 '$contact_id' => $contact['id'],
343 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
344 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
345 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
346 '$info' => $contact['info'],
347 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
348 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
349 '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
350 '$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')),
351 '$photo' => $contact['photo'],
352 '$name' => $contact['name'],
353 '$dir_icon' => $dir_icon,
354 '$alt_text' => $alt_text,
355 '$sparkle' => $sparkle,
360 $arr = array('contact' => $contact,'output' => $o);
362 call_hooks('contact_edit', $arr);
364 return $arr['output'];
373 $_SESSION['return_url'] = $a->query_string;
375 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
379 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
380 $sql_extra = " AND `blocked` = 1 ";
383 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
384 $sql_extra = " AND `hidden` = 1 ";
387 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
388 $sql_extra = " AND `readonly` = 1 ";
391 elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
392 $sql_extra = " AND `archive` = 1 ";
396 $sql_extra = " AND `blocked` = 0 ";
398 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
399 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
403 'label' => t('Suggestions'),
404 'url' => $a->get_baseurl(true) . '/suggest',
408 'label' => t('All Contacts'),
409 'url' => $a->get_baseurl(true) . '/contacts/all',
410 'sel' => ($all) ? 'active' : '',
413 'label' => t('Unblocked'),
414 'url' => $a->get_baseurl(true) . '/contacts',
415 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
419 'label' => t('Blocked'),
420 'url' => $a->get_baseurl(true) . '/contacts/blocked',
421 'sel' => ($blocked) ? 'active' : '',
425 'label' => t('Ignored'),
426 'url' => $a->get_baseurl(true) . '/contacts/ignored',
427 'sel' => ($ignored) ? 'active' : '',
431 'label' => t('Archived'),
432 'url' => $a->get_baseurl(true) . '/contacts/archived',
433 'sel' => ($archived) ? 'active' : '',
437 'label' => t('Hidden'),
438 'url' => $a->get_baseurl(true) . '/contacts/hidden',
439 'sel' => ($hidden) ? 'active' : '',
444 $tab_tpl = get_markup_template('common_tabs.tpl');
445 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
451 $search_hdr = $search;
452 $search = dbesc($search.'*');
454 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
457 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
459 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
462 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
463 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
464 intval($_SESSION['uid']));
466 $a->set_pager_total($r[0]['total']);
467 $total = $r[0]['total'];
472 $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 ",
473 intval($_SESSION['uid']),
474 intval($a->pager['start']),
475 intval($a->pager['itemspage'])
485 case CONTACT_IS_FRIEND:
486 $dir_icon = 'images/lrarrow.gif';
487 $alt_text = t('Mutual Friendship');
489 case CONTACT_IS_FOLLOWER;
490 $dir_icon = 'images/larrow.gif';
491 $alt_text = t('is a fan of yours');
493 case CONTACT_IS_SHARING;
494 $dir_icon = 'images/rarrow.gif';
495 $alt_text = t('you are a fan of');
500 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
501 $url = "redir/{$rr['id']}";
502 $sparkle = ' class="sparkle" ';
511 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
512 'edit_hover' => t('Edit contact'),
513 'photo_menu' => contact_photo_menu($rr),
515 'alt_text' => $alt_text,
516 'dir_icon' => $dir_icon,
517 'thumb' => $rr['thumb'],
518 'name' => $rr['name'],
519 'username' => $rr['name'],
520 'sparkle' => $sparkle,
521 'itemurl' => $rr['url'],
523 'network' => network_to_name($rr['network']),
531 $tpl = get_markup_template("contacts-template.tpl");
532 $o .= replace_macros($tpl,array(
533 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
536 '$search' => $search_hdr,
537 '$desc' => t('Search your contacts'),
538 '$finding' => (strlen($search) ? t('Finding: ') . "'" . $search . "'" : ""),
539 '$submit' => t('Find'),
541 '$contacts' => $contacts,
542 '$paginate' => paginate($a),