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