The class functions as an adapter for the PHP $_SESSION array and separates back end from front end session data. Usage: $session = Session::getInstance(); $session->set('foo', 'bar'); echo $session->get('foo');
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use the session service instead.
 public function replaceInsertTags($strTag)
 {
     $flags = explode('|', $strTag);
     $tag = array_shift($flags);
     list($strName, $strValue) = explode('::', $tag);
     if ($strName == 'accountmail') {
         $objSession = Session::getInstance();
         $arrData = $objSession->get('ACCOUNTMAIL_PARAMETERS');
         if (isset($arrData[$strValue])) {
             return $arrData[$strValue];
         }
     }
     return false;
 }
 /**
  * Restrict content element ids.
  *
  * @param array $allowedElements List of allowed elements.
  * @param int   $contentId       The id of the current content element.
  *
  * @return void
  * @throws AccessDeniedException When an invalid content element type is accessed.
  */
 private function restrictIds($allowedElements, $contentId)
 {
     $session = $this->session->getData();
     $allowedElements = ArrayUtil::flatten($allowedElements);
     // Set allowed content element IDs (edit multiple)
     if (!empty($session['CURRENT']['IDS']) && is_array($session['CURRENT']['IDS'])) {
         $session['CURRENT']['IDS'] = $this->filterIds($session['CURRENT']['IDS'], $allowedElements);
     }
     // Set allowed clipboard IDs
     if (!empty($session['CLIPBOARD']['tl_content']['id'])) {
         $session['CLIPBOARD']['tl_content']['id'] = $this->filterIds((array) $session['CLIPBOARD']['tl_content']['id'], $allowedElements, 'sorting');
     }
     // Overwrite session
     $this->session->setData($session);
     $this->guardAllowedAccess($allowedElements, $contentId);
 }
 /**
  * @inheritdoc
  *
  * @throws \InvalidArgumentException
  */
 protected function doSwitchView($id)
 {
     list($table, $id) = explode('.', $id);
     $url = Url::removeQueryString(['switchLanguage']);
     switch ($table) {
         case 'tl_article':
             $url = Url::addQueryString('id=' . $id, $url);
             break;
         case 'tl_page':
             Session::getInstance()->set('tl_page_node', (int) $id);
             break;
         default:
             throw new \InvalidArgumentException(sprintf('Table "%s" is not supported', $table));
     }
     Controller::redirect($url);
 }
 public function generateStandardGroup(ActionEvent $event)
 {
     $action = $event->getAction();
     $environment = $event->getEnvironment();
     $dataDefinition = $environment->getDataDefinition();
     if ($dataDefinition->getName() !== 'orm_avisota_salutation_group' || $action->getName() !== 'generate') {
         return;
     }
     global $AVISOTA_SALUTATION;
     $eventDispatcher = $environment->getEventDispatcher();
     $translator = $environment->getTranslator();
     $eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, new LoadLanguageFileEvent('avisota_salutation'));
     $eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, new LoadLanguageFileEvent('orm_avisota_salutation_group'));
     $predefinedSalutations = $AVISOTA_SALUTATION;
     $entityDataProvider = new EntityDataProvider();
     $entityDataProvider->setBaseConfig(array('source' => 'orm_avisota_salutation_group'));
     $entityManager = $entityDataProvider->getEntityManager();
     $entityAccessor = $entityDataProvider->getEntityAccessor();
     $salutationGroup = new \Avisota\Contao\Entity\SalutationGroup();
     $salutationGroup->setTitle('Default group generated at ' . date(Config::get('datimFormat')));
     $salutationGroup->setAlias(null);
     $sorting = 64;
     foreach ($predefinedSalutations as $index => $predefinedSalutation) {
         $salutation = new \Avisota\Contao\Entity\Salutation();
         $entityAccessor->setProperties($salutation, $predefinedSalutation);
         $salutation->setSalutation($translator->translate($index, 'avisota_salutation'));
         $salutation->setSalutationGroup($salutationGroup);
         $salutation->setSorting($sorting);
         $salutationGroup->addSalutation($salutation);
         $sorting *= 2;
     }
     $entityManager->persist($salutationGroup);
     $entityManager->flush($salutationGroup);
     $sessionConfirm = Session::getInstance()->get('TL_CONFIRM');
     if (!is_array($sessionConfirm)) {
         $sessionConfirm = (array) $sessionConfirm;
     }
     $sessionConfirm[] = $translator->translate('group_generated', 'orm_avisota_salutation_group');
     Session::getInstance()->set('TL_CONFIRM', $sessionConfirm);
     Controller::redirect('contao/main.php?do=avisota_salutation');
 }
 /**
  * Redirect the user to given module
  *
  * @param string $target
  */
 protected function redirectToModule($target)
 {
     list($module, $params) = trimsplit('|', $target);
     $modules = $this->getModules();
     if (!isset($modules[$module])) {
         return;
     }
     $session = Session::getInstance()->getData();
     // Set the filters of all module tables to show all message types
     foreach ($modules[$module]['tables'] as $table) {
         $session['filter'][$table][AbstractHandler::$filterName] = AbstractHandler::getAvailableFilters()[0];
     }
     // Decode the params
     if ($params) {
         $params = '&' . base64_decode($params);
     }
     Session::getInstance()->setData($session);
     Controller::redirect('contao/main.php?do=' . $module . $params . '&' . AbstractHandler::$serpTemporaryParamName . '=1');
 }
Exemple #6
0
 /**
  * @param string $strName
  * @return string
  */
 protected function getContent($strName = 'content')
 {
     $strName = ucfirst(strtolower($strName));
     if (isset($GLOBALS['TL_CONFIG'][$this->strType . $strName])) {
         $strContent = Translator::translateValue($GLOBALS['TL_CONFIG'][$this->strType . $strName], $this->strForceLanguage);
         $objSession = Session::getInstance();
         $objSession->set('ACCOUNTMAIL_PARAMETERS', $this->arrParameters);
         $strContent = $this->replaceInsertTags($strContent, false);
         $objSession->remove('ACCOUNTMAIL_PARAMETERS');
         return $strContent;
     }
 }
 /**
  * Filter the records by message type
  */
 protected function filterRecords()
 {
     parent::filterRecords();
     $pageNode = Session::getInstance()->get('tl_page_node');
     // If there is a page node selected and there are no root IDs (e.g. due to filter settings),
     // make sure that page node is displayed
     if ($pageNode && $GLOBALS['TL_DCA'][$this->table]['list']['sorting']['root'] === [0]) {
         $GLOBALS['TL_DCA'][$this->table]['list']['sorting']['root'] = [$pageNode];
     }
 }
 /**
  * @inheritdoc
  */
 protected function doSwitchView($id)
 {
     Session::getInstance()->set('tl_page_node', (int) $id);
     Controller::redirect(Url::removeQueryString(['switchLanguage']));
 }
 /**
  * Get the active filter
  *
  * @return string
  */
 protected function getActiveFilter()
 {
     $session = Session::getInstance()->getData();
     $filter = $session['filter'][$this->table][static::$filterName];
     return in_array($filter, static::getAvailableFilters(), true) ? $filter : '';
 }