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