Skip to content

Commit

Permalink
Merge pull request #836 from joomlatools/feature/835-image
Browse files Browse the repository at this point in the history
Asset prefix support for remote image base paths
  • Loading branch information
johanjanssens authored Dec 4, 2021
2 parents 7e52311 + fc748b5 commit e5cceca
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions code/template/helper/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ protected function _initialize(KObjectConfig $config)
'max_width' => 1920,
'min_width' => 320,
'max_dpr' => 3,
'base_url' => $this->getObject('request')->getBasePath().'/images',
'base_path' => $this->getObject('com:pages.config')->getSitePath().'/images',
'base_url' => $this->getObject('request')->getBasePath().'/images',
'base_path' => $this->getObject('com:pages.config')->getSitePath().'/images',
'cache_path' => $this->getObject('com:pages.config')->getCachePath().'/images',
'exclude' => ['svg'],
'lazyload' => true,
'preload' => false,
Expand Down Expand Up @@ -276,6 +277,8 @@ public function url($url, $parameters = array())
{
if(stripos((string)$url, $origin) === 0)
{
$this->getTemplate()->getFilter('asset')->filter($base);

$url = $base.'/'.ltrim(str_replace($origin, '', $url), '/');
$url = KHttpUrl::fromString($url);
break;
Expand Down Expand Up @@ -433,9 +436,12 @@ protected function _findFile($url)
{
if(stripos((string) $url, $origin) === 0)
{
$this->getTemplate()->getFilter('asset')->filter($base);

$ext = pathinfo($url, PATHINFO_EXTENSION);
$name = hash("crc32b", $url).'.' . $ext;
$file = $this->getObject('com:pages.config')->getSitePath() . '/' . trim($base, '/'). '/'.$name;
$base = str_replace(rtrim($this->getConfig()->base_url, '/').'/', '', $base);
$file = $this->getConfig()->cache_path . '/' . trim($base, '/'). '/'.$name;

if(file_exists($file))
{
Expand All @@ -445,6 +451,8 @@ protected function _findFile($url)
}
}



//Fallback if file doesn't exist
if(!$result)
{
Expand All @@ -462,7 +470,7 @@ protected function _findFile($url)
else
{
$path = $url->getPath();
$base = $this->getConfig()->base_url.'/';
$base = rtrim($this->getConfig()->base_url, '/').'/';
$file = $this->getConfig()->base_path . '/' . str_replace($base, '', $path);

if(file_exists($file)) {
Expand Down

0 comments on commit e5cceca

Please sign in to comment.