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