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');
114 $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
117 notice( t('Permission denied.') . EOL);
123 $contact_id = intval($a->argv[1]);
129 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
134 if(! count($orig_record)) {
135 notice( t('Could not access contact record.') . EOL);
136 goaway($a->get_baseurl() . '/contacts');
137 return; // NOTREACHED
140 if($cmd === 'update') {
142 // pull feed and consume it, which should subscribe to the hub.
143 proc_run('php',"include/poller.php","$contact_id");
144 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
148 if($cmd === 'block') {
149 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
150 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
156 //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
157 info( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
159 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
160 return; // NOTREACHED
163 if($cmd === 'ignore') {
164 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
165 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
171 info( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
173 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
174 return; // NOTREACHED
177 if($cmd === 'drop') {
179 // create an unfollow slap
181 if($orig_record[0]['network'] === NETWORK_OSTATUS) {
182 $tpl = get_markup_template('follow_slap.tpl');
183 $slap = replace_macros($tpl, array(
184 '$name' => $a->user['username'],
185 '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
186 '$photo' => $a->contact['photo'],
187 '$thumb' => $a->contact['thumb'],
188 '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
189 '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(),
192 '$content' => t('stopped following'),
193 '$nick' => $a->user['nickname'],
194 '$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW,
195 '$ostat_follow' => '' // '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
198 if((x($orig_record[0],'notify')) && (strlen($orig_record[0]['notify']))) {
199 require_once('include/salmon.php');
200 slapper($a->user,$orig_record[0]['notify'],$slap);
203 elseif($orig_record[0]['network'] === NETWORK_DIASPORA) {
204 require_once('include/diaspora.php');
205 diaspora_unshare($a->user,$orig_record[0]);
207 elseif($orig_record[0]['network'] === NETWORK_DFRN) {
208 require_once('include/items.php');
209 dfrn_deliver($a->user,$orig_record[0],'placeholder', 1);
212 contact_remove($orig_record[0]['id']);
213 info( t('Contact has been removed.') . EOL );
214 goaway($a->get_baseurl() . '/contacts');
215 return; // NOTREACHED
219 if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
221 $contact_id = $a->data['contact']['id'];
222 $contact = $a->data['contact'];
224 $tpl = get_markup_template('contact_head.tpl');
225 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
227 require_once('include/contact_selectors.php');
229 $tpl = get_markup_template("contact_edit.tpl");
231 switch($contact['rel']) {
232 case CONTACT_IS_FRIEND:
233 $dir_icon = 'images/lrarrow.gif';
234 $relation_text = t('You are mutual friends with %s');
236 case CONTACT_IS_FOLLOWER;
237 $dir_icon = 'images/larrow.gif';
238 $relation_text = t('You are sharing with %s');
241 case CONTACT_IS_SHARING;
242 $dir_icon = 'images/rarrow.gif';
243 $relation_text = t('%s is sharing with you');
249 $relation_text = sprintf($relation_text,$contact['name']);
251 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
252 $url = "redir/{$contact['id']}";
253 $sparkle = ' class="sparkle" ';
256 $url = $contact['url'];
260 $insecure = t('Private communications are not available for this contact.');
262 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00')
264 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
266 if($contact['last-update'] !== '0000-00-00 00:00:00')
267 $last_update .= ' ' . (($contact['last-update'] == $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
269 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
271 $poll_enabled = (($contact['network'] !== NETWORK_DIASPORA) ? true : false);
273 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network']));
275 $common = count_common_friends(local_user(),$contact['id']);
276 $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
278 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : '');
280 $x = count_all_friends(local_user(), $contact['id']);
281 $all_friends = (($x) ? t('View all contacts') : '');
286 'label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
287 'url' => $a->get_baseurl() . '/contacts/' . $contact_id . '/block',
291 'label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
292 'url' => $a->get_baseurl() . '/contacts/' . $contact_id . '/ignore',
296 'label' => t('Repair'),
297 'url' => $a->get_baseurl() . '/crepair/' . $contact_id,
301 $tab_tpl = get_markup_template('common_tabs.tpl');
302 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
305 $o .= replace_macros($tpl,array(
306 '$header' => t('Contact Editor'),
307 '$tab_str' => $tab_str,
308 '$submit' => t('Submit'),
309 '$lbl_vis1' => t('Profile Visibility'),
310 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
311 '$lbl_info1' => t('Contact Information / Notes'),
312 '$infedit' => t('Edit contact notes'),
313 '$common_text' => $common_text,
314 '$common_link' => $a->get_baseurl() . '/common/' . $contact['id'],
315 '$all_friends' => $all_friends,
316 '$relation_text' => $relation_text,
317 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
318 '$blockunblock' => t('Block/Unblock contact'),
319 '$ignorecont' => t('Ignore contact'),
320 '$lblcrepair' => t("Repair URL settings"),
321 '$lblrecent' => t('View conversations'),
322 '$lblsuggest' => $lblsuggest,
323 '$delete' => t('Delete contact'),
324 '$nettype' => $nettype,
325 '$poll_interval' => contact_poll_interval($contact['priority'],(! $poll_enabled)),
326 '$poll_enabled' => $poll_enabled,
327 '$lastupdtext' => t('Last update:'),
328 '$updpub' => t('Update public posts'),
329 '$last_update' => $last_update,
330 '$udnow' => t('Update now'),
331 '$profile_select' => contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false)),
332 '$contact_id' => $contact['id'],
333 '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
334 '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
335 '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
336 '$info' => $contact['info'],
337 '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
338 '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
339 '$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')),
340 '$photo' => $contact['photo'],
341 '$name' => $contact['name'],
342 '$dir_icon' => $dir_icon,
343 '$alt_text' => $alt_text,
344 '$sparkle' => $sparkle,
349 $arr = array('contact' => $contact,'output' => $o);
351 call_hooks('contact_edit', $arr);
353 return $arr['output'];
358 if(($a->argc == 2) && ($a->argv[1] === 'all'))
361 $sql_extra = " AND `blocked` = 0 ";
363 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
365 $tpl = get_markup_template("contacts-top.tpl");
366 $o .= replace_macros($tpl,array(
367 '$header' => t('Contacts'),
368 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
369 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
370 '$search' => $search,
371 '$desc' => t('Search your contacts'),
372 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
373 '$submit' => t('Find'),
380 $search = dbesc($search.'*');
381 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
383 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
386 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
387 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
388 intval($_SESSION['uid']));
390 $a->set_pager_total($r[0]['total']);
392 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
393 intval($_SESSION['uid']),
394 intval($a->pager['start']),
395 intval($a->pager['itemspage'])
400 $tpl = get_markup_template("contact_template.tpl");
407 case CONTACT_IS_FRIEND:
408 $dir_icon = 'images/lrarrow.gif';
409 $alt_text = t('Mutual Friendship');
411 case CONTACT_IS_FOLLOWER;
412 $dir_icon = 'images/larrow.gif';
413 $alt_text = t('is a fan of yours');
415 case CONTACT_IS_SHARING;
416 $dir_icon = 'images/rarrow.gif';
417 $alt_text = t('you are a fan of');
422 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
423 $url = "redir/{$rr['id']}";
424 $sparkle = ' class="sparkle" ';
432 $o .= replace_macros($tpl, array(
433 '$img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
434 '$edit_hover' => t('Edit contact'),
435 '$contact_photo_menu' => contact_photo_menu($rr),
437 '$alt_text' => $alt_text,
438 '$dir_icon' => $dir_icon,
439 '$thumb' => $rr['thumb'],
440 '$name' => $rr['name'],
441 '$username' => $rr['name'],
442 '$sparkle' => $sparkle,
447 $o .= '<div id="contact-edit-end"></div>';