The class returns the environment variables (which are stored in the PHP $_SERVER array) independent of the operating system. Usage: echo Environment::get('scriptName'); echo Environment::get('requestUri');
 /**
  * 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();
 }
Example #2
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var PageModel $objPage */
     global $objPage;
     if (!strlen($this->inColumn)) {
         $this->inColumn = 'main';
     }
     $intCount = 0;
     $articles = array();
     $id = $objPage->id;
     $this->Template->request = \Environment::get('request');
     // Show the articles of a different page
     if ($this->defineRoot && $this->rootPage > 0) {
         if (($objTarget = $this->objModel->getRelated('rootPage')) !== null) {
             $id = $objTarget->id;
             $this->Template->request = $this->generateFrontendUrl($objTarget->row());
         }
     }
     // Get published articles
     $objArticles = \ArticleModel::findPublishedByPidAndColumn($id, $this->inColumn);
     if ($objArticles === null) {
         return;
     }
     while ($objArticles->next()) {
         // Skip first article
         if (++$intCount <= intval($this->skipFirst)) {
             continue;
         }
         $cssID = deserialize($objArticles->cssID, true);
         $articles[] = array('link' => $objArticles->title, 'title' => specialchars($objArticles->title), 'id' => $cssID[0] ?: 'article-' . $objArticles->id, 'articleId' => $objArticles->id);
     }
     $this->Template->articles = $articles;
 }
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var PageModel $objPage */
     global $objPage;
     $this->Template->content = '';
     $this->Template->referer = 'javascript:history.go(-1)';
     $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];
     $objNewsletter = \NewsletterModel::findSentByParentAndIdOrAlias(\Input::get('items'), $this->nl_channels);
     if (null === $objNewsletter) {
         throw new PageNotFoundException('Page not found: ' . \Environment::get('uri'));
     }
     // Overwrite the page title (see #2853 and #4955)
     if ($objNewsletter->subject != '') {
         $objPage->pageTitle = strip_tags(\StringUtil::stripInsertTags($objNewsletter->subject));
     }
     // Add enclosure
     if ($objNewsletter->addFile) {
         $this->addEnclosuresToTemplate($this->Template, $objNewsletter->row(), 'files');
     }
     // Support plain text newsletters (thanks to Hagen Klemp)
     if ($objNewsletter->sendText) {
         $strContent = nl2br_html5($objNewsletter->text);
     } else {
         $strContent = str_ireplace(' align="center"', '', $objNewsletter->content);
     }
     // Parse simple tokens and insert tags
     $strContent = $this->replaceInsertTags($strContent);
     $strContent = \StringUtil::parseSimpleTokens($strContent, array());
     // Encode e-mail addresses
     $strContent = \StringUtil::encodeEmail($strContent);
     $this->Template->content = $strContent;
     $this->Template->subject = $objNewsletter->subject;
 }
Example #4
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();
 }
 public function getPageLayout(PageModel $objPage, LayoutModel &$objLayout, PageRegular $objPageRegular)
 {
     // layout must use ajax layout
     if (!$objLayout->useAjaxLayout) {
         return;
     }
     // request must be ajax
     if (!Environment::get('isAjaxRequest')) {
         return;
     }
     // set custom or default ajax layout
     if ($objLayout->customAjaxLayout) {
         // load custom layout
         if (($objAjaxLayout = LayoutModel::findById($objLayout->customAjaxLayout)) !== null) {
             $objLayout = $objAjaxLayout;
         }
     } else {
         // create default layout
         $pid = $objLayout->pid;
         $objLayout = new LayoutModel();
         $objLayout->pid = $pid;
         $objLayout->rows = '1rw';
         $objLayout->cols = '1cl';
         $objLayout->orderExt = '';
         $objLayout->modules = 'a:1:{i:0;a:3:{s:3:"mod";s:1:"0";s:3:"col";s:4:"main";s:6:"enable";s:1:"1";}}';
         $objLayout->template = 'fe_page_ajax';
         $objLayout->doctype = $objLayout->doctype;
     }
 }
