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 [profile address]'),
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 $profile_id = intval($_POST['profile-assign']);
45 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
50 notice( t('Could not locate selected profile.') . EOL);
56 $priority = intval($_POST['priority']);
59 if($priority > 5 || $priority < 0)
62 $rating = intval($_POST['reputation']);
63 if($rating > 5 || $rating < 0)
66 $reason = notags(trim($_POST['reason']));
68 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `rating` = %d, `reason` = '%s'
69 WHERE `id` = %d AND `uid` = %d LIMIT 1",
78 notice( t('Contact updated.') . EOL);
80 notice( t('Failed to update contact record.') . EOL);
87 function contacts_content(&$a) {
91 $o .= '<script> $(document).ready(function() { $(\'#nav-contacts-link\').addClass(\'nav-selected\'); });</script>';
93 $_SESSION['return_url'] = $a->get_baseurl() . '/' . $a->cmd;
96 notice( t('Permission denied.') . EOL);
102 $contact_id = intval($a->argv[1]);
108 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
113 if(! count($orig_record)) {
114 notice( t('Could not access contact record.') . EOL);
115 goaway($a->get_baseurl() . '/contacts');
116 return; // NOTREACHED
120 if($cmd === 'block') {
121 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
122 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
128 notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
130 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
131 return; // NOTREACHED
134 if($cmd === 'ignore') {
135 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
136 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
142 notice( t('Contact has been ') . (($readonly) ? t('ignored') : t('unignored')) . EOL );
144 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
145 return; // NOTREACHED
148 if($cmd === 'drop') {
149 contact_remove($contact_id);
150 notice( t('Contact has been removed.') . EOL );
151 goaway($a->get_baseurl() . '/contacts');
152 return; // NOTREACHED
156 if(($a->argc == 2) && intval($a->argv[1])) {
158 $contact_id = intval($a->argv[1]);
159 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
160 intval(local_user()),
164 notice( t('Contact not found.') . EOL);
169 require_once('include/contact_selectors.php');
171 $tpl = load_view_file("view/contact_edit.tpl");
173 switch($r[0]['rel']) {
175 $dir_icon = 'images/lrarrow.gif';
176 $alt_text = t('Mutual Friendship');
179 $dir_icon = 'images/larrow.gif';
180 $alt_text = t('is a fan of yours');
184 $dir_icon = 'images/rarrow.gif';
185 $alt_text = t('you are a fan of');
191 if(($r[0]['network'] === 'dfrn') && ($r[0]['rel'])) {
192 $url = "redir/{$r[0]['id']}";
193 $sparkle = ' class="sparkle" ';
200 $o .= replace_macros($tpl,array(
201 '$poll_interval' => contact_poll_interval($r[0]['priority']),
202 '$last_update' => (($r[0]['last-update'] == '0000-00-00 00:00:00')
204 : datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A')),
205 '$profile_select' => contact_profile_assign($r[0]['profile-id'],(($r[0]['network'] !== 'dfrn') ? true : false)),
206 '$contact_id' => $r[0]['id'],
207 '$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
208 '$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
209 '$insecure' => (($r[0]['network'] === 'dfrn') ? '' : load_view_file('view/insecure_net.tpl')),
210 '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
211 '$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),
212 '$rating' => contact_reputation($r[0]['rating']),
213 '$reason' => $r[0]['reason'],
214 '$groups' => '', // group_selector(),
215 '$photo' => $r[0]['photo'],
216 '$name' => $r[0]['name'],
217 '$dir_icon' => $dir_icon,
218 '$alt_text' => $alt_text,
219 '$sparkle' => $sparkle,
229 if(($a->argc == 2) && ($a->argv[1] === 'all'))
232 $sql_extra = " AND `blocked` = 0 ";
234 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
236 $tpl = load_view_file("view/contacts-top.tpl");
237 $o .= replace_macros($tpl,array(
238 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
239 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
240 '$search' => $search,
241 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
242 '$submit' => t('Find'),
249 $search = dbesc($search.'*');
250 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
252 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= REL_BUD)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
255 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
256 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
257 intval($_SESSION['uid']));
259 $a->set_pager_total($r[0]['total']);
261 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
262 intval($_SESSION['uid']),
263 intval($a->pager['start']),
264 intval($a->pager['itemspage'])
269 $tpl = load_view_file("view/contact_template.tpl");
277 $dir_icon = 'images/lrarrow.gif';
278 $alt_text = t('Mutual Friendship');
281 $dir_icon = 'images/larrow.gif';
282 $alt_text = t('is a fan of yours');
285 $dir_icon = 'images/rarrow.gif';
286 $alt_text = t('you are a fan of');
291 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
292 $url = "redir/{$rr['id']}";
293 $sparkle = ' class="sparkle" ';
301 $o .= replace_macros($tpl, array(
302 '$img_hover' => t('Visit ') . $rr['name'] . t('\'s profile'),
303 '$edit_hover' => t('Edit contact'),
305 '$alt_text' => $alt_text,
306 '$dir_icon' => $dir_icon,
307 '$thumb' => $rr['thumb'],
308 '$name' => $rr['name'],
309 '$sparkle' => $sparkle,
313 $o .= '<div id="contact-edit-end"></div>';