示例#1
0
 /**
  * 
  * @param type $sExcludeParams
  * @param type $sField
  * @return type
  */
 public function prepareFieldOptions($sType, $sExcludeParams, $sGroup = '')
 {
     if ($sType == 'lazyload') {
         $sGroup = 'file';
         $aFieldOptions = $this->getLazyLoad();
     } elseif ($sType == 'images') {
         $sGroup = $sType;
         $aM = explode('_', $sExcludeParams);
         $aFieldOptions = $this->getImages($aM[1]);
     } else {
         $aFieldOptions = $this->getOptions($sType, $sGroup . 's');
     }
     $aOptions = array();
     $oParams = $this->params;
     $aExcludes = JchOptimizeHelper::getArray($oParams->get($sExcludeParams, array()));
     foreach ($aExcludes as $sExclude) {
         $aOptions[$sExclude] = $this->{'prepare' . ucfirst($sGroup) . 'Values'}($sExclude);
     }
     return array_unique(array_merge($aFieldOptions, $aOptions));
     return $aFieldOptions;
 }
示例#2
0
 /**
  * 
  * @return string
  */
 public function getLazyLoadRegex($admin = FALSE)
 {
     $sRegex = '#(?><?[^<]*+(?:<script\\b[^>]*+>(?><?[^<]*+)*?</script>)?)*?' . '\\K(?:(<img(?!(?>\\s*+[^\\s>]*+)*?\\s*+(?>data-(?:src|original)';
     $aExcludeClass = JchOptimizeHelper::getArray($this->params->get('pro_excludeLazyLoadClass', array()));
     if (!empty($aExcludeClass)) {
         $aExcludeClass = array_map(function ($sValue) {
             return '\\b' . preg_quote($sValue) . '\\b';
         }, $aExcludeClass);
         $sExcludeClass = implode('|', $aExcludeClass);
         $sRegex .= '|class\\s*+=\\s*+[\'"]?[^\'">]*?(?>' . $sExcludeClass . ')';
     }
     $sRegex .= '))';
     if ($admin) {
         $sRegex .= '(?:(?=(?>\\s*+[^\\s>]*+)*?\\s*+class\\s*+=\\s*+[\'"]?([^\'">]*+)))?';
     }
     $sRegex .= '(?>\\s*+[^\\s>]*+)*?\\s*+)(src\\s*+=\\s*+(?![\'"]?[^\'"> ]*?(?:data:image';
     $aExcludesFiles = JchOptimizeHelper::getArray($this->params->get('pro_excludeLazyLoad', array()));
     $aExcludesFolders = JchOptimizeHelper::getArray($this->params->get('pro_excludeLazyLoadFolders', array()));
     $aExcludes = array_merge($aExcludesFiles, $aExcludesFolders);
     if (!empty($aExcludes)) {
         $aExcludes = array_map(function ($sValue) {
             return preg_quote($sValue);
         }, $aExcludes);
         $sExcludes = implode('|', $aExcludes);
         $sRegex .= '|' . $sExcludes;
     }
     $sRegex .= '))[\'"]?((?(?<=[\'"])[^\'"]*+|[^\\s>]*+))[\'"]?)([^>]*+>)|\\K$)#i';
     return $sRegex;
 }
示例#3
0
        /**
         * Generates regex for excluding components set in plugin params
         * 
         * @param string $param
         * @return string
         */
        protected function getExComp($sExComParam)
        {
                $aComponents = JchOptimizeHelper::getArray($sExComParam);
                $aExComp     = array();

                if (!empty($aComponents))
                {
                        $aExComp = array_map(function($sValue)
                        {
                                return $sValue . '/';
                        }, $aComponents);
                }

                return $aExComp;
        }
示例#4
0
 /**
  * Determines if js file should be loaded asynchronously. Would be aggregated otherwise.
  * 
  * @param type $sPath    File path
  * @return boolean
  */
 protected function loadAsync($sUrl = '')
 {
     return JchOptimizeHelper::findExcludes(JchOptimizeHelper::getArray($this->params->get('pro_loadFilesAsync', '')), $sUrl);
 }
示例#5
0
文件: parser.php 项目: grlf/eyedock
 /**
  * 
  * @return string
  */
 public function getLazyLoadRegex()
 {
     $sRegex = '#(?><?[^<]*+(?:<script\\b[^>]*+>(?><?[^<]*+)*?</script>)?)*?(?:<img(?!(?>\\s*+[^\\s>]*+)*?\\s*+data-src)' . '(?>\\s*+[^\\s>]*+)*?\\s*+\\Ksrc\\s*+=\\s*+(?![\'"]?(?:data:image';
     $aExcludes = JchOptimizeHelper::getArray($this->params->get('pro_excludeLazyLoad', array()));
     if (!empty($aExcludes)) {
         $aExcludes = array_map(function ($sValue) {
             return preg_quote($sValue);
         }, $aExcludes);
         $sExcludes = implode('|', $aExcludes);
         $sRegex .= '|' . $sExcludes;
     }
     $sRegex .= '))[\'"]?((?(?<=[\'"])[^\'"]*+|[^\\s>]*+))[\'"]?|\\K$)#i';
     return $sRegex;
 }
