1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-06 14:46:56 +02:00

Issue #5191 Static URL mapping.

This commit is contained in:
camer0n
2024-02-07 13:06:00 -08:00
parent 004da27010
commit d20326a2ec
2 changed files with 54 additions and 2 deletions

View File

@@ -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.
*

View File

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