示例#1
0
 /**
  * 
  * @param type $sType
  * @param type $sExclude
  * @return type
  */
 protected function getOptions($sType, $sExclude = 'files')
 {
     $aLinks = $this->links;
     $aOptions = array();
     if (!empty($aLinks[$sType][0])) {
         foreach ($aLinks[$sType][0] as $aLink) {
             if (isset($aLink['url']) && $aLink['url'] != '') {
                 if ($sExclude == 'files') {
                     $sFile = $this->prepareFileValues($aLink['url'], 'pre');
                     $sFile = $aOptions[$sFile] = $this->prepareFileValues($sFile, 'post');
                 } elseif ($sExclude == 'extensions') {
                     $sExtension = $this->prepareExtensionValues($aLink['url'], FALSE);
                     if ($sExtension === FALSE) {
                         continue;
                     }
                     $aOptions[$sExtension] = $sExtension;
                 }
             } elseif (isset($aLink['content']) && $aLink['content'] != '') {
                 if ($sExclude == 'scripts') {
                     $sScript = JchOptimize\HTML_Optimize::cleanScript($aLink['content'], 'js');
                     $sScript = trim(JchOptimize\JS_Optimize::optimize($sScript));
                     if (strlen($sScript) > 60) {
                         $sScript = substr($sScript, 0, 60);
                     }
                     $aOptions[addslashes($sScript)] = $this->prepareScriptValues($sScript);
                 }
             }
         }
     }
     return $aOptions;
 }
示例#2
0
        /**
         * Callback function used to remove urls of css and js files in head tags
         *
         * @param array $aMatches       Array of all matches
         * @return string               Returns the url if excluded, empty string otherwise
         */
        public function replaceScripts($aMatches, $aCBArgs)
        {
//                JCH_DEBUG ? JchPlatformProfiler::mark('beforeReplaceScript plgSystem (JCH Optimize)') : null; 

                $sUrl         = isset($aMatches[1]) && $aMatches[1] != '' ? $aMatches[1] : (isset($aMatches[3]) ? $aMatches[3] : '');
                $sDeclaration = isset($aMatches[2]) && $aMatches[2] != '' ? $aMatches[2] : (isset($aMatches[4]) ? $aMatches[4] : '');

                if (preg_match('#^<!--#', $aMatches[0])
                        || ((trim($sUrl) == '' || trim($sUrl) == '/') && trim($sDeclaration) == ''))
                {
                        return $aMatches[0];
                }

                $sType = preg_match('#^<script#i', $aMatches[0]) ? 'js' : 'css';

                if ($sType == 'js' && !$this->params->get('javascript', '1'))
                {
                        return $aMatches[0];
                }

                if ($sType == 'css' && !$this->params->get('css', '1'))
                {
                        return $aMatches[0];
                }

                $this->bPreserveOrder = (bool) !(($sType == 'css' && $this->params->get('pro_optimizeCssDelivery', '0'))
                        || ($this->params->get('bottom_js', '0'))
                        || ($sType == 'js' && $this->params->get('bottom_js', '0') == '1'));


                $aExcludes = array();

                if (isset($aCBArgs['excludes']))
                {
                        $aExcludes = $aCBArgs['excludes'];
                }

                $sMedia = '';

                if (($sType == 'css') && (preg_match('#media=(?(?=["\'])(?:["\']([^"\']+))|(\w+))#i', $aMatches[0], $aMediaTypes) > 0))
                {
                        $sMedia .= $aMediaTypes[1] ? $aMediaTypes[1] : $aMediaTypes[2];
                }

//                JCH_DEBUG ? JchPlatformProfiler::mark('beforeReplaceScript - ' . $sFile . ' plgSystem (JCH Optimize)') : null;

                switch (TRUE)
                {
                        case (($sUrl != '') && $this->isDuplicated($sUrl)):

                                $this->{'bExclude_' . $sType} = FALSE;

                                return '';

                        case (($sUrl != '') && !empty($aExcludes[$sType]) && JchOptimizeHelper::findExcludes($aExcludes[$sType], $sUrl)):
                        case (($sUrl != '') && $this->isHttpAdapterAvailable($sUrl)):
                        case ($sUrl != '' && preg_match('#^https#', $sUrl) && !extension_loaded('openssl')):
                        case ($sUrl != '' && preg_match('#^data:#', $sUrl)):
                        case ($sDeclaration != '' && $this->excludeDeclaration($sType)):
                        case ($sDeclaration != '' && JchOptimizeHelper::findExcludes($aExcludes['script'], $sDeclaration, TRUE)):
                        case (($sUrl != '') && $this->excludeExternalExtensions($sUrl)):

//                        JCH_DEBUG ? JchPlatformProfiler::mark('afterSkipScript - ' . $sFile . ' plgSystem (JCH Optimize)') : null;

                                $this->{'bExclude_' . $sType} = TRUE;

                                return $aMatches[0];

                        default:
//                        JCH_DEBUG ? JchPlatformProfiler::mark('afterTestScript - ' . $sFile . ' plgSystem (JCH Optimize)') : null;                                
                                $return = '';

                                if ($this->{'bExclude_' . $sType} && $this->bPreserveOrder)
                                {
                                        $this->{'bExclude_' . $sType} = FALSE;

                                        $iIndex = ++$this->{'iIndex_' . $sType};
                                        $return = '<JCH_' . strtoupper($sType) . $iIndex . '>';
                                }
                                elseif (!$this->bPreserveOrder)
                                {
                                        $iIndex = 0;
                                }
                                else
                                {
                                        $iIndex = $this->{'iIndex_' . $sType};
                                }

                                $array = array();

                                $array['match'] = $aMatches[0];

                                if ($sUrl == '' && trim($sDeclaration) != '')
                                {
                                        $content = JchOptimize\HTML_Optimize::cleanScript($sDeclaration);

                                        $array['content'] = $content;
                                        $id               = $content;
                                }
                                else
                                {
                                        $array['url']  = $sUrl;
                                        $id            = $sUrl;
                                }

                                if ($this->sFileHash != '')
                                {
                                        $array['id'] = md5($this->sFileHash . $id);
                                }

                                if ($sType == 'css')
                                {
                                        $array['media'] = $sMedia;
                                }

                                $this->aLinks[$sType][$iIndex][] = $array;

//JCH_DEBUG ? JchPlatformProfiler::mark('afterReplaceScript - ' . $sFile . ' plgSystem (JCH Optimize)') : null;
                                return $return;
                }
        }
