[!!!][TASK] Remove utf8 conversion in EXT:recycler
[Packages/TYPO3.CMS.git] / typo3 / sysext / recycler / Classes / Controller / DeletedRecordsController.php
1 <?php
2 namespace TYPO3\CMS\Recycler\Controller;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\DataHandling\DataHandler;
19 use TYPO3\CMS\Core\Imaging\Icon;
20 use TYPO3\CMS\Core\Imaging\IconFactory;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\CMS\Recycler\Utility\RecyclerUtility;
23
24 /**
25 * Deleted Records View
26 */
27 class DeletedRecordsController
28 {
29 /**
30 * @var \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
31 */
32 protected $runtimeCache = null;
33
34 /**
35 * @var DataHandler
36 */
37 protected $tce;
38
39 public function __construct()
40 {
41 $this->runtimeCache = $this->getMemoryCache();
42 $this->tce = GeneralUtility::makeInstance(DataHandler::class);
43 }
44
45 /**
46 * Transforms the rows for the deleted records
47 *
48 * @param array $deletedRowsArray Array with table as key and array with all deleted rows
49 * @param int $totalDeleted Number of deleted records in total
50 * @return string JSON array
51 */
52 public function transform($deletedRowsArray, $totalDeleted)
53 {
54 $total = 0;
55 $jsonArray = array(
56 'rows' => array()
57 );
58
59 if (is_array($deletedRowsArray)) {
60 $lang = $this->getLanguageService();
61 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
62
63 foreach ($deletedRowsArray as $table => $rows) {
64 $total += count($deletedRowsArray[$table]);
65 foreach ($rows as $row) {
66 $pageTitle = $this->getPageTitle((int)$row['pid']);
67 $backendUser = BackendUtility::getRecord('be_users', $row[$GLOBALS['TCA'][$table]['ctrl']['cruser_id']], 'username', '', false);
68 $jsonArray['rows'][] = array(
69 'uid' => $row['uid'],
70 'pid' => $row['pid'],
71 'icon' => $iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render(),
72 'pageTitle' => $pageTitle,
73 'table' => $table,
74 'crdate' => BackendUtility::datetime($row[$GLOBALS['TCA'][$table]['ctrl']['crdate']]),
75 'tstamp' => BackendUtility::datetime($row[$GLOBALS['TCA'][$table]['ctrl']['tstamp']]),
76 'owner' => htmlspecialchars($backendUser['username']),
77 'owner_uid' => $row[$GLOBALS['TCA'][$table]['ctrl']['cruser_id']],
78 'tableTitle' => $lang->sL($GLOBALS['TCA'][$table]['ctrl']['title']),
79 'title' => htmlspecialchars(BackendUtility::getRecordTitle($table, $row)),
80 'path' => RecyclerUtility::getRecordPath($row['pid'])
81 );
82 }
83 }
84 }
85 $jsonArray['total'] = $totalDeleted;
86 return $jsonArray;
87 }
88
89 /**
90 * Gets the page title of the given page id
91 *
92 * @param int $pageId
93 * @return string
94 */
95 protected function getPageTitle($pageId)
96 {
97 $cacheId = 'recycler-pagetitle-' . $pageId;
98 if ($this->runtimeCache->has($cacheId)) {
99 $pageTitle = $this->runtimeCache->get($cacheId);
100 } else {
101 if ($pageId === 0) {
102 $pageTitle = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
103 } else {
104 $recordInfo = $this->tce->recordInfo('pages', $pageId, 'title');
105 $pageTitle = $recordInfo['title'];
106 }
107 $this->runtimeCache->set($cacheId, $pageTitle);
108 }
109 return $pageTitle;
110 }
111
112 /**
113 * Returns an instance of LanguageService
114 *
115 * @return \TYPO3\CMS\Lang\LanguageService
116 */
117 protected function getLanguageService()
118 {
119 return $GLOBALS['LANG'];
120 }
121
122 /**
123 * Create and returns an instance of the CacheManager
124 *
125 * @return \TYPO3\CMS\Core\Cache\CacheManager
126 */
127 protected function getCacheManager()
128 {
129 return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class);
130 }
131
132 /**
133 * Gets an instance of the memory cache.
134 *
135 * @return \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
136 */
137 protected function getMemoryCache()
138 {
139 return $this->getCacheManager()->getCache('cache_runtime');
140 }
141 }