示例#1
0
 /**
  * Prepare base informations to be rendered in twig templates.
  *
  * ## Available contents
  *
  * - request: Main request object
  * - head
  *     - ajax: `boolean`
  *     - cmsVersion
  *     - cmsVersionNumber
  *     - cmsBuild
  *     - devMode: `boolean`
  *     - baseUrl
  *     - filesUrl
  *     - resourcesUrl
  *     - ajaxToken
  *     - fontToken
  *     - universalAnalyticsId
  *     - useCdn
  * - session
  *     - messages
  *     - id
  *     - user
  * - securityAuthorizationChecker
  *
  * @return $this
  */
 public function prepareBaseAssignation()
 {
     $this->assignation = ['request' => $this->getRequest(), 'head' => ['ajax' => $this->getRequest()->isXmlHttpRequest(), 'cmsVersion' => Kernel::CMS_VERSION, 'cmsVersionNumber' => Kernel::$cmsVersion, 'cmsBuild' => Kernel::$cmsBuild, 'devMode' => (bool) $this->container['config']['devMode'], 'useCdn' => (bool) SettingsBag::get('use_cdn'), 'universalAnalyticsId' => SettingsBag::get('universal_analytics_id'), 'baseUrl' => $this->getRequest()->getAbsoluteBaseUrl(), 'filesUrl' => $this->getRequest()->getBaseUrl() . '/' . Document::getFilesFolderName(), 'resourcesUrl' => $this->getStaticResourcesUrl(), 'ajaxToken' => $this->container['csrfTokenManager']->getToken(static::AJAX_TOKEN_INTENTION), 'fontToken' => $this->container['csrfTokenManager']->getToken(static::FONT_TOKEN_INTENTION)], 'session' => ['id' => $this->getRequest()->getSession()->getId(), 'user' => $this->getUser()]];
     if ($this->container['securityAuthorizationChecker'] !== null) {
         $this->assignation['authorizationChecker'] = $this->container['securityAuthorizationChecker'];
     }
     return $this;
 }
示例#2
0
 /**
  * @return array $assignation
  */
 public function prepareBaseAssignation()
 {
     $this->assignation = ['request' => $this->getRequest(), 'head' => ['siteTitle' => 'welcome.title', 'ajax' => $this->getRequest()->isXmlHttpRequest(), 'cmsVersion' => Kernel::CMS_VERSION, 'cmsVersionNumber' => Kernel::$cmsVersion, 'cmsBuild' => Kernel::$cmsBuild, 'devMode' => false, 'baseUrl' => $this->getRequest()->getAbsoluteBaseUrl(), 'filesUrl' => $this->getRequest()->getBaseUrl() . '/' . Document::getFilesFolderName(), 'resourcesUrl' => $this->getStaticResourcesUrl(), 'ajaxToken' => $this->getService('csrfTokenManager')->getToken(static::AJAX_TOKEN_INTENTION), 'fontToken' => $this->getService('csrfTokenManager')->getToken(static::FONT_TOKEN_INTENTION)], 'session' => ['id' => $this->getRequest()->getSession()->getId(), 'locale' => $this->getRequest()->getSession()->get('_locale', 'en')]];
     $this->assignation['head']['grunt'] = (include dirname(__FILE__) . '/static/public/config/assets.config.php');
     return $this;
 }
 /**
  * Set setting value according to its type.
  *
  * @param string  $value
  * @param Setting $setting
  */
 protected function setSettingValue($value, Setting $setting)
 {
     switch ($setting->getType()) {
         case NodeTypeField::DOCUMENTS_T:
             if ($value !== null && $value->getError() == UPLOAD_ERR_OK && $value->isValid()) {
                 $document = new Document();
                 $document->setFilename($value->getClientOriginalName());
                 $document->setMimeType($value->getMimeType());
                 $this->getService('em')->persist($document);
                 $this->getService('em')->flush();
                 $value->move(Document::getFilesFolder() . '/' . $document->getFolder(), $document->getFilename());
                 $setting->setValue($document->getId());
             }
             break;
         default:
             $setting->setValue($value);
             break;
     }
 }
