/** * 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) { header('HTTP/1.1 404 Not Found'); $this->log('Forward page ID "' . $objPage->jumpTo . '" does not exist', __METHOD__, TL_ERROR); die_nicely('be_no_forward', '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('disableAlias') && $key == 'id') { continue; } 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); }
/** * Generate an error 403 page * @param integer * @param object */ public function generate($pageId, $objRootPage = null) { // Add a log entry $this->log('Access to page ID "' . $pageId . '" denied', __METHOD__, TL_ERROR); // 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 an error_403 page $obj403 = \PageModel::find403ByPid($objRootPage->id); // Die if there is no page at all if ($obj403 === null) { header('HTTP/1.1 403 Forbidden'); die_nicely('be_forbidden', 'Forbidden'); } // Generate the error page if (!$obj403->autoforward || !$obj403->jumpTo) { global $objPage; $objPage = $obj403->loadDetails(); $objHandler = new $GLOBALS['TL_PTY']['regular'](); header('HTTP/1.1 403 Forbidden'); $objHandler->generate($objPage); exit; } // Forward to another page $objNextPage = \PageModel::findPublishedById($obj403->jumpTo); if ($objNextPage === null) { header('HTTP/1.1 403 Forbidden'); $this->log('Forward page ID "' . $obj403->jumpTo . '" does not exist', __METHOD__, TL_ERROR); die_nicely('be_no_forward', 'Forward page not found'); } $this->redirect($this->generateFrontendUrl($objNextPage->row(), null, $objRootPage->language), $obj403->redirect == 'temporary' ? 302 : 301); }
/** * Generate an error 404 page * * @param integer $pageId * @param string $strDomain * @param string $strHost * @param boolean $blnUnusedGet */ public function generate($pageId, $strDomain = null, $strHost = null, $blnUnusedGet = false) { // Add a log entry if ($blnUnusedGet) { $this->log('The request for page ID "' . $pageId . '" contained unused GET parameters: "' . implode('", "', \Input::getUnusedGet()) . '" (' . \Environment::get('base') . \Environment::get('request') . ')', __METHOD__, TL_ERROR); } elseif ($strDomain !== null || $strHost !== null) { $this->log('Page ID "' . $pageId . '" was requested via "' . $strHost . '" but can only be accessed via "' . $strDomain . '" (' . \Environment::get('base') . \Environment::get('request') . ')', __METHOD__, TL_ERROR); } elseif ($pageId != 'favicon.ico' && $pageId != 'robots.txt') { $this->log('No active page for page ID "' . $pageId . '", host "' . \Environment::get('host') . '" and languages "' . implode(', ', \Environment::get('httpAcceptLanguage')) . '" (' . \Environment::get('base') . \Environment::get('request') . ')', __METHOD__, TL_ERROR); } // Check the search index (see #3761) \Search::removeEntry(\Environment::get('request')); // Find the matching root page $objRootPage = $this->getRootPageFromUrl(); // Forward if the language should be but is not set (see #4028) if (\Config::get('addLanguageToUrl')) { // Get the request string without the index.php fragment if (\Environment::get('request') == 'index.php') { $strRequest = ''; } else { $strRequest = str_replace('index.php/', '', \Environment::get('request')); } // Only redirect if there is no language fragment (see #4669) if ($strRequest != '' && !preg_match('@^[a-z]{2}(-[A-Z]{2})?/@', $strRequest)) { // Handle language fragments without trailing slash (see #7666) if (preg_match('@^[a-z]{2}(-[A-Z]{2})?$@', $strRequest)) { $this->redirect(($GLOBALS['TL_CONFIG']['rewriteURL'] ? '' : 'index.php/') . $strRequest . '/', 301); } else { $this->redirect(($GLOBALS['TL_CONFIG']['rewriteURL'] ? '' : 'index.php/') . $objRootPage->language . '/' . $strRequest, 301); } } } // Look for a 404 page $obj404 = \PageModel::find404ByPid($objRootPage->id); // Die if there is no page at all if (null === $obj404) { header('HTTP/1.1 404 Not Found'); die_nicely('be_no_page', 'Page not found'); } // Generate the error page if (!$obj404->autoforward || !$obj404->jumpTo) { /** @var \PageModel $objPage */ global $objPage; $objPage = $obj404->loadDetails(); /** @var \PageRegular $objHandler */ $objHandler = new $GLOBALS['TL_PTY']['regular'](); header('HTTP/1.1 404 Not Found'); $objHandler->generate($objPage); exit; } // Forward to another page $objNextPage = \PageModel::findPublishedById($obj404->jumpTo); if (null === $objNextPage) { header('HTTP/1.1 404 Not Found'); $this->log('Forward page ID "' . $obj404->jumpTo . '" does not exist', __METHOD__, TL_ERROR); die_nicely('be_no_forward', 'Forward page not found'); } $this->redirect($this->generateFrontendUrl($objNextPage->row(), null, $objRootPage->language), $obj404->redirect == 'temporary' ? 302 : 301); }
/** * Show a special Contao "what to do in case of an error" message */ function show_help_message() { if (ini_get('display_errors')) { return; } header('HTTP/1.1 500 Internal Server Error'); die_nicely('be_error', 'An error occurred while executing this script!'); }
/** * Redirect to the first active regular page * @param integer * @param boolean * @return integer * @return integer */ public function generate($pageId, $blnReturn = false) { $objNextPage = \PageModel::findFirstPublishedByPid($pageId); // No published pages yet if ($objNextPage === null) { header('HTTP/1.1 404 Not Found'); $this->log('No active page found under root page "' . $pageId . '")', __METHOD__, TL_ERROR); die_nicely('be_no_active', 'No active pages found'); } if (!$blnReturn) { global $objPage; $this->redirect($this->generateFrontendUrl($objNextPage->row(), null, $objPage->language)); } return $objNextPage->id; }
/** * Redirect to the first active regular page * * @param integer $pageId * @param boolean $blnReturn * @param boolean $blnPreferAlias * * @return integer */ public function generate($pageId, $blnReturn = false, $blnPreferAlias = false) { $objNextPage = \PageModel::findFirstPublishedByPid($pageId); // No published pages yet if (null === $objNextPage) { header('HTTP/1.1 404 Not Found'); $this->log('No active page found under root page "' . $pageId . '"', __METHOD__, TL_ERROR); die_nicely('be_no_active', 'No active pages found'); } if (!$blnReturn) { $this->redirect($objNextPage->getFrontendUrl()); } if ($blnPreferAlias && $objNextPage->alias != '') { return $objNextPage->alias; } return $objNextPage->id; }
/** * Initialize the object */ public function __construct() { // Load the user object before calling the parent constructor \FrontendUser::getInstance(); parent::__construct(); // Check whether a user is logged in define('BE_USER_LOGGED_IN', $this->getLoginStatus('BE_USER_AUTH')); define('FE_USER_LOGGED_IN', $this->getLoginStatus('FE_USER_AUTH')); // No back end user logged in if (!$_SESSION['DISABLE_CACHE']) { // Maintenance mode (see #4561 and #6353) if (\Config::get('maintenanceMode')) { header('HTTP/1.1 503 Service Unavailable'); die_nicely('be_unavailable', 'This site is currently down for maintenance. Please come back later.'); } // Disable the debug mode (see #6450) \Config::set('debugMode', false); } }
/** * Get a page layout and return it as database result object * * @param \PageModel $objPage * * @return \LayoutModel */ protected function getPageLayout($objPage) { $blnMobile = $objPage->mobileLayout && \Environment::get('agent')->mobile; // Set the cookie if (isset($_GET['toggle_view'])) { if (\Input::get('toggle_view') == 'mobile') { $this->setCookie('TL_VIEW', 'mobile', 0); } else { $this->setCookie('TL_VIEW', 'desktop', 0); } $this->redirect($this->getReferer()); } // Override the autodetected value if (\Input::cookie('TL_VIEW') == 'mobile') { $blnMobile = true; } elseif (\Input::cookie('TL_VIEW') == 'desktop') { $blnMobile = false; } $intId = $blnMobile && $objPage->mobileLayout ? $objPage->mobileLayout : $objPage->layout; $objLayout = \LayoutModel::findByPk($intId); // Die if there is no layout if (null === $objLayout) { header('HTTP/1.1 501 Not Implemented'); $this->log('Could not find layout ID "' . $intId . '"', __METHOD__, TL_ERROR); die_nicely('be_no_layout', 'No layout specified'); } $objPage->hasJQuery = $objLayout->addJQuery; $objPage->hasMooTools = $objLayout->addMooTools; $objPage->isMobile = $blnMobile; return $objLayout; }
/** * Run the controller */ public function run() { global $objPage; $pageId = $this->getPageIdFromUrl(); $objRootPage = null; // Load a website root page object if there is no page ID if ($pageId === null) { $objRootPage = $this->getRootPageFromUrl(); $objHandler = new $GLOBALS['TL_PTY']['root'](); $pageId = $objHandler->generate($objRootPage->id, true); } elseif ($pageId === false) { $this->User->authenticate(); $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($pageId); } elseif (Config::get('rewriteURL') && strncmp(Environment::get('request'), 'index.php/', 10) === 0) { $this->User->authenticate(); $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($pageId); } // Get the current page object(s) $objPage = PageModel::findPublishedByIdOrAlias($pageId); // Check the URL and language of each page if there are multiple results if ($objPage !== null && $objPage->count() > 1) { $objNewPage = null; $arrPages = array(); // Order by domain and language while ($objPage->next()) { $objCurrentPage = $objPage->current()->loadDetails(); $domain = $objCurrentPage->domain ?: '*'; $arrPages[$domain][$objCurrentPage->rootLanguage] = $objCurrentPage; // Also store the fallback language if ($objCurrentPage->rootIsFallback) { $arrPages[$domain]['*'] = $objCurrentPage; } } $strHost = Environment::get('host'); // Look for a root page whose domain name matches the host name if (isset($arrPages[$strHost])) { $arrLangs = $arrPages[$strHost]; } else { $arrLangs = $arrPages['*'] ?: array(); // empty domain } // Use the first result (see #4872) if (!Config::get('addLanguageToUrl')) { $objNewPage = current($arrLangs); } elseif (($lang = Input::get('language')) != '' && isset($arrLangs[$lang])) { $objNewPage = $arrLangs[$lang]; } // Store the page object if (is_object($objNewPage)) { $objPage = $objNewPage; } } // Throw a 404 error if the page could not be found or the result is still ambiguous if ($objPage === null || $objPage instanceof Model\Collection && $objPage->count() != 1) { $this->User->authenticate(); $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($pageId); } // Make sure $objPage is a Model if ($objPage instanceof Model\Collection) { $objPage = $objPage->current(); } // Load a website root page object (will redirect to the first active regular page) if ($objPage->type == 'root') { $objHandler = new $GLOBALS['TL_PTY']['root'](); $objHandler->generate($objPage->id); } // Inherit the settings from the parent pages if it has not been done yet if (!is_bool($objPage->protected)) { $objPage->loadDetails(); } // Set the admin e-mail address if ($objPage->adminEmail != '') { list($GLOBALS['TL_ADMIN_NAME'], $GLOBALS['TL_ADMIN_EMAIL']) = String::splitFriendlyEmail($objPage->adminEmail); } else { list($GLOBALS['TL_ADMIN_NAME'], $GLOBALS['TL_ADMIN_EMAIL']) = String::splitFriendlyEmail(Config::get('adminEmail')); } // Exit if the root page has not been published (see #2425) // Do not try to load the 404 page, it can cause an infinite loop! if (!BE_USER_LOGGED_IN && !$objPage->rootIsPublic) { header('HTTP/1.1 404 Not Found'); die_nicely('be_no_page', 'Page not found'); } // Check wether the language matches the root page language if (Config::get('addLanguageToUrl') && Input::get('language') != $objPage->rootLanguage) { $this->User->authenticate(); $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($pageId); } // Check whether there are domain name restrictions if ($objPage->domain != '') { // Load an error 404 page object if ($objPage->domain != Environment::get('host')) { $this->User->authenticate(); $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($objPage->id, $objPage->domain, Environment::get('host')); } } // Authenticate the user if (!$this->User->authenticate() && $objPage->protected && !BE_USER_LOGGED_IN) { $objHandler = new $GLOBALS['TL_PTY']['error_403'](); $objHandler->generate($pageId, $objRootPage); } // Check the user groups if the page is protected if ($objPage->protected && !BE_USER_LOGGED_IN) { $arrGroups = $objPage->groups; // required for empty() if (!is_array($arrGroups) || empty($arrGroups) || !count(array_intersect($arrGroups, $this->User->groups))) { $this->log('Page "' . $pageId . '" can only be accessed by groups "' . implode(', ', (array) $objPage->groups) . '" (current user groups: ' . implode(', ', $this->User->groups) . ')', __METHOD__, TL_ERROR); $objHandler = new $GLOBALS['TL_PTY']['error_403'](); $objHandler->generate($pageId, $objRootPage); } } // Load the page object depending on its type $objHandler = new $GLOBALS['TL_PTY'][$objPage->type](); try { // Generate the page switch ($objPage->type) { case 'root': case 'error_404': $objHandler->generate($pageId); break; case 'error_403': $objHandler->generate($pageId, $objRootPage); break; default: $objHandler->generate($objPage, true); break; } } catch (UnusedArgumentsException $e) { // Render the error page (see #5570) $objHandler = new $GLOBALS['TL_PTY']['error_404'](); $objHandler->generate($pageId, null, null, true); } // Stop the script (see #4565) exit; }
/** * Get the details of a page including inherited parameters * * @return static The page model */ public function loadDetails() { // Loaded already if ($this->blnDetailsLoaded) { return $this; } // Set some default values $this->protected = (bool) $this->protected; $this->groups = $this->protected ? 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 = 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') { header('HTTP/1.1 404 Not Found'); \System::log('Page ID "' . $this->id . '" does not belong to a root page', __METHOD__, TL_ERROR); die_nicely('be_no_root', '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; }
if (USE_MBSTRING && function_exists('mb_regex_encoding')) { mb_regex_encoding(Config::get('characterSet')); } /** * HOOK: add custom logic (see #5665) */ if (isset($GLOBALS['TL_HOOKS']['initializeSystem']) && is_array($GLOBALS['TL_HOOKS']['initializeSystem'])) { foreach ($GLOBALS['TL_HOOKS']['initializeSystem'] as $callback) { System::importStatic($callback[0])->{$callback[1]}(); } } /** * Include the custom initialization file */ if (file_exists(TL_ROOT . '/system/config/initconfig.php')) { include TL_ROOT . '/system/config/initconfig.php'; } /** * Check the request token upon POST requests */ if ($_POST && !RequestToken::validate(Input::post('REQUEST_TOKEN'))) { // Force a JavaScript redirect upon Ajax requests (IE requires absolute link) if (Environment::get('isAjaxRequest')) { header('HTTP/1.1 204 No Content'); header('X-Ajax-Location: ' . Environment::get('base') . 'contao/'); } else { header('HTTP/1.1 400 Bad Request'); die_nicely('be_referer', 'Invalid request token. Please <a href="javascript:window.location.href=window.location.href">go back</a> and try again.'); } exit; }
/** * Try to find a root page based on language and URL * * @return \PageModel */ public static function getRootPageFromUrl() { // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['getRootPageFromUrl']) && is_array($GLOBALS['TL_HOOKS']['getRootPageFromUrl'])) { foreach ($GLOBALS['TL_HOOKS']['getRootPageFromUrl'] as $callback) { /** @var \PageModel $objRootPage */ if (is_object($objRootPage = static::importStatic($callback[0])->{$callback[1]}())) { return $objRootPage; } } } $host = \Environment::get('host'); // The language is set in the URL if (\Config::get('addLanguageToUrl') && !empty($_GET['language'])) { $objRootPage = \PageModel::findFirstPublishedRootByHostAndLanguage($host, \Input::get('language')); // No matching root page found if ($objRootPage === null) { header('HTTP/1.1 404 Not Found'); \System::log('No root page found (host "' . $host . '", language "' . \Input::get('language') . '")', __METHOD__, TL_ERROR); die_nicely('be_no_root', 'No root page found'); } } else { $accept_language = \Environment::get('httpAcceptLanguage'); // Find the matching root pages (thanks to Andreas Schempp) $objRootPage = \PageModel::findFirstPublishedRootByHostAndLanguage($host, $accept_language); // No matching root page found if ($objRootPage === null) { header('HTTP/1.1 404 Not Found'); \System::log('No root page found (host "' . \Environment::get('host') . '", languages "' . implode(', ', \Environment::get('httpAcceptLanguage')) . '")', __METHOD__, TL_ERROR); die_nicely('be_no_root', 'No root page found'); } // Redirect to the language root (e.g. en/) if (\Config::get('addLanguageToUrl') && !\Config::get('doNotRedirectEmpty') && \Environment::get('request') == '') { static::redirect((!\Config::get('rewriteURL') ? 'index.php/' : '') . $objRootPage->language . '/', 301); } } return $objRootPage; }
die_nicely(_("Sorry, the filename must end in '.csv'.")); } $csvfile = fopen($uploadfile, "r"); if (!$csvfile) { die_nicely(_("Unable to open CSV file.")); } // Convert whole file into giant array // (stupid workaround for PHP 5.2 because str_getcsv() is not standard yet) $rows = array(); while (($data = fgetcsv($csvfile, 1000, ",")) !== FALSE) { $rows[] = $data; } fclose($csvfile); break; default: die_nicely(_("Unknown file type {$fileType}")); } if ($action == _("Upload")) { print "<table style='border-spacing: 3'><tr>"; print "<th>ID</th><th colspan=2>" . _("Date") . "</th><th>" . _("Flight") . "</th><th>" . _("From") . "</th><th>" . _("To") . "</th><th>" . _("Miles") . "</th><th>" . _("Time") . "</th><th>" . _("Plane") . "</th><th>" . _("Reg") . "</th>"; print "<th>" . _("Seat") . "</th><th>" . _("Class") . "</th><th>" . _("Type") . "</th><th>" . _("Reason") . "</th><th>" . _("Trip") . "</th><th>" . _("Comment") . "</th></tr>"; } $count = 0; foreach ($rows as $row) { switch ($fileType) { case "FM": $row = pq($row); $cols = $row['> td, th']->elements; $id = pq($cols[0])->text(); // Read and validate date field // <td class="liste_rot"><nobr>10-05-2009</nobr><br>06:10<br>17:35 -1</td>