]> git.mxchange.org Git - friendica.git/blob - src/Module/Moderation/Item/Source.php
Happy New Year 2023!
[friendica.git] / src / Module / Moderation / Item / Source.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\Item;
23
24 use Friendica\App;
25 use Friendica\Core\Config\Capability\IManageConfigValues;
26 use Friendica\Core\L10n;
27 use Friendica\Core\Renderer;
28 use Friendica\Core\Session\Capability\IHandleUserSessions;
29 use Friendica\Model;
30 use Friendica\Module\BaseModeration;
31 use Friendica\Module\Response;
32 use Friendica\Navigation\SystemMessages;
33 use Friendica\Util\Profiler;
34 use Psr\Log\LoggerInterface;
35
36 class Source extends BaseModeration
37 {
38         /** @var IManageConfigValues */
39         private $config;
40
41         public function __construct(IManageConfigValues $config, 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 = [])
42         {
43                 parent::__construct($page, $app, $systemMessages, $session, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
44
45                 $this->config = $config;
46         }
47
48         protected function content(array $request = []): string
49         {
50                 parent::content();
51
52                 $guid = basename($request['guid'] ?? $this->parameters['guid'] ?? '');
53
54                 $item_uri = '';
55                 $item_id = '';
56                 $terms = [];
57                 $source = '';
58                 if (!empty($guid)) {
59                         $item = Model\Post::selectFirst(['id', 'uri-id', 'guid', 'uri'], ['guid' => $guid]);
60
61                         if ($item) {
62                                 $item_id = $item['id'];
63                                 $item_uri = $item['uri'];
64                                 $terms = Model\Tag::getByURIId($item['uri-id'], [Model\Tag::HASHTAG, Model\Tag::MENTION, Model\Tag::IMPLICIT_MENTION]);
65
66                                 $activity = Model\Post\Activity::getByURIId($item['uri-id']);
67                                 if (!empty($activity)) {
68                                         $source = $activity['activity'];
69                                 }
70                         }
71                 }
72
73                 $tpl = Renderer::getMarkupTemplate('moderation/item/source.tpl');
74                 return Renderer::replaceMacros($tpl, [
75                         '$l10n' => [
76                                 'title'       => $this->t('Item Source'),
77                                 'itemidlbl'   => $this->t('Item Id'),
78                                 'itemurilbl'  => $this->t('Item URI'),
79                                 'submit'      => $this->t('Submit'),
80                                 'termslbl'    => $this->t('Terms'),
81                                 'taglbl'      => $this->t('Tag'),
82                                 'typelbl'     => $this->t('Type'),
83                                 'termlbl'     => $this->t('Term'),
84                                 'urllbl'      => $this->t('URL'),
85                                 'mentionlbl'  => $this->t('Mention'),
86                                 'implicitlbl' => $this->t('Implicit Mention'),
87                                 'error'       => $this->t('Error'),
88                                 'notfound'    => $this->t('Item not found'),
89                                 'nosource'    => $this->t('No source recorded'),
90                                 'noconfig'    => !$this->config->get('debug', 'store_source') ? $this->t('Please make sure the <code>debug.store_source</code> config key is set in <code>config/local.config.php</code> for future items to have sources.') : '',
91                         ],
92                         '$guid_field' => ['guid', $this->t('Item Guid'), $guid, ''],
93                         '$guid'       => $guid,
94                         '$item_uri'   => $item_uri,
95                         '$item_id'    => $item_id,
96                         '$terms'      => $terms,
97                         '$source'     => $source,
98                 ]);
99         }
100 }