$configService = $driver->connect('config', array('dir' => $root . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR, 'humanReadable' => true)); $serviceManager = new ServiceManager($configService); $configPath = $root . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'tao' . DIRECTORY_SEPARATOR . 'websource_' . $webSourceId . '.conf.php'; if (!file_exists($configPath)) { header('HTTP/1.0 403 Forbidden'); die; } $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'] : array(); $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 { $path = $source->getFilePathFromUrl($url); $stream = $source->getFileStream($path); tao_helpers_Http::returnStream($stream, $source->getMimetype($path)); $stream->detach(); } catch (\tao_models_classes_FileNotFoundException $e) { header("HTTP/1.0 404 Not Found"); } exit;
public function getFile() { if ($this->hasRequestParameter('uri')) { $uri = urldecode($this->getRequestParameter('uri')); $mediaSource = new MediaSource(array()); $fileInfo = $mediaSource->getFileInfo($uri); $link = $fileInfo['link']; $fileManagement = $this->getServiceManager()->get(FileManagement::SERVICE_ID); if ($fileInfo['mime'] === 'application/qti+xml') { \tao_helpers_Http::returnStream($fileManagement->getFileStream($link)); return; } if ($this->hasRequestParameter('xml')) { $this->returnJson(htmlentities((string) $fileManagement->getFileStream($link))); } else { \tao_helpers_Http::returnStream($fileManagement->getFileStream($link), $fileInfo['mime']); } } else { throw new \common_exception_Error('invalid media identifier'); } }
/** * @throws ResolverException * @throws \oat\tao\model\websource\WebsourceNotFound * @throws tao_models_classes_FileNotFoundException */ public function accessFile() { list($extension, $module, $action, $code, $filePath) = explode('/', tao_helpers_Request::getRelativeUrl(), 5); list($key, $subPath) = explode(' ', base64_decode($code), 2); $source = WebsourceManager::singleton()->getWebsource($key); if ($source instanceof ActionWebSource) { $path = $subPath . (empty($filePath) ? '' : DIRECTORY_SEPARATOR . $filePath); tao_helpers_Http::returnStream($source->getFileStream($path), $source->getMimetype($path)); } }
private function renderResource($item, $path) { $lang = common_session_SessionManager::getSession()->getDataLanguage(); $resolver = new ItemMediaResolver($item, $lang); $asset = $resolver->resolve($path); if ($asset->getMediaSource() instanceof HttpSource) { throw new common_Exception('Only tao files available for rendering through item preview'); } $info = $asset->getMediaSource()->getFileInfo($asset->getMediaIdentifier()); $stream = $asset->getMediaSource()->getFileStream($asset->getMediaIdentifier()); \tao_helpers_Http::returnStream($stream, $info['mime']); }