[TASK] Respect editlock of pages in inline editing
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Tree / Pagetree / PagetreeNode.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tree\Pagetree;
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\Core\Versioning\VersionState;
18
19 /**
20 * Node designated for the page tree
21 */
22 class PagetreeNode extends \TYPO3\CMS\Backend\Tree\ExtDirectNode {
23
24 /**
25 * Cached access rights to save some performance
26 *
27 * @var array
28 */
29 protected $cachedAccessRights = array();
30
31 /**
32 * Workspace Overlay Id
33 *
34 * @var int
35 */
36 protected $workspaceId = 0;
37
38 /**
39 * Mount Point Id
40 *
41 * @var int
42 */
43 protected $mountPoint = 0;
44
45 /**
46 * Readable Rootline
47 *
48 * @var string
49 */
50 protected $readableRootline = '';
51
52 /**
53 * Indicator if the node is a mount point
54 *
55 * @var bool
56 */
57 protected $isMountPoint = FALSE;
58
59 /**
60 * Background color for the node
61 *
62 * @var string
63 */
64 protected $backgroundColor = '';
65
66 /**
67 * Sets the background color
68 *
69 * @param string $backgroundColor
70 * @return void
71 */
72 public function setBackgroundColor($backgroundColor) {
73 $this->backgroundColor = $backgroundColor;
74 }
75
76 /**
77 * Returns the background color
78 *
79 * @return string
80 */
81 public function getBackgroundColor() {
82 return $this->backgroundColor;
83 }
84
85 /**
86 * Set's the original id of the element
87 *
88 * @param int $workspaceId
89 * @return void
90 */
91 public function setWorkspaceId($workspaceId) {
92 $this->workspaceId = (int)$workspaceId;
93 }
94
95 /**
96 * Returns the original id of the element
97 *
98 * @return int
99 */
100 public function getWorkspaceId() {
101 return $this->workspaceId;
102 }
103
104 /**
105 * Sets the mount point id
106 *
107 * @param int $mountPoint
108 * @return void
109 */
110 public function setMountPoint($mountPoint) {
111 $this->mountPoint = (int)$mountPoint;
112 }
113
114 /**
115 * Returns the mount point id
116 *
117 * @return int
118 */
119 public function getMountPoint() {
120 return $this->mountPoint;
121 }
122
123 /**
124 * Sets the indicator if the node is a mount point
125 *
126 * @param bool $isMountPoint
127 * @return void
128 */
129 public function setIsMountPoint($isMountPoint) {
130 $this->isMountPoint = $isMountPoint == TRUE;
131 }
132
133 /**
134 * Returns TRUE if the node is a mount point
135 *
136 * @return bool
137 */
138 public function isMountPoint() {
139 return $this->isMountPoint;
140 }
141
142 /**
143 * Sets the readable rootline
144 *
145 * @param string $rootline
146 * @return void
147 */
148 public function setReadableRootline($rootline) {
149 $this->readableRootline = $rootline;
150 }
151
152 /**
153 * Returns the readable rootline
154 *
155 * @return string
156 */
157 public function getReadableRootline() {
158 return $this->readableRootline;
159 }
160
161 /**
162 * Checks if the user may create pages below the given page
163 *
164 * @return bool
165 */
166 protected function canCreate() {
167 if (!isset($this->cachedAccessRights['create'])) {
168 $this->cachedAccessRights['create'] = $GLOBALS['BE_USER']->doesUserHaveAccess($this->record, 8);
169 }
170 return $this->cachedAccessRights['create'];
171 }
172
173 /**
174 * Checks if the user has editing rights
175 *
176 * @return bool
177 */
178 protected function canEdit() {
179 if (!isset($this->cachedAccessRights['edit'])) {
180 $this->cachedAccessRights['edit'] =
181 $GLOBALS['BE_USER']->isAdmin()
182 || (
183 (int)$this->record['editlock'] === 0
184 && $GLOBALS['BE_USER']->doesUserHaveAccess($this->record, 2)
185 );
186 }
187 return $this->cachedAccessRights['edit'];
188 }
189
190 /**
191 * Checks if the user has the right to delete the page
192 *
193 * @return bool
194 */
195 protected function canRemove() {
196 if (!isset($this->cachedAccessRights['remove'])) {
197 $this->cachedAccessRights['remove'] =
198 $GLOBALS['BE_USER']->isAdmin()
199 || (
200 (int)$this->record['editlock'] === 0
201 && $GLOBALS['BE_USER']->doesUserHaveAccess($this->record, 4)
202 );
203 if (!$this->isLeafNode() && !$GLOBALS['BE_USER']->uc['recursiveDelete']) {
204 $this->cachedAccessRights['remove'] = FALSE;
205 }
206 }
207 return $this->cachedAccessRights['remove'];
208 }
209
210 /**
211 * Checks if the page can be disabled
212 *
213 * @return bool
214 */
215 public function canBeDisabledAndEnabled() {
216 return $this->canEdit($this->record) && $GLOBALS['BE_USER']->checkLanguageAccess(0);
217 }
218
219 /**
220 * Checks if the page is allowed to can be cut
221 *
222 * @return bool
223 */
224 public function canBeCut() {
225 return (
226 $this->canEdit($this->record)
227 && !VersionState::cast($this->record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
228 && $GLOBALS['BE_USER']->checkLanguageAccess(0)
229 );
230 }
231
232 /**
233 * Checks if the page is allowed to be edited
234 *
235 * @return bool
236 */
237 public function canBeEdited() {
238 return $this->canEdit($this->record) && $GLOBALS['BE_USER']->checkLanguageAccess(0);
239 }
240
241 /**
242 * Checks if the page is allowed to be copied
243 *
244 * @return bool
245 */
246 public function canBeCopied() {
247 return (
248 $this->canCreate($this->record)
249 && !VersionState::cast($this->record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
250 && $GLOBALS['BE_USER']->checkLanguageAccess(0)
251 );
252 }
253
254 /**
255 * Checks if there can be new pages created
256 *
257 * @return bool
258 */
259 public function canCreateNewPages() {
260 return $this->canCreate($this->record) && $GLOBALS['BE_USER']->checkLanguageAccess(0);
261 }
262
263 /**
264 * Checks if the page is allowed to be removed
265 *
266 * @return bool
267 */
268 public function canBeRemoved() {
269 return (
270 $this->canRemove($this->record)
271 && !VersionState::cast($this->record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
272 && $GLOBALS['BE_USER']->checkLanguageAccess(0)
273 );
274 }
275
276 /**
277 * Checks if something can be pasted into the node
278 *
279 * @return bool
280 */
281 public function canBePastedInto() {
282 return (
283 $this->canCreate($this->record)
284 && !VersionState::cast($this->record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
285 && $GLOBALS['BE_USER']->checkLanguageAccess(0)
286 );
287 }
288
289 /**
290 * Checks if something can be pasted after the node
291 *
292 * @return bool
293 */
294 public function canBePastedAfter() {
295 return (
296 $this->canCreate($this->record)
297 && !VersionState::cast($this->record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
298 && $GLOBALS['BE_USER']->checkLanguageAccess(0)
299 );
300 }
301
302 /**
303 * Checks if the page is allowed to show history
304 *
305 * @return bool
306 */
307 public function canShowHistory() {
308 return $GLOBALS['BE_USER']->checkLanguageAccess(0);
309 }
310
311 /**
312 * Checks if the page is allowed to be viewed
313 *
314 * @return bool
315 */
316 public function canBeViewed() {
317 return !$this->isDeleted();
318 }
319
320 /**
321 * Checks if the page is allowed to show info
322 *
323 * @return bool
324 */
325 public function canShowInfo() {
326 return TRUE;
327 }
328
329 /**
330 * Checks if the page is allowed to be a temporary mount point
331 *
332 * @return bool
333 */
334 public function canBeTemporaryMountPoint() {
335 return TRUE;
336 }
337
338 /**
339 * Determines whether this node is deleted.
340 *
341 * @return bool
342 */
343 public function isDeleted() {
344 return (
345 !empty($this->record['deleted'])
346 || VersionState::cast($this->record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
347 );
348 }
349
350 /**
351 * Returns the calculated id representation of this node
352 *
353 * @param string $prefix Defaults to 'p'
354 * @return string
355 */
356 public function calculateNodeId($prefix = 'p') {
357 return $prefix . dechex($this->getId()) . ($this->getMountPoint() ? '-' . dechex($this->getMountPoint()) : '');
358 }
359
360 /**
361 * Returns the node in an array representation that can be used for serialization
362 *
363 * @param bool $addChildNodes
364 * @return array
365 */
366 public function toArray($addChildNodes = TRUE) {
367 $arrayRepresentation = parent::toArray();
368 $arrayRepresentation['id'] = $this->calculateNodeId();
369 $arrayRepresentation['realId'] = $this->getId();
370 $arrayRepresentation['nodeData']['id'] = $this->getId();
371 $arrayRepresentation['readableRootline'] = $this->getReadableRootline();
372 $arrayRepresentation['nodeData']['readableRootline'] = $this->getReadableRootline();
373 $arrayRepresentation['nodeData']['mountPoint'] = $this->getMountPoint();
374 $arrayRepresentation['nodeData']['workspaceId'] = $this->getWorkspaceId();
375 $arrayRepresentation['nodeData']['isMountPoint'] = $this->isMountPoint();
376 $arrayRepresentation['nodeData']['backgroundColor'] = htmlspecialchars($this->getBackgroundColor());
377 $arrayRepresentation['nodeData']['serializeClassName'] = get_class($this);
378 return $arrayRepresentation;
379 }
380
381 /**
382 * Sets data of the node by a given data array
383 *
384 * @param array $data
385 * @return void
386 */
387 public function dataFromArray($data) {
388 parent::dataFromArray($data);
389 $this->setWorkspaceId($data['workspaceId']);
390 $this->setMountPoint($data['mountPoint']);
391 $this->setReadableRootline($data['readableRootline']);
392 $this->setIsMountPoint($data['isMountPoint']);
393 $this->setBackgroundColor($data['backgroundColor']);
394 }
395
396 }