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