get() public static method

Return a configuration value
public static get ( string $strKey ) : mixed | null
$strKey string The short key
return mixed | null The configuration value
Esempio n. 1
1
 /**
  * Run the controller and parse the template
  *
  * @return Response
  */
 public function run()
 {
     /** @var \BackendTemplate|object $objTemplate */
     $objTemplate = new \BackendTemplate('be_preview');
     $objTemplate->base = \Environment::get('base');
     $objTemplate->language = $GLOBALS['TL_LANGUAGE'];
     $objTemplate->title = specialchars($GLOBALS['TL_LANG']['MSC']['fePreview']);
     $objTemplate->charset = \Config::get('characterSet');
     $objTemplate->site = \Input::get('site', true);
     $objTemplate->switchHref = \System::getContainer()->get('router')->generate('contao_backend_switch');
     if (\Input::get('url')) {
         $objTemplate->url = \Environment::get('base') . \Input::get('url');
     } elseif (\Input::get('page')) {
         $objTemplate->url = $this->redirectToFrontendPage(\Input::get('page'), \Input::get('article'), true);
     } else {
         $objTemplate->url = \System::getContainer()->get('router')->generate('contao_root', [], UrlGeneratorInterface::ABSOLUTE_URL);
     }
     // Switch to a particular member (see #6546)
     if (\Input::get('user') && $this->User->isAdmin) {
         $objUser = \MemberModel::findByUsername(\Input::get('user'));
         if ($objUser !== null) {
             $strHash = $this->getSessionHash('FE_USER_AUTH');
             // Remove old sessions
             $this->Database->prepare("DELETE FROM tl_session WHERE tstamp<? OR hash=?")->execute(time() - \Config::get('sessionTimeout'), $strHash);
             // Insert the new session
             $this->Database->prepare("INSERT INTO tl_session (pid, tstamp, name, sessionID, ip, hash) VALUES (?, ?, ?, ?, ?, ?)")->execute($objUser->id, time(), 'FE_USER_AUTH', \System::getContainer()->get('session')->getId(), \Environment::get('ip'), $strHash);
             // Set the cookie
             $this->setCookie('FE_USER_AUTH', $strHash, time() + \Config::get('sessionTimeout'), null, null, false, true);
             $objTemplate->user = \Input::post('user');
         }
     }
     return $objTemplate->getResponse();
 }
Esempio n. 2
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);
 }
