mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
fix compatibility with php72
This commit is contained in:
@@ -19,7 +19,7 @@ class RedisCache {
|
|||||||
public $redis;
|
public $redis;
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
$success = $this->createRedisClient(); // Connect to Redis
|
$success = $this->connect($host = 'localhost', $port = 6379); // Connect to Redis
|
||||||
if ($success) {
|
if ($success) {
|
||||||
$this->isEnabled = 1;
|
$this->isEnabled = 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -27,9 +27,9 @@ class RedisCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createRedisClient()
|
private function connect($host, $port)
|
||||||
{
|
{
|
||||||
global $BASIC;
|
global $BASIC, $TWEAK;
|
||||||
$redis = new Redis();
|
$redis = new Redis();
|
||||||
$params = [
|
$params = [
|
||||||
$BASIC['redis_host'],
|
$BASIC['redis_host'],
|
||||||
@@ -40,29 +40,26 @@ class RedisCache {
|
|||||||
if (!empty($BASIC['redis_timeout'])) {
|
if (!empty($BASIC['redis_timeout'])) {
|
||||||
$params[] = $BASIC['redis_timeout'];
|
$params[] = $BASIC['redis_timeout'];
|
||||||
}
|
}
|
||||||
$connectResult = $redis->connect(...$params);
|
try {
|
||||||
$auth = [];
|
$connectResult = $redis->connect(...$params);
|
||||||
if (!empty($BASIC['redis_password'])) {
|
$auth = [];
|
||||||
$auth['pass'] = $BASIC['redis_password'];
|
if (!empty($BASIC['redis_password'])) {
|
||||||
if (!empty($BASIC['redis_username'])) {
|
$auth['pass'] = $BASIC['redis_password'];
|
||||||
$auth['user'] = $BASIC['redis_username'];
|
if (!empty($BASIC['redis_username'])) {
|
||||||
|
$auth['user'] = $BASIC['redis_username'];
|
||||||
|
}
|
||||||
|
$connectResult = $connectResult && $redis->auth($auth);
|
||||||
}
|
}
|
||||||
$connectResult = $connectResult && $redis->auth($auth);
|
if ($connectResult) {
|
||||||
}
|
$this->redis = $redis;
|
||||||
if ($connectResult) {
|
if (is_numeric($BASIC['redis_database'])) {
|
||||||
if (is_numeric($BASIC['redis_database'])) {
|
$redis->select($BASIC['redis_database']);
|
||||||
$selectDatabaseResult = $redis->select($BASIC['redis_database']);
|
|
||||||
if (!$selectDatabaseResult) {
|
|
||||||
$msg = "select redis database: {$BASIC['redis_database']} fail";
|
|
||||||
write_log($msg);
|
|
||||||
throw new \RuntimeException($msg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->redis = $redis;
|
return $connectResult;
|
||||||
} else {
|
} catch (\Exception $exception) {
|
||||||
write_log(sprintf('connect to redis with params: %s , with auth: %s fail', json_encode($params), json_encode($auth)));
|
return false;
|
||||||
}
|
}
|
||||||
return $connectResult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getIsEnabled() {
|
function getIsEnabled() {
|
||||||
@@ -205,6 +202,9 @@ class RedisCache {
|
|||||||
|
|
||||||
// Wrapper for Memcache::set, with the zlib option removed and default duration of 1 hour
|
// Wrapper for Memcache::set, with the zlib option removed and default duration of 1 hour
|
||||||
function cache_value($Key, $Value, $Duration = 3600){
|
function cache_value($Key, $Value, $Duration = 3600){
|
||||||
|
if (!$this->getIsEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$Value = $this->serialize($Value);
|
$Value = $this->serialize($Value);
|
||||||
// $this->set($Key,$Value, 0, $Duration);
|
// $this->set($Key,$Value, 0, $Duration);
|
||||||
$this->redis->set($Key, $Value, $Duration);
|
$this->redis->set($Key, $Value, $Duration);
|
||||||
@@ -263,6 +263,9 @@ class RedisCache {
|
|||||||
|
|
||||||
// Wrapper for Memcache::get. Why? Because wrappers are cool.
|
// Wrapper for Memcache::get. Why? Because wrappers are cool.
|
||||||
function get_value($Key) {
|
function get_value($Key) {
|
||||||
|
if (!$this->getIsEnabled()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if($this->getClearCache()){
|
if($this->getClearCache()){
|
||||||
$this->delete_value($Key);
|
$this->delete_value($Key);
|
||||||
return false;
|
return false;
|
||||||
@@ -282,6 +285,9 @@ class RedisCache {
|
|||||||
|
|
||||||
// Wrapper for Memcache::delete. For a reason, see above.
|
// Wrapper for Memcache::delete. For a reason, see above.
|
||||||
function delete_value($Key, $AllLang = false){
|
function delete_value($Key, $AllLang = false){
|
||||||
|
if (!$this->getIsEnabled()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if ($AllLang){
|
if ($AllLang){
|
||||||
$langfolder_array = $this->getLanguageFolderArray();
|
$langfolder_array = $this->getLanguageFolderArray();
|
||||||
foreach($langfolder_array as $lf)
|
foreach($langfolder_array as $lf)
|
||||||
|
|||||||
+1
-1
@@ -474,7 +474,7 @@ if ($action == "viewtopic")
|
|||||||
|
|
||||||
$topicid = $_GET["topicid"] ?? 0;
|
$topicid = $_GET["topicid"] ?? 0;
|
||||||
int_check($topicid,true);
|
int_check($topicid,true);
|
||||||
$page = $_GET["page"] ?? '';
|
$page = $_GET["page"] ?? 0;
|
||||||
$authorid = $_GET["authorid"] ?? 0;
|
$authorid = $_GET["authorid"] ?? 0;
|
||||||
if ($authorid)
|
if ($authorid)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
class DB
|
class DB
|
||||||
{
|
{
|
||||||
private DBInterface $driver;
|
private $driver;
|
||||||
|
|
||||||
private static $instance;
|
private static $instance;
|
||||||
|
|
||||||
private static array $queries = [];
|
private static $queries = [];
|
||||||
|
|
||||||
private function __construct()
|
private function __construct()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
class DBMysqli implements DBInterface
|
class DBMysqli implements DBInterface
|
||||||
{
|
{
|
||||||
private mysqli $mysqli;
|
private $mysqli;
|
||||||
|
|
||||||
public function connect($host, $username, $password, $database, $port)
|
public function connect($host, $username, $password, $database, $port)
|
||||||
{
|
{
|
||||||
@@ -43,17 +43,17 @@ class DBMysqli implements DBInterface
|
|||||||
return $this->mysqli->select_db($database);
|
return $this->mysqli->select_db($database);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetchAssoc($mysqliResult): array|null
|
public function fetchAssoc($mysqliResult)
|
||||||
{
|
{
|
||||||
return $mysqliResult->fetch_assoc();
|
return $mysqliResult->fetch_assoc();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetchRow($mysqliResult): array|null
|
public function fetchRow($mysqliResult)
|
||||||
{
|
{
|
||||||
return $mysqliResult->fetch_row();
|
return $mysqliResult->fetch_row();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetchArray($mysqliResult, $type): array|null
|
public function fetchArray($mysqliResult, $type)
|
||||||
{
|
{
|
||||||
if (is_null($type)) {
|
if (is_null($type)) {
|
||||||
$type = MYSQLI_BOTH;
|
$type = MYSQLI_BOTH;
|
||||||
|
|||||||
@@ -14,11 +14,11 @@ interface DBInterface
|
|||||||
|
|
||||||
public function selectDb($database);
|
public function selectDb($database);
|
||||||
|
|
||||||
public function fetchAssoc($result): array|null;
|
public function fetchAssoc($result);
|
||||||
|
|
||||||
public function fetchRow($result): array|null;
|
public function fetchRow($result);
|
||||||
|
|
||||||
public function fetchArray($result, $type): array|null;
|
public function fetchArray($result, $type);
|
||||||
|
|
||||||
public function affectedRows(): int;
|
public function affectedRows(): int;
|
||||||
|
|
||||||
|
|||||||
@@ -300,12 +300,12 @@ if ($CURUSER && $showpolls_main == "yes")
|
|||||||
$os = array();
|
$os = array();
|
||||||
|
|
||||||
// Count votes
|
// Count votes
|
||||||
while (($arr2 = mysql_fetch_row($res) !== null) && isset($vs[$arr2[0]]))
|
while (($arr2 = mysql_fetch_row($res) !== null) && isset($arr2[0]) && isset($vs[$arr2[0]]))
|
||||||
$vs[$arr2[0]] ++;
|
$vs[$arr2[0]] ++;
|
||||||
|
|
||||||
reset($o);
|
reset($o);
|
||||||
for ($i = 0; $i < count($o); ++$i){
|
for ($i = 0; $i < count($o); ++$i){
|
||||||
if ($o[$i])
|
if (isset($vs[$i]) && isset($o[$i]) && $o[$i])
|
||||||
$os[$i] = array($vs[$i], $o[$i], $i);
|
$os[$i] = array($vs[$i], $o[$i], $i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user