芝麻web文件管理V1.00
编辑当前文件:/home/mgatv524/cms.mgaplay.com.br/lib/Controller/Preview.php
. */ namespace Xibo\Controller; use Slim\Http\Response as Response; use Slim\Http\ServerRequest as Request; use Xibo\Factory\LayoutFactory; use Xibo\Support\Exception\AccessDeniedException; /** * Class Preview * @package Xibo\Controller */ class Preview extends Base { /** * @var LayoutFactory */ private $layoutFactory; /** * Set common dependencies. * @param LayoutFactory $layoutFactory */ public function __construct($layoutFactory) { $this->layoutFactory = $layoutFactory; } /** * Layout Preview * @param Request $request * @param Response $response * @param $id * @return \Psr\Http\Message\ResponseInterface|Response * @throws AccessDeniedException * @throws \Xibo\Support\Exception\ControllerNotImplemented * @throws \Xibo\Support\Exception\GeneralException * @throws \Xibo\Support\Exception\NotFoundException */ public function show(Request $request, Response $response, $id ) { $sanitizedParams = $this->getSanitizer($request->getParams()); // Get the layout if ($sanitizedParams->getInt('findByCode') === 1) { $layout = $this->layoutFactory->getByCode($id); } else { $layout = $this->layoutFactory->getById($id); } if (!$this->getUser()->checkViewable($layout) || !$this->getUser()->featureEnabled(['layout.view', 'playlist.view']) ) { throw new AccessDeniedException(); } // Do we want to preview the draft version of this Layout? if ($sanitizedParams->getCheckbox('isPreviewDraft') && $layout->hasDraft()) { $layout = $this->layoutFactory->getByParentId($layout->layoutId); } $this->getState()->template = 'layout-preview'; $this->getState()->setData([ 'layout' => $layout, 'previewOptions' => [ 'getXlfUrl' => $this->urlFor($request,'layout.getXlf', ['id' => $layout->layoutId]), 'getResourceUrl' => $this->urlFor($request,'module.getResource', ['regionId' => ':regionId', 'id' => ':id']), 'libraryDownloadUrl' => $this->urlFor($request,'library.download', ['id' => ':id']), 'layoutBackgroundDownloadUrl' => $this->urlFor($request,'layout.download.background', ['id' => ':id']), 'loaderUrl' => $this->getConfig()->uri('img/loader.gif'), 'layoutPreviewUrl' => $this->urlFor($request,'layout.preview', ['id' => '[layoutCode]']) ] ]); return $this->render($request, $response); } /** * Get the XLF for a Layout * @param Request $request * @param Response $response * @param $id * @return \Psr\Http\Message\ResponseInterface|Response * @throws AccessDeniedException * @throws \Xibo\Support\Exception\ControllerNotImplemented * @throws \Xibo\Support\Exception\GeneralException * @throws \Xibo\Support\Exception\InvalidArgumentException * @throws \Xibo\Support\Exception\NotFoundException */ public function getXlf(Request $request, Response $response, $id) { $layout = $this->layoutFactory->concurrentRequestLock($this->layoutFactory->getById($id)); try { if (!$this->getUser()->checkViewable($layout)) { throw new AccessDeniedException(); } echo file_get_contents($layout->xlfToDisk([ 'notify' => false, 'collectNow' => false, ])); $this->setNoOutput(); } finally { // Release lock $this->layoutFactory->concurrentRequestRelease($layout); } return $this->render($request, $response); } }