[FEATURE] Allow .ts file extension for static typoscript templates
[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 * 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
35 * See "rte" extension for usage.
36 *
37 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
38 * @package TYPO3
39 * @subpackage t3lib
40 */
41 class t3lib_rteapi {
42
43 // Internal, dynamic:
44 // Error messages regarding non-availability is collected here.
45 var $errorLog = array();
46
47 // Internal, static:
48 // Set this to the extension key of the RTE so it can identify itself.
49 var $ID = '';
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 $pObj Reference to parent object, which is an instance of the TCEforms.
81 * @param string $table The table name
82 * @param string $field The field name
83 * @param array $row The current row from which field is being rendered
84 * @param array $PA 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 $specConf "special" configuration - what is found at position 4 in the types configuration of a field from record, parsed into an array.
86 * @param array $thisConfig Configuration for RTEs; A mix between TSconfig and otherwise. Contains configuration for display, which buttons are enabled, additional transformation information etc.
87 * @param string $RTEtypeVal Record "type" field value.
88 * @param string $RTErelPath 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 $thePidValue 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 $dirRTE Keyword: "rte" means direction from db to rte, "db" means direction from Rte to DB
116 * @param string $value Value to transform.
117 * @param string $table The table name
118 * @param string $field The field name
119 * @param array $row The current row from which field is being rendered
120 * @param array $specConf "special" configuration - what is found at position 4 in the types configuration of a field from record, parsed into an array.
121 * @param array $thisConfig Configuration for RTEs; A mix between TSconfig and otherwise. Contains configuration for display, which buttons are enabled, additional transformation information etc.
122 * @param string $RTErelPath 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 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 if ($specConf['rte_transform']) {
128 $p = t3lib_BEfunc::getSpecConfParametersFromArray($specConf['rte_transform']['parameters']);
129 // There must be a mode set for transformation
130 if ($p['mode']) {
131
132 // Initialize transformation:
133 $parseHTML = t3lib_div::makeInstance('t3lib_parsehtml_proc');
134 $parseHTML->init($table . ':' . $field, $pid);
135 $parseHTML->setRelPath($RTErelPath);
136
137 // Perform transformation:
138 $value = $parseHTML->RTE_transform($value, $specConf, $dirRTE, $thisConfig);
139 }
140 }
141
142 return $value;
143 }
144
145 /***********************************
146 *
147 * Helper functions
148 *
149 **********************************/
150
151 /**
152 * Trigger field - this field tells the TCEmain that processing should be done on this value!
153 *
154 * @param string $fieldName Field name of the RTE field.
155 * @return string <input> field of type "hidden" with a flag telling the TCEmain that this fields content should be traansformed back to database state.
156 */
157 function triggerField($fieldName) {
158
159 $triggerFieldName = preg_replace('/\[([^]]+)\]$/', '[_TRANSFORM_\1]', $fieldName);
160 return '<input type="hidden" name="' . htmlspecialchars($triggerFieldName) . '" value="RTE" />';
161 }
162 }
163
164 ?>