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