Example #1
0
 /**
  * 
  * @param type $sPath
  */
 public static function path2Url($sPath)
 {
     $oUri = clone JchPlatformUri::getInstance();
     $sBaseFolder = JchOptimizeHelper::getBaseFolder();
     $abspath = str_replace(DIRECTORY_SEPARATOR, '/', ABSPATH);
     $sPath = str_replace(DIRECTORY_SEPARATOR, '/', $sPath);
     $sUriPath = $oUri->toString(array('scheme', 'user', 'pass', 'host', 'port')) . $sBaseFolder . str_replace($abspath, '', $sPath);
     return $sUriPath;
 }
 /**
  * Constructor
  * 
  * @param JRegistry object $params      Plugin parameters
  * @param string  $sHtml                Page HMTL
  */
 public function __construct($oParams, $sHtml, $oFileRetriever)
 {
     $this->params = $oParams;
     $this->sHtml = $sHtml;
     $this->oFileRetriever = $oFileRetriever;
     $this->sLnEnd = JchPlatformUtility::lnEnd();
     $this->sTab = JchPlatformUtility::tab();
     if (!defined('JCH_TEST_MODE')) {
         $oUri = JchPlatformUri::getInstance();
         $this->sFileHash = serialize($this->params->getOptions()) . JCH_VERSION . $oUri->getHost();
     }
     $this->parseHtml();
 }
Example #3
0
 /**
  * 
  * @staticvar string $sUriBase
  * @staticvar string $sUriPath
  * @param type $sUrl
  * @return boolean
  */
 protected function prepareExtensionValues($sUrl, $bReturn = TRUE)
 {
     if ($bReturn) {
         return $sUrl;
     }
     static $sHost = '';
     $oUri = JchPlatformUri::getInstance();
     $sHost = $sHost == '' ? $oUri->toString(array('host')) : $sHost;
     $result = preg_match('#^(?:https?:)?//([^/]+)#', $sUrl, $m1);
     $sExtension = isset($m1[1]) ? $m1[1] : '';
     if ($result === 0 || $sExtension == $sHost) {
         $result2 = preg_match('#' . JchPlatformExcludes::extensions() . '([^/]+)#', $sUrl, $m);
         if ($result2 === 0) {
             return FALSE;
         } else {
             $sExtension = $m[1];
         }
     }
     return $sExtension;
 }
Example #4
0
 /**
  * 
  * @return type
  */
 public static function getBaseFolder()
 {
     $sJbase = JchPlatformUri::base(true);
     return $sJbase == '/' ? $sJbase : $sJbase . '/';
 }
 /**
  * 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;
 }
Example #6
0
 /**
  * 
  */
 public function runCookieLessDomain()
 {
     if ($this->params->get('pro_cookielessdomain_enable', '0')) {
         JCH_DEBUG ? JchPlatformProfiler::start('RunCookieLessDomain') : null;
         $static_files_array = $this->params->get('pro_staticfiles', array('css', 'js', 'jpe?g', 'gif', 'png', 'ico', 'bmp', 'pdf', 'tiff?', 'docx?'));
         $static_files = implode('|', $static_files_array);
         $uri = clone JchPlatformUri::getInstance();
         $port = $uri->toString(array('port'));
         if (empty($port)) {
             $port = ':80';
         }
         $host = preg_quote($uri->getHost()) . '(?:' . $port . ')?';
         $path = $uri->getPath();
         $aPath = preg_split('#/#', $path);
         array_pop($aPath);
         $dir = trim(implode('/', $aPath), '/');
         $dir = str_replace('/administrator', '', $dir);
         $match = '(?!data:image|[\'"])' . '(?=((?:(?:https?:)?//' . $host . ')?)((?!http|//).))' . '(?:(?<![=\'(])(?:\\g{1}|\\g{2})((?>\\.?[^.">?]*+)*?\\.(?>' . $static_files . ')[^">]*+)' . '|(?<![\'="])(?:\\g{1}|\\g{2})((?>\\.?[^.)>?]*+)*?\\.(?>' . $static_files . ')[^)>]*+)' . '|(?<![="(])(?:\\g{1}|\\g{2})((?>\\.?[^.\'>?]*+)*?\\.(?>' . $static_files . ')[^\'>]*+)' . '|(?<![\'"(])(?:\\g{1}|\\g{2})((?>\\.?[^.\\s*>?]*+)*?\\.(?>' . $static_files . ')[^\\s>]*+))';
         $a = '(?:<(?:link|script|img))?(?>=?[^=<>]*+)*?(?<= href| src| data-src)=["\']?';
         $b = '(?:<style[^>]*+>|(?=(?>(?:<(?!style))?[^<]*+)?</style))(?>\\(?[^(<>]*+)*?(?<= url)\\(["\']?';
         $c = '(?>=?[^=>]++)*?(?<= style)=[^(>]++(?<=url)\\(["\']?';
         $sRegex = "#(?><?[^<]*+)*?(?:(?:{$a}|{$b}|{$c})\\K{$match}|\\K\$)#iS";
         $obj = $this;
         $sProcessedHeadHtml = preg_replace_callback($sRegex, function ($m) use($dir, $obj) {
             return $obj->cdnCB($m, $dir);
         }, $this->getHeadHtml());
         $sProcessedBodyHtml = preg_replace_callback($sRegex, function ($m) use($dir, $obj) {
             return $obj->cdnCB($m, $dir);
         }, $this->getBodyHtml());
         if (is_null($sProcessedHeadHtml) || is_null($sProcessedBodyHtml)) {
             JchOptimizeLogger::log('Cookie-less domain function failed', $this->params);
             return;
         }
         if (preg_match($this->getHeadRegex(), $sProcessedHeadHtml, $aHeadMatches) === FALSE || empty($aHeadMatches)) {
             JchOptimizeLogger::log('Failed retrieving head in cookie-less domain function', $this->params);
             return;
         }
         if (preg_match($this->getBodyRegex(), $sProcessedBodyHtml, $aBodyMatches) === FALSE || empty($aBodyMatches)) {
             JchOptimizeLogger::log('Failed retrieving body in cookie-less domain function', $this->params);
             return;
         }
         $this->sHeadHtml = $aHeadMatches[0];
         $this->sBodyHtml = $aBodyMatches[0];
         JCH_DEBUG ? JchPlatformProfiler::stop('RunCookieLessDomain', TRUE) : null;
     }
 }
 /**
  * 
  * @return type
  */
 public static function getBaseFolder()
 {
     return JchPlatformUri::base(true) . '/';
 }
