[BUGFIX] Hide version selector if workspaces are used
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Template / DocumentTemplate.php
1 <?php
2 namespace TYPO3\CMS\Backend\Template;
3
4 /**
5 * TYPO3 Backend Template Class
6 *
7 * This class contains functions for starting and ending the HTML of backend modules
8 * It also contains methods for outputting sections of content.
9 * Further there are functions for making icons, links, setting form-field widths etc.
10 * Color scheme and stylesheet definitions are also available here.
11 * Finally this file includes the language class for TYPO3's backend.
12 *
13 * After this file $LANG and $TBE_TEMPLATE are global variables / instances of their respective classes.
14 * This file is typically included right after the init.php file,
15 * if language and layout is needed.
16 *
17 * Please refer to Inside TYPO3 for a discussion of how to use this API.
18 *
19 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
20 */
21 class DocumentTemplate {
22
23 // Vars you typically might want to/should set from outside after making instance of this class:
24 // 'backPath' pointing back to the PATH_typo3
25 /**
26 * @todo Define visibility
27 */
28 public $backPath = '';
29
30 // This can be set to the HTML-code for a formtag. Useful when you need a form to span the whole page; Inserted exactly after the body-tag.
31 /**
32 * @todo Define visibility
33 */
34 public $form = '';
35
36 // Similar to $JScode (see below) but used as an associative array to prevent double inclusion of JS code. This is used to include certain external Javascript libraries before the inline JS code. <script>-Tags are not wrapped around automatically
37 /**
38 * @todo Define visibility
39 */
40 public $JScodeLibArray = array();
41
42 // Additional header code (eg. a JavaScript section) could be accommulated in this var. It will be directly outputted in the header.
43 /**
44 * @todo Define visibility
45 */
46 public $JScode = '';
47
48 // Additional header code for ExtJS. It will be included in document header and inserted in a Ext.onReady(function()
49 /**
50 * @todo Define visibility
51 */
52 public $extJScode = '';
53
54 // Similar to $JScode but for use as array with associative keys to prevent double inclusion of JS code. a <script> tag is automatically wrapped around.
55 /**
56 * @todo Define visibility
57 */
58 public $JScodeArray = array();
59
60 // Additional 'page-end' code could be accommulated in this var. It will be outputted at the end of page before </body> and some other internal page-end code.
61 /**
62 * @todo Define visibility
63 */
64 public $postCode = '';
65
66 // Doc-type used in the header. Default is xhtml_trans. You can also set it to 'html_3', 'xhtml_strict' or 'xhtml_frames'.
67 /**
68 * @todo Define visibility
69 */
70 public $docType = '';
71
72 // HTML template with markers for module
73 /**
74 * @todo Define visibility
75 */
76 public $moduleTemplate = '';
77
78 // the base file (not overlaid by TBE_STYLES) for the current module, useful for hooks when finding out which modules is rendered currently
79 protected $moduleTemplateFilename = '';
80
81 // Other vars you can change, but less frequently used:
82 // Script ID.
83 /**
84 * @todo Define visibility
85 */
86 public $scriptID = '';
87
88 // Id which can be set for the body tag. Default value is based on script ID
89 /**
90 * @todo Define visibility
91 */
92 public $bodyTagId = '';
93
94 // You can add additional attributes to the body-tag through this variable.
95 /**
96 * @todo Define visibility
97 */
98 public $bodyTagAdditions = '';
99
100 // Additional CSS styles which will be added to the <style> section in the header
101 /**
102 * @todo Define visibility
103 */
104 public $inDocStyles = '';
105
106 // Like $inDocStyles but for use as array with associative keys to prevent double inclusion of css code
107 /**
108 * @todo Define visibility
109 */
110 public $inDocStylesArray = array();
111
112 // Multiplication factor for formWidth() input size (default is 48* this value).
113 /**
114 * @todo Define visibility
115 */
116 public $form_rowsToStylewidth = 9.58;
117
118 // Compensation for large documents (used in class.t3lib_tceforms.php)
119 /**
120 * @todo Define visibility
121 */
122 public $form_largeComp = 1.33;
123
124 // If set, then a JavaScript section will be outputted in the bottom of page which will try and update the top.busy session expiry object.
125 /**
126 * @todo Define visibility
127 */
128 public $endJS = 1;
129
130 // TYPO3 Colorscheme.
131 // If you want to change this, please do so through a skin using the global var $GLOBALS['TBE_STYLES']
132 // Light background color
133 /**
134 * @todo Define visibility
135 */
136 public $bgColor = '#F7F3EF';
137
138 // Steel-blue
139 /**
140 * @todo Define visibility
141 */
142 public $bgColor2 = '#9BA1A8';
143
144 // dok.color
145 /**
146 * @todo Define visibility
147 */
148 public $bgColor3 = '#F6F2E6';
149
150 // light tablerow background, brownish
151 /**
152 * @todo Define visibility
153 */
154 public $bgColor4 = '#D9D5C9';
155
156 // light tablerow background, greenish
157 /**
158 * @todo Define visibility
159 */
160 public $bgColor5 = '#ABBBB4';
161
162 // light tablerow background, yellowish, for section headers. Light.
163 /**
164 * @todo Define visibility
165 */
166 public $bgColor6 = '#E7DBA8';
167
168 /**
169 * @todo Define visibility
170 */
171 public $hoverColor = '#254D7B';
172
173 // Filename of stylesheet (relative to PATH_typo3)
174 /**
175 * @todo Define visibility
176 */
177 public $styleSheetFile = '';
178
179 // Filename of stylesheet #2 - linked to right after the $this->styleSheetFile script (relative to PATH_typo3)
180 /**
181 * @todo Define visibility
182 */
183 public $styleSheetFile2 = '';
184
185 // Filename of a post-stylesheet - included right after all inline styles.
186 /**
187 * @todo Define visibility
188 */
189 public $styleSheetFile_post = '';
190
191 // Background image of page (relative to PATH_typo3)
192 /**
193 * @todo Define visibility
194 */
195 public $backGroundImage = '';
196
197 // Inline css styling set from TBE_STYLES array
198 /**
199 * @todo Define visibility
200 */
201 public $inDocStyles_TBEstyle = '';
202
203 /**
204 * Whether to use the X-UA-Compatible meta tag
205 *
206 * @var boolean
207 */
208 protected $useCompatibilityTag = TRUE;
209
210 /**
211 * X-Ua-Compatible version output in meta tag
212 *
213 * @var string
214 */
215 protected $xUaCompatibilityVersion = 'IE=9';
216
217 // Skinning
218 // stylesheets from core
219 protected $stylesheetsCore = array(
220 'structure' => 'stylesheets/structure/',
221 'visual' => 'stylesheets/visual/',
222 'generatedSprites' => '../typo3temp/sprites/'
223 );
224
225 // Include these CSS directories from skins by default
226 protected $stylesheetsSkins = array(
227 'structure' => 'stylesheets/structure/',
228 'visual' => 'stylesheets/visual/'
229 );
230
231 /**
232 * JavaScript files loaded for every page in the Backend
233 *
234 * @var array
235 */
236 protected $jsFiles = array(
237 'modernizr' => 'contrib/modernizr/modernizr.min.js'
238 );
239
240 // DEV:
241 // Will output the parsetime of the scripts in milliseconds (for admin-users). Set this to FALSE when releasing TYPO3. Only for dev.
242 /**
243 * @todo Define visibility
244 */
245 public $parseTimeFlag = 0;
246
247 /**
248 * internal character set, nowadays utf-8 for everything
249 */
250 protected $charset = 'utf-8';
251
252 // Internal: Indicates if a <div>-output section is open
253 /**
254 * @todo Define visibility
255 */
256 public $sectionFlag = 0;
257
258 // (Default) Class for wrapping <DIV>-tag of page. Is set in class extensions.
259 /**
260 * @todo Define visibility
261 */
262 public $divClass = '';
263
264 /**
265 * @todo Define visibility
266 */
267 public $pageHeaderBlock = '';
268
269 /**
270 * @todo Define visibility
271 */
272 public $endOfPageJsBlock = '';
273
274 /**
275 * @todo Define visibility
276 */
277 public $hasDocheader = TRUE;
278
279 /**
280 * @var \TYPO3\CMS\Core\Page\PageRenderer
281 */
282 protected $pageRenderer;
283
284 // Alternative template file
285 protected $pageHeaderFooterTemplateFile = '';
286
287 protected $extDirectStateProvider = FALSE;
288
289 /**
290 * Whether flashmessages should be rendered or not
291 *
292 * @var boolean $showFlashMessages
293 */
294 public $showFlashMessages = TRUE;
295
296 const STATUS_ICON_ERROR = 3;
297 const STATUS_ICON_WARNING = 2;
298 const STATUS_ICON_NOTIFICATION = 1;
299 const STATUS_ICON_OK = -1;
300 /**
301 * Constructor
302 * Imports relevant parts from global $GLOBALS['TBE_STYLES'] (colorscheme)
303 */
304 public function __construct() {
305 // Initializes the page rendering object:
306 $this->getPageRenderer();
307 // Setting default scriptID:
308 if (($temp_M = (string) \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('M')) && $GLOBALS['TBE_MODULES']['_PATHS'][$temp_M]) {
309 $this->scriptID = preg_replace('/^.*\\/(sysext|ext)\\//', 'ext/', $GLOBALS['TBE_MODULES']['_PATHS'][$temp_M] . 'index.php');
310 } else {
311 $this->scriptID = preg_replace('/^.*\\/(sysext|ext)\\//', 'ext/', substr(PATH_thisScript, strlen(PATH_site)));
312 }
313 if (TYPO3_mainDir != 'typo3/' && substr($this->scriptID, 0, strlen(TYPO3_mainDir)) == TYPO3_mainDir) {
314 // This fixes if TYPO3_mainDir has been changed so the script ids are STILL "typo3/..."
315 $this->scriptID = 'typo3/' . substr($this->scriptID, strlen(TYPO3_mainDir));
316 }
317 $this->bodyTagId = preg_replace('/[^A-Za-z0-9-]/', '-', $this->scriptID);
318 // Individual configuration per script? If so, make a recursive merge of the arrays:
319 if (is_array($GLOBALS['TBE_STYLES']['scriptIDindex'][$this->scriptID])) {
320 // Make copy
321 $ovr = $GLOBALS['TBE_STYLES']['scriptIDindex'][$this->scriptID];
322 // merge styles.
323 $GLOBALS['TBE_STYLES'] = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule($GLOBALS['TBE_STYLES'], $ovr);
324 // Have to unset - otherwise the second instantiation will do it again!
325 unset($GLOBALS['TBE_STYLES']['scriptIDindex'][$this->scriptID]);
326 }
327 // Color scheme:
328 if ($GLOBALS['TBE_STYLES']['mainColors']['bgColor']) {
329 $this->bgColor = $GLOBALS['TBE_STYLES']['mainColors']['bgColor'];
330 }
331 if ($GLOBALS['TBE_STYLES']['mainColors']['bgColor1']) {
332 $this->bgColor1 = $GLOBALS['TBE_STYLES']['mainColors']['bgColor1'];
333 }
334 if ($GLOBALS['TBE_STYLES']['mainColors']['bgColor2']) {
335 $this->bgColor2 = $GLOBALS['TBE_STYLES']['mainColors']['bgColor2'];
336 }
337 if ($GLOBALS['TBE_STYLES']['mainColors']['bgColor3']) {
338 $this->bgColor3 = $GLOBALS['TBE_STYLES']['mainColors']['bgColor3'];
339 }
340 if ($GLOBALS['TBE_STYLES']['mainColors']['bgColor4']) {
341 $this->bgColor4 = $GLOBALS['TBE_STYLES']['mainColors']['bgColor4'];
342 }
343 if ($GLOBALS['TBE_STYLES']['mainColors']['bgColor5']) {
344 $this->bgColor5 = $GLOBALS['TBE_STYLES']['mainColors']['bgColor5'];
345 }
346 if ($GLOBALS['TBE_STYLES']['mainColors']['bgColor6']) {
347 $this->bgColor6 = $GLOBALS['TBE_STYLES']['mainColors']['bgColor6'];
348 }
349 if ($GLOBALS['TBE_STYLES']['mainColors']['hoverColor']) {
350 $this->hoverColor = $GLOBALS['TBE_STYLES']['mainColors']['hoverColor'];
351 }
352 // Main Stylesheets:
353 if ($GLOBALS['TBE_STYLES']['stylesheet']) {
354 $this->styleSheetFile = $GLOBALS['TBE_STYLES']['stylesheet'];
355 }
356 if ($GLOBALS['TBE_STYLES']['stylesheet2']) {
357 $this->styleSheetFile2 = $GLOBALS['TBE_STYLES']['stylesheet2'];
358 }
359 if ($GLOBALS['TBE_STYLES']['styleSheetFile_post']) {
360 $this->styleSheetFile_post = $GLOBALS['TBE_STYLES']['styleSheetFile_post'];
361 }
362 if ($GLOBALS['TBE_STYLES']['inDocStyles_TBEstyle']) {
363 $this->inDocStyles_TBEstyle = $GLOBALS['TBE_STYLES']['inDocStyles_TBEstyle'];
364 }
365 // include all stylesheets
366 foreach ($this->getSkinStylesheetDirectories() as $stylesheetDirectory) {
367 $this->addStylesheetDirectory($stylesheetDirectory);
368 }
369 // Background image
370 if ($GLOBALS['TBE_STYLES']['background']) {
371 $this->backGroundImage = $GLOBALS['TBE_STYLES']['background'];
372 }
373 }
374
375 /**
376 * Gets instance of PageRenderer configured with the current language, file references and debug settings
377 *
378 * @return \TYPO3\CMS\Core\Page\PageRenderer
379 */
380 public function getPageRenderer() {
381 if (!isset($this->pageRenderer)) {
382 $this->pageRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Page\\PageRenderer');
383 $this->pageRenderer->setTemplateFile(TYPO3_mainDir . 'templates/template_page_backend.html');
384 $this->pageRenderer->setLanguage($GLOBALS['LANG']->lang);
385 $this->pageRenderer->enableConcatenateFiles();
386 $this->pageRenderer->enableCompressCss();
387 $this->pageRenderer->enableCompressJavascript();
388 // Add all JavaScript files defined in $this->jsFiles to the PageRenderer
389 foreach ($this->jsFiles as $file) {
390 $this->pageRenderer->addJsFile($GLOBALS['BACK_PATH'] . $file);
391 }
392 }
393 if (intval($GLOBALS['TYPO3_CONF_VARS']['BE']['debug']) === 1) {
394 $this->pageRenderer->enableDebugMode();
395 }
396 return $this->pageRenderer;
397 }
398
399 /**
400 * Sets inclusion of StateProvider
401 *
402 * @return void
403 */
404 public function setExtDirectStateProvider() {
405 $this->extDirectStateProvider = TRUE;
406 }
407
408 /*****************************************
409 *
410 * EVALUATION FUNCTIONS
411 * Various centralized processing
412 *
413 *****************************************/
414 /**
415 * Makes click menu link (context sensitive menu)
416 * Returns $str (possibly an <|img> tag/icon) wrapped in a link which will activate the context sensitive menu for the record ($table/$uid) or file ($table = file)
417 * The link will load the top frame with the parameter "&item" which is the table,uid and listFr arguments imploded by "|": rawurlencode($table.'|'.$uid.'|'.$listFr)
418 *
419 * @param string $str String to be wrapped in link, typ. image tag.
420 * @param string $table Table name/File path. If the icon is for a database record, enter the tablename from $GLOBALS['TCA']. If a file then enter the absolute filepath
421 * @param integer $uid If icon is for database record this is the UID for the record from $table
422 * @param boolean $listFr Tells the top frame script that the link is coming from a "list" frame which means a frame from within the backend content frame.
423 * @param string $addParams Additional GET parameters for the link to alt_clickmenu.php
424 * @param string $enDisItems Enable / Disable click menu items. Example: "+new,view" will display ONLY these two items (and any spacers in between), "new,view" will display all BUT these two items.
425 * @param boolean $returnOnClick If set, will return only the onclick JavaScript, not the whole link.
426 * @return string The link-wrapped input string.
427 * @todo Define visibility
428 */
429 public function wrapClickMenuOnIcon($str, $table, $uid = 0, $listFr = TRUE, $addParams = '', $enDisItems = '', $returnOnClick = FALSE) {
430 $backPath = rawurlencode($this->backPath) . '|' . \TYPO3\CMS\Core\Utility\GeneralUtility::shortMD5(($this->backPath . '|' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']));
431 $onClick = 'showClickmenu("' . $table . '","' . ($uid !== 0 ? $uid : '') . '","' . strval($listFr) . '","' . str_replace('+', '%2B', $enDisItems) . '","' . str_replace('&', '&amp;', addcslashes($backPath, '"')) . '","' . str_replace('&', '&amp;', addcslashes($addParams, '"')) . '");return false;';
432 return $returnOnClick ? $onClick : '<a href="#" onclick="' . htmlspecialchars($onClick) . '" oncontextmenu="' . htmlspecialchars($onClick) . '">' . $str . '</a>';
433 }
434
435 /**
436 * Makes link to page $id in frontend (view page)
437 * Returns an magnifier-glass icon which links to the frontend index.php document for viewing the page with id $id
438 * $id must be a page-uid
439 * If the BE_USER has access to Web>List then a link to that module is shown as well (with return-url)
440 *
441 * @param integer $id The page id
442 * @param string $backPath The current "BACK_PATH" (the back relative to the typo3/ directory)
443 * @param string $addParams Additional parameters for the image tag(s)
444 * @return string HTML string with linked icon(s)
445 * @todo Define visibility
446 */
447 public function viewPageIcon($id, $backPath, $addParams = 'hspace="3"') {
448 // If access to Web>List for user, then link to that module.
449 $str = \TYPO3\CMS\Backend\Utility\BackendUtility::getListViewLink(array(
450 'id' => $id,
451 'returnUrl' => \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI')
452 ), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showList'));
453 // Make link to view page
454 $str .= '<a href="#" onclick="' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::viewOnClick($id, $backPath, \TYPO3\CMS\Backend\Utility\BackendUtility::BEgetRootLine($id))) . '">' . '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($backPath, 'gfx/zoom.gif', 'width="12" height="12"') . ' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showPage', 1) . '"' . ($addParams ? ' ' . trim($addParams) : '') . ' hspace="3" alt="" />' . '</a>';
455 return $str;
456 }
457
458 /**
459 * Returns a URL with a command to TYPO3 Core Engine (tce_db.php)
460 * See description of the API elsewhere.
461 *
462 * @param string $params is a set of GET params to send to tce_db.php. Example: "&cmd[tt_content][123][move]=456" or "&data[tt_content][123][hidden]=1&data[tt_content][123][title]=Hello%20World
463 * @param string $redirectUrl Redirect URL if any other that t3lib_div::getIndpEnv('REQUEST_URI') is wished
464 * @return string URL to tce_db.php + parameters (backpath is taken from $this->backPath)
465 * @see t3lib_BEfunc::editOnClick()
466 * @todo Define visibility
467 */
468 public function issueCommand($params, $redirectUrl = '') {
469 $redirectUrl = $redirectUrl ? $redirectUrl : \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI');
470 $commandUrl = $this->backPath . 'tce_db.php?' . $params . '&redirect=' . ($redirectUrl == -1 ? '\'+T3_THIS_LOCATION+\'' : rawurlencode($redirectUrl)) . '&vC=' . rawurlencode($GLOBALS['BE_USER']->veriCode()) . \TYPO3\CMS\Backend\Utility\BackendUtility::getUrlToken('tceAction') . '&prErr=1&uPT=1';
471 return $commandUrl;
472 }
473
474 /**
475 * Returns TRUE if click-menu layers can be displayed for the current user/browser
476 * Use this to test if click-menus (context sensitive menus) can and should be displayed in the backend.
477 *
478 * @return boolean
479 * @deprecated since TYPO3 4.7, will be removed in TYPO3 6.1 - This function makes no sense anymore
480 * @todo Define visibility
481 */
482 public function isCMlayers() {
483 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
484 return !$GLOBALS['BE_USER']->uc['disableCMlayers'] && $GLOBALS['CLIENT']['FORMSTYLE'] && !($GLOBALS['CLIENT']['SYSTEM'] == 'mac' && $GLOBALS['CLIENT']['BROWSER'] == 'Opera');
485 }
486
487 /**
488 * Makes the header (icon+title) for a page (or other record). Used in most modules under Web>*
489 * $table and $row must be a tablename/record from that table
490 * $path will be shown as alt-text for the icon.
491 * The title will be truncated to 45 chars.
492 *
493 * @param string $table Table name
494 * @param array $row Record row
495 * @param string $path Alt text
496 * @param boolean $noViewPageIcon Set $noViewPageIcon TRUE if you don't want a magnifier-icon for viewing the page in the frontend
497 * @param array $tWrap is an array with indexes 0 and 1 each representing HTML-tags (start/end) which will wrap the title
498 * @return string HTML content
499 * @todo Define visibility
500 */
501 public function getHeader($table, $row, $path, $noViewPageIcon = FALSE, $tWrap = array('', '')) {
502 $viewPage = '';
503 if (is_array($row) && $row['uid']) {
504 $iconImgTag = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord($table, $row, array('title' => htmlspecialchars($path)));
505 $title = strip_tags(\TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle($table, $row));
506 $viewPage = $noViewPageIcon ? '' : $this->viewPageIcon($row['uid'], $this->backPath, '');
507 if ($table == 'pages') {
508 $path .= ' - ' . \TYPO3\CMS\Backend\Utility\BackendUtility::titleAttribForPages($row, '', 0);
509 }
510 } else {
511 $iconImgTag = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-pagetree-page-domain', array('title' => htmlspecialchars($path)));
512 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
513 }
514 return '<span class="typo3-moduleHeader">' . $this->wrapClickMenuOnIcon($iconImgTag, $table, $row['uid']) . $viewPage . $tWrap[0] . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($title, 45)) . $tWrap[1] . '</span>';
515 }
516
517 /**
518 * Like ->getHeader() but for files in the File>* main module/submodules
519 * Returns the file-icon with the path of the file set in the alt/title attribute. Shows the file-name after the icon.
520 *
521 * @param string $title Title string, expected to be the filepath
522 * @param string $path Alt text
523 * @param string $iconfile The icon file (relative to TYPO3 dir)
524 * @return string HTML content
525 * @todo Define visibility
526 */
527 public function getFileheader($title, $path, $iconfile) {
528 $fileInfo = \TYPO3\CMS\Core\Utility\GeneralUtility::split_fileref($title);
529 $title = htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($fileInfo['path'], -35)) . '<strong>' . htmlspecialchars($fileInfo['file']) . '</strong>';
530 return '<span class="typo3-moduleHeader"><img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($this->backPath, $iconfile, 'width="18" height="16"') . ' title="' . htmlspecialchars($path) . '" alt="" />' . $title . '</span>';
531 }
532
533 /**
534 * Returns a linked shortcut-icon which will call the shortcut frame and set a shortcut there back to the calling page/module
535 *
536 * @param string $gvList Is the list of GET variables to store (if any)
537 * @param string $setList Is the list of SET[] variables to store (if any) - SET[] variables a stored in $GLOBALS["SOBE"]->MOD_SETTINGS for backend modules
538 * @param string $modName Module name string
539 * @param string $motherModName Is used to enter the "parent module name" if the module is a submodule under eg. Web>* or File>*. You can also set this value to "1" in which case the currentLoadedModule is sent to the shortcut script (so - not a fixed value!) - that is used in file_edit.php and wizard_rte.php scripts where those scripts are really running as a part of another module.
540 * @return string HTML content
541 * @todo Define visibility
542 */
543 public function makeShortcutIcon($gvList, $setList, $modName, $motherModName = '') {
544 $backPath = $this->backPath;
545 $storeUrl = $this->makeShortcutUrl($gvList, $setList);
546 $pathInfo = parse_url(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'));
547 // Add the module identifier automatically if typo3/mod.php is used:
548 if (preg_match('/typo3\\/mod\\.php$/', $pathInfo['path']) && isset($GLOBALS['TBE_MODULES']['_PATHS'][$modName])) {
549 $storeUrl = '&M=' . $modName . $storeUrl;
550 }
551 if (!strcmp($motherModName, '1')) {
552 $mMN = '&motherModName=\'+top.currentModuleLoaded+\'';
553 } elseif ($motherModName) {
554 $mMN = '&motherModName=' . rawurlencode($motherModName);
555 } else {
556 $mMN = '';
557 }
558 $onClick = 'top.ShortcutManager.createShortcut(' . $GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.makeBookmark')) . ', ' . '\'' . $backPath . '\', ' . '\'' . rawurlencode($modName) . '\', ' . '\'' . rawurlencode(($pathInfo['path'] . '?' . $storeUrl)) . $mMN . '\'' . ');return false;';
559 $sIcon = '<a href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.makeBookmark', TRUE) . '">' . \t3lib_iconworks::getSpriteIcon('actions-system-shortcut-new') . '</a>';
560 return $sIcon;
561 }
562
563 /**
564 * MAKE url for storing
565 * Internal func
566 *
567 * @param string $gvList Is the list of GET variables to store (if any)
568 * @param string $setList Is the list of SET[] variables to store (if any) - SET[] variables a stored in $GLOBALS["SOBE"]->MOD_SETTINGS for backend modules
569 * @return string
570 * @access private
571 * @see makeShortcutIcon()
572 * @todo Define visibility
573 */
574 public function makeShortcutUrl($gvList, $setList) {
575 $GET = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET();
576 $storeArray = array_merge(\TYPO3\CMS\Core\Utility\GeneralUtility::compileSelectedGetVarsFromArray($gvList, $GET), array('SET' => \TYPO3\CMS\Core\Utility\GeneralUtility::compileSelectedGetVarsFromArray($setList, (array) $GLOBALS['SOBE']->MOD_SETTINGS)));
577 $storeUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl('', $storeArray);
578 return $storeUrl;
579 }
580
581 /**
582 * Returns <input> attributes to set the width of an text-type input field.
583 * For client browsers with no CSS support the cols/size attribute is returned.
584 * For CSS compliant browsers (recommended) a ' style="width: ...px;"' is returned.
585 *
586 * @param integer $size A relative number which multiplied with approx. 10 will lead to the width in pixels
587 * @param boolean $textarea A flag you can set for textareas - DEPRECATED, use ->formWidthText() for textareas!!!
588 * @param string $styleOverride A string which will be returned as attribute-value for style="" instead of the calculated width (if CSS is enabled)
589 * @return string Tag attributes for an <input> tag (regarding width)
590 * @see formWidthText()
591 * @todo Define visibility
592 */
593 public function formWidth($size = 48, $textarea = FALSE, $styleOverride = '') {
594 $wAttrib = $textarea ? 'cols' : 'size';
595 // If not setting the width by style-attribute
596 if (!$GLOBALS['CLIENT']['FORMSTYLE']) {
597 $retVal = ' ' . $wAttrib . '="' . $size . '"';
598 } else {
599 // Setting width by style-attribute. 'cols' MUST be avoided with NN6+
600 $pixels = ceil($size * $this->form_rowsToStylewidth);
601 $retVal = $styleOverride ? ' style="' . $styleOverride . '"' : ' style="width:' . $pixels . 'px;"';
602 }
603 return $retVal;
604 }
605
606 /**
607 * This function is dedicated to textareas, which has the wrapping on/off option to observe.
608 * EXAMPLE:
609 * <textarea rows="10" wrap="off" '.$GLOBALS["TBE_TEMPLATE"]->formWidthText(48, "", "off").'>
610 * or
611 * <textarea rows="10" wrap="virtual" '.$GLOBALS["TBE_TEMPLATE"]->formWidthText(48, "", "virtual").'>
612 *
613 * @param integer $size A relative number which multiplied with approx. 10 will lead to the width in pixels
614 * @param string $styleOverride A string which will be returned as attribute-value for style="" instead of the calculated width (if CSS is enabled)
615 * @param string $wrap Pass on the wrap-attribute value you use in your <textarea>! This will be used to make sure that some browsers will detect wrapping alright.
616 * @return string Tag attributes for an <input> tag (regarding width)
617 * @see formWidth()
618 * @todo Define visibility
619 */
620 public function formWidthText($size = 48, $styleOverride = '', $wrap = '') {
621 $wTags = $this->formWidth($size, 1, $styleOverride);
622 // Netscape 6+/Mozilla seems to have this ODD problem where there WILL ALWAYS be wrapping with the cols-attribute set and NEVER without the col-attribute...
623 if (strtolower(trim($wrap)) != 'off' && $GLOBALS['CLIENT']['BROWSER'] == 'net' && $GLOBALS['CLIENT']['VERSION'] >= 5) {
624 $wTags .= ' cols="' . $size . '"';
625 }
626 return $wTags;
627 }
628
629 /**
630 * Returns JavaScript variables setting the returnUrl and thisScript location for use by JavaScript on the page.
631 * Used in fx. db_list.php (Web>List)
632 *
633 * @param string $thisLocation URL to "this location" / current script
634 * @return string Urls are returned as JavaScript variables T3_RETURN_URL and T3_THIS_LOCATION
635 * @see typo3/db_list.php
636 * @todo Define visibility
637 */
638 public function redirectUrls($thisLocation = '') {
639 $thisLocation = $thisLocation ? $thisLocation : \TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array(
640 'CB' => '',
641 'SET' => '',
642 'cmd' => '',
643 'popViewId' => ''
644 ));
645 $out = '
646 var T3_RETURN_URL = \'' . str_replace('%20', '', rawurlencode(\TYPO3\CMS\Core\Utility\GeneralUtility::sanitizeLocalUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('returnUrl')))) . '\';
647 var T3_THIS_LOCATION = \'' . str_replace('%20', '', rawurlencode($thisLocation)) . '\';
648 ';
649 return $out;
650 }
651
652 /**
653 * Returns a formatted string of $tstamp
654 * Uses $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'] and $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] to format date and time
655 *
656 * @param integer $tstamp UNIX timestamp, seconds since 1970
657 * @param integer $type How much data to show: $type = 1: hhmm, $type = 10: ddmmmyy
658 * @return string Formatted timestamp
659 * @todo Define visibility
660 */
661 public function formatTime($tstamp, $type) {
662 $dateStr = '';
663 switch ($type) {
664 case 1:
665 $dateStr = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], $tstamp);
666 break;
667 case 10:
668 $dateStr = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $tstamp);
669 break;
670 }
671 return $dateStr;
672 }
673
674 /**
675 * Returns script parsetime IF ->parseTimeFlag is set and user is "admin"
676 * Automatically outputted in page end
677 *
678 * @return string HTML formated with <p>-tags
679 * @todo Define visibility
680 */
681 public function parseTime() {
682 if ($this->parseTimeFlag && $GLOBALS['BE_USER']->isAdmin()) {
683 return '<p>(ParseTime: ' . (\TYPO3\CMS\Core\Utility\GeneralUtility::milliseconds() - $GLOBALS['PARSETIME_START']) . ' ms</p>
684 <p>REQUEST_URI-length: ' . strlen(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI')) . ')</p>';
685 }
686 }
687
688 /**
689 * Defines whether to use the X-UA-Compatible meta tag.
690 *
691 * @param boolean $useCompatibilityTag Whether to use the tag
692 * @return void
693 */
694 public function useCompatibilityTag($useCompatibilityTag = TRUE) {
695 $this->useCompatibilityTag = (bool) $useCompatibilityTag;
696 }
697
698 /*****************************************
699 *
700 * PAGE BUILDING FUNCTIONS.
701 * Use this to build the HTML of your backend modules
702 *
703 *****************************************/
704 /**
705 * Returns page start
706 * This includes the proper header with charset, title, meta tag and beginning body-tag.
707 *
708 * @param string $title HTML Page title for the header
709 * @param boolean $includeCsh flag for including CSH
710 * @return string Returns the whole header section of a HTML-document based on settings in internal variables (like styles, javascript code, charset, generator and docType)
711 * @see endPage()
712 * @todo Define visibility
713 */
714 public function startPage($title, $includeCsh = TRUE) {
715 // hook pre start page
716 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['preStartPageHook'])) {
717 $preStartPageHook = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['preStartPageHook'];
718 if (is_array($preStartPageHook)) {
719 $hookParameters = array(
720 'title' => &$title
721 );
722 foreach ($preStartPageHook as $hookFunction) {
723 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
724 }
725 }
726 }
727 $this->pageRenderer->backPath = $this->backPath;
728 // alternative template for Header and Footer
729 if ($this->pageHeaderFooterTemplateFile) {
730 $file = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($this->pageHeaderFooterTemplateFile, TRUE);
731 if ($file) {
732 $this->pageRenderer->setTemplateFile($file);
733 }
734 }
735 // Send HTTP header for selected charset. Added by Robert Lemke 23.10.2003
736 header('Content-Type:text/html;charset=' . $this->charset);
737 // Standard HTML tag
738 $htmlTag = '<html xmlns="http://www.w3.org/1999/xhtml">';
739 switch ($this->docType) {
740 case 'html_3':
741 $headerStart = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">';
742 $htmlTag = '<html>';
743 // Disable rendering of XHTML tags
744 $this->getPageRenderer()->setRenderXhtml(FALSE);
745 break;
746 case 'xhtml_strict':
747 $headerStart = '<!DOCTYPE html
748 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
749 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
750 break;
751 case 'xhtml_frames':
752 $headerStart = '<!DOCTYPE html
753 PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
754 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">';
755 break;
756 case 'xhtml_trans':
757 $headerStart = '<!DOCTYPE html
758 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
759 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
760 break;
761 case 'html5':
762
763 default:
764 // The fallthrough is intended as HTML5, as this is the default for the BE since TYPO3 4.5
765 $headerStart = '<!DOCTYPE html>' . LF;
766 $htmlTag = '<html>';
767 // Disable rendering of XHTML tags
768 $this->getPageRenderer()->setRenderXhtml(FALSE);
769 break;
770 }
771 $this->pageRenderer->setHtmlTag($htmlTag);
772 // This loads the tabulator-in-textarea feature. It automatically modifies
773 // every textarea which is found.
774 if (!$GLOBALS['BE_USER']->uc['disableTabInTextarea']) {
775 $this->loadJavascriptLib('tab.js');
776 }
777 // Include the JS for the Context Sensitive Help
778 if ($includeCsh) {
779 $this->loadCshJavascript();
780 }
781 // Get the browser info
782 $browserInfo = \TYPO3\CMS\Core\Utility\ClientUtility::getBrowserInfo(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_USER_AGENT'));
783 // Set the XML prologue
784 $xmlPrologue = '<?xml version="1.0" encoding="' . $this->charset . '"?>';
785 // Set the XML stylesheet
786 $xmlStylesheet = '<?xml-stylesheet href="#internalStyle" type="text/css"?>';
787 // Add the XML prologue for XHTML doctypes
788 if (strpos($this->docType, 'xhtml') !== FALSE) {
789 // Put the XML prologue before or after the doctype declaration according to browser
790 if ($browserInfo['browser'] === 'msie' && $browserInfo['version'] < 7) {
791 $headerStart = $headerStart . LF . $xmlPrologue;
792 } else {
793 $headerStart = $xmlPrologue . LF . $headerStart;
794 }
795 // Add the xml stylesheet according to doctype
796 if ($this->docType !== 'xhtml_frames') {
797 $headerStart = $headerStart . LF . $xmlStylesheet;
798 }
799 }
800 $this->pageRenderer->setXmlPrologAndDocType($headerStart);
801 $this->pageRenderer->setHeadTag('<head>' . LF . '<!-- TYPO3 Script ID: ' . htmlspecialchars($this->scriptID) . ' -->');
802 $this->pageRenderer->setCharSet($this->charset);
803 $this->pageRenderer->addMetaTag($this->generator());
804 $this->pageRenderer->addMetaTag('<meta name="robots" content="noindex,follow" />');
805 $this->pageRenderer->setFavIcon($this->getBackendFavicon());
806 if ($this->useCompatibilityTag) {
807 $this->pageRenderer->addMetaTag($this->xUaCompatible($this->xUaCompatibilityVersion));
808 }
809 $this->pageRenderer->setTitle($title);
810 // add docstyles
811 $this->docStyle();
812 if ($this->extDirectStateProvider) {
813 $this->pageRenderer->addJsFile($this->backPath . '../t3lib/js/extjs/ExtDirect.StateProvider.js');
814 }
815 // Add jsCode for overriding the console with a debug panel connection
816 $this->pageRenderer->addJsInlineCode('consoleOverrideWithDebugPanel', 'if (typeof top.Ext === "object") {
817 top.Ext.onReady(function() {
818 if (typeof console === "undefined") {
819 if (top && top.TYPO3 && top.TYPO3.Backend && top.TYPO3.Backend.DebugConsole) {
820 console = top.TYPO3.Backend.DebugConsole;
821 } else {
822 console = {
823 log: Ext.log,
824 info: Ext.log,
825 warn: Ext.log,
826 error: Ext.log
827 };
828 }
829 }
830 });
831 }
832 ', FALSE);
833 $this->pageRenderer->addHeaderData($this->JScode);
834 foreach ($this->JScodeArray as $name => $code) {
835 $this->pageRenderer->addJsInlineCode($name, $code, FALSE);
836 }
837 if (count($this->JScodeLibArray)) {
838 foreach ($this->JScodeLibArray as $library) {
839 $this->pageRenderer->addHeaderData($library);
840 }
841 }
842 if ($this->extJScode) {
843 $this->pageRenderer->addExtOnReadyCode($this->extJScode);
844 }
845 // hook for additional headerData
846 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['preHeaderRenderHook'])) {
847 $preHeaderRenderHook = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['preHeaderRenderHook'];
848 if (is_array($preHeaderRenderHook)) {
849 $hookParameters = array(
850 'pageRenderer' => &$this->pageRenderer
851 );
852 foreach ($preHeaderRenderHook as $hookFunction) {
853 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
854 }
855 }
856 }
857 // Construct page header.
858 $str = $this->pageRenderer->render(\TYPO3\CMS\Core\Page\PageRenderer::PART_HEADER);
859 $this->JScodeLibArray = array();
860 $this->JScode = ($this->extJScode = '');
861 $this->JScodeArray = array();
862 $this->endOfPageJsBlock = $this->pageRenderer->render(\TYPO3\CMS\Core\Page\PageRenderer::PART_FOOTER);
863 if ($this->docType == 'xhtml_frames') {
864 return $str;
865 } else {
866 $str .= $this->docBodyTagBegin() . ($this->divClass ? '
867
868 <!-- Wrapping DIV-section for whole page BEGIN -->
869 <div class="' . $this->divClass . '">
870 ' : '') . trim($this->form);
871 }
872 return $str;
873 }
874
875 /**
876 * Returns page end; This includes finishing form, div, body and html tags.
877 *
878 * @return string The HTML end of a page
879 * @see startPage()
880 * @todo Define visibility
881 */
882 public function endPage() {
883 $str = $this->sectionEnd() . $this->postCode . $this->endPageJS() . $this->wrapScriptTags(\TYPO3\CMS\Backend\Utility\BackendUtility::getUpdateSignalCode()) . $this->parseTime() . ($this->form ? '
884 </form>' : '');
885 // If something is in buffer like debug, put it to end of page
886 if (ob_get_contents()) {
887 $str .= ob_get_clean();
888 if (!headers_sent()) {
889 header('Content-Encoding: None');
890 }
891 }
892 if ($this->docType !== 'xhtml_frames') {
893 $str .= ($this->divClass ? '
894
895 <!-- Wrapping DIV-section for whole page END -->
896 </div>' : '') . $this->endOfPageJsBlock;
897 }
898 // Logging: Can't find better place to put it:
899 if (TYPO3_DLOG) {
900 \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('END of BACKEND session', 'TYPO3\\CMS\\Backend\\Template\\DocumentTemplate', 0, array('_FLUSH' => TRUE));
901 }
902 return $str;
903 }
904
905 /**
906 * Shortcut for render the complete page of a module
907 *
908 * @param string $title page title
909 * @param string $content page content
910 * @param boolean $includeCsh flag for including csh code
911 * @return string complete page
912 */
913 public function render($title, $content, $includeCsh = TRUE) {
914 $pageContent = $this->startPage($title, $includeCsh);
915 $pageContent .= $content;
916 $pageContent .= $this->endPage();
917 return $this->insertStylesAndJS($pageContent);
918 }
919
920 /**
921 * Returns the header-bar in the top of most backend modules
922 * Closes section if open.
923 *
924 * @param string $text The text string for the header
925 * @return string HTML content
926 * @todo Define visibility
927 */
928 public function header($text) {
929 $str = '
930
931 <!-- MAIN Header in page top -->
932 <h2>' . htmlspecialchars($text) . '</h2>
933 ';
934 return $this->sectionEnd() . $str;
935 }
936
937 /**
938 * Begins an output section and sets header and content
939 *
940 * @param string $label The header
941 * @param string $text The HTML-content
942 * @param boolean $nostrtoupper A flag that will prevent the header from being converted to uppercase
943 * @param boolean $sH Defines the type of header (if set, "<h3>" rather than the default "h4")
944 * @param integer $type The number of an icon to show with the header (see the icon-function). -1,1,2,3
945 * @param boolean $allowHTMLinHeader If set, HTML tags are allowed in $label (otherwise this value is by default htmlspecialchars()'ed)
946 * @return string HTML content
947 * @see icons(), sectionHeader()
948 * @todo Define visibility
949 */
950 public function section($label, $text, $nostrtoupper = FALSE, $sH = FALSE, $type = 0, $allowHTMLinHeader = FALSE) {
951 $str = '';
952 // Setting header
953 if ($label) {
954 if (!$allowHTMLinHeader) {
955 $label = htmlspecialchars($label);
956 }
957 $str .= $this->sectionHeader($this->icons($type) . $label, $sH, $nostrtoupper ? '' : ' class="uppercase"');
958 }
959 // Setting content
960 $str .= '
961
962 <!-- Section content -->
963 ' . $text;
964 return $this->sectionBegin() . $str;
965 }
966
967 /**
968 * Inserts a divider image
969 * Ends a section (if open) before inserting the image
970 *
971 * @param integer $dist The margin-top/-bottom of the <hr> ruler.
972 * @return string HTML content
973 * @todo Define visibility
974 */
975 public function divider($dist) {
976 $dist = intval($dist);
977 $str = '
978
979 <!-- DIVIDER -->
980 <hr style="margin-top: ' . $dist . 'px; margin-bottom: ' . $dist . 'px;" />
981 ';
982 return $this->sectionEnd() . $str;
983 }
984
985 /**
986 * Returns a blank <div>-section with a height
987 *
988 * @param integer $dist Padding-top for the div-section (should be margin-top but konqueror (3.1) doesn't like it :-(
989 * @return string HTML content
990 * @todo Define visibility
991 */
992 public function spacer($dist) {
993 if ($dist > 0) {
994 return '
995
996 <!-- Spacer element -->
997 <div style="padding-top: ' . intval($dist) . 'px;"></div>
998 ';
999 }
1000 }
1001
1002 /**
1003 * Make a section header.
1004 * Begins a section if not already open.
1005 *
1006 * @param string $label The label between the <h3> or <h4> tags. (Allows HTML)
1007 * @param boolean $sH If set, <h3> is used, otherwise <h4>
1008 * @param string $addAttrib Additional attributes to h-tag, eg. ' class=""'
1009 * @return string HTML content
1010 * @todo Define visibility
1011 */
1012 public function sectionHeader($label, $sH = FALSE, $addAttrib = '') {
1013 $tag = $sH ? 'h3' : 'h4';
1014 if ($addAttrib && substr($addAttrib, 0, 1) !== ' ') {
1015 $addAttrib = ' ' . $addAttrib;
1016 }
1017 $str = '
1018
1019 <!-- Section header -->
1020 <' . $tag . $addAttrib . '>' . $label . '</' . $tag . '>
1021 ';
1022 return $this->sectionBegin() . $str;
1023 }
1024
1025 /**
1026 * Begins an output section.
1027 * Returns the <div>-begin tag AND sets the ->sectionFlag TRUE (if the ->sectionFlag is not already set!)
1028 * You can call this function even if a section is already begun since the function will only return something if the sectionFlag is not already set!
1029 *
1030 * @return string HTML content
1031 * @todo Define visibility
1032 */
1033 public function sectionBegin() {
1034 if (!$this->sectionFlag) {
1035 $this->sectionFlag = 1;
1036 $str = '
1037
1038 <!-- ***********************
1039 Begin output section.
1040 *********************** -->
1041 <div>
1042 ';
1043 return $str;
1044 } else {
1045 return '';
1046 }
1047 }
1048
1049 /**
1050 * Ends and output section
1051 * Returns the </div>-end tag AND clears the ->sectionFlag (but does so only IF the sectionFlag is set - that is a section is 'open')
1052 * See sectionBegin() also.
1053 *
1054 * @return string HTML content
1055 * @todo Define visibility
1056 */
1057 public function sectionEnd() {
1058 if ($this->sectionFlag) {
1059 $this->sectionFlag = 0;
1060 return '
1061 </div>
1062 <!-- *********************
1063 End output section.
1064 ********************* -->
1065 ';
1066 } else {
1067 return '';
1068 }
1069 }
1070
1071 /**
1072 * If a form-tag is defined in ->form then and end-tag for that <form> element is outputted
1073 * Further a JavaScript section is outputted which will update the top.busy session-expiry object (unless $this->endJS is set to FALSE)
1074 *
1075 * @return string HTML content (<script> tag section)
1076 * @todo Define visibility
1077 */
1078 public function endPageJS() {
1079 return $this->endJS ? '
1080 <script type="text/javascript">
1081 /*<![CDATA[*/
1082 if (top.busy && top.busy.loginRefreshed) {
1083 top.busy.loginRefreshed();
1084 }
1085 /*]]>*/
1086 </script>' : '';
1087 }
1088
1089 /**
1090 * Creates the bodyTag.
1091 * You can add to the bodyTag by $this->bodyTagAdditions
1092 *
1093 * @return string HTML body tag
1094 * @todo Define visibility
1095 */
1096 public function docBodyTagBegin() {
1097 $bodyContent = 'body onclick="if (top.menuReset) top.menuReset();" ' . trim(($this->bodyTagAdditions . ($this->bodyTagId ? ' id="' . $this->bodyTagId . '"' : '')));
1098 return '<' . trim($bodyContent) . '>';
1099 }
1100
1101 /**
1102 * Outputting document style
1103 *
1104 * @return string HTML style section/link tags
1105 * @todo Define visibility
1106 */
1107 public function docStyle() {
1108 // Request background image:
1109 if ($this->backGroundImage) {
1110 $this->inDocStylesArray[] = ' BODY { background-image: url(' . $this->backPath . $this->backGroundImage . '); }';
1111 }
1112 // Add inDoc styles variables as well:
1113 $this->inDocStylesArray[] = $this->inDocStyles;
1114 $this->inDocStylesArray[] = $this->inDocStyles_TBEstyle;
1115 // Implode it all:
1116 $inDocStyles = implode(LF, $this->inDocStylesArray);
1117 if ($this->styleSheetFile) {
1118 $this->pageRenderer->addCssFile($this->backPath . $this->styleSheetFile);
1119 }
1120 if ($this->styleSheetFile2) {
1121 $this->pageRenderer->addCssFile($this->backPath . $this->styleSheetFile2);
1122 }
1123 $this->pageRenderer->addCssInlineBlock('inDocStyles', $inDocStyles . LF . '/*###POSTCSSMARKER###*/');
1124 if ($this->styleSheetFile_post) {
1125 $this->pageRenderer->addCssFile($this->backPath . $this->styleSheetFile_post);
1126 }
1127 }
1128
1129 /**
1130 * Insert additional style sheet link
1131 *
1132 * @param string $key some key identifying the style sheet
1133 * @param string $href uri to the style sheet file
1134 * @param string $title value for the title attribute of the link element
1135 * @param string $relation value for the rel attribute of the link element
1136 * @return void
1137 * @todo Define visibility
1138 */
1139 public function addStyleSheet($key, $href, $title = '', $relation = 'stylesheet') {
1140 if (strpos($href, '://') !== FALSE || substr($href, 0, 1) === '/') {
1141 $file = $href;
1142 } else {
1143 $file = $this->backPath . $href;
1144 }
1145 $this->pageRenderer->addCssFile($file, $relation, 'screen', $title);
1146 }
1147
1148 /**
1149 * Add all *.css files of the directory $path to the stylesheets
1150 *
1151 * @param string $path directory to add
1152 * @return void
1153 * @todo Define visibility
1154 */
1155 public function addStyleSheetDirectory($path) {
1156 // Calculation needed, when TYPO3 source is used via a symlink
1157 // absolute path to the stylesheets
1158 $filePath = dirname(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('SCRIPT_FILENAME')) . '/' . $GLOBALS['BACK_PATH'] . $path;
1159 // Clean the path
1160 $resolvedPath = \TYPO3\CMS\Core\Utility\GeneralUtility::resolveBackPath($filePath);
1161 // Read all files in directory and sort them alphabetically
1162 $files = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($resolvedPath, 'css', FALSE, 1);
1163 foreach ($files as $file) {
1164 $this->pageRenderer->addCssFile($GLOBALS['BACK_PATH'] . $path . $file, 'stylesheet', 'all');
1165 }
1166 }
1167
1168 /**
1169 * Insert post rendering document style into already rendered content
1170 * This is needed for extobjbase
1171 *
1172 * @param string $content style-content to insert.
1173 * @return string content with inserted styles
1174 * @todo Define visibility
1175 */
1176 public function insertStylesAndJS($content) {
1177 // Insert accumulated CSS
1178 $this->inDocStylesArray[] = $this->inDocStyles;
1179 $styles = LF . implode(LF, $this->inDocStylesArray);
1180 $content = str_replace('/*###POSTCSSMARKER###*/', $styles, $content);
1181 // Insert accumulated JS
1182 $jscode = $this->JScode . LF . $this->wrapScriptTags(implode(LF, $this->JScodeArray));
1183 $content = str_replace('<!--###POSTJSMARKER###-->', $jscode, $content);
1184 return $content;
1185 }
1186
1187 /**
1188 * Returns an array of all stylesheet directories belonging to core and skins
1189 *
1190 * @return array Stylesheet directories
1191 */
1192 public function getSkinStylesheetDirectories() {
1193 $stylesheetDirectories = array();
1194 // Add default core stylesheets
1195 foreach ($this->stylesheetsCore as $stylesheetDir) {
1196 $stylesheetDirectories[] = $stylesheetDir;
1197 }
1198 // Stylesheets from skins
1199 // merge default css directories ($this->stylesheetsSkin) with additional ones and include them
1200 if (is_array($GLOBALS['TBE_STYLES']['skins'])) {
1201 // loop over all registered skins
1202 foreach ($GLOBALS['TBE_STYLES']['skins'] as $skinExtKey => $skin) {
1203 $skinStylesheetDirs = $this->stylesheetsSkins;
1204 // Skins can add custom stylesheetDirectories using
1205 // $GLOBALS['TBE_STYLES']['skins'][$_EXTKEY]['stylesheetDirectories']
1206 if (is_array($skin['stylesheetDirectories'])) {
1207 $skinStylesheetDirs = array_merge($skinStylesheetDirs, $skin['stylesheetDirectories']);
1208 }
1209 // Add all registered directories
1210 foreach ($skinStylesheetDirs as $stylesheetDir) {
1211 // for EXT:myskin/stylesheets/ syntax
1212 if (substr($stylesheetDir, 0, 4) === 'EXT:') {
1213 list($extKey, $path) = explode('/', substr($stylesheetDir, 4), 2);
1214 if (strcmp($extKey, '') && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extKey) && strcmp($path, '')) {
1215 $stylesheetDirectories[] = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($extKey) . $path;
1216 }
1217 } else {
1218 // For relative paths
1219 $stylesheetDirectories[] = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($skinExtKey) . $stylesheetDir;
1220 }
1221 }
1222 }
1223 }
1224 return $stylesheetDirectories;
1225 }
1226
1227 /**
1228 * Initialize the charset.
1229 * Sets the internal $this->charset variable to the charset defined in $GLOBALS["LANG"] (or the default as set in this class)
1230 * Returns the meta-tag for the document header
1231 *
1232 * @return string <meta> tag with charset from $this->charset or $GLOBALS['LANG']->charSet
1233 * @todo Define visibility
1234 * @deprecated since TYPO3 6.0, remove in 6.2. The charset is utf-8 all the time for the backend now
1235 */
1236 public function initCharset() {
1237 \TYPO3\CMS\Core\Utility\GeneralUtility::logDeprecatedFunction();
1238 // Return meta tag:
1239 return '<meta http-equiv="Content-Type" content="text/html; charset=' . $this->charset . '" />';
1240 }
1241
1242 /**
1243 * Returns generator meta tag
1244 *
1245 * @return string <meta> tag with name "generator
1246 * @todo Define visibility
1247 */
1248 public function generator() {
1249 $str = 'TYPO3 ' . TYPO3_branch . ', ' . TYPO3_URL_GENERAL . ', &#169; Kasper Sk&#229;rh&#248;j ' . TYPO3_copyright_year . ', extensions are copyright of their respective owners.';
1250 return '<meta name="generator" content="' . $str . '" />';
1251 }
1252
1253 /**
1254 * Returns X-UA-Compatible meta tag
1255 *
1256 * @param string $content Content of the compatible tag (default: IE-8)
1257 * @return string <meta http-equiv="X-UA-Compatible" content="???" />
1258 */
1259 public function xUaCompatible($content = 'IE=8') {
1260 return '<meta http-equiv="X-UA-Compatible" content="' . $content . '" />';
1261 }
1262
1263 /*****************************************
1264 *
1265 * OTHER ELEMENTS
1266 * Tables, buttons, formatting dimmed/red strings
1267 *
1268 ******************************************/
1269 /**
1270 * Returns an image-tag with an 18x16 icon of the following types:
1271 *
1272 * $type:
1273 * -1: OK icon (Check-mark)
1274 * 1: Notice (Speach-bubble)
1275 * 2: Warning (Yellow triangle)
1276 * 3: Fatal error (Red stop sign)
1277 *
1278 * @param integer $type See description
1279 * @param string $styleAttribValue Value for style attribute
1280 * @return string HTML image tag (if applicable)
1281 * @todo Define visibility
1282 */
1283 public function icons($type, $styleAttribValue = '') {
1284 switch ($type) {
1285 case self::STATUS_ICON_ERROR:
1286 $icon = 'status-dialog-error';
1287 break;
1288 case self::STATUS_ICON_WARNING:
1289 $icon = 'status-dialog-warning';
1290 break;
1291 case self::STATUS_ICON_NOTIFICATION:
1292 $icon = 'status-dialog-notification';
1293 break;
1294 case self::STATUS_ICON_OK:
1295 $icon = 'status-dialog-ok';
1296 break;
1297 default:
1298 break;
1299 }
1300 if ($icon) {
1301 return \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon($icon);
1302 }
1303 }
1304
1305 /**
1306 * Returns an <input> button with the $onClick action and $label
1307 *
1308 * @param string $onClick The value of the onclick attribute of the input tag (submit type)
1309 * @param string $label The label for the button (which will be htmlspecialchar'ed)
1310 * @return string A <input> tag of the type "submit
1311 * @todo Define visibility
1312 */
1313 public function t3Button($onClick, $label) {
1314 $button = '<input type="submit" onclick="' . htmlspecialchars($onClick) . '; return false;" value="' . htmlspecialchars($label) . '" />';
1315 return $button;
1316 }
1317
1318 /**
1319 * Dimmed-fontwrap. Returns the string wrapped in a <span>-tag defining the color to be gray/dimmed
1320 *
1321 * @param string $string Input string
1322 * @return string Output string
1323 * @todo Define visibility
1324 */
1325 public function dfw($string) {
1326 return '<span class="typo3-dimmed">' . $string . '</span>';
1327 }
1328
1329 /**
1330 * red-fontwrap. Returns the string wrapped in a <span>-tag defining the color to be red
1331 *
1332 * @param string $string Input string
1333 * @return string Output string
1334 * @todo Define visibility
1335 */
1336 public function rfw($string) {
1337 return '<span class="typo3-red">' . $string . '</span>';
1338 }
1339
1340 /**
1341 * Returns string wrapped in CDATA "tags" for XML / XHTML (wrap content of <script> and <style> sections in those!)
1342 *
1343 * @param string $string Input string
1344 * @return string Output string
1345 * @todo Define visibility
1346 */
1347 public function wrapInCData($string) {
1348 $string = '/*<![CDATA[*/' . $string . '/*]]>*/';
1349 return $string;
1350 }
1351
1352 /**
1353 * Wraps the input string in script tags.
1354 * Automatic re-identing of the JS code is done by using the first line as ident reference.
1355 * This is nice for identing JS code with PHP code on the same level.
1356 *
1357 * @param string $string Input string
1358 * @param boolean $linebreak Wrap script element in linebreaks? Default is TRUE.
1359 * @return string Output string
1360 * @todo Define visibility
1361 */
1362 public function wrapScriptTags($string, $linebreak = TRUE) {
1363 if (trim($string)) {
1364 // <script wrapped in nl?
1365 $cr = $linebreak ? LF : '';
1366 // Remove nl from the beginning
1367 $string = preg_replace('/^\\n+/', '', $string);
1368 // Re-ident to one tab using the first line as reference
1369 $match = array();
1370 if (preg_match('/^(\\t+)/', $string, $match)) {
1371 $string = str_replace($match[1], TAB, $string);
1372 }
1373 $string = $cr . '<script type="text/javascript">
1374 /*<![CDATA[*/
1375 ' . $string . '
1376 /*]]>*/
1377 </script>' . $cr;
1378 }
1379 return trim($string);
1380 }
1381
1382 // These vars defines the layout for the table produced by the table() function.
1383 // You can override these values from outside if you like.
1384 /**
1385 * @todo Define visibility
1386 */
1387 public $tableLayout = array(
1388 'defRow' => array(
1389 'defCol' => array('<td valign="top">', '</td>')
1390 )
1391 );
1392
1393 /**
1394 * @todo Define visibility
1395 */
1396 public $table_TR = '<tr>';
1397
1398 /**
1399 * @todo Define visibility
1400 */
1401 public $table_TABLE = '<table border="0" cellspacing="0" cellpadding="0" class="typo3-dblist" id="typo3-tmpltable">';
1402
1403 /**
1404 * Returns a table based on the input $data
1405 *
1406 * @param array $data Multidim array with first levels = rows, second levels = cells
1407 * @param array $layout If set, then this provides an alternative layout array instead of $this->tableLayout
1408 * @return string The HTML table.
1409 * @internal
1410 * @todo Define visibility
1411 */
1412 public function table($data, $layout = NULL) {
1413 $result = '';
1414 if (is_array($data)) {
1415 $tableLayout = is_array($layout) ? $layout : $this->tableLayout;
1416 $rowCount = 0;
1417 foreach ($data as $tableRow) {
1418 if ($rowCount % 2) {
1419 $layout = is_array($tableLayout['defRowOdd']) ? $tableLayout['defRowOdd'] : $tableLayout['defRow'];
1420 } else {
1421 $layout = is_array($tableLayout['defRowEven']) ? $tableLayout['defRowEven'] : $tableLayout['defRow'];
1422 }
1423 $rowLayout = is_array($tableLayout[$rowCount]) ? $tableLayout[$rowCount] : $layout;
1424 $rowResult = '';
1425 if (is_array($tableRow)) {
1426 $cellCount = 0;
1427 foreach ($tableRow as $tableCell) {
1428 $cellWrap = is_array($layout[$cellCount]) ? $layout[$cellCount] : $layout['defCol'];
1429 $cellWrap = is_array($rowLayout['defCol']) ? $rowLayout['defCol'] : $cellWrap;
1430 $cellWrap = is_array($rowLayout[$cellCount]) ? $rowLayout[$cellCount] : $cellWrap;
1431 $rowResult .= $cellWrap[0] . $tableCell . $cellWrap[1];
1432 $cellCount++;
1433 }
1434 }
1435 $rowWrap = is_array($layout['tr']) ? $layout['tr'] : array($this->table_TR, '</tr>');
1436 $rowWrap = is_array($rowLayout['tr']) ? $rowLayout['tr'] : $rowWrap;
1437 $result .= $rowWrap[0] . $rowResult . $rowWrap[1];
1438 $rowCount++;
1439 }
1440 $tableWrap = is_array($tableLayout['table']) ? $tableLayout['table'] : array($this->table_TABLE, '</table>');
1441 $result = $tableWrap[0] . $result . $tableWrap[1];
1442 }
1443 return $result;
1444 }
1445
1446 /**
1447 * Constructs a table with content from the $arr1, $arr2 and $arr3.
1448 * Used in eg. ext/belog/mod/index.php - refer to that for examples
1449 *
1450 * @param array $arr1 Menu elements on first level
1451 * @param array $arr2 Secondary items
1452 * @param array $arr3 Third-level items
1453 * @return string HTML content, <table>...</table>
1454 * @todo Define visibility
1455 */
1456 public function menuTable($arr1, $arr2 = array(), $arr3 = array()) {
1457 $rows = max(array(count($arr1), count($arr2), count($arr3)));
1458 $menu = '
1459 <table border="0" cellpadding="0" cellspacing="0" id="typo3-tablemenu">';
1460 for ($a = 0; $a < $rows; $a++) {
1461 $menu .= '<tr>';
1462 $cls = array();
1463 $valign = 'middle';
1464 $cls[] = '<td valign="' . $valign . '">' . $arr1[$a][0] . '</td><td>' . $arr1[$a][1] . '</td>';
1465 if (count($arr2)) {
1466 $cls[] = '<td valign="' . $valign . '">' . $arr2[$a][0] . '</td><td>' . $arr2[$a][1] . '</td>';
1467 if (count($arr3)) {
1468 $cls[] = '<td valign="' . $valign . '">' . $arr3[$a][0] . '</td><td>' . $arr3[$a][1] . '</td>';
1469 }
1470 }
1471 $menu .= implode($cls, '<td>&nbsp;&nbsp;</td>');
1472 $menu .= '</tr>';
1473 }
1474 $menu .= '
1475 </table>
1476 ';
1477 return $menu;
1478 }
1479
1480 /**
1481 * Returns a one-row/two-celled table with $content and $menu side by side.
1482 * The table is a 100% width table and each cell is aligned left / right
1483 *
1484 * @param string $content Content cell content (left)
1485 * @param string $menu Menu cell content (right)
1486 * @return string HTML output
1487 * @todo Define visibility
1488 */
1489 public function funcMenu($content, $menu) {
1490 return '
1491 <table border="0" cellpadding="0" cellspacing="0" width="100%" id="typo3-funcmenu">
1492 <tr>
1493 <td valign="top" nowrap="nowrap">' . $content . '</td>
1494 <td valign="top" align="right" nowrap="nowrap">' . $menu . '</td>
1495 </tr>
1496 </table>';
1497 }
1498
1499 /**
1500 * Includes a javascript library that exists in the core /typo3/ directory. The
1501 * backpath is automatically applied
1502 *
1503 * @param string $lib: Library name. Call it with the full path like "contrib/prototype/prototype.js" to load it
1504 * @return void
1505 * @todo Define visibility
1506 */
1507 public function loadJavascriptLib($lib) {
1508 $this->pageRenderer->addJsFile($this->backPath . $lib);
1509 }
1510
1511 /**
1512 * Includes the necessary Javascript function for the clickmenu (context sensitive menus) in the document
1513 *
1514 * @return void
1515 * @todo Define visibility
1516 */
1517 public function getContextMenuCode() {
1518 $this->pageRenderer->loadPrototype();
1519 $this->loadJavascriptLib('js/clickmenu.js');
1520 $this->JScodeArray['clickmenu'] = '
1521 Clickmenu.clickURL = "' . $this->backPath . 'alt_clickmenu.php";
1522 Clickmenu.ajax = true;';
1523 }
1524
1525 /**
1526 * Includes the necessary javascript file (tree.js) for use on pages which have the
1527 * drag and drop functionality (usually pages and folder display trees)
1528 *
1529 * @param string $table indicator of which table the drag and drop function should work on (pages or folders)
1530 * @return void
1531 * @todo Define visibility
1532 */
1533 public function getDragDropCode($table) {
1534 $this->pageRenderer->loadPrototype();
1535 $this->loadJavascriptLib('js/common.js');
1536 $this->loadJavascriptLib('js/tree.js');
1537 // Setting prefs for drag & drop
1538 $this->JScodeArray['dragdrop'] = '
1539 DragDrop.changeURL = "' . $this->backPath . 'alt_clickmenu.php";
1540 DragDrop.backPath = "' . \TYPO3\CMS\Core\Utility\GeneralUtility::shortMD5(('' . '|' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'])) . '";
1541 DragDrop.table = "' . $table . '";
1542 ';
1543 }
1544
1545 /**
1546 * This loads everything needed for the Context Sensitive Help (CSH)
1547 *
1548 * @return void
1549 */
1550 protected function loadCshJavascript() {
1551 $this->pageRenderer->loadExtJS();
1552 $this->pageRenderer->addJsFile($this->backPath . '../t3lib/js/extjs/contexthelp.js');
1553 $this->pageRenderer->addExtDirectCode();
1554 }
1555
1556 /**
1557 * Creates a tab menu from an array definition
1558 *
1559 * Returns a tab menu for a module
1560 * Requires the JS function jumpToUrl() to be available
1561 *
1562 * @param mixed $mainParams is the "&id=" parameter value to be sent to the module, but it can be also a parameter array which will be passed instead of the &id=...
1563 * @param string $elementName it the form elements name, probably something like "SET[...]
1564 * @param string $currentValue is the value to be selected currently.
1565 * @param array $menuItems is an array with the menu items for the selector box
1566 * @param string $script is the script to send the &id to, if empty it's automatically found
1567 * @param string $addparams is additional parameters to pass to the script.
1568 * @return string HTML code for tab menu
1569 * @todo Define visibility
1570 */
1571 public function getTabMenu($mainParams, $elementName, $currentValue, $menuItems, $script = '', $addparams = '') {
1572 $content = '';
1573 if (is_array($menuItems)) {
1574 if (!is_array($mainParams)) {
1575 $mainParams = array('id' => $mainParams);
1576 }
1577 $mainParams = \TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl('', $mainParams);
1578 if (!$script) {
1579 $script = basename(PATH_thisScript);
1580 }
1581 $menuDef = array();
1582 foreach ($menuItems as $value => $label) {
1583 $menuDef[$value]['isActive'] = !strcmp($currentValue, $value);
1584 $menuDef[$value]['label'] = \TYPO3\CMS\Core\Utility\GeneralUtility::deHSCentities(htmlspecialchars($label));
1585 $menuDef[$value]['url'] = $script . '?' . $mainParams . $addparams . '&' . $elementName . '=' . $value;
1586 }
1587 $content = $this->getTabMenuRaw($menuDef);
1588 }
1589 return $content;
1590 }
1591
1592 /**
1593 * Creates the HTML content for the tab menu
1594 *
1595 * @param array $menuItems Menu items for tabs
1596 * @return string Table HTML
1597 * @access private
1598 * @todo Define visibility
1599 */
1600 public function getTabMenuRaw($menuItems) {
1601 $content = '';
1602 if (is_array($menuItems)) {
1603 $options = '';
1604 $count = count($menuItems);
1605 $widthLeft = 1;
1606 $addToAct = 5;
1607 $widthRight = max(1, floor(30 - pow($count, 1.72)));
1608 $widthTabs = 100 - $widthRight - $widthLeft;
1609 $widthNo = floor(($widthTabs - $addToAct) / $count);
1610 $addToAct = max($addToAct, $widthTabs - $widthNo * $count);
1611 $widthAct = $widthNo + $addToAct;
1612 $widthRight = 100 - ($widthLeft + $count * $widthNo + $addToAct);
1613 foreach ($menuItems as $id => $def) {
1614 $isActive = $def['isActive'];
1615 $class = $isActive ? 'tabact' : 'tab';
1616 $width = $isActive ? $widthAct : $widthNo;
1617 // @rene: Here you should probably wrap $label and $url in htmlspecialchars() in order to make sure its XHTML compatible! I did it for $url already since that is VERY likely to break.
1618 $label = $def['label'];
1619 $url = htmlspecialchars($def['url']);
1620 $params = $def['addParams'];
1621 $options .= '<td width="' . $width . '%" class="' . $class . '"><a href="' . $url . '" ' . $params . '>' . $label . '</a></td>';
1622 }
1623 if ($options) {
1624 $content .= '
1625 <!-- Tab menu -->
1626 <table cellpadding="0" cellspacing="0" border="0" width="100%" id="typo3-tabmenu">
1627 <tr>
1628 <td width="' . $widthLeft . '%">&nbsp;</td>
1629 ' . $options . '
1630 <td width="' . $widthRight . '%">&nbsp;</td>
1631 </tr>
1632 </table>
1633 <div class="hr" style="margin:0px"></div>';
1634 }
1635 }
1636 return $content;
1637 }
1638
1639 /**
1640 * Creates a DYNAMIC tab-menu where the tabs are switched between with DHTML.
1641 * Should work in MSIE, Mozilla, Opera and Konqueror. On Konqueror I did find a serious problem: <textarea> fields loose their content when you switch tabs!
1642 *
1643 * @param array $menuItems Numeric array where each entry is an array in itself with associative keys: "label" contains the label for the TAB, "content" contains the HTML content that goes into the div-layer of the tabs content. "description" contains description text to be shown in the layer. "linkTitle" is short text for the title attribute of the tab-menu link (mouse-over text of tab). "stateIcon" indicates a standard status icon (see ->icon(), values: -1, 1, 2, 3). "icon" is an image tag placed before the text.
1644 * @param string $identString Identification string. This should be unique for every instance of a dynamic menu!
1645 * @param integer $toggle If "1", then enabling one tab does not hide the others - they simply toggles each sheet on/off. This makes most sense together with the $foldout option. If "-1" then it acts normally where only one tab can be active at a time BUT you can click a tab and it will close so you have no active tabs.
1646 * @param boolean $foldout If set, the tabs are rendered as headers instead over each sheet. Effectively this means there is no tab menu, but rather a foldout/foldin menu. Make sure to set $toggle as well for this option.
1647 * @param boolean $noWrap If set, tab table cells are not allowed to wrap their content
1648 * @param boolean $fullWidth If set, the tabs will span the full width of their position
1649 * @param integer $defaultTabIndex Default tab to open (for toggle <=0). Value corresponds to integer-array index + 1 (index zero is "1", index "1" is 2 etc.). A value of zero (or something non-existing) will result in no default tab open.
1650 * @param integer $dividers2tabs If set to '1' empty tabs will be remove, If set to '2' empty tabs will be disabled
1651 * @return string JavaScript section for the HTML header.
1652 */
1653 public function getDynTabMenu($menuItems, $identString, $toggle = 0, $foldout = FALSE, $noWrap = TRUE, $fullWidth = FALSE, $defaultTabIndex = 1, $dividers2tabs = 2) {
1654 // Load the static code, if not already done with the function below
1655 $this->loadJavascriptLib('js/tabmenu.js');
1656 $content = '';
1657 if (is_array($menuItems)) {
1658 // Init:
1659 $options = array(array());
1660 $divs = array();
1661 $JSinit = array();
1662 $id = $this->getDynTabMenuId($identString);
1663 $noWrap = $noWrap ? ' nowrap="nowrap"' : '';
1664 // Traverse menu items
1665 $c = 0;
1666 $tabRows = 0;
1667 $titleLenCount = 0;
1668 foreach ($menuItems as $index => $def) {
1669 // Need to add one so checking for first index in JavaScript
1670 // is different than if it is not set at all.
1671 $index += 1;
1672 // Switch to next tab row if needed
1673 if (!$foldout && ($def['newline'] === TRUE && $titleLenCount > 0)) {
1674 $titleLenCount = 0;
1675 $tabRows++;
1676 $options[$tabRows] = array();
1677 }
1678 if ($toggle == 1) {
1679 $onclick = 'this.blur(); DTM_toggle("' . $id . '","' . $index . '"); return false;';
1680 } else {
1681 $onclick = 'this.blur(); DTM_activate("' . $id . '","' . $index . '", ' . ($toggle < 0 ? 1 : 0) . '); return false;';
1682 }
1683 $isEmpty = !(strcmp(trim($def['content']), '') || strcmp(trim($def['icon']), ''));
1684 // "Removes" empty tabs
1685 if ($isEmpty && $dividers2tabs == 1) {
1686 continue;
1687 }
1688 $mouseOverOut = ' onmouseover="DTM_mouseOver(this);" onmouseout="DTM_mouseOut(this);"';
1689 $requiredIcon = '<img name="' . $id . '-' . $index . '-REQ" src="' . $GLOBALS['BACK_PATH'] . 'gfx/clear.gif" class="t3-TCEforms-reqTabImg" alt="" />';
1690 if (!$foldout) {
1691 // Create TAB cell:
1692 $options[$tabRows][] = '
1693 <td class="' . ($isEmpty ? 'disabled' : 'tab') . '" id="' . $id . '-' . $index . '-MENU"' . $noWrap . $mouseOverOut . '>' . ($isEmpty ? '' : '<a href="#" onclick="' . htmlspecialchars($onclick) . '"' . ($def['linkTitle'] ? ' title="' . htmlspecialchars($def['linkTitle']) . '"' : '') . '>') . $def['icon'] . ($def['label'] ? htmlspecialchars($def['label']) : '&nbsp;') . $requiredIcon . $this->icons($def['stateIcon'], 'margin-left: 10px;') . ($isEmpty ? '' : '</a>') . '</td>';
1694 $titleLenCount += strlen($def['label']);
1695 } else {
1696 // Create DIV layer for content:
1697 $divs[] = '
1698 <div class="' . ($isEmpty ? 'disabled' : 'tab') . '" id="' . $id . '-' . $index . '-MENU"' . $mouseOverOut . '>' . ($isEmpty ? '' : '<a href="#" onclick="' . htmlspecialchars($onclick) . '"' . ($def['linkTitle'] ? ' title="' . htmlspecialchars($def['linkTitle']) . '"' : '') . '>') . $def['icon'] . ($def['label'] ? htmlspecialchars($def['label']) : '&nbsp;') . $requiredIcon . ($isEmpty ? '' : '</a>') . '</div>';
1699 }
1700 // Create DIV layer for content:
1701 $divs[] = '
1702 <div style="display: none;" id="' . $id . '-' . $index . '-DIV" class="c-tablayer">' . ($def['description'] ? '<p class="c-descr">' . nl2br(htmlspecialchars($def['description'])) . '</p>' : '') . $def['content'] . '</div>';
1703 // Create initialization string:
1704 $JSinit[] = '
1705 DTM_array["' . $id . '"][' . $c . '] = "' . $id . '-' . $index . '";
1706 ';
1707 // If not empty and we have the toggle option on, check if the tab needs to be expanded
1708 if ($toggle == 1 && !$isEmpty) {
1709 $JSinit[] = '
1710 if (top.DTM_currentTabs["' . $id . '-' . $index . '"]) { DTM_toggle("' . $id . '","' . $index . '",1); }
1711 ';
1712 }
1713 $c++;
1714 }
1715 // Render menu:
1716 if (count($options)) {
1717 // Tab menu is compiled:
1718 if (!$foldout) {
1719 $tabContent = '';
1720 for ($a = 0; $a <= $tabRows; $a++) {
1721 $tabContent .= '
1722
1723 <!-- Tab menu -->
1724 <table cellpadding="0" cellspacing="0" border="0"' . ($fullWidth ? ' width="100%"' : '') . ' class="typo3-dyntabmenu">
1725 <tr>
1726 ' . implode('', $options[$a]) . '
1727 </tr>
1728 </table>';
1729 }
1730 $content .= '<div class="typo3-dyntabmenu-tabs">' . $tabContent . '</div>';
1731 }
1732 // Div layers are added:
1733 $content .= '
1734 <!-- Div layers for tab menu: -->
1735 <div class="typo3-dyntabmenu-divs' . ($foldout ? '-foldout' : '') . '">
1736 ' . implode('', $divs) . '</div>';
1737 // Java Script section added:
1738 $content .= '
1739 <!-- Initialization JavaScript for the menu -->
1740 <script type="text/javascript">
1741 DTM_array["' . $id . '"] = new Array();
1742 ' . implode('', $JSinit) . '
1743 ' . ($toggle <= 0 ? 'DTM_activate("' . $id . '", top.DTM_currentTabs["' . $id . '"]?top.DTM_currentTabs["' . $id . '"]:' . intval($defaultTabIndex) . ', 0);' : '') . '
1744 </script>
1745
1746 ';
1747 }
1748 }
1749 return $content;
1750 }
1751
1752 /**
1753 * Creates the id for dynTabMenus.
1754 *
1755 * @param string $identString Identification string. This should be unique for every instance of a dynamic menu!
1756 * @return string The id with a short MD5 of $identString and prefixed "DTM-", like "DTM-2e8791854a
1757 * @todo Define visibility
1758 */
1759 public function getDynTabMenuId($identString) {
1760 $id = 'DTM-' . \TYPO3\CMS\Core\Utility\GeneralUtility::shortMD5($identString);
1761 return $id;
1762 }
1763
1764 /**
1765 * Creates the version selector for the page id inputted.
1766 * Requires the core version management extension, "version" to be loaded.
1767 *
1768 * @param integer $id Page id to create selector for.
1769 * @param boolean $noAction If set, there will be no button for swapping page.
1770 * @return string
1771 */
1772 public function getVersionSelector($id, $noAction = FALSE) {
1773 if (
1774 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('version') &&
1775 !\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('workspaces')
1776 ) {
1777 $versionGuiObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Version\\View\\VersionView');
1778 return $versionGuiObj->getVersionSelector($id, $noAction);
1779 }
1780 }
1781
1782 /**
1783 * Function to load a HTML template file with markers.
1784 * When calling from own extension, use syntax getHtmlTemplate('EXT:extkey/template.html')
1785 *
1786 * @param string $filename tmpl name, usually in the typo3/template/ directory
1787 * @return string HTML of template
1788 * @todo Define visibility
1789 */
1790 public function getHtmlTemplate($filename) {
1791 // setting the name of the original HTML template
1792 $this->moduleTemplateFilename = $filename;
1793 if ($GLOBALS['TBE_STYLES']['htmlTemplates'][$filename]) {
1794 $filename = $GLOBALS['TBE_STYLES']['htmlTemplates'][$filename];
1795 }
1796 if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($filename, 'EXT:')) {
1797 $filename = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($filename, TRUE, TRUE);
1798 } elseif (!\TYPO3\CMS\Core\Utility\GeneralUtility::isAbsPath($filename)) {
1799 $filename = \TYPO3\CMS\Core\Utility\GeneralUtility::resolveBackPath($this->backPath . $filename);
1800 } elseif (!\TYPO3\CMS\Core\Utility\GeneralUtility::isAllowedAbsPath($filename)) {
1801 $filename = '';
1802 }
1803 $htmlTemplate = '';
1804 if ($filename !== '') {
1805 $htmlTemplate = \TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($filename);
1806 }
1807 return $htmlTemplate;
1808 }
1809
1810 /**
1811 * Define the template for the module
1812 *
1813 * @param string $filename filename
1814 * @return void
1815 */
1816 public function setModuleTemplate($filename) {
1817 // Load Prototype lib for IE event
1818 $this->pageRenderer->loadPrototype();
1819 $this->loadJavascriptLib('js/iecompatibility.js');
1820 $this->moduleTemplate = $this->getHtmlTemplate($filename);
1821 }
1822
1823 /**
1824 * Put together the various elements for the module <body> using a static HTML
1825 * template
1826 *
1827 * @param array $pageRecord Record of the current page, used for page path and info
1828 * @param array $buttons HTML for all buttons
1829 * @param array $markerArray HTML for all other markers
1830 * @param array $subpartArray HTML for the subparts
1831 * @return string Composite HTML
1832 */
1833 public function moduleBody($pageRecord = array(), $buttons = array(), $markerArray = array(), $subpartArray = array()) {
1834 // Get the HTML template for the module
1835 $moduleBody = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($this->moduleTemplate, '###FULLDOC###');
1836 // Add CSS
1837 $this->inDocStylesArray[] = 'html { overflow: hidden; }';
1838 // Get the page path for the docheader
1839 $markerArray['PAGEPATH'] = $this->getPagePath($pageRecord);
1840 // Get the page info for the docheader
1841 $markerArray['PAGEINFO'] = $this->getPageInfo($pageRecord);
1842 // Get all the buttons for the docheader
1843 $docHeaderButtons = $this->getDocHeaderButtons($buttons);
1844 // Merge docheader buttons with the marker array
1845 $markerArray = array_merge($markerArray, $docHeaderButtons);
1846 // replacing subparts
1847 foreach ($subpartArray as $marker => $content) {
1848 $moduleBody = \TYPO3\CMS\Core\Html\HtmlParser::substituteSubpart($moduleBody, $marker, $content);
1849 }
1850 // adding flash messages
1851 if ($this->showFlashMessages) {
1852 $flashMessages = \TYPO3\CMS\Core\Messaging\FlashMessageQueue::renderFlashMessages();
1853 if (!empty($flashMessages)) {
1854 $markerArray['FLASHMESSAGES'] = '<div id="typo3-messages">' . $flashMessages . '</div>';
1855 // If there is no dedicated marker for the messages present
1856 // then force them to appear before the content
1857 if (strpos($moduleBody, '###FLASHMESSAGES###') === FALSE) {
1858 $moduleBody = str_replace('###CONTENT###', '###FLASHMESSAGES######CONTENT###', $moduleBody);
1859 }
1860 }
1861 }
1862 // Hook for adding more markers/content to the page, like the version selector
1863 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['moduleBodyPostProcess'])) {
1864 $params = array(
1865 'moduleTemplateFilename' => &$this->moduleTemplateFilename,
1866 'moduleTemplate' => &$this->moduleTemplate,
1867 'moduleBody' => &$moduleBody,
1868 'markers' => &$markerArray,
1869 'parentObject' => &$this
1870 );
1871 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['moduleBodyPostProcess'] as $funcRef) {
1872 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this);
1873 }
1874 }
1875 // Replacing all markers with the finished markers and return the HTML content
1876 return \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($moduleBody, $markerArray, '###|###');
1877 }
1878
1879 /**
1880 * Fill the button lists with the defined HTML
1881 *
1882 * @param array $buttons HTML for all buttons
1883 * @return array Containing HTML for both buttonlists
1884 */
1885 protected function getDocHeaderButtons($buttons) {
1886 $markers = array();
1887 // Fill buttons for left and right float
1888 $floats = array('left', 'right');
1889 foreach ($floats as $key) {
1890 // Get the template for each float
1891 $buttonTemplate = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($this->moduleTemplate, '###BUTTON_GROUPS_' . strtoupper($key) . '###');
1892 // Fill the button markers in this float
1893 $buttonTemplate = \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($buttonTemplate, $buttons, '###|###', TRUE);
1894 // getting the wrap for each group
1895 $buttonWrap = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($this->moduleTemplate, '###BUTTON_GROUP_WRAP###');
1896 // looping through the groups (max 6) and remove the empty groups
1897 for ($groupNumber = 1; $groupNumber < 6; $groupNumber++) {
1898 $buttonMarker = '###BUTTON_GROUP' . $groupNumber . '###';
1899 $buttonGroup = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($buttonTemplate, $buttonMarker);
1900 if (trim($buttonGroup)) {
1901 if ($buttonWrap) {
1902 $buttonGroup = \TYPO3\CMS\Core\Html\HtmlParser::substituteMarker($buttonWrap, '###BUTTONS###', $buttonGroup);
1903 }
1904 $buttonTemplate = \TYPO3\CMS\Core\Html\HtmlParser::substituteSubpart($buttonTemplate, $buttonMarker, trim($buttonGroup));
1905 }
1906 }
1907 // Replace the marker with the template and remove all line breaks (for IE compat)
1908 $markers['BUTTONLIST_' . strtoupper($key)] = str_replace(LF, '', $buttonTemplate);
1909 }
1910 // Hook for manipulating docHeaderButtons
1911 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['docHeaderButtonsHook'])) {
1912 $params = array(
1913 'buttons' => $buttons,
1914 'markers' => &$markers,
1915 'pObj' => &$this
1916 );
1917 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['docHeaderButtonsHook'] as $funcRef) {
1918 \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this);
1919 }
1920 }
1921 return $markers;
1922 }
1923
1924 /**
1925 * Generate the page path for docheader
1926 *
1927 * @param array $pageRecord Current page
1928 * @return string Page path
1929 */
1930 protected function getPagePath($pageRecord) {
1931 // Is this a real page
1932 if (is_array($pageRecord) && $pageRecord['uid']) {
1933 $title = substr($pageRecord['_thePathFull'], 0, -1);
1934 // Remove current page title
1935 $pos = strrpos($title, '/');
1936 if ($pos !== FALSE) {
1937 $title = substr($title, 0, $pos) . '/';
1938 }
1939 } else {
1940 $title = '';
1941 }
1942 // Setting the path of the page
1943 $pagePath = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.path', 1) . ': <span class="typo3-docheader-pagePath">';
1944 // crop the title to title limit (or 50, if not defined)
1945 $cropLength = empty($GLOBALS['BE_USER']->uc['titleLen']) ? 50 : $GLOBALS['BE_USER']->uc['titleLen'];
1946 $croppedTitle = \TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($title, -$cropLength);
1947 if ($croppedTitle !== $title) {
1948 $pagePath .= '<abbr title="' . htmlspecialchars($title) . '">' . htmlspecialchars($croppedTitle) . '</abbr>';
1949 } else {
1950 $pagePath .= htmlspecialchars($title);
1951 }
1952 $pagePath .= '</span>';
1953 return $pagePath;
1954 }
1955
1956 /**
1957 * Setting page icon with clickmenu + uid for docheader
1958 *
1959 * @param array $pageRecord Current page
1960 * @return string Page info
1961 */
1962 protected function getPageInfo($pageRecord) {
1963 // Add icon with clickmenu, etc:
1964 // If there IS a real page
1965 if (is_array($pageRecord) && $pageRecord['uid']) {
1966 $alttext = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordIconAltText($pageRecord, 'pages');
1967 $iconImg = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('pages', $pageRecord, array('title' => $alttext));
1968 // Make Icon:
1969 $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconImg, 'pages', $pageRecord['uid']);
1970 $uid = $pageRecord['uid'];
1971 $title = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle('pages', $pageRecord);
1972 } else {
1973 // On root-level of page tree
1974 // Make Icon
1975 $iconImg = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-pagetree-root', array('title' => htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'])));
1976 if ($GLOBALS['BE_USER']->user['admin']) {
1977 $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconImg, 'pages', 0);
1978 } else {
1979 $theIcon = $iconImg;
1980 }
1981 $uid = '0';
1982 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
1983 }
1984 // Setting icon with clickmenu + uid
1985 $pageInfo = $theIcon . '<strong>' . htmlspecialchars($title) . '&nbsp;[' . $uid . ']</strong>';
1986 return $pageInfo;
1987 }
1988
1989 /**
1990 * Makes a collapseable section. See reports module for an example
1991 *
1992 * @param string $title
1993 * @param string $html
1994 * @param string $id
1995 * @param string $saveStatePointer
1996 * @return string
1997 */
1998 public function collapseableSection($title, $html, $id, $saveStatePointer = '') {
1999 $hasSave = $saveStatePointer ? TRUE : FALSE;
2000 $collapsedStyle = ($collapsedClass = '');
2001 if ($hasSave) {
2002 /** @var $settings \TYPO3\CMS\Backend\User\ExtDirect\BackendUserSettingsDataProvider */
2003 $settings = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\User\\ExtDirect\\BackendUserSettingsDataProvider');
2004 $value = $settings->get($saveStatePointer . '.' . $id);
2005 if ($value) {
2006 $collapsedStyle = ' style="display: none"';
2007 $collapsedClass = ' collapsed';
2008 } else {
2009 $collapsedStyle = '';
2010 $collapsedClass = ' expanded';
2011 }
2012 }
2013 $this->pageRenderer->loadExtJS();
2014 $this->pageRenderer->addExtOnReadyCode('
2015 Ext.select("h2.section-header").each(function(element){
2016 element.on("click", function(event, tag) {
2017 var state = 0,
2018 el = Ext.fly(tag),
2019 div = el.next("div"),
2020 saveKey = el.getAttribute("rel");
2021 if (el.hasClass("collapsed")) {
2022 el.removeClass("collapsed").addClass("expanded");
2023 div.slideIn("t", {
2024 easing: "easeIn",
2025 duration: .5
2026 });
2027 } else {
2028 el.removeClass("expanded").addClass("collapsed");
2029 div.slideOut("t", {
2030 easing: "easeOut",
2031 duration: .5,
2032 remove: false,
2033 useDisplay: true
2034 });
2035 state = 1;
2036 }
2037 if (saveKey) {
2038 try {
2039 top.TYPO3.BackendUserSettings.ExtDirect.set(saveKey + "." + tag.id, state, function(response) {});
2040 } catch(e) {}
2041 }
2042 });
2043 });
2044 ');
2045 return '
2046 <h2 id="' . $id . '" class="section-header' . $collapsedClass . '" rel="' . $saveStatePointer . '"> ' . $title . '</h2>
2047 <div' . $collapsedStyle . '>' . $html . '</div>
2048 ';
2049 }
2050
2051 /**
2052 * Retrieves configured favicon for backend (with fallback)
2053 *
2054 * @return string
2055 */
2056 protected function getBackendFavicon() {
2057 return \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($this->backPath, 'gfx/favicon.ico', '', 1);
2058 }
2059 }
2060
2061
2062 ?>