]> git.mxchange.org Git - friendica.git/blob - mod/contacts.php
438b37aaf3714aca340e01cc37ee001bbec80c14
[friendica.git] / mod / contacts.php
1 <?php
2
3 require_once('include/Contact.php');
4
5 function contacts_init(&$a) {
6         require_once('include/group.php');
7         $a->page['aside'] .= group_side();
8
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>';
11 }
12
13 function contacts_post(&$a) {
14         
15         if(! local_user())
16                 return;
17
18         $contact_id = intval($a->argv[1]);
19         if(! $contact_id)
20                 return;
21
22         $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
23                 intval($contact_id),
24                 intval(get_uid())
25         );
26
27         if(! count($orig_record)) {
28                 notice( t('Could not access contact record.') . EOL);
29                 goaway($a->get_baseurl() . '/contacts');
30                 return; // NOTREACHED
31         }
32
33         $profile_id = intval($_POST['profile-assign']);
34         if($profile_id) {
35                 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
36                         intval($profile_id),
37                         intval(get_uid())
38                 );
39                 if(! count($r)) {
40                         notice( t('Could not locate selected profile.') . EOL);
41                         return;
42                 }
43         }
44         $priority = intval($_POST['priority']);
45         if($priority > 5 || $priority < 0)
46                 $priority = 0;
47
48         $rating = intval($_POST['reputation']);
49         if($rating > 5 || $rating < 0)
50                 $rating = 0;
51
52         $reason = notags(trim($_POST['reason']));
53
54         $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `rating` = %d, `reason` = '%s'
55                 WHERE `id` = %d AND `uid` = %d LIMIT 1",
56                 intval($profile_id),
57                 intval($priority),
58                 intval($rating),
59                 dbesc($reason),
60                 intval($contact_id),
61                 intval(get_uid())
62         );
63         if($r)
64                 notice( t('Contact updated.') . EOL);
65         else
66                 notice( t('Failed to update contact record.') . EOL);
67         return;
68
69 }
70
71
72
73 function contacts_content(&$a) {
74
75         $o .= '<script> $(document).ready(function() { $(\'#nav-contacts-link\').addClass(\'nav-selected\'); });</script>';
76         if(! local_user()) {
77                 notice( t('Permission denied.') . EOL);
78                 return;
79         }
80
81         if($a->argc == 3) {
82
83                 $contact_id = intval($a->argv[1]);
84                 if(! $contact_id)
85                         return;
86
87                 $cmd = $a->argv[2];
88
89                 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
90                         intval($contact_id),
91                         intval(get_uid())
92                 );
93
94                 if(! count($orig_record)) {
95                         notice( t('Could not access contact record.') . EOL);
96                         goaway($a->get_baseurl() . '/contacts');
97                         return; // NOTREACHED
98                 }
99
100
101                 if($cmd === 'block') {
102                         $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
103                         $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
104                                         intval($blocked),
105                                         intval($contact_id),
106                                         intval(get_uid())
107                         );
108                         if($r) {
109                                 notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
110                         }
111                         goaway($a->get_baseurl() . '/contacts/' . $contact_id);
112                         return; // NOTREACHED
113                 }
114
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",
118                                         intval($readonly),
119                                         intval($contact_id),
120                                         intval(get_uid())
121                         );
122                         if($r) {
123                                 notice( t('Contact has been ') . (($readonly) ? t('ignored') : t('unignored')) . EOL );
124                         }
125                         goaway($a->get_baseurl() . '/contacts/' . $contact_id);
126                         return; // NOTREACHED
127                 }
128
129                 if($cmd === 'drop') {
130                         contact_remove($contact_id);
131                         notice( t('Contact has been removed.') . EOL );
132                         goaway($a->get_baseurl() . '/contacts');
133                         return; // NOTREACHED
134                 }
135         }
136
137         if(($a->argc == 2) && intval($a->argv[1])) {
138
139                 $contact_id = intval($a->argv[1]);
140                 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
141                         intval(get_uid()),
142                         intval($contact_id)
143                 );
144                 if(! count($r)) {
145                         notice( t('Contact not found.') . EOL);
146                         return;
147                 }
148
149                 require_once('view/contact_selectors.php');
150
151                 $tpl = load_view_file("view/contact_edit.tpl");
152
153                 switch($r[0]['rel']) {
154                         case REL_BUD:
155                                 $dir_icon = 'images/lrarrow.gif';
156                                 $alt_text = t('Mutual Friendship');
157                                 break;
158                         case REL_VIP;
159                                 $dir_icon = 'images/larrow.gif';
160                                 $alt_text = t('is a fan of yours');
161                                 break;
162         
163                         case REL_FAN;
164                                 $dir_icon = 'images/rarrow.gif';
165                                 $alt_text = t('you are a fan of');
166                                 break;
167                         default:
168                                 break;
169                 }
170
171                 if($r[0]['rel'] != REL_FAN) {
172                         $url = "redir/{$r[0]['id']}";
173                         $sparkle = ' class="sparkle" ';
174                 }
175                 else { 
176                         $url = $r[0]['url'];
177                         $sparkle = '';
178                 }
179                 $o .= replace_macros($tpl,array(
180                         '$poll_interval' => contact_poll_interval($r[0]['priority']),
181                         '$last_update' => (($r[0]['last-update'] == '0000-00-00 00:00:00') 
182                                 ? t('Never') 
183                                 : datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A')),
184                         '$profile_select' => contact_profile_assign($r[0]['profile-id']),
185                         '$contact_id' => $r[0]['id'],
186                         '$block_text' => (($r[0]['blocked']) ? t('Unblock this contact') : t('Block this contact') ),
187                         '$ignore_text' => (($r[0]['readonly']) ? t('Unignore this contact') : t('Ignore this contact') ),
188                         '$blocked' => (($r[0]['blocked']) ? '<div id="block-message">' . t('Currently blocked') . '</div>' : ''),
189                         '$ignored' => (($r[0]['readonly']) ? '<div id="ignore-message">' . t('Currently ignored') . '</div>' : ''),
190                         '$rating' => contact_reputation($r[0]['rating']),
191                         '$reason' => $r[0]['reason'],
192                         '$groups' => '', // group_selector(),
193                         '$photo' => $r[0]['photo'],
194                         '$name' => $r[0]['name'],
195                         '$dir_icon' => $dir_icon,
196                         '$alt_text' => $alt_text,
197                         '$sparkle' => $sparkle,
198                         '$url' => $url
199
200                 ));
201
202                 return $o;
203
204         }
205
206
207         if(($a->argc == 2) && ($a->argv[1] === 'all'))
208                 $sql_extra = '';
209         else
210                 $sql_extra = " AND `blocked` = 0 ";
211
212         $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
213
214         $tpl = load_view_file("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')),
218                 '$search' => $search,
219                 '$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : ""),
220                 '$submit' => t('Find'),
221                 '$cmd' => $a->cmd
222
223
224         )); 
225
226         if($search)
227                 $search = dbesc($search.'*');
228         $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
229
230         $sql_extra2 = ((($sort_type > 0) && ($sort_type <= REL_BUD)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : ''); 
231
232         
233         $r = q("SELECT COUNT(*) AS `total` FROM `contact` 
234                 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
235                 intval($_SESSION['uid']));
236         if(count($r))
237                 $a->set_pager_total($r[0]['total']);
238
239         $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
240                 intval($_SESSION['uid']),
241                 intval($a->pager['start']),
242                 intval($a->pager['itemspage'])
243         );
244
245         if(count($r)) {
246
247                 $tpl = load_view_file("view/contact_template.tpl");
248
249                 foreach($r as $rr) {
250                         if($rr['self'])
251                                 continue;
252
253                         switch($rr['rel']) {
254                                 case REL_BUD:
255                                         $dir_icon = 'images/lrarrow.gif';
256                                         $alt_text = t('Mutual Friendship');
257                                         break;
258                                 case  REL_VIP;
259                                         $dir_icon = 'images/larrow.gif';
260                                         $alt_text = t('is a fan of yours');
261                                         break;
262                                 case REL_FAN;
263                                         $dir_icon = 'images/rarrow.gif';
264                                         $alt_text = t('you are a fan of');
265                                         break;
266                                 default:
267                                         break;
268                         }
269
270                         if($rr['rel'] != REL_FAN) {
271                                 $url = "redir/{$rr['id']}";
272                                 $sparkle = ' class="sparkle" ';
273                         }
274                         else { 
275                                 $url = $rr['url'];
276                                 $sparkle = '';
277                         }
278
279
280                         $o .= replace_macros($tpl, array(
281                                 '$img_hover' => t('Visit ') . $rr['name'] . t('\'s profile'),
282                                 '$edit_hover' => t('Edit contact'),
283                                 '$id' => $rr['id'],
284                                 '$alt_text' => $alt_text,
285                                 '$dir_icon' => $dir_icon,
286                                 '$thumb' => $rr['thumb'], 
287                                 '$name' => $rr['name'],
288                                 '$sparkle' => $sparkle,
289                                 '$url' => $url
290                         ));
291                 }
292                 $o .= '<div id="contact-edit-end"></div>';
293
294         }
295         $o .= paginate($a);
296         return $o;
297 }