ab8c836f726f9bbdc3c095f8b5999c792bbcce59
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Tree / Pagetree / ExtdirectTreeDataProvider.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tree\Pagetree;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 TYPO3 Tree Team <http://forge.typo3.org/projects/typo3v4-extjstrees>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Backend\Tree\Pagetree\Commands;
31 use TYPO3\CMS\Backend\Utility\IconUtility;
32 use TYPO3\CMS\Core\Utility\GeneralUtility;
33
34 /**
35 * Data Provider of the Page Tree
36 *
37 * @author Stefan Galinski <stefan.galinski@gmail.com>
38 */
39 class ExtdirectTreeDataProvider extends \TYPO3\CMS\Backend\Tree\AbstractExtJsTree {
40
41 /**
42 * Data Provider
43 *
44 * @var \TYPO3\CMS\Backend\Tree\Pagetree\DataProvider
45 */
46 protected $dataProvider = NULL;
47
48 /**
49 * Sets the data provider
50 *
51 * @return void
52 */
53 protected function initDataProvider() {
54 /** @var $dataProvider \TYPO3\CMS\Backend\Tree\Pagetree\DataProvider */
55 $dataProvider = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\DataProvider');
56 $this->setDataProvider($dataProvider);
57 }
58
59 /**
60 * Returns the root node of the tree
61 *
62 * @return array
63 */
64 public function getRoot() {
65 $this->initDataProvider();
66 $node = $this->dataProvider->getRoot();
67 return $node->toArray();
68 }
69
70 /**
71 * Fetches the next tree level
72 *
73 * @param integer $nodeId
74 * @param stdClass $nodeData
75 * @return array
76 */
77 public function getNextTreeLevel($nodeId, $nodeData) {
78 $this->initDataProvider();
79 /** @var $node \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode */
80 $node = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNode', (array) $nodeData);
81 if ($nodeId === 'root') {
82 $nodeCollection = $this->dataProvider->getTreeMounts();
83 } else {
84 $nodeCollection = $this->dataProvider->getNodes($node, $node->getMountPoint());
85 }
86 return $nodeCollection->toArray();
87 }
88
89 /**
90 * Returns a tree that only contains elements that match the given search string
91 *
92 * @param integer $nodeId
93 * @param stdClass $nodeData
94 * @param string $searchFilter
95 * @return array
96 */
97 public function getFilteredTree($nodeId, $nodeData, $searchFilter) {
98 if (strval($searchFilter) === '') {
99 return array();
100 }
101 /** @var $node \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode */
102 $node = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNode', (array) $nodeData);
103 $this->initDataProvider();
104 if ($nodeId === 'root') {
105 $nodeCollection = $this->dataProvider->getTreeMounts($searchFilter);
106 } else {
107 $nodeCollection = $this->dataProvider->getFilteredNodes($node, $searchFilter, $node->getMountPoint());
108 }
109 return $nodeCollection->toArray();
110 }
111
112 /**
113 * Returns the localized list of doktypes to display
114 *
115 * Note: The list can be filtered by the user typoscript
116 * option "options.pageTree.doktypesToShowInNewPageDragArea".
117 *
118 * @return array
119 */
120 public function getNodeTypes() {
121 $map = array(
122 1 => 'LLL:EXT:lang/locallang_tca.xlf:doktype.I.0',
123 3 => 'LLL:EXT:cms/locallang_tca.xlf:pages.doktype.I.8',
124 4 => 'LLL:EXT:cms/locallang_tca.xlf:pages.doktype.I.2',
125 6 => 'LLL:EXT:cms/locallang_tca.xlf:pages.doktype.I.4',
126 7 => 'LLL:EXT:cms/locallang_tca.xlf:pages.doktype.I.5',
127 199 => 'LLL:EXT:cms/locallang_tca.xlf:pages.doktype.I.7',
128 254 => 'LLL:EXT:lang/locallang_tca.xlf:doktype.I.folder',
129 255 => 'LLL:EXT:lang/locallang_tca.xlf:doktype.I.2'
130 );
131 $doktypes = GeneralUtility::trimExplode(',', $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.doktypesToShowInNewPageDragArea'));
132 $output = array();
133 $allowedDoktypes = GeneralUtility::trimExplode(',', $GLOBALS['BE_USER']->groupData['pagetypes_select']);
134 $isAdmin = $GLOBALS['BE_USER']->isAdmin();
135 foreach ($doktypes as $doktype) {
136 if (!$isAdmin && !in_array($doktype, $allowedDoktypes)) {
137 continue;
138 }
139 $label = $GLOBALS['LANG']->sL($map[$doktype], TRUE);
140 $spriteIcon = IconUtility::getSpriteIconClasses($GLOBALS['TCA']['pages']['ctrl']['typeicon_classes'][$doktype]);
141 $output[] = array(
142 'nodeType' => $doktype,
143 'cls' => 'typo3-pagetree-topPanel-button',
144 'iconCls' => $spriteIcon,
145 'title' => $label,
146 'tooltip' => $label
147 );
148 }
149 return $output;
150 }
151
152 /**
153 * Returns
154 *
155 * @return array
156 */
157 public function getIndicators() {
158 /** @var $indicatorProvider \TYPO3\CMS\Backend\Tree\Pagetree\Indicator */
159 $indicatorProvider = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\Indicator');
160 $indicatorHtmlArr = $indicatorProvider->getAllIndicators();
161 $indicator = array(
162 'html' => implode(' ', $indicatorHtmlArr),
163 '_COUNT' => count($indicatorHtmlArr)
164 );
165 return $indicator;
166 }
167
168 /**
169 * Returns the language labels, sprites and configuration options for the pagetree
170 *
171 * @return void
172 */
173 public function loadResources() {
174 $file = 'LLL:EXT:lang/locallang_core.xlf:';
175 $indicators = $this->getIndicators();
176 $configuration = array(
177 'LLL' => array(
178 'copyHint' => $GLOBALS['LANG']->sL($file . 'tree.copyHint', TRUE),
179 'fakeNodeHint' => $GLOBALS['LANG']->sL($file . 'mess.please_wait', TRUE),
180 'activeFilterMode' => $GLOBALS['LANG']->sL($file . 'tree.activeFilterMode', TRUE),
181 'dropToRemove' => $GLOBALS['LANG']->sL($file . 'tree.dropToRemove', TRUE),
182 'buttonRefresh' => $GLOBALS['LANG']->sL($file . 'labels.refresh', TRUE),
183 'buttonNewNode' => $GLOBALS['LANG']->sL($file . 'tree.buttonNewNode', TRUE),
184 'buttonFilter' => $GLOBALS['LANG']->sL($file . 'tree.buttonFilter', TRUE),
185 'dropZoneElementRemoved' => $GLOBALS['LANG']->sL($file . 'tree.dropZoneElementRemoved', TRUE),
186 'dropZoneElementRestored' => $GLOBALS['LANG']->sL($file . 'tree.dropZoneElementRestored', TRUE),
187 'searchTermInfo' => $GLOBALS['LANG']->sL($file . 'tree.searchTermInfo', TRUE),
188 'temporaryMountPointIndicatorInfo' => $GLOBALS['LANG']->sl($file . 'labels.temporaryDBmount', TRUE),
189 'deleteDialogTitle' => $GLOBALS['LANG']->sL('LLL:EXT:cms/layout/locallang.xlf:deleteItem', TRUE),
190 'deleteDialogMessage' => $GLOBALS['LANG']->sL('LLL:EXT:cms/layout/locallang.xlf:deleteWarning', TRUE),
191 'recursiveDeleteDialogMessage' => $GLOBALS['LANG']->sL('LLL:EXT:cms/layout/locallang.xlf:recursiveDeleteWarning', TRUE)
192 ),
193 'Configuration' => array(
194 'hideFilter' => $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.hideFilter'),
195 'displayDeleteConfirmation' => $GLOBALS['BE_USER']->jsConfirmation(4),
196 'canDeleteRecursivly' => $GLOBALS['BE_USER']->uc['recursiveDelete'] == TRUE,
197 'disableIconLinkToContextmenu' => $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.disableIconLinkToContextmenu'),
198 'indicator' => $indicators['html'],
199 'temporaryMountPoint' => Commands::getMountPointPath()
200 ),
201 'Sprites' => array(
202 'Filter' => IconUtility::getSpriteIconClasses('actions-system-tree-search-open'),
203 'NewNode' => IconUtility::getSpriteIconClasses('actions-page-new'),
204 'Refresh' => IconUtility::getSpriteIconClasses('actions-system-refresh'),
205 'InputClear' => IconUtility::getSpriteIconClasses('actions-input-clear'),
206 'TrashCan' => IconUtility::getSpriteIconClasses('actions-edit-delete'),
207 'TrashCanRestore' => IconUtility::getSpriteIconClasses('actions-edit-restore'),
208 'Info' => IconUtility::getSpriteIconClasses('actions-document-info')
209 )
210 );
211 return $configuration;
212 }
213
214 }