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