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() . '/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 = 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() . '/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() . '/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() . '/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() . '/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() . '/' . $_SESSION['return_url']);
225 goaway($a->get_baseurl() . '/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 $tpl = get_markup_template('contact_head.tpl');
236 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
238 require_once('include/contact_selectors.php');
240 $tpl = get_markup_template("contact_edit.tpl");
242 switch($contact['rel']) {
243 case CONTACT_IS_FRIEND:
244 $dir_icon = 'images/lrarrow.gif';
245 $relation_text = t('You are mutual friends with %s');
247 case CONTACT_IS_FOLLOWER;
248 $dir_icon = 'images/larrow.gif';
249 $relation_text = t('You are sharing with %s');
252 case CONTACT_IS_SHARING;
253 $dir_icon = 'images/rarrow.gif';
254 $relation_text = t('%s is sharing with you');
260 $relation_text = sprintf($relation_text,$contact['name']);
262 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
263 $url = "redir/{$contact['id']}";
264 $sparkle = ' class="sparkle" ';
267 $url = $contact['url'];
271 $insecure = t('Private communications are not available for this contact.');
273 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
275 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
277 if($contact['last-update'] !== '0000-00-00 00:00:00')
278 $last_update .= ' ' . (($contact['last-update'] == $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
280 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
282 $poll_enabled = (($contact['network'] !== NETWORK_DIASPORA) ? true : false);
284 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network']));
286 $common = count_common_friends(local_user(),$contact['id']);
287 $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
289 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
291 $x = count_all_friends(local_user(), $contact['id']);
292 $all_friends = (($x) ? t('View all contacts') : '');
297 'label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
298 'url' => $a->get_baseurl() . '/contacts/' . $contact_id . '/block',
302 'label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
303 'url' => $a->get_baseurl() . '/contacts/' . $contact_id . '/ignore',
307 'label' => t('Repair'),
308 'url' => $a->get_baseurl() . '/crepair/' . $contact_id,
312 $tab_tpl = get_markup_template('common_tabs.tpl');
313 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
316 $o .= replace_macros($tpl,array(
317 '$header' => t('Contact Editor'),
318 '$tab_str' => $tab_str,
319 '$submit' => t('Submit'),
320 '$lbl_vis1' => t('Profile Visibility'),
321 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
322 '$lbl_info1' => t('Contact Information / Notes'),
323 '$infedit' => t('Edit contact notes'),
324 '$common_text' => $common_text,
325 '$common_link' => $a->get_baseurl() . '/common/' . $contact['id'],
326 '$all_friends' => $all_friends,
327 '$relation_text' => $relation_text,
328 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
329 '$blockunblock' => t('Block/Unblock contact'),
330 '$ignorecont' => t('Ignore contact'),
331 '$lblcrepair' => t("Repair URL settings"),
332 '$lblrecent' => t('View conversations'),
333 '$lblsuggest' => $lblsuggest,
334 '$delete' => t('Delete contact'),
335 '$nettype' => $nettype,
336 '$poll_interval' => contact_poll_interval($contact['priority'],(! $poll_enabled)),
337 '$poll_enabled' => $poll_enabled,
338 '$lastupdtext' => t('Last update:'),
339 '$updpub' => t('Update public posts'),
340 '$last_update' => $last_update,
341 '$udnow' => t('Update now'),
342 '$profile_select' => contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false)),
343 '$contact_id' => $contact['id'],
344 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
345 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
346 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
347 '$info' => $contact['info'],
348 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
349 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
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'];
370 $_SESSION['return_url'] = $a->query_string;
372 if(($a->argc == 2) && ($a->argv[1] === 'all'))
375 if(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
376 $sql_extra = " AND `blocked` = 1 ";
380 $sql_extra = " AND `blocked` = 0 ";
382 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
383 $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
385 $tpl = get_markup_template("contacts-top.tpl");
386 $o .= replace_macros($tpl,array(
387 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
388 '$hide_url' => (($blocked) ? 'contacts' : 'contacts/blocked'),
389 '$hide_text' => (($blocked) ? t('Show Unblocked Contacts') : t('Show Blocked Contacts')),
390 '$all_url' => 'contacts/all',
391 '$all_text' => t('Show All Contacts'),
392 '$search' => $search,
393 '$desc' => t('Search your contacts'),
394 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
395 '$submit' => t('Find'),
402 $search = dbesc($search.'*');
403 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
406 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
408 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
411 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
412 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
413 intval($_SESSION['uid']));
415 $a->set_pager_total($r[0]['total']);
417 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
418 intval($_SESSION['uid']),
419 intval($a->pager['start']),
420 intval($a->pager['itemspage'])
425 $tpl = get_markup_template("contact_template.tpl");
432 case CONTACT_IS_FRIEND:
433 $dir_icon = 'images/lrarrow.gif';
434 $alt_text = t('Mutual Friendship');
436 case CONTACT_IS_FOLLOWER;
437 $dir_icon = 'images/larrow.gif';
438 $alt_text = t('is a fan of yours');
440 case CONTACT_IS_SHARING;
441 $dir_icon = 'images/rarrow.gif';
442 $alt_text = t('you are a fan of');
447 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
448 $url = "redir/{$rr['id']}";
449 $sparkle = ' class="sparkle" ';
457 $o .= replace_macros($tpl, array(
458 '$img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
459 '$edit_hover' => t('Edit contact'),
460 '$contact_photo_menu' => contact_photo_menu($rr),
462 '$alt_text' => $alt_text,
463 '$dir_icon' => $dir_icon,
464 '$thumb' => $rr['thumb'],
465 '$name' => $rr['name'],
466 '$username' => $rr['name'],
467 '$sparkle' => $sparkle,
472 $o .= '<div id="contact-edit-end"></div>';