3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
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;
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\Security\Login;
40 use Friendica\Util\DateTimeFormat;
41 use Friendica\Util\Strings;
43 function network_init(App $a)
46 notice(DI::l10n()->t('Permission denied.'));
50 Hook::add('head', __FILE__, 'network_infinite_scroll_head');
52 $is_a_date_query = false;
54 $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0);
57 if (!empty($_GET['contactid'])) {
58 $cid = $_GET['contactid'];
64 for ($x = 1; $x < $a->argc; $x ++) {
65 if (DI::dtFormat()->isYearMonthDay($a->argv[$x])) {
66 $is_a_date_query = true;
72 // convert query string to array. remove friendica args
74 parse_str(parse_url(DI::args()->getQueryString(), PHP_URL_QUERY), $query_array);
76 // fetch last used network view and redirect if needed
77 if (!$is_a_date_query) {
78 $sel_nets = $_GET['nets'] ?? '';
79 $sel_tabs = network_query_get_sel_tab($a);
80 $sel_groups = network_query_get_sel_group($a);
81 $last_sel_tabs = DI::pConfig()->get(local_user(), 'network.view', 'tab.selected');
83 $remember_tab = ($sel_tabs[0] === 'active' && is_array($last_sel_tabs) && $last_sel_tabs[0] !== 'active');
85 $net_baseurl = '/network';
88 if ($sel_groups !== false) {
89 $net_baseurl .= '/' . $sel_groups;
93 // redirect if current selected tab is '/network' and
94 // last selected tab is _not_ '/network?order=activity'.
95 // and this isn't a date query
98 'order=activity', //all
99 'order=post', //postord
104 $k = array_search('active', $last_sel_tabs);
107 // parse out tab queries
109 $dest_qs = $tab_args[$k];
110 parse_str($dest_qs, $dest_qa);
111 $net_args = array_merge($net_args, $dest_qa);
113 $remember_tab = false;
118 $net_args['nets'] = $sel_nets;
122 $net_args = array_merge($query_array, $net_args);
123 $net_queries = http_build_query($net_args);
125 $redir_url = ($net_queries ? $net_baseurl . '?' . $net_queries : $net_baseurl);
127 DI::baseUrl()->redirect($redir_url);
131 if (empty(DI::page()['aside'])) {
132 DI::page()['aside'] = '';
135 DI::page()['aside'] .= Group::sidebarWidget('network/0', 'network', 'standard', $group_id);
136 DI::page()['aside'] .= ForumManager::widget(local_user(), $cid);
137 DI::page()['aside'] .= Widget::postedByYear('network', local_user(), false);
138 DI::page()['aside'] .= Widget::networks('network', $_GET['nets'] ?? '');
139 DI::page()['aside'] .= Widget\SavedSearches::getHTML(DI::args()->getQueryString());
140 DI::page()['aside'] .= Widget::fileAs('network', $_GET['file'] ?? '');
144 * Return selected tab from query
147 * '/network' => $no_active = 'active'
148 * '/network?order=activity' => $activity_active = 'active'
149 * '/network?order=post' => $postord_active = 'active'
150 * '/network?conv=1', => $conv_active = 'active'
151 * '/network?star=1', => $starred_active = 'active'
154 * @return array ($no_active, $activity_active, $postord_active, $conv_active, $starred_active);
156 function network_query_get_sel_tab(App $a)
159 $starred_active = '';
162 $postord_active = '';
164 if (!empty($_GET['star'])) {
165 $starred_active = 'active';
168 if (!empty($_GET['conv'])) {
169 $conv_active = 'active';
172 if (($starred_active == '') && ($conv_active == '')) {
173 $no_active = 'active';
176 if ($no_active == 'active' && !empty($_GET['order'])) {
177 switch($_GET['order']) {
178 case 'post' : $postord_active = 'active'; $no_active=''; break;
179 case 'activity' : $all_active = 'active'; $no_active=''; break;
183 return [$no_active, $all_active, $postord_active, $conv_active, $starred_active];
186 function network_query_get_sel_group(App $a)
190 if ($a->argc >= 2 && is_numeric($a->argv[1])) {
191 $group = $a->argv[1];
198 * Sets the pager data and returns SQL
200 * @param App $a The global App
201 * @param Pager $pager
202 * @param integer $update Used for the automatic reloading
203 * @return string SQL with the appropriate LIMIT clause
204 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
206 function networkPager(App $a, Pager $pager, $update)
209 // only setup pagination on initial page view
213 if (DI::mode()->isMobile()) {
214 $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network',
215 DI::config()->get('system', 'itemspage_network_mobile'));
217 $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_network',
218 DI::config()->get('system', 'itemspage_network'));
221 // now that we have the user settings, see if the theme forces
222 // a maximum item number which is lower then the user choice
223 if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {
224 $itemspage_network = $a->force_max_items;
227 $pager->setItemsPerPage($itemspage_network);
229 return sprintf(" LIMIT %d, %d ", $pager->getStart(), $pager->getItemsPerPage());
235 * @param array $condition The array with the SQL condition
236 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
238 function networkSetSeen($condition)
240 if (empty($condition)) {
244 $unseen = Item::exists($condition);
247 Item::update(['unseen' => false], $condition);
252 * Create the conversation HTML
254 * @param App $a The global App
255 * @param array $items Items of the conversation
256 * @param Pager $pager
257 * @param string $mode Display mode for the conversation
258 * @param integer $update Used for the automatic reloading
259 * @param string $ordering
260 * @return string HTML of the conversation
261 * @throws ImagickException
262 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
264 function networkConversation(App $a, $items, Pager $pager, $mode, $update, $ordering = '')
266 // Set this so that the conversation function can find out contact info for our wall-wall items
267 $a->page_contact = $a->contact;
269 if (!is_array($items)) {
270 Logger::info('Expecting items to be an array.', ['items' => $items]);
274 $o = conversation($a, $items, $mode, $update, false, $ordering, local_user());
277 if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
278 $o .= HTML::scrollLoader();
280 $o .= $pager->renderMinimal(count($items));
287 function network_content(App $a, $update = 0, $parent = 0)
290 return Login::form();
293 /// @TODO Is this really necessary? $a is already available to hooks
294 $arr = ['query' => DI::args()->getQueryString()];
295 Hook::callAll('network_content_init', $arr);
297 if (!empty($_GET['file'])) {
298 $o = networkFlatView($a, $update);
300 $o = networkThreadedView($a, $update, $parent);
304 notice(DI::l10n()->t("No items found"));
311 * Get the network content in flat view
313 * @param App $a The global App
314 * @param integer $update Used for the automatic reloading
315 * @return string HTML of the network content in flat view
316 * @throws ImagickException
317 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
318 * @global Pager $pager
320 function networkFlatView(App $a, $update = 0)
323 // Rawmode is used for fetching new content at the end of the page
324 $rawmode = (isset($_GET['mode']) && ($_GET['mode'] == 'raw'));
328 $file = $_GET['file'] ?? '';
330 if (!$update && !$rawmode) {
331 $tabs = network_tabs($a);
334 Nav::setSelected('network');
338 'allow_location' => $a->user['allow_location'],
339 'default_location' => $a->user['default-location'],
340 'nickname' => $a->user['nickname'],
341 'lockstate' => (is_array($a->user) &&
342 (strlen($a->user['allow_cid']) || strlen($a->user['allow_gid']) ||
343 strlen($a->user['deny_cid']) || strlen($a->user['deny_gid'])) ? 'lock' : 'unlock'),
344 'default_perms' => ACL::getDefaultUserPermissions($a->user),
345 'acl' => ACL::getFullSelectorHTML(DI::page(), $a->user, true),
347 'visitor' => 'block',
348 'profile_uid' => local_user(),
352 $o .= status_editor($a, $x);
354 if (!DI::config()->get('theme', 'hide_eventlist')) {
355 $o .= Profile::getBirthdays();
356 $o .= Profile::getEventsReminderHTML();
360 $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
362 networkPager($a, $pager, $update);
366 $item_params = ['order' => ['uri-id' => true]];
367 $term_condition = ['name' => $file, 'type' => Category::FILE, 'uid' => local_user()];
368 $term_params = ['order' => ['uri-id' => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
369 $result = DBA::select('category-view', ['uri-id'], $term_condition, $term_params);
372 while ($term = DBA::fetch($result)) {
373 $posts[] = $term['uri-id'];
377 if (count($posts) == 0) {
380 $item_condition = ['uid' => local_user(), 'uri-id' => $posts];
382 $item_params = ['order' => ['id' => true]];
383 $item_condition = ['uid' => local_user()];
384 $item_params['limit'] = [$pager->getStart(), $pager->getItemsPerPage()];
386 networkSetSeen(['unseen' => true, 'uid' => local_user()]);
389 $result = Item::selectForUser(local_user(), [], $item_condition, $item_params);
390 $items = Item::inArray($result);
391 $o .= networkConversation($a, $items, $pager, 'network-new', $update);
397 * Get the network content in threaded view
399 * @param App $a The global App
400 * @param integer $update Used for the automatic reloading
401 * @param integer $parent
402 * @return string HTML of the network content in flat view
403 * @throws ImagickException
404 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
405 * @global Pager $pager
407 function networkThreadedView(App $a, $update, $parent)
409 /// @TODO this will have to be converted to a static property of the converted Module\Network class
412 // Rawmode is used for fetching new content at the end of the page
413 $rawmode = (isset($_GET['mode']) AND ( $_GET['mode'] == 'raw'));
415 if (isset($_GET['last_received']) && isset($_GET['last_commented']) && isset($_GET['last_created']) && isset($_GET['last_id'])) {
416 $last_received = DateTimeFormat::utc($_GET['last_received']);
417 $last_commented = DateTimeFormat::utc($_GET['last_commented']);
418 $last_created = DateTimeFormat::utc($_GET['last_created']);
419 $last_id = intval($_GET['last_id']);
422 $last_commented = '';
427 $datequery = $datequery2 = '';
431 $default_permissions = [];
434 for ($x = 1; $x < $a->argc; $x ++) {
435 if (DI::dtFormat()->isYearMonthDay($a->argv[$x])) {
437 $datequery2 = Strings::escapeHtml($a->argv[$x]);
439 $datequery = Strings::escapeHtml($a->argv[$x]);
440 $_GET['order'] = 'post';
442 } elseif (intval($a->argv[$x])) {
443 $gid = intval($a->argv[$x]);
444 $default_permissions['allow_gid'] = [$gid];
451 $cid = intval($_GET['contactid'] ?? 0);
452 $star = intval($_GET['star'] ?? 0);
453 $conv = intval($_GET['conv'] ?? 0);
454 $order = Strings::escapeTags(($_GET['order'] ?? '') ?: 'activity');
455 $nets = $_GET['nets'] ?? '';
459 $allowedCids[] = (int) $cid;
462 'uid' => local_user(),
468 'rel' => [Contact::SHARING, Contact::FRIEND],
470 $contactStmt = DBA::select('contact', ['id'], $condition);
471 while ($contact = DBA::fetch($contactStmt)) {
472 $allowedCids[] = (int) $contact['id'];
474 DBA::close($contactStmt);
477 if (count($allowedCids)) {
478 $default_permissions['allow_cid'] = $allowedCids;
481 if (!$update && !$rawmode) {
482 $tabs = network_tabs($a);
485 Nav::setSelected('network');
490 // If $cid belongs to a communitity forum or a privat goup,.add a mention to the status editor
491 $condition = ["`id` = ? AND (`forum` OR `prv`)", $cid];
492 $contact = DBA::selectFirst('contact', ['addr', 'nick'], $condition);
493 if (DBA::isResult($contact)) {
494 if ($contact['addr'] != '') {
495 $content = '!' . $contact['addr'];
497 $content = '!' . $contact['nick'] . '+' . $cid;
504 'allow_location' => $a->user['allow_location'],
505 'default_location' => $a->user['default-location'],
506 'nickname' => $a->user['nickname'],
507 'lockstate' => ($gid || $cid || $nets || (is_array($a->user) &&
508 (strlen($a->user['allow_cid']) || strlen($a->user['allow_gid']) ||
509 strlen($a->user['deny_cid']) || strlen($a->user['deny_gid']))) ? 'lock' : 'unlock'),
510 'default_perms' => ACL::getDefaultUserPermissions($a->user),
511 'acl' => ACL::getFullSelectorHTML(DI::page(), $a->user, true, $default_permissions),
512 'bang' => (($gid || $cid || $nets) ? '!' : ''),
513 'visitor' => 'block',
514 'profile_uid' => local_user(),
515 'content' => $content,
518 $o .= status_editor($a, $x);
521 // We don't have to deal with ACLs on this page. You're looking at everything
522 // that belongs to you, hence you can see all of it. We will filter by group if
525 $sql_post_table = '';
526 $sql_options = ($star ? " AND `thread`.`starred` " : '');
527 $sql_extra = $sql_options;
530 $sql_table = '`thread`';
531 $sql_parent = '`iid`';
534 $sql_table = '`item`';
535 $sql_parent = '`parent`';
536 $sql_post_table = " INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`";
539 $sql_nets = (($nets) ? sprintf(" AND $sql_table.`network` = '%s' ", DBA::escape($nets)) : '');
542 $group = DBA::selectFirst('group', ['name'], ['id' => $gid, 'uid' => local_user()]);
543 if (!DBA::isResult($group)) {
547 notice(DI::l10n()->t('No such group'));
548 DI::baseUrl()->redirect('network/0');
552 $contacts = Group::expand(local_user(), [$gid]);
554 if ((is_array($contacts)) && count($contacts)) {
555 $contact_str_self = '';
557 $contact_str = implode(',', $contacts);
558 $self = DBA::selectFirst('contact', ['id'], ['uid' => local_user(), 'self' => true]);
559 if (DBA::isResult($self)) {
560 $contact_str_self = $self['id'];
563 $sql_post_table .= " INNER JOIN `item` AS `temp1` ON `temp1`.`id` = " . $sql_table . "." . $sql_parent;
564 $sql_extra3 .= " AND (`thread`.`contact-id` IN ($contact_str) ";
565 $sql_extra3 .= " OR (`thread`.`contact-id` = '$contact_str_self' AND `temp1`.`allow_gid` LIKE '" . Strings::protectSprintf('%<' . intval($gid) . '>%') . "' AND `temp1`.`private`))";
567 $sql_extra3 .= " AND false ";
568 notice(DI::l10n()->t('Group is empty'));
571 $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), [
572 '$title' => DI::l10n()->t('Group: %s', $group['name'])
575 $fields = ['id', 'name', 'network', 'writable', 'nurl',
576 'forum', 'prv', 'contact-type', 'addr', 'thumb', 'location'];
577 $condition = ["`id` = ? AND (NOT `blocked` OR `pending`)", $cid];
578 $contact = DBA::selectFirst('contact', $fields, $condition);
579 if (DBA::isResult($contact)) {
580 $sql_extra = " AND " . $sql_table . ".`contact-id` = " . intval($cid);
584 'name' => $contact['name'],
585 'itemurl' => ($contact['addr'] ?? '') ?: $contact['nurl'],
586 'thumb' => Contact::getThumb($contact),
587 'details' => $contact['location'],
590 $entries[0]['account_type'] = Contact::getAccountType($contact);
592 $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('viewcontact_template.tpl'), [
593 'contacts' => $entries,
597 notice(DI::l10n()->t('Invalid contact.'));
598 DI::baseUrl()->redirect('network');
603 if (!$gid && !$cid && !$update && !DI::config()->get('theme', 'hide_eventlist')) {
604 $o .= Profile::getBirthdays();
605 $o .= Profile::getEventsReminderHTML();
609 $sql_extra3 .= Strings::protectSprintf(sprintf(" AND $sql_table.received <= '%s' ",
610 DBA::escape(DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get()))));
613 $sql_extra3 .= Strings::protectSprintf(sprintf(" AND $sql_table.received >= '%s' ",
614 DBA::escape(DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get()))));
618 $sql_extra3 .= " AND $sql_table.`mention`";
621 // Normal conversation view
622 if ($order === 'post') {
623 $ordering = '`received`';
624 $order_mode = 'received';
626 $ordering = '`commented`';
627 $order_mode = 'commented';
630 $sql_order = "$sql_table.$ordering";
632 if (!empty($_GET['offset'])) {
633 $sql_range = sprintf(" AND $sql_order <= '%s'", DBA::escape($_GET['offset']));
638 $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
640 $pager_sql = networkPager($a, $pager, $update);
644 switch ($order_mode) {
646 if ($last_received != '') {
647 $last_date = $last_received;
648 $sql_range .= sprintf(" AND $sql_table.`received` < '%s'", DBA::escape($last_received));
650 $pager_sql = sprintf(" LIMIT %d, %d ", $pager->getStart(), $pager->getItemsPerPage());
654 if ($last_commented != '') {
655 $last_date = $last_commented;
656 $sql_range .= sprintf(" AND $sql_table.`commented` < '%s'", DBA::escape($last_commented));
658 $pager_sql = sprintf(" LIMIT %d, %d ", $pager->getStart(), $pager->getItemsPerPage());
662 if ($last_created != '') {
663 $last_date = $last_created;
664 $sql_range .= sprintf(" AND $sql_table.`created` < '%s'", DBA::escape($last_created));
666 $pager_sql = sprintf(" LIMIT %d, %d ", $pager->getStart(), $pager->getItemsPerPage());
670 if (($last_id > 0) && ($sql_table == '`thread`')) {
671 $sql_range .= sprintf(" AND $sql_table.`iid` < '%s'", DBA::escape($last_id));
673 $pager_sql = sprintf(" LIMIT %d, %d ", $pager->getStart(), $pager->getItemsPerPage());
678 // Fetch a page full of parent items for this page
680 if (!empty($parent)) {
681 // Load only a single thread
682 $sql_extra4 = "`item`.`id` = ".intval($parent);
684 // Load all unseen items
685 $sql_extra4 = "`item`.`unseen`";
686 if (DI::config()->get("system", "like_no_comment")) {
687 $sql_extra4 .= " AND `item`.`gravity` IN (" . GRAVITY_PARENT . "," . GRAVITY_COMMENT . ")";
689 if ($order === 'post') {
690 // Only show toplevel posts when updating posts in this order mode
691 $sql_extra4 .= " AND `item`.`gravity` = " . GRAVITY_PARENT;
695 $r = q("SELECT `item`.`parent-uri` AS `uri`, `item`.`parent` AS `item_id`, $sql_order AS `order_date`
696 FROM `item` $sql_post_table
697 STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
698 AND (NOT `contact`.`blocked` OR `contact`.`pending`)
699 AND (`item`.`gravity` != %d
700 OR `contact`.`uid` = `item`.`uid` AND `contact`.`self`
701 OR `contact`.`rel` IN (%d, %d) AND NOT `contact`.`readonly`)
702 LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = %d
703 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted`
704 AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`)
705 AND NOT `item`.`moderated` AND $sql_extra4
706 $sql_extra3 $sql_extra $sql_range $sql_nets
707 ORDER BY `order_date` DESC LIMIT 100",
708 intval(GRAVITY_PARENT),
709 intval(Contact::SHARING),
710 intval(Contact::FRIEND),
711 intval(local_user()),
715 $r = q("SELECT `item`.`uri`, `thread`.`iid` AS `item_id`, $sql_order AS `order_date`
716 FROM `thread` $sql_post_table
717 STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
718 AND (NOT `contact`.`blocked` OR `contact`.`pending`)
719 STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
720 AND (`item`.`gravity` != %d
721 OR `contact`.`uid` = `item`.`uid` AND `contact`.`self`
722 OR `contact`.`rel` IN (%d, %d) AND NOT `contact`.`readonly`)
723 LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = %d
724 WHERE `thread`.`uid` = %d AND `thread`.`visible` AND NOT `thread`.`deleted`
725 AND NOT `thread`.`moderated`
726 AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`)
727 $sql_extra2 $sql_extra3 $sql_range $sql_extra $sql_nets
728 ORDER BY `order_date` DESC $pager_sql",
729 intval(GRAVITY_PARENT),
730 intval(Contact::SHARING),
731 intval(Contact::FRIEND),
732 intval(local_user()),
742 if (DBA::isResult($items)) {
745 foreach ($items as $item) {
746 if ($date_offset < $item['order_date']) {
747 $date_offset = $item['order_date'];
749 if (!in_array($item['item_id'], $parents_arr) && ($item['item_id'] > 0)) {
750 $parents_arr[] = $item['item_id'];
753 $parents_str = implode(', ', $parents_arr);
756 if (!empty($_GET['offset'])) {
757 $date_offset = $_GET['offset'];
760 $query_string = DI::args()->getQueryString();
761 if ($date_offset && !preg_match('/[?&].offset=/', $query_string)) {
762 $query_string .= '&offset=' . urlencode($date_offset);
765 $pager->setQueryString($query_string);
767 // We aren't going to try and figure out at the item, group, and page
768 // level which items you've seen and which you haven't. If you're looking
769 // at the top level network page just mark everything seen.
771 if (!$gid && !$cid && !$star) {
772 $condition = ['unseen' => true, 'uid' => local_user()];
773 networkSetSeen($condition);
774 } elseif ($parents_str) {
775 $condition = ["`uid` = ? AND `unseen` AND `parent` IN (" . DBA::escape($parents_str) . ")", local_user()];
776 networkSetSeen($condition);
781 $o .= networkConversation($a, $items, $pager, $mode, $update, $ordering);
787 * Get the network tabs menu
789 * @param App $a The global App
790 * @return string Html of the networktab
791 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
793 function network_tabs(App $a)
796 /// @TODO fix this logic, reduce duplication
797 /// DI::page()['content'] .= '<div class="tabs-wrapper">';
798 list($no_active, $all_active, $post_active, $conv_active, $starred_active) = network_query_get_sel_tab($a);
800 // if no tabs are selected, defaults to activitys
801 if ($no_active == 'active') {
802 $all_active = 'active';
805 $cmd = DI::args()->getCommand();
808 if (!empty($_GET['contactid'])) {
809 $def_param['contactid'] = $_GET['contactid'];
815 'label' => DI::l10n()->t('Latest Activity'),
816 'url' => $cmd . '?' . http_build_query(array_merge($def_param, ['order' => 'activity'])),
817 'sel' => $all_active,
818 'title' => DI::l10n()->t('Sort by latest activity'),
819 'id' => 'activity-order-tab',
823 'label' => DI::l10n()->t('Latest Posts'),
824 'url' => $cmd . '?' . http_build_query(array_merge($def_param, ['order' => 'post'])),
825 'sel' => $post_active,
826 'title' => DI::l10n()->t('Sort by post received date'),
827 'id' => 'post-order-tab',
833 'label' => DI::l10n()->t('Personal'),
834 'url' => $cmd . '?' . http_build_query(array_merge($def_param, ['conv' => true])),
835 'sel' => $conv_active,
836 'title' => DI::l10n()->t('Posts that mention or involve you'),
837 'id' => 'personal-tab',
842 'label' => DI::l10n()->t('Starred'),
843 'url' => $cmd . '?' . http_build_query(array_merge($def_param, ['star' => true])),
844 'sel' => $starred_active,
845 'title' => DI::l10n()->t('Favourite Posts'),
846 'id' => 'starred-posts-tab',
850 // save selected tab, but only if not in file mode
851 if (empty($_GET['file'])) {
852 DI::pConfig()->set(local_user(), 'network.view', 'tab.selected', [
853 $all_active, $post_active, $conv_active, $starred_active
857 $arr = ['tabs' => $tabs];
858 Hook::callAll('network_tabs', $arr);
860 $tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
862 return Renderer::replaceMacros($tpl, ['$tabs' => $arr['tabs']]);
864 // --- end item filter tabs
868 * Network hook into the HTML head to enable infinite scroll.
870 * Since the HTML head is built after the module content has been generated, we need to retrieve the base query string
871 * of the page to make the correct asynchronous call. This is obtained through the Pager that was instantiated in
872 * networkThreadedView or networkFlatView.
875 * @param string $htmlhead The head tag HTML string
876 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
877 * @global Pager $pager
879 function network_infinite_scroll_head(App $a, &$htmlhead)
881 /// @TODO this will have to be converted to a static property of the converted Module\Network class
887 if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')
888 && ($_GET['mode'] ?? '') != 'minimal'
890 $tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
891 $htmlhead .= Renderer::replaceMacros($tpl, [
892 '$pageno' => $pager->getPage(),
893 '$reload_uri' => $pager->getBaseQueryString()