3 require_once('include/Contact.php');
4 require_once('include/socgraph.php');
6 function contacts_init(&$a) {
11 if(($a->argc == 2) && intval($a->argv[1])) {
12 $contact_id = intval($a->argv[1]);
13 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
22 require_once('include/group.php');
23 require_once('include/contact_widgets.php');
25 if(! x($a->page,'aside'))
26 $a->page['aside'] = '';
28 $a->page['aside'] .= follow_widget();
30 $a->page['aside'] .= group_side('contacts','group',false,0,$contact_id);
32 $a->page['aside'] .= findpeople_widget();
36 function contacts_post(&$a) {
41 $contact_id = intval($a->argv[1]);
45 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
50 if(! count($orig_record)) {
51 notice( t('Could not access contact record.') . EOL);
52 goaway($a->get_baseurl() . '/contacts');
56 call_hooks('contact_edit_post', $_POST);
58 $profile_id = intval($_POST['profile-assign']);
60 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
65 notice( t('Could not locate selected profile.') . EOL);
71 $priority = intval($_POST['poll']);
72 if($priority > 5 || $priority < 0)
75 $info = escape_tags(trim($_POST['info']));
77 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s'
78 WHERE `id` = %d AND `uid` = %d LIMIT 1",
86 info( t('Contact updated.') . EOL);
88 notice( t('Failed to update contact record.') . EOL);
95 function contacts_content(&$a) {
99 nav_set_selected('contacts');
101 $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
104 notice( t('Permission denied.') . EOL);
110 $contact_id = intval($a->argv[1]);
116 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
121 if(! count($orig_record)) {
122 notice( t('Could not access contact record.') . EOL);
123 goaway($a->get_baseurl() . '/contacts');
124 return; // NOTREACHED
127 if($cmd === 'update') {
129 // pull feed and consume it, which should subscribe to the hub.
130 proc_run('php',"include/poller.php","$contact_id");
131 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
135 if($cmd === 'block') {
136 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
137 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
143 //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
144 info( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
146 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
147 return; // NOTREACHED
150 if($cmd === 'ignore') {
151 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
152 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
158 info( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
160 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
161 return; // NOTREACHED
164 if($cmd === 'drop') {
166 // create an unfollow slap
168 if($orig_record[0]['network'] === NETWORK_OSTATUS) {
169 $tpl = get_markup_template('follow_slap.tpl');
170 $slap = replace_macros($tpl, array(
171 '$name' => $a->user['username'],
172 '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
173 '$photo' => $a->contact['photo'],
174 '$thumb' => $a->contact['thumb'],
175 '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
176 '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(),
179 '$content' => t('stopped following'),
180 '$nick' => $a->user['nickname'],
181 '$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW,
182 '$ostat_follow' => '' // '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
185 if((x($orig_record[0],'notify')) && (strlen($orig_record[0]['notify']))) {
186 require_once('include/salmon.php');
187 slapper($a->user,$orig_record[0]['notify'],$slap);
190 elseif($orig_record[0]['network'] === NETWORK_DIASPORA) {
191 require_once('include/diaspora.php');
192 diaspora_unshare($a->user,$orig_record[0]);
194 elseif($orig_record[0]['network'] === NETWORK_DFRN) {
195 require_once('include/items.php');
196 dfrn_deliver($a->user,$orig_record[0],'placeholder', 1);
199 contact_remove($orig_record[0]['id']);
200 info( t('Contact has been removed.') . EOL );
201 goaway($a->get_baseurl() . '/contacts');
202 return; // NOTREACHED
206 if(($a->argc == 2) && intval($a->argv[1])) {
208 $contact_id = intval($a->argv[1]);
209 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
210 intval(local_user()),
214 notice( t('Contact not found.') . EOL);
218 $tpl = get_markup_template('contact_head.tpl');
219 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
221 require_once('include/contact_selectors.php');
223 $tpl = get_markup_template("contact_edit.tpl");
225 switch($r[0]['rel']) {
226 case CONTACT_IS_FRIEND:
227 $dir_icon = 'images/lrarrow.gif';
228 $alt_text = t('Mutual Friendship');
230 case CONTACT_IS_FOLLOWER;
231 $dir_icon = 'images/larrow.gif';
232 $alt_text = t('is a fan of yours');
235 case CONTACT_IS_SHARING;
236 $dir_icon = 'images/rarrow.gif';
237 $alt_text = t('you are a fan of');
243 if(($r[0]['network'] === 'dfrn') && ($r[0]['rel'])) {
244 $url = "redir/{$r[0]['id']}";
245 $sparkle = ' class="sparkle" ';
252 $insecure = '<div id="profile-edit-insecure"><p><img src="images/unlock_icon.gif" alt="' . t('Privacy Unavailable') . '" /> '
253 . t('Private communications are not available for this contact.') . '</p></div>';
255 $last_update = (($r[0]['last-update'] == '0000-00-00 00:00:00')
257 : datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A'));
259 if($r[0]['last-update'] !== '0000-00-00 00:00:00')
260 $last_update .= ' ' . (($r[0]['last-update'] == $r[0]['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
262 $lblsuggest = (($r[0]['network'] === NETWORK_DFRN)
263 ? '<div id="contact-suggest-wrapper"><a href="fsuggest/' . $r[0]['id'] . '" id="contact-suggest">' . t('Suggest friends') . '</a></div>' : '');
265 $poll_enabled = (($r[0]['network'] !== NETWORK_DIASPORA) ? true : false);
267 $nettype = '<div id="contact-edit-nettype">' . sprintf( t('Network type: %s'),network_to_name($r[0]['network'])) . '</div>';
269 $common = count_common_friends(local_user(),$r[0]['id']);
270 $common_text = (($common) ? sprintf( tt('%d friends in common','%d friends in common', $common),$common) : '');
271 $o .= replace_macros($tpl,array(
272 '$header' => t('Contact Editor'),
273 '$submit' => t('Submit'),
274 '$lbl_vis1' => t('Profile Visibility'),
275 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $r[0]['name']),
276 '$lbl_info1' => t('Contact Information / Notes'),
277 '$lbl_rep1' => t('Online Reputation'),
278 '$lbl_rep2' => t('Occasionally your friends may wish to inquire about this person\'s online legitimacy.'),
279 '$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.'),
280 '$lbl_rep4' => t('Please take a moment to elaborate on this selection if you feel it could be helpful to others.'),
281 '$common_text' => $common_text,
282 '$common_link' => $a->get_baseurl() . '/common/' . $r[0]['id'],
283 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$r[0]['name'],$r[0]['url']),
284 '$blockunblock' => t('Block/Unblock contact'),
285 '$ignorecont' => t('Ignore contact'),
286 '$altcrepair' => t('Repair contact URL settings'),
287 '$lblcrepair' => t("Repair contact URL settings \x28WARNING: Advanced\x29"),
288 '$lblrecent' => t('View conversations'),
289 '$lblsuggest' => $lblsuggest,
290 '$delete' => t('Delete contact'),
291 '$nettype' => $nettype,
292 '$poll_interval' => contact_poll_interval($r[0]['priority'],(! $poll_enabled)),
293 '$poll_enabled' => $poll_enabled,
294 '$lastupdtext' => t('Last updated: '),
295 '$updpub' => t('Update public posts: '),
296 '$last_update' => $last_update,
297 '$udnow' => t('Update now'),
298 '$profile_select' => contact_profile_assign($r[0]['profile-id'],(($r[0]['network'] !== 'dfrn') ? true : false)),
299 '$contact_id' => $r[0]['id'],
300 '$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
301 '$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
302 '$insecure' => (($r[0]['network'] !== NETWORK_DFRN && $r[0]['network'] !== NETWORK_MAIL && $r[0]['network'] !== NETWORK_FACEBOOK && $r[0]['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
303 '$info' => $r[0]['info'],
304 '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
305 '$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),
306 '$photo' => $r[0]['photo'],
307 '$name' => $r[0]['name'],
308 '$dir_icon' => $dir_icon,
309 '$alt_text' => $alt_text,
310 '$sparkle' => $sparkle,
315 $arr = array('contact' => $r[0],'output' => $o);
317 call_hooks('contact_edit', $arr);
319 return $arr['output'];
324 if(($a->argc == 2) && ($a->argv[1] === 'all'))
327 $sql_extra = " AND `blocked` = 0 ";
329 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
331 $tpl = get_markup_template("contacts-top.tpl");
332 $o .= replace_macros($tpl,array(
333 '$header' => t('Contacts'),
334 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
335 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
336 '$search' => $search,
337 '$desc' => t('Search your contacts'),
338 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
339 '$submit' => t('Find'),
346 $search = dbesc($search.'*');
347 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
349 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
352 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
353 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
354 intval($_SESSION['uid']));
356 $a->set_pager_total($r[0]['total']);
358 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
359 intval($_SESSION['uid']),
360 intval($a->pager['start']),
361 intval($a->pager['itemspage'])
366 $tpl = get_markup_template("contact_template.tpl");
373 case CONTACT_IS_FRIEND:
374 $dir_icon = 'images/lrarrow.gif';
375 $alt_text = t('Mutual Friendship');
377 case CONTACT_IS_FOLLOWER;
378 $dir_icon = 'images/larrow.gif';
379 $alt_text = t('is a fan of yours');
381 case CONTACT_IS_SHARING;
382 $dir_icon = 'images/rarrow.gif';
383 $alt_text = t('you are a fan of');
388 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
389 $url = "redir/{$rr['id']}";
390 $sparkle = ' class="sparkle" ';
398 $o .= replace_macros($tpl, array(
399 '$img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
400 '$edit_hover' => t('Edit contact'),
401 '$contact_photo_menu' => contact_photo_menu($rr),
403 '$alt_text' => $alt_text,
404 '$dir_icon' => $dir_icon,
405 '$thumb' => $rr['thumb'],
406 '$name' => $rr['name'],
407 '$username' => $rr['name'],
408 '$sparkle' => $sparkle,
413 $o .= '<div id="contact-edit-end"></div>';