TYPO3 CMS  TYPO3_6-2
AjaxWidgetContextHolder.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License, either version 3 *
9  * of the License, or (at your option) any later version. *
10  * *
11  * *
12  * This script is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14  * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15  * General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU Lesser General Public *
18  * License along with the script. *
19  * If not, see http://www.gnu.org/licenses/lgpl.html *
20  * *
21  * The TYPO3 project - inspiring people to share! *
22  * */
31 
38  protected $widgetContexts = array();
39 
43  protected $widgetContextsStorageKey = 'TYPO3\\CMS\\Fluid\\Core\\Widget\\AjaxWidgetContextHolder_widgetContexts';
44 
48  public function __construct() {
49  $this->loadWidgetContexts();
50  }
51 
57  protected function loadWidgetContexts() {
58  if (TYPO3_MODE === 'FE') {
59  $this->widgetContexts = unserialize($GLOBALS['TSFE']->fe_user->getKey('ses', $this->widgetContextsStorageKey));
60  } else {
61  $this->widgetContexts = unserialize($GLOBALS['BE_USER']->uc[$this->widgetContextsStorageKey]);
62  $GLOBALS['BE_USER']->writeUC();
63  }
64  }
65 
72  public function get($ajaxWidgetId) {
73  if (!isset($this->widgetContexts[$ajaxWidgetId])) {
74  throw new \TYPO3\CMS\Fluid\Core\Widget\Exception\WidgetContextNotFoundException('No widget context was found for the Ajax Widget Identifier "' . $ajaxWidgetId . '". This only happens if AJAX URIs are called without including the widget on a page.', 1284793775);
75  }
76  return $this->widgetContexts[$ajaxWidgetId];
77  }
78 
86  public function store(\TYPO3\CMS\Fluid\Core\Widget\WidgetContext $widgetContext) {
87  $ajaxWidgetId = md5(uniqid(mt_rand(), TRUE));
88  $widgetContext->setAjaxWidgetIdentifier($ajaxWidgetId);
89  $this->widgetContexts[$ajaxWidgetId] = $widgetContext;
90  $this->storeWidgetContexts();
91  }
92 
98  protected function storeWidgetContexts() {
99  if (TYPO3_MODE === 'FE') {
100  $GLOBALS['TSFE']->fe_user->setKey('ses', $this->widgetContextsStorageKey, serialize($this->widgetContexts));
101  $GLOBALS['TSFE']->fe_user->storeSessionData();
102  } else {
103  $GLOBALS['BE_USER']->uc[$this->widgetContextsStorageKey] = serialize($this->widgetContexts);
104  $GLOBALS['BE_USER']->writeUc();
105  }
106  }
107 }
store(\TYPO3\CMS\Fluid\Core\Widget\WidgetContext $widgetContext)
const TYPO3_MODE
Definition: init.php:40
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]