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