public function processFormData($arrSubmitted, $arrData, $arrFiles, $arrLabels, \Form $objForm)
 {
     // check if there is a form field which we use as the code
     if (($objField = \FormFieldModel::findBy(array("pid = ?", "useCode = '1'"), array($objForm->id))) === null) {
         return;
     }
     // check if there is submitted data for the form field
     if (!isset($arrSubmitted[$objField->name])) {
         return;
     }
     // get the code
     $code = $arrSubmitted[$objField->name];
     // check if there is a page present for this alias
     if (($objPage = \PageModel::findPublishedByIdOrAlias($code)) === null) {
         return;
     }
     // redirect to page
     \Controller::redirect(\Controller::generateFrontendUrl($objPage->row(), null, null, true));
 }
예제 #2
0
 public static function processTarget($target)
 {
     // replace insert tags for Contao 3.5.7 and up
     if (version_compare(VERSION . '.' . BUILD, '3.5.7', '>=')) {
         $target = \Controller::replaceInsertTags($target);
     }
     // check for insert tag
     if (stripos($target, '{{link_url::') === 0) {
         // get the page id
         $pageId = substr($target, 12, strpos($target, '}}') - 12);
         // get the page
         if (($objPage = \PageModel::findPublishedByIdOrAlias($pageId)) === null) {
             return;
         }
         // load details of the page
         $objPage->current()->loadDetails();
         // generate the URL
         $target = \Controller::generateFrontendUrl($objPage->row(), null, $objPage->rootLanguage, true) . substr($target, strpos($target, '}}') + 2);
     }
     // return processed target
     return $target;
 }
 public static function replaceRelation(array $arrRelation, $strTag)
 {
     $params = preg_split('/::/', $strTag);
     if (!isset($arrRelation['insertTagLink']) || !isset($arrRelation['table'])) {
         return false;
     }
     $relParams = str_replace(array('{', '}'), '', $arrRelation['insertTagLink']);
     $relParams = preg_split('/::/', $relParams);
     // check if given relation inserttag is provided
     if ($relParams[0] != $params[0]) {
         return false;
     }
     $pageId = null;
     $moduleId = null;
     $entityId = null;
     if (($pageIdx = array_search('PAGE_ID', $relParams)) !== false) {
         $pageId = $params[$pageIdx];
     }
     if (($entityIdx = array_search('ENTITY_ID', $relParams)) !== false) {
         $entityId = $params[$entityIdx];
     }
     if (($moduleIdx = array_search('MODULE_ID', $relParams)) !== false) {
         $moduleId = $params[$moduleIdx];
     }
     if ($pageId === null || ($objPage = \PageModel::findPublishedByIdOrAlias($pageId)) === null) {
         return false;
     }
     if ($moduleId === null || ($objModule = \ModuleModel::findByPk($moduleId)) === null) {
         return false;
     }
     if ($entityId === null || ($objEntity = SubmissionCreator::findRelatedEntity($entityId, $arrRelation, $objModule->current())) === null) {
         return false;
     }
     if (StringUtil::endsWith($params[0], '_link')) {
         return SubmissionCreator::getRelationLink($objPage->current(), $objEntity->current(), $arrRelation);
     }
     return false;
 }
예제 #4
0
 /**
  * Do not use global $objPage, as long as pagelink module is enabled
  * because $objPage will hold the target page
  */
 protected function determineCurrentPage()
 {
     if (!in_array('pagelink', $this->Config->getActiveModules())) {
         global $objPage;
         return $objPage;
     }
     $pageId = $this->getPageIdFromUrl();
     $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['*'];
             // Empty domain
         }
         // Use the first result (see #4872)
         if (!$GLOBALS['TL_CONFIG']['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;
         }
     }
     return $objPage;
 }