Esempio n. 3
0
 /**
  * @param $strName
  * @return null
  */
 public function insertProSearchLegend($strName)
 {
     $activeTables = deserialize(Config::get('searchIndexModules'));
     $coreModulesArr = $activeTables ? $activeTables : array();
     if (in_array($strName, $coreModulesArr) && $GLOBALS['TL_DCA'][$strName]) {
         if (!$this->createColsIfNotExist($strName)) {
             return null;
         }
         $palletesArr = $GLOBALS['TL_DCA'][$strName]['palettes'] ? $GLOBALS['TL_DCA'][$strName]['palettes'] : array();
         static::loadLanguageFile('tl_prosearch_data');
         // legend label setzen
         $GLOBALS['TL_LANG'][$strName]['prosearch_legend'] = $GLOBALS['TL_LANG']['tl_prosearch_data']['prosearch_legend'];
         foreach ($palletesArr as $k => $pallete) {
             if ($k == '__selector__') {
                 continue;
             }
             $palleteArr = explode(';', $pallete);
             if (count($palleteArr) == 1) {
                 $GLOBALS['TL_DCA'][$strName]['palettes'][$k] .= ';' . static::palettesStr();
             } else {
                 $GLOBALS['TL_DCA'][$strName]['palettes'][$k] = str_replace($palleteArr[0], $palleteArr[0] . ';' . static::palettesStr(), $GLOBALS['TL_DCA'][$strName]['palettes'][$k]);
             }
         }
         $GLOBALS['TL_DCA'][$strName]['config']['onload_callback'][] = array('ProSearchPalette', 'getAvailabletags');
         foreach ($this->getFields() as $field => $method) {
             $GLOBALS['TL_DCA'][$strName]['fields'][$field] = call_user_func(array('ProSearchPalette', $method));
         }
     }
 }
 /**
  * Display a wildcard in the back end
  *
  * @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']['eventreader'][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 item from the auto_item parameter
     if (!isset($_GET['events']) && \Config::get('useAutoItem') && isset($_GET['auto_item'])) {
         \Input::setGet('events', \Input::get('auto_item'));
     }
     // Do not index or cache the page if no event has been specified
     if (!\Input::get('events')) {
         /** @var PageModel $objPage */
         global $objPage;
         $objPage->noSearch = 1;
         $objPage->cache = 0;
         return '';
     }
     $this->cal_calendar = $this->sortOutProtected(\StringUtil::deserialize($this->cal_calendar));
     // Do not index or cache the page if there are no calendars
     if (!is_array($this->cal_calendar) || empty($this->cal_calendar)) {
         /** @var PageModel $objPage */
         global $objPage;
         $objPage->noSearch = 1;
         $objPage->cache = 0;
         return '';
     }
     return parent::generate();
 }
 /**
  * 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->Template->formId = 'tl_quicknav_' . $this->id;
     $this->Template->targetPage = $GLOBALS['TL_LANG']['MSC']['targetPage'];
     $this->Template->button = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['go']);
     $this->Template->title = $this->customLabel ?: $GLOBALS['TL_LANG']['MSC']['quicknav'];
     $this->Template->request = ampersand(\Environment::get('request'), true);
     $this->Template->items = $this->getQuicknavPages($this->rootPage, 1, $host, $lang);
 }
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var PageModel $objPage */
     global $objPage;
     $arrJumpTo = array();
     $arrNewsletter = array();
     $strRequest = ampersand(\Environment::get('request'), true);
     $objNewsletter = \NewsletterModel::findSentByPids($this->nl_channels);
     if ($objNewsletter !== null) {
         while ($objNewsletter->next()) {
             /** @var NewsletterChannelModel $objTarget */
             if (!($objTarget = $objNewsletter->getRelated('pid')) instanceof NewsletterChannelModel) {
                 continue;
             }
             $jumpTo = intval($objTarget->jumpTo);
             // A jumpTo page is not mandatory for newsletter channels (see #6521) but required for the list module
             if ($jumpTo < 1) {
                 throw new \Exception("Newsletter channels without redirect page cannot be used in a newsletter list");
             }
             $strUrl = $strRequest;
             if (!isset($arrJumpTo[$objTarget->jumpTo])) {
                 if (($objJumpTo = $objTarget->getRelated('jumpTo')) instanceof PageModel) {
                     /** @var PageModel $objJumpTo */
                     $arrJumpTo[$objTarget->jumpTo] = $objJumpTo->getFrontendUrl(\Config::get('useAutoItem') ? '/%s' : '/items/%s');
                 } else {
                     $arrJumpTo[$objTarget->jumpTo] = $strUrl;
                 }
             }
             $strUrl = $arrJumpTo[$objTarget->jumpTo];
             $strAlias = $objNewsletter->alias ?: $objNewsletter->id;
             $arrNewsletter[] = array('subject' => $objNewsletter->subject, 'title' => \StringUtil::stripInsertTags($objNewsletter->subject), 'href' => sprintf($strUrl, $strAlias), 'date' => \Date::parse($objPage->dateFormat, $objNewsletter->date), 'datim' => \Date::parse($objPage->datimFormat, $objNewsletter->date), 'time' => \Date::parse($objPage->timeFormat, $objNewsletter->date), 'channel' => $objNewsletter->pid);
         }
     }
     $this->Template->newsletters = $arrNewsletter;
 }
Esempio n. 7
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);
 }
