[BUGFIX] DocumentTemplate class inserts inDocStyles twice
[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 text file 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 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($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 ($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
1168 // Reset styles so they won't be added again in insertStylesAndJS()
1169 $this->inDocStylesArray = array();
1170 $this->inDocStyles = '';
1171 $this->inDocStyles_TBEstyle = '';
1172
1173 if ($this->styleSheetFile) {
1174 $this->pageRenderer->addCssFile($this->backPath . $this->styleSheetFile);
1175 }
1176 if ($this->styleSheetFile2) {
1177 $this->pageRenderer->addCssFile($this->backPath . $this->styleSheetFile2);
1178 }
1179 $this->pageRenderer->addCssInlineBlock('inDocStyles', $inDocStyles . LF . '/*###POSTCSSMARKER###*/');
1180 if ($this->styleSheetFile_post) {
1181 $this->pageRenderer->addCssFile($this->backPath . $this->styleSheetFile_post);
1182 }
1183 }
1184
1185 /**
1186 * Insert additional style sheet link
1187 *
1188 * @param string $key some key identifying the style sheet
1189 * @param string $href uri to the style sheet file
1190 * @param string $title value for the title attribute of the link element
1191 * @param string $relation value for the rel attribute of the link element
1192 * @return void
1193 * @todo Define visibility
1194 */
1195 public function addStyleSheet($key, $href, $title = '', $relation = 'stylesheet') {
1196 if (strpos($href, '://') !== FALSE || substr($href, 0, 1) === '/') {
1197 $file = $href;
1198 } else {
1199 $file = $this->backPath . $href;
1200 }
1201 $this->pageRenderer->addCssFile($file, $relation, 'screen', $title);
1202 }
1203
1204 /**
1205 * Add all *.css files of the directory $path to the stylesheets
1206 *
1207 * @param string $path directory to add
1208 * @return void
1209 * @todo Define visibility
1210 */
1211 public function addStyleSheetDirectory($path) {
1212 // Calculation needed, when TYPO3 source is used via a symlink
1213 // absolute path to the stylesheets
1214 $filePath = dirname(GeneralUtility::getIndpEnv('SCRIPT_FILENAME')) . '/' . $GLOBALS['BACK_PATH'] . $path;
1215 // Clean the path
1216 $resolvedPath = GeneralUtility::resolveBackPath($filePath);
1217 // Read all files in directory and sort them alphabetically
1218 $files = GeneralUtility::getFilesInDir($resolvedPath, 'css', FALSE, 1);
1219 foreach ($files as $file) {
1220 $this->pageRenderer->addCssFile($GLOBALS['BACK_PATH'] . $path . $file, 'stylesheet', 'all');
1221 }
1222 }
1223
1224 /**
1225 * Insert post rendering document style into already rendered content
1226 * This is needed for extobjbase
1227 *
1228 * @param string $content style-content to insert.
1229 * @return string content with inserted styles
1230 * @todo Define visibility
1231 */
1232 public function insertStylesAndJS($content) {
1233 // Insert accumulated CSS
1234 if (!empty($this->inDocStyles)) {
1235 $this->inDocStylesArray[] = $this->inDocStyles;
1236 }
1237 $styles = LF . implode(LF, $this->inDocStylesArray);
1238 $content = str_replace('/*###POSTCSSMARKER###*/', $styles, $content);
1239
1240 // Insert accumulated JS
1241 $jscode = $this->JScode . LF . $this->wrapScriptTags(implode(LF, $this->JScodeArray));
1242 $content = str_replace('<!--###POSTJSMARKER###-->', $jscode, $content);
1243 return $content;
1244 }
1245
1246 /**
1247 * Returns an array of all stylesheet directories belonging to core and skins
1248 *
1249 * @return array Stylesheet directories
1250 */
1251 public function getSkinStylesheetDirectories() {
1252 $stylesheetDirectories = array();
1253 // Add default core stylesheets
1254 foreach ($this->stylesheetsCore as $stylesheetDir) {
1255 $stylesheetDirectories[] = $stylesheetDir;
1256 }
1257 // Stylesheets from skins
1258 // merge default css directories ($this->stylesheetsSkin) with additional ones and include them
1259 if (is_array($GLOBALS['TBE_STYLES']['skins'])) {
1260 // loop over all registered skins
1261 foreach ($GLOBALS['TBE_STYLES']['skins'] as $skinExtKey => $skin) {
1262 $skinStylesheetDirs = $this->stylesheetsSkins;
1263 // Skins can add custom stylesheetDirectories using
1264 // $GLOBALS['TBE_STYLES']['skins'][$_EXTKEY]['stylesheetDirectories']
1265 if (is_array($skin['stylesheetDirectories'])) {
1266 $skinStylesheetDirs = array_merge($skinStylesheetDirs, $skin['stylesheetDirectories']);
1267 }
1268 // Add all registered directories
1269 foreach ($skinStylesheetDirs as $stylesheetDir) {
1270 // for EXT:myskin/stylesheets/ syntax
1271 if (substr($stylesheetDir, 0, 4) === 'EXT:') {
1272 list($extKey, $path) = explode('/', substr($stylesheetDir, 4), 2);
1273 if (!empty($extKey) && ExtensionManagementUtility::isLoaded($extKey) && !empty($path)) {
1274 $stylesheetDirectories[] = ExtensionManagementUtility::extRelPath($extKey) . $path;
1275 }
1276 } else {
1277 // For relative paths
1278 $stylesheetDirectories[] = ExtensionManagementUtility::extRelPath($skinExtKey) . $stylesheetDir;
1279 }
1280 }
1281 }
1282 }
1283 return $stylesheetDirectories;
1284 }
1285
1286 /**
1287 * Initialize the charset.
1288 * Sets the internal $this->charset variable to the charset defined in $GLOBALS["LANG"] (or the default as set in this class)
1289 * Returns the meta-tag for the document header
1290 *
1291 * @return string <meta> tag with charset from $this->charset or $GLOBALS['LANG']->charSet
1292 * @todo Define visibility
1293 * @deprecated since TYPO3 6.0, remove in 6.2. The charset is utf-8 all the time for the backend now
1294 */
1295 public function initCharset() {
1296 GeneralUtility::logDeprecatedFunction();
1297 // Return meta tag:
1298 return '<meta http-equiv="Content-Type" content="text/html; charset=' . $this->charset . '" />';
1299 }
1300
1301 /**
1302 * Returns generator meta tag
1303 *
1304 * @return string <meta> tag with name "generator
1305 * @todo Define visibility
1306 */
1307 public function generator() {
1308 $str = 'TYPO3 ' . TYPO3_branch . ', ' . TYPO3_URL_GENERAL . ', &#169; Kasper Sk&#229;rh&#248;j ' . TYPO3_copyright_year . ', extensions are copyright of their respective owners.';
1309 return '<meta name="generator" content="' . $str . '" />';
1310 }
1311
1312 /**
1313 * Returns X-UA-Compatible meta tag
1314 *
1315 * @param string $content Content of the compatible tag (default: IE-8)
1316 * @return string <meta http-equiv="X-UA-Compatible" content="???" />
1317 */
1318 public function xUaCompatible($content = 'IE=8') {
1319 return '<meta http-equiv="X-UA-Compatible" content="' . $content . '" />';
1320 }
1321
1322 /*****************************************
1323 *
1324 * OTHER ELEMENTS
1325 * Tables, buttons, formatting dimmed/red strings
1326 *
1327 ******************************************/
1328 /**
1329 * Returns an image-tag with an 18x16 icon of the following types:
1330 *
1331 * $type:
1332 * -1: OK icon (Check-mark)
1333 * 1: Notice (Speach-bubble)
1334 * 2: Warning (Yellow triangle)
1335 * 3: Fatal error (Red stop sign)
1336 *
1337 * @param integer $type See description
1338 * @param string $styleAttribValue Value for style attribute
1339 * @return string HTML image tag (if applicable)
1340 * @todo Define visibility
1341 */
1342 public function icons($type, $styleAttribValue = '') {
1343 switch ($type) {
1344 case self::STATUS_ICON_ERROR:
1345 $icon = 'status-dialog-error';
1346 break;
1347 case self::STATUS_ICON_WARNING:
1348 $icon = 'status-dialog-warning';
1349 break;
1350 case self::STATUS_ICON_NOTIFICATION:
1351 $icon = 'status-dialog-notification';
1352 break;
1353 case self::STATUS_ICON_OK:
1354 $icon = 'status-dialog-ok';
1355 break;
1356 default:
1357 // Do nothing
1358 }
1359 if ($icon) {
1360 return IconUtility::getSpriteIcon($icon);
1361 }
1362 }
1363
1364 /**
1365 * Returns an <input> button with the $onClick action and $label
1366 *
1367 * @param string $onClick The value of the onclick attribute of the input tag (submit type)
1368 * @param string $label The label for the button (which will be htmlspecialchar'ed)
1369 * @return string A <input> tag of the type "submit
1370 * @todo Define visibility
1371 */
1372 public function t3Button($onClick, $label) {
1373 $button = '<input type="submit" onclick="' . htmlspecialchars($onClick) . '; return false;" value="' . htmlspecialchars($label) . '" />';
1374 return $button;
1375 }
1376
1377 /**
1378 * Dimmed-fontwrap. Returns the string wrapped in a <span>-tag defining the color to be gray/dimmed
1379 *
1380 * @param string $string Input string
1381 * @return string Output string
1382 * @todo Define visibility
1383 */
1384 public function dfw($string) {
1385 return '<span class="typo3-dimmed">' . $string . '</span>';
1386 }
1387
1388 /**
1389 * red-fontwrap. Returns the string wrapped in a <span>-tag defining the color to be red
1390 *
1391 * @param string $string Input string
1392 * @return string Output string
1393 * @todo Define visibility
1394 */
1395 public function rfw($string) {
1396 return '<span class="typo3-red">' . $string . '</span>';
1397 }
1398
1399 /**
1400 * Returns string wrapped in CDATA "tags" for XML / XHTML (wrap content of <script> and <style> sections in those!)
1401 *
1402 * @param string $string Input string
1403 * @return string Output string
1404 * @todo Define visibility
1405 */
1406 public function wrapInCData($string) {
1407 $string = '/*<![CDATA[*/' . $string . '/*]]>*/';
1408 return $string;
1409 }
1410
1411 /**
1412 * Wraps the input string in script tags.
1413 * Automatic re-identing of the JS code is done by using the first line as ident reference.
1414 * This is nice for identing JS code with PHP code on the same level.
1415 *
1416 * @param string $string Input string
1417 * @param boolean $linebreak Wrap script element in linebreaks? Default is TRUE.
1418 * @return string Output string
1419 * @todo Define visibility
1420 */
1421 public function wrapScriptTags($string, $linebreak = TRUE) {
1422 if (trim($string)) {
1423 // <script wrapped in nl?
1424 $cr = $linebreak ? LF : '';
1425 // Remove nl from the beginning
1426 $string = preg_replace('/^\\n+/', '', $string);
1427 // Re-ident to one tab using the first line as reference
1428 $match = array();
1429 if (preg_match('/^(\\t+)/', $string, $match)) {
1430 $string = str_replace($match[1], TAB, $string);
1431 }
1432 $string = $cr . '<script type="text/javascript">
1433 /*<![CDATA[*/
1434 ' . $string . '
1435 /*]]>*/
1436 </script>' . $cr;
1437 }
1438 return trim($string);
1439 }
1440
1441 // These vars defines the layout for the table produced by the table() function.
1442 // You can override these values from outside if you like.
1443 /**
1444 * @todo Define visibility
1445 */
1446 public $tableLayout = array(
1447 'defRow' => array(
1448 'defCol' => array('<td valign="top">', '</td>')
1449 )
1450 );
1451
1452 /**
1453 * @todo Define visibility
1454 */
1455 public $table_TR = '<tr>';
1456
1457 /**
1458 * @todo Define visibility
1459 */
1460 public $table_TABLE = '<table border="0" cellspacing="0" cellpadding="0" class="typo3-dblist" id="typo3-tmpltable">';
1461
1462 /**
1463 * Returns a table based on the input $data
1464 *
1465 * @param array $data Multidim array with first levels = rows, second levels = cells
1466 * @param array $layout If set, then this provides an alternative layout array instead of $this->tableLayout
1467 * @return string The HTML table.
1468 * @internal
1469 * @todo Define visibility
1470 */
1471 public function table($data, $layout = NULL) {
1472 $result = '';
1473 if (is_array($data)) {
1474 $tableLayout = is_array($layout) ? $layout : $this->tableLayout;
1475 $rowCount = 0;
1476 foreach ($data as $tableRow) {
1477 if ($rowCount % 2) {
1478 $layout = is_array($tableLayout['defRowOdd']) ? $tableLayout['defRowOdd'] : $tableLayout['defRow'];
1479 } else {
1480 $layout = is_array($tableLayout['defRowEven']) ? $tableLayout['defRowEven'] : $tableLayout['defRow'];
1481 }
1482 $rowLayout = is_array($tableLayout[$rowCount]) ? $tableLayout[$rowCount] : $layout;
1483 $rowResult = '';
1484 if (is_array($tableRow)) {
1485 $cellCount = 0;
1486 foreach ($tableRow as $tableCell) {
1487 $cellWrap = is_array($layout[$cellCount]) ? $layout[$cellCount] : $layout['defCol'];
1488 $cellWrap = is_array($rowLayout['defCol']) ? $rowLayout['defCol'] : $cellWrap;
1489 $cellWrap = is_array($rowLayout[$cellCount]) ? $rowLayout[$cellCount] : $cellWrap;
1490 $rowResult .= $cellWrap[0] . $tableCell . $cellWrap[1];
1491 $cellCount++;
1492 }
1493 }
1494 $rowWrap = is_array($layout['tr']) ? $layout['tr'] : array($this->table_TR, '</tr>');
1495 $rowWrap = is_array($rowLayout['tr']) ? $rowLayout['tr'] : $rowWrap;
1496 $result .= $rowWrap[0] . $rowResult . $rowWrap[1];
1497 $rowCount++;
1498 }
1499 $tableWrap = is_array($tableLayout['table']) ? $tableLayout['table'] : array($this->table_TABLE, '</table>');
1500 $result = $tableWrap[0] . $result . $tableWrap[1];
1501 }
1502 return $result;
1503 }
1504
1505 /**
1506 * Constructs a table with content from the $arr1, $arr2 and $arr3.
1507 * Used in eg. ext/belog/mod/index.php - refer to that for examples
1508 *
1509 * @param array $arr1 Menu elements on first level
1510 * @param array $arr2 Secondary items
1511 * @param array $arr3 Third-level items
1512 * @return string HTML content, <table>...</table>
1513 * @todo Define visibility
1514 */
1515 public function menuTable($arr1, $arr2 = array(), $arr3 = array()) {
1516 $rows = max(array(count($arr1), count($arr2), count($arr3)));
1517 $menu = '
1518 <table border="0" cellpadding="0" cellspacing="0" id="typo3-tablemenu">';
1519 for ($a = 0; $a < $rows; $a++) {
1520 $menu .= '<tr>';
1521 $cls = array();
1522 $valign = 'middle';
1523 $cls[] = '<td valign="' . $valign . '">' . $arr1[$a][0] . '</td><td>' . $arr1[$a][1] . '</td>';
1524 if (count($arr2)) {
1525 $cls[] = '<td valign="' . $valign . '">' . $arr2[$a][0] . '</td><td>' . $arr2[$a][1] . '</td>';
1526 if (count($arr3)) {
1527 $cls[] = '<td valign="' . $valign . '">' . $arr3[$a][0] . '</td><td>' . $arr3[$a][1] . '</td>';
1528 }
1529 }
1530 $menu .= implode($cls, '<td>&nbsp;&nbsp;</td>');
1531 $menu .= '</tr>';
1532 }
1533 $menu .= '
1534 </table>
1535 ';
1536 return $menu;
1537 }
1538
1539 /**
1540 * Returns a one-row/two-celled table with $content and $menu side by side.
1541 * The table is a 100% width table and each cell is aligned left / right
1542 *
1543 * @param string $content Content cell content (left)
1544 * @param string $menu Menu cell content (right)
1545 * @return string HTML output
1546 * @todo Define visibility
1547 */
1548 public function funcMenu($content, $menu) {
1549 return '
1550 <table border="0" cellpadding="0" cellspacing="0" width="100%" id="typo3-funcmenu">
1551 <tr>
1552 <td valign="top" nowrap="nowrap">' . $content . '</td>
1553 <td valign="top" align="right" nowrap="nowrap">' . $menu . '</td>
1554 </tr>
1555 </table>';
1556 }
1557
1558 /**
1559 * Includes a javascript library that exists in the core /typo3/ directory. The
1560 * backpath is automatically applied
1561 *
1562 * @param string $lib: Library name. Call it with the full path like "contrib/prototype/prototype.js" to load it
1563 * @return void
1564 * @todo Define visibility
1565 */
1566 public function loadJavascriptLib($lib) {
1567 $this->pageRenderer->addJsFile($this->backPath . $lib);
1568 }
1569
1570 /**
1571 * Includes the necessary Javascript function for the clickmenu (context sensitive menus) in the document
1572 *
1573 * @return void
1574 * @todo Define visibility
1575 */
1576 public function getContextMenuCode() {
1577 $this->pageRenderer->loadPrototype();
1578 $this->loadJavascriptLib('sysext/backend/Resources/Public/JavaScript/clickmenu.js');
1579 $this->JScodeArray['clickmenu'] = '
1580 Clickmenu.clickURL = "' . $this->backPath . 'alt_clickmenu.php";
1581 Clickmenu.ajax = true;';
1582 }
1583
1584 /**
1585 * Includes the necessary javascript file (tree.js) for use on pages which have the
1586 * drag and drop functionality (usually pages and folder display trees)
1587 *
1588 * @param string $table indicator of which table the drag and drop function should work on (pages or folders)
1589 * @return void
1590 * @todo Define visibility
1591 */
1592 public function getDragDropCode($table) {
1593 $this->pageRenderer->loadPrototype();
1594 $this->loadJavascriptLib('sysext/backend/Resources/Public/JavaScript/common.js');
1595 $this->loadJavascriptLib('js/tree.js');
1596 // Setting prefs for drag & drop
1597 $this->JScodeArray['dragdrop'] = '
1598 DragDrop.changeURL = "' . $this->backPath . 'alt_clickmenu.php";
1599 DragDrop.backPath = "' . GeneralUtility::shortMD5(('' . '|' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'])) . '";
1600 DragDrop.table = "' . $table . '";
1601 ';
1602 }
1603
1604 /**
1605 * This loads everything needed for the Context Sensitive Help (CSH)
1606 *
1607 * @return void
1608 */
1609 protected function loadCshJavascript() {
1610 $this->pageRenderer->loadExtJS();
1611 $this->pageRenderer->addJsFile($this->backPath . 'sysext/backend/Resources/Public/JavaScript/contexthelp.js');
1612 $this->pageRenderer->addExtDirectCode();
1613 }
1614
1615 /**
1616 * Creates a tab menu from an array definition
1617 *
1618 * Returns a tab menu for a module
1619 * Requires the JS function jumpToUrl() to be available
1620 *
1621 * @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=...
1622 * @param string $elementName it the form elements name, probably something like "SET[...]
1623 * @param string $currentValue is the value to be selected currently.
1624 * @param array $menuItems is an array with the menu items for the selector box
1625 * @param string $script is the script to send the &id to, if empty it's automatically found
1626 * @param string $addparams is additional parameters to pass to the script.
1627 * @return string HTML code for tab menu
1628 * @todo Define visibility
1629 */
1630 public function getTabMenu($mainParams, $elementName, $currentValue, $menuItems, $script = '', $addparams = '') {
1631 $content = '';
1632 if (is_array($menuItems)) {
1633 if (!is_array($mainParams)) {
1634 $mainParams = array('id' => $mainParams);
1635 }
1636 $mainParams = GeneralUtility::implodeArrayForUrl('', $mainParams);
1637 if (!$script) {
1638 $script = basename(PATH_thisScript);
1639 }
1640 $menuDef = array();
1641 foreach ($menuItems as $value => $label) {
1642 $menuDef[$value]['isActive'] = (string)$currentValue === (string)$value;
1643 $menuDef[$value]['label'] = GeneralUtility::deHSCentities(htmlspecialchars($label));
1644 $menuDef[$value]['url'] = $script . '?' . $mainParams . $addparams . '&' . $elementName . '=' . $value;
1645 }
1646 $content = $this->getTabMenuRaw($menuDef);
1647 }
1648 return $content;
1649 }
1650
1651 /**
1652 * Creates the HTML content for the tab menu
1653 *
1654 * @param array $menuItems Menu items for tabs
1655 * @return string Table HTML
1656 * @access private
1657 * @todo Define visibility
1658 */
1659 public function getTabMenuRaw($menuItems) {
1660 $content = '';
1661 if (is_array($menuItems)) {
1662 $options = '';
1663 $count = count($menuItems);
1664 $widthLeft = 1;
1665 $addToAct = 5;
1666 $widthRight = max(1, floor(30 - pow($count, 1.72)));
1667 $widthTabs = 100 - $widthRight - $widthLeft;
1668 $widthNo = floor(($widthTabs - $addToAct) / $count);
1669 $addToAct = max($addToAct, $widthTabs - $widthNo * $count);
1670 $widthAct = $widthNo + $addToAct;
1671 $widthRight = 100 - ($widthLeft + $count * $widthNo + $addToAct);
1672 foreach ($menuItems as $id => $def) {
1673 $isActive = $def['isActive'];
1674 $class = $isActive ? 'tabact' : 'tab';
1675 $width = $isActive ? $widthAct : $widthNo;
1676 // @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.
1677 $label = $def['label'];
1678 $url = htmlspecialchars($def['url']);
1679 $params = $def['addParams'];
1680 $options .= '<td width="' . $width . '%" class="' . $class . '"><a href="' . $url . '" ' . $params . '>' . $label . '</a></td>';
1681 }
1682 if ($options) {
1683 $content .= '
1684 <!-- Tab menu -->
1685 <table cellpadding="0" cellspacing="0" border="0" width="100%" id="typo3-tabmenu">
1686 <tr>
1687 <td width="' . $widthLeft . '%">&nbsp;</td>
1688 ' . $options . '
1689 <td width="' . $widthRight . '%">&nbsp;</td>
1690 </tr>
1691 </table>
1692 <div class="hr" style="margin:0px"></div>';
1693 }
1694 }
1695 return $content;
1696 }
1697
1698 /**
1699 * Creates a DYNAMIC tab-menu where the tabs are switched between with DHTML.
1700 * 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!
1701 *
1702 * @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.
1703 * @param string $identString Identification string. This should be unique for every instance of a dynamic menu!
1704 * @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.
1705 * @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.
1706 * @param boolean $noWrap If set, tab table cells are not allowed to wrap their content
1707 * @param boolean $fullWidth If set, the tabs will span the full width of their position
1708 * @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.
1709 * @param integer $dividers2tabs If set to '1' empty tabs will be remove, If set to '2' empty tabs will be disabled
1710 * @return string JavaScript section for the HTML header.
1711 */
1712 public function getDynTabMenu($menuItems, $identString, $toggle = 0, $foldout = FALSE, $noWrap = TRUE, $fullWidth = FALSE, $defaultTabIndex = 1, $dividers2tabs = 2) {
1713 // Load the static code, if not already done with the function below
1714 $this->loadJavascriptLib('sysext/backend/Resources/Public/JavaScript/tabmenu.js');
1715 $content = '';
1716 if (is_array($menuItems)) {
1717 // Init:
1718 $options = array(array());
1719 $divs = array();
1720 $JSinit = array();
1721 $id = $this->getDynTabMenuId($identString);
1722 $noWrap = $noWrap ? ' nowrap="nowrap"' : '';
1723 // Traverse menu items
1724 $c = 0;
1725 $tabRows = 0;
1726 $titleLenCount = 0;
1727 foreach ($menuItems as $index => $def) {
1728 // Need to add one so checking for first index in JavaScript
1729 // is different than if it is not set at all.
1730 $index += 1;
1731 // Switch to next tab row if needed
1732 if (!$foldout && ($def['newline'] === TRUE && $titleLenCount > 0)) {
1733 $titleLenCount = 0;
1734 $tabRows++;
1735 $options[$tabRows] = array();
1736 }
1737 if ($toggle == 1) {
1738 $onclick = 'this.blur(); DTM_toggle("' . $id . '","' . $index . '"); return false;';
1739 } else {
1740 $onclick = 'this.blur(); DTM_activate("' . $id . '","' . $index . '", ' . ($toggle < 0 ? 1 : 0) . '); return false;';
1741 }
1742 $isEmpty = trim($def['content']) === '' && trim($def['icon']) === '';
1743 // "Removes" empty tabs
1744 if ($isEmpty && $dividers2tabs == 1) {
1745 continue;
1746 }
1747 $mouseOverOut = ' onmouseover="DTM_mouseOver(this);" onmouseout="DTM_mouseOut(this);"';
1748 $requiredIcon = '<img name="' . $id . '-' . $index . '-REQ" src="' . $GLOBALS['BACK_PATH'] . 'gfx/clear.gif" class="t3-TCEforms-reqTabImg" alt="" />';
1749 if (!$foldout) {
1750 // Create TAB cell:
1751 $options[$tabRows][] = '
1752 <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>';
1753 $titleLenCount += strlen($def['label']);
1754 } else {
1755 // Create DIV layer for content:
1756 $divs[] = '
1757 <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>';
1758 }
1759 // Create DIV layer for content:
1760 $divs[] = '
1761 <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>';
1762 // Create initialization string:
1763 $JSinit[] = '
1764 DTM_array["' . $id . '"][' . $c . '] = "' . $id . '-' . $index . '";
1765 ';
1766 // If not empty and we have the toggle option on, check if the tab needs to be expanded
1767 if ($toggle == 1 && !$isEmpty) {
1768 $JSinit[] = '
1769 if (top.DTM_currentTabs["' . $id . '-' . $index . '"]) { DTM_toggle("' . $id . '","' . $index . '",1); }
1770 ';
1771 }
1772 $c++;
1773 }
1774 // Render menu:
1775 if (count($options)) {
1776 // Tab menu is compiled:
1777 if (!$foldout) {
1778 $tabContent = '';
1779 for ($a = 0; $a <= $tabRows; $a++) {
1780 $tabContent .= '
1781
1782 <!-- Tab menu -->
1783 <table cellpadding="0" cellspacing="0" border="0"' . ($fullWidth ? ' width="100%"' : '') . ' class="typo3-dyntabmenu">
1784 <tr>
1785 ' . implode('', $options[$a]) . '
1786 </tr>
1787 </table>';
1788 }
1789 $content .= '<div class="typo3-dyntabmenu-tabs">' . $tabContent . '</div>';
1790 }
1791 // Div layers are added:
1792 $content .= '
1793 <!-- Div layers for tab menu: -->
1794 <div class="typo3-dyntabmenu-divs' . ($foldout ? '-foldout' : '') . '">
1795 ' . implode('', $divs) . '</div>';
1796 // Java Script section added:
1797 $content .= '
1798 <!-- Initialization JavaScript for the menu -->
1799 <script type="text/javascript">
1800 DTM_array["' . $id . '"] = new Array();
1801 ' . implode('', $JSinit) . '
1802 ' . ($toggle <= 0 ? 'DTM_activate("' . $id . '", top.DTM_currentTabs["' . $id . '"]?top.DTM_currentTabs["' . $id . '"]:' . intval($defaultTabIndex) . ', 0);' : '') . '
1803 </script>
1804
1805 ';
1806 }
1807 }
1808 return $content;
1809 }
1810
1811 /**
1812 * Creates the id for dynTabMenus.
1813 *
1814 * @param string $identString Identification string. This should be unique for every instance of a dynamic menu!
1815 * @return string The id with a short MD5 of $identString and prefixed "DTM-", like "DTM-2e8791854a
1816 * @todo Define visibility
1817 */
1818 public function getDynTabMenuId($identString) {
1819 $id = 'DTM-' . GeneralUtility::shortMD5($identString);
1820 return $id;
1821 }
1822
1823 /**
1824 * Creates the version selector for the page id inputted.
1825 * Requires the core version management extension, "version" to be loaded.
1826 *
1827 * @param integer $id Page id to create selector for.
1828 * @param boolean $noAction If set, there will be no button for swapping page.
1829 * @return string
1830 */
1831 public function getVersionSelector($id, $noAction = FALSE) {
1832 if (
1833 ExtensionManagementUtility::isLoaded('version') &&
1834 !ExtensionManagementUtility::isLoaded('workspaces')
1835 ) {
1836 $versionGuiObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Version\\View\\VersionView');
1837 return $versionGuiObj->getVersionSelector($id, $noAction);
1838 }
1839 }
1840
1841 /**
1842 * Function to load a HTML template file with markers.
1843 * When calling from own extension, use syntax getHtmlTemplate('EXT:extkey/template.html')
1844 *
1845 * @param string $filename tmpl name, usually in the typo3/template/ directory
1846 * @return string HTML of template
1847 * @todo Define visibility
1848 */
1849 public function getHtmlTemplate($filename) {
1850 // setting the name of the original HTML template
1851 $this->moduleTemplateFilename = $filename;
1852 if ($GLOBALS['TBE_STYLES']['htmlTemplates'][$filename]) {
1853 $filename = $GLOBALS['TBE_STYLES']['htmlTemplates'][$filename];
1854 }
1855 if (GeneralUtility::isFirstPartOfStr($filename, 'EXT:')) {
1856 $filename = GeneralUtility::getFileAbsFileName($filename, TRUE, TRUE);
1857 } elseif (!GeneralUtility::isAbsPath($filename)) {
1858 $filename = GeneralUtility::resolveBackPath($this->backPath . $filename);
1859 } elseif (!GeneralUtility::isAllowedAbsPath($filename)) {
1860 $filename = '';
1861 }
1862 $htmlTemplate = '';
1863 if ($filename !== '') {
1864 $htmlTemplate = GeneralUtility::getUrl($filename);
1865 }
1866 return $htmlTemplate;
1867 }
1868
1869 /**
1870 * Define the template for the module
1871 *
1872 * @param string $filename filename
1873 * @return void
1874 */
1875 public function setModuleTemplate($filename) {
1876 // Load Prototype lib for IE event
1877 $this->pageRenderer->loadPrototype();
1878 $this->loadJavascriptLib('sysext/backend/Resources/Public/JavaScript/iecompatibility.js');
1879 $this->moduleTemplate = $this->getHtmlTemplate($filename);
1880 }
1881
1882 /**
1883 * Put together the various elements for the module <body> using a static HTML
1884 * template
1885 *
1886 * @param array $pageRecord Record of the current page, used for page path and info
1887 * @param array $buttons HTML for all buttons
1888 * @param array $markerArray HTML for all other markers
1889 * @param array $subpartArray HTML for the subparts
1890 * @return string Composite HTML
1891 */
1892 public function moduleBody($pageRecord = array(), $buttons = array(), $markerArray = array(), $subpartArray = array()) {
1893 // Get the HTML template for the module
1894 $moduleBody = HtmlParser::getSubpart($this->moduleTemplate, '###FULLDOC###');
1895 // Add CSS
1896 $this->inDocStylesArray[] = 'html { overflow: hidden; }';
1897 // Get the page path for the docheader
1898 $markerArray['PAGEPATH'] = $this->getPagePath($pageRecord);
1899 // Get the page info for the docheader
1900 $markerArray['PAGEINFO'] = $this->getPageInfo($pageRecord);
1901 // Get all the buttons for the docheader
1902 $docHeaderButtons = $this->getDocHeaderButtons($buttons);
1903 // Merge docheader buttons with the marker array
1904 $markerArray = array_merge($markerArray, $docHeaderButtons);
1905 // replacing subparts
1906 foreach ($subpartArray as $marker => $content) {
1907 $moduleBody = HtmlParser::substituteSubpart($moduleBody, $marker, $content);
1908 }
1909 // adding flash messages
1910 if ($this->showFlashMessages) {
1911 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
1912 $flashMessageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService');
1913 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
1914 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
1915 $flashMessages = $defaultFlashMessageQueue->renderFlashMessages();
1916 if (!empty($flashMessages)) {
1917 $markerArray['FLASHMESSAGES'] = '<div id="typo3-messages">' . $flashMessages . '</div>';
1918 // If there is no dedicated marker for the messages present
1919 // then force them to appear before the content
1920 if (strpos($moduleBody, '###FLASHMESSAGES###') === FALSE) {
1921 $moduleBody = str_replace('###CONTENT###', '###FLASHMESSAGES######CONTENT###', $moduleBody);
1922 }
1923 }
1924 }
1925 // Hook for adding more markers/content to the page, like the version selector
1926 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['moduleBodyPostProcess'])) {
1927 $params = array(
1928 'moduleTemplateFilename' => &$this->moduleTemplateFilename,
1929 'moduleTemplate' => &$this->moduleTemplate,
1930 'moduleBody' => &$moduleBody,
1931 'markers' => &$markerArray,
1932 'parentObject' => &$this
1933 );
1934 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['moduleBodyPostProcess'] as $funcRef) {
1935 GeneralUtility::callUserFunction($funcRef, $params, $this);
1936 }
1937 }
1938 // Replacing all markers with the finished markers and return the HTML content
1939 return HtmlParser::substituteMarkerArray($moduleBody, $markerArray, '###|###');
1940 }
1941
1942 /**
1943 * Fill the button lists with the defined HTML
1944 *
1945 * @param array $buttons HTML for all buttons
1946 * @return array Containing HTML for both buttonlists
1947 */
1948 protected function getDocHeaderButtons($buttons) {
1949 $markers = array();
1950 // Fill buttons for left and right float
1951 $floats = array('left', 'right');
1952 foreach ($floats as $key) {
1953 // Get the template for each float
1954 $buttonTemplate = HtmlParser::getSubpart($this->moduleTemplate, '###BUTTON_GROUPS_' . strtoupper($key) . '###');
1955 // Fill the button markers in this float
1956 $buttonTemplate = HtmlParser::substituteMarkerArray($buttonTemplate, $buttons, '###|###', TRUE);
1957 // getting the wrap for each group
1958 $buttonWrap = HtmlParser::getSubpart($this->moduleTemplate, '###BUTTON_GROUP_WRAP###');
1959 // looping through the groups (max 6) and remove the empty groups
1960 for ($groupNumber = 1; $groupNumber < 6; $groupNumber++) {
1961 $buttonMarker = '###BUTTON_GROUP' . $groupNumber . '###';
1962 $buttonGroup = HtmlParser::getSubpart($buttonTemplate, $buttonMarker);
1963 if (trim($buttonGroup)) {
1964 if ($buttonWrap) {
1965 $buttonGroup = HtmlParser::substituteMarker($buttonWrap, '###BUTTONS###', $buttonGroup);
1966 }
1967 $buttonTemplate = HtmlParser::substituteSubpart($buttonTemplate, $buttonMarker, trim($buttonGroup));
1968 }
1969 }
1970 // Replace the marker with the template and remove all line breaks (for IE compat)
1971 $markers['BUTTONLIST_' . strtoupper($key)] = str_replace(LF, '', $buttonTemplate);
1972 }
1973 // Hook for manipulating docHeaderButtons
1974 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['docHeaderButtonsHook'])) {
1975 $params = array(
1976 'buttons' => $buttons,
1977 'markers' => &$markers,
1978 'pObj' => &$this
1979 );
1980 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['docHeaderButtonsHook'] as $funcRef) {
1981 GeneralUtility::callUserFunction($funcRef, $params, $this);
1982 }
1983 }
1984 return $markers;
1985 }
1986
1987 /**
1988 * Generate the page path for docheader
1989 *
1990 * @param array $pageRecord Current page
1991 * @return string Page path
1992 */
1993 protected function getPagePath($pageRecord) {
1994 // Is this a real page
1995 if (is_array($pageRecord) && $pageRecord['uid']) {
1996 $title = substr($pageRecord['_thePathFull'], 0, -1);
1997 // Remove current page title
1998 $pos = strrpos($title, '/');
1999 if ($pos !== FALSE) {
2000 $title = substr($title, 0, $pos) . '/';
2001 }
2002 } else {
2003 $title = '';
2004 }
2005 // Setting the path of the page
2006 $pagePath = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.path', TRUE) . ': <span class="typo3-docheader-pagePath">';
2007 // crop the title to title limit (or 50, if not defined)
2008 $cropLength = empty($GLOBALS['BE_USER']->uc['titleLen']) ? 50 : $GLOBALS['BE_USER']->uc['titleLen'];
2009 $croppedTitle = GeneralUtility::fixed_lgd_cs($title, -$cropLength);
2010 if ($croppedTitle !== $title) {
2011 $pagePath .= '<abbr title="' . htmlspecialchars($title) . '">' . htmlspecialchars($croppedTitle) . '</abbr>';
2012 } else {
2013 $pagePath .= htmlspecialchars($title);
2014 }
2015 $pagePath .= '</span>';
2016 return $pagePath;
2017 }
2018
2019 /**
2020 * Setting page icon with clickmenu + uid for docheader
2021 *
2022 * @param array $pageRecord Current page
2023 * @return string Page info
2024 */
2025 protected function getPageInfo($pageRecord) {
2026 // Add icon with clickmenu, etc:
2027 // If there IS a real page
2028 if (is_array($pageRecord) && $pageRecord['uid']) {
2029 $alttext = BackendUtility::getRecordIconAltText($pageRecord, 'pages');
2030 $iconImg = IconUtility::getSpriteIconForRecord('pages', $pageRecord, array('title' => $alttext));
2031 // Make Icon:
2032 $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconImg, 'pages', $pageRecord['uid']);
2033 $uid = $pageRecord['uid'];
2034 $title = BackendUtility::getRecordTitle('pages', $pageRecord);
2035 } else {
2036 // On root-level of page tree
2037 // Make Icon
2038 $iconImg = IconUtility::getSpriteIcon('apps-pagetree-root', array('title' => htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'])));
2039 if ($GLOBALS['BE_USER']->user['admin']) {
2040 $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconImg, 'pages', 0);
2041 } else {
2042 $theIcon = $iconImg;
2043 }
2044 $uid = '0';
2045 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
2046 }
2047 // Setting icon with clickmenu + uid
2048 $pageInfo = $theIcon . '<strong>' . htmlspecialchars($title) . '&nbsp;[' . $uid . ']</strong>';
2049 return $pageInfo;
2050 }
2051
2052 /**
2053 * Makes a collapseable section. See reports module for an example
2054 *
2055 * @param string $title
2056 * @param string $html
2057 * @param string $id
2058 * @param string $saveStatePointer
2059 * @return string
2060 */
2061 public function collapseableSection($title, $html, $id, $saveStatePointer = '') {
2062 $hasSave = $saveStatePointer ? TRUE : FALSE;
2063 $collapsedStyle = ($collapsedClass = '');
2064 if ($hasSave) {
2065 /** @var $settings \TYPO3\CMS\Backend\User\ExtDirect\BackendUserSettingsDataProvider */
2066 $settings = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\User\\ExtDirect\\BackendUserSettingsDataProvider');
2067 $value = $settings->get($saveStatePointer . '.' . $id);
2068 if ($value) {
2069 $collapsedStyle = ' style="display: none"';
2070 $collapsedClass = ' collapsed';
2071 } else {
2072 $collapsedStyle = '';
2073 $collapsedClass = ' expanded';
2074 }
2075 }
2076 $this->pageRenderer->loadExtJS();
2077 $this->pageRenderer->addExtOnReadyCode('
2078 Ext.select("h2.section-header").each(function(element){
2079 element.on("click", function(event, tag) {
2080 var state = 0,
2081 el = Ext.fly(tag),
2082 div = el.next("div"),
2083 saveKey = el.getAttribute("rel");
2084 if (el.hasClass("collapsed")) {
2085 el.removeClass("collapsed").addClass("expanded");
2086 div.slideIn("t", {
2087 easing: "easeIn",
2088 duration: .5
2089 });
2090 } else {
2091 el.removeClass("expanded").addClass("collapsed");
2092 div.slideOut("t", {
2093 easing: "easeOut",
2094 duration: .5,
2095 remove: false,
2096 useDisplay: true
2097 });
2098 state = 1;
2099 }
2100 if (saveKey) {
2101 try {
2102 top.TYPO3.BackendUserSettings.ExtDirect.set(saveKey + "." + tag.id, state, function(response) {});
2103 } catch(e) {}
2104 }
2105 });
2106 });
2107 ');
2108 return '
2109 <h2 id="' . $id . '" class="section-header' . $collapsedClass . '" rel="' . $saveStatePointer . '"> ' . $title . '</h2>
2110 <div' . $collapsedStyle . '>' . $html . '</div>
2111 ';
2112 }
2113
2114 /**
2115 * Retrieves configured favicon for backend (with fallback)
2116 *
2117 * @return string
2118 */
2119 protected function getBackendFavicon() {
2120 return IconUtility::skinImg($this->backPath, 'gfx/favicon.ico', '', 1);
2121 }
2122 }