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