示例#4
0
 public function display(Document $document, array $criteria = [])
 {
     return $document->getViewer()->getDocumentByArray($criteria);
 }
 /**
  * Download a picture from the embed media platform
  * to get a thumbnail.
  *
  * @return string|false File URL in document files folder.
  */
 public function downloadThumbnail()
 {
     $url = $this->getThumbnailURL();
     if (false !== $url && '' !== $url) {
         $pathinfo = basename($url);
         if ($pathinfo != "") {
             $thumbnailName = $this->embedId . '_' . $pathinfo;
             try {
                 $original = \GuzzleHttp\Stream\Stream::factory(fopen($url, 'r'));
                 $local = \GuzzleHttp\Stream\Stream::factory(fopen(Document::getFilesFolder() . '/' . $thumbnailName, 'w'));
                 $local->write($original->getContents());
                 if (file_exists(Document::getFilesFolder() . '/' . $thumbnailName) && filesize(Document::getFilesFolder() . '/' . $thumbnailName) > 0) {
                     return $thumbnailName;
                 } else {
                     return false;
                 }
             } catch (\GuzzleHttp\Exception\RequestException $e) {
                 return false;
             }
         }
     }
     return false;
 }
 /**
  * @param  Image    $processImage
  * @param  Document $rawDocument
  * @return Document
  */
 protected function createDocumentFromImage(Image $processImage, Document $originalDocument, $keepExistingRaw = false)
 {
     $fs = new Filesystem();
     if (false === $keepExistingRaw && null !== ($formerRawDoc = $originalDocument->getRawDocument())) {
         /*
          * When document already exists with a raw doc reference.
          * We have to delete former raw document before creating a new one.
          * Keeping the same document to preserve existing relationships!!
          */
         $originalDocument->setRawDocument(null);
         /*
          * Make sure to disconnect raw document before removing it
          * not to trigger Cascade deleting.
          */
         $this->em->flush();
         $this->em->remove($formerRawDoc);
         $this->em->flush();
     }
     if (null === $originalDocument->getRawDocument() || $keepExistingRaw === false) {
         /*
          * We clone it to host raw document.
          * Keeping the same document to preserve existing relationships!!
          *
          * Get every data from raw document.
          */
         $rawDocument = clone $originalDocument;
         $rawDocumentName = preg_replace('#\\.(jpe?g|gif|tiff?|png|psd)$#', $this->rawImageSuffix . '.$1', $originalDocument->getFilename());
         $rawDocument->setFilename($rawDocumentName);
         if ($fs->exists($originalDocument->getAbsolutePath()) && !$fs->exists($rawDocument->getAbsolutePath())) {
             /*
              * Original document path becomes raw document path. Rename it.
              */
             $fs->rename($originalDocument->getAbsolutePath(), $rawDocument->getAbsolutePath());
             /*
              * Then save downscaled image as original document path.
              */
             $processImage->save($originalDocument->getAbsolutePath(), 100);
             $originalDocument->setRawDocument($rawDocument);
             $rawDocument->setRaw(true);
             $this->em->persist($rawDocument);
             $this->em->flush();
             return $originalDocument;
         } else {
             return false;
         }
     } else {
         /*
          * We keep intact raw document, just updating downscaled doc.
          */
         $rawDocument = $originalDocument->getRawDocument();
         /*
          * Remove existing downscaled document.
          */
         $fs->remove($originalDocument->getAbsolutePath());
         /*
          * Then save downscaled image as original document path.
          */
         $processImage->save($originalDocument->getAbsolutePath(), 100);
         $this->em->flush();
         return $originalDocument;
     }
 }
 /**
  * Handle upload form data to create a Document.
  *
  * @param Symfony\Component\Form\Form $data
  *
  * @return boolean
  */
 private function uploadDocument($data, $folderId = null)
 {
     if (!empty($data['attachment'])) {
         $uploadedFile = $data['attachment']->getData();
         if ($uploadedFile !== null && $uploadedFile->getError() == UPLOAD_ERR_OK && $uploadedFile->isValid()) {
             try {
                 $document = new Document();
                 $document->setFilename($uploadedFile->getClientOriginalName());
                 $document->setMimeType($uploadedFile->getMimeType());
                 $this->getService('em')->persist($document);
                 $this->getService('em')->flush();
                 if (null !== $folderId && $folderId > 0) {
                     $folder = $this->getService('em')->find('RZ\\Roadiz\\Core\\Entities\\Folder', (int) $folderId);
                     $document->addFolder($folder);
                     $folder->addDocument($document);
                     $this->getService('em')->flush();
                 }
                 $uploadedFile->move(Document::getFilesFolder() . '/' . $document->getFolder(), $document->getFilename());
                 return $document;
             } catch (\Exception $e) {
                 return false;
             }
         }
     }
     return false;
 }