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