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 <brian@teeman.net>

---------

Co-authored-by: Brian Teeman <brian@teeman.net>
This commit is contained in:
Fedir Zinchuk 2023-02-22 20:34:55 +02:00 committed by GitHub
parent b6ff47e6bf
commit 5fd5edfc45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 77 additions and 85 deletions

View File

@ -16,7 +16,7 @@ $module = $displayData['module'];
$params = $displayData['params'];
?>
<table
class="moduletable <?php echo htmlspecialchars($params->get('moduleclass_sfx'), ENT_COMPAT, 'UTF-8'); ?>">
class="moduletable <?php echo htmlspecialchars($params->get('moduleclass_sfx', ''), ENT_COMPAT, 'UTF-8'); ?>">
<?php if ((bool) $module->showtitle) : ?>
<tr>
<th>

View File

@ -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();
}
}

View File

@ -23,14 +23,15 @@
name="style"
type="list"
label="PLG_LOADMODULE_FIELD_STYLE_LABEL"
default="table"
default="none"
validate="options"
>
<option value="table">PLG_LOADMODULE_FIELD_VALUE_TABLE</option>
<option value="horz">PLG_LOADMODULE_FIELD_VALUE_HORIZONTAL</option>
<option value="xhtml">PLG_LOADMODULE_FIELD_VALUE_DIVS</option>
<option value="rounded">PLG_LOADMODULE_FIELD_VALUE_MULTIPLEDIVS</option>
<option value="none">PLG_LOADMODULE_FIELD_VALUE_RAW</option>
<option value="html5">PLG_LOADMODULE_FIELD_VALUE_DIVS</option>
<option value="table">PLG_LOADMODULE_FIELD_VALUE_TABLE</option>
<!-- @TODO: The following styles don't exist in default installation and can be removed in Joomla 5 -->
<option value="horz">PLG_LOADMODULE_FIELD_VALUE_HORIZONTAL</option>
<option value="rounded">PLG_LOADMODULE_FIELD_VALUE_MULTIPLEDIVS</option>
</field>
</fieldset>
</fields>