From b80264f7b796e2c7ca9bc68286c80fa3450e566e Mon Sep 17 00:00:00 2001 From: xiaomlove <353856593@qq.com> Date: Fri, 22 Jan 2021 19:43:15 +0800 Subject: [PATCH] improve_install --- include/functions.php | 26 ++++++++++++++----- include/update.php | 58 ------------------------------------------- public/settings.php | 16 ------------ 3 files changed, 20 insertions(+), 80 deletions(-) delete mode 100644 include/update.php diff --git a/include/functions.php b/include/functions.php index c7239184..cb9e04bd 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1,8 +1,4 @@ isConnected()) { return; @@ -1768,7 +1764,9 @@ function dbconn($autoclean = false) mysql_query("SET collation_connection = 'utf8_general_ci'"); mysql_query("SET sql_mode=''"); - userlogin(); + if ($doLogin) { + userlogin(); + } // if (!$useCronTriggerCleanUp && $autoclean) { // register_shutdown_function("autoclean"); @@ -4402,4 +4400,20 @@ function return_category_image($categoryid, $link="") return $catimg; } +function saveSetting($prefix, $nameAndValue) +{ + $prefix = strtolower($prefix); + $datetimeNow = date('Y-m-d H:i:s'); + $sql = "insert into settings (name, value, created_at, updated_at) values "; + $data = []; + foreach ($nameAndValue as $name => $value) { + if (is_array($value)) { + $value = json_encode($value); + } + $data[] = sprintf("(%s, %s, %s, %s)", sqlesc("$prefix.$name"), sqlesc($value), sqlesc($datetimeNow), sqlesc($datetimeNow)); + } + $sql .= implode(",", $data) . " on duplicate key update value = values(value)"; + sql_query($sql) or sqlerr(__FILE__, __LINE__); +} + ?> diff --git a/include/update.php b/include/update.php deleted file mode 100644 index 2e562338..00000000 --- a/include/update.php +++ /dev/null @@ -1,58 +0,0 @@ - - */ - -function printLine($msg, $exit = false) -{ - echo sprintf("[%s] %s%s", date('Y-m-d H:i:s'), $msg, PHP_EOL); - if ($exit) { - exit(0); - } -} - -if (php_sapi_name() != 'cli') { - printLine("Please run in console!", true); -} - -//environment check -printLine("Checking the environment..."); -if (version_compare(PHP_VERSION, '7.2.0', '<')) { - printLine(sprintf('Your PHP version: %s not match, require >= 7.2.0', PHP_VERSION)); -} -$requireExtensions = ['mysqli', 'mbstring', 'gd', 'json']; -foreach ($requireExtensions as $ext) { - if (extension_loaded($ext)) { - printLine("extension: $ext is loaded."); - } else { - printLine("Error: required extension: $ext is not loaded!", true); - } -} -if (!extension_loaded('redis')) { - printLine("warning: redis is not loaded. highly recommand install it, see: https://pecl.php.net/package/redis/"); -} -$gdInfo = gd_info(); -$gdShouldAvaliable = ['JPEG Support', 'PNG Support', 'GIF Read Support']; -foreach ($gdShouldAvaliable as $value) { - if (!isset($gdInfo[$value]) || !$gdInfo[$value]) { - printLine("Error: gd $value is not available", true); - } -} - -//create .env file -$rootPath = dirname(__DIR__); -$envExample = "$rootPath/.env.example"; -$env = "$rootPath/.env"; -if (!file_exists("$rootPath.env")) { - printLine("Error: $envExample not exists."); -} -$copyResult = copy($envExample, $env); -if ($copyResult !== true) { - -} - - - - - diff --git a/public/settings.php b/public/settings.php index de167ca7..a6f62dcf 100644 --- a/public/settings.php +++ b/public/settings.php @@ -8,7 +8,6 @@ parked(); if (get_user_class() < UC_SYSOP) permissiondenied(); -$datetimeNow = date('Y-m-d H:i:s'); function go_back() { global $lang_settings; @@ -21,21 +20,6 @@ function yesorno($title, $name, $value, $note="") tr($title, "
".$note, 1); } -function saveSetting($prefix, $nameAndValue) -{ - global $datetimeNow; - $sql = "insert into settings (name, value, created_at, updated_at) values "; - $data = []; - foreach ($nameAndValue as $name => $value) { - if (is_array($value)) { - $value = json_encode($value); - } - $data[] = sprintf("(%s, %s, %s, %s)", sqlesc("$prefix.$name"), sqlesc($value), sqlesc($datetimeNow), sqlesc($datetimeNow)); - } - $sql .= implode(",", $data) . " on duplicate key update value = values(value)"; - sql_query($sql) or sqlerr(__FILE__, __LINE__); -} - $action = isset($_POST['action']) ? $_POST['action'] : 'showmenu'; $allowed_actions = array('basicsettings','mainsettings','smtpsettings','securitysettings','authoritysettings','tweaksettings', 'botsettings','codesettings','bonussettings','accountsettings','torrentsettings', 'attachmentsettings', 'advertisementsettings', 'savesettings_basic', 'savesettings_main','savesettings_smtp','savesettings_security','savesettings_authority','savesettings_tweak','savesettings_bot','savesettings_code','savesettings_bonus', 'savesettings_account','savesettings_torrent', 'savesettings_attachment', 'savesettings_advertisement', 'showmenu'); if (!in_array($action, $allowed_actions))