3 * @copyright Copyright (C) 2010-2022, 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\Nav;
25 use Friendica\Content\Pager;
26 use Friendica\Content\Text\HTML;
27 use Friendica\Content\Widget;
28 use Friendica\Core\Renderer;
29 use Friendica\Database\DBA;
31 use Friendica\Model\Item;
32 use Friendica\Model\Post;
33 use Friendica\Model\Post\Category;
34 use Friendica\Module\BaseSearch;
35 use Friendica\Module\Security\Login;
37 class Filed extends BaseSearch
39 protected function content(array $request = []): string
45 DI::page()['aside'] .= Widget::fileAs(DI::args()->getCommand(), $_GET['file'] ?? '');
47 if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll') && ($_GET['mode'] ?? '') != 'minimal') {
48 $tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
49 $o = Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
54 $file = $_GET['file'] ?? '';
56 // Rawmode is used for fetching new content at the end of the page
57 if (!(isset($_GET['mode']) && ($_GET['mode'] == 'raw'))) {
58 Nav::setSelected(DI::args()->get(0));
61 if (DI::mode()->isMobile()) {
62 $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network',
63 DI::config()->get('system', 'itemspage_network_mobile'));
65 $itemspage_network = DI::pConfig()->get(local_user(), 'system', 'itemspage_network',
66 DI::config()->get('system', 'itemspage_network'));
69 $last_uriid = isset($_GET['last_uriid']) ? intval($_GET['last_uriid']) : 0;
71 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemspage_network);
73 $term_condition = ['type' => Category::FILE, 'uid' => local_user()];
75 $term_condition['name'] = $file;
78 if (!empty($last_uriid)) {
79 $term_condition = DBA::mergeConditions($term_condition, ["`uri-id` < ?", $last_uriid]);
82 $term_params = ['order' => ['uri-id' => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
83 $result = DBA::select('category-view', ['uri-id'], $term_condition, $term_params);
85 $count = DBA::count('category-view', $term_condition);
88 while ($term = DBA::fetch($result)) {
89 $posts[] = $term['uri-id'];
93 if (count($posts) == 0) {
96 $item_condition = ['uid' => [0, local_user()], 'uri-id' => $posts];
97 $item_params = ['order' => ['uri-id' => true, 'uid' => true]];
99 $items = Post::toArray(Post::selectForUser(local_user(), Item::DISPLAY_FIELDLIST, $item_condition, $item_params));
101 $o .= DI::conversation()->create($items, 'filed', false, false, '', local_user());
103 if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
104 $o .= HTML::scrollLoader();
106 $o .= $pager->renderMinimal($count);