Example #6
0
 /**
  * Generate the module
  *
  * @return string
  */
 public function run()
 {
     $arrJobs = array();
     /** @var BackendTemplate|object $objTemplate */
     $objTemplate = new \BackendTemplate('be_purge_data');
     $objTemplate->isActive = $this->isActive();
     $objTemplate->message = \Message::generateUnwrapped();
     // Run the jobs
     if (\Input::post('FORM_SUBMIT') == 'tl_purge') {
         $purge = \Input::post('purge');
         if (!empty($purge) && is_array($purge)) {
             foreach ($purge as $group => $jobs) {
                 foreach ($jobs as $job) {
                     list($class, $method) = $GLOBALS['TL_PURGE'][$group][$job]['callback'];
                     $this->import($class);
                     $this->{$class}->{$method}();
                 }
             }
         }
         \Message::addConfirmation($GLOBALS['TL_LANG']['tl_maintenance']['cacheCleared']);
         $this->reload();
     }
     // Tables
     foreach ($GLOBALS['TL_PURGE']['tables'] as $key => $config) {
         $arrJobs[$key] = array('id' => 'purge_' . $key, 'title' => $GLOBALS['TL_LANG']['tl_maintenance_jobs'][$key][0], 'description' => $GLOBALS['TL_LANG']['tl_maintenance_jobs'][$key][1], 'group' => 'tables', 'affected' => '');
         // Get the current table size
         foreach ($config['affected'] as $table) {
             $objCount = $this->Database->execute("SELECT COUNT(*) AS count FROM " . $table);
             $arrJobs[$key]['affected'] .= '<br>' . $table . ': <span>' . sprintf($GLOBALS['TL_LANG']['MSC']['entries'], $objCount->count) . ', ' . $this->getReadableSize($this->Database->getSizeOf($table), 0) . '</span>';
         }
     }
     $strCachePath = str_replace(TL_ROOT . DIRECTORY_SEPARATOR, '', \System::getContainer()->getParameter('kernel.cache_dir'));
     // Folders
     foreach ($GLOBALS['TL_PURGE']['folders'] as $key => $config) {
         $arrJobs[$key] = array('id' => 'purge_' . $key, 'title' => $GLOBALS['TL_LANG']['tl_maintenance_jobs'][$key][0], 'description' => $GLOBALS['TL_LANG']['tl_maintenance_jobs'][$key][1], 'group' => 'folders', 'affected' => '');
         // Get the current folder size
         foreach ($config['affected'] as $folder) {
             $total = 0;
             $folder = sprintf($folder, $strCachePath);
             // Only check existing folders
             if (is_dir(TL_ROOT . '/' . $folder)) {
                 $objFiles = Finder::create()->in(TL_ROOT . '/' . $folder)->files();
                 $total = iterator_count($objFiles);
             }
             $arrJobs[$key]['affected'] .= '<br>' . $folder . ': <span>' . sprintf($GLOBALS['TL_LANG']['MSC']['files'], $total) . '</span>';
         }
     }
     // Custom
     foreach ($GLOBALS['TL_PURGE']['custom'] as $key => $job) {
         $arrJobs[$key] = array('id' => 'purge_' . $key, 'title' => $GLOBALS['TL_LANG']['tl_maintenance_jobs'][$key][0], 'description' => $GLOBALS['TL_LANG']['tl_maintenance_jobs'][$key][1], 'group' => 'custom');
     }
     $objTemplate->jobs = $arrJobs;
     $objTemplate->action = ampersand(\Environment::get('request'));
     $objTemplate->headline = $GLOBALS['TL_LANG']['tl_maintenance']['clearCache'];
     $objTemplate->job = $GLOBALS['TL_LANG']['tl_maintenance']['job'];
     $objTemplate->description = $GLOBALS['TL_LANG']['tl_maintenance']['description'];
     $objTemplate->submit = \StringUtil::specialchars($GLOBALS['TL_LANG']['tl_maintenance']['clearCache']);
     $objTemplate->help = \Config::get('showHelp') && $GLOBALS['TL_LANG']['tl_maintenance']['cacheTables'][1] != '' ? $GLOBALS['TL_LANG']['tl_maintenance']['cacheTables'][1] : '';
     return $objTemplate->parse();
 }
 /**
  * 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);
 }
Example #8
0
 /**
  * Logout the current user and redirect
  *
  * @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']['logout'][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 last page visited
     if ($this->redirectBack) {
         $_SESSION['LAST_PAGE_VISITED'] = $this->getReferer();
     }
     $this->import('FrontendUser', 'User');
     $strRedirect = \Environment::get('base');
     // Redirect to last page visited
     if ($this->redirectBack && !empty($_SESSION['LAST_PAGE_VISITED'])) {
         $strRedirect = $_SESSION['LAST_PAGE_VISITED'];
     } elseif ($this->jumpTo && ($objTarget = $this->objModel->getRelated('jumpTo')) !== null) {
         $strRedirect = $this->generateFrontendUrl($objTarget->row());
     }
     // Log out and redirect
     if ($this->User->logout()) {
         $this->redirect($strRedirect);
     }
     return '';
 }
 /**
  * Generate the module
  */
 protected function compile()
 {
     // Overwrite default template
     if ($this->clr_template) {
         $this->Template = new \FrontendTemplate($this->clr_template);
         $this->Template->setData($this->arrData);
     }
     // Subscribe
     if (Input::post('FORM_SUBMIT') == 'clr_subscribe') {
         $this->addSubscriber();
     }
     $blnHasError = false;
     // Error message
     if (strlen($_SESSION['SUBSCRIBE_ERROR'])) {
         $blnHasError = true;
         $this->Template->mclass = 'error';
         $this->Template->message = $_SESSION['SUBSCRIBE_ERROR'];
         $_SESSION['SUBSCRIBE_ERROR'] = '';
     }
     // Confirmation message
     if (strlen($_SESSION['SUBSCRIBE_CONFIRM'])) {
         $this->Template->mclass = 'confirm';
         $this->Template->message = $_SESSION['SUBSCRIBE_CONFIRM'];
         $_SESSION['SUBSCRIBE_CONFIRM'] = '';
     }
     // Default template variables
     $this->Template->email = '';
     $this->Template->submit = specialchars($GLOBALS['TL_LANG']['MSC']['subscribe']);
     $this->Template->emailLabel = $GLOBALS['TL_LANG']['MSC']['emailAddress'];
     $this->Template->action = Environment::get('indexFreeRequest');
     $this->Template->formId = 'clr_subscribe';
     $this->Template->id = $this->id;
     $this->Template->hasError = $blnHasError;
 }
 /**
  * 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;
 }
Example #11
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);
 }
Example #12
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     $dc = \Contao\Database::getInstance();
     $row = $dc->prepare('SELECT * FROM tl_rs_settings WHERE id = ?')->limit(1)->execute($this->rs_setting)->fetchAssoc();
     $href = '';
     if ($row) {
         $customerid = '6857';
         $lang = $row['language_demo'];
         $speed = $row['speed'];
         $readid = $this->rs_readid ? $this->rs_readid : $this->strColumn;
         $stattype = \Contao\Environment::get('host');
         $url = \Contao\Environment::get('base');
         $url2 = \Contao\Environment::get('requestUri');
         if ($url2 != '/') {
             $url .= substr($url2, 1);
         }
         if ($row['have_license']) {
             $customerid = $row['customer_id'];
             $lang = $row['language'];
         }
         $protocol = \Contao\Environment::get('https');
         $ssl = false;
         if (isset($protocol)) {
             if ('on' == strtolower($protocol)) {
                 $ssl = true;
             }
             if ('1' == $protocol) {
                 $ssl = true;
             }
         }
         if (!$GLOBALS['RS_IN_HEAD']) {
             $GLOBALS['RS_IN_HEAD'] = true;
             if ($ssl) {
                 $GLOBALS['TL_HEAD'][] = '<script src="system/modules/readspeaker/assets/rs_ssl/ReadSpeaker.js?pids=embhl" type="text/javascript"></script>';
             } else {
                 $GLOBALS['TL_HEAD'][] = '<script src="http://f1.eu.readspeaker.com/script/' . $customerid . '/ReadSpeaker.js?pids=embhl" type="text/javascript"></script>';
             }
         }
         $GLOBALS['TL_HEAD'][] = '<script src="system/modules/readspeaker/assets/readspeaker.js"></script>';
         $GLOBALS['TL_HEAD'][] = '<script type="text/javascript">
                                 <!--
                                 window.rsConf = {general: {usePost: true}};
                                 //-->
                                 </script>';
         $href = '';
         if ($ssl) {
             $href .= "https://app.readspeaker.com/cgi-bin/rsent?";
         } else {
             $href .= "http://app.eu.readspeaker.com/cgi-bin/rsent?";
         }
         $href .= "customerid=" . $customerid;
         $href .= "&amp;lang=" . $lang;
         $href .= "&amp;readid=" . $readid;
         $href .= "&amp;url=" . urlencode($url);
         $href .= "&amp;stattype=" . $stattype;
     }
     $this->Template->href = $href;
     $this->Template->button_title = $this->rs_player_title;
 }
Example #13
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     // Create the date object
     try {
         if (\Input::get('month')) {
             $this->Date = new \Date(\Input::get('month'), 'Ym');
         } elseif (\Input::get('day')) {
             $this->Date = new \Date(\Input::get('day'), 'Ymd');
         } else {
             $this->Date = new \Date();
         }
     } catch (\OutOfBoundsException $e) {
         throw new PageNotFoundException('Page not found: ' . \Environment::get('uri'));
     }
     $time = \Date::floorToMinute();
     // Find the boundaries
     $objMinMax = $this->Database->query("SELECT MIN(startTime) AS dateFrom, MAX(endTime) AS dateTo, MAX(repeatEnd) AS repeatUntil FROM tl_calendar_events WHERE pid IN(" . implode(',', array_map('intval', $this->cal_calendar)) . ")" . (!BE_USER_LOGGED_IN ? " AND (start='' OR start<='{$time}') AND (stop='' OR stop>'" . ($time + 60) . "') AND published='1'" : ""));
     /** @var FrontendTemplate|object $objTemplate */
     $objTemplate = new \FrontendTemplate($this->cal_ctemplate);
     // Store year and month
     $intYear = date('Y', $this->Date->tstamp);
     $intMonth = date('m', $this->Date->tstamp);
     $objTemplate->intYear = $intYear;
     $objTemplate->intMonth = $intMonth;
     // Previous month
     $prevMonth = $intMonth == 1 ? 12 : $intMonth - 1;
     $prevYear = $intMonth == 1 ? $intYear - 1 : $intYear;
     $lblPrevious = $GLOBALS['TL_LANG']['MONTHS'][$prevMonth - 1] . ' ' . $prevYear;
     $intPrevYm = intval($prevYear . str_pad($prevMonth, 2, 0, STR_PAD_LEFT));
     // Only generate a link if there are events (see #4160)
     if ($objMinMax->dateFrom !== null && $intPrevYm >= date('Ym', $objMinMax->dateFrom) || $intPrevYm >= date('Ym')) {
         $objTemplate->prevHref = $this->strUrl . '?month=' . $intPrevYm;
         $objTemplate->prevTitle = \StringUtil::specialchars($lblPrevious);
         $objTemplate->prevLink = $GLOBALS['TL_LANG']['MSC']['cal_previous'] . ' ' . $lblPrevious;
         $objTemplate->prevLabel = $GLOBALS['TL_LANG']['MSC']['cal_previous'];
     }
     // Current month
     $objTemplate->current = $GLOBALS['TL_LANG']['MONTHS'][date('m', $this->Date->tstamp) - 1] . ' ' . date('Y', $this->Date->tstamp);
     // Next month
     $nextMonth = $intMonth == 12 ? 1 : $intMonth + 1;
     $nextYear = $intMonth == 12 ? $intYear + 1 : $intYear;
     $lblNext = $GLOBALS['TL_LANG']['MONTHS'][$nextMonth - 1] . ' ' . $nextYear;
     $intNextYm = $nextYear . str_pad($nextMonth, 2, 0, STR_PAD_LEFT);
     // Only generate a link if there are events (see #4160)
     if ($objMinMax->dateTo !== null && $intNextYm <= date('Ym', max($objMinMax->dateTo, $objMinMax->repeatUntil)) || $intNextYm <= date('Ym')) {
         $objTemplate->nextHref = $this->strUrl . '?month=' . $intNextYm;
         $objTemplate->nextTitle = \StringUtil::specialchars($lblNext);
         $objTemplate->nextLink = $lblNext . ' ' . $GLOBALS['TL_LANG']['MSC']['cal_next'];
         $objTemplate->nextLabel = $GLOBALS['TL_LANG']['MSC']['cal_next'];
     }
     // Set the week start day
     if (!$this->cal_startDay) {
         $this->cal_startDay = 0;
     }
     $objTemplate->days = $this->compileDays();
     $objTemplate->weeks = $this->compileWeeks();
     $objTemplate->substr = $GLOBALS['TL_LANG']['MSC']['dayShortLength'];
     $this->Template->calendar = $objTemplate->parse();
 }
 /**
  * Generate the URL path
  *
  * @param PageModel $pageModel
  *
  * @return string
  */
 protected function generateUrlPath(PageModel $pageModel)
 {
     $pageModel->loadDetails();
     if (($rootModel = PageModel::findByPk($pageModel->rootId)) === null) {
         return '';
     }
     return ($rootModel->rootUseSSL ? 'https://' : 'http://') . ($rootModel->domain ?: Environment::get('host')) . TL_PATH . '/' . $pageModel->alias . '/';
 }
