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 $rating = intval($_POST['reputation']);
44 if($rating > 5 || $rating < 0)
47 $reason = notags(trim($_POST['reason']));
49 $r = q("UPDATE `contact` SET `profile-id` = %d, `rating` = %d, `reason` = '%s'
50 WHERE `id` = %d AND `uid` = %d LIMIT 1",
55 intval($_SESSION['uid'])
58 notice( t('Contact updated.') . EOL);
60 notice( t('Failed to update contact record.') . EOL);
67 function contacts_content(&$a) {
70 notice( t('Permission denied.') . EOL);
76 $contact_id = intval($a->argv[1]);
82 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
84 intval($_SESSION['uid'])
87 if(! count($orig_record)) {
88 notice( t('Could not access contact record.') . EOL);
89 goaway($a->get_baseurl() . '/contacts');
94 // $photo = str_replace('-4.jpg', '' , $r[0]['photo']);
95 // $photos = q("SELECT `id` FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d",
97 // intval($_SESSION['uid'])
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",
105 intval($_SESSION['uid'])
108 $msg = 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",
120 intval($_SESSION['uid'])
123 $msg = t('Contact has been ') . (($readonly) ? t('ignored') : t('unignored')) . EOL ;
126 goaway($a->get_baseurl() ."/contacts/$contact_id");
127 return; // NOTREACHED
131 $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
133 intval($_SESSION['uid']));
135 // if(count($photos)) {
136 // foreach($photos as $p) {
137 // q("DELETE FROM `photos` WHERE `id` = %d LIMIT 1",
142 if(intval($contact_id))
143 q("DELETE FROM `item` WHERE `contact-id` = %d LIMIT 1",
147 notice("Contact has been removed." . EOL );
148 goaway($a->get_baseurl() . '/contacts');
149 return; // NOTREACHED
153 if(($a->argc == 2) && intval($a->argv[1])) {
155 $contact_id = intval($a->argv[1]);
156 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
161 notice( t('Contact not found.') . EOL);
165 require_once('view/contact_selectors.php');
167 $tpl = file_get_contents("view/contact_edit.tpl");
170 if(strlen($r[0]['issued-id'])) {
171 if(strlen($r[0]['dfrn-id'])) {
172 $direction = DIRECTION_BOTH;
173 $dir_icon = 'images/lrarrow.gif';
174 $alt_text = t('Mutual Friendship');
177 $direction = DIRECTION_IN;
178 $dir_icon = 'images/larrow.gif';
179 $alt_text = t('is a fan of yours');
183 $direction = DIRECTION_OUT;
184 $dir_icon = 'images/rarrow.gif';
185 $alt_text = t('you are a fan of');
188 $o .= replace_macros($tpl,array(
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 '$url' => (($direction != DIRECTION_IN) ? "redir/{$r[0]['id']}" : $r[0]['url'] )
210 if(($a->argc == 2) && ($a->argv[1] == 'all'))
213 $sql_extra = " AND `blocked` = 0 ";
215 $tpl = file_get_contents("view/contacts-top.tpl");
216 $o .= replace_macros($tpl,array(
217 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
218 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections'))
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` = '' ";
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 ",
244 intval($_SESSION['uid']));
248 $tpl = file_get_contents("view/contact_template.tpl");
254 if(strlen($rr['issued-id'])) {
255 if(strlen($rr['dfrn-id'])) {
256 $direction = DIRECTION_BOTH;
257 $dir_icon = 'images/lrarrow.gif';
258 $alt_text = t('Mutual Friendship');
261 $direction = DIRECTION_IN;
262 $dir_icon = 'images/larrow.gif';
263 $alt_text = t('is a fan of yours');
267 $direction = DIRECTION_OUT;
268 $dir_icon = 'images/rarrow.gif';
269 $alt_text = t('you are a fan of');
272 $o .= replace_macros($tpl, array(
273 '$img_hover' => t('Visit ') . $rr['name'] . t('\'s profile'),
274 '$edit_hover' => t('Edit contact'),
276 '$alt_text' => $alt_text,
277 '$dir_icon' => $dir_icon,
278 '$thumb' => $rr['thumb'],
279 '$name' => $rr['name'],
280 '$url' => (($direction != DIRECTION_IN) ? "redir/{$rr['id']}" : $rr['url'] )
283 $o .= '<div id="contact-edit-end"></div>';