예제 #5
0
파일: index.php 프로젝트: iCodr8/core
 /**
  * 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;
 }
예제 #6
0
파일: Frontend.php 프로젝트: bytehead/core
 /**
  * Replace the current page with a reader page if applicable
  *
  * @param array $arrFragments
  *
  * @return array
  */
 public function loadReaderPageFromUrl($arrFragments)
 {
     $strKey = 'product';
     $strAlias = '';
     // Find products alias. Can't use Input because they're not yet initialized
     if ($GLOBALS['TL_CONFIG']['useAutoItem'] && in_array($strKey, $GLOBALS['TL_AUTO_ITEM'])) {
         $strKey = 'auto_item';
     }
     for ($i = 1, $c = count($arrFragments); $i < $c; $i += 2) {
         if ($arrFragments[$i] == $strKey) {
             $strAlias = $arrFragments[$i + 1];
         }
     }
     global $objIsotopeListPage;
     $objIsotopeListPage = null;
     if ($strAlias != '' && ($objPage = \PageModel::findPublishedByIdOrAlias($arrFragments[0])) !== null) {
         // Check the URL and language of each page if there are multiple results
         // see Contao's index.php
         if ($objPage !== null && $objPage->count() > 1) {
             $objNewPage = null;
             $arrPages = array();
             // Order by domain and language
             /** @var \PageModel $objCurrentPage */
             foreach ($objPage as $objCurrentPage) {
                 $objCurrentPage->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['*'];
                 // Empty domain
             }
             // Use the first result (see #4872)
             if (!$GLOBALS['TL_CONFIG']['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;
             }
         }
         if ($objPage->iso_setReaderJumpTo && ($objReader = $objPage->getRelated('iso_readerJumpTo')) !== null) {
             /** @var \PageModel $objIsotopeListPage */
             $objIsotopeListPage = $objPage->current();
             $objIsotopeListPage->loadDetails();
             $arrFragments[0] = $objReader->alias ?: $objReader->id;
         }
     }
     return $arrFragments;
 }
예제 #7
0
파일: index.php 프로젝트: rikaix/core
 /**
  * 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 ($GLOBALS['TL_CONFIG']['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()) {
             // Pass the ID so a new page object is created!
             $objCurrentPage = $this->getPageDetails($objPage->id);
             $domain = $objCurrentPage->domain ?: '*';
             $arrPages[$domain][$objCurrentPage->rootLanguage] = $objCurrentPage;
             // Also store the fallback language
             if ($objCurrentPage->rootIsFallback) {
                 $arrPages[$domain]['*'] = $objCurrentPage;
             }
         }
         // Look for a root page whose domain name matches the host name
         if (isset($arrPages[Environment::get('host')])) {
             $arrLangs = $arrPages[Environment::get('host')];
         } else {
             $arrLangs = $arrPages['*'];
             // Empty domain
         }
         // Try to find a page matching the language parameter
         if (!$GLOBALS['TL_CONFIG']['addLanguageToUrl']) {
             $objNewPage = $arrLangs['*'];
             // Fallback language
         } 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->count() != 1) {
         $this->User->authenticate();
         $objHandler = new $GLOBALS['TL_PTY']['error_404']();
         $objHandler->generate($pageId);
     }
     // 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 = $this->getPageDetails($objPage);
     }
     // Use the global date format if none is set
     if ($objPage->dateFormat == '') {
         $objPage->dateFormat = $GLOBALS['TL_CONFIG']['dateFormat'];
     }
     if ($objPage->timeFormat == '') {
         $objPage->timeFormat = $GLOBALS['TL_CONFIG']['timeFormat'];
     }
     if ($objPage->datimFormat == '') {
         $objPage->datimFormat = $GLOBALS['TL_CONFIG']['datimFormat'];
     }
     // Set the admin e-mail address
     if ($objPage->adminEmail != '') {
         list($GLOBALS['TL_ADMIN_NAME'], $GLOBALS['TL_ADMIN_EMAIL']) = $this->splitFriendlyName($objPage->adminEmail);
     } else {
         list($GLOBALS['TL_ADMIN_NAME'], $GLOBALS['TL_ADMIN_EMAIL']) = $this->splitFriendlyName($GLOBALS['TL_CONFIG']['adminEmail']);
     }
     // Exit if the root page has not been published (see #2425) and
     // 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('Page not found');
     }
     // Check wether the language matches the root page language
     if ($GLOBALS['TL_CONFIG']['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) . ')', 'Index run()', 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]();
     switch ($objPage->type) {
         case 'root':
         case 'error_404':
             $objHandler->generate($pageId);
             break;
         case 'error_403':
             $objHandler->generate($pageId, $objRootPage);
             break;
         default:
             $objHandler->generate($objPage);
             break;
     }
 }