@@ -44,6 +44,12 @@ class PlgSystemMVCOverride extends JPlugin
44
44
*/
45
45
protected static $ option ;
46
46
47
+ /**
48
+ * @var array
49
+ * @since 1.6
50
+ */
51
+ protected $ pathwaysFromTemplate = [];
52
+
47
53
/**
48
54
* Constructor
49
55
*
@@ -58,92 +64,131 @@ public function __construct(&$subject, $config = array())
58
64
JPlugin::loadLanguage ('plg_system_mvcoverride ' );
59
65
60
66
parent ::__construct ($ subject , $ config );
61
- }
62
67
63
- /**
64
- * onAfterRoute function.
65
- *
66
- * @return void
67
- * @since 1.4
68
- */
69
- public function onAfterRoute ()
70
- {
71
- JPluginHelper::importPlugin ('redcore ' );
72
-
73
- $ app = JFactory::getApplication ();
74
-
75
- $ includePath = $ this ->params ->get ('includePath ' , '{JPATH_BASE}/code,{JPATH_THEMES}/{template}/code ' );
76
-
77
- $ includePath = str_replace (
78
- array ('{JPATH_BASE} ' , '{JPATH_THEMES} ' , '{template} ' ),
79
- array (JPATH_BASE , JPATH_THEMES , $ app ->getTemplate ()),
80
- $ includePath
81
- );
68
+ $ redcoreLoader = JPATH_LIBRARIES . '/redcore/bootstrap.php ' ;
82
69
83
- $ includePath = explode ( ' , ' , $ includePath );
84
-
85
- // Register additional include paths for code replacements from plugins
86
- $ app -> triggerEvent ( ' onMVCOverrideIncludePaths ' , array (& $ includePath )) ;
87
-
88
- MVCOverrideHelperCodepool:: addCodePath ( $ includePath );
70
+ // Try to support redCORE RLoader if exist
71
+ if ( file_exists ( $ redcoreLoader ))
72
+ {
73
+ require_once $ redcoreLoader ;
74
+ RBootstrap:: bootstrap ( false );
75
+ }
89
76
90
77
MVCLoader::setupOverrideLoader (
91
78
$ this ->params ->get ('changePrivate ' , 0 ),
92
79
$ this ->params ->get ('extendPrefix ' , '' ),
93
80
$ this ->params ->get ('extendSuffix ' , 'Default ' )
94
81
);
82
+ MVCOverrideHelperCodepool::initialize ();
83
+
84
+ $ includedPathways = $ this ->params ->get ('includePath ' , '{JPATH_BASE}/code,{JPATH_THEMES}/{template}/code ' );
85
+
86
+ $ includedPathways = str_replace (
87
+ ['{JPATH_BASE} ' , '{JPATH_THEMES} ' ],
88
+ [JPATH_BASE , JPATH_THEMES ],
89
+ $ includedPathways
90
+ );
95
91
96
- $ this ->setOverrideFiles ();
97
- $ option = $ this ->getOption ();
98
- $ hasOption = true ;
92
+ $ includedPathways = explode (', ' , $ includedPathways );
99
93
100
- if ($ option === false || ! isset ( self :: $ componentList [ $ option ]) )
94
+ foreach ($ includedPathways as $ key => $ includedPatch )
101
95
{
102
- $ hasOption = false ;
96
+ if (strpos ($ includedPatch , '{template} ' ) !== false )
97
+ {
98
+ // We will attach it in onAfterRoute
99
+ $ this ->pathwaysFromTemplate [] = $ includedPatch ;
100
+ unset($ includedPathways [$ key ]);
101
+ }
103
102
}
104
103
105
- MVCOverrideHelperCodepool::initialize ();
104
+ $ this ->initialiseComponents ($ includedPathways );
105
+ }
106
+
107
+ /**
108
+ * @param array|string $includedPathways Included pathways
109
+ *
110
+ * @since 1.6.0
111
+ * @return void
112
+ */
113
+ protected function initialiseComponents ($ includedPathways )
114
+ {
115
+ if (empty ($ includedPathways ))
116
+ {
117
+ return ;
118
+ }
106
119
107
120
// Add override paths for the current component files
108
- foreach (MVCOverrideHelperCodepool:: addCodePath () as $ codePool )
121
+ foreach (( array ) $ includedPathways as $ codePool )
109
122
{
123
+ if (!JFolder::exists ($ codePool ))
124
+ {
125
+ continue ;
126
+ }
127
+
128
+ MVCOverrideHelperCodepool::addCodePath ($ codePool );
129
+
130
+ $ components = JFolder::folders ($ codePool );
131
+
132
+ if (!empty ($ components ))
133
+ {
134
+ foreach ($ components as $ key => $ component )
135
+ {
136
+ if (strpos ($ component , 'com_ ' ) !== 0 )
137
+ {
138
+ unset($ components [$ key ]);
139
+ continue ;
140
+ }
141
+
142
+ $ this ->addOverrideFiles ($ codePool , $ component );
143
+ }
144
+ }
145
+
110
146
if (version_compare (JVERSION , '3.8 ' , '>= ' ))
111
147
{
112
- if ($ hasOption )
148
+ if (! empty ( $ components ) )
113
149
{
114
- Joomla \CMS \MVC \View \HtmlView::addViewHelperPath ($ codePool . '/ ' . $ option );
115
- Joomla \CMS \MVC \View \HtmlView::addViewTemplatePath ($ codePool . '/ ' . $ option );
116
- Joomla \CMS \Table \Table::addIncludePath ($ codePool . '/ ' . $ option . '/tables ' );
117
- Joomla \CMS \MVC \Model \FormModel::addComponentFormPath ($ codePool . '/ ' . $ option . '/models/forms ' );
118
- Joomla \CMS \MVC \Model \FormModel::addComponentFieldPath ($ codePool . '/ ' . $ option . '/models/fields ' );
119
- Joomla \CMS \MVC \Model \ListModel::addComponentFormPath ($ codePool . '/ ' . $ option . '/models/forms ' );
120
- Joomla \CMS \MVC \Model \ListModel::addComponentFieldPath ($ codePool . '/ ' . $ option . '/models/fields ' );
150
+ foreach ($ components as $ option )
151
+ {
152
+ Joomla \CMS \MVC \View \HtmlView::addViewHelperPath ($ codePool . '/ ' . $ option );
153
+ Joomla \CMS \MVC \View \HtmlView::addViewTemplatePath ($ codePool . '/ ' . $ option );
154
+ Joomla \CMS \Table \Table::addIncludePath ($ codePool . '/ ' . $ option . '/tables ' );
155
+ Joomla \CMS \MVC \Model \FormModel::addComponentFormPath ($ codePool . '/ ' . $ option . '/models/forms ' );
156
+ Joomla \CMS \MVC \Model \FormModel::addComponentFieldPath ($ codePool . '/ ' . $ option . '/models/fields ' );
157
+ Joomla \CMS \MVC \Model \ListModel::addComponentFormPath ($ codePool . '/ ' . $ option . '/models/forms ' );
158
+ Joomla \CMS \MVC \Model \ListModel::addComponentFieldPath ($ codePool . '/ ' . $ option . '/models/fields ' );
159
+ }
121
160
}
122
161
123
162
Joomla \CMS \Helper \ModuleHelper::addIncludePath ($ codePool . '/modules ' );
124
163
}
125
164
elseif (version_compare (JVERSION , '3.0 ' , '>= ' ))
126
165
{
127
- if ($ hasOption )
166
+ if (! empty ( $ components ) )
128
167
{
129
- JViewLegacy::addViewHelperPath ($ codePool . '/ ' . $ option );
130
- JViewLegacy::addViewTemplatePath ($ codePool . '/ ' . $ option );
131
- JTable::addIncludePath ($ codePool . '/ ' . $ option . '/tables ' );
132
- JModelForm::addComponentFormPath ($ codePool . '/ ' . $ option . '/models/forms ' );
133
- JModelForm::addComponentFieldPath ($ codePool . '/ ' . $ option . '/models/fields ' );
168
+ foreach ($ components as $ option )
169
+ {
170
+ JViewLegacy::addViewHelperPath ($ codePool . '/ ' . $ option );
171
+ JViewLegacy::addViewTemplatePath ($ codePool . '/ ' . $ option );
172
+ JTable::addIncludePath ($ codePool . '/ ' . $ option . '/tables ' );
173
+ JModelForm::addComponentFormPath ($ codePool . '/ ' . $ option . '/models/forms ' );
174
+ JModelForm::addComponentFieldPath ($ codePool . '/ ' . $ option . '/models/fields ' );
175
+ }
134
176
}
135
177
136
178
JModuleHelper::addIncludePath ($ codePool . '/modules ' );
137
179
}
138
180
else
139
181
{
140
- if ($ hasOption )
182
+ if (! empty ( $ components ) )
141
183
{
142
- JView::addViewHelperPath ($ codePool . '/ ' . $ option );
143
- JView::addViewTemplatePath ($ codePool . '/ ' . $ option );
144
- JTable::addIncludePath ($ codePool . '/ ' . $ option . '/tables ' );
145
- JModelForm::addComponentFormPath ($ codePool . '/ ' . $ option . '/models/forms ' );
146
- JModelForm::addComponentFieldPath ($ codePool . '/ ' . $ option . '/models/fields ' );
184
+ foreach ($ components as $ option )
185
+ {
186
+ JView::addViewHelperPath ($ codePool . '/ ' . $ option );
187
+ JView::addViewTemplatePath ($ codePool . '/ ' . $ option );
188
+ JTable::addIncludePath ($ codePool . '/ ' . $ option . '/tables ' );
189
+ JModelForm::addComponentFormPath ($ codePool . '/ ' . $ option . '/models/forms ' );
190
+ JModelForm::addComponentFieldPath ($ codePool . '/ ' . $ option . '/models/fields ' );
191
+ }
147
192
}
148
193
149
194
JModuleHelper::addIncludePath ($ codePool . '/modules ' );
@@ -152,26 +197,32 @@ public function onAfterRoute()
152
197
}
153
198
154
199
/**
155
- * Set Override Files
200
+ * onAfterRoute function.
156
201
*
157
- * @return void
202
+ * @return void
158
203
* @since 1.4
204
+ * @throws Exception
159
205
*/
160
- public function setOverrideFiles ()
206
+ public function onAfterRoute ()
161
207
{
162
- $ includePaths = MVCOverrideHelperCodepool:: addCodePath ( null );
208
+ $ app = JFactory:: getApplication ( );
163
209
164
- foreach ( $ includePaths as $ includePath )
210
+ if (! empty ( $ this -> pathwaysFromTemplate ) )
165
211
{
166
- if ($ components = JFolder:: folders ( $ includePath ) )
212
+ foreach ($ this -> pathwaysFromTemplate as & $ pathwayFromTemplate )
167
213
{
168
- foreach ( $ components as $ component )
169
- {
170
- self :: $ componentList [ $ component ] = $ component ;
171
- $ this -> addOverrideFiles ( $ includePath , $ component );
172
- }
214
+ $ pathwayFromTemplate = str_replace (
215
+ array ( ' {template} ' ),
216
+ array ( $ app -> getTemplate ()),
217
+ $ pathwayFromTemplate
218
+ );
173
219
}
174
220
}
221
+
222
+ // Register additional include paths for code replacements from plugins
223
+ $ app ->triggerEvent ('onMVCOverrideIncludePaths ' , array (&$ this ->pathwaysFromTemplate ));
224
+
225
+ $ this ->initialiseComponents ($ this ->pathwaysFromTemplate );
175
226
}
176
227
177
228
/**
@@ -183,7 +234,7 @@ public function setOverrideFiles()
183
234
* @return void
184
235
* @since 1.4
185
236
*/
186
- private function addOverrideFiles ($ includePath , $ component )
237
+ protected function addOverrideFiles ($ includePath , $ component )
187
238
{
188
239
$ types = array ('controllers ' , 'models ' , 'helpers ' , 'views ' );
189
240
$ currentFormat = JFactory::getDocument ()->getType ();
@@ -202,7 +253,9 @@ private function addOverrideFiles($includePath, $component)
202
253
switch ($ type )
203
254
{
204
255
case 'helpers ' :
205
- if ($ listFiles = JFolder::files ($ searchFolder , '.php ' , false , true ))
256
+ $ listFiles = JFolder::files ($ searchFolder , '.php ' , false , true );
257
+
258
+ if (!empty ($ listFiles ))
206
259
{
207
260
foreach ($ listFiles as $ file )
208
261
{
@@ -215,12 +268,16 @@ private function addOverrideFiles($includePath, $component)
215
268
216
269
case 'views ' :
217
270
// Reading view folders
218
- if ($ views = JFolder::folders ($ searchFolder ))
271
+ $ views = JFolder::folders ($ searchFolder );
272
+
273
+ if (!empty ($ views ))
219
274
{
220
275
foreach ($ views as $ view )
221
276
{
222
277
// Get view formats files
223
- if ($ listFiles = JFolder::files ($ searchFolder . '/ ' . $ view , '. ' . $ currentFormat . '.php ' , false , true ))
278
+ $ listFiles = JFolder::files ($ searchFolder . '/ ' . $ view , '. ' . $ currentFormat . '.php ' , false , true );
279
+
280
+ if (!empty ($ listFiles ))
224
281
{
225
282
foreach ($ listFiles as $ file )
226
283
{
@@ -232,7 +289,9 @@ private function addOverrideFiles($includePath, $component)
232
289
break ;
233
290
234
291
default :
235
- if ($ listFiles = JFolder::files ($ searchFolder , '.php ' , false , true ))
292
+ $ listFiles = JFolder::files ($ searchFolder , '.php ' , false , true );
293
+
294
+ if (!empty ($ listFiles ))
236
295
{
237
296
foreach ($ listFiles as $ file )
238
297
{
@@ -255,7 +314,7 @@ private function addOverrideFiles($includePath, $component)
255
314
* @return void
256
315
* @since 1.4
257
316
*/
258
- private function getOverrideFileInfo ($ includePath , $ component , $ filePath , $ type = '' , $ indexName = '' )
317
+ protected function getOverrideFileInfo ($ includePath , $ component , $ filePath , $ type = '' , $ indexName = '' )
259
318
{
260
319
$ filePath = JPath::clean ($ filePath );
261
320
$ sameFolderPrefix = $ component . '/ ' . $ type ;
@@ -309,42 +368,4 @@ private function getOverrideFileInfo($includePath, $component, $filePath, $type
309
368
$ this ->params ->get ('extendSuffix ' , 'Default ' )
310
369
);
311
370
}
312
-
313
- /**
314
- * Get option
315
- *
316
- * @return boolean|mixed|string
317
- * @since 1.4
318
- */
319
- private function getOption ()
320
- {
321
- if (self ::$ option )
322
- {
323
- return self ::$ option ;
324
- }
325
-
326
- $ app = JFactory::getApplication ();
327
- self ::$ option = $ app ->input ->getCmd ('option ' , '' );
328
-
329
- if (empty (self ::$ option ) && $ app ->isSite ())
330
- {
331
- $ menuDefault = JFactory::getApplication ()->getMenu ()->getDefault ();
332
-
333
- if (!$ menuDefault )
334
- {
335
- return false ;
336
- }
337
-
338
- $ componentID = $ menuDefault ->component_id ;
339
- $ db = JFactory::getDBO ();
340
- $ query = $ db ->getQuery (true )
341
- ->select ('element ' )
342
- ->from ($ db ->qn ('#__extensions ' ))
343
- ->where ('extension_id = ' . $ db ->quote ($ componentID ));
344
- $ db ->setQuery ($ query );
345
- self ::$ option = $ db ->loadResult ();
346
- }
347
-
348
- return self ::$ option ;
349
- }
350
371
}
0 commit comments