Esempio n. 8
0
 /**
  * Run the controller and parse the login template
  *
  * @return Response
  */
 public function run()
 {
     /** @var BackendTemplate|object $objTemplate */
     $objTemplate = new \BackendTemplate('be_login');
     $strHeadline = sprintf($GLOBALS['TL_LANG']['MSC']['loginTo'], \Config::get('websiteTitle'));
     $objTemplate->theme = \Backend::getTheme();
     $objTemplate->messages = \Message::generate();
     $objTemplate->base = \Environment::get('base');
     $objTemplate->language = $GLOBALS['TL_LANGUAGE'];
     $objTemplate->languages = \System::getLanguages(true);
     $objTemplate->title = \StringUtil::specialchars($strHeadline);
     $objTemplate->charset = \Config::get('characterSet');
     $objTemplate->action = ampersand(\Environment::get('request'));
     $objTemplate->userLanguage = $GLOBALS['TL_LANG']['tl_user']['language'][0];
     $objTemplate->headline = $strHeadline;
     $objTemplate->curLanguage = \Input::post('language') ?: str_replace('-', '_', $GLOBALS['TL_LANGUAGE']);
     $objTemplate->curUsername = \Input::post('username') ?: '';
     $objTemplate->uClass = $_POST && empty($_POST['username']) ? ' class="login_error"' : '';
     $objTemplate->pClass = $_POST && empty($_POST['password']) ? ' class="login_error"' : '';
     $objTemplate->loginButton = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['loginBT']);
     $objTemplate->username = $GLOBALS['TL_LANG']['tl_user']['username'][0];
     $objTemplate->password = $GLOBALS['TL_LANG']['MSC']['password'][0];
     $objTemplate->feLink = $GLOBALS['TL_LANG']['MSC']['feLink'];
     $objTemplate->default = $GLOBALS['TL_LANG']['MSC']['default'];
     $objTemplate->jsDisabled = $GLOBALS['TL_LANG']['MSC']['jsDisabled'];
     return $objTemplate->getResponse();
 }
Esempio n. 9
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);
 }
Esempio n. 10
0
 /**
  * Constructor
  */
 public function __construct()
 {
     try {
         $this->apiKey = Config::get('clr_api_key');
         $this->soap = new SoapClient(Config::get('clr_wsdl_url'));
     } catch (Exception $e) {
         $this->log('Kein API-Key oder WSDL-File für cleverreach.de in den Einstellungen hinterlegt', 'CleverReach::construct', TL_ERROR);
     }
     parent::__construct();
 }
Esempio n. 11
0
 /**
  * Run the controller and parse the template
  *
  * @return Response
  */
 public function run()
 {
     /** @var BackendTemplate|object $objTemplate */
     $objTemplate = new \BackendTemplate('be_alerts');
     $objTemplate->theme = \Backend::getTheme();
     $objTemplate->base = \Environment::get('base');
     $objTemplate->language = $GLOBALS['TL_LANGUAGE'];
     $objTemplate->title = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['systemMessages']);
     $objTemplate->charset = \Config::get('characterSet');
     $objTemplate->messages = \Message::generateUnwrapped() . \Backend::getSystemMessages();
     return $objTemplate->getResponse();
 }
 /**
  * Rebuild the cache and return true on success, false otherwise
  *
  * @param ProviderInterface $dataProvider
  * @param ContentModel      $contentElement
  *
  * @return bool
  */
 public function rebuild(ProviderInterface $dataProvider, ContentModel $contentElement)
 {
     $factory = new Factory($dataProvider);
     if (($video = $factory->createVideo($contentElement->vimeo_videoId)) === null) {
         return false;
     }
     if (Config::get('vimeo_allImages') && $dataProvider->getVideoImages($contentElement->vimeo_videoId) === null) {
         return false;
     }
     if ($dataProvider->getVideoImage($contentElement->vimeo_videoId, Config::get('vimeo_imageIndex')) === null) {
         return false;
     }
     return true;
 }
