]> git.mxchange.org Git - friendica.git/blob - include/acl_selectors.php
make notes work
[friendica.git] / include / acl_selectors.php
1 <?php
2
3 require_once("include/contact_selectors.php");
4 require_once("include/features.php");
5 require_once("mod/proxy.php");
6
7 /**
8  *
9  */
10
11 /**
12  * @package acl_selectors
13  */
14 function group_select($selname,$selclass,$preselected = false,$size = 4) {
15
16         $a = get_app();
17
18         $o = '';
19
20         $o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"$size\" >\r\n";
21
22         $r = q("SELECT * FROM `group` WHERE `deleted` = 0 AND `uid` = %d ORDER BY `name` ASC",
23                 intval(local_user())
24         );
25
26
27         $arr = array('group' => $r, 'entry' => $o);
28
29         // e.g. 'network_pre_group_deny', 'profile_pre_group_allow'
30
31         call_hooks($a->module . '_pre_' . $selname, $arr);
32
33         if(count($r)) {
34                 foreach($r as $rr) {
35                         if((is_array($preselected)) && in_array($rr['id'], $preselected))
36                                 $selected = " selected=\"selected\" ";
37                         else
38                                 $selected = '';
39
40                         $trimmed = mb_substr($rr['name'],0,12);
41
42                         $o .= "<option value=\"{$rr['id']}\" $selected title=\"{$rr['name']}\" >$trimmed</option>\r\n";
43                 }
44
45         }
46         $o .= "</select>\r\n";
47
48         call_hooks($a->module . '_post_' . $selname, $o);
49
50
51         return $o;
52 }
53
54
55 function contact_selector($selname, $selclass, $preselected = false, $options) {
56
57         $a = get_app();
58
59         $mutual = false;
60         $networks = null;
61         $single = false;
62         $exclude = false;
63         $size = 4;
64
65         if(is_array($options)) {
66                 if(x($options,'size'))
67                         $size = $options['size'];
68
69                 if(x($options,'mutual_friends'))
70                         $mutual = true;
71                 if(x($options,'single'))
72                         $single = true;
73                 if(x($options,'multiple'))
74                         $single = false;
75                 if(x($options,'exclude'))
76                         $exclude = $options['exclude'];
77
78                 if(x($options,'networks')) {
79                         switch($options['networks']) {
80                                 case 'DFRN_ONLY':
81                                         $networks = array(NETWORK_DFRN);
82                                         break;
83                                 case 'PRIVATE':
84                                         if(is_array($a->user) && $a->user['prvnets'])
85                                                 $networks = array(NETWORK_DFRN,NETWORK_MAIL,NETWORK_DIASPORA);
86                                         else
87                                                 $networks = array(NETWORK_DFRN,NETWORK_FACEBOOK,NETWORK_MAIL, NETWORK_DIASPORA);
88                                         break;
89                                 case 'TWO_WAY':
90                                         if(is_array($a->user) && $a->user['prvnets'])
91                                                 $networks = array(NETWORK_DFRN,NETWORK_MAIL,NETWORK_DIASPORA);
92                                         else
93                                                 $networks = array(NETWORK_DFRN,NETWORK_FACEBOOK,NETWORK_MAIL,NETWORK_DIASPORA,NETWORK_OSTATUS);
94                                         break;
95                                 default:
96                                         break;
97                         }
98                 }
99         }
100
101         $x = array('options' => $options, 'size' => $size, 'single' => $single, 'mutual' => $mutual, 'exclude' => $exclude, 'networks' => $networks);
102
103         call_hooks('contact_select_options', $x);
104
105         $o = '';
106
107         $sql_extra = '';
108
109         if($x['mutual']) {
110                 $sql_extra .= sprintf(" AND `rel` = %d ", intval(CONTACT_IS_FRIEND));
111         }
112
113         if(intval($x['exclude']))
114                 $sql_extra .= sprintf(" AND `id` != %d ", intval($x['exclude']));
115
116         if(is_array($x['networks']) && count($x['networks'])) {
117                 for($y = 0; $y < count($x['networks']) ; $y ++)
118                         $x['networks'][$y] = "'" . dbesc($x['networks'][$y]) . "'";
119                 $str_nets = implode(',',$x['networks']);
120                 $sql_extra .= " AND `network` IN ( $str_nets ) ";
121         }
122
123         $tabindex = (x($options, 'tabindex') ? "tabindex=\"" . $options["tabindex"] . "\"" : "");
124
125         if($x['single'])
126                 $o .= "<select name=\"$selname\" id=\"$selclass\" class=\"$selclass\" size=\"" . $x['size'] . "\" $tabindex >\r\n";
127         else
128                 $o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"" . $x['size'] . "$\" $tabindex >\r\n";
129
130         $r = q("SELECT `id`, `name`, `url`, `network` FROM `contact`
131                 WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != ''
132                 $sql_extra
133                 ORDER BY `name` ASC ",
134                 intval(local_user())
135         );
136
137
138         $arr = array('contact' => $r, 'entry' => $o);
139
140         // e.g. 'network_pre_contact_deny', 'profile_pre_contact_allow'
141
142         call_hooks($a->module . '_pre_' . $selname, $arr);
143
144         if(count($r)) {
145                 foreach($r as $rr) {
146                         if((is_array($preselected)) && in_array($rr['id'], $preselected))
147                                 $selected = " selected=\"selected\" ";
148                         else
149                                 $selected = '';
150
151                         $trimmed = mb_substr($rr['name'],0,20);
152
153                         $o .= "<option value=\"{$rr['id']}\" $selected title=\"{$rr['name']}|{$rr['url']}\" >$trimmed</option>\r\n";
154                 }
155
156         }
157
158         $o .= "</select>\r\n";
159
160         call_hooks($a->module . '_post_' . $selname, $o);
161
162         return $o;
163 }
164
165
166
167 function contact_select($selname, $selclass, $preselected = false, $size = 4, $privmail = false, $celeb = false, $privatenet = false, $tabindex = null) {
168
169         require_once("include/bbcode.php");
170
171         $a = get_app();
172
173         $o = '';
174
175         // When used for private messages, we limit correspondence to mutual DFRN/Friendica friends and the selector
176         // to one recipient. By default our selector allows multiple selects amongst all contacts.
177
178         $sql_extra = '';
179
180         if($privmail || $celeb) {
181                 $sql_extra .= sprintf(" AND `rel` = %d ", intval(CONTACT_IS_FRIEND));
182         }
183
184         if($privmail)
185                 $sql_extra .= sprintf(" AND `network` IN ('%s' , '%s') ",
186                                         NETWORK_DFRN, NETWORK_DIASPORA);
187         elseif($privatenet)
188                 $sql_extra .= sprintf(" AND `network` IN ('%s' , '%s', '%s', '%s') ",
189                                         NETWORK_DFRN, NETWORK_MAIL, NETWORK_FACEBOOK, NETWORK_DIASPORA);
190
191         $tabindex = ($tabindex > 0 ? "tabindex=\"$tabindex\"" : "");
192
193         if($privmail)
194                 $o .= "<select name=\"$selname\" id=\"$selclass\" class=\"$selclass\" size=\"$size\" $tabindex >\r\n";
195         else
196                 $o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"$size\" $tabindex >\r\n";
197
198         $r = q("SELECT `id`, `name`, `url`, `network` FROM `contact`
199                 WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != ''
200                 $sql_extra
201                 ORDER BY `name` ASC ",
202                 intval(local_user())
203         );
204
205
206         $arr = array('contact' => $r, 'entry' => $o);
207
208         // e.g. 'network_pre_contact_deny', 'profile_pre_contact_allow'
209
210         call_hooks($a->module . '_pre_' . $selname, $arr);
211
212         if(count($r)) {
213                 foreach($r as $rr) {
214                         if((is_array($preselected)) && in_array($rr['id'], $preselected))
215                                 $selected = " selected=\"selected\" ";
216                         else
217                                 $selected = '';
218
219                         if($privmail)
220                                 $trimmed = GetProfileUsername($rr['url'], $rr['name'], false);
221                         else
222                                 $trimmed = mb_substr($rr['name'],0,20);
223
224                         $o .= "<option value=\"{$rr['id']}\" $selected title=\"{$rr['name']}|{$rr['url']}\" >$trimmed</option>\r\n";
225                 }
226
227         }
228
229         $o .= "</select>\r\n";
230
231         call_hooks($a->module . '_post_' . $selname, $o);
232
233         return $o;
234 }
235
236
237 function fixacl(&$item) {
238         $item = intval(str_replace(array('<','>'),array('',''),$item));
239 }
240
241 function prune_deadguys($arr) {
242
243         if(! $arr)
244                 return $arr;
245         $str = dbesc(implode(',',$arr));
246         $r = q("select id from contact where id in ( " . $str . ") and blocked = 0 and pending = 0 and archive = 0 ");
247         if($r) {
248                 $ret = array();
249                 foreach($r as $rr)
250                         $ret[] = intval($rr['id']);
251                 return $ret;
252         }
253         return array();
254 }
255
256
257 function get_acl_permissions($user = null) {
258         $allow_cid = $allow_gid = $deny_cid = $deny_gid = false;
259
260         if(is_array($user)) {
261                 $allow_cid = ((strlen($user['allow_cid']))
262                         ? explode('><', $user['allow_cid']) : array() );
263                 $allow_gid = ((strlen($user['allow_gid']))
264                         ? explode('><', $user['allow_gid']) : array() );
265                 $deny_cid  = ((strlen($user['deny_cid']))
266                         ? explode('><', $user['deny_cid']) : array() );
267                 $deny_gid  = ((strlen($user['deny_gid']))
268                         ? explode('><', $user['deny_gid']) : array() );
269                 array_walk($allow_cid,'fixacl');
270                 array_walk($allow_gid,'fixacl');
271                 array_walk($deny_cid,'fixacl');
272                 array_walk($deny_gid,'fixacl');
273         }
274
275         $allow_cid = prune_deadguys($allow_cid);
276
277         return array(
278                 'allow_cid' => $allow_cid,
279                 'allow_gid' => $allow_gid,
280                 'deny_cid' => $deny_cid,
281                 'deny_gid' => $deny_gid,
282         );
283 }
284
285
286 function populate_acl($user = null,$celeb = false,$show_jotnets = false) {
287
288         $perms = get_acl_permissions($user);
289
290         $jotnets = '';
291         if($show_jotnets) {
292                 $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
293
294                 $mail_enabled = false;
295                 $pubmail_enabled = false;
296
297                 if(! $mail_disabled) {
298                         $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
299                                 intval(local_user())
300                         );
301                         if(count($r)) {
302                                 $mail_enabled = true;
303                                 if(intval($r[0]['pubmail']))
304                                         $pubmail_enabled = true;
305                         }
306                 }
307
308                 if (!$user['hidewall']) {
309                         if($mail_enabled) {
310                                 $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
311                                 $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> ' . t("Post to Email") . '</div>';
312                         }
313
314                         call_hooks('jot_networks', $jotnets);
315                 } else
316                         $jotnets .= sprintf(t('Connectors disabled, since "%s" is enabled.'),
317                                             t('Hide your profile details from unknown viewers?'));
318                 }
319
320         // We shouldn't need to prune deadguys from the block list. Either way they can't get the message.
321         // Also no point enumerating groups and checking them, that will take place on delivery.
322
323 //      $deny_cid = prune_deadguys($deny_cid);
324
325
326         /*$o = '';
327         $o .= '<div id="acl-wrapper">';
328         $o .= '<div id="acl-permit-outer-wrapper">';
329         $o .= '<div id="acl-permit-text">' . t('Visible To:') . '</div><div id="jot-public">' . t('everybody') . '</div>';
330         $o .= '<div id="acl-permit-text-end"></div>';
331         $o .= '<div id="acl-permit-wrapper">';
332         $o .= '<div id="group_allow_wrapper">';
333         $o .= '<label id="acl-allow-group-label" for="group_allow" >' . t('Groups') . '</label>';
334         $o .= group_select('group_allow','group_allow',$allow_gid);
335         $o .= '</div>';
336         $o .= '<div id="contact_allow_wrapper">';
337         $o .= '<label id="acl-allow-contact-label" for="contact_allow" >' . t('Contacts') . '</label>';
338         $o .= contact_select('contact_allow','contact_allow',$allow_cid,4,false,$celeb,true);
339         $o .= '</div>';
340         $o .= '</div>' . "\r\n";
341         $o .= '<div id="acl-allow-end"></div>' . "\r\n";
342         $o .= '</div>';
343         $o .= '<div id="acl-deny-outer-wrapper">';
344         $o .= '<div id="acl-deny-text">' . t('Except For:') . '</div>';
345         $o .= '<div id="acl-deny-text-end"></div>';
346         $o .= '<div id="acl-deny-wrapper">';
347         $o .= '<div id="group_deny_wrapper" >';
348         $o .= '<label id="acl-deny-group-label" for="group_deny" >' . t('Groups') . '</label>';
349         $o .= group_select('group_deny','group_deny', $deny_gid);
350         $o .= '</div>';
351         $o .= '<div id="contact_deny_wrapper" >';
352         $o .= '<label id="acl-deny-contact-label" for="contact_deny" >' . t('Contacts') . '</label>';
353         $o .= contact_select('contact_deny','contact_deny', $deny_cid,4,false, $celeb,true);
354         $o .= '</div>';
355         $o .= '</div>' . "\r\n";
356         $o .= '<div id="acl-deny-end"></div>' . "\r\n";
357         $o .= '</div>';
358         $o .= '</div>' . "\r\n";
359         $o .= '<div id="acl-wrapper-end"></div>' . "\r\n";*/
360
361         $tpl = get_markup_template("acl_selector.tpl");
362         $o = replace_macros($tpl, array(
363                 '$showall'=> t("Visible to everybody"),
364                 '$show'          => t("show"),
365                 '$hide'          => t("don't show"),
366                 '$allowcid' => json_encode($perms['allow_cid']),
367                 '$allowgid' => json_encode($perms['allow_gid']),
368                 '$denycid' => json_encode($perms['deny_cid']),
369                 '$denygid' => json_encode($perms['deny_gid']),
370                 '$networks' => $show_jotnets,
371                 '$emailcc' => t('CC: email addresses'),
372                 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
373                 '$jotnets' => $jotnets,
374                 '$aclModalTitle' => t('Permissions'),
375                 '$aclModalDismiss' => t('Close'),
376                 '$features' => array(
377                 "aclautomention"=>(feature_enabled($user['uid'],"aclautomention")?"true":"false")
378                 ),
379         ));
380
381
382         return $o;
383
384 }
385
386 function construct_acl_data(&$a, $user) {
387
388         // Get group and contact information for html ACL selector
389         $acl_data = acl_lookup($a, 'html');
390
391         $user_defaults = get_acl_permissions($user);
392
393         if($acl_data['groups']) {
394                 foreach($acl_data['groups'] as $key=>$group) {
395                         // Add a "selected" flag to groups that are posted to by default
396                         if($user_defaults['allow_gid'] &&
397                            in_array($group['id'], $user_defaults['allow_gid']) && !in_array($group['id'], $user_defaults['deny_gid']) )
398                                 $acl_data['groups'][$key]['selected'] = 1;
399                         else
400                                 $acl_data['groups'][$key]['selected'] = 0;
401                 }
402         }
403         if($acl_data['contacts']) {
404                 foreach($acl_data['contacts'] as $key=>$contact) {
405                         // Add a "selected" flag to groups that are posted to by default
406                         if($user_defaults['allow_cid'] &&
407                            in_array($contact['id'], $user_defaults['allow_cid']) && !in_array($contact['id'], $user_defaults['deny_cid']) )
408                                 $acl_data['contacts'][$key]['selected'] = 1;
409                         else
410                                 $acl_data['contacts'][$key]['selected'] = 0;
411                 }
412         }
413
414         return $acl_data;
415
416 }
417
418 function acl_lookup(&$a, $out_type = 'json') {
419
420         if(!local_user())
421                 return "";
422
423
424         $start = (x($_REQUEST,'start')?$_REQUEST['start']:0);
425         $count = (x($_REQUEST,'count')?$_REQUEST['count']:100);
426         $search = (x($_REQUEST,'search')?$_REQUEST['search']:"");
427         $type = (x($_REQUEST,'type')?$_REQUEST['type']:"");
428         $conv_id = (x($_REQUEST,'conversation')?$_REQUEST['conversation']:null);
429
430         // For use with jquery.autocomplete for private mail completion
431
432         if(x($_REQUEST,'query') && strlen($_REQUEST['query'])) {
433                 if(! $type)
434                         $type = 'm';
435                 $search = $_REQUEST['query'];
436         }
437
438
439         if ($search!=""){
440                 $sql_extra = "AND `name` LIKE '%%".dbesc($search)."%%'";
441                 $sql_extra2 = "AND (`attag` LIKE '%%".dbesc($search)."%%' OR `name` LIKE '%%".dbesc($search)."%%' OR `nick` LIKE '%%".dbesc($search)."%%')";
442         } else {
443                 $sql_extra = $sql_extra2 = "";
444         }
445
446         // count groups and contacts
447         if ($type=='' || $type=='g'){
448                 $r = q("SELECT COUNT(*) AS g FROM `group` WHERE `deleted` = 0 AND `uid` = %d $sql_extra",
449                         intval(local_user())
450                 );
451                 $group_count = (int)$r[0]['g'];
452         } else {
453                 $group_count = 0;
454         }
455
456         if ($type=='' || $type=='c'){
457                 $r = q("SELECT COUNT(*) AS c FROM `contact`
458                                 WHERE `uid` = %d AND `self` = 0
459                                 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0
460                                 AND `notify` != '' $sql_extra2" ,
461                         intval(local_user())
462                 );
463                 $contact_count = (int)$r[0]['c'];
464         }
465         elseif ($type == 'm') {
466
467                 // autocomplete for Private Messages
468
469                 $r = q("SELECT COUNT(*) AS c FROM `contact`
470                                 WHERE `uid` = %d AND `self` = 0
471                                 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0
472                                 AND `network` IN ('%s','%s','%s') $sql_extra2" ,
473                         intval(local_user()),
474                         dbesc(NETWORK_DFRN),
475                         dbesc(NETWORK_ZOT),
476                         dbesc(NETWORK_DIASPORA)
477                 );
478                 $contact_count = (int)$r[0]['c'];
479
480         }
481         elseif ($type == 'a') {
482
483                 // autocomplete for Contacts
484
485                 $r = q("SELECT COUNT(*) AS c FROM `contact`
486                                 WHERE `uid` = %d AND `self` = 0
487                                 AND `pending` = 0 $sql_extra2" ,
488                         intval(local_user())
489                 );
490                 $contact_count = (int)$r[0]['c'];
491
492         } else {
493                 $contact_count = 0;
494         }
495
496
497         $tot = $group_count+$contact_count;
498
499         $groups = array();
500         $contacts = array();
501
502         if ($type=='' || $type=='g'){
503
504                 $r = q("SELECT `group`.`id`, `group`.`name`, GROUP_CONCAT(DISTINCT `group_member`.`contact-id` SEPARATOR ',') as uids
505                                 FROM `group`,`group_member`
506                                 WHERE `group`.`deleted` = 0 AND `group`.`uid` = %d
507                                         AND `group_member`.`gid`=`group`.`id`
508                                         $sql_extra
509                                 GROUP BY `group`.`id`
510                                 ORDER BY `group`.`name`
511                                 LIMIT %d,%d",
512                         intval(local_user()),
513                         intval($start),
514                         intval($count)
515                 );
516
517                 foreach($r as $g){
518 //              logger('acl: group: ' . $g['name'] . ' members: ' . $g['uids']);
519                         $groups[] = array(
520                                 "type"  => "g",
521                                 "photo" => "images/twopeople.png",
522                                 "name"  => $g['name'],
523                                 "id"    => intval($g['id']),
524                                 "uids"  => array_map("intval", explode(",",$g['uids'])),
525                                 "link"  => '',
526                                 "forum" => '0'
527                         );
528                 }
529         }
530
531         if ($type=='' || $type=='c'){
532
533                 $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, forum FROM `contact`
534                         WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != ''
535                         $sql_extra2
536                         ORDER BY `name` ASC ",
537                         intval(local_user())
538                 );
539         }
540         elseif($type == 'm') {
541                 $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact`
542                         WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0
543                         AND `network` IN ('%s','%s','%s')
544                         $sql_extra2
545                         ORDER BY `name` ASC ",
546                         intval(local_user()),
547                         dbesc(NETWORK_DFRN),
548                         dbesc(NETWORK_ZOT),
549                         dbesc(NETWORK_DIASPORA)
550                 );
551         }
552         elseif($type == 'a') {
553                 $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact`
554                         WHERE `uid` = %d AND `pending` = 0
555                         $sql_extra2
556                         ORDER BY `name` ASC ",
557                         intval(local_user())
558                 );
559         }
560         else
561                 $r = array();
562
563
564         if($type == 'm' || $type == 'a') {
565                 $x = array();
566                 $x['query'] = $search;
567                 $x['photos'] = array();
568                 $x['links'] = array();
569                 $x['suggestions'] = array();
570                 $x['data'] = array();
571                 if(count($r)) {
572                         foreach($r as $g) {
573                                 $x['photos'][] = proxy_url($g['micro']);
574                                 $x['links'][] = $g['url'];
575                                 $x['suggestions'][] = $g['name'];
576                                 $x['data'][] = intval($g['id']);
577                         }
578                 }
579                 echo json_encode($x);
580                 killme();
581         }
582
583         if(count($r)) {
584                 foreach($r as $g){
585                         $contacts[] = array(
586                                 "type"  => "c",
587                                 "photo" => proxy_url($g['micro']),
588                                 "name"  => $g['name'],
589                                 "id"    => intval($g['id']),
590                                 "network" => $g['network'],
591                                 "link" => $g['url'],
592                                 "nick" => ($g['attag']) ? $g['attag'] : $g['nick'],
593                                 "forum" => $g['forum']
594                         );
595                 }
596         }
597
598         $items = array_merge($groups, $contacts);
599
600         if ($conv_id) {
601                 /* if $conv_id is set, get unknow contacts in thread */
602                 /* but first get know contacts url to filter them out */
603                 function _contact_link($i){ return dbesc($i['link']); }
604                 $known_contacts = array_map(_contact_link, $contacts);
605                 $unknow_contacts=array();
606                 $r = q("select
607                                         `author-avatar`,`author-name`,`author-link`
608                                 from item where parent=%d
609                                 and (
610                                         `author-name` LIKE '%%%s%%' OR
611                                         `author-link` LIKE '%%%s%%'
612                                 ) and
613                                 `author-link` NOT IN ('%s')
614                                 GROUP BY `author-link`
615                                 ORDER BY `author-name` ASC
616                                 ",
617                                 intval($conv_id),
618                                 dbesc($search),
619                                 dbesc($search),
620                                 implode("','", $known_contacts)
621                 );
622                 if (is_array($r) && count($r)){
623                         foreach($r as $row) {
624                                 // nickname..
625                                 $up = parse_url($row['author-link']);
626                                 $nick = explode("/",$up['path']);
627                                 $nick = $nick[count($nick)-1];
628                                 $nick .= "@".$up['host'];
629                                 // /nickname
630                                 $unknow_contacts[] = array(
631                                         "type"  => "c",
632                                         "photo" => proxy_url($row['author-avatar']),
633                                         "name"  => $row['author-name'],
634                                         "id"    => '',
635                                         "network" => "unknown",
636                                         "link" => $row['author-link'],
637                                         "nick" => $nick,
638                                         "forum" => false
639                                 );
640                         }
641                 }
642
643                 $items = array_merge($items, $unknow_contacts);
644                 $tot += count($unknow_contacts);
645         }
646
647         if($out_type === 'html') {
648                 $o = array(
649                         'tot'           => $tot,
650                         'start' => $start,
651                         'count' => $count,
652                         'groups'        => $groups,
653                         'contacts'      => $contacts,
654                 );
655                 return $o;
656         }
657
658         $o = array(
659                 'tot'   => $tot,
660                 'start' => $start,
661                 'count' => $count,
662                 'items' => $items,
663         );
664
665         echo json_encode($o);
666
667         killme();
668 }
669