]> git.mxchange.org Git - friendica.git/blob - src/Module/Moderation/Reports.php
Merge pull request #13488 from MrPetovan/bug/frio-search-result-padding
[friendica.git] / src / Module / Moderation / Reports.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\Moderation;
23
24 use Friendica\App;
25 use Friendica\Content\Pager;
26 use Friendica\Content\Text\BBCode;
27 use Friendica\Core\L10n;
28 use Friendica\Core\Renderer;
29 use Friendica\Core\Session\Capability\IHandleUserSessions;
30 use Friendica\Database\Database;
31 use Friendica\Database\DBA;
32 use Friendica\Module\BaseModeration;
33 use Friendica\Module\Response;
34 use Friendica\Navigation\SystemMessages;
35 use Friendica\Util\DateTimeFormat;
36 use Friendica\Util\Profiler;
37 use Psr\Log\LoggerInterface;
38
39 class Reports extends BaseModeration
40 {
41         /** @var Database */
42         private $database;
43
44         public function __construct(Database $database, App\Page $page, App $app, SystemMessages $systemMessages, IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
45         {
46                 parent::__construct($page, $app, $systemMessages, $session, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
47
48                 $this->database = $database;
49         }
50
51         protected function content(array $request = []): string
52         {
53                 parent::content();
54
55                 $total = $this->database->count('report');
56
57                 $pager = new Pager($this->l10n, $this->args->getQueryString(), 10);
58
59                 $query = $this->database->p("SELECT `report`.`id`, `report`.`cid`, `report`.`comment`, `report`.`forward`, `report`.`created`, `report`.`reporter-id`,
60                         `report`.`category`, `report`.`rules`, `contact`.`micro`, `contact`.`name`, `contact`.`nick`, `contact`.`url`, `contact`.`addr` FROM report
61                         INNER JOIN `contact` ON `contact`.`id` = `report`.`cid` ORDER BY `report`.`created` DESC LIMIT ?, ?", $pager->getStart(), $pager->getItemsPerPage());
62
63                 $reports = [];
64                 while ($report = $this->database->fetch($query)) {
65                         $report['posts']   = [];
66                         $report['created'] = DateTimeFormat::local($report['created'], DateTimeFormat::MYSQL);
67
68                         $reports[$report['id']] = $report;
69                 }
70                 $this->database->close($query);
71
72                 $condition = ["SELECT `post-view`.`created`, `post-view`.`guid`, `post-view`.`plink`, `post-view`.`title`, `post-view`.`body`, `report-post`.`rid`
73                         FROM `report-post` INNER JOIN `post-view` ON `report-post`.`uri-id` = `post-view`.`uri-id`"];
74                 $condition = DBA::mergeConditions($condition, ['rid' => array_keys($reports)]);
75                 $posts     = $this->database->p(array_shift($condition), $condition);
76                 while ($post = $this->database->fetch($posts)) {
77                         if (in_array($post['rid'], array_keys($reports))) {
78                                 $post['created'] = DateTimeFormat::local($post['created'], DateTimeFormat::MYSQL);
79                                 $post['body']    = BBCode::toPlaintext($post['body']);
80
81                                 $reports[$post['rid']]['posts'][] = $post;
82                         }
83                 }
84                 $this->database->close($posts);
85
86                 $t = Renderer::getMarkupTemplate('moderation/report/overview.tpl');
87                 return Renderer::replaceMacros($t, [
88                         // strings //
89                         '$title'       => $this->t('Moderation'),
90                         '$page'        => $this->t('List of reports'),
91                         '$description' => $this->t('This page display reports created by our or remote users.'),
92                         '$no_data'     => $this->t('No report exists at this node.'),
93
94                         '$h_reports'  => $this->t('Reports'),
95                         '$th_reports' => [$this->t('Created'), $this->t('Photo'), $this->t('Name'), $this->t('Comment'), $this->t('Category')],
96
97                         // values //
98                         '$baseurl' => $this->baseUrl,
99
100                         '$reports'       => $reports,
101                         '$total_reports' => $this->tt('%s total report', '%s total reports', $total),
102                         '$paginate'      => $pager->renderFull($total),
103
104                         '$contacturl' => ['contact_url', $this->t('Profile URL'), '', $this->t('URL of the reported contact.')],
105                 ]);
106         }
107 }