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