3 * @copyright Copyright (C) 2010-2023, the Friendica project
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/>.
22 namespace Friendica\Module\Search;
24 use Friendica\Content\Conversation;
25 use Friendica\Content\Nav;
26 use Friendica\Content\Pager;
27 use Friendica\Content\Text\HTML;
28 use Friendica\Content\Widget;
29 use Friendica\Core\Renderer;
30 use Friendica\Database\DBA;
32 use Friendica\Model\Item;
33 use Friendica\Model\Post;
34 use Friendica\Model\Post\Category;
35 use Friendica\Module\BaseSearch;
36 use Friendica\Module\Security\Login;
38 class Filed extends BaseSearch
40 protected function content(array $request = []): string
42 if (!DI::userSession()->getLocalUserId()) {
46 DI::page()['aside'] .= Widget::fileAs(DI::args()->getCommand(), $_GET['file'] ?? '');
48 if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll') && ($_GET['mode'] ?? '') != 'minimal') {
49 $tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
50 $o = Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
55 $file = $_GET['file'] ?? '';
57 // Rawmode is used for fetching new content at the end of the page
58 if (!(isset($_GET['mode']) && ($_GET['mode'] == 'raw'))) {
59 Nav::setSelected(DI::args()->get(0));
62 if (DI::mode()->isMobile()) {
63 $itemspage_network = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_mobile_network',
64 DI::config()->get('system', 'itemspage_network_mobile'));
66 $itemspage_network = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_network',
67 DI::config()->get('system', 'itemspage_network'));
70 $last_uriid = isset($_GET['last_uriid']) ? intval($_GET['last_uriid']) : 0;
72 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemspage_network);
74 $term_condition = ['type' => Category::FILE, 'uid' => DI::userSession()->getLocalUserId()];
76 $term_condition['name'] = $file;
79 if (!empty($last_uriid)) {
80 $term_condition = DBA::mergeConditions($term_condition, ["`uri-id` < ?", $last_uriid]);
83 $term_params = ['order' => ['uri-id' => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
84 $result = DBA::select('category-view', ['uri-id'], $term_condition, $term_params);
86 $count = DBA::count('category-view', $term_condition);
89 while ($term = DBA::fetch($result)) {
90 $posts[] = $term['uri-id'];
94 if (count($posts) == 0) {
97 $item_condition = ['uid' => [0, DI::userSession()->getLocalUserId()], 'uri-id' => $posts];
98 $item_params = ['order' => ['uri-id' => true, 'uid' => true]];
100 $items = Post::toArray(Post::selectForUser(DI::userSession()->getLocalUserId(), Item::DISPLAY_FIELDLIST, $item_condition, $item_params));
102 $o .= DI::conversation()->render($items, Conversation::MODE_FILED, false, false, '', DI::userSession()->getLocalUserId());
104 if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll')) {
105 $o .= HTML::scrollLoader();
107 $o .= $pager->renderMinimal($count);