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\Feature;
24 use Friendica\Content\ForumManager;
25 use Friendica\Content\Nav;
26 use Friendica\Content\Pager;
27 use Friendica\Content\Widget;
28 use Friendica\Content\Text\HTML;
29 use Friendica\Core\ACL;
30 use Friendica\Core\Hook;
31 use Friendica\Core\Logger;
32 use Friendica\Core\Protocol;
33 use Friendica\Core\Renderer;
34 use Friendica\Core\Session;
35 use Friendica\Database\DBA;
37 use Friendica\Model\Contact;
38 use Friendica\Model\Group;
39 use Friendica\Model\Item;
40 use Friendica\Model\Post\Category;
41 use Friendica\Model\Profile;
42 use Friendica\Module\Security\Login;
43 use Friendica\Util\DateTimeFormat;
44 use Friendica\Util\Proxy as ProxyUtils;
45 use Friendica\Util\Strings;
47 function network_init(App $a)
50 notice(DI::l10n()->t('Permission denied.') . EOL);
54 Hook::add('head', __FILE__, 'network_infinite_scroll_head');
56 $is_a_date_query = false;
58 $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0);
61 if (!empty($_GET['contactid'])) {
62 $cid = $_GET['contactid'];
68 for ($x = 1; $x < $a->argc; $x ++) {
69 if (DI::dtFormat()->isYearMonthDay($a->argv[$x])) {
70 $is_a_date_query = true;
76 // convert query string to array. remove friendica args
78 parse_str(parse_url(DI::args()->getQueryString(), PHP_URL_QUERY), $query_array);
80 // fetch last used network view and redirect if needed
81 if (!$is_a_date_query) {
82 $sel_nets = $_GET['nets'] ?? '';
83 $sel_tabs = network_query_get_sel_tab($a);
84 $sel_groups = network_query_get_sel_group($a);
85 $last_sel_tabs = DI::pConfig()->get(local_user(), 'network.view', 'tab.selected');
87 $remember_tab = ($sel_tabs[0] === 'active' && is_array($last_sel_tabs) && $last_sel_tabs[0] !== 'active');
89 $net_baseurl = '/network';
92 if ($sel_groups !== false) {
93 $net_baseurl .= '/' . $sel_groups;
97 // redirect if current selected tab is '/network' and
98 // last selected tab is _not_ '/network?order=activity'.
99 // and this isn't a date query
102 'order=activity', //all
103 'order=post', //postord
108 $k = array_search('active', $last_sel_tabs);
111 // parse out tab queries
113 $dest_qs = $tab_args[$k];
114 parse_str($dest_qs, $dest_qa);
115 $net_args = array_merge($net_args, $dest_qa);
117 $remember_tab = false;
122 $net_args['nets'] = $sel_nets;
126 $net_args = array_merge($query_array, $net_args);
127 $net_queries = http_build_query($net_args);
129 $redir_url = ($net_queries ? $net_baseurl . '?' . $net_queries : $net_baseurl);
131 DI::baseUrl()->redirect($redir_url);
135 if (empty(DI::page()['aside'])) {
136 DI::page()['aside'] = '';
139 DI::page()['aside'] .= Group::sidebarWidget('network/0', 'network', 'standard', $group_id);
140 DI::page()['aside'] .= ForumManager::widget(local_user(), $cid);
141 DI::page()['aside'] .= Widget::postedByYear('network', local_user(), false);
142 DI::page()['aside'] .= Widget::networks('network', $_GET['nets'] ?? '');
143 DI::page()['aside'] .= Widget\SavedSearches::getHTML(DI::args()->getQueryString());
144 DI::page()['aside'] .= Widget::fileAs('network', $_GET['file'] ?? '');
148 * Return selected tab from query
151 * '/network' => $no_active = 'active'
152 * '/network?order=activity' => $activity_active = 'active'
153 * '/network?order=post' => $postord_active = 'active'
154 * '/network?conv=1', => $conv_active = 'active'
155 * '/network?star=1', => $starred_active = 'active'
158 * @return array ($no_active, $activity_active, $postord_active, $conv_active, $starred_active);
160 function network_query_get_sel_tab(App $a)
163 $starred_active = '';
166 $postord_active = '';
168 if (!empty($_GET['star'])) {
169 $starred_active = 'active';
172 if (!empty($_GET['conv'])) {
173 $conv_active = 'active';
176 if (($starred_active == '') && ($conv_active == '')) {
177 $no_active = 'active';
180 if ($no_active == 'active' && !empty($_GET['order'])) {
181 switch($_GET['order']) {
182 case 'post' : $postord_active = 'active'; $no_active=''; break;
183 case 'activity' : $all_active = 'active'; $no_active=''; break;
187 return [$no_active, $all_active, $postord_active, $conv_active, $starred_active];
190 function network_query_get_sel_group(App $a)
194 if ($a->argc >= 2 && is_numeric($a->argv[1])) {
195 $group = $a->argv[1];
202 * Sets the pager data and returns SQL
204 * @param App $a The global App
205 * @param Pager $pager
206 * @param integer $update Used for the automatic reloading
207 * @return string SQL with the appropriate LIMIT clause
208 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
210 function networkPager(App $a, Pager $pager, $update)
213 // only setup pagination on initial page view
217 if (DI::mode()->isMobile()) {
218 $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network',
219 DI::config()->get('system', 'itemspage_network_mobile'));
221 $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_network',
222 DI::config()->get('system', 'itemspage_network'));
225 // now that we have the user settings, see if the theme forces
226 // a maximum item number which is lower then the user choice
227 if (($a->force_max_items > 0) && ($a->force_max_items < $itemspage_network)) {
228 $itemspage_network = $a->force_max_items;
231 $pager->setItemsPerPage($itemspage_network);
233 return sprintf(" LIMIT %d, %d ", $pager->getStart(), $pager->getItemsPerPage());
239 * @param array $condition The array with the SQL condition
240 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
242 function networkSetSeen($condition)
244 if (empty($condition)) {
248 $unseen = Item::exists($condition);
251 Item::update(['unseen' => false], $condition);
256 * Create the conversation HTML
258 * @param App $a The global App
259 * @param array $items Items of the conversation
260 * @param Pager $pager
261 * @param string $mode Display mode for the conversation
262 * @param integer $update Used for the automatic reloading
263 * @param string $ordering
264 * @return string HTML of the conversation
265 * @throws ImagickException
266 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
268 function networkConversation(App $a, $items, Pager $pager, $mode, $update, $ordering = '')
270 // Set this so that the conversation function can find out contact info for our wall-wall items
271 $a->page_contact = $a->contact;
273 if (!is_array($items)) {
274 Logger::info('Expecting items to be an array.', ['items' => $items]);
278 $o = conversation($a, $items, $mode, $update, false, $ordering, local_user());
281 if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
282 $o .= HTML::scrollLoader();
284 $o .= $pager->renderMinimal(count($items));
291 function network_content(App $a, $update = 0, $parent = 0)
294 return Login::form();
297 /// @TODO Is this really necessary? $a is already available to hooks
298 $arr = ['query' => DI::args()->getQueryString()];
299 Hook::callAll('network_content_init', $arr);
301 if (!empty($_GET['file'])) {
302 $o = networkFlatView($a, $update);
304 $o = networkThreadedView($a, $update, $parent);
308 info("No items found");
315 * Get the network content in flat view
317 * @param App $a The global App
318 * @param integer $update Used for the automatic reloading
319 * @return string HTML of the network content in flat view
320 * @throws ImagickException
321 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
322 * @global Pager $pager
324 function networkFlatView(App $a, $update = 0)
327 // Rawmode is used for fetching new content at the end of the page
328 $rawmode = (isset($_GET['mode']) && ($_GET['mode'] == 'raw'));
332 $file = $_GET['file'] ?? '';
334 if (!$update && !$rawmode) {
335 $tabs = network_tabs($a);
338 Nav::setSelected('network');
342 'allow_location' => $a->user['allow_location'],
343 'default_location' => $a->user['default-location'],
344 'nickname' => $a->user['nickname'],
345 'lockstate' => (is_array($a->user) &&
346 (strlen($a->user['allow_cid']) || strlen($a->user['allow_gid']) ||
347 strlen($a->user['deny_cid']) || strlen($a->user['deny_gid'])) ? 'lock' : 'unlock'),
348 'default_perms' => ACL::getDefaultUserPermissions($a->user),
349 'acl' => ACL::getFullSelectorHTML(DI::page(), $a->user, true),
351 'visitor' => 'block',
352 'profile_uid' => local_user(),
356 $o .= status_editor($a, $x);
358 if (!DI::config()->get('theme', 'hide_eventlist')) {
359 $o .= Profile::getBirthdays();
360 $o .= Profile::getEventsReminderHTML();
364 $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
366 networkPager($a, $pager, $update);
370 $item_params = ['order' => ['uri-id' => true]];
371 $term_condition = ['name' => $file, 'type' => Category::FILE, 'uid' => local_user()];
372 $term_params = ['order' => ['uri-id' => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
373 $result = DBA::select('category-view', ['uri-id'], $term_condition, $term_params);
376 while ($term = DBA::fetch($result)) {
377 $posts[] = $term['uri-id'];
381 if (count($posts) == 0) {
384 $item_condition = ['uid' => local_user(), 'uri-id' => $posts];
386 $item_params = ['order' => ['id' => true]];
387 $item_condition = ['uid' => local_user()];
388 $item_params['limit'] = [$pager->getStart(), $pager->getItemsPerPage()];
390 networkSetSeen(['unseen' => true, 'uid' => local_user()]);
393 $result = Item::selectForUser(local_user(), [], $item_condition, $item_params);
394 $items = Item::inArray($result);
395 $o .= networkConversation($a, $items, $pager, 'network-new', $update);
401 * Get the network content in threaded view
403 * @param App $a The global App
404 * @param integer $update Used for the automatic reloading
405 * @param integer $parent
406 * @return string HTML of the network content in flat view
407 * @throws ImagickException
408 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
409 * @global Pager $pager
411 function networkThreadedView(App $a, $update, $parent)
413 /// @TODO this will have to be converted to a static property of the converted Module\Network class
416 // Rawmode is used for fetching new content at the end of the page
417 $rawmode = (isset($_GET['mode']) AND ( $_GET['mode'] == 'raw'));
419 if (isset($_GET['last_received']) && isset($_GET['last_commented']) && isset($_GET['last_created']) && isset($_GET['last_id'])) {
420 $last_received = DateTimeFormat::utc($_GET['last_received']);
421 $last_commented = DateTimeFormat::utc($_GET['last_commented']);
422 $last_created = DateTimeFormat::utc($_GET['last_created']);
423 $last_id = intval($_GET['last_id']);
426 $last_commented = '';
431 $datequery = $datequery2 = '';
435 $default_permissions = [];
438 for ($x = 1; $x < $a->argc; $x ++) {
439 if (DI::dtFormat()->isYearMonthDay($a->argv[$x])) {
441 $datequery2 = Strings::escapeHtml($a->argv[$x]);
443 $datequery = Strings::escapeHtml($a->argv[$x]);
444 $_GET['order'] = 'post';
446 } elseif (intval($a->argv[$x])) {
447 $gid = intval($a->argv[$x]);
448 $default_permissions['allow_gid'] = [$gid];
455 $cid = intval($_GET['contactid'] ?? 0);
456 $star = intval($_GET['star'] ?? 0);
457 $conv = intval($_GET['conv'] ?? 0);
458 $order = Strings::escapeTags(($_GET['order'] ?? '') ?: 'activity');
459 $nets = $_GET['nets'] ?? '';
463 $allowedCids[] = (int) $cid;
466 'uid' => local_user(),
472 'rel' => [Contact::SHARING, Contact::FRIEND],
474 $contactStmt = DBA::select('contact', ['id'], $condition);
475 while ($contact = DBA::fetch($contactStmt)) {
476 $allowedCids[] = (int) $contact['id'];
478 DBA::close($contactStmt);
481 if (count($allowedCids)) {
482 $default_permissions['allow_cid'] = $allowedCids;
485 if (!$update && !$rawmode) {
486 $tabs = network_tabs($a);
489 Nav::setSelected('network');
494 // If $cid belongs to a communitity forum or a privat goup,.add a mention to the status editor
495 $condition = ["`id` = ? AND (`forum` OR `prv`)", $cid];
496 $contact = DBA::selectFirst('contact', ['addr', 'nick'], $condition);
497 if (DBA::isResult($contact)) {
498 if ($contact['addr'] != '') {
499 $content = '!' . $contact['addr'];
501 $content = '!' . $contact['nick'] . '+' . $cid;
508 'allow_location' => $a->user['allow_location'],
509 'default_location' => $a->user['default-location'],
510 'nickname' => $a->user['nickname'],
511 'lockstate' => ($gid || $cid || $nets || (is_array($a->user) &&
512 (strlen($a->user['allow_cid']) || strlen($a->user['allow_gid']) ||
513 strlen($a->user['deny_cid']) || strlen($a->user['deny_gid']))) ? 'lock' : 'unlock'),
514 'default_perms' => ACL::getDefaultUserPermissions($a->user),
515 'acl' => ACL::getFullSelectorHTML(DI::page(), $a->user, true, $default_permissions),
516 'bang' => (($gid || $cid || $nets) ? '!' : ''),
517 'visitor' => 'block',
518 'profile_uid' => local_user(),
519 'content' => $content,
522 $o .= status_editor($a, $x);
525 // We don't have to deal with ACLs on this page. You're looking at everything
526 // that belongs to you, hence you can see all of it. We will filter by group if
529 $sql_post_table = '';
530 $sql_options = ($star ? " AND `thread`.`starred` " : '');
531 $sql_extra = $sql_options;
534 $sql_table = '`thread`';
535 $sql_parent = '`iid`';
538 $sql_table = '`item`';
539 $sql_parent = '`parent`';
540 $sql_post_table = " INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`";
543 $sql_nets = (($nets) ? sprintf(" AND $sql_table.`network` = '%s' ", DBA::escape($nets)) : '');
546 $group = DBA::selectFirst('group', ['name'], ['id' => $gid, 'uid' => local_user()]);
547 if (!DBA::isResult($group)) {
551 notice(DI::l10n()->t('No such group') . EOL);
552 DI::baseUrl()->redirect('network/0');
556 $contacts = Group::expand(local_user(), [$gid]);
558 if ((is_array($contacts)) && count($contacts)) {
559 $contact_str_self = '';
561 $contact_str = implode(',', $contacts);
562 $self = DBA::selectFirst('contact', ['id'], ['uid' => local_user(), 'self' => true]);
563 if (DBA::isResult($self)) {
564 $contact_str_self = $self['id'];
567 $sql_post_table .= " INNER JOIN `item` AS `temp1` ON `temp1`.`id` = " . $sql_table . "." . $sql_parent;
568 $sql_extra3 .= " AND (`thread`.`contact-id` IN ($contact_str) ";
569 $sql_extra3 .= " OR (`thread`.`contact-id` = '$contact_str_self' AND `temp1`.`allow_gid` LIKE '" . Strings::protectSprintf('%<' . intval($gid) . '>%') . "' AND `temp1`.`private`))";
571 $sql_extra3 .= " AND false ";
572 info(DI::l10n()->t('Group is empty'));
575 $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), [
576 '$title' => DI::l10n()->t('Group: %s', $group['name'])
579 $fields = ['id', 'name', 'network', 'writable', 'nurl',
580 'forum', 'prv', 'contact-type', 'addr', 'thumb', 'location'];
581 $condition = ["`id` = ? AND (NOT `blocked` OR `pending`)", $cid];
582 $contact = DBA::selectFirst('contact', $fields, $condition);
583 if (DBA::isResult($contact)) {
584 $sql_extra = " AND " . $sql_table . ".`contact-id` = " . intval($cid);
588 'name' => $contact['name'],
589 'itemurl' => ($contact['addr'] ?? '') ?: $contact['nurl'],
590 'thumb' => ProxyUtils::proxifyUrl($contact['thumb'], false, ProxyUtils::SIZE_THUMB),
591 'details' => $contact['location'],
594 $entries[0]['account_type'] = Contact::getAccountType($contact);
596 $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('viewcontact_template.tpl'), [
597 'contacts' => $entries,
601 notice(DI::l10n()->t('Invalid contact.') . EOL);
602 DI::baseUrl()->redirect('network');
607 if (!$gid && !$cid && !$update && !DI::config()->get('theme', 'hide_eventlist')) {
608 $o .= Profile::getBirthdays();
609 $o .= Profile::getEventsReminderHTML();
613 $sql_extra3 .= Strings::protectSprintf(sprintf(" AND $sql_table.received <= '%s' ",
614 DBA::escape(DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get()))));
617 $sql_extra3 .= Strings::protectSprintf(sprintf(" AND $sql_table.received >= '%s' ",
618 DBA::escape(DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get()))));
622 $sql_extra3 .= " AND $sql_table.`mention`";
625 // Normal conversation view
626 if ($order === 'post') {
627 $ordering = '`received`';
628 $order_mode = 'received';
630 $ordering = '`commented`';
631 $order_mode = 'commented';
634 $sql_order = "$sql_table.$ordering";
636 if (!empty($_GET['offset'])) {
637 $sql_range = sprintf(" AND $sql_order <= '%s'", DBA::escape($_GET['offset']));
642 $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
644 $pager_sql = networkPager($a, $pager, $update);
648 switch ($order_mode) {
650 if ($last_received != '') {
651 $last_date = $last_received;
652 $sql_range .= sprintf(" AND $sql_table.`received` < '%s'", DBA::escape($last_received));
654 $pager_sql = sprintf(" LIMIT %d, %d ", $pager->getStart(), $pager->getItemsPerPage());
658 if ($last_commented != '') {
659 $last_date = $last_commented;
660 $sql_range .= sprintf(" AND $sql_table.`commented` < '%s'", DBA::escape($last_commented));
662 $pager_sql = sprintf(" LIMIT %d, %d ", $pager->getStart(), $pager->getItemsPerPage());
666 if ($last_created != '') {
667 $last_date = $last_created;
668 $sql_range .= sprintf(" AND $sql_table.`created` < '%s'", DBA::escape($last_created));
670 $pager_sql = sprintf(" LIMIT %d, %d ", $pager->getStart(), $pager->getItemsPerPage());
674 if (($last_id > 0) && ($sql_table == '`thread`')) {
675 $sql_range .= sprintf(" AND $sql_table.`iid` < '%s'", DBA::escape($last_id));
677 $pager_sql = sprintf(" LIMIT %d, %d ", $pager->getStart(), $pager->getItemsPerPage());
682 // Fetch a page full of parent items for this page
684 if (!empty($parent)) {
685 // Load only a single thread
686 $sql_extra4 = "`item`.`id` = ".intval($parent);
688 // Load all unseen items
689 $sql_extra4 = "`item`.`unseen`";
690 if (DI::config()->get("system", "like_no_comment")) {
691 $sql_extra4 .= " AND `item`.`gravity` IN (" . GRAVITY_PARENT . "," . GRAVITY_COMMENT . ")";
693 if ($order === 'post') {
694 // Only show toplevel posts when updating posts in this order mode
695 $sql_extra4 .= " AND `item`.`gravity` = " . GRAVITY_PARENT;
699 $r = q("SELECT `item`.`parent-uri` AS `uri`, `item`.`parent` AS `item_id`, $sql_order AS `order_date`
700 FROM `item` $sql_post_table
701 STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
702 AND (NOT `contact`.`blocked` OR `contact`.`pending`)
703 AND (`item`.`gravity` != %d
704 OR `contact`.`uid` = `item`.`uid` AND `contact`.`self`
705 OR `contact`.`rel` IN (%d, %d) AND NOT `contact`.`readonly`)
706 LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = %d
707 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted`
708 AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`)
709 AND NOT `item`.`moderated` AND $sql_extra4
710 $sql_extra3 $sql_extra $sql_range $sql_nets
711 ORDER BY `order_date` DESC LIMIT 100",
712 intval(GRAVITY_PARENT),
713 intval(Contact::SHARING),
714 intval(Contact::FRIEND),
715 intval(local_user()),
719 $r = q("SELECT `item`.`uri`, `thread`.`iid` AS `item_id`, $sql_order AS `order_date`
720 FROM `thread` $sql_post_table
721 STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
722 AND (NOT `contact`.`blocked` OR `contact`.`pending`)
723 STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
724 AND (`item`.`gravity` != %d
725 OR `contact`.`uid` = `item`.`uid` AND `contact`.`self`
726 OR `contact`.`rel` IN (%d, %d) AND NOT `contact`.`readonly`)
727 LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = %d
728 WHERE `thread`.`uid` = %d AND `thread`.`visible` AND NOT `thread`.`deleted`
729 AND NOT `thread`.`moderated`
730 AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`)
731 $sql_extra2 $sql_extra3 $sql_range $sql_extra $sql_nets
732 ORDER BY `order_date` DESC $pager_sql",
733 intval(GRAVITY_PARENT),
734 intval(Contact::SHARING),
735 intval(Contact::FRIEND),
736 intval(local_user()),
746 if (DBA::isResult($items)) {
749 foreach ($items as $item) {
750 if ($date_offset < $item['order_date']) {
751 $date_offset = $item['order_date'];
753 if (!in_array($item['item_id'], $parents_arr) && ($item['item_id'] > 0)) {
754 $parents_arr[] = $item['item_id'];
757 $parents_str = implode(', ', $parents_arr);
760 if (!empty($_GET['offset'])) {
761 $date_offset = $_GET['offset'];
764 $query_string = DI::args()->getQueryString();
765 if ($date_offset && !preg_match('/[?&].offset=/', $query_string)) {
766 $query_string .= '&offset=' . urlencode($date_offset);
769 $pager->setQueryString($query_string);
771 // We aren't going to try and figure out at the item, group, and page
772 // level which items you've seen and which you haven't. If you're looking
773 // at the top level network page just mark everything seen.
775 if (!$gid && !$cid && !$star) {
776 $condition = ['unseen' => true, 'uid' => local_user()];
777 networkSetSeen($condition);
778 } elseif ($parents_str) {
779 $condition = ["`uid` = ? AND `unseen` AND `parent` IN (" . DBA::escape($parents_str) . ")", local_user()];
780 networkSetSeen($condition);
785 $o .= networkConversation($a, $items, $pager, $mode, $update, $ordering);
791 * Get the network tabs menu
793 * @param App $a The global App
794 * @return string Html of the networktab
795 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
797 function network_tabs(App $a)
800 /// @TODO fix this logic, reduce duplication
801 /// DI::page()['content'] .= '<div class="tabs-wrapper">';
802 list($no_active, $all_active, $post_active, $conv_active, $starred_active) = network_query_get_sel_tab($a);
804 // if no tabs are selected, defaults to activitys
805 if ($no_active == 'active') {
806 $all_active = 'active';
809 $cmd = DI::args()->getCommand();
812 if (!empty($_GET['contactid'])) {
813 $def_param['contactid'] = $_GET['contactid'];
819 'label' => DI::l10n()->t('Latest Activity'),
820 'url' => $cmd . '?' . http_build_query(array_merge($def_param, ['order' => 'activity'])),
821 'sel' => $all_active,
822 'title' => DI::l10n()->t('Sort by latest activity'),
823 'id' => 'activity-order-tab',
827 'label' => DI::l10n()->t('Latest Posts'),
828 'url' => $cmd . '?' . http_build_query(array_merge($def_param, ['order' => 'post'])),
829 'sel' => $post_active,
830 'title' => DI::l10n()->t('Sort by post received date'),
831 'id' => 'post-order-tab',
837 'label' => DI::l10n()->t('Personal'),
838 'url' => $cmd . '?' . http_build_query(array_merge($def_param, ['conv' => true])),
839 'sel' => $conv_active,
840 'title' => DI::l10n()->t('Posts that mention or involve you'),
841 'id' => 'personal-tab',
846 'label' => DI::l10n()->t('Starred'),
847 'url' => $cmd . '?' . http_build_query(array_merge($def_param, ['star' => true])),
848 'sel' => $starred_active,
849 'title' => DI::l10n()->t('Favourite Posts'),
850 'id' => 'starred-posts-tab',
854 // save selected tab, but only if not in file mode
855 if (empty($_GET['file'])) {
856 DI::pConfig()->set(local_user(), 'network.view', 'tab.selected', [
857 $all_active, $post_active, $conv_active, $starred_active
861 $arr = ['tabs' => $tabs];
862 Hook::callAll('network_tabs', $arr);
864 $tpl = Renderer::getMarkupTemplate('common_tabs.tpl');
866 return Renderer::replaceMacros($tpl, ['$tabs' => $arr['tabs']]);
868 // --- end item filter tabs
872 * Network hook into the HTML head to enable infinite scroll.
874 * Since the HTML head is built after the module content has been generated, we need to retrieve the base query string
875 * of the page to make the correct asynchronous call. This is obtained through the Pager that was instantiated in
876 * networkThreadedView or networkFlatView.
879 * @param string $htmlhead The head tag HTML string
880 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
881 * @global Pager $pager
883 function network_infinite_scroll_head(App $a, &$htmlhead)
885 /// @TODO this will have to be converted to a static property of the converted Module\Network class
891 if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')
892 && ($_GET['mode'] ?? '') != 'minimal'
894 $tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
895 $htmlhead .= Renderer::replaceMacros($tpl, [
896 '$pageno' => $pager->getPage(),
897 '$reload_uri' => $pager->getBaseQueryString()