[TASK] Cleanup feedit
[Packages/TYPO3.CMS.git] / typo3 / sysext / feedit / Classes / FrontendEditPanel.php
1 <?php
2 namespace TYPO3\CMS\Feedit;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2008-2011 Jeff Segars <jeff@webempoweredchurch.org>
8 * (c) 2008-2011 David Slayback <dave@webempoweredchurch.org>
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 * A copy is found in the textfile GPL.txt and important notices to the license
20 * from the author is found in LICENSE.txt distributed with these scripts.
21 *
22 *
23 * This script is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * This copyright notice MUST APPEAR in all copies of the script!
29 ***************************************************************/
30
31 /**
32 * View class for the edit panels in frontend editing.
33 *
34 * @author Jeff Segars <jeff@webempoweredchurch.org>
35 * @author David Slayback <dave@webempoweredchurch.org>
36 */
37 class FrontendEditPanel {
38
39 /**
40 * Local instance of tslib_cObj.
41 *
42 * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
43 */
44 protected $cObj;
45
46 /**
47 * Constructor for the edit panel. Creates a new cObject instance to be used in wrapping, etc.
48 *
49 * @return void
50 */
51 public function __construct() {
52 $this->cObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
53 $this->cObj->start(array());
54 }
55
56 /**
57 * Generates the "edit panels" which can be shown for a page or records on a page when the Admin Panel is enabled for a backend users surfing the frontend.
58 * With the "edit panel" the user will see buttons with links to editing, moving, hiding, deleting the element
59 * This function is used for the cObject EDITPANEL and the stdWrap property ".editPanel"
60 *
61 * @param string $content A content string containing the content related to the edit panel. For cObject "EDITPANEL" this is empty but not so for the stdWrap property. The edit panel is appended to this string and returned.
62 * @param array $conf TypoScript configuration properties for the editPanel
63 * @param string $currentRecord The "table:uid" of the record being shown. If empty string then $this->currentRecord is used. For new records (set by $conf['newRecordFromTable']) it's auto-generated to "[tablename]:NEW
64 * @param array $dataArr Alternative data array to use. Default is $this->data
65 * @param string $table
66 * @param string $allow
67 * @param integer $newUID
68 * @param array $hiddenFields
69 * @return string The input content string with the editPanel appended. This function returns only an edit panel appended to the content string if a backend user is logged in (and has the correct permissions). Otherwise the content string is directly returned.
70 */
71 public function editPanel($content, array $conf, $currentRecord = '', array $dataArr = array(), $table = '', $allow = '', $newUID = 0, array $hiddenFields = array()) {
72 // Special content is about to be shown, so the cache must be disabled.
73 $GLOBALS['TSFE']->set_no_cache('Frontend edit panel is shown');
74 $formName = 'TSFE_EDIT_FORM_' . substr($GLOBALS['TSFE']->uniqueHash(), 0, 4);
75 $formTag = '<form name="' . $formName . '" id ="' . $formName . '" action="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI')) . '" method="post" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '" onsubmit="return TBE_EDITOR.checkSubmit(1);" style="margin: 0 0 0 0;">';
76 $sortField = $GLOBALS['TCA'][$table]['ctrl']['sortby'];
77 $labelField = $GLOBALS['TCA'][$table]['ctrl']['label'];
78 $hideField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'];
79 $blackLine = $conf['line'] ? '<img src="clear.gif" width="1" height="' . intval($conf['line']) . '" alt="" title="" /><br /><table border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="black" style="border: 0px;" summary=""><tr style="border: 0px;"><td style="border: 0px;"><img src="clear.gif" width="1" height="1" alt="" title="" /></td></tr></table><br />' : '';
80 $theCmd = '';
81 $TSFE_EDIT = $GLOBALS['BE_USER']->frontendEdit->TSFE_EDIT;
82 if (is_array($TSFE_EDIT) && $TSFE_EDIT['record'] == $currentRecord && !$TSFE_EDIT['update_close']) {
83 $theCmd = $TSFE_EDIT['cmd'];
84 }
85 switch ($theCmd) {
86 case 'edit':
87
88 case 'new':
89 $finalOut = $this->editContent($formTag, $formName, $theCmd, $newUID, $dataArr, $table, $currentRecord, $blackLine);
90 break;
91 default:
92 $panel = '';
93 if (isset($allow['toolbar']) && $GLOBALS['BE_USER']->adminPanel instanceof \TYPO3\CMS\Frontend\View\AdminPanelView) {
94 $panel .= $GLOBALS['BE_USER']->adminPanel->ext_makeToolBar() . '<img src="clear.gif" width="2" height="1" alt="" title="" />';
95 }
96 if (isset($allow['edit'])) {
97 $panel .= $this->editPanelLinkWrap('<img ' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg(TYPO3_mainDir, 'gfx/edit2.gif', 'width="11" height="12" hspace="2" border="0"') . ' title="' . $GLOBALS['BE_USER']->extGetLL('p_editRecord') . '" align="top" alt="" />', $formName, 'edit', $dataArr['_LOCALIZED_UID'] ? $table . ':' . $dataArr['_LOCALIZED_UID'] : $currentRecord);
98 }
99 // Hiding in workspaces because implementation is incomplete
100 if (isset($allow['move']) && $sortField && $GLOBALS['BE_USER']->workspace === 0) {
101 $panel .= $this->editPanelLinkWrap('<img ' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg(TYPO3_mainDir, 'gfx/button_up.gif', 'width="11" height="10" vspace="1" hspace="2" border="0" ') . ' title="' . $GLOBALS['BE_USER']->extGetLL('p_moveUp') . '" align="top" alt="" />', $formName, 'up');
102 $panel .= $this->editPanelLinkWrap('<img ' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg(TYPO3_mainDir, 'gfx/button_down.gif', 'width="11" height="10" vspace="1" hspace="2" border="0" ') . ' title="' . $GLOBALS['BE_USER']->extGetLL('p_moveDown') . '" align="top" alt="" />', $formName, 'down');
103 }
104 // Hiding in workspaces because implementation is incomplete, Hiding for localizations because it is unknown what should be the function in that case
105 if (isset($allow['hide']) && $hideField && $GLOBALS['BE_USER']->workspace === 0 && !$dataArr['_LOCALIZED_UID']) {
106 if ($dataArr[$hideField]) {
107 $panel .= $this->editPanelLinkWrap('<img ' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg(TYPO3_mainDir, 'gfx/button_unhide.gif', 'width="11" height="10" vspace="1" hspace="2" border="0" ') . ' title="' . $GLOBALS['BE_USER']->extGetLL('p_unhide') . '" align="top" alt="" />', $formName, 'unhide');
108 } else {
109 $panel .= $this->editPanelLinkWrap('<img ' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg(TYPO3_mainDir, 'gfx/button_hide.gif', 'width="11" height="10" vspace="1" hspace="2" border="0" ') . ' title="' . $GLOBALS['BE_USER']->extGetLL('p_hide') . '" align="top" alt="" />', $formName, 'hide', '', $GLOBALS['BE_USER']->extGetLL('p_hideConfirm'));
110 }
111 }
112 if (isset($allow['new'])) {
113 if ($table == 'pages') {
114 $panel .= $this->editPanelLinkWrap('<img ' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg(TYPO3_mainDir, 'gfx/new_page.gif', 'width="13" height="12" vspace="1" hspace="2" border="0" ') . ' title="' . $GLOBALS['BE_USER']->extGetLL('p_newSubpage') . '" align="top" alt="" />', $formName, 'new', $currentRecord, '');
115 } else {
116 $panel .= $this->editPanelLinkWrap('<img ' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg(TYPO3_mainDir, 'gfx/new_record.gif', 'width="16" height="12" vspace="1" hspace="2" border="0" ') . ' title="' . $GLOBALS['BE_USER']->extGetLL('p_newRecordAfter') . '" align="top" alt="" />', $formName, 'new', $currentRecord, '', $newUID);
117 }
118 }
119 // Hiding in workspaces because implementation is incomplete, Hiding for localizations because it is unknown what should be the function in that case
120 if (isset($allow['delete']) && $GLOBALS['BE_USER']->workspace === 0 && !$dataArr['_LOCALIZED_UID']) {
121 $panel .= $this->editPanelLinkWrap('<img ' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg(TYPO3_mainDir, 'gfx/delete_record.gif', 'width="12" height="12" vspace="1" hspace="2" border="0" ') . ' title="' . $GLOBALS['BE_USER']->extGetLL('p_delete') . '" align="top" alt="" />', $formName, 'delete', '', $GLOBALS['BE_USER']->extGetLL('p_deleteConfirm'));
122 }
123 // Final
124 $labelTxt = $this->cObj->stdWrap($conf['label'], $conf['label.']);
125 foreach ((array) $hiddenFields as $name => $value) {
126 $hiddenFieldString .= '<input type="hidden" name="TSFE_EDIT[' . $name . ']" value="' . $value . '"/>' . LF;
127 }
128 $panel = '
129
130 <!-- BE_USER Edit Panel: -->
131 ' . $formTag . $hiddenFieldString . '
132 <input type="hidden" name="TSFE_EDIT[cmd]" value="" />
133 <input type="hidden" name="TSFE_EDIT[record]" value="' . $currentRecord . '" />
134 <table border="0" cellpadding="0" cellspacing="0" class="typo3-editPanel" summary="">
135 <tr>
136 <td nowrap="nowrap" bgcolor="#ABBBB4" class="typo3-editPanel-controls">' . $panel . '</td>' . ($labelTxt ? '<td nowrap="nowrap" bgcolor="#F6F2E6" class="typo3-editPanel-label"><font face="verdana" size="1" color="black">&nbsp;' . sprintf($labelTxt, htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($dataArr[$labelField], 50))) . '&nbsp;</font></td>' : '') . '
137 </tr>
138 </table>
139 </form>';
140 // Wrap the panel
141 if ($conf['innerWrap']) {
142 $panel = $this->cObj->wrap($panel, $conf['innerWrap']);
143 }
144 if ($conf['innerWrap.']) {
145 $panel = $this->cObj->stdWrap($panel, $conf['innerWrap.']);
146 }
147 // Add black line:
148 $panel .= $blackLine;
149 // Wrap the complete panel
150 if ($conf['outerWrap']) {
151 $panel = $this->cObj->wrap($panel, $conf['outerWrap']);
152 }
153 if ($conf['outerWrap.']) {
154 $panel = $this->cObj->stdWrap($panel, $conf['outerWrap.']);
155 }
156 if ($conf['printBeforeContent']) {
157 $finalOut = $panel . $content;
158 } else {
159 $finalOut = $content . $panel;
160 }
161 break;
162 }
163 if ($conf['previewBorder']) {
164 if (!is_array($conf['previewBorder.'])) {
165 $conf['previewBorder.'] = array();
166 }
167 $finalOut = $this->editPanelPreviewBorder($table, $dataArr, $finalOut, $conf['previewBorder'], $conf['previewBorder.']);
168 }
169 return $finalOut;
170 }
171
172 /**
173 * Adds an edit icon to the content string. The edit icon links to alt_doc.php with proper parameters for editing the table/fields of the context.
174 * This implements TYPO3 context sensitive editing facilities. Only backend users will have access (if properly configured as well).
175 *
176 * @param string $content The content to which the edit icons should be appended
177 * @param string $params The parameters defining which table and fields to edit. Syntax is [tablename]:[fieldname],[fieldname],[fieldname],... OR [fieldname],[fieldname],[fieldname],... (basically "[tablename]:" is optional, default table is the one of the "current record" used in the function). The fieldlist is sent as "&columnsOnly=" parameter to alt_doc.php
178 * @param array $conf TypoScript properties for configuring the edit icons.
179 * @param string $currentRecord The "table:uid" of the record being shown. If empty string then $this->currentRecord is used. For new records (set by $conf['newRecordFromTable']) it's auto-generated to "[tablename]:NEW
180 * @param array $dataArr Alternative data array to use. Default is $this->data
181 * @param string $addUrlParamStr Additional URL parameters for the link pointing to alt_doc.php
182 * @param string $table
183 * @param integer $editUid
184 * @param string $fieldList
185 * @return string The input content string, possibly with edit icons added (not necessarily in the end but just after the last string of normal content.
186 */
187 public function editIcons($content, $params, array $conf = array(), $currentRecord = '', array $dataArr = array(), $addUrlParamStr = '', $table, $editUid, $fieldList) {
188 // Special content is about to be shown, so the cache must be disabled.
189 $GLOBALS['TSFE']->set_no_cache('Display frontend edit icons');
190 $style = $conf['styleAttribute'] ? ' style="' . htmlspecialchars($conf['styleAttribute']) . '"' : '';
191 $iconTitle = $this->cObj->stdWrap($conf['iconTitle'], $conf['iconTitle.']);
192 $iconImg = $conf['iconImg'] ? $conf['iconImg'] : '<img ' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg(TYPO3_mainDir, 'gfx/edit_fe.gif', 'width="11" height="12" border="0" align="top" ') . ' title="' . \TYPO3\CMS\Core\Utility\GeneralUtility::deHSCentities(htmlspecialchars($iconTitle)) . '"' . $style . ' class="frontEndEditIcons" alt="" />';
193 $nV = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('ADMCMD_view') ? 1 : 0;
194 $adminURL = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir;
195 $icon = $this->editPanelLinkWrap_doWrap($iconImg, $adminURL . 'alt_doc.php?edit[' . $table . '][' . $editUid . ']=edit&columnsOnly=' . rawurlencode($fieldList) . '&noView=' . $nV . $addUrlParamStr, $currentRecord);
196 if ($conf['beforeLastTag'] < 0) {
197 $content = $icon . $content;
198 } elseif ($conf['beforeLastTag'] > 0) {
199 $cBuf = rtrim($content);
200 $securCount = 30;
201 while ($securCount && substr($cBuf, -1) == '>' && substr($cBuf, -4) != '</a>') {
202 $cBuf = rtrim(preg_replace('/<[^<]*>$/', '', $cBuf));
203 $securCount--;
204 }
205 $content = strlen($cBuf) && $securCount ? substr($content, 0, strlen($cBuf)) . $icon . substr($content, strlen($cBuf)) : ($content = $icon . $content);
206 } else {
207 $content .= $icon;
208 }
209 return $content;
210 }
211
212 /**
213 * Helper function for editPanel() which wraps icons in the panel in a link with the action of the panel.
214 * The links are for some of them not simple hyperlinks but onclick-actions which submits a little form which the panel is wrapped in.
215 *
216 * @param string $string The string to wrap in a link, typ. and image used as button in the edit panel.
217 * @param string $formName The name of the form wrapping the edit panel.
218 * @param string $cmd The command of the link. There is a predefined list available: edit, new, up, down etc.
219 * @param string $currentRecord The "table:uid" of the record being processed by the panel.
220 * @param string $confirm Text string with confirmation message; If set a confirm box will be displayed before carrying out the action (if Yes is pressed)
221 * @param integer $nPid "New pid" - for new records
222 * @return string A <a> tag wrapped string.
223 * @see editPanel(), editIcons(), t3lib_tsfeBeUserAuth::extEditAction()
224 */
225 protected function editPanelLinkWrap($string, $formName, $cmd, $currentRecord = '', $confirm = '', $nPid = '') {
226 // Editing forms on page only supported in Live workspace (because of incomplete implementation)
227 $editFormsOnPage = $GLOBALS['BE_USER']->uc['TSFE_adminConfig']['edit_editFormsOnPage'] && $GLOBALS['BE_USER']->workspace === 0;
228 $nV = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('ADMCMD_view') ? 1 : 0;
229 $adminURL = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir;
230 if ($cmd == 'edit' && !$editFormsOnPage) {
231 $rParts = explode(':', $currentRecord);
232 $out = $this->editPanelLinkWrap_doWrap($string, $adminURL . 'alt_doc.php?edit[' . $rParts[0] . '][' . $rParts[1] . ']=edit&noView=' . $nV, $currentRecord);
233 } elseif ($cmd == 'new' && !$editFormsOnPage) {
234 $rParts = explode(':', $currentRecord);
235 if ($rParts[0] == 'pages') {
236 $out = $this->editPanelLinkWrap_doWrap($string, $adminURL . 'db_new.php?id=' . $rParts[1] . '&pagesOnly=1', $currentRecord);
237 } else {
238 if (!intval($nPid)) {
239 $nPid = \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($rParts[1]) ? -$rParts[1] : $GLOBALS['TSFE']->id;
240 }
241 $out = $this->editPanelLinkWrap_doWrap($string, $adminURL . 'alt_doc.php?edit[' . $rParts[0] . '][' . $nPid . ']=new&noView=' . $nV, $currentRecord);
242 }
243 } else {
244 if ($confirm && $GLOBALS['BE_USER']->jsConfirmation(8)) {
245 // Gets htmlspecialchared later
246 $cf1 = 'if (confirm(' . \TYPO3\CMS\Core\Utility\GeneralUtility::quoteJSvalue($confirm, TRUE) . ')) {';
247 $cf2 = '}';
248 } else {
249 $cf1 = ($cf2 = '');
250 }
251 $out = '<a href="#" onclick="' . htmlspecialchars(($cf1 . 'document.' . $formName . '[\'TSFE_EDIT[cmd]\'].value=\'' . $cmd . '\'; document.' . $formName . '.submit();' . $cf2 . ' return false;')) . '">' . $string . '</a>';
252 }
253 return $out;
254 }
255
256 /**
257 * Creates a link to a script (eg. typo3/alt_doc.php or typo3/db_new.php) which either opens in the current frame OR in a pop-up window.
258 *
259 * @param string $string The string to wrap in a link, typ. and image used as button in the edit panel.
260 * @param string $url The URL of the link. Should be absolute if supposed to work with <base> path set.
261 * @param string $currentRecord The "table:uid" of the record being processed by the panel.
262 * @return string A <a> tag wrapped string.
263 * @see editPanelLinkWrap()
264 */
265 protected function editPanelLinkWrap_doWrap($string, $url, $currentRecord) {
266 if ($GLOBALS['BE_USER']->uc['TSFE_adminConfig']['edit_editNoPopup'] || $GLOBALS['BE_USER']->extAdminConfig['module.']['edit.']['forceNoPopup']) {
267 $retUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI');
268 $rParts = explode(':', $currentRecord);
269 // This parentRecordNumber is used to make sure that only elements 3- of ordinary content elements makes a 'anchor' jump down the page.
270 if ($rParts[0] == 'tt_content' && $this->parentRecordNumber > 2) {
271 $retUrl .= '#' . $rParts[1];
272 }
273 return '<a href="' . htmlspecialchars(($url . '&returnUrl=' . rawurlencode($retUrl))) . '" class="frontEndEditIconLinks">' . $string . '</a>';
274 } else {
275 return '<a href="#" onclick="' . htmlspecialchars(('vHWin=window.open(\'' . $url . '&returnUrl=close.html\',\'FEquickEditWindow\',\'' . ($GLOBALS['BE_USER']->uc['edit_wideDocument'] ? 'width=690,height=500' : 'width=540,height=400') . ',status=0,menubar=0,scrollbars=1,resizable=1\');vHWin.focus();return false;')) . '" class="frontEndEditIconLinks">' . $string . '</a>';
276 }
277 }
278
279 /**
280 * Wraps the input content string in a table with a gray border if the table/row combination evaluates to being disabled/hidden.
281 * Used for marking previewed records in the frontend.
282 *
283 * @param string $table The table name
284 * @param array $row The data record from $table
285 * @param string $content The content string to wrap
286 * @param integer $thick The thickness of the border
287 * @param array $conf The array with TypoScript properties for the content object
288 * @return string The input string wrapped in a table with a border color of #cccccc and thickness = $thick
289 * @see editPanel()
290 */
291 protected function editPanelPreviewBorder($table, array $row, $content, $thick, array $conf = array()) {
292 if ($this->isDisabled($table, $row)) {
293 $thick = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($thick, 1, 100);
294 $color = $conf['color'] ? $conf['color'] : '#cccccc';
295 if ($conf['innerWrap']) {
296 $content = $this->wrap($content, $conf['innerWrap']);
297 }
298 if ($conf['innerWrap.']) {
299 $content = $this->stdWrap($content, $conf['innerWrap.']);
300 }
301 $content = '<table class="typo3-editPanel-previewBorder" border="' . $thick . '" cellpadding="0" cellspacing="0" bordercolor="' . $color . '" width="100%" summary=""><tr><td>' . $content . '</td></tr></table>';
302 if ($conf['outerWrap']) {
303 $content = $this->wrap($content, $conf['outerWrap']);
304 }
305 if ($conf['outerWrap.']) {
306 $content = $this->stdWrap($panel, $conf['outerWrap.']);
307 }
308 }
309 return $content;
310 }
311
312 /**
313 * Returns TRUE if the input table/row would be hidden in the frontend (according nto the current time and simulate user group)
314 *
315 * @param string $table The table name
316 * @param array $row The data record
317 * @return boolean
318 * @see editPanelPreviewBorder()
319 */
320 protected function isDisabled($table, $row) {
321 if (
322 $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'] &&
323 $row[$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled']] ||
324 $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['fe_group'] &&
325 $GLOBALS['TSFE']->simUserGroup &&
326 $row[$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['fe_group']] == $GLOBALS['TSFE']->simUserGroup ||
327 $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['starttime'] &&
328 $row[$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['starttime']] > $GLOBALS['EXEC_TIME'] ||
329 $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['endtime'] &&
330 $row[$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['endtime']] &&
331 $row[$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['endtime']] < $GLOBALS['EXEC_TIME']
332 ) {
333 return TRUE;
334 }
335 }
336
337 /**
338 * Returns the editing form for a content element.
339 *
340 * @param string $formTag Form tag
341 * @param string $formName Form name
342 * @param string $theCmd The command
343 * @param integer $newUID newUID
344 * @param array $dataArray dataArray for element
345 * @param string $table Table name of element
346 * @param string $currentRecord Current record
347 * @param string $blackLine Blackline
348 * @return string
349 */
350 protected function editContent($formTag, $formName, $theCmd, $newUID, array $dataArray, $table, $currentRecord, $blackLine) {
351 $tceforms = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\FrontendFormEngine');
352 $tceforms->initDefaultBEMode();
353 $tceforms->prependFormFieldNames = 'TSFE_EDIT[data]';
354 $tceforms->prependFormFieldNames_file = 'TSFE_EDIT_file';
355 $tceforms->doSaveFieldName = 'TSFE_EDIT[doSave]';
356 $tceforms->formName = $formName;
357 $tceforms->backPath = TYPO3_mainDir;
358 $tceforms->setFancyDesign();
359 $tceforms->defStyle = 'font-family:Verdana;font-size:10px;';
360 $tceforms->edit_showFieldHelp = 0;
361 $tceforms->helpTextFontTag = '<font face="verdana,sans-serif" color="#333333" size="1">';
362 $trData = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Form\\DataPreprocessor');
363 $trData->addRawData = TRUE;
364 $trData->lockRecords = 1;
365 // Added without testing - should provide ability to submit default values in frontend editing, in-page.
366 $trData->defVals = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('defVals');
367 $trData->fetchRecord($table, $theCmd == 'new' ? $newUID : $dataArray['uid'], $theCmd == 'new' ? 'new' : '');
368 reset($trData->regTableItems_data);
369 $processedDataArr = current($trData->regTableItems_data);
370 $processedDataArr['uid'] = $theCmd == 'new' ? 'NEW' : $dataArray['uid'];
371 $processedDataArr['pid'] = $theCmd == 'new' ? $newUID : $dataArray['pid'];
372 $panel = '';
373 $buttons = '<input type="image" border="0" name="TSFE_EDIT[update]" src="' . $tceforms->backPath . 'gfx/savedok.gif" hspace="2" width="21" height="16" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.saveDoc', 1) . '" />';
374 $buttons .= '<input type="image" border="0" name="TSFE_EDIT[update_close]" src="' . $tceforms->backPath . 'gfx/saveandclosedok.gif" hspace="2" width="21" height="16" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.saveCloseDoc', 1) . '" />';
375 $buttons .= '<input type="image" border="0" name="TSFE_EDIT[cancel]" onclick="' . htmlspecialchars(('window.location.href=\'' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI') . '\';return false;')) . '" src="' . $tceforms->backPath . 'gfx/closedok.gif" hspace="2" width="21" height="16" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.closeDoc', 1) . '" />';
376 // Buttons top
377 $panel .= $tceforms->intoTemplate(array('ITEM' => $buttons));
378 $panel .= $tceforms->getMainFields($table, $processedDataArr);
379 $hiddenF = '';
380 if ($theCmd == 'new') {
381 $hiddenF .= '<input type="hidden" name="TSFE_EDIT[data][' . $table . '][NEW][pid]" value="' . $newUID . '" />';
382 if ($table == 'pages') {
383 // If a new page is created in front-end, then show it by default!
384 $hiddenF .= '<input type="hidden" name="TSFE_EDIT[data][' . $table . '][NEW][hidden]" value="0" />';
385 } else {
386 $hiddenF .= '<input type="hidden" name="TSFE_EDIT[record]" value="' . $currentRecord . '" />';
387 $hiddenF .= '<input type="hidden" name="TSFE_EDIT[cmd]" value="edit" />';
388 }
389 }
390 $hiddenF .= '<input type="hidden" name="TSFE_EDIT[doSave]" value="0" />';
391 // Buttons AND hidden fields bottom.
392 $panel .= $tceforms->intoTemplate(array('ITEM' => $buttons . $hiddenF));
393 $panel = $formTag . $tceforms->wrapTotal($panel, $dataArray, $table) . '</form>' . ($theCmd != 'new' ? $blackLine : '');
394 $finalOut = $tceforms->printNeededJSFunctions_top() . ($conf['edit.']['displayRecord'] ? $content : '') . $panel . ($theCmd == 'new' ? $blackLine : '') . $tceforms->printNeededJSFunctions();
395 $GLOBALS['SOBE']->doc->insertHeaderData();
396 return $finalOut;
397 }
398
399 }
400
401 ?>