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