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