From e9d44453fb191ad98b074266bb82d06d834dd1df Mon Sep 17 00:00:00 2001 From: "o.pinke" Date: Wed, 19 Jul 2023 18:55:39 +0200 Subject: [PATCH 1/3] optimize for php8 --- .../class.modrewrite_content_controller.php | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/classes/controller/class.modrewrite_content_controller.php b/classes/controller/class.modrewrite_content_controller.php index 18e23b3..ed75e19 100644 --- a/classes/controller/class.modrewrite_content_controller.php +++ b/classes/controller/class.modrewrite_content_controller.php @@ -27,6 +27,12 @@ if (!defined('CON_FRAMEWORK')) { */ class ModRewrite_ContentController extends ModRewrite_ControllerAbstract { + public $_oView; + public $_client; + /** + * @var array + */ + public $_cfg; /** * Index action */ @@ -41,13 +47,12 @@ class ModRewrite_ContentController extends ModRewrite_ControllerAbstract { public function saveAction() { $bDebug = $this->getProperty('bDebug'); $aSeparator = $this->getProperty('aSeparator'); - $aWordSeparator = $this->getProperty('aWordSeparator'); $routingSeparator = $this->getProperty('routingSeparator'); $bError = false; - $aMR = array(); + $aMR = []; - $request = (count($_POST) > 0) ? $_POST : $_GET; + $request = ($_POST !== []) ? $_POST : $_GET; mr_requestCleanup($request); // use cl-mod-rewrite @@ -321,10 +326,10 @@ class ModRewrite_ContentController extends ModRewrite_ControllerAbstract { // routing if (isset($request['rewrite_routing'])) { - $aRouting = array(); + $aRouting = []; $items = explode("\n", $request['rewrite_routing']); - foreach ($items as $p => $v) { - $routingDef = explode($routingSeparator, $v); + foreach ($items as $item) { + $routingDef = explode($routingSeparator, $item); if (count($routingDef) !== 2) { continue; } @@ -339,7 +344,7 @@ class ModRewrite_ContentController extends ModRewrite_ControllerAbstract { $aMR['cl-mod-rewrite']['routing'] = $aRouting; } else { $this->_oView->rewrite_routing = ''; - $aMR['cl-mod-rewrite']['routing'] = array(); + $aMR['cl-mod-rewrite']['routing'] = []; } // redirect invalid article to errorsite @@ -385,9 +390,8 @@ class ModRewrite_ContentController extends ModRewrite_ControllerAbstract { /** * Checks, if any sseparators setting is modified or not * @param array $aNewCfg New configuration send by requests. - * @return bool */ - protected function _separatorModified($aNewCfg) { + protected function _separatorModified($aNewCfg): bool { $aCfg = ModRewrite::getConfig(); if ($aCfg['category_seperator'] != $aNewCfg['category_seperator']) { @@ -405,18 +409,19 @@ class ModRewrite_ContentController extends ModRewrite_ControllerAbstract { /** * Does some checks like 'is_start_compatible' check. * Adds notifications, if something will went wrong... + * + * @todo review text and translations */ protected function _doChecks() { - // Check for not supported '$cfg["is_start_compatible"] = true;' mode if (!empty($this->_cfg['is_start_compatible']) && true === $this->_cfg['is_start_compatible']) { $sMsg = i18n("Your Contenido installation runs with the setting 'is_start_compatible'. This plugin will not work properly in this mode.
Please check following topic in Contenido forum to change this:

is_start_compatible auf neue Version umstellen", "cl-mod-rewrite"); $this->_oView->content_before .= $this->_notifyBox('warning', $sMsg); } // Check for empty urlpath entries in cat_lang table - $db = new DB_Contenido(); + $dbConLite = new DB_ConLite(); $sql = "SELECT idcatlang FROM " . $this->_cfg['tab']['cat_lang'] . " WHERE urlpath = ''"; - if ($db->query($sql) && $db->next_record()) { + if ($dbConLite->query($sql) && $dbConLite->next_record()) { $sMsg = i18n("It seems as if some categories don't have a set 'urlpath' entry in the database. Please reset empty aliases in %sFunctions%s area.", "cl-mod-rewrite"); $sMsg = sprintf($sMsg, '', ''); $this->_oView->content_before .= $this->_notifyBox('warning', $sMsg); From 606b832ce8926ac51d5d4605a9ebb32c0e1745ad Mon Sep 17 00:00:00 2001 From: "o.pinke" Date: Wed, 19 Jul 2023 18:59:11 +0200 Subject: [PATCH 2/3] optimize for php8 --- ...ss.modrewrite_contentexpert_controller.php | 20 ++------- ...lass.modrewrite_contenttest_controller.php | 42 ++++++++----------- .../class.modrewrite_controller_abstract.php | 14 +++---- 3 files changed, 27 insertions(+), 49 deletions(-) diff --git a/classes/controller/class.modrewrite_contentexpert_controller.php b/classes/controller/class.modrewrite_contentexpert_controller.php index a0ae01f..e49daa1 100644 --- a/classes/controller/class.modrewrite_contentexpert_controller.php +++ b/classes/controller/class.modrewrite_contentexpert_controller.php @@ -77,17 +77,9 @@ class ModRewrite_ContentExpertController extends ModRewrite_ControllerAbstract { return; } - if ($type == 'restrictive') { - $source = $this->_htaccessRestrictive; - } else { - $source = $this->_htaccessSimple; - } + $source = $type == 'restrictive' ? $this->_htaccessRestrictive : $this->_htaccessSimple; - if ($copy == 'contenido') { - $dest = $aInfo['contenido_full_path'] . '.htaccess'; - } else { - $dest = $aInfo['client_full_path'] . '.htaccess'; - } + $dest = $copy == 'contenido' ? $aInfo['contenido_full_path'] . '.htaccess' : $aInfo['client_full_path'] . '.htaccess'; if (!$result = @copy($source, $dest)) { $this->_oView->content_before = $this->_notifyBox('info', 'Die .htaccess konnte nicht von ' . $source . ' nach ' . $dest . ' kopiert werden!'); @@ -108,16 +100,12 @@ class ModRewrite_ContentExpertController extends ModRewrite_ControllerAbstract { return; } - if ($type == 'restrictive') { - $source = $this->_htaccessRestrictive; - } else { - $source = $this->_htaccessSimple; - } + $source = $type == 'restrictive' ? $this->_htaccessRestrictive : $this->_htaccessSimple; $this->_oView->content = file_get_contents($source); header('Content-Type: text/plain'); - header('Etag: ' . md5(mt_rand())); + header('Etag: ' . md5(random_int(0, mt_getrandmax()))); header('Content-Disposition: attachment; filename="' . $type . '.htaccess"'); $this->render('{CONTENT}'); } diff --git a/classes/controller/class.modrewrite_contenttest_controller.php b/classes/controller/class.modrewrite_contenttest_controller.php index 1f095ee..0b0c5fd 100644 --- a/classes/controller/class.modrewrite_contenttest_controller.php +++ b/classes/controller/class.modrewrite_contenttest_controller.php @@ -60,33 +60,25 @@ class ModRewrite_ContentTestController extends ModRewrite_ControllerAbstract { $this->_oView->content = ''; // Array for testcases - $aTests = array(); + $aTests = []; // Instance of mr test - $oMRTest = new ModRewriteTest($this->_iMaxItems); + $modRewriteTest = new ModRewriteTest($this->_iMaxItems); $startTime = getmicrotime(); // Fetch complete CONTENIDO page structure - $aStruct = $oMRTest->fetchFullStructure(); + $aStruct = $modRewriteTest->fetchFullStructure(); ModRewriteDebugger::add($aStruct, 'ModRewrite_ContentTestController::testAction() $aStruct'); // Loop through the structure and compose testcases - foreach ($aStruct as $idcat => $aCat) { + foreach ($aStruct as $aCat) { // category - $aTests[] = array( - 'url' => $oMRTest->composeURL($aCat, 'c'), - 'level' => $aCat['level'], - 'name' => $aCat['name'] - ); + $aTests[] = ['url' => $modRewriteTest->composeURL($aCat, 'c'), 'level' => $aCat['level'], 'name' => $aCat['name']]; - foreach ($aCat['articles'] as $idart => $aArt) { + foreach ($aCat['articles'] as $aArt) { // articles - $aTests[] = array( - 'url' => $oMRTest->composeURL($aArt, 'a'), - 'level' => $aCat['level'], - 'name' => $aCat['name'] . ' :: ' . $aArt['title'] - ); + $aTests[] = ['url' => $modRewriteTest->composeURL($aArt, 'a'), 'level' => $aCat['level'], 'name' => $aCat['name'] . ' :: ' . $aArt['title']]; } } @@ -96,7 +88,7 @@ class ModRewrite_ContentTestController extends ModRewrite_ControllerAbstract { $oMRUrlStack = ModRewriteUrlStack::getInstance(); // first loop to add urls to mr url stack - foreach ($aTests as $p => $v) { + foreach ($aTests as $v) { $oMRUrlStack->add($v['url']); } @@ -104,15 +96,15 @@ class ModRewrite_ContentTestController extends ModRewrite_ControllerAbstract { $failCounter = 0; // second loop to do the rest - foreach ($aTests as $p => $v) { - $url = mr_buildNewUrl($v['url']); - $arr = $oMRTest->resolveUrl($url); + foreach ($aTests as $aTest) { + $url = mr_buildNewUrl($aTest['url']); + $arr = $modRewriteTest->resolveUrl($url); $error = ''; - $resUrl = $oMRTest->getResolvedUrl(); + $resUrl = $modRewriteTest->getResolvedUrl(); $color = 'green'; if ($url !== $resUrl) { - if ($oMRTest->getRoutingFoundState()) { + if ($modRewriteTest->getRoutingFoundState()) { $successCounter++; $resUrl = 'route to -> ' . $resUrl; } else { @@ -144,18 +136,18 @@ class ModRewrite_ContentTestController extends ModRewrite_ControllerAbstract { } } - $pref = str_repeat(' ', $v['level']); + $pref = str_repeat(' ', $aTest['level']); // render resolve information for current item $itemTpl = $this->_oView->lng_result_item_tpl; $itemTpl = str_replace('{pref}', $pref, $itemTpl); - $itemTpl = str_replace('{name}', $v['name'], $itemTpl); - $itemTpl = str_replace('{url_in}', $v['url'], $itemTpl); + $itemTpl = str_replace('{name}', $aTest['name'], $itemTpl); + $itemTpl = str_replace('{url_in}', $aTest['url'], $itemTpl); $itemTpl = str_replace('{url_out}', $url, $itemTpl); $itemTpl = str_replace('{color}', $color, $itemTpl); $itemTpl = str_replace('{url_res}', $resUrl, $itemTpl); $itemTpl = str_replace('{err}', $error, $itemTpl); - $itemTpl = str_replace('{data}', $oMRTest->getReadableResolvedData($arr), $itemTpl); + $itemTpl = str_replace('{data}', $modRewriteTest->getReadableResolvedData($arr), $itemTpl); $this->_oView->content .= "\n" . $itemTpl . "\n"; } diff --git a/classes/controller/class.modrewrite_controller_abstract.php b/classes/controller/class.modrewrite_controller_abstract.php index cf1bb01..de104f9 100644 --- a/classes/controller/class.modrewrite_controller_abstract.php +++ b/classes/controller/class.modrewrite_controller_abstract.php @@ -72,13 +72,13 @@ abstract class ModRewrite_ControllerAbstract { * Template file or template string to render * @var string */ - protected $_template = null; + protected $_template; /** * Additional properties list * @var array */ - protected $_properties = array(); + protected $_properties = []; /** * Debug flag @@ -138,20 +138,18 @@ abstract class ModRewrite_ControllerAbstract { /** * Property setter. * @param string $key - * @param mixed $value */ - public function setProperty($key, $value) { + public function setProperty($key, mixed $value) { $this->_properties[$key] = $value; } /** * Property getter. * @param string $key - * @param mixed $default * @return mixed */ - public function getProperty($key, $default = null) { - return (isset($this->_properties[$key])) ? $this->_properties[$key] : $default; + public function getProperty($key, mixed $default = null) { + return $this->_properties[$key] ?? $default; } /** @@ -202,7 +200,7 @@ abstract class ModRewrite_ControllerAbstract { * @param mixed $default The default value * @return mixed */ - protected function _getParam($key, $default = null) { + protected function _getParam($key, mixed $default = null) { if (isset($_GET[$key])) { return $_GET[$key]; } elseif (isset($_POST[$key])) { From a00c8149f7f6fce4202c6c5ca4642a681d444750 Mon Sep 17 00:00:00 2001 From: "o.pinke" Date: Tue, 12 Mar 2024 19:19:19 +0100 Subject: [PATCH 3/3] use new log class --- includes/functions.mod_rewrite.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/includes/functions.mod_rewrite.php b/includes/functions.mod_rewrite.php index a787210..59772c1 100644 --- a/includes/functions.mod_rewrite.php +++ b/includes/functions.mod_rewrite.php @@ -23,6 +23,10 @@ * @link http://www.4fb.de * @link http://www.contenido.org */ + +use ConLite\Log\LogWriter; +use ConLite\Log\Log; + if (!defined('CON_FRAMEWORK')) { die('Illegal call'); } @@ -679,9 +683,9 @@ function mr_setConfiguration($clientId, array $config) { try { mkdir($sConfigClientPath, 0777, true); } catch (Exception $ex) { - $oWriter = cLogWriter::factory("File", array('destination' => 'contenido.log')); - $oLog = new cLog($oWriter); - $oLog->log($ex->getFile() . " (" . $ex->getLine() . "): " . $ex->getMessage(), cLog::WARN); + $writer = LogWriter::factory("File", array('destination' => 'contenido.log')); + $log = new Log($writer); + $log->log($ex->getFile() . " (" . $ex->getLine() . "): " . $ex->getMessage(), Log::WARN); } }