Example #15
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);
 }
Example #16
0
 /**
  * @param $strType
  * @param null $strForceLanguage
  */
 public function __construct($strType, $strForceLanguage = null)
 {
     if (in_array($strType, $GLOBALS['TL_EMAIL'])) {
         $this->strType = $strType;
     }
     $this->strForceLanguage = $strForceLanguage;
     // Set default parameters
     $this->addParameter('host', Idna::decode(Environment::get('host')));
     $this->addParameter('admin_name', BackendUser::getInstance()->name);
 }
Example #17
0
 /**
  * Generate the widget and return it as string
  *
  * @return string
  */
 public function generate()
 {
     $arrOptions = array();
     if (!$this->multiple && count($this->arrOptions) > 1) {
         $this->arrOptions = array($this->arrOptions[0]);
     }
     // The "required" attribute only makes sense for single checkboxes
     if ($this->mandatory && !$this->multiple) {
         $this->arrAttributes['required'] = 'required';
     }
     /** @var AttributeBagInterface $objSessionBag */
     $objSessionBag = \System::getContainer()->get('session')->getBag('contao_backend');
     $state = $objSessionBag->get('checkbox_groups');
     // Toggle the checkbox group
     if (\Input::get('cbc')) {
         $state[\Input::get('cbc')] = isset($state[\Input::get('cbc')]) && $state[\Input::get('cbc')] == 1 ? 0 : 1;
         $objSessionBag->set('checkbox_groups', $state);
         $this->redirect(preg_replace('/(&(amp;)?|\\?)cbc=[^& ]*/i', '', \Environment::get('request')));
     }
     $blnFirst = true;
     $blnCheckAll = true;
     foreach ($this->arrOptions as $i => $arrOption) {
         // Single dimension array
         if (is_numeric($i)) {
             $arrOptions[] = $this->generateCheckbox($arrOption, $i);
             continue;
         }
         $id = 'cbc_' . $this->strId . '_' . \StringUtil::standardize($i);
         $img = 'folPlus.svg';
         $display = 'none';
         if (!isset($state[$id]) || !empty($state[$id])) {
             $img = 'folMinus.svg';
             $display = 'block';
         }
         $arrOptions[] = '<div class="checkbox_toggler' . ($blnFirst ? '_first' : '') . '"><a href="' . $this->addToUrl('cbc=' . $id) . '" onclick="AjaxRequest.toggleCheckboxGroup(this,\'' . $id . '\');Backend.getScrollOffset();return false">' . \Image::getHtml($img) . '</a>' . $i . '</div><fieldset id="' . $id . '" class="tl_checkbox_container checkbox_options" style="display:' . $display . '"><input type="checkbox" id="check_all_' . $id . '" class="tl_checkbox" onclick="Backend.toggleCheckboxGroup(this, \'' . $id . '\')"> <label for="check_all_' . $id . '" style="color:#a6a6a6"><em>' . $GLOBALS['TL_LANG']['MSC']['selectAll'] . '</em></label>';
         // Multidimensional array
         foreach ($arrOption as $k => $v) {
             $arrOptions[] = $this->generateCheckbox($v, standardize($i) . '_' . $k);
         }
         $arrOptions[] = '</fieldset>';
         $blnFirst = false;
         $blnCheckAll = false;
     }
     // Add a "no entries found" message if there are no options
     if (empty($arrOptions)) {
         $arrOptions[] = '<p class="tl_noopt">' . $GLOBALS['TL_LANG']['MSC']['noResult'] . '</p>';
         $blnCheckAll = false;
     }
     if ($this->multiple) {
         return sprintf('<fieldset id="ctrl_%s" class="tl_checkbox_container%s"><legend>%s%s%s%s</legend><input type="hidden" name="%s" value="">%s%s</fieldset>%s', $this->strId, $this->strClass != '' ? ' ' . $this->strClass : '', $this->mandatory ? '<span class="invisible">' . $GLOBALS['TL_LANG']['MSC']['mandatory'] . ' </span>' : '', $this->strLabel, $this->mandatory ? '<span class="mandatory">*</span>' : '', $this->xlabel, $this->strName, $blnCheckAll ? '<input type="checkbox" id="check_all_' . $this->strId . '" class="tl_checkbox" onclick="Backend.toggleCheckboxGroup(this,\'ctrl_' . $this->strId . '\')' . ($this->onclick ? ';' . $this->onclick : '') . '"> <label for="check_all_' . $this->strId . '" style="color:#a6a6a6"><em>' . $GLOBALS['TL_LANG']['MSC']['selectAll'] . '</em></label><br>' : '', str_replace('<br></fieldset><br>', '</fieldset>', implode('<br>', $arrOptions)), $this->wizard);
     } else {
         return sprintf('<div id="ctrl_%s" class="tl_checkbox_single_container%s"><input type="hidden" name="%s" value="">%s</div>%s', $this->strId, $this->strClass != '' ? ' ' . $this->strClass : '', $this->strName, str_replace('<br></div><br>', '</div>', implode('<br>', $arrOptions)), $this->wizard);
     }
 }
 /**
  * Get the URL path
  *
  * @param int $id
  *
  * @return string
  */
 public function getUrlPath($id)
 {
     if (($pageModel = $this->getPageModel($id)) === null) {
         return '';
     }
     $pageModel->loadDetails();
     if (($rootModel = PageModel::findByPk($pageModel->rootId)) === null) {
         return '';
     }
     return ($rootModel->rootUseSSL ? 'https://' : 'http://') . ($rootModel->domain ?: Environment::get('host')) . TL_PATH . '/';
 }
 /**
  * Handle the event.
  *
  * @param HandleSubmitEvent $event The event.
  *
  * @return void
  */
 public function handleEvent(HandleSubmitEvent $event)
 {
     $dispatcher = func_get_arg(2);
     $currentUrl = $this->environment->get('uri');
     switch ($event->getButtonName()) {
         case 'save':
             // Could be a create action, always redirect to current page with edit action and id properly set.
             $url = UrlBuilder::fromUrl($currentUrl)->setQueryParameter('act', 'edit')->setQueryParameter('id', ModelId::fromModel($event->getModel())->getSerialized());
             $dispatcher->dispatch(ContaoEvents::CONTROLLER_REDIRECT, new RedirectEvent($url->getUrl()));
             break;
         case 'saveNcreate':
             // We want to create a new model, set create action and pass the current id as "after" to keep sorting.
             $after = ModelId::fromModel($event->getModel());
             $url = UrlBuilder::fromUrl($currentUrl)->unsetQueryParameter('id')->setQueryParameter('act', 'create')->setQueryParameter('after', $after->getSerialized());
             $dispatcher->dispatch(ContaoEvents::CONTROLLER_REDIRECT, new RedirectEvent($url->getUrl()));
             break;
         default:
             // Do nothing.
     }
 }
