Пример #1
0
 public function replaceCdnImages($aMatches)
 {
     $sImage = trim(trim($aMatches[1], '"'), "'");
     $sActualFile = rtrim($this->_sStyleDir, '/') . str_replace('..', '', $sImage);
     if (file_exists($sActualFile)) {
         $aParts = explode('upload/', $this->_sStyleDir);
         $sUrl = Phpfox::getParam('core.rackspace_url') . $aParts[1];
         Phpfox::getLib('cdn')->put($sActualFile, $aParts[1] . str_replace('..', '', $sImage));
     } else {
         $sUrl = Phpfox::getCdnPath() . 'theme/frontend/default/style/default';
     }
     $sImage = str_replace('..', $sUrl, $sImage);
     return 'url(\'' . $sImage . '\')';
 }
Пример #2
0
 public function minify($aFiles, $sVersion, $bIsJS = true, $bDoInit = false, $bReturn = false, $bReplaceUrl = true)
 {
     static $oFormat = null;
     if (!isset($oFormat)) {
         $oFormat = Phpfox::getLib('parse.format');
     }
     if (!is_array($aFiles)) {
         $aFiles = array($aFiles);
     }
     $sHash = md5(implode($aFiles) . $sVersion);
     $sNameMd5 = md5(implode($aFiles) . $sVersion) . ($bIsJS ? '.js' : '.css');
     $sFilePath = PHPFOX_DIR_FILE . 'static' . PHPFOX_DS . $sNameMd5;
     $sUrl = Phpfox::getParam('core.path') . 'file/static/' . $sNameMd5;
     $bExists = false;
     if (Phpfox::getParam('core.allow_cdn') && Phpfox::getParam('core.push_jscss_to_cdn')) {
         $sCacheId = Phpfox::getLib('cache')->set(array('jscss', $sHash));
         if (Phpfox::getLib('cache')->get($sCacheId)) {
             $bExists = true;
         }
     } else {
         $bExists = file_exists($sFilePath);
     }
     if ($bExists) {
         if (Phpfox::getParam('core.allow_cdn') && Phpfox::getParam('core.push_jscss_to_cdn')) {
             $sUrl = Phpfox::getLib('cdn')->getUrl($sUrl);
         }
     } else {
         $sMinified = '';
         if ($bIsJS) {
             foreach ($aFiles as $sFile) {
                 $sOriginal = file_get_contents(PHPFOX_DIR . $sFile);
                 $oJsMin = new JSMin($sOriginal);
                 $sCompressed = $oJsMin->min();
                 // $sCompressed = $oFormat->helpJS($sCompressed);
                 $sMinified .= "\n /* {$sFile} */" . $sCompressed;
             }
         } else {
             $sHomeThemePath = Phpfox::getParam('core.force_https_secure_pages') && Phpfox::getParam('core.force_secure_site') ? 'https://' : 'http://';
             $sHomeThemePath .= Phpfox::getParam('core.host') . Phpfox::getParam('core.folder') . 'theme';
             foreach ($aFiles as $sFile) {
                 $sOriginal = file_get_contents(PHPFOX_DIR . $sFile);
                 $sCompressed = str_replace(array("\r\n", "\r", "\n", "\t", '  ', '    ', '    '), ' ', $sOriginal);
                 $sPathTo = substr($sFile, 0, strrpos($sFile, '/'));
                 $sPathTo = substr($sPathTo, 0, strrpos($sPathTo, '/'));
                 if (Phpfox::getParam('core.allow_cdn') && Phpfox::getParam('core.push_jscss_to_cdn') && defined('PHPFOX_IS_HOSTED_SCRIPT')) {
                     $sCompressed = str_replace('url(\'..', 'url(\'' . Phpfox::getCdnPath() . '' . $sPathTo, $sCompressed, $iCount);
                     $sCompressed = str_replace('url("..', 'url("' . Phpfox::getCdnPath() . '' . $sPathTo, $sCompressed, $iCount);
                     $sCompressed = str_replace('url(..', 'url(' . Phpfox::getCdnPath() . '' . $sPathTo, $sCompressed, $iCount);
                 } else {
                     if ($bReplaceUrl == true) {
                         $sCompressed = str_replace('url(\'..', 'url(\'../../' . $sPathTo, $sCompressed, $iCount);
                         $sCompressed = str_replace('url("..', 'url("../../' . $sPathTo, $sCompressed, $iCount);
                         $sCompressed = str_replace('url(..', 'url(../../' . $sPathTo, $sCompressed, $iCount);
                         $sCompressed = str_replace('../../theme', '' . $sHomeThemePath, $sCompressed, $iCount);
                     }
                 }
                 if ($bReplaceUrl == true) {
                     $sCompressed = str_replace('css/', 'image/', $sCompressed);
                 }
                 $sMinified .= $sCompressed;
             }
         }
         if ($bReturn == true) {
             return $sMinified;
         }
         if ($bIsJS && $bDoInit) {
             $sMinified .= "\n" . '$Core.init();';
         }
         file_put_contents($sFilePath, $sMinified);
         // if cdn enabled put it in cdn as well here
         if (Phpfox::getParam('core.allow_cdn') && Phpfox::getParam('core.push_jscss_to_cdn')) {
             Phpfox::getLib('cache')->save($sCacheId, '1');
             Phpfox::getLib('cdn')->put($sFilePath);
             $sUrl = Phpfox::getLib('cdn')->getUrl($sUrl);
         }
     }
     return $sUrl . $sVersion;
 }