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