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'] = '';
25 $a->page['aside'] .= replace_macros(get_markup_template('follow.tpl'),array(
26 '$connect' => t('Add New Contact'),
27 '$desc' => t('Enter address or web location'),
28 '$hint' => t('Example: bob@example.com, http://example.com/barbara'),
29 '$follow' => t('Connect')
34 $a->page['aside'] .= group_side('contacts','group',false,0,$contact_id);
36 if(get_config('system','invitation_only')) {
37 $x = get_pconfig(local_user(),'system','invites_remaining');
38 if($x || is_site_admin()) {
39 $a->page['aside'] .= '<div class="side-link" id="side-invite-remain">'
40 . sprintf( tt('%d invitation available','%d invitations available',$x), $x)
45 $tpl = get_markup_template('peoplefind.tpl');
47 $inv = (($a->config['register_policy'] != REGISTER_CLOSED) ? t('Invite Friends') : '');
49 $a->page['aside'] .= replace_macros($tpl,array(
50 '$findpeople' => t('Find People'),
51 '$desc' => t('Enter name or interest'),
52 '$label' => t('Connect/Follow'),
53 '$hint' => t('Examples: Robert Morgenstein, Fishing'),
54 '$findthem' => t('Find'),
55 '$similar' => t('Similar Interests'),
63 function contacts_post(&$a) {
68 $contact_id = intval($a->argv[1]);
72 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
77 if(! count($orig_record)) {
78 notice( t('Could not access contact record.') . EOL);
79 goaway($a->get_baseurl() . '/contacts');
83 call_hooks('contact_edit_post', $_POST);
85 $profile_id = intval($_POST['profile-assign']);
87 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
92 notice( t('Could not locate selected profile.') . EOL);
98 $priority = intval($_POST['poll']);
99 if($priority > 5 || $priority < 0)
102 $info = escape_tags(trim($_POST['info']));
104 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s'
105 WHERE `id` = %d AND `uid` = %d LIMIT 1",
113 info( t('Contact updated.') . EOL);
115 notice( t('Failed to update contact record.') . EOL);
122 function contacts_content(&$a) {
126 nav_set_selected('contacts');
128 $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
131 notice( t('Permission denied.') . EOL);
137 $contact_id = intval($a->argv[1]);
143 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
148 if(! count($orig_record)) {
149 notice( t('Could not access contact record.') . EOL);
150 goaway($a->get_baseurl() . '/contacts');
151 return; // NOTREACHED
154 if($cmd === 'update') {
156 // pull feed and consume it, which should subscribe to the hub.
157 proc_run('php',"include/poller.php","$contact_id");
158 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
162 if($cmd === 'block') {
163 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
164 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
170 //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
171 info( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
173 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
174 return; // NOTREACHED
177 if($cmd === 'ignore') {
178 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
179 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
185 info( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
187 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
188 return; // NOTREACHED
191 if($cmd === 'drop') {
193 // create an unfollow slap
195 if($orig_record[0]['network'] === NETWORK_OSTATUS) {
196 $tpl = get_markup_template('follow_slap.tpl');
197 $slap = replace_macros($tpl, array(
198 '$name' => $a->user['username'],
199 '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
200 '$photo' => $a->contact['photo'],
201 '$thumb' => $a->contact['thumb'],
202 '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
203 '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(),
206 '$content' => t('stopped following'),
207 '$nick' => $a->user['nickname'],
208 '$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW,
209 '$ostat_follow' => '' // '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
212 if((x($orig_record[0],'notify')) && (strlen($orig_record[0]['notify']))) {
213 require_once('include/salmon.php');
214 slapper($a->user,$orig_record[0]['notify'],$slap);
217 elseif($orig_record[0]['network'] === NETWORK_DIASPORA) {
218 require_once('include/diaspora.php');
219 diaspora_unshare($a->user,$orig_record[0]);
221 elseif($orig_record[0]['network'] === NETWORK_DFRN) {
222 require_once('include/items.php');
223 dfrn_deliver($a->user,$orig_record[0],'placeholder', 1);
226 contact_remove($orig_record[0]['id']);
227 info( t('Contact has been removed.') . EOL );
228 goaway($a->get_baseurl() . '/contacts');
229 return; // NOTREACHED
233 if(($a->argc == 2) && intval($a->argv[1])) {
235 $contact_id = intval($a->argv[1]);
236 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
237 intval(local_user()),
241 notice( t('Contact not found.') . EOL);
245 $tpl = get_markup_template('contact_head.tpl');
246 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
248 require_once('include/contact_selectors.php');
250 $tpl = get_markup_template("contact_edit.tpl");
252 switch($r[0]['rel']) {
253 case CONTACT_IS_FRIEND:
254 $dir_icon = 'images/lrarrow.gif';
255 $alt_text = t('Mutual Friendship');
257 case CONTACT_IS_FOLLOWER;
258 $dir_icon = 'images/larrow.gif';
259 $alt_text = t('is a fan of yours');
262 case CONTACT_IS_SHARING;
263 $dir_icon = 'images/rarrow.gif';
264 $alt_text = t('you are a fan of');
270 if(($r[0]['network'] === 'dfrn') && ($r[0]['rel'])) {
271 $url = "redir/{$r[0]['id']}";
272 $sparkle = ' class="sparkle" ';
279 $insecure = '<div id="profile-edit-insecure"><p><img src="images/unlock_icon.gif" alt="' . t('Privacy Unavailable') . '" /> '
280 . t('Private communications are not available for this contact.') . '</p></div>';
282 $last_update = (($r[0]['last-update'] == '0000-00-00 00:00:00')
284 : datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A'));
286 if($r[0]['last-update'] !== '0000-00-00 00:00:00')
287 $last_update .= ' ' . (($r[0]['last-update'] == $r[0]['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
289 $lblsuggest = (($r[0]['network'] === NETWORK_DFRN)
290 ? '<div id="contact-suggest-wrapper"><a href="fsuggest/' . $r[0]['id'] . '" id="contact-suggest">' . t('Suggest friends') . '</a></div>' : '');
292 $poll_enabled = (($r[0]['network'] !== NETWORK_DIASPORA) ? true : false);
294 $nettype = '<div id="contact-edit-nettype">' . sprintf( t('Network type: %s'),network_to_name($r[0]['network'])) . '</div>';
296 $o .= replace_macros($tpl,array(
297 '$header' => t('Contact Editor'),
298 '$submit' => t('Submit'),
299 '$lbl_vis1' => t('Profile Visibility'),
300 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $r[0]['name']),
301 '$lbl_info1' => t('Contact Information / Notes'),
302 '$lbl_rep1' => t('Online Reputation'),
303 '$lbl_rep2' => t('Occasionally your friends may wish to inquire about this person\'s online legitimacy.'),
304 '$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.'),
305 '$lbl_rep4' => t('Please take a moment to elaborate on this selection if you feel it could be helpful to others.'),
306 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$r[0]['name'],$r[0]['url']),
307 '$blockunblock' => t('Block/Unblock contact'),
308 '$ignorecont' => t('Ignore contact'),
309 '$altcrepair' => t('Repair contact URL settings'),
310 '$lblcrepair' => t("Repair contact URL settings \x28WARNING: Advanced\x29"),
311 '$lblrecent' => t('View conversations'),
312 '$lblsuggest' => $lblsuggest,
313 '$delete' => t('Delete contact'),
314 '$nettype' => $nettype,
315 '$poll_interval' => contact_poll_interval($r[0]['priority'],(! $poll_enabled)),
316 '$poll_enabled' => $poll_enabled,
317 '$lastupdtext' => t('Last updated: '),
318 '$updpub' => t('Update public posts: '),
319 '$last_update' => $last_update,
320 '$udnow' => t('Update now'),
321 '$profile_select' => contact_profile_assign($r[0]['profile-id'],(($r[0]['network'] !== 'dfrn') ? true : false)),
322 '$contact_id' => $r[0]['id'],
323 '$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
324 '$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
325 '$insecure' => (($r[0]['network'] !== NETWORK_DFRN && $r[0]['network'] !== NETWORK_MAIL && $r[0]['network'] !== NETWORK_FACEBOOK && $r[0]['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
326 '$info' => $r[0]['info'],
327 '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
328 '$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),
329 '$photo' => $r[0]['photo'],
330 '$name' => $r[0]['name'],
331 '$dir_icon' => $dir_icon,
332 '$alt_text' => $alt_text,
333 '$sparkle' => $sparkle,
338 $arr = array('contact' => $r[0],'output' => $o);
340 call_hooks('contact_edit', $arr);
342 return $arr['output'];
347 if(($a->argc == 2) && ($a->argv[1] === 'all'))
350 $sql_extra = " AND `blocked` = 0 ";
352 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
354 $tpl = get_markup_template("contacts-top.tpl");
355 $o .= replace_macros($tpl,array(
356 '$header' => t('Contacts'),
357 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
358 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
359 '$search' => $search,
360 '$desc' => t('Search your contacts'),
361 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
362 '$submit' => t('Find'),
369 $search = dbesc($search.'*');
370 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
372 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
375 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
376 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
377 intval($_SESSION['uid']));
379 $a->set_pager_total($r[0]['total']);
381 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
382 intval($_SESSION['uid']),
383 intval($a->pager['start']),
384 intval($a->pager['itemspage'])
389 $tpl = get_markup_template("contact_template.tpl");
396 case CONTACT_IS_FRIEND:
397 $dir_icon = 'images/lrarrow.gif';
398 $alt_text = t('Mutual Friendship');
400 case CONTACT_IS_FOLLOWER;
401 $dir_icon = 'images/larrow.gif';
402 $alt_text = t('is a fan of yours');
404 case CONTACT_IS_SHARING;
405 $dir_icon = 'images/rarrow.gif';
406 $alt_text = t('you are a fan of');
411 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
412 $url = "redir/{$rr['id']}";
413 $sparkle = ' class="sparkle" ';
421 $o .= replace_macros($tpl, array(
422 '$img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
423 '$edit_hover' => t('Edit contact'),
424 '$contact_photo_menu' => contact_photo_menu($rr),
426 '$alt_text' => $alt_text,
427 '$dir_icon' => $dir_icon,
428 '$thumb' => $rr['thumb'],
429 '$name' => $rr['name'],
430 '$username' => $rr['name'],
431 '$sparkle' => $sparkle,
436 $o .= '<div id="contact-edit-end"></div>';