示例#1
0
 /**
  * Render-content action
  */
 public function customCssAction()
 {
     /* @var $siteInfo \Zork\Db\SiteInfo */
     /* @var $model \Grid\Customize\Model\Extra\Model */
     /* @var $structure \Grid\Customize\Model\Extra\Structure */
     $params = $this->params();
     $request = $this->getRequest();
     $id = $params->fromRoute('id');
     $rootId = is_numeric($id) ? (int) $id : null;
     $schema = $params->fromRoute('schema');
     $locator = $this->getServiceLocator();
     $siteInfo = $locator->get('Zork\\Db\\SiteInfo');
     if ($schema != $siteInfo->getSchema()) {
         $this->getResponse()->setResultCode(403);
         return;
     }
     $model = $locator->get('Grid\\Customize\\Model\\Extra\\Model');
     $structure = $model->findByRoot($rootId);
     if (empty($structure)) {
         $this->getResponse()->setResultCode(404);
         return;
     }
     $id = $rootId ?: 'global';
     $url = $this->url();
     $hash = $structure->updated->toHash();
     $cssPath = $url->fromRoute('Grid\\Customize\\Render\\CustomCss', array('schema' => $schema, 'id' => $id, 'hash' => $hash));
     $cssFile = static::PUBLIC_DIR . $cssPath;
     if (!is_file($cssFile)) {
         $dir = dirname($cssFile);
         if (!is_dir($dir)) {
             mkdir($dir, 0777, true);
         }
         $iterator = new RegexIterator(new FileSystemIterator($dir, FileSystemIterator::SKIP_DOTS | FileSystemIterator::KEY_AS_FILENAME | FileSystemIterator::CURRENT_AS_PATHNAME), '#.*[/\\\\]custom\\.([^\\.]+|' . preg_quote($id, '#') . '\\.[^\\.]+)\\.css$#');
         foreach ($iterator as $unlinkPath) {
             @unlink($unlinkPath);
         }
         $this->getServiceLocator()->get('Grid\\Customize\\Model\\Sheet\\Model')->findByExtra($structure)->render($cssFile);
     }
     $requestPath = $request->getUri()->getPath();
     if (ltrim($requestPath, '/') != ltrim($cssPath, '/')) {
         return $this->redirect()->toUrl($cssPath);
     }
     $response = Readfile::fromFile($cssFile, 'text/css');
     $this->getEvent()->setResponse($response);
     return $response;
 }
示例#2
0
 /**
  * Export paragraph action
  */
 public function exportAction()
 {
     $params = $this->params();
     $paragraphId = $params->fromRoute('paragraphId');
     $serviceLocator = $this->getServiceLocator();
     $paragraphModel = $serviceLocator->get('Grid\\Paragraph\\Model\\Paragraph\\Model');
     $paragraph = $paragraphModel->find($paragraphId);
     if (empty($paragraph)) {
         $this->getResponse()->setResultCode(404);
         return;
     }
     $zipFile = $serviceLocator->get('Grid\\Customize\\Model\\Exporter')->export($paragraph->id);
     $name = strtolower($paragraph->name);
     if (empty($name)) {
         $name = 'paragraph-' . $paragraph->id;
     }
     $response = Readfile::fromFile($zipFile, 'application/zip', $name . '.zip', true);
     $this->getEvent()->setResponse($response);
     return $response;
 }
