/** * Instanciates a frontend engine * * @param \int $pid Current page ID * @return void */ public static function simulateFrontendEnvironment($pid) { self::$_tsfeBackup = isset($GLOBALS['TSFE']) ? $GLOBALS['TSFE'] : NULL; self::$_httpHostBackup = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null; $GLOBALS['TSFE'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', $GLOBALS['TYPO3_CONF_VARS'], $pid, 0, true); $GLOBALS['TT'] = new \TYPO3\CMS\Core\TimeTracker\NullTimeTracker(); /* @var $tsfe \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController */ $tsfe =& $GLOBALS['TSFE']; $tsfe->tmpl = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\TemplateService'); $tsfe->tmpl->init(); $tsfe->initFEuser(); // $tsfe->fe_user->fetchGroupData(); // $tsfe->includeTCA(); $tsfe->fetch_the_id(); $tsfe->getConfigArray(); // $tsfe->includeLibraries($tsfe->tmpl->setup['includeLibs.']); // $tsfe->newCObj(); // Tweak the HTTP host name $rootLine = $tsfe->sys_page->getRootLine($pid); $domain = \TYPO3\CMS\Backend\Utility\BackendUtility::firstDomainRecord($rootLine); if (!$domain) { $domain = array_key_exists('baseURL', $tsfe->config) ? parse_url($tsfe->config['baseURL'], PHP_URL_HOST) : ''; } $_SERVER['HTTP_HOST'] = $domain; }
/** * initialize the TYPO3 frontend * * @param integer $id * @param integer $typeNum */ protected function initTSFE($id = 1, $typeNum = 0) { EidUtility::initTCA(); if (!is_object($GLOBALS['TT'])) { $GLOBALS['TT'] = new \TYPO3\CMS\Core\TimeTracker\NullTimeTracker(); $GLOBALS['TT']->start(); } $GLOBALS['TSFE'] = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', $GLOBALS['TYPO3_CONF_VARS'], $id, $typeNum); $GLOBALS['TSFE']->connectToDB(); $GLOBALS['TSFE']->initFEuser(); $GLOBALS['TSFE']->determineId(); $GLOBALS['TSFE']->initTemplate(); $GLOBALS['TSFE']->getConfigArray(); if (ExtensionManagementUtility::isLoaded('realurl')) { $rootline = BackendUtility::BEgetRootLine($id); $host = BackendUtility::firstDomainRecord($rootline); $_SERVER['HTTP_HOST'] = $host; } }
/** * Get domain name for requested page id * * @param integer $pageId * @return string|NULL Domain name from first sys_domains-Record or from TCEMAIN.previewDomain, NULL if neither is configured */ protected function getDomainName($pageId) { $previewDomainConfig = $GLOBALS['BE_USER']->getTSConfig('TCEMAIN.previewDomain', BackendUtility::getPagesTSconfig($pageId)); if ($previewDomainConfig['value']) { $domain = $previewDomainConfig['value']; } else { $domain = BackendUtility::firstDomainRecord(BackendUtility::BEgetRootLine($pageId)); } return $domain; }
/** * Constructs a valid Url for browser output * * @param array $row Broken link record * @return string Parsed broken url */ public function getBrokenUrl($row) { $domain = rtrim(GeneralUtility::getIndpEnv('TYPO3_SITE_URL'), '/'); $rootLine = BackendUtility::BEgetRootLine($row['record_pid']); // checks alternate domains if (count($rootLine) > 0) { $protocol = GeneralUtility::getIndpEnv('TYPO3_SSL') ? 'https://' : 'http://'; $domainRecord = BackendUtility::firstDomainRecord($rootLine); if (!empty($domainRecord)) { $domain = $protocol . $domainRecord; } } return $domain . '/index.php?id=' . $row['url']; }
/** * Initializes the $_SERVER['HTTP_HOST'] environment variable in CLI * environments dependent on the Index Queue item's root page. * * When the Index Queue Worker task is executed by a cron job there is no * HTTP_HOST since we are in a CLI environment. RealURL needs the host * information to generate a proper URL though. Using the Index Queue item's * root page information we can determine the correct host although being * in a CLI environment. * * @param Item $item Index Queue item to use to determine the host. */ protected function initializeHttpHost(Item $item) { static $hosts = array(); $rootpageId = $item->getRootPageUid(); $hostFound = !empty($hosts[$rootpageId]); if (!$hostFound) { $rootline = BackendUtility::BEgetRootLine($rootpageId); $host = BackendUtility::firstDomainRecord($rootline); $hosts[$rootpageId] = $host; } $_SERVER['HTTP_HOST'] = $hosts[$rootpageId]; // needed since TYPO3 7.5 GeneralUtility::flushInternalRuntimeCaches(); }
/** * Gets the site's main domain. More specifically the first domain record in * the site tree. * * @return string The site's main domain. */ public function getDomain() { $pageSelect = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository'); $rootLine = $pageSelect->getRootLine($this->rootPage['uid']); return BackendUtility::firstDomainRecord($rootLine); }
/** * First initialization of global variables * * @return void */ public function init() { parent::init(); // initialize IconFactory $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class); // get the config from pageTS $temp = BackendUtility::getModTSconfig($this->id, 'mod.web_modules.dmail'); if (!is_array($temp['properties'])) { $temp['properties'] = array(); } $this->params = $temp['properties']; $this->implodedParams = DirectMailUtility::implodeTSParams($this->params); if ($this->params['userTable'] && is_array($GLOBALS['TCA'][$this->params['userTable']])) { $this->userTable = $this->params['userTable']; $this->allowedTables[] = $this->userTable; } // check if the right domain shoud be set if (!$this->params['use_domain']) { $rootLine = BackendUtility::BEgetRootLine($this->id); if ($rootLine) { $parts = parse_url(GeneralUtility::getIndpEnv('TYPO3_SITE_URL')); if (BackendUtility::getDomainStartPage($parts['host'], $parts['path'])) { $temporaryPreUrl = BackendUtility::firstDomainRecord($rootLine); $domain = BackendUtility::getRecordsByField('sys_domain', 'domainName', $temporaryPreUrl, ' AND hidden=0', '', 'sorting'); if (is_array($domain)) { reset($domain); $dom = current($domain); $this->params['use_domain'] = $dom['uid']; } } } } $this->MOD_MENU['dmail_mode'] = BackendUtility::unsetMenuItems($this->params, $this->MOD_MENU['dmail_mode'], 'menu.dmail_mode'); // initialize backend user language if ($this->getLanguageService()->lang && ExtensionManagementUtility::isLoaded('static_info_tables')) { $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('sys_language.uid', 'sys_language LEFT JOIN static_languages ON sys_language.static_lang_isocode=static_languages.uid', 'static_languages.lg_typo3=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->getLanguageService()->lang, 'static_languages') . BackendUtility::BEenableFields('sys_language') . BackendUtility::deleteClause('sys_language') . BackendUtility::deleteClause('static_languages')); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $this->sys_language_uid = $row['uid']; } $GLOBALS['TYPO3_DB']->sql_free_result($res); } // load contextual help $this->cshTable = '_MOD_' . $this->MCONF['name']; if ($GLOBALS['BE_USER']->uc['edit_showFieldHelp']) { $this->getLanguageService()->loadSingleTableDescription($this->cshTable); } }
/** * Get domain name for requested page id * * @param integer $pageId * @return boolean|string Domain name if there is one, FALSE if not */ protected function getDomainName($pageId) { $domain = \TYPO3\CMS\Backend\Utility\BackendUtility::firstDomainRecord(\TYPO3\CMS\Backend\Utility\BackendUtility::BEgetRootLine($pageId)); return $domain; }
/** * Initializes the frontend to render frontend links in scheduler tasks * * @param integer $pageid Page ID for the frontend configuration */ public static function initFrontend($pageid) { $type = 0; $name = 'TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController'; if (!is_object($GLOBALS['TT'])) { $GLOBALS['TT'] = new \TYPO3\CMS\Core\TimeTracker\TimeTracker(); $GLOBALS['TT']->start(); } $GLOBALS['TSFE'] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($name, $GLOBALS['TYPO3_CONF_VARS'], $pageid, $type); $GLOBALS['TSFE']->connectToDB(); $GLOBALS['TSFE']->initFEuser(); $GLOBALS['TSFE']->determineId(); $GLOBALS['TSFE']->initTemplate(); $GLOBALS['TSFE']->getConfigArray(); if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('realurl')) { $rootline = \TYPO3\CMS\Backend\Utility\BackendUtility::BEgetRootLine($pageid); $host = \TYPO3\CMS\Backend\Utility\BackendUtility::firstDomainRecord($rootline); $SERVER['HTTP_HOST'] = $host; } }
/** * Initializes the $_SERVER['HTTP_HOST'] environment variable in CLI * environments dependent on the Index Queue item's root page. * * When the Index Queue Worker task is executed by a cron job there is no * HTTP_HOST since we are in a CLI environment. RealURL needs the host * information to generate a proper URL though. Using the Index Queue item's * root page information we can determine the correct host although being * in a CLI environment. * * @param Item $item Index Queue item to use to determine the host. */ protected function initializeHttpHost(Item $item) { static $hosts = array(); // relevant for realURL environments, only if (ExtensionManagementUtility::isLoaded('realurl')) { $rootpageId = $item->getRootPageUid(); $hostFound = !empty($hosts[$rootpageId]); if (!$hostFound) { $rootline = BackendUtility::BEgetRootLine($rootpageId); $host = BackendUtility::firstDomainRecord($rootline); $hosts[$rootpageId] = $host; } $_SERVER['HTTP_HOST'] = $hosts[$rootpageId]; } }
/** * Generate the body content * * If there is an error, no reference to a record, a Flash Message will be * displayed * * @return string The body content */ protected function getBodyContent($data, $table) { // template1 $wizardView = GeneralUtility::makeInstance(\TYPO3\CMS\Fluid\View\StandaloneView::class); $wizardView->setFormat('html'); $wizardView->setLayoutRootPaths([10 => ExtensionManagementUtility::extPath('cs_seo') . '/Resources/Private/Layouts/']); $wizardView->setTemplatePathAndFilename(ExtensionManagementUtility::extPath('cs_seo') . 'Resources/Private/Templates/Wizard.html'); if (strpos($data['uid'], 'NEW') === false) { // set pageID for TSSetup check $pageUid = $table == 'pages' ? $data['uid'] : $data['pid']; $_GET['id'] = $pageUid; // check if TS page type exists /** @var BackendConfigurationManager $configurationManager */ $backendConfigurationManager = GeneralUtility::makeInstance(BackendConfigurationManager::class); $fullTS = $backendConfigurationManager->getTypoScriptSetup(); if (isset($fullTS['types.'][$this->typeNum])) { // render page title $rootline = BackendUtility::BEgetRootLine($pageUid); /** @var TSFEUtility $TSFEUtility */ $TSFEUtility = GeneralUtility::makeInstance(TSFEUtility::class, $pageUid, $data['sys_language_uid']); $siteTitle = $TSFEUtility->getSiteTitle(); $pageTitleSeparator = $TSFEUtility->getPageTitleSeparator(); $config = $TSFEUtility->getConfig(); if ($table == 'pages' || $table == 'pages_language_overlay') { PageGenerator::generatePageTitle(); $pageTitle = static::getPageRenderer()->getTitle(); // get page path $path = $TSFEUtility->getPagePath(); // TYPO3 8 $urlScheme = is_array($data['url_scheme']) ? $data['url_scheme'][0] : $data['url_scheme']; // check if path is absolute if (strpos($path, '://') !== false) { $path = ''; } } else { $pageTitle = $TSFEUtility->getFinalTitle($data['title'], $data['title_only']); $path = ''; $urlScheme = 'http://'; } $wizardView->assignMultiple(['config' => $config, 'domain' => BackendUtility::firstDomainRecord($rootline), 'data' => $data, 'pageTitle' => $pageTitle, 'pageTitleSeparator' => $pageTitleSeparator, 'path' => $path, 'siteTitle' => $siteTitle, 'urlScheme' => $urlScheme]); } else { $wizardView->assign('error', 'no_ts'); } } else { $wizardView->assign('error', 'no_data'); } return $wizardView->render(); }
/** * initialize the TSFE for the backend * * @return void */ protected function initTSFE() { try { if (!is_object($GLOBALS['TT'])) { $GLOBALS['TT'] = new NullTimeTracker(); $GLOBALS['TT']->start(); } $GLOBALS['TSFE'] = GeneralUtility::makeInstance(TypoScriptFrontendController::class, $GLOBALS['TYPO3_CONF_VARS'], $this->pageUid, $this->typeNum); $GLOBALS['TSFE']->config = []; $GLOBALS['TSFE']->forceTemplateParsing = true; $GLOBALS['TSFE']->connectToDB(); $GLOBALS['TSFE']->initFEuser(); $GLOBALS['TSFE']->determineId(); $GLOBALS['TSFE']->initTemplate(); $GLOBALS['TSFE']->newCObj(); if ($this->lang > 0) { $GLOBALS['TSFE']->config['config']['sys_language_uid'] = $this->lang; $GLOBALS['TSFE']->settingLanguage(); } if (ExtensionManagementUtility::isLoaded('realurl')) { $rootline = BackendUtility::BEgetRootLine($this->pageUid); $host = BackendUtility::firstDomainRecord($rootline); $_SERVER['HTTP_HOST'] = $host; } $GLOBALS['TSFE']->getConfigArray(); } catch (\Exception $e) { // \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($e); return; } }
/** * Get domain name for requested page id * * @param integer $pageId * @return boolean|string Domain name if there is one, FALSE if not */ protected function getDomainName($pageId) { $domain = BackendUtility::firstDomainRecord(BackendUtility::BEgetRootLine($pageId)); return $domain; }
/** * Get principal domain by page uid * * @param int $pageUid * @return mixed */ public static function getDomain($pageUid) { $domain = \TYPO3\CMS\Backend\Utility\BackendUtility::firstDomainRecord(self::getRootLine($pageUid)); if (empty($domain)) { $domain = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'); } if (empty($domain)) { $domain = 'localhost'; } return $domain; }
/** * Initializes the $_SERVER['HTTP_HOST'] environment variable in CLI * environments dependent on the Index Queue item's root page. * * When the Index Queue Worker task is executed by a cron job there is no * HTTP_HOST since we are in a CLI environment. RealURL needs the host * information to generate a proper URL though. Using the Index Queue item's * root page information we can determine the correct host although being * in a CLI environment. * * @param Item $item Index Queue item to use to determine the host. */ protected function initializeHttpHost(Item $item) { static $hosts = array(); // relevant for realURL environments, only if (ExtensionManagementUtility::isLoaded('realurl')) { $rootpageId = $item->getRootPageUid(); $hostFound = !empty($hosts[$rootpageId]); if (!$hostFound) { $rootline = BackendUtility::BEgetRootLine($rootpageId); $host = BackendUtility::firstDomainRecord($rootline); $hosts[$rootpageId] = $host; } $_SERVER['HTTP_HOST'] = $hosts[$rootpageId]; if (version_compare(TYPO3_branch, '7.5', '>=')) { GeneralUtility::flushInternalRuntimeCaches(); } } }