-
-
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 2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -644,4 +644,111 @@ public static function isAdminMultilang() | |
|
||
return $enabled; | ||
} | ||
|
||
/** | ||
* Get module by id | ||
* | ||
* @param string $id The name of the module | ||
* @param string $title The title of the module, optional | ||
* | ||
* @return \stdClass The Module object | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
public static function &getModuleid($id, $title = null) | ||
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. Shouldn't the name of that method be something like 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. changed |
||
{ | ||
$app = \JFactory::getApplication(); | ||
$result = null; | ||
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. Remove. |
||
$groups = implode(',', \JFactory::getUser()->getAuthorisedViewLevels()); | ||
$lang = \JFactory::getLanguage()->getTag(); | ||
$clientId = (int) $app->getClientId(); | ||
|
||
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. Please remove all the code from lone 659 to 693 as it is not used in the method 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. true again |
||
// Build a cache ID for the resulting data object | ||
$cacheId = $groups . $clientId . $id; | ||
|
||
$db = \JFactory::getDbo(); | ||
|
||
$query = $db->getQuery(true) | ||
->select('m.id, m.title, m.module, m.position, m.content, m.showtitle, m.params, mm.menuid') | ||
->from('#__modules AS m') | ||
->join('LEFT', '#__modules_menu AS mm ON mm.moduleid = m.id') | ||
->where('m.id = ' . (int) $id) | ||
->where('m.published = 1') | ||
->join('LEFT', '#__extensions AS e ON e.element = m.module AND e.client_id = m.client_id') | ||
->where('e.enabled = 1'); | ||
|
||
$date = \JFactory::getDate(); | ||
$now = $date->toSql(); | ||
$nullDate = $db->getNullDate(); | ||
$query->where('(m.publish_up = ' . $db->quote($nullDate) . ' OR m.publish_up <= ' . $db->quote($now) . ')') | ||
->where('(m.publish_down = ' . $db->quote($nullDate) . ' OR m.publish_down >= ' . $db->quote($now) . ')') | ||
->where('m.access IN (' . $groups . ')') | ||
->where('m.client_id = ' . $clientId); | ||
|
||
// Filter by language | ||
if ($app->isClient('site') && $app->getLanguageFilter()) | ||
{ | ||
$query->where('m.language IN (' . $db->quote($lang) . ',' . $db->quote('*') . ')'); | ||
$cacheId .= $lang . '*'; | ||
} | ||
|
||
if ($app->isClient('administrator') && static::isAdminMultilang()) | ||
{ | ||
$query->where('m.language IN (' . $db->quote($lang) . ',' . $db->quote('*') . ')'); | ||
$cacheId .= $lang . '*'; | ||
} | ||
|
||
$query->order('m.position, m.ordering'); | ||
|
||
// Set the query | ||
$db->setQuery($query); | ||
|
||
try | ||
{ | ||
/** @var \JCacheControllerCallback $cache */ | ||
$cache = \JFactory::getCache('com_modules', 'callback'); | ||
|
||
$modules = $cache->get(array($db, 'loadObjectList'), array(), md5($cacheId), false); | ||
} | ||
catch (\RuntimeException $e) | ||
{ | ||
\JLog::add(\JText::sprintf('JLIB_APPLICATION_ERROR_MODULE_LOAD', $e->getMessage()), \JLog::WARNING, 'jerror'); | ||
|
||
$modules = array(); | ||
} | ||
|
||
|
||
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. Remove blank line. |
||
$total = count($modules); | ||
|
||
for ($i = 0; $i < $total; $i++) | ||
{ | ||
// Match the id of the module | ||
if ($modules[$i]->id === $id) | ||
{ | ||
// Match the title if we're looking for a specific instance of the module | ||
if (!$title || $modules[$i]->title === $title) | ||
{ | ||
// Found it | ||
$result = &$modules[$i]; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
// If we didn't find it, and the name is mod_something, create a dummy object | ||
if ($result === null && strpos($name, 'mod_') === 0) | ||
{ | ||
$result = new \stdClass; | ||
$result->id = 0; | ||
$result->title = ''; | ||
$result->module = $name; | ||
$result->position = ''; | ||
$result->content = ''; | ||
$result->showtitle = 0; | ||
$result->control = ''; | ||
$result->params = ''; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
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'); | ||
|
||
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. Remove tabs. |
||
// Expression to search for(id) | ||
$regexmodid = '/{loadmoduleid\s(.*?)}/i'; | ||
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. Change regex to match for digits. |
||
$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,26 @@ 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) | ||
{ | ||
$matcheslist = explode('id:', $match[1]); | ||
|
||
$id = trim($matcheslist[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'); | ||
} | ||
|
||
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. Remove blank line. 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. done |
||
} | ||
} | ||
|
||
/** | ||
|
@@ -187,4 +210,30 @@ protected function _loadmod($module, $title, $style = 'none') | |
|
||
return self::$mods[$module]; | ||
} | ||
|
||
/** | ||
* Loads and renders the module | ||
* | ||
* @param string $id The id of the module | ||
* @param string $style The style assigned to the module | ||
* | ||
* @return mixed | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
protected function _loadid($id, $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. The syntax 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. removed |
||
{ | ||
self::$modules[$id] = ''; | ||
$document = JFactory::getDocument(); | ||
$renderer = $document->loadRenderer('module'); | ||
$modules = JModuleHelper::getModuleid($id); | ||
$params = array('style' => $style); | ||
ob_start(); | ||
|
||
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. Remove tab. 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. removed |
||
echo $renderer->render($modules->module, $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.
change to
The id