3 require_once('include/Contact.php');
5 function contacts_init(&$a) {
6 require_once('include/group.php');
7 $a->page['aside'] .= group_side();
9 if($a->config['register_policy'] != REGISTER_CLOSED)
10 $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>';
13 function contacts_post(&$a) {
18 $contact_id = intval($a->argv[1]);
22 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
27 if(! count($orig_record)) {
28 notice( t('Could not access contact record.') . EOL);
29 goaway($a->get_baseurl() . '/contacts');
33 $profile_id = intval($_POST['profile-assign']);
35 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
40 notice( t('Could not locate selected profile.') . EOL);
44 $priority = intval($_POST['priority']);
45 if($priority > 5 || $priority < 0)
48 $rating = intval($_POST['reputation']);
49 if($rating > 5 || $rating < 0)
52 $reason = notags(trim($_POST['reason']));
54 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `rating` = %d, `reason` = '%s'
55 WHERE `id` = %d AND `uid` = %d LIMIT 1",
64 notice( t('Contact updated.') . EOL);
66 notice( t('Failed to update contact record.') . EOL);
73 function contacts_content(&$a) {
75 $o .= '<script> $(document).ready(function() { $(\'#nav-contacts-link\').addClass(\'nav-selected\'); });</script>';
77 notice( t('Permission denied.') . EOL);
83 $contact_id = intval($a->argv[1]);
89 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
94 if(! count($orig_record)) {
95 notice( t('Could not access contact record.') . EOL);
96 goaway($a->get_baseurl() . '/contacts');
101 if($cmd == 'block') {
102 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
103 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
109 notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
111 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
112 return; // NOTREACHED
115 if($cmd == 'ignore') {
116 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
117 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
123 notice( t('Contact has been ') . (($readonly) ? t('ignored') : t('unignored')) . EOL );
125 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
126 return; // NOTREACHED
130 contact_remove($contact_id);
131 notice( t('Contact has been removed.') . EOL );
132 goaway($a->get_baseurl() . '/contacts');
133 return; // NOTREACHED
137 if(($a->argc == 2) && intval($a->argv[1])) {
139 $contact_id = intval($a->argv[1]);
140 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
145 notice( t('Contact not found.') . EOL);
149 require_once('view/contact_selectors.php');
151 $tpl = file_get_contents("view/contact_edit.tpl");
153 switch($r[0]['rel']) {
155 $dir_icon = 'images/lrarrow.gif';
156 $alt_text = t('Mutual Friendship');
159 $dir_icon = 'images/larrow.gif';
160 $alt_text = t('is a fan of yours');
164 $dir_icon = 'images/rarrow.gif';
165 $alt_text = t('you are a fan of');
171 $o .= replace_macros($tpl,array(
172 '$poll_interval' => contact_poll_interval($r[0]['priority']),
173 '$last_update' => (($r[0]['last-update'] == '0000-00-00 00:00:00')
175 : datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A')),
176 '$profile_select' => contact_profile_assign($r[0]['profile-id']),
177 '$contact_id' => $r[0]['id'],
178 '$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
179 '$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
180 '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
181 '$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),
182 '$rating' => contact_reputation($r[0]['rating']),
183 '$reason' => $r[0]['reason'],
184 '$groups' => '', // group_selector(),
185 '$photo' => $r[0]['photo'],
186 '$name' => $r[0]['name'],
187 '$dir_icon' => $dir_icon,
188 '$alt_text' => $alt_text,
189 '$url' => (($r[0]['rel'] != DIRECTION_OUT) ? "redir/{$r[0]['id']}" : $r[0]['url'] )
198 if(($a->argc == 2) && ($a->argv[1] == 'all'))
201 $sql_extra = " AND `blocked` = 0 ";
203 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
205 $tpl = file_get_contents("view/contacts-top.tpl");
206 $o .= replace_macros($tpl,array(
207 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
208 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
209 '$search' => $search,
210 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
211 '$submit' => t('Find'),
218 $search = dbesc($search.'*');
219 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
223 case DIRECTION_BOTH :
224 $sql_extra2 = " AND `dfrn-id` != '' AND `issued-id` != '' ";
227 $sql_extra2 = " AND `dfrn-id` = '' AND `issued-id` != '' ";
230 $sql_extra2 = " AND `dfrn-id` != '' AND `issued-id` = '' ";
232 case DIRECTION_NONE :
238 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
239 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
240 intval($_SESSION['uid']));
242 $a->set_pager_total($r[0]['total']);
244 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
245 intval($_SESSION['uid']),
246 intval($a->pager['start']),
247 intval($a->pager['itemspage'])
252 $tpl = file_get_contents("view/contact_template.tpl");
260 $dir_icon = 'images/lrarrow.gif';
261 $alt_text = t('Mutual Friendship');
264 $dir_icon = 'images/larrow.gif';
265 $alt_text = t('is a fan of yours');
268 $dir_icon = 'images/rarrow.gif';
269 $alt_text = t('you are a fan of');
275 $o .= replace_macros($tpl, array(
276 '$img_hover' => t('Visit ') . $rr['name'] . t('\'s profile'),
277 '$edit_hover' => t('Edit contact'),
279 '$alt_text' => $alt_text,
280 '$dir_icon' => $dir_icon,
281 '$thumb' => $rr['thumb'],
282 '$name' => $rr['name'],
283 '$url' => (($rr['rel'] != DIRECTION_OUT) ? "redir/{$rr['id']}" : $rr['url'] )
286 $o .= '<div id="contact-edit-end"></div>';