/**
  * Get the page model
  *
  * @param int $id
  *
  * @return PageModel|null
  */
 protected function getPageModel($id)
 {
     if (($newsModel = NewsModel::findByPk($id)) === null) {
         return null;
     }
     if (($newsArchiveModel = NewsArchiveModel::findByPk($newsModel->pid)) === null) {
         return null;
     }
     return PageModel::findByPk($newsArchiveModel->jumpTo);
 }
 protected function compile()
 {
     global $objPage;
     // Get the current news item
     $objNewsItem = NewsModel::findPublishedByParentAndIdOrAlias(Input::get('items'), $this->news_archives);
     if ($objNewsItem === null) {
         parent::compile();
     }
     $objPage->canonicalType = $objNewsItem->canonicalType;
     $objPage->canonicalJumpTo = $objNewsItem->canonicalJumpTo;
     $objPage->canonicalWebsite = $objNewsItem->canonicalWebsite;
     if ($objNewsItem->canonicalType == 'self') {
         $objPage->canonicalType = 'external';
         $objPage->canonicalWebsite = Environment::get('url') . TL_PATH . '/' . Environment::get('request');
     }
     parent::compile();
 }
Esempio n. 3
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var PageModel $objPage */
     global $objPage;
     $limit = null;
     $offset = 0;
     $intBegin = 0;
     $intEnd = 0;
     $intYear = \Input::get('year');
     $intMonth = \Input::get('month');
     $intDay = \Input::get('day');
     // Jump to the current period
     if (!isset($_GET['year']) && !isset($_GET['month']) && !isset($_GET['day']) && $this->news_jumpToCurrent != 'all_items') {
         switch ($this->news_format) {
             case 'news_year':
                 $intYear = date('Y');
                 break;
             default:
             case 'news_month':
                 $intMonth = date('Ym');
                 break;
             case 'news_day':
                 $intDay = date('Ymd');
                 break;
         }
     }
     // Create the date object
     try {
         if ($intYear) {
             $strDate = $intYear;
             $objDate = new \Date($strDate, 'Y');
             $intBegin = $objDate->yearBegin;
             $intEnd = $objDate->yearEnd;
             $this->headline .= ' ' . date('Y', $objDate->tstamp);
         } elseif ($intMonth) {
             $strDate = $intMonth;
             $objDate = new \Date($strDate, 'Ym');
             $intBegin = $objDate->monthBegin;
             $intEnd = $objDate->monthEnd;
             $this->headline .= ' ' . \Date::parse('F Y', $objDate->tstamp);
         } elseif ($intDay) {
             $strDate = $intDay;
             $objDate = new \Date($strDate, 'Ymd');
             $intBegin = $objDate->dayBegin;
             $intEnd = $objDate->dayEnd;
             $this->headline .= ' ' . \Date::parse($objPage->dateFormat, $objDate->tstamp);
         } elseif ($this->news_jumpToCurrent == 'all_items') {
             $intBegin = 0;
             $intEnd = time();
         }
     } catch (\OutOfBoundsException $e) {
         throw new PageNotFoundException('Page not found: ' . \Environment::get('uri'));
     }
     $this->Template->articles = array();
     // Split the result
     if ($this->perPage > 0) {
         // Get the total number of items
         $intTotal = \NewsModel::countPublishedFromToByPids($intBegin, $intEnd, $this->news_archives);
         if ($intTotal > 0) {
             $total = $intTotal;
             // Get the current page
             $id = 'page_a' . $this->id;
             $page = \Input::get($id) !== null ? \Input::get($id) : 1;
             // Do not index or cache the page if the page number is outside the range
             if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) {
                 throw new PageNotFoundException('Page not found: ' . \Environment::get('uri'));
             }
             // Set limit and offset
             $limit = $this->perPage;
             $offset = (max($page, 1) - 1) * $this->perPage;
             // Add the pagination menu
             $objPagination = new \Pagination($total, $this->perPage, \Config::get('maxPaginationLinks'), $id);
             $this->Template->pagination = $objPagination->generate("\n  ");
         }
     }
     // Get the news items
     if (isset($limit)) {
         $objArticles = \NewsModel::findPublishedFromToByPids($intBegin, $intEnd, $this->news_archives, $limit, $offset);
     } else {
         $objArticles = \NewsModel::findPublishedFromToByPids($intBegin, $intEnd, $this->news_archives);
     }
     // Add the articles
     if ($objArticles !== null) {
         $this->Template->articles = $this->parseArticles($objArticles);
     }
     $this->Template->headline = trim($this->headline);
     $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];
     $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['empty'];
 }
 /**
  * @inheritdoc
  */
 protected function findPublishedBy(array $columns, array $values = array(), array $options = array())
 {
     return NewsModel::findOneBy($this->addPublishedConditions($columns, NewsModel::getTable()), $values, $options);
 }
 /**
  * Generate a URL and return it as string.
  *
  * @param EventDispatcherInterface $eventDispatcher The event dispatcher.
  *
  * @param NewsModel                $objItem         The news model.
  *
  * @param boolean                  $blnAddArchive   Add the current archive parameter (news archive) (default: false).
  *
  * @return string
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 protected function generateNewsUrl(EventDispatcherInterface $eventDispatcher, NewsModel $objItem, $blnAddArchive = false)
 {
     $url = null;
     switch ($objItem->source) {
         // Link to an external page.
         case 'external':
             if (substr($objItem->url, 0, 7) == 'mailto:') {
                 $url = StringHelper::encodeEmail($objItem->url);
             } else {
                 $url = ampersand($objItem->url);
             }
             break;
             // Link to an internal page.
         // Link to an internal page.
         case 'internal':
             if (($objTarget = $objItem->getRelated('jumpTo')) !== null) {
                 $generateFrontendUrlEvent = new GenerateFrontendUrlEvent($objTarget->row());
                 $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_GENERATE_FRONTEND_URL, $generateFrontendUrlEvent);
                 $url = $generateFrontendUrlEvent->getUrl();
             }
             break;
             // Link to an article.
         // Link to an article.
         case 'article':
             if (($objArticle = ArticleModel::findByPk($objItem->articleId, array('eager' => true))) !== null && ($objPid = $objArticle->getRelated('pid')) !== null) {
                 $generateFrontendUrlEvent = new GenerateFrontendUrlEvent($objPid->row(), '/articles/' . (!$GLOBALS['TL_CONFIG']['disableAlias'] && $objArticle->alias != '' ? $objArticle->alias : $objArticle->id));
                 $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_GENERATE_FRONTEND_URL, $generateFrontendUrlEvent);
                 $url = $generateFrontendUrlEvent->getUrl();
             }
             break;
         default:
     }
     // Link to the default page.
     if ($url === null) {
         $objPage = PageModel::findByPk($objItem->getRelated('pid')->jumpTo);
         if ($objPage === null) {
             $url = ampersand(Environment::get('request'), true);
         } else {
             $generateFrontendUrlEvent = new GenerateFrontendUrlEvent($objPage->row(), ($GLOBALS['TL_CONFIG']['useAutoItem'] && !$GLOBALS['TL_CONFIG']['disableAlias'] ? '/' : '/items/') . (!$GLOBALS['TL_CONFIG']['disableAlias'] && $objItem->alias != '' ? $objItem->alias : $objItem->id));
             $eventDispatcher->dispatch(ContaoEvents::CONTROLLER_GENERATE_FRONTEND_URL, $generateFrontendUrlEvent);
             $url = $generateFrontendUrlEvent->getUrl();
         }
         // Add the current archive parameter (news archive).
         if ($blnAddArchive && Input::get('month') != '') {
             $url .= ($GLOBALS['TL_CONFIG']['disableAlias'] ? '&amp;' : '?') . 'month=' . Input::get('month');
         }
     }
     return $url;
 }
Esempio n. 6
0
 /**
  * Generate the module
  */
 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);
     if (null === $objArticle) {
         throw new PageNotFoundException('Page not found');
     }
     $arrArticle = $this->parseArticle($objArticle);
     $this->Template->articles = $arrArticle;
     // Overwrite the page title (see #2853 and #4955)
     if ($objArticle->headline != '') {
         $objPage->pageTitle = strip_tags(strip_insert_tags($objArticle->headline));
     }
     // Overwrite the page description
     if ($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(intval(str_replace('h', '', $this->hl)), 5);
     $this->Template->hlc = 'h' . ($intHl + 1);
     $this->import('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')) !== null && $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 missing translation warning for news child records.
  *
  * @param array $args
  * @param mixed $previousResult
  *
  * @return string
  */
 public function onNewsChildRecords(array $args, $previousResult = null)
 {
     $row = $args[0];
     $label = (string) $previousResult;
     $archive = NewsArchiveModel::findByPk($row['pid']);
     if ($archive->master && (!$row['languageMain'] || null === NewsModel::findByPk($row['languageMain']))) {
         return $this->generateLabelWithWarning($label);
     }
     return $label;
 }
