2015-12-09 22:19:23 +01:00
|
|
|
<?php
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
namespace SilverStripe\Assets\Flysystem;
|
|
|
|
|
|
|
|
use SilverStripe\Control\Director;
|
|
|
|
use SilverStripe\Control\Controller;
|
|
|
|
use SilverStripe\Core\Config\Config;
|
2015-12-09 22:19:23 +01:00
|
|
|
|
|
|
|
class ProtectedAssetAdapter extends AssetAdapter implements ProtectedAdapter {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Name of default folder to save secure assets in under ASSETS_PATH.
|
|
|
|
* This can be bypassed by specifying an absolute filesystem path via
|
|
|
|
* the SS_PROTECTED_ASSETS_PATH environment definition.
|
|
|
|
*
|
|
|
|
* @config
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private static $secure_folder = '.protected';
|
|
|
|
|
|
|
|
private static $server_configuration = array(
|
|
|
|
'apache' => array(
|
2016-09-08 06:31:02 +02:00
|
|
|
'.htaccess' => "SilverStripe\\Assets\\Flysystem\\ProtectedAssetAdapter_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\\ProtectedAssetAdapter_WebConfig"
|
2015-12-09 22:19:23 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
protected function findRoot($root) {
|
|
|
|
// Use explicitly defined path
|
|
|
|
if($root) {
|
|
|
|
return parent::findRoot($root);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use environment defined path
|
|
|
|
if(defined('SS_PROTECTED_ASSETS_PATH')) {
|
|
|
|
return SS_PROTECTED_ASSETS_PATH;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default location is under assets
|
2016-08-19 00:51:35 +02:00
|
|
|
return ASSETS_PATH . '/' . Config::inst()->get(get_class($this), 'secure_folder');
|
2015-12-09 22:19:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provide secure downloadable
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @return string|null
|
|
|
|
*/
|
|
|
|
public function getProtectedUrl($path) {
|
|
|
|
// Public URLs are handled via a request handler within /assets.
|
|
|
|
// If assets are stored locally, then asset paths of protected files should be equivalent.
|
2016-08-19 00:51:35 +02:00
|
|
|
return Controller::join_links(Director::baseURL(), ASSETS_DIR, $path);
|
2015-12-09 22:19:23 +01:00
|
|
|
}
|
|
|
|
}
|