Fixed bug #17184: Disable the CSRF protection in ExtDirect calls coming from the...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_tsstyleconfig.php
old mode 100755 (executable)
new mode 100644 (file)
index 09c1221..cf4e09b
@@ -1,35 +1,35 @@
 <?php
 /***************************************************************
-*  Copyright notice
-*
-*  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
-*  All rights reserved
-*
-*  This script is part of the TYPO3 project. The TYPO3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*  A copy is found in the textfile GPL.txt and important notices to the license
-*  from the author is found in LICENSE.txt distributed with these scripts.
-*
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
+ *  Copyright notice
+ *
+ *  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
 /**
  * Provides a simplified layer for making Constant Editor style configuration forms
  *
  * $Id$
  *
- * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  */
 /**
  * [CLASS/FUNCTION INDEX of SCRIPT]
  *
  *
  *   79: class t3lib_tsStyleConfig extends t3lib_tsparser_ext
- *   98:     function ext_initTSstyleConfig($configTemplate,$pathRel,$pathAbs,$backPath)
- *  118:     function ext_setValueArray($theConstants,$valueArray)
- *  145:     function ext_getCategoriesForModMenu()
- *  155:     function ext_makeHelpInformationForCategory($cat)
- *  168:     function ext_getForm($cat,$theConstants,$script="",$addFields="")
- *  175:     function uFormUrl(aname)
- *  197:     function ext_displayExample()
- *  213:     function ext_mergeIncomingWithExisting($arr)
- *  221:     function ext_getKeyImage($key)
- *  231:     function ext_getTSCE_config_image($imgConf)
- *  244:     function ext_fNandV($params)
- *  261:     function ext_loadResources($absPath)
- *  277:     function ext_putValueInConf($key, $var)
- *  287:     function ext_removeValueInConf($key)
+ *   98:        function ext_initTSstyleConfig($configTemplate,$pathRel,$pathAbs,$backPath)
+ *  118:        function ext_setValueArray($theConstants,$valueArray)
+ *  145:        function ext_getCategoriesForModMenu()
+ *  155:        function ext_makeHelpInformationForCategory($cat)
+ *  168:        function ext_getForm($cat,$theConstants,$script="",$addFields="")
+ *  175:        function uFormUrl(aname)
+ *  197:        function ext_displayExample()
+ *  213:        function ext_mergeIncomingWithExisting($arr)
+ *  221:        function ext_getKeyImage($key)
+ *  231:        function ext_getTSCE_config_image($imgConf)
+ *  244:        function ext_fNandV($params)
+ *  262:        function ext_loadResources($absPath)
+ *  278:        function ext_putValueInConf($key, $var)
+ *  288:        function ext_removeValueInConf($key)
  *
  * TOTAL FUNCTIONS: 14
  * (This index is automatically created/updated by the extension "extdeveval")
  *
  */
 
-require_once(PATH_t3lib.'class.t3lib_tsparser_ext.php');
-
-
-
-
-
-
-
-
-
-
 
 /**
  * Provides a simplified layer for making Constant Editor style configuration forms
  *
- * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage t3lib
  */
