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