Esempio n. 8
0
 /**
  * Fetch the matching items
  *
  * @param  array   $newsArchives
  * @param  boolean $blnFeatured
  * @param  integer $limit
  * @param  integer $offset
  *
  * @return Model\Collection|NewsModel|null
  */
 protected function fetchItems($newsArchives, $blnFeatured, $limit, $offset)
 {
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['newsListFetchItems']) && is_array($GLOBALS['TL_HOOKS']['newsListFetchItems'])) {
         foreach ($GLOBALS['TL_HOOKS']['newsListFetchItems'] as $callback) {
             if (($objCollection = \System::importStatic($callback[0])->{$callback[1]}($newsArchives, $blnFeatured, $limit, $offset, $this)) === false) {
                 continue;
             }
             if ($objCollection === null || $objCollection instanceof Model\Collection) {
                 return $objCollection;
             }
         }
     }
     return \NewsModel::findPublishedByPids($newsArchives, $blnFeatured, $limit, $offset);
 }
Esempio n. 9
0
 /**
  * Generates URL to a news item.
  *
  * @param NewsModel $news
  *
  * @return string
  */
 private function generateNewsReaderUrl(NewsModel $news)
 {
     /** @var PageModel $targetPage */
     if (!($archive = $news->getRelated('pid')) instanceof NewsArchiveModel || !($targetPage = $archive->getRelated('jumpTo')) instanceof PageModel) {
         return '';
     }
     /** @var Config $config */
     $config = $this->framework->getAdapter(Config::class);
     return $targetPage->getFrontendUrl(($config->get('useAutoItem') ? '/' : '/items/') . ($news->alias ?: $news->id));
 }