]> git.mxchange.org Git - friendica.git/commitdiff
Issue 14344: Contact import is relocated to a dedicated place
authorMichael <heluecht@pirati.ca>
Fri, 20 Dec 2024 08:22:56 +0000 (08:22 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 20 Dec 2024 08:22:56 +0000 (08:22 +0000)
src/Module/BaseSettings.php
src/Module/Settings/Account.php
src/Module/Settings/Connectors.php
src/Module/Settings/ContactImport.php [new file with mode: 0644]
static/routes.config.php
view/templates/settings/account.tpl
view/templates/settings/connectors.tpl
view/templates/settings/contactimport.tpl [new file with mode: 0644]
view/theme/frio/templates/settings/account.tpl
view/theme/frio/templates/settings/connectors.tpl
view/theme/frio/templates/settings/contactimport.tpl [new file with mode: 0644]

index 693554f49308644913e63b35df0683ee5814a212..49e75ebaff45275738f2366fd9cb17a1ecfbda7f 100644 (file)
@@ -149,6 +149,13 @@ class BaseSettings extends BaseModule
                        'accesskey' => 's',
                ];
 
+               $tabs[] = [
+                       'label'     => $this->t('Import Contacts'),
+                       'url'       => 'settings/importcontacts',
+                       'selected'  => static::class == Settings\UserExport::class ? 'active' : '',
+                       'accesskey' => '',
+               ];
+
                $tabs[] = [
                        'label'     => $this->t('Export personal data'),
                        'url'       => 'settings/userexport',
index 8e8bd5a9098403543f8824b1dc5f53813af8af4d..567ac41fd6b231f771c5dda82c5544a75c014e05 100644 (file)
@@ -9,7 +9,6 @@ namespace Friendica\Module\Settings;
 
 use Exception;
 use Friendica\Core\ACL;
-use Friendica\Core\Logger;
 use Friendica\Core\Renderer;
 use Friendica\Core\Search;
 use Friendica\Core\Worker;
@@ -25,7 +24,6 @@ use Friendica\Module\BaseSettings;
 use Friendica\Network\HTTPException;
 use Friendica\Protocol\Activity;
 use Friendica\Protocol\Delivery;
-use Friendica\Util\Network;
 use Friendica\Util\Temporal;
 
 class Account extends BaseSettings
@@ -324,42 +322,6 @@ class Account extends BaseSettings
                        DI::baseUrl()->redirect($redirectUrl);
                }
 
