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