class.t3lib_rteapi.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2004-2010 Kasper Skaarhoj (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  * RTE API parent class.
00029  *
00030  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00031  */
00032 /**
00033  * [CLASS/FUNCTION INDEX of SCRIPT]
00034  *
00035  *
00036  *
00037  *   64: class t3lib_rteapi
00038  *
00039  *              SECTION: Main API functions;
00040  *   93:     function isAvailable()
00041  *  118:     function drawRTE(&$pObj,$table,$field,$row,$PA,$specConf,$thisConfig,$RTEtypeVal,$RTErelPath,$thePidValue)
00042  *  151:     function transformContent($dirRTE,$value,$table,$field,$row,$specConf,$thisConfig,$RTErelPath,$pid)
00043  *
00044  *              SECTION: Helper functions
00045  *  197:     function triggerField($fieldName)
00046  *
00047  * TOTAL FUNCTIONS: 4
00048  * (This index is automatically created/updated by the extension "extdeveval")
00049  *
00050  */
00051 
00052 
00053 
00054 
00055 
00056 /**
00057  * RTE base class: Delivers browser-detection, TCEforms binding and transformation routines for the "rte" extension, registering it with the RTE API in TYPO3 3.6.0
00058  * See "rte" extension for usage.
00059  *
00060  * @author  Kasper Skaarhoj <kasperYYYY@typo3.com>
00061  * @package TYPO3
00062  * @subpackage t3lib
00063  */
00064 class t3lib_rteapi {
00065 
00066         // Internal, dynamic:
00067     var $errorLog = array();        // Error messages regarding non-availability is collected here.
00068 
00069         // Internal, static:
00070     var $ID = '';                   // Set this to the extension key of the RTE so it can identify itself.
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078 
00079     /***********************************
00080      *
00081      * Main API functions;
00082      * When you create alternative RTEs, simply override these functions in your parent class.
00083      * See the "rte" or "rtehtmlarea" extension as an example!
00084      *
00085      **********************************/
00086 
00087     /**
00088      * Returns true if the RTE is available. Here you check if the browser requirements are met.
00089      * If there are reasons why the RTE cannot be displayed you simply enter them as text in ->errorLog
00090      *
00091      * @return  boolean     TRUE if this RTE object offers an RTE in the current browser environment
00092      */
00093     function isAvailable()  {
00094         global $CLIENT;
00095 
00096         $this->errorLog = array();
00097         if (!$CLIENT['FORMSTYLE'])  $this->errorLog[] = 'RTE API: Browser didn\'t support styles';
00098 
00099         if (!count($this->errorLog))    return TRUE;
00100     }
00101 
00102     /**
00103      * Draws the RTE as a form field or whatever is needed (inserts JavaApplet, creates iframe, renders ....)
00104      * Default is to output the transformed content in a plain textarea field. This mode is great for debugging transformations!
00105      *
00106      * @param   object      Reference to parent object, which is an instance of the TCEforms.
00107      * @param   string      The table name
00108      * @param   string      The field name
00109      * @param   array       The current row from which field is being rendered
00110      * @param   array       Array of standard content for rendering form fields from TCEforms. See TCEforms for details on this. Includes for instance the value and the form field name, java script actions and more.
00111      * @param   array       "special" configuration - what is found at position 4 in the types configuration of a field from record, parsed into an array.
00112      * @param   array       Configuration for RTEs; A mix between TSconfig and otherwise. Contains configuration for display, which buttons are enabled, additional transformation information etc.
00113      * @param   string      Record "type" field value.
00114      * @param   string      Relative path for images/links in RTE; this is used when the RTE edits content from static files where the path of such media has to be transformed forth and back!
00115      * @param   integer     PID value of record (true parent page id)
00116      * @return  string      HTML code for RTE!
00117      */
00118     function drawRTE(&$pObj,$table,$field,$row,$PA,$specConf,$thisConfig,$RTEtypeVal,$RTErelPath,$thePidValue)  {
00119 
00120             // Transform value:
00121         $value = $this->transformContent('rte',$PA['itemFormElValue'],$table,$field,$row,$specConf,$thisConfig,$RTErelPath,$thePidValue);
00122 
00123             // Create item:
00124         $item = '
00125             '.$this->triggerField($PA['itemFormElName']).'
00126             <textarea name="'.htmlspecialchars($PA['itemFormElName']).'"'.$pObj->formWidthText('48','off').' rows="20" wrap="off" style="background-color: #99eebb;">'.
00127             t3lib_div::formatForTextarea($value).
00128             '</textarea>';
00129 
00130             // Return form item:
00131         return $item;
00132     }
00133 
00134     /**
00135      * Performs transformation of content to/from RTE. The keyword $dirRTE determines the direction.
00136      * This function is called in two situations:
00137      * a) Right before content from database is sent to the RTE (see ->drawRTE()) it might need transformation
00138      * b) When content is sent from the RTE and into the database it might need transformation back again (going on in TCEmain class; You can't affect that.)
00139      *
00140      * @param   string      Keyword: "rte" means direction from db to rte, "db" means direction from Rte to DB
00141      * @param   string      Value to transform.
00142      * @param   string      The table name
00143      * @param   string      The field name
00144      * @param   array       The current row from which field is being rendered
00145      * @param   array       "special" configuration - what is found at position 4 in the types configuration of a field from record, parsed into an array.
00146      * @param   array       Configuration for RTEs; A mix between TSconfig and otherwise. Contains configuration for display, which buttons are enabled, additional transformation information etc.
00147      * @param   string      Relative path for images/links in RTE; this is used when the RTE edits content from static files where the path of such media has to be transformed forth and back!
00148      * @param   integer     PID value of record (true parent page id)
00149      * @return  string      Transformed content
00150      */
00151     function transformContent($dirRTE,$value,$table,$field,$row,$specConf,$thisConfig,$RTErelPath,$pid) {
00152 
00153 #debug(array($dirRTE,$value,$table,$field,array(),$specConf,$thisConfig,$RTErelPath,$pid));
00154 
00155         if ($specConf['rte_transform']) {
00156             $p = t3lib_BEfunc::getSpecConfParametersFromArray($specConf['rte_transform']['parameters']);
00157             if ($p['mode']) {   // There must be a mode set for transformation
00158 #debug($p['mode'],'MODE');
00159 
00160                     // Initialize transformation:
00161                 $parseHTML = t3lib_div::makeInstance('t3lib_parsehtml_proc');
00162                 $parseHTML->init($table.':'.$field, $pid);
00163                 $parseHTML->setRelPath($RTErelPath);
00164 
00165                     // Perform transformation:
00166                 $value = $parseHTML->RTE_transform($value, $specConf, $dirRTE, $thisConfig);
00167             }
00168         }
00169 
00170 #debug(array($dirRTE,$value),'OUT: '.$dirRTE);
00171         return $value;
00172     }
00173 
00174 
00175 
00176 
00177 
00178 
00179 
00180 
00181 
00182 
00183 
00184 
00185     /***********************************
00186      *
00187      * Helper functions
00188      *
00189      **********************************/
00190 
00191     /**
00192      * Trigger field - this field tells the TCEmain that processing should be done on this value!
00193      *
00194      * @param   string      Field name of the RTE field.
00195      * @return  string      <input> field of type "hidden" with a flag telling the TCEmain that this fields content should be traansformed back to database state.
00196      */
00197     function triggerField($fieldName)   {
00198 
00199         $triggerFieldName = preg_replace('/\[([^]]+)\]$/','[_TRANSFORM_\1]', $fieldName);
00200         return '<input type="hidden" name="'.htmlspecialchars($triggerFieldName).'" value="RTE" />';
00201     }
00202 }
00203 
00204 /**
00205  * @deprecated since TYPO3 4.4: Use XCLASS t3lib/class.t3lib_rteapi.php instead. Will be removed in TYPO3 4.6.
00206  */
00207 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rte/class.tx_rte_base.php'])   {
00208     t3lib_div::deprecationLog('XCLASS "ext/rte/class.tx_rte_base.php" is deprecated since TYPO3 4.4 - use "t3lib/class.t3lib_rteapi.php" instead.');
00209     include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rte/class.tx_rte_base.php']);
00210 }
00211 
00212 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_rteapi.php']) {
00213     include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_rteapi.php']);
00214 }
00215 
00216 ?>

Generated on Sat Jul 24 04:17:17 2010 for TYPO3 API by  doxygen 1.4.7