Exemplo n.º 1
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)
 {
     // global $_PROFILER;
     //JCH_DEBUG ? $_PROFILER->mark('beforeGetFilePath - ' . $sUrl . ' plgSystem (JCH Optimize)') : null;
     $sUriBase = str_replace('/administrator/', '', JUri::base());
     $sUriPath = str_replace('/administrator', '', JUri::base(TRUE));
     $oUri = clone JUri::getInstance($sUriBase);
     if (JchOptimizeHelper::isInternal($sUrl) && !preg_match('#\\.php#i', $sUrl)) {
         $sUrl = preg_replace(array('#^' . preg_quote($sUriBase, '#') . '#', '#^' . preg_quote($sUriPath, '#') . '/#', '#\\?.*?$#'), '', $sUrl);
         //JCH_DEBUG ? $_PROFILER->mark('afterGetFilePath - ' . $sUrl . ' plgSystem (JCH Optimize)') : null;
         return JPATH_ROOT . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $sUrl);
     } else {
         switch (TRUE) {
             case preg_match('#://#', $sUrl):
                 break;
             case substr($sUrl, 0, 2) == '//':
                 $sUrl = $oUri->toString(array('scheme')) . substr($sUrl, 2);
                 break;
             case substr($sUrl, 0, 1) == '/':
                 $sUrl = $oUri->toString(array('scheme', 'host')) . $sUrl;
                 break;
             default:
                 $sUrl = $sUriBase . $sUrl;
                 break;
         }
         //JCH_DEBUG ? $_PROFILER->mark('afterGetFilePath - ' . $sUrl . ' plgSystem (JCH Optimize)') : null;
         return html_entity_decode($sUrl);
     }
 }
Exemplo n.º 2
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)
 {
     //JCH_DEBUG ? JchPlatformProfiler::mark('beforeGetFilePath - ' . $sUrl . ' plgSystem (JCH Optimize)') : null;
     $sUriBase = JchPlatformUri::base();
     $sUriPath = JchPlatformUri::base(TRUE);
     $oUri = clone JchPlatformUri::getInstance();
     $aUrl = parse_url($sUrl);
     if (JchOptimizeHelper::isInternal($sUrl) && preg_match('#\\.(?>css|js|png|gif|jpe?g)$#i', $aUrl['path'])) {
         $sUrl = preg_replace(array('#^' . preg_quote($sUriBase, '#') . '#', '#^' . preg_quote($sUriPath, '#') . '/#', '#\\?.*?$#'), '', $sUrl);
         //JCH_DEBUG ? JchPlatformProfiler::mark('afterGetFilePath - ' . $sUrl . ' plgSystem (JCH Optimize)') : null;
         return JchPlatformPaths::absolutePath($sUrl);
     } else {
         switch (TRUE) {
             case preg_match('#://#', $sUrl):
                 break;
             case substr($sUrl, 0, 2) == '//':
                 $sUrl = $oUri->toString(array('scheme')) . substr($sUrl, 2);
                 break;
             case substr($sUrl, 0, 1) == '/':
                 $sUrl = $oUri->toString(array('scheme', 'user', 'pass', 'host', 'port')) . $sUrl;
                 break;
             default:
                 $sUrl = $sUriBase . $sUrl;
                 break;
         }
         //JCH_DEBUG ? JchPlatformProfiler::mark('afterGetFilePath - ' . $sUrl . ' plgSystem (JCH Optimize)') : null;
         return html_entity_decode($sUrl);
     }
 }
Exemplo n.º 3
0
 /**
  * Determines if file requires http protocol to get contents (Not allowed)
  * 
  * @param string $sUrl
  * @return boolean
  */
 protected function isHttpAdapterAvailable($sUrl)
 {
     return preg_match('#^(?:http|//)#i', $sUrl) && !JchOptimizeHelper::isInternal($sUrl) || preg_match('#\\.php|^(?!.*?\\.(?:js|css)).++#i', $sUrl);
 }