示例#3
0
 /**
  * Thumbnail renderer action
  *
  * @return array
  */
 public function renderAction()
 {
     $redir = false;
     $params = $this->params();
     $pathname = $params->fromRoute('pathname');
     $matches = array();
     $hasMatch = preg_match('#^(.+)/([^/]+)/([0-9x\\-]+)/([^/]+)/' . '([^/]+)/([0-9]+)/([^/\\?]+)(\\?.*)?$#', $pathname, $matches);
     if (!$hasMatch) {
         return $this->error(400);
     }
     list(, $this->path, $this->method, $sizes, $this->bgColor, $filters, $mtime, $this->file) = $matches;
     $sizes = explode('-', $sizes, 3);
     if (count($sizes) == 3) {
         $this->crop = true;
         list($this->width, $this->height) = explode('x', $sizes[2], 2);
         list($this->cropLeft, $this->cropTop) = explode('x', $sizes[0], 2);
         list($this->cropWidth, $this->cropHeight) = explode('x', $sizes[1], 2);
     } else {
         $this->crop = false;
         list($this->width, $this->height) = explode('x', $sizes[0], 2);
     }
     $mtime = (int) $mtime;
     $this->width = (int) $this->width;
     $this->height = (int) $this->height;
     $inputPath = Thumbnail::THUMBNAIL_BASEPATH . '/' . $this->filePath();
     if (0 == $this->width && self::MIN_HEIGHT <= $this->height && is_file($inputPath) && filesize($inputPath) > 0) {
         $inputSizes = getimagesize($inputPath);
         if (!empty($inputSizes[0]) && !empty($inputSizes[1])) {
             $this->width = (int) ($inputSizes[0] * $this->height / $inputSizes[1]);
             $redir = true;
         }
     }
     if (0 == $this->height && self::MIN_WIDTH <= $this->width && is_file($inputPath) && filesize($inputPath) > 0) {
         $inputSizes = getimagesize($inputPath);
         if (!empty($inputSizes[0]) && !empty($inputSizes[1])) {
             $this->height = (int) ($inputSizes[1] * $this->width / $inputSizes[0]);
             $redir = true;
         }
     }
     if (self::MIN_WIDTH > $this->width) {
         $this->width = self::DEFAULT_WIDTH;
         $redir = true;
     }
     if (self::MIN_HEIGHT > $this->height) {
         $this->height = self::DEFAULT_HEIGHT;
         $redir = true;
     }
     if (!is_file($inputPath)) {
         return $this->error(404);
     }
     if (1 > filesize($inputPath)) {
         return $this->error(415);
     }
     if (preg_match('#^image/(x-|vnd.microsoft.)?icon?$#', $this->getMime($inputPath))) {
         return $this->redirect()->toUrl('/uploads/' . $this->filePath());
     }
     if ($filters == 'none') {
         $this->filters = array();
     } else {
         $this->filters = explode('-', $filters);
     }
     if (!Image::isResize($this->method)) {
         $this->method = self::DEFAULT_METHOD;
         $redir = true;
     }
     foreach ($this->filters as $index => $filter) {
         $filter = explode(',', $filter);
         if (!Image::isFilter($filter[0])) {
             unset($this->filters[$index]);
         }
     }
     if (empty($this->filters)) {
         $newFilters = 'none';
     } else {
         $newFilters = implode('-', $this->filters);
     }
     if ($filters != $newFilters) {
         $redir = true;
     }
     $fmt = filemtime($inputPath);
     if ($fmt != $mtime) {
         $mtime = $fmt;
         $redir = true;
     }
     if ($redir) {
         return $this->redirect()->toUrl($this->outputUri($mtime));
     }
     if (!$this->getImage($inputPath)) {
         return $this->error(415);
     }
     if ($this->crop) {
         $this->getImage()->cropTo($this->cropLeft, $this->cropTop, $this->cropWidth, $this->cropHeight);
     }
     $this->getImage()->resize($this->width, $this->height, $this->method, $this->bgColor);
     foreach ($this->filters as $filter) {
         $filter = explode(',', $filter);
         $name = array_shift($filter);
         $this->getImage()->filter($name, $filter);
     }
     $outputPath = $this->outputPath($mtime);
     if (!is_dir(dirname($outputPath))) {
         mkdir(dirname($outputPath), 0777, true);
     }
     $this->getImage()->render($outputPath);
     $response = Readfile::fromFile($outputPath, Image::typeToMimeType($this->getImage()->getType()));
     $this->getEvent()->setResponse($response);
     return $response;
 }
示例#4
0
 /**
  * Test empty file
  *
  * @expectedException   RuntimeException
  */
 public function testSetContent()
 {
     $readfile = Readfile::fromFile($this->file);
     $readfile->setContent('foo-bar');
 }