]> git.mxchange.org Git - friendica.git/blob - mod/contacts.php
Merge pull request #622 from zzottel/master
[friendica.git] / mod / contacts.php
1 <?php
2
3 require_once('include/Contact.php');
4 require_once('include/socgraph.php');
5 require_once('include/contact_selectors.php');
6
7 function contacts_init(&$a) {
8         if(! local_user())
9                 return;
10
11         $contact_id = 0;
12
13         if(($a->argc == 2) && intval($a->argv[1])) {
14                 $contact_id = intval($a->argv[1]);
15                 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
16                         intval(local_user()),
17                         intval($contact_id)
18                 );
19                 if(! count($r)) {
20                         $contact_id = 0;
21                 }
22         }
23
24         require_once('include/group.php');
25         require_once('include/contact_widgets.php');
26
27         if(! x($a->page,'aside'))
28                 $a->page['aside'] = '';
29
30         if($contact_id) {
31                         $a->data['contact'] = $r[0];
32                         $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array(
33                                 '$name' => $a->data['contact']['name'],
34                                 '$photo' => $a->data['contact']['photo']
35                         ));
36                         $follow_widget = '';
37         }       
38         else {
39                 $vcard_widget = '';
40                 $follow_widget = follow_widget();
41         }
42
43         $groups_widget .= group_side('contacts','group',false,0,$contact_id);
44         $findpeople_widget .= findpeople_widget();
45         $networks_widget .= networks_widget('contacts',$_GET['nets']);
46         $a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"),array(
47                 '$vcard_widget' => $vcard_widget,
48                 '$follow_widget' => $follow_widget,
49                 '$groups_widget' => $groups_widget,
50                 '$findpeople_widget' => $findpeople_widget,
51                 '$networks_widget' => $networks_widget
52         ));
53
54         $base = $a->get_baseurl();
55         $tpl = get_markup_template("contacts-head.tpl");
56         $a->page['htmlhead'] .= replace_macros($tpl,array(
57                 '$baseurl' => $a->get_baseurl(true),
58                 '$base' => $base
59         ));
60
61         $tpl = get_markup_template("contacts-end.tpl");
62         $a->page['end'] .= replace_macros($tpl,array(
63                 '$baseurl' => $a->get_baseurl(true),
64                 '$base' => $base
65         ));
66
67
68 }
69
70 function contacts_post(&$a) {
71         
72         if(! local_user())
73                 return;
74
75         $contact_id = intval($a->argv[1]);
76         if(! $contact_id)
77                 return;
78
79         $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
80                 intval($contact_id),
81                 intval(local_user())
82         );
83
84         if(! count($orig_record)) {
85                 notice( t('Could not access contact record.') . EOL);
86                 goaway($a->get_baseurl(true) . '/contacts');
87                 return; // NOTREACHED
88         }
89
90         call_hooks('contact_edit_post', $_POST);
91
92         $profile_id = intval($_POST['profile-assign']);
93         if($profile_id) {
94                 $r = q("SELECT `id` FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
95                         intval($profile_id),
96                         intval(local_user())
97                 );
98                 if(! count($r)) {
99                         notice( t('Could not locate selected profile.') . EOL);
100                         return;
101                 }
102         }
103
104         $hidden = intval($_POST['hidden']);
105
106         $priority = intval($_POST['poll']);
107         if($priority > 5 || $priority < 0)
108                 $priority = 0;
109
110         $info = fix_mce_lf(escape_tags(trim($_POST['info'])));
111
112         $r = q("UPDATE `contact` SET `profile-id` = %d, `priority` = %d , `info` = '%s',
113                 `hidden` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
114                 intval($profile_id),
115                 intval($priority),
116                 dbesc($info),
117                 intval($hidden),
118                 intval($contact_id),
119                 intval(local_user())
120         );
121         if($r)
122                 info( t('Contact updated.') . EOL);
123         else
124                 notice( t('Failed to update contact record.') . EOL);
125
126         $r = q("select * from contact where id = %d and uid = %d limit 1",
127                 intval($contact_id),
128                 intval(local_user())
129         );
130         if($r && count($r))
131                 $a->data['contact'] = $r[0];
132
133         return;
134
135 }
136
137
138
139 function contacts_content(&$a) {
140
141         $sort_type = 0;
142         $o = '';
143         nav_set_selected('contacts');
144
145
146         if(! local_user()) {
147                 notice( t('Permission denied.') . EOL);
148                 return;
149         }
150
151         if($a->argc == 3) {
152
153                 $contact_id = intval($a->argv[1]);
154                 if(! $contact_id)
155                         return;
156
157                 $cmd = $a->argv[2];
158
159                 $orig_record = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1",
160                         intval($contact_id),
161                         intval(local_user())
162                 );
163
164                 if(! count($orig_record)) {
165                         notice( t('Could not access contact record.') . EOL);
166                         goaway($a->get_baseurl(true) . '/contacts');
167                         return; // NOTREACHED
168                 }
169                 
170                 if($cmd === 'update') {
171
172                         // pull feed and consume it, which should subscribe to the hub.
173                         proc_run('php',"include/poller.php","$contact_id");
174                         goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
175                         // NOTREACHED
176                 }
177
178                 if($cmd === 'block') {
179                         $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
180                         $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
181                                 intval($blocked),
182                                 intval($contact_id),
183                                 intval(local_user())
184                         );
185                         if($r) {
186                                 //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
187                                 info( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
188                         }
189                         goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
190                         return; // NOTREACHED
191                 }
192
193                 if($cmd === 'ignore') {
194                         $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
195                         $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
196                                 intval($readonly),
197                                 intval($contact_id),
198                                 intval(local_user())
199                         );
200                         if($r) {
201                                 info( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
202                         }
203                         goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
204                         return; // NOTREACHED
205                 }
206
207
208                 if($cmd === 'archive') {
209                         $archived = (($orig_record[0]['archive']) ? 0 : 1);
210                         $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
211                                 intval($archived),
212                                 intval($contact_id),
213                                 intval(local_user())
214                         );
215                         if ($archived) {
216                                 q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
217                         }
218                         if($r) {
219                                 //notice( t('Contact has been ') . (($archived) ? t('archived') : t('unarchived')) . EOL );
220                                 info( (($archived) ? t('Contact has been archived') : t('Contact has been unarchived')) . EOL );
221                         }
222                         goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
223                         return; // NOTREACHED
224                 }
225
226                 if($cmd === 'drop') {
227
228                         // Check if we should do HTML-based delete confirmation
229                         if($_REQUEST['confirm']) {
230                                 // <form> can't take arguments in its "action" parameter
231                                 // so add any arguments as hidden inputs
232                                 $query = explode_querystring($a->query_string);
233                                 $inputs = array();
234                                 foreach($query['args'] as $arg) {
235                                         if(strpos($arg, 'confirm=') === false) {
236                                                 $arg_parts = explode('=', $arg);
237                                                 $inputs[] = array('name' => $arg_parts[0], 'value' => $arg_parts[1]);
238                                         }
239                                 }
240
241                                 $a->page['aside'] = '';
242                                 return replace_macros(get_markup_template('confirm.tpl'), array(
243                                         '$method' => 'get',
244                                         '$message' => t('Do you really want to delete this contact?'),
245                                         '$extra_inputs' => $inputs,
246                                         '$confirm' => t('Yes'),
247                                         '$confirm_url' => $query['base'],
248                                         '$confirm_name' => 'confirmed',
249                                         '$cancel' => t('Cancel'),
250                                 ));
251                         }
252                         // Now check how the user responded to the confirmation query
253                         if($_REQUEST['canceled']) {
254                                 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
255
256                         }
257
258                         require_once('include/Contact.php');
259
260                         terminate_friendship($a->user,$a->contact,$orig_record[0]);
261
262                         contact_remove($orig_record[0]['id']);
263                         info( t('Contact has been removed.') . EOL );
264                         if(x($_SESSION,'return_url'))
265                                 goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
266                         else
267                                 goaway($a->get_baseurl(true) . '/contacts');
268                         return; // NOTREACHED
269                 }
270         }
271
272
273
274         $_SESSION['return_url'] = $a->query_string;
275
276         if((x($a->data,'contact')) && (is_array($a->data['contact']))) {
277
278                 $contact_id = $a->data['contact']['id'];
279                 $contact = $a->data['contact'];
280
281                 $editselect = 'none';
282                 if( feature_enabled(local_user(),'richtext') )
283                         $editselect = 'exact';
284
285                 $a->page['htmlhead'] .= replace_macros(get_markup_template('contact_head.tpl'), array(
286                         '$baseurl' => $a->get_baseurl(true),
287                         '$editselect' => $editselect,
288                 ));
289                 $a->page['end'] .= replace_macros(get_markup_template('contact_end.tpl'), array(
290                         '$baseurl' => $a->get_baseurl(true),
291                         '$editselect' => $editselect,
292                 ));
293
294                 require_once('include/contact_selectors.php');
295
296                 $tpl = get_markup_template("contact_edit.tpl");
297
298                 switch($contact['rel']) {
299                         case CONTACT_IS_FRIEND:
300                                 $dir_icon = 'images/lrarrow.gif';
301                                 $relation_text = t('You are mutual friends with %s');
302                                 break;
303                         case CONTACT_IS_FOLLOWER;
304                                 $dir_icon = 'images/larrow.gif';
305                                 $relation_text = t('You are sharing with %s');
306                                 break;
307         
308                         case CONTACT_IS_SHARING;
309                                 $dir_icon = 'images/rarrow.gif';
310                                 $relation_text = t('%s is sharing with you');
311                                 break;
312                         default:
313                                 break;
314                 }
315
316                 $relation_text = sprintf($relation_text,$contact['name']);
317
318                 if(($contact['network'] === NETWORK_DFRN) && ($contact['rel'])) {
319                         $url = "redir/{$contact['id']}";
320                         $sparkle = ' class="sparkle" ';
321                 }
322                 else { 
323                         $url = $contact['url'];
324                         $sparkle = '';
325                 }
326
327                 $insecure = t('Private communications are not available for this contact.');
328
329                 $last_update = (($contact['last-update'] == '0000-00-00 00:00:00') 
330                                 ? t('Never') 
331                                 : datetime_convert('UTC',date_default_timezone_get(),$contact['last-update'],'D, j M Y, g:i A'));
332
333                 if($contact['last-update'] !== '0000-00-00 00:00:00')
334                         $last_update .= ' ' . (($contact['last-update'] == $contact['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
335
336                 $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : '');
337
338                 $poll_enabled = (($contact['network'] !== NETWORK_DIASPORA) ? true : false);
339
340                 $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network']));
341
342                 $common = count_common_friends(local_user(),$contact['id']);
343                 $common_text = (($common) ? sprintf( tt('%d contact in common','%d contacts in common', $common),$common) : '');
344
345                 $polling = (($contact['network'] === NETWORK_MAIL | $contact['network'] === NETWORK_FEED) ? 'polling' : ''); 
346
347                 $x = count_all_friends(local_user(), $contact['id']);
348                 $all_friends = (($x) ? t('View all contacts') : '');
349
350                 // tabs
351                 $tabs = array(
352                         array(
353                                 'label' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
354                                 'url'   => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/block',
355                                 'sel'   => '',
356                                 'title' => t('Toggle Blocked status'),
357                         ),
358                         array(
359                                 'label' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
360                                 'url'   => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/ignore',
361                                 'sel'   => '',
362                                 'title' => t('Toggle Ignored status'),
363                         ),
364
365                         array(
366                                 'label' => (($contact['archive']) ? t('Unarchive') : t('Archive') ),
367                                 'url'   => $a->get_baseurl(true) . '/contacts/' . $contact_id . '/archive',
368                                 'sel'   => '',
369                                 'title' => t('Toggle Archive status'),
370                         ),
371                         array(
372                                 'label' => t('Repair'),
373                                 'url'   => $a->get_baseurl(true) . '/crepair/' . $contact_id,
374                                 'sel'   => '',
375                                 'title' => t('Advanced Contact Settings'),
376                         )
377                 );
378                 $tab_tpl = get_markup_template('common_tabs.tpl');
379                 $tab_str = replace_macros($tab_tpl, array('$tabs' => $tabs));
380
381                 $lost_contact = (($contact['archive'] && $contact['term-date'] != '0000-00-00 00:00:00' && $contact['term-date'] < datetime_convert('','','now')) ? t('Communications lost with this contact!') : '');
382
383                 $o .= replace_macros($tpl, array(
384                         '$header' => t('Contact Editor'),
385                         '$tab_str' => $tab_str,
386                         '$submit' => t('Submit'),
387                         '$lbl_vis1' => t('Profile Visibility'),
388                         '$lbl_vis2' => sprintf( t('Please choose the profile you would like to display to %s when viewing your profile securely.'), $contact['name']),
389                         '$lbl_info1' => t('Contact Information / Notes'),
390                         '$infedit' => t('Edit contact notes'),
391                         '$common_text' => $common_text,
392                         '$common_link' => $a->get_baseurl(true) . '/common/loc/' . local_user() . '/' . $contact['id'],
393                         '$all_friends' => $all_friends,
394                         '$relation_text' => $relation_text,
395                         '$visit' => sprintf( t('Visit %s\'s profile [%s]'),$contact['name'],$contact['url']),
396                         '$blockunblock' => t('Block/Unblock contact'),
397                         '$ignorecont' => t('Ignore contact'),
398                         '$lblcrepair' => t("Repair URL settings"),
399                         '$lblrecent' => t('View conversations'),
400                         '$lblsuggest' => $lblsuggest,
401                         '$delete' => t('Delete contact'),
402                         '$nettype' => $nettype,
403                         '$poll_interval' => contact_poll_interval($contact['priority'],(! $poll_enabled)),
404                         '$poll_enabled' => $poll_enabled,
405                         '$lastupdtext' => t('Last update:'),
406                         '$lost_contact' => $lost_contact,
407                         '$updpub' => t('Update public posts'),
408                         '$last_update' => $last_update,
409                         '$udnow' => t('Update now'),
410                         '$profile_select' => contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false)),
411                         '$contact_id' => $contact['id'],
412                         '$block_text' => (($contact['blocked']) ? t('Unblock') : t('Block') ),
413                         '$ignore_text' => (($contact['readonly']) ? t('Unignore') : t('Ignore') ),
414                         '$insecure' => (($contact['network'] !== NETWORK_DFRN && $contact['network'] !== NETWORK_MAIL && $contact['network'] !== NETWORK_FACEBOOK && $contact['network'] !== NETWORK_DIASPORA) ? $insecure : ''),
415                         '$info' => $contact['info'],
416                         '$blocked' => (($contact['blocked']) ? t('Currently blocked') : ''),
417                         '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''),
418                         '$archived' => (($contact['archive']) ? t('Currently archived') : ''),
419                         '$hidden' => array('hidden', t('Hide this contact from others'), ($contact['hidden'] == 1), t('Replies/likes to your public posts <strong>may</strong> still be visible')),
420                         '$photo' => $contact['photo'],
421                         '$name' => $contact['name'],
422                         '$dir_icon' => $dir_icon,
423                         '$alt_text' => $alt_text,
424                         '$sparkle' => $sparkle,
425                         '$url' => $url,
426
427                 ));
428
429                 $arr = array('contact' => $contact,'output' => $o);
430
431                 call_hooks('contact_edit', $arr);
432
433                 return $arr['output'];
434
435         }
436
437         $blocked = false;
438         $hidden = false;
439         $ignored = false;
440         $all = false;
441
442         if(($a->argc == 2) && ($a->argv[1] === 'all')) {
443                 $sql_extra = '';
444                 $all = true;
445         }
446         elseif(($a->argc == 2) && ($a->argv[1] === 'blocked')) {
447                 $sql_extra = " AND `blocked` = 1 ";
448                 $blocked = true;
449         }
450         elseif(($a->argc == 2) && ($a->argv[1] === 'hidden')) {
451                 $sql_extra = " AND `hidden` = 1 ";
452                 $hidden = true;
453         }
454         elseif(($a->argc == 2) && ($a->argv[1] === 'ignored')) {
455                 $sql_extra = " AND `readonly` = 1 ";
456                 $ignored = true;
457         }
458         elseif(($a->argc == 2) && ($a->argv[1] === 'archived')) {
459                 $sql_extra = " AND `archive` = 1 ";
460                 $archived = true;
461         }
462         else
463                 $sql_extra = " AND `blocked` = 0 ";
464
465         $search = ((x($_GET,'search')) ? notags(trim($_GET['search'])) : '');
466         $nets = ((x($_GET,'nets')) ? notags(trim($_GET['nets'])) : '');
467
468         $tabs = array(
469                 array(
470                         'label' => t('Suggestions'),
471                         'url'   => $a->get_baseurl(true) . '/suggest', 
472                         'sel'   => '',
473                         'title' => t('Suggest potential friends'),
474                 ),
475                 array(
476                         'label' => t('All Contacts'),
477                         'url'   => $a->get_baseurl(true) . '/contacts/all', 
478                         'sel'   => ($all) ? 'active' : '',
479                         'title' => t('Show all contacts'),
480                 ),
481                 array(
482                         'label' => t('Unblocked'),
483                         'url'   => $a->get_baseurl(true) . '/contacts',
484                         'sel'   => ((! $all) && (! $blocked) && (! $hidden) && (! $search) && (! $nets) && (! $ignored) && (! $archived)) ? 'active' : '',
485                         'title' => t('Only show unblocked contacts'),
486                 ),
487
488                 array(
489                         'label' => t('Blocked'),
490                         'url'   => $a->get_baseurl(true) . '/contacts/blocked',
491                         'sel'   => ($blocked) ? 'active' : '',
492                         'title' => t('Only show blocked contacts'),
493                 ),
494
495                 array(
496                         'label' => t('Ignored'),
497                         'url'   => $a->get_baseurl(true) . '/contacts/ignored',
498                         'sel'   => ($ignored) ? 'active' : '',
499                         'title' => t('Only show ignored contacts'),
500                 ),
501
502                 array(
503                         'label' => t('Archived'),
504                         'url'   => $a->get_baseurl(true) . '/contacts/archived',
505                         'sel'   => ($archived) ? 'active' : '',
506                         'title' => t('Only show archived contacts'),
507                 ),
508
509                 array(
510                         'label' => t('Hidden'),
511                         'url'   => $a->get_baseurl(true) . '/contacts/hidden',
512                         'sel'   => ($hidden) ? 'active' : '',
513                         'title' => t('Only show hidden contacts'),
514                 ),
515
516         );
517
518         $tab_tpl = get_markup_template('common_tabs.tpl');
519         $t = replace_macros($tab_tpl, array('$tabs'=>$tabs));
520
521
522
523         $searching = false;
524         if($search) {
525                 $search_hdr = $search;
526                 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
527                 $searching = true;
528         }
529         $sql_extra .= (($searching) ? " AND `name` REGEXP '$search_txt' " : "");
530
531         if($nets)
532                 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
533  
534         $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : ''); 
535
536         
537         $r = q("SELECT COUNT(*) AS `total` FROM `contact` 
538                 WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
539                 intval($_SESSION['uid']));
540         if(count($r)) {
541                 $a->set_pager_total($r[0]['total']);
542                 $total = $r[0]['total'];
543         }
544
545
546         $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ORDER BY `name` ASC LIMIT %d , %d ",
547                 intval($_SESSION['uid']),
548                 intval($a->pager['start']),
549                 intval($a->pager['itemspage'])
550         );
551
552         $contacts = array();
553
554         if(count($r)) {
555
556                 foreach($r as $rr) {
557
558                         switch($rr['rel']) {
559                                 case CONTACT_IS_FRIEND:
560                                         $dir_icon = 'images/lrarrow.gif';
561                                         $alt_text = t('Mutual Friendship');
562                                         break;
563                                 case  CONTACT_IS_FOLLOWER;
564                                         $dir_icon = 'images/larrow.gif';
565                                         $alt_text = t('is a fan of yours');
566                                         break;
567                                 case CONTACT_IS_SHARING;
568                                         $dir_icon = 'images/rarrow.gif';
569                                         $alt_text = t('you are a fan of');
570                                         break;
571                                 default:
572                                         break;
573                         }
574                         if(($rr['network'] === 'dfrn') && ($rr['rel'])) {
575                                 $url = "redir/{$rr['id']}";
576                                 $sparkle = ' class="sparkle" ';
577                         }
578                         else { 
579                                 $url = $rr['url'];
580                                 $sparkle = '';
581                         }
582
583
584                         $contacts[] = array(
585                                 'img_hover' => sprintf( t('Visit %s\'s profile [%s]'),$rr['name'],$rr['url']),
586                                 'edit_hover' => t('Edit contact'),
587                                 'photo_menu' => contact_photo_menu($rr),
588                                 'id' => $rr['id'],
589                                 'alt_text' => $alt_text,
590                                 'dir_icon' => $dir_icon,
591                                 'thumb' => $rr['thumb'], 
592                                 'name' => $rr['name'],
593                                 'username' => $rr['name'],
594                                 'sparkle' => $sparkle,
595                                 'itemurl' => $rr['url'],
596                                 'url' => $url,
597                                 'network' => network_to_name($rr['network']),
598                         );
599                 }
600
601                 
602
603         }
604         
605         $tpl = get_markup_template("contacts-template.tpl");
606         $o .= replace_macros($tpl, array(
607                 '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
608                 '$tabs' => $t,
609                 '$total' => $total,
610                 '$search' => $search_hdr,
611                 '$desc' => t('Search your contacts'),
612                 '$finding' => (($searching) ? t('Finding: ') . "'" . $search . "'" : ""),
613                 '$submit' => t('Find'),
614                 '$cmd' => $a->cmd,
615                 '$contacts' => $contacts,
616                 '$paginate' => paginate($a),
617
618         )); 
619         
620         return $o;
621 }