Changed lots of stuff...
[Packages/TYPO3.CMS.git] / typo3 / template.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 Kasper Skaarhoj (kasper@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 * $Id$
31 * Revised for TYPO3 3.6 2/2003 by Kasper Skaarhoj
32 * XHTML-trans compliant
33 *
34 * @author Kasper Skaarhoj <kasper@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 * 133: function fw($str)
40 *
41 *
42 * 157: class template
43 * 212: function template()
44 *
45 * SECTION: EVALUATION FUNCTIONS
46 * 279: function wrapClickMenuOnIcon($str,$table,$uid='',$listFr=1)
47 * 295: function viewPageIcon($id,$backPath,$addParams='hspace="3"')
48 * 320: function issueCommand($params,$rUrl='')
49 * 335: function isCMlayers()
50 * 345: function thisBlur()
51 * 355: function helpStyle()
52 * 372: function getHeader($table,$row,$path,$noViewPageIcon=0,$tWrap=array('',''))
53 * 398: function getFileheader($title,$path,$iconfile)
54 * 413: function makeShortcutIcon($gvList,$setList,$modName,$motherModName="")
55 * 446: function makeShortcutUrl($gvList,$setList)
56 * 468: function formWidth($size=48,$textarea=0,$styleOverride='')
57 * 493: function formWidthText($size=48,$styleOverride='',$wrap='')
58 * 510: function redirectUrls($thisLocation='')
59 * 534: function formatTime($tstamp,$type)
60 * 547: function parseTime()
61 *
62 * SECTION: PAGE BUILDING FUNCTIONS.
63 * 580: function startPage($title)
64 * 649: function endPage()
65 * 674: function header($text)
66 * 695: function section($label,$text,$nostrtoupper=FALSE,$sH=FALSE,$type=0,$allowHTMLinHeader=FALSE)
67 * 719: function divider($dist)
68 * 735: function spacer($dist)
69 * 754: function sectionHeader($label,$sH=FALSE,$addAttrib='')
70 * 771: function sectionBegin()
71 * 792: function sectionEnd()
72 * 812: function middle()
73 * 821: function endPageJS()
74 * 838: function docBodyTagBegin()
75 * 848: function docStyle()
76 * 889: function insertStylesAndJS($content)
77 * 909: function initCharset()
78 * 921: function generator()
79 *
80 * SECTION: OTHER ELEMENTS
81 * 953: function icons($type)
82 * 982: function t3Button($onClick,$label)
83 * 993: function dfw($string)
84 * 1003: function rfw($string)
85 * 1013: function wrapInCData($string)
86 * 1030: function wrapScriptTags($string, $linebreak=TRUE)
87 * 1067: function table($arr)
88 * 1107: function menuTable($arr1,$arr2=array(), $arr3=array())
89 * 1140: function funcMenu($content,$menu)
90 * 1158: function clearCacheMenu($id,$addSaveOptions=0)
91 * 1194: function getContextMenuCode()
92 * 1340: function getTabMenu($id,$elementName,$currentValue,$menuItems,$script='',$addparams='')
93 *
94 *
95 * 1452: class bigDoc extends template
96 *
97 *
98 * 1461: class noDoc extends template
99 *
100 *
101 * 1470: class smallDoc extends template
102 *
103 *
104 * 1479: class mediumDoc extends template
105 *
106 * TOTAL FUNCTIONS: 45
107 * (This index is automatically created/updated by the extension "extdeveval")
108 *
109 */
110
111
112
113 if (!defined('TYPO3_MODE')) die("Can't include this file directly.");
114
115
116
117
118
119
120
121
122
123
124
125
126 /**
127 * Depreciated fontwrap function. Is just transparent now.
128 *
129 * @param string Input string
130 * @return string Output string (in the old days this was wrapped in <font> tags)
131 * @depreciated
132 */
133 function fw($str) {
134 return $str;
135 }
136
137
138 /**
139 * TYPO3 Backend Template Class
140 *
141 * This class contains functions for starting and ending the HTML of backend modules
142 * It also contains methods for outputting sections of content.
143 * Further there are functions for making icons, links, setting form-field widths etc.
144 * Color scheme and stylesheet definitions are also available here.
145 * Finally this file includes the language class for TYPO3's backend.
146 *
147 * After this file $LANG and $TBE_TEMPLATE are global variables / instances of their respective classes.
148 * This file is typically included right after the init.php file,
149 * if language and layout is needed.
150 *
151 * Please refer to Inside TYPO3 for a discussion of how to use this API.
152 *
153 * @author Kasper Skaarhoj <kasper@typo3.com>
154 * @package TYPO3
155 * @subpackage core
156 */
157 class template {
158
159 // Vars you typically might want to/should set from outside after making instance of this class:
160 var $backPath = ''; // 'backPath' pointing back to the PATH_typo3
161 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.
162 var $JScode=''; // Additional header code (eg. a JavaScript section) could be accommulated in this var. It will be directly outputted in the header.
163 var $JScodeArray=array(); // Similar to $JScode but for use as array with assioziative keys to prevent double inclusion of JS code. a <script> tag is automatically wrapped around.
164 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.
165 var $docType=''; // Doc-type used in the header. Default is HTML 3.2. You can also set it to 'strict', 'xhtml_trans', or 'xhtml_frames'.
166
167 // Other vars you can change, but less frequently used:
168 var $scriptID=''; // Script ID.
169 var $bodyTagId=''; // Id which can be set for the body tag. Default value is based on script ID
170 var $bodyTagAdditions=''; // You can add additional attributes to the body-tag through this variable.
171 var $inDocStyles=''; // Additional CSS styles which will be added to the <style> section in the header
172 var $inDocStylesArray=array(); // Like $inDocStyles but for use as array with associative keys to prevent double inclusion of css code
173 var $form_rowsToStylewidth = 9.58; // Multiplication factor for formWidth() input size (default is 48* this value).
174 var $form_largeComp = 1.33; // Compensation for large documents (used in class.t3lib_tceforms.php)
175 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.
176
177 // TYPO3 Colorscheme.
178 // If you want to change this, please do so through a skin using the global var $TBE_STYLES
179 var $bgColor = '#F7F3EF'; // Light background color
180 var $bgColor2 = '#9BA1A8'; // Steel-blue
181 var $bgColor3 = '#F6F2E6'; // dok.color
182 var $bgColor4 = '#D9D5C9'; // light tablerow background, brownish
183 var $bgColor5 = '#ABBBB4'; // light tablerow background, greenish
184 var $bgColor6 = '#E7DBA8'; // light tablerow background, yellowish, for section headers. Light.
185 var $hoverColor = '#254D7B';
186 var $styleSheetFile = 'stylesheet.css'; // Filename of stylesheet (relative to PATH_typo3)
187 var $styleSheetFile2 = ''; // Filename of stylesheet #2 - linked to right after the $this->styleSheetFile script (relative to PATH_typo3)
188 var $styleSheetFile_post = ''; // Filename of a post-stylesheet - included right after all inline styles.
189 var $backGroundImage = ''; // Background image of page (relative to PATH_typo3)
190 var $inDocStyles_TBEstyle = ''; // Inline css styling set from TBE_STYLES array
191
192 // DEV:
193 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.
194
195 // INTERNAL
196 var $charset = 'iso-8859-1'; // Default charset. see function initCharset()
197
198 var $sectionFlag=0; // Internal: Indicates if a <div>-output section is open
199 var $divClass = ''; // (Default) Class for wrapping <DIV>-tag of page. Is set in class extensions.
200
201
202
203
204
205
206 /**
207 * Constructor
208 * Imports relevant parts from global $TBE_STYLES (colorscheme)
209 *
210 * @return void
211 */
212 function template() {
213 global $TBE_STYLES;
214
215 // Setting default scriptID:
216 $this->scriptID = ereg_replace('^.*\/(sysext|ext)\/','ext/',substr(PATH_thisScript,strlen(PATH_site)));
217 if (TYPO3_mainDir!='typo3/' && substr($this->scriptID,0,strlen(TYPO3_mainDir)) == TYPO3_mainDir) {
218 $this->scriptID = 'typo3/'.substr($this->scriptID,strlen(TYPO3_mainDir)); // This fixes if TYPO3_mainDir has been changed so the script ids are STILL "typo3/..."
219 }
220
221 $this->bodyTagId = ereg_replace('[^[:alnum:]-]','-',$this->scriptID);
222
223 // Individual configuration per script? If so, make a recursive merge of the arrays:
224 if (is_array($TBE_STYLES['scriptIDindex'][$this->scriptID])) {
225 $ovr = $TBE_STYLES['scriptIDindex'][$this->scriptID]; // Make copy
226 $TBE_STYLES = t3lib_div::array_merge_recursive_overrule($TBE_STYLES,$ovr); // merge styles.
227 unset($TBE_STYLES['scriptIDindex'][$this->scriptID]); // Have to unset - otherwise the second instantiation will do it again!
228 }
229
230 // Color scheme:
231 if ($TBE_STYLES['mainColors']['bgColor']) $this->bgColor=$TBE_STYLES['mainColors']['bgColor'];
232 if ($TBE_STYLES['mainColors']['bgColor1']) $this->bgColor1=$TBE_STYLES['mainColors']['bgColor1'];
233 if ($TBE_STYLES['mainColors']['bgColor2']) $this->bgColor2=$TBE_STYLES['mainColors']['bgColor2'];
234 if ($TBE_STYLES['mainColors']['bgColor3']) $this->bgColor3=$TBE_STYLES['mainColors']['bgColor3'];
235 if ($TBE_STYLES['mainColors']['bgColor4']) $this->bgColor4=$TBE_STYLES['mainColors']['bgColor4'];
236 if ($TBE_STYLES['mainColors']['bgColor5']) $this->bgColor5=$TBE_STYLES['mainColors']['bgColor5'];
237 if ($TBE_STYLES['mainColors']['bgColor6']) $this->bgColor6=$TBE_STYLES['mainColors']['bgColor6'];
238 if ($TBE_STYLES['mainColors']['hoverColor']) $this->hoverColor=$TBE_STYLES['mainColors']['hoverColor'];
239
240 // Main Stylesheets:
241 if ($TBE_STYLES['stylesheet']) $this->styleSheetFile = $TBE_STYLES['stylesheet'];
242 if ($TBE_STYLES['stylesheet2']) $this->styleSheetFile2 = $TBE_STYLES['stylesheet2'];
243 if ($TBE_STYLES['styleSheetFile_post']) $this->styleSheetFile_post = $TBE_STYLES['styleSheetFile_post'];
244 if ($TBE_STYLES['inDocStyles_TBEstyle']) $this->inDocStyles_TBEstyle = $TBE_STYLES['inDocStyles_TBEstyle'];
245
246 // Background image
247 if ($TBE_STYLES['background']) $this->backGroundImage = $TBE_STYLES['background'];
248 }
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265 /*****************************************
266 *
267 * EVALUATION FUNCTIONS
268 * Various centralized processing
269 *
270 *****************************************/
271
272 /**
273 * Makes click menu link (context sensitive menu)
274 * 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)
275 * 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)
276 *
277 * @param string String to be wrapped in link, typ. image tag.
278 * @param string Table name/File path. If the icon is for a database record, enter the tablename from $TCA. If a file then enter the absolute filepath
279 * @param integer If icon is for database record this is the UID for the record from $table
280 * @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.
281 * @return string The link-wrapped input string.
282 */
283 function wrapClickMenuOnIcon($str,$table,$uid='',$listFr=1) {
284 $backPath = '&backPath='.rawurlencode($this->backPath).'|'.t3lib_div::shortMD5($this->backPath.'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']);
285 $onClick = 'top.loadTopMenu(\''.$this->backPath.'alt_clickmenu.php?item='.rawurlencode($table.'|'.$uid.'|'.$listFr).$backPath.'\');'.$this->thisBlur().'return false;';
286 return '<a href="#" onclick="'.htmlspecialchars($onClick).'">'.$str.'</a>';
287 }
288
289 /**
290 * Makes link to page $id in frontend (view page)
291 * Returns an magnifier-glass icon which links to the frontend index.php document for viewing the page with id $id
292 * $id must be a page-uid
293 * If the BE_USER has access to Web>List then a link to that module is shown as well (with return-url)
294 *
295 * @param integer The page id
296 * @param string The current "BACK_PATH" (the back relative to the typo3/ directory)
297 * @param string Additional parameters for the image tag(s)
298 * @return string HTML string with linked icon(s)
299 */
300 function viewPageIcon($id,$backPath,$addParams='hspace="3"') {
301 global $BE_USER;
302 $str = '';
303 // If access to Web>List for user, then link to that module.
304 if ($BE_USER->check('modules','web_list')) {
305 $href=$backPath.'db_list.php?id='.$id.'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'));
306 $str.= '<a href="'.htmlspecialchars($href).'">'.
307 '<img'.t3lib_iconWorks::skinImg($backPath,'gfx/list.gif','width="11" height="11"').' title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showList',1).'"'.($addParams?' '.trim($addParams):'').' alt="" />'.
308 '</a>';
309 }
310 // Make link to view page
311 $str.= '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::viewOnClick($id,$backPath,t3lib_BEfunc::BEgetRootLine($id))).'">'.
312 '<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="" />'.
313 '</a>';
314 return $str;
315 }
316
317 /**
318 * Returns a URL with a command to TYPO3 Core Engine (tce_db.php)
319 * See description of the API elsewhere.
320 *
321 * @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"
322 * @param string Redirect URL if any other that t3lib_div::getIndpEnv('REQUEST_URI') is wished
323 * @return string URL to tce_db.php + parameters (backpath is taken from $this->backPath)
324 */
325 function issueCommand($params,$rUrl='') {
326 $rUrl = $rUrl ? $rUrl : t3lib_div::getIndpEnv('REQUEST_URI');
327 return $this->backPath.'tce_db.php?'.
328 $params.
329 '&redirect='.($rUrl==-1?"'+T3_THIS_LOCATION+'":rawurlencode($rUrl)).
330 '&vC='.rawurlencode($GLOBALS['BE_USER']->veriCode()).
331 '&prErr=1&uPT=1';
332 }
333
334 /**
335 * Returns true if click-menu layers can be displayed for the current user/browser
336 * Use this to test if click-menus (context sensitive menus) can and should be displayed in the backend.
337 *
338 * @return boolean
339 */
340 function isCMlayers() {
341 return !$GLOBALS['BE_USER']->uc['disableCMlayers'] && $GLOBALS['CLIENT']['FORMSTYLE'] && $GLOBALS['CLIENT']['SYSTEM']!='mac';
342 }
343
344 /**
345 * Returns 'this.blur();' if the client supports CSS styles
346 * Use this in links to remove the underlining after being clicked
347 *
348 * @return string
349 */
350 function thisBlur() {
351 return ($GLOBALS['CLIENT']['FORMSTYLE']?'this.blur();':'');
352 }
353
354 /**
355 * Returns ' style='cursor:help;'' if the client supports CSS styles
356 * Use for <a>-links to help texts
357 *
358 * @return string
359 */
360 function helpStyle() {
361 return $GLOBALS['CLIENT']['FORMSTYLE'] ? ' style="cursor:help;"':'';
362 }
363
364 /**
365 * Makes the header (icon+title) for a page (or other record). Used in most modules under Web>*
366 * $table and $row must be a tablename/record from that table
367 * $path will be shown as alt-text for the icon.
368 * The title will be truncated to 45 chars.
369 *
370 * @param string Table name
371 * @param array Record row
372 * @param string Alt text
373 * @param boolean Set $noViewPageIcon true if you don't want a magnifier-icon for viewing the page in the frontend
374 * @param array $tWrap is an array with indexes 0 and 1 each representing HTML-tags (start/end) which will wrap the title
375 * @return string HTML content
376 */
377 function getHeader($table,$row,$path,$noViewPageIcon=0,$tWrap=array('','')) {
378 global $TCA;
379 if (is_array($row) && $row['uid']) {
380 $iconImgTag=t3lib_iconWorks::getIconImage($table,$row,$this->backPath,'title="'.htmlspecialchars($path).'"');
381 $title= strip_tags($row[$TCA[$table]['ctrl']['label']]);
382 $viewPage = $noViewPageIcon ? '' : $this->viewPageIcon($row['uid'],$this->backPath,'');
383 if ($table=='pages') $path.=' - '.t3lib_BEfunc::titleAttribForPages($row,'',0);
384 } else {
385 $iconImgTag='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/i/_icon_website.gif',$wHattribs='width="18" height="16"').' title="'.htmlspecialchars($path).'" alt="" />';
386 $title=$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
387 }
388
389 return '<span class="typo3-moduleHeader">'.$this->wrapClickMenuOnIcon($iconImgTag,$table,$row['uid']).
390 $viewPage.
391 $tWrap[0].htmlspecialchars(t3lib_div::fixed_lgd($title,45)).$tWrap[1].'</span>';
392 }
393
394 /**
395 * Like ->getHeader() but for files in the File>* main module/submodules
396 * Returns the file-icon with the path of the file set in the alt/title attribute. Shows the file-name after the icon.
397 *
398 * @param string Title string, expected to be the filepath
399 * @param string Alt text
400 * @param string The icon file (relative to TYPO3 dir)
401 * @return string HTML content
402 */
403 function getFileheader($title,$path,$iconfile) {
404 $fileInfo = t3lib_div::split_fileref($title);
405 $title = htmlspecialchars(t3lib_div::fixed_lgd_pre($fileInfo['path'],35)).'<b>'.htmlspecialchars($fileInfo['file']).'</b>';
406 return '<span class="typo3-moduleHeader"><img'.t3lib_iconWorks::skinImg($this->backPath,$iconfile,'width="18" height="16"').' title="'.htmlspecialchars($path).'" alt="" />'.$title.'</span>';
407 }
408
409 /**
410 * Returns a linked shortcut-icon which will call the shortcut frame and set a shortcut there back to the calling page/module
411 *
412 * @param string Is the list of GET variables to store (if any)
413 * @param string Is the list of SET[] variables to store (if any) - SET[] variables a stored in $GLOBALS["SOBE"]->MOD_SETTINGS for backend modules
414 * @param string Module name string
415 * @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.
416 * @return string HTML content
417 */
418 function makeShortcutIcon($gvList,$setList,$modName,$motherModName="") {
419 $backPath=$this->backPath;
420 $storeUrl=$this->makeShortcutUrl($gvList,$setList);
421 $pathInfo = parse_url(t3lib_div::getIndpEnv('REQUEST_URI'));
422
423 if (!strcmp($motherModName,'1')) {
424 $mMN="&motherModName='+top.currentModuleLoaded+'";
425 } elseif ($motherModName) {
426 $mMN='&motherModName='.rawurlencode($motherModName);
427 } else $mMN="";
428
429 $onClick = 'if (top.shortcutFrame && confirm('.
430 $GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.makeShortcut')).
431 ')){top.shortcutFrame.document.location=\''.$backPath.'alt_shortcut.php?modName='.rawurlencode($modName).
432 '&URL='.rawurlencode($pathInfo['path']."?".$storeUrl).
433 $mMN.
434 '\';}return false;';
435
436 $sIcon = '<a href="#" onclick="'.htmlspecialchars($onClick).'">
437 <img'.t3lib_iconWorks::skinImg($backPath,'gfx/shortcut.gif','width="14" height="14"').' title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.makeShortcut',1).'" alt="" /></a>';
438 return $sIcon;
439 }
440
441 /**
442 * MAKE url for storing
443 * Internal func
444 *
445 * @param string Is the list of GET variables to store (if any)
446 * @param string Is the list of SET[] variables to store (if any) - SET[] variables a stored in $GLOBALS["SOBE"]->MOD_SETTINGS for backend modules
447 * @return string
448 * @access private
449 * @see makeShortcutIcon()
450 */
451 function makeShortcutUrl($gvList,$setList) {
452 $GET = t3lib_div::_GET();
453 $storeArray = array_merge(
454 t3lib_div::compileSelectedGetVarsFromArray($gvList,$GET),
455 array('SET'=>t3lib_div::compileSelectedGetVarsFromArray($setList,$GLOBALS['SOBE']->MOD_SETTINGS))
456 );
457 $storeUrl = t3lib_div::implodeArrayForUrl('',$storeArray);
458 return $storeUrl;
459 }
460
461 /**
462 * Returns <input> attributes to set the width of an text-type input field.
463 * For client browsers with no CSS support the cols/size attribute is returned.
464 * For CSS compliant browsers (recommended) a ' style="width: ...px;"' is returned.
465 *
466 * @param integer A relative number which multiplied with approx. 10 will lead to the width in pixels
467 * @param boolean A flag you can set for textareas - DEPRECIATED, use ->formWidthText() for textareas!!!
468 * @param string A string which will be returned as attribute-value for style="" instead of the calculated width (if CSS is enabled)
469 * @return string Tag attributes for an <input> tag (regarding width)
470 * @see formWidthText()
471 */
472 function formWidth($size=48,$textarea=0,$styleOverride='') {
473 $wAttrib = $textarea?'cols':'size';
474 if (!$GLOBALS['CLIENT']['FORMSTYLE']) { // If not setting the width by style-attribute
475 $size = $size;
476 $retVal = ' '.$wAttrib.'="'.$size.'"';
477 } else { // Setting width by style-attribute. 'cols' MUST be avoided with NN6+
478 $pixels = ceil($size*$this->form_rowsToStylewidth);
479 $retVal = $styleOverride ? ' style="'.$styleOverride.'"' : ' style="width:'.$pixels.'px;"';
480 }
481 return $retVal;
482 }
483
484 /**
485 * This function is dedicated to textareas, which has the wrapping on/off option to observe.
486 * EXAMPLE:
487 * <textarea rows="10" wrap="off" '.$GLOBALS["TBE_TEMPLATE"]->formWidthText(48,"","off").'>
488 * or
489 * <textarea rows="10" wrap="virtual" '.$GLOBALS["TBE_TEMPLATE"]->formWidthText(48,"","virtual").'>
490 *
491 * @param integer A relative number which multiplied with approx. 10 will lead to the width in pixels
492 * @param string A string which will be returned as attribute-value for style="" instead of the calculated width (if CSS is enabled)
493 * @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.
494 * @return string Tag attributes for an <input> tag (regarding width)
495 * @see formWidth()
496 */
497 function formWidthText($size=48,$styleOverride='',$wrap='') {
498 $wTags = $this->formWidth($size,1,$styleOverride);
499 // 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...
500 if (strtolower(trim($wrap))!='off' && $GLOBALS['CLIENT']['BROWSER']=='net' && $GLOBALS['CLIENT']['VERSION']>=5) {
501 $wTags.=' cols="'.$size.'"';
502 }
503 return $wTags;
504 }
505
506 /**
507 * Returns JavaScript variables setting the returnUrl and thisScript location for use by JavaScript on the page.
508 * Used in fx. db_list.php (Web>List)
509 *
510 * @param string URL to "this location" / current script
511 * @return string
512 * @see typo3/db_list.php
513 */
514 function redirectUrls($thisLocation='') {
515 $thisLocation = $thisLocation?$thisLocation:t3lib_div::linkThisScript(
516 array(
517 'CB'=>'',
518 'SET'=>'',
519 'cmd' => '',
520 'popViewId'=>''
521 ));
522
523 $out ="
524 var T3_RETURN_URL = '".str_replace('%20','',rawurlencode(t3lib_div::_GP('returnUrl')))."';
525 var T3_THIS_LOCATION = '".str_replace('%20','',rawurlencode($thisLocation))."';
526 ";
527 return $out;
528 }
529
530 /**
531 * Returns a formatted string of $tstamp
532 * Uses $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'] and $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] to format date and time
533 *
534 * @param integer UNIX timestamp, seconds since 1970
535 * @param integer How much data to show: $type = 1: hhmm, $type = 10: ddmmmyy
536 * @return string Formatted timestamp
537 */
538 function formatTime($tstamp,$type) {
539 switch($type) {
540 case 1: return date($GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'],$tstamp); break;
541 case 10: return date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'],$tstamp); break;
542 }
543 }
544
545 /**
546 * Returns script parsetime IF ->parseTimeFlag is set and user is "admin"
547 * Automatically outputted in page end
548 *
549 * @return string
550 */
551 function parseTime() {
552 if ($this->parseTimeFlag && $GLOBALS['BE_USER']->isAdmin()) {
553 return '<p>(ParseTime: '.(t3lib_div::milliseconds()-$GLOBALS['PARSETIME_START']).' ms</p>
554 <p>REQUEST_URI-length: '.strlen(t3lib_div::getIndpEnv('REQUEST_URI')).')</p>';
555 }
556 }
557
558
559
560
561
562
563
564
565
566
567
568
569 /*****************************************
570 *
571 * PAGE BUILDING FUNCTIONS.
572 * Use this to build the HTML of your backend modules
573 *
574 *****************************************/
575
576 /**
577 * Returns page start
578 * This includes the proper header with charset, title, meta tag and beginning body-tag.
579 *
580 * @param string HTML Page title for the header
581 * @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)
582 * @see endPage()
583 */
584 function startPage($title) {
585 // Get META tag containing the currently selected charset for backend output. The function sets $this->charSet.
586 $charSet = $this->initCharset();
587 $generator = $this->generator();
588
589 // For debugging: If this outputs "QuirksMode"/"BackCompat" (IE) the browser runs in quirks-mode. Otherwise the value is "CSS1Compat"
590 # $this->JScodeArray[]='alert(document.compatMode);';
591
592 // Send HTTP header for selected charset. Added by Robert Lemke 23.10.2003
593 header ('Content-Type:text/html;charset='.$this->charset);
594
595 switch($this->docType) {
596 case 'xhtml_strict':
597 $headerStart= '<!DOCTYPE html
598 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
599 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
600 <?xml version="1.0" encoding="'.$this->charset.'"?>
601 <?xml-stylesheet href="#internalStyle" type="text/css"?>
602 ';
603 break;
604 case 'xhtml_trans':
605 $headerStart= '<!DOCTYPE html
606 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
607 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
608 <?xml version="1.0" encoding="'.$this->charset.'"?>
609 <?xml-stylesheet href="#internalStyle" type="text/css"?>
610 ';
611 break;
612 case 'xhtml_frames':
613 $headerStart= '<!DOCTYPE html
614 PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
615 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
616 <?xml version="1.0" encoding="'.$this->charset.'"?>
617 ';
618 break;
619 default:
620 $headerStart='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">';
621 break;
622 }
623
624 // Construct page header.
625 $str = $headerStart.'
626 <html>
627 <head>
628 <!-- TYPO3 Script ID: '.htmlspecialchars($this->scriptID).' -->
629 '.$charSet.'
630 '.$generator.'
631 <title>'.htmlspecialchars($title).'</title>
632 '.$this->docStyle().'
633 '.$this->JScode.'
634 '.$this->wrapScriptTags(implode("\n", $this->JScodeArray)).'
635 <!--###POSTJSMARKER###-->
636 </head>
637 ';
638 $this->JScode='';
639 $this->JScodeArray=array();
640
641 if ($this->docType=='xhtml_frames') {
642 return $str;
643 } else
644 $str.=$this->docBodyTagBegin().
645 ($this->divClass?'
646
647 <!-- Wrapping DIV-section for whole page BEGIN -->
648 <div class="'.$this->divClass.'">
649 ':'').trim($this->form);
650 return $str;
651 }
652
653 /**
654 * Returns page end; This includes finishing form, div, body and html tags.
655 *
656 * @return string The HTML end of a page
657 * @see startPage()
658 */
659 function endPage() {
660 $str = $this->sectionEnd().
661 $this->postCode.
662 $this->endPageJS().
663 t3lib_BEfunc::getSetUpdateSignal().
664 $this->parseTime().
665 ($this->form?'
666 </form>':'').
667 ($this->divClass?'
668
669 <!-- Wrapping DIV-section for whole page END -->
670 </div>':'').
671 '
672 </body>
673 </html> ';
674 return $str;
675 }
676
677 /**
678 * Returns the header-bar in the top of most backend modules
679 * Closes section if open.
680 *
681 * @param string The text string for the header
682 * @return string HTML content
683 */
684 function header($text) {
685 $str='
686
687 <!-- MAIN Header in page top -->
688 <h2>'.htmlspecialchars($text).'</h2>
689 ';
690 return $this->sectionEnd().$str;
691 }
692
693 /**
694 * Begins an output section and sets header and content
695 *
696 * @param string The header
697 * @param string The HTML-content
698 * @param boolean A flag that will prevent the header from being converted to uppercase
699 * @param boolean Defines the type of header (if set, "<h3>" rather than the default "h4")
700 * @param integer The number of an icon to show with the header (see the icon-function). -1,1,2,3
701 * @param boolean If set, HTML tags are allowed in $label (otherwise this value is by default htmlspecialchars()'ed)
702 * @return string HTML content
703 * @see icons(), sectionHeader()
704 */
705 function section($label,$text,$nostrtoupper=FALSE,$sH=FALSE,$type=0,$allowHTMLinHeader=FALSE) {
706 $str='';
707
708 // Setting header
709 if ($label) {
710 if (!$allowHTMLinHeader) $label = htmlspecialchars($label);
711 $str.=$this->sectionHeader($this->icons($type).$label, $sH, $nostrtoupper ? '' : ' class="uppercase"');
712 }
713 // Setting content
714 $str.='
715
716 <!-- Section content -->
717 '.$text;
718
719 return $this->sectionBegin().$str;
720 }
721
722 /**
723 * Inserts a divider image
724 * Ends a section (if open) before inserting the image
725 *
726 * @param integer The margin-top/-bottom of the <hr> ruler.
727 * @return string HTML content
728 */
729 function divider($dist) {
730 $dist = intval($dist);
731 $str='
732
733 <!-- DIVIDER -->
734 <hr style="margin-top: '.$dist.'px; margin-bottom: '.$dist.'px;" />
735 ';
736 return $this->sectionEnd().$str;
737 }
738
739 /**
740 * Returns a blank <div>-section with a height
741 *
742 * @param integer Padding-top for the div-section (should be margin-top but konquorer (3.1) don't like it :-(
743 * @return string HTML content
744 */
745 function spacer($dist) {
746 if ($dist>0) {
747 return '
748
749 <!-- Spacer element -->
750 <div style="padding-top: '.intval($dist).'px;"></div>
751 ';
752 }
753 }
754
755 /**
756 * Make a section header.
757 * Begins a section if not already open.
758 *
759 * @param string The label between the <h3> or <h4> tags. (Allows HTML)
760 * @param boolean If set, <h3> is used, otherwise <h4>
761 * @param string Additional attributes to h-tag, eg. ' class=""'
762 * @return string HTML content
763 */
764 function sectionHeader($label,$sH=FALSE,$addAttrib='') {
765 $tag = ($sH?'h3':'h4');
766 $str='
767
768 <!-- Section header -->
769 <'.$tag.$addAttrib.'>'.$label.'</'.$tag.'>
770 ';
771 return $this->sectionBegin().$str;
772 }
773
774 /**
775 * Begins an output section.
776 * Returns the <div>-begin tag AND sets the ->sectionFlag true (if the ->sectionFlag is not already set!)
777 * 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!
778 *
779 * @return string HTML content
780 */
781 function sectionBegin() {
782 if (!$this->sectionFlag) {
783 $this->sectionFlag=1;
784 $str='
785
786 <!-- ***********************
787 Begin output section.
788 *********************** -->
789 <div>
790 ';
791 return $str;
792 } else return '';
793 }
794
795 /**
796 * Ends and output section
797 * Returns the </div>-end tag AND clears the ->sectionFlag (but does so only IF the sectionFlag is set - that is a section is 'open')
798 * See sectionBegin() also.
799 *
800 * @return string HTML content
801 */
802 function sectionEnd() {
803 if ($this->sectionFlag) {
804 $this->sectionFlag=0;
805 return '
806 </div>
807 <!-- *********************
808 End output section.
809 ********************* -->
810 ';
811 } else return '';
812 }
813
814 /**
815 * Originally it printed a kind of divider.
816 * Depreciated. Just remove function calls to it or call the divider() function instead.
817 *
818 * @return void
819 * @internal
820 * @depreciated
821 */
822 function middle() {
823 }
824
825 /**
826 * If a form-tag is defined in ->form then and end-tag for that <form> element is outputted
827 * Further a JavaScript section is outputted which will update the top.busy session-expiry object (unless $this->endJS is set to false)
828 *
829 * @return string HTML content (<script> tag section)
830 */
831 function endPageJS() {
832 return ($this->endJS?'
833 <script type="text/javascript">
834 /*<![CDATA[*/
835 if (top.busy && top.busy.loginRefreshed) {
836 top.busy.loginRefreshed();
837 }
838 /*]]>*/
839 </script>':'');
840 }
841
842 /**
843 * Creates the bodyTag.
844 * You can add to the bodyTag by $this->bodyTagAdditions
845 *
846 * @return string HTML body tag
847 */
848 function docBodyTagBegin() {
849 $bodyContent = 'body '.trim($this->bodyTagAdditions.($this->bodyTagId ? ' id="'.$this->bodyTagId.'"' : ''));
850 return '<'.trim($bodyContent).'>';
851 }
852
853 /**
854 * Outputting document style
855 *
856 * @return string HTML style section/link tags
857 */
858 function docStyle() {
859
860 // Request background image:
861 if ($this->backGroundImage) {
862 $this->inDocStylesArray[]=' BODY { background-image: url('.$this->backPath.$this->backGroundImage.'); }';
863 }
864
865 // Add inDoc styles variables as well:
866 $this->inDocStylesArray[] = $this->inDocStyles;
867 $this->inDocStylesArray[] = $this->inDocStyles_TBEstyle;
868
869 // Implode it all:
870 $inDocStyles = implode('
871 ',$this->inDocStylesArray);
872
873 // The default color scheme should also in full be represented in the stylesheet.
874 $style=trim('
875 '.($this->styleSheetFile?'<link rel="stylesheet" type="text/css" href="'.$this->backPath.$this->styleSheetFile.'" />':'').'
876 '.($this->styleSheetFile2?'<link rel="stylesheet" type="text/css" href="'.$this->backPath.$this->styleSheetFile2.'" />':'').'
877 '.(trim($inDocStyles) ? '
878 <style type="text/css" id="internalStyle">
879 /*<![CDATA[*/
880 '.trim($inDocStyles).'
881 /*]]>*/
882 </style>' : '').'
883 '.($this->styleSheetFile_post?'<link rel="stylesheet" type="text/css" href="'.$this->backPath.$this->styleSheetFile_post.'" />':'')
884 )
885 ;
886 $this->inDocStyles='';
887 $this->inDocStylesArray=array();
888
889 return '
890 '.$style;
891 }
892
893 /**
894 * Insert post rendering document style into already rendered content
895 *
896 * @param string style-content to insert.
897 * @return string content with inserted styles
898 */
899 function insertStylesAndJS($content) {
900 // insert accumulated CSS
901 $this->inDocStylesArray[] = $this->inDocStyles;
902 $styles = "\n".implode("\n", $this->inDocStylesArray);
903 $content = str_replace('/*###POSTCSSMARKER###*/',$styles,$content);
904
905 // insert accumulated JS
906 $jscode = $this->JScode."\n".$this->wrapScriptTags(implode("\n", $this->JScodeArray));
907 $content = str_replace('<!--###POSTJSMARKER###-->',$jscode,$content);
908
909 return $content;
910 }
911
912 /**
913 * Initialize the charset.
914 * Sets the internal $this->charset variable to the charset defined in $GLOBALS["LANG"] (or the default as set in this class)
915 * Returns the meta-tag for the document header
916 *
917 * @return string <meta> tag with charset from $this->charset or $GLOBALS['LANG']->charSet
918 */
919 function initCharset() {
920 // Set charset to the charset provided by the current backend users language selection:
921 $this->charset = $GLOBALS['LANG']->charSet ? $GLOBALS['LANG']->charSet : $this->charset;
922 // Return meta tag:
923 return '<meta http-equiv="Content-Type" content="text/html; charset='.$this->charset.'" />';
924 }
925
926 /**
927 * Returns generator meta tag
928 *
929 * @return string <meta> tag with name "GENERATOR"
930 */
931 function generator() {
932 $str = 'TYPO3 '.$GLOBALS['TYPO_VERSION'].', http://typo3.com, &#169; Kasper Sk&#229;rh&#248;j 1998-2004, extensions are copyright of their respective owners.';
933 return '<meta name="GENERATOR" content="'.$str .'" />';
934 }
935
936
937
938
939
940
941
942
943 /*****************************************
944 *
945 * OTHER ELEMENTS
946 * Tables, buttons, formatting dimmed/red strings
947 *
948 ******************************************/
949
950
951 /**
952 * Returns an image-tag with an 18x16 icon of the following types:
953 *
954 * $type:
955 * -1: OK icon (Check-mark)
956 * 1: Notice (Speach-bubble)
957 * 2: Warning (Yellow triangle)
958 * 3: Fatal error (Red stop sign)
959 *
960 * @param integer See description
961 * @return string HTML image tag (if applicable)
962 */
963 function icons($type) {
964 switch($type) {
965 case '3':
966 $icon = 'gfx/icon_fatalerror.gif';
967 break;
968 case '2':
969 $icon = 'gfx/icon_warning.gif';
970 break;
971 case '1':
972 $icon = 'gfx/icon_note.gif';
973 break;
974 case '-1':
975 $icon = 'gfx/icon_ok.gif';
976 break;
977 default:
978 break;
979 }
980 if ($icon) {
981 return '<img'.t3lib_iconWorks::skinImg($this->backPath,$icon,'width="18" height="16"').' class="absmiddle" alt="" />';
982 }
983 }
984
985 /**
986 * Returns an <input> button with the $onClick action and $label
987 *
988 * @param string The value of the onclick attribute of the input tag (submit type)
989 * @param string The label for the button (which will be htmlspecialchar'ed)
990 * @return string A <input> tag of the type "submit"
991 */
992 function t3Button($onClick,$label) {
993 $button = '<input type="submit" onclick="'.htmlspecialchars($onClick).'; return false;" value="'.htmlspecialchars($label).'" />';
994 return $button;
995 }
996
997 /**
998 * dimmed-fontwrap. Returns the string wrapped in a <span>-tag defining the color to be gray/dimmed
999 *
1000 * @param string Input string
1001 * @return string Output string
1002 */
1003 function dfw($string) {
1004 return '<span class="typo3-dimmed">'.$string.'</span>';
1005 }
1006
1007 /**
1008 * red-fontwrap. Returns the string wrapped in a <span>-tag defining the color to be red
1009 *
1010 * @param string Input string
1011 * @return string Output string
1012 */
1013 function rfw($string) {
1014 return '<span class="typo3-red">'.$string.'</span>';
1015 }
1016
1017 /**
1018 * Returns string wrapped in CDATA "tags" for XML / XHTML (wrap content of <script> and <style> sections in those!)
1019 *
1020 * @param string Input string
1021 * @return string Output string
1022 */
1023 function wrapInCData($string) {
1024 $string = '/*<![CDATA[*/'.
1025 $string.
1026 '/*]]>*/';
1027
1028 return $string;
1029 }
1030
1031 /**
1032 * Wraps the input string in script tags.
1033 * Automatic re-identing of the JS code is done by using the first line as ident reference.
1034 * This is nice for identing JS code with PHP code on the same level.
1035 *
1036 * @param string Input string
1037 * @param boolean Wrap script element in linebreaks? Default is TRUE.
1038 * @return string Output string
1039 */
1040 function wrapScriptTags($string, $linebreak=TRUE) {
1041 if(trim($string)) {
1042 // <script wrapped in nl?
1043 $cr = $linebreak? "\n" : '';
1044
1045 // remove nl from the beginning
1046 $string = preg_replace ('/^\n+/', '', $string);
1047 // re-ident to one tab using the first line as reference
1048 if(preg_match('/^(\t+)/',$string,$match)) {
1049 $string = str_replace($match[1],"\t", $string);
1050 }
1051 $string = $cr.'<script type="text/javascript">
1052 /*<![CDATA[*/
1053 '.$string.'
1054 /*]]>*/
1055 </script>'.$cr;
1056 }
1057 return trim($string);
1058 }
1059
1060 // These vars defines the layout for the table produced by the table() function.
1061 // You can override these values from outside if you like.
1062 var $tableLayout = Array (
1063 'defRow' => Array (
1064 'defCol' => Array('<td valign="top">','</td>')
1065 )
1066 );
1067 var $table_TR = '<tr>';
1068 var $table_TABLE = '<table border="0" cellspacing="0" cellpadding="0" id="typo3-tmpltable">';
1069
1070 /**
1071 * Returns a table based on the input $arr
1072 *
1073 * @param array Multidim array with first levels = rows, second levels = cells
1074 * @return string The HTML table.
1075 * @internal
1076 */
1077 function table($arr) {
1078 if (is_array($arr)) {
1079 reset($arr);
1080 $code='';
1081 $rc=0;
1082 while(list(,$val)=each($arr)) {
1083 if ($rc % 2) {
1084 $layout = is_array($this->tableLayout['defRowOdd']) ? $this->tableLayout['defRowOdd'] : $this->tableLayout['defRow'];
1085 } else {
1086 $layout = is_array($this->tableLayout['defRowEven']) ? $this->tableLayout['defRowEven'] : $this->tableLayout['defRow'];
1087 }
1088 $layout = is_array($this->tableLayout[$rc]) ? $this->tableLayout[$rc] : $layout;
1089 $code_td='';
1090 if (is_array($val)) {
1091 $cc=0;
1092 while(list(,$content)=each($val)) {
1093 $wrap= is_array($layout[$cc]) ? $layout[$cc] : $layout['defCol'];
1094 $code_td.=$wrap[0].$content.$wrap[1];
1095 $cc++;
1096 }
1097 }
1098 $trWrap = is_array($layout['tr']) ? $layout['tr'] : array($this->table_TR, '</tr>');
1099 $code.=$trWrap[0].$code_td.$trWrap[1];
1100 $rc++;
1101 }
1102 $tableWrap = is_array($this->tableLayout['table']) ? $this->tableLayout['table'] : array($this->table_TABLE, '</table>');
1103 $code=$tableWrap[0].$code.$tableWrap[1];
1104 }
1105 return $code;
1106 }
1107
1108 /**
1109 * Constructs a table with content from the $arr1, $arr2 and $arr3.
1110 * Used in eg. ext/belog/mod/index.php - refer to that for examples
1111 *
1112 * @param array Menu elements on first level
1113 * @param array Secondary items
1114 * @param array Third-level items
1115 * @return string HTML content, <table>...</table>
1116 */
1117 function menuTable($arr1,$arr2=array(), $arr3=array()) {
1118 $rows = max(array(count($arr1),count($arr2),count($arr3)));
1119
1120 $menu='
1121 <table border="0" cellpadding="0" cellspacing="0" id="typo3-tablemenu">';
1122 for($a=0;$a<$rows;$a++) {
1123 $menu.='<tr>';
1124 $cls=array();
1125 $valign='middle';
1126 $cls[]='<td valign="'.$valign.'">'.$arr1[$a][0].'</td><td>'.$arr1[$a][1].'</td>';
1127 if (count($arr2)) {
1128 $cls[]='<td valign="'.$valign.'">'.$arr2[$a][0].'</td><td>'.$arr2[$a][1].'</td>';
1129 if (count($arr3)) {
1130 $cls[]='<td valign="'.$valign.'">'.$arr3[$a][0].'</td><td>'.$arr3[$a][1].'</td>';
1131 }
1132 }
1133 $menu.=implode($cls,'<td>&nbsp;&nbsp;</td>');
1134 $menu.='</tr>';
1135 }
1136 $menu.='
1137 </table>
1138 ';
1139 return $menu;
1140 }
1141
1142 /**
1143 * Returns a one-row/two-celled table with $content and $menu side by side.
1144 * The table is a 100% width table and each cell is aligned left / right
1145 *
1146 * @param string Content cell content (left)
1147 * @param string Menu cell content (right)
1148 * @return string HTML output
1149 */
1150 function funcMenu($content,$menu) {
1151 return '
1152 <table border="0" cellpadding="0" cellspacing="0" width="100%" id="typo3-funcmenu">
1153 <tr>
1154 <td valign="top" nowrap="nowrap">'.$content.'</td>
1155 <td valign="top" align="right" nowrap="nowrap">'.$menu.'</td>
1156 </tr>
1157 </table>';
1158 }
1159
1160 /**
1161 * Creates a selector box with clear-cache items.
1162 * Rather specialized functions - at least don't use it with $addSaveOptions unless you know what you do...
1163 *
1164 * @param integer The page uid of the "current page" - the one that will be cleared as "clear cache for this page".
1165 * @param boolean If $addSaveOptions is set, then also the array of save-options for TCE_FORMS will appear.
1166 * @return string <select> tag with content - a selector box for clearing the cache
1167 */
1168 function clearCacheMenu($id,$addSaveOptions=0) {
1169 global $BE_USER;
1170 $opt=$addOptions;
1171 if ($addSaveOptions) {
1172 $opt[]='<option value="">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.menu',1).'</option>';
1173 $opt[]='<option value="TBE_EDITOR_checkAndDoSubmit(1);">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.saveDoc',1).'</option>';
1174 $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>';
1175 if ($BE_USER->uc['allSaveFunctions']) $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>';
1176 $opt[]='<option value="document.editform.closeDoc.value=2; document.editform.submit();">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.closeDoc',1).'</option>';
1177 $opt[]='<option value="document.editform.closeDoc.value=3; document.editform.submit();">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.closeAllDocs',1).'</option>';
1178 $opt[]='<option value=""></option>';
1179 }
1180 $opt[]='<option value="">[ '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.clearCache_clearCache',1).' ]</option>';
1181 if ($id) $opt[]='<option value="'.$id.'">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.clearCache_thisPage',1).'</option>';
1182 if ($BE_USER->isAdmin() || $BE_USER->getTSConfigVal('options.clearCache.pages')) $opt[]='<option value="pages">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.clearCache_pages',1).'</option>';
1183 if ($BE_USER->isAdmin() || $BE_USER->getTSConfigVal('options.clearCache.all')) $opt[]='<option value="all">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.clearCache_all',1).'</option>';
1184
1185 $onChange = 'if (!this.options[this.selectedIndex].value) {
1186 this.selectedIndex=0;
1187 } else if (this.options[this.selectedIndex].value.indexOf(\';\')!=-1) {
1188 eval(this.options[this.selectedIndex].value);
1189 }else{
1190 document.location=\''.$this->backPath.'tce_db.php?vC='.$BE_USER->veriCode().'&redirect='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')).'&cacheCmd=\'+this.options[this.selectedIndex].value;
1191 }';
1192 $af_content = '<select name="cacheCmd" onchange="'.htmlspecialchars($onChange).'">'.implode('',$opt).'</select>';
1193
1194 if (count($opt)>2) {
1195 return $af_content;
1196 }
1197 }
1198
1199 /**
1200 * Returns an array with parts (JavaScript, init-functions, <div>-layers) for use on pages which displays the clickmenu layers (context sensitive menus)
1201 *
1202 * @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] = Two empty <div> layers for the context menu
1203 */
1204 function getContextMenuCode() {
1205 if ($this->isCMlayers()) {
1206 $content='
1207 <script type="text/javascript">
1208 /*<![CDATA[*/
1209 var GLV_gap=10;
1210 var GLV_curLayerX=new Array(0,0);
1211 var GLV_curLayerY=new Array(0,0);
1212 var GLV_curLayerWidth=new Array(0,0);
1213 var GLV_curLayerHeight=new Array(0,0);
1214 var GLV_isVisible=new Array(0,0);
1215 var GLV_x=0;
1216 var GLV_y=0;
1217 var GLV_xRel=0;
1218 var GLV_yRel=0;
1219 var layerObj=new Array();
1220 var layerObjCss=new Array();
1221
1222 //browsercheck...
1223 function GL_checkBrowser(){ //
1224 this.dom= (document.getElementById);
1225 this.op= (navigator.userAgent.indexOf("Opera")>-1);
1226 this.op7= this.op && (navigator.appVersion.indexOf("7")>-1); // check for Opera version 7
1227 this.konq= (navigator.userAgent.indexOf("Konq")>-1);
1228 this.ie4= (document.all && !this.dom && !this.op && !this.konq);
1229 this.ie5= (document.all && this.dom && !this.op && !this.konq);
1230 this.ns4= (document.layers && !this.dom && !this.konq);
1231 this.ns5= (!document.all && this.dom && !this.op && !this.konq);
1232 this.ns6= (this.ns5);
1233 this.bw= (this.ie4 || this.ie5 || this.ns4 || this.ns6 || this.op || this.konq);
1234 return this;
1235 }
1236 bw= new GL_checkBrowser();
1237
1238 // GL_getObj(obj)
1239 function GL_getObj(obj){ //
1240 nest="";
1241 this.el= (bw.ie4||bw.op7)?document.all[obj]:bw.ns4?eval(nest+"document."+obj):document.getElementById(obj);
1242 this.css= bw.ns4?this.el:this.el.style;
1243 this.ref= bw.ns4?this.el.document:document;
1244 this.x= (bw.ns4||bw.op)?this.css.left:this.el.offsetLeft;
1245 this.y= (bw.ns4||bw.op)?this.css.top:this.el.offsetTop;
1246 this.height= (bw.ie4||bw.ie5||bw.ns6||this.konq||bw.op7)?this.el.offsetHeight:bw.ns4?this.ref.height:bw.op?this.css.pixelHeight:0;
1247 this.width= (bw.ie4||bw.ie5||bw.ns6||this.konq||bw.op7)?this.el.offsetWidth:bw.ns4?this.ref.width:bw.op?this.css.pixelWidth:0;
1248 return this;
1249 }
1250 // GL_getObjCss(obj)
1251 function GL_getObjCss(obj){ //
1252 return bw.dom? document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?document.layers[obj]:0;
1253 }
1254 // GL_getMouse(event)
1255 function GL_getMouse(event) { //
1256 if (layerObj) {
1257 // GLV_x= (bw.ns4||bw.ns5)?event.pageX:(bw.ie4||bw.op)?event.clientX:(event.clientX-2)+document.body.scrollLeft;
1258 // GLV_y= (bw.ns4||bw.ns5)?event.pageY:(bw.ie4||bw.op)?event.clientY:(event.clientY-2)+document.body.scrollTop;
1259 // 17/12 2003: When documents run in XHTML standard compliance mode, the old scrollLeft/Top properties of document.body is gone - and for Opera/MSIE we have to use document.documentElement:
1260
1261 GLV_xRel = event.clientX-2;
1262 GLV_yRel = event.clientY-2;
1263 GLV_x = GLV_xRel + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
1264 GLV_y = GLV_yRel + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
1265
1266 // status = (GLV_x+GLV_gap-GLV_curLayerX[0]) + " | " + (GLV_y+GLV_gap-GLV_curLayerY[0]);
1267 if (GLV_isVisible[1]) {
1268 if (outsideLayer(1)) hideSpecific(1);
1269 } else if (GLV_isVisible[0]) {
1270 if (outsideLayer(0)) hideSpecific(0);
1271 }
1272 }
1273 }
1274 // outsideLayer(level)
1275 function outsideLayer(level) { //
1276 return GLV_x+GLV_gap-GLV_curLayerX[level] <0 ||
1277 GLV_y+GLV_gap-GLV_curLayerY[level] <0 ||
1278 GLV_curLayerX[level]+GLV_curLayerWidth[level]+GLV_gap-GLV_x <0 ||
1279 GLV_curLayerY[level]+GLV_curLayerHeight[level]+GLV_gap-GLV_y <0;
1280 }
1281 // setLayerObj(html,level)
1282 function setLayerObj(html,level) { //
1283 var tempLayerObj = GL_getObj("contentMenu"+level);
1284 var tempLayerObjCss = GL_getObjCss("contentMenu"+level);
1285
1286 if (tempLayerObj && (level==0 || GLV_isVisible[level-1])) {
1287 tempLayerObj.el.innerHTML = html;
1288 tempLayerObj.width= (bw.ie4||bw.ie5||bw.ns6||bw.konq||bw.op7)?this.el.offsetWidth:bw.ns4?this.ref.width:bw.op?this.css.pixelWidth:0;
1289 tempLayerObj.height= (bw.ie4||bw.ie5||bw.ns6||bw.konq||bw.op7)?this.el.offsetHeight:bw.ns4?this.ref.height:bw.op?this.css.pixelHeight:0;
1290
1291 // Adjusting the Y-height of the layer to fit it into the window frame if it goes under the window frame in the bottom:
1292 tempLayerObj.winHeight = document.documentElement.clientHeight && !bw.op7 ? document.documentElement.clientHeight : document.body.clientHeight;
1293 if (tempLayerObj.winHeight-tempLayerObj.height < GLV_yRel) {
1294 if (GLV_yRel < tempLayerObj.height) {
1295 GLV_y+= (tempLayerObj.winHeight-tempLayerObj.height-GLV_yRel); // Setting it so bottom is just above window height.
1296 } else {
1297 GLV_y-= tempLayerObj.height-8; // Showing the menu upwards
1298 }
1299 }
1300
1301 GLV_curLayerX[level] = GLV_x;
1302 GLV_curLayerY[level] = GLV_y;
1303 tempLayerObjCss.left = GLV_x+"px";
1304 tempLayerObjCss.top = GLV_y+"px";
1305 tempLayerObjCss.visibility = "visible";
1306 if (bw.ie5) showHideSelectorBoxes("hidden");
1307
1308 GLV_isVisible[level]=1;
1309 GLV_curLayerWidth[level] = tempLayerObj.width;
1310 GLV_curLayerHeight[level] = tempLayerObj.height;
1311 }
1312 }
1313 // hideEmpty()
1314 function hideEmpty() { //
1315 hideSpecific(0);
1316 hideSpecific(1);
1317 return false;
1318 }
1319 // hideSpecific(level)
1320 function hideSpecific(level) { //
1321 GL_getObjCss("contentMenu"+level).visibility = "hidden";
1322 GL_getObj("contentMenu"+level).el.innerHTML = "";
1323 GLV_isVisible[level]=0;
1324
1325 if (bw.ie5 && level==0) showHideSelectorBoxes("visible");
1326 }
1327 // debugObj(obj,name)
1328 function debugObj(obj,name) { //
1329 var acc;
1330 for (i in obj) {if (obj[i]) {acc+=i+": "+obj[i]+"\n";}}
1331 alert("Object: "+name+"\n\n"+acc);
1332 }
1333 // initLayer()
1334 function initLayer(){ //
1335 if (document.all) {
1336 window.onmousemove=GL_getMouse;
1337 }
1338 layerObj = GL_getObj("contentMenu1");
1339 layerObjCss = GL_getObjCss("contentMenu1");
1340 }
1341 function showHideSelectorBoxes(action) { // This function by Michiel van Leening
1342 for (i=0;i<document.forms.length;i++) {
1343 for (j=0;j<document.forms[i].elements.length;j++) {
1344 if(document.forms[i].elements[j].type=="select-one") {
1345 document.forms[i].elements[j].style.visibility=action;
1346 }
1347 }
1348 }
1349 }
1350 /*]]>*/
1351 </script>
1352 ';
1353 return array(
1354 $content,
1355 ' onmousemove="GL_getMouse(event);" onload="initLayer();"',
1356 '<div id="contentMenu0" style="z-index:1; position:absolute;visibility:hidden"></div><div id="contentMenu1" style="z-index:2; position:absolute;visibility:hidden"></div>'
1357 );
1358 } else return array('','','');
1359 }
1360
1361
1362
1363
1364 /**
1365 * creates a tab menu from an array definition
1366 *
1367 * Returns a tab menu for a module
1368 * Requires the JS function jumpToUrl() to be available
1369 *
1370 * @param string $id is the "&id=" parameter value to be sent to the module
1371 * @param string $elementName it the form elements name, probably something like "SET[...]"
1372 * @param string $currentValue is the value to be selected currently.
1373 * @param array $menuItems is an array with the menu items for the selector box
1374 * @param string $script is the script to send the &id to, if empty it's automatically found
1375 * @param string $addParams is additional parameters to pass to the script.
1376 * @return string HTML code for tab menu
1377 * @todo Update the HTML code to use the stylesheet.css instead.
1378 * @author René Fritz <r.fritz@colorcube.de>
1379 */
1380 function getTabMenu($id,$elementName,$currentValue,$menuItems,$script='',$addparams='') {
1381 $content='';
1382
1383 if (is_array($menuItems)) {
1384 if (!$script) {$script=basename(PATH_thisScript);}
1385 $options='';
1386
1387 $count = count($menuItems);
1388 $widthLeft = 1;
1389 $addToAct = 5;
1390
1391 $widthRight = max (1,floor(30-pow($count,1.72)));
1392 $widthTabs = 100 - $widthRight - $widthLeft;
1393 $widthNo = floor(($widthTabs - $addToAct)/$count);
1394 $addToAct = max ($addToAct,$widthTabs-($widthNo*$count));
1395 $widthAct = $widthNo + $addToAct;
1396 $widthRight = 100 - ($widthLeft + ($count*$widthNo) + $addToAct);
1397
1398 $first=true;
1399 foreach($menuItems as $value => $label) {
1400 $isActive = !strcmp($currentValue,$value);
1401 $class = $isActive ? "tabact" : "tab";
1402 $width = $isActive ? $widthAct : $widthNo;
1403
1404 $label = t3lib_div::deHSCentities(htmlspecialchars($label));
1405 $link = htmlspecialchars($script.'?id='.rawurlencode($id).$addparams.'&'.$elementName.'='.$value);
1406 if($first) {
1407 $options.= '
1408 <td width="'.$width.'%" class="'.$class.'" style="border-left: solid #000 1px;"><a href="'.$link.'" class="'.$class.'" style="padding-left:5px;padding-right:2px;">'.$label.'</a></td>';
1409 } else {
1410 $options.='
1411 <td width="'.$width.'%" class="'.$class.'"><a href="'.$link.'" class="'.$class.'">'.$label.'</a></td>';
1412 }
1413 $first=false;
1414 }
1415
1416 if ($options) {
1417 $content .= '
1418 <!-- Tab menu -->
1419 <table cellpadding="0" cellspacing="0" border="0" width="100%" id="typo3-tabmenu">
1420 <tr>
1421 <td width="'.$widthLeft.'%">&nbsp;</td>
1422 '.$options.'
1423 <td width="'.$widthRight.'%">&nbsp;</td>
1424 </tr>
1425 </table>
1426 <div class="hr" style="display:block;margin:0px;padding:0px;"></div>';
1427 }
1428
1429 // include CSS
1430 $actBgColor = t3lib_div::modifyHTMLcolorAll($this->bgColor6,0);
1431 $lgBgColor = t3lib_div::modifyHTMLcolorAll($this->bgColor5,25);
1432 $hoverBgColor = t3lib_div::modifyHTMLcolorAll($this->bgColor6,15);
1433
1434 $this->inDocStylesArray['getTabMenu'] = '
1435 td.tabact {
1436 border: solid black 1px;
1437 background: '.$actBgColor.';
1438 color:#000;
1439 }
1440 td.tabact>a {
1441 color:#000;
1442 }
1443 td.tab {
1444 border: solid #555 1px;
1445 border-left: solid #aaa 3px;
1446 background: '.$lgBgColor.';
1447 color:grey;
1448 }
1449 td.tab, td.tabact {
1450 border-bottom: none;
1451 border-radius: 3px;
1452 -moz-border-radius: 3px;
1453 }
1454 a.tab, a.tabact {
1455 color:grey;
1456 text-decoration:none;
1457 display: block;
1458 width:auto;
1459 padding:2px;
1460 padding-left:3px;
1461 padding-right:5px;
1462 }
1463 a.tabact {
1464 padding-left:10px;
1465 padding-right:10px;
1466 }
1467 a.tab:hover,a.tabact:hover {
1468 color:black;
1469 background: '.$hoverBgColor.';
1470 text-decoration:none;
1471 cursor: pointer;
1472 }';
1473 }
1474 return $content;
1475 }
1476 }
1477
1478
1479
1480 // ******************************
1481 // Extension classes of the template class.
1482 // These are meant to provide backend screens with different widths.
1483 // They still do because of the different class-prefixes used for the <div>-sections
1484 // but obviously the final width is determined by the stylesheet used.
1485 // ******************************
1486
1487 /**
1488 * 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
1489 * The class were more significant in the past than today.
1490 *
1491 */
1492 class bigDoc extends template {
1493 var $divClass = 'typo3-bigDoc';
1494 }
1495
1496 /**
1497 * Extension class for "template" - used for backend pages without the "document" background image
1498 * The class were more significant in the past than today.
1499 *
1500 */
1501 class noDoc extends template {
1502 var $divClass = 'typo3-noDoc';
1503 }
1504
1505 /**
1506 * 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)
1507 * The class were more significant in the past than today.
1508 *
1509 */
1510 class smallDoc extends template {
1511 var $divClass = 'typo3-smallDoc';
1512 }
1513
1514 /**
1515 * 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.
1516 * The class were more significant in the past than today. But probably you should use this one for most modules you make.
1517 *
1518 */
1519 class mediumDoc extends template {
1520 var $divClass = 'typo3-mediumDoc';
1521 }
1522
1523
1524
1525 // Include extension to the template class?
1526 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/template.php']) {
1527 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/template.php']);
1528 }
1529
1530
1531
1532 // ******************************************************
1533 // The backend language engine is started (ext: "lang")
1534 // ******************************************************
1535 require_once(PATH_typo3.'sysext/lang/lang.php');
1536 $LANG = t3lib_div::makeInstance('language');
1537 $LANG->init($BE_USER->uc['lang']);
1538
1539
1540
1541 // ******************************
1542 // The template is loaded
1543 // ******************************
1544 $TBE_TEMPLATE = t3lib_div::makeInstance('template');
1545 ?>