示例#6
0
 /**
  * Uses regex to find css declarations containing background images to include in sprite
  * 
  * @param string $sCss  Aggregated css file
  * @return array        Array of css declarations and image urls to replace with sprite
  */
 public function processCssUrls($sCss, $bBackend = FALSE)
 {
     JCH_DEBUG ? JchPlatformProfiler::start('ProcessCssUrls') : null;
     $params = $this->params;
     $aRegexStart = array();
     $aRegexStart[0] = '
                     #(?:{
                             (?=\\s*+(?>[^}\\s:]++[\\s:]++)*?url\\(
                                     (?=[^)]+\\.(?:png|gif|jpe?g))
                             ([^)]+)\\))';
     $aRegexStart[1] = '
                     (?=\\s*+(?>[^}\\s:]++[\\s:]++)*?no-repeat)';
     $aRegexStart[2] = '
                     (?(?=\\s*(?>[^};]++[;\\s]++)*?background(?:-position)?\\s*+:\\s*+(?:[^;}\\s]++[^}\\S]++)*?
                             (?<p>(?:[tblrc](?:op|ottom|eft|ight|enter)|-?[0-9]+(?:%|[c-x]{2})?))(?:\\s+(?&p))?)
                                     (?=\\s*(?>[^};]++[;\\s]++)*?background(?:-position)?\\s*+:\\s*+(?>[^;}\\s]++[\\s]++)*?
                                             (?:left|top|0(?:%|[c-x]{2})?)\\s+(?:left|top|0(?:%|[c-x]{2})?)
                                     )
                     )';
     $sRegexMiddle = '   
                     [^{}]++} )';
     $sRegexEnd = '#isx';
     $aIncludeImages = JchOptimizeHelper::getArray($params->get('csg_include_images'));
     $aExcludeImages = JchOptimizeHelper::getArray($params->get('csg_exclude_images'));
     $sIncImagesRegex = '';
     if (!empty($aIncludeImages[0])) {
         foreach ($aIncludeImages as &$sImage) {
             $sImage = preg_quote($sImage, '#');
         }
         $sIncImagesRegex .= '
                             |(?:{
                                     (?=\\s*+(?>[^}\\s:]++[\\s:]++)*?url';
         $sIncImagesRegex .= ' (?=[^)]* [/(](?:' . implode('|', $aIncludeImages) . ')\\))';
         $sIncImagesRegex .= '\\(([^)]+)\\)
                                     )
                                     [^{}]++ })';
     }
     $sExImagesRegex = '';
     if (!empty($aExcludeImages[0])) {
         $sExImagesRegex .= '(?=\\s*+(?>[^}\\s:]++[\\s:]++)*?url\\(
                                                     [^)]++  (?<!';
         foreach ($aExcludeImages as &$sImage) {
             $sImage = preg_quote($sImage, '#');
         }
         $sExImagesRegex .= implode('|', $aExcludeImages) . ')\\)
                                                     )';
     }
     $sRegexStart = implode('', $aRegexStart);
     $sRegex = $sRegexStart . $sExImagesRegex . $sRegexMiddle . $sIncImagesRegex . $sRegexEnd;
     if (preg_match_all($sRegex, $sCss, $aMatches) === FALSE) {
         throw new Exception('Error occurred matching for images to sprite');
     }
     if (isset($aMatches[3])) {
         $total = count($aMatches[1]);
         for ($i = 0; $i < $total; $i++) {
             $aMatches[1][$i] = trim($aMatches[1][$i]) ? $aMatches[1][$i] : $aMatches[3][$i];
         }
     }
     if ($bBackend) {
         $aImages = array();
         $aImagesMatches = array();
         $aImgRegex = array();
         $aImgRegex[0] = $aRegexStart[0];
         $aImgRegex[2] = $aRegexStart[1];
         $aImgRegex[4] = $sRegexMiddle;
         $aImgRegex[5] = $sRegexEnd;
         $sImgRegex = implode('', $aImgRegex);
         if (preg_match_all($sImgRegex, $sCss, $aImagesMatches) === FALSE) {
             throw new Exception('Error occurred matching for images to include');
         }
         $aImagesMatches[0] = array_diff($aImagesMatches[0], $aMatches[0]);
         $aImagesMatches[1] = array_diff($aImagesMatches[1], $aMatches[1]);
         $oImageLibrary = $this->getImageLibrary();
         if ($oImageLibrary === FALSE) {
             return array();
         }
         $oCssSpriteGen = new CssSpriteGen($oImageLibrary, $this->params, $bBackend);
         $aImages['include'] = $oCssSpriteGen->CreateSprite($aImagesMatches[1]);
         $aImages['exclude'] = $oCssSpriteGen->CreateSprite($aMatches[1]);
         return $aImages;
     }
     JCH_DEBUG ? JchPlatformProfiler::stop('ProcessCssUrls', TRUE) : null;
     return $aMatches;
 }