Example #20
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();
 }
Example #21
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;
 }
Example #22
0
 /**
  * @param string $strEmail
  * @param int $intFormId
  *
  * @return bool
  */
 public function sendActivationMail($strEmail, $intFormId)
 {
     if ($this->soap) {
         $objReturn = $this->soap->formsSendActivationMail($this->apiKey, $intFormId, $strEmail, array('user_ip' => '0.0.0.0', 'user_agent' => Environment::get('httpUserAgent'), 'referer' => Environment::get('uri')));
         if ($objReturn->status == 'SUCCESS') {
             $this->log('E-Mail erfolgreich versendet an ' . $strEmail . ' - ' . $objReturn->message, 'CleverReach::sendActivationMail', TL_NEWSLETTER);
             return true;
         } else {
             $this->log('Fehler beim versenden an ' . $strEmail . ' - ' . $objReturn->message, 'CleverReach::sendActivationMail', TL_ERROR);
             return false;
         }
     } else {
         $this->log('Fehler beim versenden an ' . $strEmail . ' - Keine Verbindung zur SOAP-Schnittstelle', 'CleverReach::sendActivationMail', TL_ERROR);
         return false;
     }
 }
 /**
  * Generate the module
  *
  * @return string
  */
 public function run()
 {
     $GLOBALS['TL_CSS'][] = 'system/modules/vimeo_api/assets/backend.min.css';
     $elementsData = $this->getContentElements();
     $template = new BackendTemplate('be_vimeo_rebuilder');
     $template->action = ampersand(Environment::get('request'));
     $template->isActive = $this->isActive();
     $template->elementsCount = count($elementsData);
     $template->canRun = true;
     // Add the stats data
     if (($stats = static::generateStats()) !== null) {
         foreach ($stats as $k => $v) {
             $template->{$k} = $v;
         }
     }
     // Generate the elements
     if ($this->isActive()) {
         // Redirect to the maintenance module if the rebuilder cannot be run
         if (!$template->canRun) {
             Controller::redirect('contao/main.php?do=maintenance');
         }
         $elements = [];
         foreach ($elementsData as $data) {
             switch ($data['ptable']) {
                 case 'tl_article':
                     $source = $GLOBALS['TL_LANG']['tl_maintenance']['vimeo.tableSourceRef']['article'];
                     $path = [$data['_page'], $data['_article']];
                     break;
                 case 'tl_news':
                     $source = $GLOBALS['TL_LANG']['tl_maintenance']['vimeo.tableSourceRef']['news'];
                     $path = [$data['_archive'], $data['_news']];
                     break;
                 case 'tl_calendar_events':
                     $source = $GLOBALS['TL_LANG']['tl_maintenance']['vimeo.tableSourceRef']['event'];
                     $path = [$data['_calendar'], $data['_event']];
                     break;
                 default:
                     $source = '';
                     $path = [];
             }
             $elements[] = ['type' => $data['type'], 'ref' => $data['type'] === 'vimeo_album' ? $data['vimeo_albumId'] : $data['vimeo_videoId'], 'id' => $data['id'], 'source' => $source, 'path' => $path];
         }
         $template->elements = $elements;
         $template->ajaxAction = $this->ajaxAction;
     }
     return $template->parse();
 }
