3 require_once('include/Contact.php');
4 require_once('include/socgraph.php');
6 function contacts_init(&$a) {
12 if(($a->argc == 2) && intval($a->argv[1])) {
13 $contact_id = intval($a->argv[1]);
14 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
23 require_once('include/group.php');
24 require_once('include/contact_widgets.php');
26 if(! x($a->page,'aside'))
27 $a->page['aside'] = '';
30 $a->data['contact'] = $r[0];
31 $o .= '<div class="vcard">';
32 $o .= '<div class="fn">' . $a->data['contact']['name'] . '</div>';
33 $o .= '<div id="profile-photo-wrapper"><img class="photo" style="width: 175px; height: 175px;" src="' . $a->data['contact']['photo'] . '" alt="' . $a->data['contact']['name'] . '" /></div>';
35 $a->page['aside'] .= $o;
39 $a->page['aside'] .= group_side('contacts','group',false,0,$contact_id);
41 $a->page['aside'] .= findpeople_widget();
45 function contacts_post(&$a) {
50 $contact_id = intval($a->argv[1]);
54 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
59 if(! count($orig_record)) {
60 notice( t('Could not access contact record.') . EOL);
61 goaway($a->get_baseurl() . '/contacts');
65 call_hooks('contact_edit_post', $_POST);
67 $profile_id = intval($_POST['profile-assign']);
69 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
74 notice( t('Could not locate selected profile.') . EOL);
80 $priority = intval($_POST['poll']);
81 if($priority > 5 || $priority < 0)
84 $info = escape_tags(trim($_POST['info']));
86 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s'
87 WHERE `id` = %d AND `uid` = %d LIMIT 1",
95 info( t('Contact updated.') . EOL);
97 notice( t('Failed to update contact record.') . EOL);
104 function contacts_content(&$a) {
108 nav_set_selected('contacts');
110 $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
113 notice( t('Permission denied.') . EOL);
119 $contact_id = intval($a->argv[1]);
125 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
130 if(! count($orig_record)) {
131 notice( t('Could not access contact record.') . EOL);
132 goaway($a->get_baseurl() . '/contacts');
133 return; // NOTREACHED
136 if($cmd === 'update') {
138 // pull feed and consume it, which should subscribe to the hub.
139 proc_run('php',"include/poller.php","$contact_id");
140 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
144 if($cmd === 'block') {
145 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
146 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
152 //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
153 info( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
155 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
156 return; // NOTREACHED
159 if($cmd === 'ignore') {
160 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
161 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
167 info( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
169 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
170 return; // NOTREACHED
173 if($cmd === 'drop') {
175 // create an unfollow slap
177 if($orig_record[0]['network'] === NETWORK_OSTATUS) {
178 $tpl = get_markup_template('follow_slap.tpl');
179 $slap = replace_macros($tpl, array(
180 '$name' => $a->user['username'],
181 '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
182 '$photo' => $a->contact['photo'],
183 '$thumb' => $a->contact['thumb'],
184 '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
185 '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(),
188 '$content' => t('stopped following'),
189 '$nick' => $a->user['nickname'],
190 '$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW,
191 '$ostat_follow' => '' // '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
194 if((x($orig_record[0],'notify')) && (strlen($orig_record[0]['notify']))) {
195 require_once('include/salmon.php');
196 slapper($a->user,$orig_record[0]['notify'],$slap);
199 elseif($orig_record[0]['network'] === NETWORK_DIASPORA) {
200 require_once('include/diaspora.php');
201 diaspora_unshare($a->user,$orig_record[0]);
203 elseif($orig_record[0]['network'] === NETWORK_DFRN) {
204 require_once('include/items.php');
205 dfrn_deliver($a->user,$orig_record[0],'placeholder', 1);
208 contact_remove($orig_record[0]['id']);
209 info( t('Contact has been removed.') . EOL );
210 goaway($a->get_baseurl() . '/contacts');
211 return; // NOTREACHED
215 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
217 $contact_id = $a->data['contact']['id'];
218 $contact = $a->data['contact'];
220 $tpl = get_markup_template('contact_head.tpl');
221 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
223 require_once('include/contact_selectors.php');
225 $tpl = get_markup_template("contact_edit.tpl");
227 switch($contact['rel']) {
228 case CONTACT_IS_FRIEND:
229 $dir_icon = 'images/lrarrow.gif';
230 $relation_text = t('You are mutual friends with %s');
232 case CONTACT_IS_FOLLOWER;
233 $dir_icon = 'images/larrow.gif';
234 $relation_text = t('You are sharing with %s');
237 case CONTACT_IS_SHARING;
238 $dir_icon = 'images/rarrow.gif';
239 $relation_text = t('%s is sharing with you');
245 $relation_text = sprintf($relation_text,$contact['name']);
247 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
248 $url = "redir/{$contact['id']}";
249 $sparkle = ' class="sparkle" ';
252 $url = $contact['url'];
256 $insecure = t('Private communications are not available for this contact.');
258 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
260 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
262 if($contact['last-update'] !== '0000-00-00 00:00:00')
263 $last_update .= ' ' . (($contact['last-update'] == $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
265 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
267 $poll_enabled = (($contact['network'] !== NETWORK_DIASPORA) ? true : false);
269 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network']));
271 $common = count_common_friends(local_user(),$contact['id']);
272 $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
274 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
276 $x = count_all_friends(local_user(), $contact['id']);
277 $all_friends = (($x) ? t('View all contacts') : '');
282 'label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
283 'url' => $a->get_baseurl() . '/contacts/' . $contact_id . '/block',
287 'label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
288 'url' => $a->get_baseurl() . '/contacts/' . $contact_id . '/ignore',
292 'label' => t('Repair'),
293 'url' => $a->get_baseurl() . '/crepair/' . $contact_id,
297 $tab_tpl = get_markup_template('common_tabs.tpl');
298 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
301 $o .= replace_macros($tpl,array(
302 '$header' => t('Contact Editor'),
303 '$tab_str' => $tab_str,
304 '$submit' => t('Submit'),
305 '$lbl_vis1' => t('Profile Visibility'),
306 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
307 '$lbl_info1' => t('Contact Information / Notes'),
308 '$infedit' => t('Edit contact notes'),
309 '$common_text' => $common_text,
310 '$common_link' => $a->get_baseurl() . '/common/' . $contact['id'],
311 '$all_friends' => $all_friends,
312 '$relation_text' => $relation_text,
313 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
314 '$blockunblock' => t('Block/Unblock contact'),
315 '$ignorecont' => t('Ignore contact'),
316 '$lblcrepair' => t("Repair URL settings"),
317 '$lblrecent' => t('View conversations'),
318 '$lblsuggest' => $lblsuggest,
319 '$delete' => t('Delete contact'),
320 '$nettype' => $nettype,
321 '$poll_interval' => contact_poll_interval($contact['priority'],(! $poll_enabled)),
322 '$poll_enabled' => $poll_enabled,
323 '$lastupdtext' => t('Last update:'),
324 '$updpub' => t('Update public posts'),
325 '$last_update' => $last_update,
326 '$udnow' => t('Update now'),
327 '$profile_select' => contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false)),
328 '$contact_id' => $contact['id'],
329 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
330 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
331 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
332 '$info' => $contact['info'],
333 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
334 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
335 '$photo' => $contact['photo'],
336 '$name' => $contact['name'],
337 '$dir_icon' => $dir_icon,
338 '$alt_text' => $alt_text,
339 '$sparkle' => $sparkle,
344 $arr = array('contact' => $contact,'output' => $o);
346 call_hooks('contact_edit', $arr);
348 return $arr['output'];
353 if(($a->argc == 2) && ($a->argv[1] === 'all'))
356 $sql_extra = " AND `blocked` = 0 ";
358 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
360 $tpl = get_markup_template("contacts-top.tpl");
361 $o .= replace_macros($tpl,array(
362 '$header' => t('Contacts'),
363 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
364 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
365 '$search' => $search,
366 '$desc' => t('Search your contacts'),
367 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
368 '$submit' => t('Find'),
375 $search = dbesc($search.'*');
376 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
378 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
381 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
382 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
383 intval($_SESSION['uid']));
385 $a->set_pager_total($r[0]['total']);
387 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
388 intval($_SESSION['uid']),
389 intval($a->pager['start']),
390 intval($a->pager['itemspage'])
395 $tpl = get_markup_template("contact_template.tpl");
402 case CONTACT_IS_FRIEND:
403 $dir_icon = 'images/lrarrow.gif';
404 $alt_text = t('Mutual Friendship');
406 case CONTACT_IS_FOLLOWER;
407 $dir_icon = 'images/larrow.gif';
408 $alt_text = t('is a fan of yours');
410 case CONTACT_IS_SHARING;
411 $dir_icon = 'images/rarrow.gif';
412 $alt_text = t('you are a fan of');
417 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
418 $url = "redir/{$rr['id']}";
419 $sparkle = ' class="sparkle" ';
427 $o .= replace_macros($tpl, array(
428 '$img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
429 '$edit_hover' => t('Edit contact'),
430 '$contact_photo_menu' => contact_photo_menu($rr),
432 '$alt_text' => $alt_text,
433 '$dir_icon' => $dir_icon,
434 '$thumb' => $rr['thumb'],
435 '$name' => $rr['name'],
436 '$username' => $rr['name'],
437 '$sparkle' => $sparkle,
442 $o .= '<div id="contact-edit-end"></div>';