3 require_once('include/Contact.php');
5 function contacts_init(&$a) {
6 require_once('include/group.php');
7 if(! x($a->page,'aside'))
8 $a->page['aside'] = '';
9 $a->page['aside'] .= group_side();
11 if($a->config['register_policy'] != REGISTER_CLOSED)
12 $a->page['aside'] .= '<div class="side-link" id="side-invite-link" ><a href="invite" >' . t("Invite Friends") . '</a></div>';
15 $a->page['aside'] .= '<div class="side-link" id="side-match-link"><a href="match" >'
16 . t('Find People With Shared Interests') . '</a></div>';
18 $tpl = get_markup_template('follow.tpl');
19 $a->page['aside'] .= replace_macros($tpl,array(
20 '$label' => t('Connect/Follow'),
21 '$hint' => t('Example: bob@example.com, http://example.com/barbara'),
22 '$follow' => t('Follow')
29 function contacts_post(&$a) {
34 $contact_id = intval($a->argv[1]);
38 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
43 if(! count($orig_record)) {
44 notice( t('Could not access contact record.') . EOL);
45 goaway($a->get_baseurl() . '/contacts');
49 call_hooks('contact_edit_post', $_POST);
51 $profile_id = intval($_POST['profile-assign']);
53 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
58 notice( t('Could not locate selected profile.') . EOL);
64 $priority = intval($_POST['poll']);
67 if($priority > 5 || $priority < 0)
70 $rating = intval($_POST['reputation']);
71 if($rating > 5 || $rating < 0)
74 $reason = notags(trim($_POST['reason']));
76 $info = escape_tags(trim($_POST['info']));
78 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `rating` = %d, `reason` = '%s', `info` = '%s'
79 WHERE `id` = %d AND `uid` = %d LIMIT 1",
89 info( t('Contact updated.') . EOL);
91 notice( t('Failed to update contact record.') . EOL);
98 function contacts_content(&$a) {
102 $o .= '<script> $(document).ready(function() { $(\'#nav-contacts-link\').addClass(\'nav-selected\'); });</script>';
104 $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
107 notice( t('Permission denied.') . EOL);
113 $contact_id = intval($a->argv[1]);
119 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
124 if(! count($orig_record)) {
125 notice( t('Could not access contact record.') . EOL);
126 goaway($a->get_baseurl() . '/contacts');
127 return; // NOTREACHED
130 if($cmd === 'update') {
132 // pull feed and consume it, which should subscribe to the hub.
133 proc_run('php',"include/poller.php","$contact_id");
134 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
138 if($cmd === 'block') {
139 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
140 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
146 //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
147 info( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
149 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
150 return; // NOTREACHED
153 if($cmd === 'ignore') {
154 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
155 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
161 info( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
163 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
164 return; // NOTREACHED
167 if($cmd === 'drop') {
169 // create an unfollow slap
171 if($orig_record[0]['network'] === 'stat') {
172 $tpl = get_markup_template('follow_slap.tpl');
173 $slap = replace_macros($tpl, array(
174 '$name' => $a->user['username'],
175 '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
176 '$photo' => $a->contact['photo'],
177 '$thumb' => $a->contact['thumb'],
178 '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
179 '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(),
182 '$content' => t('stopped following'),
183 '$nick' => $a->user['nickname'],
184 '$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW,
185 '$ostat_follow' => '' // '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
188 if((x($orig_record[0],'notify')) && (strlen($orig_record[0]['notify']))) {
189 require_once('include/salmon.php');
190 slapper($a->user,$orig_record[0]['notify'],$slap);
194 if($orig_record[0]['network'] === 'dfrn') {
195 require_once('include/items.php');
196 dfrn_deliver($a->user,$orig_record[0],'placeholder', 1);
200 contact_remove($contact_id);
201 info( t('Contact has been removed.') . EOL );
202 goaway($a->get_baseurl() . '/contacts');
203 return; // NOTREACHED
207 if(($a->argc == 2) && intval($a->argv[1])) {
209 $contact_id = intval($a->argv[1]);
210 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
211 intval(local_user()),
215 notice( t('Contact not found.') . EOL);
219 $tpl = get_markup_template('contact_head.tpl');
220 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
222 require_once('include/contact_selectors.php');
224 $tpl = get_markup_template("contact_edit.tpl");
226 switch($r[0]['rel']) {
228 $dir_icon = 'images/lrarrow.gif';
229 $alt_text = t('Mutual Friendship');
232 $dir_icon = 'images/larrow.gif';
233 $alt_text = t('is a fan of yours');
237 $dir_icon = 'images/rarrow.gif';
238 $alt_text = t('you are a fan of');
244 if(($r[0]['network'] === 'dfrn') && ($r[0]['rel'])) {
245 $url = "redir/{$r[0]['id']}";
246 $sparkle = ' class="sparkle" ';
254 $member_of = member_of($r[0]['id']);
255 if(is_array($member_of) && count($member_of)) {
256 $grps = t('Member of: ') . EOL . '<ul>';
257 foreach($member_of as $member)
258 $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>';
262 $insecure = '<div id="profile-edit-insecure"><p><img src="images/unlock_icon.gif" alt="' . t('Privacy Unavailable') . '" /> '
263 . t('Private communications are not available for this contact.') . '</p></div>';
265 $last_update = (($r[0]['last-update'] == '0000-00-00 00:00:00')
267 : datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A'));
269 if($r[0]['last-update'] !== '0000-00-00 00:00:00')
270 $last_update .= ' ' . (($r[0]['last-update'] == $r[0]['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
272 $lblsuggest = (($r[0]['network'] === NETWORK_DFRN)
273 ? '<div id="contact-suggest-wrapper"><a href="fsuggest/' . $r[0]['id'] . '" id="contact-suggest">' . t('Suggest friends') . '</a></div>' : '');
276 $o .= replace_macros($tpl,array(
277 '$header' => t('Contact Editor'),
278 '$submit' => t('Submit'),
279 '$lbl_vis1' => t('Profile Visibility'),
280 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $r[0]['name']),
281 '$lbl_info1' => t('Contact Information / Notes'),
282 '$lbl_rep1' => t('Online Reputation'),
283 '$lbl_rep2' => t('Occasionally your friends may wish to inquire about this person\'s online legitimacy.'),
284 '$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.'),
285 '$lbl_rep4' => t('Please take a moment to elaborate on this selection if you feel it could be helpful to others.'),
286 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$r[0]['name'],$r[0]['url']),
287 '$blockunblock' => t('Block/Unblock contact'),
288 '$ignorecont' => t('Ignore contact'),
289 '$altcrepair' => t('Repair contact URL settings'),
290 '$lblcrepair' => t("Repair contact URL settings \x28WARNING: Advanced\x29"),
291 '$lblrecent' => t('View conversations'),
292 '$lblsuggest' => $lblsuggest,
294 '$delete' => t('Delete contact'),
295 '$poll_interval' => contact_poll_interval($r[0]['priority']),
296 '$lastupdtext' => t('Last updated: '),
297 '$updpub' => t('Update public posts: '),
298 '$last_update' => $last_update,
299 '$udnow' => t('Update now'),
300 '$profile_select' => contact_profile_assign($r[0]['profile-id'],(($r[0]['network'] !== 'dfrn') ? true : false)),
301 '$contact_id' => $r[0]['id'],
302 '$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
303 '$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
304 '$insecure' => (($r[0]['network'] !== NETWORK_DFRN && $r[0]['network'] !== NETWORK_MAIL && $r[0]['network'] !== NETWORK_FACEBOOK) ? $insecure : ''),
305 '$info' => $r[0]['info'],
306 '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
307 '$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),
308 '$rating' => contact_reputation($r[0]['rating']),
309 '$reason' => $r[0]['reason'],
310 '$groups' => '', // group_selector(),
311 '$photo' => $r[0]['photo'],
312 '$name' => $r[0]['name'],
313 '$dir_icon' => $dir_icon,
314 '$alt_text' => $alt_text,
315 '$sparkle' => $sparkle,
320 $arr = array('contact' => $r[0],'output' => $o);
322 call_hooks('contact_edit', $arr);
324 return $arr['output'];
329 if(($a->argc == 2) && ($a->argv[1] === 'all'))
332 $sql_extra = " AND `blocked` = 0 ";
334 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
336 $tpl = get_markup_template("contacts-top.tpl");
337 $o .= replace_macros($tpl,array(
338 '$header' => t('Contacts'),
339 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
340 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
341 '$search' => $search,
342 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
343 '$submit' => t('Find'),
350 $search = dbesc($search.'*');
351 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
353 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= REL_BUD)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
356 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
357 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
358 intval($_SESSION['uid']));
360 $a->set_pager_total($r[0]['total']);
362 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
363 intval($_SESSION['uid']),
364 intval($a->pager['start']),
365 intval($a->pager['itemspage'])
370 $tpl = get_markup_template("contact_template.tpl");
378 $dir_icon = 'images/lrarrow.gif';
379 $alt_text = t('Mutual Friendship');
382 $dir_icon = 'images/larrow.gif';
383 $alt_text = t('is a fan of yours');
386 $dir_icon = 'images/rarrow.gif';
387 $alt_text = t('you are a fan of');
392 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
393 $url = "redir/{$rr['id']}";
394 $sparkle = ' class="sparkle" ';
402 $o .= replace_macros($tpl, array(
403 '$img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
404 '$edit_hover' => t('Edit contact'),
406 '$alt_text' => $alt_text,
407 '$dir_icon' => $dir_icon,
408 '$thumb' => $rr['thumb'],
409 '$name' => substr($rr['name'],0,20),
410 '$username' => $rr['name'],
411 '$sparkle' => $sparkle,
416 $o .= '<div id="contact-edit-end"></div>';