示例#3
0
 /**
  * Callback function used to remove urls of css and js files in head tags
  *
  * @param array $aMatches       Array of all matches
  * @return string               Returns the url if excluded, empty string otherwise
  */
 public function replaceScripts($aMatches, $aCBArgs)
 {
     $sUrl = $aMatches['url'] = isset($aMatches[1]) && $aMatches[1] != '' ? $aMatches[1] : (isset($aMatches[3]) ? $aMatches[3] : '');
     $sDeclaration = isset($aMatches[2]) && $aMatches[2] != '' ? $aMatches[2] : (isset($aMatches[4]) ? $aMatches[4] : '');
     if (preg_match('#^<!--#', $aMatches[0]) || (trim($sUrl) == '' || trim($sUrl) == '/') && trim($sDeclaration) == '') {
         return $aMatches[0];
     }
     $sType = preg_match('#^<script#i', $aMatches[0]) ? 'js' : 'css';
     if ($sType == 'js' && !$this->params->get('javascript', '1')) {
         return $aMatches[0];
     }
     if ($sType == 'css' && !$this->params->get('css', '1')) {
         return $aMatches[0];
     }
     $this->bPreserveOrder = (bool) (!($sType == 'css' && $this->params->get('pro_optimizeCssDelivery_enable', '0') || $this->params->get('bottom_js', '0') || $sType == 'js' && $this->params->get('bottom_js', '0') == '1'));
     $aExcludes = array();
     if (isset($aCBArgs['excludes'])) {
         $aExcludes = $aCBArgs['excludes'];
     }
     $aRemovals = array();
     if (isset($aCBArgs['removals'])) {
         $aRemovals = $aCBArgs['removals'];
     }
     $sMedia = '';
     if ($sType == 'css' && preg_match('#media=(?(?=["\'])(?:["\']([^"\']+))|(\\w+))#i', $aMatches[0], $aMediaTypes) > 0) {
         $sMedia .= $aMediaTypes[1] ? $aMediaTypes[1] : $aMediaTypes[2];
     }
     switch (TRUE) {
         case $sUrl != '' && !empty($aExcludes[$sType]) && JchOptimizeHelper::findExcludes($aExcludes[$sType], $sUrl):
         case $sUrl != '' && $this->isHttpAdapterAvailable($sUrl):
         case $sUrl != '' && preg_match('#^https#', $sUrl) && !extension_loaded('openssl'):
         case $sUrl != '' && preg_match('#^data:#', $sUrl):
         case $sDeclaration != '' && $this->excludeDeclaration($sType):
         case $sDeclaration != '' && JchOptimizeHelper::findExcludes($aExcludes[$sType . '_script'], $sDeclaration, $sType):
         case $sUrl != '' && $this->excludeExternalExtensions($sUrl):
             $this->{'bExclude_' . $sType} = TRUE;
             return $aMatches[0];
         case $sUrl != '' && $this->isDuplicated($sUrl):
         case $sUrl != '' && !empty($aRemovals[$sType]) && JchOptimizeHelper::findExcludes($aRemovals[$sType], $sUrl):
             return '';
         default:
             $return = '';
             if ($this->{'bExclude_' . $sType} && $this->bPreserveOrder) {
                 $this->{'bExclude_' . $sType} = FALSE;
                 $iIndex = ++$this->{'iIndex_' . $sType};
                 $return = '<JCH_' . strtoupper($sType) . $iIndex . '>';
             } elseif (!$this->bPreserveOrder) {
                 $iIndex = 0;
             } else {
                 $iIndex = $this->{'iIndex_' . $sType};
             }
             $array = array();
             $array['match'] = $aMatches[0];
             if ($sUrl == '' && trim($sDeclaration) != '') {
                 $content = JchOptimize\HTML_Optimize::cleanScript($sDeclaration, $sType);
                 $array['content'] = $content;
             } else {
                 $array['url'] = $sUrl;
             }
             if ($this->sFileHash != '') {
                 $array['id'] = $this->getFileID($aMatches);
             }
             if ($sType == 'css') {
                 $array['media'] = $sMedia;
             }
             $this->aLinks[$sType][$iIndex][] = $array;
             return $return;
     }
 }
