f2539b26b7727d030e5a4696d9820dcfee67fed0
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Tree / View / ElementBrowserPageTreeView.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tree\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 /**
18 * Class which generates the page tree
19 *
20 * Browsable tree, used in PagePositionMaps (move elements), Element Browser and RTE (for which it will be extended)
21 * previously located inside typo3/class.browse_links.php
22 */
23 class ElementBrowserPageTreeView extends BrowseTreeView {
24
25 /**
26 * whether the page ID should be shown next to the title, activate through
27 * userTSconfig (options.pageTree.showPageIdWithTitle)
28 *
29 * @var bool
30 */
31 public $ext_showPageId = FALSE;
32
33 /**
34 * Constructor. Just calling init()
35 */
36 public function __construct() {
37 $this->determineScriptUrl();
38 $this->init();
39 $this->clause = ' AND doktype!=' . \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_RECYCLER . $this->clause;
40 }
41
42 /**
43 * Wrapping the title in a link, if applicable.
44 *
45 * @param string $title Title, (must be ready for output, that means it must be htmlspecialchars()'ed).
46 * @param array $v The record
47 * @param bool $ext_pArrPages (Ignore)
48 * @return string Wrapping title string.
49 */
50 public function wrapTitle($title, $v, $ext_pArrPages = '') {
51 if ($this->ext_isLinkable($v['doktype'], $v['uid'])) {
52 $aOnClick = 'return link_typo3Page(' . \TYPO3\CMS\Core\Utility\GeneralUtility::quoteJSvalue($v['uid']) . ');';
53 return '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '">' . $title . '</a>';
54 } else {
55 return '<span class="text-muted">' . $title . '</span>';
56 }
57 }
58
59 /**
60 * Create the page navigation tree in HTML
61 *
62 * @param array $treeArr Tree array
63 * @return string HTML output.
64 */
65 public function printTree($treeArr = '') {
66 $titleLen = (int)$GLOBALS['BE_USER']->uc['titleLen'];
67 if (!is_array($treeArr)) {
68 $treeArr = $this->tree;
69 }
70 $out = '';
71 // We need to count the opened <ul>'s every time we dig into another level,
72 // so we know how many we have to close when all children are done rendering
73 $closeDepth = array();
74 foreach ($treeArr as $treeItem) {
75 $classAttr = $treeItem['row']['_CSSCLASS'];
76 if ($treeItem['isFirst']) {
77 $out .= '<ul class="list-tree">';
78 }
79
80 // Add CSS classes to the list item
81 if ($treeItem['hasSub']) {
82 $classAttr .= ' list-tree-control-open';
83 }
84
85 $selected = '';
86 if ($GLOBALS['SOBE']->browser->curUrlInfo['act'] == 'page' && $GLOBALS['SOBE']->browser->curUrlInfo['pageid'] == $treeItem['row']['uid'] && $GLOBALS['SOBE']->browser->curUrlInfo['pageid']) {
87 $selected = ' bg-success';
88 }
89 $aOnClick = 'return jumpToUrl(' . \TYPO3\CMS\Core\Utility\GeneralUtility::quoteJSvalue($this->getThisScript() . 'act=' . $GLOBALS['SOBE']->browser->act . '&mode=' . $GLOBALS['SOBE']->browser->mode . '&expandPage=' . $treeItem['row']['uid']) . ');';
90 $cEbullet = $this->ext_isLinkable($treeItem['row']['doktype'], $treeItem['row']['uid']) ? '<a href="#" class="pull-right" onclick="' . htmlspecialchars($aOnClick) . '"><i class="fa fa-caret-square-o-right"></i></a>' : '';
91 $out .= '<li' . ($classAttr ? ' class="' . trim($classAttr) . '"' : '') . '><span class="list-tree-group' . $selected . '">' . $cEbullet . $treeItem['HTML'] . $this->wrapTitle($this->getTitleStr($treeItem['row'], $titleLen), $treeItem['row'], $this->ext_pArrPages) . '</span>';
92
93 if (!$treeItem['hasSub']) {
94 $out .= '</li>';
95 }
96
97 // We have to remember if this is the last one
98 // on level X so the last child on level X+1 closes the <ul>-tag
99 if ($treeItem['isLast']) {
100 $closeDepth[$treeItem['invertedDepth']] = 1;
101 }
102 // If this is the last one and does not have subitems, we need to close
103 // the tree as long as the upper levels have last items too
104 if ($treeItem['isLast'] && !$treeItem['hasSub']) {
105 for ($i = $treeItem['invertedDepth']; $closeDepth[$i] == 1; $i++) {
106 $closeDepth[$i] = 0;
107 $out .= '</ul></li>';
108 }
109 }
110
111 }
112 $out = '<ul class="list-tree" id="treeRoot">' . $out . '</ul>';
113 return $out;
114 }
115
116 /**
117 * Returns TRUE if a doktype can be linked.
118 *
119 * @param int $doktype Doktype value to test
120 * @param int $uid uid to test.
121 * @return bool
122 */
123 public function ext_isLinkable($doktype, $uid) {
124 if ($uid && $doktype < 199) {
125 return TRUE;
126 }
127 }
128
129 /**
130 * Wrap the plus/minus icon in a link
131 *
132 * @param string $icon HTML string to wrap, probably an image tag.
133 * @param string $cmd Command for 'PM' get var
134 * @param bool $bMark If set, the link will have a anchor point (=$bMark) and a name attribute (=$bMark)
135 * @param bool $isOpen
136 * @return string Link-wrapped input string
137 */
138 public function PM_ATagWrap($icon, $cmd, $bMark = '', $isOpen = FALSE) {
139 $name = '';
140 if ($bMark) {
141 $anchor = '#' . $bMark;
142 $name = ' name=' . $bMark;
143 }
144 $aOnClick = 'return jumpToUrl(' . \TYPO3\CMS\Core\Utility\GeneralUtility::quoteJSvalue($this->getThisScript() . 'PM=' . $cmd) . ',' . \TYPO3\CMS\Core\Utility\GeneralUtility::quoteJSvalue($anchor) . ');';
145 return '<a class="list-tree-control ' . ($isOpen ? 'list-tree-control-open' : 'list-tree-control-closed') . '" href="#"' . htmlspecialchars($name) . ' onclick="' . htmlspecialchars($aOnClick) . '"><i class="fa"></i></a>';
146 }
147
148 /**
149 * Wrapping the image tag, $icon, for the row, $row
150 *
151 * @param string $icon The image tag for the icon
152 * @param array $row The row for the current element
153 * @return string The processed icon input value.
154 */
155 public function wrapIcon($icon, $row) {
156 if ($this->ext_showPageId) {
157 $icon .= '[' . $row['uid'] . ']&nbsp;';
158 }
159 return $icon;
160 }
161
162 }