mirror of
https://github.com/kleeja-official/kleeja.git
synced 2025-12-16 04:59:42 +01:00
Add PHP 8.5 support
Updated calls to resource cleanup functions (curl_close, imagedestroy, finfo_close) to only execute for PHP versions below 8.0, as these functions have no effect in PHP 8+. Improved error handling and connection management in mysqli and sqlite drivers, and added missing DOCTYPE in error output for better HTML compliance.
This commit is contained in:
@@ -131,7 +131,12 @@ class FetchFile
|
|||||||
kleeja_log(sprintf("cUrl error (#%d): %s\n", curl_errno($ch), htmlspecialchars(curl_error($ch))));
|
kleeja_log(sprintf("cUrl error (#%d): %s\n", curl_errno($ch), htmlspecialchars(curl_error($ch))));
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_close($ch);
|
// curl_close() has no effect since PHP 8.0
|
||||||
|
// Only call it for PHP < 8.0 where it actually closes the handle
|
||||||
|
if (PHP_VERSION_ID < 80000)
|
||||||
|
{
|
||||||
|
curl_close($ch);
|
||||||
|
}
|
||||||
fclose($out);
|
fclose($out);
|
||||||
|
|
||||||
return isset($error) ? false : true;
|
return isset($error) ? false : true;
|
||||||
@@ -146,7 +151,12 @@ class FetchFile
|
|||||||
kleeja_log(sprintf("FetchFile error (curl: #%d): %s\n", curl_errno($ch), htmlspecialchars(curl_error($ch))));
|
kleeja_log(sprintf("FetchFile error (curl: #%d): %s\n", curl_errno($ch), htmlspecialchars(curl_error($ch))));
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_close($ch);
|
// curl_close() has no effect since PHP 8.0
|
||||||
|
// Only call it for PHP < 8.0 where it actually closes the handle
|
||||||
|
if (PHP_VERSION_ID < 80000)
|
||||||
|
{
|
||||||
|
curl_close($ch);
|
||||||
|
}
|
||||||
|
|
||||||
return isset($error) ? false : $data;
|
return isset($error) ? false : $data;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,7 +101,12 @@ function kleeja_cpatcha_image()
|
|||||||
imagepng($image);
|
imagepng($image);
|
||||||
|
|
||||||
//Free up resources
|
//Free up resources
|
||||||
imagedestroy($image);
|
// imagedestroy() has no effect since PHP 8.0
|
||||||
|
// Only call it for PHP < 8.0 where it actually frees memory
|
||||||
|
if (PHP_VERSION_ID < 80000)
|
||||||
|
{
|
||||||
|
imagedestroy($image);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//<--- EOF
|
//<--- EOF
|
||||||
|
|||||||
@@ -66,9 +66,15 @@ error_reporting(defined('DEV_STAGE') ? E_ALL : E_ALL ^ E_NOTICE);
|
|||||||
*/
|
*/
|
||||||
function kleeja_show_error($error_number, $error_string = '', $error_file = '', $error_line = '')
|
function kleeja_show_error($error_number, $error_string = '', $error_file = '', $error_line = '')
|
||||||
{
|
{
|
||||||
|
// Check if error reporting is disabled (happens with @ operator)
|
||||||
|
if (!(error_reporting() & $error_number))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
switch ($error_number)
|
switch ($error_number)
|
||||||
{
|
{
|
||||||
case E_NOTICE: case E_WARNING: case E_USER_WARNING: case E_USER_NOTICE: case E_STRICT:
|
case E_NOTICE: case E_WARNING: case E_USER_WARNING: case E_USER_NOTICE: case 2048: // E_STRICT (deprecated in PHP 8.4, using numeric value for compatibility)
|
||||||
if (function_exists('kleeja_log'))
|
if (function_exists('kleeja_log'))
|
||||||
{
|
{
|
||||||
$error_name = [
|
$error_name = [
|
||||||
@@ -81,6 +87,7 @@ function kleeja_show_error($error_number, $error_string = '', $error_file = '',
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
header('HTTP/1.1 503 Service Temporarily Unavailable');
|
header('HTTP/1.1 503 Service Temporarily Unavailable');
|
||||||
|
echo '<!DOCTYPE html>' . "\n";
|
||||||
echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">' . "\n<head>\n";
|
echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">' . "\n<head>\n";
|
||||||
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' . "\n";
|
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' . "\n";
|
||||||
echo '<title>Kleeja Error</title>' . "\n" . '<style type="text/css">' . "\n\t";
|
echo '<title>Kleeja Error</title>' . "\n" . '<style type="text/css">' . "\n\t";
|
||||||
|
|||||||
@@ -335,6 +335,7 @@ function kleeja_debug()
|
|||||||
function big_error($error_title, $msg_text, $error = true)
|
function big_error($error_title, $msg_text, $error = true)
|
||||||
{
|
{
|
||||||
global $SQL;
|
global $SQL;
|
||||||
|
echo '<!DOCTYPE html>' . "\n";
|
||||||
echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">' . "\n";
|
echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">' . "\n";
|
||||||
echo '<head>' . "\n";
|
echo '<head>' . "\n";
|
||||||
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' . "\n";
|
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' . "\n";
|
||||||
|
|||||||
@@ -94,10 +94,9 @@ if (! defined('SQL_LAYER')):
|
|||||||
|
|
||||||
public function is_connected()
|
public function is_connected()
|
||||||
{
|
{
|
||||||
return ! (is_resource($this->connect_id) || empty($this->connect_id));
|
return is_object($this->connect_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// close the connection
|
|
||||||
public function close()
|
public function close()
|
||||||
{
|
{
|
||||||
if (! $this->is_connected())
|
if (! $this->is_connected())
|
||||||
@@ -114,12 +113,16 @@ if (! defined('SQL_LAYER')):
|
|||||||
//loggin -> close connection
|
//loggin -> close connection
|
||||||
kleeja_log('[Closing connection] : ' . kleeja_get_page());
|
kleeja_log('[Closing connection] : ' . kleeja_get_page());
|
||||||
|
|
||||||
if (! is_resource($this->connect_id))
|
// Close the mysqli connection only once.
|
||||||
|
// After closing, reset $this->connect_id so subsequent calls are no-ops.
|
||||||
|
$result = @mysqli_close($this->connect_id);
|
||||||
|
|
||||||
|
if ($result)
|
||||||
{
|
{
|
||||||
return true;
|
$this->connect_id = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return @mysqli_close($this->connect_id);
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// encoding functions
|
// encoding functions
|
||||||
@@ -130,11 +133,21 @@ if (! defined('SQL_LAYER')):
|
|||||||
|
|
||||||
public function set_names($charset)
|
public function set_names($charset)
|
||||||
{
|
{
|
||||||
|
if (! $this->is_connected())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@mysqli_set_charset($this->connect_id, $charset);
|
@mysqli_set_charset($this->connect_id, $charset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function client_encoding()
|
public function client_encoding()
|
||||||
{
|
{
|
||||||
|
if (! $this->is_connected())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return mysqli_character_set_name($this->connect_id);
|
return mysqli_character_set_name($this->connect_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ if (! defined('SQL_LAYER')):
|
|||||||
|
|
||||||
public function is_connected()
|
public function is_connected()
|
||||||
{
|
{
|
||||||
return ! (is_null($this->connect_id) || empty($this->connect_id));
|
return is_object($this->connect_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// close the connection
|
// close the connection
|
||||||
@@ -111,12 +111,16 @@ if (! defined('SQL_LAYER')):
|
|||||||
//loggin -> close connection
|
//loggin -> close connection
|
||||||
kleeja_log('[Closing connection] : ' . kleeja_get_page());
|
kleeja_log('[Closing connection] : ' . kleeja_get_page());
|
||||||
|
|
||||||
if (! is_resource($this->connect_id))
|
// Close the SQLite3 connection only once.
|
||||||
|
// After closing, reset $this->connect_id so subsequent calls are no-ops.
|
||||||
|
$result = @$this->connect_id->close();
|
||||||
|
|
||||||
|
if ($result)
|
||||||
{
|
{
|
||||||
return true;
|
$this->connect_id = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return @mysqli_close($this->connect_id);
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// encoding functions
|
// encoding functions
|
||||||
|
|||||||
@@ -226,7 +226,12 @@ function check_mime_type($given_file_mime, $file_ext, $file_path)
|
|||||||
{
|
{
|
||||||
$f_info = finfo_open(FILEINFO_MIME_TYPE);
|
$f_info = finfo_open(FILEINFO_MIME_TYPE);
|
||||||
$mime = finfo_file($f_info, $file_path);
|
$mime = finfo_file($f_info, $file_path);
|
||||||
finfo_close($f_info);
|
// finfo_close() has no effect since PHP 8.0
|
||||||
|
// Only call it for PHP < 8.0 where it actually closes the resource
|
||||||
|
if (PHP_VERSION_ID < 80000)
|
||||||
|
{
|
||||||
|
finfo_close($f_info);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif (! empty($given_file_mime))
|
elseif (! empty($given_file_mime))
|
||||||
|
|||||||
@@ -178,8 +178,13 @@ function helper_thumb($source_path, $ext, $dest_image, $dw, $dh)
|
|||||||
$return = false;
|
$return = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@imagedestroy($desired_gdim);
|
// imagedestroy() has no effect since PHP 8.0
|
||||||
@imagedestroy($source_gdim);
|
// Only call it for PHP < 8.0 where it actually frees memory
|
||||||
|
if (PHP_VERSION_ID < 80000)
|
||||||
|
{
|
||||||
|
imagedestroy($desired_gdim);
|
||||||
|
imagedestroy($source_gdim);
|
||||||
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user