public function onMasterOptions(DataContainer $dc)
 {
     if (($jumpTo = PageModel::findByPk($dc->activeRecord->jumpTo)) === null) {
         return [];
     }
     $associated = [];
     $pageFinder = new PageFinder();
     foreach ($pageFinder->findAssociatedForPage($jumpTo, true) as $page) {
         $associated[] = $page->id;
     }
     if (0 === count($associated)) {
         return [];
     }
     $options = [];
     $result = Database::getInstance()->prepare('
             SELECT id, title 
             FROM ' . $this->table . ' 
             WHERE jumpTo IN (' . implode(',', $associated) . ') AND master=0 
             ORDER BY title
         ')->execute($dc->activeRecord->language);
     while ($result->next()) {
         $options[$result->id] = sprintf($GLOBALS['TL_LANG'][$this->table]['isSlave'], $result->title);
     }
     return $options;
 }
 /**
  * @inheritdoc
  */
 protected function getCurrentPage()
 {
     $node = Session::getInstance()->get('tl_page_node');
     if ($node < 1) {
         return null;
     }
     return PageModel::findByPk($node);
 }
 /**
  * Generate the URL path
  *
  * @param PageModel $pageModel
  *
  * @return string
  */
 protected function generateUrlPath(PageModel $pageModel)
 {
     $pageModel->loadDetails();
     if (($rootModel = PageModel::findByPk($pageModel->rootId)) === null) {
         return '';
     }
     return ($rootModel->rootUseSSL ? 'https://' : 'http://') . ($rootModel->domain ?: Environment::get('host')) . TL_PATH . '/' . $pageModel->alias . '/';
 }
 /**
  * Get the page model
  *
  * @param int $id
  *
  * @return PageModel|null
  */
 protected function getPageModel($id)
 {
     if (($eventModel = CalendarEventsModel::findByPk($id)) === null) {
         return '';
     }
     if (($calendarModel = CalendarModel::findByPk($eventModel->pid)) === null) {
         return '';
     }
     return PageModel::findByPk($calendarModel->jumpTo);
 }
 /**
  * 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);
 }
 /**
  * Adds missing translation warning to article tree.
  *
  * @param array $args
  * @param mixed $previousResult
  *
  * @return string
  */
 public function onArticleLabel(array $args, $previousResult = null)
 {
     list($row, $label) = $args;
     if ($previousResult) {
         $label = $previousResult;
     }
     $page = PageModel::findWithDetails($row['pid']);
     $root = PageModel::findByPk($page->rootId);
     if ((!$root->fallback || $root->languageRoot > 0) && $page->languageMain > 0 && null !== PageModel::findByPk($page->languageMain) && (!$row['languageMain'] || null === ArticleModel::findByPk($row['languageMain']))) {
         return $this->generateLabelWithWarning($label);
     }
     return $label;
 }
 public function onLanguageMainOptions(DataContainer $dc)
 {
     $pageFinder = new PageFinder();
     $current = ArticleModel::findByPk($dc->id);
     $page = PageModel::findByPk($current->pid);
     if (null === $page || ($master = $pageFinder->findAssociatedInMaster($page)) === null) {
         return [];
     }
     $options = [];
     $result = Database::getInstance()->prepare('
             SELECT id, title 
             FROM tl_article 
             WHERE pid=? AND id NOT IN (
                 SELECT languageMain FROM tl_article WHERE id!=? AND pid=? AND languageMain > 0
             )
         ')->execute($master->id, $current->id, $page->id);
     while ($result->next()) {
         $options[$result->id] = sprintf('%s [ID %s]', $result->title, $result->id);
     }
     return $options;
 }
 /**
  * @param PageModel $page
  * @param bool      $skipCurrent
  *
  * @return \Contao\PageModel[]
  */
 public function findAssociatedForPage(PageModel $page, $skipCurrent = false)
 {
     if ('root' === $page->type) {
         return $this->findRootPagesForPage($page, $skipCurrent);
     }
     $page->loadDetails();
     $t = $page::getTable();
     if ($page->rootIsFallback && ($root = PageModel::findByPk($page->rootId)) !== null && !$root->languageRoot) {
         $values = [$page->id, $page->id];
     } elseif (!$page->languageMain) {
         return $skipCurrent ? [] : [$page];
     } else {
         $values = [$page->languageMain, $page->languageMain];
     }
     $columns = ["({$t}.id=? OR {$t}.languageMain=?)"];
     if ($skipCurrent) {
         $columns[] = "{$t}.id!=?";
         $values[] = $page->id;
     }
     $this->addPublishingConditions($columns, $t);
     return $this->findPages($columns, $values);
 }
 /**
  * Limits the available pages in page picker to the fallback page tree.
  *
  * @param int $pageId
  */
 private function setRootNodesForPage($pageId)
 {
     $page = PageModel::findWithDetails($pageId);
     $root = PageModel::findByPk($page->rootId);
     if ($root->fallback && (!$root->languageRoot || ($languageRoot = PageModel::findByPk($root->languageRoot)) === null)) {
         return;
     }
     $pageFinder = new PageFinder();
     $masterRoot = $pageFinder->findMasterRootForPage($page);
     if (null !== $masterRoot) {
         $GLOBALS['TL_DCA']['tl_page']['fields']['languageMain']['eval']['rootNodes'] = Database::getInstance()->prepare('SELECT id FROM tl_page WHERE pid=?')->execute($masterRoot->id)->fetchEach('id');
     }
 }
Exemplo n.º 10
0
 /**
  * Add the file meta information to the request
  *
  * @param string  $strUuid
  * @param string  $strPtable
  * @param integer $intPid
  */
 public static function addFileMetaInformationToRequest($strUuid, $strPtable, $intPid)
 {
     $objFile = \FilesModel::findByUuid($strUuid);
     if ($objFile === null) {
         return;
     }
     $arrMeta = \StringUtil::deserialize($objFile->meta);
     if (empty($arrMeta)) {
         return;
     }
     $objPage = null;
     if ($strPtable == 'tl_article') {
         $objPage = \PageModel::findOneBy(array('tl_page.id=(SELECT pid FROM tl_article WHERE id=?)'), $intPid);
     } else {
         // HOOK: support custom modules
         if (isset($GLOBALS['TL_HOOKS']['addFileMetaInformationToRequest']) && is_array($GLOBALS['TL_HOOKS']['addFileMetaInformationToRequest'])) {
             foreach ($GLOBALS['TL_HOOKS']['addFileMetaInformationToRequest'] as $callback) {
                 if (($val = \System::importStatic($callback[0])->{$callback[1]}($strPtable, $intPid)) !== false) {
                     $objPage = $val;
                 }
             }
             if ($objPage instanceof Result && $objPage->numRows < 1) {
                 return;
             }
             if (is_object($objPage) && !$objPage instanceof PageModel) {
                 $objPage = \PageModel::findByPk($objPage->id);
             }
         }
     }
     if ($objPage === null) {
         return;
     }
     $objPage->loadDetails();
     // Convert the language to a locale (see #5678)
     $strLanguage = str_replace('-', '_', $objPage->rootLanguage);
     if (isset($arrMeta[$strLanguage])) {
         if (\Input::post('title') == '' && !empty($arrMeta[$strLanguage]['title'])) {
             \Input::setPost('title', $arrMeta[$strLanguage]['title']);
         }
         if (\Input::post('alt') == '' && !empty($arrMeta[$strLanguage]['alt'])) {
             \Input::setPost('alt', $arrMeta[$strLanguage]['alt']);
         }
         if (\Input::post('caption') == '' && !empty($arrMeta[$strLanguage]['caption'])) {
             \Input::setPost('caption', $arrMeta[$strLanguage]['caption']);
         }
     }
 }
 /**
  * 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;
 }
 /**
  * Get the page model
  *
  * @param int $id
  *
  * @return PageModel|null
  */
 protected function getPageModel($id)
 {
     return PageModel::findByPk($id);
 }
Exemplo n.º 13
0
 /**
  * Create links and remember pages that have been processed
  *
  * @param FaqModel $objFaq
  *
  * @return string
  *
  * @throws \Exception
  */
 protected function generateFaqLink($objFaq)
 {
     /** @var FaqCategoryModel $objCategory */
     $objCategory = $objFaq->getRelated('pid');
     $jumpTo = intval($objCategory->jumpTo);
     // A jumpTo page is not mandatory for FAQ categories (see #6226) but required for the FAQ list module
     if ($jumpTo < 1) {
         throw new \Exception("FAQ categories without redirect page cannot be used in an FAQ list");
     }
     // Get the URL from the jumpTo page of the category
     if (!isset($this->arrTargets[$jumpTo])) {
         $this->arrTargets[$jumpTo] = ampersand(\Environment::get('request'), true);
         if ($jumpTo > 0 && ($objTarget = \PageModel::findByPk($jumpTo)) !== null) {
             /** @var PageModel $objTarget */
             $this->arrTargets[$jumpTo] = ampersand($objTarget->getFrontendUrl(\Config::get('useAutoItem') ? '/%s' : '/items/%s'));
         }
     }
     return sprintf($this->arrTargets[$jumpTo], $objFaq->alias ?: $objFaq->id);
 }
 /**
  * Handles submitting a page and resets tl_page.languageMain if necessary.
  *
  * @param DataContainer $dc
  */
 public function onSubmit(DataContainer $dc)
 {
     if ('root' === $dc->activeRecord->type && $dc->activeRecord->fallback && (!$dc->activeRecord->languageRoot || null === PageModel::findByPk($dc->activeRecord->languageRoot))) {
         $this->resetPageAndChildren($dc->id);
     }
 }