Example #1
0
 /**
  * Fetches HTML to be sent to browser
  * 
  * @return string
  */
 public function getHtml()
 {
     $sHtml = preg_replace($this->getHeadRegex(), JchOptimizeHelper::cleanReplacement($this->sHeadHtml), $this->sHtml, 1);
     if (is_null($sHtml) || $sHtml == '') {
         throw new Exception('Error occured while trying to get html');
     }
     return $sHtml;
 }
Example #2
0
 /**
  * Prepare links for the combined files and insert them in the processed HTML
  * 
  */
 public function insertJchLinks()
 {
     $aLinks = $this->oParser->getReplacedFiles();
     if (!JchOptimizeHelper::isMsieLT10() && $this->params->get('combine_files_enable', '1')) {
         if ($this->params->get('htaccess', 2) == 2) {
             JchOptimizeHelper::checkModRewriteEnabled($this->params);
         }
         $replace_css_links = FALSE;
         if ($this->params->get('css', 1) && !empty($aLinks['css'])) {
             $sCssCacheId = $this->getCacheId($aLinks['css']);
             $sCssCache = $this->getCombinedFiles($aLinks['css'], $sCssCacheId, 'css');
             if ($this->params->get('pro_optimizeCssDelivery_enable', '0')) {
                 $sCriticalCss = '<style type="text/css">' . $this->sLnEnd . $sCssCache['criticalcss'] . $this->sLnEnd . '</style>' . $this->sLnEnd . '</head>';
                 $sHeadHtml = preg_replace('#</head>#i', JchOptimizeHelper::cleanReplacement($sCriticalCss), $this->oParser->getHeadHtml(), 1);
                 $this->oParser->setSearchArea($sHeadHtml, 'head');
                 $sUrl = $this->buildUrl($sCssCacheId, 'css');
                 $sUrl = str_replace('JCHI', '0', $sUrl);
                 $this->loadCssAsync($sUrl);
             } else {
                 $replace_css_links = TRUE;
             }
         }
         if ($this->params->get('javascript', 1) && !empty($aLinks['js'])) {
             $sJsCacheId = $this->getCacheId($aLinks['js']);
             $this->getCombinedFiles($aLinks['js'], $sJsCacheId, 'js');
             $this->replaceLinks($sJsCacheId, 'js');
         }
         if ($replace_css_links) {
             $this->replaceLinks($sCssCacheId, 'css');
         }
     }
     if (!empty($aLinks['img'])) {
         $this->addImgAttributes($aLinks['img']);
     }
     $this->runCronTasks();
 }
 /**
  * Returns processed html to be sent to the browser
  * 
  * @return string
  */
 public function getHtml()
 {
     $sHtml = parent::getHtml();
     if ($this->sBodyHtml != '') {
         $sHtml = preg_replace($this->getBodyRegex(), JchOptimizeHelper::cleanReplacement($this->sBodyHtml), $sHtml, 1);
         if (is_null($sHtml) || $sHtml == '') {
             throw new Exception('Error occured while trying to get HTML');
         }
     }
     return $sHtml;
 }