Skip to content

Commit 39d95a1

Browse files
authored
Merge pull request #23 from shandak/joomla_3_8_0_support
fix for Joomla 3.8 support
2 parents 18d027b + 7808509 commit 39d95a1

13 files changed

+898
-126
lines changed

core/model/modelform.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
*
1616
* @package Joomla.Legacy
1717
* @subpackage Module
18-
* @since 11.1
18+
* @since 1.4
1919
*/
2020
abstract class JModelForm extends LIB_JModelFormDefault
2121
{
2222
/**
2323
* Array to registry paths from component form and gields
2424
*
2525
* @var array
26+
* @since 1.4
2627
*/
2728
static private $codePaths = array('form' => array(), 'fields' => array());
2829

@@ -38,7 +39,7 @@ abstract class JModelForm extends LIB_JModelFormDefault
3839
* @return mixed JForm object on success, False on error.
3940
*
4041
* @see JForm
41-
* @since 11.1
42+
* @since 1.4
4243
*/
4344
protected function loadForm($name, $source = null, $options = array(), $clear = false, $xpath = false)
4445
{
@@ -101,7 +102,8 @@ protected function loadForm($name, $source = null, $options = array(), $clear =
101102
*
102103
* @param string $path Path
103104
*
104-
* @return void
105+
* @return string
106+
* @since 1.4
105107
*/
106108
static public function addComponentFormPath($path = null)
107109
{
@@ -120,7 +122,8 @@ static public function addComponentFormPath($path = null)
120122
*
121123
* @param string $path Path
122124
*
123-
* @return void
125+
* @return string
126+
* @since 1.4
124127
*/
125128
static public function addComponentFieldPath($path = null)
126129
{

core/module/helper.php

+14-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @package RedCORE.Plugin
44
* @subpackage System.MVCOverride
55
*
6-
* @copyright Copyright (C) 2008 - 2015 redCOMPONENT.com. All rights reserved.
6+
* @copyright Copyright (C) 2008 - 2017 redCOMPONENT.com. All rights reserved.
77
* @license GNU General Public License version 2 or later; see LICENSE
88
*/
99

@@ -14,18 +14,22 @@
1414
*
1515
* @package Joomla.Legacy
1616
* @subpackage Module
17-
* @since 11.1
17+
* @since 1.4
1818
*/
1919
abstract class JModuleHelper extends LIB_JModuleHelperDefault
2020
{
2121
/**
2222
* An array to hold included paths
2323
*
2424
* @var array
25-
* @since 11.1
25+
* @since 1.4
2626
*/
2727
protected static $includePaths = array();
2828

29+
/**
30+
* @var boolean
31+
* @since 1.4
32+
*/
2933
public static $chrome = false;
3034

3135
/**
@@ -36,7 +40,7 @@ abstract class JModuleHelper extends LIB_JModuleHelperDefault
3640
*
3741
* @return string The HTML content of the module output.
3842
*
39-
* @since 11.1
43+
* @since 1.4
4044
*/
4145
public static function renderModule($module, $attribs = array())
4246
{
@@ -154,19 +158,19 @@ public static function renderModule($module, $attribs = array())
154158
*
155159
* @return string The path to the module layout
156160
*
157-
* @since 11.1
161+
* @since 1.4
158162
*/
159163
public static function getLayoutPath($module, $layout = 'default')
160164
{
161-
$template = JFactory::getApplication()->getTemplate();
165+
$template = JFactory::getApplication()->getTemplate();
162166
$defaultLayout = $layout;
163167

164168
if (strpos($layout, ':') !== false)
165169
{
166170
// Get the template and file name from the string
167-
$temp = explode(':', $layout);
168-
$template = ($temp[0] == '_') ? $template : $temp[0];
169-
$layout = $temp[1];
171+
$temp = explode(':', $layout);
172+
$template = ($temp[0] == '_') ? $template : $temp[0];
173+
$layout = $temp[1];
170174
$defaultLayout = ($temp[1]) ? $temp[1] : 'default';
171175
}
172176

@@ -199,7 +203,7 @@ public static function getLayoutPath($module, $layout = 'default')
199203
*
200204
* @return array An array with directory elements
201205
*
202-
* @since 11.1
206+
* @since 1.4
203207
*/
204208
public static function addIncludePath($path = '')
205209
{

core/src/Helper/ModuleHelper.php

+267
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,267 @@
1+
<?php
2+
/**
3+
* @package RedCORE.Plugin
4+
* @subpackage System.MVCOverride
5+
*
6+
* @copyright Copyright (C) 2008 - 2017 redCOMPONENT.com. All rights reserved.
7+
* @license GNU General Public License version 2 or later; see LICENSE
8+
*/
9+
10+
namespace Joomla\CMS\Helper;
11+
12+
defined('JPATH_PLATFORM') or die;
13+
14+
use Joomla\CMS\Component\ComponentHelper;
15+
use Joomla\Registry\Registry;
16+
use Joomla\Filesystem\Path;
17+
18+
/**
19+
* Module helper class
20+
*
21+
* @since 1.5
22+
*/
23+
abstract class ModuleHelper extends LIB_ModuleHelperDefault
24+
{
25+
/**
26+
* An array to hold included paths
27+
*
28+
* @var array
29+
* @since 1.5
30+
*/
31+
protected static $includePaths = array();
32+
33+
/**
34+
* Render the module.
35+
*
36+
* @param object $module A module object.
37+
* @param array $attribs An array of attributes for the module (probably from the XML).
38+
*
39+
* @return string The HTML content of the module output.
40+
*
41+
* @since 1.5
42+
*/
43+
public static function renderModule($module, $attribs = array())
44+
{
45+
static $chrome;
46+
47+
// Check that $module is a valid module object
48+
if (!is_object($module) || !isset($module->module) || !isset($module->params))
49+
{
50+
if (JDEBUG)
51+
{
52+
\JLog::addLogger(array('text_file' => 'jmodulehelper.log.php'), \JLog::ALL, array('modulehelper'));
53+
\JLog::add('ModuleHelper::renderModule($module) expects a module object', \JLog::DEBUG, 'modulehelper');
54+
}
55+
56+
return '';
57+
}
58+
59+
if (JDEBUG)
60+
{
61+
\JProfiler::getInstance('Application')->mark('beforeRenderModule ' . $module->module . ' (' . $module->title . ')');
62+
}
63+
64+
$app = \JFactory::getApplication();
65+
66+
// Record the scope.
67+
$scope = $app->scope;
68+
69+
// Set scope to component name
70+
$app->scope = $module->module;
71+
72+
// Get module parameters
73+
$params = new Registry($module->params);
74+
75+
// Get the template
76+
$template = $app->getTemplate();
77+
78+
// Get module path
79+
$module->module = preg_replace('/[^A-Z0-9_\.-]/i', '', $module->module);
80+
$path = JPATH_BASE . '/modules/' . $module->module . '/' . $module->module . '.php';
81+
82+
// Load the module
83+
if (file_exists($path))
84+
{
85+
$lang = \JFactory::getLanguage();
86+
87+
$coreLanguageDirectory = JPATH_BASE;
88+
$extensionLanguageDirectory = dirname($path);
89+
90+
$langPaths = $lang->getPaths();
91+
92+
// Only load the module's language file if it hasn't been already
93+
if (!$langPaths || (!isset($langPaths[$coreLanguageDirectory]) && !isset($langPaths[$extensionLanguageDirectory])))
94+
{
95+
// 1.5 or Core then 1.6 3PD
96+
$lang->load($module->module, $coreLanguageDirectory, null, false, true) ||
97+
$lang->load($module->module, $extensionLanguageDirectory, null, false, true);
98+
}
99+
100+
$paths = array(JPATH_BASE . '/modules');
101+
$paths = array_merge(self::addIncludePath(), $paths);
102+
$filePath = Path::find($paths, $module->module . '/' . $module->module . '.php');
103+
104+
if ($filePath)
105+
{
106+
$content = '';
107+
ob_start();
108+
include $filePath;
109+
$module->content = ob_get_contents() . $content;
110+
ob_end_clean();
111+
}
112+
}
113+
114+
// Load the module chrome functions
115+
if (!$chrome)
116+
{
117+
$chrome = array();
118+
}
119+
120+
include_once JPATH_THEMES . '/system/html/modules.php';
121+
$chromePath = JPATH_THEMES . '/' . $template . '/html/modules.php';
122+
123+
if (!isset($chrome[$chromePath]))
124+
{
125+
if (file_exists($chromePath))
126+
{
127+
include_once $chromePath;
128+
}
129+
130+
$chrome[$chromePath] = true;
131+
}
132+
133+
// Check if the current module has a style param to override template module style
134+
$paramsChromeStyle = $params->get('style');
135+
136+
if ($paramsChromeStyle)
137+
{
138+
$attribs['style'] = preg_replace('/^(system|' . $template . ')\-/i', '', $paramsChromeStyle);
139+
}
140+
141+
// Make sure a style is set
142+
if (!isset($attribs['style']))
143+
{
144+
$attribs['style'] = 'none';
145+
}
146+
147+
// Dynamically add outline style
148+
if ($app->input->getBool('tp') && ComponentHelper::getParams('com_templates')->get('template_positions_display'))
149+
{
150+
$attribs['style'] .= ' outline';
151+
}
152+
153+
// If the $module is nulled it will return an empty content, otherwise it will render the module normally.
154+
$app->triggerEvent('onRenderModule', array(&$module, &$attribs));
155+
156+
if ($module === null || !isset($module->content))
157+
{
158+
return '';
159+
}
160+
161+
foreach (explode(' ', $attribs['style']) as $style)
162+
{
163+
$chromeMethod = 'modChrome_' . $style;
164+
165+
// Apply chrome and render module
166+
if (function_exists($chromeMethod))
167+
{
168+
$module->style = $attribs['style'];
169+
170+
ob_start();
171+
$chromeMethod($module, $params, $attribs);
172+
$module->content = ob_get_contents();
173+
ob_end_clean();
174+
}
175+
}
176+
177+
// Revert the scope
178+
$app->scope = $scope;
179+
180+
$app->triggerEvent('onAfterRenderModule', array(&$module, &$attribs));
181+
182+
if (JDEBUG)
183+
{
184+
\JProfiler::getInstance('Application')->mark('afterRenderModule ' . $module->module . ' (' . $module->title . ')');
185+
}
186+
187+
return $module->content;
188+
}
189+
190+
/**
191+
* Get the path to a layout for a module
192+
*
193+
* @param string $module The name of the module
194+
* @param string $layout The name of the module layout. If alternative layout, in the form template:filename.
195+
*
196+
* @return string The path to the module layout
197+
*
198+
* @since 1.5
199+
*/
200+
public static function getLayoutPath($module, $layout = 'default')
201+
{
202+
$template = \JFactory::getApplication()->getTemplate();
203+
$defaultLayout = $layout;
204+
$templatePaths = array();
205+
206+
if (strpos($layout, ':') !== false)
207+
{
208+
// Get the template and file name from the string
209+
$temp = explode(':', $layout);
210+
$template = $temp[0] === '_' ? $template : $temp[0];
211+
$layout = $temp[1];
212+
$defaultLayout = $temp[1] ?: 'default';
213+
}
214+
215+
foreach (self::addIncludePath() as $onePath)
216+
{
217+
$templatePaths[] = $onePath . '/' . $module;
218+
}
219+
220+
$templatePaths[] = JPATH_THEMES . '/' . $template . '/html/' . $module;
221+
$templatePaths[] = JPATH_BASE . '/modules/' . $module;
222+
223+
// If the template has a layout override use it
224+
if ($tPath = Path::find($templatePaths, $layout . '.php'))
225+
{
226+
return $tPath;
227+
}
228+
elseif ($tPath = Path::find($templatePaths, 'tmpl/' . $defaultLayout . '.php'))
229+
{
230+
return $tPath;
231+
}
232+
else
233+
{
234+
return JPATH_BASE . '/modules/' . $module . '/tmpl/default.php';
235+
}
236+
}
237+
238+
/**
239+
* Add a directory where JModuleHelper should search for module. You may
240+
* either pass a string or an array of directories.
241+
*
242+
* @param string $path A path to search.
243+
*
244+
* @return array An array with directory elements
245+
*
246+
* @since 1.5
247+
*/
248+
public static function addIncludePath($path = '')
249+
{
250+
if ($path)
251+
{
252+
// Force path to array
253+
settype($path, 'array');
254+
255+
// Loop through the path directories
256+
foreach ($path as $dir)
257+
{
258+
if (!empty($dir) && !in_array(Path::clean($dir), self::$includePaths))
259+
{
260+
array_unshift(self::$includePaths, Path::clean($dir));
261+
}
262+
}
263+
}
264+
265+
return self::$includePaths;
266+
}
267+
}

0 commit comments

Comments
 (0)