Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

JModuleHelper - JPath and addIncludePath #1369

Closed
wants to merge 1 commit into from

2 participants

@juliopontes

Hi,

I've changed some include files to use more platform code improved with use of JPath to find module files. Added a feature that will be used just by devs that wish to override module code.
I've implement new method addIncludePath to find modules in this new path.
these changes will not affect actual working code of cms.

Cheers,

Julio Pontes

@eddieajau

Julio, this pull request is really only of use to the CMS, so I feel it's better added to the CMS codebase.

@eddieajau eddieajau closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 15, 2012
  1. @juliopontes

    changed some include paths to use JPath and added new feature addIncl…

    juliopontes authored
    …udePath to override modules code.
This page is out of date. Refresh to see the latest.
Showing with 48 additions and 11 deletions.
  1. +48 −11 libraries/legacy/module/helper.php
View
59 libraries/legacy/module/helper.php
@@ -19,6 +19,14 @@
abstract class JModuleHelper
{
/**
+ * An array to hold included paths
+ *
+ * @var array
+ * @since 11.1
+ */
+ protected static $includePaths = array();
+
+ /**
* Get module by name (real, eg 'Breadcrumbs' or folder, eg 'mod_breadcrumbs')
*
* @param string $name The name of the module
@@ -156,11 +164,11 @@ public static function renderModule($module, $attribs = array())
// Get module path
$module->module = preg_replace('/[^A-Z0-9_\.-]/i', '', $module->module);
- $path = JPATH_BASE . '/modules/' . $module->module . '/' . $module->module . '.php';
-
+ self::addIncludePath(JPATH_BASE . '/modules');
+
// Load the module
// $module->user is a check for 1.0 custom modules and is deprecated refactoring
- if (empty($module->user) && file_exists($path))
+ if (empty($module->user))
{
$lang = JFactory::getLanguage();
@@ -172,7 +180,7 @@ public static function renderModule($module, $attribs = array())
$content = '';
ob_start();
- include $path;
+ include JPath::find(self::addIncludePath(),$module->module . '/' . $module->module . '.php');
$module->content = ob_get_contents() . $content;
ob_end_clean();
}
@@ -260,19 +268,17 @@ public static function getLayoutPath($module, $layout = 'default')
}
// Build the template and base path for the layout
- $tPath = JPATH_THEMES . '/' . $template . '/html/' . $module . '/' . $layout . '.php';
- $bPath = JPATH_BASE . '/modules/' . $module . '/tmpl/' . $defaultLayout . '.php';
+ $templatePaths = array(
+ JPATH_THEMES . '/' . $template . '/html/' . $module,
+ JPATH_BASE . '/modules/' . $module . '/tmpl',
+ );
$dPath = JPATH_BASE . '/modules/' . $module . '/tmpl/default.php';
// If the template has a layout override use it
- if (file_exists($tPath))
+ if ($tPath = JPath::find($templatePaths,$defaultLayout.'.php'))
{
return $tPath;
}
- elseif (file_exists($bPath))
- {
- return $bPath;
- }
else
{
return $dPath;
@@ -512,4 +518,35 @@ public static function moduleCache($module, $moduleparams, $cacheparams)
return $ret;
}
+
+ /**
+ * Add a directory where JModuleHelper should search for module. You may
+ * either pass a string or an array of directories.
+ *
+ * @param string $path A path to search.
+ *
+ * @return array An array with directory elements
+ *
+ * @since 11.1
+ */
+ public static function addIncludePath($path = '')
+ {
+ // Force path to array
+ settype($path, 'array');
+
+ // Loop through the path directories
+ foreach ($path as $dir)
+ {
+ if (!empty($dir) && !in_array($dir, self::$includePaths))
+ {
+ jimport('joomla.filesystem.path');
+ array_unshift(self::$includePaths, JPath::clean($dir));
+
+ //fix to override include path priority
+ self::$includePath = array_reverse(self::$includePath);
+ }
+ }
+
+ return self::$includePaths;
+ }
}
Something went wrong with that request. Please try again.