[CLEANUP] Code Cleanup EXT:feedit

Refactor the code to go green in PHPStorm.
Main tasks:
* Initialize variables
* Centralize objects in $GLOBALS

Resolves: #62691
Releases: master
Change-Id: Iaf4659bc9ef4cdeffbccd53fde2969a9b4c592c4
Reviewed-on: http://review.typo3.org/33785
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
This commit is contained in:
Mathias Schreiber 2014-11-04 14:22:56 +01:00 committed by Anja Leichsenring
parent 3e4e23ba52
commit 2b5fa80be7

View file

@ -1,7 +1,7 @@
<?php <?php
namespace TYPO3\CMS\Feedit; namespace TYPO3\CMS\Feedit;
/* /**
* This file is part of the TYPO3 CMS project. * This file is part of the TYPO3 CMS project.
* *
* It is free software; you can redistribute it and/or modify it under * It is free software; you can redistribute it and/or modify it under
@ -15,8 +15,12 @@ namespace TYPO3\CMS\Feedit;
*/ */
use TYPO3\CMS\Backend\Utility\IconUtility; use TYPO3\CMS\Backend\Utility\IconUtility;
use TYPO3\CMS\Backend\FrontendBackendUserAuthentication;
use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\CMS\Frontend\View\AdminPanelView;
/** /**
* View class for the edit panels in frontend editing. * View class for the edit panels in frontend editing.
@ -24,15 +28,43 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
class FrontendEditPanel { class FrontendEditPanel {
/** /**
* The Content Object Renderer
*
* @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
*/ */
protected $cObj; protected $cObj;
/** /**
* Constructor for the edit panel * Property for accessing TypoScriptFrontendController centrally
*
* @var TypoScriptFrontendController
*/ */
public function __construct() { protected $frontendController;
$this->cObj = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
/**
* Property for accessing DatabaseConnection centrally
*
* @var DatabaseConnection
*/
protected $databaseConnection;
/**
* @var FrontendBackendUserAuthentication
*/
protected $backendUser;
/**
* Constructor for the edit panel
*
* @param DatabaseConnection $databaseConnection
* @param TypoScriptFrontendController $frontendController
* @param FrontendBackendUserAuthentication $backendUser
*/
public function __construct(DatabaseConnection $databaseConnection = NULL, TypoScriptFrontendController $frontendController = NULL, FrontendBackendUserAuthentication $backendUser = NULL) {
$this->databaseConnection = $databaseConnection ?: $GLOBALS['TYPO3_DB'];
$this->frontendController = $frontendController ?: $GLOBALS['TSFE'];
$this->backendUser = $backendUser ?: $GLOBALS['BE_USER'];
$this->cObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
$this->cObj->start(array()); $this->cObj->start(array());
} }
@ -46,68 +78,63 @@ class FrontendEditPanel {
* @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 * @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
* @param array $dataArr Alternative data array to use. Default is $this->data * @param array $dataArr Alternative data array to use. Default is $this->data
* @param string $table * @param string $table
* @param string $allow * @param array $allow
* @param int $newUID * @param int $newUID
* @param array $hiddenFields * @param array $hiddenFields
* @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. * @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.
*/ */
public function editPanel($content, array $conf, $currentRecord = '', array $dataArr = array(), $table = '', $allow = '', $newUID = 0, array $hiddenFields = array()) { public function editPanel($content, array $conf, $currentRecord = '', array $dataArr = array(), $table = '', array $allow = array(), $newUID = 0, array $hiddenFields = array()) {
$hiddenFieldString = $command = ''; $hiddenFieldString = $command = '';
// Special content is about to be shown, so the cache must be disabled. // Special content is about to be shown, so the cache must be disabled.
$GLOBALS['TSFE']->set_no_cache('Frontend edit panel is shown', TRUE); $this->frontendController->set_no_cache('Frontend edit panel is shown', TRUE);
$formName = 'TSFE_EDIT_FORM_' . substr($GLOBALS['TSFE']->uniqueHash(), 0, 4); $formName = 'TSFE_EDIT_FORM_' . substr($this->frontendController->uniqueHash(), 0, 4);
$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);">'; $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);">';
$sortField = $GLOBALS['TCA'][$table]['ctrl']['sortby']; $sortField = $GLOBALS['TCA'][$table]['ctrl']['sortby'];
$labelField = $GLOBALS['TCA'][$table]['ctrl']['label']; $labelField = $GLOBALS['TCA'][$table]['ctrl']['label'];
$hideField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled']; $hideField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'];
$TSFE_EDIT = $GLOBALS['BE_USER']->frontendEdit->TSFE_EDIT;
if (is_array($TSFE_EDIT) && $TSFE_EDIT['record'] == $currentRecord && !$TSFE_EDIT['update_close']) {
$command = $TSFE_EDIT['cmd'];
}
$panel = ''; $panel = '';
if (isset($allow['toolbar']) && $GLOBALS['BE_USER']->adminPanel instanceof \TYPO3\CMS\Frontend\View\AdminPanelView) { if (isset($allow['toolbar']) && $this->backendUser->adminPanel instanceof AdminPanelView) {
$panel .= $GLOBALS['BE_USER']->adminPanel->ext_makeToolBar(); $panel .= $this->backendUser->adminPanel->ext_makeToolBar();
} }
if (isset($allow['edit'])) { if (isset($allow['edit'])) {
$icon = IconUtility::getSpriteIcon('actions-document-open', array('title' => $GLOBALS['BE_USER']->extGetLL('p_editRecord'))); $icon = IconUtility::getSpriteIcon('actions-document-open', array('title' => $this->backendUser->extGetLL('p_editRecord')));
$panel .= $this->editPanelLinkWrap($icon, $formName, 'edit', $dataArr['_LOCALIZED_UID'] ? $table . ':' . $dataArr['_LOCALIZED_UID'] : $currentRecord); $panel .= $this->editPanelLinkWrap($icon, $formName, 'edit', $dataArr['_LOCALIZED_UID'] ? $table . ':' . $dataArr['_LOCALIZED_UID'] : $currentRecord);
} }
// Hiding in workspaces because implementation is incomplete // Hiding in workspaces because implementation is incomplete
if (isset($allow['move']) && $sortField && $GLOBALS['BE_USER']->workspace === 0) { if (isset($allow['move']) && $sortField && $this->backendUser->workspace === 0) {
$icon = IconUtility::getSpriteIcon('actions-move-up', array('title' => $GLOBALS['BE_USER']->extGetLL('p_moveUp'))); $icon = IconUtility::getSpriteIcon('actions-move-up', array('title' => $this->backendUser->extGetLL('p_moveUp')));
$panel .= $this->editPanelLinkWrap($icon, $formName, 'up'); $panel .= $this->editPanelLinkWrap($icon, $formName, 'up');
$icon = IconUtility::getSpriteIcon('actions-move-down', array('title' => $GLOBALS['BE_USER']->extGetLL('p_moveDown'))); $icon = IconUtility::getSpriteIcon('actions-move-down', array('title' => $this->backendUser->extGetLL('p_moveDown')));
$panel .= $this->editPanelLinkWrap($icon, $formName, 'down'); $panel .= $this->editPanelLinkWrap($icon, $formName, 'down');
} }
// Hiding in workspaces because implementation is incomplete // Hiding in workspaces because implementation is incomplete
// Hiding for localizations because it is unknown what should be the function in that case // Hiding for localizations because it is unknown what should be the function in that case
if (isset($allow['hide']) && $hideField && $GLOBALS['BE_USER']->workspace === 0 && !$dataArr['_LOCALIZED_UID']) { if (isset($allow['hide']) && $hideField && $this->backendUser->workspace === 0 && !$dataArr['_LOCALIZED_UID']) {
if ($dataArr[$hideField]) { if ($dataArr[$hideField]) {
$icon = IconUtility::getSpriteIcon('actions-edit-unhide', array('title' => $GLOBALS['BE_USER']->extGetLL('p_unhide'))); $icon = IconUtility::getSpriteIcon('actions-edit-unhide', array('title' => $this->backendUser->extGetLL('p_unhide')));
$panel .= $this->editPanelLinkWrap($icon, $formName, 'unhide'); $panel .= $this->editPanelLinkWrap($icon, $formName, 'unhide');
} else { } else {
$icon = IconUtility::getSpriteIcon('actions-edit-hide', array('title' => $GLOBALS['BE_USER']->extGetLL('p_hide'))); $icon = IconUtility::getSpriteIcon('actions-edit-hide', array('title' => $this->backendUser->extGetLL('p_hide')));
$panel .= $this->editPanelLinkWrap($icon, $formName, 'hide', '', $GLOBALS['BE_USER']->extGetLL('p_hideConfirm')); $panel .= $this->editPanelLinkWrap($icon, $formName, 'hide', '', $this->backendUser->extGetLL('p_hideConfirm'));
} }
} }
if (isset($allow['new'])) { if (isset($allow['new'])) {
if ($table === 'pages') { if ($table === 'pages') {
$icon = IconUtility::getSpriteIcon('actions-page-new', array('title' => $GLOBALS['BE_USER']->extGetLL('p_newSubpage'))); $icon = IconUtility::getSpriteIcon('actions-page-new', array('title' => $this->backendUser->extGetLL('p_newSubpage')));
$panel .= $this->editPanelLinkWrap($icon, $formName, 'new', $currentRecord, ''); $panel .= $this->editPanelLinkWrap($icon, $formName, 'new', $currentRecord, '');
} else { } else {
$icon = IconUtility::getSpriteIcon('actions-document-new', array('title' => $GLOBALS['BE_USER']->extGetLL('p_newRecordAfter'))); $icon = IconUtility::getSpriteIcon('actions-document-new', array('title' => $this->backendUser->extGetLL('p_newRecordAfter')));
$panel .= $this->editPanelLinkWrap($icon, $formName, 'new', $currentRecord, '', $newUID); $panel .= $this->editPanelLinkWrap($icon, $formName, 'new', $currentRecord, '', $newUID);
} }
} }
// Hiding in workspaces because implementation is incomplete // Hiding in workspaces because implementation is incomplete
// Hiding for localizations because it is unknown what should be the function in that case // Hiding for localizations because it is unknown what should be the function in that case
if (isset($allow['delete']) && $GLOBALS['BE_USER']->workspace === 0 && !$dataArr['_LOCALIZED_UID']) { if (isset($allow['delete']) && $this->backendUser->workspace === 0 && !$dataArr['_LOCALIZED_UID']) {
$icon = IconUtility::getSpriteIcon('actions-edit-delete', array('title' => $GLOBALS['BE_USER']->extGetLL('p_delete'))); $icon = IconUtility::getSpriteIcon('actions-edit-delete', array('title' => $this->backendUser->extGetLL('p_delete')));
$panel .= $this->editPanelLinkWrap($icon, $formName, 'delete', '', $GLOBALS['BE_USER']->extGetLL('p_deleteConfirm')); $panel .= $this->editPanelLinkWrap($icon, $formName, 'delete', '', $this->backendUser->extGetLL('p_deleteConfirm'));
} }
// Final // Final
$labelTxt = $this->cObj->stdWrap($conf['label'], $conf['label.']); $labelTxt = $this->cObj->stdWrap($conf['label'], $conf['label.']);
@ -172,10 +199,10 @@ class FrontendEditPanel {
*/ */
public function editIcons($content, $params, array $conf = array(), $currentRecord = '', array $dataArr = array(), $addUrlParamStr = '', $table, $editUid, $fieldList) { public function editIcons($content, $params, array $conf = array(), $currentRecord = '', array $dataArr = array(), $addUrlParamStr = '', $table, $editUid, $fieldList) {
// Special content is about to be shown, so the cache must be disabled. // Special content is about to be shown, so the cache must be disabled.
$GLOBALS['TSFE']->set_no_cache('Display frontend edit icons', TRUE); $this->frontendController->set_no_cache('Display frontend edit icons', TRUE);
$style = $conf['styleAttribute'] ? ' style="' . htmlspecialchars($conf['styleAttribute']) . '"' : ''; $style = $conf['styleAttribute'] ? ' style="' . htmlspecialchars($conf['styleAttribute']) . '"' : '';
$iconTitle = $this->cObj->stdWrap($conf['iconTitle'], $conf['iconTitle.']); $iconTitle = $this->cObj->stdWrap($conf['iconTitle'], $conf['iconTitle.']);
$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="" />'; $iconImg = $conf['iconImg'] ? $conf['iconImg'] : '<img ' . 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="" />';
$nV = GeneralUtility::_GP('ADMCMD_view') ? 1 : 0; $nV = GeneralUtility::_GP('ADMCMD_view') ? 1 : 0;
$adminURL = GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir; $adminURL = GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir;
$icon = $this->editPanelLinkWrap_doWrap($iconImg, $adminURL . 'alt_doc.php?edit[' . $table . '][' . $editUid . ']=edit&columnsOnly=' . rawurlencode($fieldList) . '&noView=' . $nV . $addUrlParamStr); $icon = $this->editPanelLinkWrap_doWrap($iconImg, $adminURL . 'alt_doc.php?edit[' . $table . '][' . $editUid . ']=edit&columnsOnly=' . rawurlencode($fieldList) . '&noView=' . $nV . $addUrlParamStr);
@ -188,9 +215,7 @@ class FrontendEditPanel {
$cBuf = rtrim(preg_replace('/<[^<]*>$/', '', $cBuf)); $cBuf = rtrim(preg_replace('/<[^<]*>$/', '', $cBuf));
$secureCount--; $secureCount--;
} }
$content = $cBuf !== '' && $secureCount $content = strlen($cBuf) && $secureCount ? substr($content, 0, strlen($cBuf)) . $icon . substr($content, strlen($cBuf)) : ($content = $icon . $content);
? substr($content, 0, strlen($cBuf)) . $icon . substr($content, strlen($cBuf))
: $icon . $content;
} else { } else {
$content .= $icon; $content .= $icon;
} }
@ -221,12 +246,12 @@ class FrontendEditPanel {
$out = $this->editPanelLinkWrap_doWrap($string, $adminURL . 'db_new.php?id=' . $rParts[1] . '&pagesOnly=1', $currentRecord); $out = $this->editPanelLinkWrap_doWrap($string, $adminURL . 'db_new.php?id=' . $rParts[1] . '&pagesOnly=1', $currentRecord);
} else { } else {
if (!(int)$nPid) { if (!(int)$nPid) {
$nPid = \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($rParts[1]) ? -$rParts[1] : $GLOBALS['TSFE']->id; $nPid = MathUtility::canBeInterpretedAsInteger($rParts[1]) ? -$rParts[1] : $this->frontendController->id;
} }
$out = $this->editPanelLinkWrap_doWrap($string, $adminURL . 'alt_doc.php?edit[' . $rParts[0] . '][' . $nPid . ']=new&noView=' . $nV, $currentRecord); $out = $this->editPanelLinkWrap_doWrap($string, $adminURL . 'alt_doc.php?edit[' . $rParts[0] . '][' . $nPid . ']=new&noView=' . $nV, $currentRecord);
} }
} else { } else {
if ($confirm && $GLOBALS['BE_USER']->jsConfirmation(8)) { if ($confirm && $this->backendUser->jsConfirmation(8)) {
// Gets htmlspecialchared later // Gets htmlspecialchared later
$cf1 = 'if (confirm(' . GeneralUtility::quoteJSvalue($confirm, TRUE) . ')) {'; $cf1 = 'if (confirm(' . GeneralUtility::quoteJSvalue($confirm, TRUE) . ')) {';
$cf2 = '}'; $cf2 = '}';
@ -239,8 +264,7 @@ class FrontendEditPanel {
} }
/** /**
* Creates a link to a script (eg. typo3/alt_doc.php or typo3/db_new.php) * 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.
* which either opens in the current frame OR in a pop-up window.
* *
* @param string $string The string to wrap in a link, typ. and image used as button in the edit panel. * @param string $string The string to wrap in a link, typ. and image used as button in the edit panel.
* @param string $url The URL of the link. Should be absolute if supposed to work with <base> path set. * @param string $url The URL of the link. Should be absolute if supposed to work with <base> path set.
@ -248,16 +272,9 @@ class FrontendEditPanel {
* @see editPanelLinkWrap() * @see editPanelLinkWrap()
*/ */
protected function editPanelLinkWrap_doWrap($string, $url) { protected function editPanelLinkWrap_doWrap($string, $url) {
// Open in the current frame? $onclick = 'vHWin=window.open(' . GeneralUtility::quoteJSvalue($url . '&returnUrl=close.html') . ',\'FEquickEditWindow\',\'width=690,height=500,status=0,menubar=0,scrollbars=1,resizable=1\');vHWin.focus();return false;';
if ($GLOBALS['BE_USER']->adminPanel->extGetFeAdminValue('edit', 'editNoPopup')) {
$href = htmlspecialchars($url . '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI')));
return '<a href="' . $href . '" class="frontEndEditIconLinks">' . $string . '</a>';
} else {
$onclick = 'vHWin=window.open(' . GeneralUtility::quoteJSvalue($url . '&returnUrl=close.html') .
',\'FEquickEditWindow\',\'width=690,height=500,status=0,menubar=0,scrollbars=1,resizable=1\');vHWin.focus();return false;';
return '<a href="#" onclick="' . htmlspecialchars($onclick) . '" class="frontEndEditIconLinks">' . $string . '</a>'; return '<a href="#" onclick="' . htmlspecialchars($onclick) . '" class="frontEndEditIconLinks">' . $string . '</a>';
} }
}
/** /**
* Returns TRUE if the input table/row would be hidden in the frontend, according to the current time and simulate user group * Returns TRUE if the input table/row would be hidden in the frontend, according to the current time and simulate user group
@ -272,8 +289,8 @@ class FrontendEditPanel {
$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'] && $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'] &&
$row[$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled']] || $row[$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled']] ||
$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['fe_group'] && $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['fe_group'] &&
$GLOBALS['TSFE']->simUserGroup && $this->frontendController->simUserGroup &&
$row[$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['fe_group']] == $GLOBALS['TSFE']->simUserGroup || $row[$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['fe_group']] == $this->frontendController->simUserGroup ||
$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['starttime'] && $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['starttime'] &&
$row[$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['starttime']] > $GLOBALS['EXEC_TIME'] || $row[$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['starttime']] > $GLOBALS['EXEC_TIME'] ||
$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['endtime'] && $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['endtime'] &&