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