]> git.mxchange.org Git - friendica.git/commitdiff
Create new OStatus\Repair module class
authorHypolite Petovan <hypolite@mrpetovan.com>
Tue, 8 Nov 2022 02:44:18 +0000 (21:44 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Tue, 8 Nov 2022 02:44:18 +0000 (21:44 -0500)
- Create corresponding template file

mod/settings.php
src/Module/OStatus/Repair.php [new file with mode: 0644]
static/routes.config.php
view/templates/ostatus/repair.tpl [new file with mode: 0644]

index 45f5f96c54ed3967793c879a01c6d896faaeca69..259981541b7dc2777c76878fd1e92f25d46d3bae 100644 (file)
@@ -331,7 +331,7 @@ function settings_content(App $a)
                        '$attach_link_title' => ['attach_link_title', DI::l10n()->t('Attach the link title'), $attach_link_title, DI::l10n()->t('When activated, the title of the attached link will be added as a title on posts to Diaspora. This is mostly helpful with "remote-self" contacts that share feed content.')],
                        '$legacy_contact' => ['legacy_contact', DI::l10n()->t('Your legacy ActivityPub/GNU Social account'), $legacy_contact, DI::l10n()->t("If you enter your old account name from an ActivityPub based system or your GNU Social/Statusnet account name here (in the format user@domain.tld), your contacts will be added automatically. The field will be emptied when done.")],
 
-                       '$repair_ostatus_url' => DI::baseUrl() . '/repair_ostatus',
+                       '$repair_ostatus_url' => 'ostatus/repair',
                        '$repair_ostatus_text' => DI::l10n()->t('Repair OStatus subscriptions'),
 
                        '$connector_settings_forms' => $connector_settings_forms,
diff --git a/src/Module/OStatus/Repair.php b/src/Module/OStatus/Repair.php
new file mode 100644 (file)
index 0000000..b7920c2
--- /dev/null
@@ -0,0 +1,93 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2022, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Module\OStatus;
+
+use Friendica\App;
+use Friendica\Core\L10n;
+use Friendica\Core\Protocol;
+use Friendica\Core\Renderer;
+use Friendica\Core\Session\Capability\IHandleUserSessions;
+use Friendica\Database\Database;
+use Friendica\Model\Contact;
+use Friendica\Module\Response;
+use Friendica\Navigation\SystemMessages;
+use Friendica\Util\Profiler;
+use Psr\Log\LoggerInterface;
+
+class Repair extends \Friendica\BaseModule
+{
+       /** @var IHandleUserSessions */
+       private $session;
+       /** @var SystemMessages */
+       private $systemMessages;
+       /** @var Database */
+       private $database;
+       /** @var App\Page */
+       private $page;
+
+       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 = [])
+       {
+               parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
+
+               $this->session        = $session;
+               $this->systemMessages = $systemMessages;
+               $this->database       = $database;
+               $this->page           = $page;
+       }
+
+       protected function content(array $request = []): string
+       {
+               if (!$this->session->getLocalUserId()) {
+                       $this->systemMessages->addNotice($this->t('Permission denied.'));
+                       $this->baseUrl->redirect('login');
+               }
+
+               $uid = $this->session->getLocalUserId();
+
+               $counter = intval($request['counter'] ?? 0);
+
+               $condition = ['uid' => $uid, 'network' => Protocol::OSTATUS, 'rel' => [Contact::FRIEND, Contact::SHARING]];
+               $total     = $this->database->count('contact', $condition);
+               if ($total) {
+                       $contacts = Contact::selectToArray(['url'], $condition, ['order' => ['url'], 'limit' => [$counter++, 1]]);
+                       if ($contacts) {
+                               Contact::createFromProbeForUser($this->session->getLocalUserId(), $contacts[0]['url']);
+
+                               $this->page['htmlhead'] .= '<meta http-equiv="refresh" content="5; url=ostatus/repair?counter=' . $counter . '">';
+                       }
+               }
+
+               $tpl = Renderer::getMarkupTemplate('ostatus/repair.tpl');
+
+               return Renderer::replaceMacros($tpl, [
+                       '$l10n'    => [
+                               'title'      => $this->t('Resubscribing to OStatus contacts'),
+                               'keep'       => $this->t('Keep this window open until done.'),
+                               'done'       => $this->t('✔ Done'),
+                               'nocontacts' => $this->t('No OStatus contacts to resubscribe to.'),
+                       ],
+                       '$total'   => $total,
+                       '$counter' => $counter,
+                       '$contact' => $contacts[0] ?? null,
+               ]);
+       }
+}
index 773b8d253162a5b5436b149043293ed490c6a3ca..e64b138307c1001f2022df5971758f88e80354e4 100644 (file)
@@ -522,6 +522,8 @@ return [
        '/openid'            => [Module\Security\OpenID::class,    [R::GET]],
        '/opensearch'        => [Module\OpenSearch::class,         [R::GET]],
 
+       '/ostatus/repair'                     => [Module\OStatus\Repair::class,    [R::GET]],
+
        '/parseurl'                           => [Module\ParseUrl::class,          [R::GET]],
        '/permission/tooltip/{type}/{id:\d+}' => [Module\PermissionTooltip::class, [R::GET]],
 
diff --git a/view/templates/ostatus/repair.tpl b/view/templates/ostatus/repair.tpl
new file mode 100644 (file)
index 0000000..06298ad
--- /dev/null
@@ -0,0 +1,18 @@
+<div class="generic-page-wrapper">
+       <h2>{{$l10n.title}}</h2>
+{{if $total}}
+       {{if $contact}}
+               <div class="alert alert-info">
+            {{$counter}} / {{$total}} : {{$contact.url}}
+               </div>
+       {{else}}
+               <div class="alert alert-success">
+                       {{$l10n.done}}
+               </div>
+       {{/if}}
+{{else}}
+       <div class="alert alert-warning">
+               {{$l10n.nocontacts}}
+       </div>
+{{/if}}
+</div>