[TASK] Merge submodule fluid into core
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Rte / AbstractRte.php
1 <?php
2 namespace TYPO3\CMS\Backend\Rte;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2004-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Core\Utility\GeneralUtility;
31
32 /**
33 * 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
34 * See "rte" extension for usage.
35 *
36 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
37 */
38 class AbstractRte {
39
40 // Internal, dynamic:
41 // Error messages regarding non-availability is collected here.
42 /**
43 * @todo Define visibility
44 */
45 public $errorLog = array();
46
47 // Internal, static:
48 // Set this to the extension key of the RTE so it can identify itself.
49 /**
50 * @todo Define visibility
51 */
52 public $ID = '';
53
54 /***********************************
55 *
56 * Main API functions;
57 * When you create alternative RTEs, simply override these functions in your parent class.
58 * See the "rte" or "rtehtmlarea" extension as an example!
59 *
60 **********************************/
61 /**
62 * Returns TRUE if the RTE is available. Here you check if the browser requirements are met.
63 * If there are reasons why the RTE cannot be displayed you simply enter them as text in ->errorLog
64 *
65 * @return boolean TRUE if this RTE object offers an RTE in the current browser environment
66 * @todo Define visibility
67 */
68 public function isAvailable() {
69 $this->errorLog = array();
70 if (!$GLOBALS['CLIENT']['FORMSTYLE']) {
71 $this->errorLog[] = 'RTE API: Browser didn\'t support styles';
72 }
73 if (!count($this->errorLog)) {
74 return TRUE;
75 }
76 }
77
78 /**
79 * Draws the RTE as a form field or whatever is needed (inserts JavaApplet, creates iframe, renders ....)
80 * Default is to output the transformed content in a plain textarea field. This mode is great for debugging transformations!
81 *
82 * @param object $pObj Reference to parent object, which is an instance of the TCEforms.
83 * @param string $table The table name
84 * @param string $field The field name
85 * @param array $row The current row from which field is being rendered
86 * @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.
87 * @param array $specConf "special" configuration - what is found at position 4 in the types configuration of a field from record, parsed into an array.
88 * @param array $thisConfig Configuration for RTEs; A mix between TSconfig and otherwise. Contains configuration for display, which buttons are enabled, additional transformation information etc.
89 * @param string $RTEtypeVal Record "type" field value.
90 * @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!
91 * @param integer $thePidValue PID value of record (true parent page id)
92 * @return string HTML code for RTE!
93 * @todo Define visibility
94 */
95 public function drawRTE(&$pObj, $table, $field, $row, $PA, $specConf, $thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue) {
96 // Transform value:
97 $value = $this->transformContent('rte', $PA['itemFormElValue'], $table, $field, $row, $specConf, $thisConfig, $RTErelPath, $thePidValue);
98 // Create item:
99 $item = '
100 ' . $this->triggerField($PA['itemFormElName']) . '
101 <textarea name="' . htmlspecialchars($PA['itemFormElName']) . '"' . $pObj->formWidthText('48', 'off') . ' rows="20" wrap="off" style="background-color: #99eebb;">' . GeneralUtility::formatForTextarea($value) . '</textarea>';
102 // Return form item:
103 return $item;
104 }
105
106 /**
107 * Performs transformation of content to/from RTE. The keyword $dirRTE determines the direction.
108 * This function is called in two situations:
109 * a) Right before content from database is sent to the RTE (see ->drawRTE()) it might need transformation
110 * 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.)
111 *
112 * @param string $dirRTE Keyword: "rte" means direction from db to rte, "db" means direction from Rte to DB
113 * @param string $value Value to transform.
114 * @param string $table The table name
115 * @param string $field The field name
116 * @param array $row The current row from which field is being rendered
117 * @param array $specConf "special" configuration - what is found at position 4 in the types configuration of a field from record, parsed into an array.
118 * @param array $thisConfig Configuration for RTEs; A mix between TSconfig and otherwise. Contains configuration for display, which buttons are enabled, additional transformation information etc.
119 * @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!
120 * @param integer $pid PID value of record (true parent page id)
121 * @return string Transformed content
122 * @todo Define visibility
123 */
124 public function transformContent($dirRTE, $value, $table, $field, $row, $specConf, $thisConfig, $RTErelPath, $pid) {
125 if ($specConf['rte_transform']) {
126 $p = \TYPO3\CMS\Backend\Utility\BackendUtility::getSpecConfParametersFromArray($specConf['rte_transform']['parameters']);
127 // There must be a mode set for transformation
128 if ($p['mode']) {
129 // Initialize transformation:
130 $parseHTML = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Html\\RteHtmlParser');
131 $parseHTML->init($table . ':' . $field, $pid);
132 $parseHTML->setRelPath($RTErelPath);
133 // Perform transformation:
134 $value = $parseHTML->RTE_transform($value, $specConf, $dirRTE, $thisConfig);
135 }
136 }
137 return $value;
138 }
139
140 /***********************************
141 *
142 * Helper functions
143 *
144 **********************************/
145 /**
146 * Trigger field - this field tells the TCEmain that processing should be done on this value!
147 *
148 * @param string $fieldName Field name of the RTE field.
149 * @return string <input> field of type "hidden" with a flag telling the TCEmain that this fields content should be traansformed back to database state.
150 * @todo Define visibility
151 */
152 public function triggerField($fieldName) {
153 $triggerFieldName = preg_replace('/\\[([^]]+)\\]$/', '[_TRANSFORM_\\1]', $fieldName);
154 return '<input type="hidden" name="' . htmlspecialchars($triggerFieldName) . '" value="RTE" />';
155 }
156
157 }
158
159
160 ?>