Esempio n. 1
0
 /**
  * If parameter is set will minify HTML before sending to browser; 
  * Inline CSS and JS will also be minified if respective parameters are set
  * 
  * @return string                       Optimized HTML
  * @throws Exception
  */
 public static function minifyHtml($sHtml, $oParams)
 {
     JCH_DEBUG ? JchPlatformProfiler::mark('beforeMinifyHtml plgSystem (JCH Optimize)') : null;
     $aOptions = array();
     if ($oParams->get('css_minify', 0)) {
         $aOptions['cssMinifier'] = array('JchOptimize\\CSS_Optimize', 'process');
     }
     if ($oParams->get('js_minify', 0)) {
         $aOptions['jsMinifier'] = array('JchOptimize\\JS_Optimize', 'minify');
     }
     $aOptions['minify_level'] = $oParams->get('html_minify_level', 2);
     if ($oParams->get('html_minify', 0)) {
         $sHtmlMin = HTML_Optimize::minify($sHtml, $aOptions);
         if ($sHtmlMin == '') {
             JchOptimizeLogger::log(JchPlatformUtility::translate('Error while minifying HTML'), $oParams);
             $sHtmlMin = $sHtml;
         }
         $sHtml = $sHtmlMin;
     }
     JCH_DEBUG ? JchPlatformProfiler::mark('afterMinifyHtml plgSystem (JCH Optimize)') : null;
     return $sHtml;
 }
Esempio n. 2
0
 /**
  * If parameter is set will minify HTML before sending to browser; 
  * Inline CSS and JS will also be minified if respective parameters are set
  * 
  * @return string                       Optimized HTML
  * @throws Exception
  */
 public static function minifyHtml($sHtml, $oParams)
 {
     JCH_DEBUG ? JchPlatformProfiler::start('MinifyHtml') : null;
     if ($oParams->get('html_minify', 0)) {
         $aOptions = array();
         if ($oParams->get('css_minify', 0)) {
             $aOptions['cssMinifier'] = array('JchOptimize\\CSS_Optimize', 'optimize');
         }
         if ($oParams->get('js_minify', 0)) {
             $aOptions['jsMinifier'] = array('JchOptimize\\JS_Optimize', 'optimize');
         }
         $aOptions['minifyLevel'] = $oParams->get('html_minify_level', 2);
         $aOptions['isXhtml'] = (bool) $oParams->get('isXhtml', false);
         $aOptions['isHtml5'] = (bool) $oParams->get('isHtml5', false);
         $sHtmlMin = HTML_Optimize::optimize($sHtml, $aOptions);
         if ($sHtmlMin == '') {
             JchOptimizeLogger::log('Error while minifying HTML', $oParams);
             $sHtmlMin = $sHtml;
         }
         $sHtml = $sHtmlMin;
         JCH_DEBUG ? JchPlatformProfiler::stop('MinifyHtml', TRUE) : null;
     }
     return $sHtml;
 }