TYPO3 API  SVNRelease
class.t3lib_tsstyleconfig.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
00006  *  All rights reserved
00007  *
00008  *  This script is part of the TYPO3 project. The TYPO3 project is
00009  *  free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  The GNU General Public License can be found at
00015  *  http://www.gnu.org/copyleft/gpl.html.
00016  *  A copy is found in the textfile GPL.txt and important notices to the license
00017  *  from the author is found in LICENSE.txt distributed with these scripts.
00018  *
00019  *
00020  *  This script is distributed in the hope that it will be useful,
00021  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *  GNU General Public License for more details.
00024  *
00025  *  This copyright notice MUST APPEAR in all copies of the script!
00026  ***************************************************************/
00027 /**
00028  * Provides a simplified layer for making Constant Editor style configuration forms
00029  *
00030  * $Id: class.t3lib_tsstyleconfig.php 10325 2011-01-26 08:44:08Z stephenking $
00031  *
00032  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00033  */
00034 /**
00035  * [CLASS/FUNCTION INDEX of SCRIPT]
00036  *
00037  *
00038  *
00039  *   79: class t3lib_tsStyleConfig extends t3lib_tsparser_ext
00040  *   98:     function ext_initTSstyleConfig($configTemplate,$pathRel,$pathAbs,$backPath)
00041  *  118:     function ext_setValueArray($theConstants,$valueArray)
00042  *  145:     function ext_getCategoriesForModMenu()
00043  *  155:     function ext_makeHelpInformationForCategory($cat)
00044  *  168:     function ext_getForm($cat,$theConstants,$script="",$addFields="")
00045  *  175:     function uFormUrl(aname)
00046  *  197:     function ext_displayExample()
00047  *  213:     function ext_mergeIncomingWithExisting($arr)
00048  *  221:     function ext_getKeyImage($key)
00049  *  231:     function ext_getTSCE_config_image($imgConf)
00050  *  244:     function ext_fNandV($params)
00051  *  262:     function ext_loadResources($absPath)
00052  *  278:     function ext_putValueInConf($key, $var)
00053  *  288:     function ext_removeValueInConf($key)
00054  *
00055  * TOTAL FUNCTIONS: 14
00056  * (This index is automatically created/updated by the extension "extdeveval")
00057  *
00058  */
00059 
00060 
00061 /**
00062  * Provides a simplified layer for making Constant Editor style configuration forms
00063  *
00064  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00065  * @package TYPO3
00066  * @subpackage t3lib
00067  */
00068 class t3lib_tsStyleConfig extends t3lib_tsparser_ext {
00069         // internal
00070     var $categories = array();
00071     var $ext_dontCheckIssetValues = 1;
00072     var $ext_CEformName = "tsStyleConfigForm";
00073     var $ext_noCEUploadAndCopying = 1;
00074     var $ext_printAll = 1;
00075     var $ext_defaultOnlineResourceFlag = 1;
00076 
00077     var $ext_incomingValues = array();
00078 
00079 
00080     /**
00081      * @param   string      pathRel is the path relative to the typo3/ directory
00082      * @param   string      pathAbs is the absolute path from root
00083      * @param   string      backPath is the backReference from current position to typo3/ dir
00084      * @param   [type]      $backPath: ...
00085      * @return  [type]      ...
00086      */
00087     function ext_initTSstyleConfig($configTemplate, $pathRel, $pathAbs, $backPath) {
00088         $this->tt_track = 0; // Do not log time-performance information
00089         $this->constants = array($configTemplate, "");
00090 
00091         $theConstants = $this->generateConfig_constants(); // The editable constants are returned in an array.
00092 
00093         $this->ext_localGfxPrefix = $pathAbs;
00094         $this->ext_localWebGfxPrefix = $backPath . $pathRel;
00095         $this->ext_backPath = $backPath;
00096 
00097         return $theConstants;
00098     }
00099 
00100     /**
00101      * [Describe function...]
00102      *
00103      * @param   [type]      $theConstants: ...
00104      * @param   [type]      $valueArray: ...
00105      * @return  [type]      ...
00106      */
00107     function ext_setValueArray($theConstants, $valueArray) {
00108 
00109         $temp = $this->flatSetup;
00110         $this->flatSetup = array();
00111         $this->flattenSetup($valueArray, "", "");
00112         $this->objReg = $this->ext_realValues = $this->flatSetup;
00113         $this->flatSetup = $temp;
00114 
00115 
00116         foreach ($theConstants as $k => $p) {
00117             if (isset($this->objReg[$k])) {
00118                 $theConstants[$k]["value"] = $this->ext_realValues[$k];
00119             }
00120         }
00121 
00122         $this->categories = array(); // Reset the default pool of categories.
00123         $this->ext_categorizeEditableConstants($theConstants); // The returned constants are sorted in categories, that goes into the $this->categories array
00124 
00125         return $theConstants;
00126     }
00127 
00128     /**
00129      * [Describe function...]
00130      *
00131      * @return  [type]      ...
00132      */
00133     function ext_getCategoriesForModMenu() {
00134         return $this->ext_getCategoryLabelArray();
00135     }
00136 
00137     /**
00138      * [Describe function...]
00139      *
00140      * @param   [type]      $cat: ...
00141      * @return  [type]      ...
00142      */
00143     function ext_makeHelpInformationForCategory($cat) {
00144         return $this->ext_getTSCE_config($cat);
00145     }
00146 
00147     /**
00148      * Get the form for extension configuration
00149      *
00150      * @param  string  $cat
00151      * @param  array $theConstants
00152      * @param  string  $script
00153      * @param  string $addFields
00154      * @param  string $extKey
00155      * @param  bool  Adds opening <form> tag to the ouput, if TRUE
00156      * @return  string the form
00157      */
00158     function ext_getForm($cat, $theConstants, $script = "", $addFields = "", $extKey = "", $addFormTag = TRUE) {
00159         $this->ext_makeHelpInformationForCategory($cat);
00160         $printFields = trim($this->ext_printFields($theConstants, $cat));
00161 
00162         $content = '';
00163         $content .= t3lib_div::wrapJS('
00164             function uFormUrl(aname) {
00165                 document.' . $this->ext_CEformName . '.action = "' . t3lib_div::linkThisScript() . '#"+aname;
00166             }
00167         ');
00168 
00169         if ($addFormTag) {
00170             $content .= '<form action="' . htmlspecialchars($script ? $script : t3lib_div::linkThisScript()) . '" name="' . $this->ext_CEformName . '" method="post" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">';
00171         }
00172         $content .= $addFields;
00173         $content .= $printFields;
00174         $content .= '<input type="submit" name="submit" value="' .
00175                 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_tsfe.xml:update', TRUE) . '" id="configuration-submit-' . htmlspecialchars($extKey) . '" />';
00176 
00177         $example = $this->ext_displayExample();
00178         $content .= $example ? '<hr/>' . $example : "";
00179 
00180         return $content;
00181     }
00182 
00183     /**
00184      * [Describe function...]
00185      *
00186      * @return  [type]      ...
00187      */
00188     function ext_displayExample() {
00189         global $SOBE, $tmpl;
00190         if ($this->helpConfig["imagetag"] || $this->helpConfig["description"] || $this->helpConfig["header"]) {
00191             $out = '<div align="center">' . $this->helpConfig["imagetag"] . '</div><BR>' .
00192                    ($this->helpConfig["description"] ? implode(explode("//", $this->helpConfig["description"]), "<BR>") . "<BR>" : "") .
00193                    ($this->helpConfig["bulletlist"] ? "<ul><li>" . implode(explode("//", $this->helpConfig["bulletlist"]), "<li>") . "</ul>" : "<BR>");
00194         }
00195         return $out;
00196     }
00197 
00198     /**
00199      * [Describe function...]
00200      *
00201      * @param   [type]      $arr: ...
00202      * @return  [type]      ...
00203      */
00204     function ext_mergeIncomingWithExisting($arr) {
00205         $parseObj = t3lib_div::makeInstance("t3lib_TSparser");
00206         $parseObj->parse(implode(LF, $this->ext_incomingValues));
00207         $arr2 = $parseObj->setup;
00208         return t3lib_div::array_merge_recursive_overrule($arr, $arr2);
00209     }
00210 
00211         // extends:
00212     function ext_getKeyImage($key) {
00213         return '<img' . t3lib_iconWorks::skinImg($this->ext_backPath, 'gfx/rednumbers/' . $key . '.gif', '') . ' hspace="2" align="top" alt="" />';
00214     }
00215 
00216     /**
00217      * [Describe function...]
00218      *
00219      * @param   [type]      $imgConf: ...
00220      * @return  [type]      ...
00221      */
00222     function ext_getTSCE_config_image($imgConf) {
00223         $iFile = $this->ext_localGfxPrefix . $imgConf;
00224         $tFile = $this->ext_localWebGfxPrefix . $imgConf;
00225         $imageInfo = @getImagesize($iFile);
00226         return '<img src="' . $tFile . '" ' . $imageInfo[3] . '>';
00227     }
00228 
00229     /**
00230      * [Describe function...]
00231      *
00232      * @param   [type]      $params: ...
00233      * @return  [type]      ...
00234      */
00235     function ext_fNandV($params) {
00236         $fN = 'data[' . $params["name"] . ']';
00237         $fV = $params["value"] = isset($this->ext_realValues[$params["name"]]) ? $this->ext_realValues[$params["name"]] : $params["default_value"];
00238         $reg = array();
00239         if (preg_match('/^\{[\$][a-zA-Z0-9\.]*\}$/', trim($fV), $reg)) { // Values entered from the constantsedit cannot be constants!
00240             $fV = "";
00241         }
00242         $fV = htmlspecialchars($fV);
00243 
00244         return array($fN, $fV, $params);
00245     }
00246 
00247     /**
00248      * [Describe function...]
00249      *
00250      * @param   [type]      $absPath: ...
00251      * @return  [type]      ...
00252      */
00253     function ext_loadResources($absPath) {
00254         $this->ext_readDirResources($GLOBALS["TYPO3_CONF_VARS"]["MODS"]["web_ts"]["onlineResourceDir"]);
00255         if (is_dir($absPath)) {
00256             $absPath = rtrim($absPath, '/');
00257             $this->readDirectory($absPath);
00258         }
00259         $this->ext_resourceDims();
00260     }
00261 
00262     /**
00263      * [Describe function...]
00264      *
00265      * @param   [type]      $key: ...
00266      * @param   [type]      $var: ...
00267      * @return  [type]      ...
00268      */
00269     function ext_putValueInConf($key, $var) {
00270         $this->ext_incomingValues[$key] = $key . "=" . $var;
00271     }
00272 
00273     /**
00274      * [Describe function...]
00275      *
00276      * @param   [type]      $key: ...
00277      * @return  [type]      ...
00278      */
00279     function ext_removeValueInConf($key) {
00280         // Nothing...
00281     }
00282 }
00283 
00284 
00285 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsstyleconfig.php'])) {
00286     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tsstyleconfig.php']);
00287 }
00288 ?>