From d20326a2ec8fc7785fb07fc3993c79ed9a65118a Mon Sep 17 00:00:00 2001 From: camer0n Date: Wed, 7 Feb 2024 13:06:00 -0800 Subject: [PATCH] Issue #5191 Static URL mapping. --- e107_handlers/e_parse_class.php | 12 +++++++- e107_tests/tests/unit/e_parseTest.php | 44 ++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index c6ef77033..1a4cfb6e7 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -63,8 +63,10 @@ class e_parse protected $staticUrl; + protected $staticUrlMap = []; + /** @var array Stored relative paths - used by replaceConstants() */ - private $relativePaths = array(); + private $relativePaths = []; // BBcode that contain preformatted code. @@ -2478,6 +2480,9 @@ class e_parse $ret = str_replace(e_MEDIA_ABS, $http . $base . e107::getFolder('media'), $ret); } + $key = ltrim(eHelper::dasherize($path), '/'); + $this->staticUrlMap[$key] = $ret; + return $ret; } @@ -2492,6 +2497,11 @@ class e_parse $this->staticUrl = $url; } + public function getStaticUrlMap() + { + return $this->staticUrlMap; + } + /** * Generate an auto-sized Image URL. * diff --git a/e107_tests/tests/unit/e_parseTest.php b/e107_tests/tests/unit/e_parseTest.php index 94786e587..759354e26 100644 --- a/e107_tests/tests/unit/e_parseTest.php +++ b/e107_tests/tests/unit/e_parseTest.php @@ -1790,12 +1790,54 @@ EXPECTED; $static = !empty($val['static']) ? 'https://static.mydomain.com/' : null; $this->tp->setStaticUrl($static); $actual = $this->tp->staticUrl($val['input']); - $this->assertSame($val['expected'], $actual); + self::assertSame($val['expected'], $actual); } $this->tp->setStaticUrl(null); + // Test with Static Array + $static = [ + 'https://static.mydomain.com/', + 'https://static2.mydomain.com/', + 'https://static3.mydomain.com/', + ]; + + $this->tp->setStaticUrl($static); + $tests = [ + 1 => array( + 'expected' => 'https://static.mydomain.com/e107_themes/bootstrap3/images/myimage1.jpg', + 'input' => '{THEME}images/myimage1.jpg', + 'static' => true, + ), + 2 => array( + 'expected' => 'https://static2.mydomain.com/e107_themes/bootstrap3/images/myimage2.jpg', + 'input' => '{THEME}images/myimage2.jpg', + 'static' => true, + ), + 3 => array( + 'expected' => 'https://static3.mydomain.com/e107_themes/bootstrap3/images/myimage3.jpg', + 'input' => '{THEME}images/myimage3.jpg', + 'static' => true, + ), + 4 => array( + 'expected' => 'https://static.mydomain.com/e107_themes/bootstrap3/images/myimage4.jpg', + 'input' => '{THEME}images/myimage4.jpg', + 'static' => true, + ), + + ]; + + foreach($tests as $val) + { + $actual = $this->tp->staticUrl($val['input']); + self::assertSame($val['expected'], $actual); + } + + $map = $this->tp->getStaticUrlMap(); + self::assertStringContainsString('myimage2.jpg', $map['e107-themes/bootstrap3/images/myimage2.jpg'] ); + + $this->tp->setStaticUrl(null); } /*