'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',
use Exception;
use Friendica\Core\ACL;
-use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\Core\Search;
use Friendica\Core\Worker;
use Friendica\Network\HTTPException;
use Friendica\Protocol\Activity;
use Friendica\Protocol\Delivery;
-use Friendica\Util\Network;
use Friendica\Util\Temporal;
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"));
'$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"),
$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'] ?? '';
$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) {
'$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,
--- /dev/null
+<?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.')],
+ ]);
+ }
+}
'/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]],
</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}}">
{{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}}"/>
--- /dev/null
+{{*
+ * 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
</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}}">
{{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>
--- /dev/null
+{{*
+ * 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