diff --git a/typo3/sysext/recycler/Classes/Controller/DeletedRecordsController.php b/typo3/sysext/recycler/Classes/Controller/DeletedRecordsController.php index 920faaf669b29bf4d76fb23e956d77f112304a61..7471cf521ea7cd2e7cf1ede3d317e9756cf124fe 100644 --- a/typo3/sysext/recycler/Classes/Controller/DeletedRecordsController.php +++ b/typo3/sysext/recycler/Classes/Controller/DeletedRecordsController.php @@ -15,6 +15,7 @@ namespace TYPO3\CMS\Recycler\Controller; */ use TYPO3\CMS\Backend\Utility\BackendUtility; +use TYPO3\CMS\Recycler\Utility\RecyclerUtility; /** * Deleted Records View @@ -24,12 +25,24 @@ use TYPO3\CMS\Backend\Utility\BackendUtility; */ class DeletedRecordsController { + /** + * @var \TYPO3\CMS\Lang\LanguageService + */ + protected $languageService; + + /** + * Constructor + */ + public function __construct() { + $this->languageService = $GLOBALS['LANG']; + } + /** * Transforms the rows for the deleted Records into the Array View necessary for ExtJS Ext.data.ArrayReader * - * @param array $rows Array with table as key and array with all deleted rows - * @param int $totalDeleted: Number of deleted records in total, for PagingToolbar - * @return string JSON Array + * @param array $deletedRowsArray Array with table as key and array with all deleted rows + * @param int $totalDeleted Number of deleted records in total, for PagingToolbar + * @return string JSON array */ public function transform($deletedRowsArray, $totalDeleted) { $total = 0; @@ -50,10 +63,10 @@ class DeletedRecordsController { 'tstamp' => BackendUtility::datetime($row[$GLOBALS['TCA'][$table]['ctrl']['tstamp']]), 'owner' => htmlspecialchars($backendUser['username']), 'owner_uid' => $row[$GLOBALS['TCA'][$table]['ctrl']['cruser_id']], - 'tableTitle' => \TYPO3\CMS\Recycler\Utility\RecyclerUtility::getUtf8String($GLOBALS['LANG']->sL($GLOBALS['TCA'][$table]['ctrl']['title'])), - 'title' => htmlspecialchars(\TYPO3\CMS\Recycler\Utility\RecyclerUtility::getUtf8String( + 'tableTitle' => RecyclerUtility::getUtf8String($this->languageService->sL($GLOBALS['TCA'][$table]['ctrl']['title'])), + 'title' => htmlspecialchars(RecyclerUtility::getUtf8String( BackendUtility::getRecordTitle($table, $row))), - 'path' => \TYPO3\CMS\Recycler\Utility\RecyclerUtility::getRecordPath($row['pid']) + 'path' => RecyclerUtility::getRecordPath($row['pid']) ); } } @@ -61,5 +74,4 @@ class DeletedRecordsController { $jsonArray['total'] = $totalDeleted; return json_encode($jsonArray); } - } \ No newline at end of file diff --git a/typo3/sysext/recycler/Classes/Controller/RecyclerAjaxController.php b/typo3/sysext/recycler/Classes/Controller/RecyclerAjaxController.php index 99fa4ad2e96bb1670507fd8c149fa519fa3d0bec..ffbc313870245e46d792b3dc65cc4d9640d6667c 100644 --- a/typo3/sysext/recycler/Classes/Controller/RecyclerAjaxController.php +++ b/typo3/sysext/recycler/Classes/Controller/RecyclerAjaxController.php @@ -68,7 +68,7 @@ class RecyclerAjaxController { // check params if (!is_string($this->command)) { // @TODO make devlog output - return FALSE; + return; } // Create content $this->createContent(); @@ -80,7 +80,6 @@ class RecyclerAjaxController { * @return void */ protected function createContent() { - $str = ''; switch ($this->command) { case 'getDeletedRecords': $table = GeneralUtility::_GP('table') ? GeneralUtility::_GP('table') : GeneralUtility::_GP('tableDefault'); @@ -90,17 +89,20 @@ class RecyclerAjaxController { $startUid = GeneralUtility::_GP('startUid') ? GeneralUtility::_GP('startUid') : ''; $depth = GeneralUtility::_GP('depth') ? GeneralUtility::_GP('depth') : ''; $this->setDataInSession('tableSelection', $table); + /* @var $model \TYPO3\CMS\Recycler\Domain\Model\DeletedRecords */ $model = GeneralUtility::makeInstance('TYPO3\\CMS\\Recycler\\Domain\\Model\\DeletedRecords'); $model->loadData($startUid, $table, $depth, $start . ',' . $limit, $filter); $deletedRowsArray = $model->getDeletedRows(); $model = GeneralUtility::makeInstance('TYPO3\\CMS\\Recycler\\Domain\\Model\\DeletedRecords'); $totalDeleted = $model->getTotalCount($startUid, $table, $depth, $filter); // load view + /* @var $view \TYPO3\CMS\Recycler\Controller\DeletedRecordsController */ $view = GeneralUtility::makeInstance('TYPO3\\CMS\\Recycler\\Controller\\DeletedRecordsController'); $str = $view->transform($deletedRowsArray, $totalDeleted); break; case 'doDelete': $str = FALSE; + /* @var $model \TYPO3\CMS\Recycler\Domain\Model\DeletedRecords */ $model = GeneralUtility::makeInstance('TYPO3\\CMS\\Recycler\\Domain\\Model\\DeletedRecords'); if ($model->deleteData($this->data)) { $str = TRUE; @@ -109,6 +111,7 @@ class RecyclerAjaxController { case 'doUndelete': $str = FALSE; $recursive = GeneralUtility::_GP('recursive'); + /* @var $model \TYPO3\CMS\Recycler\Domain\Model\DeletedRecords */ $model = GeneralUtility::makeInstance('TYPO3\\CMS\\Recycler\\Domain\\Model\\DeletedRecords'); if ($model->undeleteData($this->data, $recursive)) { $str = TRUE; @@ -118,8 +121,9 @@ class RecyclerAjaxController { $depth = GeneralUtility::_GP('depth') ? GeneralUtility::_GP('depth') : 0; $startUid = GeneralUtility::_GP('startUid') ? GeneralUtility::_GP('startUid') : ''; $this->setDataInSession('depthSelection', $depth); + /* @var $model \TYPO3\CMS\Recycler\Domain\Model\Tables */ $model = GeneralUtility::makeInstance('TYPO3\\CMS\\Recycler\\Domain\\Model\\Tables'); - $str = $model->getTables('json', 1, $startUid, $depth); + $str = $model->getTables('json', TRUE, $startUid, $depth); break; default: $str = 'No command was recognized.'; @@ -144,8 +148,9 @@ class RecyclerAjaxController { * @return void */ protected function setDataInSession($identifier, $data) { - $GLOBALS['BE_USER']->uc['tx_recycler'][$identifier] = $data; - $GLOBALS['BE_USER']->writeUC(); + /* @var $beUser \TYPO3\CMS\Core\Authentication\BackendUserAuthentication */ + $beUser = $GLOBALS['BE_USER']; + $beUser->uc['tx_recycler'][$identifier] = $data; + $beUser->writeUC(); } - } diff --git a/typo3/sysext/recycler/Classes/Controller/RecyclerModuleController.php b/typo3/sysext/recycler/Classes/Controller/RecyclerModuleController.php index 86e7146aa16c5ea8143c99b4c1bf703e12775ab8..2b3d3eead07783e90a5114cdc338522ffe85f36e 100644 --- a/typo3/sysext/recycler/Classes/Controller/RecyclerModuleController.php +++ b/typo3/sysext/recycler/Classes/Controller/RecyclerModuleController.php @@ -15,6 +15,8 @@ namespace TYPO3\CMS\Recycler\Controller; */ use TYPO3\CMS\Backend\Utility\BackendUtility; +use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; +use TYPO3\CMS\Core\Utility\GeneralUtility; /** * Module 'Recycler' for the 'recycler' extension. @@ -58,12 +60,25 @@ class RecyclerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass */ protected $pageRenderer; + /** + * @var \TYPO3\CMS\Core\Authentication\BackendUserAuthentication + */ + protected $backendUser; + + /** + * @var \TYPO3\CMS\Lang\LanguageService + */ + protected $languageService; + /** * Constructor */ public function __construct() { - $GLOBALS['LANG']->includeLLFile('EXT:recycler/mod1/locallang.xlf'); - $GLOBALS['BE_USER']->modAccess($GLOBALS['MCONF'], TRUE); + $this->languageService = $GLOBALS['LANG']; + $this->languageService->includeLLFile('EXT:recycler/mod1/locallang.xlf'); + + $this->backendUser = $GLOBALS['BE_USER']; + $this->backendUser->modAccess($GLOBALS['MCONF'], TRUE); } /** @@ -73,20 +88,20 @@ class RecyclerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass */ public function initialize() { parent::init(); - $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate'); - $this->doc->setModuleTemplate(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('recycler') . 'mod1/mod_template.html'); + $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate'); + $this->doc->setModuleTemplate(ExtensionManagementUtility::extPath('recycler') . 'mod1/mod_template.html'); $this->doc->backPath = $GLOBALS['BACK_PATH']; $this->doc->setExtDirectStateProvider(); $this->pageRenderer = $this->doc->getPageRenderer(); - $this->relativePath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('recycler'); + $this->relativePath = ExtensionManagementUtility::extRelPath('recycler'); $this->pageRecord = BackendUtility::readPageAccess($this->id, $this->perms_clause); $this->isAccessibleForCurrentUser = $this->id && is_array($this->pageRecord) || !$this->id && $this->isCurrentUserAdmin(); //don't access in workspace - if ($GLOBALS['BE_USER']->workspace !== 0) { + if ($this->backendUser->workspace !== 0) { $this->isAccessibleForCurrentUser = FALSE; } //read configuration - $modTS = $GLOBALS['BE_USER']->getTSConfig('mod.recycler'); + $modTS = $this->backendUser->getTSConfig('mod.recycler'); if ($this->isCurrentUserAdmin()) { $this->allowDelete = TRUE; } else { @@ -103,8 +118,8 @@ class RecyclerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass * @return void */ public function render() { - $this->content .= $this->doc->header($GLOBALS['LANG']->getLL('title')); - $this->content .= '<p class="lead">' . $GLOBALS['LANG']->getLL('description') . '</p>'; + $this->content .= $this->doc->header($this->languageService->getLL('title')); + $this->content .= '<p class="lead">' . $this->languageService->getLL('description') . '</p>'; if ($this->isAccessibleForCurrentUser) { $this->loadHeaderData(); // div container for renderTo @@ -123,7 +138,7 @@ class RecyclerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass public function flush() { $content = $this->doc->moduleBody($this->pageRecord, $this->getDocHeaderButtons(), $this->getTemplateMarkers()); // Renders the module page - $content = $this->doc->render($GLOBALS['LANG']->getLL('title'), $content); + $content = $this->doc->render($this->languageService->getLL('title'), $content); $this->content = NULL; $this->doc = NULL; echo $content; @@ -135,7 +150,7 @@ class RecyclerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass * @return bool Whether the current user is admin */ protected function isCurrentUserAdmin() { - return (bool)$GLOBALS['BE_USER']->user['admin']; + return (bool)$this->backendUser->user['admin']; } /** @@ -154,7 +169,7 @@ class RecyclerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass $this->pageRenderer->addInlineLanguageLabelArray($this->getJavaScriptLabels()); // Load Recycler JavaScript: // Load Plugins - $uxPath = $this->doc->backpath . 'js/extjs/ux/'; + $uxPath = $this->doc->backPath . 'js/extjs/ux/'; $this->pageRenderer->addJsFile($uxPath . 'Ext.grid.RowExpander.js'); $this->pageRenderer->addJsFile($uxPath . 'Ext.app.SearchField.js'); $this->pageRenderer->addJsFile($uxPath . 'Ext.ux.FitToParent.js'); @@ -174,11 +189,11 @@ class RecyclerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass 'startUid' => $this->id, 'tableDefault' => 'pages', 'renderTo' => 'recyclerContent', - 'isSSL' => \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SSL'), + 'isSSL' => GeneralUtility::getIndpEnv('TYPO3_SSL'), 'deleteDisable' => $this->allowDelete ? 0 : 1, 'depthSelection' => $this->getDataFromSession('depthSelection', 0), 'tableSelection' => $this->getDataFromSession('tableSelection', 'pages'), - 'States' => $GLOBALS['BE_USER']->uc['moduleData']['web_recycler']['States'] + 'States' => $this->backendUser->uc['moduleData']['web_recycler']['States'] ); return $configuration; } @@ -190,16 +205,16 @@ class RecyclerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass */ protected function getJavaScriptLabels() { $coreLabels = array( - 'title' => $GLOBALS['LANG']->getLL('title'), - 'path' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.path'), - 'table' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.table'), - 'depth' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_web_perm.xlf:Depth'), - 'depth_0' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_0'), - 'depth_1' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_1'), - 'depth_2' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_2'), - 'depth_3' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_3'), - 'depth_4' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_4'), - 'depth_infi' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_infi') + 'title' => $this->languageService->getLL('title'), + 'path' => $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.path'), + 'table' => $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.table'), + 'depth' => $this->languageService->sL('LLL:EXT:lang/locallang_mod_web_perm.xlf:Depth'), + 'depth_0' => $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_0'), + 'depth_1' => $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_1'), + 'depth_2' => $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_2'), + 'depth_3' => $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_3'), + 'depth_4' => $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_4'), + 'depth_infi' => $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_infi') ); $extensionLabels = $this->getJavaScriptLabelsFromLocallang('js.', 'label_'); $javaScriptLabels = array_merge($coreLabels, $extensionLabels); @@ -209,14 +224,14 @@ class RecyclerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass /** * Gets labels to be used in JavaScript fetched from the current locallang file. * - * @param string $selectionPrefix: Prefix to select the correct labels (default: 'js.') - * @param string $stripFromSelectionName: Sub-prefix to be removed from label names in the result (default: '') + * @param string $selectionPrefix Prefix to select the correct labels (default: 'js.') + * @param string $stripFromSelectionName Sub-prefix to be removed from label names in the result (default: '') * @return array Labels to be used in JavaScript of the current locallang file * @todo Check, whether this method can be moved in a generic way to $GLOBALS['LANG'] */ protected function getJavaScriptLabelsFromLocallang($selectionPrefix = 'js.', $stripFromSelectionName = '') { $extraction = array(); - $labels = array_merge((array)$GLOBALS['LOCAL_LANG']['default'], (array)$GLOBALS['LOCAL_LANG'][$GLOBALS['LANG']->lang]); + $labels = array_merge((array)$GLOBALS['LOCAL_LANG']['default'], (array)$GLOBALS['LOCAL_LANG'][$this->languageService->lang]); // Regular expression to strip the selection prefix and possibly something from the label name: $labelPattern = '#^' . preg_quote($selectionPrefix, '#') . '(' . preg_quote($stripFromSelectionName, '#') . ')?#'; // Iterate through all locallang labels: @@ -252,7 +267,7 @@ class RecyclerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass */ protected function getShortcutButton() { $result = ''; - if ($GLOBALS['BE_USER']->mayMakeShortcut()) { + if ($this->backendUser->mayMakeShortcut()) { $result = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']); } return $result; @@ -267,7 +282,7 @@ class RecyclerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass $markers = array( 'FUNC_MENU' => $this->getFunctionMenu(), 'CONTENT' => $this->content, - 'TITLE' => $GLOBALS['LANG']->getLL('title') + 'TITLE' => $this->languageService->getLL('title') ); return $markers; } @@ -284,12 +299,12 @@ class RecyclerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass /** * Gets data from the session of the current backend user. * - * @param string $identifier: The identifier to be used to get the data - * @param string $default: The default date to be used if nothing was found in the session + * @param string $identifier The identifier to be used to get the data + * @param string $default The default date to be used if nothing was found in the session * @return string The accordant data in the session of the current backend user */ protected function getDataFromSession($identifier, $default = NULL) { - $sessionData = &$GLOBALS['BE_USER']->uc['tx_recycler']; + $sessionData = &$this->backendUser->uc['tx_recycler']; if (isset($sessionData[$identifier]) && $sessionData[$identifier]) { $data = $sessionData[$identifier]; } else { @@ -297,5 +312,4 @@ class RecyclerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass } return $data; } - } \ No newline at end of file diff --git a/typo3/sysext/recycler/Classes/Domain/Model/DeletedRecords.php b/typo3/sysext/recycler/Classes/Domain/Model/DeletedRecords.php index 806165708a79d06387b18122392823cb32baae18..4a3ba104bdf5bc65d3943df727baa9d0f10278a6 100644 --- a/typo3/sysext/recycler/Classes/Domain/Model/DeletedRecords.php +++ b/typo3/sysext/recycler/Classes/Domain/Model/DeletedRecords.php @@ -14,6 +14,9 @@ namespace TYPO3\CMS\Recycler\Domain\Model; * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Recycler\Utility\RecyclerUtility; + /** * Model class for the 'recycler' extension. * @@ -45,7 +48,7 @@ class DeletedRecords { /** * Object from helper class * - * @var \TYPO3\CMS\Recycler\Utility\RecyclerUtility + * @var RecyclerUtility */ protected $recyclerHelper; @@ -63,6 +66,20 @@ class DeletedRecords { */ public $title; + /** + * Database Connection + * + * @var \TYPO3\CMS\Core\Database\DatabaseConnection + */ + protected $databaseConnection; + + /** + * Constructor + */ + public function __construct() { + $this->databaseConnection = $GLOBALS['TYPO3_DB']; + } + /************************************************************ * GET DATA FUNCTIONS * @@ -72,12 +89,12 @@ class DeletedRecords { * Load all deleted rows from $table * If table is not set, it iterates the TCA tables * - * @param int $id: UID from selected page - * @param string $table: Tablename - * @param int $depth: How many levels recursive - * @param int $limit: MySQL LIMIT - * @param string $filter: Filter text - * @return recycler_model_delRecords + * @param int $id UID from selected page + * @param string $table Tablename + * @param int $depth How many levels recursive + * @param string $limit MySQL LIMIT + * @param string $filter Filter text + * @return DeletedRecords */ public function loadData($id, $table, $depth, $limit = '', $filter = '') { // set the limit @@ -91,7 +108,7 @@ class DeletedRecords { foreach ($GLOBALS['TCA'] as $tableKey => $tableValue) { // only go into this table if the limit allows it if ($this->limit != '') { - $parts = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->limit); + $parts = GeneralUtility::trimExplode(',', $this->limit); // abort loop if LIMIT 0,0 if ($parts[0] == 0 && $parts[1] == 0) { break; @@ -107,11 +124,11 @@ class DeletedRecords { /** * Find the total count of deleted records * - * @param int $id: UID from record - * @param string $table: Tablename from record - * @param int $depth: How many levels recursive - * @param string $filter: Filter text - * @return void + * @param int $id UID from record + * @param string $table Tablename from record + * @param int $depth How many levels recursive + * @param string $filter Filter text + * @return int */ public function getTotalCount($id, $table, $depth, $filter) { $deletedRecords = $this->loadData($id, $table, $depth, '', $filter)->getDeletedRows(); @@ -125,28 +142,30 @@ class DeletedRecords { /** * Set all deleted rows * - * @param int $id: UID from record - * @param string $table: Tablename from record - * @param int $depth: How many levels recursive - * @param array $ctrl: TCA CTRL Array - * @param string $filter: Filter text + * @param int $id UID from record + * @param string $table Tablename from record + * @param int $depth How many levels recursive + * @param array $tcaCtrl TCA CTRL array + * @param string $filter Filter text * @return void */ protected function setData($id = 0, $table, $depth, $tcaCtrl, $filter) { $id = (int)$id; if (array_key_exists('delete', $tcaCtrl)) { // find the 'deleted' field for this table - $deletedField = \TYPO3\CMS\Recycler\Utility\RecyclerUtility::getDeletedField($table); + $deletedField = RecyclerUtility::getDeletedField($table); // create the filter WHERE-clause + $filterWhere = ''; if (trim($filter) != '') { $filterWhere = ' AND (' . (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($filter) ? 'uid = ' . $filter . ' OR pid = ' . $filter . ' OR ' : '') . $tcaCtrl['label'] . ' LIKE "%' . $this->escapeValueForLike($filter, $table) . '%"' . ')'; } + // get the limit if ($this->limit != '') { // count the number of deleted records for this pid - $deletedCount = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('uid', $table, $deletedField . '<>0 AND pid = ' . $id . $filterWhere); + $deletedCount = $this->databaseConnection->exec_SELECTcountRows('uid', $table, $deletedField . '<>0 AND pid = ' . $id . $filterWhere); // split the limit - $parts = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->limit); + $parts = GeneralUtility::trimExplode(',', $this->limit); $offset = $parts[0]; $rowCount = $parts[1]; // subtract the number of deleted records from the limit's offset @@ -216,20 +235,20 @@ class DeletedRecords { // go into depth if ($allowDepth && $depth >= 1) { // check recursively for elements beneath this page - $resPages = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'pid=' . $id, '', 'sorting'); + $resPages = $this->databaseConnection->exec_SELECTquery('uid', 'pages', 'pid=' . $id, '', 'sorting'); if ($resPages) { - while ($rowPages = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resPages)) { + while ($rowPages = $this->databaseConnection->sql_fetch_assoc($resPages)) { $this->setData($rowPages['uid'], $table, $depth - 1, $tcaCtrl, $filter); // some records might have been added, check if we still have the limit for further queries if ('' != $this->limit) { - $parts = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->limit); + $parts = GeneralUtility::trimExplode(',', $this->limit); // abort loop if LIMIT 0,0 if ($parts[0] == 0 && $parts[1] == 0) { break; } } } - $GLOBALS['TYPO3_DB']->sql_free_result($resPages); + $this->databaseConnection->sql_free_result($resPages); } } $this->label[$table] = $tcaCtrl['label']; @@ -240,13 +259,13 @@ class DeletedRecords { /** * Checks whether the current backend user has access to the given records. * - * @param string $table: Name of the table - * @param array $rows: Record row + * @param string $table Name of the table + * @param array $rows Record row * @return void */ protected function checkRecordAccess($table, array $rows) { foreach ($rows as $key => $row) { - if (\TYPO3\CMS\Recycler\Utility\RecyclerUtility::checkAccess($table, $row)) { + if (RecyclerUtility::checkAccess($table, $row)) { $this->setDeletedRows($table, $row); } } @@ -256,12 +275,12 @@ class DeletedRecords { * Escapes a value to be used for like in a database query. * There is a special handling for the characters '%' and '_'. * - * @param string $value: The value to be escaped for like conditions - * @param string $tableName: The name of the table the query should be used for + * @param string $value The value to be escaped for like conditions + * @param string $tableName The name of the table the query should be used for * @return string The escaped value to be used for like conditions */ protected function escapeValueForLike($value, $tableName) { - return $GLOBALS['TYPO3_DB']->escapeStrForLike($GLOBALS['TYPO3_DB']->quoteStr($value, $tableName), $tableName); + return $this->databaseConnection->escapeStrForLike($this->databaseConnection->quoteStr($value, $tableName), $tableName); } /************************************************************ @@ -270,13 +289,13 @@ class DeletedRecords { /** * Delete element from any table * - * @param string $recordArray: Representation of the records - * @return void + * @param array $recordsArray Representation of the records + * @return bool */ public function deleteData($recordsArray) { $recordsArray = json_decode($recordsArray); if (is_array($recordsArray)) { - $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler'); + $tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler'); $tce->start('', ''); $tce->disableDeleteClause(); foreach ($recordsArray as $key => $record) { @@ -294,8 +313,8 @@ class DeletedRecords { * Undelete records * If $recursive is TRUE all records below the page uid would be undelete too * - * @param string $recordArray: Representation of the records - * @param bool $recursive: TRUE/FALSE + * @param array $recordsArray Representation of the records + * @param bool $recursive Whether to recursively undelete * @return bool */ public function undeleteData($recordsArray, $recursive = FALSE) { @@ -320,7 +339,7 @@ class DeletedRecords { } } if ($cmd) { - $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler'); + $tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler'); $tce->start(array(), $cmd); $tce->process_cmdmap(); $result = TRUE; @@ -335,8 +354,8 @@ class DeletedRecords { /** * Set deleted rows * - * @param string $table: Tablename - * @param array $row: Deleted record row + * @param string $table Tablename + * @param array $row Deleted record row * @return void */ public function setDeletedRows($table, array $row) { @@ -349,7 +368,7 @@ class DeletedRecords { /** * Get deleted Rows * - * @return array $this->deletedRows: Array with all deleted rows from TCA + * @return array Array with all deleted rows from TCA */ public function getDeletedRows() { return $this->deletedRows; @@ -358,10 +377,9 @@ class DeletedRecords { /** * Get table * - * @return array $this->table: Array with table from TCA + * @return array Array with table from TCA */ public function getTable() { return $this->table; } - } diff --git a/typo3/sysext/recycler/Classes/Domain/Model/Tables.php b/typo3/sysext/recycler/Classes/Domain/Model/Tables.php index 0674d0ae200ff1f40c16b027d640b32b9b5c54ad..566c5e7a63a7b855a2abdd86b50f7aa7225cd8a1 100644 --- a/typo3/sysext/recycler/Classes/Domain/Model/Tables.php +++ b/typo3/sysext/recycler/Classes/Domain/Model/Tables.php @@ -14,6 +14,8 @@ namespace TYPO3\CMS\Recycler\Domain\Model; * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Recycler\Utility\RecyclerUtility; + /** * Model class for the 'recycler' extension. * @@ -21,24 +23,45 @@ namespace TYPO3\CMS\Recycler\Domain\Model; */ class Tables { + /** + * @var \TYPO3\CMS\Lang\LanguageService + */ + protected $languageService; + + /** + * Database Connection + * + * @var \TYPO3\CMS\Core\Database\DatabaseConnection + */ + protected $databaseConnection; + + /** + * Constructor + */ + public function __construct() { + $this->languageService = $GLOBALS['LANG']; + $this->databaseConnection = $GLOBALS['TYPO3_DB']; + } + /** * Get tables for menu example * - * @param string $format: Return format (example: json) - * @param bool $withAllOption: 0 no, 1 return tables with a "all" option - * @param int $id: UID from selected page - * @param int $depth: How many levels recursive + * @param string $format Return format (example: json) - currently unused + * @param bool $withAllOption FALSE: no, TRUE: return tables with a "all" option + * @param int $startUid UID from selected page + * @param int $depth How many levels recursive * @return string The tables to be displayed */ - public function getTables($format, $withAllOption = 0, $startUid, $depth = 0) { + public function getTables($format, $withAllOption = TRUE, $startUid, $depth = 0) { $deletedRecordsTotal = 0; $tables = array(); foreach (array_keys($GLOBALS['TCA']) as $tableName) { - $deletedField = \TYPO3\CMS\Recycler\Utility\RecyclerUtility::getDeletedField($tableName); + $deletedField = RecyclerUtility::getDeletedField($tableName); if ($deletedField) { // Determine whether the table has deleted records: - $deletedCount = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('uid', $tableName, $deletedField . '<>0'); + $deletedCount = $this->databaseConnection->exec_SELECTcountRows('uid', $tableName, $deletedField . '<>0'); if ($deletedCount) { + /* @var $deletedDataObject \TYPO3\CMS\Recycler\Domain\Model\DeletedRecords */ $deletedDataObject = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Recycler\\Domain\\Model\\DeletedRecords'); $deletedData = $deletedDataObject->loadData($startUid, $tableName, $depth)->getDeletedRows(); if (isset($deletedData[$tableName])) { @@ -48,7 +71,7 @@ class Tables { $tableName, $deletedRecordsInTable, $tableName, - \TYPO3\CMS\Recycler\Utility\RecyclerUtility::getUtf8String($GLOBALS['LANG']->sL($GLOBALS['TCA'][$tableName]['ctrl']['title'])) + RecyclerUtility::getUtf8String($this->languageService->sL($GLOBALS['TCA'][$tableName]['ctrl']['title'])) ); } } @@ -61,11 +84,10 @@ class Tables { '', $deletedRecordsTotal, '', - $GLOBALS['LANG']->sL('LLL:EXT:recycler/mod1/locallang.xlf:label_alltables') + $this->languageService->sL('LLL:EXT:recycler/mod1/locallang.xlf:label_alltables') )); } $output = json_encode($jsonArray); return $output; } - } diff --git a/typo3/sysext/recycler/Classes/Utility/RecyclerUtility.php b/typo3/sysext/recycler/Classes/Utility/RecyclerUtility.php index a884af56a5bf63995d11b652e7d1d55f78f8e584..9c3d73ef2aac616d4b46256eaf755cad35fd3208 100644 --- a/typo3/sysext/recycler/Classes/Utility/RecyclerUtility.php +++ b/typo3/sysext/recycler/Classes/Utility/RecyclerUtility.php @@ -15,6 +15,7 @@ namespace TYPO3\CMS\Recycler\Utility; */ use TYPO3\CMS\Backend\Utility\BackendUtility; +use TYPO3\CMS\Core\Utility\GeneralUtility; /** * Helper class for the 'recycler' extension. @@ -37,30 +38,33 @@ class RecyclerUtility { * @return bool Returns TRUE is the user has access, or FALSE if not */ static public function checkAccess($table, $row) { + /* @var $backendUser \TYPO3\CMS\Core\Authentication\BackendUserAuthentication */ + $backendUser = $GLOBALS['BE_USER']; + // Checking if the user has permissions? (Only working as a precaution, because the final permission check is always down in TCE. But it's good to notify the user on beforehand...) // First, resetting flags. - $hasAccess = 0; + $hasAccess = FALSE; $calcPRec = $row; BackendUtility::fixVersioningPid($table, $calcPRec); if (is_array($calcPRec)) { if ($table == 'pages') { // If pages: - $CALC_PERMS = $GLOBALS['BE_USER']->calcPerms($calcPRec); - $hasAccess = $CALC_PERMS & 2 ? 1 : 0; + $calculatedPermissions = $backendUser->calcPerms($calcPRec); + $hasAccess = $calculatedPermissions & 2 ? TRUE : FALSE; } else { - $CALC_PERMS = $GLOBALS['BE_USER']->calcPerms(BackendUtility::getRecord('pages', $calcPRec['pid'])); + $calculatedPermissions = $backendUser->calcPerms(BackendUtility::getRecord('pages', $calcPRec['pid'])); // Fetching pid-record first. - $hasAccess = $CALC_PERMS & 16 ? 1 : 0; + $hasAccess = $calculatedPermissions & 16 ? TRUE : FALSE; } // Check internals regarding access: if ($hasAccess) { - $hasAccess = $GLOBALS['BE_USER']->recordEditAccessInternals($table, $calcPRec); + $hasAccess = $backendUser->recordEditAccessInternals($table, $calcPRec); } } - if (!$GLOBALS['BE_USER']->check('tables_modify', $table)) { - $hasAccess = 0; + if (!$backendUser->check('tables_modify', $table)) { + $hasAccess = FALSE; } - return $hasAccess ? TRUE : FALSE; + return $hasAccess; } /** @@ -68,31 +72,34 @@ class RecyclerUtility { * Each part of the path will be limited to $titleLimit characters * Deleted pages are filtered out. * - * @param int Page uid for which to create record path + * @param int $uid Page uid for which to create record path * @param string $clause is additional where clauses, eg. - * @param int Title limit - * @param int Title limit of Full title (typ. set to 1000 or so) + * @param int $titleLimit Title limit + * @param int $fullTitleLimit Title limit of Full title (typ. set to 1000 or so) * @return mixed Path of record (string) OR array with short/long title if $fullTitleLimit is set. */ static public function getRecordPath($uid, $clause = '', $titleLimit = 1000, $fullTitleLimit = 0) { + /* @var $databaseConnection \TYPO3\CMS\Core\Database\DatabaseConnection */ + $databaseConnection = $GLOBALS['TYPO3_DB']; + $loopCheck = 100; $output = ($fullOutput = '/'); while ($uid != 0 && $loopCheck > 0) { $loopCheck--; - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,pid,title,deleted,t3ver_oid,t3ver_wsid', 'pages', 'uid=' . (int)$uid . (strlen(trim($clause)) ? ' AND ' . $clause : '')); + $res = $databaseConnection->exec_SELECTquery('uid,pid,title,deleted,t3ver_oid,t3ver_wsid', 'pages', 'uid=' . (int)$uid . (strlen(trim($clause)) ? ' AND ' . $clause : '')); if (is_resource($res)) { - $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); - $GLOBALS['TYPO3_DB']->sql_free_result($res); + $row = $databaseConnection->sql_fetch_assoc($res); + $databaseConnection->sql_free_result($res); BackendUtility::workspaceOL('pages', $row); if (is_array($row)) { BackendUtility::fixVersioningPid('pages', $row); $uid = $row['pid']; - $output = '/' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($row['title'], $titleLimit)) . $output; + $output = '/' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($row['title'], $titleLimit)) . $output; if ($row['deleted']) { $output = '<span class="deletedPath">' . $output . '</span>'; } if ($fullTitleLimit) { - $fullOutput = '/' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($row['title'], $fullTitleLimit)) . $fullOutput; + $fullOutput = '/' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($row['title'], $fullTitleLimit)) . $fullOutput; } } else { break; @@ -111,7 +118,7 @@ class RecyclerUtility { /** * Gets the name of the field with the information whether a record is deleted. * - * @param string $tableName: Name of the table to get the deleted field for + * @param string $tableName Name of the table to get the deleted field for * @return string Name of the field with the information whether a record is deleted */ static public function getDeletedField($tableName) { @@ -119,13 +126,14 @@ class RecyclerUtility { if ($TCA && isset($TCA['ctrl']['delete']) && $TCA['ctrl']['delete']) { return $TCA['ctrl']['delete']; } + return ''; } /** * Gets the TCA of the table used in the current context. * - * @param string $tableName: Name of the table to get TCA for - * @return mixed TCA of the table used in the current context (array) + * @param string $tableName Name of the table to get TCA for + * @return array|FALSE TCA of the table used in the current context */ static public function getTableTCA($tableName) { $TCA = FALSE; @@ -156,7 +164,7 @@ class RecyclerUtility { /** * Gets an UTF-8 encoded string (only if the current charset is not UTF-8!). * - * @param string $string: String to be converted to UTF-8 if required + * @param string $string String to be converted to UTF-8 if required * @return string UTF-8 encoded string */ static public function getUtf8String($string) {