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