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);
45 $usehub = ((intval($_POST['usehub'])) ? 1 : 0);
46 if($orig_record[0]['usehub'] && (! $usehub)) {
47 // remove hub subscription
50 $priority = intval($_POST['priority']);
53 if($priority > 5 || $priority < 0)
56 $rating = intval($_POST['reputation']);
57 if($rating > 5 || $rating < 0)
60 $reason = notags(trim($_POST['reason']));
62 $r = q("UPDATE `contact` SET `profile-id` = %d, `usehub` = %d, `priority` = %d , `rating` = %d, `reason` = '%s'
63 WHERE `id` = %d AND `uid` = %d LIMIT 1",
73 notice( t('Contact updated.') . EOL);
75 notice( t('Failed to update contact record.') . EOL);
82 function contacts_content(&$a) {
84 $o .= '<script> $(document).ready(function() { $(\'#nav-contacts-link\').addClass(\'nav-selected\'); });</script>';
86 notice( t('Permission denied.') . EOL);
92 $contact_id = intval($a->argv[1]);
98 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
103 if(! count($orig_record)) {
104 notice( t('Could not access contact record.') . EOL);
105 goaway($a->get_baseurl() . '/contacts');
106 return; // NOTREACHED
110 if($cmd === 'block') {
111 $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
112 $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
118 notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
120 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
121 return; // NOTREACHED
124 if($cmd === 'ignore') {
125 $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
126 $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
132 notice( t('Contact has been ') . (($readonly) ? t('ignored') : t('unignored')) . EOL );
134 goaway($a->get_baseurl() . '/contacts/' . $contact_id);
135 return; // NOTREACHED
138 if($cmd === 'drop') {
139 contact_remove($contact_id);
140 notice( t('Contact has been removed.') . EOL );
141 goaway($a->get_baseurl() . '/contacts');
142 return; // NOTREACHED
146 if(($a->argc == 2) && intval($a->argv[1])) {
148 $contact_id = intval($a->argv[1]);
149 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
154 notice( t('Contact not found.') . EOL);
158 require_once('view/contact_selectors.php');
160 $tpl = load_view_file("view/contact_edit.tpl");
162 switch($r[0]['rel']) {
164 $dir_icon = 'images/lrarrow.gif';
165 $alt_text = t('Mutual Friendship');
168 $dir_icon = 'images/larrow.gif';
169 $alt_text = t('is a fan of yours');
173 $dir_icon = 'images/rarrow.gif';
174 $alt_text = t('you are a fan of');
180 if($r[0]['rel'] != REL_FAN) {
181 $url = "redir/{$r[0]['id']}";
182 $sparkle = ' class="sparkle" ';
189 $huburl = get_config('system','huburl');
198 $o .= replace_macros($tpl,array(
199 '$poll_interval' => contact_poll_interval($r[0]['priority']),
200 '$hubenable' => $hubenable,
201 '$last_update' => (($r[0]['last-update'] == '0000-00-00 00:00:00')
203 : datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A')),
204 '$profile_select' => contact_profile_assign($r[0]['profile-id']),
205 '$contact_id' => $r[0]['id'],
206 '$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
207 '$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
208 '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
209 '$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),
210 '$rating' => contact_reputation($r[0]['rating']),
211 '$reason' => $r[0]['reason'],
212 '$groups' => '', // group_selector(),
213 '$photo' => $r[0]['photo'],
214 '$name' => $r[0]['name'],
215 '$dir_icon' => $dir_icon,
216 '$alt_text' => $alt_text,
217 '$sparkle' => $sparkle,
227 if(($a->argc == 2) && ($a->argv[1] === 'all'))
230 $sql_extra = " AND `blocked` = 0 ";
232 $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
234 $tpl = load_view_file("view/contacts-top.tpl");
235 $o .= replace_macros($tpl,array(
236 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
237 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections')),
238 '$search' => $search,
239 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
240 '$submit' => t('Find'),
247 $search = dbesc($search.'*');
248 $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
250 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= REL_BUD)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
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 = load_view_file("view/contact_template.tpl");
275 $dir_icon = 'images/lrarrow.gif';
276 $alt_text = t('Mutual Friendship');
279 $dir_icon = 'images/larrow.gif';
280 $alt_text = t('is a fan of yours');
283 $dir_icon = 'images/rarrow.gif';
284 $alt_text = t('you are a fan of');
290 if($rr['rel'] != REL_FAN) {
291 $url = "redir/{$rr['id']}";
292 $sparkle = ' class="sparkle" ';
300 $o .= replace_macros($tpl, array(
301 '$img_hover' => t('Visit ') . $rr['name'] . t('\'s profile'),
302 '$edit_hover' => t('Edit contact'),
304 '$alt_text' => $alt_text,
305 '$dir_icon' => $dir_icon,
306 '$thumb' => $rr['thumb'],
307 '$name' => $rr['name'],
308 '$sparkle' => $sparkle,
312 $o .= '<div id="contact-edit-end"></div>';