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 // create an unfollow slap
189 if($orig_record[0]['network'] === NETWORK_OSTATUS) {
190 $tpl = get_markup_template('follow_slap.tpl');
191 $slap = replace_macros($tpl, array(
192 '$name' => $a->user['username'],
193 '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
194 '$photo' => $a->contact['photo'],
195 '$thumb' => $a->contact['thumb'],
196 '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
197 '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(),
200 '$content' => t('stopped following'),
201 '$nick' => $a->user['nickname'],
202 '$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW,
203 '$ostat_follow' => '' // '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
206 if((x($orig_record[0],'notify')) && (strlen($orig_record[0]['notify']))) {
207 require_once('include/salmon.php');
208 slapper($a->user,$orig_record[0]['notify'],$slap);
211 elseif($orig_record[0]['network'] === NETWORK_DIASPORA) {
212 require_once('include/diaspora.php');
213 diaspora_unshare($a->user,$orig_record[0]);
215 elseif($orig_record[0]['network'] === NETWORK_DFRN) {
216 require_once('include/items.php');
217 dfrn_deliver($a->user,$orig_record[0],'placeholder', 1);
220 contact_remove($orig_record[0]['id']);
221 info( t('Contact has been removed.') . EOL );
222 if(x($_SESSION,'return_url'))
223 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
225 goaway($a->get_baseurl(true) . '/contacts');
226 return; // NOTREACHED
230 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
232 $contact_id = $a->data['contact']['id'];
233 $contact = $a->data['contact'];
235 $editselect = 'exact';
236 if(intval(get_pconfig(local_user(),'system','plaintext')))
237 $editselect = 'none';
239 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
240 '$baseurl' => $a->get_baseurl(true),
241 '$editselect' => $editselect,
244 require_once('include/contact_selectors.php');
246 $tpl = get_markup_template("contact_edit.tpl");
248 switch($contact['rel']) {
249 case CONTACT_IS_FRIEND:
250 $dir_icon = 'images/lrarrow.gif';
251 $relation_text = t('You are mutual friends with %s');
253 case CONTACT_IS_FOLLOWER;
254 $dir_icon = 'images/larrow.gif';
255 $relation_text = t('You are sharing with %s');
258 case CONTACT_IS_SHARING;
259 $dir_icon = 'images/rarrow.gif';
260 $relation_text = t('%s is sharing with you');
266 $relation_text = sprintf($relation_text,$contact['name']);
268 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
269 $url = "redir/{$contact['id']}";
270 $sparkle = ' class="sparkle" ';
273 $url = $contact['url'];
277 $insecure = t('Private communications are not available for this contact.');
279 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
281 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
283 if($contact['last-update'] !== '0000-00-00 00:00:00')
284 $last_update .= ' ' . (($contact['last-update'] == $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
286 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
288 $poll_enabled = (($contact['network'] !== NETWORK_DIASPORA) ? true : false);
290 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network']));
292 $common = count_common_friends(local_user(),$contact['id']);
293 $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
295 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
297 $x = count_all_friends(local_user(), $contact['id']);
298 $all_friends = (($x) ? t('View all contacts') : '');
303 'label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
304 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/block',
308 'label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
309 'url' => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/ignore',
313 'label' => t('Repair'),
314 'url' => $a->get_baseurl(true) . '/crepair/' . $contact_id,
318 $tab_tpl = get_markup_template('common_tabs.tpl');
319 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
322 $o .= replace_macros($tpl,array(
323 '$header' => t('Contact Editor'),
324 '$tab_str' => $tab_str,
325 '$submit' => t('Submit'),
326 '$lbl_vis1' => t('Profile Visibility'),
327 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
328 '$lbl_info1' => t('Contact Information / Notes'),
329 '$infedit' => t('Edit contact notes'),
330 '$common_text' => $common_text,
331 '$common_link' => $a->get_baseurl(true) . '/common/' . $contact['id'],
332 '$all_friends' => $all_friends,
333 '$relation_text' => $relation_text,
334 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
335 '$blockunblock' => t('Block/Unblock contact'),
336 '$ignorecont' => t('Ignore contact'),
337 '$lblcrepair' => t("Repair URL settings"),
338 '$lblrecent' => t('View conversations'),
339 '$lblsuggest' => $lblsuggest,
340 '$delete' => t('Delete contact'),
341 '$nettype' => $nettype,
342 '$poll_interval' => contact_poll_interval($contact['priority'],(! $poll_enabled)),
343 '$poll_enabled' => $poll_enabled,
344 '$lastupdtext' => t('Last update:'),
345 '$updpub' => t('Update public posts'),
346 '$last_update' => $last_update,
347 '$udnow' => t('Update now'),
348 '$profile_select' => contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false)),
349 '$contact_id' => $contact['id'],
350 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
351 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
352 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
353 '$info' => $contact['info'],
354 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
355 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
356 '$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')),
357 '$photo' => $contact['photo'],
358 '$name' => $contact['name'],
359 '$dir_icon' => $dir_icon,
360 '$alt_text' => $alt_text,
361 '$sparkle' => $sparkle,
366 $arr = array('contact' => $contact,'output' => $o);
368 call_hooks('contact_edit', $arr);
370 return $arr['output'];
379 $_SESSION['return_url'] = $a->query_string;
381 if(($a->argc == 2) && ($a->argv[1] === 'all')) {
385 elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
386 $sql_extra = " AND `blocked` = 1 ";
389 elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
390 $sql_extra = " AND `hidden` = 1 ";
393 elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
394 $sql_extra = " AND `readonly` = 1 ";
398 $sql_extra = " AND `blocked` = 0 ";
400 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
401 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
405 'label' => t('Suggestions'),
406 'url' => $a->get_baseurl(true) . '/suggest',
410 'label' => t('All Contacts'),
411 'url' => $a->get_baseurl(true) . '/contacts/all',
412 'sel' => ($all) ? 'active' : '',
415 'label' => t('Unblocked Contacts'),
416 'url' => $a->get_baseurl(true) . '/contacts',
417 'sel' => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored)) ? 'active' : '',
421 'label' => t('Blocked Contacts'),
422 'url' => $a->get_baseurl(true) . '/contacts/blocked',
423 'sel' => ($blocked) ? 'active' : '',
427 'label' => t('Ignored Contacts'),
428 'url' => $a->get_baseurl(true) . '/contacts/ignored',
429 'sel' => ($ignored) ? 'active' : '',
433 'label' => t('Hidden Contacts'),
434 'url' => $a->get_baseurl(true) . '/contacts/hidden',
435 'sel' => ($hidden) ? 'active' : '',
440 $tab_tpl = get_markup_template('common_tabs.tpl');
441 $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
447 $search_hdr = $search;
448 $search = dbesc($search.'*');
450 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
453 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
455 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
458 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
459 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
460 intval($_SESSION['uid']));
462 $a->set_pager_total($r[0]['total']);
463 $total = $r[0]['total'];
468 $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 ",
469 intval($_SESSION['uid']),
470 intval($a->pager['start']),
471 intval($a->pager['itemspage'])
481 case CONTACT_IS_FRIEND:
482 $dir_icon = 'images/lrarrow.gif';
483 $alt_text = t('Mutual Friendship');
485 case CONTACT_IS_FOLLOWER;
486 $dir_icon = 'images/larrow.gif';
487 $alt_text = t('is a fan of yours');
489 case CONTACT_IS_SHARING;
490 $dir_icon = 'images/rarrow.gif';
491 $alt_text = t('you are a fan of');
496 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
497 $url = "redir/{$rr['id']}";
498 $sparkle = ' class="sparkle" ';
507 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
508 'edit_hover' => t('Edit contact'),
509 'photo_menu' => contact_photo_menu($rr),
511 'alt_text' => $alt_text,
512 'dir_icon' => $dir_icon,
513 'thumb' => $rr['thumb'],
514 'name' => $rr['name'],
515 'username' => $rr['name'],
516 'sparkle' => $sparkle,
517 'itemurl' => $rr['url'],
519 'network' => network_to_name($rr['network']),
527 $tpl = get_markup_template("contacts-template.tpl");
528 $o .= replace_macros($tpl,array(
529 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
532 '$search' => $search_hdr,
533 '$desc' => t('Search your contacts'),
534 '$finding' => (strlen($search) ? t('Finding: ') . "'" . $search . "'" : ""),
535 '$submit' => t('Find'),
537 '$contacts' => $contacts,
538 '$paginate' => paginate($a),