From 9934c312b7e102dacb470dab3d950c1437db214f Mon Sep 17 00:00:00 2001
From: xiaomlove <353856593@qq.com>
Date: Tue, 12 Jan 2021 21:14:02 +0800
Subject: [PATCH] settings load from database and i18n from config files
---
classes/class_cache_redis.php | 28 ++--
config/database.php | 1 -
include/bittorrent.php | 6 +-
include/bittorrent_announce.php | 16 +-
include/config.php | 62 ++++----
include/core.php | 7 +-
include/database/class_db.php | 8 +-
include/functions.php | 247 +------------------------------
include/functions_announce.php | 9 +-
include/globalfunctions.php | 254 +++++++++++++++++++++++++++++++-
invite.php | 8 +-
lang/chs/lang_settings.php | 6 +
lang/cht/lang_settings.php | 6 +
lang/en/lang_settings.php | 6 +
settings.php | 68 ++++-----
takemessage.php | 2 +-
16 files changed, 374 insertions(+), 360 deletions(-)
diff --git a/classes/class_cache_redis.php b/classes/class_cache_redis.php
index ccbf550b..7170e53c 100644
--- a/classes/class_cache_redis.php
+++ b/classes/class_cache_redis.php
@@ -19,7 +19,7 @@ class RedisCache {
public $redis;
function __construct() {
- $success = $this->connect($host = 'localhost', $port = 6379); // Connect to Redis
+ $success = $this->connect(); // Connect to Redis
if ($success) {
$this->isEnabled = 1;
} else {
@@ -27,33 +27,33 @@ class RedisCache {
}
}
- private function connect($host, $port)
+ private function connect()
{
- global $BASIC, $TWEAK;
+ $config = config('database.redis');
$redis = new Redis();
$params = [
- $BASIC['redis_host'],
+ $config['host'],
];
- if (!empty($BASIC['redis_port'])) {
- $params[] = $BASIC['redis_port'];
+ if (!empty($config['port'])) {
+ $params[] = $config['port'];
}
- if (!empty($BASIC['redis_timeout'])) {
- $params[] = $BASIC['redis_timeout'];
+ if (!empty($config['timeout'])) {
+ $params[] = $config['timeout'];
}
try {
$connectResult = $redis->connect(...$params);
$auth = [];
- if (!empty($BASIC['redis_password'])) {
- $auth['pass'] = $BASIC['redis_password'];
- if (!empty($BASIC['redis_username'])) {
- $auth['user'] = $BASIC['redis_username'];
+ if (!empty($config['password'])) {
+ $auth['pass'] = $config['password'];
+ if (!empty($config['username'])) {
+ $auth['user'] = $config['username'];
}
$connectResult = $connectResult && $redis->auth($auth);
}
if ($connectResult) {
$this->redis = $redis;
- if (is_numeric($BASIC['redis_database'])) {
- $redis->select($BASIC['redis_database']);
+ if (is_numeric($config['database'])) {
+ $redis->select($config['database']);
}
}
return $connectResult;
diff --git a/config/database.php b/config/database.php
index 07fed63a..857e1904 100644
--- a/config/database.php
+++ b/config/database.php
@@ -1,5 +1,4 @@
[
diff --git a/include/bittorrent.php b/include/bittorrent.php
index 3ec0a03d..406f67a6 100644
--- a/include/bittorrent.php
+++ b/include/bittorrent.php
@@ -10,5 +10,9 @@ $showversion = " - Powered by ".PROJECTNAME;
$rootpath=realpath(dirname(__FILE__) . '/..');
set_include_path(get_include_path() . PATH_SEPARATOR . $rootpath);
$rootpath .= "/";
-
+require $rootpath . 'include/functions.php';
+require $rootpath . 'include/globalfunctions.php';
+require $rootpath . get_langfile_path("functions.php");
require $rootpath . 'include/core.php';
+
+
diff --git a/include/bittorrent_announce.php b/include/bittorrent_announce.php
index 04040c18..4d453a65 100644
--- a/include/bittorrent_announce.php
+++ b/include/bittorrent_announce.php
@@ -4,18 +4,6 @@ define('NEXUS_START', microtime(true));
define('IN_TRACKER', true);
$rootpath=realpath(dirname(__FILE__) . '/..')."/";
-require $rootpath . 'include/config.php';
-require $rootpath . 'include/functions.php';
-require $rootpath . 'include/globalfunctions.php';
-require $rootpath . get_langfile_path("functions.php");
-
-require $rootpath . 'include/database/interface_db.php';
-require $rootpath . 'include/database/class_db_mysqli.php';
-require $rootpath . 'include/database/class_db.php';
-require $rootpath . 'include/database/helpers.php';
-require $rootpath . 'include/database/class_exception.php';
-
-require $rootpath . 'classes/class_cache_redis.php';
-
-require $rootpath . 'include/core.php';
require $rootpath . 'include/functions_announce.php';
+require $rootpath . 'include/globalfunctions.php';
+require $rootpath . 'include/core.php';
diff --git a/include/config.php b/include/config.php
index 998c6d4a..fef90a2d 100644
--- a/include/config.php
+++ b/include/config.php
@@ -2,33 +2,22 @@
# IMPORTANT: Do not edit below unless you know what you are doing!
if(!defined('IN_TRACKER'))
die('Hacking attempt!');
-
+/*
$CONFIGURATIONS = array('ACCOUNT', 'ADVERTISEMENT', 'ATTACHMENT', 'AUTHORITY', 'BASIC', 'BONUS', 'CODE', 'MAIN', 'SECURITY', 'SMTP', 'TORRENT', 'TWEAK');
+
function ReadConfig ($configname = NULL) {
- static $allConfig;
-
global $CONFIGURATIONS;
-
- if (is_null($allConfig)) {
- $configs = config();
- foreach ($configs as $name => $value) {
- $prefix = strtoupper(strstr($name, '.', true));
- $pureName = substr($name, strpos($name, '.') + 1);
- $GLOBALS[$prefix][$pureName] = $value;
+ if ($configname) {
+ $configname = basename($configname);
+ $tmp = oldReadConfig($configname);
+ WriteConfig($configname, $tmp);
+ @unlink('./config/'.$configname);
+ return $tmp;
+ } else {
+ foreach ($CONFIGURATIONS as $CONFIGURATION) {
+ $GLOBALS[$CONFIGURATION] = ReadConfig($CONFIGURATION);
}
}
-dd($GLOBALS);
-// if ($configname) {
-// $configname = basename($configname);
-// $tmp = oldReadConfig($configname);
-// WriteConfig($configname, $tmp);
-// @unlink('./config/'.$configname);
-// return $tmp;
-// } else {
-// foreach ($CONFIGURATIONS as $CONFIGURATION) {
-// $GLOBALS[$CONFIGURATION] = ReadConfig($CONFIGURATION);
-// }
-// }
}
function oldReadConfig ($configname) {
@@ -41,8 +30,7 @@ function oldReadConfig ($configname) {
$configname = basename($configname);
$path = './config/'.$configname;
if (!file_exists($path)) {
- do_log($path);
- die("Error! File ".htmlspecialchars($configname)." doesn't exist!
Before the setup starts, please ensure that you have properly configured file and directory access permissions. Please see below.
chmod 777 config/
chmod 777 config/".$configname);
+ die("Error! File ".htmlspecialchars($configname)." doesn't exist!
Before the setup starts, please ensure that you have properly configured file and directory access permissions. Please see below.
chmod 777 config/
chmod 777 config/".$configname);
}
$fp = fopen($path, 'r');
@@ -65,13 +53,27 @@ function oldReadConfig ($configname) {
}
}
-ReadConfig();
-//if (file_exists('config/allconfig.php')) {
-// require('config/allconfig.php');
-//} else {
-// ReadConfig();
-//}
+if (file_exists('config/allconfig.php')) {
+ require('config/allconfig.php');
+} else {
+ ReadConfig();
+}
+*/
+
+//load settings from database
+if (basename($_SERVER['SCRIPT_FILENAME']) == 'announce.php') {
+ dbconn_announce();
+} else {
+ dbconn();
+}
+$settings = get_setting();
+foreach ($settings as $name => $value) {
+ $prefix = strtoupper(strstr($name, '.', true));
+ $pureName = substr($name, strpos($name, '.') + 1);
+ $GLOBALS[$prefix][$pureName] = $value;
+}
+
$SITENAME = $BASIC['SITENAME'];
$BASEURL = $BASIC['BASEURL'];
$announce_urls = array();
diff --git a/include/core.php b/include/core.php
index c45fe7cf..2fb84204 100644
--- a/include/core.php
+++ b/include/core.php
@@ -3,9 +3,6 @@ if(!defined('IN_TRACKER'))
die('Hacking attempt!');
error_reporting(E_ALL);
-require $rootpath . 'include/functions.php';
-require $rootpath . 'include/globalfunctions.php';
-
require $rootpath . 'include/database/interface_db.php';
require $rootpath . 'include/database/class_db_mysqli.php';
require $rootpath . 'include/database/class_db.php';
@@ -14,12 +11,10 @@ require $rootpath . 'include/database/class_exception.php';
require $rootpath . 'classes/class_advertisement.php';
require $rootpath . 'classes/class_cache_redis.php';
-
require $rootpath . 'include/config.php';
-require $rootpath . get_langfile_path("functions.php");
-
ini_set('display_errors', $TWEAK['display_errors']);
+
$Cache = new RedisCache(); //Load the caching class
$Cache->setLanguageFolderArray(get_langfolder_list());
define('TIMENOW', time());
diff --git a/include/database/class_db.php b/include/database/class_db.php
index bbe7d857..315f76fe 100644
--- a/include/database/class_db.php
+++ b/include/database/class_db.php
@@ -8,6 +8,8 @@ class DB
private static $queries = [];
+ private $isConnected = false;
+
private function __construct()
{
@@ -39,9 +41,11 @@ class DB
public function connect($host, $username, $password, $database, $port)
{
- if (is_null($this->driver)) {
+ if (!$this->isConnected) {
$this->driver->connect($host, $username, $password, $database, $port);
+ $this->isConnected = true;
}
+ return true;
}
public function query(string $sql)
@@ -112,7 +116,7 @@ class DB
public function isConnected()
{
- return !is_null($this->driver);
+ return $this->isConnected;
}
diff --git a/include/functions.php b/include/functions.php
index 403903bc..50bf1748 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -1720,32 +1720,20 @@ function dbconn($autoclean = false)
if (DB::getInstance()->isConnected()) {
return;
}
- global $lang_functions;
- global $mysql_host, $mysql_user, $mysql_pass, $mysql_db;
- global $useCronTriggerCleanUp;
- global $BASIC;
-
- if (!mysql_connect($mysql_host, $mysql_user, $mysql_pass, $BASIC['mysql_db'], $BASIC['mysql_port']))
+ $config = config('database.mysql');
+ if (!mysql_connect($config['host'], $config['username'], $config['password'], $config['database'], $config['port']))
{
- switch (mysql_errno())
- {
- case 1040:
- case 2002:
- die("
".$lang_functions['std_server_load_very_high']." |
';
- array_map(function ($var) {
- var_dump($var);
- }, func_get_args());
- echo '';
- exit(0);
-}
-
-function do_log($log)
-{
- global $TWEAK;
- if (!empty($TWEAK['logging'])) {
- $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
- $content = sprintf(
- "[%s] %s:%s %s%s%s %s%s",
- date('Y-m-d H:i:s'),
- $backtrace[0]['file'] ?? '',
- $backtrace[0]['line'] ?? '',
- $backtrace[1]['class'] ?? '',
- $backtrace[1]['type'] ?? '',
- $backtrace[1]['function'] ?? '',
- $log,
- PHP_EOL
- );
- file_put_contents($TWEAK['logging'], $content, FILE_APPEND);
- }
-}
-
-/**
- * get translation for given name
- *
- * @author xiaomlove
- * @date 2021/1/11
- * @param null $name
- * @param null $prefix
- * @return mixed|string
- */
-function __($name = null, $prefix = null)
-{
- static $i18n;
- static $i18nWithoutPrefix;
- $userLocale = get_langfolder_cookie();
- $defaultLocale = 'en';
- if (is_null($prefix)) {
- //get prefix from scripe name
- $prefix = basename($_SERVER['SCRIPT_NAME']);
- $prefix = strstr($prefix, '.php', true);
- }
- if (is_null($i18n)) {
- //get all in18 may be used, incldue user locale and default locale, and name in('_target', 'functions') (because they are common) or prefixed with given prefix
- $sql = "select locale, name, translation from i18n where locale in (" . sqlesc($userLocale) . ", " . sqlesc($defaultLocale) . ") and (name in ('_target', 'functions') or name like '{$prefix}%')";
- $result = sql_query($sql);
- while ($row = mysql_fetch_assoc($result)) {
- $i18n[$row['locale']][$row['name']] = $row['translation'];
- $i18nWithoutPrefix[$row['locale']][substr($row['name'], strpos($row['name'], '.') + 1)] = $row['translation'];
- }
- }
- if (is_null($name)) {
- return $i18nWithoutPrefix[$userLocale] ?? $i18nWithoutPrefix[$defaultLocale] ?? [];
- }
- $name = "$prefix.$name";
- return $i18n[$userLocale][$name] ?? $i18n[$defaultLocale][$name] ?? '';
-
-}
-
-function config($key, $default = null)
-{
- static $configs;
- if (is_null($configs)) {
- //get all configuration from config file
- $files = glob($rootpath . 'config/*.php');
- foreach ($files as $file) {
- $basename = basename($file);
- if ($basename != 'allconfig.php') {
- continue;
- }
- $values = require $file;
- $configPrefix = strstr($basename, '.php', true);
- foreach ($values as $key => $value) {
- $configs["$configPrefix.$key"] = $value;
- }
- }
- }
- return $configs[$key] ?? $default;
-}
-
-/**
- * get setting for given name and prefix
- *
- * $name == null and $prefix == null, return all
- * $name == null and $prefix != null, return with specified prefix, but the result's prefix will be stripped
- *
- * @author xiaomlove
- * @date 2021/1/11
- * @param null $name
- * @param null $prefix
- * @return array|mixed|string
- */
-function get_setting($name = null, $prefix = null)
-{
- static $settings;
- if (is_null($settings)) {
- //get all settings from database
- $sql = "select config_name, config_value from configs";
- $result = sql_query($sql);
- while ($row = mysql_fetch_assoc($result)) {
- $value = $row['config_value'];
- $arr = json_decode($value, true);
- if (is_array($arr)) {
- $value = $arr;
- }
- $settings[$row['config_name']] = $value;
- }
-
- }
- if (!is_null($name)) {
- if (!is_null($prefix)) {
- $name = "$prefix.$name";
- }
- return $settings[$name] ?? null;
- }
- if (is_null($prefix)) {
- return $settings;
- }
- $filtered = [];
- foreach ($settings as $name => $value) {
- if (preg_match("/^$prefix/", $name)) {
- $nameWithoutPrefix = substr($name, strpos($name, '.') + 1);
- $filtered[$nameWithoutPrefix] = $value;
- }
- }
- return $filtered;
-
-}
-
-function env($key, $default = null)
-{
- static $env;
- if (is_null($env)) {
- $envFile = $rootpath . '.env';
- if (!file_exists($envFile)) {
- throw new \RuntimeException(".env file is not exists in the root path.");
- }
- $fp = fopen($envFile, 'r');
- if ($fp === false) {
- throw new \RuntimeException(".env file: $envFile is not readable.");
- }
- while ($line = trim(fgets($fp))) {
- if (empty($line)) {
- continue;
- }
- $pos = strpos($line, '=');
- $key = normalize_env(mb_substr($line, 0, $pos, 'utf-8'));
- $value = normalize_env(mb_substr($line, $pos + 1, null, 'utf-8'));
- $env[$key] = $value;
- }
- }
- return $env[$key] ?? $default;
-
-}
-
-function normalize_env($value)
-{
- $value = trim($value);
- $toStrip = ['\'', '"'];
- if (in_array(mb_substr($value, 0, 1, 'utf-8'), $toStrip)) {
- $value = mb_substr($value, 1, null, 'utf-8');
- }
- if (in_array(mb_substr($value, -1, 'utf-8'), $toStrip)) {
- $value = mb_substr($value, 0, -1, 'utf-8');
- }
- switch (strtolower($value)) {
- case 'true':
- return true;
- case 'false':
- return false;
- case 'null':
- return null;
- default:
- return $value;
- }
-}
-
?>
diff --git a/include/functions_announce.php b/include/functions_announce.php
index 7784850e..644d2f80 100644
--- a/include/functions_announce.php
+++ b/include/functions_announce.php
@@ -2,21 +2,18 @@
# IMPORTANT: Do not edit below unless you know what you are doing!
if(!defined('IN_TRACKER'))
die('Hacking attempt!');
-include_once($rootpath . 'include/globalfunctions.php');
-include_once($rootpath . 'include/config.php');
function dbconn_announce() {
- global $mysql_host, $mysql_user, $mysql_pass, $mysql_db;
- global $BASIC;
- if (!@mysql_connect($mysql_host, $mysql_user, $mysql_pass, $BASIC['mysql_db'], $BASIC['mysql_port']))
+ $config = config('database.mysql');
+
+ if (!@mysql_connect($config['host'], $config['username'], $config['password'], $config['database'], $config['port']))
{
die('dbconn: mysql_connect: ' . mysql_error());
}
mysql_query("SET NAMES UTF8");
mysql_query("SET collation_connection = 'utf8_general_ci'");
mysql_query("SET sql_mode=''");
- mysql_select_db($mysql_db) or die('dbconn: mysql_select_db: ' + mysql_error());
}
function hash_where_arr($name, $hash_arr) {
diff --git a/include/globalfunctions.php b/include/globalfunctions.php
index 664f320e..0c6504c2 100644
--- a/include/globalfunctions.php
+++ b/include/globalfunctions.php
@@ -67,12 +67,12 @@ function getip() {
function sql_query($query)
{
- $begin = getmicrotime();
+ $begin = microtime(true);
global $query_name;
$result = mysql_query($query);
$query_name[] = [
'query' => $query,
- 'time' => sprintf('%.3f', getmicrotime() - $begin),
+ 'time' => microtime(true) - $begin,
];
return $result;
}
@@ -93,4 +93,254 @@ function hash_where($name, $hash) {
$shhash = preg_replace('/ *$/s', "", $hash);
return "($name = " . sqlesc($hash) . " OR $name = " . sqlesc($shhash) . ")";
}
+
+
+function strip_magic_quotes($arr)
+{
+ foreach ($arr as $k => $v)
+ {
+ if (is_array($v))
+ {
+ $arr[$k] = strip_magic_quotes($v);
+ } else {
+ $arr[$k] = stripslashes($v);
+ }
+ }
+ return $arr;
+}
+
+if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
+{
+ if (!empty($_GET)) {
+ $_GET = strip_magic_quotes($_GET);
+ }
+ if (!empty($_POST)) {
+ $_POST = strip_magic_quotes($_POST);
+ }
+ if (!empty($_COOKIE)) {
+ $_COOKIE = strip_magic_quotes($_COOKIE);
+ }
+}
+
+
+function get_langfolder_list()
+{
+ //do not access db for speed up, or for flexibility
+ return array("en", "chs", "cht", "ko", "ja");
+}
+
+function printLine($line, $exist = false)
+{
+ echo "[" . date('Y-m-d H:i:s') . "] $line';
+ array_map(function ($var) {
+ var_dump($var);
+ }, func_get_args());
+ echo '';
+ exit(0);
+}
+
+function do_log($log)
+{
+ global $TWEAK;
+ if (!empty($TWEAK['logging'])) {
+ $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
+ $content = sprintf(
+ "[%s] %s:%s %s%s%s %s%s",
+ date('Y-m-d H:i:s'),
+ $backtrace[0]['file'] ?? '',
+ $backtrace[0]['line'] ?? '',
+ $backtrace[1]['class'] ?? '',
+ $backtrace[1]['type'] ?? '',
+ $backtrace[1]['function'] ?? '',
+ $log,
+ PHP_EOL
+ );
+ file_put_contents($TWEAK['logging'], $content, FILE_APPEND);
+ }
+}
+
+/**
+ * get translation for given name
+ *
+ * @author xiaomlove
+ * @date 2021/1/11
+ * @param null $name
+ * @param null $prefix
+ * @return mixed|string
+ */
+function __($name = null, $prefix = null)
+{
+ static $i18n;
+ static $i18nWithoutPrefix;
+ $userLocale = get_langfolder_cookie();
+ $defaultLocale = 'en';
+ if (is_null($prefix)) {
+ //get prefix from scripe name
+ $prefix = basename($_SERVER['SCRIPT_NAME']);
+ $prefix = strstr($prefix, '.php', true);
+ }
+ if (is_null($i18n)) {
+ //get all in18 may be used, incldue user locale and default locale, and name in('_target', 'functions') (because they are common) or prefixed with given prefix
+ $sql = "select locale, name, translation from i18n where locale in (" . sqlesc($userLocale) . ", " . sqlesc($defaultLocale) . ") and (name in ('_target', 'functions') or name like '{$prefix}%')";
+ $result = sql_query($sql);
+ while ($row = mysql_fetch_assoc($result)) {
+ $i18n[$row['locale']][$row['name']] = $row['translation'];
+ $i18nWithoutPrefix[$row['locale']][substr($row['name'], strpos($row['name'], '.') + 1)] = $row['translation'];
+ }
+ }
+ if (is_null($name)) {
+ return $i18nWithoutPrefix[$userLocale] ?? $i18nWithoutPrefix[$defaultLocale] ?? [];
+ }
+ $name = "$prefix.$name";
+ return $i18n[$userLocale][$name] ?? $i18n[$defaultLocale][$name] ?? '';
+
+}
+
+function config($key, $default = null)
+{
+ global $rootpath;
+ static $configs;
+ if (is_null($configs)) {
+ //get all configuration from config file
+ $files = glob($rootpath . 'config/*.php');
+ foreach ($files as $file) {
+ $basename = basename($file);
+ if ($basename == 'allconfig.php') {
+ //exclude the NexusPHP default config file
+ continue;
+ }
+ $values = require $file;
+ $configPrefix = strstr($basename, '.php', true);
+ $configs[$configPrefix] = $values;
+ }
+ }
+ return arr_get($configs, $key, $default);
+}
+
+/**
+ * get setting for given name and prefix
+ *
+ * $name == null and $prefix == null, return all
+ * $name == null and $prefix != null, return with specified prefix, but the result's prefix will be stripped
+ *
+ * @author xiaomlove
+ * @date 2021/1/11
+ * @param null $name
+ * @param null $prefix
+ * @return array|mixed|string
+ */
+function get_setting($name = null, $prefix = null)
+{
+ static $settings;
+ if (is_null($settings)) {
+ //get all settings from database
+ $sql = "select config_name, config_value from configs";
+ $result = sql_query($sql);
+ while ($row = mysql_fetch_assoc($result)) {
+ $value = $row['config_value'];
+ $arr = json_decode($value, true);
+ if (is_array($arr)) {
+ $value = $arr;
+ }
+ $settings[$row['config_name']] = $value;
+ }
+
+ }
+ if (!is_null($name)) {
+ if (!is_null($prefix)) {
+ $name = "$prefix.$name";
+ }
+ return $settings[$name] ?? null;
+ }
+ if (is_null($prefix)) {
+ return $settings;
+ }
+ $filtered = [];
+ foreach ($settings as $name => $value) {
+ if (preg_match("/^$prefix/", $name)) {
+ $nameWithoutPrefix = substr($name, strpos($name, '.') + 1);
+ $filtered[$nameWithoutPrefix] = $value;
+ }
+ }
+ return $filtered;
+
+}
+
+function env($key, $default = null)
+{
+ global $rootpath;
+ static $env;
+ if (is_null($env)) {
+ $envFile = $rootpath . '.env';
+ if (!file_exists($envFile)) {
+ throw new \RuntimeException(".env file is not exists in the root path.");
+ }
+ $fp = fopen($envFile, 'r');
+ if ($fp === false) {
+ throw new \RuntimeException(".env file: $envFile is not readable.");
+ }
+ while ($line = trim(fgets($fp))) {
+ if (empty($line)) {
+ continue;
+ }
+ $pos = strpos($line, '=');
+ if ($pos <= 0) {
+ continue;
+ }
+ if (mb_substr($line, 0, 1, 'utf-8') == '#') {
+ continue;
+ }
+ $lineKey = normalize_env(mb_substr($line, 0, $pos, 'utf-8'));
+ $lineValue = normalize_env(mb_substr($line, $pos + 1, null, 'utf-8'));
+ $env[$lineKey] = $lineValue;
+ }
+ }
+ return $env[$key] ?? $default;
+
+}
+
+function normalize_env($value)
+{
+ $value = trim($value);
+ $toStrip = ['\'', '"'];
+ if (in_array(mb_substr($value, 0, 1, 'utf-8'), $toStrip)) {
+ $value = mb_substr($value, 1, null, 'utf-8');
+ }
+ if (in_array(mb_substr($value, -1, null,'utf-8'), $toStrip)) {
+ $value = mb_substr($value, 0, -1, 'utf-8');
+ }
+ switch (strtolower($value)) {
+ case 'true':
+ return true;
+ case 'false':
+ return false;
+ case 'null':
+ return null;
+ default:
+ return $value;
+ }
+}
+
+function arr_get($array, $key, $default = null)
+{
+ if (strpos($key, '.') === false) {
+ return $array[$key] ?? $default;
+ }
+ foreach (explode('.', $key) as $segment) {
+ if (isset($array[$segment])) {
+ $array = $array[$segment];
+ } else {
+ return $default;
+ }
+ }
+ return $array;
+}
?>
diff --git a/invite.php b/invite.php
index f26f199a..3e66bbbb 100644
--- a/invite.php
+++ b/invite.php
@@ -9,7 +9,7 @@ $type = unesc($_GET["type"] ?? '');
registration_check('invitesystem',true,false);
-if (($CURUSER[id] != $id && get_user_class() < $viewinvite_class) || !is_valid_id($id))
+if (($CURUSER['id'] != $id && get_user_class() < $viewinvite_class) || !is_valid_id($id))
stderr($lang_invite['std_sorry'],$lang_invite['std_permission_denied']);
if (get_user_class() < $sendinvite_class)
stderr($lang_invite['std_sorry'],$lang_invite['std_only'].get_user_class_name($sendinvite_class,false,true,true).$lang_invite['std_or_above_can_invite'],false);
@@ -19,7 +19,7 @@ stdhead($lang_invite['head_invites']);
print("");
print("".$user['username'].$lang_invite['text_invite_system'].""); - $sent = htmlspecialchars($_GET['sent']); + $sent = htmlspecialchars($_GET['sent'] ?? ''); if ($sent == 1){ $msg = $lang_invite['text_invite_code_sent']; print("".$msg." "); @@ -108,7 +108,7 @@ if ($type == 'new'){ } } - if ($CURUSER[id] == $id || get_user_class() >= UC_SYSOP) + if ($CURUSER['id'] == $id || get_user_class() >= UC_SYSOP) { $pendingcount = number_format(get_row_count("users", "WHERE status='pending' AND invited_by=$CURUSER[id]")); @@ -117,7 +117,7 @@ if ($type == 'new'){ print(" | ||||||