3 require_once('include/Contact.php');
5 function contacts_init(&$a) {
10 if(($a->argc == 2) && intval($a->argv[1])) {
11 $contact_id = intval($a->argv[1]);
12 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
21 require_once('include/group.php');
22 require_once('include/contact_widgets.php');
24 if(! x($a->page,'aside'))
25 $a->page['aside'] = '';
27 $a->page['aside'] .= follow_widget();
29 $a->page['aside'] .= group_side('contacts','group',false,0,$contact_id);
31 $a->page['aside'] .= findpeople_widget();
35 function contacts_post(&$a) {
40 $contact_id = intval($a->argv[1]);
44 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
49 if(! count($orig_record)) {
50 notice( t('Could not access contact record.') . EOL);
51 goaway($a->get_baseurl() . '/contacts');
55 call_hooks('contact_edit_post', $_POST);
57 $profile_id = intval($_POST['profile-assign']);
59 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
64 notice( t('Could not locate selected profile.') . EOL);
70 $priority = intval($_POST['poll']);
71 if($priority > 5 || $priority < 0)
74 $info = escape_tags(trim($_POST['info']));
76 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s'
77 WHERE `id` = %d AND `uid` = %d LIMIT 1",
85 info( t('Contact updated.') . EOL);
87 notice( t('Failed to update contact record.') . EOL);
94 function contacts_content(&$a) {
98 nav_set_selected('contacts');
100 $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
103 notice( t('Permission denied.') . EOL);
109 $contact_id = intval($a->argv[1]);
115 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
120 if(! count($orig_record)) {
121 notice( t('Could not access contact record.') . EOL);
122 goaway($a->get_baseurl() . '/contacts');
123 return; // NOTREACHED
126 if($cmd === 'update') {
128 // pull feed and consume it, which should subscribe to the hub.
129 proc_run('php',"include/poller.php","$contact_id");
130 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
134 if($cmd === 'block') {
135 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
136 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
142 //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
143 info( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
145 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
146 return; // NOTREACHED
149 if($cmd === 'ignore') {
150 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
151 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
157 info( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
159 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
160 return; // NOTREACHED
163 if($cmd === 'drop') {
165 // create an unfollow slap
167 if($orig_record[0]['network'] === NETWORK_OSTATUS) {
168 $tpl = get_markup_template('follow_slap.tpl');
169 $slap = replace_macros($tpl, array(
170 '$name' => $a->user['username'],
171 '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
172 '$photo' => $a->contact['photo'],
173 '$thumb' => $a->contact['thumb'],
174 '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
175 '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(),
178 '$content' => t('stopped following'),
179 '$nick' => $a->user['nickname'],
180 '$verb' => 'http://ostatus.org/schema/1.0/unfollow', // ACTIVITY_UNFOLLOW,
181 '$ostat_follow' => '' // '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
184 if((x($orig_record[0],'notify')) && (strlen($orig_record[0]['notify']))) {
185 require_once('include/salmon.php');
186 slapper($a->user,$orig_record[0]['notify'],$slap);
189 elseif($orig_record[0]['network'] === NETWORK_DIASPORA) {
190 require_once('include/diaspora.php');
191 diaspora_unshare($a->user,$orig_record[0]);
193 elseif($orig_record[0]['network'] === NETWORK_DFRN) {
194 require_once('include/items.php');
195 dfrn_deliver($a->user,$orig_record[0],'placeholder', 1);
198 contact_remove($orig_record[0]['id']);
199 info( t('Contact has been removed.') . EOL );
200 goaway($a->get_baseurl() . '/contacts');
201 return; // NOTREACHED
205 if(($a->argc == 2) && intval($a->argv[1])) {
207 $contact_id = intval($a->argv[1]);
208 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
209 intval(local_user()),
213 notice( t('Contact not found.') . EOL);
217 $tpl = get_markup_template('contact_head.tpl');
218 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
220 require_once('include/contact_selectors.php');
222 $tpl = get_markup_template("contact_edit.tpl");
224 switch($r[0]['rel']) {
225 case CONTACT_IS_FRIEND:
226 $dir_icon = 'images/lrarrow.gif';
227 $alt_text = t('Mutual Friendship');
229 case CONTACT_IS_FOLLOWER;
230 $dir_icon = 'images/larrow.gif';
231 $alt_text = t('is a fan of yours');
234 case CONTACT_IS_SHARING;
235 $dir_icon = 'images/rarrow.gif';
236 $alt_text = t('you are a fan of');
242 if(($r[0]['network'] === 'dfrn') && ($r[0]['rel'])) {
243 $url = "redir/{$r[0]['id']}";
244 $sparkle = ' class="sparkle" ';
251 $insecure = '<div id="profile-edit-insecure"><p><img src="images/unlock_icon.gif" alt="' . t('Privacy Unavailable') . '" /> '
252 . t('Private communications are not available for this contact.') . '</p></div>';
254 $last_update = (($r[0]['last-update'] == '0000-00-00 00:00:00')
256 : datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A'));
258 if($r[0]['last-update'] !== '0000-00-00 00:00:00')
259 $last_update .= ' ' . (($r[0]['last-update'] == $r[0]['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
261 $lblsuggest = (($r[0]['network'] === NETWORK_DFRN)
262 ? '<div id="contact-suggest-wrapper"><a href="fsuggest/' . $r[0]['id'] . '" id="contact-suggest">' . t('Suggest friends') . '</a></div>' : '');
264 $poll_enabled = (($r[0]['network'] !== NETWORK_DIASPORA) ? true : false);
266 $nettype = '<div id="contact-edit-nettype">' . sprintf( t('Network type: %s'),network_to_name($r[0]['network'])) . '</div>';
268 $o .= replace_macros($tpl,array(
269 '$header' => t('Contact Editor'),
270 '$submit' => t('Submit'),
271 '$lbl_vis1' => t('Profile Visibility'),
272 '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $r[0]['name']),
273 '$lbl_info1' => t('Contact Information / Notes'),
274 '$lbl_rep1' => t('Online Reputation'),
275 '$lbl_rep2' => t('Occasionally your friends may wish to inquire about this person\'s online legitimacy.'),
276 '$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.'),
277 '$lbl_rep4' => t('Please take a moment to elaborate on this selection if you feel it could be helpful to others.'),
278 '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$r[0]['name'],$r[0]['url']),
279 '$blockunblock' => t('Block/Unblock contact'),
280 '$ignorecont' => t('Ignore contact'),
281 '$altcrepair' => t('Repair contact URL settings'),
282 '$lblcrepair' => t("Repair contact URL settings \x28WARNING: Advanced\x29"),
283 '$lblrecent' => t('View conversations'),
284 '$lblsuggest' => $lblsuggest,
285 '$delete' => t('Delete contact'),
286 '$nettype' => $nettype,
287 '$poll_interval' => contact_poll_interval($r[0]['priority'],(! $poll_enabled)),
288 '$poll_enabled' => $poll_enabled,
289 '$lastupdtext' => t('Last updated: '),
290 '$updpub' => t('Update public posts: '),
291 '$last_update' => $last_update,
292 '$udnow' => t('Update now'),
293 '$profile_select' => contact_profile_assign($r[0]['profile-id'],(($r[0]['network'] !== 'dfrn') ? true : false)),
294 '$contact_id' => $r[0]['id'],
295 '$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
296 '$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
297 '$insecure' => (($r[0]['network'] !== NETWORK_DFRN && $r[0]['network'] !== NETWORK_MAIL && $r[0]['network'] !== NETWORK_FACEBOOK && $r[0]['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
298 '$info' => $r[0]['info'],
299 '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
300 '$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),
301 '$photo' => $r[0]['photo'],
302 '$name' => $r[0]['name'],
303 '$dir_icon' => $dir_icon,
304 '$alt_text' => $alt_text,
305 '$sparkle' => $sparkle,
310 $arr = array('contact' => $r[0],'output' => $o);
312 call_hooks('contact_edit', $arr);
314 return $arr['output'];
319 if(($a->argc == 2) && ($a->argv[1] === 'all'))
322 $sql_extra = " AND `blocked` = 0 ";
324 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
326 $tpl = get_markup_template("contacts-top.tpl");
327 $o .= replace_macros($tpl,array(
328 '$header' => t('Contacts'),
329 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
330 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
331 '$search' => $search,
332 '$desc' => t('Search your contacts'),
333 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
334 '$submit' => t('Find'),
341 $search = dbesc($search.'*');
342 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
344 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
347 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
348 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
349 intval($_SESSION['uid']));
351 $a->set_pager_total($r[0]['total']);
353 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
354 intval($_SESSION['uid']),
355 intval($a->pager['start']),
356 intval($a->pager['itemspage'])
361 $tpl = get_markup_template("contact_template.tpl");
368 case CONTACT_IS_FRIEND:
369 $dir_icon = 'images/lrarrow.gif';
370 $alt_text = t('Mutual Friendship');
372 case CONTACT_IS_FOLLOWER;
373 $dir_icon = 'images/larrow.gif';
374 $alt_text = t('is a fan of yours');
376 case CONTACT_IS_SHARING;
377 $dir_icon = 'images/rarrow.gif';
378 $alt_text = t('you are a fan of');
383 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
384 $url = "redir/{$rr['id']}";
385 $sparkle = ' class="sparkle" ';
393 $o .= replace_macros($tpl, array(
394 '$img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
395 '$edit_hover' => t('Edit contact'),
396 '$contact_photo_menu' => contact_photo_menu($rr),
398 '$alt_text' => $alt_text,
399 '$dir_icon' => $dir_icon,
400 '$thumb' => $rr['thumb'],
401 '$name' => $rr['name'],
402 '$username' => $rr['name'],
403 '$sparkle' => $sparkle,
408 $o .= '<div id="contact-edit-end"></div>';