]> git.mxchange.org Git - friendica.git/blob - src/Module/Search/Filed.php
The GNU-Social import is removed
[friendica.git] / src / Module / Search / Filed.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
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 namespace Friendica\Module\Search;
23
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;
30 use Friendica\DI;
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;
36
37 class Filed extends BaseSearch
38 {
39         protected function content(array $request = []): string
40         {
41                 if (!DI::userSession()->getLocalUserId()) {
42                         return Login::form();
43                 }
44
45                 DI::page()['aside'] .= Widget::fileAs(DI::args()->getCommand(), $_GET['file'] ?? '');
46
47                 if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll') && ($_GET['mode'] ?? '') != 'minimal') {
48                         $tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
49                         $o = Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
50                 } else {
51                         $o = '';
52                 }
53
54                 $file = $_GET['file'] ?? '';
55
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));
59                 }
60
61                 if (DI::mode()->isMobile()) {
62                         $itemspage_network = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_mobile_network',
63                                 DI::config()->get('system', 'itemspage_network_mobile'));
64                 } else {
65                         $itemspage_network = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'itemspage_network',
66                                 DI::config()->get('system', 'itemspage_network'));
67                 }
68
69                 $last_uriid = isset($_GET['last_uriid']) ? intval($_GET['last_uriid']) : 0;
70
71                 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemspage_network);
72
73                 $term_condition = ['type' => Category::FILE, 'uid' => DI::userSession()->getLocalUserId()];
74                 if ($file) {
75                         $term_condition['name'] = $file;
76                 }
77
78                 if (!empty($last_uriid)) {
79                         $term_condition = DBA::mergeConditions($term_condition, ["`uri-id` < ?", $last_uriid]);
80                 }
81
82                 $term_params = ['order' => ['uri-id' => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
83                 $result = DBA::select('category-view', ['uri-id'], $term_condition, $term_params);
84
85                 $count = DBA::count('category-view', $term_condition);
86
87                 $posts = [];
88                 while ($term = DBA::fetch($result)) {
89                         $posts[] = $term['uri-id'];
90                 }
91                 DBA::close($result);
92
93                 if (count($posts) == 0) {
94                         return '';
95                 }
96                 $item_condition = ['uid' => [0, DI::userSession()->getLocalUserId()], 'uri-id' => $posts];
97                 $item_params = ['order' => ['uri-id' => true, 'uid' => true]];
98
99                 $items = Post::toArray(Post::selectForUser(DI::userSession()->getLocalUserId(), Item::DISPLAY_FIELDLIST, $item_condition, $item_params));
100
101                 $o .= DI::conversation()->create($items, 'filed', false, false, '', DI::userSession()->getLocalUserId());
102
103                 if (DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'infinite_scroll')) {
104                         $o .= HTML::scrollLoader();
105                 } else {
106                         $o .= $pager->renderMinimal($count);
107                 }
108
109                 return $o;
110         }
111 }