3 require_once('include/Contact.php');
5 function contacts_init(&$a) {
9 require_once('include/group.php');
10 if(! x($a->page,'aside'))
11 $a->page['aside'] = '';
12 $a->page['aside'] .= group_side();
14 $inv = '<div class="side-link" id="side-invite-link" ><a href="invite" >' . t("Invite Friends") . '</a></div>';
16 if(get_config('system','invitation_only')) {
17 $x = get_pconfig(local_user(),'system','invites_remaining');
18 if($x || is_site_admin()) {
19 $a->page['aside'] .= '<div class="side-link" id="side-invite-remain">'
20 . sprintf( tt('%d invitation available','%d invitations available',$x), $x)
24 elseif($a->config['register_policy'] != REGISTER_CLOSED)
25 $a->page['aside'] .= $inv;
28 $a->page['aside'] .= '<div class="side-link" id="side-match-link"><a href="match" >'
29 . t('Find People With Shared Interests') . '</a></div>';
31 $tpl = get_markup_template('follow.tpl');
32 $a->page['aside'] .= replace_macros($tpl,array(
33 '$label' => t('Connect/Follow'),
34 '$hint' => t('Example: bob@example.com, http://example.com/barbara'),
35 '$follow' => t('Follow')
42 function contacts_post(&$a) {
47 $contact_id = intval($a->argv[1]);
51 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
56 if(! count($orig_record)) {
57 notice( t('Could not access contact record.') . EOL);
58 goaway($a->get_baseurl() . '/contacts');
62 call_hooks('contact_edit_post', $_POST);
64 $profile_id = intval($_POST['profile-assign']);
66 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
71 notice( t('Could not locate selected profile.') . EOL);
77 $priority = intval($_POST['poll']);
80 if($priority > 5 || $priority < 0)
83 $rating = intval($_POST['reputation']);
84 if($rating > 5 || $rating < 0)
87 $reason = notags(trim($_POST['reason']));
89 $info = escape_tags(trim($_POST['info']));
91 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `rating` = %d, `reason` = '%s', `info` = '%s'
92 WHERE `id` = %d AND `uid` = %d LIMIT 1",
102 info( t('Contact updated.') . EOL);
104 notice( t('Failed to update contact record.') . EOL);
111 function contacts_content(&$a) {
115 $o .= '<script> $(document).ready(function() { $(\'#nav-contacts-link\').addClass(\'nav-selected\'); });</script>';
117 $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
120 notice( t('Permission denied.') . EOL);
126 $contact_id = intval($a->argv[1]);
132 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
137 if(! count($orig_record)) {
138 notice( t('Could not access contact record.') . EOL);
139 goaway($a->get_baseurl() . '/contacts');
140 return; // NOTREACHED
143 if($cmd === 'update') {
145 // pull feed and consume it, which should subscribe to the hub.
146 proc_run('php',"include/poller.php","$contact_id");
147 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
151 if($cmd === 'block') {
152 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
153 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
159 //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
160 info( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
162 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
163 return; // NOTREACHED
166 if($cmd === 'ignore') {
167 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
168 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
174 info( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
176 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
177 return; // NOTREACHED
180 if($cmd === 'drop') {
182 // create an unfollow slap
184 if($orig_record[0]['network'] === 'stat') {
185 $tpl = get_markup_template('follow_slap.tpl');
186 $slap = replace_macros($tpl, array(
187 '$name' => $a->user['username'],
188 '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
189 '$photo' => $a->contact['photo'],
190 '$thumb' => $a->contact['thumb'],
191 '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
192 '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(),
195 '$content' => t('stopped following'),
196 '$nick' => $a->user['nickname'],
197 '$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW,
198 '$ostat_follow' => '' // '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
201 if((x($orig_record[0],'notify')) && (strlen($orig_record[0]['notify']))) {
202 require_once('include/salmon.php');
203 slapper($a->user,$orig_record[0]['notify'],$slap);
207 if($orig_record[0]['network'] === 'dfrn') {
208 require_once('include/items.php');
209 dfrn_deliver($a->user,$orig_record[0],'placeholder', 1);
213 contact_remove($contact_id);
214 info( t('Contact has been removed.') . EOL );
215 goaway($a->get_baseurl() . '/contacts');
216 return; // NOTREACHED
220 if(($a->argc == 2) && intval($a->argv[1])) {
222 $contact_id = intval($a->argv[1]);
223 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
224 intval(local_user()),
228 notice( t('Contact not found.') . EOL);
232 $tpl = get_markup_template('contact_head.tpl');
233 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
235 require_once('include/contact_selectors.php');
237 $tpl = get_markup_template("contact_edit.tpl");
239 switch($r[0]['rel']) {
241 $dir_icon = 'images/lrarrow.gif';
242 $alt_text = t('Mutual Friendship');
245 $dir_icon = 'images/larrow.gif';
246 $alt_text = t('is a fan of yours');
250 $dir_icon = 'images/rarrow.gif';
251 $alt_text = t('you are a fan of');
257 if(($r[0]['network'] === 'dfrn') && ($r[0]['rel'])) {
258 $url = "redir/{$r[0]['id']}";
259 $sparkle = ' class="sparkle" ';
267 $member_of = member_of($r[0]['id']);
268 if(is_array($member_of) && count($member_of)) {
269 $grps = t('Member of: ') . EOL . '<ul>';
270 foreach($member_of as $member)
271 $grps .= '<li><a href="group/' . $member['id'] . '" title="' . t('Edit') . '" ><img src="images/spencil.gif" alt="' . t('Edit') . '" /></a> <a href="network/' . $member['id'] . '">' . $member['name'] . '</a></li>';
275 $insecure = '<div id="profile-edit-insecure"><p><img src="images/unlock_icon.gif" alt="' . t('Privacy Unavailable') . '" /> '
276 . t('Private communications are not available for this contact.') . '</p></div>';
278 $last_update = (($r[0]['last-update'] == '0000-00-00 00:00:00')
280 : datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A'));
282 if($r[0]['last-update'] !== '0000-00-00 00:00:00')
283 $last_update .= ' ' . (($r[0]['last-update'] == $r[0]['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
285 $lblsuggest = (($r[0]['network'] === NETWORK_DFRN)
286 ? '<div id="contact-suggest-wrapper"><a href="fsuggest/' . $r[0]['id'] . '" id="contact-suggest">' . t('Suggest friends') . '</a></div>' : '');
289 $o .= replace_macros($tpl,array(
290 '$header' => t('Contact Editor'),
291 '$submit' => t('Submit'),
292 '$lbl_vis1' => t('Profile Visibility'),
293 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $r[0]['name']),
294 '$lbl_info1' => t('Contact Information / Notes'),
295 '$lbl_rep1' => t('Online Reputation'),
296 '$lbl_rep2' => t('Occasionally your friends may wish to inquire about this person\'s online legitimacy.'),
297 '$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.'),
298 '$lbl_rep4' => t('Please take a moment to elaborate on this selection if you feel it could be helpful to others.'),
299 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$r[0]['name'],$r[0]['url']),
300 '$blockunblock' => t('Block/Unblock contact'),
301 '$ignorecont' => t('Ignore contact'),
302 '$altcrepair' => t('Repair contact URL settings'),
303 '$lblcrepair' => t("Repair contact URL settings \x28WARNING: Advanced\x29"),
304 '$lblrecent' => t('View conversations'),
305 '$lblsuggest' => $lblsuggest,
307 '$delete' => t('Delete contact'),
308 '$poll_interval' => contact_poll_interval($r[0]['priority']),
309 '$lastupdtext' => t('Last updated: '),
310 '$updpub' => t('Update public posts: '),
311 '$last_update' => $last_update,
312 '$udnow' => t('Update now'),
313 '$profile_select' => contact_profile_assign($r[0]['profile-id'],(($r[0]['network'] !== 'dfrn') ? true : false)),
314 '$contact_id' => $r[0]['id'],
315 '$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
316 '$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
317 '$insecure' => (($r[0]['network'] !== NETWORK_DFRN && $r[0]['network'] !== NETWORK_MAIL && $r[0]['network'] !== NETWORK_FACEBOOK) ? $insecure : ''),
318 '$info' => $r[0]['info'],
319 '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
320 '$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),
321 '$rating' => contact_reputation($r[0]['rating']),
322 '$reason' => $r[0]['reason'],
323 '$groups' => '', // group_selector(),
324 '$photo' => $r[0]['photo'],
325 '$name' => $r[0]['name'],
326 '$dir_icon' => $dir_icon,
327 '$alt_text' => $alt_text,
328 '$sparkle' => $sparkle,
333 $arr = array('contact' => $r[0],'output' => $o);
335 call_hooks('contact_edit', $arr);
337 return $arr['output'];
342 if(($a->argc == 2) && ($a->argv[1] === 'all'))
345 $sql_extra = " AND `blocked` = 0 ";
347 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
349 $tpl = get_markup_template("contacts-top.tpl");
350 $o .= replace_macros($tpl,array(
351 '$header' => t('Contacts'),
352 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
353 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
354 '$search' => $search,
355 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
356 '$submit' => t('Find'),
363 $search = dbesc($search.'*');
364 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
366 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= REL_BUD)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
369 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
370 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
371 intval($_SESSION['uid']));
373 $a->set_pager_total($r[0]['total']);
375 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
376 intval($_SESSION['uid']),
377 intval($a->pager['start']),
378 intval($a->pager['itemspage'])
383 $tpl = get_markup_template("contact_template.tpl");
391 $dir_icon = 'images/lrarrow.gif';
392 $alt_text = t('Mutual Friendship');
395 $dir_icon = 'images/larrow.gif';
396 $alt_text = t('is a fan of yours');
399 $dir_icon = 'images/rarrow.gif';
400 $alt_text = t('you are a fan of');
405 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
406 $url = "redir/{$rr['id']}";
407 $sparkle = ' class="sparkle" ';
415 $o .= replace_macros($tpl, array(
416 '$img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
417 '$edit_hover' => t('Edit contact'),
419 '$alt_text' => $alt_text,
420 '$dir_icon' => $dir_icon,
421 '$thumb' => $rr['thumb'],
422 '$name' => substr($rr['name'],0,20),
423 '$username' => $rr['name'],
424 '$sparkle' => $sparkle,
429 $o .= '<div id="contact-edit-end"></div>';