[CLEANUP] Use Permission constants consistently
[Packages/TYPO3.CMS.git] / typo3 / sysext / impexp / Classes / View / ExportPageTreeView.php
1 <?php
2 namespace TYPO3\CMS\Impexp\View;
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 use TYPO3\CMS\Backend\Tree\View\BrowseTreeView;
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
19 use TYPO3\CMS\Core\Imaging\Icon;
20 use TYPO3\CMS\Core\Imaging\IconFactory;
21 use TYPO3\CMS\Core\Type\Bitmask\Permission;
22 use TYPO3\CMS\Core\Utility\GeneralUtility;
23
24 /**
25 * Extension of the page tree class. Used to get the tree of pages to export.
26 */
27 class ExportPageTreeView extends BrowseTreeView
28 {
29 /**
30 * Initialization
31 */
32 public function __construct()
33 {
34 parent::__construct();
35 $this->init();
36 }
37
38 /**
39 * Wrapping title from page tree.
40 *
41 * @param string $title Title to wrap
42 * @param string $row Item record
43 * @param int $bank Bank pointer (which mount point number)
44 * @return string Wrapped title
45 * @access private
46 */
47 public function wrapTitle($title, $row, $bank = 0)
48 {
49 return trim($title) === '' ? '<em>[' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.no_title')) . ']</em>' : htmlspecialchars($title);
50 }
51
52 /**
53 * Wrapping Plus/Minus icon
54 *
55 * @param string $icon Icon HTML
56 * @param mixed $cmd (See parent class)
57 * @param mixed $bMark (See parent class)
58 * @param bool $isOpen
59 * @return string Icon HTML
60 */
61 public function PM_ATagWrap($icon, $cmd, $bMark = '', $isOpen = false)
62 {
63 return $icon;
64 }
65
66 /**
67 * Wrapping Icon
68 *
69 * @param string $icon Icon HTML
70 * @param array $row Record row (page)
71 * @return string Icon HTML
72 */
73 public function wrapIcon($icon, $row)
74 {
75 return $icon;
76 }
77
78 /**
79 * Tree rendering
80 *
81 * @param int $pid PID value
82 * @param string $clause Additional where clause
83 * @return array Array of tree elements
84 */
85 public function ext_tree($pid, $clause = '')
86 {
87 // Initialize:
88 $this->init(' AND ' . $this->BE_USER->getPagePermsClause(Permission::PAGE_SHOW) . $clause);
89 // Get stored tree structure:
90 $this->stored = unserialize($this->BE_USER->uc['browseTrees']['browsePages'], ['allowed_classes' => false]);
91 $treeArr = [];
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 if ($pid > 0) {
101 $rootRec = BackendUtility::getRecordWSOL('pages', $pid);
102 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
103 $firstHtml = $iconFactory->getIconForRecord('pages', $rootRec, Icon::SIZE_SMALL)->render();
104 } else {
105 $rootRec = [
106 'title' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'],
107 'uid' => 0
108 ];
109 $firstHtml = $this->getRootIcon($rootRec);
110 }
111 $this->tree[] = ['HTML' => $firstHtml, 'row' => $rootRec, 'hasSub' => $isOpen];
112 if ($isOpen) {
113 // Set depth:
114 if ($this->addSelfId) {
115 $this->ids[] = $pid;
116 }
117 $this->getTree($pid, 999, '');
118 $idH = [];
119 $idH[$pid]['uid'] = $pid;
120 if (!empty($this->buffer_idH)) {
121 $idH[$pid]['subrow'] = $this->buffer_idH;
122 }
123 $this->buffer_idH = $idH;
124 }
125 // Add tree:
126 return array_merge($treeArr, $this->tree);
127 }
128 }