2 /***************************************************************
5 * (c) 1999-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Wizard for inserting TSconfig in form fields. (page,user or TS)
31 * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
34 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
37 * [CLASS/FUNCTION INDEX of SCRIPT]
41 * 98: class ext_TSparser extends t3lib_tsparser_ext
42 * 106: function makeHtmlspecialchars($P)
45 * 127: class SC_wizard_tsconfig
46 * 149: function init()
47 * 202: function setValue(field,value)
48 * 232: function mixerField(cmd,objString)
49 * 258: function str_replace(match,replace,string)
50 * 280: function jump(show,objString)
51 * 295: function main()
52 * 320: function printContent()
53 * 333: function browseTSprop($mode,$show)
55 * SECTION: Module functions
56 * 419: function getObjTree()
57 * 449: function setObj(&$objTree,$strArr,$params)
58 * 469: function revertFromSpecialChars($str)
59 * 482: function doLink($params)
60 * 495: function removePointerObjects($objArray)
61 * 514: function linkToObj($str,$uid,$objString='')
62 * 527: function printTable($table,$objString,$objTree)
63 * 608: function linkProperty($str,$propertyName,$prefix,$datatype)
66 * (This index is automatically created/updated by the extension "extdeveval")
74 require ('template.php');
75 $LANG->includeLLFile('EXT:lang/locallang_wizards.xml');
84 * TypoScript parser extension class.
86 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
90 class ext_TSparser
extends t3lib_tsparser_ext
{
93 * Pass through of incoming value for link.
95 * @param array P array
96 * @return string The "_LINK" key value, straight away.
98 function makeHtmlspecialchars($P) {
113 * Script Class for rendering the TSconfig/TypoScript property browser.
115 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
119 class SC_wizard_tsconfig
{
121 // Internal, dynamic:
123 * document template object
128 var $content; // Content accumulation for the module.
130 // Internal, static: GPvars
131 var $P; // Wizard parameters, coming from TCEforms linking to the wizard.
132 var $mode; // "page", "tsref" or "beuser"
133 var $show; // Pointing to an entry in static_tsconfig_help to show.
134 var $objString; // Object path - for display.
135 var $onlyProperty; // If set, the "mixed-field" is not shown and you can select only one property at a time.
142 * Initialization of the class
147 global $LANG,$BACK_PATH;
149 // Check if the tsconfig_help extension is loaded - which is mandatory for this wizard to work.
150 t3lib_extMgm
::isLoaded('tsconfig_help',1);
153 $this->P
= t3lib_div
::_GP('P');
154 $this->mode
= t3lib_div
::_GP('mode');
155 $this->show
= t3lib_div
::_GP('show');
156 $this->objString
= t3lib_div
::_GP('objString');
157 $this->onlyProperty
= t3lib_div
::_GP('onlyProperty');
158 // Preparing some JavaScript code:
159 if (!is_array($this->P
['fieldChangeFunc'])) $this->P
['fieldChangeFunc']=array();
160 unset($this->P
['fieldChangeFunc']['alert']);
162 foreach($this->P
['fieldChangeFunc'] as $k=>$v) {
167 // Init the document table object:
168 $this->doc
= t3lib_div
::makeInstance('mediumDoc');
169 $this->doc
->backPath
= $BACK_PATH;
170 $this->doc
->form
='<form action="" name="editform">';
172 // Adding Styles (should go into stylesheet?)
173 $this->doc
->inDocStylesArray
[] = '
174 A:link {text-decoration: bold; color: '.$this->doc
->hoverColor
.';}
175 A:visited {text-decoration: bold; color: '.$this->doc
->hoverColor
.';}
176 A:active {text-decoration: bold; color: '.$this->doc
->hoverColor
.';}
177 A:hover {color: '.$this->doc
->bgColor2
.'}
180 $this->doc
->JScode
.=$this->doc
->wrapScriptTags('
181 function checkReference_name() { // Checks if the input field containing the name exists in the document
182 if (window.opener && window.opener.document && window.opener.document.'.$this->P
['formName'].' && window.opener.document.'.$this->P
['formName'].'["'.$this->P
['itemName'].'"] ) {
183 return window.opener.document.'.$this->P
['formName'].'["'.$this->P
['itemName'].'"];
186 function checkReference_value() { // Checks if the input field containing the value exists in the document
187 if (window.opener && window.opener.document && window.opener.document.'.$this->P
['formName'].' && window.opener.document.'.$this->P
['formName'].'["'.$this->P
['itemValue'].'"] ) {
188 return window.opener.document.'.$this->P
['formName'].'["'.$this->P
['itemValue'].'"];
193 * [Describe function...]
195 * @param [type] $field,value: ...
198 function setValue(field,value) {
199 var nameField = checkReference_name();
200 var valueField = checkReference_value();
202 if (valueField) { // This applies to the TS Object Browser module
203 nameField.value=field;
204 valueField.value=value;
205 } else { // This applies to the Info/Modify module and the Page TSconfig field
207 nameField.value=field+"="+value+"\n"+nameField.value;
209 nameField.value=field+"\n"+nameField.value;
213 window.opener.focus();
217 function getValue() { // This is never used. Remove it?
218 var field = checkReference_name();
227 * [Describe function...]
229 * @param [type] $cmd,objString: ...
232 function mixerField(cmd,objString) {
236 temp = str_replace("\n","\n ","\n"+document.editform.mixer.value);
237 document.editform.mixer.value = temp.substr(1);
240 temp = str_replace("\n ","\n","\n"+document.editform.mixer.value);
241 document.editform.mixer.value = temp.substr(1);
244 setValue(document.editform.mixer.value);
247 document.editform.mixer.value=objString+" {\n"+document.editform.mixer.value+"\n}";
253 * [Describe function...]
255 * @param [type] $match,replace,string: ...
258 function str_replace(match,replace,string) {
259 var input = ""+string;
260 var matchStr = ""+match;
261 if (!matchStr) {return string;}
264 var pos = input.indexOf(matchStr);
266 output+=""+input.substr(pointer, pos-pointer)+replace;
267 pointer=pos+matchStr.length;
268 pos = input.indexOf(match,pos+1);
270 output+=""+input.substr(pointer);
275 * [Describe function...]
277 * @param [type] $show,objString: ...
280 function jump(show,objString) {
281 window.location.href = "'.t3lib_div
::linkThisScript(array('show'=>'','objString'=>'')).'&show="+show+"&objString="+objString;
287 $this->content
.=$this->doc
->startPage($LANG->getLL('tsprop'));
291 * Main function, rendering the content of the TypoScript property browser, including links to online resources
298 // Adding module content:
299 $this->content
.=$this->doc
->section($LANG->getLL('tsprop'),$this->browseTSprop($this->mode
,$this->show
),0,1);
301 // Adding link to TSref:
302 if ($this->mode
=='tsref') {
303 $this->content
.=$this->doc
->section($LANG->getLL('tsprop_TSref'),'
304 <a href="'.htmlspecialchars('http://typo3.org/documentation/document-library/references/doc_core_tsref/current/view/').'" target="_blank">'.$LANG->getLL('tsprop_TSref',1).'</a>
307 // Adding link to admin guides etc:
308 if ($this->mode
=='page' ||
$this->mode
=='beuser') {
309 $this->content
.=$this->doc
->section($LANG->getLL('tsprop_tsconfig'),'
310 <a href="'.htmlspecialchars('http://typo3.org/documentation/document-library/references/doc_core_tsconfig/current/view/').'" target="_blank">'.$LANG->getLL('tsprop_tsconfig',1).'</a>
316 * Outputting the accumulated content to screen
320 function printContent() {
321 $this->content
.= $this->doc
->endPage();
322 $this->content
= $this->doc
->insertStylesAndJS($this->content
);
327 * Create the content of the module:
329 * @param string Object string
330 * @param integer Pointing to an entry in static_tsconfig_help to show.
331 * @return string HTML
333 function browseTSprop($mode,$show) {
337 $objTree = $this->getObjTree();
339 // Show single element, if show is set.
342 // Get the entry data:
343 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'static_tsconfig_help', 'uid='.intval($show));
344 $rec = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
345 $table = unserialize($rec['appdata']);
346 $obj_string = strtr($this->objString
,'()','[]'); // Title:
348 // Title and description:
349 $out.='<a href="'.htmlspecialchars(t3lib_div
::linkThisScript(array('show'=>''))).'" class="typo3-goBack">'.
350 t3lib_iconWorks
::getSpriteIcon('actions-go-back') .
351 htmlspecialchars($obj_string).
353 if ($rec['title']) $out.= '<strong>'.htmlspecialchars($rec['title']).': </strong>';
354 if ($rec['description']) $out.= nl2br(htmlspecialchars(trim($rec['description']))).'<br />';
356 // Printing the content:
357 $out.= '<br />'.$this->printTable($table, $obj_string, $objTree[$mode.'.']);
360 // Printing the "mixer-field":
361 if (!$this->onlyProperty
) {
363 $links[]='<a href="#" onclick="mixerField(\'Indent\');return false;">'.$LANG->getLL('tsprop_mixer_indent',1).'</a>';
364 $links[]='<a href="#" onclick="mixerField(\'Outdent\');return false;">'.$LANG->getLL('tsprop_mixer_outdent',1).'</a>';
365 $links[]='<a href="#" onclick="mixerField(\'Wrap\',unescape(\''.rawurlencode($obj_string).'\'));return false;">'.$LANG->getLL('tsprop_mixer_wrap',1).'</a>';
366 $links[]='<a href="#" onclick="mixerField(\'Transfer\');return false;">'.$LANG->getLL('tsprop_mixer_transfer',1).'</a>';
367 $out.='<textarea rows="5" name="mixer" wrap="off"'.$this->doc
->formWidthText(48,'','off').' class="fixed-font enable-tab"></textarea>';
368 $out.='<br /><strong>'.implode(' | ',$links).'</strong>';
374 // SECTION: Showing property tree:
375 $tmpl = t3lib_div
::makeInstance('ext_TSparser');
376 $tmpl->tt_track
= 0; // Do not log time-performance information
378 $tmpl->linkObjects
=0;
380 $tmpl->ext_expandAllNotes
=1;
381 $tmpl->ext_noPMicons
=1;
382 $tmpl->ext_noSpecialCharsOnLabels
=1;
384 if (is_array($objTree[$mode.'.'])) {
389 TSconfig, object tree:
391 <table border="0" cellpadding="0" cellspacing="0" id="typo3-objtree">
393 <td nowrap="nowrap">'.$tmpl->ext_getObjTree($this->removePointerObjects($objTree[$mode.'.']),'','','','','1').'</td>
407 /***************************
411 ***************************/
414 * Create object tree from static_tsconfig_help table
416 * @return array Object tree.
419 function getObjTree() {
422 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,obj_string,title', 'static_tsconfig_help', '');
423 while($rec = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
424 $rec['obj_string'] = $this->revertFromSpecialChars($rec['obj_string']);
425 $p = explode(';',$rec['obj_string']);
427 $p2 = t3lib_div
::trimExplode(':',$v,1);
428 $subp=t3lib_div
::trimExplode('/',$p2[1],1);
429 foreach ($subp as $v2) {
430 $this->setObj($objTree,explode('.',$p2[0].'.'.$v2),array($rec,$v2));
438 * Sets the information from a static_tsconfig_help record in the object array.
439 * Makes recursive calls.
441 * @param array Object tree array, passed by value!
442 * @param array Array of elements from object path (?)
443 * @param array Array with record and something else (?)
448 function setObj(&$objTree,$strArr,$params) {
449 $key = current($strArr);
451 if (count($strArr)>1) {
452 array_shift($strArr);
453 if (!isset($objTree[$key.'.'])) $objTree[$key.'.']=array();
454 $this->setObj($objTree[$key.'.'],$strArr,$params);
456 $objTree[$key]=$params;
457 $objTree[$key]['_LINK']=$this->doLink($params);
462 * Converts > and < to > and <
464 * @param string Input string
465 * @return string Output string
468 function revertFromSpecialChars($str) {
469 $str = str_replace('>','>',$str);
470 $str = str_replace('<','<',$str);
475 * Creates a link based on input params array:
477 * @param array Parameters
478 * @return string The link.
481 function doLink($params) {
482 $title = trim($params[0]['title'])?
trim($params[0]['title']):'[GO]';
483 $str = $this->linkToObj($title,$params[0]['uid'],$params[1]);
488 * Remove pointer strings from an array
490 * @param array Input array
491 * @return array Modified input array
494 function removePointerObjects($objArray) {
495 foreach ($objArray as $k => $value) {
496 if (substr(trim($k),0,2)=="->" && trim($k)!='->.') {
497 $objArray['->.'][substr(trim($k),2)]=$objArray[$k];
498 unset($objArray[$k]);
505 * Linking string to object by UID
507 * @param string String to link
508 * @param integer UID of a static_tsconfig_help record.
509 * @param string Title string for that record!
510 * @return string Linked string
512 function linkToObj($str,$uid,$objString='') {
513 $aOnClick='jump(\''.rawurlencode($uid).'\',\''.rawurlencode($objString).'\');return false;';
514 return '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.htmlspecialchars($str).'</a>';
518 * Creates a table of properties:
520 * @param array Array with properties for the current object path
521 * @param string Object path
522 * @param array Object tree
523 * @return string HTML content.
525 function printTable($table,$objString,$objTree) {
526 if (is_array($table['rows'])) {
534 <td><img src="clear.gif" width="175" height="1" alt="" /></td>
535 <td><img src="clear.gif" width="100" height="1" alt="" /></td>
536 <td><img src="clear.gif" width="400" height="1" alt="" /></td>
537 <td><img src="clear.gif" width="70" height="1" alt="" /></td>
540 <tr class="bgColor5">
541 <td><strong>Property:</strong></td>
542 <td><strong>Data type:</strong></td>
543 <td><strong>Description:</strong></td>
544 <td><strong>Default:</strong></td>
547 // Traverse the content of "rows":
548 foreach($table['rows'] as $row) {
551 $lP=t3lib_div
::trimExplode(LF
,$row['property'],1);
553 foreach ($lP as $k => $lStr) {
554 $lP2[$k] = $this->linkProperty($lStr,$lStr,$objString,$row['datatype']);
556 $linkedProperties=implode('<hr />',$lP2);
559 $dataType = $row['datatype'];
561 // Generally "->[something]"
563 preg_match('/->[[:alnum:]_]*/',$dataType,$reg);
564 if ($reg[0] && is_array($objTree[$reg[0]])) {
565 $dataType = str_replace($reg[0],'<a href="'.htmlspecialchars(t3lib_div
::linkThisScript(array('show'=>$objTree[$reg[0]][0]['uid'],'objString'=>$objString.'.'.$lP[0]))).'">'.htmlspecialchars($reg[0]).'</a>',$dataType);
569 if (!strstr($dataType,'->stdWrap') && strstr(strip_tags($dataType),'stdWrap')) {
570 // Potential problem can be that "stdWrap" is substituted inside another A-tag. So maybe we should even check if there is already a <A>-tag present and if so, not make a substitution?
571 $dataType = str_replace('stdWrap','<a href="'.htmlspecialchars(t3lib_div
::linkThisScript(array('show'=>$objTree['->stdWrap'][0]['uid'],'objString'=>$objString.'.'.$lP[0]))).'">stdWrap</a>',$dataType);
576 <tr class="bgColor4">
577 <td valign="top" class="bgColor4-20"><strong>'.$linkedProperties.'</strong></td>
578 <td valign="top">'.nl2br($dataType.' ').'</td>
579 <td valign="top">'.nl2br($row['description']).'</td>
580 <td valign="top">'.nl2br($row['default']).'</td>
589 TSconfig, attribute selector:
591 <table border="0" cellpadding="0" cellspacing="1" width="500" id="typo3-attributes">
592 '.implode('',$lines).'
598 * Creates a link on a property.
600 * @param string String to link
601 * @param string Property value.
602 * @param string Object path prefix to value
603 * @param string Data type
604 * @return string Linked $str
606 function linkProperty($str,$propertyName,$prefix,$datatype) {
609 // Setting preset value:
610 if (strstr($datatype,'boolean')) {
611 $propertyVal='1'; // preset "1" to boolean values.
614 // Adding mixer features; The plus icon:
615 if(!$this->onlyProperty
) {
616 $aOnClick = 'document.editform.mixer.value=unescape(\' '.rawurlencode($propertyName.'='.$propertyVal).'\')+\'\n\'+document.editform.mixer.value; return false;';
617 $out.= '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
618 t3lib_iconWorks
::getSpriteIcon('actions-edit-add', array('title' => $GLOBALS['LANG']->getLL('tsprop_addToList', TRUE
))) .
620 $propertyName = $prefix.'.'.$propertyName;
624 $aOnClick = 'setValue(unescape(\''.rawurlencode($propertyName).'\'),unescape(\''.rawurlencode($propertyVal).'\')); return false;';
625 $out.= '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$str.'</a>';
633 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/wizard_tsconfig.php']) {
634 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/wizard_tsconfig.php']);
640 $SOBE = t3lib_div
::makeInstance('SC_wizard_tsconfig');
643 $SOBE->printContent();