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) {
76 notice( t('Permission denied.') . EOL);
82 $contact_id = intval($a->argv[1]);
88 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
93 if(! count($orig_record)) {
94 notice( t('Could not access contact record.') . EOL);
95 goaway($a->get_baseurl() . '/contacts');
100 if($cmd == 'block') {
101 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
102 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
108 notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
110 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
111 return; // NOTREACHED
114 if($cmd == 'ignore') {
115 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
116 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
122 notice( t('Contact has been ') . (($readonly) ? t('ignored') : t('unignored')) . EOL );
124 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
125 return; // NOTREACHED
129 contact_remove($contact_id);
130 notice( t('Contact has been removed.') . EOL );
131 goaway($a->get_baseurl() . '/contacts');
132 return; // NOTREACHED
136 if(($a->argc == 2) && intval($a->argv[1])) {
138 $contact_id = intval($a->argv[1]);
139 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
144 notice( t('Contact not found.') . EOL);
148 require_once('view/contact_selectors.php');
150 $tpl = file_get_contents("view/contact_edit.tpl");
152 switch($r[0]['rel']) {
154 $dir_icon = 'images/lrarrow.gif';
155 $alt_text = t('Mutual Friendship');
158 $dir_icon = 'images/larrow.gif';
159 $alt_text = t('is a fan of yours');
163 $dir_icon = 'images/rarrow.gif';
164 $alt_text = t('you are a fan of');
170 $o .= replace_macros($tpl,array(
171 '$poll_interval' => contact_poll_interval($r[0]['priority']),
172 '$last_update' => (($r[0]['last-update'] == '0000-00-00 00:00:00')
174 : datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A')),
175 '$profile_select' => contact_profile_assign($r[0]['profile-id']),
176 '$contact_id' => $r[0]['id'],
177 '$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
178 '$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
179 '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
180 '$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),
181 '$rating' => contact_reputation($r[0]['rating']),
182 '$reason' => $r[0]['reason'],
183 '$groups' => '', // group_selector(),
184 '$photo' => $r[0]['photo'],
185 '$name' => $r[0]['name'],
186 '$dir_icon' => $dir_icon,
187 '$alt_text' => $alt_text,
188 '$url' => (($r[0]['rel'] != DIRECTION_OUT) ? "redir/{$r[0]['id']}" : $r[0]['url'] )
197 if(($a->argc == 2) && ($a->argv[1] == 'all'))
200 $sql_extra = " AND `blocked` = 0 ";
202 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
204 $tpl = file_get_contents("view/contacts-top.tpl");
205 $o .= replace_macros($tpl,array(
206 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
207 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
208 '$search' => $search,
209 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
210 '$submit' => t('Find'),
217 $search = dbesc($search.'*');
218 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
222 case DIRECTION_BOTH :
223 $sql_extra2 = " AND `dfrn-id` != '' AND `issued-id` != '' ";
226 $sql_extra2 = " AND `dfrn-id` = '' AND `issued-id` != '' ";
229 $sql_extra2 = " AND `dfrn-id` != '' AND `issued-id` = '' ";
231 case DIRECTION_NONE :
237 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
238 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
239 intval($_SESSION['uid']));
241 $a->set_pager_total($r[0]['total']);
243 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
244 intval($_SESSION['uid']),
245 intval($a->pager['start']),
246 intval($a->pager['itemspage'])
251 $tpl = file_get_contents("view/contact_template.tpl");
259 $dir_icon = 'images/lrarrow.gif';
260 $alt_text = t('Mutual Friendship');
263 $dir_icon = 'images/larrow.gif';
264 $alt_text = t('is a fan of yours');
267 $dir_icon = 'images/rarrow.gif';
268 $alt_text = t('you are a fan of');
274 $o .= replace_macros($tpl, array(
275 '$img_hover' => t('Visit ') . $rr['name'] . t('\'s profile'),
276 '$edit_hover' => t('Edit contact'),
278 '$alt_text' => $alt_text,
279 '$dir_icon' => $dir_icon,
280 '$thumb' => $rr['thumb'],
281 '$name' => $rr['name'],
282 '$url' => (($rr['rel'] != DIRECTION_OUT) ? "redir/{$rr['id']}" : $rr['url'] )
285 $o .= '<div id="contact-edit-end"></div>';