]> git.mxchange.org Git - friendica.git/blobdiff - mod/settings.php
Merge pull request #10237 from annando/oauth-flow
[friendica.git] / mod / settings.php
index e147144e21633fef45cd8c234ed6fa12dcbf99f9..3a3f0b65dccf974004433a96c4a0dff60a1e1555 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -32,7 +32,7 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Group;
-use Friendica\Model\Notify\Type;
+use Friendica\Model\Notification;
 use Friendica\Model\User;
 use Friendica\Module\BaseSettings;
 use Friendica\Module\Security\Login;
@@ -225,10 +225,11 @@ function settings_post(App $a)
                if (isset($_FILES['importcontact-filename'])) {
                        // was there an error
                        if ($_FILES['importcontact-filename']['error'] > 0) {
-                               Logger::notice('Contact CSV file upload error');
+                               Logger::notice('Contact CSV file upload error', ['error' => $_FILES['importcontact-filename']['error']]);
                                notice(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
@@ -236,15 +237,20 @@ function settings_post(App $a)
                                        // 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) || (strpos($csvRow[0],'http') !== false)) {
+                                       if ((strpos($csvRow[0],'@') !== false) || in_array(parse_url($csvRow[0], PHP_URL_SCHEME), ['http', 'https'])) {
                                                Worker::add(PRIORITY_LOW, 'AddContact', $_SESSION['uid'], $csvRow[0]);
+                                       } else {
+                                               Logger::notice('Invalid account', ['url' => $csvRow[0]]);
                                        }
                                }
+                               Logger::notice('Import done');
 
                                info(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.');
                }
 
                return;
@@ -319,6 +325,8 @@ function settings_post(App $a)
        $email_textonly   = (($_POST['email_textonly'] == 1) ? 1 : 0);
        $detailed_notif   = (($_POST['detailed_notif'] == 1) ? 1 : 0);
 
+       $notify_ignored   = (($_POST['notify_ignored'] == 1) ? 1 : 0);
+       
        $notify = 0;
 
        if (!empty($_POST['notify1'])) {
@@ -412,6 +420,7 @@ function settings_post(App $a)
 
        DI::pConfig()->set(local_user(), 'system', 'email_textonly', $email_textonly);
        DI::pConfig()->set(local_user(), 'system', 'detailed_notif', $detailed_notif);
+       DI::pConfig()->set(local_user(), 'system', 'notify_ignored', $notify_ignored);
        DI::pConfig()->set(local_user(), 'system', 'unlisted', $unlisted);
        DI::pConfig()->set(local_user(), 'system', 'accessible-photos', $accessiblephotos);
 
@@ -491,77 +500,26 @@ function settings_content(App $a)
        }
 
        if (($a->argc > 1) && ($a->argv[1] === 'oauth')) {
-               if (($a->argc > 2) && ($a->argv[2] === 'add')) {
-                       $tpl = Renderer::getMarkupTemplate('settings/oauth_edit.tpl');
-                       $o .= Renderer::replaceMacros($tpl, [
-                               '$form_security_token' => BaseModule::getFormSecurityToken("settings_oauth"),
-                               '$title'        => DI::l10n()->t('Add application'),
-                               '$submit'       => DI::l10n()->t('Save Settings'),
-                               '$cancel'       => DI::l10n()->t('Cancel'),
-                               '$name'         => ['name', DI::l10n()->t('Name'), '', ''],
-                               '$key'          => ['key', DI::l10n()->t('Consumer Key'), '', ''],
-                               '$secret'       => ['secret', DI::l10n()->t('Consumer Secret'), '', ''],
-                               '$redirect'     => ['redirect', DI::l10n()->t('Redirect'), '', ''],
-                               '$icon'         => ['icon', DI::l10n()->t('Icon url'), '', ''],
-                       ]);
-                       return $o;
-               }
-
-               if (($a->argc > 3) && ($a->argv[2] === 'edit')) {
-                       $r = q("SELECT * FROM clients WHERE client_id='%s' AND uid=%d",
-                                       DBA::escape($a->argv[3]),
-                                       local_user());
-
-                       if (!DBA::isResult($r)) {
-                               notice(DI::l10n()->t("You can't edit this application."));
-                               return;
-                       }
-                       $app = $r[0];
-
-                       $tpl = Renderer::getMarkupTemplate('settings/oauth_edit.tpl');
-                       $o .= Renderer::replaceMacros($tpl, [
-                               '$form_security_token' => BaseModule::getFormSecurityToken("settings_oauth"),
-                               '$title'        => DI::l10n()->t('Add application'),
-                               '$submit'       => DI::l10n()->t('Update'),
-                               '$cancel'       => DI::l10n()->t('Cancel'),
-                               '$name'         => ['name', DI::l10n()->t('Name'), $app['name'] , ''],
-                               '$key'          => ['key', DI::l10n()->t('Consumer Key'), $app['client_id'], ''],
-                               '$secret'       => ['secret', DI::l10n()->t('Consumer Secret'), $app['pw'], ''],
-                               '$redirect'     => ['redirect', DI::l10n()->t('Redirect'), $app['redirect_uri'], ''],
-                               '$icon'         => ['icon', DI::l10n()->t('Icon url'), $app['icon'], ''],
-                       ]);
-                       return $o;
-               }
-
                if (($a->argc > 3) && ($a->argv[2] === 'delete')) {
                        BaseModule::checkFormSecurityTokenRedirectOnError('/settings/oauth', 'settings_oauth', 't');
 
-                       DBA::delete('clients', ['client_id' => $a->argv[3], 'uid' => local_user()]);
+                       DBA::delete('application-token', ['application-id' => $a->argv[3], 'uid' => local_user()]);
                        DI::baseUrl()->redirect('settings/oauth/', true);
                        return;
                }
 
-               /// @TODO validate result with DBA::isResult()
-               $r = q("SELECT clients.*, tokens.id as oauth_token, (clients.uid=%d) AS my
-                               FROM clients
-                               LEFT JOIN tokens ON clients.client_id=tokens.client_id
-                               WHERE clients.uid IN (%d, 0)",
-                               local_user(),
-                               local_user());
-
+               $applications = DBA::selectToArray('application-view', ['id', 'uid', 'name', 'website', 'scopes', 'created_at'], ['uid' => local_user()]);
 
                $tpl = Renderer::getMarkupTemplate('settings/oauth.tpl');
                $o .= Renderer::replaceMacros($tpl, [
                        '$form_security_token' => BaseModule::getFormSecurityToken("settings_oauth"),
-                       '$baseurl'      => DI::baseUrl()->get(true),
-                       '$title'        => DI::l10n()->t('Connected Apps'),
-                       '$add'          => DI::l10n()->t('Add application'),
-                       '$edit'         => DI::l10n()->t('Edit'),
-                       '$delete'               => DI::l10n()->t('Delete'),
-                       '$consumerkey' => DI::l10n()->t('Client key starts with'),
-                       '$noname'       => DI::l10n()->t('No name'),
-                       '$remove'       => DI::l10n()->t('Remove authorization'),
-                       '$apps'         => $r,
+                       '$baseurl'             => DI::baseUrl()->get(true),
+                       '$title'               => DI::l10n()->t('Connected Apps'),
+                       '$name'                => DI::l10n()->t('Name'),
+                       '$website'             => DI::l10n()->t('Home Page'),
+                       '$created_at'          => DI::l10n()->t('Created'),
+                       '$delete'              => DI::l10n()->t('Remove authorization'),
+                       '$apps'                => $applications,
                ]);
                return $o;
        }
@@ -829,26 +787,6 @@ function settings_content(App $a)
 
        $stpl = Renderer::getMarkupTemplate('settings/settings.tpl');
 
-       // Private/public post links for the non-JS ACL form
-       $private_post = 1;
-       if (!empty($_REQUEST['public']) && !$_REQUEST['public']) {
-               $private_post = 0;
-       }
-
-       $query_str = DI::args()->getQueryString();
-       if (strpos($query_str, 'public=1') !== false) {
-               $query_str = str_replace(['?public=1', '&public=1'], ['', ''], $query_str);
-       }
-
-       // I think $a->query_string may never have ? in it, but I could be wrong
-       // It looks like it's from the index.php?q=[etc] rewrite that the web
-       // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
-       if (strpos($query_str, '?') === false) {
-               $public_post_link = '?public=1';
-       } else {
-               $public_post_link = '&public=1';
-       }
-
        /* Installed langs */
        $lang_choices = DI::l10n()->getAvailableLanguages();
 
@@ -866,7 +804,7 @@ function settings_content(App $a)
                '$password1'=> ['password', DI::l10n()->t('New Password:'), '', DI::l10n()->t('Allowed characters are a-z, A-Z, 0-9 and special characters except white spaces, accentuated letters and colon (:).')],
                '$password2'=> ['confirm', DI::l10n()->t('Confirm:'), '', DI::l10n()->t('Leave password fields blank unless changing')],
                '$password3'=> ['opassword', DI::l10n()->t('Current Password:'), '', DI::l10n()->t('Your current password to confirm the changes')],
-               '$password4'=> ['mpassword', DI::l10n()->t('Password:'), '', DI::l10n()->t('Your current password to confirm the changes')],
+               '$password4'=> ['mpassword', DI::l10n()->t('Password:'), '', DI::l10n()->t('Your current password to confirm the changes of the email address')],
                '$oid_enable' => (!DI::config()->get('system', 'no_openid')),
                '$openid'       => $openid_field,
                '$delete_openid' => ['delete_openid', DI::l10n()->t('Delete OpenID URL'), false, ''],
@@ -908,14 +846,14 @@ function settings_content(App $a)
 
                '$h_not'        => DI::l10n()->t('Notification Settings'),
                '$lbl_not'      => DI::l10n()->t('Send a notification email when:'),
-               '$notify1'      => ['notify1', DI::l10n()->t('You receive an introduction'), ($notify & Type::INTRO), Type::INTRO, ''],
-               '$notify2'      => ['notify2', DI::l10n()->t('Your introductions are confirmed'), ($notify & Type::CONFIRM), Type::CONFIRM, ''],
-               '$notify3'      => ['notify3', DI::l10n()->t('Someone writes on your profile wall'), ($notify & Type::WALL), Type::WALL, ''],
-               '$notify4'      => ['notify4', DI::l10n()->t('Someone writes a followup comment'), ($notify & Type::COMMENT), Type::COMMENT, ''],
-               '$notify5'      => ['notify5', DI::l10n()->t('You receive a private message'), ($notify & Type::MAIL), Type::MAIL, ''],
-               '$notify6'  => ['notify6', DI::l10n()->t('You receive a friend suggestion'), ($notify & Type::SUGGEST), Type::SUGGEST, ''],
-               '$notify7'  => ['notify7', DI::l10n()->t('You are tagged in a post'), ($notify & Type::TAG_SELF), Type::TAG_SELF, ''],
-               '$notify8'  => ['notify8', DI::l10n()->t('You are poked/prodded/etc. in a post'), ($notify & Type::POKE), Type::POKE, ''],
+               '$notify1'      => ['notify1', DI::l10n()->t('You receive an introduction'), ($notify & Notification\Type::INTRO), Notification\Type::INTRO, ''],
+               '$notify2'      => ['notify2', DI::l10n()->t('Your introductions are confirmed'), ($notify & Notification\Type::CONFIRM), Notification\Type::CONFIRM, ''],
+               '$notify3'      => ['notify3', DI::l10n()->t('Someone writes on your profile wall'), ($notify & Notification\Type::WALL), Notification\Type::WALL, ''],
+               '$notify4'      => ['notify4', DI::l10n()->t('Someone writes a followup comment'), ($notify & Notification\Type::COMMENT), Notification\Type::COMMENT, ''],
+               '$notify5'      => ['notify5', DI::l10n()->t('You receive a private message'), ($notify & Notification\Type::MAIL), Notification\Type::MAIL, ''],
+               '$notify6'  => ['notify6', DI::l10n()->t('You receive a friend suggestion'), ($notify & Notification\Type::SUGGEST), Notification\Type::SUGGEST, ''],
+               '$notify7'  => ['notify7', DI::l10n()->t('You are tagged in a post'), ($notify & Notification\Type::TAG_SELF), Notification\Type::TAG_SELF, ''],
+               '$notify8'  => ['notify8', DI::l10n()->t('You are poked/prodded/etc. in a post'), ($notify & Notification\Type::POKE), Notification\Type::POKE, ''],
 
                '$desktop_notifications' => ['desktop_notifications', DI::l10n()->t('Activate desktop notifications') , false, DI::l10n()->t('Show desktop popup on new notifications')],
 
@@ -927,7 +865,11 @@ function settings_content(App $a)
                                                                        DI::pConfig()->get(local_user(), 'system', 'detailed_notif'),
                                                                        DI::l10n()->t('Per default, notifications are condensed to a single notification per item. When enabled every notification is displayed.')],
 
-               '$h_advn' => DI::l10n()->t('Advanced Account/Page Type Settings'),
+               '$notify_ignored' => ['notify_ignored', DI::l10n()->t('Show notifications of ignored contacts') ,
+                                                                       DI::pConfig()->get(local_user(), 'system', 'notify_ignored', true),
+                                                                       DI::l10n()->t("You don't see posts from ignored contacts. But you still see their comments. This setting controls if you want to still receive regular notifications that are caused by ignored contacts or not.")],
+
+                                                                       '$h_advn' => DI::l10n()->t('Advanced Account/Page Type Settings'),
                '$h_descadvn' => DI::l10n()->t('Change the behaviour of this account for special situations'),
                '$pagetype' => $pagetype,