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