Esempio n. 13
0
 /**
  * @return string
  */
 public function generate()
 {
     // translation
     $bStr = $GLOBALS['TL_LANG']['MSC']['ajaxSearchIndex']['button'];
     // load active modules
     $activeModules = deserialize(Config::get('searchIndexModules'));
     // encode to json
     $json = json_encode($activeModules);
     // set to global js varaible
     $GLOBALS['TL_MOOTOOLS'][] = '<script>var proSearchActiveModules = ' . $json . ';</script>';
     // load js
     $GLOBALS['TL_JAVASCRIPT'][] = $GLOBALS['PS_PUBLIC_PATH'] . 'JsIndex.js|static';
     return '<div class="index_list"><ul class="ul"></ul></div><div class="ajaxSearchIndex"><a class="tl_submit" style="margin-bottom: 5px; margin-top: 5px" onclick="Backend.getScrollOffset();return AjaxRequest.ajaxSearchIndex()">' . $bStr . '</a></div>';
 }
Esempio n. 14
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;
 }
Esempio n. 15
0
 /**
  * Run the controller
  *
  * @return Response
  */
 public function run()
 {
     $objResponse = new Response();
     // Do not run if there is POST data or the last execution was less than a minute ago
     if (!empty($_POST) || $this->hasToWait()) {
         return $objResponse;
     }
     $arrLock = array();
     $arrIntervals = array('monthly', 'weekly', 'daily', 'hourly', 'minutely');
     // Store the current timestamps
     $arrCurrent = array('monthly' => date('Ym'), 'weekly' => date('YW'), 'daily' => date('Ymd'), 'hourly' => date('YmdH'), 'minutely' => date('YmdHi'));
     // Get the timestamps from tl_cron
     $objLock = $this->Database->query("SELECT * FROM tl_cron WHERE name !='lastrun'");
     while ($objLock->next()) {
         $arrLock[$objLock->name] = $objLock->value;
     }
     // Create the database entries
     foreach ($arrIntervals as $strInterval) {
         if (!isset($arrLock[$strInterval])) {
             $arrLock[$strInterval] = 0;
             $this->Database->query("INSERT INTO tl_cron (name, value) VALUES ('{$strInterval}', 0)");
         }
     }
     // Run the jobs
     foreach ($arrIntervals as $strInterval) {
         $intCurrent = $arrCurrent[$strInterval];
         // Skip empty intervals and jobs that have been executed already
         if (empty($GLOBALS['TL_CRON'][$strInterval]) || $arrLock[$strInterval] == $intCurrent) {
             continue;
         }
         // Update the database before the jobs are executed, in case one of them fails
         $this->Database->query("UPDATE tl_cron SET value={$intCurrent} WHERE name='{$strInterval}'");
         // Add a log entry if in debug mode (see #4729)
         if (\Config::get('debugMode')) {
             $this->log('Running the ' . $strInterval . ' cron jobs', __METHOD__, TL_CRON);
         }
         foreach ($GLOBALS['TL_CRON'][$strInterval] as $callback) {
             $this->import($callback[0]);
             $this->{$callback[0]}->{$callback[1]}();
         }
         // Add a log entry if in debug mode (see #4729)
         if (\Config::get('debugMode')) {
             $this->log(ucfirst($strInterval) . ' cron jobs complete', __METHOD__, TL_CRON);
         }
     }
     return $objResponse;
 }
 /**
  * Rebuild the cache and return true on success, false otherwise
  *
  * @param ProviderInterface $dataProvider
  * @param ContentModel      $contentElement
  *
  * @return bool
  */
 public function rebuild(ProviderInterface $dataProvider, ContentModel $contentElement)
 {
     $factory = new Factory($dataProvider);
     $album = $factory->createAlbum($contentElement->vimeo_albumId, true, $contentElement->vimeo_sorting, $contentElement->vimeo_sortingDirection);
     if ($album === null) {
         return false;
     }
     /** @var Video $video */
     foreach ($album->getVideos() as $video) {
         if (Config::get('vimeo_allImages') && $dataProvider->getVideoImages($video->getId()) === null) {
             return false;
         }
         if ($dataProvider->getVideoImage($video->getId(), Config::get('vimeo_imageIndex')) === null) {
             return false;
         }
     }
     return true;
 }
