Пример #1
0
 /**
  * Determines if file requires http protocol to get contents (Not allowed)
  * 
  * @param string $sUrl
  * @return boolean
  */
 public function isHttpAdapterAvailable($sUrl)
 {
     return !(preg_match('#^(?:http|//)#i', $sUrl) && !JchOptimizeUrl::isInternal($sUrl) || $this->isPHPFile($sUrl));
 }
Пример #2
0
 /**
  * Callback function to correct urls in aggregated css files
  *
  * @param array $aMatches Array of all matches
  * @return string         Correct url of images from aggregated css file
  */
 public function _correctUrlCB($aMatches, $aUrl)
 {
     if (empty($aMatches[1]) || preg_match('#^(?:\\(|/\\*)#', $aMatches[0])) {
         return $aMatches[0];
     }
     $sImageUrl = $aMatches[1];
     $sCssFileUrl = empty($aUrl['url']) ? '' : $aUrl['url'];
     if (JchOptimizeUrl::isHttpScheme($sImageUrl)) {
         if ((JchOptimizeUrl::isInternal($sCssFileUrl) || $sCssFileUrl == '') && JchOptimizeUrl::isInternal($sImageUrl)) {
             $sImageUrl = JchOptimizeUrl::toRootRelative($sImageUrl, $sCssFileUrl);
             $oImageUri = clone JchPlatformUri::getInstance($sImageUrl);
             $aStaticFiles = $this->params->get('pro_staticfiles', array('css', 'js', 'jpe?g', 'gif', 'png', 'ico', 'bmp', 'pdf'));
             unset($aStaticFiles[0]);
             $sStaticFiles = implode('|', $aStaticFiles);
             $aFontFiles = $this->fontFiles();
             $sFontFiles = implode('|', $aFontFiles);
             if (preg_match('#\\.(?>' . $sStaticFiles . ')#', $oImageUri->getPath())) {
                 $sImageUrl = JchOptimizeHelper::cookieLessDomain($this->params, $oImageUri->toString(array('path')));
             } elseif ($this->params->get('pro_cookielessdomain_enable', '0') && preg_match('#\\.(?>' . $sFontFiles . ')#', $oImageUri->getPath())) {
                 $oUri = clone JchPlatformUri::getInstance();
                 $sImageUrl = '//' . $oUri->toString(array('host', 'port')) . $oImageUri->toString(array('path'));
             }
         } else {
             if (!JchOptimizeUrl::isAbsolute($sImageUrl)) {
                 $sImageUrl = JchOptimizeUrl::toAbsolute($sImageUrl, $sCssFileUrl);
             }
         }
     }
     $sImageUrl = preg_match('#(?<!\\\\)[\\s\'"(),]#', $sImageUrl) ? '"' . $sImageUrl . '"' : $sImageUrl;
     return $sImageUrl;
 }
Пример #3
0
 /**
  * Get local path of file from the url if internal
  * If external or php file, the url is returned
  *
  * @param string  $sUrl  Url of file
  * @return string       File path
  */
 public static function getFilePath($sUrl)
 {
     $sUriPath = JchPlatformUri::base(TRUE);
     $oUri = clone JchPlatformUri::getInstance();
     $oUrl = clone JchPlatformUri::getInstance(html_entity_decode($sUrl));
     //Use absolute file path if file is internal and a static file
     if (JchOptimizeUrl::isInternal($sUrl) && !JchOptimizeUrl::requiresHttpProtocol($sUrl)) {
         return JchPlatformPaths::absolutePath(str_replace($sUriPath, '', $oUrl->getPath()));
     } else {
         $scheme = $oUrl->getScheme();
         if (empty($scheme)) {
             $oUrl->setScheme($oUri->getScheme());
         }
         $host = $oUrl->getHost();
         if (empty($host)) {
             $oUrl->setHost($oUri->getHost());
         }
         $path = $oUrl->getPath();
         if (!empty($path)) {
             if (substr($path, 0, 1) != '/') {
                 $oUrl->setPath($sUriPath . '/' . $path);
             }
         }
         $sUrl = $oUrl->toString();
         $query = $oUrl->getQuery();
         if (!empty($query)) {
             parse_str($query, $args);
             $sUrl = str_replace($query, http_build_query($args, '', '&'), $sUrl);
         }
         return $sUrl;
     }
 }
Пример #4
0
 /**
  * 
  * @param type $sPath
  */
 protected function excludeExternalExtensions($sPath)
 {
     if (!$this->params->get('includeAllExtensions', '0')) {
         return !JchOptimizeUrl::isInternal($sPath) || preg_match('#' . JchPlatformExcludes::extensions() . '#i', $sPath);
     }
     return FALSE;
 }
Пример #5
0
 /**
  * 
  * @param type $sUrl
  * @return type
  */
 public static function prepareFileValues($sFile, $sType = '', $iLen = 27)
 {
     if ($sType != 'value') {
         $oFile = JchPlatformUri::getInstance($sFile);
         if (JchOptimizeUrl::isInternal($sFile)) {
             $sFile = $oFile->getPath();
         } else {
             $sFile = $oFile->toString(array('scheme', 'user', 'pass', 'host', 'port', 'path'));
         }
         if ($sType == 'key') {
             return $sFile;
         }
     }
     $sEps = '';
     if (strlen($sFile) > $iLen) {
         $sFile = substr($sFile, -$iLen);
         $sFile = preg_replace('#^[^/]*+/#', '/', $sFile);
         $sEps = '...';
     }
     return $sEps . $sFile;
 }
 /**
  * 
  * @param type $aImgs
  */
 public function getCachedImgAttributes($aImgs)
 {
     $aImgAttributes = array();
     $total = count($aImgs[0]);
     for ($i = 0; $i < $total; $i++) {
         $sUrl = !empty($aImgs[1][$i]) ? $aImgs[1][$i] : (!empty($aImgs[2][$i]) ? $aImgs[2][$i] : $aImgs[3][$i]);
         if (JchOptimizeUrl::isInvalid($sUrl) || !$this->oParser->isHttpAdapterAvailable($sUrl) || JchOptimizeUrl::isSSL($sUrl) && !extension_loaded('openssl') || !JchOptimizeUrl::isHttpScheme($sUrl)) {
             $aImgAttributes[] = $aImgs[0][$i];
             continue;
         }
         $sPath = JchOptimizeHelper::getFilePath($sUrl);
         if (file_exists($sPath)) {
             $aSize = getimagesize($sPath);
             if ($aSize === false || empty($aSize) || $aSize[0] == '1' && $aSize[1] == '1') {
                 $aImgAttributes[] = $aImgs[0][$i];
                 continue;
             }
             $sImg = preg_replace('#(?:width|height)\\s*+=(?:\\s*+"([^">]*+)"|\\s*+\'([^\'>]*+)\'|([^\\s>]++))#i', '', $aImgs[0][$i]);
             $aImgAttributes[] = preg_replace('#\\s*+/?>#', ' ' . $aSize[3] . ' />', $sImg);
         } else {
             $aImgAttributes[] = $aImgs[0][$i];
             continue;
         }
     }
     return $aImgAttributes;
 }