fix: apply various PHP (5.3 -> 8.3 lol) fixes

This commit is contained in:
Emmanuel BENOîT 2024-12-30 22:50:47 +01:00
parent b9d217eb5f
commit b18b795ab3
Signed by: Emmanuel BENOîT
SSH key fingerprint: SHA256:l7PFUUF5TCDsvYeQC9OnTNz08dFY7Fvf4Hv3neIqYpg
9 changed files with 60 additions and 67 deletions

View file

@ -16,7 +16,12 @@ function dbConnect($fatal = true) {
$rv = db::$database->open(); $rv = db::$database->open();
} }
if ($fatal && !$rv) { if ($fatal && !$rv) {
l::fatal(1, array("SQL: Database connection failed", pg_last_error())); try {
$lastError = pg_last_error();
} catch (Error) {
$lastError = "(no connection)";
}
l::fatal(1, array("SQL: Database connection failed", $lastError));
} }
return $rv; return $rv;
} }

View file

@ -266,7 +266,7 @@ class db {
pg_free_result($r); pg_free_result($r);
$tn = $match[1]; $tn = $match[1];
if ($tn{0} == '"') { if ($tn[0] == '"') {
$tn = str_replace('"', '', $tn); $tn = str_replace('"', '', $tn);
} else { } else {
$tn = strtolower($tn); $tn = strtolower($tn);

View file

@ -15,7 +15,7 @@ class engine {
* A fatal error is displayed if the engine isn't found in the engines/ * A fatal error is displayed if the engine isn't found in the engines/
* subdirectory of the script directory. * subdirectory of the script directory.
*/ */
function load() { public static function load() {
$eType = input::$eType; $eType = input::$eType;
// Check for a valid type // Check for a valid type

View file

@ -41,7 +41,7 @@ class game {
function addTick($tick) { function addTick($tick) {
$td = $tick->definition->script; $td = $tick->definition->script;
if (is_null($this->ticks[$td])) { if (!isset($this->ticks[$td])) {
$this->ticks[$td] = $tick; $this->ticks[$td] = $tick;
} }
} }

View file

@ -12,7 +12,7 @@ class handler {
* version and page. If such a handler is found, the file is loaded and the * version and page. If such a handler is found, the file is loaded and the
* handler is initialized. * handler is initialized.
*/ */
function load() { public static function load() {
$path = input::$path; $path = input::$path;
$page = input::$page; $page = input::$page;
$game = input::$game; $game = input::$game;
@ -53,10 +53,10 @@ class handler {
$engines = array('page', 'css', 'js', 'rpc'); $engines = array('page', 'css', 'js', 'rpc');
} }
// Get the default engine // Get the default engine
if (is_null($handler->defaultEngine)) { if (isset($handler->defaultEngine)) {
$dEngine = $engines[0];
} else {
$dEngine = $handler->defaultEngine; $dEngine = $handler->defaultEngine;
} else {
$dEngine = $engines[0];
} }
// Set the engine type to default if it isn't set // Set the engine type to default if it isn't set

View file

@ -21,7 +21,7 @@ class input {
* accessed, and which page should be displayed. * accessed, and which page should be displayed.
*/ */
static function identify() { static function identify() {
$p = $_SERVER["PATH_INFO"]; $p = $_SERVER["PATH_INFO"] ?? "";
if (preg_match('/\.[a-z0-9]{2,10}$/', $p)) { if (preg_match('/\.[a-z0-9]{2,10}$/', $p)) {
input::$eType = preg_replace('/^.*\.([a-z0-9]{2,10})$/', '\1', $p); input::$eType = preg_replace('/^.*\.([a-z0-9]{2,10})$/', '\1', $p);
@ -87,7 +87,7 @@ class input {
* quotes" are enabled, remove them. * quotes" are enabled, remove them.
* NOTE: This behaviour should be reversed in a production version. * NOTE: This behaviour should be reversed in a production version.
*/ */
function read() { static function read() {
input::$IE = preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT']) input::$IE = preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])
&& !preg_match('/Opera/', $_SERVER['HTTP_USER_AGENT']); && !preg_match('/Opera/', $_SERVER['HTTP_USER_AGENT']);
input::$safari = preg_match('/AppleWebKit/', $_SERVER['HTTP_USER_AGENT']); input::$safari = preg_match('/AppleWebKit/', $_SERVER['HTTP_USER_AGENT']);
@ -99,18 +99,6 @@ class input {
foreach ($_GET as $k => $v) { foreach ($_GET as $k => $v) {
$p[$k] = $v; $p[$k] = $v;
} }
if (get_magic_quotes_gpc()) {
foreach ($p as $k => $v) {
if (is_scalar($v)) {
$p[$k] = stripslashes($v);
} elseif (is_array($v)) {
$p[$k] = array();
foreach ($v as $ak => $av) {
$p[$k][$ak] = stripslashes($av);
}
}
}
}
input::$input = $p; input::$input = $p;
return $p; return $p;
} }

View file

@ -82,7 +82,7 @@ class l {
/** This function is the default fatal error display function. */ /** This function is the default fatal error display function. */
private function defaultFatalError($errno, $error, $info) { private static function defaultFatalError($errno, $error, $info) {
ob_start(); ob_start();
?> ?>
<html> <html>
@ -113,7 +113,6 @@ class l {
return; return;
} }
define_syslog_variables();
openlog(self::$syslogPrefix, LOG_PID, LOG_USER); openlog(self::$syslogPrefix, LOG_PID, LOG_USER);
self::$initialised = true; self::$initialised = true;
} }
@ -142,7 +141,7 @@ class l {
/** This method displays one of the game engine's /** This method displays one of the game engine's
* fatal errors and adds log entries accordingly. * fatal errors and adds log entries accordingly.
*/ */
public function fatal($errno, $information = null) { public static function fatal($errno, $information = null) {
// Log the error // Log the error
$errorText = self::$engineErrors[$errno] . " [" . sprintf("%03d", $errno) . "]"; $errorText = self::$engineErrors[$errno] . " [" . sprintf("%03d", $errno) . "]";
self::critical($errorText); self::critical($errorText);
@ -183,17 +182,18 @@ class l {
/** This method writes a backtrace to the log, removing all /** This method writes a backtrace to the log, removing all
* entries from the logging class. * entries from the logging class.
*/ */
public function backtrace() { public static function backtrace() {
$bt = debug_backtrace(); $bt = debug_backtrace();
while (is_array($bt[1]) && $bt[1]['class'] == 'l') { while (is_array($bt[1]) && isset($bt[1]['class']) && $bt[1]['class'] == 'l') {
array_shift($bt); array_shift($bt);
} }
self::info("Backtrace to the error:"); self::info("Backtrace to the error:");
$base = dirname(config::$main['scriptdir']); $base = dirname(config::$main['scriptdir']);
foreach ($bt as $data) { foreach ($bt as $data) {
$cnLength = strlen($data['class']); $class = $data['class'] ?? '';
$str = "... " . str_repeat(' ', $cnLength > 30 ? 1 : (31 - $cnLength)) . $data['class'] $cnLength = strlen($class);
$str = "... " . str_repeat(' ', $cnLength > 30 ? 1 : (31 - $cnLength)) . $class
. " :: " . $data['function']; . " :: " . $data['function'];
if (!is_null($data['file'])) { if (!is_null($data['file'])) {
$cnLength = strlen($data['function']); $cnLength = strlen($data['function']);
@ -208,7 +208,7 @@ class l {
/** This method changes the syslog prefix. /** This method changes the syslog prefix.
*/ */
public function setSyslogPrefix($prefix) { public static function setSyslogPrefix($prefix) {
self::$syslogPrefix = $prefix; self::$syslogPrefix = $prefix;
if (self::$initialised) { if (self::$initialised) {
closelog(); closelog();
@ -218,14 +218,14 @@ class l {
/** This method changes the string prefix. /** This method changes the string prefix.
*/ */
public function setPrefix($prefix) { public static function setPrefix($prefix) {
self::$prefix = "$prefix "; self::$prefix = "$prefix ";
} }
/** This method changes the function to call /** This method changes the function to call
* for fatal errors. * for fatal errors.
*/ */
public function setFatalHandler($function) { public static function setFatalHandler($function) {
self::$fatalErrorCallback = $function; self::$fatalErrorCallback = $function;
} }
@ -233,7 +233,7 @@ class l {
* function call and prevents further logging of * function call and prevents further logging of
* similar occurences. * similar occurences.
*/ */
public function deprecated($function) { public static function deprecated($function) {
if (config::$main['debug'] == 2 && !self::$deprecatedLogged) { if (config::$main['debug'] == 2 && !self::$deprecatedLogged) {
l::trace("DEPRECATED: $function"); l::trace("DEPRECATED: $function");
l::backtrace(); l::backtrace();
@ -242,7 +242,7 @@ class l {
} }
/** This function logs FIXME's. */ /** This function logs FIXME's. */
public function FIXME($text) { public static function FIXME($text) {
if (config::$main['debug'] >= 1 && !self::$fixmeLogged) { if (config::$main['debug'] >= 1 && !self::$fixmeLogged) {
l::debug("FIXME: $text"); l::debug("FIXME: $text");
if (config::$main['debug'] == 2) { if (config::$main['debug'] == 2) {
@ -256,19 +256,19 @@ class l {
/******************* LOGGING METHODS ************************/ /******************* LOGGING METHODS ************************/
/* These methods should replace logText() wherever possible */ /* These methods should replace logText() wherever possible */
/************************************************************/ /************************************************************/
public function crit($txt) { self::init(); self::__write($txt, LOG_CRIT); } public static function crit($txt) { self::init(); self::__write($txt, LOG_CRIT); }
public function critical($txt) { self::init(); self::__write($txt, LOG_CRIT); } public static function critical($txt) { self::init(); self::__write($txt, LOG_CRIT); }
public function error($txt) { self::init(); self::__write($txt, LOG_ERR); } public static function error($txt) { self::init(); self::__write($txt, LOG_ERR); }
public function warn($txt) { self::init(); self::__write($txt, LOG_WARNING); } public static function warn($txt) { self::init(); self::__write($txt, LOG_WARNING); }
public function warning($txt) { self::init(); self::__write($txt, LOG_WARNING); } public static function warning($txt) { self::init(); self::__write($txt, LOG_WARNING); }
public function notice($txt) { self::init(); self::__write($txt, LOG_NOTICE); } public static function notice($txt) { self::init(); self::__write($txt, LOG_NOTICE); }
public function info($txt) { self::init(); self::__write($txt, LOG_INFO); } public static function info($txt) { self::init(); self::__write($txt, LOG_INFO); }
public function debug($txt) { public static function debug($txt) {
if (config::$main['debug'] >= 1) { if (config::$main['debug'] >= 1) {
self::init(); self::__write($txt, LOG_DEBUG); self::init(); self::__write($txt, LOG_DEBUG);
} }
} }
public function trace($txt) { public static function trace($txt) {
if (config::$main['debug'] == 2) { if (config::$main['debug'] == 2) {
self::init(); self::__write($txt, LOG_DEBUG); self::init(); self::__write($txt, LOG_DEBUG);
} }

View file

@ -14,13 +14,13 @@ class version {
} }
function addTickDefinition($def) { function addTickDefinition($def) {
if (is_null($this->tickDefs[$def->script])) { if (!isset($this->tickDefs[$def->script])) {
$this->tickDefs[$def->script] = $def; $this->tickDefs[$def->script] = $def;
} }
} }
function getTickDefinition($id) { function getTickDefinition($id) {
return $this->tickDefs[$id]; return $this->tickDefs[$id] ?? null;
} }
function getDirectory() { function getDirectory() {

View file

@ -12,7 +12,7 @@ class xml_config {
private static $games = null; private static $games = null;
private static $defGame = null; private static $defGame = null;
private function parseMainParams($root) { private static function parseMainParams($root) {
$node = $root->firstChild; $node = $root->firstChild;
while ($node) { while ($node) {
@ -21,7 +21,7 @@ class xml_config {
$aValue = $node->getAttribute('value'); $aValue = $node->getAttribute('value');
if ($aName == "") { if ($aName == "") {
l::warn("CONFIG: a main parameter is missing a 'name' attribute"); l::warn("CONFIG: a main parameter is missing a 'name' attribute");
} elseif (is_null(xml_config::$mGame->params[$aName])) { } elseif (!isset(xml_config::$mGame->params[$aName])) {
xml_config::$mGame->params[$aName] = $aValue; xml_config::$mGame->params[$aName] = $aValue;
} else { } else {
l::notice("CONFIG: duplicate main parameter '$aName'"); l::notice("CONFIG: duplicate main parameter '$aName'");
@ -34,7 +34,7 @@ class xml_config {
} }
private function parseMainTicks($root) { private static function parseMainTicks($root) {
$node = $root->firstChild; $node = $root->firstChild;
while ($node) { while ($node) {
@ -62,7 +62,7 @@ class xml_config {
} }
private function parseTickDefinition($version, $root) { private static function parseTickDefinition($version, $root) {
$script = $root->getAttribute('script'); $script = $root->getAttribute('script');
$public = ($root->getAttribute('public') == 1); $public = ($root->getAttribute('public') == 1);
@ -127,7 +127,7 @@ class xml_config {
} }
private function parseVersion($root) { private static function parseVersion($root) {
$id = $root->getAttribute("id"); $id = $root->getAttribute("id");
$cp = ($root->getAttribute("playable") == 1); $cp = ($root->getAttribute("playable") == 1);
$tx = $root->getAttribute("text"); $tx = $root->getAttribute("text");
@ -156,7 +156,7 @@ class xml_config {
} }
private function parseVersions($root) { private static function parseVersions($root) {
$node = $root->firstChild; $node = $root->firstChild;
$versions = array(); $versions = array();
@ -164,10 +164,10 @@ class xml_config {
if ($node->nodeType == XML_ELEMENT_NODE && $node->nodeName == 'Version') { if ($node->nodeType == XML_ELEMENT_NODE && $node->nodeName == 'Version') {
$v = xml_config::parseVersion($node); $v = xml_config::parseVersion($node);
if (!is_null($v)) { if (!is_null($v)) {
if (is_null($versions[$v->id])) { if (isset($versions[$v->id])) {
$versions[$v->id] = $v;
} else {
l::notice("CONFIG: found duplicate definition for version '{$v->id}'"); l::notice("CONFIG: found duplicate definition for version '{$v->id}'");
} else {
$versions[$v->id] = $v;
} }
} }
} elseif ($node->nodeType == XML_ELEMENT_NODE) { } elseif ($node->nodeType == XML_ELEMENT_NODE) {
@ -180,7 +180,7 @@ class xml_config {
} }
private function parseGame($root) { private static function parseGame($root) {
$id = $root->getAttribute('id'); $id = $root->getAttribute('id');
if ($id == '') { if ($id == '') {
l::warn("CONFIG: game definition is missing an identifier"); l::warn("CONFIG: game definition is missing an identifier");
@ -225,10 +225,10 @@ class xml_config {
$aValue = $node->getAttribute('value'); $aValue = $node->getAttribute('value');
if ($aName == "") { if ($aName == "") {
l::warn("CONFIG: a parameter is missing a 'name' attribute for game '$id'"); l::warn("CONFIG: a parameter is missing a 'name' attribute for game '$id'");
} elseif (is_null($game->params[$aName])) { } elseif (isset($game->params[$aName])) {
$game->params[$aName] = $aValue;
} else {
l::notice("CONFIG: duplicate parameter '$aName'"); l::notice("CONFIG: duplicate parameter '$aName'");
} else {
$game->params[$aName] = $aValue;
} }
} elseif ($node->nodeName == 'Description') { } elseif ($node->nodeName == 'Description') {
$lang = $node->getAttribute('lang'); $lang = $node->getAttribute('lang');
@ -237,7 +237,7 @@ class xml_config {
l::warn("CONFIG: a description is missing the 'lang' attribute for game '$id'"); l::warn("CONFIG: a description is missing the 'lang' attribute for game '$id'");
} elseif ($contents == "") { } elseif ($contents == "") {
l::warn("CONFIG: description in language '$lang' has no contents for game '$id'"); l::warn("CONFIG: description in language '$lang' has no contents for game '$id'");
} elseif (!is_null($game->descriptions[$lang])) { } elseif (isset($game->descriptions[$lang])) {
l::notice("CONFIG: description in language '$lang' appears twice for game '$id'"); l::notice("CONFIG: description in language '$lang' appears twice for game '$id'");
} else { } else {
$game->descriptions[$lang] = $contents; $game->descriptions[$lang] = $contents;
@ -255,11 +255,11 @@ class xml_config {
} elseif (is_null($game->version->getTickDefinition($tScript))) { } elseif (is_null($game->version->getTickDefinition($tScript))) {
l::warn("CONFIG: no definition for tick '$tScript' in game '$id' " l::warn("CONFIG: no definition for tick '$tScript' in game '$id' "
. "(version '$version')"); . "(version '$version')");
} elseif (is_null($game->ticks[$tScript])) { } elseif (isset($game->ticks[$tScript])) {
l::notice("CONFIG: duplicate tick initialiser for tick '$tScript' in game '$id'");
} else {
new tick_instance($game, $tScript, (int)$tFirst, (int)$tInterval, new tick_instance($game, $tScript, (int)$tFirst, (int)$tInterval,
$tLast ? (int)$tLast : null); $tLast ? (int)$tLast : null);
} else {
l::notice("CONFIG: duplicate tick initialiser for tick '$tScript' in game '$id'");
} }
} else { } else {
l::notice("CONFIG: found unexpected tag '{$node->nodeName}' in game '$id' definition"); l::notice("CONFIG: found unexpected tag '{$node->nodeName}' in game '$id' definition");
@ -272,7 +272,7 @@ class xml_config {
} }
private function parseGames($root) { private static function parseGames($root) {
$defaultId = $root->getAttribute('default'); $defaultId = $root->getAttribute('default');
$games = array(); $games = array();
@ -281,10 +281,10 @@ class xml_config {
if ($node->nodeType == XML_ELEMENT_NODE && $node->nodeName == 'Game') { if ($node->nodeType == XML_ELEMENT_NODE && $node->nodeName == 'Game') {
$g = xml_config::parseGame($node); $g = xml_config::parseGame($node);
if (!is_null($g)) { if (!is_null($g)) {
if (is_null($games[$g->name])) { if (isset($games[$g->name])) {
$games[$g->name] = $g;
} else {
l::notice("CONFIG: found duplicate definition for game '{$v->name}'"); l::notice("CONFIG: found duplicate definition for game '{$v->name}'");
} else {
$games[$g->name] = $g;
} }
} }
} elseif ($node->nodeType == XML_ELEMENT_NODE) { } elseif ($node->nodeType == XML_ELEMENT_NODE) {
@ -303,7 +303,7 @@ class xml_config {
} }
function parse($xmlData) { public static function parse($xmlData) {
$doc = new DOMDocument(); $doc = new DOMDocument();
if (!$doc->loadXML($xmlData)) { if (!$doc->loadXML($xmlData)) {
l::error("CONFIG: error while parsing XML configuration"); l::error("CONFIG: error while parsing XML configuration");