[TASK] Cleanup entry classes in typo3/ part2
[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
87 */
88 public function __construct() {
89 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_misc.xlf');
90 $GLOBALS['SOBE'] = $this;
91
92 $this->init();
93 }
94
95 /**
96 * Constructor function for script class.
97 *
98 * @return void
99 */
100 protected function init() {
101 // Setting GPvars:
102 $this->backPath = GeneralUtility::_GP('backPath');
103 $this->item = GeneralUtility::_GP('item');
104 $this->reloadListFrame = GeneralUtility::_GP('reloadListFrame');
105 // Setting pseudo module name
106 $this->MCONF['name'] = 'xMOD_alt_clickmenu.php';
107 // 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:
108 $inputBP = explode('|', $this->backPath);
109 if (count($inputBP) == 2 && $inputBP[1] == GeneralUtility::shortMD5($inputBP[0] . '|' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'])) {
110 $this->backPath = $inputBP[0];
111 } else {
112 $this->backPath = $GLOBALS['BACK_PATH'];
113 }
114 // Setting internal array of classes for extending the clickmenu:
115 $this->extClassArray = $GLOBALS['TBE_MODULES_EXT']['xMOD_alt_clickmenu']['extendCMclasses'];
116 // Traversing that array and setting files for inclusion:
117 // @deprecated since 6.1, will be removed 2 versions later
118 if (is_array($this->extClassArray)) {
119 foreach ($this->extClassArray as $extClassConf) {
120 if (isset($extClassConf['path'])) {
121 GeneralUtility::deprecationLog(
122 '$GLOBALS[\'TBE_MODULES_EXT\'][\'xMOD_alt_clickmenu\'][\'extendCMclasses\'][\'path\'] option is not needed anymore. The autoloader takes care of loading the class.'
123 );
124 $this->include_once[] = $extClassConf['path'];
125 }
126 }
127 }
128 // Initialize template object
129 if (!$this->ajax) {
130 $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
131 $this->doc->backPath = $GLOBALS['BACK_PATH'];
132 }
133 // Setting mode for display and background image in the top frame
134
135 // Setting clickmenu timeout
136 $secs = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($GLOBALS['BE_USER']->getTSConfigVal('options.contextMenu.options.clickMenuTimeOut'), 1, 100, 5);
137 // default is 5
138 // Setting the JavaScript controlling the timer on the page
139 $listFrameDoc = $this->reloadListFrame != 2 ? 'top.content.list_frame' : 'top.content';
140 $this->doc->JScode .= $this->doc->wrapScriptTags('
141 var date = new Date();
142 var mo_timeout = Math.floor(date.getTime()/1000);
143
144 roImg = "' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconClasses('status-status-current') . '";
145
146 routImg = "t3-icon-empty";
147
148 function mo(c) { //
149 var name="roimg_"+c;
150 document.getElementById(name).className = roImg;
151 updateTime();
152 }
153 function mout(c) { //
154 var name="roimg_"+c;
155 document[name].src = routImg;
156 updateTime();
157 }
158 function updateTime() { //
159 date = new Date();
160 mo_timeout = Math.floor(date.getTime()/1000);
161 }
162 function timeout_func() { //
163 date = new Date();
164 if (Math.floor(date.getTime()/1000)-mo_timeout > ' . $secs . ') {
165 hideCM();
166 return false;
167 } else {
168 window.setTimeout("timeout_func();",1*1000);
169 }
170 }
171 function hideCM() { //
172 window.location.href="alt_topmenu_dummy.php";
173 return false;
174 }
175
176 // Start timer
177 timeout_func();
178
179 ' . ($this->reloadListFrame ? '
180 // Reload list frame:
181 if(' . $listFrameDoc . '){' . $listFrameDoc . '.location.href=' . $listFrameDoc . '.location.href;}' : '') . '
182 ');
183 }
184
185 /**
186 * Main function - generating the click menu in whatever form it has.
187 *
188 * @return void
189 */
190 public function main() {
191 $this->ajax = GeneralUtility::_GP('ajax') ? TRUE : FALSE;
192 // Initialize Clipboard object:
193 $clipObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Clipboard\\Clipboard');
194 $clipObj->initializeClipboard();
195 // This locks the clipboard to the Normal for this request.
196 $clipObj->lockToNormal();
197 // Update clipboard if some actions are sent.
198 $CB = GeneralUtility::_GET('CB');
199 $clipObj->setCmd($CB);
200 $clipObj->cleanCurrent();
201 // Saves
202 $clipObj->endClipboard();
203 // Create clickmenu object
204 $clickMenu = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\ClickMenu\\ClickMenu');
205 // Set internal vars in clickmenu object:
206 $clickMenu->clipObj = $clipObj;
207 $clickMenu->extClassArray = $this->extClassArray;
208 $clickMenu->backPath = $this->backPath;
209 // Start page
210 if (!$this->ajax) {
211 $this->content .= $this->doc->startPage('Context Sensitive Menu');
212 }
213 // Set content of the clickmenu with the incoming var, "item"
214 $this->content .= $clickMenu->init();
215 }
216
217 /**
218 * End page and output content.
219 *
220 * @return void
221 */
222 public function printContent() {
223 if (!$this->ajax) {
224 $this->content .= $this->doc->endPage();
225 $this->content = $this->doc->insertStylesAndJS($this->content);
226 echo $this->content;
227 } else {
228 header('Content-Type: text/xml');
229 echo '<?xml version="1.0"?>' . LF . '<t3ajax>' . $this->content . '</t3ajax>';
230 }
231 }
232
233 }
234
235 ?>