|
TYPO3 API
SVNRelease
|
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 * Page Tree and Context Menu Commands 00030 * 00031 * @author Stefan Galinski <stefan.galinski@gmail.com> 00032 * @package TYPO3 00033 * @subpackage t3lib 00034 */ 00035 final class t3lib_tree_pagetree_Commands { 00036 /** 00037 * Visibly the page 00038 * 00039 * @param t3lib_tree_pagetree_Node $nodeData 00040 * @return void 00041 */ 00042 public static function visiblyNode(t3lib_tree_pagetree_Node $node) { 00043 $data['pages'][$node->getWorkspaceId()]['hidden'] = 0; 00044 self::processTceCmdAndDataMap(array(), $data); 00045 } 00046 00047 /** 00048 * Hide the page 00049 * 00050 * @param t3lib_tree_pagetree_Node $nodeData 00051 * @return void 00052 */ 00053 public static function disableNode(t3lib_tree_pagetree_Node $node) { 00054 $data['pages'][$node->getWorkspaceId()]['hidden'] = 1; 00055 self::processTceCmdAndDataMap(array(), $data); 00056 } 00057 00058 /** 00059 * Delete the page 00060 * 00061 * @param t3lib_tree_pagetree_Node $nodeData 00062 * @return void 00063 */ 00064 public static function deleteNode(t3lib_tree_pagetree_Node $node) { 00065 $cmd['pages'][$node->getId()]['delete'] = 1; 00066 self::processTceCmdAndDataMap($cmd); 00067 } 00068 00069 /** 00070 * Restore the page 00071 * 00072 * @param t3lib_tree_pagetree_Node $nodeData 00073 * @param int $targetId 00074 * @return void 00075 */ 00076 public static function restoreNode(t3lib_tree_pagetree_Node $node, $targetId) { 00077 $cmd['pages'][$node->getId()]['undelete'] = 1; 00078 self::processTceCmdAndDataMap($cmd); 00079 00080 if ($node->getId() !== $targetId) { 00081 self::moveNode($node, $targetId); 00082 } 00083 } 00084 00085 /** 00086 * Updates the node label 00087 * 00088 * @param t3lib_tree_pagetree_Node $nodeData 00089 * @param string $updatedLabel 00090 * @return void 00091 */ 00092 public static function updateNodeLabel(t3lib_tree_pagetree_Node $node, $updatedLabel) { 00093 $data['pages'][$node->getWorkspaceId()][$node->getTextSourceField()] = $updatedLabel; 00094 self::processTceCmdAndDataMap(array(), $data); 00095 } 00096 00097 /** 00098 * Copies a page and returns the id of the new page 00099 * 00100 * Node: Use a negative target id to specify a sibling target else the parent is used 00101 * 00102 * @param t3lib_tree_pagetree_Node $sourceNode 00103 * @param int $targetId 00104 * @return int 00105 */ 00106 public static function copyNode(t3lib_tree_pagetree_Node $sourceNode, $targetId) { 00107 $cmd['pages'][$sourceNode->getId()]['copy'] = $targetId; 00108 $returnValue = self::processTceCmdAndDataMap($cmd); 00109 00110 return $returnValue['pages'][$sourceNode->getId()]; 00111 } 00112 00113 /** 00114 * Moves a page 00115 * 00116 * Node: Use a negative target id to specify a sibling target else the parent is used 00117 * 00118 * @param t3lib_tree_pagetree_Node $sourceNode 00119 * @param int $targetId 00120 * @return void 00121 */ 00122 public static function moveNode(t3lib_tree_pagetree_Node $sourceNode, $targetId) { 00123 $cmd['pages'][$sourceNode->getId()]['move'] = $targetId; 00124 self::processTceCmdAndDataMap($cmd); 00125 } 00126 00127 /** 00128 * Creates a page of the given doktype and returns the id of the created page 00129 * 00130 * @param t3lib_tree_pagetree_Node $parentNode 00131 * @param int $targetId 00132 * @param int $pageType 00133 * @return int 00134 */ 00135 public static function createNode(t3lib_tree_pagetree_Node $parentNode, $targetId, $pageType) { 00136 $placeholder = 'NEW12345'; 00137 $data['pages'][$placeholder] = array( 00138 'pid' => $parentNode->getWorkspaceId(), 00139 'doktype' => $pageType, 00140 'title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:tree.defaultPageTitle', TRUE), 00141 ); 00142 $newPageId = self::processTceCmdAndDataMap(array(), $data); 00143 $node = self::getNode($newPageId[$placeholder]); 00144 00145 if ($parentNode->getWorkspaceId() !== $targetId) { 00146 self::moveNode($node, $targetId); 00147 } 00148 00149 return $newPageId[$placeholder]; 00150 } 00151 00152 /** 00153 * Process TCEMAIN commands and data maps 00154 * 00155 * Command Map: 00156 * Used for moving, recover, remove and some more operations. 00157 * 00158 * Data Map: 00159 * Used for creating and updating records, 00160 * 00161 * This API contains all necessary access checks. 00162 * 00163 * @param array $cmd 00164 * @param array $data 00165 * @throws Exception if an error happened while the TCE processing 00166 * @return array 00167 */ 00168 protected static function processTceCmdAndDataMap(array $cmd, array $data = array()) { 00169 /** @var $tce t3lib_TCEmain */ 00170 $tce = t3lib_div::makeInstance('t3lib_TCEmain'); 00171 $tce->stripslashes_values = 0; 00172 $tce->start($data, $cmd); 00173 $tce->copyTree = t3lib_div::intInRange($GLOBALS['BE_USER']->uc['copyLevels'], 0, 100); 00174 00175 if (count($cmd)) { 00176 $tce->process_cmdmap(); 00177 $returnValues = $tce->copyMappingArray_merged; 00178 } elseif (count($data)) { 00179 $tce->process_datamap(); 00180 $returnValues = $tce->substNEWwithIDs; 00181 } 00182 00183 // check errors 00184 if (count($tce->errorLog)) { 00185 throw new Exception(implode(chr(10), $tce->errorLog)); 00186 } 00187 00188 return $returnValues; 00189 } 00190 00191 /** 00192 * Returns a node from the given node id 00193 * 00194 * @param int $nodeId 00195 * @param boolean $unsetMovePointers 00196 * @return t3lib_tree_pagetree_Node 00197 */ 00198 public static function getNode($nodeId, $unsetMovePointers = TRUE) { 00199 $record = self::getNodeRecord($nodeId, $unsetMovePointers); 00200 return self::getNewNode($record); 00201 } 00202 00203 /** 00204 * Returns the mount point path for a temporary mount or the given id 00205 * 00206 * @static 00207 * @param int $uid 00208 * @return void 00209 */ 00210 public static function getMountPointPath($uid = -1) { 00211 if ($uid === -1) { 00212 $uid = intval($GLOBALS['BE_USER']->uc['pageTree_temporaryMountPoint']); 00213 } 00214 00215 if ($uid <= 0) { 00216 return ''; 00217 } 00218 00219 $useNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle'); 00220 $rootline = array_reverse(t3lib_BEfunc::BEgetRootLine($uid)); 00221 array_shift($rootline); 00222 00223 $path = array(); 00224 foreach ($rootline as $rootlineElement) { 00225 $record = t3lib_tree_pagetree_Commands::getNodeRecord($rootlineElement['uid']); 00226 00227 $text = $record['title']; 00228 if ($useNavTitle && trim($record['nav_title']) !== '') { 00229 $text = $record['nav_title']; 00230 } 00231 00232 $path[] = $text; 00233 } 00234 00235 return htmlspecialchars('/' . implode('/', $path)); 00236 } 00237 00238 /** 00239 * Returns a node record from a given id 00240 * 00241 * @param int $nodeId 00242 * @param boolean $unsetMovePointers 00243 * @return array 00244 */ 00245 public static function getNodeRecord($nodeId, $unsetMovePointers = TRUE) { 00246 $record = t3lib_BEfunc::getRecordWSOL('pages', $nodeId, '*', '', TRUE, $unsetMovePointers); 00247 return $record; 00248 } 00249 00250 /** 00251 * Returns the first configured domain name for a page 00252 * 00253 * @static 00254 * @param integer $uid 00255 * @return string 00256 */ 00257 public static function getDomainName($uid) { 00258 $whereClause = $GLOBALS['TYPO3_DB']->quoteStr( 00259 'pid=' . intval($uid) . t3lib_BEfunc::deleteClause('sys_domain') . 00260 t3lib_BEfunc::BEenableFields('sys_domain'), 00261 'sys_domain' 00262 ); 00263 00264 $domain = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow( 00265 'domainName', 00266 'sys_domain', 00267 $whereClause, 00268 '', 00269 'sorting' 00270 ); 00271 00272 return htmlspecialchars($domain['domainName']); 00273 } 00274 00275 /** 00276 * Creates a node with the given record information's 00277 * 00278 * @param array $record 00279 * @return t3lib_tree_pagetree_Node 00280 */ 00281 public static function getNewNode($record, $mountPoint = 0) { 00282 $useNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle'); 00283 $addIdAsPrefix = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showPageIdWithTitle'); 00284 $addDomainName = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showDomainNameWithTitle'); 00285 $titleLength = intval($GLOBALS['BE_USER']->uc['titleLen']); 00286 00287 /** @var $subNode t3lib_tree_pagetree_Node */ 00288 $subNode = t3lib_div::makeInstance('t3lib_tree_pagetree_Node'); 00289 $subNode->setRecord($record); 00290 $subNode->setCls($record['_CSSCLASS']); 00291 $subNode->setType('pages'); 00292 00293 $subNode->setId($record['uid']); 00294 $subNode->setMountPoint($mountPoint); 00295 $subNode->setWorkspaceId(($record['_ORIG_uid'] ? $record['_ORIG_uid'] : $record['uid'])); 00296 00297 $field = 'title'; 00298 $text = $record['title']; 00299 if ($useNavTitle && trim($record['nav_title']) !== '') { 00300 $field = 'nav_title'; 00301 $text = $record['nav_title']; 00302 } 00303 00304 if (trim($text) === '') { 00305 $visibleText = '[' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.no_title', TRUE) . ']'; 00306 } else { 00307 $visibleText = $text; 00308 } 00309 $visibleText = t3lib_div::fixed_lgd_cs($visibleText, $titleLength); 00310 00311 $suffix = ''; 00312 if ($addDomainName) { 00313 $domain = self::getDomainName($record['uid']); 00314 $suffix = ($domain !== '' ? ' [' . $domain . ']' : ''); 00315 } 00316 00317 $qtip = str_replace(' - ', '<br />', htmlspecialchars( 00318 t3lib_BEfunc::titleAttribForPages($record, '', FALSE)) 00319 ); 00320 00321 $prefix = ''; 00322 $lockInfo = t3lib_BEfunc::isRecordLocked('pages', $record['uid']); 00323 if (is_array($lockInfo)) { 00324 $qtip .= '<br />' . htmlspecialchars($lockInfo['msg']); 00325 $prefix .= t3lib_iconWorks::getSpriteIcon( 00326 'status-warning-in-use', 00327 array( 00328 'class' => 'typo3-pagetree-status' 00329 ) 00330 ); 00331 } 00332 00333 $prefix .= htmlspecialchars($addIdAsPrefix ? '[' . $record['uid'] . '] ' : ''); 00334 $subNode->setEditableText($text); 00335 $subNode->setText( 00336 htmlspecialchars($visibleText), 00337 $field, 00338 $prefix, 00339 htmlspecialchars($suffix) 00340 ); 00341 00342 $subNode->setQTip($qtip); 00343 00344 if ($record['uid'] !== 0) { 00345 $spriteIconCode = t3lib_iconWorks::getSpriteIconForRecord('pages', $record); 00346 } else { 00347 $spriteIconCode = t3lib_iconWorks::getSpriteIcon('apps-pagetree-root'); 00348 } 00349 $subNode->setSpriteIconCode($spriteIconCode); 00350 00351 if (!$subNode->canCreateNewPages() || intval($record['t3ver_state']) === 2) { 00352 $subNode->setIsDropTarget(FALSE); 00353 } 00354 00355 if (!$subNode->canBeEdited() || !$subNode->canBeRemoved() || intval($record['t3ver_state']) === 2) { 00356 $subNode->setDraggable(FALSE); 00357 } 00358 00359 return $subNode; 00360 } 00361 } 00362 00363 ?>
1.8.0