news-bundle/src/Resources/contao/modules/ModuleNewsReader.php
protected function compile()
	{
		/** @var PageModel $objPage */
		global $objPage;

		$this->Template->articles = '';
		$this->Template->referer = 'javascript:history.go(-1)';
		$this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];

		// Get the news item
		$objArticle = NewsModel::findPublishedByParentAndIdOrAlias(Input::get('items'), $this->news_archives);

		// The news item does not exist or has an external target (see #33)
		if (null === $objArticle || $objArticle->source != 'default')
		{
			throw new PageNotFoundException('Page not found: ' . Environment::get('uri'));
		}

		$arrArticle = $this->parseArticle($objArticle);
		$this->Template->articles = $arrArticle;

		// Overwrite the page title (see #2853, #4955 and #87)
		if ($objArticle->pageTitle)
		{
			$objPage->pageTitle = $objArticle->pageTitle;
		}
		elseif ($objArticle->headline)
		{
			$objPage->pageTitle = strip_tags(StringUtil::stripInsertTags($objArticle->headline));
		}

		// Overwrite the page description
		if ($objArticle->description)
		{
			$objPage->description = $objArticle->description;
		}
		elseif ($objArticle->teaser)
		{
			$objPage->description = $this->prepareMetaDescription($objArticle->teaser);
		}

		$bundles = System::getContainer()->getParameter('kernel.bundles');

		// HOOK: comments extension required
		if ($objArticle->noComments || !isset($bundles['ContaoCommentsBundle']))
		{
			$this->Template->allowComments = false;

			return;
		}

		/** @var NewsArchiveModel $objArchive */
		$objArchive = $objArticle->getRelated('pid');
		$this->Template->allowComments = $objArchive->allowComments;

		// Comments are not allowed
		if (!$objArchive->allowComments)
		{
			return;
		}

		// Adjust the comments headline level
		$intHl = min((int) str_replace('h', '', $this->hl), 5);
		$this->Template->hlc = 'h' . ($intHl + 1);

		$this->import(Comments::class, 'Comments');
		$arrNotifies = array();

		// Notify the system administrator
		if ($objArchive->notify != 'notify_author')
		{
			$arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL'];
		}

		// Notify the author
		if ($objArchive->notify != 'notify_admin')
		{
			/** @var UserModel $objAuthor */
			if (($objAuthor = $objArticle->getRelated('author')) instanceof UserModel && $objAuthor->email != '')
			{
				$arrNotifies[] = $objAuthor->email;
			}
		}

		$objConfig = new \stdClass();

		$objConfig->perPage = $objArchive->perPage;
		$objConfig->order = $objArchive->sortOrder;
		$objConfig->template = $this->com_template;
		$objConfig->requireLogin = $objArchive->requireLogin;
		$objConfig->disableCaptcha = $objArchive->disableCaptcha;
		$objConfig->bbcode = $objArchive->bbcode;
		$objConfig->moderate = $objArchive->moderate;

		$this->Comments->addCommentsToTemplate($this->Template, $objConfig, 'tl_news', $objArticle->id, $arrNotifies);
	}
protected function compile()
	{
		/** @var PageModel $objPage */
		global $objPage;

		$this->Template->articles = '';
		$this->Template->referer = 'javascript:history.go(-1)';
		$this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];

		// Get the news item
		$objArticle = NewsModel::findPublishedByParentAndIdOrAlias(Input::get('items'), $this->news_archives);

		// The news item does not exist or has an external target (see #33)
		if (null === $objArticle || $objArticle->source != 'default')
		{
			throw new PageNotFoundException('Page not found: ' . Environment::get('uri'));
		}

		$arrArticle = $this->parseArticle($objArticle);
		$this->Template->articles = $arrArticle;

		// Overwrite the page title (see #2853, #4955 and #87)
		if ($objArticle->pageTitle)
		{
			$objPage->pageTitle = $objArticle->pageTitle;
		}
		elseif ($objArticle->headline)
		{
			$objPage->pageTitle = strip_tags(StringUtil::stripInsertTags($objArticle->headline));
		}

		// Overwrite the page description
		if ($objArticle->description)
		{
			$objPage->description = $objArticle->description;
		}
		elseif ($objArticle->teaser)
		{
			$objPage->description = $this->prepareMetaDescription($objArticle->teaser);
		}

		$bundles = System::getContainer()->getParameter('kernel.bundles');

		// HOOK: comments extension required
		if ($objArticle->noComments || !isset($bundles['ContaoCommentsBundle']))
		{
			$this->Template->allowComments = false;

			return;
		}

		/** @var NewsArchiveModel $objArchive */
		$objArchive = $objArticle->getRelated('pid');
		$this->Template->allowComments = $objArchive->allowComments;

		// Comments are not allowed
		if (!$objArchive->allowComments)
		{
			return;
		}

		// Adjust the comments headline level
		$intHl = min((int) str_replace('h', '', $this->hl), 5);
		$this->Template->hlc = 'h' . ($intHl + 1);

		$this->import(Comments::class, 'Comments');
		$arrNotifies = array();

		// Notify the system administrator
		if ($objArchive->notify != 'notify_author')
		{
			$arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL'];
		}

		// Notify the author
		if ($objArchive->notify != 'notify_admin')
		{
			/** @var UserModel $objAuthor */
			if (($objAuthor = $objArticle->getRelated('author')) instanceof UserModel && $objAuthor->email != '')
			{
				$arrNotifies[] = $objAuthor->email;
			}
		}

		$objConfig = new \stdClass();

		$objConfig->perPage = $objArchive->perPage;
		$objConfig->order = $objArchive->sortOrder;
		$objConfig->template = $this->com_template;
		$objConfig->requireLogin = $objArchive->requireLogin;
		$objConfig->disableCaptcha = $objArchive->disableCaptcha;
		$objConfig->bbcode = $objArchive->bbcode;
		$objConfig->moderate = $objArchive->moderate;

		$this->Comments->addCommentsToTemplate($this->Template, $objConfig, 'tl_news', $objArticle->id, $arrNotifies);
	}
