a3a33dac362ca8b8d76c4abedbb55fe3840f83cc
[Packages/TYPO3.CMS.git] / t3lib / tree / pagetree / extdirect / class.t3lib_tree_pagetree_extdirect_commands.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 TYPO3 Tree Team <http://forge.typo3.org/projects/typo3v4-extjstrees>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Commands for the Page tree
30 *
31 * @author Stefan Galinski <stefan.galinski@gmail.com>
32 * @package TYPO3
33 * @subpackage t3lib
34 */
35 class t3lib_tree_pagetree_extdirect_Commands {
36 /**
37 * Visibly the page
38 *
39 * @param stdClass $nodeData
40 * @return array
41 */
42 public function visiblyNode($nodeData) {
43 /** @var $node t3lib_tree_pagetree_Node */
44 $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
45
46 /** @var $dataProvider t3lib_tree_pagetree_DataProvider */
47 $dataProvider = t3lib_div::makeInstance('t3lib_tree_pagetree_DataProvider');
48
49 try {
50 t3lib_tree_pagetree_Commands::visiblyNode($node);
51 $newNode = t3lib_tree_pagetree_Commands::getNode($node->getId());
52 $newNode->setLeaf($node->isLeafNode());
53 $returnValue = $newNode->toArray();
54 } catch (Exception $exception) {
55 $returnValue = array(
56 'success' => FALSE,
57 'error' => $exception->getMessage(),
58 );
59 }
60
61 return $returnValue;
62 }
63
64 /**
65 * Hide the page
66 *
67 * @param stdClass $nodeData
68 * @return array
69 */
70 public function disableNode($nodeData) {
71 /** @var $node t3lib_tree_pagetree_Node */
72 $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
73
74 /** @var $dataProvider t3lib_tree_pagetree_DataProvider */
75 $dataProvider = t3lib_div::makeInstance('t3lib_tree_pagetree_DataProvider');
76
77 try {
78 t3lib_tree_pagetree_Commands::disableNode($node);
79 $newNode = t3lib_tree_pagetree_Commands::getNode($node->getId());
80 $newNode->setLeaf($node->isLeafNode());
81 $returnValue = $newNode->toArray();
82 } catch (Exception $exception) {
83 $returnValue = array(
84 'success' => FALSE,
85 'message' => $exception->getMessage(),
86 );
87 }
88
89 return $returnValue;
90 }
91
92 /**
93 * Delete the page
94 *
95 * @param stdClass $nodeData
96 * @return array
97 */
98 public function deleteNode($nodeData) {
99 /** @var $node t3lib_tree_pagetree_Node */
100 $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
101
102 try {
103 t3lib_tree_pagetree_Commands::deleteNode($node);
104
105 $returnValue = array();
106 if ($GLOBALS['BE_USER']->workspace) {
107 $record = t3lib_tree_pagetree_Commands::getNodeRecord($node->getId());
108 if ($record['_ORIG_uid']) {
109 $newNode = t3lib_tree_pagetree_Commands::getNewNode($record);
110 $returnValue = $newNode->toArray();
111 }
112 }
113 } catch (Exception $exception) {
114 $returnValue = array(
115 'success' => FALSE,
116 'message' => $exception->getMessage(),
117 );
118 }
119
120 return $returnValue;
121 }
122
123 /**
124 * Restore the page
125 *
126 * @param stdClass $nodeData
127 * @param int $destination
128 * @return array
129 */
130 public function restoreNode($nodeData, $destination) {
131 /** @var $node t3lib_tree_pagetree_Node */
132 $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
133
134 try {
135 t3lib_tree_pagetree_Commands::restoreNode($node, $destination);
136 $newNode = t3lib_tree_pagetree_Commands::getNode($node->getId());
137 $returnValue = $newNode->toArray();
138 } catch (Exception $exception) {
139 $returnValue = array(
140 'success' => FALSE,
141 'message' => $exception->getMessage(),
142 );
143 }
144
145 return $returnValue;
146 }
147
148 /**
149 * Updates the given field with a new text value, may be used to inline update
150 * the title field in the new page tree
151 *
152 * @param stdClass $nodeData
153 * @param string $updatedLabel
154 * @return array
155 */
156 public function updateLabel($nodeData, $updatedLabel) {
157 if ($updatedLabel === '') {
158 return array();
159 }
160
161 /** @var $node t3lib_tree_pagetree_Node */
162 $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
163
164 try {
165 t3lib_tree_pagetree_Commands::updateNodeLabel($node, $updatedLabel);
166
167 $shortendedText = t3lib_div::fixed_lgd_cs($updatedLabel, intval($GLOBALS['BE_USER']->uc['titleLen']));
168 $returnValue = array(
169 'editableText' => $updatedLabel,
170 'updatedText' => htmlspecialchars($shortendedText),
171 );
172 } catch (Exception $exception) {
173 $returnValue = array(
174 'success' => FALSE,
175 'message' => $exception->getMessage(),
176 );
177 }
178
179 return $returnValue;
180 }
181
182 /**
183 * Sets a temporary mount point
184 *
185 * @param stdClass $nodeData
186 * @return array
187 */
188 public static function setTemporaryMountPoint($nodeData) {
189 /** @var $node t3lib_tree_pagetree_Node */
190 $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
191 $GLOBALS['BE_USER']->uc['pageTree_temporaryMountPoint'] = $node->getId();
192 $GLOBALS['BE_USER']->writeUC($GLOBALS['BE_USER']->uc);
193
194 return t3lib_tree_pagetree_Commands::getMountPointPath();
195 }
196
197 /**
198 * Moves the source node directly as the first child of the destination node
199 *
200 * @param stdClass $nodeData
201 * @param int $destination
202 * @return array
203 */
204 public function moveNodeToFirstChildOfDestination($nodeData, $destination) {
205 /** @var $node t3lib_tree_pagetree_Node */
206 $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
207
208 try {
209 t3lib_tree_pagetree_Commands::moveNode($node, $destination);
210 $newNode = t3lib_tree_pagetree_Commands::getNode($node->getId(), FALSE);
211 $newNode->setLeaf($node->isLeafNode());
212 $returnValue = $newNode->toArray();
213 } catch (Exception $exception) {
214 $returnValue = array(
215 'success' => FALSE,
216 'message' => $exception->getMessage(),
217 );
218 }
219
220 return $returnValue;
221 }
222
223 /**
224 * Moves the source node directly after the destination node
225 *
226 * @param stdClass $nodeData
227 * @param int $destination
228 * @return void
229 */
230 public function moveNodeAfterDestination($nodeData, $destination) {
231 /** @var $node t3lib_tree_pagetree_Node */
232 $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
233
234 try {
235 t3lib_tree_pagetree_Commands::moveNode($node, -$destination);
236 $newNode = t3lib_tree_pagetree_Commands::getNode($node->getId(), FALSE);
237 $newNode->setLeaf($node->isLeafNode());
238 $returnValue = $newNode->toArray();
239 } catch (Exception $exception) {
240 $returnValue = array(
241 'success' => FALSE,
242 'message' => $exception->getMessage(),
243 );
244 }
245
246 return $returnValue;
247 }
248
249 /**
250 * Copies the source node directly as the first child of the destination node and
251 * returns the created node.
252 *
253 * @param stdClass $nodeData
254 * @param int $destination
255 * @return array
256 */
257 public function copyNodeToFirstChildOfDestination($nodeData, $destination) {
258 /** @var $node t3lib_tree_pagetree_Node */
259 $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
260
261 /** @var $dataProvider t3lib_tree_pagetree_DataProvider */
262 $dataProvider = t3lib_div::makeInstance('t3lib_tree_pagetree_DataProvider');
263
264 try {
265 $newPageId = t3lib_tree_pagetree_Commands::copyNode($node, $destination);
266 $newNode = t3lib_tree_pagetree_Commands::getNode($newPageId);
267 $newNode->setLeaf($node->isLeafNode());
268 $returnValue = $newNode->toArray();
269 } catch (Exception $exception) {
270 $returnValue = array(
271 'success' => FALSE,
272 'message' => $exception->getMessage(),
273 );
274 }
275
276 return $returnValue;
277 }
278
279 /**
280 * Copies the source node directly after the destination node and returns the
281 * created node.
282 *
283 * @param stdClass $nodeData
284 * @param int $destination
285 * @return array
286 */
287 public function copyNodeAfterDestination($nodeData, $destination) {
288 /** @var $node t3lib_tree_pagetree_Node */
289 $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
290
291 /** @var $dataProvider t3lib_tree_pagetree_DataProvider */
292 $dataProvider = t3lib_div::makeInstance('t3lib_tree_pagetree_DataProvider');
293
294 try {
295 $newPageId = t3lib_tree_pagetree_Commands::copyNode($node, -$destination);
296 $newNode = t3lib_tree_pagetree_Commands::getNode($newPageId);
297 $newNode->setLeaf($node->isLeafNode());
298 $returnValue = $newNode->toArray();
299 } catch (Exception $exception) {
300 $returnValue = array(
301 'success' => FALSE,
302 'message' => $exception->getMessage(),
303 );
304 }
305
306 return $returnValue;
307 }
308
309 /**
310 * Inserts a new node as the first child node of the destination node and returns the created node.
311 *
312 * @param stdClass $parentNodeData
313 * @param int $pageType
314 * @return array
315 */
316 public function insertNodeToFirstChildOfDestination($parentNodeData, $pageType) {
317 /** @var $parentNode t3lib_tree_pagetree_Node */
318 $parentNode = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $parentNodeData);
319
320 try {
321 $newPageId = t3lib_tree_pagetree_Commands::createNode($parentNode, $parentNode->getId(), $pageType);
322 $returnValue = t3lib_tree_pagetree_Commands::getNode($newPageId)->toArray();
323 } catch (Exception $exception) {
324 $returnValue = array(
325 'success' => FALSE,
326 'message' => $exception->getMessage(),
327 );
328 }
329
330 return $returnValue;
331 }
332
333 /**
334 * Inserts a new node directly after the destination node and returns the created node.
335 *
336 * @param stdClass $parentNodeData
337 * @param int $destination
338 * @param int $pageType
339 * @return array
340 */
341 public function insertNodeAfterDestination($parentNodeData, $destination, $pageType) {
342 /** @var $parentNode t3lib_tree_pagetree_Node */
343 $parentNode = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $parentNodeData);
344
345 try {
346 $newPageId = t3lib_tree_pagetree_Commands::createNode($parentNode, -$destination, $pageType);
347 $returnValue = t3lib_tree_pagetree_Commands::getNode($newPageId)->toArray();
348 } catch (Exception $exception) {
349 $returnValue = array(
350 'success' => FALSE,
351 'message' => $exception->getMessage(),
352 );
353 }
354
355 return $returnValue;
356 }
357
358 /**
359 * Returns the view link of a given node
360 *
361 * @param stdClass $nodeData
362 * @return string
363 */
364 public static function getViewLink($nodeData) {
365 /** @var $node t3lib_tree_pagetree_Node */
366 $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
367
368 $javascriptLink = t3lib_BEfunc::viewOnClick($node->getId());
369 preg_match('/window\.open\(\'([^\']+)\'/i', $javascriptLink, $match);
370
371 return $match[1];
372 }
373 }
374
375 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/tree/pagetree/extdirect/class.t3lib_tree_pagetree_extdirect_commands.php'])) {
376 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/tree/pagetree/extdirect/class.t3lib_tree_pagetree_extdirect_commands.php']);
377 }
378
379 ?>