TYPO3 CMS  TYPO3_6-2
FrontendEditPanel.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Feedit;
3 
18 
20 
25 
29  protected $cObj;
30 
34  public function __construct() {
35  $this->cObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
36  $this->cObj->start(array());
37  }
38 
54  public function editPanel($content, array $conf, $currentRecord = '', array $dataArr = array(), $table = '', $allow = '', $newUID = 0, array $hiddenFields = array()) {
55  $hiddenFieldString = $command = '';
56 
57  // Special content is about to be shown, so the cache must be disabled.
58  $GLOBALS['TSFE']->set_no_cache('Frontend edit panel is shown', TRUE);
59 
60  $formName = 'TSFE_EDIT_FORM_' . substr($GLOBALS['TSFE']->uniqueHash(), 0, 4);
61  $formTag = '<form name="' . $formName . '" id ="' . $formName . '" action="' . htmlspecialchars(GeneralUtility::getIndpEnv('REQUEST_URI')) . '" method="post" enctype="' . htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype']) . '" onsubmit="return TBE_EDITOR.checkSubmit(1);">';
62  $sortField = $GLOBALS['TCA'][$table]['ctrl']['sortby'];
63  $labelField = $GLOBALS['TCA'][$table]['ctrl']['label'];
64  $hideField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'];
65 
66  $TSFE_EDIT = $GLOBALS['BE_USER']->frontendEdit->TSFE_EDIT;
67  if (is_array($TSFE_EDIT) && $TSFE_EDIT['record'] == $currentRecord && !$TSFE_EDIT['update_close']) {
68  $command = $TSFE_EDIT['cmd'];
69  }
70 
71  $panel = '';
72  if (isset($allow['toolbar']) && $GLOBALS['BE_USER']->adminPanel instanceof \TYPO3\CMS\Frontend\View\AdminPanelView) {
73  $panel .= $GLOBALS['BE_USER']->adminPanel->ext_makeToolBar();
74  }
75  if (isset($allow['edit'])) {
76  $icon = IconUtility::getSpriteIcon('actions-document-open', array('title' => $GLOBALS['BE_USER']->extGetLL('p_editRecord')));
77  $panel .= $this->editPanelLinkWrap($icon, $formName, 'edit', $dataArr['_LOCALIZED_UID'] ? $table . ':' . $dataArr['_LOCALIZED_UID'] : $currentRecord);
78  }
79  // Hiding in workspaces because implementation is incomplete
80  if (isset($allow['move']) && $sortField && $GLOBALS['BE_USER']->workspace === 0) {
81  $icon = IconUtility::getSpriteIcon('actions-move-up', array('title' => $GLOBALS['BE_USER']->extGetLL('p_moveUp')));
82  $panel .= $this->editPanelLinkWrap($icon, $formName, 'up');
83  $icon = IconUtility::getSpriteIcon('actions-move-down', array('title' => $GLOBALS['BE_USER']->extGetLL('p_moveDown')));
84  $panel .= $this->editPanelLinkWrap($icon, $formName, 'down');
85  }
86  // Hiding in workspaces because implementation is incomplete
87  // Hiding for localizations because it is unknown what should be the function in that case
88  if (isset($allow['hide']) && $hideField && $GLOBALS['BE_USER']->workspace === 0 && !$dataArr['_LOCALIZED_UID']) {
89  if ($dataArr[$hideField]) {
90  $icon = IconUtility::getSpriteIcon('actions-edit-unhide', array('title' => $GLOBALS['BE_USER']->extGetLL('p_unhide')));
91  $panel .= $this->editPanelLinkWrap($icon, $formName, 'unhide');
92  } else {
93  $icon = IconUtility::getSpriteIcon('actions-edit-hide', array('title' => $GLOBALS['BE_USER']->extGetLL('p_hide')));
94  $panel .= $this->editPanelLinkWrap($icon, $formName, 'hide', '', $GLOBALS['BE_USER']->extGetLL('p_hideConfirm'));
95  }
96  }
97  if (isset($allow['new'])) {
98  if ($table === 'pages') {
99  $icon = IconUtility::getSpriteIcon('actions-page-new', array('title' => $GLOBALS['BE_USER']->extGetLL('p_newSubpage')));
100  $panel .= $this->editPanelLinkWrap($icon, $formName, 'new', $currentRecord, '');
101  } else {
102  $icon = IconUtility::getSpriteIcon('actions-document-new', array('title' => $GLOBALS['BE_USER']->extGetLL('p_newRecordAfter')));
103  $panel .= $this->editPanelLinkWrap($icon, $formName, 'new', $currentRecord, '', $newUID);
104  }
105  }
106  // Hiding in workspaces because implementation is incomplete
107  // Hiding for localizations because it is unknown what should be the function in that case
108  if (isset($allow['delete']) && $GLOBALS['BE_USER']->workspace === 0 && !$dataArr['_LOCALIZED_UID']) {
109  $icon = IconUtility::getSpriteIcon('actions-edit-delete', array('title' => $GLOBALS['BE_USER']->extGetLL('p_delete')));
110  $panel .= $this->editPanelLinkWrap($icon, $formName, 'delete', '', $GLOBALS['BE_USER']->extGetLL('p_deleteConfirm'));
111  }
112  // Final
113  $labelTxt = $this->cObj->stdWrap($conf['label'], $conf['label.']);
114  foreach ((array)$hiddenFields as $name => $value) {
115  $hiddenFieldString .= '<input type="hidden" name="TSFE_EDIT[' . htmlspecialchars($name) . ']" value="' . htmlspecialchars($value) . '"/>' . LF;
116  }
117 
118  $panel = '<!-- BE_USER Edit Panel: -->
119  ' . $formTag . $hiddenFieldString . '
120  <input type="hidden" name="TSFE_EDIT[cmd]" value="" />
121  <input type="hidden" name="TSFE_EDIT[record]" value="' . $currentRecord . '" />
122  <div class="typo3-editPanel">'
123  . $panel .
124  ($labelTxt ? '<div class="typo3-editPanel-label">' . sprintf($labelTxt, htmlspecialchars(GeneralUtility::fixed_lgd_cs($dataArr[$labelField], 50))) . '</div>' : '') . '
125  </div>
126  </form>';
127 
128  // Wrap the panel
129  if ($conf['innerWrap']) {
130  $panel = $this->cObj->wrap($panel, $conf['innerWrap']);
131  }
132  if ($conf['innerWrap.']) {
133  $panel = $this->cObj->stdWrap($panel, $conf['innerWrap.']);
134  }
135 
136  // Wrap the complete panel
137  if ($conf['outerWrap']) {
138  $panel = $this->cObj->wrap($panel, $conf['outerWrap']);
139  }
140  if ($conf['outerWrap.']) {
141  $panel = $this->cObj->stdWrap($panel, $conf['outerWrap.']);
142  }
143  if ($conf['printBeforeContent']) {
144  $finalOut = $panel . $content;
145  } else {
146  $finalOut = $content . $panel;
147  }
148 
149  $hidden = $this->isDisabled($table, $dataArr) ? ' typo3-feedit-element-hidden' : '';
150  $outerWrapConfig = isset($conf['stdWrap.'])
151  ? $conf['stdWrap.']
152  : array('wrap' => '<div class="typo3-feedit-element' . $hidden . '">|</div>');
153  $finalOut = $this->cObj->stdWrap($finalOut, $outerWrapConfig);
154 
155  return $finalOut;
156  }
157 
173  public function editIcons($content, $params, array $conf = array(), $currentRecord = '', array $dataArr = array(), $addUrlParamStr = '', $table, $editUid, $fieldList) {
174  // Special content is about to be shown, so the cache must be disabled.
175  $GLOBALS['TSFE']->set_no_cache('Display frontend edit icons', TRUE);
176  $style = $conf['styleAttribute'] ? ' style="' . htmlspecialchars($conf['styleAttribute']) . '"' : '';
177  $iconTitle = $this->cObj->stdWrap($conf['iconTitle'], $conf['iconTitle.']);
178  $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="' . htmlspecialchars($iconTitle, ENT_COMPAT, 'UTF-8', FALSE) . '"' . $style . ' class="frontEndEditIcons" alt="" />';
179  $nV = GeneralUtility::_GP('ADMCMD_view') ? 1 : 0;
180  $adminURL = GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir;
181  $icon = $this->editPanelLinkWrap_doWrap($iconImg, $adminURL . 'alt_doc.php?edit[' . $table . '][' . $editUid . ']=edit&columnsOnly=' . rawurlencode($fieldList) . '&noView=' . $nV . $addUrlParamStr);
182  if ($conf['beforeLastTag'] < 0) {
183  $content = $icon . $content;
184  } elseif ($conf['beforeLastTag'] > 0) {
185  $cBuf = rtrim($content);
186  $secureCount = 30;
187  while ($secureCount && substr($cBuf, -1) == '>' && substr($cBuf, -4) != '</a>') {
188  $cBuf = rtrim(preg_replace('/<[^<]*>$/', '', $cBuf));
189  $secureCount--;
190  }
191  $content = strlen($cBuf) && $secureCount ? substr($content, 0, strlen($cBuf)) . $icon . substr($content, strlen($cBuf)) : ($content = $icon . $content);
192  } else {
193  $content .= $icon;
194  }
195  return $content;
196  }
197 
210  protected function editPanelLinkWrap($string, $formName, $cmd, $currentRecord = '', $confirm = '', $nPid = '') {
211  $nV = GeneralUtility::_GP('ADMCMD_view') ? 1 : 0;
212  $adminURL = GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir;
213  if ($cmd == 'edit') {
214  $rParts = explode(':', $currentRecord);
215  $out = $this->editPanelLinkWrap_doWrap($string, $adminURL . 'alt_doc.php?edit[' . $rParts[0] . '][' . $rParts[1] . ']=edit&noView=' . $nV, $currentRecord);
216  } elseif ($cmd == 'new') {
217  $rParts = explode(':', $currentRecord);
218  if ($rParts[0] == 'pages') {
219  $out = $this->editPanelLinkWrap_doWrap($string, $adminURL . 'db_new.php?id=' . $rParts[1] . '&pagesOnly=1', $currentRecord);
220  } else {
221  if (!(int)$nPid) {
222  $nPid = \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($rParts[1]) ? -$rParts[1] : $GLOBALS['TSFE']->id;
223  }
224  $out = $this->editPanelLinkWrap_doWrap($string, $adminURL . 'alt_doc.php?edit[' . $rParts[0] . '][' . $nPid . ']=new&noView=' . $nV, $currentRecord);
225  }
226  } else {
227  if ($confirm && $GLOBALS['BE_USER']->jsConfirmation(8)) {
228  // Gets htmlspecialchared later
229  $cf1 = 'if (confirm(' . GeneralUtility::quoteJSvalue($confirm, TRUE) . ')) {';
230  $cf2 = '}';
231  } else {
232  $cf1 = ($cf2 = '');
233  }
234  $out = '<a href="#" onclick="' . htmlspecialchars(($cf1 . 'document.' . $formName . '[\'TSFE_EDIT[cmd]\'].value=\'' . $cmd . '\'; document.' . $formName . '.submit();' . $cf2 . ' return false;')) . '">' . $string . '</a>';
235  }
236  return $out;
237  }
238 
248  protected function editPanelLinkWrap_doWrap($string, $url) {
249  // Open in the current frame?
250  if ($GLOBALS['BE_USER']->adminPanel->extGetFeAdminValue('edit', 'editNoPopup')) {
251  $href = htmlspecialchars($url . '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI')));
252  return '<a href="' . $href . '" class="frontEndEditIconLinks">' . $string . '</a>';
253  } else {
254  $onclick = 'vHWin=window.open(' . GeneralUtility::quoteJSvalue($url . '&returnUrl=close.html') .
255  ',\'FEquickEditWindow\',\'width=690,height=500,status=0,menubar=0,scrollbars=1,resizable=1\');vHWin.focus();return false;';
256  return '<a href="#" onclick="' . htmlspecialchars($onclick) . '" class="frontEndEditIconLinks">' . $string . '</a>';
257  }
258  }
259 
267  protected function isDisabled($table, array $row) {
268  $status = FALSE;
269  if (
270  $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'] &&
271  $row[$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled']] ||
272  $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['fe_group'] &&
273  $GLOBALS['TSFE']->simUserGroup &&
274  $row[$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['fe_group']] == $GLOBALS['TSFE']->simUserGroup ||
275  $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['starttime'] &&
276  $row[$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['starttime']] > $GLOBALS['EXEC_TIME'] ||
277  $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['endtime'] &&
278  $row[$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['endtime']] &&
279  $row[$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['endtime']] < $GLOBALS['EXEC_TIME']
280  ) {
281  $status = TRUE;
282  }
283 
284  return $status;
285  }
286 
287 }
static skinImg($backPath, $src, $wHattribs='', $outputMode=0)
editPanelLinkWrap($string, $formName, $cmd, $currentRecord='', $confirm='', $nPid='')
editPanel($content, array $conf, $currentRecord='', array $dataArr=array(), $table='', $allow='', $newUID=0, array $hiddenFields=array())
editIcons($content, $params, array $conf=array(), $currentRecord='', array $dataArr=array(), $addUrlParamStr='', $table, $editUid, $fieldList)
static getSpriteIcon($iconName, array $options=array(), array $overlays=array())
static fixed_lgd_cs($string, $chars, $appendString='...')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]