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