diff --git a/mod/repair_ostatus.php b/mod/repair_ostatus.php deleted file mode 100644 index b0ee0bf575..0000000000 --- a/mod/repair_ostatus.php +++ /dev/null @@ -1,64 +0,0 @@ -. - * - */ - -use Friendica\App; -use Friendica\Core\Protocol; -use Friendica\Database\DBA; -use Friendica\DI; -use Friendica\Model\Contact; - -function repair_ostatus_content(App $a) { - - if (!DI::userSession()->getLocalUserId()) { - DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.')); - DI::baseUrl()->redirect('ostatus_repair'); - // NOTREACHED - } - - $o = '
' . $counter . '/' . $total . ': ' . $contact[0]['url'] . '
'; - - $o .= '' . DI::l10n()->t('Keep this window open until done.') . '
'; - - Contact::createFromProbeForUser($a->getLoggedInUserId(), $contact[0]['url']); - - DI::page()['htmlhead'] = ''; - - return $o; -} diff --git a/mod/settings.php b/mod/settings.php index 45f5f96c54..259981541b 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -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 index 0000000000..b7920c2abc --- /dev/null +++ b/src/Module/OStatus/Repair.php @@ -0,0 +1,93 @@ +. + * + */ + +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'] .= ''; + } + } + + $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, + ]); + } +} diff --git a/static/routes.config.php b/static/routes.config.php index 773b8d2531..e64b138307 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -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/lang/C/messages.po b/view/lang/C/messages.po index 359fbebd0c..0aaf5d0176 100644 --- a/view/lang/C/messages.po +++ b/view/lang/C/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 2022.12-dev\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-11-07 19:28+0000\n" +"POT-Creation-Date: 2022-11-07 21:47-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME