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