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