Esempio n. 17
0
 /**
  * Check for new \Contao versions
  */
 public function checkForUpdates()
 {
     if (!is_numeric(BUILD)) {
         return;
     }
     // HOOK: proxy module
     if (Config::get('useProxy')) {
         $objRequest = new \ProxyRequest();
     } else {
         $objRequest = new \Request();
     }
     $objRequest->send(\Config::get('liveUpdateBase') . (LONG_TERM_SUPPORT ? 'lts-version.txt' : 'version.txt'));
     if (!$objRequest->hasError()) {
         \System::getContainer()->get('contao.cache')->save('latest-version', $objRequest->response);
     }
     // Add a log entry
     $this->log('Checked for Contao updates', __METHOD__, TL_CRON);
 }
Esempio n. 18
0
 /**
  * Validate a token
  *
  * @param string $strToken The request token
  *
  * @return boolean True if the token matches the stored one
  */
 public static function validate($strToken)
 {
     // The feature has been disabled
     if (\Config::get('disableRefererCheck') || defined('BYPASS_TOKEN_CHECK')) {
         return true;
     }
     // Check against the whitelist (thanks to Tristan Lins) (see #3164)
     if (\Config::get('requestTokenWhitelist')) {
         $strHostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
         foreach (\Config::get('requestTokenWhitelist') as $strDomain) {
             if ($strDomain == $strHostname || preg_match('/\\.' . preg_quote($strDomain, '/') . '$/', $strHostname)) {
                 return true;
             }
         }
     }
     $container = \System::getContainer();
     return $container->get('security.csrf.token_manager')->isTokenValid(new CsrfToken($container->getParameter('contao.csrf_token_name'), $strToken));
 }
Esempio n. 19
0
 /**
  * Initialize the object
  */
 public function __construct()
 {
     //Safely store the $_GET and $_POST vals in AjaxInput
     AjaxInput::initialize();
     // Load the user object before calling the parent constructor
     $this->import('FrontendUser', 'User');
     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('This site is currently down for maintenance. Please come back later.');
         }
     }
 }
Esempio n. 20
0
 /**
  * Prepare the output
  *
  * @return \PageModel
  *
  * @internal
  */
 protected function prepare()
 {
     // Check the search index (see #3761)
     \Search::removeEntry(\Environment::get('relativeRequest'));
     // 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 script name
         $strRequest = \Environment::get('relativeRequest');
         // 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(\Environment::get('request') . '/', 301);
             } else {
                 if ($strRequest == \Environment::get('request')) {
                     $strRequest = $objRootPage->language . '/' . $strRequest;
                 } else {
                     $strRequest = \Environment::get('script') . '/' . $objRootPage->language . '/' . $strRequest;
                 }
                 $this->redirect($strRequest, 301);
             }
         }
     }
     // Look for a 404 page
     $obj404 = \PageModel::find404ByPid($objRootPage->id);
     // Die if there is no page at all
     if (null === $obj404) {
         throw new PageNotFoundException('Page not found');
     }
     // Forward to another page
     if ($obj404->autoforward && $obj404->jumpTo) {
         $objNextPage = \PageModel::findPublishedById($obj404->jumpTo);
         if (null === $objNextPage) {
             $this->log('Forward page ID "' . $obj404->jumpTo . '" does not exist', __METHOD__, TL_ERROR);
             throw new ForwardPageNotFoundException('Forward page not found');
         }
         $this->redirect($this->generateFrontendUrl($objNextPage->row(), null, $objRootPage->language), $obj404->redirect == 'temporary' ? 302 : 301);
     }
     return $obj404;
 }
 /**
  * Run the controller and parse the template
  */
 public function run()
 {
     $template = new BackendTemplate('be_picker');
     $template->main = '';
     // Ajax request
     if ($_POST && Environment::get('isAjaxRequest')) {
         $this->ajax = new Ajax(Input::post('action'));
         $this->ajax->executePreActions();
     }
     $rebuilder = new Rebuilder();
     $rebuilder->setPopupMode(true);
     $template->main = $rebuilder->run();
     $template->theme = Backend::getTheme();
     $template->base = Environment::get('base');
     $template->language = $GLOBALS['TL_LANGUAGE'];
     $template->title = specialchars($GLOBALS['TL_LANG']['MSC']['pagepicker']);
     $template->charset = Config::get('characterSet');
     Config::set('debugMode', false);
     $template->output();
 }
 /**
  * Pre-fetch the videos to save the number of API calls
  */
 protected function preFetchVideos()
 {
     if (($videos = $this->fetchVideos()) === null) {
         return;
     }
     foreach ($videos as $video) {
         $videoId = $this->extractVideoId($video);
         $cacheKey = 'video_' . $videoId;
         // Get the cached video before overriding its data
         if ($this->cache->hasData($cacheKey)) {
             $cachedVideo = $this->cache->getData($cacheKey);
         } else {
             $cachedVideo = null;
         }
         $this->cache->setData($cacheKey, $video);
         // Get the video images only if the video has been not cached yet or has been modified since last time
         if ($cachedVideo === null || $cachedVideo['modified_time'] !== $video['modified_time']) {
             $this->getVideoImage($videoId, Config::get('vimeo_imageIndex'));
         }
     }
 }
