2015-12-09 22:19:23 +01:00
|
|
|
<?php
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
namespace SilverStripe\Assets\Flysystem;
|
2015-12-09 22:19:23 +01:00
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Control\Controller;
|
|
|
|
use SilverStripe\Control\Director;
|
2015-12-09 22:19:23 +01:00
|
|
|
|
|
|
|
class PublicAssetAdapter extends AssetAdapter implements PublicAdapter {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Server specific configuration necessary to block http traffic to a local folder
|
|
|
|
*
|
|
|
|
* @config
|
|
|
|
* @var array Mapping of server configurations to configuration files necessary
|
|
|
|
*/
|
|
|
|
private static $server_configuration = array(
|
|
|
|
'apache' => array(
|
2016-09-08 06:31:02 +02:00
|
|
|
'.htaccess' => "SilverStripe\\Assets\\Flysystem\\PublicAssetAdapter_HTAccess"
|
2015-12-09 22:19:23 +01:00
|
|
|
),
|
|
|
|
'microsoft-iis' => array(
|
2016-09-08 06:31:02 +02:00
|
|
|
'web.config' => "SilverStripe\\Assets\\Flysystem\\PublicAssetAdapter_WebConfig"
|
2015-12-09 22:19:23 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
protected function findRoot($root) {
|
|
|
|
if ($root) {
|
|
|
|
return parent::findRoot($root);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Empty root will set the path to assets
|
|
|
|
return ASSETS_PATH;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provide downloadable url
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @return string|null
|
|
|
|
*/
|
|
|
|
public function getPublicUrl($path) {
|
|
|
|
$rootPath = realpath(BASE_PATH);
|
|
|
|
$filesPath = realpath($this->pathPrefix);
|
|
|
|
|
|
|
|
if(stripos($filesPath, $rootPath) === 0) {
|
|
|
|
$dir = substr($filesPath, strlen($rootPath));
|
|
|
|
return Controller::join_links(Director::baseURL(), $dir, $path);
|
|
|
|
}
|
|
|
|
|
|
|
|
// File outside of webroot can't be used
|
|
|
|
return null;
|
|
|
|
}
|
2016-03-08 21:50:18 +01:00
|
|
|
}
|