From 5fd5edfc45719ab2b9b0e28d45de5f21b31608b4 Mon Sep 17 00:00:00 2001 From: Fedir Zinchuk Date: Wed, 22 Feb 2023 20:34:55 +0200 Subject: [PATCH] Fix for the title of a loaded module is not visible (#39839) * Fix default style for "load module" plugin * Fix default style for "load module" plugin * Fix default style for "load module" plugin, performance * Fix default style for "load module" plugin, deprecation * Fix default style for "load module" plugin, remove unused * phpcs * Update plugins/content/loadmodule/loadmodule.xml Co-authored-by: Brian Teeman --------- Co-authored-by: Brian Teeman --- layouts/chromes/table.php | 2 +- plugins/content/loadmodule/loadmodule.php | 149 ++++++++++------------ plugins/content/loadmodule/loadmodule.xml | 11 +- 3 files changed, 77 insertions(+), 85 deletions(-) diff --git a/layouts/chromes/table.php b/layouts/chromes/table.php index b19b8c1c2db..2176625b876 100644 --- a/layouts/chromes/table.php +++ b/layouts/chromes/table.php @@ -16,7 +16,7 @@ $module = $displayData['module']; $params = $displayData['params']; ?> + class="moduletable get('moduleclass_sfx', ''), ENT_COMPAT, 'UTF-8'); ?>"> showtitle) : ?>
diff --git a/plugins/content/loadmodule/loadmodule.php b/plugins/content/loadmodule/loadmodule.php index 1e8e15925c4..b4f08799a2a 100644 --- a/plugins/content/loadmodule/loadmodule.php +++ b/plugins/content/loadmodule/loadmodule.php @@ -54,101 +54,101 @@ class PlgContentLoadmodule extends CMSPlugin return; } - // Simple performance check to determine whether bot should process further - if (strpos($article->text, 'loadposition') === false && strpos($article->text, 'loadmodule') === false) { - return; + $defaultStyle = $this->params->get('style', 'none'); + + // Fallback xhtml (used in Joomla 3) to html5 + if ($defaultStyle === 'xhtml') { + $defaultStyle = 'html5'; } // Expression to search for (positions) $regex = '/{loadposition\s(.*?)}/i'; - $style = $this->params->def('style', 'none'); // Expression to search for(modules) $regexmod = '/{loadmodule\s(.*?)}/i'; - $stylemod = $this->params->def('style', 'none'); // Expression to search for(id) $regexmodid = '/{loadmoduleid\s([1-9][0-9]*)}/i'; - // Find all instances of plugin and put in $matches for loadposition - // $matches[0] is full pattern match, $matches[1] is the position - preg_match_all($regex, $article->text, $matches, PREG_SET_ORDER); + if (str_contains($article->text, '{loadposition ')) { + // Find all instances of plugin and put in $matches for loadposition + // $matches[0] is full pattern match, $matches[1] is the position + preg_match_all($regex, $article->text, $matches, PREG_SET_ORDER); - // No matches, skip this - if ($matches) { - foreach ($matches as $match) { - $matcheslist = explode(',', $match[1]); + // No matches, skip this + if ($matches) { + foreach ($matches as $match) { + $matcheslist = explode(',', $match[1]); - // We may not have a module style so fall back to the plugin default. - if (!array_key_exists(1, $matcheslist)) { - $matcheslist[1] = $style; + // We may not have a module style so fall back to the plugin default. + if (!array_key_exists(1, $matcheslist)) { + $matcheslist[1] = $defaultStyle; + } + + $position = trim($matcheslist[0]); + $style = trim($matcheslist[1]); + + $output = $this->_load($position, $style); + + // We should replace only first occurrence in order to allow positions with the same name to regenerate their content: + if (($start = strpos($article->text, $match[0])) !== false) { + $article->text = substr_replace($article->text, $output, $start, strlen($match[0])); + } } - - $position = trim($matcheslist[0]); - $style = trim($matcheslist[1]); - - $output = $this->_load($position, $style); - - // We should replace only first occurrence in order to allow positions with the same name to regenerate their content: - if (($start = strpos($article->text, $match[0])) !== false) { - $article->text = substr_replace($article->text, $output, $start, strlen($match[0])); - } - - $style = $this->params->def('style', 'none'); } } - // Find all instances of plugin and put in $matchesmod for loadmodule - preg_match_all($regexmod, $article->text, $matchesmod, PREG_SET_ORDER); + if (str_contains($article->text, '{loadmodule ')) { + // Find all instances of plugin and put in $matchesmod for loadmodule + preg_match_all($regexmod, $article->text, $matchesmod, PREG_SET_ORDER); - // If no matches, skip this - if ($matchesmod) { - foreach ($matchesmod as $matchmod) { - $matchesmodlist = explode(',', $matchmod[1]); + // If no matches, skip this + if ($matchesmod) { + foreach ($matchesmod as $matchmod) { + $matchesmodlist = explode(',', $matchmod[1]); - // First parameter is the module, will be prefixed with mod_ later - $module = trim($matchesmodlist[0]); + // First parameter is the module, will be prefixed with mod_ later + $module = trim($matchesmodlist[0]); - // Second parameter is the title - $title = ''; + // Second parameter is the title + $title = ''; - if (array_key_exists(1, $matchesmodlist)) { - $title = htmlspecialchars_decode(trim($matchesmodlist[1])); + if (array_key_exists(1, $matchesmodlist)) { + $title = htmlspecialchars_decode(trim($matchesmodlist[1])); + } + + // Third parameter is the module style, (fallback is the plugin default set earlier). + $stylemod = $defaultStyle; + + if (array_key_exists(2, $matchesmodlist)) { + $stylemod = trim($matchesmodlist[2]); + } + + $output = $this->_loadmod($module, $title, $stylemod); + + // We should replace only first occurrence in order to allow positions with the same name to regenerate their content: + if (($start = strpos($article->text, $matchmod[0])) !== false) { + $article->text = substr_replace($article->text, $output, $start, strlen($matchmod[0])); + } } - - // Third parameter is the module style, (fallback is the plugin default set earlier). - $stylemod = ''; - - if (array_key_exists(2, $matchesmodlist)) { - $stylemod = trim($matchesmodlist[2]); - } - - $output = $this->_loadmod($module, $title, $stylemod); - - // We should replace only first occurrence in order to allow positions with the same name to regenerate their content: - if (($start = strpos($article->text, $matchmod[0])) !== false) { - $article->text = substr_replace($article->text, $output, $start, strlen($matchmod[0])); - } - - $stylemod = $this->params->def('style', 'none'); } } - // Find all instances of plugin and put in $matchesmodid for loadmoduleid - preg_match_all($regexmodid, $article->text, $matchesmodid, PREG_SET_ORDER); + if (str_contains($article->text, '{loadmoduleid ')) { + // Find all instances of plugin and put in $matchesmodid for loadmoduleid + preg_match_all($regexmodid, $article->text, $matchesmodid, PREG_SET_ORDER); - // If no matches, skip this - if ($matchesmodid) { - foreach ($matchesmodid as $match) { - $id = trim($match[1]); - $output = $this->_loadid($id); + // If no matches, skip this + if ($matchesmodid) { + foreach ($matchesmodid as $match) { + $id = trim($match[1]); + $output = $this->_loadid($id); - // We should replace only first occurrence in order to allow positions with the same name to regenerate their content: - if (($start = strpos($article->text, $match[0])) !== false) { - $article->text = substr_replace($article->text, $output, $start, strlen($match[0])); + // We should replace only first occurrence in order to allow positions with the same name to regenerate their content: + if (($start = strpos($article->text, $match[0])) !== false) { + $article->text = substr_replace($article->text, $output, $start, strlen($match[0])); + } } - - $style = $this->params->def('style', 'none'); } } } @@ -165,7 +165,6 @@ class PlgContentLoadmodule extends CMSPlugin */ protected function _load($position, $style = 'none') { - self::$modules[$position] = ''; $document = Factory::getDocument(); $renderer = $document->loadRenderer('module'); $modules = ModuleHelper::getModules($position); @@ -176,9 +175,7 @@ class PlgContentLoadmodule extends CMSPlugin echo $renderer->render($module, $params); } - self::$modules[$position] = ob_get_clean(); - - return self::$modules[$position]; + return ob_get_clean(); } /** @@ -195,7 +192,6 @@ class PlgContentLoadmodule extends CMSPlugin */ protected function _loadmod($module, $title, $style = 'none') { - self::$mods[$module] = ''; $document = Factory::getDocument(); $renderer = $document->loadRenderer('module'); $mod = ModuleHelper::getModule($module, $title); @@ -214,9 +210,7 @@ class PlgContentLoadmodule extends CMSPlugin echo $renderer->render($mod, $params); } - self::$mods[$module] = ob_get_clean(); - - return self::$mods[$module]; + return ob_get_clean(); } /** @@ -230,7 +224,6 @@ class PlgContentLoadmodule extends CMSPlugin */ protected function _loadid($id) { - self::$modules[$id] = ''; $document = Factory::getDocument(); $renderer = $document->loadRenderer('module'); $modules = ModuleHelper::getModuleById($id); @@ -241,8 +234,6 @@ class PlgContentLoadmodule extends CMSPlugin echo $renderer->render($modules, $params); } - self::$modules[$id] = ob_get_clean(); - - return self::$modules[$id]; + return ob_get_clean(); } } diff --git a/plugins/content/loadmodule/loadmodule.xml b/plugins/content/loadmodule/loadmodule.xml index 3ec39dd58c4..a350810c185 100644 --- a/plugins/content/loadmodule/loadmodule.xml +++ b/plugins/content/loadmodule/loadmodule.xml @@ -23,14 +23,15 @@ name="style" type="list" label="PLG_LOADMODULE_FIELD_STYLE_LABEL" - default="table" + default="none" validate="options" > - - - - + + + + +