vendor/markocupic/contao-news-infinite-scroll-bundle/src/Resources/contao/modules/ModuleNewslistInfiniteScroll.php line 63

Open in your IDE?
  1. <?php
  2. /**
  3.  * Contao News Infinite Scroll Bundle
  4.  *
  5.  * Copyright (c) 2021 Marko Cupic
  6.  *
  7.  * @author Marko Cupic <https://github.com/markocupic/contao-news-infinite-scroll-bundle>
  8.  *
  9.  * @license LGPL-3.0+
  10.  */
  11. namespace Markocupic;
  12. use Contao\BackendTemplate;
  13. use Contao\CoreBundle\Exception\ResponseException
  14. use Contao\Environment;
  15. use Contao\Input;
  16. use Contao\ModuleNewsList;
  17. class ModuleNewslistInfiniteScroll extends ModuleNewsList
  18. {
  19.     /**
  20.      * Display a wildcard in the back end
  21.      *
  22.      * @return string
  23.      */
  24.     public function generate()
  25.     {
  26.         if (TL_MODE === 'BE')
  27.         {
  28.             $objTemplate = new BackendTemplate('be_wildcard');
  29.             $objTemplate->wildcard '### ' $GLOBALS['TL_LANG']['FMD']['contao_news_infinite_scroll'][0] . ' ###';
  30.             $objTemplate->title $this->headline;
  31.             $objTemplate->id $this->id;
  32.             $objTemplate->link $this->name;
  33.             $objTemplate->href 'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' $this->id;
  34.             return $objTemplate->parse();
  35.         }
  36.         // Do not add the page to the search index on ajax calls
  37.         // Send articles without a frame to the browser
  38.         if ($this->isAjaxRequest())
  39.         {
  40.             global $objPage;
  41.             $objPage->noSearch;
  42.             $this->strTemplate 'mod_newslist_infinite_scroll';
  43.         }
  44.         else
  45.         {
  46.             // Load JavaScript
  47.             $GLOBALS['TL_JAVASCRIPT'][] = 'bundles/markocupiccontaonewsinfinitescroll/js/news_infinite_scroll.min.js';
  48.         }
  49.         return parent::generate();
  50.     }
  51.     /**
  52.      * Generate the module
  53.      */
  54.     protected function compile()
  55.     {
  56.         // Add CSS Class
  57.         $cssID $this->cssID;
  58.         $cssID[1] = trim($cssID[1].' ajaxCall');
  59.         $this->cssID $cssID;
  60.         parent::compile();
  61.         if ($this->isAjaxRequest())
  62.         {
  63.             $this->Template->headline '';
  64.             $this->Template->pagination '';
  65.             $this->Template->archives $this->news_archives;
  66.             throw new ResponseException($this->Template->getResponse(truetrue));
  67.         }
  68.         parent::compile();
  69.     }
  70.     /**
  71.      * Checks whether the request is an AJAX request for this module
  72.      */
  73.     private function isAjaxRequest(): bool
  74.     {
  75.         return Environment::get('isAjaxRequest') && null !== Input::get('page_n'.$this->id) && null !== Input::get('ajaxCall');
  76.     }
  77. }