Example #24
0
    /**
     * Generate the widget and return it as string
     *
     * @return string
     */
    public function generate()
    {
        $action = Input::get('actionPSTag');
        $tags = Input::get('ps_tags');
        $requestUri = Environment::get('requestUri');
        $requestUri = Helper::removeRequestTokenFromUri($requestUri);
        if ($action && $action == 'updateTags') {
            $this->updateTags($tags);
        }
        if ($action && $action == 'removeTags') {
            $this->removeTags($tags);
        }
        $GLOBALS['TL_JAVASCRIPT'][] = $GLOBALS['PS_PUBLIC_PATH'] . 'vendor/mootagify.js|static';
        $GLOBALS['TL_CSS'][] = $GLOBALS['PS_PUBLIC_PATH'] . 'css/mootagify-bootstrap.css|static';
        $GLOBALS['TL_CSS'][] = $GLOBALS['PS_PUBLIC_PATH'] . 'css/mootagify.css|static';
        $options = $this->options ? $this->options : array();
        $script = sprintf('<script>' . 'window.addEvent("domready", function(){

                var tagify = new mooTagify(document.id("tagWrap_%s"), null ,{
                    autoSuggest: true,
                    availableOptions: ' . json_encode($options) . '
                });

                tagify.addEvent("tagsUpdate", function(){

                    var tags = tagify.getTags();
                    document.id("ctrl_%s").set("value", tags.join());

                    new Request({url: "%s&actionPSTag=updateTags"}).get({"ps_tags": tags, "rt": Contao.request_token });

                });

                tagify.addEvent("tagRemove", function(tag){

                    var tags = tagify.getTags()

                    var deleted = tag;

                    document.id("ctrl_%s").set("value", tags.join());

                    new Request({url: "%s&actionPSTag=removeTags"}).get({ "ps_tags": deleted, "rt": Contao.request_token });

                });
            });' . '</script>', $this->strId, $this->strId, $requestUri, $this->strId, $requestUri);
        return sprintf('<input type="hidden" id="ctrl_%s" name="%s" value="%s"><div id="tagWrap_%s" class="hide"> <div class="tag-wrapper"></div> <div class="tag-input"> <input type="text" id="listTags" class="tl_text" name="listTags" value="%s" placeholder="%s"> </div> <div class="clear"></div></div>' . $script . '', $this->strId, $this->strName, specialchars($this->varValue), $this->strId, specialchars($this->varValue), $GLOBALS['TL_LANG']['MSC']['TagTextField']['tag']);
    }
 /**
  * Initialize the tests handler
  *
  * @param DataContainer|null $dc
  */
 public function initialize(DataContainer $dc = null)
 {
     if ($dc === null) {
         return;
     }
     $this->table = $this->getTableName();
     $this->dc = $dc;
     // Enable or disable the analyzer
     if (isset($_GET[self::$serpParamName])) {
         Input::get(self::$serpParamName) ? static::enable() : static::disable();
         Controller::redirect(str_replace(['&' . self::$serpParamName . '=' . Input::get(self::$serpParamName), '&' . self::$serpTemporaryParamName . '=' . Input::get(self::$serpTemporaryParamName)], '', Environment::get('request')));
     }
     $this->addGlobalOperations();
     if ($this->isEnabled()) {
         $this->initializeEnabled();
     }
 }
 protected function compile()
 {
     global $objPage;
     // Get the current news item
     $objNewsItem = NewsModel::findPublishedByParentAndIdOrAlias(Input::get('items'), $this->news_archives);
     if ($objNewsItem === null) {
         parent::compile();
     }
     $objPage->canonicalType = $objNewsItem->canonicalType;
     $objPage->canonicalJumpTo = $objNewsItem->canonicalJumpTo;
     $objPage->canonicalWebsite = $objNewsItem->canonicalWebsite;
     if ($objNewsItem->canonicalType == 'self') {
         $objPage->canonicalType = 'external';
         $objPage->canonicalWebsite = Environment::get('url') . TL_PATH . '/' . Environment::get('request');
     }
     parent::compile();
 }
 protected function compile()
 {
     global $objPage;
     // Get the current event
     $objEvent = CalendarEventsModel::findPublishedByParentAndIdOrAlias(Input::get('events'), $this->cal_calendar);
     if ($objEvent === null) {
         parent::compile();
     }
     $objPage->canonicalType = $objEvent->canonicalType;
     $objPage->canonicalJumpTo = $objEvent->canonicalJumpTo;
     $objPage->canonicalWebsite = $objEvent->canonicalWebsite;
     if ($objEvent->canonicalType == 'self') {
         $objPage->canonicalType = 'external';
         $objPage->canonicalWebsite = Environment::get('url') . TL_PATH . '/' . Environment::get('request');
     }
     parent::compile();
 }
 /**
  * Auto expand the tree
  *
  * @throws \Exception
  */
 public function autoExpandTree()
 {
     $session = Session::getInstance()->getData();
     if ($session['seo_serp_expand_tree'] !== 'tl_page' && !Input::get('serp_tests_expand')) {
         return;
     }
     $nodes = Database::getInstance()->execute("SELECT DISTINCT pid FROM tl_page WHERE pid>0");
     // Reset the array first
     $session['tl_page_tree'] = [];
     // Expand the tree
     while ($nodes->next()) {
         $session['tl_page_tree'][$nodes->pid] = 1;
     }
     // Avoid redirect loop
     $session['seo_serp_expand_tree'] = null;
     Session::getInstance()->setData($session);
     Backend::redirect(str_replace('serp_tests_expand=1', '', Environment::get('request')));
 }
