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