Skip to content

Commit

Permalink
Merge pull request #86 from barryvdh/feat-urlcallback
Browse files Browse the repository at this point in the history
Add URL Callback
  • Loading branch information
barryvdh authored Mar 15, 2022
2 parents 15e15ef + 52d7faa commit e342ea6
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public function __construct()
{
$opts = array(
'filesystem' => null,
'URLCallback' => null,
'glideURL' => null,
'glideKey' => null,
'imageManager' => null,
'cache' => 'session', // 'session', 'memory' or false
'fscache' => null, // The Flysystem cache
'checkSubfolders' => false, // Disable for performance
);

Expand All @@ -88,13 +88,13 @@ public function mount(array $opts)
}

/**
* Find the icon based on the used Adapter
* Return the icon
*
* @return string
*/
protected function getIcon()
{
$icon = 'volume_icon_local.png';
$icon = 'volume_icon_ftp.png';

$parentUrl = defined('ELFINDER_IMG_PARENT_URL') ? (rtrim(ELFINDER_IMG_PARENT_URL, '/') . '/') : '';
return $parentUrl . 'img/' . $icon;
Expand Down Expand Up @@ -302,6 +302,10 @@ protected function _stat($path)
}
}

if ($this->options['URLCallback'] && is_callable($this->options['URLCallback'])) {
$stat['url'] = $this->options['URLCallback']($path);
}

return $stat;
}

Expand Down Expand Up @@ -828,11 +832,17 @@ public function getContentUrl($hash, $options = array())
return $url;
}
}

if (($file = $this->file($hash)) == false || !isset($file['url']) || !$file['url'] || $file['url'] == 1) {
if ($file && !empty($file['url']) && !empty($options['temporary'])) {
return parent::getContentUrl($hash, $options);
}
$path = $this->decode($hash);

if ($this->options['URLCallback'] && is_callable($this->options['URLCallback'])) {
return $this->options['URLCallback']($path);
}

return parent::getContentUrl($hash, $options);
}
return $file['url'];
Expand Down

0 comments on commit e342ea6

Please sign in to comment.