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 '$rating' => contact_reputation($r[0]['rating']),
195 '$reason' => $r[0]['reason'],
196 '$groups' => '', // group_selector(),
197 '$photo' => $r[0]['photo'],
198 '$name' => $r[0]['name'],
199 '$dir_icon' => $dir_icon,
200 '$alt_text' => $alt_text,
201 '$url' => (($direction != DIRECTION_IN) ? "redir/{$r[0]['id']}" : $r[0]['url'] )
209 if(($a->argc == 2) && ($a->argv[1] == 'all'))
212 $sql_extra = " AND `blocked` = 0 ";
214 $tpl = file_get_contents("view/contacts-top.tpl");
215 $o .= replace_macros($tpl,array(
216 '$hide_url' => ((strlen($sql_extra)) ? 'contacts/all' : 'contacts' ),
217 '$hide_text' => ((strlen($sql_extra)) ? t('Show Blocked Connections') : t('Hide Blocked Connections'))
221 case DIRECTION_BOTH :
222 $sql_extra2 = " AND `dfrn-id` != '' AND `issued-id` != '' ";
225 $sql_extra2 = " AND `dfrn-id` = '' AND `issued-id` != '' ";
228 $sql_extra2 = " AND `dfrn-id` != '' AND `issued-id` = '' ";
236 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
237 intval($_SESSION['uid']));
241 $tpl = file_get_contents("view/contact_template.tpl");
247 if(strlen($rr['issued-id'])) {
248 if(strlen($rr['dfrn-id'])) {
249 $direction = DIRECTION_BOTH;
250 $dir_icon = 'images/lrarrow.gif';
251 $alt_text = t('Mutual Friendship');
254 $direction = DIRECTION_IN;
255 $dir_icon = 'images/larrow.gif';
256 $alt_text = t('is a fan of yours');
260 $direction = DIRECTION_OUT;
261 $dir_icon = 'images/rarrow.gif';
262 $alt_text = t('you are a fan of');
265 $o .= replace_macros($tpl, array(
267 '$alt_text' => $alt_text,
268 '$dir_icon' => $dir_icon,
269 '$thumb' => $rr['thumb'],
270 '$name' => $rr['name'],
271 '$url' => (($direction != DIRECTION_IN) ? "redir/{$rr['id']}" : $rr['url'] )