c8826ae1a5bf1b4f316800de54fad8c2425b2932
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / ClickMenuController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Core\Utility\GeneralUtility;
31
32 /**
33 * Script Class for the Context Sensitive Menu in TYPO3 (rendered in top frame, normally writing content dynamically to list frames).
34 *
35 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
36 * @see template::getContextMenuCode()
37 */
38 class ClickMenuController {
39
40 // Internal, static: GPvar:
41 // Back path.
42 /**
43 * @todo Define visibility
44 */
45 public $backPath;
46
47 // Definition of which item the click menu should be made for.
48 /**
49 * @todo Define visibility
50 */
51 public $item;
52
53 // Defines the name of the document object for which to reload the URL.
54 /**
55 * @todo Define visibility
56 */
57 public $reloadListFrame;
58
59 // Internal:
60 // Content accumulation
61 /**
62 * @todo Define visibility
63 */
64 public $content = '';
65
66 // Template object
67 /**
68 * @todo Define visibility
69 */
70 public $doc;
71
72 /**
73 * Files to include_once() - set in init() function
74 *
75 * @deprecated since 6.1, will be removed 2 versions later
76 */
77 public $include_once = array();
78
79 // Internal array of classes for extending the clickmenu
80 /**
81 * @todo Define visibility
82 */
83 public $extClassArray = array();
84
85 /**
86 * Constructor function for script class.
87 *
88 * @return void
89 * @todo Define visibility
90 */
91 public function init() {
92 // Setting GPvars:
93 $this->backPath = GeneralUtility::_GP('backPath');
94 $this->item = GeneralUtility::_GP('item');
95 $this->reloadListFrame = GeneralUtility::_GP('reloadListFrame');
96 // Setting pseudo module name
97 $this->MCONF['name'] = 'xMOD_alt_clickmenu.php';
98 // Takes the backPath as a parameter BUT since we are worried about someone forging a backPath (XSS security hole) we will check with sent md5 hash:
99 $inputBP = explode('|', $this->backPath);
100 if (count($inputBP) == 2 && $inputBP[1] == GeneralUtility::shortMD5($inputBP[0] . '|' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'])) {
101 $this->backPath = $inputBP[0];
102 } else {
103 $this->backPath = $GLOBALS['BACK_PATH'];
104 }
105 // Setting internal array of classes for extending the clickmenu:
106 $this->extClassArray = $GLOBALS['TBE_MODULES_EXT']['xMOD_alt_clickmenu']['extendCMclasses'];
107 // Traversing that array and setting files for inclusion:
108 // @deprecated since 6.1, will be removed 2 versions later
109 if (is_array($this->extClassArray)) {
110 foreach ($this->extClassArray as $extClassConf) {
111 if (isset($extClassConf['path'])) {
112 GeneralUtility::deprecationLog(
113 '$GLOBALS[\'TBE_MODULES_EXT\'][\'xMOD_alt_clickmenu\'][\'extendCMclasses\'][\'path\'] option is not needed anymore. The autoloader takes care of loading the class.'
114 );
115 $this->include_once[] = $extClassConf['path'];
116 }
117 }
118 }
119 // Initialize template object
120 if (!$this->ajax) {
121 $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
122 $this->doc->backPath = $GLOBALS['BACK_PATH'];
123 }
124 // Setting mode for display and background image in the top frame
125
126 // Setting clickmenu timeout
127 $secs = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($GLOBALS['BE_USER']->getTSConfigVal('options.contextMenu.options.clickMenuTimeOut'), 1, 100, 5);
128 // default is 5
129 // Setting the JavaScript controlling the timer on the page
130 $listFrameDoc = $this->reloadListFrame != 2 ? 'top.content.list_frame' : 'top.content';
131 $this->doc->JScode .= $this->doc->wrapScriptTags('
132 var date = new Date();
133 var mo_timeout = Math.floor(date.getTime()/1000);
134
135 roImg = "' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconClasses('status-status-current') . '";
136
137 routImg = "t3-icon-empty";
138
139 function mo(c) { //
140 var name="roimg_"+c;
141 document.getElementById(name).className = roImg;
142 updateTime();
143 }
144 function mout(c) { //
145 var name="roimg_"+c;
146 document[name].src = routImg;
147 updateTime();
148 }
149 function updateTime() { //
150 date = new Date();
151 mo_timeout = Math.floor(date.getTime()/1000);
152 }
153 function timeout_func() { //
154 date = new Date();
155 if (Math.floor(date.getTime()/1000)-mo_timeout > ' . $secs . ') {
156 hideCM();
157 return false;
158 } else {
159 window.setTimeout("timeout_func();",1*1000);
160 }
161 }
162 function hideCM() { //
163 window.location.href="alt_topmenu_dummy.php";
164 return false;
165 }
166
167 // Start timer
168 timeout_func();
169
170 ' . ($this->reloadListFrame ? '
171 // Reload list frame:
172 if(' . $listFrameDoc . '){' . $listFrameDoc . '.location.href=' . $listFrameDoc . '.location.href;}' : '') . '
173 ');
174 }
175
176 /**
177 * Main function - generating the click menu in whatever form it has.
178 *
179 * @return void
180 * @todo Define visibility
181 */
182 public function main() {
183 $this->ajax = GeneralUtility::_GP('ajax') ? TRUE : FALSE;
184 // Initialize Clipboard object:
185 $clipObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Clipboard\\Clipboard');
186 $clipObj->initializeClipboard();
187 // This locks the clipboard to the Normal for this request.
188 $clipObj->lockToNormal();
189 // Update clipboard if some actions are sent.
190 $CB = GeneralUtility::_GET('CB');
191 $clipObj->setCmd($CB);
192 $clipObj->cleanCurrent();
193 // Saves
194 $clipObj->endClipboard();
195 // Create clickmenu object
196 $clickMenu = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\ClickMenu\\ClickMenu');
197 // Set internal vars in clickmenu object:
198 $clickMenu->clipObj = $clipObj;
199 $clickMenu->extClassArray = $this->extClassArray;
200 $clickMenu->backPath = $this->backPath;
201 // Start page
202 if (!$this->ajax) {
203 $this->content .= $this->doc->startPage('Context Sensitive Menu');
204 }
205 // Set content of the clickmenu with the incoming var, "item"
206 $this->content .= $clickMenu->init();
207 }
208
209 /**
210 * End page and output content.
211 *
212 * @return void
213 * @todo Define visibility
214 */
215 public function printContent() {
216 if (!$this->ajax) {
217 $this->content .= $this->doc->endPage();
218 $this->content = $this->doc->insertStylesAndJS($this->content);
219 echo $this->content;
220 } else {
221 header('Content-Type: text/xml');
222 echo '<?xml version="1.0"?>' . LF . '<t3ajax>' . $this->content . '</t3ajax>';
223 }
224 }
225
226 }
227
228 ?>