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