-class t3lib_tsStyleConfig extends t3lib_tsparser_ext   {
+class t3lib_tsStyleConfig extends t3lib_tsparser_ext {
                // internal
        var $categories = array();
-       var $ext_dontCheckIssetValues=1;
-       var $ext_CEformName="tsStyleConfigForm";
-       var $ext_noCEUploadAndCopying=1;
-       var $ext_printAll=1;
-       var $ext_defaultOnlineResourceFlag=1;
+       var $ext_dontCheckIssetValues = 1;
+       var $ext_CEformName = "tsStyleConfigForm";
+       var $ext_noCEUploadAndCopying = 1;
+       var $ext_printAll = 1;
+       var $ext_defaultOnlineResourceFlag = 1;
 
        var $ext_incomingValues = array();
 
@@ -95,14 +84,14 @@ class t3lib_tsStyleConfig extends t3lib_tsparser_ext        {
         * @param       [type]          $backPath: ...
         * @return      [type]          ...
         */
-       function ext_initTSstyleConfig($configTemplate,$pathRel,$pathAbs,$backPath)     {
-               $this->tt_track = 0;    // Do not log time-performance information
-               $this->constants=array($configTemplate,"");
+       function ext_initTSstyleConfig($configTemplate, $pathRel, $pathAbs, $backPath) {
+               $this->tt_track = 0; // Do not log time-performance information
+               $this->constants = array($configTemplate, "");
 
-               $theConstants = $this->generateConfig_constants();      // The editable constants are returned in an array.
+               $theConstants = $this->generateConfig_constants(); // The editable constants are returned in an array.
 
-               $this->ext_localGfxPrefix=$pathAbs;
-               $this->ext_localWebGfxPrefix=$backPath.$pathRel;
+               $this->ext_localGfxPrefix = $pathAbs;
+               $this->ext_localWebGfxPrefix = $backPath . $pathRel;
                $this->ext_backPath = $backPath;
 
                return $theConstants;
@@ -115,24 +104,23 @@ class t3lib_tsStyleConfig extends t3lib_tsparser_ext      {
         * @param       [type]          $valueArray: ...
         * @return      [type]          ...
         */
-       function ext_setValueArray($theConstants,$valueArray)   {
+       function ext_setValueArray($theConstants, $valueArray) {
 
                $temp = $this->flatSetup;
-               $this->flatSetup = Array();
-               $this->flattenSetup($valueArray,"","");
+               $this->flatSetup = array();
+               $this->flattenSetup($valueArray, "", "");
                $this->objReg = $this->ext_realValues = $this->flatSetup;
                $this->flatSetup = $temp;
 
 
-               reset($theConstants);
-               while(list($k,$p)=each($theConstants))  {
-                       if (isset($this->objReg[$k]))   {
+               foreach ($theConstants as $k => $p) {
+                       if (isset($this->objReg[$k])) {
                                $theConstants[$k]["value"] = $this->ext_realValues[$k];
                        }
                }
 
-               $this->categories=array(); // Reset the default pool of categories.
-               $this->ext_categorizeEditableConstants($theConstants);  // The returned constants are sorted in categories, that goes into the $this->categories array
+               $this->categories = array(); // Reset the default pool of categories.
+               $this->ext_categorizeEditableConstants($theConstants); // The returned constants are sorted in categories, that goes into the $this->categories array
 
                return $theConstants;
        }
@@ -142,7 +130,7 @@ class t3lib_tsStyleConfig extends t3lib_tsparser_ext        {
         *
         * @return      [type]          ...
         */
-       function ext_getCategoriesForModMenu()  {
+       function ext_getCategoriesForModMenu() {
                return $this->ext_getCategoryLabelArray();
        }
 
@@ -152,39 +140,38 @@ class t3lib_tsStyleConfig extends t3lib_tsparser_ext      {
         * @param       [type]          $cat: ...
         * @return      [type]          ...
         */
-       function ext_makeHelpInformationForCategory($cat)       {
+       function ext_makeHelpInformationForCategory($cat) {
                return $this->ext_getTSCE_config($cat);
        }
 
        /**
-        * [Describe function...]
+        * Get the form for extension configuration
         *
-        * @param       [type]          $cat: ...
-        * @param       [type]          $theConstants: ...
-        * @param       [type]          $script: ...
-        * @param       [type]          $addFields: ...
-        * @return      [type]          ...
+        * @param  string  $cat
+        * @param  array $theConstants
+        * @param  string  $script
+        * @param  string $addFields
+        * @param  string $extKey
+        * @return  string the form
         */
-       function ext_getForm($cat,$theConstants,$script="",$addFields="")       {
+       function ext_getForm($cat, $theConstants, $script = "", $addFields = "", $extKey = "") {
                $this->ext_makeHelpInformationForCategory($cat);
-               $printFields = trim($this->ext_printFields($theConstants,$cat));
+               $printFields = trim($this->ext_printFields($theConstants, $cat));
 
-               $content='';
-               $content.='
-               <script language="javascript" type="text/javascript">
-                       function uFormUrl(aname)        {
-                               document.'.$this->ext_CEformName.'.action = "'.t3lib_div::linkThisScript().'#"+aname;
+               $content = '';
+               $content .= t3lib_div::wrapJS('
+                       function uFormUrl(aname) {
+                               document.' . $this->ext_CEformName . '.action = "' . t3lib_div::linkThisScript() . '#"+aname;
                        }
-               </script>
-               ';
-               $content.= '<form action="'.($script?$script:t3lib_div::linkThisScript()).'" name="'.$this->ext_CEformName.'" method="POST" enctype="'.$GLOBALS["TYPO3_CONF_VARS"]["SYS"]["form_enctype"].'">';
-               $content.= $addFields;
-#              $content.= '<input type="Submit" name="submit" value="Update"><BR>';
-               $content.= $printFields;
-               $content.= '<input type="Submit" name="submit" value="Update">';
+               ');
+               $content .= '<form action="' . htmlspecialchars($script ? $script : t3lib_div::linkThisScript()) . '" name="' . $this->ext_CEformName . '" method="post" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">';
+               $content .= $addFields;
+               $content .= $printFields;
+               $content .= '<input type="Submit" name="submit" value="' .
+                               $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_tsfe.xml:update', TRUE) . '" id="configuration-submit-' . htmlspecialchars($extKey) . '" />';
 
                $example = $this->ext_displayExample();
-               $content.= $example?'<HR>'.$example:"";
+               $content .= $example ? '<hr/>' . $example : "";
 
                return $content;
        }
@@ -194,12 +181,12 @@ class t3lib_tsStyleConfig extends t3lib_tsparser_ext      {
         *
         * @return      [type]          ...
         */
-       function ext_displayExample()   {
-               global $SOBE,$tmpl;
-               if ($this->helpConfig["imagetag"] || $this->helpConfig["description"] || $this->helpConfig["header"])   {
-                       $out = '<div align="center">'.$this->helpConfig["imagetag"].'</div><BR>'.
-                               ($this->helpConfig["description"] ? implode(explode("//",$this->helpConfig["description"]),"<BR>")."<BR>" : "").
-                               ($this->helpConfig["bulletlist"] ? "<ul><li>".implode(explode("//",$this->helpConfig["bulletlist"]),"<li>")."</ul>" : "<BR>");
+       function ext_displayExample() {
+               global $SOBE, $tmpl;
+               if ($this->helpConfig["imagetag"] || $this->helpConfig["description"] || $this->helpConfig["header"]) {
+                       $out = '<div align="center">' . $this->helpConfig["imagetag"] . '</div><BR>' .
+                                  ($this->helpConfig["description"] ? implode(explode("//", $this->helpConfig["description"]), "<BR>") . "<BR>" : "") .
+                                  ($this->helpConfig["bulletlist"] ? "<ul><li>" . implode(explode("//", $this->helpConfig["bulletlist"]), "<li>") . "</ul>" : "<BR>");
                }
                return $out;
        }
@@ -210,16 +197,16 @@ class t3lib_tsStyleConfig extends t3lib_tsparser_ext      {
         * @param       [type]          $arr: ...
         * @return      [type]          ...
         */
-       function ext_mergeIncomingWithExisting($arr)    {
+       function ext_mergeIncomingWithExisting($arr) {
                $parseObj = t3lib_div::makeInstance("t3lib_TSparser");
-               $parseObj->parse(implode(chr(10),$this->ext_incomingValues));
+               $parseObj->parse(implode(LF, $this->ext_incomingValues));
                $arr2 = $parseObj->setup;
-               return t3lib_div::array_merge_recursive_overrule($arr,$arr2);
+               return t3lib_div::array_merge_recursive_overrule($arr, $arr2);
        }
 
                // extends:
-       function ext_getKeyImage($key)  {
-               return '<img'.t3lib_iconWorks::skinImg($this->ext_backPath,'gfx/rednumbers/'.$key.'.gif','').' hspace="2" align="top" alt="" />';
+       function ext_getKeyImage($key) {
+               return '<img' . t3lib_iconWorks::skinImg($this->ext_backPath, 'gfx/rednumbers/' . $key . '.gif', '') . ' hspace="2" align="top" alt="" />';
        }
 
        /**
@@ -228,11 +215,11 @@ class t3lib_tsStyleConfig extends t3lib_tsparser_ext      {
         * @param       [type]          $imgConf: ...
         * @return      [type]          ...
         */
-       function ext_getTSCE_config_image($imgConf)     {
-               $iFile=$this->ext_localGfxPrefix.$imgConf;
-               $tFile=$this->ext_localWebGfxPrefix.$imgConf;
-               $imageInfo=@getImagesize($iFile);
-               return '<img src="'.$tFile.'" '.$imageInfo[3].'>';
+       function ext_getTSCE_config_image($imgConf) {
+               $iFile = $this->ext_localGfxPrefix . $imgConf;
+               $tFile = $this->ext_localWebGfxPrefix . $imgConf;
+               $imageInfo = @getImagesize($iFile);
+               return '<img src="' . $tFile . '" ' . $imageInfo[3] . '>';
        }
 
        /**
@@ -241,15 +228,16 @@ class t3lib_tsStyleConfig extends t3lib_tsparser_ext      {
         * @param       [type]          $params: ...
         * @return      [type]          ...
         */
-       function ext_fNandV($params)    {
-               $fN='data['.$params["name"].']';
-               $fV=$params["value"]=isset($this->ext_realValues[$params["name"]]) ? $this->ext_realValues[$params["name"]] : $params["default_value"];
-               if (ereg("^{[\$][a-zA-Z0-9\.]*}$",trim($fV),$reg))      {               // Values entered from the constantsedit cannot be constants!   230502; removed \{ and set {
-                       $fV="";
+       function ext_fNandV($params) {
+               $fN = 'data[' . $params["name"] . ']';
+               $fV = $params["value"] = isset($this->ext_realValues[$params["name"]]) ? $this->ext_realValues[$params["name"]] : $params["default_value"];
+               $reg = array();
+               if (preg_match('/^\{[\$][a-zA-Z0-9\.]*\}$/', trim($fV), $reg)) { // Values entered from the constantsedit cannot be constants!
+                       $fV = "";
                }
-               $fV=htmlspecialchars($fV);
-#debug(array($params,$fN,$fV,isset($this->ext_realValues[$params["name"]])));
-               return array($fN,$fV,$params);
+               $fV = htmlspecialchars($fV);
+
+               return array($fN, $fV, $params);
        }
 
        /**
@@ -258,10 +246,10 @@ class t3lib_tsStyleConfig extends t3lib_tsparser_ext      {
         * @param       [type]          $absPath: ...
         * @return      [type]          ...
         */
-       function ext_loadResources($absPath)    {
+       function ext_loadResources($absPath) {
                $this->ext_readDirResources($GLOBALS["TYPO3_CONF_VARS"]["MODS"]["web_ts"]["onlineResourceDir"]);
-               if (is_dir($absPath))   {
-                       $absPath = ereg_replace("\/$","",$absPath);
+               if (is_dir($absPath)) {
+                       $absPath = rtrim($absPath, '/');
                        $this->readDirectory($absPath);
                }
                $this->ext_resourceDims();
@@ -274,8 +262,8 @@ class t3lib_tsStyleConfig extends t3lib_tsparser_ext        {
         * @param       [type]          $var: ...
         * @return      [type]          ...
         */
-       function ext_putValueInConf($key, $var) {
-               $this->ext_incomingValues[$key]=$key."=".$var;
+       function ext_putValueInConf($key, $var) {
+               $this->ext_incomingValues[$key] = $key . "=" . $var;
        }
 
        /**
@@ -284,13 +272,13 @@ class t3lib_tsStyleConfig extends t3lib_tsparser_ext      {
         * @param       [type]          $key: ...
         * @return      [type]          ...
         */
-       function ext_removeValueInConf($key)    {
+       function ext_removeValueInConf($key) {
                // Nothing...
        }
 }
 
 
-if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsstyleconfig.php'])    {
-       include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsstyleconfig.php']);
+if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsstyleconfig.php'])) {
+       include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsstyleconfig.php']);
 }
 ?>
\ No newline at end of file