示例#4
0
 /**
  * Callback function used to remove urls of css and js files in head tags
  *
  * @param array $aMatches       Array of all matches
  * @return string               Returns the url if excluded, empty string otherwise
  */
 public function replaceScripts($aMatches, $aCBArgs, $sSection)
 {
     $sUrl = isset($aMatches[1]) && $aMatches[1] != '' ? $aMatches[1] : (isset($aMatches[4]) ? $aMatches[4] : '');
     $sFile = isset($aMatches[2]) && $aMatches[2] != '' ? $aMatches[2] : (isset($aMatches[5]) ? $aMatches[5] : '');
     $sDeclaration = isset($aMatches[3]) && $aMatches[3] != '' ? $aMatches[3] : (isset($aMatches[6]) ? $aMatches[6] : '');
     if (preg_match('#^<!--#', $aMatches[0]) || (trim($sUrl) == '' || trim($sUrl) == '/') && trim($sDeclaration) == '') {
         return $aMatches[0];
     }
     $sType = preg_match('#^<script#i', $aMatches[0]) ? 'js' : 'css';
     if ($sType == 'js' && !$this->params->get('javascript', '1')) {
         return $aMatches[0];
     }
     if ($sType == 'css' && !$this->enableCssCompression()) {
         return $aMatches[0];
     }
     $this->bPreserveOrder = (bool) (!($sType == 'css' && $this->params->get('pro_optimizeCssDelivery', '0') || $this->params->get('bottom_js', '0') || $sType == 'js' && $this->params->get('bottom_js', '0') == '1'));
     $aExcludes = array();
     $sPath = '';
     if (isset($aCBArgs['excludes'])) {
         $aExcludes = $aCBArgs['excludes'];
     }
     $aExcludes['script'] = array_map(function ($sScript) {
         return stripslashes($sScript);
     }, $aExcludes['script']);
     $aExcludes['js'] = array_merge($aExcludes['js'], array('.com/maps/api/js', '.com/jsapi', '.com/uds', 'typekit.net'), JchPlatformExcludes::head('js'));
     $aExcludes['css'] = array_merge($aExcludes['css'], array('fonts.googleapis.com'), JchPlatformExcludes::head('css'));
     if ($sSection == 'body') {
         $aExcludes['script'] = array_merge($aExcludes['script'], array('document.write'), JchPlatformExcludes::body('js', 'script'));
         $aExcludes['js'] = array_merge($aExcludes['js'], array('.com/recaptcha/api'), JchPlatformExcludes::body('js'));
     }
     if ($sUrl != '') {
         $sPath .= JchOptimizeHelper::getFilePath($sUrl);
     }
     $sMedia = '';
     if ($sType == 'css' && preg_match('#media=(?(?=["\'])(?:["\']([^"\']+))|(\\w+))#i', $aMatches[0], $aMediaTypes) > 0) {
         $sMedia .= $aMediaTypes[1] ? $aMediaTypes[1] : $aMediaTypes[2];
     }
     //JCH_DEBUG ? JchPlatformProfiler::mark('beforeReplaceScript - ' . $sFile . ' plgSystem (JCH Optimize)') : null;
     switch (TRUE) {
         case $sUrl != '' && $this->isDuplicated($sUrl):
             $this->{'bExclude_' . $sType} = FALSE;
             return '';
         case $sUrl != '' && !empty($aExcludes[$sType]) && JchOptimizeHelper::findExcludes($aExcludes[$sType], $sUrl):
         case $sPath != '' && $this->isHttpAdapterAvailable($sPath):
         case $sUrl != '' && preg_match('#^https#', $sUrl) && !extension_loaded('openssl'):
         case $sUrl != '' && preg_match('#^data:#', $sUrl):
         case $sDeclaration != '' && $this->excludeDeclaration($sType):
         case $sDeclaration != '' && JchOptimizeHelper::findExcludes($aExcludes['script'], $sDeclaration, TRUE):
         case $sUrl != '' && $this->excludeExternalExtensions($sUrl):
             //JCH_DEBUG ? JchPlatformProfiler::mark('afterReplaceScript - ' . $sFile . ' plgSystem (JCH Optimize)') : null;
             $this->{'bExclude_' . $sType} = TRUE;
             return $aMatches[0];
         default:
             $return = '';
             if ($this->{'bExclude_' . $sType} && $this->bPreserveOrder) {
                 $this->{'bExclude_' . $sType} = FALSE;
                 $iIndex = ++$this->{'iIndex_' . $sType};
                 $return = '<JCH_' . strtoupper($sType) . $iIndex . '>';
             } elseif (!$this->bPreserveOrder) {
                 $iIndex = 0;
             } else {
                 $iIndex = $this->{'iIndex_' . $sType};
             }
             $array = array();
             $array['match'] = $aMatches[0];
             if ($sUrl == '' && trim($sDeclaration) != '') {
                 $content = JchOptimize\HTML_Optimize::cleanScript($sDeclaration);
                 $array['content'] = $content;
                 $id = $content;
             } else {
                 $array['url'] = $sUrl;
                 $array['path'] = $sPath;
                 $array['file'] = $sFile;
                 $id = $sUrl;
             }
             if ($this->sFileHash != '') {
                 $array['id'] = md5($this->sFileHash . $id);
             }
             if ($sType == 'css') {
                 $array['media'] = $sMedia;
             }
             $this->aLinks[$sType][$iIndex][] = $array;
             return $return;
     }
 }