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\Moderation;
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;
39 class Reports extends BaseModeration
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 = [])
46 parent::__construct($page, $app, $systemMessages, $session, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
48 $this->database = $database;
51 protected function content(array $request = []): string
55 $total = $this->database->count('report');
57 $pager = new Pager($this->l10n, $this->args->getQueryString(), 10);
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());
64 while ($report = $this->database->fetch($query)) {
65 $report['posts'] = [];
66 $report['created'] = DateTimeFormat::local($report['created'], DateTimeFormat::MYSQL);
68 $reports[$report['id']] = $report;
70 $this->database->close($query);
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']);
81 $reports[$post['rid']]['posts'][] = $post;
84 $this->database->close($posts);
86 $t = Renderer::getMarkupTemplate('moderation/report/overview.tpl');
87 return Renderer::replaceMacros($t, [
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.'),
94 '$h_reports' => $this->t('Reports'),
95 '$th_reports' => [$this->t('Created'), $this->t('Photo'), $this->t('Name'), $this->t('Comment'), $this->t('Category')],
98 '$baseurl' => $this->baseUrl,
100 '$reports' => $reports,
101 '$total_reports' => $this->tt('%s total report', '%s total reports', $total),
102 '$paginate' => $pager->renderFull($total),
104 '$contacturl' => ['contact_url', $this->t('Profile URL'), '', $this->t('URL of the reported contact.')],