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