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