-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[plugin][content] - loadmodule by id #19362
Changes from 25 commits
0432413
3281e2a
035df51
799c175
90f2c61
8c1dd54
9af765d
6e8f758
5cc1b00
6fb2fc0
21dc445
197152b
ae46c4d
62beaa9
23731bc
d2873ed
852d5c3
4ef6d69
9ce44e9
d5c74e1
8d36d1d
781ddf3
ed57a9b
d593013
6da43c4
16ecfff
9215455
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,10 @@ public function onContentPrepare($context, &$article, &$params, $page = 0) | |
|
||
// 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'; | ||
$stylemod = $this->params->def('style', 'none'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move back to its original line so it is not assumed to be related to modid. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved back |
||
|
||
// Find all instances of plugin and put in $matches for loadposition | ||
// $matches[0] is full pattern match, $matches[1] is the position | ||
|
@@ -117,6 +120,22 @@ public function onContentPrepare($context, &$article, &$params, $page = 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 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: | ||
$article->text = preg_replace("|$match[0]|", addcslashes($output, '\\$'), $article->text, 1); | ||
$style = $this->params->def('style', 'none'); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -187,4 +206,32 @@ protected function _loadmod($module, $title, $style = 'none') | |
|
||
return self::$mods[$module]; | ||
} | ||
|
||
/** | ||
* Loads and renders the module | ||
* | ||
* @param string $id The id of the module | ||
* | ||
* @return mixed | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
protected function _loadid($id) | ||
{ | ||
self::$modules[$id] = ''; | ||
$document = JFactory::getDocument(); | ||
$renderer = $document->loadRenderer('module'); | ||
$modules = JModuleHelper::getModuleById($id); | ||
$params = array('style' => 'none'); | ||
ob_start(); | ||
|
||
if ($modules->id > 0) | ||
{ | ||
echo $renderer->render($modules, $params); | ||
} | ||
|
||
self::$modules[$id] = ob_get_clean(); | ||
|
||
return self::$modules[$id]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove blank line.