Scrutinizer fixes for mod/settings
- Use defaults() - Remove unused variables and constants - Fix some formatting - Improve documentation
This commit is contained in:
parent
c157e7ffa4
commit
1cc39e7fb4
106
mod/settings.php
106
mod/settings.php
|
@ -14,7 +14,8 @@ use Friendica\Model\Group;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
use Friendica\Protocol\Email;
|
use Friendica\Protocol\Email;
|
||||||
|
|
||||||
function get_theme_config_file($theme) {
|
function get_theme_config_file($theme)
|
||||||
|
{
|
||||||
$a = get_app();
|
$a = get_app();
|
||||||
$base_theme = $a->theme_info['extends'];
|
$base_theme = $a->theme_info['extends'];
|
||||||
|
|
||||||
|
@ -27,8 +28,8 @@ function get_theme_config_file($theme) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function settings_init(App $a) {
|
function settings_init(App $a)
|
||||||
|
{
|
||||||
if (!local_user()) {
|
if (!local_user()) {
|
||||||
notice(t('Permission denied.') . EOL);
|
notice(t('Permission denied.') . EOL);
|
||||||
return;
|
return;
|
||||||
|
@ -41,8 +42,6 @@ function settings_init(App $a) {
|
||||||
'$ispublic' => t('everybody')
|
'$ispublic' => t('everybody')
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$tabs = array(
|
$tabs = array(
|
||||||
array(
|
array(
|
||||||
'label' => t('Account'),
|
'label' => t('Account'),
|
||||||
|
@ -120,9 +119,8 @@ function settings_init(App $a) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function settings_post(App $a)
|
||||||
function settings_post(App $a) {
|
{
|
||||||
|
|
||||||
if (!local_user()) {
|
if (!local_user()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -150,20 +148,19 @@ function settings_post(App $a) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($a->argc > 2) && ($a->argv[1] === 'oauth') && ($a->argv[2] === 'edit'||($a->argv[2] === 'add')) && x($_POST, 'submit')) {
|
if (($a->argc > 2) && ($a->argv[1] === 'oauth') && ($a->argv[2] === 'edit'||($a->argv[2] === 'add')) && x($_POST, 'submit')) {
|
||||||
|
|
||||||
check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth');
|
check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth');
|
||||||
|
|
||||||
$name = ((x($_POST, 'name')) ? $_POST['name'] : '');
|
$name = defaults($_POST, 'name' , '');
|
||||||
$key = ((x($_POST, 'key')) ? $_POST['key'] : '');
|
$key = defaults($_POST, 'key' , '');
|
||||||
$secret = ((x($_POST, 'secret')) ? $_POST['secret'] : '');
|
$secret = defaults($_POST, 'secret' , '');
|
||||||
$redirect = ((x($_POST, 'redirect')) ? $_POST['redirect'] : '');
|
$redirect = defaults($_POST, 'redirect', '');
|
||||||
$icon = ((x($_POST, 'icon')) ? $_POST['icon'] : '');
|
$icon = defaults($_POST, 'icon' , '');
|
||||||
if ($name=="" || $key=="" || $secret=="") {
|
|
||||||
notice(t("Missing some important data!"));
|
|
||||||
|
|
||||||
|
if ($name == "" || $key == "" || $secret == "") {
|
||||||
|
notice(t("Missing some important data!"));
|
||||||
} else {
|
} else {
|
||||||
if ($_POST['submit']==t("Update")) {
|
if ($_POST['submit']==t("Update")) {
|
||||||
$r = q("UPDATE clients SET
|
q("UPDATE clients SET
|
||||||
client_id='%s',
|
client_id='%s',
|
||||||
pw='%s',
|
pw='%s',
|
||||||
name='%s',
|
name='%s',
|
||||||
|
@ -179,7 +176,7 @@ function settings_post(App $a) {
|
||||||
local_user(),
|
local_user(),
|
||||||
dbesc($key));
|
dbesc($key));
|
||||||
} else {
|
} else {
|
||||||
$r = q("INSERT INTO clients
|
q("INSERT INTO clients
|
||||||
(client_id, pw, name, redirect_uri, icon, uid)
|
(client_id, pw, name, redirect_uri, icon, uid)
|
||||||
VALUES ('%s', '%s', '%s', '%s', '%s',%d)",
|
VALUES ('%s', '%s', '%s', '%s', '%s',%d)",
|
||||||
dbesc($key),
|
dbesc($key),
|
||||||
|
@ -342,8 +339,8 @@ function settings_post(App $a) {
|
||||||
|
|
||||||
if ($theme == $a->user['theme']) {
|
if ($theme == $a->user['theme']) {
|
||||||
// call theme_post only if theme has not been changed
|
// call theme_post only if theme has not been changed
|
||||||
if (($themeconfigfile = get_theme_config_file($theme)) != null) {
|
if (($themeconfigfile = get_theme_config_file($theme)) !== null) {
|
||||||
require_once($themeconfigfile);
|
require_once $themeconfigfile;
|
||||||
theme_post($a);
|
theme_post($a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -395,7 +392,7 @@ function settings_post(App $a) {
|
||||||
dbesc($password),
|
dbesc($password),
|
||||||
intval(local_user())
|
intval(local_user())
|
||||||
);
|
);
|
||||||
if ($r) {
|
if (DBM::is_result($r)) {
|
||||||
info(t('Password changed.') . EOL);
|
info(t('Password changed.') . EOL);
|
||||||
} else {
|
} else {
|
||||||
notice(t('Password update failed. Please try again.') . EOL);
|
notice(t('Password update failed. Please try again.') . EOL);
|
||||||
|
@ -535,9 +532,8 @@ function settings_post(App $a) {
|
||||||
//$openid = normalise_openid($openid);
|
//$openid = normalise_openid($openid);
|
||||||
|
|
||||||
// If openid has changed or if there's an openid but no openidserver, try and discover it.
|
// If openid has changed or if there's an openid but no openidserver, try and discover it.
|
||||||
|
|
||||||
if ($openid != $a->user['openid'] || (strlen($openid) && (!strlen($openidserver)))) {
|
if ($openid != $a->user['openid'] || (strlen($openid) && (!strlen($openidserver)))) {
|
||||||
if (strlen($tmp_str) && validate_url($openid)) {
|
if (validate_url($openid)) {
|
||||||
logger('updating openidserver');
|
logger('updating openidserver');
|
||||||
require_once 'library/openid.php';
|
require_once 'library/openid.php';
|
||||||
$open_id_obj = new LightOpenID;
|
$open_id_obj = new LightOpenID;
|
||||||
|
@ -608,7 +604,7 @@ function settings_post(App $a) {
|
||||||
dbesc($language),
|
dbesc($language),
|
||||||
intval(local_user())
|
intval(local_user())
|
||||||
);
|
);
|
||||||
if ($r) {
|
if (DBM::is_result($r)) {
|
||||||
info(t('Settings updated.') . EOL);
|
info(t('Settings updated.') . EOL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -650,21 +646,13 @@ function settings_post(App $a) {
|
||||||
// Update the global contact for the user
|
// Update the global contact for the user
|
||||||
GContact::updateForUser(local_user());
|
GContact::updateForUser(local_user());
|
||||||
|
|
||||||
//$_SESSION['theme'] = $theme;
|
|
||||||
if ($email_changed && $a->config['register_policy'] == REGISTER_VERIFY) {
|
|
||||||
|
|
||||||
/// @TODO set to un-verified, blocked and redirect to logout
|
|
||||||
/// @TODO Why? Are we verifying people or email addresses?
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
goaway('settings');
|
goaway('settings');
|
||||||
return; // NOTREACHED
|
return; // NOTREACHED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function settings_content(App $a) {
|
function settings_content(App $a)
|
||||||
|
{
|
||||||
$o = '';
|
$o = '';
|
||||||
nav_set_selected('settings');
|
nav_set_selected('settings');
|
||||||
|
|
||||||
|
@ -678,10 +666,7 @@ function settings_content(App $a) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (($a->argc > 1) && ($a->argv[1] === 'oauth')) {
|
if (($a->argc > 1) && ($a->argv[1] === 'oauth')) {
|
||||||
|
|
||||||
if (($a->argc > 2) && ($a->argv[2] === 'add')) {
|
if (($a->argc > 2) && ($a->argv[2] === 'add')) {
|
||||||
$tpl = get_markup_template('settings/oauth_edit.tpl');
|
$tpl = get_markup_template('settings/oauth_edit.tpl');
|
||||||
$o .= replace_macros($tpl, array(
|
$o .= replace_macros($tpl, array(
|
||||||
|
@ -727,7 +712,7 @@ function settings_content(App $a) {
|
||||||
if (($a->argc > 3) && ($a->argv[2] === 'delete')) {
|
if (($a->argc > 3) && ($a->argv[2] === 'delete')) {
|
||||||
check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth', 't');
|
check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth', 't');
|
||||||
|
|
||||||
$r = q("DELETE FROM clients WHERE client_id='%s' AND uid=%d",
|
q("DELETE FROM clients WHERE client_id='%s' AND uid=%d",
|
||||||
dbesc($a->argv[3]),
|
dbesc($a->argv[3]),
|
||||||
local_user());
|
local_user());
|
||||||
goaway(System::baseUrl(true)."/settings/oauth/");
|
goaway(System::baseUrl(true)."/settings/oauth/");
|
||||||
|
@ -757,7 +742,6 @@ function settings_content(App $a) {
|
||||||
'$apps' => $r,
|
'$apps' => $r,
|
||||||
));
|
));
|
||||||
return $o;
|
return $o;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($a->argc > 1) && ($a->argv[1] === 'addon')) {
|
if (($a->argc > 1) && ($a->argv[1] === 'addon')) {
|
||||||
|
@ -899,8 +883,8 @@ function settings_content(App $a) {
|
||||||
$default_theme = 'default';
|
$default_theme = 'default';
|
||||||
}
|
}
|
||||||
$default_mobile_theme = Config::get('system', 'mobile-theme');
|
$default_mobile_theme = Config::get('system', 'mobile-theme');
|
||||||
if (!$mobile_default_theme) {
|
if (!$default_mobile_theme) {
|
||||||
$mobile_default_theme = 'none';
|
$default_mobile_theme = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
$allowed_themes_str = Config::get('system', 'allowed_themes');
|
$allowed_themes_str = Config::get('system', 'allowed_themes');
|
||||||
|
@ -917,25 +901,28 @@ function settings_content(App $a) {
|
||||||
|
|
||||||
$themes = array();
|
$themes = array();
|
||||||
$mobile_themes = array("---" => t('No special theme for mobile devices'));
|
$mobile_themes = array("---" => t('No special theme for mobile devices'));
|
||||||
$files = glob('view/theme/*'); /* */
|
|
||||||
if ($allowed_themes) {
|
if ($allowed_themes) {
|
||||||
foreach ($allowed_themes as $th) {
|
foreach ($allowed_themes as $theme) {
|
||||||
$f = $th;
|
$is_experimental = file_exists('view/theme/' . $theme . '/experimental');
|
||||||
$is_experimental = file_exists('view/theme/' . $th . '/experimental');
|
$is_unsupported = file_exists('view/theme/' . $theme . '/unsupported');
|
||||||
$unsupported = file_exists('view/theme/' . $th . '/unsupported');
|
$is_mobile = file_exists('view/theme/' . $theme . '/mobile');
|
||||||
$is_mobile = file_exists('view/theme/' . $th . '/mobile');
|
|
||||||
if (!$is_experimental || ($is_experimental && (Config::get('experimentals', 'exp_themes')==1 || is_null(Config::get('experimentals', 'exp_themes'))))) {
|
if (!$is_experimental || ($is_experimental && (Config::get('experimentals', 'exp_themes')==1 || is_null(Config::get('experimentals', 'exp_themes'))))) {
|
||||||
$theme_name = (($is_experimental) ? sprintf("%s - \x28Experimental\x29", $f) : $f);
|
$theme_name = ucfirst($theme);
|
||||||
|
if ($is_unsupported) {
|
||||||
|
$theme_name = t("%s - (Unsupported)", $theme_name);
|
||||||
|
} elseif ($is_experimental) {
|
||||||
|
$theme_name = t("%s - (Experimental)", $theme_name);
|
||||||
|
}
|
||||||
if ($is_mobile) {
|
if ($is_mobile) {
|
||||||
$mobile_themes[$f]=$theme_name;
|
$mobile_themes[$theme] = $theme_name;
|
||||||
} else {
|
} else {
|
||||||
$themes[$f]=$theme_name;
|
$themes[$theme] = $theme_name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$theme_selected = (!x($_SESSION, 'theme')? $default_theme : $_SESSION['theme']);
|
$theme_selected = defaults($_SESSION, 'theme' , $default_theme);
|
||||||
$mobile_theme_selected = (!x($_SESSION, 'mobile-theme')? $default_mobile_theme : $_SESSION['mobile-theme']);
|
$mobile_theme_selected = defaults($_SESSION, 'mobile-theme', $default_mobile_theme);
|
||||||
|
|
||||||
$nowarn_insecure = intval(PConfig::get(local_user(), 'system', 'nowarn_insecure'));
|
$nowarn_insecure = intval(PConfig::get(local_user(), 'system', 'nowarn_insecure'));
|
||||||
|
|
||||||
|
@ -960,8 +947,8 @@ function settings_content(App $a) {
|
||||||
$smart_threading = PConfig::get(local_user(), 'system', 'smart_threading', 0);
|
$smart_threading = PConfig::get(local_user(), 'system', 'smart_threading', 0);
|
||||||
|
|
||||||
$theme_config = "";
|
$theme_config = "";
|
||||||
if (($themeconfigfile = get_theme_config_file($theme_selected)) != null) {
|
if (($themeconfigfile = get_theme_config_file($theme_selected)) !== null) {
|
||||||
require_once($themeconfigfile);
|
require_once $themeconfigfile;
|
||||||
$theme_config = theme_content($a);
|
$theme_config = theme_content($a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1010,11 +997,10 @@ function settings_content(App $a) {
|
||||||
|
|
||||||
require_once('include/acl_selectors.php');
|
require_once('include/acl_selectors.php');
|
||||||
|
|
||||||
$p = q("SELECT * FROM `profile` WHERE `is-default` = 1 AND `uid` = %d LIMIT 1",
|
$profile = dba::select('profile', [], ['is-default' => true, 'uid' => local_user()], ['limit' => 1]);
|
||||||
intval(local_user())
|
if (!DBM::is_result($profile)) {
|
||||||
);
|
notice(t('Unable to find your profile. Please contact your admin.') . EOL);
|
||||||
if (count($p)) {
|
return;
|
||||||
$profile = $p[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$username = $a->user['username'];
|
$username = $a->user['username'];
|
||||||
|
@ -1027,8 +1013,6 @@ function settings_content(App $a) {
|
||||||
$openid = $a->user['openid'];
|
$openid = $a->user['openid'];
|
||||||
$maxreq = $a->user['maxreq'];
|
$maxreq = $a->user['maxreq'];
|
||||||
$expire = ((intval($a->user['expire'])) ? $a->user['expire'] : '');
|
$expire = ((intval($a->user['expire'])) ? $a->user['expire'] : '');
|
||||||
$blockwall = $a->user['blockwall'];
|
|
||||||
$blocktags = $a->user['blocktags'];
|
|
||||||
$unkmail = $a->user['unkmail'];
|
$unkmail = $a->user['unkmail'];
|
||||||
$cntunkmail = $a->user['cntunkmail'];
|
$cntunkmail = $a->user['cntunkmail'];
|
||||||
|
|
||||||
|
|
|
@ -66,8 +66,8 @@ class Email
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $mailacct mail account
|
* @param array $mailacct mail account
|
||||||
* @return object
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function constructMailboxName($mailacct)
|
public static function constructMailboxName($mailacct)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue