Наследование: extends Model
Пример #1
0
 /**
  * Redirect to an internal page
  *
  * @param \PageModel $objPage
  */
 public function generate($objPage)
 {
     // Forward to the jumpTo or first published page
     if ($objPage->jumpTo) {
         /** @var \PageModel $objNextPage */
         $objNextPage = $objPage->getRelated('jumpTo');
     } else {
         $objNextPage = \PageModel::findFirstPublishedRegularByPid($objPage->id);
     }
     // Forward page does not exist
     if ($objNextPage === null) {
         $this->log('Forward page ID "' . $objPage->jumpTo . '" does not exist', __METHOD__, TL_ERROR);
         throw new ForwardPageNotFoundException('Forward page not found');
     }
     $strForceLang = null;
     // Check the target page language (see #4706)
     if (\Config::get('addLanguageToUrl')) {
         $objNextPage->loadDetails();
         // see #3983
         $strForceLang = $objNextPage->language;
     }
     $strGet = '';
     $strQuery = \Environment::get('queryString');
     $arrQuery = array();
     // Extract the query string keys (see #5867)
     if ($strQuery != '') {
         $arrChunks = explode('&', $strQuery);
         foreach ($arrChunks as $strChunk) {
             list($k, ) = explode('=', $strChunk, 2);
             $arrQuery[] = $k;
         }
     }
     // Add $_GET parameters
     if (!empty($_GET)) {
         foreach (array_keys($_GET) as $key) {
             if (\Config::get('addLanguageToUrl') && $key == 'language') {
                 continue;
             }
             // Ignore the query string parameters (see #5867)
             if (in_array($key, $arrQuery)) {
                 continue;
             }
             // Ignore the auto_item parameter (see #5886)
             if ($key == 'auto_item') {
                 $strGet .= '/' . \Input::get($key);
             } else {
                 $strGet .= '/' . $key . '/' . \Input::get($key);
             }
         }
     }
     // Append the query string (see #5867)
     if ($strQuery != '') {
         $strQuery = '?' . $strQuery;
     }
     $this->redirect($this->generateFrontendUrl($objNextPage->row(), $strGet, $strForceLang) . $strQuery, $objPage->redirect == 'temporary' ? 302 : 301);
 }
Пример #2
0
 /**
  * Return the URL to the jumpTo or first published page
  *
  * @param PageModel $objPage
  *
  * @return string
  *
  * @throws ForwardPageNotFoundException
  */
 private function getForwardUrl($objPage)
 {
     if ($objPage->jumpTo) {
         /** @var PageModel $objNextPage */
         $objNextPage = $objPage->getRelated('jumpTo');
     } else {
         $objNextPage = \PageModel::findFirstPublishedRegularByPid($objPage->id);
     }
     // Forward page does not exist
     if (!$objNextPage instanceof PageModel) {
         $this->log('Forward page ID "' . $objPage->jumpTo . '" does not exist', __METHOD__, TL_ERROR);
         throw new ForwardPageNotFoundException('Forward page not found');
     }
     $strGet = '';
     $strQuery = \Environment::get('queryString');
     $arrQuery = array();
     // Extract the query string keys (see #5867)
     if ($strQuery != '') {
         $arrChunks = explode('&', $strQuery);
         foreach ($arrChunks as $strChunk) {
             list($k) = explode('=', $strChunk, 2);
             $arrQuery[] = $k;
         }
     }
     // Add $_GET parameters
     if (!empty($_GET)) {
         foreach (array_keys($_GET) as $key) {
             if (\Config::get('addLanguageToUrl') && $key == 'language') {
                 continue;
             }
             // Ignore the query string parameters (see #5867)
             if (in_array($key, $arrQuery)) {
                 continue;
             }
             // Ignore the auto_item parameter (see #5886)
             if ($key == 'auto_item') {
                 $strGet .= '/' . \Input::get($key);
             } else {
                 $strGet .= '/' . $key . '/' . \Input::get($key);
             }
         }
     }
     // Append the query string (see #5867)
     if ($strQuery != '') {
         $strQuery = '?' . $strQuery;
     }
     return $objNextPage->getAbsoluteUrl($strGet) . $strQuery;
 }
Пример #3
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var PageModel $objPage */
     global $objPage;
     $lang = null;
     $host = null;
     // Start from the website root if there is no reference page
     if (!$this->rootPage) {
         $this->rootPage = $objPage->rootId;
     } else {
         $objRootPage = \PageModel::findWithDetails($this->rootPage);
         // Set the language
         if (\Config::get('addLanguageToUrl') && $objRootPage->rootLanguage != $objPage->rootLanguage) {
             $lang = $objRootPage->rootLanguage;
         }
         // Set the domain
         if ($objRootPage->rootId != $objPage->rootId && $objRootPage->domain != '' && $objRootPage->domain != $objPage->domain) {
             $host = $objRootPage->domain;
         }
     }
     $this->showLevel = 0;
     $this->hardLimit = false;
     $this->levelOffset = 0;
     $this->Template->items = $this->renderNavigation($this->rootPage, 1, $host, $lang);
 }
Пример #4
0
 /**
  * Prepare the output
  *
  * @param PageModel|integer $objRootPage
  *
  * @return PageModel
  *
  * @throws AccessDeniedException
  *
  * @internal Do not call this method in your code. It will be made private in Contao 5.0.
  */
 protected function prepare($objRootPage = null)
 {
     // Use the given root page object if available (thanks to Andreas Schempp)
     if ($objRootPage === null) {
         $objRootPage = $this->getRootPageFromUrl();
     } else {
         $objRootPage = \PageModel::findPublishedById(is_integer($objRootPage) ? $objRootPage : $objRootPage->id);
     }
     // Look for a 403 page
     $obj403 = \PageModel::find403ByPid($objRootPage->id);
     // Die if there is no page at all
     if (null === $obj403) {
         throw new AccessDeniedException('Forbidden');
     }
     // Forward to another page
     if ($obj403->autoforward && $obj403->jumpTo) {
         $objNextPage = \PageModel::findPublishedById($obj403->jumpTo);
         if (null === $objNextPage) {
             $this->log('Forward page ID "' . $obj403->jumpTo . '" does not exist', __METHOD__, TL_ERROR);
             throw new ForwardPageNotFoundException('Forward page not found');
         }
         $this->redirect($objNextPage->getFrontendUrl(), $obj403->redirect == 'temporary' ? 302 : 301);
     }
     return $obj403;
 }
 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;
 }
Пример #6
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var PageModel $objPage */
     global $objPage;
     // Set the trail and level
     if ($this->defineRoot && $this->rootPage > 0) {
         $trail = array($this->rootPage);
         $level = 0;
     } else {
         $trail = $objPage->trail;
         $level = $this->levelOffset > 0 ? $this->levelOffset : 0;
     }
     $lang = null;
     $host = null;
     // Overwrite the domain and language if the reference page belongs to a differnt root page (see #3765)
     if ($this->defineRoot && $this->rootPage > 0) {
         $objRootPage = \PageModel::findWithDetails($this->rootPage);
         // Set the language
         if (\Config::get('addLanguageToUrl') && $objRootPage->rootLanguage != $objPage->rootLanguage) {
             $lang = $objRootPage->rootLanguage;
         }
         // Set the domain
         if ($objRootPage->rootId != $objPage->rootId && $objRootPage->domain != '' && $objRootPage->domain != $objPage->domain) {
             $host = $objRootPage->domain;
         }
     }
     $this->Template->request = ampersand(\Environment::get('indexFreeRequest'));
     $this->Template->skipId = 'skipNavigation' . $this->id;
     $this->Template->skipNavigation = specialchars($GLOBALS['TL_LANG']['MSC']['skipNavigation']);
     $this->Template->items = $this->renderNavigation($trail[$level], 1, $host, $lang);
 }
Пример #7
0
 /**
  * Alter the "domain" key
  *
  * @return static The page model
  */
 public function loadDetails()
 {
     parent::loadDetails();
     // Return the current host if in dns list or the full dns list to have a domain restriction at all
     $this->domain = in_array(\Environment::get('host'), trimsplit(',', $this->domain)) ? \Environment::get('host') : $this->domain;
     return $this;
 }
 private function validateLanguageMainForPage($pageId)
 {
     $page = PageModel::findWithDetails($pageId);
     // Moving a root page does not affect language assignments
     if (null === $page || !$page->languageMain || 'root' === $page->type) {
         return;
     }
     $duplicates = PageModel::countBy(['id IN (' . implode(',', Database::getInstance()->getChildRecords($page->rootId, 'tl_page')) . ')', 'languageMain=?', 'id!=?'], [$page->languageMain, $page->id]);
     // Reset languageMain if another page in the new page tree has the same languageMain
     if ($duplicates > 0) {
         $this->resetPageAndChildren($page->id);
         return;
     }
     $pageFinder = new PageFinder();
     $masterRoot = $pageFinder->findMasterRootForPage($page);
     // Reset languageMain if current tree has no master or if it's the master tree
     if (null === $masterRoot || $masterRoot->id === $page->rootId) {
         $this->resetPageAndChildren($page->id);
         return;
     }
     // Reset languageMain if the current value is not a valid ID of the master tree
     if (!in_array($page->id, Database::getInstance()->getChildRecords($masterRoot->id, 'tl_page'), false)) {
         $this->resetPageAndChildren($page->id);
     }
 }
 /**
  * @inheritdoc
  */
 protected function getCurrentPage()
 {
     $node = Session::getInstance()->get('tl_page_node');
     if ($node < 1) {
         return null;
     }
     return PageModel::findByPk($node);
 }
 /**
  * Generate the page title with ##title## as placeholder for dynamic title
  *
  * @param PageModel $pageModel
  *
  * @return string
  */
 protected function generatePageTitle(PageModel $pageModel)
 {
     $pageModel->loadDetails();
     $layoutModel = LayoutModel::findByPk($pageModel->layout);
     if ($layoutModel === null) {
         return '##title##';
     }
     $title = $layoutModel->titleTag ?: '{{page::pageTitle}} - {{page::rootPageTitle}}';
     $title = str_replace('{{page::pageTitle}}', '##title##', $title);
     // Fake the global page object
     $GLOBALS['objPage'] = $pageModel;
     // Replace the insert tags
     $title = Controller::replaceInsertTags($title, false);
     // Remove the faked global page object
     unset($GLOBALS['objPage']);
     return $title;
 }
Пример #11
0
 /**
  * Return a redirect response object
  *
  * @param PageModel $objPage
  *
  * @return RedirectResponse
  */
 public function getResponse($objPage)
 {
     // Set last page visited
     if ($objPage->redirectBack) {
         $_SESSION['LAST_PAGE_VISITED'] = $this->getReferer();
     }
     $this->import('FrontendUser', 'User');
     $strRedirect = \Environment::get('base');
     // Redirect to last page visited
     if ($objPage->redirectBack && !empty($_SESSION['LAST_PAGE_VISITED'])) {
         $strRedirect = $_SESSION['LAST_PAGE_VISITED'];
     } elseif ($objPage->jumpTo && ($objTarget = $objPage->getRelated('jumpTo')) instanceof PageModel) {
         /** @var PageModel $objTarget */
         $strRedirect = $objTarget->getAbsoluteUrl();
     }
     $this->User->logout();
     return new RedirectResponse($strRedirect);
 }
 /**
  * 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);
 }
 /**
  * @inheritdoc
  */
 protected function getCurrentPage()
 {
     if (false === $this->currentArticle) {
         $this->currentArticle = ArticleModel::findByPk($this->dataContainer->id);
     }
     if (null === $this->currentArticle) {
         return null;
     }
     return PageModel::findWithDetails($this->currentArticle->pid);
 }
 /**
  * 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);
 }
Пример #15
0
 /**
  * Prepare the page object and redirect URL
  *
  * @param integer $rootPageId
  *
  * @return PageModel
  *
  * @throws NoActivePageFoundException
  */
 protected function getNextPage($rootPageId)
 {
     $objNextPage = \PageModel::findFirstPublishedByPid($rootPageId);
     // No published pages yet
     if (null === $objNextPage) {
         $this->log('No active page found under root page "' . $rootPageId . '")', __METHOD__, TL_ERROR);
         throw new NoActivePageFoundException('No active page found under root page.');
     }
     return $objNextPage;
 }
Пример #16
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     // Get all active pages
     $objPages = \PageModel::findPublishedRegularWithoutGuestsByIds($this->pages);
     // Return if there are no pages
     if ($objPages === null) {
         return;
     }
     $arrPages = array();
     // Sort the array keys according to the given order
     if ($this->orderPages != '') {
         $tmp = \StringUtil::deserialize($this->orderPages);
         if (!empty($tmp) && is_array($tmp)) {
             $arrPages = array_map(function () {
             }, array_flip($tmp));
         }
     }
     // Add the items to the pre-sorted array
     while ($objPages->next()) {
         $arrPages[$objPages->id] = $objPages->current();
     }
     $items = array();
     $arrPages = array_values(array_filter($arrPages));
     /** @var PageModel[] $arrPages */
     foreach ($arrPages as $objPage) {
         $objPage->title = \StringUtil::stripInsertTags($objPage->title);
         $objPage->pageTitle = \StringUtil::stripInsertTags($objPage->pageTitle);
         // Get href
         switch ($objPage->type) {
             case 'redirect':
                 $href = $objPage->url;
                 break;
             case 'forward':
                 if (($objNext = $objPage->getRelated('jumpTo')) instanceof PageModel) {
                     /** @var PageModel $objNext */
                     $href = $objNext->getFrontendUrl();
                     break;
                 }
                 // DO NOT ADD A break; STATEMENT
             // DO NOT ADD A break; STATEMENT
             default:
                 $href = $objPage->getFrontendUrl();
                 break;
         }
         $items[] = array('href' => $href, 'title' => \StringUtil::specialchars($objPage->pageTitle ?: $objPage->title), 'link' => $objPage->title);
     }
     $this->Template->items = $items;
     $this->Template->formId = 'tl_quicklink_' . $this->id;
     $this->Template->request = ampersand(\Environment::get('request'), true);
     $this->Template->title = $this->customLabel ?: $GLOBALS['TL_LANG']['MSC']['quicklink'];
     $this->Template->button = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['go']);
 }
 /**
  * @inheritdoc
  */
 protected function getCurrentPage()
 {
     /** @var Model $class */
     $class = $this->getModelClass();
     if (false === $this->current) {
         $this->current = $class::findByPk($this->dataContainer->id);
     }
     if (null === $this->current) {
         return null;
     }
     $pageId = $this->current->pid ? $this->current->getRelated('pid')->jumpTo : $this->current->jumpTo;
     return PageModel::findWithDetails($pageId);
 }
 /**
  * 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;
 }
 /**
  * Gets list of options for language root selection (linking multiple fallback roots on different domains).
  *
  * @param DataContainer $dc
  *
  * @return array
  */
 public function onLanguageRootOptions(DataContainer $dc)
 {
     /** @var PageModel[] $pages */
     $pages = PageModel::findBy(["tl_page.type='root'", "tl_page.fallback='1'", 'tl_page.languageRoot=0', 'tl_page.id!=?'], [$dc->id]);
     if (null === $pages) {
         return [];
     }
     $options = [];
     foreach ($pages as $page) {
         $options[$page->id] = sprintf('%s%s [%s]', $page->title, strlen($page->dns) ? ' (' . $page->dns . ')' : '', $page->language);
     }
     return $options;
 }
Пример #20
0
 /**
  * Redirect to the first active regular page
  *
  * @param integer $rootPageId
  * @param boolean $blnReturn
  * @param boolean $blnPreferAlias
  *
  * @return integer
  */
 public function generate($rootPageId, $blnReturn = false, $blnPreferAlias = false)
 {
     $objNextPage = \PageModel::findFirstPublishedByPid($rootPageId);
     // No published pages yet
     if (null === $objNextPage) {
         $this->log('No active page found under root page "' . $rootPageId . '")', __METHOD__, TL_ERROR);
         throw new NoActivePageFoundException('No active page found under root page.');
     }
     if (!$blnReturn) {
         /** @var \PageModel $objPage */
         global $objPage;
         $this->redirect($this->generateFrontendUrl($objNextPage->row(), null, $objPage->language));
     }
     if ($blnPreferAlias && $objNextPage->alias != '') {
         return $objNextPage->alias;
     }
     return $objNextPage->id;
 }
 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;
 }
Пример #22
0
 /**
  * Run the controller
  *
  * @return Response
  *
  * @throws PageNotFoundException
  */
 public function run()
 {
     $pageId = $this->getPageIdFromUrl();
     $objRootPage = null;
     // Load a website root page object if there is no page ID
     if ($pageId === null) {
         $objRootPage = $this->getRootPageFromUrl();
         /** @var PageRoot $objHandler */
         $objHandler = new $GLOBALS['TL_PTY']['root']();
         $pageId = $objHandler->generate($objRootPage->id, true, true);
     } elseif ($pageId === false) {
         $this->User->authenticate();
         throw new PageNotFoundException('Page not found: ' . \Environment::get('uri'));
     }
     $pageModel = \PageModel::findPublishedByIdOrAlias($pageId);
     // Throw a 404 error if the page could not be found
     if ($pageModel === null) {
         throw new PageNotFoundException('Page not found: ' . \Environment::get('uri'));
     }
     return $this->renderPage($pageModel);
 }
Пример #23
0
 public function checkLoginStatus($objPage, $objLayout, \PageRegular $objPageRegular)
 {
     global $objPage;
     $loggedIn = FE_USER_LOGGED_IN;
     if (\Input::get('logout')) {
         if (@$this->User->logout()) {
             $loggedIn = false;
         }
     }
     if (!$loggedIn && $objPage->type != "login" && (Config::get("globalLogin") == 1 || $objPage->type == "error_403")) {
         $loginPage = PageModel::findOneBy("type", "login");
         if (isset($loginPage) && $loginPage->published == 1) {
             $loginPage->loadDetails();
             $objPage = $loginPage;
             $handler = new LoginPage(\Environment::get("request"));
             $handler->generate($loginPage);
             exit;
         } else {
             System::log("Please create a Login-Page urgently!!", "LoginPage\\checkLoginStatus", TL_ERROR);
             if ($objPage->type == "error_403") {
                 return;
             }
             $page403_model = \PageModel::find403ByPid($objPage->rootId);
             if (isset($page403_model) && $page403_model->published == 1) {
                 $page403_model->loadDetails();
                 $objPage = $page403_model;
                 $handler = new PageError403();
                 $handler->generate($page403_model->id, $page403_model->rootId);
                 exit;
             } else {
                 System::log("Please create a 403-Error-Page urgently!!", "LoginPage\\checkLoginStatus", TL_ERROR);
                 $objPage->template = 'fe_login';
                 $objPage->templateGroup = $objLayout->templates;
                 $objPageRegular->createTemplate($objPage, $objLayout);
             }
         }
     }
 }
Пример #24
0
 /**
  * Generate a particular subpart of the tree and return it as HTML string
  *
  * @param integer $id
  * @param integer $level
  *
  * @return string
  */
 public function ajaxTreeView($id, $level)
 {
     if (!\Environment::get('isAjaxRequest')) {
         return '';
     }
     $return = '';
     $table = $this->strTable;
     $blnPtable = false;
     // Load parent table
     if ($GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 6) {
         $table = $this->ptable;
         \System::loadLanguageFile($table);
         $this->loadDataContainer($table);
         $blnPtable = true;
     }
     $blnProtected = false;
     // Check protected pages
     if ($table == 'tl_page') {
         $objParent = \PageModel::findWithDetails($id);
         $blnProtected = $objParent->protected ? true : false;
     }
     $margin = $level * 20;
     $hasSorting = $this->Database->fieldExists('sorting', $table);
     $arrIds = array();
     // Get records
     $objRows = $this->Database->prepare("SELECT id FROM " . $table . " WHERE pid=?" . ($hasSorting ? " ORDER BY sorting" : ""))->execute($id);
     while ($objRows->next()) {
         $arrIds[] = $objRows->id;
     }
     /** @var SessionInterface $objSession */
     $objSession = \System::getContainer()->get('session');
     $blnClipboard = false;
     $arrClipboard = $objSession->get('CLIPBOARD');
     // Check clipboard
     if (!empty($arrClipboard[$this->strTable])) {
         $blnClipboard = true;
         $arrClipboard = $arrClipboard[$this->strTable];
     }
     for ($i = 0, $c = count($arrIds); $i < $c; $i++) {
         $return .= ' ' . trim($this->generateTree($table, $arrIds[$i], array('p' => $arrIds[$i - 1], 'n' => $arrIds[$i + 1]), $hasSorting, $margin, $blnClipboard ? $arrClipboard : false, $id == $arrClipboard['id'] || is_array($arrClipboard['id']) && in_array($id, $arrClipboard['id']) || !$blnPtable && !is_array($arrClipboard['id']) && in_array($id, $this->Database->getChildRecords($arrClipboard['id'], $table)), $blnProtected));
     }
     return $return;
 }
 /**
  * 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');
     }
 }
Пример #26
0
 /**
  * Get the details of a page including inherited parameters
  *
  * @return PageModel The page model
  *
  * @throws NoRootPageFoundException If no root page is found
  */
 public function loadDetails()
 {
     // Loaded already
     if ($this->blnDetailsLoaded) {
         return $this;
     }
     // Set some default values
     $this->protected = (bool) $this->protected;
     $this->groups = $this->protected ? \StringUtil::deserialize($this->groups) : false;
     $this->layout = $this->includeLayout ? $this->layout : false;
     $this->mobileLayout = $this->includeLayout ? $this->mobileLayout : false;
     $this->cache = $this->includeCache ? $this->cache : false;
     $pid = $this->pid;
     $type = $this->type;
     $alias = $this->alias;
     $name = $this->title;
     $title = $this->pageTitle ?: $this->title;
     $folderUrl = '';
     $palias = '';
     $pname = '';
     $ptitle = '';
     $trail = array($this->id, $pid);
     // Inherit the settings
     if ($this->type == 'root') {
         $objParentPage = $this;
         // see #4610
     } else {
         // Load all parent pages
         $objParentPage = \PageModel::findParentsById($pid);
         if ($objParentPage !== null) {
             while ($pid > 0 && $type != 'root' && $objParentPage->next()) {
                 $pid = $objParentPage->pid;
                 $type = $objParentPage->type;
                 // Parent title
                 if ($ptitle == '') {
                     $palias = $objParentPage->alias;
                     $pname = $objParentPage->title;
                     $ptitle = $objParentPage->pageTitle ?: $objParentPage->title;
                 }
                 // Page title
                 if ($type != 'root') {
                     $alias = $objParentPage->alias;
                     $name = $objParentPage->title;
                     $title = $objParentPage->pageTitle ?: $objParentPage->title;
                     $folderUrl = basename($alias) . '/' . $folderUrl;
                     $trail[] = $objParentPage->pid;
                 }
                 // Cache
                 if ($objParentPage->includeCache && $this->cache === false) {
                     $this->cache = $objParentPage->cache;
                 }
                 // Layout
                 if ($objParentPage->includeLayout) {
                     if ($this->layout === false) {
                         $this->layout = $objParentPage->layout;
                     }
                     if ($this->mobileLayout === false) {
                         $this->mobileLayout = $objParentPage->mobileLayout;
                     }
                 }
                 // Protection
                 if ($objParentPage->protected && $this->protected === false) {
                     $this->protected = true;
                     $this->groups = \StringUtil::deserialize($objParentPage->groups);
                 }
             }
         }
         // Set the titles
         $this->mainAlias = $alias;
         $this->mainTitle = $name;
         $this->mainPageTitle = $title;
         $this->parentAlias = $palias;
         $this->parentTitle = $pname;
         $this->parentPageTitle = $ptitle;
         $this->folderUrl = $folderUrl;
     }
     // Set the root ID and title
     if ($objParentPage !== null && $objParentPage->type == 'root') {
         $this->rootId = $objParentPage->id;
         $this->rootAlias = $objParentPage->alias;
         $this->rootTitle = $objParentPage->title;
         $this->rootPageTitle = $objParentPage->pageTitle ?: $objParentPage->title;
         $this->domain = $objParentPage->dns;
         $this->rootLanguage = $objParentPage->language;
         $this->language = $objParentPage->language;
         $this->staticFiles = $objParentPage->staticFiles;
         $this->staticPlugins = $objParentPage->staticPlugins;
         $this->dateFormat = $objParentPage->dateFormat;
         $this->timeFormat = $objParentPage->timeFormat;
         $this->datimFormat = $objParentPage->datimFormat;
         $this->adminEmail = $objParentPage->adminEmail;
         // Store whether the root page has been published
         $time = \Date::floorToMinute();
         $this->rootIsPublic = $objParentPage->published && ($objParentPage->start == '' || $objParentPage->start <= $time) && ($objParentPage->stop == '' || $objParentPage->stop > $time + 60);
         $this->rootIsFallback = true;
         $this->rootUseSSL = $objParentPage->useSSL;
         $this->rootFallbackLanguage = $objParentPage->language;
         // Store the fallback language (see #6874)
         if (!$objParentPage->fallback) {
             $this->rootIsFallback = false;
             $this->rootFallbackLanguage = null;
             $objFallback = static::findPublishedFallbackByHostname($objParentPage->dns);
             if ($objFallback !== null) {
                 $this->rootFallbackLanguage = $objFallback->language;
             }
         }
     } elseif (TL_MODE == 'FE' && $this->type != 'root') {
         \System::log('Page ID "' . $this->id . '" does not belong to a root page', __METHOD__, TL_ERROR);
         throw new NoRootPageFoundException('No root page found');
     }
     $this->trail = array_reverse($trail);
     // Do not cache protected pages
     if ($this->protected) {
         $this->cache = 0;
     }
     // Use the global date format if none is set (see #6104)
     if ($this->dateFormat == '') {
         $this->dateFormat = \Config::get('dateFormat');
     }
     if ($this->timeFormat == '') {
         $this->timeFormat = \Config::get('timeFormat');
     }
     if ($this->datimFormat == '') {
         $this->datimFormat = \Config::get('datimFormat');
     }
     // Prevent saving (see #6506 and #7199)
     $this->preventSaving();
     $this->blnDetailsLoaded = true;
     return $this;
 }
Пример #27
0
 /**
  * Display a login form
  *
  * @return string
  */
 public function generate()
 {
     if (TL_MODE == 'BE') {
         /** @var BackendTemplate|object $objTemplate */
         $objTemplate = new \BackendTemplate('be_wildcard');
         $objTemplate->wildcard = '### ' . Utf8::strtoupper($GLOBALS['TL_LANG']['FMD']['login'][0]) . ' ###';
         $objTemplate->title = $this->headline;
         $objTemplate->id = $this->id;
         $objTemplate->link = $this->name;
         $objTemplate->href = 'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' . $this->id;
         return $objTemplate->parse();
     }
     // Set the last page visited
     if (!$_POST && $this->redirectBack) {
         $_SESSION['LAST_PAGE_VISITED'] = $this->getReferer();
     }
     // Login
     if (\Input::post('FORM_SUBMIT') == 'tl_login_' . $this->id) {
         // Check whether username and password are set
         if (empty($_POST['username']) || empty($_POST['password'])) {
             \System::getContainer()->get('session')->getFlashBag()->set($this->strFlashType, $GLOBALS['TL_LANG']['MSC']['emptyField']);
             $this->reload();
         }
         $this->import('FrontendUser', 'User');
         $strRedirect = \Environment::get('request');
         // Redirect to the last page visited
         if ($this->redirectBack && $_SESSION['LAST_PAGE_VISITED'] != '') {
             $strRedirect = $_SESSION['LAST_PAGE_VISITED'];
         } else {
             // Redirect to the jumpTo page
             if ($this->jumpTo && ($objTarget = $this->objModel->getRelated('jumpTo')) instanceof PageModel) {
                 /** @var PageModel $objTarget */
                 $strRedirect = $objTarget->getFrontendUrl();
             }
             // Overwrite the jumpTo page with an individual group setting
             $objMember = \MemberModel::findByUsername(\Input::post('username'));
             if ($objMember !== null) {
                 $arrGroups = \StringUtil::deserialize($objMember->groups);
                 if (!empty($arrGroups) && is_array($arrGroups)) {
                     $objGroupPage = \PageModel::findFirstActiveByMemberGroups($arrGroups);
                     if ($objGroupPage !== null) {
                         $strRedirect = $objGroupPage->getFrontendUrl();
                     }
                 }
             }
         }
         // Auto login is not allowed
         if (isset($_POST['autologin']) && !$this->autologin) {
             unset($_POST['autologin']);
             \Input::setPost('autologin', null);
         }
         // Login and redirect
         if ($this->User->login()) {
             $this->redirect($strRedirect);
         }
         $this->reload();
     }
     // Logout and redirect to the website root if the current page is protected
     if (\Input::post('FORM_SUBMIT') == 'tl_logout_' . $this->id) {
         /** @var PageModel $objPage */
         global $objPage;
         $this->import('FrontendUser', 'User');
         $strRedirect = \Environment::get('request');
         // Redirect to last page visited
         if ($this->redirectBack && strlen($_SESSION['LAST_PAGE_VISITED'])) {
             $strRedirect = $_SESSION['LAST_PAGE_VISITED'];
         } elseif ($objPage->protected) {
             $strRedirect = \Environment::get('base');
         }
         // Logout and redirect
         if ($this->User->logout()) {
             $this->redirect($strRedirect);
         }
         $this->reload();
     }
     return parent::generate();
 }
