3 require_once('include/Contact.php');
5 function contacts_init(&$a) {
10 if(($a->argc == 2) && intval($a->argv[1])) {
11 $contact_id = intval($a->argv[1]);
12 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
21 require_once('include/group.php');
22 if(! x($a->page,'aside'))
23 $a->page['aside'] = '';
24 $a->page['aside'] .= group_side('contacts','group',false,0,$contact_id);
26 $inv = '<div class="side-link" id="side-invite-link" ><a href="invite" >' . t("Invite Friends") . '</a></div>';
28 if(get_config('system','invitation_only')) {
29 $x = get_pconfig(local_user(),'system','invites_remaining');
30 if($x || is_site_admin()) {
31 $a->page['aside'] .= '<div class="side-link" id="side-invite-remain">'
32 . sprintf( tt('%d invitation available','%d invitations available',$x), $x)
36 elseif($a->config['register_policy'] != REGISTER_CLOSED)
37 $a->page['aside'] .= $inv;
40 $a->page['aside'] .= '<div class="side-link" id="side-match-link"><a href="match" >'
41 . t('Find People With Shared Interests') . '</a></div>';
43 $tpl = get_markup_template('follow.tpl');
44 $a->page['aside'] .= replace_macros($tpl,array(
45 '$label' => t('Connect/Follow'),
46 '$hint' => t('Example: bob@example.com, http://example.com/barbara'),
47 '$follow' => t('Follow')
54 function contacts_post(&$a) {
59 $contact_id = intval($a->argv[1]);
63 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
68 if(! count($orig_record)) {
69 notice( t('Could not access contact record.') . EOL);
70 goaway($a->get_baseurl() . '/contacts');
74 call_hooks('contact_edit_post', $_POST);
76 $profile_id = intval($_POST['profile-assign']);
78 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
83 notice( t('Could not locate selected profile.') . EOL);
89 $priority = intval($_POST['poll']);
92 if($priority > 5 || $priority < 0)
95 $rating = intval($_POST['reputation']);
96 if($rating > 5 || $rating < 0)
99 $reason = notags(trim($_POST['reason']));
101 $info = escape_tags(trim($_POST['info']));
103 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `rating` = %d, `reason` = '%s', `info` = '%s'
104 WHERE `id` = %d AND `uid` = %d LIMIT 1",
114 info( t('Contact updated.') . EOL);
116 notice( t('Failed to update contact record.') . EOL);
123 function contacts_content(&$a) {
127 nav_set_selected('contacts');
129 $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
132 notice( t('Permission denied.') . EOL);
138 $contact_id = intval($a->argv[1]);
144 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
149 if(! count($orig_record)) {
150 notice( t('Could not access contact record.') . EOL);
151 goaway($a->get_baseurl() . '/contacts');
152 return; // NOTREACHED
155 if($cmd === 'update') {
157 // pull feed and consume it, which should subscribe to the hub.
158 proc_run('php',"include/poller.php","$contact_id");
159 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
163 if($cmd === 'block') {
164 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
165 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
171 //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
172 info( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
174 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
175 return; // NOTREACHED
178 if($cmd === 'ignore') {
179 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
180 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
186 info( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
188 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
189 return; // NOTREACHED
192 if($cmd === 'drop') {
194 // create an unfollow slap
196 if($orig_record[0]['network'] === NETWORK_OSTATUS) {
197 $tpl = get_markup_template('follow_slap.tpl');
198 $slap = replace_macros($tpl, array(
199 '$name' => $a->user['username'],
200 '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
201 '$photo' => $a->contact['photo'],
202 '$thumb' => $a->contact['thumb'],
203 '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
204 '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(),
207 '$content' => t('stopped following'),
208 '$nick' => $a->user['nickname'],
209 '$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW,
210 '$ostat_follow' => '' // '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
213 if((x($orig_record[0],'notify')) && (strlen($orig_record[0]['notify']))) {
214 require_once('include/salmon.php');
215 slapper($a->user,$orig_record[0]['notify'],$slap);
218 elseif($orig_record[0]['network'] === NETWORK_DIASPORA) {
219 require_once('include/diaspora.php');
220 diaspora_unshare($a->user,$orig_record[0]);
222 elseif($orig_record[0]['network'] === NETWORK_DFRN) {
223 require_once('include/items.php');
224 dfrn_deliver($a->user,$orig_record[0],'placeholder', 1);
227 contact_remove($orig_record[0]['id']);
228 info( t('Contact has been removed.') . EOL );
229 goaway($a->get_baseurl() . '/contacts');
230 return; // NOTREACHED
234 if(($a->argc == 2) && intval($a->argv[1])) {
236 $contact_id = intval($a->argv[1]);
237 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
238 intval(local_user()),
242 notice( t('Contact not found.') . EOL);
246 $tpl = get_markup_template('contact_head.tpl');
247 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
249 require_once('include/contact_selectors.php');
251 $tpl = get_markup_template("contact_edit.tpl");
253 switch($r[0]['rel']) {
254 case CONTACT_IS_FRIEND:
255 $dir_icon = 'images/lrarrow.gif';
256 $alt_text = t('Mutual Friendship');
258 case CONTACT_IS_FOLLOWER;
259 $dir_icon = 'images/larrow.gif';
260 $alt_text = t('is a fan of yours');
263 case CONTACT_IS_SHARING;
264 $dir_icon = 'images/rarrow.gif';
265 $alt_text = t('you are a fan of');
271 if(($r[0]['network'] === 'dfrn') && ($r[0]['rel'])) {
272 $url = "redir/{$r[0]['id']}";
273 $sparkle = ' class="sparkle" ';
282 $insecure = '<div id="profile-edit-insecure"><p><img src="images/unlock_icon.gif" alt="' . t('Privacy Unavailable') . '" /> '
283 . t('Private communications are not available for this contact.') . '</p></div>';
285 $last_update = (($r[0]['last-update'] == '0000-00-00 00:00:00')
287 : datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A'));
289 if($r[0]['last-update'] !== '0000-00-00 00:00:00')
290 $last_update .= ' ' . (($r[0]['last-update'] == $r[0]['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
292 $lblsuggest = (($r[0]['network'] === NETWORK_DFRN)
293 ? '<div id="contact-suggest-wrapper"><a href="fsuggest/' . $r[0]['id'] . '" id="contact-suggest">' . t('Suggest friends') . '</a></div>' : '');
295 $poll_enabled = (($r[0]['network'] !== NETWORK_DIASPORA) ? true : false);
297 $nettype = '<div id="contact-edit-nettype">' . sprintf( t('Network type: %s'),network_to_name($r[0]['network'])) . '</div>';
299 $o .= replace_macros($tpl,array(
300 '$header' => t('Contact Editor'),
301 '$submit' => t('Submit'),
302 '$lbl_vis1' => t('Profile Visibility'),
303 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $r[0]['name']),
304 '$lbl_info1' => t('Contact Information / Notes'),
305 '$lbl_rep1' => t('Online Reputation'),
306 '$lbl_rep2' => t('Occasionally your friends may wish to inquire about this person\'s online legitimacy.'),
307 '$lbl_rep3' => t('You may help them choose whether or not to interact with this person by providing a <em>reputation</em> to guide them.'),
308 '$lbl_rep4' => t('Please take a moment to elaborate on this selection if you feel it could be helpful to others.'),
309 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$r[0]['name'],$r[0]['url']),
310 '$blockunblock' => t('Block/Unblock contact'),
311 '$ignorecont' => t('Ignore contact'),
312 '$altcrepair' => t('Repair contact URL settings'),
313 '$lblcrepair' => t("Repair contact URL settings \x28WARNING: Advanced\x29"),
314 '$lblrecent' => t('View conversations'),
315 '$lblsuggest' => $lblsuggest,
317 '$delete' => t('Delete contact'),
318 '$nettype' => $nettype,
319 '$poll_interval' => contact_poll_interval($r[0]['priority'],(! $poll_enabled)),
320 '$poll_enabled' => $poll_enabled,
321 '$lastupdtext' => t('Last updated: '),
322 '$updpub' => t('Update public posts: '),
323 '$last_update' => $last_update,
324 '$udnow' => t('Update now'),
325 '$profile_select' => contact_profile_assign($r[0]['profile-id'],(($r[0]['network'] !== 'dfrn') ? true : false)),
326 '$contact_id' => $r[0]['id'],
327 '$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
328 '$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
329 '$insecure' => (($r[0]['network'] !== NETWORK_DFRN && $r[0]['network'] !== NETWORK_MAIL && $r[0]['network'] !== NETWORK_FACEBOOK && $r[0]['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
330 '$info' => $r[0]['info'],
331 '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
332 '$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),
333 '$rating' => contact_reputation($r[0]['rating']),
334 '$reason' => $r[0]['reason'],
335 '$groups' => '', // group_selector(),
336 '$photo' => $r[0]['photo'],
337 '$name' => $r[0]['name'],
338 '$dir_icon' => $dir_icon,
339 '$alt_text' => $alt_text,
340 '$sparkle' => $sparkle,
345 $arr = array('contact' => $r[0],'output' => $o);
347 call_hooks('contact_edit', $arr);
349 return $arr['output'];
354 if(($a->argc == 2) && ($a->argv[1] === 'all'))
357 $sql_extra = " AND `blocked` = 0 ";
359 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
361 $tpl = get_markup_template("contacts-top.tpl");
362 $o .= replace_macros($tpl,array(
363 '$header' => t('Contacts'),
364 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
365 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
366 '$search' => $search,
367 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
368 '$submit' => t('Find'),
375 $search = dbesc($search.'*');
376 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
378 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
381 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
382 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
383 intval($_SESSION['uid']));
385 $a->set_pager_total($r[0]['total']);
387 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
388 intval($_SESSION['uid']),
389 intval($a->pager['start']),
390 intval($a->pager['itemspage'])
395 $tpl = get_markup_template("contact_template.tpl");
402 case CONTACT_IS_FRIEND:
403 $dir_icon = 'images/lrarrow.gif';
404 $alt_text = t('Mutual Friendship');
406 case CONTACT_IS_FOLLOWER;
407 $dir_icon = 'images/larrow.gif';
408 $alt_text = t('is a fan of yours');
410 case CONTACT_IS_SHARING;
411 $dir_icon = 'images/rarrow.gif';
412 $alt_text = t('you are a fan of');
417 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
418 $url = "redir/{$rr['id']}";
419 $sparkle = ' class="sparkle" ';
427 $o .= replace_macros($tpl, array(
428 '$img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
429 '$edit_hover' => t('Edit contact'),
430 '$contact_photo_menu' => contact_photo_menu($rr),
432 '$alt_text' => $alt_text,
433 '$dir_icon' => $dir_icon,
434 '$thumb' => $rr['thumb'],
435 '$name' => $rr['name'],
436 '$username' => $rr['name'],
437 '$sparkle' => $sparkle,
442 $o .= '<div id="contact-edit-end"></div>';