@@ -30,6 +30,7 @@ class Document
3030 protected $ minify_html = false ;
3131 protected static $ _fontawesome = false ;
3232 protected static $ _layout_paths = [];
33+ protected $ type = null ;
3334
3435 public function __construct ()
3536 {
@@ -38,11 +39,18 @@ public function __construct()
3839 $ this ->minify_js = $ params ->get ('minify_js ' , false );
3940 $ this ->minify_html = $ params ->get ('minify_html ' , false );
4041
42+ $ doc = \JFactory::getDocument ();
43+ $ this ->type = $ doc ->getType ();
4144
4245 $ template = Framework::getTemplate ();
4346 $ this ->addLayoutPath (JPATH_SITE . '/templates/ ' . $ template ->template . '/html/frontend/ ' );
4447 }
4548
49+ public function getType ()
50+ {
51+ return $ this ->type ;
52+ }
53+
4654 public function addLayoutPath ($ path )
4755 {
4856 self ::$ _layout_paths [] = $ path ;
@@ -104,17 +112,15 @@ public function compress()
104112 $ app = \JFactory::getApplication ();
105113 $ body = $ app ->getBody ();
106114
107- if ($ this ->minify_css ) {
108- $ body = $ this ->minifyCSS ($ body );
109- }
115+ // Stop Minification for RSSFeeds and other doc types.
116+ if ($ this ->type == 'feed ' ) $ this ->minify_css = $ this ->minify_js = $ this ->minify_html = false ;
110117
111- if ($ this ->minify_js && !$ this ->isFrontendEditing ()) {
112- $ body = $ this ->minifyJS ($ body );
113- }
118+ if ($ this ->minify_css ) $ body = $ this ->minifyCSS ($ body );
114119
115- if ($ this ->minify_html ) {
116- $ body = $ this ->minifyHTML ($ body );
117- }
120+ if ($ this ->minify_js && !$ this ->isFrontendEditing ()) $ body = $ this ->minifyJS ($ body );
121+
122+ if ($ this ->minify_html ) $ body = $ this ->minifyHTML ($ body );
123+
118124 $ app ->setBody ($ body );
119125 }
120126
@@ -499,6 +505,11 @@ public function position($position, $style = 'none')
499505 return $ return ;
500506 }
501507
508+ public function hasModule ($ position , $ module )
509+ {
510+ return in_array ($ module , array_column (\JModuleHelper::getModules ($ position ), 'module ' ));
511+ }
512+
502513 public function loadModule ($ content )
503514 {
504515 // Expression to search for(module Position)
@@ -779,7 +790,7 @@ public function addStyleDeclaration($content, $device = 'desktop')
779790 $ this ->_styles [$ device ][] = trim ($ content );
780791 }
781792
782- public function addStyleSheet ($ url , $ attribs = ['rel ' => 'stylesheet ' , 'type ' => 'text/css ' ])
793+ public function addStyleSheet ($ url , $ attribs = ['rel ' => 'stylesheet ' , 'type ' => 'text/css ' ], $ shifted = 0 )
783794 {
784795 if (!is_array ($ url )) {
785796 $ url = [$ url ];
@@ -792,7 +803,7 @@ public function addStyleSheet($url, $attribs = ['rel' => 'stylesheet', 'type' =>
792803 }
793804 foreach ($ url as $ u ) {
794805 if (!empty (trim ($ u ))) {
795- $ stylesheet = ['url ' => $ u , 'attribs ' => $ attribs ];
806+ $ stylesheet = ['url ' => $ u , 'attribs ' => $ attribs, ' shifted ' => $ shifted ];
796807 $ this ->_stylesheets [md5 ($ u )] = $ stylesheet ;
797808 }
798809 }
@@ -814,15 +825,31 @@ public function loadFontAwesome()
814825 Helper \Font::loadFontAwesome ();
815826 }
816827
828+ public function moveFile (&$ array , $ a , $ b )
829+ {
830+ $ out = array_splice ($ array , $ a , 1 );
831+ array_splice ($ array , $ b , 0 , $ out );
832+ }
833+
817834 public function getStylesheets ()
818835 {
836+ $ keys = array_keys ($ this ->_stylesheets );
837+
838+ foreach ($ keys as $ index => $ key ) {
839+ if ($ this ->_stylesheets [$ key ]['shifted ' ]) {
840+ $ newindex = $ index + $ this ->_stylesheets [$ key ]['shifted ' ];
841+ $ this ->moveFile ($ keys , $ index , $ newindex );
842+ }
843+ }
844+
819845 $ content = '' ;
820- foreach ($ this ->_stylesheets as $ stylesheet ) {
846+ foreach ($ keys as $ key ) {
847+ $ stylesheet = $ this ->_stylesheets [$ key ];
821848 $ content .= '<link href=" ' . $ this ->_systemUrl ($ stylesheet ['url ' ]) . '" ' ;
822849 foreach ($ stylesheet ['attribs ' ] as $ prop => $ value ) {
823850 $ content .= ' ' . $ prop . '=" ' . $ value . '" ' ;
824851 }
825- $ content .= ' /> ' ;
852+ $ content .= ' /> ' . "\n" ;
826853 }
827854 return $ content ;
828855 }
0 commit comments