[TASK] Re-work/simplify copyright header in PHP files - Part 8
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / ExtDirect / ExtDirectServer.php
1 <?php
2 namespace TYPO3\CMS\Workspaces\ExtDirect;
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
19 /**
20 * ExtDirect server
21 *
22 * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
23 */
24 class ExtDirectServer extends \TYPO3\CMS\Workspaces\ExtDirect\AbstractHandler {
25
26 /**
27 * @var \TYPO3\CMS\Workspaces\Service\GridDataService
28 */
29 protected $gridDataService;
30
31 /**
32 * @var \TYPO3\CMS\Workspaces\Service\StagesService
33 */
34 protected $stagesService;
35
36 /**
37 * Checks integrity of elements before peforming actions on them.
38 *
39 * @param stdClass $parameters
40 * @return array
41 */
42 public function checkIntegrity(\stdClass $parameters) {
43 $integrity = $this->createIntegrityService($this->getAffectedElements($parameters));
44 $integrity->check();
45 $response = array(
46 'result' => $integrity->getStatusRepresentation()
47 );
48 return $response;
49 }
50
51 /**
52 * Get List of workspace changes
53 *
54 * @param object $parameter
55 * @return array $data
56 */
57 public function getWorkspaceInfos($parameter) {
58 // To avoid too much work we use -1 to indicate that every page is relevant
59 $pageId = $parameter->id > 0 ? $parameter->id : -1;
60 if (!isset($parameter->language) || !\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($parameter->language)) {
61 $parameter->language = NULL;
62 }
63 $versions = $this->getWorkspaceService()->selectVersionsInWorkspace($this->getCurrentWorkspace(), 0, -99, $pageId, $parameter->depth, 'tables_select', $parameter->language);
64 $data = $this->getGridDataService()->generateGridListFromVersions($versions, $parameter, $this->getCurrentWorkspace());
65 return $data;
66 }
67
68 /**
69 * Gets the editing history of a record.
70 *
71 * @param stdClass $parameters
72 * @return array
73 */
74 public function getHistory($parameters) {
75 /** @var $historyService \TYPO3\CMS\Workspaces\Service\HistoryService */
76 $historyService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\HistoryService');
77 $history = $historyService->getHistory($parameters->table, $parameters->liveId);
78 return array(
79 'data' => $history,
80 'total' => count($history)
81 );
82 }
83
84 /**
85 * Get List of available workspace actions
86 *
87 * @param object $parameter
88 * @return array $data
89 */
90 public function getStageActions($parameter) {
91 $currentWorkspace = $this->getCurrentWorkspace();
92 $stages = array();
93 if ($currentWorkspace != \TYPO3\CMS\Workspaces\Service\WorkspaceService::SELECT_ALL_WORKSPACES) {
94 $stages = $this->getStagesService()->getStagesForWSUser();
95 }
96 $data = array(
97 'total' => count($stages),
98 'data' => $stages
99 );
100 return $data;
101 }
102
103 /**
104 * Fetch futher information to current selected worspace record.
105 *
106 * @param object $parameter
107 * @return array $data
108 */
109 public function getRowDetails($parameter) {
110 $diffReturnArray = array();
111 $liveReturnArray = array();
112 /** @var $t3lib_diff \TYPO3\CMS\Core\Utility\DiffUtility */
113 $t3lib_diff = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\DiffUtility');
114 /** @var $parseObj \TYPO3\CMS\Core\Html\RteHtmlParser */
115 $parseObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Html\\RteHtmlParser');
116 $liveRecord = BackendUtility::getRecord($parameter->table, $parameter->t3ver_oid);
117 $versionRecord = BackendUtility::getRecord($parameter->table, $parameter->uid);
118 $icon_Live = \TYPO3\CMS\Backend\Utility\IconUtility::mapRecordTypeToSpriteIconClass($parameter->table, $liveRecord);
119 $icon_Workspace = \TYPO3\CMS\Backend\Utility\IconUtility::mapRecordTypeToSpriteIconClass($parameter->table, $versionRecord);
120 $stagePosition = $this->getStagesService()->getPositionOfCurrentStage($parameter->stage);
121 $fieldsOfRecords = array_keys($liveRecord);
122 if ($GLOBALS['TCA'][$parameter->table]) {
123 if ($GLOBALS['TCA'][$parameter->table]['interface']['showRecordFieldList']) {
124 $fieldsOfRecords = $GLOBALS['TCA'][$parameter->table]['interface']['showRecordFieldList'];
125 $fieldsOfRecords = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $fieldsOfRecords, TRUE);
126 }
127 }
128 foreach ($fieldsOfRecords as $fieldName) {
129 // check for exclude fields
130 if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['TCA'][$parameter->table]['columns'][$fieldName]['exclude'] == 0 || \TYPO3\CMS\Core\Utility\GeneralUtility::inList($GLOBALS['BE_USER']->groupData['non_exclude_fields'], $parameter->table . ':' . $fieldName)) {
131 // call diff class only if there is a difference
132 if ((string)$liveRecord[$fieldName] !== (string)$versionRecord[$fieldName]) {
133 // Select the human readable values before diff
134 $liveRecord[$fieldName] = BackendUtility::getProcessedValue(
135 $parameter->table,
136 $fieldName,
137 $liveRecord[$fieldName],
138 0,
139 1,
140 FALSE,
141 $liveRecord['uid']
142 );
143 $versionRecord[$fieldName] = BackendUtility::getProcessedValue(
144 $parameter->table,
145 $fieldName,
146 $versionRecord[$fieldName],
147 0,
148 1,
149 FALSE,
150 $versionRecord['uid']
151 );
152 // Get the field's label. If not available, use the field name
153 $fieldTitle = $GLOBALS['LANG']->sL(BackendUtility::getItemLabel($parameter->table, $fieldName));
154 if (empty($fieldTitle)) {
155 $fieldTitle = $fieldName;
156 }
157 if ($GLOBALS['TCA'][$parameter->table]['columns'][$fieldName]['config']['type'] == 'group' && $GLOBALS['TCA'][$parameter->table]['columns'][$fieldName]['config']['internal_type'] == 'file') {
158 $versionThumb = BackendUtility::thumbCode($versionRecord, $parameter->table, $fieldName, '');
159 $liveThumb = BackendUtility::thumbCode($liveRecord, $parameter->table, $fieldName, '');
160 $diffReturnArray[] = array(
161 'field' => $fieldName,
162 'label' => $fieldTitle,
163 'content' => $versionThumb
164 );
165 $liveReturnArray[] = array(
166 'field' => $fieldName,
167 'label' => $fieldTitle,
168 'content' => $liveThumb
169 );
170 } else {
171 $diffReturnArray[] = array(
172 'field' => $fieldName,
173 'label' => $fieldTitle,
174 'content' => $t3lib_diff->makeDiffDisplay($liveRecord[$fieldName], $versionRecord[$fieldName])
175 );
176 $liveReturnArray[] = array(
177 'field' => $fieldName,
178 'label' => $fieldTitle,
179 'content' => $parseObj->TS_images_rte($liveRecord[$fieldName])
180 );
181 }
182 }
183 }
184 }
185 // Hook for modifying the difference and live arrays
186 // (this may be used by custom or dynamically-defined fields)
187 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['workspaces']['modifyDifferenceArray'])) {
188 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['workspaces']['modifyDifferenceArray'] as $className) {
189 $hookObject =& \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($className);
190 $hookObject->modifyDifferenceArray($parameter, $diffReturnArray, $liveReturnArray, $t3lib_diff);
191 }
192 }
193 $commentsForRecord = $this->getCommentsForRecord($parameter->uid, $parameter->table);
194 return array(
195 'total' => 1,
196 'data' => array(
197 array(
198 'diff' => $diffReturnArray,
199 'live_record' => $liveReturnArray,
200 'path_Live' => $parameter->path_Live,
201 'label_Stage' => $parameter->label_Stage,
202 'stage_position' => $stagePosition['position'],
203 'stage_count' => $stagePosition['count'],
204 'comments' => $commentsForRecord,
205 'icon_Live' => $icon_Live,
206 'icon_Workspace' => $icon_Workspace
207 )
208 )
209 );
210 }
211
212 /**
213 * Gets an array with all sys_log entries and their comments for the given record uid and table
214 *
215 * @param integer $uid uid of changed element to search for in log
216 * @param string $table Name of the record's table
217 * @return array
218 */
219 public function getCommentsForRecord($uid, $table) {
220 $sysLogReturnArray = array();
221 $sysLogRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('log_data,tstamp,userid', 'sys_log', 'action=6 and details_nr=30
222 AND tablename=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($table, 'sys_log') . '
223 AND recuid=' . (int)$uid, '', 'tstamp DESC');
224 foreach ($sysLogRows as $sysLogRow) {
225 $sysLogEntry = array();
226 $data = unserialize($sysLogRow['log_data']);
227 $beUserRecord = BackendUtility::getRecord('be_users', $sysLogRow['userid']);
228 $sysLogEntry['stage_title'] = $this->getStagesService()->getStageTitle($data['stage']);
229 $sysLogEntry['user_uid'] = $sysLogRow['userid'];
230 $sysLogEntry['user_username'] = is_array($beUserRecord) ? $beUserRecord['username'] : '';
231 $sysLogEntry['tstamp'] = BackendUtility::datetime($sysLogRow['tstamp']);
232 $sysLogEntry['user_comment'] = $data['comment'];
233 $sysLogReturnArray[] = $sysLogEntry;
234 }
235 return $sysLogReturnArray;
236 }
237
238 /**
239 * Gets all available system languages.
240 *
241 * @return array
242 */
243 public function getSystemLanguages() {
244 $systemLanguages = array(
245 array(
246 'uid' => 'all',
247 'title' => \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('language.allLanguages', 'workspaces'),
248 'cls' => \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconClasses('empty-empty')
249 )
250 );
251 foreach ($this->getGridDataService()->getSystemLanguages() as $id => $systemLanguage) {
252 if ($id < 0) {
253 continue;
254 }
255 $systemLanguages[] = array(
256 'uid' => $id,
257 'title' => htmlspecialchars($systemLanguage['title']),
258 'cls' => \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconClasses($systemLanguage['flagIcon'])
259 );
260 }
261 $result = array(
262 'total' => count($systemLanguages),
263 'data' => $systemLanguages
264 );
265 return $result;
266 }
267
268 /**
269 * Gets the Grid Data Service.
270 *
271 * @return \TYPO3\CMS\Workspaces\Service\GridDataService
272 */
273 protected function getGridDataService() {
274 if (!isset($this->gridDataService)) {
275 $this->gridDataService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\GridDataService');
276 }
277 return $this->gridDataService;
278 }
279
280 /**
281 * Gets the Stages Service.
282 *
283 * @return \TYPO3\CMS\Workspaces\Service\StagesService
284 */
285 protected function getStagesService() {
286 if (!isset($this->stagesService)) {
287 $this->stagesService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Workspaces\\Service\\StagesService');
288 }
289 return $this->stagesService;
290 }
291
292 }