]> git.mxchange.org Git - friendica.git/blob - mod/network.php
Network page: reworked infinite scrolling
[friendica.git] / mod / network.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 use Friendica\App;
23 use Friendica\Content\ForumManager;
24 use Friendica\Content\Nav;
25 use Friendica\Content\Pager;
26 use Friendica\Content\Widget;
27 use Friendica\Content\Text\HTML;
28 use Friendica\Core\ACL;
29 use Friendica\Core\Hook;
30 use Friendica\Core\Logger;
31 use Friendica\Core\Renderer;
32 use Friendica\Database\DBA;
33 use Friendica\DI;
34 use Friendica\Model\Contact;
35 use Friendica\Model\Group;
36 use Friendica\Model\Item;
37 use Friendica\Model\Post\Category;
38 use Friendica\Model\Profile;
39 use Friendica\Module\Contact as ModuleContact;
40 use Friendica\Module\Security\Login;
41 use Friendica\Util\DateTimeFormat;
42 use Friendica\Util\Strings;
43
44 function network_init(App $a)
45 {
46         if (!local_user()) {
47                 notice(DI::l10n()->t('Permission denied.'));
48                 return;
49         }
50
51         $is_a_date_query = false;
52
53         $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0);
54
55         $cid = 0;
56         if (!empty($_GET['contactid'])) {
57                 $cid = $_GET['contactid'];
58                 $_GET['nets'] = '';
59                 $group_id = 0;
60         }
61
62         if ($a->argc > 1) {
63                 for ($x = 1; $x < $a->argc; $x ++) {
64                         if (DI::dtFormat()->isYearMonthDay($a->argv[$x])) {
65                                 $is_a_date_query = true;
66                                 break;
67                         }
68                 }
69         }
70
71         // convert query string to array. remove friendica args
72         $query_array = [];
73         parse_str(parse_url(DI::args()->getQueryString(), PHP_URL_QUERY), $query_array);
74
75         // fetch last used network view and redirect if needed
76         if (!$is_a_date_query) {
77                 $sel_nets = $_GET['nets'] ?? '';
78                 $sel_tabs = network_query_get_sel_tab($a);
79                 $sel_groups = network_query_get_sel_group($a);
80                 $last_sel_tabs = DI::pConfig()->get(local_user(), 'network.view', 'tab.selected');
81
82                 $remember_tab = ($sel_tabs[0] === 'active' && is_array($last_sel_tabs) && $last_sel_tabs[0] !== 'active');
83
84                 $net_baseurl = '/network';
85                 $net_args = [];
86
87                 if ($sel_groups !== false) {
88                         $net_baseurl .= '/' . $sel_groups;
89                 }
90
91                 if ($remember_tab) {
92                         // redirect if current selected tab is '/network' and
93                         // last selected tab is _not_ '/network?order=activity'.
94                         // and this isn't a date query
95
96                         $tab_args = [
97                                 'order=activity', //all
98                                 'order=post',     //postord
99                                 'conv=1',         //conv
100                                 'star=1',         //starred
101                         ];
102
103                         $k = array_search('active', $last_sel_tabs);
104
105                         if ($k != 3) {
106                                 // parse out tab queries
107                                 $dest_qa = [];
108                                 $dest_qs = $tab_args[$k];
109                                 parse_str($dest_qs, $dest_qa);
110                                 $net_args = array_merge($net_args, $dest_qa);
111                         } else {
112                                 $remember_tab = false;
113                         }
114                 }
115
116                 if ($sel_nets) {
117                         $net_args['nets'] = $sel_nets;
118                 }
119
120                 if ($remember_tab) {
121                         $net_args = array_merge($query_array, $net_args);
122                         $net_queries = http_build_query($net_args);
123
124                         $redir_url = ($net_queries ? $net_baseurl . '?' . $net_queries : $net_baseurl);
125
126                         DI::baseUrl()->redirect($redir_url);
127                 }
128         }
129
130         if (empty(DI::page()['aside'])) {
131                 DI::page()['aside'] = '';
132         }
133
134         DI::page()['aside'] .= Group::sidebarWidget('network/0', 'network', 'standard', $group_id);
135         DI::page()['aside'] .= ForumManager::widget(local_user(), $cid);
136         DI::page()['aside'] .= Widget::postedByYear('network', local_user(), false);
137         DI::page()['aside'] .= Widget::networks('network', $_GET['nets'] ?? '');
138         DI::page()['aside'] .= Widget\SavedSearches::getHTML(DI::args()->getQueryString());
139         DI::page()['aside'] .= Widget::fileAs('network', $_GET['file'] ?? '');
140 }
141
142 /**
143  * Return selected tab from query
144  *
145  * urls -> returns
146  *        '/network'                => $no_active = 'active'
147  *        '/network?order=activity' => $activity_active = 'active'
148  *        '/network?order=post'     => $postord_active = 'active'
149  *        '/network?conv=1',        => $conv_active = 'active'
150  *        '/network?star=1',        => $starred_active = 'active'
151  *
152  * @param App $a
153  * @return array ($no_active, $activity_active, $postord_active, $conv_active, $starred_active);
154  */
155 function network_query_get_sel_tab(App $a)
156 {
157         $no_active = '';
158         $starred_active = '';
159         $all_active = '';
160         $conv_active = '';
161         $postord_active = '';
162
163         if (!empty($_GET['star'])) {
164                 $starred_active = 'active';
165         }
166
167         if (!empty($_GET['conv'])) {
168                 $conv_active = 'active';
169         }
170
171         if (($starred_active == '') && ($conv_active == '')) {
172                 $no_active = 'active';
173         }
174
175         if ($no_active == 'active' && !empty($_GET['order'])) {
176                 switch($_GET['order']) {
177                         case 'post' :     $postord_active = 'active'; $no_active=''; break;
178                         case 'activity' : $all_active     = 'active'; $no_active=''; break;
179                 }
180         }
181
182         return [$no_active, $all_active, $postord_active, $conv_active, $starred_active];
183 }
184
185 function network_query_get_sel_group(App $a)
186 {
187         $group = false;
188
189         if ($a->argc >= 2 && is_numeric($a->argv[1])) {
190                 $group = $a->argv[1];
191         }
192
193         return $group;
194 }
195
196 /**
197  * Sets the pager data and returns SQL
198  *
199  * @param App     $a      The global App
200  * @param Pager   $pager
201  * @return string SQL with the appropriate LIMIT clause
202  * @throws \Friendica\Network\HTTPException\InternalServerErrorException
203  */
204 function networkPager(App $a, Pager $pager)
205 {
206         if (DI::mode()->isMobile()) {
207                 $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network',
208                         DI::config()->get('system', 'itemspage_network_mobile'));
209         } else {
210                 $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_network',
211                         DI::config()->get('system', 'itemspage_network'));
212         }
213
214         //  now that we have the user settings, see if the theme forces
215         //  a maximum item number which is lower then the user choice
216         if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {
217                 $itemspage_network = $a->force_max_items;
218         }
219
220         $pager->setItemsPerPage($itemspage_network);
221 }
222
223 /**
224  * Sets items as seen
225  *
226  * @param array $condition The array with the SQL condition
227  * @throws \Friendica\Network\HTTPException\InternalServerErrorException
228  */
229 function networkSetSeen($condition)
230 {
231         if (empty($condition)) {
232                 return;
233         }
234
235         $unseen = Item::exists($condition);
236
237         if ($unseen) {
238                 Item::update(['unseen' => false], $condition);
239         }
240 }
241
242 /**
243  * Create the conversation HTML
244  *
245  * @param App     $a      The global App
246  * @param array   $items  Items of the conversation
247  * @param Pager   $pager
248  * @param string  $mode   Display mode for the conversation
249  * @param integer $update Used for the automatic reloading
250  * @param string  $ordering
251  * @return string HTML of the conversation
252  * @throws ImagickException
253  * @throws \Friendica\Network\HTTPException\InternalServerErrorException
254  */
255 function networkConversation(App $a, $items, Pager $pager, $mode, $update, $ordering = '')
256 {
257         // Set this so that the conversation function can find out contact info for our wall-wall items
258         $a->page_contact = $a->contact;
259
260         if (!is_array($items)) {
261                 Logger::info('Expecting items to be an array.', ['items' => $items]);
262                 $items = [];
263         }
264
265         $o = conversation($a, $items, $mode, $update, false, $ordering, local_user());
266
267         if (!$update) {
268                 if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
269                         $o .= HTML::scrollLoader();
270                 } else {
271                         $o .= $pager->renderMinimal(count($items));
272                 }
273         }
274
275         return $o;
276 }
277
278 function network_content(App $a, $update = 0, $parent = 0)
279 {
280         if (!local_user()) {
281                 return Login::form();
282         }
283
284         /// @TODO Is this really necessary? $a is already available to hooks
285         $arr = ['query' => DI::args()->getQueryString()];
286         Hook::callAll('network_content_init', $arr);
287
288         if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll') && ($_GET['mode'] ?? '') != 'minimal') {
289                 $tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
290                 $o = Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
291         }
292
293         if (!empty($_GET['file'])) {
294                 $o .= networkFlatView($a, $update);
295         } else {
296                 $o .= networkThreadedView($a, $update, $parent);
297         }
298
299         if (!$update && ($o === '')) {
300                 notice(DI::l10n()->t("No items found"));
301         }
302
303         return $o;
304 }
305
306 /**
307  * Get the network content in flat view
308  *
309  * @param App     $a      The global App
310  * @param integer $update Used for the automatic reloading
311  * @return string HTML of the network content in flat view
312  * @throws ImagickException
313  * @throws \Friendica\Network\HTTPException\InternalServerErrorException
314  * @global Pager  $pager
315  */
316 function networkFlatView(App $a, $update = 0)
317 {
318         global $pager;
319         // Rawmode is used for fetching new content at the end of the page
320         $rawmode = (isset($_GET['mode']) && ($_GET['mode'] == 'raw'));
321
322         $o = '';
323
324         $file = $_GET['file'] ?? '';
325
326         if (!$update && !$rawmode) {
327                 $tabs = network_tabs($a);
328                 $o .= $tabs;
329
330                 Nav::setSelected('network');
331
332                 $x = [
333                         'is_owner' => true,
334                         'allow_location' => $a->user['allow_location'],
335                         'default_location' => $a->user['default-location'],
336                         'nickname' => $a->user['nickname'],
337                         'lockstate' => (is_array($a->user) &&
338                         (strlen($a->user['allow_cid']) || strlen($a->user['allow_gid']) ||
339                         strlen($a->user['deny_cid']) || strlen($a->user['deny_gid'])) ? 'lock' : 'unlock'),
340                         'default_perms' => ACL::getDefaultUserPermissions($a->user),
341                         'acl' => ACL::getFullSelectorHTML(DI::page(), $a->user, true),
342                         'bang' => '',
343                         'visitor' => 'block',
344                         'profile_uid' => local_user(),
345                         'content' => '',
346                 ];
347
348                 $o .= status_editor($a, $x);
349
350                 if (!DI::config()->get('theme', 'hide_eventlist')) {
351                         $o .= Profile::getBirthdays();
352                         $o .= Profile::getEventsReminderHTML();
353                 }
354         }
355
356         $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
357
358         networkPager($a, $pager);
359
360         if (strlen($file)) {
361                 $item_params = ['order' => ['uri-id' => true]];
362                 $term_condition = ['name' => $file, 'type' => Category::FILE, 'uid' => local_user()];
363                 $term_params = ['order' => ['uri-id' => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
364                 $result = DBA::select('category-view', ['uri-id'], $term_condition, $term_params);
365
366                 $posts = [];
367                 while ($term = DBA::fetch($result)) {
368                         $posts[] = $term['uri-id'];
369                 }
370                 DBA::close($result);
371
372                 if (count($posts) == 0) {
373                         return '';
374                 }
375                 $item_condition = ['uid' => local_user(), 'uri-id' => $posts];
376         } else {
377                 $item_params = ['order' => ['id' => true]];
378                 $item_condition = ['uid' => local_user()];
379                 $item_params['limit'] = [$pager->getStart(), $pager->getItemsPerPage()];
380
381                 networkSetSeen(['unseen' => true, 'uid' => local_user()]);
382         }
383
384         $result = Item::selectForUser(local_user(), [], $item_condition, $item_params);
385         $items = Item::inArray($result);
386         $o .= networkConversation($a, $items, $pager, 'network-new', $update);
387
388         return $o;
389 }
390
391 /**
392  * Get the network content in threaded view
393  *
394  * @param  App     $a      The global App
395  * @param  integer $update Used for the automatic reloading
396  * @param  integer $parent
397  * @return string HTML of the network content in flat view
398  * @throws ImagickException
399  * @throws \Friendica\Network\HTTPException\InternalServerErrorException
400  * @global Pager   $pager
401  */
402 function networkThreadedView(App $a, $update, $parent)
403 {
404         /// @TODO this will have to be converted to a static property of the converted Module\Network class
405         global $pager;
406
407         // Rawmode is used for fetching new content at the end of the page
408         $rawmode = (isset($_GET['mode']) AND ($_GET['mode'] == 'raw'));
409
410         $last_received = isset($_GET['last_received']) ? DateTimeFormat::utc($_GET['last_received']) : '';
411         $last_commented = isset($_GET['last_commented']) ? DateTimeFormat::utc($_GET['last_commented']) : '';
412         $last_created = isset($_GET['last_created']) ? DateTimeFormat::utc($_GET['last_created']) : '';
413         $last_uriid = isset($_GET['last_uriid']) ? intval($_GET['last_uriid']) : 0;
414
415         $datequery = $datequery2 = '';
416
417         $gid = 0;
418
419         $default_permissions = [];
420
421         if ($a->argc > 1) {
422                 for ($x = 1; $x < $a->argc; $x ++) {
423                         if (DI::dtFormat()->isYearMonthDay($a->argv[$x])) {
424                                 if ($datequery) {
425                                         $datequery2 = Strings::escapeHtml($a->argv[$x]);
426                                 } else {
427                                         $datequery = Strings::escapeHtml($a->argv[$x]);
428                                         $_GET['order'] = 'post';
429                                 }
430                         } elseif (intval($a->argv[$x])) {
431                                 $gid = intval($a->argv[$x]);
432                                 $default_permissions['allow_gid'] = [$gid];
433                         }
434                 }
435         }
436
437         $o = '';
438
439         $cid   = intval($_GET['contactid'] ?? 0);
440         $star  = intval($_GET['star']      ?? 0);
441         $conv  = intval($_GET['conv']      ?? 0);
442         $order = Strings::escapeTags(($_GET['order'] ?? '') ?: 'activity');
443         $nets  =        $_GET['nets']      ?? '';
444
445         $allowedCids = [];
446         if ($cid) {
447                 $allowedCids[] = (int) $cid;
448         } elseif ($nets) {
449                 $condition = [
450                         'uid'     => local_user(),
451                         'network' => $nets,
452                         'self'    => false,
453                         'blocked' => false,
454                         'pending' => false,
455                         'archive' => false,
456                         'rel'     => [Contact::SHARING, Contact::FRIEND],
457                 ];
458                 $contactStmt = DBA::select('contact', ['id'], $condition);
459                 while ($contact = DBA::fetch($contactStmt)) {
460                         $allowedCids[] = (int) $contact['id'];
461                 }
462                 DBA::close($contactStmt);
463         }
464
465         if (count($allowedCids)) {
466                 $default_permissions['allow_cid'] = $allowedCids;
467         }
468
469         if (!$update && !$rawmode) {
470                 $tabs = network_tabs($a);
471                 $o .= $tabs;
472
473                 Nav::setSelected('network');
474
475                 $content = '';
476
477                 if ($cid) {
478                         // If $cid belongs to a communitity forum or a privat goup,.add a mention to the status editor
479                         $condition = ["`id` = ? AND (`forum` OR `prv`)", $cid];
480                         $contact = DBA::selectFirst('contact', ['addr'], $condition);
481                         if (!empty($contact['addr'])) {
482                                 $content = '!' . $contact['addr'];
483                         }
484                 }
485
486                 $x = [
487                         'is_owner' => true,
488                         'allow_location' => $a->user['allow_location'],
489                         'default_location' => $a->user['default-location'],
490                         'nickname' => $a->user['nickname'],
491                         'lockstate' => ($gid || $cid || $nets || (is_array($a->user) &&
492                         (strlen($a->user['allow_cid']) || strlen($a->user['allow_gid']) ||
493                         strlen($a->user['deny_cid']) || strlen($a->user['deny_gid']))) ? 'lock' : 'unlock'),
494                         'default_perms' => ACL::getDefaultUserPermissions($a->user),
495                         'acl' => ACL::getFullSelectorHTML(DI::page(), $a->user, true, $default_permissions),
496                         'bang' => (($gid || $cid || $nets) ? '!' : ''),
497                         'visitor' => 'block',
498                         'profile_uid' => local_user(),
499                         'content' => $content,
500                 ];
501
502                 $o .= status_editor($a, $x);
503         }
504
505         $conditionFields = ['uid' => local_user()];
506         $conditionStrings = [];
507
508         if ($star) {
509                 $conditionFields['starred'] = true;
510         }
511         if ($conv) {
512                 $conditionFields['mention'] = true;
513         }
514         if ($nets) {
515                 $conditionFields['network'] = $nets;
516         }
517
518         if ($datequery) {
519                 $conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` <= ? ", DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get())]);
520         }
521         if ($datequery2) {
522                 $conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` >= ? ", DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get())]);
523         }
524
525         if ($gid) {
526                 $group = DBA::selectFirst('group', ['name'], ['id' => $gid, 'uid' => local_user()]);
527                 if (!DBA::isResult($group)) {
528                         if ($update) {
529                                 exit();
530                         }
531                         notice(DI::l10n()->t('No such group'));
532                         DI::baseUrl()->redirect('network/0');
533                         // NOTREACHED
534                 }
535
536                 $conditionStrings = DBA::mergeConditions($conditionStrings, ["`contact-id` IN (SELECT `contact-id` FROM `group_member` WHERE `gid` = ?)", $gid]);
537
538                 $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), [
539                         '$title' => DI::l10n()->t('Group: %s', $group['name'])
540                 ]) . $o;
541         } elseif ($cid) {
542                 $contact = Contact::getById($cid);
543                 if (DBA::isResult($contact)) {
544                         $conditionFields['contact-id'] = $cid;
545
546                         $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('viewcontact_template.tpl'), [
547                                 'contacts' => [ModuleContact::getContactTemplateVars($contact)],
548                                 'id' => 'network',
549                         ]) . $o;
550                 } else {
551                         notice(DI::l10n()->t('Invalid contact.'));
552                         DI::baseUrl()->redirect('network');
553                         // NOTREACHED
554                 }
555         } elseif (!$update && !DI::config()->get('theme', 'hide_eventlist')) {
556                 $o .= Profile::getBirthdays();
557                 $o .= Profile::getEventsReminderHTML();
558         }
559
560         // Normal conversation view
561         if ($order === 'post') {
562                 $ordering = '`received`';
563                 $order_mode = 'received';
564         } else {
565                 $ordering = '`commented`';
566                 $order_mode = 'commented';
567         }
568
569         $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
570
571         networkPager($a, $pager);
572
573         if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
574                 $pager->setPage(1);
575         }
576
577         // Currently only the order modes "received" and "commented" are in use
578         switch ($order_mode) {
579                 case 'received':
580                         if ($last_received != '') {
581                                 $conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` < ?", $last_received]);
582                         }
583                         break;
584                 case 'commented':
585                         if ($last_commented != '') {
586                                 $conditionStrings = DBA::mergeConditions($conditionStrings, ["`commented` < ?", $last_commented]);
587                         }
588                         break;
589                 case 'created':
590                         if ($last_created != '') {
591                                 $conditionStrings = DBA::mergeConditions($conditionStrings, ["`created` < ?", $last_created]);
592                         }
593                         break;
594                 case 'uriid':
595                         if ($last_uriid > 0) {
596                                 $conditionStrings = DBA::mergeConditions($conditionStrings, ["`uri-id` < ?", $last_uriid]);
597                         }
598                         break;
599         }
600
601         // Fetch a page full of parent items for this page
602         if ($update) {
603                 if (!empty($parent)) {
604                         // Load only a single thread
605                         $conditionFields['parent'] = $parent;
606                 } elseif ($order === 'post') {
607                         // Only load new toplevel posts
608                         $conditionFields['unseen'] = true;
609                         $conditionFields['gravity'] = GRAVITY_PARENT;
610                 } else {
611                         // Load all unseen items
612                         $conditionFields['unseen'] = true;
613                 }
614
615                 $params = ['order' => [$order_mode => true], 'limit' => 100];
616                 $table = 'network-item-view';
617         } else {
618                 $params = ['order' => [$order_mode => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
619                 $table = 'network-thread-view';
620         }
621         $r = DBA::selectToArray($table, [], DBA::mergeConditions($conditionFields, $conditionStrings), $params);
622
623         return $o . network_display_post($a, $pager, (!$gid && !$cid && !$star), $update, $ordering, $r);
624 }
625
626 function network_display_post($a, $pager, $mark_all, $update, $ordering, $items)
627 {
628         $parents_str = '';
629
630         if (DBA::isResult($items)) {
631                 $parents_arr = [];
632
633                 foreach ($items as $item) {
634                         if (!in_array($item['parent'], $parents_arr) && ($item['parent'] > 0)) {
635                                 $parents_arr[] = $item['parent'];
636                         }
637                 }
638                 $parents_str = implode(', ', $parents_arr);
639         }
640
641         $pager->setQueryString(DI::args()->getQueryString());
642
643         // We aren't going to try and figure out at the item, group, and page
644         // level which items you've seen and which you haven't. If you're looking
645         // at the top level network page just mark everything seen.
646
647         if ($mark_all) {
648                 $condition = ['unseen' => true, 'uid' => local_user()];
649                 networkSetSeen($condition);
650         } elseif ($parents_str) {
651                 $condition = ["`uid` = ? AND `unseen` AND `parent` IN (" . DBA::escape($parents_str) . ")", local_user()];
652                 networkSetSeen($condition);
653         }
654
655         return networkConversation($a, $items, $pager, 'network', $update, $ordering);
656 }
657
658 /**
659  * Get the network tabs menu
660  *
661  * @param App $a The global App
662  * @return string Html of the networktab
663  * @throws \Friendica\Network\HTTPException\InternalServerErrorException
664  */
665 function network_tabs(App $a)
666 {
667         // item filter tabs
668         /// @TODO fix this logic, reduce duplication
669         /// DI::page()['content'] .= '<div class="tabs-wrapper">';
670         list($no_active, $all_active, $post_active, $conv_active, $starred_active) = network_query_get_sel_tab($a);
671
672         // if no tabs are selected, defaults to activitys
673         if ($no_active == 'active') {
674                 $all_active = 'active';
675         }
676
677         $cmd = DI::args()->getCommand();
678
679         $def_param = [];
680         if (!empty($_GET['contactid'])) {
681                 $def_param['contactid'] = $_GET['contactid'];
682         }
683
684         // tabs
685         $tabs = [
686                 [
687                         'label' => DI::l10n()->t('Latest Activity'),
688                         'url'   => $cmd . '?' . http_build_query(array_merge($def_param, ['order' => 'activity'])),
689                         'sel'   => $all_active,
690                         'title' => DI::l10n()->t('Sort by latest activity'),
691                         'id'    => 'activity-order-tab',
692                         'accesskey' => 'e',
693                 ],
694                 [
695                         'label' => DI::l10n()->t('Latest Posts'),
696                         'url'   => $cmd . '?' . http_build_query(array_merge($def_param, ['order' => 'post'])),
697                         'sel'   => $post_active,
698                         'title' => DI::l10n()->t('Sort by post received date'),
699                         'id'    => 'post-order-tab',
700                         'accesskey' => 't',
701                 ],
702         ];
703
704         $tabs[] = [
705                 'label' => DI::l10n()->t('Personal'),
706                 'url'   => $cmd . '?' . http_build_query(array_merge($def_param, ['conv' => true])),
707                 'sel'   => $conv_active,
708                 'title' => DI::l10n()->t('Posts that mention or involve you'),
709                 'id'    => 'personal-tab',
710                 'accesskey' => 'r',
711         ];
712
713         $tabs[] = [
714                 'label' => DI::l10n()->t('Starred'),
715                 'url'   => $cmd . '?' . http_build_query(array_merge($def_param, ['star' => true])),
716                 'sel'   => $starred_active,
717                 'title' => DI::l10n()->t('Favourite Posts'),
718                 'id'    => 'starred-posts-tab',
719                 'accesskey' => 'm',
720         ];
721
722         // save selected tab, but only if not in file mode
723         if (empty($_GET['file'])) {
724                 DI::pConfig()->set(local_user(), 'network.view', 'tab.selected', [
725                         $all_active, $post_active, $conv_active, $starred_active
726                 ]);
727         }
728
729         $arr = ['tabs' => $tabs];
730         Hook::callAll('network_tabs', $arr);
731
732         $tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
733
734         return Renderer::replaceMacros($tpl, ['$tabs' => $arr['tabs']]);
735
736         // --- end item filter tabs
737 }