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