Fixed bug #14050: CleanUp - CGL format of t3lib files - t3lib_tceforms_inline
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_rteapi.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2004-2010 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
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.
13 *
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.
18 *
19 *
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.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * RTE API parent class.
29 *
30 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
31 */
32 /**
33 * [CLASS/FUNCTION INDEX of SCRIPT]
34 *
35 *
36 *
37 * 64: class t3lib_rteapi
38 *
39 * SECTION: Main API functions;
40 * 93: function isAvailable()
41 * 118: function drawRTE(&$pObj,$table,$field,$row,$PA,$specConf,$thisConfig,$RTEtypeVal,$RTErelPath,$thePidValue)
42 * 151: function transformContent($dirRTE,$value,$table,$field,$row,$specConf,$thisConfig,$RTErelPath,$pid)
43 *
44 * SECTION: Helper functions
45 * 197: function triggerField($fieldName)
46 *
47 * TOTAL FUNCTIONS: 4
48 * (This index is automatically created/updated by the extension "extdeveval")
49 *
50 */
51
52
53 /**
54 * 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
55 * See "rte" extension for usage.
56 *
57 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
58 * @package TYPO3
59 * @subpackage t3lib
60 */
61 class t3lib_rteapi {
62
63 // Internal, dynamic:
64 var $errorLog = array(); // Error messages regarding non-availability is collected here.
65
66 // Internal, static:
67 var $ID = ''; // Set this to the extension key of the RTE so it can identify itself.
68
69
70 /***********************************
71 *
72 * Main API functions;
73 * When you create alternative RTEs, simply override these functions in your parent class.
74 * See the "rte" or "rtehtmlarea" extension as an example!
75 *
76 **********************************/
77
78 /**
79 * Returns true if the RTE is available. Here you check if the browser requirements are met.
80 * If there are reasons why the RTE cannot be displayed you simply enter them as text in ->errorLog
81 *
82 * @return boolean TRUE if this RTE object offers an RTE in the current browser environment
83 */
84 function isAvailable() {
85 global $CLIENT;
86
87 $this->errorLog = array();
88 if (!$CLIENT['FORMSTYLE']) {
89 $this->errorLog[] = 'RTE API: Browser didn\'t support styles';
90 }
91
92 if (!count($this->errorLog)) {
93 return TRUE;
94 }
95 }
96
97 /**
98 * Draws the RTE as a form field or whatever is needed (inserts JavaApplet, creates iframe, renders ....)
99 * Default is to output the transformed content in a plain textarea field. This mode is great for debugging transformations!
100 *
101 * @param object Reference to parent object, which is an instance of the TCEforms.
102 * @param string The table name
103 * @param string The field name
104 * @param array The current row from which field is being rendered
105 * @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.
106 * @param array "special" configuration - what is found at position 4 in the types configuration of a field from record, parsed into an array.
107 * @param array Configuration for RTEs; A mix between TSconfig and otherwise. Contains configuration for display, which buttons are enabled, additional transformation information etc.
108 * @param string Record "type" field value.
109 * @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!
110 * @param integer PID value of record (true parent page id)
111 * @return string HTML code for RTE!
112 */
113 function drawRTE(&$pObj, $table, $field, $row, $PA, $specConf, $thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue) {
114
115 // Transform value:
116 $value = $this->transformContent('rte', $PA['itemFormElValue'], $table, $field, $row, $specConf, $thisConfig, $RTErelPath, $thePidValue);
117
118 // Create item:
119 $item = '
120 ' . $this->triggerField($PA['itemFormElName']) . '
121 <textarea name="' . htmlspecialchars($PA['itemFormElName']) . '"' .
122 $pObj->formWidthText('48', 'off') . ' rows="20" wrap="off" style="background-color: #99eebb;">' .
123 t3lib_div::formatForTextarea($value) .
124 '</textarea>';
125
126 // Return form item:
127 return $item;
128 }
129
130 /**
131 * Performs transformation of content to/from RTE. The keyword $dirRTE determines the direction.
132 * This function is called in two situations:
133 * a) Right before content from database is sent to the RTE (see ->drawRTE()) it might need transformation
134 * 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.)
135 *
136 * @param string Keyword: "rte" means direction from db to rte, "db" means direction from Rte to DB
137 * @param string Value to transform.
138 * @param string The table name
139 * @param string The field name
140 * @param array The current row from which field is being rendered
141 * @param array "special" configuration - what is found at position 4 in the types configuration of a field from record, parsed into an array.
142 * @param array Configuration for RTEs; A mix between TSconfig and otherwise. Contains configuration for display, which buttons are enabled, additional transformation information etc.
143 * @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!
144 * @param integer PID value of record (true parent page id)
145 * @return string Transformed content
146 */
147 function transformContent($dirRTE, $value, $table, $field, $row, $specConf, $thisConfig, $RTErelPath, $pid) {
148
149 #debug(array($dirRTE,$value,$table,$field,array(),$specConf,$thisConfig,$RTErelPath,$pid));
150
151 if ($specConf['rte_transform']) {
152 $p = t3lib_BEfunc::getSpecConfParametersFromArray($specConf['rte_transform']['parameters']);
153 if ($p['mode']) { // There must be a mode set for transformation
154 #debug($p['mode'],'MODE');
155
156 // Initialize transformation:
157 $parseHTML = t3lib_div::makeInstance('t3lib_parsehtml_proc');
158 $parseHTML->init($table . ':' . $field, $pid);
159 $parseHTML->setRelPath($RTErelPath);
160
161 // Perform transformation:
162 $value = $parseHTML->RTE_transform($value, $specConf, $dirRTE, $thisConfig);
163 }
164 }
165
166 #debug(array($dirRTE,$value),'OUT: '.$dirRTE);
167 return $value;
168 }
169
170
171 /***********************************
172 *
173 * Helper functions
174 *
175 **********************************/
176
177 /**
178 * Trigger field - this field tells the TCEmain that processing should be done on this value!
179 *
180 * @param string Field name of the RTE field.
181 * @return string <input> field of type "hidden" with a flag telling the TCEmain that this fields content should be traansformed back to database state.
182 */
183 function triggerField($fieldName) {
184
185 $triggerFieldName = preg_replace('/\[([^]]+)\]$/', '[_TRANSFORM_\1]', $fieldName);
186 return '<input type="hidden" name="' . htmlspecialchars($triggerFieldName) . '" value="RTE" />';
187 }
188 }
189
190 /**
191 * @deprecated since TYPO3 4.4: Use XCLASS t3lib/class.t3lib_rteapi.php instead. Will be removed in TYPO3 4.6.
192 */
193 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rte/class.tx_rte_base.php']) {
194 t3lib_div::deprecationLog('XCLASS "ext/rte/class.tx_rte_base.php" is deprecated since TYPO3 4.4 - use "t3lib/class.t3lib_rteapi.php" instead.');
195 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rte/class.tx_rte_base.php']);
196 }
197
198 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_rteapi.php']) {
199 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_rteapi.php']);
200 }
201
202 ?>