Esempio n. 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);
             }
         }
     }
 }
Esempio n. 24
0
 /**
  * Make an API request to Vimeo.
  *
  * @param string $url    A Vimeo API Endpoint. Should not include the host
  * @param array  $params An array of parameters to send to the endpoint. If the HTTP method is GET, they will be added to the url, otherwise they will be written to the body
  * @param string $method The HTTP Method of the request
  * @param bool   $json_body
  *
  * @return array|null
  */
 public function request($url, $params = array(), $method = 'GET', $json_body = true)
 {
     if (Config::get('debugMode')) {
         static $requestCount = 0;
         if (++$requestCount > $this->requestLimit) {
             System::log(sprintf('The request limit of %s has been reached. Please check your script for possible optimizations.', $this->requestLimit), __METHOD__, 'VIMEO');
             return null;
         }
         System::log('Vimeo request to: ' . $url, __METHOD__, 'VIMEO');
     }
     try {
         $response = parent::request($url, $params, $method, $json_body);
     } catch (\Exception $e) {
         System::log(sprintf('Vimeo request (%s) failed with exception: %s', $url, $e->getMessage()), __METHOD__, TL_ERROR);
         return null;
     }
     $this->updateStats($response['headers']);
     if ($response['status'] !== 200) {
         System::log(sprintf('Vimeo request (%s) failed (code %s): %s', $url, $response['status'], print_r($response, true)), __METHOD__, TL_ERROR);
         return null;
     }
     return $response;
 }
 /**
  * Generate the content element
  */
 protected function compile()
 {
     $dataProvider = new StandardProvider(new Cache(), Client::getInstance());
     $factory = new Factory($dataProvider);
     $album = $factory->createAlbum($this->vimeo_albumId, true, $this->vimeo_sorting, $this->vimeo_sortingDirection);
     if ($album === null) {
         return;
     }
     $this->Template->setData($album->getData());
     $posterSize = deserialize($this->size, true);
     $videos = [];
     // Generate the videos
     /** @var Video $video */
     foreach ($album->getVideos() as $video) {
         // Set the images
         if (Config::get('vimeo_allImages') && ($images = $dataProvider->getVideoImages($video->getId())) !== null) {
             $video->setPicturesData($images);
         }
         $image = $dataProvider->getVideoImage($video->getId(), Config::get('vimeo_imageIndex'));
         // Set the poster
         if ($image !== null) {
             $video->setPoster($image);
         }
         $video->setPosterSize($posterSize);
         // Enable the lightbox
         if ($this->vimeo_lightbox) {
             $video->enableLightbox();
             // Enable the lightbox autoplay
             if ($this->vimeo_lightboxAutoplay) {
                 $video->enableLightboxAutoplay();
             }
         }
         $videos[] = $video->generate(new FrontendTemplate($this->vimeo_template));
     }
     $this->Template->videos = $videos;
 }
Esempio n. 26
0
 /**
  * @param string $language
  * @param string $GlobalMapID
  * @return string
  */
 public static function setMapJs($language = 'en', $GlobalMapID = '')
 {
     $startPoint = $GLOBALS['loadGoogleMapLibraries'] ? 'FModuleLoadLibraries' : 'FModuleLoadMaps';
     $apiKey = '';
     if (Config::get('googleApiKey')) {
         $apiKey = '&key=' . Config::get('googleApiKey');
     }
     $mapJSLoadTemplate = '<script async defer>
             (function(){
                 var FModuleGoogleApiLoader = function(){
                     var mapApiScript = document.createElement("script");
                     mapApiScript.src = "http' . (Environment::get('ssl') ? 's' : '') . '://maps.google.com/maps/api/js?language=' . $language . $apiKey . '";
                     mapApiScript.onload = ' . $startPoint . ';
                     document.body.appendChild(mapApiScript);
                 };
                 var FModuleLoadLibraries = function()
                 {
                     var mapInfoBox = document.createElement("script");
                     mapInfoBox.src = "' . $GLOBALS['FM_AUTO_PATH'] . 'InfoBox.js";
                     mapInfoBox.onload = FModuleLoadMaps;
                     document.body.appendChild(mapInfoBox);
                 };
                 var FModuleLoadMaps = function()
                 {
                     try{
                         if(typeof FModuleGoogleMap != "undefined"){for(var i = 0; i < FModuleGoogleMap.length; i++){FModuleGoogleMap[i]();}}
                     } catch(err)
                     {
                         console.warn("No Google Map found!");
                     }
                 };
                 if (document.addEventListener){document.addEventListener("DOMContentLoaded", FModuleGoogleApiLoader, false);} else if (document.attachEvent){document.attachEvent("onload", FModuleGoogleApiLoader);}
             })();
         </script>';
     return $mapJSLoadTemplate;
 }
Esempio n. 27
0
 /**
  * @param int $total
  * @return null|string
  */
 public function createPagination($total = 0)
 {
     global $objPage;
     $this->listViewLimit = $total;
     $getPagination = \Input::get('pagination');
     if ($getPagination) {
         if (is_array($getPagination)) {
             $this->f_perPage = $getPagination[0];
         }
         if (is_string($getPagination)) {
             $this->f_perPage = $getPagination;
         }
     }
     if ($getPagination == '0' && !is_null($getPagination)) {
         $this->f_perPage = $getPagination;
     }
     if ($this->f_limit_page > 0) {
         $total = min($this->f_limit_page, $total);
         $this->listViewLimit = $total;
     }
     if ($this->f_perPage > 0 && $this->strOrderBy != 'RAND') {
         $id = 'page_e' . $this->id;
         $page = \Input::get($id) !== null ? \Input::get($id) : 1;
         if ($page < 1 || $page > max(ceil($total / $this->f_perPage), 1)) {
             $objHandler = new $GLOBALS['TL_PTY']['error_404']();
             $objHandler->generate($objPage->id);
         }
         $this->listViewOffset = ($page - 1) * $this->f_perPage;
         $this->listViewLimit = min($this->f_perPage + $this->listViewOffset, $total);
         $objPagination = new Pagination($total, $this->f_perPage, Config::get('maxPaginationLinks'), $id);
         return $objPagination->generate("\n  ");
     }
     return '';
 }
Esempio n. 28
0
 /**
  * Convert special characters to HTML entities preventing double conversions
  *
  * @param string  $strString          The input string
  * @param boolean $blnStripInsertTags True to strip insert tags
  *
  * @return string The converted string
  */
 public static function specialchars($strString, $blnStripInsertTags = false)
 {
     if ($blnStripInsertTags) {
         $strString = static::stripInsertTags($strString);
     }
     // Use ENT_COMPAT here (see #4889)
     return htmlspecialchars($strString, ENT_COMPAT, \Config::get('characterSet'), false);
 }
