예제 #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
 /**
  * 
  * @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;
 }
예제 #4
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;
     }
 }
예제 #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;
 }