src/Rhyme/WMassArtsHub/Module/Profile/Reader.php line 81

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (C) 2021 Rhyme Digital, LLC.
  4.  *
  5.  * @author        Blair Winans <blair@rhyme.digital>
  6.  * @author        Adam Fisher <adam@rhyme.digital>
  7.  * @link        https://rhyme.digital
  8.  * @license        http://www.gnu.org/licenses/lgpl-3.0.html LGPL
  9.  */
  10. namespace Rhyme\WMassArtsHub\Module\Profile;
  11. use Contao\CoreBundle\Routing\ResponseContext\HtmlHeadBag\HtmlHeadBag;
  12. use Contao\CoreBundle\Routing\ResponseContext\ResponseContextAccessor;
  13. use Contao\Database;
  14. use Contao\PageModel;
  15. use Contao\StringUtil;
  16. use Contao\Environment;
  17. use Contao\PageError404;
  18. use Contao\BackendTemplate;
  19. use Contao\System;
  20. use Haste\Http\Response\HtmlResponse;
  21. use Haste\Input\Input;
  22. use Rhyme\WMassArtsHub\Model\Profile\Item as ProfileItemModel;
  23. /**
  24.  * Class Reader
  25.  * @package Rhyme\WMassArtsHub\Module\Collection
  26.  */
  27. class Reader extends Module
  28. {
  29.     /**
  30.      * Template
  31.      * @var string
  32.      */
  33.     protected $strTemplate 'mod_artshub_profile_reader';
  34.     /**
  35.      * Item
  36.      * @var ProfileItemModel
  37.      */
  38.     protected $objItem;
  39.     /**
  40.      * Display a wildcard in the back end
  41.      * @return string
  42.      */
  43.     public function generate()
  44.     {
  45.         if ('BE' === TL_MODE) {
  46.             $objTemplate = new BackendTemplate('be_wildcard');
  47.             $objTemplate->wildcard '### ' . \strtoupper($GLOBALS['TL_LANG']['FMD'][$this->type][0]) . ' ###';
  48.             $objTemplate->title    $this->headline;
  49.             $objTemplate->id       $this->id;
  50.             $objTemplate->link     $this->name;
  51.             $objTemplate->href     'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' $this->id;
  52.             return $objTemplate->parse();
  53.         }
  54.         // Return if no item has been specified
  55.         if (Input::getAutoItem('detail'falsetrue) == '') {
  56.             if ($this->iso_display404Page) {
  57.                 $this->generate404();
  58.             } else {
  59.                 return '';
  60.             }
  61.         }
  62.         return parent::generate();
  63.     }
  64.     /**
  65.      * Generate module
  66.      * @return void
  67.      */
  68.     protected function compile()
  69.     {
  70.         global $objPage;
  71.         $objItem ProfileItemModel::findAvailableByIdOrAlias(Input::getAutoItem('detail'));
  72.         if (null === $objItem) {
  73.             $this->generate404();
  74.         }
  75.         $arrConfig = array(
  76.             'module'      => $this,
  77.             'template'    => $this->artshub_profile_reader_layout ?: 'artshub_profile_reader_default',
  78.             'jumpTo'      => $objPage,
  79.             'imgSize'     => $this->imgSize,
  80.             'gallery_imgSize' => $this->gallery_imgSize
  81.         );
  82.         $GLOBALS['TL_JAVASCRIPT']['jquerymosaic'] = 'web/bundles/rhymewmassartshub/assets/js/vendor/jquerymosaic/jquery.mosaic.js|static';
  83.         $GLOBALS['TL_CSS']['jquerymosaic'] = 'web/bundles/rhymewmassartshub/assets/js/vendor/jquerymosaic/jquery.mosaic.css|static';
  84.         $this->addMetaTags($objItem);
  85.         $this->Template->item           $objItem->generate($arrConfig);
  86.         $this->Template->item_id        $this->getCssId($objItem);
  87.         $this->Template->item_class     $this->getCssClass($objItem);
  88.         $this->Template->referer        'javascript:history.go(-1)';
  89.         $this->Template->back           $GLOBALS['TL_LANG']['MSC']['goBack'];
  90.     }
  91.     /**
  92.      * Add meta header fields to the current page
  93.      *
  94.      * @param ProfileItemModel $objItem
  95.      */
  96.     protected function addMetaTags(ProfileItemModel $objItem)
  97.     {
  98.         // Overwrite the page meta data (see #2853, #4955 and #87)
  99.         $responseContext System::getContainer()->get(ResponseContextAccessor::class)->getResponseContext();
  100.         if ($responseContext && $responseContext->has(HtmlHeadBag::class))
  101.         {
  102.             /** @var HtmlHeadBag $htmlHeadBag */
  103.             $htmlHeadBag $responseContext->get(HtmlHeadBag::class);
  104.             $htmlHeadBag->setTitle($objItem->getPageTitle());
  105.             $htmlHeadBag->setMetaDescription(StringUtil::inputEncodedToPlainText($objItem->getPageDescription()));
  106.         }
  107.     }
  108.     /**
  109.      * Gets the CSS ID for this item
  110.      *
  111.      * @param ProfileItemModel $objItem
  112.      *
  113.      * @return string|null
  114.      */
  115.     protected function getCssId(ProfileItemModel $objItem)
  116.     {
  117.         $css StringUtil::deserialize(\strval($objItem->cssID), true);
  118.         return $css[0] ? ' id="' $css[0] . '"' null;
  119.     }
  120.     /**
  121.      * Gets the CSS classes for this item
  122.      *
  123.      * @param ProfileItemModel $objItem
  124.      *
  125.      * @return string
  126.      */
  127.     protected function getCssClass(ProfileItemModel $objItem)
  128.     {
  129.         $classes = ['item'];
  130.         $arrCSS StringUtil::deserialize($objItem->cssIDtrue);
  131.         if (\count($arrCSS) > && '' !== (string) $arrCSS[1]) {
  132.             $classes[] = (string) $arrCSS[1];
  133.         }
  134.         return \implode(' '$classes);
  135.     }
  136.     /**
  137.      * Generates a 404 page and stops page output.
  138.      */
  139.     private function generate404()
  140.     {
  141.         /** @var PageError404 $objHandler */
  142.         $objHandler = new $GLOBALS['TL_PTY']['error_404']();
  143.         $objHandler->generate();
  144.         exit;
  145.     }
  146. }