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
185 if($cmd === 'drop') {
187 require_once('include/Contact.php');
189 terminate_friendship($a->user,$a->contact,$orig_record[0]);
191 contact_remove($orig_record[0]['id']);
192 info( t('Contact has been removed.') . EOL );
193 if(x($_SESSION,'return_url'))
194 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
196 goaway($a->get_baseurl(true) . '/contacts');
197 return; // NOTREACHED
201 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
203 $contact_id = $a->data['contact']['id'];
204 $contact = $a->data['contact'];
206 $editselect = 'exact';
207 if(intval(get_pconfig(local_user(),'system','plaintext')))
208 $editselect = 'none';
210 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
211 '$baseurl' => $a->get_baseurl(true),
212 '$editselect' => $editselect,
215 require_once('include/contact_selectors.php');
217 $tpl = get_markup_template("contact_edit.tpl");
219 switch($contact['rel']) {
220 case CONTACT_IS_FRIEND:
221 $dir_icon = 'images/lrarrow.gif';
222 $relation_text = t('You are mutual friends with %s');
224 case CONTACT_IS_FOLLOWER;
225 $dir_icon = 'images/larrow.gif';
226 $relation_text = t('You are sharing with %s');
229 case CONTACT_IS_SHARING;
230 $dir_icon = 'images/rarrow.gif';
231 $relation_text = t('%s is sharing with you');
237 $relation_text = sprintf($relation_text,$contact['name']);
239 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
240 $url = "redir/{$contact['id']}";
241 $sparkle = ' class="sparkle" ';
244 $url = $contact['url'];
248 $insecure = t('Private communications are not available for this contact.');
250 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
252 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
254 if($contact['last-update'] !== '0000-00-00 00:00:00')
255 $last_update .= ' ' . (($contact['last-update'] == $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
257 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
259 $poll_enabled = (($contact['network'] !== NETWORK_DIASPORA) ? true : false);
261 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network']));
263 $common = count_common_friends(local_user(),$contact['id']);
264 $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
266 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
268 $x = count_all_friends(local_user(), $contact['id']);
269 $all_friends = (($x) ? t('View all contacts') : '');
274 'label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
275 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/block',
279 'label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
280 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/ignore',
284 'label' => t('Repair'),
285 'url' => $a->get_baseurl(true) . '/crepair/' . $contact_id,
289 $tab_tpl = get_markup_template('common_tabs.tpl');
290 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
293 $o .= replace_macros($tpl,array(
294 '$header' => t('Contact Editor'),
295 '$tab_str' => $tab_str,
296 '$submit' => t('Submit'),
297 '$lbl_vis1' => t('Profile Visibility'),
298 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
299 '$lbl_info1' => t('Contact Information / Notes'),
300 '$infedit' => t('Edit contact notes'),
301 '$common_text' => $common_text,
302 '$common_link' => $a->get_baseurl(true) . '/common/' . $contact['id'],
303 '$all_friends' => $all_friends,
304 '$relation_text' => $relation_text,
305 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
306 '$blockunblock' => t('Block/Unblock contact'),
307 '$ignorecont' => t('Ignore contact'),
308 '$lblcrepair' => t("Repair URL settings"),
309 '$lblrecent' => t('View conversations'),
310 '$lblsuggest' => $lblsuggest,
311 '$delete' => t('Delete contact'),
312 '$nettype' => $nettype,
313 '$poll_interval' => contact_poll_interval($contact['priority'],(! $poll_enabled)),
314 '$poll_enabled' => $poll_enabled,
315 '$lastupdtext' => t('Last update:'),
316 '$updpub' => t('Update public posts'),
317 '$last_update' => $last_update,
318 '$udnow' => t('Update now'),
319 '$profile_select' => contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false)),
320 '$contact_id' => $contact['id'],
321 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
322 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
323 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
324 '$info' => $contact['info'],
325 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
326 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
327 '$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')),
328 '$photo' => $contact['photo'],
329 '$name' => $contact['name'],
330 '$dir_icon' => $dir_icon,
331 '$alt_text' => $alt_text,
332 '$sparkle' => $sparkle,
337 $arr = array('contact' => $contact,'output' => $o);
339 call_hooks('contact_edit', $arr);
341 return $arr['output'];
350 $_SESSION['return_url'] = $a->query_string;
352 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
356 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
357 $sql_extra = " AND `blocked` = 1 ";
360 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
361 $sql_extra = " AND `hidden` = 1 ";
364 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
365 $sql_extra = " AND `readonly` = 1 ";
369 $sql_extra = " AND `blocked` = 0 ";
371 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
372 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
376 'label' => t('Suggestions'),
377 'url' => $a->get_baseurl(true) . '/suggest',
381 'label' => t('All Contacts'),
382 'url' => $a->get_baseurl(true) . '/contacts/all',
383 'sel' => ($all) ? 'active' : '',
386 'label' => t('Unblocked Contacts'),
387 'url' => $a->get_baseurl(true) . '/contacts',
388 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored)) ? 'active' : '',
392 'label' => t('Blocked Contacts'),
393 'url' => $a->get_baseurl(true) . '/contacts/blocked',
394 'sel' => ($blocked) ? 'active' : '',
398 'label' => t('Ignored Contacts'),
399 'url' => $a->get_baseurl(true) . '/contacts/ignored',
400 'sel' => ($ignored) ? 'active' : '',
404 'label' => t('Hidden Contacts'),
405 'url' => $a->get_baseurl(true) . '/contacts/hidden',
406 'sel' => ($hidden) ? 'active' : '',
411 $tab_tpl = get_markup_template('common_tabs.tpl');
412 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
418 $search_hdr = $search;
419 $search = dbesc($search.'*');
421 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
424 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
426 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
429 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
430 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
431 intval($_SESSION['uid']));
433 $a->set_pager_total($r[0]['total']);
434 $total = $r[0]['total'];
439 $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 ",
440 intval($_SESSION['uid']),
441 intval($a->pager['start']),
442 intval($a->pager['itemspage'])
452 case CONTACT_IS_FRIEND:
453 $dir_icon = 'images/lrarrow.gif';
454 $alt_text = t('Mutual Friendship');
456 case CONTACT_IS_FOLLOWER;
457 $dir_icon = 'images/larrow.gif';
458 $alt_text = t('is a fan of yours');
460 case CONTACT_IS_SHARING;
461 $dir_icon = 'images/rarrow.gif';
462 $alt_text = t('you are a fan of');
467 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
468 $url = "redir/{$rr['id']}";
469 $sparkle = ' class="sparkle" ';
478 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
479 'edit_hover' => t('Edit contact'),
480 'photo_menu' => contact_photo_menu($rr),
482 'alt_text' => $alt_text,
483 'dir_icon' => $dir_icon,
484 'thumb' => $rr['thumb'],
485 'name' => $rr['name'],
486 'username' => $rr['name'],
487 'sparkle' => $sparkle,
488 'itemurl' => $rr['url'],
490 'network' => network_to_name($rr['network']),
498 $tpl = get_markup_template("contacts-template.tpl");
499 $o .= replace_macros($tpl,array(
500 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
503 '$search' => $search_hdr,
504 '$desc' => t('Search your contacts'),
505 '$finding' => (strlen($search) ? t('Finding: ') . "'" . $search . "'" : ""),
506 '$submit' => t('Find'),
508 '$contacts' => $contacts,
509 '$paginate' => paginate($a),