From 4bb57380755c6f7b4589f4bab18be000958c6d79 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Thu, 4 Dec 2025 19:17:31 -0500 Subject: [PATCH] fix some longstanding bugs and stamp out deprecation warnings --- lib/phast/server/Parser/XMLParser.inc.php | 12 ++-- lib/phast/server/System.inc.php | 84 +++++++++++++---------- lib/phast/server/WebPage.inc.php | 40 ++++++----- 3 files changed, 80 insertions(+), 56 deletions(-) diff --git a/lib/phast/server/Parser/XMLParser.inc.php b/lib/phast/server/Parser/XMLParser.inc.php index bfe07a5..e139314 100644 --- a/lib/phast/server/Parser/XMLParser.inc.php +++ b/lib/phast/server/Parser/XMLParser.inc.php @@ -323,10 +323,10 @@ $this->resParser = \xml_parser_create (); \xml_parser_set_option($this->resParser, XML_OPTION_CASE_FOLDING, 0); - \xml_set_object($this->resParser, $this); - \xml_set_element_handler($this->resParser, "tagOpen", "tagClosed"); + // \xml_set_object($this->resParser, $this); + \xml_set_element_handler($this->resParser, $this->tagOpen(...), $this->tagClosed(...)); - \xml_set_character_data_handler($this->resParser, "tagData"); + \xml_set_character_data_handler($this->resParser, $this->tagData(...)); $this->strXmlData = \xml_parse($this->resParser, $input); if(!$this->strXmlData) @@ -335,8 +335,10 @@ $lineNumber = \xml_get_current_line_number($this->resParser); die(sprintf("XML error: %s at line %d", $message, $lineNumber)); } - - \xml_parser_free($this->resParser); + + if (PHP_VERSION_ID < 80000) { + \xml_parser_free($this->resParser); + } return MarkupObjectModel::FromArray($this->mvarOutput); } diff --git a/lib/phast/server/System.inc.php b/lib/phast/server/System.inc.php index 6ac6cd2..03252cd 100644 --- a/lib/phast/server/System.inc.php +++ b/lib/phast/server/System.inc.php @@ -621,7 +621,7 @@ return $_GET["virtualpath"]; } } - return null; + return ""; } public static function IncludeFile($filename, $isRequired) { @@ -882,6 +882,17 @@ */ public static function ParsePathVariables(string $template, string $pathstr) { + if ($pathstr == "") + { + if ($template == "") + { + return [ ]; + } + else + { + return false; + } + } $l = strlen($template); $i = 0; @@ -1056,45 +1067,48 @@ } $path = System::GetVirtualPath(); - if (System::$Configuration["Runtime.DisableAutomaticExtensionParsing"] !== true) + if (System::GetConfigurationValue("Runtime.DisableAutomaticExtensionParsing") !== true) { // strip path extension if there is one - $pathLast = $path[count($path) - 1]; - $ix = strripos($pathLast, "."); - if ($ix !== false) + if (count($path) > 0) { - $pathExt = substr($pathLast, $ix + 1); - $path[count($path) - 1] = substr($pathLast, 0, $ix); - - switch ($pathExt) + $pathLast = $path[count($path) - 1]; + $ix = strripos($pathLast, "."); + if ($ix !== false) { - case "json": + $pathExt = substr($pathLast, $ix + 1); + $path[count($path) - 1] = substr($pathLast, 0, $ix); + + switch ($pathExt) { - System::$WebPageFormat = WebPageFormat::JSON; - break; - } - case "xml": - { - System::$WebPageFormat = WebPageFormat::XML; - break; - } - case "html": - { - System::$WebPageFormat = WebPageFormat::HTML; - break; - } - case "js": - { - System::$WebPageFormat = WebPageFormat::JavaScript; - break; - } - default: - { - if ($path[count($path) - 1] != "") + case "json": { - $path[count($path) - 1] = $path[count($path) - 1]; - System::Redirect("~/" . implode("/", $path)); - return; + System::$WebPageFormat = WebPageFormat::JSON; + break; + } + case "xml": + { + System::$WebPageFormat = WebPageFormat::XML; + break; + } + case "html": + { + System::$WebPageFormat = WebPageFormat::HTML; + break; + } + case "js": + { + System::$WebPageFormat = WebPageFormat::JavaScript; + break; + } + default: + { + if ($path[count($path) - 1] != "") + { + $path[count($path) - 1] = $path[count($path) - 1]; + System::Redirect("~/" . implode("/", $path)); + return; + } } } } @@ -1138,7 +1152,7 @@ if (!$success) { - $retval = call_user_func(System::$ErrorEventHandler, new ErrorEventArgs("The specified resource is not available on this server. (" . (System::$EnableTenantedHosting ? ("Tenanted - " . System::GetTenantName()) : "Non-Tenanted") . ")
Path: " . $_GET["virtualpath"])); + $retval = call_user_func(System::$ErrorEventHandler, new ErrorEventArgs("The specified resource is not available on this server. (" . (System::$EnableTenantedHosting ? ("Tenanted - " . System::GetTenantName()) : "Non-Tenanted") . ")
Path: " . (isset($_GET["virtualpath"]) ? $_GET["virtualpath"] : ""))); return false; } return true; diff --git a/lib/phast/server/WebPage.inc.php b/lib/phast/server/WebPage.inc.php index bbcdc59..1a79364 100644 --- a/lib/phast/server/WebPage.inc.php +++ b/lib/phast/server/WebPage.inc.php @@ -59,12 +59,15 @@ { $path = System::GetVirtualPath(); // strip path extension if there is one - $pathLast = $path[count($path) - 1]; - $ix = strripos($pathLast, "."); - if ($ix !== false) + if (count($path) > 0) { - $pathExt = substr($pathLast, $ix + 1); - $path[count($path) - 1] = substr($pathLast, 0, $ix); + $pathLast = $path[count($path) - 1]; + $ix = strripos($pathLast, "."); + if ($ix !== false) + { + $pathExt = substr($pathLast, $ix + 1); + $path[count($path) - 1] = substr($pathLast, 0, $ix); + } } return System::ExpandRelativePath("~/" . implode("/", $path)); } @@ -557,10 +560,10 @@ } $initializingEventArgs = new CancelEventArgs(); - $initializingEventArgs->RenderingPage = $renderingPage; + // $initializingEventArgs->RenderingPage = $renderingPage; $initializedEventArgs = new EventArgs(); - $initializedEventArgs->RenderingPage = $renderingPage; + // $initializedEventArgs->RenderingPage = $renderingPage; if (method_exists($this, "OnInitializing")) { @@ -941,10 +944,13 @@ if ($e->Cancel) return; - if (method_exists($this->ClassReference, "OnPreRender")) + if ($this->ClassReference != null) { - $retval = $this->ClassReference->OnPreRender($e); - if ($e->Cancel) return; + if (method_exists($this->ClassReference, "OnPreRender")) + { + $retval = $this->ClassReference->OnPreRender($e); + if ($e->Cancel) return; + } } $handled = false; @@ -1300,13 +1306,15 @@ } } - - if (method_exists($this->ClassReference, "RenderContents")) + if ($this->ClassReference != null) { - ob_start(); - $this->ClassReference->RenderContents($e); - $tagBODY->Content = ob_get_contents(); - ob_end_clean(); + if (method_exists($this->ClassReference, "RenderContents")) + { + ob_start(); + $this->ClassReference->RenderContents($e); + $tagBODY->Content = ob_get_contents(); + ob_end_clean(); + } } $tagHTML->Controls[] = $tagBODY;