From 27910c87c74e9113da6f77fc98b579bd38f0f1d9 Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 25 Oct 2017 19:02:10 -0700 Subject: [PATCH] Issue #2827 Support for multiple static domains for distributed static URLs. --- e107_handlers/e107_class.php | 4 +- e107_handlers/e_parse_class.php | 97 +++++++++++++++++++++++++++++++-- e107_handlers/js_manager.php | 21 +++++-- 3 files changed, 109 insertions(+), 13 deletions(-) diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index 93c7330c4..a4d46f5a1 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -4030,9 +4030,7 @@ class e107 return $this->e107_dirs[$dir.'_HTTP']; } - $http = ($dir === "CACHE_IMAGE" && defined('e_MEDIA_STATIC') && defined('e_HTTP_STATIC')) ? e_HTTP_STATIC : e_HTTP; - - return $http.$this->e107_dirs[$dir.'_DIRECTORY']; + return e_HTTP.$this->e107_dirs[$dir.'_DIRECTORY']; } /** diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index 0e937b8c7..387cc4406 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -62,6 +62,8 @@ class e_parse extends e_parser private $thumbEncode = 0; + private $staticCount = 0; + // BBcode that contain preformatted code. private $preformatted = array('html', 'markdown'); @@ -2568,6 +2570,90 @@ class e_parse extends e_parser } + + private function staticCount($val=false) + { + + $count = $this->staticCount; + + if($val === 0) + { + $this->staticCount = 0; + } + elseif($val !== false) + { + $this->staticCount = $this->staticCount + (int) $val; + } + + return (int) $count; + + } + + + /** + * @param string $path - absolute path + * @return string - static path. + */ + public function staticUrl($path=null) + { + if(!defined('e_HTTP_STATIC')) + { + return ($path === null) ? e_HTTP : $path; + } + + + + $staticArray = e_HTTP_STATIC; + + if(is_array($staticArray)) + { + $cnt = count($staticArray); + $staticCount = $this->staticCount(); + if($staticCount > ($cnt -1)) + { + $staticCount = 0; + $this->staticCount(0); + } + + $http = !empty($staticArray[$staticCount]) ? $staticArray[$staticCount] : e_HTTP; + + } + else + { + $http = e_HTTP_STATIC; + } + + $this->staticCount(1); + + if(empty($path)) + { + return $http; + } + + $base = ''; + + $srch = array( + e_PLUGIN_ABS, + e_THEME_ABS, + e_WEB_ABS, + e_CACHE_IMAGE_ABS, + ); + + + $repl = array( + $http.$base.e107::getFolder('plugins'), + $http.$base.e107::getFolder('themes'), + $http.$base.e107::getFolder('web'), + $http.$base.str_replace('../', '', e_CACHE_IMAGE), + ); + + $ret = str_replace($srch,$repl,$path); + + return $ret; + + } + + /** * Generate an auto-sized Image URL. * @param $url - path to image or leave blank for a placeholder. eg. {e_MEDIA}folder/my-image.jpg @@ -2584,6 +2670,8 @@ class e_parse extends e_parser */ public function thumbUrl($url=null, $options = array(), $raw = false, $full = false) { + $this->staticCount++; // increment counter. + if(strpos($url,"{e_") === 0) // Fix for broken links that use {e_MEDIA} etc. { //$url = $this->replaceConstants($url,'abs'); @@ -2591,7 +2679,7 @@ class e_parse extends e_parser $url = str_replace($this->getUrlConstants('sc'), $this->getUrlConstants('raw'), $url); } - if(!is_array($options)) + if(is_string($options)) { parse_str($options, $options); } @@ -2617,7 +2705,7 @@ class e_parse extends e_parser if(defined('e_HTTP_STATIC')) { - $baseurl = e_HTTP_STATIC.'thumb.php?'; + $baseurl = $this->staticUrl().'thumb.php?'; } $thurl = 'src='.urlencode($url).'&'; @@ -2678,8 +2766,7 @@ class e_parse extends e_parser if(!empty($staticFile) && is_readable(e_CACHE_IMAGE.$staticFile)) { - //file_put_contents(e_LOG."thumbCache.log",$staticFile."\n",FILE_APPEND); - return e_CACHE_IMAGE_ABS.$staticFile; + return $this->staticUrl(e_CACHE_IMAGE.$staticFile); } $options['nosef'] = true; @@ -2834,7 +2921,7 @@ class e_parse extends e_parser if(defined('e_HTTP_STATIC')) { - $base = e_HTTP_STATIC; + $base = $this->staticUrl(); } // $base = (!empty($options['full'])) ? SITEURL : e_HTTP; diff --git a/e107_handlers/js_manager.php b/e107_handlers/js_manager.php index 6daee89e2..7b95d641d 100644 --- a/e107_handlers/js_manager.php +++ b/e107_handlers/js_manager.php @@ -1400,13 +1400,19 @@ class e_jsmanager } - - private function url($path,$cacheId = true) + /** + * Return the URL while checking for staticUrl configuration. + * @param $path + * @param bool $cacheId + * @return mixed|string + */ + private function url($path, $cacheId = true) { - if((e_MOD_REWRITE_STATIC === true || defined('e_HTTP_STATIC')) && $this->isInAdmin() !== true) + + if(/*(e_MOD_REWRITE_STATIC === true || defined('e_HTTP_STATIC')) &&*/ $this->isInAdmin() !== true) { - $srch = array( + /* $srch = array( e_PLUGIN_ABS, e_THEME_ABS, e_WEB_ABS @@ -1430,10 +1436,15 @@ class e_jsmanager return trim($folder); } - $path = $folder; + $path = $folder;*/ + + $path = e107::getParser()->staticUrl($path); } + + + if(strpos($path,'?')!==false) { $path .= "&".$this->getCacheId();