3 function contacts_init(&$a) {
4 require_once('include/group.php');
5 $a->page['aside'] .= group_side();
7 if($a->config['register_policy'] != REGISTER_CLOSED)
8 $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>';
11 function contacts_post(&$a) {
17 $contact_id = intval($a->argv[1]);
21 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
23 intval($_SESSION['uid'])
26 if(! count($orig_record)) {
27 notice("Could not access contact record." . EOL);
28 goaway($a->get_baseurl() . '/contacts');
32 $profile_id = intval($_POST['profile-assign']);
34 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
36 intval($_SESSION['uid'])
39 notice( t('Could not locate selected profile.') . EOL);
43 $priority = intval($_POST['priority']);
44 if($priority > 5 || $priority < 0)
47 $rating = intval($_POST['reputation']);
48 if($rating > 5 || $rating < 0)
51 $reason = notags(trim($_POST['reason']));
53 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `rating` = %d, `reason` = '%s'
54 WHERE `id` = %d AND `uid` = %d LIMIT 1",
60 intval($_SESSION['uid'])
63 notice( t('Contact updated.') . EOL);
65 notice( t('Failed to update contact record.') . EOL);
72 function contacts_content(&$a) {
75 notice( t('Permission denied.') . EOL);
81 $contact_id = intval($a->argv[1]);
87 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
89 intval($_SESSION['uid'])
92 if(! count($orig_record)) {
93 notice( t('Could not access contact record.') . EOL);
94 goaway($a->get_baseurl() . '/contacts');
100 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
101 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
104 intval($_SESSION['uid'])
107 $msg = 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",
119 intval($_SESSION['uid'])
122 $msg = t('Contact has been ') . (($readonly) ? t('ignored') : t('unignored')) . EOL ;
125 goaway($a->get_baseurl() ."/contacts/$contact_id");
126 return; // NOTREACHED
130 $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
132 intval($_SESSION['uid'])
135 q("DELETE FROM `item` WHERE `contact-id` = %d AND `uid` = %d ",
137 intval($_SESSION['uid'])
139 q("DELETE FROM `photo` WHERE `contact-id` = %d AND `uid` = %d ",
142 intval($_SESSION['uid'])
145 notice( t('Contact has been removed.') . EOL );
146 goaway($a->get_baseurl() . '/contacts');
147 return; // NOTREACHED
151 if(($a->argc == 2) && intval($a->argv[1])) {
153 $contact_id = intval($a->argv[1]);
154 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
159 notice( t('Contact not found.') . EOL);
163 require_once('view/contact_selectors.php');
165 $tpl = file_get_contents("view/contact_edit.tpl");
168 if(strlen($r[0]['issued-id'])) {
169 if(strlen($r[0]['dfrn-id'])) {
170 $direction = DIRECTION_BOTH;
171 $dir_icon = 'images/lrarrow.gif';
172 $alt_text = t('Mutual Friendship');
175 $direction = DIRECTION_IN;
176 $dir_icon = 'images/larrow.gif';
177 $alt_text = t('is a fan of yours');
181 $direction = DIRECTION_OUT;
182 $dir_icon = 'images/rarrow.gif';
183 $alt_text = t('you are a fan of');
186 $o .= replace_macros($tpl,array(
187 '$poll_interval' => contact_poll_interval($r[0]['priority']),
188 '$last_update' => (($r[0]['last-update'] == '0000-00-00 00:00:00')
190 : datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A')),
191 '$profile_select' => contact_profile_assign($r[0]['profile-id']),
192 '$contact_id' => $r[0]['id'],
193 '$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
194 '$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
195 '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
196 '$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),
197 '$rating' => contact_reputation($r[0]['rating']),
198 '$reason' => $r[0]['reason'],
199 '$groups' => '', // group_selector(),
200 '$photo' => $r[0]['photo'],
201 '$name' => $r[0]['name'],
202 '$dir_icon' => $dir_icon,
203 '$alt_text' => $alt_text,
204 '$url' => (($direction != DIRECTION_OUT) ? "redir/{$r[0]['id']}" : $r[0]['url'] )
213 if(($a->argc == 2) && ($a->argv[1] == 'all'))
216 $sql_extra = " AND `blocked` = 0 ";
218 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
220 $tpl = file_get_contents("view/contacts-top.tpl");
221 $o .= replace_macros($tpl,array(
222 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
223 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
224 '$search' => $search,
225 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
226 '$submit' => t('Find'),
233 $search = dbesc($search.'*');
234 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
238 case DIRECTION_BOTH :
239 $sql_extra2 = " AND `dfrn-id` != '' AND `issued-id` != '' ";
242 $sql_extra2 = " AND `dfrn-id` = '' AND `issued-id` != '' ";
245 $sql_extra2 = " AND `dfrn-id` != '' AND `issued-id` = '' ";
247 case DIRECTION_NONE :
253 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
254 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
255 intval($_SESSION['uid']));
257 $a->set_pager_total($r[0]['total']);
259 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
260 intval($_SESSION['uid']),
261 intval($a->pager['start']),
262 intval($a->pager['itemspage'])
267 $tpl = file_get_contents("view/contact_template.tpl");
273 if(strlen($rr['issued-id'])) {
274 if(strlen($rr['dfrn-id'])) {
275 $direction = DIRECTION_BOTH;
276 $dir_icon = 'images/lrarrow.gif';
277 $alt_text = t('Mutual Friendship');
280 $direction = DIRECTION_IN;
281 $dir_icon = 'images/larrow.gif';
282 $alt_text = t('is a fan of yours');
286 $direction = DIRECTION_OUT;
287 $dir_icon = 'images/rarrow.gif';
288 $alt_text = t('you are a fan of');
291 $o .= replace_macros($tpl, array(
292 '$img_hover' => t('Visit ') . $rr['name'] . t('\'s profile'),
293 '$edit_hover' => t('Edit contact'),
295 '$alt_text' => $alt_text,
296 '$dir_icon' => $dir_icon,
297 '$thumb' => $rr['thumb'],
298 '$name' => $rr['name'],
299 '$url' => (($direction != DIRECTION_OUT) ? "redir/{$rr['id']}" : $rr['url'] )
302 $o .= '<div id="contact-edit-end"></div>';