X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fsettings.php;h=080bcdeb93848a7cc086c60798583752a3b17be3;hb=0c26ae31f6ca925cd88a53a47c2484c7078950e8;hp=9ece81b556ac8272b8cd51ed99a58cfe3d80ce3a;hpb=18470da84ad699135882cd09a9f56c6421f43b6b;p=friendica.git diff --git a/mod/settings.php b/mod/settings.php index 9ece81b556..080bcdeb93 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -37,7 +37,6 @@ use Friendica\Model\User; use Friendica\Module\BaseSettings; use Friendica\Module\Security\Login; use Friendica\Protocol\Email; -use Friendica\Util\Strings; use Friendica\Util\Temporal; use Friendica\Worker\Delivery; @@ -93,11 +92,7 @@ function settings_post(App $a) $mail_pubmail = $_POST['mail_pubmail'] ?? ''; if (function_exists('imap_open') && !DI::config()->get('system', 'imap_disabled')) { - $failed = false; - $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", - intval(local_user()) - ); - if (!DBA::isResult($r)) { + if (!DBA::exists('mailacct', ['uid' => local_user()])) { DBA::insert('mailacct', ['uid' => local_user()]); } if (strlen($mail_pass)) { @@ -105,34 +100,30 @@ function settings_post(App $a) openssl_public_encrypt($mail_pass, $pass, $user['pubkey']); DBA::update('mailacct', ['pass' => bin2hex($pass)], ['uid' => local_user()]); } - $r = q("UPDATE `mailacct` SET `server` = '%s', `port` = %d, `ssltype` = '%s', `user` = '%s', - `action` = %d, `movetofolder` = '%s', - `mailbox` = 'INBOX', `reply_to` = '%s', `pubmail` = %d WHERE `uid` = %d", - DBA::escape($mail_server), - intval($mail_port), - DBA::escape($mail_ssl), - DBA::escape($mail_user), - intval($mail_action), - DBA::escape($mail_movetofolder), - DBA::escape($mail_replyto), - intval($mail_pubmail), - intval(local_user()) - ); + + $r = DBA::update('mailacct', [ + 'server' => $mail_server, + 'port' => $mail_port, + 'ssltype' => $mail_ssl, + 'user' => $mail_user, + `action` => $mail_action, + 'movetofolder' => $mail_movetofolder, + 'mailbox' => 'INBOX', + 'reply_to' => $mail_replyto, + 'pubmail' => $mail_pubmail + ], ['uid' => local_user()]); + Logger::notice('updating mailaccount', ['response' => $r]); - $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", - intval(local_user()) - ); - if (DBA::isResult($r)) { - $eacct = $r[0]; - $mb = Email::constructMailboxName($eacct); - - if (strlen($eacct['server'])) { + $mailacct = DBA::selectFirst('mailacct', [], ['uid' => local_user()]); + if (DBA::isResult($mailacct)) { + $mb = Email::constructMailboxName($mailacct); + + if (strlen($mailacct['server'])) { $dcrpass = ''; - openssl_private_decrypt(hex2bin($eacct['pass']), $dcrpass, $user['prvkey']); + openssl_private_decrypt(hex2bin($mailacct['pass']), $dcrpass, $user['prvkey']); $mbox = Email::connect($mb, $mail_user, $dcrpass); unset($dcrpass); if (!$mbox) { - $failed = true; notice(DI::l10n()->t('Failed to connect with email account using the settings provided.')); } } @@ -224,14 +215,14 @@ function settings_post(App $a) } } - $username = (!empty($_POST['username']) ? Strings::escapeTags(trim($_POST['username'])) : ''); - $email = (!empty($_POST['email']) ? Strings::escapeTags(trim($_POST['email'])) : ''); - $timezone = (!empty($_POST['timezone']) ? Strings::escapeTags(trim($_POST['timezone'])) : ''); - $language = (!empty($_POST['language']) ? Strings::escapeTags(trim($_POST['language'])) : ''); + $username = (!empty($_POST['username']) ? trim($_POST['username']) : ''); + $email = (!empty($_POST['email']) ? trim($_POST['email']) : ''); + $timezone = (!empty($_POST['timezone']) ? trim($_POST['timezone']) : ''); + $language = (!empty($_POST['language']) ? trim($_POST['language']) : ''); - $defloc = (!empty($_POST['defloc']) ? Strings::escapeTags(trim($_POST['defloc'])) : ''); - $maxreq = (!empty($_POST['maxreq']) ? intval($_POST['maxreq']) : 0); - $expire = (!empty($_POST['expire']) ? intval($_POST['expire']) : 0); + $defloc = (!empty($_POST['defloc']) ? trim($_POST['defloc']) : ''); + $maxreq = (!empty($_POST['maxreq']) ? intval($_POST['maxreq']) : 0); + $expire = (!empty($_POST['expire']) ? intval($_POST['expire']) : 0); $def_gid = (!empty($_POST['group-selection']) ? intval($_POST['group-selection']) : 0); @@ -317,7 +308,9 @@ function settings_post(App $a) if ($email != $user['email']) { // check for the correct password - if (!User::authenticate(intval(local_user()), $_POST['mpassword'])) { + try { + User::getIdFromPasswordAuthentication(local_user(), $_POST['mpassword']); + } catch (Exception $ex) { $err .= DI::l10n()->t('Wrong Password.'); $email = $user['email']; } @@ -341,7 +334,7 @@ function settings_post(App $a) } if (($timezone != $user['timezone']) && strlen($timezone)) { - date_default_timezone_set($timezone); + $a->setTimeZone($timezone); } $aclFormatter = DI::aclFormatter(); @@ -500,7 +493,7 @@ function settings_content(App $a) $settings_connectors = ''; Hook::callAll('connector_settings', $settings_connectors); - if (is_site_admin()) { + if ($a->isSiteAdmin()) { $diasp_enabled = DI::l10n()->t('Built-in support for %s connectivity is %s', DI::l10n()->t('Diaspora (Socialhome, Hubzilla)'), ((DI::config()->get('system', 'diaspora_enabled')) ? DI::l10n()->t('enabled') : DI::l10n()->t('disabled'))); $ostat_enabled = DI::l10n()->t('Built-in support for %s connectivity is %s', DI::l10n()->t('OStatus (GNU Social)'), ((DI::config()->get('system', 'ostatus_disabled')) ? DI::l10n()->t('disabled') : DI::l10n()->t('enabled'))); } else { @@ -510,22 +503,20 @@ function settings_content(App $a) $mail_disabled = ((function_exists('imap_open') && (!DI::config()->get('system', 'imap_disabled'))) ? 0 : 1); if (!$mail_disabled) { - $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", - local_user() - ); + $mailacct = DBA::selectFirst('mailacct', [], ['uid' => local_user()]); } else { - $r = null; + $mailacct = null; } - $mail_server = ((DBA::isResult($r)) ? $r[0]['server'] : ''); - $mail_port = ((DBA::isResult($r) && intval($r[0]['port'])) ? intval($r[0]['port']) : ''); - $mail_ssl = ((DBA::isResult($r)) ? $r[0]['ssltype'] : ''); - $mail_user = ((DBA::isResult($r)) ? $r[0]['user'] : ''); - $mail_replyto = ((DBA::isResult($r)) ? $r[0]['reply_to'] : ''); - $mail_pubmail = ((DBA::isResult($r)) ? $r[0]['pubmail'] : 0); - $mail_action = ((DBA::isResult($r)) ? $r[0]['action'] : 0); - $mail_movetofolder = ((DBA::isResult($r)) ? $r[0]['movetofolder'] : ''); - $mail_chk = ((DBA::isResult($r)) ? $r[0]['last_check'] : DBA::NULL_DATETIME); + $mail_server = $mailacct['server'] ?? ''; + $mail_port = (!empty($mailacct['port']) && is_numeric($mailacct['port'])) ? (int)$mailacct['port'] : ''; + $mail_ssl = $mailacct['ssltype'] ?? ''; + $mail_user = $mailacct['user'] ?? ''; + $mail_replyto = $mailacct['reply_to'] ?? ''; + $mail_pubmail = $mailacct['pubmail'] ?? 0; + $mail_action = $mailacct['action'] ?? 0; + $mail_movetofolder = $mailacct['movetofolder'] ?? ''; + $mail_chk = $mailacct['last_check'] ?? DBA::NULL_DATETIME; $tpl = Renderer::getMarkupTemplate('settings/connectors.tpl'); @@ -611,7 +602,7 @@ function settings_content(App $a) $expire_network_only = DI::pConfig()->get(local_user(), 'expire', 'network_only', false); if (!strlen($user['timezone'])) { - $timezone = date_default_timezone_get(); + $timezone = $a->getTimeZone(); } // Set the account type to "Community" when the page is a community page but the account type doesn't fit