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'] .= follow_widget();
41 $a->page['aside'] .= group_side('contacts','group',false,0,$contact_id);
43 $a->page['aside'] .= findpeople_widget();
47 function contacts_post(&$a) {
52 $contact_id = intval($a->argv[1]);
56 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
61 if(! count($orig_record)) {
62 notice( t('Could not access contact record.') . EOL);
63 goaway($a->get_baseurl() . '/contacts');
67 call_hooks('contact_edit_post', $_POST);
69 $profile_id = intval($_POST['profile-assign']);
71 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
76 notice( t('Could not locate selected profile.') . EOL);
81 $hidden = intval($_POST['hidden']);
83 $priority = intval($_POST['poll']);
84 if($priority > 5 || $priority < 0)
87 $info = escape_tags(trim($_POST['info']));
89 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
90 `hidden` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
99 info( t('Contact updated.') . EOL);
101 notice( t('Failed to update contact record.') . EOL);
108 function contacts_content(&$a) {
112 nav_set_selected('contacts');
116 notice( t('Permission denied.') . EOL);
122 $contact_id = intval($a->argv[1]);
128 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
133 if(! count($orig_record)) {
134 notice( t('Could not access contact record.') . EOL);
135 goaway($a->get_baseurl() . '/contacts');
136 return; // NOTREACHED
139 if($cmd === 'update') {
141 // pull feed and consume it, which should subscribe to the hub.
142 proc_run('php',"include/poller.php","$contact_id");
143 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
147 if($cmd === 'block') {
148 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
149 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
155 //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
156 info( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
158 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
159 return; // NOTREACHED
162 if($cmd === 'ignore') {
163 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
164 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
170 info( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
172 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
173 return; // NOTREACHED
176 if($cmd === 'drop') {
178 // create an unfollow slap
180 if($orig_record[0]['network'] === NETWORK_OSTATUS) {
181 $tpl = get_markup_template('follow_slap.tpl');
182 $slap = replace_macros($tpl, array(
183 '$name' => $a->user['username'],
184 '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
185 '$photo' => $a->contact['photo'],
186 '$thumb' => $a->contact['thumb'],
187 '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
188 '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(),
191 '$content' => t('stopped following'),
192 '$nick' => $a->user['nickname'],
193 '$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW,
194 '$ostat_follow' => '' // '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
197 if((x($orig_record[0],'notify')) && (strlen($orig_record[0]['notify']))) {
198 require_once('include/salmon.php');
199 slapper($a->user,$orig_record[0]['notify'],$slap);
202 elseif($orig_record[0]['network'] === NETWORK_DIASPORA) {
203 require_once('include/diaspora.php');
204 diaspora_unshare($a->user,$orig_record[0]);
206 elseif($orig_record[0]['network'] === NETWORK_DFRN) {
207 require_once('include/items.php');
208 dfrn_deliver($a->user,$orig_record[0],'placeholder', 1);
211 contact_remove($orig_record[0]['id']);
212 info( t('Contact has been removed.') . EOL );
213 if(x($_SESSION,'return_url'))
214 goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
216 goaway($a->get_baseurl() . '/contacts');
217 return; // NOTREACHED
221 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
223 $contact_id = $a->data['contact']['id'];
224 $contact = $a->data['contact'];
226 $tpl = get_markup_template('contact_head.tpl');
227 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
229 require_once('include/contact_selectors.php');
231 $tpl = get_markup_template("contact_edit.tpl");
233 switch($contact['rel']) {
234 case CONTACT_IS_FRIEND:
235 $dir_icon = 'images/lrarrow.gif';
236 $relation_text = t('You are mutual friends with %s');
238 case CONTACT_IS_FOLLOWER;
239 $dir_icon = 'images/larrow.gif';
240 $relation_text = t('You are sharing with %s');
243 case CONTACT_IS_SHARING;
244 $dir_icon = 'images/rarrow.gif';
245 $relation_text = t('%s is sharing with you');
251 $relation_text = sprintf($relation_text,$contact['name']);
253 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
254 $url = "redir/{$contact['id']}";
255 $sparkle = ' class="sparkle" ';
258 $url = $contact['url'];
262 $insecure = t('Private communications are not available for this contact.');
264 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
266 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
268 if($contact['last-update'] !== '0000-00-00 00:00:00')
269 $last_update .= ' ' . (($contact['last-update'] == $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
271 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
273 $poll_enabled = (($contact['network'] !== NETWORK_DIASPORA) ? true : false);
275 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network']));
277 $common = count_common_friends(local_user(),$contact['id']);
278 $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
280 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
282 $x = count_all_friends(local_user(), $contact['id']);
283 $all_friends = (($x) ? t('View all contacts') : '');
288 'label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
289 'url' => $a->get_baseurl() . '/contacts/' . $contact_id . '/block',
293 'label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
294 'url' => $a->get_baseurl() . '/contacts/' . $contact_id . '/ignore',
298 'label' => t('Repair'),
299 'url' => $a->get_baseurl() . '/crepair/' . $contact_id,
303 $tab_tpl = get_markup_template('common_tabs.tpl');
304 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
307 $o .= replace_macros($tpl,array(
308 '$header' => t('Contact Editor'),
309 '$tab_str' => $tab_str,
310 '$submit' => t('Submit'),
311 '$lbl_vis1' => t('Profile Visibility'),
312 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
313 '$lbl_info1' => t('Contact Information / Notes'),
314 '$infedit' => t('Edit contact notes'),
315 '$common_text' => $common_text,
316 '$common_link' => $a->get_baseurl() . '/common/' . $contact['id'],
317 '$all_friends' => $all_friends,
318 '$relation_text' => $relation_text,
319 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
320 '$blockunblock' => t('Block/Unblock contact'),
321 '$ignorecont' => t('Ignore contact'),
322 '$lblcrepair' => t("Repair URL settings"),
323 '$lblrecent' => t('View conversations'),
324 '$lblsuggest' => $lblsuggest,
325 '$delete' => t('Delete contact'),
326 '$nettype' => $nettype,
327 '$poll_interval' => contact_poll_interval($contact['priority'],(! $poll_enabled)),
328 '$poll_enabled' => $poll_enabled,
329 '$lastupdtext' => t('Last update:'),
330 '$updpub' => t('Update public posts'),
331 '$last_update' => $last_update,
332 '$udnow' => t('Update now'),
333 '$profile_select' => contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false)),
334 '$contact_id' => $contact['id'],
335 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
336 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
337 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
338 '$info' => $contact['info'],
339 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
340 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
341 '$hidden' => array('hidden', t('Hide this contact from others'), ($contact['hidden'] == 1), t('Replies/likes to your public posts <strong>may</strong> still be visible')),
342 '$photo' => $contact['photo'],
343 '$name' => $contact['name'],
344 '$dir_icon' => $dir_icon,
345 '$alt_text' => $alt_text,
346 '$sparkle' => $sparkle,
351 $arr = array('contact' => $contact,'output' => $o);
353 call_hooks('contact_edit', $arr);
355 return $arr['output'];
359 $_SESSION['return_url'] = $a->query_string;
361 if(($a->argc == 2) && ($a->argv[1] === 'all'))
364 $sql_extra = " AND `blocked` = 0 ";
366 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
368 $tpl = get_markup_template("contacts-top.tpl");
369 $o .= replace_macros($tpl,array(
370 '$header' => t('Contacts'),
371 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
372 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
373 '$search' => $search,
374 '$desc' => t('Search your contacts'),
375 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
376 '$submit' => t('Find'),
383 $search = dbesc($search.'*');
384 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
386 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
389 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
390 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
391 intval($_SESSION['uid']));
393 $a->set_pager_total($r[0]['total']);
395 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
396 intval($_SESSION['uid']),
397 intval($a->pager['start']),
398 intval($a->pager['itemspage'])
403 $tpl = get_markup_template("contact_template.tpl");
410 case CONTACT_IS_FRIEND:
411 $dir_icon = 'images/lrarrow.gif';
412 $alt_text = t('Mutual Friendship');
414 case CONTACT_IS_FOLLOWER;
415 $dir_icon = 'images/larrow.gif';
416 $alt_text = t('is a fan of yours');
418 case CONTACT_IS_SHARING;
419 $dir_icon = 'images/rarrow.gif';
420 $alt_text = t('you are a fan of');
425 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
426 $url = "redir/{$rr['id']}";
427 $sparkle = ' class="sparkle" ';
435 $o .= replace_macros($tpl, array(
436 '$img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
437 '$edit_hover' => t('Edit contact'),
438 '$contact_photo_menu' => contact_photo_menu($rr),
440 '$alt_text' => $alt_text,
441 '$dir_icon' => $dir_icon,
442 '$thumb' => $rr['thumb'],
443 '$name' => $rr['name'],
444 '$username' => $rr['name'],
445 '$sparkle' => $sparkle,
450 $o .= '<div id="contact-edit-end"></div>';