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