(bugfix) Fixed Image Generation bug. Call in t3lib_div now uses the IM wrapper to...
[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
180 // Other vars you can change, but less frequently used:
181 var $scriptID=''; // Script ID.
182 var $bodyTagId=''; // Id which can be set for the body tag. Default value is based on script ID
183 var $bodyTagAdditions=''; // You can add additional attributes to the body-tag through this variable.
184 var $inDocStyles=''; // Additional CSS styles which will be added to the <style> section in the header
185 var $inDocStylesArray=array(); // Like $inDocStyles but for use as array with associative keys to prevent double inclusion of css code
186 var $form_rowsToStylewidth = 9.58; // Multiplication factor for formWidth() input size (default is 48* this value).
187 var $form_largeComp = 1.33; // Compensation for large documents (used in class.t3lib_tceforms.php)
188 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.
189
190 // TYPO3 Colorscheme.
191 // If you want to change this, please do so through a skin using the global var $TBE_STYLES
192 var $bgColor = '#F7F3EF'; // Light background color
193 var $bgColor2 = '#9BA1A8'; // Steel-blue
194 var $bgColor3 = '#F6F2E6'; // dok.color
195 var $bgColor4 = '#D9D5C9'; // light tablerow background, brownish
196 var $bgColor5 = '#ABBBB4'; // light tablerow background, greenish
197 var $bgColor6 = '#E7DBA8'; // light tablerow background, yellowish, for section headers. Light.
198 var $hoverColor = '#254D7B';
199 var $styleSheetFile = 'stylesheet.css'; // Filename of stylesheet (relative to PATH_typo3)
200 var $styleSheetFile2 = ''; // Filename of stylesheet #2 - linked to right after the $this->styleSheetFile script (relative to PATH_typo3)
201 var $styleSheetFile_post = ''; // Filename of a post-stylesheet - included right after all inline styles.
202 var $backGroundImage = ''; // Background image of page (relative to PATH_typo3)
203 var $inDocStyles_TBEstyle = ''; // Inline css styling set from TBE_STYLES array
204
205 // DEV:
206 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.
207
208 // INTERNAL
209 var $charset = 'iso-8859-1'; // Default charset. see function initCharset()
210
211 var $sectionFlag=0; // Internal: Indicates if a <div>-output section is open
212 var $divClass = ''; // (Default) Class for wrapping <DIV>-tag of page. Is set in class extensions.
213
214
215
216
217
218
219 /**
220 * Constructor
221 * Imports relevant parts from global $TBE_STYLES (colorscheme)
222 *
223 * @return void
224 */
225 function template() {
226 global $TBE_STYLES;
227
228 // Setting default scriptID:
229 $this->scriptID = ereg_replace('^.*\/(sysext|ext)\/','ext/',substr(PATH_thisScript,strlen(PATH_site)));
230 if (TYPO3_mainDir!='typo3/' && substr($this->scriptID,0,strlen(TYPO3_mainDir)) == TYPO3_mainDir) {
231 $this->scriptID = 'typo3/'.substr($this->scriptID,strlen(TYPO3_mainDir)); // This fixes if TYPO3_mainDir has been changed so the script ids are STILL "typo3/..."
232 }
233
234 $this->bodyTagId = ereg_replace('[^[:alnum:]-]','-',$this->scriptID);
235
236 // Individual configuration per script? If so, make a recursive merge of the arrays:
237 if (is_array($TBE_STYLES['scriptIDindex'][$this->scriptID])) {
238 $ovr = $TBE_STYLES['scriptIDindex'][$this->scriptID]; // Make copy
239 $TBE_STYLES = t3lib_div::array_merge_recursive_overrule($TBE_STYLES,$ovr); // merge styles.
240 unset($TBE_STYLES['scriptIDindex'][$this->scriptID]); // Have to unset - otherwise the second instantiation will do it again!
241 }
242
243 // Color scheme:
244 if ($TBE_STYLES['mainColors']['bgColor']) $this->bgColor=$TBE_STYLES['mainColors']['bgColor'];
245 if ($TBE_STYLES['mainColors']['bgColor1']) $this->bgColor1=$TBE_STYLES['mainColors']['bgColor1'];
246 if ($TBE_STYLES['mainColors']['bgColor2']) $this->bgColor2=$TBE_STYLES['mainColors']['bgColor2'];
247 if ($TBE_STYLES['mainColors']['bgColor3']) $this->bgColor3=$TBE_STYLES['mainColors']['bgColor3'];
248 if ($TBE_STYLES['mainColors']['bgColor4']) $this->bgColor4=$TBE_STYLES['mainColors']['bgColor4'];
249 if ($TBE_STYLES['mainColors']['bgColor5']) $this->bgColor5=$TBE_STYLES['mainColors']['bgColor5'];
250 if ($TBE_STYLES['mainColors']['bgColor6']) $this->bgColor6=$TBE_STYLES['mainColors']['bgColor6'];
251 if ($TBE_STYLES['mainColors']['hoverColor']) $this->hoverColor=$TBE_STYLES['mainColors']['hoverColor'];
252
253 // Main Stylesheets:
254 if ($TBE_STYLES['stylesheet']) $this->styleSheetFile = $TBE_STYLES['stylesheet'];
255 if ($TBE_STYLES['stylesheet2']) $this->styleSheetFile2 = $TBE_STYLES['stylesheet2'];
256 if ($TBE_STYLES['styleSheetFile_post']) $this->styleSheetFile_post = $TBE_STYLES['styleSheetFile_post'];
257 if ($TBE_STYLES['inDocStyles_TBEstyle']) $this->inDocStyles_TBEstyle = $TBE_STYLES['inDocStyles_TBEstyle'];
258
259 // Background image
260 if ($TBE_STYLES['background']) $this->backGroundImage = $TBE_STYLES['background'];
261 }
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278 /*****************************************
279 *
280 * EVALUATION FUNCTIONS
281 * Various centralized processing
282 *
283 *****************************************/
284
285 /**
286 * Makes click menu link (context sensitive menu)
287 * 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)
288 * 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)
289 *
290 * @param string String to be wrapped in link, typ. image tag.
291 * @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
292 * @param integer If icon is for database record this is the UID for the record from $table
293 * @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.
294 * @param string Additional GET parameters for the link to alt_clickmenu.php
295 * @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.
296 * @param boolean If set, will return only the onclick JavaScript, not the whole link.
297 * @return string The link-wrapped input string.
298 */
299 function wrapClickMenuOnIcon($str,$table,$uid='',$listFr=1,$addParams='',$enDisItems='', $returnOnClick=FALSE) {
300 $backPath = rawurlencode($this->backPath).'|'.t3lib_div::shortMD5($this->backPath.'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']);
301 $onClick = 'showClickmenu("'.$table.'","'.$uid.'","'.$listFr.'","'.str_replace('+','%2B',$enDisItems).'","'.str_replace('&','&amp;',addcslashes($backPath,'"')).'","'.str_replace('&','&amp;',addcslashes($addParams,'"')).'");return false;';
302 return $returnOnClick ? $onClick : '<a href="#" onclick="'.htmlspecialchars($onClick).'"'.($GLOBALS['TYPO3_CONF_VARS']['BE']['useOnContextMenuHandler'] ? ' oncontextmenu="'.htmlspecialchars($onClick).'"' : '').'>'.$str.'</a>';
303 }
304
305 /**
306 * Makes link to page $id in frontend (view page)
307 * Returns an magnifier-glass icon which links to the frontend index.php document for viewing the page with id $id
308 * $id must be a page-uid
309 * If the BE_USER has access to Web>List then a link to that module is shown as well (with return-url)
310 *
311 * @param integer The page id
312 * @param string The current "BACK_PATH" (the back relative to the typo3/ directory)
313 * @param string Additional parameters for the image tag(s)
314 * @return string HTML string with linked icon(s)
315 */
316 function viewPageIcon($id,$backPath,$addParams='hspace="3"') {
317 global $BE_USER;
318 $str = '';
319 // If access to Web>List for user, then link to that module.
320 if ($BE_USER->check('modules','web_list')) {
321 $href=$backPath.'db_list.php?id='.$id.'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'));
322 $str.= '<a href="'.htmlspecialchars($href).'">'.
323 '<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="" />'.
324 '</a>';
325 }
326 // Make link to view page
327 $str.= '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::viewOnClick($id,$backPath,t3lib_BEfunc::BEgetRootLine($id))).'">'.
328 '<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="" />'.
329 '</a>';
330 return $str;
331 }
332
333 /**
334 * Returns a URL with a command to TYPO3 Core Engine (tce_db.php)
335 * See description of the API elsewhere.
336 *
337 * @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"
338 * @param string Redirect URL if any other that t3lib_div::getIndpEnv('REQUEST_URI') is wished
339 * @return string URL to tce_db.php + parameters (backpath is taken from $this->backPath)
340 * @see t3lib_BEfunc::editOnClick()
341 */
342 function issueCommand($params,$rUrl='') {
343 $rUrl = $rUrl ? $rUrl : t3lib_div::getIndpEnv('REQUEST_URI');
344 return $this->backPath.'tce_db.php?'.
345 $params.
346 '&redirect='.($rUrl==-1?"'+T3_THIS_LOCATION+'":rawurlencode($rUrl)).
347 '&vC='.rawurlencode($GLOBALS['BE_USER']->veriCode()).
348 '&prErr=1&uPT=1';
349 }
350
351 /**
352 * Returns true if click-menu layers can be displayed for the current user/browser
353 * Use this to test if click-menus (context sensitive menus) can and should be displayed in the backend.
354 *
355 * @return boolean
356 */
357 function isCMlayers() {
358 return !$GLOBALS['BE_USER']->uc['disableCMlayers'] && $GLOBALS['CLIENT']['FORMSTYLE'] && !($GLOBALS['CLIENT']['SYSTEM']=='mac' && $GLOBALS['CLIENT']['BROWSER']=='Opera');
359 }
360
361 /**
362 * Returns 'this.blur();' if the client supports CSS styles
363 * Use this in links to remove the underlining after being clicked
364 *
365 * @return string
366 */
367 function thisBlur() {
368 return ($GLOBALS['CLIENT']['FORMSTYLE']?'this.blur();':'');
369 }
370
371 /**
372 * Returns ' style='cursor:help;'' if the client supports CSS styles
373 * Use for <a>-links to help texts
374 *
375 * @return string
376 */
377 function helpStyle() {
378 return $GLOBALS['CLIENT']['FORMSTYLE'] ? ' style="cursor:help;"':'';
379 }
380
381 /**
382 * Makes the header (icon+title) for a page (or other record). Used in most modules under Web>*
383 * $table and $row must be a tablename/record from that table
384 * $path will be shown as alt-text for the icon.
385 * The title will be truncated to 45 chars.
386 *
387 * @param string Table name
388 * @param array Record row
389 * @param string Alt text
390 * @param boolean Set $noViewPageIcon true if you don't want a magnifier-icon for viewing the page in the frontend
391 * @param array $tWrap is an array with indexes 0 and 1 each representing HTML-tags (start/end) which will wrap the title
392 * @return string HTML content
393 */
394 function getHeader($table,$row,$path,$noViewPageIcon=0,$tWrap=array('','')) {
395 global $TCA;
396 if (is_array($row) && $row['uid']) {
397 $iconImgTag=t3lib_iconWorks::getIconImage($table,$row,$this->backPath,'title="'.htmlspecialchars($path).'"');
398 $title= strip_tags($row[$TCA[$table]['ctrl']['label']]);
399 $viewPage = $noViewPageIcon ? '' : $this->viewPageIcon($row['uid'],$this->backPath,'');
400 if ($table=='pages') $path.=' - '.t3lib_BEfunc::titleAttribForPages($row,'',0);
401 } else {
402 $iconImgTag='<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/i/_icon_website.gif',$wHattribs='width="18" height="16"').' title="'.htmlspecialchars($path).'" alt="" />';
403 $title=$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
404 }
405
406 return '<span class="typo3-moduleHeader">'.$this->wrapClickMenuOnIcon($iconImgTag,$table,$row['uid']).
407 $viewPage.
408 $tWrap[0].htmlspecialchars(t3lib_div::fixed_lgd_cs($title,45)).$tWrap[1].'</span>';
409 }
410
411 /**
412 * Like ->getHeader() but for files in the File>* main module/submodules
413 * Returns the file-icon with the path of the file set in the alt/title attribute. Shows the file-name after the icon.
414 *
415 * @param string Title string, expected to be the filepath
416 * @param string Alt text
417 * @param string The icon file (relative to TYPO3 dir)
418 * @return string HTML content
419 */
420 function getFileheader($title,$path,$iconfile) {
421 $fileInfo = t3lib_div::split_fileref($title);
422 $title = htmlspecialchars(t3lib_div::fixed_lgd_cs($fileInfo['path'],-35)).'<b>'.htmlspecialchars($fileInfo['file']).'</b>';
423 return '<span class="typo3-moduleHeader"><img'.t3lib_iconWorks::skinImg($this->backPath,$iconfile,'width="18" height="16"').' title="'.htmlspecialchars($path).'" alt="" />'.$title.'</span>';
424 }
425
426 /**
427 * Returns a linked shortcut-icon which will call the shortcut frame and set a shortcut there back to the calling page/module
428 *
429 * @param string Is the list of GET variables to store (if any)
430 * @param string Is the list of SET[] variables to store (if any) - SET[] variables a stored in $GLOBALS["SOBE"]->MOD_SETTINGS for backend modules
431 * @param string Module name string
432 * @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.
433 * @return string HTML content
434 */
435 function makeShortcutIcon($gvList,$setList,$modName,$motherModName="") {
436 $backPath=$this->backPath;
437 $storeUrl=$this->makeShortcutUrl($gvList,$setList);
438 $pathInfo = parse_url(t3lib_div::getIndpEnv('REQUEST_URI'));
439
440 // Add the module identifier automatically if typo3/mod.php is used:
441 if (ereg('typo3/mod\.php$', $pathInfo['path']) && isset($GLOBALS['TBE_MODULES']['_PATHS'][$modName])) {
442 $storeUrl = '&M='.$modName.$storeUrl;
443 }
444
445 if (!strcmp($motherModName,'1')) {
446 $mMN="&motherModName='+top.currentModuleLoaded+'";
447 } elseif ($motherModName) {
448 $mMN='&motherModName='.rawurlencode($motherModName);
449 } else $mMN='';
450
451 $onClick = 'if (top.shortcutFrame && confirm('.
452 $GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.makeShortcut')).
453 ')){top.shortcutFrame.location.href=\''.$backPath.'alt_shortcut.php?modName='.rawurlencode($modName).
454 '&URL='.rawurlencode($pathInfo['path']."?".$storeUrl).
455 $mMN.
456 '\';}return false;';
457
458 $sIcon = '<a href="#" onclick="'.htmlspecialchars($onClick).'">
459 <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 * Returns an array with parts (JavaScript, init-functions, <div>-layers) for use on pages which displays the clickmenu layers (context sensitive menus)
1267 *
1268 * @return array If values are present: [0] = A <script> section for the HTML page header, [1] = onmousemove/onload handler for HTML tag or alike, [2] = Two empty <div> layers for the context menu
1269 */
1270 function getContextMenuCode() {
1271 $content = '
1272 <script type="text/javascript">
1273 /*<![CDATA[*/
1274 // is called from most clickmenu links
1275 function showClickmenu(table, uid, listFr, enDisItems, backPath, addParams) {
1276 var url = "'.$this->backPath.'alt_clickmenu.php?table=" + encodeURIComponent(table)
1277 + "&uid=" + uid
1278 + "&listFr=" + listFr
1279 + "&enDisItems=" + enDisItems
1280 + "&backPath=" + backPath
1281 + "&addParams=" + addParams;
1282
1283 showClickmenu_raw(url);
1284 }
1285 // switch - either forwards call to ajax or does the request in the top frame
1286 function showClickmenu_raw(url) {';
1287 if ($this->isCMlayers()) { // AJAX
1288 $content.= '
1289 url += "&ajax=1";
1290 ajax_doRequest(url);';
1291 } else { // no AJAX
1292 $content.= '
1293 showClickmenu_noajax(url);';
1294 }
1295 $content.= '
1296 }
1297
1298 function showClickmenu_noajax(url) {
1299 top.loadTopMenu(url);
1300 }';
1301 if ($this->isCMlayers()) {
1302 $content.= t3lib_ajax::getJScode('showClickmenu_ajax', 'showClickmenu_noajax');
1303 $content.='
1304 // opens the clickmenu, is called from ajax_doRequest
1305 function showClickmenu_ajax(t3ajax) {
1306 if (t3ajax.getElementsByTagName("data")[0]) {
1307 var clickmenu = t3ajax.getElementsByTagName("data")[0].getElementsByTagName("clickmenu")[0];
1308 var tableData = clickmenu.getElementsByTagName("htmltable")[0].firstChild.data;
1309 var cmlevel = clickmenu.getElementsByTagName("cmlevel")[0].firstChild.data;
1310 setLayerObj(tableData,cmlevel);
1311 }
1312 }
1313
1314 var GLV_gap=10;
1315 var GLV_curLayerX=new Array(0,0);
1316 var GLV_curLayerY=new Array(0,0);
1317 var GLV_curLayerWidth=new Array(0,0);
1318 var GLV_curLayerHeight=new Array(0,0);
1319 var GLV_isVisible=new Array(0,0);
1320 var GLV_x=0;
1321 var GLV_y=0;
1322 var GLV_xRel=0;
1323 var GLV_yRel=0;
1324 var layerObj=new Array();
1325 var layerObjCss=new Array();
1326
1327 //browsercheck...
1328 function GL_checkBrowser(){ //
1329 this.dom= (document.getElementById);
1330 this.safari = (navigator.userAgent.indexOf("Safari")>-1);
1331 this.op= (navigator.userAgent.indexOf("Opera")>-1);
1332 this.op7= this.op && (navigator.appVersion.indexOf("7")>-1); // check for Opera version 7
1333 this.konq= (navigator.userAgent.indexOf("Konq")>-1);
1334 this.ie4= (document.all && !this.dom && !this.op && !this.konq);
1335 this.ie5= (document.all && this.dom && !this.op && !this.konq);
1336 this.ns4= (document.layers && !this.dom && !this.konq);
1337 this.ns5= (!document.all && this.dom && !this.op && !this.konq);
1338 this.ns6= (this.ns5);
1339 this.bw= (this.ie4 || this.ie5 || this.ns4 || this.ns6 || this.op || this.konq);
1340 return this;
1341 }
1342 bw= new GL_checkBrowser();
1343
1344 // GL_getObj(obj)
1345 function GL_getObj(obj){ //
1346 nest="";
1347 this.el= (bw.ie4||bw.op7)?document.all[obj]:bw.ns4?eval(nest+"document."+obj):document.getElementById(obj);
1348 this.css= bw.ns4?this.el:this.el.style;
1349 this.ref= bw.ns4?this.el.document:document;
1350 this.x= (bw.ns4||bw.op)?this.css.left:this.el.offsetLeft;
1351 this.y= (bw.ns4||bw.op)?this.css.top:this.el.offsetTop;
1352 this.height= (bw.ie4||bw.dom)?this.el.offsetHeight:bw.ns4?this.ref.height:0;
1353 this.width= (bw.ie4||bw.dom)?this.el.offsetWidth:bw.ns4?this.ref.width:0;
1354 return this;
1355 }
1356 // GL_getObjCss(obj)
1357 function GL_getObjCss(obj){ //
1358 return bw.dom? document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?document.layers[obj]:0;
1359 }
1360 // GL_getMouse(event)
1361 function GL_getMouse(event) { //
1362 if (layerObj) {
1363 // GLV_x= (bw.ns4||bw.ns5)?event.pageX:(bw.ie4||bw.op)?event.clientX:(event.clientX-2)+document.body.scrollLeft;
1364 // GLV_y= (bw.ns4||bw.ns5)?event.pageY:(bw.ie4||bw.op)?event.clientY:(event.clientY-2)+document.body.scrollTop;
1365 // 17/12 2003: When documents run in XHTML standard compliance mode, the old scrollLeft/Top properties of document.body is gone - and for Opera/MSIE we have to use document.documentElement:
1366
1367 GLV_xRel = event.clientX-2;
1368 GLV_yRel = event.clientY-2;
1369
1370 GLV_x = GLV_xRel;
1371 GLV_y = GLV_yRel;
1372
1373 if (!bw.safari) {
1374 GLV_x = GLV_xRel + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
1375 GLV_y = GLV_yRel + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
1376 }
1377
1378 // status = (GLV_x+GLV_gap-GLV_curLayerX[0]) + " | " + (GLV_y+GLV_gap-GLV_curLayerY[0]);
1379 if (GLV_isVisible[1]) {
1380 if (outsideLayer(1)) hideSpecific(1);
1381 } else if (GLV_isVisible[0]) {
1382 if (outsideLayer(0)) hideSpecific(0);
1383 }
1384 }
1385 }
1386 // outsideLayer(level)
1387 function outsideLayer(level) { //
1388 return GLV_x+GLV_gap-GLV_curLayerX[level] <0 ||
1389 GLV_y+GLV_gap-GLV_curLayerY[level] <0 ||
1390 GLV_curLayerX[level]+GLV_curLayerWidth[level]+GLV_gap-GLV_x <0 ||
1391 GLV_curLayerY[level]+GLV_curLayerHeight[level]+GLV_gap-GLV_y <0;
1392 }
1393 // setLayerObj(html,level)
1394 function setLayerObj(html,level) { //
1395 var winHeight = document.documentElement.clientHeight && !bw.op7 ? document.documentElement.clientHeight : document.body.clientHeight;
1396 var winWidth = document.documentElement.clientWidth && !bw.op7 ? document.documentElement.clientWidth : document.body.clientWidth;
1397 var tempLayerObj = GL_getObj("contentMenu"+level);
1398 var tempLayerObjCss = GL_getObjCss("contentMenu"+level);
1399
1400 if (tempLayerObj && (level==0 || GLV_isVisible[level-1])) {
1401 tempLayerObj.el.innerHTML = html;
1402 tempLayerObj.width= (bw.ie4||bw.dom)?this.el.offsetWidth:bw.ns4?this.ref.width:0;
1403 tempLayerObj.height= (bw.ie4||bw.dom)?this.el.offsetHeight:bw.ns4?this.ref.height:0;
1404
1405 // konqueror (3.2.2) workaround
1406 winHeight = (bw.konq)?window.innerHeight:winHeight;
1407 winWidth = (bw.konq)?window.innerWidth:winWidth;
1408
1409 // Adjusting the Y-height of the layer to fit it into the window frame if it goes under the window frame in the bottom:
1410 if (winHeight-tempLayerObj.height < GLV_yRel) {
1411 if (GLV_yRel < tempLayerObj.height) {
1412 GLV_y+= (winHeight-tempLayerObj.height-GLV_yRel); // Setting it so bottom is just above window height.
1413 } else {
1414 GLV_y-= tempLayerObj.height-8; // Showing the menu upwards
1415 }
1416 }
1417 // Adjusting the X position like Y above
1418 if (winWidth-tempLayerObj.width < GLV_xRel) {
1419 if (GLV_xRel < tempLayerObj.width) {
1420 GLV_x+= (winWidth-tempLayerObj.width-GLV_xRel);
1421 } else {
1422 GLV_x-= tempLayerObj.width-8;
1423 }
1424 }
1425 GLV_x = Math.max(GLV_x,1);
1426 GLV_y = Math.max(GLV_y,1);
1427
1428 GLV_curLayerX[level] = GLV_x;
1429 GLV_curLayerY[level] = GLV_y;
1430 tempLayerObjCss.left = GLV_x+"px";
1431 tempLayerObjCss.top = GLV_y+"px";
1432 tempLayerObjCss.visibility = "visible";
1433 if (bw.ie5) showHideSelectorBoxes("hidden");
1434
1435 GLV_isVisible[level]=1;
1436 GLV_curLayerWidth[level] = tempLayerObj.width;
1437 GLV_curLayerHeight[level] = tempLayerObj.height;
1438 }
1439 }
1440 // hideEmpty()
1441 function hideEmpty() { //
1442 hideSpecific(0);
1443 hideSpecific(1);
1444 return false;
1445 }
1446 // hideSpecific(level)
1447 function hideSpecific(level) { //
1448 GL_getObjCss("contentMenu"+level).visibility = "hidden";
1449 GL_getObj("contentMenu"+level).el.innerHTML = "";
1450 GLV_isVisible[level]=0;
1451
1452 if (bw.ie5 && level==0) showHideSelectorBoxes("visible");
1453 }
1454 // debugObj(obj,name)
1455 function debugObj(obj,name) { //
1456 var acc;
1457 for (i in obj) {if (obj[i]) {acc+=i+": "+obj[i]+"\n";}}
1458 alert("Object: "+name+"\n\n"+acc);
1459 }
1460 // initLayer()
1461 function initLayer(){ //
1462 if (document.all) {
1463 window.onmousemove=GL_getMouse;
1464 }
1465 layerObj = GL_getObj("contentMenu1");
1466 layerObjCss = GL_getObjCss("contentMenu1");
1467 }
1468 function showHideSelectorBoxes(action) { // This function by Michiel van Leening
1469 for (i=0;i<document.forms.length;i++) {
1470 for (j=0;j<document.forms[i].elements.length;j++) {
1471 if(document.forms[i].elements[j].type=="select-one") {
1472 document.forms[i].elements[j].style.visibility=action;
1473 }
1474 }
1475 }
1476 }';
1477 $content.=' /*]]>*/
1478 </script>';
1479 return array(
1480 $content,
1481 ' onmousemove="GL_getMouse(event);" onload="initLayer();"',
1482 '<div id="contentMenu0" style="z-index:1; position:absolute;visibility:hidden"></div><div id="contentMenu1" style="z-index:2; position:absolute;visibility:hidden"></div>'
1483 );
1484 } else {
1485 $content.=' /*]]>*/
1486 </script>';
1487 return array($content,'','');
1488 }
1489 }
1490
1491 /**
1492 * Returns an array with parts (JavaScript, init-functions, <div>-layers) for use on pages which have the drag and drop functionality (usually pages and folder display trees)
1493 *
1494 * @param string indicator of which table the drag and drop function should work on (pages or folders)
1495 * @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
1496 */
1497 function getDragDropCode($table) {
1498 $content = '
1499 <script type="text/javascript">
1500 /*<![CDATA[*/
1501 ';
1502
1503 if ($this->isCMlayers()) {
1504 $content.= '
1505 var dragID = null;
1506 var dragIconCSS = null;
1507
1508 function cancelDragEvent(event) {
1509 dragID = null;
1510 dragIconCSS.visibility = "hidden";
1511 document.onmouseup = null;
1512 document.onmousemove = null;
1513 }
1514
1515 /**
1516 * [Describe function...]
1517 *
1518 * @param [type] $event: ...
1519 * @return [type] ...
1520 */
1521 function mouseMoveEvent (event) {
1522 dragIconCSS.left = GLV_x+5+"px";
1523 dragIconCSS.top = GLV_y-5+"px";
1524 dragIconCSS.visibility = "visible";
1525 return false;
1526 }
1527
1528 /**
1529 * [Describe function...]
1530 *
1531 * @param [type] $id,elementID: ...
1532 * @return [type] ...
1533 */
1534 function dragElement(id,elementID) {
1535 dragID = id;
1536 if (elementID == null) {
1537 elementID = id;
1538 }
1539 document.getElementById("dragIcon").innerHTML=document.getElementById("dragIconID_"+elementID).innerHTML + document.getElementById("dragTitleID_"+elementID).getElementsByTagName("a")[0].innerHTML;
1540 dragIconCSS = new GL_getObjCss("dragIcon");
1541 dragIconCSS.whiteSpace = "nowrap";
1542 document.onmouseup = cancelDragEvent;
1543 document.onmousemove = mouseMoveEvent;
1544 return false;
1545 }
1546
1547 /**
1548 * [Describe function...]
1549 *
1550 * @param [type] $id: ...
1551 * @return [type] ...
1552 */
1553 function dropElement(id) {
1554 if ((dragID != null) && (dragID != id)) {
1555 var url = "'.$this->backPath.'alt_clickmenu.php?dragDrop='.$table.'"
1556 + "&srcId=" + dragID
1557 + "&dstId=" + id
1558 + "&backPath='.t3lib_div::shortMD5(''.'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']).'";
1559 showClickmenu_raw(url);
1560 }
1561 cancelDragEvent();
1562 return false;
1563 }
1564 ';
1565 }
1566 else {
1567 $content.= '
1568 function dragElement(id) { return false; }
1569 function dropElement(id) { return false; }
1570 ';
1571 }
1572 $content.='
1573 /*]]>*/
1574 </script>';
1575
1576 if ($this->isCMlayers()) {
1577 return array(
1578 $content,
1579 '',
1580 '<div id="dragIcon" style="z-index:1;position:absolute;visibility:hidden;filter:alpha(opacity=50);-moz-opacity:0.5;opacity:0.5;"><img src="" width="18" height="16"></div>'
1581 );
1582 } else {
1583 return array($content,'','');
1584 }
1585 }
1586
1587 /**
1588 * Creates a tab menu from an array definition
1589 *
1590 * Returns a tab menu for a module
1591 * Requires the JS function jumpToUrl() to be available
1592 *
1593 * @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=...
1594 * @param string $elementName it the form elements name, probably something like "SET[...]"
1595 * @param string $currentValue is the value to be selected currently.
1596 * @param array $menuItems is an array with the menu items for the selector box
1597 * @param string $script is the script to send the &id to, if empty it's automatically found
1598 * @param string $addParams is additional parameters to pass to the script.
1599 * @return string HTML code for tab menu
1600 * @author Rene Fritz <r.fritz@colorcube.de>
1601 */
1602 function getTabMenu($mainParams,$elementName,$currentValue,$menuItems,$script='',$addparams='') {
1603 $content='';
1604
1605 if (is_array($menuItems)) {
1606 if (!is_array($mainParams)) {
1607 $mainParams = array('id' => $mainParams);
1608 }
1609 $mainParams = t3lib_div::implodeArrayForUrl('',$mainParams);
1610
1611 if (!$script) {$script=basename(PATH_thisScript);}
1612
1613 $menuDef = array();
1614 foreach($menuItems as $value => $label) {
1615 $menuDef[$value]['isActive'] = !strcmp($currentValue,$value);
1616 $menuDef[$value]['label'] = t3lib_div::deHSCentities(htmlspecialchars($label));
1617 $menuDef[$value]['url'] = htmlspecialchars($script.'?'.$mainParams.$addparams.'&'.$elementName.'='.$value);
1618 }
1619 $content = $this->getTabMenuRaw($menuDef);
1620
1621 }
1622 return $content;
1623 }
1624
1625 /**
1626 * Creates the HTML content for the tab menu
1627 *
1628 * @param array Menu items for tabs
1629 * @return string Table HTML
1630 * @access private
1631 */
1632 function getTabMenuRaw($menuItems) {
1633 $content='';
1634
1635 if (is_array($menuItems)) {
1636 $options='';
1637
1638 $count = count($menuItems);
1639 $widthLeft = 1;
1640 $addToAct = 5;
1641
1642 $widthRight = max (1,floor(30-pow($count,1.72)));
1643 $widthTabs = 100 - $widthRight - $widthLeft;
1644 $widthNo = floor(($widthTabs - $addToAct)/$count);
1645 $addToAct = max ($addToAct,$widthTabs-($widthNo*$count));
1646 $widthAct = $widthNo + $addToAct;
1647 $widthRight = 100 - ($widthLeft + ($count*$widthNo) + $addToAct);
1648
1649 $first=true;
1650 foreach($menuItems as $id => $def) {
1651 $isActive = $def['isActive'];
1652 $class = $isActive ? 'tabact' : 'tab';
1653 $width = $isActive ? $widthAct : $widthNo;
1654
1655 // @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.
1656 $label = $def['label'];
1657 $url = htmlspecialchars($def['url']);
1658 $params = $def['addParams'];
1659
1660 if($first) {
1661 $options.= '
1662 <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>';
1663 } else {
1664 $options.='
1665 <td width="'.$width.'%" class="'.$class.'"><a href="'.$url.'" '.$params.'>'.$label.'</a></td>';
1666 }
1667 $first=false;
1668 }
1669
1670 if ($options) {
1671 $content .= '
1672 <!-- Tab menu -->
1673 <table cellpadding="0" cellspacing="0" border="0" width="100%" id="typo3-tabmenu">
1674 <tr>
1675 <td width="'.$widthLeft.'%">&nbsp;</td>
1676 '.$options.'
1677 <td width="'.$widthRight.'%">&nbsp;</td>
1678 </tr>
1679 </table>
1680 <div class="hr" style="margin:0px"></div>';
1681 }
1682
1683 }
1684 return $content;
1685 }
1686
1687 /**
1688 * Creates a DYNAMIC tab-menu where the tabs are switched between with DHTML.
1689 * 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!
1690 *
1691 * @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.
1692 * @param string Identification string. This should be unique for every instance of a dynamic menu!
1693 * @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.
1694 * @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.
1695 * @param integer Character limit for a new row.
1696 * @param boolean If set, tab table cells are not allowed to wrap their content
1697 * @param boolean If set, the tabs will span the full width of their position
1698 * @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.
1699 * @return string JavaScript section for the HTML header.
1700 */
1701 function getDynTabMenu($menuItems,$identString,$toggle=0,$foldout=FALSE,$newRowCharLimit=50,$noWrap=1,$fullWidth=FALSE,$defaultTabIndex=1) {
1702 $content = '';
1703
1704 if (is_array($menuItems)) {
1705
1706 // Init:
1707 $options = array(array());
1708 $divs = array();
1709 $JSinit = array();
1710 $id = $this->getDynTabMenuId($identString);
1711 $noWrap = $noWrap ? ' nowrap="nowrap"' : '';
1712
1713 // Traverse menu items
1714 $c=0;
1715 $tabRows=0;
1716 $titleLenCount = 0;
1717 foreach($menuItems as $index => $def) {
1718 $index+=1; // Need to add one so checking for first index in JavaScript is different than if it is not set at all.
1719
1720 // Switch to next tab row if needed
1721 if (!$foldout && $titleLenCount>$newRowCharLimit) { // 50 characters is probably a reasonable count of characters before switching to next row of tabs.
1722 $titleLenCount=0;
1723 $tabRows++;
1724 $options[$tabRows] = array();
1725 }
1726
1727 if ($toggle==1) {
1728 $onclick = 'this.blur(); DTM_toggle("'.$id.'","'.$index.'"); return false;';
1729 } else {
1730 $onclick = 'this.blur(); DTM_activate("'.$id.'","'.$index.'", '.($toggle<0?1:0).'); return false;';
1731 }
1732
1733 $isActive = strcmp(trim($def['content']),'');
1734
1735 if ($isActive) {
1736
1737 $mouseOverOut = ' onmouseover="DTM_mouseOver(this);" onmouseout="DTM_mouseOut(this);"';
1738
1739 if (!$foldout) {
1740 // Create TAB cell:
1741 $options[$tabRows][] = '
1742 <td class="'.($isActive ? 'tab' : 'disabled').'" id="'.$id.'-'.$index.'-MENU"'.$noWrap.$mouseOverOut.'>'.
1743 ($isActive ? '<a href="#" onclick="'.htmlspecialchars($onclick).'"'.($def['linkTitle'] ? ' title="'.htmlspecialchars($def['linkTitle']).'"':'').'>' : '').
1744 $def['icon'].
1745 ($def['label'] ? htmlspecialchars($def['label']) : '&nbsp;').
1746 $this->icons($def['stateIcon'],'margin-left: 10px;').
1747 ($isActive ? '</a>' :'').
1748 '</td>';
1749 $titleLenCount+= strlen($def['label']);
1750 } else {
1751 // Create DIV layer for content:
1752 $divs[] = '
1753 <div class="'.($isActive ? 'tab' : 'disabled').'" id="'.$id.'-'.$index.'-MENU"'.$mouseOverOut.'>'.
1754 ($isActive ? '<a href="#" onclick="'.htmlspecialchars($onclick).'"'.($def['linkTitle'] ? ' title="'.htmlspecialchars($def['linkTitle']).'"':'').'>' : '').
1755 $def['icon'].
1756 ($def['label'] ? htmlspecialchars($def['label']) : '&nbsp;').
1757 ($isActive ? '</a>' : '').
1758 '</div>';
1759 }
1760
1761 // Create DIV layer for content:
1762 $divs[] = '
1763 <div style="display: none;" id="'.$id.'-'.$index.'-DIV" class="c-tablayer">'.
1764 ($def['description'] ? '<p class="c-descr">'.nl2br(htmlspecialchars($def['description'])).'</p>' : '').
1765 $def['content'].
1766 '</div>';
1767 // Create initialization string:
1768 $JSinit[] = '
1769 DTM_array["'.$id.'"]['.$c.'] = "'.$id.'-'.$index.'";
1770 ';
1771 if ($toggle==1) {
1772 $JSinit[] = '
1773 if (top.DTM_currentTabs["'.$id.'-'.$index.'"]) { DTM_toggle("'.$id.'","'.$index.'",1); }
1774 ';
1775 }
1776
1777 $c++;
1778 }
1779 }
1780
1781 // Render menu:
1782 if (count($options)) {
1783
1784 // Tab menu is compiled:
1785 if (!$foldout) {
1786 $tabContent = '';
1787 for($a=0;$a<=$tabRows;$a++) {
1788 $tabContent.= '
1789
1790 <!-- Tab menu -->
1791 <table cellpadding="0" cellspacing="0" border="0"'.($fullWidth ? ' width="100%"' : '').' class="typo3-dyntabmenu">
1792 <tr>
1793 '.implode('',$options[$a]).'
1794 </tr>
1795 </table>';
1796 }
1797 $content.= '<div class="typo3-dyntabmenu-tabs">'.$tabContent.'</div>';
1798 }
1799
1800 // Div layers are added:
1801 $content.= '
1802 <!-- Div layers for tab menu: -->
1803 <div class="typo3-dyntabmenu-divs'.($foldout?'-foldout':'').'">
1804 '.implode('',$divs).'</div>';
1805
1806 // Java Script section added:
1807 $content.= '
1808 <!-- Initialization JavaScript for the menu -->
1809 <script type="text/javascript">
1810 DTM_array["'.$id.'"] = new Array();
1811 '.implode('',$JSinit).'
1812 '.($toggle<=0 ? 'DTM_activate("'.$id.'", top.DTM_currentTabs["'.$id.'"]?top.DTM_currentTabs["'.$id.'"]:'.intval($defaultTabIndex).', 0);' : '').'
1813 </script>
1814
1815 ';
1816 }
1817
1818 }
1819 return $content;
1820 }
1821
1822 /**
1823 * Creates the id for dynTabMenus.
1824 *
1825 * @param string $identString: Identification string. This should be unique for every instance of a dynamic menu!
1826 * @return string The id with a short MD5 of $identString and prefixed "DTM-", like "DTM-2e8791854a"
1827 */
1828 function getDynTabMenuId($identString) {
1829 $id = 'DTM-'.t3lib_div::shortMD5($identString);
1830 return $id;
1831 }
1832
1833 /**
1834 * Returns dynamic tab menu header JS code.
1835 *
1836 * @return string JavaScript section for the HTML header.
1837 */
1838 function getDynTabMenuJScode() {
1839 return '
1840 <script type="text/javascript">
1841 /*<![CDATA[*/
1842 var DTM_array = new Array();
1843 var DTM_origClass = new String();
1844
1845 // if tabs are used in a popup window the array might not exists
1846 if(!top.DTM_currentTabs) {
1847 top.DTM_currentTabs = new Array();
1848 }
1849
1850 function DTM_activate(idBase,index,doToogle) { //
1851 // Hiding all:
1852 if (DTM_array[idBase]) {
1853 for(cnt = 0; cnt < DTM_array[idBase].length ; cnt++) {
1854 if (DTM_array[idBase][cnt] != idBase+"-"+index) {
1855 document.getElementById(DTM_array[idBase][cnt]+"-DIV").style.display = "none";
1856 document.getElementById(DTM_array[idBase][cnt]+"-MENU").attributes.getNamedItem("class").nodeValue = "tab";
1857 }
1858 }
1859 }
1860
1861 // Showing one:
1862 if (document.getElementById(idBase+"-"+index+"-DIV")) {
1863 if (doToogle && document.getElementById(idBase+"-"+index+"-DIV").style.display == "block") {
1864 document.getElementById(idBase+"-"+index+"-DIV").style.display = "none";
1865 if(DTM_origClass=="") {
1866 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "tab";
1867 } else {
1868 DTM_origClass = "tab";
1869 }
1870 top.DTM_currentTabs[idBase] = -1;
1871 } else {
1872 document.getElementById(idBase+"-"+index+"-DIV").style.display = "block";
1873 if(DTM_origClass=="") {
1874 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "tabact";
1875 } else {
1876 DTM_origClass = "tabact";
1877 }
1878 top.DTM_currentTabs[idBase] = index;
1879 }
1880 }
1881 }
1882 function DTM_toggle(idBase,index,isInit) { //
1883 // Showing one:
1884 if (document.getElementById(idBase+"-"+index+"-DIV")) {
1885 if (document.getElementById(idBase+"-"+index+"-DIV").style.display == "block") {
1886 document.getElementById(idBase+"-"+index+"-DIV").style.display = "none";
1887 if(isInit) {
1888 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "tab";
1889 } else {
1890 DTM_origClass = "tab";
1891 }
1892 top.DTM_currentTabs[idBase+"-"+index] = 0;
1893 } else {
1894 document.getElementById(idBase+"-"+index+"-DIV").style.display = "block";
1895 if(isInit) {
1896 document.getElementById(idBase+"-"+index+"-MENU").attributes.getNamedItem("class").nodeValue = "tabact";
1897 } else {
1898 DTM_origClass = "tabact";
1899 }
1900 top.DTM_currentTabs[idBase+"-"+index] = 1;
1901 }
1902 }
1903 }
1904
1905 function DTM_mouseOver(obj) { //
1906 DTM_origClass = obj.attributes.getNamedItem(\'class\').nodeValue;
1907 obj.attributes.getNamedItem(\'class\').nodeValue += "_over";
1908 }
1909
1910 function DTM_mouseOut(obj) { //
1911 obj.attributes.getNamedItem(\'class\').nodeValue = DTM_origClass;
1912 DTM_origClass = "";
1913 }
1914
1915
1916 /*]]>*/
1917 </script>
1918 ';
1919 }
1920
1921 /**
1922 * Creates the version selector for the page id inputted.
1923 * Requires the core version management extension, "version" to be loaded.
1924 *
1925 * @param integer Page id to create selector for.
1926 * @param boolean If set, there will be no button for swapping page.
1927 * @return void
1928 */
1929 function getVersionSelector($id,$noAction=FALSE) {
1930
1931 if ($id>0) {
1932 if (t3lib_extMgm::isLoaded('version') && $GLOBALS['BE_USER']->workspace==0) {
1933
1934 // Get Current page record:
1935 $curPage = t3lib_BEfunc::getRecord('pages',$id);
1936 // If the selected page is not online, find the right ID
1937 $onlineId = ($curPage['pid']==-1 ? $curPage['t3ver_oid'] : $id);
1938 // Select all versions of online version:
1939 $versions = t3lib_BEfunc::selectVersionsOfRecord('pages', $onlineId, 'uid,pid,t3ver_label,t3ver_oid,t3ver_wsid,t3ver_id');
1940
1941 // If more than one was found...:
1942 if (count($versions)>1) {
1943
1944 // Create selector box entries:
1945 $opt = array();
1946 foreach($versions as $vRow) {
1947 $opt[] = '<option value="'.htmlspecialchars(t3lib_div::linkThisScript(array('id'=>$vRow['uid']))).'"'.($id==$vRow['uid']?' selected="selected"':'').'>'.
1948 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').'<=':'')).
1949 '</option>';
1950 }
1951
1952 // Add management link:
1953 $opt[] = '<option value="'.htmlspecialchars(t3lib_div::linkThisScript(array('id'=>$id))).'">---</option>';
1954 $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>';
1955
1956 // Create onchange handler:
1957 $onChange = "window.location.href=this.options[this.selectedIndex].value;";
1958
1959 // Controls:
1960 if ($id==$onlineId) {
1961 $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>';
1962 } elseif (!$noAction) {
1963 $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">'.
1964 '<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).'" />'.
1965 '<b>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:ver.swap',1).'</b></a>';
1966 }
1967
1968 // Write out HTML code:
1969 return '
1970
1971 <!--
1972 Version selector:
1973 -->
1974 <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
1975 <tr>
1976 <td>'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:ver.selVer',1).'</td>
1977 <td>
1978 <select onchange="'.htmlspecialchars($onChange).'">
1979 '.implode('',$opt).'
1980 </select></td>
1981 <td>'.$controls.'</td>
1982 </tr>
1983 </table>
1984 ';
1985 }
1986 } elseif ($GLOBALS['BE_USER']->workspace!==0) {
1987
1988 // Write out HTML code:
1989 switch($GLOBALS['BE_USER']->workspace) {
1990 case 0:
1991 $wsTitle = 'LIVE';
1992 break;
1993 case -1:
1994 $wsTitle = 'Draft';
1995 break;
1996 default:
1997 $wsTitle = $GLOBALS['BE_USER']->workspaceRec['title'];
1998 break;
1999 }
2000
2001 if (t3lib_BEfunc::isPidInVersionizedBranch($id)=='branchpoint') {
2002 return '
2003
2004 <!--
2005 Version selector:
2006 -->
2007 <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
2008 <tr>
2009 <td>Workspace: "'.htmlspecialchars($wsTitle).'"</td>
2010 <td><em>Inside branch, no further versioning possible</em></td>
2011 </tr>
2012 </table>
2013 ';
2014 } else {
2015 // Get Current page record:
2016 $curPage = t3lib_BEfunc::getRecord('pages',$id);
2017 // If the selected page is not online, find the right ID
2018 $onlineId = ($curPage['pid']==-1 ? $curPage['t3ver_oid'] : $id);
2019 // The version of page:
2020 $verPage = t3lib_BEfunc::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, 'pages', $onlineId);
2021
2022 if (!$verPage) {
2023
2024 if (!count(t3lib_BEfunc::countVersionsOfRecordsOnPage($GLOBALS['BE_USER']->workspace, $onlineId))) {
2025 if ($GLOBALS['BE_USER']->workspaceVersioningTypeAccess(0)) {
2026
2027 $onClick = $this->issueCommand('&cmd[pages]['.$onlineId.'][version][action]=new&cmd[pages]['.$onlineId.'][version][treeLevels]=0',t3lib_div::linkThisScript(array('id'=>$onlineId)));
2028 $onClick = 'window.location.href=\''.$onClick.'\'; return false;';
2029 // Write out HTML code:
2030 return '
2031
2032 <!--
2033 No version yet, create one?
2034 -->
2035 <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
2036 <tr>
2037 <td>Workspace: "'.htmlspecialchars($wsTitle).'"</td>
2038 <td>
2039 <input type="submit" value="New version of page" name="_" onclick="'.htmlspecialchars($onClick).'" /></td>
2040 </tr>
2041 </table>
2042 ';
2043 }
2044 } else {
2045 return '
2046
2047 <!--
2048 Version selector:
2049 -->
2050 <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
2051 <tr>
2052 <td>Workspace: "'.htmlspecialchars($wsTitle).'"</td>
2053 <td><em>Versions found on page, no "Page" versioning possible</em></td>
2054 </tr>
2055 </table>
2056 ';
2057 }
2058 } elseif ($verPage['t3ver_swapmode']==0) {
2059 $onClick = $this->issueCommand('&cmd[pages]['.$onlineId.'][version][action]=swap&cmd[pages]['.$onlineId.'][version][swapWith]='.$verPage['uid'],t3lib_div::linkThisScript(array('id'=>$onlineId)));
2060 $onClick = 'window.location.href=\''.$onClick.'\'; return false;';
2061
2062 // Write out HTML code:
2063 return '
2064
2065 <!--
2066 Version selector:
2067 -->
2068 <table border="0" cellpadding="0" cellspacing="0" id="typo3-versionSelector">
2069 <tr>
2070 <td>Workspace: "'.htmlspecialchars($wsTitle).'"</td>
2071 <td>
2072 <input type="submit" value="Publish page" name="_" onclick="'.htmlspecialchars($onClick).'" /></td>
2073 </tr>
2074 </table>
2075 ';
2076 }
2077 }
2078 }
2079 }
2080 }
2081 }
2082
2083
2084
2085 // ******************************
2086 // Extension classes of the template class.
2087 // These are meant to provide backend screens with different widths.
2088 // They still do because of the different class-prefixes used for the <div>-sections
2089 // but obviously the final width is determined by the stylesheet used.
2090 // ******************************
2091
2092 /**
2093 * 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
2094 * The class were more significant in the past than today.
2095 *
2096 */
2097 class bigDoc extends template {
2098 var $divClass = 'typo3-bigDoc';
2099 }
2100
2101 /**
2102 * Extension class for "template" - used for backend pages without the "document" background image
2103 * The class were more significant in the past than today.
2104 *
2105 */
2106 class noDoc extends template {
2107 var $divClass = 'typo3-noDoc';
2108 }
2109
2110 /**
2111 * 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)
2112 * The class were more significant in the past than today.
2113 *
2114 */
2115 class smallDoc extends template {
2116 var $divClass = 'typo3-smallDoc';
2117 }
2118
2119 /**
2120 * 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.
2121 * The class were more significant in the past than today. But probably you should use this one for most modules you make.
2122 *
2123 */
2124 class mediumDoc extends template {
2125 var $divClass = 'typo3-mediumDoc';
2126 }
2127
2128
2129
2130 // Include extension to the template class?
2131 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/template.php']) {
2132 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/template.php']);
2133 }
2134
2135
2136
2137 // ******************************************************
2138 // The backend language engine is started (ext: "lang")
2139 // ******************************************************
2140 require_once(PATH_typo3.'sysext/lang/lang.php');
2141 $LANG = t3lib_div::makeInstance('language');
2142 $LANG->init($BE_USER->uc['lang']);
2143
2144
2145
2146 // ******************************
2147 // The template is loaded
2148 // ******************************
2149 $TBE_TEMPLATE = t3lib_div::makeInstance('template');
2150 ?>