fix: fix even more PHP errors and warnings

This commit is contained in:
Emmanuel BENOîT 2024-12-31 13:43:31 +01:00
parent 077f97d5fc
commit 7debdba37c
Signed by: Emmanuel BENOîT
SSH key fingerprint: SHA256:l7PFUUF5TCDsvYeQC9OnTNz08dFY7Fvf4Hv3neIqYpg
28 changed files with 80 additions and 72 deletions
scripts/site

View file

@ -10,7 +10,7 @@ class page_handler {
public function getOverview() {
$overview = $this->game->action('getOverview', $_SESSION[game::sessName()]['player'],
getLanguage());
$result = array($_SESSION[game::sessName()]['ov_complete'] ? "1" : "0");
$result = array($_SESSION[game::sessName()]['ov_complete'] ?? false ? "1" : "0");
// Protection level
array_push($result, $overview['protection']);
@ -18,7 +18,7 @@ class page_handler {
// Communications overview
$data = $overview['comms'];
array_push($result, count($data['folders']['CUS']) . "#" . count($data['forums']['general'])
. "#" . count($data['forums']['alliance']) . "#" . $data['forums']['allianceID']);
. "#" . count($data['forums']['alliance']) . "#" . ($data['forums']['allianceID'] ?? ''));
// Messages in default folders
$dFld = array('IN', 'INT', 'OUT');
@ -75,7 +75,7 @@ class page_handler {
}
public function switchOvMode() {
$_SESSION[game::sessName()]['ov_complete'] = ! $_SESSION[game::sessName()]['ov_complete'];
$_SESSION[game::sessName()]['ov_complete'] = !( $_SESSION[game::sessName()]['ov_complete'] ?? false );
}
public function handle($input) {

View file

@ -2,17 +2,20 @@
class page_handler
{
var $needsAuth = true;
var $ajax = array();
private $mailError = null;
private $passError = null;
function checkMail($a) {
public $needsAuth = true;
public $ajax = array();
private static function checkMail($a) {
return preg_match(
'/^[A-Za-z0-9_\.\-\+]+@([A-Za-z0-9_\.\-\+]+)+\.[A-Za-z]{2,6}/',
'/^[A-Za-z0-9_\.\-\+]+@([A-Za-z0-9_\.\-\+]+)+\.[A-Za-z]{2,6}$/',
$a
);
}
function checkPassword($op, $np, $cp) {
private function checkPassword($op, $np, $cp) {
$q = dbQuery("SELECT password FROM account WHERE id=".$_SESSION['userid']);
if (!$q) {
$this->passError = 1;
@ -44,8 +47,7 @@ class page_handler
}
}
function checkFormData($input)
{
private function checkFormData($input) {
$pLang = array('fr', 'en');
if (in_array($input['lang'], $pLang))
prefs::set('main/language', $input['lang']);
@ -65,7 +67,7 @@ class page_handler
if (preg_match('/^[0-4]$/', $input['fs']))
prefs::set('main/font_size', $input['fs']);
if ($this->checkMail($input['mail']))
if (self::checkMail($input['mail']))
dbQuery("UPDATE account SET email='".$input['mail']."' WHERE id=".$_SESSION['userid']);
else
$this->mailError = preg_replace('/"/', '"', $input['mail']);
@ -91,7 +93,7 @@ class page_handler
$this->checkPassword($input['opass'], $input['npass'], $input['cpass']);
}
function handleQuit() {
private function handleQuit() {
if (gameAction('isFinished')) {
return;
}
@ -103,9 +105,9 @@ class page_handler
gameAction('setPlayerQuit', $pid);
}
function handle($input)
public function handle($input)
{
if (!is_null($input['quit']))
if (isset($input['quit']))
$this->handleQuit();
elseif ($input['col'] != "")
$this->checkFormData($input);

View file

@ -7,7 +7,8 @@ function thm_getHeaderData() {
$pi = $pLib->call('get', $player);
$newMsg = ($mLib->call('getNew', $player) > 0) ? 1 : 0;
return time() . "#{$pi['name']}#{$pi['cash']}#$newMsg#{$pi['alliance']}";
$alliance = $pi['alliance'] ?? '';
return time() . "#{$pi['name']}#{$pi['cash']}#$newMsg#$alliance";
}
function thm_getHeaderPList() {

View file

@ -71,7 +71,7 @@ $alliance = $game->getLib('beta5/alliance');
$player = $_SESSION[game::sessName()]['player'];
$pInfo = $players->call('get', $player);
if ($pInfo['aid']) {
if (isset($pInfo['aid'])) {
$privileges = $alliance->call('getPrivileges', $player);
$techTrade = ($privileges['tech_trade'] > 0);
} else {

View file

@ -22,10 +22,10 @@ class page_layout {
// Generate CSS and JS resources
$this->generateStylesheets($pg, $thm, $fs, $col);
if (is_null(handler::$h->customJS)) {
$this->generateJS($pg, $thm, $col, $lg, $tt, $fs);
} else {
if (isset(handler::$h->customJS)) {
$this->jsRes = handler::$h->customJS;
} else {
$this->generateJS($pg, $thm, $col, $lg, $tt, $fs);
}
if (!is_null($this->cssRes)) {
@ -37,7 +37,14 @@ class page_layout {
// Generate HTML body tag
echo "</head><body";
if (is_null(handler::$h->customJS)) {
if (isset(handler::$h->customJS)) {
if (!is_null(handler::$h->customJS['load'])) {
echo " onload='" . handler::$h->customJS['load'] . "'";
}
if (!is_null(handler::$h->customJS['unload'])) {
echo " onunload='" . handler::$h->customJS['unload'] ."'";
}
} else {
if (ajax::$init != "" || $tt) {
echo " onload='lwAutoInit();'";
}
@ -45,20 +52,13 @@ class page_layout {
echo " onunload='tt_Disable()'";
}
echo ">\n";
} else {
if (!is_null(handler::$h->customJS['load'])) {
echo " onload='" . handler::$h->customJS['load'] . "'";
}
if (!is_null(handler::$h->customJS['unload'])) {
echo " onunload='" . handler::$h->customJS['unload'] ."'";
}
}
// Load the header
if (is_null(handler::$h->customHeader)) {
$hdr = "header";
} else {
if (isset(handler::$h->customHeader)) {
$hdr = handler::$h->customHeader;
} else {
$hdr = "header";
}
$this->includeFile("{$this->dir}/layout/$thm/$hdr.$lg.inc");
}
@ -69,15 +69,15 @@ class page_layout {
$col = prefs::get('main/colour', 'purple');
$thm = prefs::get('beta5/theme', "default");
if (is_null(handler::$h->customFooter)) {
$ftr = "footer";
} else {
if (isset(handler::$h->customFooter)) {
$ftr = handler::$h->customFooter;
} else {
$ftr = "footer";
}
$this->includeFile("{$this->dir}/layout/$thm/$ftr.$lg.inc");
// Tooltips
if ($tt && is_null(handler::$h->customJS)) {
if ($tt && !isset(handler::$h->customJS)) {
echo "<div id='ttPlaceHolderReserved'></div>";
$f = getStatic("beta5/js/tt_{$thm}_$col.js");
if (!is_null($f)) {

View file

@ -104,7 +104,7 @@ class page_handler {
tracking::$data['readDisclaimer'] = true;
$this->output = "disclaimer";
$this->data = true;
} elseif (tracking::$data['bat']) {
} elseif (isset(tracking::$data['bat'])) {
$this->output = "kicked";
} elseif ($input['create'] == "") {
$this->output = "create";