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