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 = get_markup_template('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 info( 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 info( (($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 info( (($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 = get_markup_template('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 info( 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 = get_markup_template('contact_head.tpl');
219 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
221 require_once('include/contact_selectors.php');
223 $tpl = get_markup_template("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 '$lblrecent' => t('View conversations'),
278 '$delete' => t('Delete contact'),
279 '$poll_interval' => contact_poll_interval($r[0]['priority']),
280 '$lastupdtext' => t('Last updated: '),
281 '$updpub' => t('Update public posts: '),
282 '$last_update' => $last_update,
283 '$udnow' => t('Update now'),
284 '$profile_select' => contact_profile_assign($r[0]['profile-id'],(($r[0]['network'] !== 'dfrn') ? true : false)),
285 '$contact_id' => $r[0]['id'],
286 '$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
287 '$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
288 '$insecure' => (($r[0]['network'] !== NETWORK_DFRN && $r[0]['network'] !== NETWORK_MAIL && $r[0]['network'] !== NETWORK_FACEBOOK) ? $insecure : ''),
289 '$info' => $r[0]['info'],
290 '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
291 '$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),
292 '$rating' => contact_reputation($r[0]['rating']),
293 '$reason' => $r[0]['reason'],
294 '$groups' => '', // group_selector(),
295 '$photo' => $r[0]['photo'],
296 '$name' => $r[0]['name'],
297 '$dir_icon' => $dir_icon,
298 '$alt_text' => $alt_text,
299 '$sparkle' => $sparkle,
304 $arr = array('contact' => $r[0],'output' => $o);
306 call_hooks('contact_edit', $arr);
308 return $arr['output'];
313 if(($a->argc == 2) && ($a->argv[1] === 'all'))
316 $sql_extra = " AND `blocked` = 0 ";
318 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
320 $tpl = get_markup_template("contacts-top.tpl");
321 $o .= replace_macros($tpl,array(
322 '$header' => t('Contacts'),
323 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
324 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
325 '$search' => $search,
326 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
327 '$submit' => t('Find'),
334 $search = dbesc($search.'*');
335 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
337 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= REL_BUD)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
340 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
341 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
342 intval($_SESSION['uid']));
344 $a->set_pager_total($r[0]['total']);
346 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
347 intval($_SESSION['uid']),
348 intval($a->pager['start']),
349 intval($a->pager['itemspage'])
354 $tpl = get_markup_template("contact_template.tpl");
362 $dir_icon = 'images/lrarrow.gif';
363 $alt_text = t('Mutual Friendship');
366 $dir_icon = 'images/larrow.gif';
367 $alt_text = t('is a fan of yours');
370 $dir_icon = 'images/rarrow.gif';
371 $alt_text = t('you are a fan of');
376 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
377 $url = "redir/{$rr['id']}";
378 $sparkle = ' class="sparkle" ';
386 $o .= replace_macros($tpl, array(
387 '$img_hover' => t('Visit $username\'s profile'),
388 '$edit_hover' => t('Edit contact'),
390 '$alt_text' => $alt_text,
391 '$dir_icon' => $dir_icon,
392 '$thumb' => $rr['thumb'],
393 '$name' => substr($rr['name'],0,20),
394 '$username' => $rr['name'],
395 '$sparkle' => $sparkle,
400 $o .= '<div id="contact-edit-end"></div>';