/** * 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); } }
/** * 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; } }