Skip to content
This repository

JModuleHelper - JPath and addIncludePath #1369

Closed
wants to merge 1 commit into from

2 participants

Júlio Pontes Andrew Eddie
Júlio Pontes

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

Andrew Eddie
Owner

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

Andrew Eddie eddieajau closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jul 14, 2012
Júlio Pontes changed some include paths to use JPath and added new feature addIncl…
…udePath to override modules code.
4e6b74d
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 48 additions and 11 deletions. Show diff stats Hide diff stats

  1. 59  libraries/legacy/module/helper.php
59  libraries/legacy/module/helper.php
@@ -19,6 +19,14 @@
19 19
 abstract class JModuleHelper
20 20
 {
21 21
 	/**
  22
+	 * An array to hold included paths
  23
+	 *
  24
+	 * @var    array
  25
+	 * @since  11.1
  26
+	 */
  27
+	protected static $includePaths = array();
  28
+
  29
+	/**
22 30
 	 * Get module by name (real, eg 'Breadcrumbs' or folder, eg 'mod_breadcrumbs')
23 31
 	 *
24 32
 	 * @param   string  $name   The name of the module
@@ -156,11 +164,11 @@ public static function renderModule($module, $attribs = array())
156 164
 
157 165
 		// Get module path
158 166
 		$module->module = preg_replace('/[^A-Z0-9_\.-]/i', '', $module->module);
159  
-		$path = JPATH_BASE . '/modules/' . $module->module . '/' . $module->module . '.php';
160  
-
  167
+		self::addIncludePath(JPATH_BASE . '/modules');
  168
+		
161 169
 		// Load the module
162 170
 		// $module->user is a check for 1.0 custom modules and is deprecated refactoring
163  
-		if (empty($module->user) && file_exists($path))
  171
+		if (empty($module->user))
164 172
 		{
165 173
 			$lang = JFactory::getLanguage();
166 174
 
@@ -172,7 +180,7 @@ public static function renderModule($module, $attribs = array())
172 180
 
173 181
 			$content = '';
174 182
 			ob_start();
175  
-			include $path;
  183
+			include JPath::find(self::addIncludePath(),$module->module . '/' . $module->module . '.php');
176 184
 			$module->content = ob_get_contents() . $content;
177 185
 			ob_end_clean();
178 186
 		}
@@ -260,19 +268,17 @@ public static function getLayoutPath($module, $layout = 'default')
260 268
 		}
261 269
 
262 270
 		// Build the template and base path for the layout
263  
-		$tPath = JPATH_THEMES . '/' . $template . '/html/' . $module . '/' . $layout . '.php';
264  
-		$bPath = JPATH_BASE . '/modules/' . $module . '/tmpl/' . $defaultLayout . '.php';
  271
+		$templatePaths = array(
  272
+			JPATH_THEMES . '/' . $template . '/html/' . $module,
  273
+			JPATH_BASE . '/modules/' . $module . '/tmpl',
  274
+		);
265 275
 		$dPath = JPATH_BASE . '/modules/' . $module . '/tmpl/default.php';
266 276
 
267 277
 		// If the template has a layout override use it
268  
-		if (file_exists($tPath))
  278
+		if ($tPath = JPath::find($templatePaths,$defaultLayout.'.php'))
269 279
 		{
270 280
 			return $tPath;
271 281
 		}
272  
-		elseif (file_exists($bPath))
273  
-		{
274  
-			return $bPath;
275  
-		}
276 282
 		else
277 283
 		{
278 284
 			return $dPath;
@@ -512,4 +518,35 @@ public static function moduleCache($module, $moduleparams, $cacheparams)
512 518
 
513 519
 		return $ret;
514 520
 	}
  521
+
  522
+	/**
  523
+	 * Add a directory where JModuleHelper should search for module. You may
  524
+	 * either pass a string or an array of directories.
  525
+	 *
  526
+	 * @param   string  $path  A path to search.
  527
+	 *
  528
+	 * @return  array  An array with directory elements
  529
+	 *
  530
+	 * @since   11.1
  531
+	 */
  532
+	public static function addIncludePath($path = '')
  533
+	{
  534
+		// Force path to array
  535
+		settype($path, 'array');
  536
+
  537
+		// Loop through the path directories
  538
+		foreach ($path as $dir)
  539
+		{
  540
+			if (!empty($dir) && !in_array($dir, self::$includePaths))
  541
+			{
  542
+				jimport('joomla.filesystem.path');
  543
+				array_unshift(self::$includePaths, JPath::clean($dir));
  544
+				
  545
+				//fix to override include path priority
  546
+				self::$includePath = array_reverse(self::$includePath);
  547
+			}
  548
+		}
  549
+
  550
+		return self::$includePaths;
  551
+	}
515 552
 }
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.