vendor/pimcore/pimcore/bundles/CoreBundle/EventListener/Frontend/InternalWysiwygHtmlAttributeFilterListener.php line 46

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\Bundle\CoreBundle\EventListener\Frontend;
  15. use Pimcore\Bundle\CoreBundle\EventListener\Traits\PimcoreContextAwareTrait;
  16. use Pimcore\Bundle\CoreBundle\EventListener\Traits\ResponseInjectionTrait;
  17. use Pimcore\Bundle\CoreBundle\EventListener\Traits\StaticPageContextAwareTrait;
  18. use Pimcore\Http\Request\Resolver\PimcoreContextResolver;
  19. use Pimcore\Tool;
  20. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  21. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  22. use Symfony\Component\HttpKernel\KernelEvents;
  23. /**
  24.  * @internal
  25.  */
  26. class InternalWysiwygHtmlAttributeFilterListener implements EventSubscriberInterface
  27. {
  28.     use ResponseInjectionTrait;
  29.     use PimcoreContextAwareTrait;
  30.     use StaticPageContextAwareTrait;
  31.     public static function getSubscribedEvents()
  32.     {
  33.         return [
  34.             KernelEvents::RESPONSE => 'onKernelResponse',
  35.         ];
  36.     }
  37.     /**
  38.      * @param ResponseEvent $event
  39.      */
  40.     public function onKernelResponse(ResponseEvent $event)
  41.     {
  42.         $request $event->getRequest();
  43.         if (!$event->isMainRequest() && !$this->matchesStaticPageContext($request)) {
  44.             return;
  45.         }
  46.         if (!$this->matchesPimcoreContext($requestPimcoreContextResolver::CONTEXT_DEFAULT)
  47.             && !$this->matchesStaticPageContext($request)) {
  48.             return;
  49.         }
  50.         if (!Tool::useFrontendOutputFilters()) {
  51.             return;
  52.         }
  53.         $response $event->getResponse();
  54.         if (!$this->isHtmlResponse($response)) {
  55.             return;
  56.         }
  57.         $content $response->getContent();
  58.         $content preg_replace('/ pimcore_(id|type|disable_thumbnail)=\\"([0-9a-z]+)\\"/'''$content);
  59.         $response->setContent($content);
  60.     }
  61. }