]> git.mxchange.org Git - friendica.git/blob - mod/contacts.php
bd5bf8ea80b9c56d3acbf4d55aa342a1224b6673
[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(local_user())
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(local_user())
38                 );
39                 if(! count($r)) {
40                         notice( t('Could not locate selected profile.') . EOL);
41                         return;
42                 }
43         }
44
45
46         $priority = intval($_POST['priority']);
47         if($priority == (-1))
48                 
49         if($priority > 5 || $priority < 0)
50                 $priority = 0;
51
52         $rating = intval($_POST['reputation']);
53         if($rating > 5 || $rating < 0)
54                 $rating = 0;
55
56         $reason = notags(trim($_POST['reason']));
57
58         $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `rating` = %d, `reason` = '%s'
59                 WHERE `id` = %d AND `uid` = %d LIMIT 1",
60                 intval($profile_id),
61                 intval($priority),
62                 intval($rating),
63                 dbesc($reason),
64                 intval($contact_id),
65                 intval(local_user())
66         );
67         if($r)
68                 notice( t('Contact updated.') . EOL);
69         else
70                 notice( t('Failed to update contact record.') . EOL);
71         return;
72
73 }
74
75
76
77 function contacts_content(&$a) {
78
79         $o .= '<script> $(document).ready(function() { $(\'#nav-contacts-link\').addClass(\'nav-selected\'); });</script>';
80         if(! local_user()) {
81                 notice( t('Permission denied.') . EOL);
82                 return;
83         }
84
85         if($a->argc == 3) {
86
87                 $contact_id = intval($a->argv[1]);
88                 if(! $contact_id)
89                         return;
90
91                 $cmd = $a->argv[2];
92
93                 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
94                         intval($contact_id),
95                         intval(local_user())
96                 );
97
98                 if(! count($orig_record)) {
99                         notice( t('Could not access contact record.') . EOL);
100                         goaway($a->get_baseurl() . '/contacts');
101                         return; // NOTREACHED
102                 }
103
104
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",
108                                         intval($blocked),
109                                         intval($contact_id),
110                                         intval(local_user())
111                         );
112                         if($r) {
113                                 notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
114                         }
115                         goaway($a->get_baseurl() . '/contacts/' . $contact_id);
116                         return; // NOTREACHED
117                 }
118
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",
122                                         intval($readonly),
123                                         intval($contact_id),
124                                         intval(local_user())
125                         );
126                         if($r) {
127                                 notice( t('Contact has been ') . (($readonly) ? t('ignored') : t('unignored')) . EOL );
128                         }
129                         goaway($a->get_baseurl() . '/contacts/' . $contact_id);
130                         return; // NOTREACHED
131                 }
132
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
138                 }
139         }
140
141         if(($a->argc == 2) && intval($a->argv[1])) {
142
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()),
146                         intval($contact_id)
147                 );
148                 if(! count($r)) {
149                         notice( t('Contact not found.') . EOL);
150                         return;
151                 }
152
153                 require_once('view/contact_selectors.php');
154
155                 $tpl = load_view_file("view/contact_edit.tpl");
156
157                 switch($r[0]['rel']) {
158                         case REL_BUD:
159                                 $dir_icon = 'images/lrarrow.gif';
160                                 $alt_text = t('Mutual Friendship');
161                                 break;
162                         case REL_VIP;
163                                 $dir_icon = 'images/larrow.gif';
164                                 $alt_text = t('is a fan of yours');
165                                 break;
166         
167                         case REL_FAN;
168                                 $dir_icon = 'images/rarrow.gif';
169                                 $alt_text = t('you are a fan of');
170                                 break;
171                         default:
172                                 break;
173                 }
174
175                 if(($r[0]['network'] === 'dfrn') && ($r[0]['rel'])) {
176                         $url = "redir/{$r[0]['id']}";
177                         $sparkle = ' class="sparkle" ';
178                 }
179                 else { 
180                         $url = $r[0]['url'];
181                         $sparkle = '';
182                 }
183
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') 
187                                 ? t('Never') 
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,
203                         '$url' => $url
204
205                 ));
206
207                 return $o;
208
209         }
210
211
212         if(($a->argc == 2) && ($a->argv[1] === 'all'))
213                 $sql_extra = '';
214         else
215                 $sql_extra = " AND `blocked` = 0 ";
216
217         $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
218
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'),
226                 '$cmd' => $a->cmd
227
228
229         )); 
230
231         if($search)
232                 $search = dbesc($search.'*');
233         $sql_extra .= ((strlen($search)) ? " AND MATCH `name` AGAINST ('$search' IN BOOLEAN MODE) " : "");
234
235         $sql_extra2 = ((($sort_type > 0) && ($sort_type <= REL_BUD)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : ''); 
236
237         
238         $r = q("SELECT COUNT(*) AS `total` FROM `contact` 
239                 WHERE `uid` = %d AND `pending` = 0 $sql_extra $sql_extra2 ",
240                 intval($_SESSION['uid']));
241         if(count($r))
242                 $a->set_pager_total($r[0]['total']);
243
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'])
248         );
249
250         if(count($r)) {
251
252                 $tpl = load_view_file("view/contact_template.tpl");
253
254                 foreach($r as $rr) {
255                         if($rr['self'])
256                                 continue;
257
258                         switch($rr['rel']) {
259                                 case REL_BUD:
260                                         $dir_icon = 'images/lrarrow.gif';
261                                         $alt_text = t('Mutual Friendship');
262                                         break;
263                                 case  REL_VIP;
264                                         $dir_icon = 'images/larrow.gif';
265                                         $alt_text = t('is a fan of yours');
266                                         break;
267                                 case REL_FAN;
268                                         $dir_icon = 'images/rarrow.gif';
269                                         $alt_text = t('you are a fan of');
270                                         break;
271                                 default:
272                                         break;
273                         }
274                         if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
275                                 $url = "redir/{$rr['id']}";
276                                 $sparkle = ' class="sparkle" ';
277                         }
278                         else { 
279                                 $url = $rr['url'];
280                                 $sparkle = '';
281                         }
282
283
284                         $o .= replace_macros($tpl, array(
285                                 '$img_hover' => t('Visit ') . $rr['name'] . t('\'s profile'),
286                                 '$edit_hover' => t('Edit contact'),
287                                 '$id' => $rr['id'],
288                                 '$alt_text' => $alt_text,
289                                 '$dir_icon' => $dir_icon,
290                                 '$thumb' => $rr['thumb'], 
291                                 '$name' => $rr['name'],
292                                 '$sparkle' => $sparkle,
293                                 '$url' => $url
294                         ));
295                 }
296                 $o .= '<div id="contact-edit-end"></div>';
297
298         }
299         $o .= paginate($a);
300         return $o;
301 }