Esempio n. 29
0
 /**
  * Instantiate the Database object (Factory)
  *
  * @param array $arrCustomConfig A configuration array
  *
  * @return Database The Database object
  */
 public static function getInstance(array $arrCustomConfig = null)
 {
     $arrConfig = array();
     $arrDefaultConfig = array('dbHost' => \Config::get('dbHost'), 'dbPort' => \Config::get('dbPort'), 'dbUser' => \Config::get('dbUser'), 'dbPass' => \Config::get('dbPass'), 'dbDatabase' => \Config::get('dbDatabase'));
     if (is_array($arrCustomConfig)) {
         $arrConfig = array_merge($arrDefaultConfig, $arrCustomConfig);
     }
     // Sort the array before generating the key
     ksort($arrConfig);
     $strKey = md5(implode('', $arrConfig));
     if (!isset(static::$arrInstances[$strKey])) {
         static::$arrInstances[$strKey] = new static($arrConfig);
     }
     return static::$arrInstances[$strKey];
 }
Esempio n. 30
0
 /**
  * Run the controller and parse the password template
  *
  * @return Response
  */
 public function run()
 {
     /** @var BackendTemplate|object $objTemplate */
     $objTemplate = new \BackendTemplate('be_password');
     if (\Input::post('FORM_SUBMIT') == 'tl_password') {
         $pw = \Input::postUnsafeRaw('password');
         $cnf = \Input::postUnsafeRaw('confirm');
         // The passwords do not match
         if ($pw != $cnf) {
             \Message::addError($GLOBALS['TL_LANG']['ERR']['passwordMatch']);
         } elseif (Utf8::strlen($pw) < \Config::get('minPasswordLength')) {
             \Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['passwordLength'], \Config::get('minPasswordLength')));
         } elseif ($pw == $this->User->username) {
             \Message::addError($GLOBALS['TL_LANG']['ERR']['passwordName']);
         } else {
             // Make sure the password has been changed
             if (\Encryption::verify($pw, $this->User->password)) {
                 \Message::addError($GLOBALS['TL_LANG']['MSC']['pw_change']);
             } else {
                 $this->loadDataContainer('tl_user');
                 // Trigger the save_callback
                 if (is_array($GLOBALS['TL_DCA']['tl_user']['fields']['password']['save_callback'])) {
                     foreach ($GLOBALS['TL_DCA']['tl_user']['fields']['password']['save_callback'] as $callback) {
                         if (is_array($callback)) {
                             $this->import($callback[0]);
                             $pw = $this->{$callback[0]}->{$callback[1]}($pw);
                         } elseif (is_callable($callback)) {
                             $pw = $callback($pw);
                         }
                     }
                 }
                 $objUser = \UserModel::findByPk($this->User->id);
                 $objUser->pwChange = '';
                 $objUser->password = \Encryption::hash($pw);
                 $objUser->save();
                 \Message::addConfirmation($GLOBALS['TL_LANG']['MSC']['pw_changed']);
                 $this->redirect('contao/main.php');
             }
         }
         $this->reload();
     }
     $objTemplate->theme = \Backend::getTheme();
     $objTemplate->messages = \Message::generate();
     $objTemplate->base = \Environment::get('base');
     $objTemplate->language = $GLOBALS['TL_LANGUAGE'];
     $objTemplate->title = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['pw_new']);
     $objTemplate->charset = \Config::get('characterSet');
     $objTemplate->action = ampersand(\Environment::get('request'));
     $objTemplate->headline = $GLOBALS['TL_LANG']['MSC']['pw_change'];
     $objTemplate->submitButton = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['continue']);
     $objTemplate->password = $GLOBALS['TL_LANG']['MSC']['password'][0];
     $objTemplate->confirm = $GLOBALS['TL_LANG']['MSC']['confirm'][0];
     return $objTemplate->getResponse();
 }