protected function compile ( ) { /** @var PageModel $objPage */ global $ objPage ; $ this -> Template -> articles = '' ; $ this -> Template -> referer = 'javascript:history.go(-1)' ; $ this -> Template -> back = $ GLOBALS [ 'TL_LANG' ] [ 'MSC' ] [ 'goBack' ] ; // Get the news item $ objArticle = NewsModel :: findPublishedByParentAndIdOrAlias ( Input :: get ( 'items' ) , $ this -> news_archives ) ; // The news item does not exist or has an external target (see #33) if ( null === $ objArticle || $ objArticle -> source != 'default' ) { throw new PageNotFoundException ( 'Page not found: ' . Environment :: get ( 'uri' ) ) ; } $ arrArticle = $ this -> parseArticle ( $ objArticle ) ; $ this -> Template -> articles = $ arrArticle ; // Overwrite the page title (see #2853, #4955 and #87) if ( $ objArticle -> pageTitle ) { $ objPage -> pageTitle = $ objArticle -> pageTitle ; } elseif ( $ objArticle -> headline ) { $ objPage -> pageTitle = strip_tags ( StringUtil :: stripInsertTags ( $ objArticle -> headline ) ) ; } // Overwrite the page description if ( $ objArticle -> description ) { $ objPage -> description = $ objArticle -> description ; } elseif ( $ objArticle -> teaser ) { $ objPage -> description = $ this -> prepareMetaDescription ( $ objArticle -> teaser ) ; } $ bundles = System :: getContainer ( ) -> getParameter ( 'kernel.bundles' ) ; // HOOK: comments extension required if ( $ objArticle -> noComments || ! isset ( $ bundles [ 'ContaoCommentsBundle' ] ) ) { $ this -> Template -> allowComments = false ; return ; } /** @var NewsArchiveModel $objArchive */ $ objArchive = $ objArticle -> getRelated ( 'pid' ) ; $ this -> Template -> allowComments = $ objArchive -> allowComments ; // Comments are not allowed if ( ! $ objArchive -> allowComments ) { return ; } // Adjust the comments headline level $ intHl = min ( ( int ) str_replace ( 'h' , '' , $ this -> hl ) , 5 ) ; $ this -> Template -> hlc = 'h' . ( $ intHl + 1 ) ; $ this -> import ( Comments :: class , 'Comments' ) ; $ arrNotifies = array ( ) ; // Notify the system administrator if ( $ objArchive -> notify != 'notify_author' ) { $ arrNotifies [ ] = $ GLOBALS [ 'TL_ADMIN_EMAIL' ] ; } // Notify the author if ( $ objArchive -> notify != 'notify_admin' ) { /** @var UserModel $objAuthor */ if ( ( $ objAuthor = $ objArticle -> getRelated ( 'author' ) ) instanceof UserModel && $ objAuthor -> email != '' ) { $ arrNotifies [ ] = $ objAuthor -> email ; } } $ objConfig = new \ stdClass ( ) ; $ objConfig -> perPage = $ objArchive -> perPage ; $ objConfig -> order = $ objArchive -> sortOrder ; $ objConfig -> template = $ this -> com_template ; $ objConfig -> requireLogin = $ objArchive -> requireLogin ; $ objConfig -> disableCaptcha = $ objArchive -> disableCaptcha ; $ objConfig -> bbcode = $ objArchive -> bbcode ; $ objConfig -> moderate = $ objArchive -> moderate ; $ this -> Comments -> addCommentsToTemplate ( $ this -> Template , $ objConfig , 'tl_news' , $ objArticle -> id , $ arrNotifies ) ; }
Generate the module
Generate the module