3 require_once('include/Contact.php');
5 function contacts_init(&$a) {
6 require_once('include/group.php');
7 if(! x($a->page,'aside'))
8 $a->page['aside'] = '';
9 $a->page['aside'] .= group_side();
11 if($a->config['register_policy'] != REGISTER_CLOSED)
12 $a->page['aside'] .= '<div class="side-invite-link-wrapper" id="side-invite-link-wrapper" ><a href="invite" class="side-invite-link" id="side-invite-link">' . t("Invite Friends") . '</a></div>';
14 $tpl = load_view_file('view/follow.tpl');
15 $a->page['aside'] .= replace_macros($tpl,array(
16 '$label' => t('Connect/Follow'),
17 '$hint' => t('Example: bob@example.com, http://example.com/barbara'),
18 '$follow' => t('Follow')
23 function contacts_post(&$a) {
28 $contact_id = intval($a->argv[1]);
32 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
37 if(! count($orig_record)) {
38 notice( t('Could not access contact record.') . EOL);
39 goaway($a->get_baseurl() . '/contacts');
43 call_hooks('contact_edit_post', $_POST);
45 $profile_id = intval($_POST['profile-assign']);
47 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
52 notice( t('Could not locate selected profile.') . EOL);
56 logger('contact_edit ' . print_r($_POST,true));
58 $priority = intval($_POST['poll']);
61 if($priority > 5 || $priority < 0)
64 $rating = intval($_POST['reputation']);
65 if($rating > 5 || $rating < 0)
68 $reason = notags(trim($_POST['reason']));
70 $info = escape_tags(trim($_POST['info']));
72 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `rating` = %d, `reason` = '%s', `info` = '%s'
73 WHERE `id` = %d AND `uid` = %d LIMIT 1",
83 notice( t('Contact updated.') . EOL);
85 notice( t('Failed to update contact record.') . EOL);
92 function contacts_content(&$a) {
96 $o .= '<script> $(document).ready(function() { $(\'#nav-contacts-link\').addClass(\'nav-selected\'); });</script>';
98 $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
101 notice( t('Permission denied.') . EOL);
107 $contact_id = intval($a->argv[1]);
113 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
118 if(! count($orig_record)) {
119 notice( t('Could not access contact record.') . EOL);
120 goaway($a->get_baseurl() . '/contacts');
121 return; // NOTREACHED
124 if($cmd === 'update') {
126 // pull feed and consume it, which should subscribe to the hub.
127 proc_run('php',"include/poller.php","$contact_id");
128 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
132 if($cmd === 'block') {
133 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
134 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
140 //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
141 notice( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
143 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
144 return; // NOTREACHED
147 if($cmd === 'ignore') {
148 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
149 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
155 notice( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
157 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
158 return; // NOTREACHED
161 if($cmd === 'drop') {
163 // create an unfollow slap
165 if($orig_record[0]['network'] === 'stat') {
166 $tpl = load_view_file('view/follow_slap.tpl');
167 $slap = replace_macros($tpl, array(
168 '$name' => $a->user['username'],
169 '$profile_page' => $a->get_baseurl() . '/profile/' . $a->user['nickname'],
170 '$photo' => $a->contact['photo'],
171 '$thumb' => $a->contact['thumb'],
172 '$published' => datetime_convert('UTC','UTC', 'now', ATOM_TIME),
173 '$item_id' => 'urn:X-dfrn:' . $a->get_hostname() . ':unfollow:' . random_string(),
176 '$content' => t('stopped following'),
177 '$nick' => $a->user['nickname'],
178 '$verb' => ACTIVITY_UNFOLLOW,
179 '$ostat_follow' => '<as:verb>http://ostatus.org/schema/1.0/unfollow</as:verb>' . "\r\n"
182 if((x($orig_record[0],'notify')) && (strlen($orig_record[0]['notify']))) {
183 require_once('include/salmon.php');
184 slapper($a->user,$orig_record[0]['notify'],$slap);
188 if($orig_record[0]['network'] === 'dfrn') {
189 require_once('include/items.php');
190 dfrn_deliver($a->user,$orig_record[0],'placeholder', 1);
194 contact_remove($contact_id);
195 notice( t('Contact has been removed.') . EOL );
196 goaway($a->get_baseurl() . '/contacts');
197 return; // NOTREACHED
201 if(($a->argc == 2) && intval($a->argv[1])) {
203 $contact_id = intval($a->argv[1]);
204 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
205 intval(local_user()),
209 notice( t('Contact not found.') . EOL);
213 $tpl = load_view_file('view/contact_head.tpl');
214 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
216 require_once('include/contact_selectors.php');
218 $tpl = load_view_file("view/contact_edit.tpl");
220 switch($r[0]['rel']) {
222 $dir_icon = 'images/lrarrow.gif';
223 $alt_text = t('Mutual Friendship');
226 $dir_icon = 'images/larrow.gif';
227 $alt_text = t('is a fan of yours');
231 $dir_icon = 'images/rarrow.gif';
232 $alt_text = t('you are a fan of');
238 if(($r[0]['network'] === 'dfrn') && ($r[0]['rel'])) {
239 $url = "redir/{$r[0]['id']}";
240 $sparkle = ' class="sparkle" ';
247 $insecure = '<div id="profile-edit-insecure"><p><img src="images/unlock_icon.gif" alt="' . t('Privacy Unavailable') . '" /> '
248 . t('Private communications are not available for this contact.') . '</p></div>';
250 $last_update = (($r[0]['last-update'] == '0000-00-00 00:00:00')
252 : datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A'));
254 if($r[0]['last-update'] !== '0000-00-00 00:00:00')
255 $last_update .= ' ' . (($r[0]['last-update'] == $r[0]['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
257 $o .= replace_macros($tpl,array(
258 '$header' => t('Contact Editor'),
259 '$visit' => t('Visit $name\'s profile'),
260 '$blockunblock' => t('Block/Unblock contact'),
261 '$ignorecont' => t('Ignore contact'),
262 '$delete' => t('Delete contact'),
263 '$poll_interval' => contact_poll_interval($r[0]['priority']),
264 '$lastupdtext' => t('Last updated: '),
265 '$updpub' => t('Update public posts: '),
266 '$last_update' => $last_update,
267 '$udnow' => t('Update now'),
268 '$profile_select' => contact_profile_assign($r[0]['profile-id'],(($r[0]['network'] !== 'dfrn') ? true : false)),
269 '$contact_id' => $r[0]['id'],
270 '$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
271 '$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
272 '$insecure' => (($r[0]['network'] !== 'dfrn') ? $insecure : ''),
273 '$info' => $r[0]['info'],
274 '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
275 '$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),
276 '$rating' => contact_reputation($r[0]['rating']),
277 '$reason' => $r[0]['reason'],
278 '$groups' => '', // group_selector(),
279 '$photo' => $r[0]['photo'],
280 '$name' => $r[0]['name'],
281 '$dir_icon' => $dir_icon,
282 '$alt_text' => $alt_text,
283 '$sparkle' => $sparkle,
288 $arr = array('contact' => $r[0],'output' => $o);
290 call_hooks('contact_edit', $arr);
292 return $arr['output'];
297 if(($a->argc == 2) && ($a->argv[1] === 'all'))
300 $sql_extra = " AND `blocked` = 0 ";
302 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
304 $tpl = load_view_file("view/contacts-top.tpl");
305 $o .= replace_macros($tpl,array(
306 '$header' => t('Contacts'),
307 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
308 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
309 '$search' => $search,
310 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
311 '$submit' => t('Find'),
318 $search = dbesc($search.'*');
319 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
321 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= REL_BUD)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
324 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
325 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
326 intval($_SESSION['uid']));
328 $a->set_pager_total($r[0]['total']);
330 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
331 intval($_SESSION['uid']),
332 intval($a->pager['start']),
333 intval($a->pager['itemspage'])
338 $tpl = load_view_file("view/contact_template.tpl");
346 $dir_icon = 'images/lrarrow.gif';
347 $alt_text = t('Mutual Friendship');
350 $dir_icon = 'images/larrow.gif';
351 $alt_text = t('is a fan of yours');
354 $dir_icon = 'images/rarrow.gif';
355 $alt_text = t('you are a fan of');
360 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
361 $url = "redir/{$rr['id']}";
362 $sparkle = ' class="sparkle" ';
370 $o .= replace_macros($tpl, array(
371 '$img_hover' => t('Visit $username\'s profile'),
372 '$edit_hover' => t('Edit contact'),
374 '$alt_text' => $alt_text,
375 '$dir_icon' => $dir_icon,
376 '$thumb' => $rr['thumb'],
377 '$name' => substr($rr['name'],0,20),
378 '$username' => $rr['name'],
379 '$sparkle' => $sparkle,
384 $o .= '<div id="contact-edit-end"></div>';