TYPO3 API  SVNRelease
class.t3lib_tree_pagetree_extdirect_commands.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2010-2011 TYPO3 Tree Team <http://forge.typo3.org/projects/typo3v4-extjstrees>
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00027 
00028 /**
00029  * Commands for the Page tree
00030  *
00031  * @author Stefan Galinski <stefan.galinski@gmail.com>
00032  * @package TYPO3
00033  * @subpackage t3lib
00034  */
00035 class t3lib_tree_pagetree_extdirect_Commands {
00036     /**
00037      * Visibly the page
00038      *
00039      * @param stdClass $nodeData
00040      * @return array
00041      */
00042     public function visiblyNode($nodeData) {
00043         /** @var $node t3lib_tree_pagetree_Node */
00044         $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
00045 
00046         /** @var $dataProvider t3lib_tree_pagetree_DataProvider */
00047         $dataProvider = t3lib_div::makeInstance('t3lib_tree_pagetree_DataProvider');
00048 
00049         try {
00050             t3lib_tree_pagetree_Commands::visiblyNode($node);
00051             $newNode = t3lib_tree_pagetree_Commands::getNode($node->getId());
00052             $newNode->setLeaf($node->isLeafNode());
00053             $returnValue = $newNode->toArray();
00054         } catch (Exception $exception) {
00055             $returnValue = array(
00056                  'success' => FALSE,
00057                  'error' => $exception->getMessage(),
00058              );
00059         }
00060 
00061         return $returnValue;
00062     }
00063 
00064     /**
00065      * Hide the page
00066      *
00067      * @param stdClass $nodeData
00068      * @return array
00069      */
00070     public function disableNode($nodeData) {
00071         /** @var $node t3lib_tree_pagetree_Node */
00072         $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
00073 
00074         /** @var $dataProvider t3lib_tree_pagetree_DataProvider */
00075         $dataProvider = t3lib_div::makeInstance('t3lib_tree_pagetree_DataProvider');
00076 
00077         try {
00078             t3lib_tree_pagetree_Commands::disableNode($node);
00079             $newNode = t3lib_tree_pagetree_Commands::getNode($node->getId());
00080             $newNode->setLeaf($node->isLeafNode());
00081             $returnValue = $newNode->toArray();
00082         } catch (Exception $exception) {
00083             $returnValue = array(
00084                  'success' => FALSE,
00085                  'message' => $exception->getMessage(),
00086              );
00087         }
00088 
00089         return $returnValue;
00090     }
00091 
00092     /**
00093      * Delete the page
00094      *
00095      * @param stdClass $nodeData
00096      * @return array
00097      */
00098     public function deleteNode($nodeData) {
00099         /** @var $node t3lib_tree_pagetree_Node */
00100         $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
00101 
00102         try {
00103             t3lib_tree_pagetree_Commands::deleteNode($node);
00104 
00105             $returnValue = array();
00106             if ($GLOBALS['BE_USER']->workspace) {
00107                 $record = t3lib_tree_pagetree_Commands::getNodeRecord($node->getId());
00108                 if ($record['_ORIG_uid']) {
00109                     $newNode = t3lib_tree_pagetree_Commands::getNewNode($record);
00110                     $returnValue = $newNode->toArray();
00111                 }
00112             }
00113         } catch (Exception $exception) {
00114             $returnValue = array(
00115                  'success' => FALSE,
00116                  'message' => $exception->getMessage(),
00117              );
00118         }
00119 
00120         return $returnValue;
00121     }
00122 
00123     /**
00124      * Restore the page
00125      *
00126      * @param stdClass $nodeData
00127      * @param int $destination
00128      * @return array
00129      */
00130     public function restoreNode($nodeData, $destination) {
00131         /** @var $node t3lib_tree_pagetree_Node */
00132         $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
00133 
00134         try {
00135             t3lib_tree_pagetree_Commands::restoreNode($node, $destination);
00136             $newNode = t3lib_tree_pagetree_Commands::getNode($node->getId());
00137             $returnValue = $newNode->toArray();
00138         } catch (Exception $exception) {
00139             $returnValue = array(
00140                  'success' => FALSE,
00141                  'message' => $exception->getMessage(),
00142              );
00143         }
00144 
00145         return $returnValue;
00146     }
00147 
00148     /**
00149      * Updates the given field with a new text value, may be used to inline update
00150      * the title field in the new page tree
00151      *
00152      * @param stdClass $nodeData
00153      * @param string $updatedLabel
00154      * @return array
00155      */
00156     public function updateLabel($nodeData, $updatedLabel) {
00157         if ($updatedLabel === '') {
00158             return array();
00159         }
00160 
00161         /** @var $node t3lib_tree_pagetree_Node */
00162         $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
00163 
00164         try {
00165             t3lib_tree_pagetree_Commands::updateNodeLabel($node, $updatedLabel);
00166 
00167             $shortendedText = t3lib_div::fixed_lgd_cs($updatedLabel, intval($GLOBALS['BE_USER']->uc['titleLen']));
00168             $returnValue = array(
00169                 'editableText' => $updatedLabel,
00170                 'updatedText' => htmlspecialchars($shortendedText),
00171             );
00172         } catch (Exception $exception) {
00173             $returnValue = array(
00174                  'success' => FALSE,
00175                  'message' => $exception->getMessage(),
00176              );
00177         }
00178 
00179         return $returnValue;
00180     }
00181 
00182     /**
00183      * Sets a temporary mount point
00184      *
00185      * @param stdClass $nodeData
00186      * @return array
00187      */
00188     public static function setTemporaryMountPoint($nodeData) {
00189         /** @var $node t3lib_tree_pagetree_Node */
00190         $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
00191         $GLOBALS['BE_USER']->uc['pageTree_temporaryMountPoint'] = $node->getId();
00192         $GLOBALS['BE_USER']->writeUC($GLOBALS['BE_USER']->uc);
00193 
00194         return t3lib_tree_pagetree_Commands::getMountPointPath();
00195     }
00196 
00197     /**
00198      * Moves the source node directly as the first child of the destination node
00199      *
00200      * @param stdClass $nodeData
00201      * @param int $destination
00202      * @return array
00203      */
00204     public function moveNodeToFirstChildOfDestination($nodeData, $destination) {
00205         /** @var $node t3lib_tree_pagetree_Node */
00206         $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
00207 
00208         try {
00209             t3lib_tree_pagetree_Commands::moveNode($node, $destination);
00210             $newNode = t3lib_tree_pagetree_Commands::getNode($node->getId(), FALSE);
00211             $newNode->setLeaf($node->isLeafNode());
00212             $returnValue = $newNode->toArray();
00213         } catch (Exception $exception) {
00214             $returnValue = array(
00215                  'success' => FALSE,
00216                  'message' => $exception->getMessage(),
00217              );
00218         }
00219 
00220         return $returnValue;
00221     }
00222 
00223     /**
00224      * Moves the source node directly after the destination node
00225      *
00226      * @param stdClass $nodeData
00227      * @param int $destination
00228      * @return void
00229      */
00230     public function moveNodeAfterDestination($nodeData, $destination) {
00231         /** @var $node t3lib_tree_pagetree_Node */
00232         $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
00233 
00234         try {
00235             t3lib_tree_pagetree_Commands::moveNode($node, -$destination);
00236             $newNode = t3lib_tree_pagetree_Commands::getNode($node->getId(), FALSE);
00237             $newNode->setLeaf($node->isLeafNode());
00238             $returnValue = $newNode->toArray();
00239         } catch (Exception $exception) {
00240             $returnValue = array(
00241                  'success' => FALSE,
00242                  'message' => $exception->getMessage(),
00243              );
00244         }
00245 
00246         return $returnValue;
00247     }
00248 
00249     /**
00250      * Copies the source node directly as the first child of the destination node and
00251      * returns the created node.
00252      *
00253      * @param stdClass $nodeData
00254      * @param int $destination
00255      * @return array
00256      */
00257     public function copyNodeToFirstChildOfDestination($nodeData, $destination) {
00258         /** @var $node t3lib_tree_pagetree_Node */
00259         $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
00260 
00261         /** @var $dataProvider t3lib_tree_pagetree_DataProvider */
00262         $dataProvider = t3lib_div::makeInstance('t3lib_tree_pagetree_DataProvider');
00263 
00264         try {
00265             $newPageId = t3lib_tree_pagetree_Commands::copyNode($node, $destination);
00266             $newNode = t3lib_tree_pagetree_Commands::getNode($newPageId);
00267             $newNode->setLeaf($node->isLeafNode());
00268             $returnValue = $newNode->toArray();
00269         } catch (Exception $exception) {
00270             $returnValue = array(
00271                  'success' => FALSE,
00272                  'message' => $exception->getMessage(),
00273              );
00274         }
00275 
00276         return $returnValue;
00277     }
00278 
00279     /**
00280      * Copies the source node directly after the destination node and returns the
00281      * created node.
00282      *
00283      * @param stdClass $nodeData
00284      * @param int $destination
00285      * @return array
00286      */
00287     public function copyNodeAfterDestination($nodeData, $destination) {
00288         /** @var $node t3lib_tree_pagetree_Node */
00289         $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
00290 
00291         /** @var $dataProvider t3lib_tree_pagetree_DataProvider */
00292         $dataProvider = t3lib_div::makeInstance('t3lib_tree_pagetree_DataProvider');
00293 
00294         try {
00295             $newPageId = t3lib_tree_pagetree_Commands::copyNode($node, -$destination);
00296             $newNode = t3lib_tree_pagetree_Commands::getNode($newPageId);
00297             $newNode->setLeaf($node->isLeafNode());
00298             $returnValue = $newNode->toArray();
00299         } catch (Exception $exception) {
00300             $returnValue = array(
00301                  'success' => FALSE,
00302                  'message' => $exception->getMessage(),
00303              );
00304         }
00305 
00306         return $returnValue;
00307     }
00308 
00309     /**
00310      * Inserts a new node as the first child node of the destination node and returns the created node.
00311      *
00312      * @param stdClass $parentNodeData
00313      * @param int $pageType
00314      * @return array
00315      */
00316     public function insertNodeToFirstChildOfDestination($parentNodeData, $pageType) {
00317         /** @var $parentNode t3lib_tree_pagetree_Node */
00318         $parentNode = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $parentNodeData);
00319 
00320         try {
00321             $newPageId = t3lib_tree_pagetree_Commands::createNode($parentNode, $parentNode->getId(), $pageType);
00322             $returnValue = t3lib_tree_pagetree_Commands::getNode($newPageId)->toArray();
00323         } catch (Exception $exception) {
00324             $returnValue = array(
00325                  'success' => FALSE,
00326                  'message' => $exception->getMessage(),
00327              );
00328         }
00329 
00330         return $returnValue;
00331     }
00332 
00333     /**
00334      * Inserts a new node directly after the destination node and returns the created node.
00335      *
00336      * @param stdClass $parentNodeData
00337      * @param int $destination
00338      * @param int $pageType
00339      * @return array
00340      */
00341     public function insertNodeAfterDestination($parentNodeData, $destination, $pageType) {
00342         /** @var $parentNode t3lib_tree_pagetree_Node */
00343         $parentNode = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $parentNodeData);
00344 
00345         try {
00346             $newPageId = t3lib_tree_pagetree_Commands::createNode($parentNode, -$destination, $pageType);
00347             $returnValue = t3lib_tree_pagetree_Commands::getNode($newPageId)->toArray();
00348         } catch (Exception $exception) {
00349             $returnValue = array(
00350                  'success' => FALSE,
00351                  'message' => $exception->getMessage(),
00352              );
00353         }
00354 
00355         return $returnValue;
00356     }
00357 
00358     /**
00359      * Returns the view link of a given node
00360      *
00361      * @param stdClass $nodeData
00362      * @return string
00363      */
00364     public static function getViewLink($nodeData) {
00365         /** @var $node t3lib_tree_pagetree_Node */
00366         $node = t3lib_div::makeInstance('t3lib_tree_pagetree_Node', (array) $nodeData);
00367 
00368         $javascriptLink = t3lib_BEfunc::viewOnClick($node->getId());
00369         preg_match('/window\.open\(\'([^\']+)\'/i', $javascriptLink, $match);
00370 
00371         return $match[1];
00372     }
00373 }
00374 
00375 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/tree/pagetree/extdirect/class.t3lib_tree_pagetree_extdirect_commands.php'])) {
00376     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/tree/pagetree/extdirect/class.t3lib_tree_pagetree_extdirect_commands.php']);
00377 }
00378 
00379 ?>