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