forked from oat-sa/tao-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getFileFlysystem.php
73 lines (63 loc) · 2.68 KB
/
getFileFlysystem.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*
*
*/
require_once __DIR__ . '/../vendor/autoload.php';
use oat\tao\model\websource\FlyTokenWebSource;
use oat\oatbox\filesystem\FileSystemService;
use oat\tao\model\mvc\Bootstrap;
$url = $_SERVER['REQUEST_URI'];
$rel = substr($url, strpos($url, FlyTokenWebSource::ENTRY_POINT) + strlen(FlyTokenWebSource::ENTRY_POINT));
$parts = explode('/', $rel, 2);
list($webSourceId) = $parts;
$webSourceId = preg_replace('/[^a-zA-Z0-9]*/', '', $webSourceId);
$root = dirname(__DIR__);
$bootstrap = new Bootstrap($root . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'generis.conf.php');
$serviceManager = $bootstrap->getServiceLocator();
common_Logger::singleton()->register();
/** @var common_ext_ExtensionsManager $e */
$e = $serviceManager->get(common_ext_ExtensionsManager::SERVICE_ID);
$config = $e->getExtensionById('tao')->getConfig('websource_' . $webSourceId);
//$config = include $configPath;
if (!is_array($config) || !isset($config['className'])) {
header('HTTP/1.0 403 Forbidden');
die();
}
$className = $config['className'];
$options = isset($config['options']) ? $config['options'] : [];
$source = new $className($options);
if (!$source instanceof FlyTokenWebSource) {
header('HTTP/1.0 403 Forbidden');
die();
}
$fsService = $serviceManager->get(FileSystemService::SERVICE_ID);
$fileSystem = $fsService->getFileSystem($source->getOption($source::OPTION_FILESYSTEM_ID));
$source->setFileSystem($fileSystem);
try {
$ttl = isset($options['ttl']) && $options['ttl'] ? $options['ttl'] : (30 * 60); //30 min default
$path = $source->getFilePathFromUrl($url);
$stream = $source->getFileStream($path);
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + $ttl));
tao_helpers_Http::returnStream($stream, $source->getMimetype($path));
$stream->detach();
} catch (\tao_models_classes_FileNotFoundException $e) {
header("HTTP/1.0 404 Not Found");
}
exit();