[TASK] Follow-Up: favicon for backend window
[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 $this->pageRenderer->setFavIcon('gfx/favicon.ico');
719 if ($this->useCompatibilityTag) {
720 $this->pageRenderer->addMetaTag($this->xUaCompatible($this->xUaCompatibilityVersion));
721 }
722 $this->pageRenderer->setTitle($title);
723
724 // add docstyles
725 $this->docStyle();
726
727 if ($this->extDirectStateProvider) {
728 $this->pageRenderer->addJsFile($this->backPath . '../t3lib/js/extjs/ExtDirect.StateProvider.js');
729 }
730
731 // Add jsCode for overriding the console with a debug panel connection
732 $this->pageRenderer->addJsInlineCode(
733 'consoleOverrideWithDebugPanel',
734 'if (typeof top.Ext === "object") {
735 top.Ext.onReady(function() {
736 if (typeof console === "undefined") {
737 if (top && top.TYPO3 && top.TYPO3.Backend && top.TYPO3.Backend.DebugConsole) {
738 console = top.TYPO3.Backend.DebugConsole;
739 } else {
740 console = {
741 log: Ext.log,
742 info: Ext.log,
743 warn: Ext.log,
744 error: Ext.log
745 };
746 }
747 }
748 });
749 }
750 ',
751 FALSE
752 );
753
754 $this->pageRenderer->addHeaderData($this->JScode);
755
756 foreach ($this->JScodeArray as $name => $code) {
757 $this->pageRenderer->addJsInlineCode($name, $code, FALSE);
758 }
759
760 if (count($this->JScodeLibArray)) {
761 foreach($this->JScodeLibArray as $library) {
762 $this->pageRenderer->addHeaderData($library);
763 }
764 }
765
766 if ($this->extJScode) {
767 $this->pageRenderer->addExtOnReadyCode($this->extJScode);
768 }
769
770 // hook for additional headerData
771 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['preHeaderRenderHook'])) {
772 $preHeaderRenderHook =& $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['preHeaderRenderHook'];
773 if (is_array($preHeaderRenderHook)) {
774 $hookParameters = array(
775 'pageRenderer' => &$this->pageRenderer,
776 );
777 foreach ($preHeaderRenderHook as $hookFunction) {
778 t3lib_div::callUserFunction($hookFunction, $hookParameters, $this);
779 }
780 }
781 }
782
783 // Construct page header.
784 $str = $this->pageRenderer->render(t3lib_PageRenderer::PART_HEADER);
785
786 $this->JScodeLibArray = array();
787 $this->JScode = $this->extJScode = '';
788 $this->JScodeArray = array();
789
790 $this->endOfPageJsBlock = $this->pageRenderer->render(t3lib_PageRenderer::PART_FOOTER);
791
792 if ($this->docType == 'xhtml_frames') {
793 return $str;
794 } else
795 $str .= $this->docBodyTagBegin().
796 ($this->divClass ?
797 '
798
799 <!-- Wrapping DIV-section for whole page BEGIN -->
800 <div class="' . $this->divClass . '">
801 '
802 : '' ) . trim($this->form);
803 return $str;
804 }
805
806 /**
807 * Returns page end; This includes finishing form, div, body and html tags.
808 *
809 * @return string The HTML end of a page
810 * @see startPage()
811 */
812 function endPage() {
813 $str = $this->sectionEnd().
814 $this->postCode.
815 $this->endPageJS().
816 $this->wrapScriptTags(t3lib_BEfunc::getUpdateSignalCode()).
817 $this->parseTime().
818 ($this->form?'
819 </form>':'');
820 // If something is in buffer like debug, put it to end of page
821 if (ob_get_contents()) {
822 $str .= ob_get_clean();
823 if (!headers_sent()) {
824 header('Content-Encoding: None');
825 }
826 }
827
828 if ($this->docType !== 'xhtml_frames') {
829
830 $str .= ($this->divClass?'
831
832 <!-- Wrapping DIV-section for whole page END -->
833 </div>':'') . $this->endOfPageJsBlock;
834 }
835
836
837 // Logging: Can't find better place to put it:
838 if (TYPO3_DLOG) t3lib_div::devLog('END of BACKEND session', 'template', 0, array('_FLUSH' => TRUE));
839
840 return $str;
841 }
842
843 /**
844 * Shortcut for render the complete page of a module
845 *
846 * @param string $title page title
847 * @param string $content page content
848 * @param boolean $includeCsh flag for including csh code
849 * @return string complete page
850 */
851 public function render($title, $content, $includeCsh = TRUE) {
852 $pageContent = $this->startPage($title, $includeCsh);
853 $pageContent .= $content;
854 $pageContent .= $this->endPage();
855
856 return $this->insertStylesAndJS($pageContent);
857 }
858
859 /**
860 * Returns the header-bar in the top of most backend modules
861 * Closes section if open.
862 *
863 * @param string $text The text string for the header
864 * @return string HTML content
865 */
866 function header($text) {
867 $str='
868
869 <!-- MAIN Header in page top -->
870 <h2>'.htmlspecialchars($text).'</h2>
871 ';
872 return $this->sectionEnd().$str;
873 }
874
875 /**
876 * Begins an output section and sets header and content
877 *
878 * @param string $label The header
879 * @param string $text The HTML-content
880 * @param boolean $nostrtoupper A flag that will prevent the header from being converted to uppercase
881 * @param boolean $sH Defines the type of header (if set, "<h3>" rather than the default "h4")
882 * @param integer $type The number of an icon to show with the header (see the icon-function). -1,1,2,3
883 * @param boolean $allowHTMLinHeader If set, HTML tags are allowed in $label (otherwise this value is by default htmlspecialchars()'ed)
884 * @return string HTML content
885 * @see icons(), sectionHeader()
886 */
887 function section($label, $text, $nostrtoupper = FALSE, $sH = FALSE, $type = 0, $allowHTMLinHeader = FALSE) {
888 $str = '';
889
890 // Setting header
891 if ($label) {
892 if (!$allowHTMLinHeader) $label = htmlspecialchars($label);
893 $str.=$this->sectionHeader($this->icons($type).$label, $sH, $nostrtoupper ? '' : ' class="uppercase"');
894 }
895 // Setting content
896 $str .= '
897
898 <!-- Section content -->
899 '.$text;
900
901 return $this->sectionBegin().$str;
902 }
903
904 /**
905 * Inserts a divider image
906 * Ends a section (if open) before inserting the image
907 *
908 * @param integer $dist The margin-top/-bottom of the <hr> ruler.
909 * @return string HTML content
910 */
911 function divider($dist) {
912 $dist = intval($dist);
913 $str = '
914
915 <!-- DIVIDER -->
916 <hr style="margin-top: '.$dist.'px; margin-bottom: '.$dist.'px;" />
917 ';
918 return $this->sectionEnd().$str;
919 }
920
921 /**
922 * Returns a blank <div>-section with a height
923 *
924 * @param integer $dist Padding-top for the div-section (should be margin-top but konqueror (3.1) doesn't like it :-(
925 * @return string HTML content
926 */
927 function spacer($dist) {
928 if ($dist > 0) {
929 return '
930
931 <!-- Spacer element -->
932 <div style="padding-top: '.intval($dist).'px;"></div>
933 ';
934 }
935 }
936
937 /**
938 * Make a section header.
939 * Begins a section if not already open.
940 *
941 * @param string $label The label between the <h3> or <h4> tags. (Allows HTML)
942 * @param boolean $sH If set, <h3> is used, otherwise <h4>
943 * @param string $addAttrib Additional attributes to h-tag, eg. ' class=""'
944 * @return string HTML content
945 */
946 function sectionHeader($label, $sH = FALSE, $addAttrib = '') {
947 $tag = ($sH ? 'h3' : 'h4');
948 if ($addAttrib && substr($addAttrib, 0, 1) !== ' ') {
949 $addAttrib = ' ' . $addAttrib;
950 }
951 $str = '
952
953 <!-- Section header -->
954 <' . $tag . $addAttrib . '>' . $label . '</' . $tag . '>
955 ';
956 return $this->sectionBegin() . $str;
957 }
958
959 /**
960 * Begins an output section.
961 * Returns the <div>-begin tag AND sets the ->sectionFlag TRUE (if the ->sectionFlag is not already set!)
962 * 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!
963 *
964 * @return string HTML content
965 */
966 function sectionBegin() {
967 if (!$this->sectionFlag) {
968 $this->sectionFlag=1;
969 $str='
970
971 <!-- ***********************
972 Begin output section.
973 *********************** -->
974 <div>
975 ';
976 return $str;
977 } else return '';
978 }
979
980 /**
981 * Ends and output section
982 * Returns the </div>-end tag AND clears the ->sectionFlag (but does so only IF the sectionFlag is set - that is a section is 'open')
983 * See sectionBegin() also.
984 *
985 * @return string HTML content
986 */
987 function sectionEnd() {
988 if ($this->sectionFlag) {
989 $this->sectionFlag=0;
990 return '
991 </div>
992 <!-- *********************
993 End output section.
994 ********************* -->
995 ';
996 } else return '';
997 }
998
999 /**
1000 * If a form-tag is defined in ->form then and end-tag for that <form> element is outputted
1001 * Further a JavaScript section is outputted which will update the top.busy session-expiry object (unless $this->endJS is set to FALSE)
1002 *
1003 * @return string HTML content (<script> tag section)
1004 */
1005 function endPageJS() {
1006 return ($this->endJS?'
1007 <script type="text/javascript">
1008 /*<![CDATA[*/
1009 if (top.busy && top.busy.loginRefreshed) {
1010 top.busy.loginRefreshed();
1011 }
1012 /*]]>*/
1013 </script>':'');
1014 }
1015
1016 /**
1017 * Creates the bodyTag.
1018 * You can add to the bodyTag by $this->bodyTagAdditions
1019 *
1020 * @return string HTML body tag
1021 */
1022 function docBodyTagBegin() {
1023 $bodyContent = 'body onclick="if (top.menuReset) top.menuReset();" '.trim($this->bodyTagAdditions.($this->bodyTagId ? ' id="'.$this->bodyTagId.'"' : ''));
1024 return '<'.trim($bodyContent).'>';
1025 }
1026
1027 /**
1028 * Outputting document style
1029 *
1030 * @return string HTML style section/link tags
1031 */
1032 function docStyle() {
1033
1034 // Request background image:
1035 if ($this->backGroundImage) {
1036 $this->inDocStylesArray[]=' BODY { background-image: url('.$this->backPath.$this->backGroundImage.'); }';
1037 }
1038
1039 // Add inDoc styles variables as well:
1040 $this->inDocStylesArray[] = $this->inDocStyles;
1041 $this->inDocStylesArray[] = $this->inDocStyles_TBEstyle;
1042
1043 // Implode it all:
1044 $inDocStyles = implode(LF, $this->inDocStylesArray);
1045
1046 if ($this->styleSheetFile) {
1047 $this->pageRenderer->addCssFile($this->backPath . $this->styleSheetFile);
1048 }
1049 if ($this->styleSheetFile2) {
1050 $this->pageRenderer->addCssFile($this->backPath . $this->styleSheetFile2);
1051 }
1052
1053 $this->pageRenderer->addCssInlineBlock('inDocStyles', $inDocStyles . LF . '/*###POSTCSSMARKER###*/');
1054 if ($this->styleSheetFile_post) {
1055 $this->pageRenderer->addCssFile($this->backPath . $this->styleSheetFile_post);
1056 }
1057
1058 }
1059
1060 /**
1061 * Insert additional style sheet link
1062 *
1063 * @param string $key some key identifying the style sheet
1064 * @param string $href uri to the style sheet file
1065 * @param string $title value for the title attribute of the link element
1066 * @param string $relation value for the rel attribute of the link element
1067 * @return void
1068 */
1069 function addStyleSheet($key, $href, $title = '', $relation = 'stylesheet') {
1070 if (strpos($href, '://') !== FALSE || substr($href, 0, 1) === '/') {
1071 $file = $href;
1072 } else {
1073 $file = $this->backPath . $href;
1074 }
1075 $this->pageRenderer->addCssFile($file, $relation, 'screen', $title);
1076 }
1077
1078 /**
1079 * Add all *.css files of the directory $path to the stylesheets
1080 *
1081 * @param string $path directory to add
1082 * @return void
1083 */
1084 function addStyleSheetDirectory($path) {
1085 // Calculation needed, when TYPO3 source is used via a symlink
1086 // absolute path to the stylesheets
1087 $filePath = dirname(t3lib_div::getIndpEnv('SCRIPT_FILENAME')) . '/' . $GLOBALS['BACK_PATH'] . $path;
1088 // Clean the path
1089 $resolvedPath = t3lib_div::resolveBackPath($filePath);
1090 // Read all files in directory and sort them alphabetically
1091 $files = t3lib_div::getFilesInDir($resolvedPath, 'css', FALSE, 1);
1092 foreach ($files as $file) {
1093 $this->pageRenderer->addCssFile($GLOBALS['BACK_PATH'] . $path . $file, 'stylesheet', 'all');
1094 }
1095 }
1096
1097 /**
1098 * Insert post rendering document style into already rendered content
1099 * This is needed for extobjbase
1100 *
1101 * @param string $content style-content to insert.
1102 * @return string content with inserted styles
1103 */
1104 function insertStylesAndJS($content) {
1105 // Insert accumulated CSS
1106 $this->inDocStylesArray[] = $this->inDocStyles;
1107 $styles = LF.implode(LF, $this->inDocStylesArray);
1108 $content = str_replace('/*###POSTCSSMARKER###*/', $styles, $content);
1109
1110 // Insert accumulated JS
1111 $jscode = $this->JScode.LF.$this->wrapScriptTags(implode(LF, $this->JScodeArray));
1112 $content = str_replace('<!--###POSTJSMARKER###-->', $jscode, $content);
1113
1114 return $content;
1115 }
1116
1117 /**
1118 * Returns an array of all stylesheet directories belonging to core and skins
1119 *
1120 * @return array Stylesheet directories
1121 */
1122 public function getSkinStylesheetDirectories() {
1123 $stylesheetDirectories = array();
1124
1125 // Add default core stylesheets
1126 foreach ($this->stylesheetsCore as $stylesheetDir) {
1127 $stylesheetDirectories[] = $stylesheetDir;
1128 }
1129
1130 // Stylesheets from skins
1131 // merge default css directories ($this->stylesheetsSkin) with additional ones and include them
1132 if (is_array($GLOBALS['TBE_STYLES']['skins'])) {
1133 // loop over all registered skins
1134 foreach ($GLOBALS['TBE_STYLES']['skins'] as $skinExtKey => $skin) {
1135 $skinStylesheetDirs = $this->stylesheetsSkins;
1136
1137 // Skins can add custom stylesheetDirectories using
1138 // $GLOBALS['TBE_STYLES']['skins'][$_EXTKEY]['stylesheetDirectories']
1139 if (is_array($skin['stylesheetDirectories'])) {
1140 $skinStylesheetDirs = array_merge($skinStylesheetDirs, $skin['stylesheetDirectories']);
1141 }
1142
1143 // Add all registered directories
1144 foreach ($skinStylesheetDirs as $stylesheetDir) {
1145 // for EXT:myskin/stylesheets/ syntax
1146 if (substr($stylesheetDir, 0, 4) === 'EXT:') {
1147 list($extKey, $path) = explode('/', substr($stylesheetDir, 4), 2);
1148 if (strcmp($extKey, '') && t3lib_extMgm::isLoaded($extKey) && strcmp($path, '')) {
1149 $stylesheetDirectories[] = t3lib_extMgm::extRelPath($extKey) . $path;
1150 }
1151 } else {
1152 // For relative paths
1153 $stylesheetDirectories[] = t3lib_extMgm::extRelPath($skinExtKey) . $stylesheetDir;
1154 }
1155 }
1156 }
1157 }
1158 return $stylesheetDirectories;
1159 }
1160
1161 /**
1162 * Initialize the charset.
1163 * Sets the internal $this->charset variable to the charset defined in $GLOBALS["LANG"] (or the default as set in this class)
1164 * Returns the meta-tag for the document header
1165 *
1166 * @return string <meta> tag with charset from $this->charset or $GLOBALS['LANG']->charSet
1167 */
1168 function initCharset() {
1169 // Set charset to the charset provided by the current backend users language selection:
1170 $this->charset = $GLOBALS['LANG']->charSet ? $GLOBALS['LANG']->charSet : $this->charset;
1171 // Return meta tag:
1172 return '<meta http-equiv="Content-Type" content="text/html; charset='.$this->charset.'" />';
1173 }
1174
1175 /**
1176 * Returns generator meta tag
1177 *
1178 * @return string <meta> tag with name "generator"
1179 */
1180 function generator() {
1181 $str = 'TYPO3 '.TYPO3_branch.', ' . TYPO3_URL_GENERAL . ', &#169; Kasper Sk&#229;rh&#248;j ' . TYPO3_copyright_year . ', extensions are copyright of their respective owners.';
1182 return '<meta name="generator" content="'.$str .'" />';
1183 }
1184
1185 /**
1186 * Returns X-UA-Compatible meta tag
1187 *
1188 * @param string $content Content of the compatible tag (default: IE-8)
1189 * @return string <meta http-equiv="X-UA-Compatible" content="???" />
1190 */
1191 public function xUaCompatible($content = 'IE=8') {
1192 return '<meta http-equiv="X-UA-Compatible" content="' . $content . '" />';
1193 }
1194
1195 /*****************************************
1196 *
1197 * OTHER ELEMENTS
1198 * Tables, buttons, formatting dimmed/red strings
1199 *
1200 ******************************************/
1201
1202 /**
1203 * Returns an image-tag with an 18x16 icon of the following types:
1204 *
1205 * $type:
1206 * -1: OK icon (Check-mark)
1207 * 1: Notice (Speach-bubble)
1208 * 2: Warning (Yellow triangle)
1209 * 3: Fatal error (Red stop sign)
1210 *
1211 * @param integer $type See description
1212 * @param string $styleAttribValue Value for style attribute
1213 * @return string HTML image tag (if applicable)
1214 */
1215 function icons($type, $styleAttribValue = '') {
1216 switch($type) {
1217 case self::STATUS_ICON_ERROR:
1218 $icon = 'status-dialog-error';
1219 break;
1220 case self::STATUS_ICON_WARNING:
1221 $icon = 'status-dialog-warning';
1222 break;
1223 case self::STATUS_ICON_NOTIFICATION:
1224 $icon = 'status-dialog-notification';
1225 break;
1226 case self::STATUS_ICON_OK:
1227 $icon = 'status-dialog-ok';
1228 break;
1229 default:
1230 break;
1231 }
1232 if ($icon) {
1233 return t3lib_iconWorks::getSpriteIcon($icon);
1234 }
1235 }
1236
1237 /**
1238 * Returns an <input> button with the $onClick action and $label
1239 *
1240 * @param string $onClick The value of the onclick attribute of the input tag (submit type)
1241 * @param string $label The label for the button (which will be htmlspecialchar'ed)
1242 * @return string A <input> tag of the type "submit"
1243 */
1244 function t3Button($onClick, $label) {
1245 $button = '<input type="submit" onclick="'.htmlspecialchars($onClick).'; return false;" value="'.htmlspecialchars($label).'" />';
1246 return $button;
1247 }
1248
1249 /**
1250 * Dimmed-fontwrap. Returns the string wrapped in a <span>-tag defining the color to be gray/dimmed
1251 *
1252 * @param string $string Input string
1253 * @return string Output string
1254 */
1255 function dfw($string) {
1256 return '<span class="typo3-dimmed">'.$string.'</span>';
1257 }
1258
1259 /**
1260 * red-fontwrap. Returns the string wrapped in a <span>-tag defining the color to be red
1261 *
1262 * @param string $string Input string
1263 * @return string Output string
1264 */
1265 function rfw($string) {
1266 return '<span class="typo3-red">'.$string.'</span>';
1267 }
1268
1269 /**
1270 * Returns string wrapped in CDATA "tags" for XML / XHTML (wrap content of <script> and <style> sections in those!)
1271 *
1272 * @param string $string Input string
1273 * @return string Output string
1274 */
1275 function wrapInCData($string) {
1276 $string = '/*<![CDATA[*/'.
1277 $string.
1278 '/*]]>*/';
1279
1280 return $string;
1281 }
1282
1283 /**
1284 * Wraps the input string in script tags.
1285 * Automatic re-identing of the JS code is done by using the first line as ident reference.
1286 * This is nice for identing JS code with PHP code on the same level.
1287 *
1288 * @param string $string Input string
1289 * @param boolean $linebreak Wrap script element in linebreaks? Default is TRUE.
1290 * @return string Output string
1291 */
1292 function wrapScriptTags($string, $linebreak = TRUE) {
1293 if (trim($string)) {
1294 // <script wrapped in nl?
1295 $cr = $linebreak? LF : '';
1296
1297 // Remove nl from the beginning
1298 $string = preg_replace ('/^\n+/', '', $string);
1299 // Re-ident to one tab using the first line as reference
1300 $match = array();
1301 if (preg_match('/^(\t+)/', $string, $match)) {
1302 $string = str_replace($match[1], TAB, $string);
1303 }
1304 $string = $cr.'<script type="text/javascript">
1305 /*<![CDATA[*/
1306 '.$string.'
1307 /*]]>*/
1308 </script>'.$cr;
1309 }
1310 return trim($string);
1311 }
1312
1313 // These vars defines the layout for the table produced by the table() function.
1314 // You can override these values from outside if you like.
1315 var $tableLayout = array(
1316 'defRow' => array(
1317 'defCol' => array('<td valign="top">', '</td>')
1318 )
1319 );
1320 var $table_TR = '<tr>';
1321 var $table_TABLE = '<table border="0" cellspacing="0" cellpadding="0" class="typo3-dblist" id="typo3-tmpltable">';
1322
1323 /**
1324 * Returns a table based on the input $data
1325 *
1326 * @param array $data Multidim array with first levels = rows, second levels = cells
1327 * @param array $layout If set, then this provides an alternative layout array instead of $this->tableLayout
1328 * @return string The HTML table.
1329 * @internal
1330 */
1331 function table($data, $layout = NULL) {
1332 $result = '';
1333 if (is_array($data)) {
1334 $tableLayout = (is_array($layout) ? $layout : $this->tableLayout);
1335
1336 $rowCount = 0;
1337 foreach ($data as $tableRow) {
1338 if ($rowCount % 2) {
1339 $layout = is_array($tableLayout['defRowOdd']) ? $tableLayout['defRowOdd'] : $tableLayout['defRow'];
1340 } else {
1341 $layout = is_array($tableLayout['defRowEven']) ? $tableLayout['defRowEven'] : $tableLayout['defRow'];
1342 }
1343 $rowLayout = is_array($tableLayout[$rowCount]) ? $tableLayout[$rowCount] : $layout;
1344 $rowResult = '';
1345 if (is_array($tableRow)) {
1346 $cellCount = 0;
1347 foreach ($tableRow as $tableCell) {
1348 $cellWrap = (is_array($layout[$cellCount]) ? $layout[$cellCount] : $layout['defCol']);
1349 $cellWrap = (is_array($rowLayout['defCol']) ? $rowLayout['defCol'] : $cellWrap);
1350 $cellWrap = (is_array($rowLayout[$cellCount]) ? $rowLayout[$cellCount] : $cellWrap);
1351 $rowResult .= $cellWrap[0] . $tableCell . $cellWrap[1];
1352 $cellCount++;
1353 }
1354 }
1355 $rowWrap = (is_array($layout['tr']) ? $layout['tr'] : array($this->table_TR, '</tr>'));
1356 $rowWrap = (is_array($rowLayout['tr']) ? $rowLayout['tr'] : $rowWrap);
1357 $result .= $rowWrap[0] . $rowResult . $rowWrap[1];
1358 $rowCount++;
1359 }
1360 $tableWrap = is_array($tableLayout['table']) ? $tableLayout['table'] : array($this->table_TABLE, '</table>');
1361 $result = $tableWrap[0] . $result . $tableWrap[1];
1362 }
1363 return $result;
1364 }
1365
1366 /**
1367 * Constructs a table with content from the $arr1, $arr2 and $arr3.
1368 * Used in eg. ext/belog/mod/index.php - refer to that for examples
1369 *
1370 * @param array $arr1 Menu elements on first level
1371 * @param array $arr2 Secondary items
1372 * @param array $arr3 Third-level items
1373 * @return string HTML content, <table>...</table>
1374 */
1375 function menuTable($arr1, $arr2 = array(), $arr3 = array()) {
1376 $rows = max(array(count($arr1), count($arr2), count($arr3)));
1377
1378 $menu = '
1379 <table border="0" cellpadding="0" cellspacing="0" id="typo3-tablemenu">';
1380 for ($a = 0; $a < $rows; $a++) {
1381 $menu .= '<tr>';
1382 $cls = array();
1383 $valign = 'middle';
1384 $cls[] = '<td valign="'.$valign.'">'.$arr1[$a][0].'</td><td>'.$arr1[$a][1].'</td>';
1385 if (count($arr2)) {
1386 $cls[] = '<td valign="'.$valign.'">'.$arr2[$a][0].'</td><td>'.$arr2[$a][1].'</td>';
1387 if (count($arr3)) {
1388 $cls[] = '<td valign="'.$valign.'">'.$arr3[$a][0].'</td><td>'.$arr3[$a][1].'</td>';
1389 }
1390 }
1391 $menu .= implode($cls, '<td>&nbsp;&nbsp;</td>');
1392 $menu .= '</tr>';
1393 }
1394 $menu .= '
1395 </table>
1396 ';
1397 return $menu;
1398 }
1399
1400 /**
1401 * Returns a one-row/two-celled table with $content and $menu side by side.
1402 * The table is a 100% width table and each cell is aligned left / right
1403 *
1404 * @param string $content Content cell content (left)
1405 * @param string $menu Menu cell content (right)
1406 * @return string HTML output
1407 */
1408 function funcMenu($content, $menu) {
1409 return '
1410 <table border="0" cellpadding="0" cellspacing="0" width="100%" id="typo3-funcmenu">
1411 <tr>
1412 <td valign="top" nowrap="nowrap">'.$content.'</td>
1413 <td valign="top" align="right" nowrap="nowrap">'.$menu.'</td>
1414 </tr>
1415 </table>';
1416 }
1417
1418
1419 /**
1420 * Includes a javascript library that exists in the core /typo3/ directory. The
1421 * backpath is automatically applied
1422 *
1423 * @param string $lib: Library name. Call it with the full path like "contrib/prototype/prototype.js" to load it
1424 * @return void
1425 */
1426 function loadJavascriptLib($lib) {
1427 $this->pageRenderer->addJsFile($this->backPath . $lib);
1428 }
1429
1430 /**
1431 * Includes the necessary Javascript function for the clickmenu (context sensitive menus) in the document
1432 * @return void
1433 */
1434 function getContextMenuCode() {
1435 $this->pageRenderer->loadPrototype();
1436 $this->loadJavascriptLib('js/clickmenu.js');
1437
1438 $this->JScodeArray['clickmenu'] = '
1439 Clickmenu.clickURL = "'.$this->backPath.'alt_clickmenu.php";
1440 Clickmenu.ajax = '.($this->isCMLayers() ? 'true' : 'false' ).';';
1441 }
1442
1443 /**
1444 * Includes the necessary javascript file (tree.js) for use on pages which have the
1445 * drag and drop functionality (usually pages and folder display trees)
1446 *
1447 * @param string $table indicator of which table the drag and drop function should work on (pages or folders)
1448 * @return void
1449 */
1450 function getDragDropCode($table) {
1451 $this->pageRenderer->loadPrototype();
1452 $this->loadJavascriptLib('js/common.js');
1453 $this->loadJavascriptLib('js/tree.js');
1454
1455 // Setting prefs for drag & drop
1456 $this->JScodeArray['dragdrop'] = '
1457 DragDrop.changeURL = "'.$this->backPath.'alt_clickmenu.php";
1458 DragDrop.backPath = "'.t3lib_div::shortMD5(''.'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']).'";
1459 DragDrop.table = "'.$table.'";
1460 ';
1461 }
1462
1463 /**
1464 * This loads everything needed for the Context Sensitive Help (CSH)
1465 *
1466 * @return void
1467 */
1468 protected function loadCshJavascript() {
1469 $this->pageRenderer->loadExtJS();
1470 $this->pageRenderer->addJsFile($this->backPath .'../t3lib/js/extjs/contexthelp.js');
1471 $this->pageRenderer->addExtDirectCode();
1472 }
1473
1474 /**
1475 * Creates a tab menu from an array definition
1476 *
1477 * Returns a tab menu for a module
1478 * Requires the JS function jumpToUrl() to be available
1479 *
1480 * @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=...
1481 * @param string $elementName it the form elements name, probably something like "SET[...]"
1482 * @param string $currentValue is the value to be selected currently.
1483 * @param array $menuItems is an array with the menu items for the selector box
1484 * @param string $script is the script to send the &id to, if empty it's automatically found
1485 * @param string $addparams is additional parameters to pass to the script.
1486 * @return string HTML code for tab menu
1487 */
1488 function getTabMenu($mainParams, $elementName, $currentValue, $menuItems, $script = '', $addparams = '') {
1489 $content='';
1490
1491 if (is_array($menuItems)) {
1492 if (!is_array($mainParams)) {
1493 $mainParams = array('id' => $mainParams);
1494 }
1495 $mainParams = t3lib_div::implodeArrayForUrl('', $mainParams);
1496
1497 if (!$script) {$script=basename(PATH_thisScript);}
1498
1499 $menuDef = array();
1500 foreach ($menuItems as $value => $label) {
1501 $menuDef[$value]['isActive'] = !strcmp($currentValue, $value);
1502 $menuDef[$value]['label'] = t3lib_div::deHSCentities(htmlspecialchars($label));
1503 $menuDef[$value]['url'] = $script . '?' . $mainParams . $addparams . '&' . $elementName . '=' . $value;
1504 }
1505 $content = $this->getTabMenuRaw($menuDef);
1506
1507 }
1508 return $content;
1509 }
1510
1511 /**
1512 * Creates the HTML content for the tab menu
1513 *
1514 * @param array $menuItems Menu items for tabs
1515 * @return string Table HTML
1516 * @access private
1517 */
1518 function getTabMenuRaw($menuItems) {
1519 $content = '';
1520
1521 if (is_array($menuItems)) {
1522 $options = '';
1523
1524 $count = count($menuItems);
1525 $widthLeft = 1;
1526 $addToAct = 5;
1527
1528 $widthRight = max (1, floor(30-pow($count, 1.72)));
1529 $widthTabs = 100 - $widthRight - $widthLeft;
1530 $widthNo = floor(($widthTabs - $addToAct)/$count);
1531 $addToAct = max ($addToAct, $widthTabs-($widthNo*$count));
1532 $widthAct = $widthNo + $addToAct;
1533 $widthRight = 100 - ($widthLeft + ($count*$widthNo) + $addToAct);
1534
1535 foreach ($menuItems as $id => $def) {
1536 $isActive = $def['isActive'];
1537 $class = $isActive ? 'tabact' : 'tab';
1538 $width = $isActive ? $widthAct : $widthNo;
1539
1540 // @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.
1541 $label = $def['label'];
1542 $url = htmlspecialchars($def['url']);
1543 $params = $def['addParams'];
1544
1545 $options .= '<td width="' . $width . '%" class="' . $class . '"><a href="' . $url . '" ' . $params . '>' . $label . '</a></td>';
1546 }
1547
1548 if ($options) {
1549 $content .= '
1550 <!-- Tab menu -->
1551 <table cellpadding="0" cellspacing="0" border="0" width="100%" id="typo3-tabmenu">
1552 <tr>
1553 <td width="'.$widthLeft.'%">&nbsp;</td>
1554 '.$options.'
1555 <td width="'.$widthRight.'%">&nbsp;</td>
1556 </tr>
1557 </table>
1558 <div class="hr" style="margin:0px"></div>';
1559 }
1560
1561 }
1562 return $content;
1563 }
1564
1565 /**
1566 * Creates a DYNAMIC tab-menu where the tabs are switched between with DHTML.
1567 * 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!
1568 *
1569 * @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.
1570 * @param string $identString Identification string. This should be unique for every instance of a dynamic menu!
1571 * @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.
1572 * @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.
1573 * @param boolean $noWrap If set, tab table cells are not allowed to wrap their content
1574 * @param boolean $fullWidth If set, the tabs will span the full width of their position
1575 * @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.
1576 * @param integer $dividers2tabs If set to '1' empty tabs will be remove, If set to '2' empty tabs will be disabled
1577 * @return string JavaScript section for the HTML header.
1578 */
1579 public function getDynTabMenu($menuItems, $identString, $toggle = 0, $foldout = FALSE, $noWrap = TRUE, $fullWidth = FALSE, $defaultTabIndex = 1, $dividers2tabs = 2) {
1580 // Load the static code, if not already done with the function below
1581 $this->loadJavascriptLib('js/tabmenu.js');
1582
1583 $content = '';
1584
1585 if (is_array($menuItems)) {
1586
1587 // Init:
1588 $options = array(array());
1589 $divs = array();
1590 $JSinit = array();
1591 $id = $this->getDynTabMenuId($identString);
1592 $noWrap = $noWrap ? ' nowrap="nowrap"' : '';
1593
1594 // Traverse menu items
1595 $c = 0;
1596 $tabRows = 0;
1597 $titleLenCount = 0;
1598 foreach ($menuItems as $index => $def) {
1599 // Need to add one so checking for first index in JavaScript
1600 // is different than if it is not set at all.
1601 $index += 1;
1602
1603 // Switch to next tab row if needed
1604 if (!$foldout && ($def['newline'] === TRUE && $titleLenCount > 0)) {
1605 $titleLenCount=0;
1606 $tabRows++;
1607 $options[$tabRows] = array();
1608 }
1609
1610 if ($toggle==1) {
1611 $onclick = 'this.blur(); DTM_toggle("'.$id.'","'.$index.'"); return false;';
1612 } else {
1613 $onclick = 'this.blur(); DTM_activate("'.$id.'","'.$index.'", '.($toggle<0?1:0).'); return false;';
1614 }
1615
1616 $isEmpty = !(strcmp(trim($def['content']), '') || strcmp(trim($def['icon']), ''));
1617
1618 // "Removes" empty tabs
1619 if ($isEmpty && $dividers2tabs == 1) {
1620 continue;
1621 }
1622
1623 $mouseOverOut = ' onmouseover="DTM_mouseOver(this);" onmouseout="DTM_mouseOut(this);"';
1624 $requiredIcon = '<img name="' . $id . '-' . $index . '-REQ" src="' . $GLOBALS['BACK_PATH'] . 'gfx/clear.gif" class="t3-TCEforms-reqTabImg" alt="" />';
1625
1626 if (!$foldout) {
1627 // Create TAB cell:
1628 $options[$tabRows][] = '
1629 <td class="'.($isEmpty ? 'disabled' : 'tab').'" id="'.$id.'-'.$index.'-MENU"'.$noWrap.$mouseOverOut.'>'.
1630 ($isEmpty ? '' : '<a href="#" onclick="'.htmlspecialchars($onclick).'"'.($def['linkTitle'] ? ' title="'.htmlspecialchars($def['linkTitle']).'"':'').'>').
1631 $def['icon'].
1632 ($def['label'] ? htmlspecialchars($def['label']) : '&nbsp;').
1633 $requiredIcon.
1634 $this->icons($def['stateIcon'], 'margin-left: 10px;').
1635 ($isEmpty ? '' : '</a>').
1636 '</td>';
1637 $titleLenCount+= strlen($def['label']);
1638 } else {
1639 // Create DIV layer for content:
1640 $divs[] = '
1641 <div class="'.($isEmpty ? 'disabled' : 'tab').'" id="'.$id.'-'.$index.'-MENU"'.$mouseOverOut.'>'.
1642 ($isEmpty ? '' : '<a href="#" onclick="'.htmlspecialchars($onclick).'"'.($def['linkTitle'] ? ' title="'.htmlspecialchars($def['linkTitle']).'"':'').'>').
1643 $def['icon'].
1644 ($def['label'] ? htmlspecialchars($def['label']) : '&nbsp;').
1645 $requiredIcon.
1646 ($isEmpty ? '' : '</a>').
1647 '</div>';
1648 }
1649
1650 // Create DIV layer for content:
1651 $divs[] = '
1652 <div style="display: none;" id="'.$id.'-'.$index.'-DIV" class="c-tablayer">'.
1653 ($def['description'] ? '<p class="c-descr">'.nl2br(htmlspecialchars($def['description'])).'</p>' : '').
1654 $def['content'].
1655 '</div>';
1656 // Create initialization string:
1657 $JSinit[] = '
1658 DTM_array["'.$id.'"]['.$c.'] = "'.$id.'-'.$index.'";
1659 ';
1660 // If not empty and we have the toggle option on, check if the tab needs to be expanded
1661 if ($toggle == 1 && !$isEmpty) {
1662 $JSinit[] = '
1663 if (top.DTM_currentTabs["'.$id.'-'.$index.'"]) { DTM_toggle("'.$id.'","'.$index.'",1); }
1664 ';
1665 }
1666
1667 $c++;
1668 }
1669
1670 // Render menu:
1671 if (count($options)) {
1672
1673 // Tab menu is compiled:
1674 if (!$foldout) {
1675 $tabContent = '';
1676 for($a = 0; $a <= $tabRows; $a++) {
1677 $tabContent .= '
1678
1679 <!-- Tab menu -->
1680 <table cellpadding="0" cellspacing="0" border="0"'.($fullWidth ? ' width="100%"' : '').' class="typo3-dyntabmenu">
1681 <tr>
1682 '.implode('', $options[$a]).'
1683 </tr>
1684 </table>';
1685 }
1686 $content .= '<div class="typo3-dyntabmenu-tabs">'.$tabContent.'</div>';
1687 }
1688
1689 // Div layers are added:
1690 $content .= '
1691 <!-- Div layers for tab menu: -->
1692 <div class="typo3-dyntabmenu-divs'.($foldout?'-foldout':'').'">
1693 '.implode('', $divs).'</div>';
1694
1695 // Java Script section added:
1696 $content .= '
1697 <!-- Initialization JavaScript for the menu -->
1698 <script type="text/javascript">
1699 DTM_array["'.$id.'"] = new Array();
1700 '.implode('', $JSinit).'
1701 '.($toggle <= 0 ? 'DTM_activate("'.$id.'", top.DTM_currentTabs["'.$id.'"]?top.DTM_currentTabs["'.$id.'"]:'.intval($defaultTabIndex).', 0);' : '').'
1702 </script>
1703
1704 ';
1705 }
1706
1707 }
1708 return $content;
1709 }
1710
1711 /**
1712 * Creates the id for dynTabMenus.
1713 *
1714 * @param string $identString Identification string. This should be unique for every instance of a dynamic menu!
1715 * @return string The id with a short MD5 of $identString and prefixed "DTM-", like "DTM-2e8791854a"
1716 */
1717 function getDynTabMenuId($identString) {
1718 $id = 'DTM-'.t3lib_div::shortMD5($identString);
1719 return $id;
1720 }
1721
1722 /**
1723 * Creates the version selector for the page id inputted.
1724 * Requires the core version management extension, "version" to be loaded.
1725 *
1726 * @param integer $id Page id to create selector for.
1727 * @param boolean $noAction If set, there will be no button for swapping page.
1728 * @return string
1729 */
1730 public function getVersionSelector($id, $noAction = FALSE) {
1731 if (t3lib_extMgm::isLoaded('version')) {
1732 $versionGuiObj = t3lib_div::makeInstance('tx_version_gui');
1733 return $versionGuiObj->getVersionSelector($id, $noAction);
1734 }
1735 }
1736
1737 /**
1738 * Function to load a HTML template file with markers.
1739 * When calling from own extension, use syntax getHtmlTemplate('EXT:extkey/template.html')
1740 *
1741 * @param string $filename tmpl name, usually in the typo3/template/ directory
1742 * @return string HTML of template
1743 */
1744 function getHtmlTemplate($filename) {
1745 // setting the name of the original HTML template
1746 $this->moduleTemplateFilename = $filename;
1747
1748 if ($GLOBALS['TBE_STYLES']['htmlTemplates'][$filename]) {
1749 $filename = $GLOBALS['TBE_STYLES']['htmlTemplates'][$filename];
1750 }
1751 if (t3lib_div::isFirstPartOfStr($filename, 'EXT:')) {
1752 $filename = t3lib_div::getFileAbsFileName($filename, TRUE, TRUE);
1753 } elseif (!t3lib_div::isAbsPath($filename)) {
1754 $filename = t3lib_div::resolveBackPath($this->backPath . $filename);
1755 } elseif (!t3lib_div::isAllowedAbsPath($filename)) {
1756 $filename = '';
1757 }
1758 $htmlTemplate = '';
1759 if ($filename !== '') {
1760 $htmlTemplate = t3lib_div::getUrl($filename);
1761 }
1762 return $htmlTemplate;
1763 }
1764
1765 /**
1766 * Define the template for the module
1767 *
1768 * @param string $filename filename
1769 * @return void
1770 */
1771 public function setModuleTemplate($filename) {
1772 // Load Prototype lib for IE event
1773 $this->pageRenderer->loadPrototype();
1774 $this->loadJavascriptLib('js/iecompatibility.js');
1775 $this->moduleTemplate = $this->getHtmlTemplate($filename);
1776 }
1777
1778 /**
1779 * Put together the various elements for the module <body> using a static HTML
1780 * template
1781 *
1782 * @param array $pageRecord Record of the current page, used for page path and info
1783 * @param array $buttons HTML for all buttons
1784 * @param array $markerArray HTML for all other markers
1785 * @param array $subpartArray HTML for the subparts
1786 * @return string Composite HTML
1787 */
1788 public function moduleBody($pageRecord = array(), $buttons = array(), $markerArray = array(), $subpartArray = array()) {
1789 // Get the HTML template for the module
1790 $moduleBody = t3lib_parsehtml::getSubpart($this->moduleTemplate, '###FULLDOC###');
1791 // Add CSS
1792 $this->inDocStylesArray[] = 'html { overflow: hidden; }';
1793
1794 // Get the page path for the docheader
1795 $markerArray['PAGEPATH'] = $this->getPagePath($pageRecord);
1796 // Get the page info for the docheader
1797 $markerArray['PAGEINFO'] = $this->getPageInfo($pageRecord);
1798 // Get all the buttons for the docheader
1799 $docHeaderButtons = $this->getDocHeaderButtons($buttons);
1800 // Merge docheader buttons with the marker array
1801 $markerArray = array_merge($markerArray, $docHeaderButtons);
1802 // replacing subparts
1803 foreach ($subpartArray as $marker => $content) {
1804 $moduleBody = t3lib_parsehtml::substituteSubpart($moduleBody, $marker, $content);
1805 }
1806
1807 // adding flash messages
1808 if ($this->showFlashMessages) {
1809 $flashMessages = t3lib_FlashMessageQueue::renderFlashMessages();
1810 if (!empty($flashMessages)) {
1811 $markerArray['FLASHMESSAGES'] = '<div id="typo3-messages">' . $flashMessages . '</div>';
1812
1813 // If there is no dedicated marker for the messages present
1814 // then force them to appear before the content
1815 if (strpos($moduleBody, '###FLASHMESSAGES###') === FALSE) {
1816 $moduleBody = str_replace(
1817 '###CONTENT###',
1818 '###FLASHMESSAGES######CONTENT###',
1819 $moduleBody
1820 );
1821 }
1822 }
1823 }
1824
1825 // Hook for adding more markers/content to the page, like the version selector
1826 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['moduleBodyPostProcess'])) {
1827 $params = array(
1828 'moduleTemplateFilename' => &$this->moduleTemplateFilename,
1829 'moduleTemplate' => &$this->moduleTemplate,
1830 'moduleBody' => &$moduleBody,
1831 'markers' => &$markerArray,
1832 'parentObject' => &$this
1833 );
1834 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['moduleBodyPostProcess'] as $funcRef) {
1835 t3lib_div::callUserFunction($funcRef, $params, $this);
1836 }
1837 }
1838
1839 // Replacing all markers with the finished markers and return the HTML content
1840 return t3lib_parsehtml::substituteMarkerArray($moduleBody, $markerArray, '###|###');
1841
1842 }
1843
1844 /**
1845 * Fill the button lists with the defined HTML
1846 *
1847 * @param array $buttons HTML for all buttons
1848 * @return array Containing HTML for both buttonlists
1849 */
1850 protected function getDocHeaderButtons($buttons) {
1851 $markers = array();
1852 // Fill buttons for left and right float
1853 $floats = array('left', 'right');
1854 foreach ($floats as $key) {
1855 // Get the template for each float
1856 $buttonTemplate = t3lib_parsehtml::getSubpart($this->moduleTemplate, '###BUTTON_GROUPS_' . strtoupper($key) . '###');
1857 // Fill the button markers in this float
1858 $buttonTemplate = t3lib_parsehtml::substituteMarkerArray($buttonTemplate, $buttons, '###|###', TRUE);
1859 // getting the wrap for each group
1860 $buttonWrap = t3lib_parsehtml::getSubpart($this->moduleTemplate, '###BUTTON_GROUP_WRAP###');
1861 // looping through the groups (max 6) and remove the empty groups
1862 for ($groupNumber = 1; $groupNumber < 6; $groupNumber++) {
1863 $buttonMarker = '###BUTTON_GROUP' . $groupNumber . '###';
1864 $buttonGroup = t3lib_parsehtml::getSubpart($buttonTemplate, $buttonMarker);
1865 if (trim($buttonGroup)) {
1866 if ($buttonWrap) {
1867 $buttonGroup = t3lib_parsehtml::substituteMarker($buttonWrap, '###BUTTONS###', $buttonGroup);
1868 }
1869 $buttonTemplate = t3lib_parsehtml::substituteSubpart($buttonTemplate, $buttonMarker, trim($buttonGroup));
1870 }
1871 }
1872 // Replace the marker with the template and remove all line breaks (for IE compat)
1873 $markers['BUTTONLIST_' . strtoupper($key)] = str_replace(LF, '', $buttonTemplate);
1874 }
1875
1876 // Hook for manipulating docHeaderButtons
1877 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['docHeaderButtonsHook'])) {
1878 $params = array(
1879 'buttons' => $buttons,
1880 'markers' => &$markers,
1881 'pObj' => &$this
1882 );
1883 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['docHeaderButtonsHook'] as $funcRef) {
1884 t3lib_div::callUserFunction($funcRef, $params, $this);
1885 }
1886 }
1887
1888 return $markers;
1889 }
1890
1891 /**
1892 * Generate the page path for docheader
1893 *
1894 * @param array $pageRecord Current page
1895 * @return string Page path
1896 */
1897 protected function getPagePath($pageRecord) {
1898 // Is this a real page
1899 if (is_array($pageRecord) && $pageRecord['uid']) {
1900 $title = substr($pageRecord['_thePathFull'], 0, -1);
1901 // Remove current page title
1902 $pos = strrpos($title, '/');
1903 if ($pos !== FALSE) {
1904 $title = substr($title, 0, $pos) . '/';
1905 }
1906 } else {
1907 $title = '';
1908 }
1909
1910 // Setting the path of the page
1911 $pagePath = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.path', 1) . ': <span class="typo3-docheader-pagePath">';
1912
1913 // crop the title to title limit (or 50, if not defined)
1914 $cropLength = (empty($GLOBALS['BE_USER']->uc['titleLen'])) ? 50 : $GLOBALS['BE_USER']->uc['titleLen'];
1915 $croppedTitle = t3lib_div::fixed_lgd_cs($title, -$cropLength);
1916 if ($croppedTitle !== $title) {
1917 $pagePath .= '<abbr title="' . htmlspecialchars($title) . '">' . htmlspecialchars($croppedTitle) . '</abbr>';
1918 } else {
1919 $pagePath .= htmlspecialchars($title);
1920 }
1921 $pagePath .= '</span>';
1922 return $pagePath;
1923 }
1924
1925 /**
1926 * Setting page icon with clickmenu + uid for docheader
1927 *
1928 * @param array $pageRecord Current page
1929 * @return string Page info
1930 */
1931 protected function getPageInfo($pageRecord) {
1932
1933 // Add icon with clickmenu, etc:
1934 // If there IS a real page
1935 if (is_array($pageRecord) && $pageRecord['uid']) {
1936 $alttext = t3lib_BEfunc::getRecordIconAltText($pageRecord, 'pages');
1937 $iconImg = t3lib_iconWorks::getSpriteIconForRecord('pages', $pageRecord, array('title'=>$alttext));
1938 // Make Icon:
1939 $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconImg, 'pages', $pageRecord['uid']);
1940 $uid = $pageRecord['uid'];
1941 $title = t3lib_BEfunc::getRecordTitle('pages', $pageRecord);
1942 } else { // On root-level of page tree
1943 // Make Icon
1944 $iconImg = t3lib_iconWorks::getSpriteIcon('apps-pagetree-root', array('title' => htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'])));
1945 if ($GLOBALS['BE_USER']->user['admin']) {
1946 $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconImg, 'pages', 0);
1947 } else {
1948 $theIcon = $iconImg;
1949 }
1950 $uid = '0';
1951 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
1952 }
1953
1954 // Setting icon with clickmenu + uid
1955 $pageInfo = $theIcon . '<strong>' . htmlspecialchars($title) . '&nbsp;[' . $uid . ']</strong>';
1956 return $pageInfo;
1957 }
1958
1959 /**
1960 * Makes a collapseable section. See reports module for an example
1961 *
1962 * @param string $title
1963 * @param string $html
1964 * @param string $id
1965 * @param string $saveStatePointer
1966 * @return string
1967 */
1968 public function collapseableSection($title, $html, $id, $saveStatePointer = '') {
1969 $hasSave = $saveStatePointer ? TRUE : FALSE;
1970 $collapsedStyle = $collapsedClass = '';
1971
1972 if ($hasSave) {
1973 /** @var $settings extDirect_DataProvider_BackendUserSettings */
1974 $settings = t3lib_div::makeInstance('extDirect_DataProvider_BackendUserSettings');
1975 $value = $settings->get($saveStatePointer . '.' . $id);
1976 if ($value) {
1977 $collapsedStyle = ' style="display: none"';
1978 $collapsedClass = ' collapsed';
1979 } else {
1980 $collapsedStyle = '';
1981 $collapsedClass = ' expanded';
1982 }
1983 }
1984
1985 $this->pageRenderer->loadExtJS();
1986 $this->pageRenderer->addExtOnReadyCode('
1987 Ext.select("h2.section-header").each(function(element){
1988 element.on("click", function(event, tag) {
1989 var state = 0,
1990 el = Ext.fly(tag),
1991 div = el.next("div"),
1992 saveKey = el.getAttribute("rel");
1993 if (el.hasClass("collapsed")) {
1994 el.removeClass("collapsed").addClass("expanded");
1995 div.slideIn("t", {
1996 easing: "easeIn",
1997 duration: .5
1998 });
1999 } else {
2000 el.removeClass("expanded").addClass("collapsed");
2001 div.slideOut("t", {
2002 easing: "easeOut",
2003 duration: .5,
2004 remove: false,
2005 useDisplay: true
2006 });
2007 state = 1;
2008 }
2009 if (saveKey) {
2010 try {
2011 top.TYPO3.BackendUserSettings.ExtDirect.set(saveKey + "." + tag.id, state, function(response) {});
2012 } catch(e) {}
2013 }
2014 });
2015 });
2016 ');
2017 return '
2018 <h2 id="' . $id . '" class="section-header' . $collapsedClass . '" rel="' . $saveStatePointer . '"> ' . $title . '</h2>
2019 <div' . $collapsedStyle . '>' . $html . '</div>
2020 ';
2021
2022 }
2023 }
2024
2025 // Extension classes of the template class.
2026 // These are meant to provide backend screens with different widths.
2027 // They still do because of the different class-prefixes used for the <div>-sections
2028 // but obviously the final width is determined by the stylesheet used.
2029
2030 /**
2031 * 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
2032 * The class were more significant in the past than today.
2033 *
2034 */
2035 class bigDoc extends template {
2036 var $divClass = 'typo3-bigDoc';
2037 }
2038
2039 /**
2040 * Extension class for "template" - used for backend pages without the "document" background image
2041 * The class were more significant in the past than today.
2042 *
2043 */
2044 class noDoc extends template {
2045 var $divClass = 'typo3-noDoc';
2046 }
2047
2048 /**
2049 * 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)
2050 * The class were more significant in the past than today.
2051 *
2052 */
2053 class smallDoc extends template {
2054 var $divClass = 'typo3-smallDoc';
2055 }
2056
2057 /**
2058 * 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.
2059 * The class were more significant in the past than today. But probably you should use this one for most modules you make.
2060 *
2061 */
2062 class mediumDoc extends template {
2063 var $divClass = 'typo3-mediumDoc';
2064 }
2065
2066 /**
2067 * Extension class for "template" - used in the context of frontend editing.
2068 */
2069 class frontendDoc extends template {
2070
2071 /**
2072 * Gets instance of PageRenderer
2073 *
2074 * @return t3lib_PageRenderer
2075 */
2076 public function getPageRenderer() {
2077 if (!isset($this->pageRenderer)) {
2078 $this->pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
2079 }
2080 return $this->pageRenderer;
2081 }
2082
2083 /**
2084 * Used in the frontend context to insert header data via TSFE->additionalHeaderData.
2085 * Mimics header inclusion from template->startPage().
2086 *
2087 * @return void
2088 */
2089 public function insertHeaderData() {
2090
2091 $this->backPath = $GLOBALS['TSFE']->backPath = TYPO3_mainDir;
2092 $this->pageRenderer->setBackPath($this->backPath);
2093 $this->docStyle();
2094
2095 // Add applied JS/CSS to $GLOBALS['TSFE']
2096 if ($this->JScode) {
2097 $this->pageRenderer->addHeaderData($this->JScode);
2098 }
2099 if (count($this->JScodeArray)) {
2100 foreach ($this->JScodeArray as $name => $code) {
2101 $this->pageRenderer->addJsInlineCode($name, $code, FALSE);
2102 }
2103 }
2104 }
2105 }
2106
2107 ?>