89de2da7e3098b4c4293d8fa9795549ba0c93099
[Packages/TYPO3.CMS.git] / typo3 / sysext / impexp / Classes / LocalPageTree.php
1 <?php
2 namespace TYPO3\CMS\Impexp;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Extension of the page tree class. Used to get the tree of pages to export.
19 *
20 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
21 */
22 class LocalPageTree extends \TYPO3\CMS\Backend\Tree\View\BrowseTreeView {
23
24 /**
25 * Initialization
26 */
27 public function __construct() {
28 $this->init();
29 }
30
31 /**
32 * Wrapping title from page tree.
33 *
34 * @param string $title Title to wrap
35 * @param mixed $v (See parent class)
36 * @return string Wrapped title
37 */
38 public function wrapTitle($title, $v) {
39 $title = trim($title) === '' ? '<em>[' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.no_title', TRUE) . ']</em>' : htmlspecialchars($title);
40 return $title;
41 }
42
43 /**
44 * Wrapping Plus/Minus icon
45 *
46 * @param string $icon Icon HTML
47 * @param mixed $cmd (See parent class)
48 * @param mixed $bMark (See parent class)
49 * @return string Icon HTML
50 */
51 public function PM_ATagWrap($icon, $cmd, $bMark = '') {
52 return $icon;
53 }
54
55 /**
56 * Wrapping Icon
57 *
58 * @param string $icon Icon HTML
59 * @param array $row Record row (page)
60 * @return string Icon HTML
61 */
62 public function wrapIcon($icon, $row) {
63 return $icon;
64 }
65
66 /**
67 * Select permissions
68 *
69 * @return string SQL where clause
70 */
71 public function permsC() {
72 return $this->BE_USER->getPagePermsClause(1);
73 }
74
75 /**
76 * Tree rendering
77 *
78 * @param int $pid PID value
79 * @param string $clause Additional where clause
80 * @return array Array of tree elements
81 */
82 public function ext_tree($pid, $clause = '') {
83 // Initialize:
84 $this->init(' AND ' . $this->permsC() . $clause);
85 // Get stored tree structure:
86 $this->stored = unserialize($this->BE_USER->uc['browseTrees']['browsePages']);
87 // PM action:
88 $PM = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode('_', \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('PM'));
89 // traverse mounts:
90 $titleLen = (int)$this->BE_USER->uc['titleLen'];
91 $treeArr = array();
92 $idx = 0;
93 // Set first:
94 $this->bank = $idx;
95 $isOpen = $this->stored[$idx][$pid] || $this->expandFirst;
96 // save ids
97 $curIds = $this->ids;
98 $this->reset();
99 $this->ids = $curIds;
100 // Set PM icon:
101 $cmd = $this->bank . '_' . ($isOpen ? '0_' : '1_') . $pid;
102 $icon = '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($this->backPath, ('gfx/ol/' . ($isOpen ? 'minus' : 'plus') . 'only.gif'), 'width="18" height="16"') . ' align="top" alt="" />';
103 $firstHtml = $this->PM_ATagWrap($icon, $cmd);
104 if ($pid > 0) {
105 $rootRec = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordWSOL('pages', $pid);
106 $firstHtml .= $this->wrapIcon(\TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('pages', $rootRec), $rootRec);
107 } else {
108 $rootRec = array(
109 'title' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'],
110 'uid' => 0
111 );
112 $firstHtml .= $this->wrapIcon(\TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('apps-pagetree-page-domain'), $rootRec);
113 }
114 $this->tree[] = array('HTML' => $firstHtml, 'row' => $rootRec);
115 if ($isOpen) {
116 // Set depth:
117 $depthD = '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($this->backPath, 'gfx/ol/blank.gif', 'width="18" height="16"') . ' align="top" alt="" />';
118 if ($this->addSelfId) {
119 $this->ids[] = $pid;
120 }
121 $this->getTree($pid, 999, $depthD);
122 $idH = array();
123 $idH[$pid]['uid'] = $pid;
124 if (!empty($this->buffer_idH)) {
125 $idH[$pid]['subrow'] = $this->buffer_idH;
126 }
127 $this->buffer_idH = $idH;
128 }
129 // Add tree:
130 $treeArr = array_merge($treeArr, $this->tree);
131 return $treeArr;
132 }
133
134 }