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(($a->argc == 2) && intval($a->argv[1])) {
217 $contact_id = intval($a->argv[1]);
218 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
219 intval(local_user()),
223 notice( t('Contact not found.') . EOL);
227 $tpl = get_markup_template('contact_head.tpl');
228 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
230 require_once('include/contact_selectors.php');
232 $tpl = get_markup_template("contact_edit.tpl");
234 switch($r[0]['rel']) {
235 case CONTACT_IS_FRIEND:
236 $dir_icon = 'images/lrarrow.gif';
237 $relation_text = t('You are mutual friends with %s');
239 case CONTACT_IS_FOLLOWER;
240 $dir_icon = 'images/larrow.gif';
241 $relation_text = t('You are sharing with %s');
244 case CONTACT_IS_SHARING;
245 $dir_icon = 'images/rarrow.gif';
246 $relation_text = t('%s is sharing with you');
252 $relation_text = sprintf($relation_text,$r[0]['name']);
254 if(($r[0]['network'] === 'dfrn') && ($r[0]['rel'])) {
255 $url = "redir/{$r[0]['id']}";
256 $sparkle = ' class="sparkle" ';
263 $insecure = t('Private communications are not available for this contact.');
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) ? t('Suggest friends') : '');
274 $poll_enabled = (($r[0]['network'] !== NETWORK_DIASPORA) ? true : false);
276 $nettype = sprintf( t('Network type: %s'),network_to_name($r[0]['network']));
278 $common = count_common_friends(local_user(),$r[0]['id']);
279 $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
281 $polling = (($r[0]['network'] === NETWORK_MAIL | $r[0]['network'] === NETWORK_FEED) ? 'polling' : '');
283 $x = count_all_friends(local_user(), $r[0]['id']);
284 $all_friends = (($x) ? t('View all contacts') : '');
286 $o .= replace_macros($tpl,array(
287 '$header' => t('Contact Editor'),
288 '$submit' => t('Submit'),
289 '$lbl_vis1' => t('Profile Visibility'),
290 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $r[0]['name']),
291 '$lbl_info1' => t('Contact Information / Notes'),
292 '$infedit' => t('Edit contact notes'),
293 '$common_text' => $common_text,
294 '$common_link' => $a->get_baseurl() . '/common/' . $r[0]['id'],
295 '$all_friends' => $all_friends,
296 '$relation_text' => $relation_text,
297 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$r[0]['name'],$r[0]['url']),
298 '$blockunblock' => t('Block/Unblock contact'),
299 '$ignorecont' => t('Ignore contact'),
300 '$lblcrepair' => t("Repair URL settings"),
301 '$lblrecent' => t('View conversations'),
302 '$lblsuggest' => $lblsuggest,
303 '$delete' => t('Delete contact'),
304 '$nettype' => $nettype,
305 '$poll_interval' => contact_poll_interval($r[0]['priority'],(! $poll_enabled)),
306 '$poll_enabled' => $poll_enabled,
307 '$lastupdtext' => t('Last update:'),
308 '$updpub' => t('Update public posts'),
309 '$last_update' => $last_update,
310 '$udnow' => t('Update now'),
311 '$profile_select' => contact_profile_assign($r[0]['profile-id'],(($r[0]['network'] !== NETWORK_DFRN) ? true : false)),
312 '$contact_id' => $r[0]['id'],
313 '$block_text' => (($r[0]['blocked']) ? t('Unblock') : t('Block') ),
314 '$ignore_text' => (($r[0]['readonly']) ? t('Unignore') : t('Ignore') ),
315 '$insecure' => (($r[0]['network'] !== NETWORK_DFRN && $r[0]['network'] !== NETWORK_MAIL && $r[0]['network'] !== NETWORK_FACEBOOK && $r[0]['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
316 '$info' => $r[0]['info'],
317 '$blocked' => (($r[0]['blocked']) ? t('Currently blocked') : ''),
318 '$ignored' => (($r[0]['readonly']) ? t('Currently ignored') : ''),
319 '$photo' => $r[0]['photo'],
320 '$name' => $r[0]['name'],
321 '$dir_icon' => $dir_icon,
322 '$alt_text' => $alt_text,
323 '$sparkle' => $sparkle,
328 $arr = array('contact' => $r[0],'output' => $o);
330 call_hooks('contact_edit', $arr);
332 return $arr['output'];
337 if(($a->argc == 2) && ($a->argv[1] === 'all'))
340 $sql_extra = " AND `blocked` = 0 ";
342 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
344 $tpl = get_markup_template("contacts-top.tpl");
345 $o .= replace_macros($tpl,array(
346 '$header' => t('Contacts'),
347 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
348 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
349 '$search' => $search,
350 '$desc' => t('Search your contacts'),
351 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
352 '$submit' => t('Find'),
359 $search = dbesc($search.'*');
360 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
362 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
365 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
366 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
367 intval($_SESSION['uid']));
369 $a->set_pager_total($r[0]['total']);
371 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
372 intval($_SESSION['uid']),
373 intval($a->pager['start']),
374 intval($a->pager['itemspage'])
379 $tpl = get_markup_template("contact_template.tpl");
386 case CONTACT_IS_FRIEND:
387 $dir_icon = 'images/lrarrow.gif';
388 $alt_text = t('Mutual Friendship');
390 case CONTACT_IS_FOLLOWER;
391 $dir_icon = 'images/larrow.gif';
392 $alt_text = t('is a fan of yours');
394 case CONTACT_IS_SHARING;
395 $dir_icon = 'images/rarrow.gif';
396 $alt_text = t('you are a fan of');
401 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
402 $url = "redir/{$rr['id']}";
403 $sparkle = ' class="sparkle" ';
411 $o .= replace_macros($tpl, array(
412 '$img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
413 '$edit_hover' => t('Edit contact'),
414 '$contact_photo_menu' => contact_photo_menu($rr),
416 '$alt_text' => $alt_text,
417 '$dir_icon' => $dir_icon,
418 '$thumb' => $rr['thumb'],
419 '$name' => $rr['name'],
420 '$username' => $rr['name'],
421 '$sparkle' => $sparkle,
426 $o .= '<div id="contact-edit-end"></div>';