Пример #28
0
 /**
  * Get all allowed pages and return them as string
  *
  * @return string
  */
 public function createPageList()
 {
     $this->import('BackendUser', 'User');
     if ($this->User->isAdmin) {
         return $this->doCreatePageList();
     }
     $return = '';
     $processed = array();
     foreach ($this->eliminateNestedPages($this->User->pagemounts) as $page) {
         $objPage = \PageModel::findWithDetails($page);
         // Root page mounted
         if ($objPage->type == 'root') {
             $title = $objPage->title;
             $start = $objPage->id;
         } else {
             $title = $objPage->rootTitle;
             $start = $objPage->rootId;
         }
         // Do not process twice
         if (in_array($start, $processed)) {
             continue;
         }
         // Skip websites that run under a different domain (see #2387)
         if ($objPage->domain && $objPage->domain != \Environment::get('host')) {
             continue;
         }
         $processed[] = $start;
         $return .= '<optgroup label="' . $title . '">' . $this->doCreatePageList($start) . '</optgroup>';
     }
     return $return;
 }
Пример #29
0
 /**
  * Recursively get all quicknav pages and return them as array
  *
  * @param integer $pid
  * @param integer $level
  * @param string  $host
  * @param string  $language
  *
  * @return array
  */
 protected function getQuicknavPages($pid, $level = 1, $host = null, $language = null)
 {
     /** @var PageModel $objPage */
     global $objPage;
     $groups = array();
     $arrPages = array();
     // Get all groups of the current front end user
     if (FE_USER_LOGGED_IN) {
         $this->import('FrontendUser', 'User');
         $groups = $this->User->groups;
     }
     // Get all active subpages
     $objSubpages = \PageModel::findPublishedRegularWithoutGuestsByPid($pid);
     if ($objSubpages === null) {
         return array();
     }
     ++$level;
     foreach ($objSubpages as $objSubpage) {
         $_groups = \StringUtil::deserialize($objSubpage->groups);
         // Override the domain (see #3765)
         if ($host !== null) {
             $objSubpage->domain = $host;
         }
         // Do not show protected pages unless a back end or front end user is logged in
         if (!$objSubpage->protected || !is_array($_groups) && FE_USER_LOGGED_IN || BE_USER_LOGGED_IN || is_array($_groups) && array_intersect($_groups, $groups) || $this->showProtected) {
             // Do not skip the current page here! (see #4523)
             // Check hidden pages
             if (!$objSubpage->hide || $this->showHidden) {
                 $arrPages[] = array('level' => $level - 2, 'title' => \StringUtil::specialchars(\StringUtil::stripInsertTags($objSubpage->pageTitle ?: $objSubpage->title)), 'href' => $objSubpage->getFrontendUrl(), 'link' => \StringUtil::stripInsertTags($objSubpage->title));
                 // Subpages
                 if (!$this->showLevel || $this->showLevel >= $level || !$this->hardLimit && ($objPage->id == $objSubpage->id || in_array($objPage->id, $this->Database->getChildRecords($objSubpage->id, 'tl_page')))) {
                     $subpages = $this->getQuicknavPages($objSubpage->id, $level);
                     if (is_array($subpages)) {
                         $arrPages = array_merge($arrPages, $subpages);
                     }
                 }
             }
         }
     }
     return $arrPages;
 }
Пример #30
0
 /**
  * Fetch the page model
  *
  * @param array $entry
  *
  * @return PageModel|null
  */
 private function fetchPageModel(array $entry)
 {
     $pageId = $this->fetchPageId($entry);
     if ($pageId === null) {
         return null;
     }
     return PageModel::findPublishedById($pageId);
 }