Example #8
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;
 }
Example #9
0
 /**
  * 
  * @return type
  */
 public static function rewriteBase()
 {
     $sJbase = JchPlatformUri::base(true);
     return $sJbase == '/' ? $sJbase : $sJbase . '/';
 }
Example #10
0
 /**
  * Returns url of aggregated file
  *
  * @param string $sFile		Aggregated file name
  * @param string $sType		css or js
  * @param mixed $bGz		True (or 1) if gzip set and enabled
  * @param number $sTime		Expire header time
  * @return string			Url of aggregated file
  */
 protected function buildUrl($sId, $sType)
 {
     $iTime = (int) $this->params->get('cache_lifetime', '1');
     $bGz = $this->isGZ();
     $htaccess = $this->params->get('htaccess', 0);
     if ($htaccess == 1 || $htaccess == 3) {
         $sPath = $this->cookieLessDomain($sType);
         $sPath = $htaccess == 3 ? $sPath . '3' : $sPath;
         $sUrl = $sPath . JchPlatformPaths::rewriteBase() . ($bGz ? 'gz/' : 'nz/') . $iTime . '/JCHI/' . $sId . '.' . $sType;
     } else {
         $oUri = clone JchPlatformUri::getInstance(JchPlatformPaths::assetPath());
         $oUri->setPath($oUri->getPath() . '2/jscss.php');
         $aVar = array();
         $aVar['f'] = $sId;
         $aVar['type'] = $sType;
         $aVar['gz'] = $bGz ? 'gz' : 'nz';
         $aVar['d'] = $iTime;
         $aVar['i'] = 'JCHI';
         $oUri->setQuery($aVar);
         $sUrl = htmlentities($oUri->toString());
     }
     return $sUrl;
 }
Example #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;
 }
Example #12
0
 /**
  * Returns url of aggregated file
  *
  * @param string $sFile		Aggregated file name
  * @param string $sType		css or js
  * @param mixed $bGz		True (or 1) if gzip set and enabled
  * @param number $sTime		Expire header time
  * @return string			Url of aggregated file
  */
 protected function buildUrl($sId, $sType)
 {
     $sPath = JchPlatformPaths::assetPath();
     $iTime = (int) $this->params->get('lifetime', '30');
     $bGz = $this->isGZ();
     if ($this->params->get('htaccess', 0) == 1) {
         $sUrl = JchOptimizeHelper::cookieLessDomain($this->params) . $sPath . JchPlatformPaths::rewriteBase() . ($bGz ? 'gz/' : 'nz/') . $iTime . '/JCHI/' . $sId . '.' . $sType;
     } else {
         $oUri = clone JchPlatformUri::getInstance();
         $oUri->setPath($sPath . '2/jscss.php');
         $aVar = array();
         $aVar['f'] = $sId;
         $aVar['type'] = $sType;
         $aVar['gz'] = $bGz ? 'gz' : 'nz';
         $aVar['d'] = $iTime;
         $aVar['i'] = 'JCHI';
         $oUri->setQuery($aVar);
         $sUrl = htmlentities($oUri->toString(array('path', 'query')));
     }
     return $sUrl;
 }
Example #13
0
 /**
  * 
  * @return type
  */
 public static function currentUrl()
 {
     $oUri = JchPlatformUri::getInstance();
     return $oUri->toString(array('scheme', 'host', 'port', 'path'));
 }
Example #14
0
 /**
  * 
  * @param type $sUrl
  * @param type $sCurFile
  */
 public static function toAbsolute($sUrl, $sCurFile)
 {
     $oUri = clone JchPlatformUri::getInstance($sCurFile);
     if (self::isPathRelative($sUrl)) {
         $oUri->setPath(dirname($oUri->getPath()) . '/' . $sUrl);
     }
     if (self::isRootRelative($sUrl)) {
         $oUri->setPath($sUrl);
     }
     if (self::isProtocolRelative($sUrl)) {
         $scheme = $oUri->getScheme();
         if (!empty($scheme)) {
             $sUrl = $scheme . ':' . $sUrl;
         }
         $oUri = JchPlatformUri::getInstance($sUrl);
     }
     $sUrl = $oUri->toString();
     $host = $oUri->getHost();
     if (!self::isAbsolute($sUrl) && !empty($host)) {
         return '//' . $sUrl;
     }
     return $sUrl;
 }