Example #29
0
 /**
  * Return a redirect response object
  *
  * @param PageModel $objPage
  *
  * @return RedirectResponse
  */
 public function getResponse($objPage)
 {
     // Set last page visited
     if ($objPage->redirectBack) {
         $_SESSION['LAST_PAGE_VISITED'] = $this->getReferer();
     }
     $this->import('FrontendUser', 'User');
     $strRedirect = \Environment::get('base');
     // Redirect to last page visited
     if ($objPage->redirectBack && !empty($_SESSION['LAST_PAGE_VISITED'])) {
         $strRedirect = $_SESSION['LAST_PAGE_VISITED'];
     } elseif ($objPage->jumpTo && ($objTarget = $objPage->getRelated('jumpTo')) instanceof PageModel) {
         /** @var PageModel $objTarget */
         $strRedirect = $objTarget->getAbsoluteUrl();
     }
     $this->User->logout();
     return new RedirectResponse($strRedirect);
 }
Example #30
0
 /**
  * Run the controller and parse the template
  */
 public function run()
 {
     $template = new BackendTemplate('be_main');
     $template->main = '';
     // Ajax request
     if ($_POST && Environment::get('isAjaxRequest')) {
         $this->objAjax = new Ajax(Input::post('action'));
         $this->objAjax->executePreActions();
     }
     $strTable = Input::get('table');
     $strField = Input::get('field');
     // Define the current ID
     define('CURRENT_ID', Input::get('table') ? $this->Session->get('CURRENT_ID') : Input::get('id'));
     Controller::loadDataContainer($strTable);
     $strDriver = 'DC_' . $GLOBALS['TL_DCA'][$strTable]['config']['dataContainer'];
     $objDca = new $strDriver($strTable);
     $objDca->field = $strField;
     // Set the active record
     if ($this->Database->tableExists($strTable)) {
         /** @var Model $strModel $strModel */
         $strModel = Model::getClassFromTable($strTable);
         if (class_exists($strModel)) {
             $objModel = $strModel::findByPk(Input::get('id'));
             if ($objModel !== null) {
                 $objDca->activeRecord = $objModel;
             }
         }
     }
     // AJAX request
     if ($_POST && Environment::get('isAjaxRequest')) {
         $this->objAjax->executePostActions($objDca);
     }
     $partial = new BackendTemplate('be_rte_table_editor');
     $template->isPopup = true;
     $template->main = $partial->parse();
     $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();
 }