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