f2d279e999e5ec120367117d8db560fd3887e8b5
[Packages/TYPO3.CMS.git] / typo3 / sysext / pagetree / classes / extdirect / class.tx_pagetree_extdirect_commands.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 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 tx_pagetree
34 */
35 class tx_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 tx_pagetree_Node */
44 $node = t3lib_div::makeInstance('tx_pagetree_Node', (array) $nodeData);
45
46 try {
47 tx_pagetree_Commands::visiblyNode($node);
48 $newNode = tx_pagetree_Commands::getNode($node->getId());
49 $newNode->setLeaf($node->isLeafNode());
50 $returnValue = $newNode->toArray();
51 } catch (Exception $exception) {
52 $returnValue = array(
53 'success' => FALSE,
54 'error' => $exception->getMessage(),
55 );
56 }
57
58 return $returnValue;
59 }
60
61 /**
62 * Hide the page
63 *
64 * @param stdClass $nodeData
65 * @return array
66 */
67 public function disableNode($nodeData) {
68 /** @var $node tx_pagetree_Node */
69 $node = t3lib_div::makeInstance('tx_pagetree_Node', (array) $nodeData);
70
71 try {
72 tx_pagetree_Commands::disableNode($node);
73 $newNode = tx_pagetree_Commands::getNode($node->getId());
74 $newNode->setLeaf($node->isLeafNode());
75 $returnValue = $newNode->toArray();
76 } catch (Exception $exception) {
77 $returnValue = array(
78 'success' => FALSE,
79 'message' => $exception->getMessage(),
80 );
81 }
82
83 return $returnValue;
84 }
85
86 /**
87 * Delete the page
88 *
89 * @param stdClass $nodeData
90 * @return array
91 */
92 public function deleteNode($nodeData) {
93 /** @var $node tx_pagetree_Node */
94 $node = t3lib_div::makeInstance('tx_pagetree_Node', (array) $nodeData);
95
96 try {
97 tx_pagetree_Commands::deleteNode($node);
98 $returnValue = array();
99 } catch (Exception $exception) {
100 $returnValue = array(
101 'success' => FALSE,
102 'message' => $exception->getMessage(),
103 );
104 }
105
106 return $returnValue;
107
108 }
109
110 /**
111 * Restore the page
112 *
113 * @param stdClass $nodeData
114 * @return array
115 */
116 public function restoreNode($nodeData) {
117 /** @var $node tx_pagetree_Node */
118 $node = t3lib_div::makeInstance('tx_pagetree_Node', (array) $nodeData);
119
120 try {
121 tx_pagetree_Commands::restoreNode($node);
122 $newNode = tx_pagetree_Commands::getNode($node->getId());
123 $returnValue = $newNode->toArray();
124 } catch (Exception $exception) {
125 $returnValue = array(
126 'success' => FALSE,
127 'message' => $exception->getMessage(),
128 );
129 }
130
131 return $returnValue;
132 }
133
134 /**
135 * Updates the given field with a new text value, may be used to inline update
136 * the title field in the new page tree
137 *
138 * @param stdClass $nodeData
139 * @param string $updatedLabel
140 * @return array
141 */
142 public function updateLabel($nodeData, $updatedLabel) {
143 /** @var $node tx_pagetree_Node */
144 $node = t3lib_div::makeInstance('tx_pagetree_Node', (array) $nodeData);
145
146 try {
147 tx_pagetree_Commands::updateNodeLabel($node, $updatedLabel);
148 $returnValue = array();
149 } catch (Exception $exception) {
150 $returnValue = array(
151 'success' => FALSE,
152 'message' => $exception->getMessage(),
153 );
154 }
155
156 return $returnValue;
157 }
158
159 /**
160 * Moves the source node directly as the first child of the destination node
161 *
162 * @param stdClass $nodeData
163 * @param int $destination
164 * @return array
165 */
166 public function moveNodeToFirstChildOfDestination($nodeData, $destination) {
167 /** @var $node tx_pagetree_Node */
168 $node = t3lib_div::makeInstance('tx_pagetree_Node', (array) $nodeData);
169
170 try {
171 tx_pagetree_Commands::moveNode($node, $destination);
172 $returnValue = array();
173 } catch (Exception $exception) {
174 $returnValue = array(
175 'success' => FALSE,
176 'message' => $exception->getMessage(),
177 );
178 }
179
180 return $returnValue;
181 }
182
183 /**
184 * Moves the source node directly after the destination node
185 *
186 * @param stdClass $nodeData
187 * @param int $destination
188 * @return void
189 */
190 public function moveNodeAfterDestination($nodeData, $destination) {
191 /** @var $node tx_pagetree_Node */
192 $node = t3lib_div::makeInstance('tx_pagetree_Node', (array) $nodeData);
193
194 try {
195 tx_pagetree_Commands::moveNode($node, -$destination);
196 $returnValue = array();
197 } catch (Exception $exception) {
198 $returnValue = array(
199 'success' => FALSE,
200 'message' => $exception->getMessage(),
201 );
202 }
203
204 return $returnValue;
205 }
206
207 /**
208 * Copies the source node directly as the first child of the destination node and
209 * returns the created node.
210 *
211 * @param stdClass $nodeData
212 * @param int $destination
213 * @return array
214 */
215 public function copyNodeToFirstChildOfDestination($nodeData, $destination) {
216 /** @var $node tx_pagetree_Node */
217 $node = t3lib_div::makeInstance('tx_pagetree_Node', (array) $nodeData);
218
219 try {
220 $newPageId = tx_pagetree_Commands::copyNode($node, $destination);
221 $returnValue = tx_pagetree_Commands::getNode($newPageId)->toArray();
222 } catch (Exception $exception) {
223 $returnValue = array(
224 'success' => FALSE,
225 'message' => $exception->getMessage(),
226 );
227 }
228
229 return $returnValue;
230 }
231
232 /**
233 * Copies the source node directly after the destination node and returns the
234 * created node.
235 *
236 * @param stdClass $nodeData
237 * @param int $destination
238 * @return array
239 */
240 public function copyNodeAfterDestination($nodeData, $destination) {
241 /** @var $node tx_pagetree_Node */
242 $node = t3lib_div::makeInstance('tx_pagetree_Node', (array) $nodeData);
243
244 try {
245 $newPageId = tx_pagetree_Commands::copyNode($node, -$destination);
246 $returnValue = tx_pagetree_Commands::getNode($newPageId)->toArray();
247 } catch (Exception $exception) {
248 $returnValue = array(
249 'success' => FALSE,
250 'message' => $exception->getMessage(),
251 );
252 }
253
254 return $returnValue;
255 }
256
257 /**
258 * Inserts a new node as the first child node of the destination node and returns the created node.
259 *
260 * @param stdClass $parentNodeData
261 * @param int $pageType
262 * @return array
263 */
264 public function insertNodeToFirstChildOfDestination($parentNodeData, $pageType) {
265 /** @var $parentNode tx_pagetree_Node */
266 $parentNode = t3lib_div::makeInstance('tx_pagetree_Node', (array) $parentNodeData);
267
268 try {
269 $newPageId = tx_pagetree_Commands::createNode($parentNode, $parentNode->getId(), $pageType);
270 $returnValue = tx_pagetree_Commands::getNode($newPageId)->toArray();
271 } catch (Exception $exception) {
272 $returnValue = array(
273 'success' => FALSE,
274 'message' => $exception->getMessage(),
275 );
276 }
277
278 return $returnValue;
279 }
280
281 /**
282 * Inserts a new node directly after the destination node and returns the created node.
283 *
284 * @param stdClass $parentNodeData
285 * @param int $destination
286 * @param int $pageType
287 * @return array
288 */
289 public function insertNodeAfterDestination($parentNodeData, $destination, $pageType) {
290 /** @var $parentNode tx_pagetree_Node */
291 $parentNode = t3lib_div::makeInstance('tx_pagetree_Node', (array) $parentNodeData);
292
293 try {
294 $newPageId = tx_pagetree_Commands::createNode($parentNode, -$destination, $pageType);
295 $returnValue = tx_pagetree_Commands::getNode($newPageId)->toArray();
296 } catch (Exception $exception) {
297 $returnValue = array(
298 'success' => FALSE,
299 'message' => $exception->getMessage(),
300 );
301 }
302
303 return $returnValue;
304 }
305
306 /**
307 * Returns the view link of a given node
308 *
309 * @param stdClass $nodeData
310 * @param string $workspacePreview
311 * @return string
312 */
313 public static function getViewLink($nodeData, $workspacePreview) {
314 // @TODO use the hook to get the needed information's
315
316
317 // $viewScriptPreviewEnabled = '/' . TYPO3_mainDir . 'mod/user/ws/wsol_preview.php?id=';
318 // $viewScriptPreviewDisabled = '/index.php?id=';
319 //
320 // // check alternate Domains
321 // $rootLine = t3lib_BEfunc::BEgetRootLine($id);
322 // if ($rootLine) {
323 // $parts = parse_url(t3lib_div::getIndpEnv('TYPO3_SITE_URL'));
324 // if (t3lib_BEfunc::getDomainStartPage($parts['host'], $parts['path'])) {
325 // $preUrl_temp = t3lib_BEfunc::firstDomainRecord($rootLine);
326 // }
327 // }
328 // $preUrl = ($preUrl_temp ? (t3lib_div::getIndpEnv('TYPO3_SSL') ?
329 // 'https://' : 'http://') . $preUrl_temp : '' . '..');
330 //
331 // // Look if a fixed preview language should be added:
332 // $viewLanguageOrder = $GLOBALS['BE_USER']->getTSConfigVal('options.view.languageOrder');
333 // if (strlen($viewLanguageOrder)) {
334 // $suffix = '';
335 //
336 // // Find allowed languages (if none, all are allowed!)
337 // if (!$GLOBALS['BE_USER']->user['admin'] &&
338 // strlen($GLOBALS['BE_USER']->groupData['allowed_languages'])) {
339 // $allowed_languages = array_flip(explode(',', $GLOBALS['BE_USER']->groupData['allowed_languages']));
340 // }
341 //
342 // // Traverse the view order, match first occurrence
343 // $lOrder = t3lib_div::intExplode(',',$viewLanguageOrder);
344 // foreach($lOrder as $langUid) {
345 // if (is_array($allowed_languages) && count($allowed_languages)) {
346 // if (isset($allowed_languages[$langUid])) { // Choose if set.
347 // $suffix = '&L='.$langUid;
348 // break;
349 // }
350 // } else { // All allowed since no lang. are listed.
351 // $suffix = '&L='.$langUid;
352 // break;
353 // }
354 // }
355 //
356 // // Add it:
357 // $addGetVars.= $suffix;
358 // }
359 //
360 // $urlPreviewEnabled = $preUrl . $viewScriptPreviewEnabled . $id . $addGetVars;
361 // $urlPreviewDisabled = $preUrl . $viewScriptPreviewDisabled . $id . $addGetVars;
362 //
363 // if ($workspacePreview) {
364 // return $urlPreviewEnabled;
365 // } else {
366 // return $urlPreviewDisabled;
367 // }
368
369 // $javascriptLink = t3lib_BEfunc::viewOnClick($id);
370 // debug($javascriptLink);
371
372 return 'http://linux-schmie.de/wp-content/uploads/2010/07/Baustelle.png';
373 }
374 }
375
376 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/sysext/pagetree/classes/extdirect/class.tx_pagetree_extdirect_commands.php']) {
377 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/sysext/pagetree/classes/extdirect/class.tx_pagetree_extdirect_commands.php']);
378 }
379
380 ?>