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);
46 $priority = intval($_POST['priority']);
49 if($priority > 5 || $priority < 0)
52 $rating = intval($_POST['reputation']);
53 if($rating > 5 || $rating < 0)
56 $reason = notags(trim($_POST['reason']));
58 $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `rating` = %d, `reason` = '%s'
59 WHERE `id` = %d AND `uid` = %d LIMIT 1",
68 notice( t('Contact updated.') . EOL);
70 notice( t('Failed to update contact record.') . EOL);
77 function contacts_content(&$a) {
79 $o .= '<script> $(document).ready(function() { $(\'#nav-contacts-link\').addClass(\'nav-selected\'); });</script>';
81 notice( t('Permission denied.') . EOL);
87 $contact_id = intval($a->argv[1]);
93 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
98 if(! count($orig_record)) {
99 notice( t('Could not access contact record.') . EOL);
100 goaway($a->get_baseurl() . '/contacts');
101 return; // NOTREACHED
105 if($cmd === 'block') {
106 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
107 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
113 notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
115 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
116 return; // NOTREACHED
119 if($cmd === 'ignore') {
120 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
121 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
127 notice( t('Contact has been ') . (($readonly) ? t('ignored') : t('unignored')) . EOL );
129 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
130 return; // NOTREACHED
133 if($cmd === 'drop') {
134 contact_remove($contact_id);
135 notice( t('Contact has been removed.') . EOL );
136 goaway($a->get_baseurl() . '/contacts');
137 return; // NOTREACHED
141 if(($a->argc == 2) && intval($a->argv[1])) {
143 $contact_id = intval($a->argv[1]);
144 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
145 intval(local_user()),
149 notice( t('Contact not found.') . EOL);
153 require_once('view/contact_selectors.php');
155 $tpl = load_view_file("view/contact_edit.tpl");
157 switch($r[0]['rel']) {
159 $dir_icon = 'images/lrarrow.gif';
160 $alt_text = t('Mutual Friendship');
163 $dir_icon = 'images/larrow.gif';
164 $alt_text = t('is a fan of yours');
168 $dir_icon = 'images/rarrow.gif';
169 $alt_text = t('you are a fan of');
175 if(($r[0]['network'] === 'dfrn') && ($r[0]['rel'])) {
176 $url = "redir/{$r[0]['id']}";
177 $sparkle = ' class="sparkle" ';
184 $o .= replace_macros($tpl,array(
185 '$poll_interval' => contact_poll_interval($r[0]['priority']),
186 '$last_update' => (($r[0]['last-update'] == '0000-00-00 00:00:00')
188 : datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A')),
189 '$profile_select' => contact_profile_assign($r[0]['profile-id']),
190 '$contact_id' => $r[0]['id'],
191 '$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
192 '$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
193 '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
194 '$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),
195 '$rating' => contact_reputation($r[0]['rating']),
196 '$reason' => $r[0]['reason'],
197 '$groups' => '', // group_selector(),
198 '$photo' => $r[0]['photo'],
199 '$name' => $r[0]['name'],
200 '$dir_icon' => $dir_icon,
201 '$alt_text' => $alt_text,
202 '$sparkle' => $sparkle,
212 if(($a->argc == 2) && ($a->argv[1] === 'all'))
215 $sql_extra = " AND `blocked` = 0 ";
217 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
219 $tpl = load_view_file("view/contacts-top.tpl");
220 $o .= replace_macros($tpl,array(
221 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
222 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
223 '$search' => $search,
224 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
225 '$submit' => t('Find'),
232 $search = dbesc($search.'*');
233 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
235 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= REL_BUD)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
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 = load_view_file("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 if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
276 $url = "redir/{$rr['id']}";
277 $sparkle = ' class="sparkle" ';
285 $o .= replace_macros($tpl, array(
286 '$img_hover' => t('Visit ') . $rr['name'] . t('\'s profile'),
287 '$edit_hover' => t('Edit contact'),
289 '$alt_text' => $alt_text,
290 '$dir_icon' => $dir_icon,
291 '$thumb' => $rr['thumb'],
292 '$name' => $rr['name'],
293 '$sparkle' => $sparkle,
297 $o .= '<div id="contact-edit-end"></div>';