RFC #7262: Fixing docheader in the backend modules
[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 HTML 4. You can also set it to 'strict', 'xhtml_trans', 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,$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 // Get META tag containing the currently selected charset for backend output. The function sets $this->charSet.
612 $charSet = $this->initCharset();
613 $generator = $this->generator();
614
615 // For debugging: If this outputs "QuirksMode"/"BackCompat" (IE) the browser runs in quirks-mode. Otherwise the value is "CSS1Compat"
616 # $this->JScodeArray[]='alert(document.compatMode);';
617
618 // Send HTTP header for selected charset. Added by Robert Lemke 23.10.2003
619 header ('Content-Type:text/html;charset='.$this->charset);
620
621 switch($this->docType) {
622 case 'xhtml_strict':
623 $headerStart= '<!DOCTYPE html
624 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
625 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
626 <?xml version="1.0" encoding="'.$this->charset.'"?>
627 <?xml-stylesheet href="#internalStyle" type="text/css"?>
628 ';
629 break;
630 case 'xhtml_trans':
631 $headerStart= '<!DOCTYPE html
632 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
633 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
634 <?xml version="1.0" encoding="'.$this->charset.'"?>
635 <?xml-stylesheet href="#internalStyle" type="text/css"?>
636 ';
637 break;
638 case 'xhtml_frames':
639 $headerStart= '<!DOCTYPE html
640 PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
641 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
642 <?xml version="1.0" encoding="'.$this->charset.'"?>
643 ';
644 break;
645 default:
646 $headerStart='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">';
647 break;
648 }
649
650 $tabJScode = '';
651 if (!$GLOBALS['BE_USER']->uc['disableTabInTextarea']) {
652 // This loads the tabulator-in-textarea feature. It automatically modifies every textarea which is found.
653 $tabJScode = '<script src="'.$this->backPath.'tab.js" type="text/javascript"></script>';
654 }
655
656 // Construct page header.
657 $str = $headerStart.'
658 <html>
659 <head>
660 <!-- TYPO3 Script ID: '.htmlspecialchars($this->scriptID).' -->
661 '.$charSet.'
662 '.$generator.'
663 <title>'.htmlspecialchars($title).'</title>
664 '.$this->docStyle().'
665 '.implode("\n", $this->JScodeLibArray).'
666 '.$this->JScode.'
667 '.$tabJScode.'
668 '.$this->wrapScriptTags(implode("\n", $this->JScodeArray)).'
669 <!--###POSTJSMARKER###-->
670 </head>
671 ';
672 $this->JScodeLibArray=array();
673 $this->JScode='';
674 $this->JScodeArray=array();
675
676 if ($this->docType=='xhtml_frames') {
677 return $str;
678 } else
679 $str.=$this->docBodyTagBegin().
680 ($this->divClass?'
681
682 <!-- Wrapping DIV-section for whole page BEGIN -->
683 <div class="'.$this->divClass.'">
684 ':'').trim($this->form);
685 return $str;
686 }
687
688 /**
689 * Returns page end; This includes finishing form, div, body and html tags.
690 *
691 * @return string The HTML end of a page
692 * @see startPage()
693 */
694 function endPage() {
695 $str = $this->sectionEnd().
696 $this->postCode.
697 $this->endPageJS().
698 t3lib_BEfunc::getSetUpdateSignal().
699 $this->parseTime().
700 ($this->form?'
701 </form>':'');
702
703 if ($this->docType!='xhtml_frames') {
704
705 $str .= ($this->divClass?'
706
707 <!-- Wrapping DIV-section for whole page END -->
708 </div>':'').'
709 </body> ';
710
711 }
712
713 $str .= '</html>';
714
715 // Logging: Can't find better place to put it:
716 if (TYPO3_DLOG) t3lib_div::devLog('END of BACKEND session','',0,array('_FLUSH'=>TRUE));
717
718 return $str;
719 }
720
721 /**
722 * Returns the header-bar in the top of most backend modules
723 * Closes section if open.
724 *
725 * @param string The text string for the header
726 * @return string HTML content
727 */
728 function header($text) {
729 $str='
730
731 <!-- MAIN Header in page top -->
732 <h2>'.htmlspecialchars($text).'</h2>
733 ';
734 return $this->sectionEnd().$str;
735 }
736
737 /**
738 * Begins an output section and sets header and content
739 *
740 * @param string The header
741 * @param string The HTML-content
742 * @param boolean A flag that will prevent the header from being converted to uppercase
743 * @param boolean Defines the type of header (if set, "<h3>" rather than the default "h4")
744 * @param integer The number of an icon to show with the header (see the icon-function). -1,1,2,3
745 * @param boolean If set, HTML tags are allowed in $label (otherwise this value is by default htmlspecialchars()'ed)
746 * @return string HTML content
747 * @see icons(), sectionHeader()
748 */
749 function section($label,$text,$nostrtoupper=FALSE,$sH=FALSE,$type=0,$allowHTMLinHeader=FALSE) {
750 $str='';
751
752 // Setting header
753 if ($label) {
754 if (!$allowHTMLinHeader) $label = htmlspecialchars($label);
755 $str.=$this->sectionHeader($this->icons($type).$label, $sH, $nostrtoupper ? '' : ' class="uppercase"');
756 }
757 // Setting content
758 $str.='
759
760 <!-- Section content -->
761 '.$text;
762
763 return $this->sectionBegin().$str;
764 }
765
766 /**
767 * Inserts a divider image
768 * Ends a section (if open) before inserting the image
769 *
770 * @param integer The margin-top/-bottom of the <hr> ruler.
771 * @return string HTML content
772 */
773 function divider($dist) {
774 $dist = intval($dist);
775 $str='
776
777 <!-- DIVIDER -->
778 <hr style="margin-top: '.$dist.'px; margin-bottom: '.$dist.'px;" />
779 ';
780 return $this->sectionEnd().$str;
781 }
782
783 /**
784 * Returns a blank <div>-section with a height
785 *
786 * @param integer Padding-top for the div-section (should be margin-top but konqueror (3.1) doesn't like it :-(
787 * @return string HTML content
788 */
789 function spacer($dist) {
790 if ($dist>0) {
791 return '
792
793 <!-- Spacer element -->
794 <div style="padding-top: '.intval($dist).'px;"></div>
795 ';
796 }
797 }
798
799 /**
800 * Make a section header.
801 * Begins a section if not already open.
802 *
803 * @param string The label between the <h3> or <h4> tags. (Allows HTML)
804 * @param boolean If set, <h3> is used, otherwise <h4>
805 * @param string Additional attributes to h-tag, eg. ' class=""'
806 * @return string HTML content
807 */
808 function sectionHeader($label,$sH=FALSE,$addAttrib='') {
809 $tag = ($sH?'h3':'h4');
810 $str='
811
812 <!-- Section header -->
813 <'.$tag.$addAttrib.'>'.$label.'</'.$tag.'>
814 ';
815 return $this->sectionBegin().$str;
816 }
817
818 /**
819 * Begins an output section.
820 * Returns the <div>-begin tag AND sets the ->sectionFlag true (if the ->sectionFlag is not already set!)
821 * 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!
822 *
823 * @return string HTML content
824 */
825 function sectionBegin() {
826 if (!$this->sectionFlag) {
827 $this->sectionFlag=1;
828 $str='
829
830 <!-- ***********************
831 Begin output section.
832 *********************** -->
833 <div>
834 ';
835 return $str;
836 } else return '';
837 }
838
839 /**
840 * Ends and output section
841 * Returns the </div>-end tag AND clears the ->sectionFlag (but does so only IF the sectionFlag is set - that is a section is 'open')
842 * See sectionBegin() also.
843 *
844 * @return string HTML content
845 */
846 function sectionEnd() {
847 if ($this->sectionFlag) {
848 $this->sectionFlag=0;
849 return '
850 </div>
851 <!-- *********************
852 End output section.
853 ********************* -->
854 ';
855 } else return '';
856 }
857
858 /**
859 * Originally it printed a kind of divider.
860 * Deprecated. Just remove function calls to it or call the divider() function instead.
861 *
862 * @return void
863 * @internal
864 * @deprecated
865 */
866 function middle() {
867 }
868
869 /**
870 * If a form-tag is defined in ->form then and end-tag for that <form> element is outputted
871 * Further a JavaScript section is outputted which will update the top.busy session-expiry object (unless $this->endJS is set to false)
872 *
873 * @return string HTML content (<script> tag section)
874 */
875 function endPageJS() {
876 return ($this->endJS?'
877 <script type="text/javascript">
878 /*<![CDATA[*/
879 if (top.busy && top.busy.loginRefreshed) {
880 top.busy.loginRefreshed();
881 }
882 /*]]>*/
883 </script>':'');
884 }
885
886 /**
887 * Creates the bodyTag.
888 * You can add to the bodyTag by $this->bodyTagAdditions
889 *
890 * @return string HTML body tag
891 */
892 function docBodyTagBegin() {
893 $bodyContent = 'body onclick="if (top.menuReset) top.menuReset();" '.trim($this->bodyTagAdditions.($this->bodyTagId ? ' id="'.$this->bodyTagId.'"' : ''));
894 return '<'.trim($bodyContent).'>';
895 }
896
897 /**
898 * Outputting document style
899 *
900 * @return string HTML style section/link tags
901 */
902 function docStyle() {
903
904 // Request background image:
905 if ($this->backGroundImage) {
906 $this->inDocStylesArray[]=' BODY { background-image: url('.$this->backPath.$this->backGroundImage.'); }';
907 }
908
909 // Add inDoc styles variables as well:
910 $this->inDocStylesArray[] = $this->inDocStyles;
911 $this->inDocStylesArray[] = $this->inDocStyles_TBEstyle;
912
913 // Implode it all:
914 $inDocStyles = implode('
915 ',$this->inDocStylesArray);
916
917 // The default color scheme should also in full be represented in the stylesheet.
918 $style=trim('
919 '.($this->styleSheetFile?'<link rel="stylesheet" type="text/css" href="'.$this->backPath.$this->styleSheetFile.'" />':'').'
920 '.($this->styleSheetFile2?'<link rel="stylesheet" type="text/css" href="'.$this->backPath.$this->styleSheetFile2.'" />':'').'
921 <style type="text/css" id="internalStyle">
922 /*<![CDATA[*/
923 '.trim($inDocStyles).'
924 /*###POSTCSSMARKER###*/
925 /*]]>*/
926 </style>
927 '.($this->styleSheetFile_post?'<link rel="stylesheet" type="text/css" href="'.$this->backPath.$this->styleSheetFile_post.'" />':'')
928 )
929 ;
930 $this->inDocStyles='';
931 $this->inDocStylesArray=array();
932
933 return '
934 '.$style;
935 }
936
937 /**
938 * Insert post rendering document style into already rendered content
939 * This is needed for extobjbase
940 *
941 * @param string style-content to insert.
942 * @return string content with inserted styles
943 */
944 function insertStylesAndJS($content) {
945 // insert accumulated CSS
946 $this->inDocStylesArray[] = $this->inDocStyles;
947 $styles = "\n".implode("\n", $this->inDocStylesArray);
948 $content = str_replace('/*###POSTCSSMARKER###*/',$styles,$content);
949
950 // insert accumulated JS
951 $jscode = $this->JScode."\n".$this->wrapScriptTags(implode("\n", $this->JScodeArray));
952 $content = str_replace('<!--###POSTJSMARKER###-->',$jscode,$content);
953
954 return $content;
955 }
956
957 /**
958 * Initialize the charset.
959 * Sets the internal $this->charset variable to the charset defined in $GLOBALS["LANG"] (or the default as set in this class)
960 * Returns the meta-tag for the document header
961 *
962 * @return string <meta> tag with charset from $this->charset or $GLOBALS['LANG']->charSet
963 */
964 function initCharset() {
965 // Set charset to the charset provided by the current backend users language selection:
966 $this->charset = $GLOBALS['LANG']->charSet ? $GLOBALS['LANG']->charSet : $this->charset;
967 // Return meta tag:
968 return '<meta http-equiv="Content-Type" content="text/html; charset='.$this->charset.'" />';
969 }
970
971 /**
972 * Returns generator meta tag
973 *
974 * @return string <meta> tag with name "generator"
975 */
976 function generator() {
977 $str = 'TYPO3 '.TYPO3_branch.', http://typo3.com, &#169; Kasper Sk&#229;rh&#248;j 1998-2006, extensions are copyright of their respective owners.';
978 return '<meta name="generator" content="'.$str .'" />';
979 }
980
981
982
983
984
985
986
987
988 /*****************************************
989 *
990 * OTHER ELEMENTS
991 * Tables, buttons, formatting dimmed/red strings
992 *
993 ******************************************/
994
995
996 /**
997 * Returns an image-tag with an 18x16 icon of the following types:
998 *
999 * $type:
1000 * -1: OK icon (Check-mark)
1001 * 1: Notice (Speach-bubble)
1002 * 2: Warning (Yellow triangle)
1003 * 3: Fatal error (Red stop sign)
1004 *
1005 * @param integer See description
1006 * @param string Value for style attribute
1007 * @return string HTML image tag (if applicable)
1008 */
1009 function icons($type, $styleAttribValue='') {
1010 switch($type) {
1011 case '3':
1012 $icon = 'gfx/icon_fatalerror.gif';
1013 break;
1014 case '2':
1015 $icon = 'gfx/icon_warning.gif';
1016 break;
1017 case '1':
1018 $icon = 'gfx/icon_note.gif';
1019 break;
1020 case '-1':
1021 $icon = 'gfx/icon_ok.gif';
1022 break;
1023 default:
1024 break;
1025 }
1026 if ($icon) {
1027 return '<img'.t3lib_iconWorks::skinImg($this->backPath,$icon,'width="18" height="16"').' class="absmiddle"'.($styleAttribValue ? ' style="'.htmlspecialchars($styleAttribValue).'"' : '').' alt="" />';
1028 }
1029 }
1030
1031 /**
1032 * Returns an <input> button with the $onClick action and $label
1033 *
1034 * @param string The value of the onclick attribute of the input tag (submit type)
1035 * @param string The label for the button (which will be htmlspecialchar'ed)
1036 * @return string A <input> tag of the type "submit"
1037 */
1038 function t3Button($onClick,$label) {
1039 $button = '<input type="submit" onclick="'.htmlspecialchars($onClick).'; return false;" value="'.htmlspecialchars($label).'" />';
1040 return $button;
1041 }
1042
1043 /**
1044 * dimmed-fontwrap. Returns the string wrapped in a <span>-tag defining the color to be gray/dimmed
1045 *
1046 * @param string Input string
1047 * @return string Output string
1048 */
1049 function dfw($string) {
1050 return '<span class="typo3-dimmed">'.$string.'</span>';
1051 }
1052
1053 /**
1054 * red-fontwrap. Returns the string wrapped in a <span>-tag defining the color to be red
1055 *
1056 * @param string Input string
1057 * @return string Output string
1058 */
1059 function rfw($string) {
1060 return '<span class="typo3-red">'.$string.'</span>';
1061 }
1062
1063 /**
1064 * Returns string wrapped in CDATA "tags" for XML / XHTML (wrap content of <script> and <style> sections in those!)
1065 *
1066 * @param string Input string
1067 * @return string Output string
1068 */
1069 function wrapInCData($string) {
1070 $string = '/*<![CDATA[*/'.
1071 $string.
1072 '/*]]>*/';
1073
1074 return $string;
1075 }
1076
1077 /**
1078 * Wraps the input string in script tags.
1079 * Automatic re-identing of the JS code is done by using the first line as ident reference.
1080 * This is nice for identing JS code with PHP code on the same level.
1081 *
1082 * @param string Input string
1083 * @param boolean Wrap script element in linebreaks? Default is TRUE.
1084 * @return string Output string
1085 */
1086 function wrapScriptTags($string, $linebreak=TRUE) {
1087 if(trim($string)) {
1088 // <script wrapped in nl?
1089 $cr = $linebreak? "\n" : '';
1090
1091 // remove nl from the beginning
1092 $string = preg_replace ('/^\n+/', '', $string);
1093 // re-ident to one tab using the first line as reference
1094 $match = array();
1095 if(preg_match('/^(\t+)/',$string,$match)) {
1096 $string = str_replace($match[1],"\t", $string);
1097 }
1098 $string = $cr.'<script type="text/javascript">
1099 /*<![CDATA[*/
1100 '.$string.'
1101 /*]]>*/
1102 </script>'.$cr;
1103 }
1104 return trim($string);
1105 }
1106
1107 // These vars defines the layout for the table produced by the table() function.
1108 // You can override these values from outside if you like.
1109 var $tableLayout = Array (
1110 'defRow' => Array (
1111 'defCol' => Array('<td valign="top">','</td>')
1112 )
1113 );
1114 var $table_TR = '<tr>';
1115 var $table_TABLE = '<table border="0" cellspacing="0" cellpadding="0" id="typo3-tmpltable">';
1116
1117 /**
1118 * Returns a table based on the input $arr
1119 *
1120 * @param array Multidim array with first levels = rows, second levels = cells
1121 * @param array If set, then this provides an alternative layout array instead of $this->tableLayout
1122 * @return string The HTML table.
1123 * @internal
1124 */
1125 function table($arr, $layout='') {
1126 if (is_array($arr)) {
1127 $tableLayout = (is_array($layout)) ? $layout : $this->tableLayout;
1128
1129 reset($arr);
1130 $code='';
1131 $rc=0;
1132 while(list(,$val)=each($arr)) {
1133 if ($rc % 2) {
1134 $layout = is_array($tableLayout['defRowOdd']) ? $tableLayout['defRowOdd'] : $tableLayout['defRow'];
1135 } else {
1136 $layout = is_array($tableLayout['defRowEven']) ? $tableLayout['defRowEven'] : $tableLayout['defRow'];
1137 }
1138 $layoutRow = is_array($tableLayout[$rc]) ? $tableLayout[$rc] : $layout;
1139 $code_td='';
1140 if (is_array($val)) {
1141 $cc=0;
1142 while(list(,$content)=each($val)) {
1143 $wrap= is_array($layoutRow[$cc]) ? $layoutRow[$cc] : (is_array($layoutRow['defCol']) ? $layoutRow['defCol'] : (is_array($layout[$cc]) ? $layout[$cc] : $layout['defCol']));
1144 $code_td.=$wrap[0].$content.$wrap[1];
1145 $cc++;
1146 }
1147 }
1148 $trWrap = is_array($layoutRow['tr']) ? $layoutRow['tr'] : (is_array($layout['tr']) ? $layout['tr'] : array($this->table_TR, '</tr>'));
1149 $code.=$trWrap[0].$code_td.$trWrap[1];
1150 $rc++;
1151 }
1152 $tableWrap = is_array($tableLayout['table']) ? $tableLayout['table'] : array($this->table_TABLE, '</table>');
1153 $code=$tableWrap[0].$code.$tableWrap[1];
1154 }
1155 return $code;
1156 }
1157
1158 /**
1159 * Constructs a table with content from the $arr1, $arr2 and $arr3.
1160 * Used in eg. ext/belog/mod/index.php - refer to that for examples
1161 *
1162 * @param array Menu elements on first level
1163 * @param array Secondary items
1164 * @param array Third-level items
1165 * @return string HTML content, <table>...</table>
1166 */
1167 function menuTable($arr1,$arr2=array(), $arr3=array()) {
1168 $rows = max(array(count($arr1),count($arr2),count($arr3)));
1169
1170 $menu='
1171 <table border="0" cellpadding="0" cellspacing="0" id="typo3-tablemenu">';
1172 for($a=0;$a<$rows;$a++) {
1173 $menu.='<tr>';
1174 $cls=array();
1175 $valign='middle';
1176 $cls[]='<td valign="'.$valign.'">'.$arr1[$a][0].'</td><td>'.$arr1[$a][1].'</td>';
1177 if (count($arr2)) {
1178 $cls[]='<td valign="'.$valign.'">'.$arr2[$a][0].'</td><td>'.$arr2[$a][1].'</td>';
1179 if (count($arr3)) {
1180 $cls[]='<td valign="'.$valign.'">'.$arr3[$a][0].'</td><td>'.$arr3[$a][1].'</td>';
1181 }
1182 }
1183 $menu.=implode($cls,'<td>&nbsp;&nbsp;</td>');
1184 $menu.='</tr>';
1185 }
1186 $menu.='
1187 </table>
1188 ';
1189 return $menu;
1190 }
1191
1192 /**
1193 * Returns a one-row/two-celled table with $content and $menu side by side.
1194 * The table is a 100% width table and each cell is aligned left / right
1195 *
1196 * @param string Content cell content (left)
1197 * @param string Menu cell content (right)
1198 * @return string HTML output
1199 */
1200 function funcMenu($content,$menu) {
1201 return '
1202 <table border="0" cellpadding="0" cellspacing="0" width="100%" id="typo3-funcmenu">
1203 <tr>
1204 <td valign="top" nowrap="nowrap">'.$content.'</td>
1205 <td valign="top" align="right" nowrap="nowrap">'.$menu.'</td>
1206 </tr>
1207 </table>';
1208 }
1209
1210 /**
1211 * Creates a selector box with clear-cache items.
1212 * Rather specialized functions - at least don't use it with $addSaveOptions unless you know what you do...
1213 *
1214 * @param integer The page uid of the "current page" - the one that will be cleared as "clear cache for this page".
1215 * @param boolean If $addSaveOptions is set, then also the array of save-options for TCE_FORMS will appear.
1216 * @return string <select> tag with content - a selector box for clearing the cache
1217 */
1218 function clearCacheMenu($id,$addSaveOptions=0) {
1219 global $BE_USER;
1220 $opt=array();
1221 if ($addSaveOptions) {
1222 $opt[]='<option value="">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.menu',1).'</option>';
1223 $opt[]='<option value="TBE_EDITOR.checkAndDoSubmit(1);">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.saveDoc',1).'</option>';
1224 $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>';
1225 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>';
1226 $opt[]='<option value="document.editform.closeDoc.value=2; document.editform.submit();">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.closeDoc',1).'</option>';
1227 $opt[]='<option value="document.editform.closeDoc.value=3; document.editform.submit();">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.closeAllDocs',1).'</option>';
1228 $opt[]='<option value=""></option>';
1229 }
1230 $opt[]='<option value="">[ '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.clearCache_clearCache',1).' ]</option>';
1231 if ($id) $opt[]='<option value="'.$id.'">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.clearCache_thisPage',1).'</option>';
1232 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>';
1233 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>';
1234
1235 $onChange = 'if (!this.options[this.selectedIndex].value) {
1236 this.selectedIndex=0;
1237 } else if (this.options[this.selectedIndex].value.indexOf(\';\')!=-1) {
1238 eval(this.options[this.selectedIndex].value);
1239 }else{
1240 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;
1241 }';
1242 $af_content = '<select name="cacheCmd" onchange="'.htmlspecialchars($onChange).'">'.implode('',$opt).'</select>';
1243
1244 if (count($opt)>1) {
1245 return $af_content;
1246 }
1247 }
1248
1249
1250 /**
1251 * Includes a javascript library that exists in the core /typo3/ directory. The
1252 * backpath is automatically applied
1253 *
1254 * @param string $lib: Library name. Call it with the full path
1255 * like "contrib/prototype/prototype.js" to load it
1256 * @return void
1257 */
1258 function loadJavascriptLib($lib) {
1259 if (!isset($this->JScodeLibArray[$lib])) {
1260 $this->JScodeLibArray[$lib] = '<script type="text/javascript" src="'.$this->backPath.$lib.'"></script>';
1261 }
1262 }
1263
1264
1265 /**
1266 * Includes the necessary Javascript function for the clickmenu (context sensitive menus) in the document
1267 *
1268 * @return array Deprecated: Includes the code already in the doc, so the return array is always empty.
1269 * Please just call this function without expecting a return value for future calls
1270 */
1271 function getContextMenuCode() {
1272 $this->loadJavascriptLib('contrib/prototype/prototype.js');
1273 $this->loadJavascriptLib('js/clickmenu.js');
1274
1275 $this->JScodeArray['clickmenu'] = '
1276 Clickmenu.clickURL = "'.$this->backPath.'alt_clickmenu.php";
1277 Clickmenu.ajax = '.($this->isCMLayers() ? 'true' : 'false' ).';';
1278
1279 // return array deprecated since 4.2
1280 return array('','','');
1281 }
1282
1283 /**
1284 * Includes the necessary javascript file (tree.js) for use on pages which have the
1285 * drag and drop functionality (usually pages and folder display trees)
1286 *
1287 * @param string indicator of which table the drag and drop function should work on (pages or folders)
1288 * @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
1289 */
1290 function getDragDropCode($table) {
1291 $this->loadJavascriptLib('contrib/prototype/prototype.js');
1292 $this->loadJavascriptLib('js/common.js');
1293 $this->loadJavascriptLib('tree.js');
1294
1295 // setting prefs for drag & drop
1296 $this->JScodeArray['dragdrop'] = '
1297 DragDrop.changeURL = "'.$this->backPath.'alt_clickmenu.php";
1298 DragDrop.backPath = "'.t3lib_div::shortMD5(''.'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']).'";
1299 DragDrop.table = "'.$table.'";
1300 ';
1301
1302 // return array deprecated since 4.2
1303 return array('','','');
1304 }
1305
1306
1307 /**
1308 * Creates a tab menu from an array definition
1309 *
1310 * Returns a tab menu for a module
1311 * Requires the JS function jumpToUrl() to be available
1312 *
1313 * @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=...
1314 * @param string $elementName it the form elements name, probably something like "SET[...]"
1315 * @param string $currentValue is the value to be selected currently.
1316 * @param array $menuItems is an array with the menu items for the selector box
1317 * @param string $script is the script to send the &id to, if empty it's automatically found
1318 * @param string $addParams is additional parameters to pass to the script.
1319 * @return string HTML code for tab menu
1320 * @author Rene Fritz <r.fritz@colorcube.de>
1321 */
1322 function getTabMenu($mainParams,$elementName,$currentValue,$menuItems,$script='',$addparams='') {
1323 $content='';
1324
1325 if (is_array($menuItems)) {
1326 if (!is_array($mainParams)) {
1327 $mainParams = array('id' => $mainParams);
1328 }
1329 $mainParams = t3lib_div::implodeArrayForUrl('',$mainParams);
1330
1331 if (!$script) {$script=basename(PATH_thisScript);}
1332
1333 $menuDef = array();
1334 foreach($menuItems as $value => $label) {
1335 $menuDef[$value]['isActive'] = !strcmp($currentValue,$value);
1336 $menuDef[$value]['label'] = t3lib_div::deHSCentities(htmlspecialchars($label));
1337 $menuDef[$value]['url'] = htmlspecialchars($script.'?'.$mainParams.$addparams.'&'.$elementName.'='.$value);
1338 }
1339 $content = $this->getTabMenuRaw($menuDef);
1340
1341 }
1342 return $content;
1343 }
1344
1345 /**
1346 * Creates the HTML content for the tab menu
1347 *
1348 * @param array Menu items for tabs
1349 * @return string Table HTML
1350 * @access private
1351 */
1352 function getTabMenuRaw($menuItems) {
1353 $content='';
1354
1355 if (is_array($menuItems)) {
1356 $options='';
1357
1358 $count = count($menuItems);
1359 $widthLeft = 1;
1360 $addToAct = 5;
1361
1362 $widthRight = max (1,floor(30-pow($count,1.72)));
1363 $widthTabs = 100 - $widthRight - $widthLeft;
1364 $widthNo = floor(($widthTabs - $addToAct)/$count);
1365 $addToAct = max ($addToAct,$widthTabs-($widthNo*$count));
1366 $widthAct = $widthNo + $addToAct;
1367 $widthRight = 100 - ($widthLeft + ($count*$widthNo) + $addToAct);
1368
1369 $first=true;
1370 foreach($menuItems as $id => $def) {
1371 $isActive = $def['isActive'];
1372 $class = $isActive ? 'tabact' : 'tab';
1373 $width = $isActive ? $widthAct : $widthNo;
1374
1375 // @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.
1376 $label = $def['label'];
1377 $url = htmlspecialchars($def['url']);
1378 $params = $def['addParams'];
1379
1380 if($first) {
1381 $options.= '
1382 <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>';
1383 } else {
1384 $options.='
1385 <td width="'.$width.'%" class="'.$class.'"><a href="'.$url.'" '.$params.'>'.$label.'</a></td>';
1386 }
1387 $first=false;
1388 }
1389
1390 if ($options) {
1391 $content .= '
1392 <!-- Tab menu -->
1393 <table cellpadding="0" cellspacing="0" border="0" width="100%" id="typo3-tabmenu">
1394 <tr>
1395 <td width="'.$widthLeft.'%">&nbsp;</td>
1396 '.$options.'
1397 <td width="'.$widthRight.'%">&nbsp;</td>
1398 </tr>
1399 </table>
1400 <div class="hr" style="margin:0px"></div>';
1401 }
1402
1403 }
1404 return $content;
1405 }
1406
1407 /**
1408 * Creates a DYNAMIC tab-menu where the tabs are switched between with DHTML.
1409 * 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!
1410 *
1411 * @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.
1412 * @param string Identification string. This should be unique for every instance of a dynamic menu!
1413 * @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.
1414 * @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.
1415 * @param integer Character limit for a new row.
1416 * @param boolean If set, tab table cells are not allowed to wrap their content
1417 * @param boolean If set, the tabs will span the full width of their position
1418 * @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.
1419 * @param integer If set to '1' empty tabs will be remove, If set to '2' empty tabs will be disabled
1420 * @return string JavaScript section for the HTML header.
1421 */
1422 function getDynTabMenu($menuItems,$identString,$toggle=0,$foldout=FALSE,$newRowCharLimit=50,$noWrap=1,$fullWidth=FALSE,$defaultTabIndex=1,$dividers2tabs=2) {
1423 $content = '';
1424
1425 if (is_array($menuItems)) {
1426
1427 // Init:
1428 $options = array(array());
1429 $divs = array();
1430 $JSinit = array();
1431 $id = $this->getDynTabMenuId($identString);
1432 $noWrap = $noWrap ? ' nowrap="nowrap"' : '';
1433
1434 // Traverse menu items
1435 $c=0;
1436 $tabRows=0;
1437 $titleLenCount = 0;
1438 foreach($menuItems as $index => $def) {
1439 $index+=1; // Need to add one so checking for first index in JavaScript is different than if it is not set at all.
1440
1441 // Switch to next tab row if needed
1442 if (!$foldout && ($titleLenCount>$newRowCharLimit | ($def['newline'] === true && $titleLenCount > 0))) {
1443 $titleLenCount=0;
1444 $tabRows++;
1445 $options[$tabRows] = array();
1446 }
1447
1448 if ($toggle==1) {
1449 $onclick = 'this.blur(); DTM_toggle("'.$id.'","'.$index.'"); return false;';
1450 } else {
1451 $onclick = 'this.blur(); DTM_activate("'.$id.'","'.$index.'", '.($toggle<0?1:0).'); return false;';
1452 }
1453
1454 $isNotEmpty = strcmp(trim($def['content']),'');
1455
1456 // "Removes" empty tabs
1457 if (!$isNotEmpty && $dividers2tabs == 1) {
1458 continue;
1459 }
1460
1461 $mouseOverOut = ' onmouseover="DTM_mouseOver(this);" onmouseout="DTM_mouseOut(this);"';
1462 $requiredIcon = '<img name="'.$id.'-'.$index.'-REQ" src="clear.gif" width="10" height="10" hspace="4" alt="" />';
1463
1464 if (!$foldout) {
1465 // Create TAB cell:
1466 $options[$tabRows][] = '
1467 <td class="'.($isNotEmpty ? 'tab' : 'disabled').'" id="'.$id.'-'.$index.'-MENU"'.$noWrap.$mouseOverOut.'>'.
1468 ($isNotEmpty ? '<a href="#" onclick="'.htmlspecialchars($onclick).'"'.($def['linkTitle'] ? ' title="'.htmlspecialchars($def['linkTitle']).'"':'').'>' : '').
1469 $def['icon'].
1470 ($def['label'] ? htmlspecialchars($def['label']) : '&nbsp;').
1471 $requiredIcon.
1472 $this->icons($def['stateIcon'],'margin-left: 10px;').
1473 ($isNotEmpty ? '</a>' :'').
1474 '</td>';
1475 $titleLenCount+= strlen($def['label']);
1476 } else {
1477 // Create DIV layer for content:
1478 $divs[] = '
1479 <div class="'.($isNotEmpty ? 'tab' : 'disabled').'" id="'.$id.'-'.$index.'-MENU"'.$mouseOverOut.'>'.
1480 ($isNotEmpty ? '<a href="#" onclick="'.htmlspecialchars($onclick).'"'.($def['linkTitle'] ? ' title="'.htmlspecialchars($def['linkTitle']).'"':'').'>' : '').
1481 $def['icon'].
1482 ($def['label'] ? htmlspecialchars($def['label']) : '&nbsp;').
1483 $requiredIcon.
1484 ($isNotEmpty ? '</a>' : '').
1485 '</div>';
1486 }
1487
1488 // Create DIV layer for content:
1489 $divs[] = '
1490 <div style="display: none;" id="'.$id.'-'.$index.'-DIV" class="c-tablayer">'.
1491 ($def['description'] ? '<p class="c-descr">'.nl2br(htmlspecialchars($def['description'])).'</p>' : '').
1492 $def['content'].
1493 '</div>';
1494 // Create initialization string:
1495 $JSinit[] = '
1496 DTM_array["'.$id.'"]['.$c.'] = "'.$id.'-'.$index.'";
1497 ';
1498 if ($toggle==1) {
1499 $JSinit[] = '
1500 if (top.DTM_currentTabs["'.$id.'-'.$index.'"]) { DTM_toggle("'.$id.'","'.$index.'",1); }
1501 ';
1502 }
1503
1504 $c++;
1505 }
1506
1507 // Render menu:
1508 if (count($options)) {
1509
1510 // Tab menu is compiled:
1511 if (!$foldout) {
1512 $tabContent = '';
1513 for($a=0;$a<=$tabRows;$a++) {
1514 $tabContent.= '
1515
1516 <!-- Tab menu -->
1517 <table cellpadding="0" cellspacing="0" border="0"'.($fullWidth ? ' width="100%"' : '').' class="typo3-dyntabmenu">
1518 <tr>
1519 '.implode('',$options[$a]).'
1520 </tr>
1521 </table>';
1522 }
1523 $content.= '<div class="typo3-dyntabmenu-tabs">'.$tabContent.'</div>';
1524 }
1525
1526 // Div layers are added:
1527 $content.= '
1528 <!-- Div layers for tab menu: -->
1529 <div class="typo3-dyntabmenu-divs'.($foldout?'-foldout':'').'">
1530 '.implode('',$divs).'</div>';
1531
1532 // Java Script section added:
1533 $content.= '
1534 <!-- Initialization JavaScript for the menu -->
1535 <script type="text/javascript">
1536 DTM_array["'.$id.'"] = new Array();
1537 '.implode('',$JSinit).'
1538 '.($toggle<=0 ? 'DTM_activate("'.$id.'", top.DTM_currentTabs["'.$id.'"]?top.DTM_currentTabs["'.$id.'"]:'.intval($defaultTabIndex).', 0);' : '').'
1539 </script>
1540
1541 ';
1542 }
1543
1544 }
1545 return $content;
1546 }
1547
1548 /**
1549 * Creates the id for dynTabMenus.
1550 *
1551 * @param string $identString: Identification string. This should be unique for every instance of a dynamic menu!
1552 * @return string The id with a short MD5 of $identString and prefixed "DTM-", like "DTM-2e8791854a"
1553 */
1554 function getDynTabMenuId($identString) {
1555 $id = 'DTM-'.t3lib_div::shortMD5($identString);
1556 return $id;
1557 }
1558
1559 /**
1560 * Returns dynamic tab menu header JS code.
1561 *
1562 * @return string JavaScript section for the HTML header.
1563 */
1564 function getDynTabMenuJScode() {
1565 return '
1566 <script type="text/javascript">
1567 /*<![CDATA[*/
1568 var DTM_array = new Array();
1569 var DTM_origClass = new String();
1570
1571 // if tabs are used in a popup window the array might not exists
1572 if(!top.DTM_currentTabs) {
1573 top.DTM_currentTabs = new Array();
1574 }
1575
1576 function DTM_activate(idBase,index,doToogle) { //
1577 // Hiding all:
1578 if (DTM_array[idBase]) {
1579 for(cnt = 0; cnt < DTM_array[idBase].length ; cnt++) {
1580 if (DTM_array[idBase][cnt] != idBase+"-"+index) {
1581 document.getElementById(DTM_array[idBase][cnt]+"-DIV").style.display = "none";
1582 // Only Overriding when Tab not disabled
1583 if (document.getElementById(DTM_array[idBase][cnt]+"-MENU").attributes.getNamedItem("class").nodeValue != "disabled") {
1584 document.getElementById(DTM_array[idBase][cnt]+"-MENU").attributes.getNamedItem("class").nodeValue = "tab";
1585 }
1586 }
1587 }
1588 }
1589
1590 // Showing one:
1591 if (document.getElementById(idBase+"-"+index+"-DIV")) {
1592 if (doToogle && document.getElementById(idBase+"-"+index+"-DIV").style.display == "block") {
1593 document.getElementById(idBase+"-"+index+"-DIV").style.display = "none";
1594 if(DTM_origClass=="") {
1595 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "tab";
1596 } else {
1597 DTM_origClass = "tab";
1598 }
1599 top.DTM_currentTabs[idBase] = -1;
1600 } else {
1601 document.getElementById(idBase+"-"+index+"-DIV").style.display = "block";
1602 if(DTM_origClass=="") {
1603 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "tabact";
1604 } else {
1605 DTM_origClass = "tabact";
1606 }
1607 top.DTM_currentTabs[idBase] = index;
1608 }
1609 }
1610 }
1611 function DTM_toggle(idBase,index,isInit) { //
1612 // Showing one:
1613 if (document.getElementById(idBase+"-"+index+"-DIV")) {
1614 if (document.getElementById(idBase+"-"+index+"-DIV").style.display == "block") {
1615 document.getElementById(idBase+"-"+index+"-DIV").style.display = "none";
1616 if(isInit) {
1617 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "tab";
1618 } else {
1619 DTM_origClass = "tab";
1620 }
1621 top.DTM_currentTabs[idBase+"-"+index] = 0;
1622 } else {
1623 document.getElementById(idBase+"-"+index+"-DIV").style.display = "block";
1624 if(isInit) {
1625 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "tabact";
1626 } else {
1627 DTM_origClass = "tabact";
1628 }
1629 top.DTM_currentTabs[idBase+"-"+index] = 1;
1630 }
1631 }
1632 }
1633
1634 function DTM_mouseOver(obj) { //
1635 DTM_origClass = obj.attributes.getNamedItem(\'class\').nodeValue;
1636 obj.attributes.getNamedItem(\'class\').nodeValue += "_over";
1637 }
1638
1639 function DTM_mouseOut(obj) { //
1640 obj.attributes.getNamedItem(\'class\').nodeValue = DTM_origClass;
1641 DTM_origClass = "";
1642 }
1643
1644
1645 /*]]>*/
1646 </script>
1647 ';
1648 }
1649
1650 /**
1651 * Creates the version selector for the page id inputted.
1652 * Requires the core version management extension, "version" to be loaded.
1653 *
1654 * @param integer Page id to create selector for.
1655 * @param boolean If set, there will be no button for swapping page.
1656 * @return void
1657 */
1658 function getVersionSelector($id,$noAction=FALSE) {
1659
1660 if ($id>0) {
1661 if (t3lib_extMgm::isLoaded('version') && $GLOBALS['BE_USER']->workspace==0) {
1662
1663 // Get Current page record:
1664 $curPage = t3lib_BEfunc::getRecord('pages',$id);
1665 // If the selected page is not online, find the right ID
1666 $onlineId = ($curPage['pid']==-1 ? $curPage['t3ver_oid'] : $id);
1667 // Select all versions of online version:
1668 $versions = t3lib_BEfunc::selectVersionsOfRecord('pages', $onlineId, 'uid,pid,t3ver_label,t3ver_oid,t3ver_wsid,t3ver_id');
1669
1670 // If more than one was found...:
1671 if (count($versions)>1) {
1672
1673 // Create selector box entries:
1674 $opt = array();
1675 foreach($versions as $vRow) {
1676 $opt[] = '<option value="'.htmlspecialchars(t3lib_div::linkThisScript(array('id'=>$vRow['uid']))).'"'.($id==$vRow['uid']?' selected="selected"':'').'>'.
1677 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').'<=':'')).
1678 '</option>';
1679 }
1680
1681 // Add management link:
1682 $opt[] = '<option value="'.htmlspecialchars(t3lib_div::linkThisScript(array('id'=>$id))).'">---</option>';
1683 $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>';
1684
1685 // Create onchange handler:
1686 $onChange = "window.location.href=this.options[this.selectedIndex].value;";
1687
1688 // Controls:
1689 if ($id==$onlineId) {
1690 $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>';
1691 } elseif (!$noAction) {
1692 $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">'.
1693 '<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).'" />'.
1694 '<b>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:ver.swap',1).'</b></a>';
1695 }
1696
1697 // Write out HTML code:
1698 return '
1699
1700 <!--
1701 Version selector:
1702 -->
1703 <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
1704 <tr>
1705 <td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:ver.selVer',1).'</td>
1706 <td>
1707 <select onchange="'.htmlspecialchars($onChange).'">
1708 '.implode('',$opt).'
1709 </select></td>
1710 <td>'.$controls.'</td>
1711 </tr>
1712 </table>
1713 ';
1714 }
1715 } elseif ($GLOBALS['BE_USER']->workspace!==0) {
1716
1717 // Write out HTML code:
1718 switch($GLOBALS['BE_USER']->workspace) {
1719 case 0:
1720 $wsTitle = 'LIVE';
1721 break;
1722 case -1:
1723 $wsTitle = 'Draft';
1724 break;
1725 default:
1726 $wsTitle = $GLOBALS['BE_USER']->workspaceRec['title'];
1727 break;
1728 }
1729
1730 if (t3lib_BEfunc::isPidInVersionizedBranch($id)=='branchpoint') {
1731 return '
1732
1733 <!--
1734 Version selector:
1735 -->
1736 <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
1737 <tr>
1738 <td>Workspace: "'.htmlspecialchars($wsTitle).'"</td>
1739 <td><em>Inside branch, no further versioning possible</em></td>
1740 </tr>
1741 </table>
1742 ';
1743 } else {
1744 // Get Current page record:
1745 $curPage = t3lib_BEfunc::getRecord('pages',$id);
1746 // If the selected page is not online, find the right ID
1747 $onlineId = ($curPage['pid']==-1 ? $curPage['t3ver_oid'] : $id);
1748 // The version of page:
1749 $verPage = t3lib_BEfunc::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, 'pages', $onlineId);
1750
1751 if (!$verPage) {
1752
1753 if (!count(t3lib_BEfunc::countVersionsOfRecordsOnPage($GLOBALS['BE_USER']->workspace, $onlineId))) {
1754 if ($GLOBALS['BE_USER']->workspaceVersioningTypeAccess(0)) {
1755
1756 $onClick = $this->issueCommand('&cmd[pages]['.$onlineId.'][version][action]=new&cmd[pages]['.$onlineId.'][version][treeLevels]=0',t3lib_div::linkThisScript(array('id'=>$onlineId)));
1757 $onClick = 'window.location.href=\''.$onClick.'\'; return false;';
1758 // Write out HTML code:
1759 return '
1760
1761 <!--
1762 No version yet, create one?
1763 -->
1764 <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
1765 <tr>
1766 <td>Workspace: "'.htmlspecialchars($wsTitle).'"</td>
1767 <td>
1768 <input type="submit" value="New version of page" name="_" onclick="'.htmlspecialchars($onClick).'" /></td>
1769 </tr>
1770 </table>
1771 ';
1772 }
1773 } else {
1774 return '
1775
1776 <!--
1777 Version selector:
1778 -->
1779 <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
1780 <tr>
1781 <td>Workspace: "'.htmlspecialchars($wsTitle).'"</td>
1782 <td><em>Versions found on page, no "Page" versioning possible</em></td>
1783 </tr>
1784 </table>
1785 ';
1786 }
1787 } elseif ($verPage['t3ver_swapmode']==0) {
1788 $onClick = $this->issueCommand('&cmd[pages]['.$onlineId.'][version][action]=swap&cmd[pages]['.$onlineId.'][version][swapWith]='.$verPage['uid'],t3lib_div::linkThisScript(array('id'=>$onlineId)));
1789 $onClick = 'window.location.href=\''.$onClick.'\'; return false;';
1790
1791 // Write out HTML code:
1792 return '
1793
1794 <!--
1795 Version selector:
1796 -->
1797 <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
1798 <tr>
1799 <td>Workspace: "'.htmlspecialchars($wsTitle).'"</td>
1800 <td>
1801 <input type="submit" value="Publish page" name="_" onclick="'.htmlspecialchars($onClick).'" /></td>
1802 </tr>
1803 </table>
1804 ';
1805 }
1806 }
1807 }
1808 }
1809 }
1810
1811
1812 /**
1813 * Function to load a HTML template file with markers.
1814 *
1815 * @param string tmpl name, usually in the typo3/template/ directory
1816 * @return string HTML of template
1817 */
1818 function getHtmlTemplate($filename) {
1819 if ($GLOBALS['TBE_STYLES']['htmlTemplates'][$filename]) {
1820 $filename = $GLOBALS['TBE_STYLES']['htmlTemplates'][$filename];
1821 }
1822 return ($filename ? t3lib_div::getURL($this->backPath . $filename) : '');
1823 }
1824
1825 /**
1826 * Define the template for the module
1827 *
1828 * @param string filename
1829 */
1830 function setModuleTemplate($filename) {
1831 $this->moduleTemplate = $this->getHtmlTemplate($filename);
1832 }
1833
1834 /**
1835 * Put together the various elements for the module <body> using a static HTML
1836 * template
1837 *
1838 * @param array Record of the current page, used for page path and info
1839 * @param array HTML for all buttons
1840 * @param array HTML for all other markers
1841 * @return string Composite HTML
1842 */
1843 public function moduleBody($pageRecord = array(), $buttons = array(), $markerArray = array()) {
1844 // Get the HTML template for the module
1845 $moduleBody = t3lib_parsehtml::getSubpart($this->moduleTemplate, '###FULLDOC###');
1846 // Add CSS
1847 $this->inDocStylesArray[] = 'html { overflow: hidden; }';
1848 // Add JS code to the <head> for IE
1849 $this->JScode.= $this->wrapScriptTags('
1850 // workaround since IE6 cannot deal with relative height for scrolling elements
1851 function resizeDocBody() {
1852 $("typo3-docbody").style.height = (document.body.offsetHeight - parseInt($("typo3-docheader").getStyle("height")));
1853 }
1854 if (/MSIE 6/.test(navigator.userAgent)) {
1855 Event.observe(window, "resize", resizeDocBody, false);
1856 Event.observe(window, "load", resizeDocBody, false);
1857 }
1858 ');
1859 // Get the page path for the docheader
1860 $markerArray['PAGEPATH'] = $this->getPagePath($pageRecord);
1861 // Get the page info for the docheader
1862 $markerArray['PAGEINFO'] = $this->getPageInfo($pageRecord);
1863 // Get all the buttons for the docheader
1864 $docHeaderButtons = $this->getDocHeaderButtons($buttons);
1865 // Merge docheader buttons with the marker array
1866 $markerArray = array_merge($markerArray, $docHeaderButtons);
1867 // replacing all markers with the finished markers and return the HTML content
1868 return t3lib_parsehtml::substituteMarkerArray($moduleBody, $markerArray, '###|###');
1869 }
1870
1871 /**
1872 * Fill the button lists with the defined HTML
1873 *
1874 * @param array HTML for all buttons
1875 * @return array Containing HTML for both buttonlists
1876 */
1877 private function getDocHeaderButtons($buttons) {
1878 $markers = array();
1879 // Fill buttons for left and right float
1880 $floats = array('left', 'right');
1881 foreach($floats as $key) {
1882 // Get the template for each float
1883 $buttonTemplate = t3lib_parsehtml::getSubpart($this->moduleTemplate, '###BUTTON_GROUPS_' . strtoupper($key) . '###');
1884 // Fill the button markers in this float
1885 $buttonTemplate = t3lib_parsehtml::substituteMarkerArray($buttonTemplate, $buttons, '###|###', true);
1886 // getting the wrap for each group
1887 $buttonWrap = t3lib_parsehtml::getSubpart($this->moduleTemplate, '###BUTTON_GROUP_WRAP###');
1888 // looping through the groups (max 6) and remove the empty groups
1889 for ($groupNumber = 1; $groupNumber < 6; $groupNumber++) {
1890 $buttonMarker = '###BUTTON_GROUP' . $groupNumber . '###';
1891 $buttonGroup = t3lib_parsehtml::getSubpart($buttonTemplate, $buttonMarker);
1892 if (trim($buttonGroup)) {
1893 if ($buttonWrap) {
1894 $buttonGroup = t3lib_parsehtml::substituteMarker($buttonWrap, '###BUTTONS###', $buttonGroup);
1895 }
1896 $buttonTemplate = t3lib_parsehtml::substituteSubpart($buttonTemplate, $buttonMarker, trim($buttonGroup));
1897 }
1898 }
1899 // replace the marker with the template and remove all line breaks (for IE compat)
1900 $markers['BUTTONLIST_' . strtoupper($key)] = str_replace("\n", '', $buttonTemplate);
1901 }
1902 return $markers;
1903 }
1904
1905 /**
1906 * Generate the page path for docheader
1907 *
1908 * @param array Current page
1909 * @return string Page path
1910 */
1911 private function getPagePath($pageRecord) {
1912 global $LANG;
1913 // Is this a real page
1914 if ($pageRecord['uid']) {
1915 $title = $pageRecord['_thePath'];
1916 } else {
1917 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
1918 }
1919 // Setting the path of the page
1920 $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>';
1921 return $pagePath;
1922 }
1923
1924 /**
1925 * Setting page icon with clickmenu + uid for docheader
1926 *
1927 * @param array Current page
1928 * @return string Page info
1929 */
1930 private function getPageInfo($pageRecord) {
1931 global $BE_USER;
1932 // Add icon with clickmenu, etc:
1933 if ($pageRecord['uid']) { // If there IS a real page
1934 $alttext = t3lib_BEfunc::getRecordIconAltText($pageRecord, 'pages');
1935 $iconImg = t3lib_iconWorks::getIconImage('pages', $pageRecord, $this->backPath, 'class="absmiddle" title="'. htmlspecialchars($alttext) . '"');
1936 // Make Icon:
1937 $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconImg, 'pages', $pageRecord['uid']);
1938 } else { // On root-level of page tree
1939 // Make Icon
1940 $iconImg = '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/i/_icon_website.gif') . ' alt="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] . '" />';
1941 if($BE_USER->user['admin']) {
1942 $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconImg, 'pages', 0);
1943 } else {
1944 $theIcon = $iconImg;
1945 }
1946 }
1947
1948 // Setting icon with clickmenu + uid
1949 $pageInfo = $theIcon . '<em>[pid: ' . $pageRecord['uid'] . ']</em>';
1950 return $pageInfo;
1951 }
1952 }
1953
1954
1955 // ******************************
1956 // Extension classes of the template class.
1957 // These are meant to provide backend screens with different widths.
1958 // They still do because of the different class-prefixes used for the <div>-sections
1959 // but obviously the final width is determined by the stylesheet used.
1960 // ******************************
1961
1962 /**
1963 * 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
1964 * The class were more significant in the past than today.
1965 *
1966 */
1967 class bigDoc extends template {
1968 var $divClass = 'typo3-bigDoc';
1969 }
1970
1971 /**
1972 * Extension class for "template" - used for backend pages without the "document" background image
1973 * The class were more significant in the past than today.
1974 *
1975 */
1976 class noDoc extends template {
1977 var $divClass = 'typo3-noDoc';
1978 }
1979
1980 /**
1981 * 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)
1982 * The class were more significant in the past than today.
1983 *
1984 */
1985 class smallDoc extends template {
1986 var $divClass = 'typo3-smallDoc';
1987 }
1988
1989 /**
1990 * 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.
1991 * The class were more significant in the past than today. But probably you should use this one for most modules you make.
1992 *
1993 */
1994 class mediumDoc extends template {
1995 var $divClass = 'typo3-mediumDoc';
1996 }
1997
1998
1999
2000 // Include extension to the template class?
2001 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/template.php']) {
2002 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/template.php']);
2003 }
2004
2005
2006
2007 // ******************************************************
2008 // The backend language engine is started (ext: "lang")
2009 // ******************************************************
2010 require_once(PATH_typo3.'sysext/lang/lang.php');
2011 $GLOBALS['LANG'] = t3lib_div::makeInstance('language');
2012 $GLOBALS['LANG']->init($BE_USER->uc['lang']);
2013
2014
2015
2016 // ******************************
2017 // The template is loaded
2018 // ******************************
2019 $GLOBALS['TBE_TEMPLATE'] = t3lib_div::makeInstance('template');
2020 ?>