TYPO3 CMS  TYPO3_7-6
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 = [];
39 
43  protected $widgetContextsStorageKey = 'TYPO3\\CMS\\Fluid\\Core\\Widget\\AjaxWidgetContextHolder_widgetContexts';
44 
48  public function __construct()
49  {
50  $this->loadWidgetContexts();
51  }
52 
58  protected function loadWidgetContexts()
59  {
60  if (TYPO3_MODE === 'FE') {
61  $this->widgetContexts = unserialize($GLOBALS['TSFE']->fe_user->getKey('ses', $this->widgetContextsStorageKey));
62  } else {
63  $this->widgetContexts = unserialize($GLOBALS['BE_USER']->uc[$this->widgetContextsStorageKey]);
64  $GLOBALS['BE_USER']->writeUC();
65  }
66  }
67 
74  public function get($ajaxWidgetId)
75  {
76  if (!isset($this->widgetContexts[$ajaxWidgetId])) {
77  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);
78  }
79  return $this->widgetContexts[$ajaxWidgetId];
80  }
81 
89  public function store(\TYPO3\CMS\Fluid\Core\Widget\WidgetContext $widgetContext)
90  {
91  $ajaxWidgetId = md5(uniqid(mt_rand(), true));
92  $widgetContext->setAjaxWidgetIdentifier($ajaxWidgetId);
93  $this->widgetContexts[$ajaxWidgetId] = $widgetContext;
94  $this->storeWidgetContexts();
95  }
96 
102  protected function storeWidgetContexts()
103  {
104  if (TYPO3_MODE === 'FE') {
105  $GLOBALS['TSFE']->fe_user->setKey('ses', $this->widgetContextsStorageKey, serialize($this->widgetContexts));
106  $GLOBALS['TSFE']->fe_user->storeSessionData();
107  } else {
108  $GLOBALS['BE_USER']->uc[$this->widgetContextsStorageKey] = serialize($this->widgetContexts);
109  $GLOBALS['BE_USER']->writeUc();
110  }
111  }
112 }
store(\TYPO3\CMS\Fluid\Core\Widget\WidgetContext $widgetContext)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']