]> git.mxchange.org Git - friendica.git/blob - include/acl_selectors.php
some more work to get acl data into populate_acl
[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($mail_enabled) {
309                         $selected = (($pubmail_enabled) ? ' checked="checked" ' : '');
310                         $jotnets .= '<div class="profile-jot-net"><input type="checkbox" name="pubmail_enable"' . $selected . ' value="1" /> '
311                         . t("Post to Email") . '</div>';
312                 }
313
314                 call_hooks('jot_networks', $jotnets);
315         }
316
317         // We shouldn't need to prune deadguys from the block list. Either way they can't get the message.
318         // Also no point enumerating groups and checking them, that will take place on delivery.
319
320 //      $deny_cid = prune_deadguys($deny_cid);
321
322
323         /*$o = '';
324         $o .= '<div id="acl-wrapper">';
325         $o .= '<div id="acl-permit-outer-wrapper">';
326         $o .= '<div id="acl-permit-text">' . t('Visible To:') . '</div><div id="jot-public">' . t('everybody') . '</div>';
327         $o .= '<div id="acl-permit-text-end"></div>';
328         $o .= '<div id="acl-permit-wrapper">';
329         $o .= '<div id="group_allow_wrapper">';
330         $o .= '<label id="acl-allow-group-label" for="group_allow" >' . t('Groups') . '</label>';
331         $o .= group_select('group_allow','group_allow',$allow_gid);
332         $o .= '</div>';
333         $o .= '<div id="contact_allow_wrapper">';
334         $o .= '<label id="acl-allow-contact-label" for="contact_allow" >' . t('Contacts') . '</label>';
335         $o .= contact_select('contact_allow','contact_allow',$allow_cid,4,false,$celeb,true);
336         $o .= '</div>';
337         $o .= '</div>' . "\r\n";
338         $o .= '<div id="acl-allow-end"></div>' . "\r\n";
339         $o .= '</div>';
340         $o .= '<div id="acl-deny-outer-wrapper">';
341         $o .= '<div id="acl-deny-text">' . t('Except For:') . '</div>';
342         $o .= '<div id="acl-deny-text-end"></div>';
343         $o .= '<div id="acl-deny-wrapper">';
344         $o .= '<div id="group_deny_wrapper" >';
345         $o .= '<label id="acl-deny-group-label" for="group_deny" >' . t('Groups') . '</label>';
346         $o .= group_select('group_deny','group_deny', $deny_gid);
347         $o .= '</div>';
348         $o .= '<div id="contact_deny_wrapper" >';
349         $o .= '<label id="acl-deny-contact-label" for="contact_deny" >' . t('Contacts') . '</label>';
350         $o .= contact_select('contact_deny','contact_deny', $deny_cid,4,false, $celeb,true);
351         $o .= '</div>';
352         $o .= '</div>' . "\r\n";
353         $o .= '<div id="acl-deny-end"></div>' . "\r\n";
354         $o .= '</div>';
355         $o .= '</div>' . "\r\n";
356         $o .= '<div id="acl-wrapper-end"></div>' . "\r\n";*/
357
358         $tpl = get_markup_template("acl_selector.tpl");
359         $o = replace_macros($tpl, array(
360                 '$showall'=> t("Visible to everybody"),
361                 '$show'          => t("show"),
362                 '$hide'          => t("don't show"),
363                 '$allowcid' => json_encode($perms['allow_cid']),
364                 '$allowgid' => json_encode($perms['allow_gid']),
365                 '$denycid' => json_encode($perms['deny_cid']),
366                 '$denygid' => json_encode($perms['deny_gid']),
367                 '$networks' => $show_jotnets,
368                 '$emailcc' => t('CC: email addresses'),
369                 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
370                 '$jotnets' => $jotnets,
371                 '$aclModalTitle' => t('Permissions'),
372                 '$aclModalDismiss' => t('Close'),
373                 '$features' => array(
374                         "aclautomention"=>(feature_enabled($user['uid'],"aclautomention")?"true":"false")
375                 ),
376         ));
377
378
379         return $o;
380
381 }
382
383 function construct_acl_data(&$a, $user) {
384
385         // Get group and contact information for html ACL selector
386         $acl_data = acl_lookup($a, 'html');
387
388         $user_defaults = get_acl_permissions($user);
389
390         if($acl_data['groups']) {
391                 foreach($acl_data['groups'] as $key=>$group) {
392                         // Add a "selected" flag to groups that are posted to by default
393                         if($user_defaults['allow_gid'] &&
394                            in_array($group['id'], $user_defaults['allow_gid']) && !in_array($group['id'], $user_defaults['deny_gid']) )
395                                 $acl_data['groups'][$key]['selected'] = 1;
396                         else
397                                 $acl_data['groups'][$key]['selected'] = 0;
398                 }
399         }
400         if($acl_data['contacts']) {
401                 foreach($acl_data['contacts'] as $key=>$contact) {
402                         // Add a "selected" flag to groups that are posted to by default
403                         if($user_defaults['allow_cid'] &&
404                            in_array($contact['id'], $user_defaults['allow_cid']) && !in_array($contact['id'], $user_defaults['deny_cid']) )
405                                 $acl_data['contacts'][$key]['selected'] = 1;
406                         else
407                                 $acl_data['contacts'][$key]['selected'] = 0;
408                 }
409         }
410
411         return $acl_data;
412
413 }
414
415 function acl_lookup(&$a, $out_type = 'json') {
416
417         if(!local_user())
418                 return "";
419
420
421         $start = (x($_REQUEST,'start')?$_REQUEST['start']:0);
422         $count = (x($_REQUEST,'count')?$_REQUEST['count']:100);
423         $search = (x($_REQUEST,'search')?$_REQUEST['search']:"");
424         $type = (x($_REQUEST,'type')?$_REQUEST['type']:"");
425         $conv_id = (x($_REQUEST,'conversation')?$_REQUEST['conversation']:null);
426
427         // For use with jquery.autocomplete for private mail completion
428
429         if(x($_REQUEST,'query') && strlen($_REQUEST['query'])) {
430                 if(! $type)
431                         $type = 'm';
432                 $search = $_REQUEST['query'];
433         }
434
435
436         if ($search!=""){
437                 $sql_extra = "AND `name` LIKE '%%".dbesc($search)."%%'";
438                 $sql_extra2 = "AND (`attag` LIKE '%%".dbesc($search)."%%' OR `name` LIKE '%%".dbesc($search)."%%' OR `nick` LIKE '%%".dbesc($search)."%%')";
439         } else {
440                 $sql_extra = $sql_extra2 = "";
441         }
442
443         // count groups and contacts
444         if ($type=='' || $type=='g'){
445                 $r = q("SELECT COUNT(*) AS g FROM `group` WHERE `deleted` = 0 AND `uid` = %d $sql_extra",
446                         intval(local_user())
447                 );
448                 $group_count = (int)$r[0]['g'];
449         } else {
450                 $group_count = 0;
451         }
452
453         if ($type=='' || $type=='c'){
454                 $r = q("SELECT COUNT(*) AS c FROM `contact`
455                                 WHERE `uid` = %d AND `self` = 0
456                                 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0
457                                 AND `notify` != '' $sql_extra2" ,
458                         intval(local_user())
459                 );
460                 $contact_count = (int)$r[0]['c'];
461         }
462         elseif ($type == 'm') {
463
464                 // autocomplete for Private Messages
465
466                 $r = q("SELECT COUNT(*) AS c FROM `contact`
467                                 WHERE `uid` = %d AND `self` = 0
468                                 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0
469                                 AND `network` IN ('%s','%s','%s') $sql_extra2" ,
470                         intval(local_user()),
471                         dbesc(NETWORK_DFRN),
472                         dbesc(NETWORK_ZOT),
473                         dbesc(NETWORK_DIASPORA)
474                 );
475                 $contact_count = (int)$r[0]['c'];
476
477         }
478         elseif ($type == 'a') {
479
480                 // autocomplete for Contacts
481
482                 $r = q("SELECT COUNT(*) AS c FROM `contact`
483                                 WHERE `uid` = %d AND `self` = 0
484                                 AND `pending` = 0 $sql_extra2" ,
485                         intval(local_user())
486                 );
487                 $contact_count = (int)$r[0]['c'];
488
489         } else {
490                 $contact_count = 0;
491         }
492
493
494         $tot = $group_count+$contact_count;
495
496         $groups = array();
497         $contacts = array();
498
499         if ($type=='' || $type=='g'){
500
501                 $r = q("SELECT `group`.`id`, `group`.`name`, GROUP_CONCAT(DISTINCT `group_member`.`contact-id` SEPARATOR ',') as uids
502                                 FROM `group`,`group_member`
503                                 WHERE `group`.`deleted` = 0 AND `group`.`uid` = %d
504                                         AND `group_member`.`gid`=`group`.`id`
505                                         $sql_extra
506                                 GROUP BY `group`.`id`
507                                 ORDER BY `group`.`name`
508                                 LIMIT %d,%d",
509                         intval(local_user()),
510                         intval($start),
511                         intval($count)
512                 );
513
514                 foreach($r as $g){
515 //              logger('acl: group: ' . $g['name'] . ' members: ' . $g['uids']);
516                         $groups[] = array(
517                                 "type"  => "g",
518                                 "photo" => "images/twopeople.png",
519                                 "name"  => $g['name'],
520                                 "id"    => intval($g['id']),
521                                 "uids"  => array_map("intval", explode(",",$g['uids'])),
522                                 "link"  => '',
523                                 "forum" => '0'
524                         );
525                 }
526         }
527
528         if ($type=='' || $type=='c'){
529
530                 $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, forum FROM `contact`
531                         WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != ''
532                         $sql_extra2
533                         ORDER BY `name` ASC ",
534                         intval(local_user())
535                 );
536         }
537         elseif($type == 'm') {
538                 $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact`
539                         WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0
540                         AND `network` IN ('%s','%s','%s')
541                         $sql_extra2
542                         ORDER BY `name` ASC ",
543                         intval(local_user()),
544                         dbesc(NETWORK_DFRN),
545                         dbesc(NETWORK_ZOT),
546                         dbesc(NETWORK_DIASPORA)
547                 );
548         }
549         elseif($type == 'a') {
550                 $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact`
551                         WHERE `uid` = %d AND `pending` = 0
552                         $sql_extra2
553                         ORDER BY `name` ASC ",
554                         intval(local_user())
555                 );
556         }
557         else
558                 $r = array();
559
560
561         if($type == 'm' || $type == 'a') {
562                 $x = array();
563                 $x['query'] = $search;
564                 $x['photos'] = array();
565                 $x['links'] = array();
566                 $x['suggestions'] = array();
567                 $x['data'] = array();
568                 if(count($r)) {
569                         foreach($r as $g) {
570                                 $x['photos'][] = proxy_url($g['micro']);
571                                 $x['links'][] = $g['url'];
572                                 $x['suggestions'][] = $g['name'];
573                                 $x['data'][] = intval($g['id']);
574                         }
575                 }
576                 echo json_encode($x);
577                 killme();
578         }
579
580         if(count($r)) {
581                 foreach($r as $g){
582                         $contacts[] = array(
583                                 "type"  => "c",
584                                 "photo" => proxy_url($g['micro']),
585                                 "name"  => $g['name'],
586                                 "id"    => intval($g['id']),
587                                 "network" => $g['network'],
588                                 "link" => $g['url'],
589                                 "nick" => ($g['attag']) ? $g['attag'] : $g['nick'],
590                                 "forum" => $g['forum']
591                         );
592                 }
593         }
594
595         $items = array_merge($groups, $contacts);
596
597         if ($conv_id) {
598                 /* if $conv_id is set, get unknow contacts in thread */
599                 /* but first get know contacts url to filter them out */
600                 function _contact_link($i){ return dbesc($i['link']); }
601                 $known_contacts = array_map(_contact_link, $contacts);
602                 $unknow_contacts=array();
603                 $r = q("select
604                                         `author-avatar`,`author-name`,`author-link`
605                                 from item where parent=%d
606                                 and (
607                                         `author-name` LIKE '%%%s%%' OR
608                                         `author-link` LIKE '%%%s%%'
609                                 ) and
610                                 `author-link` NOT IN ('%s')
611                                 GROUP BY `author-link`
612                                 ORDER BY `author-name` ASC
613                                 ",
614                                 intval($conv_id),
615                                 dbesc($search),
616                                 dbesc($search),
617                                 implode("','", $known_contacts)
618                 );
619                 if (is_array($r) && count($r)){
620                         foreach($r as $row) {
621                                 // nickname..
622                                 $up = parse_url($row['author-link']);
623                                 $nick = explode("/",$up['path']);
624                                 $nick = $nick[count($nick)-1];
625                                 $nick .= "@".$up['host'];
626                                 // /nickname
627                                 $unknow_contacts[] = array(
628                                         "type"  => "c",
629                                         "photo" => proxy_url($row['author-avatar']),
630                                         "name"  => $row['author-name'],
631                                         "id"    => '',
632                                         "network" => "unknown",
633                                         "link" => $row['author-link'],
634                                         "nick" => $nick,
635                                         "forum" => false
636                                 );
637                         }
638                 }
639
640                 $items = array_merge($items, $unknow_contacts);
641                 $tot += count($unknow_contacts);
642         }
643
644         if($out_type === 'html') {
645                 $o = array(
646                         'tot'           => $tot,
647                         'start' => $start,
648                         'count' => $count,
649                         'groups'        => $groups,
650                         'contacts'      => $contacts,
651                 );
652                 return $o;
653         }
654
655         $o = array(
656                 'tot'   => $tot,
657                 'start' => $start,
658                 'count' => $count,
659                 'items' => $items,
660         );
661
662         echo json_encode($o);
663
664         killme();
665 }
666