-               // Import Contacts from CSV file
-               if (!empty($request['importcontact-submit'])) {
-                       if (isset($_FILES['importcontact-filename'])) {
-                               // was there an error
-                               if ($_FILES['importcontact-filename']['error'] > 0) {
-                                       Logger::notice('Contact CSV file upload error', ['error' => $_FILES['importcontact-filename']['error']]);
-                                       DI::sysmsg()->addNotice(DI::l10n()->t('Contact CSV file upload error'));
-                               } else {
-                                       $csvArray = array_map('str_getcsv', file($_FILES['importcontact-filename']['tmp_name']));
-                                       Logger::notice('Import started', ['lines' => count($csvArray)]);
-                                       // import contacts
-                                       foreach ($csvArray as $csvRow) {
-                                               // The 1st row may, or may not contain the headers of the table
-                                               // We expect the 1st field of the row to contain either the URL
-                                               // or the handle of the account, therefore we check for either
-                                               // "http" or "@" to be present in the string.
-                                               // All other fields from the row will be ignored
-                                               if ((strpos($csvRow[0], '@') !== false) || Network::isValidHttpUrl($csvRow[0])) {
-                                                       Worker::add(Worker::PRIORITY_MEDIUM, 'AddContact', DI::userSession()->getLocalUserId(), trim($csvRow[0], '@'));
-                                               } else {
-                                                       Logger::notice('Invalid account', ['url' => $csvRow[0]]);
-                                               }
-                                       }
-                                       Logger::notice('Import done');
-
-                                       DI::sysmsg()->addInfo(DI::l10n()->t('Importing Contacts done'));
-                                       // delete temp file
-                                       unlink($_FILES['importcontact-filename']['tmp_name']);
-                               }
-                       } else {
-                               Logger::notice('Import triggered, but no import file was found.');
-                       }
-
-                       DI::baseUrl()->redirect($redirectUrl);
-               }
-
                if (!empty($request['relocate-submit'])) {
                        Worker::add(Worker::PRIORITY_HIGH, 'Notifier', Delivery::RELOCATION, DI::userSession()->getLocalUserId());
                        DI::sysmsg()->addInfo(DI::l10n()->t("Relocate message has been send to your contacts"));
@@ -637,11 +599,6 @@ class Account extends BaseSettings
                        '$h_descadvn' => DI::l10n()->t('Change the behaviour of this account for special situations'),
                        '$pagetype'   => $pagetype,
 
-                       '$importcontact'         => DI::l10n()->t('Import Contacts'),
-                       '$importcontact_text'    => DI::l10n()->t('Upload a CSV file that contains the handle of your followed accounts in the first column you exported from the old account.'),
-                       '$importcontact_button'  => DI::l10n()->t('Upload File'),
-                       '$importcontact_maxsize' => DI::config()->get('system', 'max_csv_file_size', 30720),
-
                        '$relocate'        => DI::l10n()->t('Relocate'),
                        '$relocate_text'   => DI::l10n()->t("If you have moved this profile from another server, and some of your contacts don't receive your updates, try pushing this button."),
                        '$relocate_button' => DI::l10n()->t("Resend relocate message to contacts"),
index 3e6829a0d6a47c6fa3f9d56a8ab374c535631442..7e5b57a783d5f02dbbd534e4a6b61001e5bf2117 100644 (file)
@@ -62,7 +62,6 @@ class Connectors extends BaseSettings
                        $this->pconfig->set($this->session->getLocalUserId(), 'system', 'api_spoiler_title', intval($request['api_spoiler_title']));
                        $this->pconfig->set($this->session->getLocalUserId(), 'system', 'api_auto_attach', intval($request['api_auto_attach']));
                        $this->pconfig->set($this->session->getLocalUserId(), 'system', 'article_mode', intval($request['article_mode']));
-                       $this->pconfig->set($this->session->getLocalUserId(), 'ostatus', 'legacy_contact', $request['legacy_contact']);
                } elseif (!empty($request['mail-submit']) && function_exists('imap_open') && !$this->config->get('system', 'imap_disabled')) {
                        $mail_server       =                 $request['mail_server'] ?? '';
                        $mail_port         =                 $request['mail_port'] ?? '';
@@ -127,11 +126,6 @@ class Connectors extends BaseSettings
                $api_spoiler_title       =  intval($this->pconfig->get($this->session->getLocalUserId(), 'system', 'api_spoiler_title', true));
                $api_auto_attach         =  intval($this->pconfig->get($this->session->getLocalUserId(), 'system', 'api_auto_attach', false));
                $article_mode            =  intval($this->pconfig->get($this->session->getLocalUserId(), 'system', 'article_mode'));
-               $legacy_contact          =         $this->pconfig->get($this->session->getLocalUserId(), 'ostatus', 'legacy_contact');
-
-               if (!empty($legacy_contact)) {
-                       $this->baseUrl->redirect('ostatus/subscribe?url=' . urlencode($legacy_contact));
-               }
 
                $connector_settings_forms = [];
                foreach ($this->database->selectToArray('hook', ['file', 'function'], ['hook' => 'connector_settings']) as $hook) {
@@ -215,7 +209,6 @@ class Connectors extends BaseSettings
                        '$api_spoiler_title'       => ['api_spoiler_title', $this->t('API: Use spoiler field as title'), $api_spoiler_title, $this->t('When activated, the "spoiler_text" field in the API will be used for the title on standalone posts. When deactivated it will be used for spoiler text. For comments it will always be used for spoiler text.')],
                        '$api_auto_attach'         => ['api_auto_attach', $this->t('API: Automatically links at the end of the post as attached posts'), $api_auto_attach, $this->t('When activated, added links at the end of the post react the same way as added links in the web interface.')],
                        '$article_mode'            => ['article_mode', $this->t('Article Mode'), $article_mode, $this->t("Controls how posts with titles are transmitted. Mastodon and its forks don't display the content of these posts if the post is created in the correct (default) way."), $article_modes],
-                       '$legacy_contact'          => ['legacy_contact', $this->t('Your legacy ActivityPub/GNU Social account'), $legacy_contact, $this->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.')],
 
                        '$connector_settings_forms' => $connector_settings_forms,
 
diff --git a/src/Module/Settings/ContactImport.php b/src/Module/Settings/ContactImport.php
new file mode 100644 (file)
index 0000000..991b447
--- /dev/null
@@ -0,0 +1,118 @@
+<?php
+
+// Copyright (C) 2010-2024, the Friendica project
+// SPDX-FileCopyrightText: 2010-2024 the Friendica project
+//
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+namespace Friendica\Module\Settings;
+
+use Friendica\App;
+use Friendica\Core\Config\Capability\IManageConfigValues;
+use Friendica\Core\L10n;
+use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
+use Friendica\Core\Renderer;
+use Friendica\Core\Session\Capability\IHandleUserSessions;
+use Friendica\Core\Worker;
+use Friendica\Module\BaseSettings;
+use Friendica\Module\Response;
+use Friendica\Navigation\SystemMessages;
+use Friendica\Network\HTTPException;
+use Friendica\Util\Network;
+use Friendica\Util\Profiler;
+use Psr\Log\LoggerInterface;
+
+/**
+ * Module to export user data
+ **/
+class ContactImport extends BaseSettings
+{
+       /** @var IManageConfigValues */
+       private $config;
+       /** @var IManagePersonalConfigValues */
+       private $pconfig;
+       /** @var SystemMessages */
+       protected $systemMessages;
+
+       public function __construct(SystemMessages $systemMessages, IManagePersonalConfigValues $pconfig, IManageConfigValues $config, IHandleUserSessions $session, App\Page $page, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
+       {
+               parent::__construct($session, $page, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
+
+               $this->config         = $config;
+               $this->pconfig        = $pconfig;
+               $this->systemMessages = $systemMessages;
+       }
+
+       protected function post(array $request = [])
+       {
+               if (!$this->session->getLocalUserId()) {
+                       throw new HTTPException\ForbiddenException($this->l10n->t('Permission denied.'));
+               }
+
+               self::checkFormSecurityTokenRedirectOnError($this->args->getQueryString(), 'contactimport');
+
+               parent::post();
+
+               // Import Contacts from CSV file
+               if (!empty($request['importcontact-submit'])) {
+                       $this->pconfig->set($this->session->getLocalUserId(), 'ostatus', 'legacy_contact', $request['legacy_contact']);
+                       if (isset($_FILES['importcontact-filename']) && !empty($_FILES['importcontact-filename']['tmp_name'])) {
+                               // was there an error
+                               if ($_FILES['importcontact-filename']['error'] > 0) {
+                                       $this->logger->notice('Contact CSV file upload error', ['error' => $_FILES['importcontact-filename']['error']]);
+                                       $this->systemMessages->addNotice($this->l10n->t('Contact CSV file upload error'));
+                               } else {
+                                       $csvArray = array_map('str_getcsv', file($_FILES['importcontact-filename']['tmp_name']));
+                                       $this->logger->notice('Import started', ['lines' => count($csvArray)]);
+                                       // import contacts
+                                       foreach ($csvArray as $csvRow) {
+                                               // The 1st row may, or may not contain the headers of the table
+                                               // We expect the 1st field of the row to contain either the URL
+                                               // or the handle of the account, therefore we check for either
+                                               // "http" or "@" to be present in the string.
+                                               // All other fields from the row will be ignored
+                                               if ((strpos($csvRow[0], '@') !== false) || Network::isValidHttpUrl($csvRow[0])) {
+                                                       Worker::add(Worker::PRIORITY_MEDIUM, 'AddContact', $this->session->getLocalUserId(), trim($csvRow[0], '@'));
+                                               } else {
+                                                       $this->logger->notice('Invalid account', ['url' => $csvRow[0]]);
+                                               }
+                                       }
+                                       $this->logger->notice('Import done');
+
+                                       $this->systemMessages->addInfo($this->l10n->t('Importing Contacts done'));
+                                       // delete temp file
+                                       unlink($_FILES['importcontact-filename']['tmp_name']);
+                               }
+                       } else {
+                               $this->logger->notice('Import triggered, but no import file was found.');
+                       }
+               }
+               $this->baseUrl->redirect($this->args->getQueryString());
+       }
+
+       protected function content(array $request = []): string
+       {
+               if (!$this->session->getLocalUserId()) {
+                       throw new HTTPException\ForbiddenException($this->l10n->t('Permission denied.'));
+               }
+
+               parent::content();
+
+               $legacy_contact = $this->pconfig->get($this->session->getLocalUserId(), 'ostatus', 'legacy_contact');
+
+               if (!empty($legacy_contact)) {
+                       $this->baseUrl->redirect('ostatus/subscribe?url=' . urlencode($legacy_contact));
+               }
+
+               $tpl = Renderer::getMarkupTemplate('settings/contactimport.tpl');
+               return Renderer::replaceMacros($tpl, [
+                       '$title'                 => $this->l10n->t('Import Contacts'),
+                       '$submit'                => $this->l10n->t('Save Settings'),
+                       '$form_security_token'   => self::getFormSecurityToken('contactimport'),
+                       '$importcontact_text'    => $this->l10n->t('Upload a CSV file that contains the handle of your followed accounts in the first column you exported from the old account.'),
+                       '$importcontact_button'  => $this->l10n->t('Upload File'),
+                       '$importcontact_maxsize' => $this->config->get('system', 'max_csv_file_size', 30720),
+                       '$legacy_contact'        => ['legacy_contact', $this->t('Your legacy ActivityPub/GNU Social account'), $legacy_contact, $this->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.')],
+               ]);
+       }
+}
index f9680216e2cd5c48c4a046e50ff538bc8329853e..5ebce2738bf68fbf15b4892a611434cf1a20d941 100644 (file)
@@ -622,6 +622,7 @@ return [
                '/delegation[/{action}/{user_id}]' => [Module\Settings\Delegation::class,       [R::GET, R::POST]],
                '/display'                         => [Module\Settings\Display::class,          [R::GET, R::POST]],
                '/features'                        => [Module\Settings\Features::class,         [R::GET, R::POST]],
+               '/importcontacts'                  => [Module\Settings\ContactImport::class,    [R::GET, R::POST]],
                '/oauth'                           => [Module\Settings\OAuth::class,            [R::GET, R::POST]],
                '/profile' => [
                        '[/]'                  => [Module\Settings\Profile\Index::class,       [R::GET, R::POST]],
index eb7b9c7dc7e8d9b769ce69c3e995184f39e0bacc..daaa6c178a932af2df67c878b595028d16f80c20 100644 (file)
                </div>
        </form>
 
-       <h2 class="settings-heading"><a href="javascript:;">{{$importcontact}}</a></h2>
-       <form class="settings-content-block" action="settings" method="post" autocomplete="off" enctype="multipart/form-data">
-               <input type="hidden" name="form_security_token" value="{{$form_security_token}}">
-               <input type="hidden" name="MAX_FILE_SIZE" value="{{$importcontact_maxsize}}"/>
-               <p id="settings-pagetype-desc">{{$importcontact_text}}</p>
-               <p><input type="file" name="importcontact-filename"/></p>
-
-               <div class="settings-submit-wrapper">
-                       <input type="submit" name="importcontact-submit" class="importcontact-submit" value="{{$importcontact_button}}"/>
-               </div>
-       </form>
-
        <h2 class="settings-heading"><a href="javascript:;">{{$relocate}}</a></h2>
        <form class="settings-content-block" action="settings" method="post" autocomplete="off" enctype="multipart/form-data">
                <input type="hidden" name="form_security_token" value="{{$form_security_token}}">
index 7c92f54b41dcd5e65adbdf6a97b8e9e50a1b9c4f..a62da74c0d5ea938e725e545f9525d3f1797c628 100644 (file)
@@ -25,7 +25,6 @@
                {{include file="field_checkbox.tpl" field=$api_spoiler_title}}
                {{include file="field_checkbox.tpl" field=$api_auto_attach}}
                {{include file="field_select.tpl" field=$article_mode}}
-               {{include file="field_input.tpl" field=$legacy_contact}}
 
                <div class="settings-submit-wrapper">
                        <input type="submit" id="general-submit" name="general-submit" class="settings-submit" value="{{$submit}}"/>
diff --git a/view/templates/settings/contactimport.tpl b/view/templates/settings/contactimport.tpl
new file mode 100644 (file)
index 0000000..d132b26
--- /dev/null
@@ -0,0 +1,23 @@
+{{*
+  * Copyright (C) 2010-2024, the Friendica project
+  * SPDX-FileCopyrightText: 2010-2024 the Friendica project
+  *
+  * SPDX-License-Identifier: AGPL-3.0-or-later
+  *}}
+<h1>{{$title}}</h1>
+
+<div id="settings-form">
+       <form action="settings/importcontacts" method="post" autocomplete="off" enctype="multipart/form-data">
+               <input type="hidden" name="form_security_token" value="{{$form_security_token}}">
+               <input type="hidden" name="MAX_FILE_SIZE" value="{{$importcontact_maxsize}}" />
+               {{include file="field_input.tpl" field=$legacy_contact}}
+               <hr>
+               <p id="settings-pagetype-desc">{{$importcontact_text}}</p>
+               <p><input type="file" name="importcontact-filename" /></p>
+
+               <div class="settings-submit-wrapper">
+                       <input type="submit" name="importcontact-submit" class="importcontact-submit"
+                               value="{{$importcontact_button}}" />
+               </div>
+       </form>
+</div>
\ No newline at end of file
index 22a77d0226a9cacd03baa7454c1ef79421ca05d3..2a8fd1e1bc2813b667b9eeafcc5ec648da3310b7 100644 (file)
                                </div>
                        </form>
 
-                       {{* Import contacts CSV *}}
-                       <form action="settings/account/importcontact" method="post" autocomplete="off" class="panel" enctype="multipart/form-data">
-                               <input type="hidden" name="form_security_token" value="{{$form_security_token}}">
-                               <div class="section-subtitle-wrapper panel-heading" role="tab" id="importcontact-settings">
-                                       <h2>
-                                               <button class="btn-link accordion-toggle{{if $open !== 'importcontact'}} collapsed{{/if}}" data-toggle="collapse" data-parent="#settings" href="#importcontact-settings-collapse" aria-expanded="false" aria-controls="importcontact-settings-collapse">
-                                                       {{$importcontact}}
-                                               </button>
-                                       </h2>
-                               </div>
-                               <div id="importcontact-settings-collapse" class="panel-collapse collapse{{if $open == 'importcontact'}} in{{/if}}" role="tabpanel" aria-labelledby="importcontact-settings">
-                                       <div class="panel-body">
-                                               <div id="importcontact-relocate-desc">{{$importcontact_text}}</div>
-                                               <input type="hidden" name="MAX_FILE_SIZE" value="{{$importcontact_maxsize}}" />
-                                               <input type="file" name="importcontact-filename" />
-                                       </div>
-                                       <div class="panel-footer">
-                                               <button type="submit" name="importcontact-submit" class="btn btn-primary" value="{{$submit}}">{{$submit}}</button>
-                                       </div>
-                               </div>
-                       </form>
-
                        {{* The relocate setting section *}}
                        <form action="settings/account/relocate" method="post" autocomplete="off" class="panel">
                                <input type="hidden" name="form_security_token" value="{{$form_security_token}}">
index aa1e0e7dbdf02fdbe1a3419bcfe1f03baed94ba1..31f5e7b0dd661ec85c2249e207e7e9b9a3b6de69 100644 (file)
@@ -39,8 +39,6 @@
                                        {{include file="field_checkbox.tpl" field=$api_auto_attach}}
 
                                        {{include file="field_select.tpl" field=$article_mode}}
-
-                                       {{include file="field_input.tpl" field=$legacy_contact}}                                        
                                </div>
                                <div class="panel-footer">
                                        <button type="submit" id="general-submit" name="general-submit" class="btn btn-primary" value="{{$submit}}">{{$submit}}</button>
diff --git a/view/theme/frio/templates/settings/contactimport.tpl b/view/theme/frio/templates/settings/contactimport.tpl
new file mode 100644 (file)
index 0000000..00e5508
--- /dev/null
@@ -0,0 +1,28 @@
+{{*
+  * Copyright (C) 2010-2024, the Friendica project
+  * SPDX-FileCopyrightText: 2010-2024 the Friendica project
+  *
+  * SPDX-License-Identifier: AGPL-3.0-or-later
+  *}}
+<div class="generic-page-wrapper">
+       <h1>{{$title}}</h1>
+       <div id="settings-form">
+               {{* Import contacts CSV *}}
+               <form action="settings/importcontacts" method="post" autocomplete="off" class="panel"
+                       enctype="multipart/form-data">
+                       <input type="hidden" name="form_security_token" value="{{$form_security_token}}">
+                       <div class="panel-body">
+                               {{include file="field_input.tpl" field=$legacy_contact}}
+                               <hr>
+                               <div id="importcontact-relocate-desc">{{$importcontact_text}}</div>
+                               <input type="hidden" name="MAX_FILE_SIZE" value="{{$importcontact_maxsize}}" />
+                               <input type="file" name="importcontact-filename" />
+                       </div>
+                       <div class="panel-footer">
+                               <button type="submit" name="importcontact-submit" class="btn btn-primary"
+                                       value="{{$submit}}">{{$submit}}</button>
+                       </div>
+       </div>
+       </form>
+</div>
+</div>
\ No newline at end of file