Exemplo n.º 4
0
 /**
  * Determines if file contents can be fetched using http protocol if required
  * 
  * @param string $sPath    Url of file
  * @return boolean        
  */
 public function isHttpAdapterAvailable($sUrl)
 {
     if ($this->params->get('pro_phpAndExternal', '1')) {
         return (preg_match('#^(?:http|//)#i', $sUrl) && !JchOptimizeHelper::isInternal($sUrl) || preg_match('#\\.php|^(?!.*?\\.(?:js|css)).++#i', $sUrl)) && !$this->oFileRetriever->isHttpAdapterAvailable();
     } else {
         return parent::isHttpAdapterAvailable($sUrl);
     }
 }
Exemplo n.º 5
0
        /**
         * 
         * @param type $sPath
         */
        protected function excludeExternalExtensions($sPath)
        {
                if (!$this->params->get('includeAllExtensions', '0'))
                {
                        return !JchOptimizeHelper::isInternal($sPath) || preg_match('#' . JchPlatformExcludes::extensions() . '#i', $sPath);
                }

                return FALSE;
        }
Exemplo n.º 6
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)
 {
     //JCH_DEBUG ? JchPlatformProfiler::mark('beforeCorrectUrl plgSystem (JCH Optimize)') : null;
     if (preg_match('#^(?:\\(|/(?:/|\\*))#', $aMatches[0])) {
         return $aMatches[0];
     }
     if ($aMatches[0] == '') {
         return ' ';
     }
     $sUriBase = JchPlatformUri::base(TRUE);
     $sImageUrl = $aMatches[1];
     $sCssFileUrl = isset($this->aUrl['url']) ? $this->aUrl['url'] : '/';
     if (preg_match('#^data:#', $sImageUrl)) {
         return $sImageUrl;
     }
     if (!preg_match('#^/|://#', $sImageUrl)) {
         $aCssUrlArray = explode('/', $sCssFileUrl);
         array_pop($aCssUrlArray);
         $sCssRootPath = implode('/', $aCssUrlArray) . '/';
         $sImagePath = $sCssRootPath . $sImageUrl;
         $oImageUri = clone JchPlatformUri::getInstance($sImagePath);
         $sUriPath = preg_replace('#^' . preg_quote($sUriBase, '#') . '/#', '', $oImageUri->getPath());
         $oImageUri->setPath($sUriBase . '/' . $sUriPath);
         $sImageUrl = $oImageUri->toString();
     }
     if (JchOptimizeHelper::isInternal($sCssFileUrl) && JchOptimizeHelper::isInternal($sImageUrl)) {
         $oImageUri = clone JchPlatformUri::getInstance($sImageUrl);
         $aStaticFiles = $this->staticFiles();
         $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 (preg_match('#\\.php#', $oImageUri->getPath())) {
             $sImageUrl = $oImageUri->toString(array('path', 'query', 'fragment'));
         } elseif ($this->params->get('pro_cookielessdomain', '') && preg_match('#\\.(?>' . $sFontFiles . ')#', $oImageUri->getPath())) {
             $oUri = clone JchPlatformUri::getInstance();
             $sImageUrl = '//' . $oUri->toString(array('host', 'port')) . $oImageUri->toString(array('path'));
         } else {
             $sImageUrl = $oImageUri->toString(array('path'));
         }
     }
     //JCH_DEBUG ? JchPlatformProfiler::mark('afterCorrectUrl plgSystem (JCH Optimize)') : null;
     $sImageUrl = preg_match('#(?<!\\\\)[\\s\'"(),]#', $sImageUrl) ? '"' . $sImageUrl . '"' : $sImageUrl;
     return $sImageUrl;
 }
Exemplo n.º 7
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
  */
 protected function _correctUrlCB($aMatches)
 {
     $sUriBase = str_replace('/administrator', '', JUri::base(TRUE));
     $sImageUrl = $aMatches[1];
     $sCssFileUrl = isset($this->aUrl['url']) ? $this->aUrl['url'] : '/';
     if (!preg_match('#^/|://|^data:#', $sImageUrl)) {
         $aCssUrlArray = explode('/', $sCssFileUrl);
         array_pop($aCssUrlArray);
         $sCssRootPath = implode('/', $aCssUrlArray) . '/';
         $sImagePath = $sCssRootPath . $sImageUrl;
         $oUri = JURI::getInstance($sImagePath);
         $sUriPath = preg_replace('#^' . preg_quote($sUriBase, '#') . '/#', '', $oUri->getPath());
         $oUri->setPath($sUriBase . '/' . $sUriPath);
         $sImageUrl = $oUri->toString();
     }
     if (JchOptimizeHelper::isInternal($sCssFileUrl)) {
         if (JchOptimizeHelper::isInternal($sImageUrl)) {
             $oUri = JURI::getInstance($sImageUrl);
             $sImageUrl = $oUri->toString(array('path', 'query', 'fragment'));
         }
     }
     return 'url(' . $sImageUrl . ')';
 }
