@@ -32,131 +32,48 @@ abstract class HTMLHelper extends HTMLHelperCore
3232 *
3333 * @since 1.6.0
3434 */
35- protected static function includeRelativeFiles ($ folder , $ file , $ relative , $ detect_browser , $ detect_debug )
35+ protected static function includeRelativeFiles ($ folder , $ file , $ relative , $ detectBrowser , $ detectDebug )
3636 {
37- // Get defaults include paths
38- $ default = parent ::includeRelativeFiles ($ folder , $ file , $ relative , $ detect_browser , $ detect_debug );
39-
40- // If don't child return default
41- if (!defined ('YOOTHEME_CHILD ' )) return $ default ;
42-
43- // If http is present return default path
44- if (strpos ($ file , 'http ' ) === 0 || strpos ($ file , '// ' ) === 0 ) return $ default ;
45-
46- // If don't relative return default path
47- if (!$ relative ) return $ default ;
48-
49- // Prepare array of files
50- $ includes = array ();
51-
52- // Extract extension and strip the file
53- $ strip = File::stripExt ($ file );
54- $ ext = File::getExt ($ file );
55-
56- // Detect browser and compute potential files
57- if ($ detect_browser )
37+ if (!defined ('YOOTHEME_CHILD ' ))
5838 {
59- $ navigator = Browser::getInstance ();
60- $ browser = $ navigator ->getBrowser ();
61- $ major = $ navigator ->getMajor ();
62- $ minor = $ navigator ->getMinor ();
63-
64- // Try to include files named filename.ext, filename_browser.ext, filename_browser_major.ext, filename_browser_major_minor.ext
65- // where major and minor are the browser version names
66- $ potential = array (
67- $ strip ,
68- $ strip . '_ ' . $ browser ,
69- $ strip . '_ ' . $ browser . '_ ' . $ major ,
70- $ strip . '_ ' . $ browser . '_ ' . $ major . '_ ' . $ minor ,
71- );
72- }
73- else
74- {
75- $ potential = array ($ strip );
39+ return parent ::includeRelativeFiles ($ folder , $ file , $ relative , $ detectBrowser , $ detectDebug );
7640 }
7741
78- // Get the template
79- $ template = 'yootheme_ ' . YOOTHEME_CHILD ;
80-
81- // For each potential files
82- foreach ($ potential as $ strip )
83- {
84- $ files = array ();
85-
86- // Detect debug mode
87- if ($ detect_debug && Factory::getConfig ()->get ('debug ' ))
88- {
89- /*
90- * Detect if we received a file in the format name.min.ext
91- * If so, strip the .min part out, otherwise append -uncompressed
92- */
93- if (strlen ($ strip ) > 4 && preg_match ('#\.min$# ' , $ strip ))
94- {
95- $ files [] = preg_replace ('#\.min$# ' , '. ' , $ strip ) . $ ext ;
96- }
97- else
98- {
99- $ files [] = $ strip . '-uncompressed. ' . $ ext ;
100- }
101- }
42+ $ app = Factory::getApplication ();
43+ $ template = $ app ->getTemplate (true );
44+ $ source = clone $ template ;
10245
103- $ files [] = $ strip . '. ' . $ ext ;
46+ $ template ->template = 'yootheme_ ' . YOOTHEME_CHILD ;
47+ $ template ->parent = 'yootheme ' ;
48+ $ app ->set ('template ' , $ template );
10449
105- /*
106- * Loop on 1 or 2 files and break on first found.
107- * Add the content of the MD5SUM file located in the same folder to URL to ensure cache browser refresh
108- * This MD5SUM file must represent the signature of the folder content
109- */
110- foreach ($ files as $ file )
111- {
112- // If the file is in the template folder
113- $ path = JPATH_THEMES . "/ $ template/ $ folder/ $ file " ;
114- if (file_exists ($ path ))
115- {
116- $ includes [] = Uri::base (true ) . "/templates/ $ template/ $ folder/ $ file " . static ::getMd5Version ($ path );
50+ $ result = parent ::includeRelativeFiles ($ folder , $ file , $ relative , $ detectBrowser , $ detectDebug );
11751
118- break ;
119- }
120- else
121- {
122- // If the file contains any /: it can be in a media extension subfolder
123- if (strpos ($ file , '/ ' ))
124- {
125- // Divide the file extracting the extension as the first part before /
126- list ($ extension , $ file ) = explode ('/ ' , $ file , 2 );
52+ $ app ->set ('template ' , $ source );
12753
128- // If the file yet contains any /: it can be a plugin
129- if (strpos ($ file , '/ ' ))
130- {
131- // Divide the file extracting the element as the first part before /
132- list ($ element , $ file ) = explode ('/ ' , $ file , 2 );
133-
134- // Try to deal with system files in the template folder
135- $ path = JPATH_THEMES . "/ $ template/ $ folder/system/ $ element/ $ file " ;
136- if (file_exists ($ path ))
137- {
138- $ includes [] = Uri::root (true ) . "/templates/ $ template/ $ folder/system/ $ element/ $ file " . static ::getMd5Version ($ path );
139-
140- break ;
141- }
142- }
143- else
144- {
145- // Try to deal with system files in the template folder
146- $ path = JPATH_THEMES . "/ $ template/ $ folder/system/ $ file " ;
147-
148- if (file_exists ($ path ))
149- {
150- $ includes [] = Uri::root (true ) . "/templates/ $ template/ $ folder/system/ $ file " . static ::getMd5Version ($ path );
54+ return $ result ;
55+ }
15156
152- break ;
153- }
154- }
155- }
156- }
157- }
57+ /**
58+ * Method that searches if file exists in given path and returns the relative path. If a minified version exists it will be preferred.
59+ *
60+ * @param string $path The actual path of the file
61+ * @param string $ext The extension of the file
62+ * @param boolean $debugMode Signifies if debug is enabled
63+ *
64+ * @return string The relative path of the file
65+ *
66+ * @since __DEPLOY_VERSION__
67+ */
68+ protected static function addFileToBuffer ($ path = '' , $ ext = '' , $ debugMode = false )
69+ {
70+ $ result = parent ::addFileToBuffer ($ path , $ ext , $ debugMode );
71+ if (empty ($ result ) && strpos ($ path , 'media/templates/site/yootheme ' ) !== false )
72+ {
73+ $ path = str_replace ('media/templates/site/ ' , 'templates/ ' , $ path );
74+ $ result = parent ::addFileToBuffer ($ path , $ ext , $ debugMode );
15875 }
15976
160- return (! empty ( $ includes )) ? $ includes : $ default ;
77+ return $ result ;
16178 }
16279}
0 commit comments