[TASK] Remove global declarations inside methods
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_rteapi.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2004-2011 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 $this->errorLog = array();
86 if (!$GLOBALS['CLIENT']['FORMSTYLE']) {
87 $this->errorLog[] = 'RTE API: Browser didn\'t support styles';
88 }
89
90 if (!count($this->errorLog)) {
91 return TRUE;
92 }
93 }
94
95 /**
96 * Draws the RTE as a form field or whatever is needed (inserts JavaApplet, creates iframe, renders ....)
97 * Default is to output the transformed content in a plain textarea field. This mode is great for debugging transformations!
98 *
99 * @param object Reference to parent object, which is an instance of the TCEforms.
100 * @param string The table name
101 * @param string The field name
102 * @param array The current row from which field is being rendered
103 * @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.
104 * @param array "special" configuration - what is found at position 4 in the types configuration of a field from record, parsed into an array.
105 * @param array Configuration for RTEs; A mix between TSconfig and otherwise. Contains configuration for display, which buttons are enabled, additional transformation information etc.
106 * @param string Record "type" field value.
107 * @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!
108 * @param integer PID value of record (true parent page id)
109 * @return string HTML code for RTE!
110 */
111 function drawRTE(&$pObj, $table, $field, $row, $PA, $specConf, $thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue) {
112
113 // Transform value:
114 $value = $this->transformContent('rte', $PA['itemFormElValue'], $table, $field, $row, $specConf, $thisConfig, $RTErelPath, $thePidValue);
115
116 // Create item:
117 $item = '
118 ' . $this->triggerField($PA['itemFormElName']) . '
119 <textarea name="' . htmlspecialchars($PA['itemFormElName']) . '"' .
120 $pObj->formWidthText('48', 'off') . ' rows="20" wrap="off" style="background-color: #99eebb;">' .
121 t3lib_div::formatForTextarea($value) .
122 '</textarea>';
123
124 // Return form item:
125 return $item;
126 }
127
128 /**
129 * Performs transformation of content to/from RTE. The keyword $dirRTE determines the direction.
130 * This function is called in two situations:
131 * a) Right before content from database is sent to the RTE (see ->drawRTE()) it might need transformation
132 * 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.)
133 *
134 * @param string Keyword: "rte" means direction from db to rte, "db" means direction from Rte to DB
135 * @param string Value to transform.
136 * @param string The table name
137 * @param string The field name
138 * @param array The current row from which field is being rendered
139 * @param array "special" configuration - what is found at position 4 in the types configuration of a field from record, parsed into an array.
140 * @param array Configuration for RTEs; A mix between TSconfig and otherwise. Contains configuration for display, which buttons are enabled, additional transformation information etc.
141 * @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!
142 * @param integer PID value of record (true parent page id)
143 * @return string Transformed content
144 */
145 function transformContent($dirRTE, $value, $table, $field, $row, $specConf, $thisConfig, $RTErelPath, $pid) {
146
147 #debug(array($dirRTE,$value,$table,$field,array(),$specConf,$thisConfig,$RTErelPath,$pid));
148
149 if ($specConf['rte_transform']) {
150 $p = t3lib_BEfunc::getSpecConfParametersFromArray($specConf['rte_transform']['parameters']);
151 if ($p['mode']) { // There must be a mode set for transformation
152 #debug($p['mode'],'MODE');
153
154 // Initialize transformation:
155 $parseHTML = t3lib_div::makeInstance('t3lib_parsehtml_proc');
156 $parseHTML->init($table . ':' . $field, $pid);
157 $parseHTML->setRelPath($RTErelPath);
158
159 // Perform transformation:
160 $value = $parseHTML->RTE_transform($value, $specConf, $dirRTE, $thisConfig);
161 }
162 }
163
164 #debug(array($dirRTE,$value),'OUT: '.$dirRTE);
165 return $value;
166 }
167
168
169 /***********************************
170 *
171 * Helper functions
172 *
173 **********************************/
174
175 /**
176 * Trigger field - this field tells the TCEmain that processing should be done on this value!
177 *
178 * @param string Field name of the RTE field.
179 * @return string <input> field of type "hidden" with a flag telling the TCEmain that this fields content should be traansformed back to database state.
180 */
181 function triggerField($fieldName) {
182
183 $triggerFieldName = preg_replace('/\[([^]]+)\]$/', '[_TRANSFORM_\1]', $fieldName);
184 return '<input type="hidden" name="' . htmlspecialchars($triggerFieldName) . '" value="RTE" />';
185 }
186 }
187
188 /**
189 * @deprecated since TYPO3 4.4: Use XCLASS t3lib/class.t3lib_rteapi.php instead. Will be removed in TYPO3 4.6.
190 */
191 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rte/class.tx_rte_base.php'])) {
192 t3lib_div::deprecationLog('XCLASS "ext/rte/class.tx_rte_base.php" is deprecated since TYPO3 4.4 - use "t3lib/class.t3lib_rteapi.php" instead.');
193 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rte/class.tx_rte_base.php']);
194 }
195
196 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_rteapi.php'])) {
197 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_rteapi.php']);
198 }
199
200 ?>