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