Exemplo n.º 8
0
 /**
  * 
  * @param type $sUrl
  * @return type
  */
 public static function prepareFileValues($sFile, $sType = '', $iLen = 27)
 {
     if ($sType != 'value') {
         $oFile = JchPlatformUri::getInstance($sFile);
         if (JchOptimizeHelper::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;
 }
Exemplo n.º 9
0
 /**
  * Determines if file requires http protocol to get contents (Not allowed)
  * 
  * @param string $sUrl
  * @return boolean
  */
 protected function isUrlFopenAllowed($sUrl)
 {
     return preg_match('#(?:.*\\.php)#', $sUrl) === 1 || !JchOptimizeHelper::isInternal($sUrl);
 }
Exemplo n.º 10
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) && !JchOptimizeHelper::isInternal($sUrl)
                 || $this->isPHPFile($sUrl));
 }
Exemplo n.º 11
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 (!isset($aMatches[1]) || $aMatches[1] == '' || preg_match('#^(?:\\(|/(?:/|\\*))#', $aMatches[0])) {
         return $aMatches[0];
     }
     $sUriBase = JchPlatformUri::base(TRUE);
     $sImageUrl = $aMatches[1];
     $sCssFileUrl = isset($aUrl['url']) ? $aUrl['url'] : '/';
     if (!preg_match('#^data:#', $sImageUrl)) {
         if (!preg_match('#^/|://#', $sImageUrl)) {
             $aCssUrlArray = explode('/', $sCssFileUrl);
             array_pop($aCssUrlArray);
             $sCssRootPath = implode('/', $aCssUrlArray) . '/';
             $sImagePath = $sCssRootPath . $sImageUrl;
             $oImageUri = clone JchPlatformUri::getInstance($sImagePath);
             if (JchOptimizeHelper::isInternal($sCssFileUrl)) {
                 $sUriPath = preg_replace('#^' . preg_quote($sUriBase, '#') . '/#', '', $oImageUri->getPath());
                 $oImageUri->setPath($sUriBase . '/' . $sUriPath);
                 $sImageUrl = $oImageUri->toString();
             } else {
                 $oImageUri->setPath($oImageUri->getPath());
                 $sImageUrl = ($oImageUri->toString(array('scheme')) ? '' : '//') . $oImageUri->toString();
             }
         }
         if (JchOptimizeHelper::isInternal($sCssFileUrl) && JchOptimizeHelper::isInternal($sImageUrl)) {
             $oImageUri = clone JchPlatformUri::getInstance($sImageUrl);
             $aStaticFiles = $this->params->get('pro_staticfiles', array('css', 'js', 'jpe?g', 'gif', 'png', 'ico', 'bmp', 'pdf'));
             $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 (preg_match('#\\.php#', $oImageUri->getPath())) {
                 $sImageUrl = $oImageUri->toString(array('path', 'query', 'fragment'));
             } 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 {
                 $sImageUrl = $oImageUri->toString(array('path'));
             }
         }
     }
     $sImageUrl = preg_match('#(?<!\\\\)[\\s\'"(),]#', $sImageUrl) ? '"' . $sImageUrl . '"' : $sImageUrl;
     return $sImageUrl;
 }
Exemplo n.º 12
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 (JchOptimizeHelper::isInternal($sUrl) && !preg_match('#\\.php\\d?(?:$|\\?)#i', $oUrl->getPath())) {
         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, '', '&', PHP_QUERY_RFC3986), $sUrl);
         }
         return $sUrl;
     }
 }