vendor/pimcore/pimcore/models/Document/Page.php line 25

  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Pimcore
  5.  *
  6.  * This source file is available under two different licenses:
  7.  * - GNU General Public License version 3 (GPLv3)
  8.  * - Pimcore Commercial License (PCL)
  9.  * Full copyright and license information is available in
  10.  * LICENSE.md which is distributed with this source code.
  11.  *
  12.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  13.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  14.  */
  15. namespace Pimcore\Model\Document;
  16. use Pimcore\Messenger\GeneratePagePreviewMessage;
  17. /**
  18.  * @method \Pimcore\Model\Document\Page\Dao getDao()
  19.  */
  20. class Page extends PageSnippet
  21. {
  22.     /**
  23.      * Contains the title of the page (meta-title)
  24.      *
  25.      * @internal
  26.      *
  27.      */
  28.     protected string $title '';
  29.     /**
  30.      * Contains the description of the page (meta-description)
  31.      *
  32.      * @internal
  33.      *
  34.      */
  35.     protected string $description '';
  36.     protected string $type 'page';
  37.     /**
  38.      * @internal
  39.      *
  40.      */
  41.     protected ?string $prettyUrl null;
  42.     public function getDescription(): string
  43.     {
  44.         return $this->description;
  45.     }
  46.     public function getTitle(): string
  47.     {
  48.         return \Pimcore\Tool\Text::removeLineBreaks($this->title);
  49.     }
  50.     public function setDescription(string $description): static
  51.     {
  52.         $this->description str_replace("\n"' '$description);
  53.         return $this;
  54.     }
  55.     public function setTitle(string $title): static
  56.     {
  57.         $this->title $title;
  58.         return $this;
  59.     }
  60.     public function getFullPath(bool $force false): string
  61.     {
  62.         $path parent::getFullPath($force);
  63.         // do not use pretty url's when in admin, the current document is wrapped by a hardlink or this document isn't in the current site
  64.         if (!\Pimcore::inAdmin() && !($this instanceof Hardlink\Wrapper\WrapperInterface) && \Pimcore\Tool\Frontend::isDocumentInCurrentSite($this)) {
  65.             // check for a pretty url
  66.             $prettyUrl $this->getPrettyUrl();
  67.             if (!empty($prettyUrl) && strlen($prettyUrl) > 1) {
  68.                 return $prettyUrl;
  69.             }
  70.         }
  71.         return $path;
  72.     }
  73.     public function setPrettyUrl(?string $prettyUrl): static
  74.     {
  75.         if (!$prettyUrl) {
  76.             $this->prettyUrl null;
  77.         } else {
  78.             $this->prettyUrl '/' trim($prettyUrl' /');
  79.             if (strlen($this->prettyUrl) < 2) {
  80.                 $this->prettyUrl null;
  81.             }
  82.         }
  83.         return $this;
  84.     }
  85.     public function getPrettyUrl(): ?string
  86.     {
  87.         return $this->prettyUrl;
  88.     }
  89.     public function getPreviewImageFilesystemPath(): string
  90.     {
  91.         return PIMCORE_SYSTEM_TEMP_DIRECTORY '/document-page-previews/document-page-screenshot-' $this->getId() . '@2x.jpg';
  92.     }
  93.     public function save(array $parameters = []): static
  94.     {
  95.         $page parent::save($parameters);
  96.         // Dispatch page preview message, if preview is enabled.
  97.         $documentsConfig \Pimcore\Config::getSystemConfiguration('documents');
  98.         if ($documentsConfig['generate_preview'] ?? false) {
  99.             \Pimcore::getContainer()->get('messenger.bus.pimcore-core')->dispatch(
  100.                 new GeneratePagePreviewMessage($this->getId(), \Pimcore\Tool::getHostUrl())
  101.             );
  102.         }
  103.         return $page;
  104.     }
  105. }