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']);
90 if($priority > 5 || $priority < 0)
93 $info = escape_tags(trim($_POST['info']));
95 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s'
96 WHERE `id` = %d AND `uid` = %d LIMIT 1",
104 info( t('Contact updated.') . EOL);
106 notice( t('Failed to update contact record.') . EOL);
113 function contacts_content(&$a) {
117 $o .= '<script> $(document).ready(function() { $(\'#nav-contacts-link\').addClass(\'nav-selected\'); });</script>';
119 $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
122 notice( t('Permission denied.') . EOL);
128 $contact_id = intval($a->argv[1]);
134 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
139 if(! count($orig_record)) {
140 notice( t('Could not access contact record.') . EOL);
141 goaway($a->get_baseurl() . '/contacts');
142 return; // NOTREACHED
145 if($cmd === 'update') {
147 // pull feed and consume it, which should subscribe to the hub.
148 proc_run('php',"include/poller.php","$contact_id");
149 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
153 if($cmd === 'block') {
154 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
155 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
161 //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
162 info( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
164 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
165 return; // NOTREACHED
168 if($cmd === 'ignore') {
169 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
170 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
176 info( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
178 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
179 return; // NOTREACHED
182 if($cmd === 'drop') {
184 // create an unfollow slap
186 if($orig_record[0]['network'] === NETWORK_OSTATUS) {
187 $tpl = get_markup_template('follow_slap.tpl');
188 $slap = replace_macros($tpl, array(
189 '$name' => $a->user['username'],
190 '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
191 '$photo' => $a->contact['photo'],
192 '$thumb' => $a->contact['thumb'],
193 '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
194 '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(),
197 '$content' => t('stopped following'),
198 '$nick' => $a->user['nickname'],
199 '$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW,
200 '$ostat_follow' => '' // '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
203 if((x($orig_record[0],'notify')) && (strlen($orig_record[0]['notify']))) {
204 require_once('include/salmon.php');
205 slapper($a->user,$orig_record[0]['notify'],$slap);
208 elseif($orig_record[0]['network'] === NETWORK_DIASPORA) {
209 require_once('include/diaspora.php');
210 diaspora_unshare($a->user,$orig_record[0]);
212 elseif($orig_record[0]['network'] === NETWORK_DFRN) {
213 require_once('include/items.php');
214 dfrn_deliver($a->user,$orig_record[0],'placeholder', 1);
217 contact_remove($orig_record[0]['id']);
218 info( t('Contact has been removed.') . EOL );
219 goaway($a->get_baseurl() . '/contacts');
220 return; // NOTREACHED
224 if(($a->argc == 2) && intval($a->argv[1])) {
226 $contact_id = intval($a->argv[1]);
227 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
228 intval(local_user()),
232 notice( t('Contact not found.') . EOL);
236 $tpl = get_markup_template('contact_head.tpl');
237 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
239 require_once('include/contact_selectors.php');
241 $tpl = get_markup_template("contact_edit.tpl");
243 switch($r[0]['rel']) {
244 case CONTACT_IS_FRIEND:
245 $dir_icon = 'images/lrarrow.gif';
246 $alt_text = t('Mutual Friendship');
248 case CONTACT_IS_FOLLOWER;
249 $dir_icon = 'images/larrow.gif';
250 $alt_text = t('is a fan of yours');
253 case CONTACT_IS_SHARING;
254 $dir_icon = 'images/rarrow.gif';
255 $alt_text = t('you are a fan of');
261 if(($r[0]['network'] === 'dfrn') && ($r[0]['rel'])) {
262 $url = "redir/{$r[0]['id']}";
263 $sparkle = ' class="sparkle" ';
270 $insecure = '<div id="profile-edit-insecure"><p><img src="images/unlock_icon.gif" alt="' . t('Privacy Unavailable') . '" /> '
271 . t('Private communications are not available for this contact.') . '</p></div>';
273 $last_update = (($r[0]['last-update'] == '0000-00-00 00:00:00')
275 : datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A'));
277 if($r[0]['last-update'] !== '0000-00-00 00:00:00')
278 $last_update .= ' ' . (($r[0]['last-update'] == $r[0]['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
280 $lblsuggest = (($r[0]['network'] === NETWORK_DFRN)
281 ? '<div id="contact-suggest-wrapper"><a href="fsuggest/' . $r[0]['id'] . '" id="contact-suggest">' . t('Suggest friends') . '</a></div>' : '');
283 $poll_enabled = (($r[0]['network'] !== NETWORK_DIASPORA) ? true : false);
285 $nettype = '<div id="contact-edit-nettype">' . sprintf( t('Network type: %s'),network_to_name($r[0]['network'])) . '</div>';
287 $o .= replace_macros($tpl,array(
288 '$header' => t('Contact Editor'),
289 '$submit' => t('Submit'),
290 '$lbl_vis1' => t('Profile Visibility'),
291 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $r[0]['name']),
292 '$lbl_info1' => t('Contact Information / Notes'),
293 '$lbl_rep1' => t('Online Reputation'),
294 '$lbl_rep2' => t('Occasionally your friends may wish to inquire about this person\'s online legitimacy.'),
295 '$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.'),
296 '$lbl_rep4' => t('Please take a moment to elaborate on this selection if you feel it could be helpful to others.'),
297 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$r[0]['name'],$r[0]['url']),
298 '$blockunblock' => t('Block/Unblock contact'),
299 '$ignorecont' => t('Ignore contact'),
300 '$altcrepair' => t('Repair contact URL settings'),
301 '$lblcrepair' => t("Repair contact URL settings \x28WARNING: Advanced\x29"),
302 '$lblrecent' => t('View conversations'),
303 '$lblsuggest' => $lblsuggest,
304 '$delete' => t('Delete contact'),
305 '$nettype' => $nettype,
306 '$poll_interval' => contact_poll_interval($r[0]['priority'],(! $poll_enabled)),
307 '$poll_enabled' => $poll_enabled,
308 '$lastupdtext' => t('Last updated: '),
309 '$updpub' => t('Update public posts: '),
310 '$last_update' => $last_update,
311 '$udnow' => t('Update now'),
312 '$profile_select' => contact_profile_assign($r[0]['profile-id'],(($r[0]['network'] !== 'dfrn') ? true : false)),
313 '$contact_id' => $r[0]['id'],
314 '$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
315 '$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
316 '$insecure' => (($r[0]['network'] !== NETWORK_DFRN && $r[0]['network'] !== NETWORK_MAIL && $r[0]['network'] !== NETWORK_FACEBOOK && $r[0]['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
317 '$info' => $r[0]['info'],
318 '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
319 '$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),
320 '$photo' => $r[0]['photo'],
321 '$name' => $r[0]['name'],
322 '$dir_icon' => $dir_icon,
323 '$alt_text' => $alt_text,
324 '$sparkle' => $sparkle,
329 $arr = array('contact' => $r[0],'output' => $o);
331 call_hooks('contact_edit', $arr);
333 return $arr['output'];
338 if(($a->argc == 2) && ($a->argv[1] === 'all'))
341 $sql_extra = " AND `blocked` = 0 ";
343 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
345 $tpl = get_markup_template("contacts-top.tpl");
346 $o .= replace_macros($tpl,array(
347 '$header' => t('Contacts'),
348 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
349 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
350 '$search' => $search,
351 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
352 '$submit' => t('Find'),
359 $search = dbesc($search.'*');
360 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
362 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
365 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
366 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
367 intval($_SESSION['uid']));
369 $a->set_pager_total($r[0]['total']);
371 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
372 intval($_SESSION['uid']),
373 intval($a->pager['start']),
374 intval($a->pager['itemspage'])
379 $tpl = get_markup_template("contact_template.tpl");
386 case CONTACT_IS_FRIEND:
387 $dir_icon = 'images/lrarrow.gif';
388 $alt_text = t('Mutual Friendship');
390 case CONTACT_IS_FOLLOWER;
391 $dir_icon = 'images/larrow.gif';
392 $alt_text = t('is a fan of yours');
394 case CONTACT_IS_SHARING;
395 $dir_icon = 'images/rarrow.gif';
396 $alt_text = t('you are a fan of');
401 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
402 $url = "redir/{$rr['id']}";
403 $sparkle = ' class="sparkle" ';
411 $o .= replace_macros($tpl, array(
412 '$img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
413 '$edit_hover' => t('Edit contact'),
414 '$contact_photo_menu' => contact_photo_menu($rr),
416 '$alt_text' => $alt_text,
417 '$dir_icon' => $dir_icon,
418 '$thumb' => $rr['thumb'],
419 '$name' => $rr['name'],
420 '$username' => $rr['name'],
421 '$sparkle' => $sparkle,
426 $o .= '<div id="contact-edit-end"></div>';