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>';
14 if(strlen(get_config('system','directory_submit_url')))
15 $a->page['aside'] .= '<div class="side-link" id="side-match-link"><a href="match" >' . t('Find People With Shared Interests') . '</a></div>';
17 $tpl = load_view_file('view/follow.tpl');
18 $a->page['aside'] .= replace_macros($tpl,array(
19 '$label' => t('Connect/Follow'),
20 '$hint' => t('Example: bob@example.com, http://example.com/barbara'),
21 '$follow' => t('Follow')
28 function contacts_post(&$a) {
33 $contact_id = intval($a->argv[1]);
37 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
42 if(! count($orig_record)) {
43 notice( t('Could not access contact record.') . EOL);
44 goaway($a->get_baseurl() . '/contacts');
48 call_hooks('contact_edit_post', $_POST);
50 $profile_id = intval($_POST['profile-assign']);
52 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
57 notice( t('Could not locate selected profile.') . EOL);
61 logger('contact_edit ' . print_r($_POST,true));
63 $priority = intval($_POST['poll']);
66 if($priority > 5 || $priority < 0)
69 $rating = intval($_POST['reputation']);
70 if($rating > 5 || $rating < 0)
73 $reason = notags(trim($_POST['reason']));
75 $info = escape_tags(trim($_POST['info']));
77 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `rating` = %d, `reason` = '%s', `info` = '%s'
78 WHERE `id` = %d AND `uid` = %d LIMIT 1",
88 notice( t('Contact updated.') . EOL);
90 notice( t('Failed to update contact record.') . EOL);
97 function contacts_content(&$a) {
101 $o .= '<script> $(document).ready(function() { $(\'#nav-contacts-link\').addClass(\'nav-selected\'); });</script>';
103 $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
106 notice( t('Permission denied.') . EOL);
112 $contact_id = intval($a->argv[1]);
118 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
123 if(! count($orig_record)) {
124 notice( t('Could not access contact record.') . EOL);
125 goaway($a->get_baseurl() . '/contacts');
126 return; // NOTREACHED
129 if($cmd === 'update') {
131 // pull feed and consume it, which should subscribe to the hub.
132 proc_run('php',"include/poller.php","$contact_id");
133 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
137 if($cmd === 'block') {
138 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
139 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
145 //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
146 notice( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
148 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
149 return; // NOTREACHED
152 if($cmd === 'ignore') {
153 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
154 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
160 notice( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
162 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
163 return; // NOTREACHED
166 if($cmd === 'drop') {
168 // create an unfollow slap
170 if($orig_record[0]['network'] === 'stat') {
171 $tpl = load_view_file('view/follow_slap.tpl');
172 $slap = replace_macros($tpl, array(
173 '$name' => $a->user['username'],
174 '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
175 '$photo' => $a->contact['photo'],
176 '$thumb' => $a->contact['thumb'],
177 '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
178 '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(),
181 '$content' => t('stopped following'),
182 '$nick' => $a->user['nickname'],
183 '$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW,
184 '$ostat_follow' => '' // '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
187 if((x($orig_record[0],'notify')) && (strlen($orig_record[0]['notify']))) {
188 require_once('include/salmon.php');
189 slapper($a->user,$orig_record[0]['notify'],$slap);
193 if($orig_record[0]['network'] === 'dfrn') {
194 require_once('include/items.php');
195 dfrn_deliver($a->user,$orig_record[0],'placeholder', 1);
199 contact_remove($contact_id);
200 notice( t('Contact has been removed.') . EOL );
201 goaway($a->get_baseurl() . '/contacts');
202 return; // NOTREACHED
206 if(($a->argc == 2) && intval($a->argv[1])) {
208 $contact_id = intval($a->argv[1]);
209 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
210 intval(local_user()),
214 notice( t('Contact not found.') . EOL);
218 $tpl = load_view_file('view/contact_head.tpl');
219 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
221 require_once('include/contact_selectors.php');
223 $tpl = load_view_file("view/contact_edit.tpl");
225 switch($r[0]['rel']) {
227 $dir_icon = 'images/lrarrow.gif';
228 $alt_text = t('Mutual Friendship');
231 $dir_icon = 'images/larrow.gif';
232 $alt_text = t('is a fan of yours');
236 $dir_icon = 'images/rarrow.gif';
237 $alt_text = t('you are a fan of');
243 if(($r[0]['network'] === 'dfrn') && ($r[0]['rel'])) {
244 $url = "redir/{$r[0]['id']}";
245 $sparkle = ' class="sparkle" ';
252 $insecure = '<div id="profile-edit-insecure"><p><img src="images/unlock_icon.gif" alt="' . t('Privacy Unavailable') . '" /> '
253 . t('Private communications are not available for this contact.') . '</p></div>';
255 $last_update = (($r[0]['last-update'] == '0000-00-00 00:00:00')
257 : datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A'));
259 if($r[0]['last-update'] !== '0000-00-00 00:00:00')
260 $last_update .= ' ' . (($r[0]['last-update'] == $r[0]['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
262 $o .= replace_macros($tpl,array(
263 '$header' => t('Contact Editor'),
264 '$submit' => t('Submit'),
265 '$lbl_vis1' => t('Profile Visibility'),
266 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $r[0]['name']),
267 '$lbl_info1' => t('Contact Information / Notes'),
268 '$lbl_rep1' => t('Online Reputation'),
269 '$lbl_rep2' => t('Occasionally your friends may wish to inquire about this person\'s online legitimacy.'),
270 '$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.'),
271 '$lbl_rep4' => t('Please take a moment to elaborate on this selection if you feel it could be helpful to others.'),
272 '$visit' => t('Visit $name\'s profile'),
273 '$blockunblock' => t('Block/Unblock contact'),
274 '$ignorecont' => t('Ignore contact'),
275 '$altcrepair' => t('Repair contact URL settings'),
276 '$lblcrepair' => t("Repair contact URL settings \x28WARNING: Advanced\x29"),
277 '$delete' => t('Delete contact'),
278 '$poll_interval' => contact_poll_interval($r[0]['priority']),
279 '$lastupdtext' => t('Last updated: '),
280 '$updpub' => t('Update public posts: '),
281 '$last_update' => $last_update,
282 '$udnow' => t('Update now'),
283 '$profile_select' => contact_profile_assign($r[0]['profile-id'],(($r[0]['network'] !== 'dfrn') ? true : false)),
284 '$contact_id' => $r[0]['id'],
285 '$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
286 '$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
287 '$insecure' => (($r[0]['network'] !== 'dfrn') ? $insecure : ''),
288 '$info' => $r[0]['info'],
289 '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
290 '$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),
291 '$rating' => contact_reputation($r[0]['rating']),
292 '$reason' => $r[0]['reason'],
293 '$groups' => '', // group_selector(),
294 '$photo' => $r[0]['photo'],
295 '$name' => $r[0]['name'],
296 '$dir_icon' => $dir_icon,
297 '$alt_text' => $alt_text,
298 '$sparkle' => $sparkle,
303 $arr = array('contact' => $r[0],'output' => $o);
305 call_hooks('contact_edit', $arr);
307 return $arr['output'];
312 if(($a->argc == 2) && ($a->argv[1] === 'all'))
315 $sql_extra = " AND `blocked` = 0 ";
317 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
319 $tpl = load_view_file("view/contacts-top.tpl");
320 $o .= replace_macros($tpl,array(
321 '$header' => t('Contacts'),
322 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
323 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
324 '$search' => $search,
325 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
326 '$submit' => t('Find'),
333 $search = dbesc($search.'*');
334 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
336 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= REL_BUD)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
339 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
340 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
341 intval($_SESSION['uid']));
343 $a->set_pager_total($r[0]['total']);
345 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
346 intval($_SESSION['uid']),
347 intval($a->pager['start']),
348 intval($a->pager['itemspage'])
353 $tpl = load_view_file("view/contact_template.tpl");
361 $dir_icon = 'images/lrarrow.gif';
362 $alt_text = t('Mutual Friendship');
365 $dir_icon = 'images/larrow.gif';
366 $alt_text = t('is a fan of yours');
369 $dir_icon = 'images/rarrow.gif';
370 $alt_text = t('you are a fan of');
375 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
376 $url = "redir/{$rr['id']}";
377 $sparkle = ' class="sparkle" ';
385 $o .= replace_macros($tpl, array(
386 '$img_hover' => t('Visit $username\'s profile'),
387 '$edit_hover' => t('Edit contact'),
389 '$alt_text' => $alt_text,
390 '$dir_icon' => $dir_icon,
391 '$thumb' => $rr['thumb'],
392 '$name' => substr($rr['name'],0,20),
393 '$username' => $rr['name'],
394 '$sparkle' => $sparkle,
399 $o .= '<div id="contact-edit-end"></div>';