vendor/pimcore/pimcore/models/Document/Editable/Embed.php line 23

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Commercial License (PCL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  13.  */
  14. namespace Pimcore\Model\Document\Editable;
  15. use Pimcore\Model;
  16. /**
  17.  * @method \Pimcore\Model\Document\Editable\Dao getDao()
  18.  */
  19. class Embed extends Model\Document\Editable
  20. {
  21.     /**
  22.      * @internal
  23.      *
  24.      * @var string|null
  25.      */
  26.     protected $url;
  27.     /**
  28.      * {@inheritdoc}
  29.      */
  30.     public function getType()
  31.     {
  32.         return 'embed';
  33.     }
  34.     /**
  35.      * {@inheritdoc}
  36.      *
  37.      * @return mixed
  38.      */
  39.     public function getData()
  40.     {
  41.         return [
  42.             'url' => $this->url,
  43.         ];
  44.     }
  45.     /**
  46.      * @return string|null
  47.      */
  48.     public function getUrl()
  49.     {
  50.         return $this->url;
  51.     }
  52.     /**
  53.      * {@inheritdoc}
  54.      *
  55.      * @return array
  56.      */
  57.     public function getDataForResource()
  58.     {
  59.         return [
  60.             'url' => $this->url,
  61.         ];
  62.     }
  63.     /**
  64.      * {@inheritdoc}
  65.      */
  66.     public function frontend()
  67.     {
  68.         if ($this->url) {
  69.             $config $this->getConfig();
  70.             if (!isset($config['params'])) {
  71.                 $config['params'] = [];
  72.             }
  73.             foreach (['width''height'] as $property) {
  74.                 if (isset($config[$property])) {
  75.                     $config['params'][$property] = $config[$property];
  76.                 }
  77.             }
  78.             $cacheKey 'doc_embed_' crc32(serialize([$this->url$config]));
  79.             if (!$html \Pimcore\Cache::load($cacheKey)) {
  80.                 $embera = new \Embera\Embera($config);
  81.                 $html $embera->autoEmbed($this->url);
  82.                 \Pimcore\Cache::save($html$cacheKey, ['embed'], 864001true);
  83.             }
  84.             return $html;
  85.         }
  86.         return '';
  87.     }
  88.     /**
  89.      * {@inheritdoc}
  90.      */
  91.     public function admin()
  92.     {
  93.         $html parent::admin();
  94.         // get frontendcode for preview
  95.         // put the video code inside the generic code
  96.         $html str_replace('</div>'$this->frontend() . '</div>'$html);
  97.         return $html;
  98.     }
  99.     /**
  100.      * {@inheritdoc}
  101.      */
  102.     public function setDataFromResource($data)
  103.     {
  104.         if (!empty($data)) {
  105.             $data \Pimcore\Tool\Serialize::unserialize($data);
  106.         }
  107.         $this->url $data['url'];
  108.         return $this;
  109.     }
  110.     /**
  111.      * {@inheritdoc}
  112.      */
  113.     public function setDataFromEditmode($data)
  114.     {
  115.         if ($data['url']) {
  116.             $this->url $data['url'];
  117.         }
  118.         return $this;
  119.     }
  120.     /**
  121.      * {@inheritdoc}
  122.      */
  123.     public function isEmpty()
  124.     {
  125.         if ($this->url) {
  126.             return false;
  127.         }
  128.         return true;
  129.     }
  130. }