]> git.mxchange.org Git - friendica.git/blob - src/Module/OStatus/Repair.php
Use the post language for the language detection / config for quality
[friendica.git] / src / Module / OStatus / Repair.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\OStatus;
23
24 use Friendica\App;
25 use Friendica\Core\L10n;
26 use Friendica\Core\Protocol;
27 use Friendica\Core\Renderer;
28 use Friendica\Core\Session\Capability\IHandleUserSessions;
29 use Friendica\Database\Database;
30 use Friendica\Model\Contact;
31 use Friendica\Module\Response;
32 use Friendica\Navigation\SystemMessages;
33 use Friendica\Util\Profiler;
34 use Psr\Log\LoggerInterface;
35
36 class Repair extends \Friendica\BaseModule
37 {
38         /** @var IHandleUserSessions */
39         private $session;
40         /** @var SystemMessages */
41         private $systemMessages;
42         /** @var Database */
43         private $database;
44         /** @var App\Page */
45         private $page;
46
47         public function __construct(App\Page $page, Database $database, SystemMessages $systemMessages, IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
48         {
49                 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
50
51                 $this->session        = $session;
52                 $this->systemMessages = $systemMessages;
53                 $this->database       = $database;
54                 $this->page           = $page;
55         }
56
57         protected function content(array $request = []): string
58         {
59                 if (!$this->session->getLocalUserId()) {
60                         $this->systemMessages->addNotice($this->t('Permission denied.'));
61                         $this->baseUrl->redirect('login');
62                 }
63
64                 $uid = $this->session->getLocalUserId();
65
66                 $counter = intval($request['counter'] ?? 0);
67
68                 $condition = ['uid' => $uid, 'network' => Protocol::OSTATUS, 'rel' => [Contact::FRIEND, Contact::SHARING]];
69                 $total     = $this->database->count('contact', $condition);
70                 if ($total) {
71                         $contacts = Contact::selectToArray(['url'], $condition, ['order' => ['url'], 'limit' => [$counter++, 1]]);
72                         if ($contacts) {
73                                 Contact::createFromProbeForUser($this->session->getLocalUserId(), $contacts[0]['url']);
74
75                                 $this->page['htmlhead'] .= '<meta http-equiv="refresh" content="5; url=ostatus/repair?counter=' . $counter . '">';
76                         }
77                 }
78
79                 $tpl = Renderer::getMarkupTemplate('ostatus/repair.tpl');
80
81                 return Renderer::replaceMacros($tpl, [
82                         '$l10n'    => [
83                                 'title'      => $this->t('Resubscribing to OStatus contacts'),
84                                 'keep'       => $this->t('Keep this window open until done.'),
85                                 'done'       => $this->t('✔ Done'),
86                                 'nocontacts' => $this->t('No OStatus contacts to resubscribe to.'),
87                         ],
88                         '$total'   => $total,
89                         '$counter' => $counter,
90                         '$contact' => $contacts[0] ?? null,
91                 ]);
92         }
93 }