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