ElementBrowserPageTreeView.php 5.75 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
namespace TYPO3\CMS\Backend\Tree\View;

/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */

/**
 * Class which generates the page tree
 *
 * Browsable tree, used in PagePositionMaps (move elements), Element Browser and RTE (for which it will be extended)
 * previously located inside typo3/class.browse_links.php
 */
class ElementBrowserPageTreeView extends BrowseTreeView {

	/**
	 * whether the page ID should be shown next to the title, activate through
	 * userTSconfig (options.pageTree.showPageIdWithTitle)
	 *
29
	 * @var bool
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
	 */
	public $ext_showPageId = FALSE;

	/**
	 * Constructor. Just calling init()
	 */
	public function __construct() {
		$this->determineScriptUrl();
		$this->init();
		$this->clause = ' AND doktype!=' . \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_RECYCLER . $this->clause;
	}

	/**
	 * Wrapping the title in a link, if applicable.
	 *
	 * @param string $title Title, (must be ready for output, that means it must be htmlspecialchars()'ed).
	 * @param array $v The record
	 * @param bool $ext_pArrPages (Ignore)
	 * @return string Wrapping title string.
	 */
	public function wrapTitle($title, $v, $ext_pArrPages = '') {
		if ($this->ext_isLinkable($v['doktype'], $v['uid'])) {
52
			$aOnClick = 'return link_typo3Page(' . \TYPO3\CMS\Core\Utility\GeneralUtility::quoteJSvalue($v['uid']) . ');';
53
54
			return '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '">' . $title . '</a>';
		} else {
55
			return '<span class="text-muted">' . $title . '</span>';
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
		}
	}

	/**
	 * Create the page navigation tree in HTML
	 *
	 * @param array $treeArr Tree array
	 * @return string HTML output.
	 */
	public function printTree($treeArr = '') {
		$titleLen = (int)$GLOBALS['BE_USER']->uc['titleLen'];
		if (!is_array($treeArr)) {
			$treeArr = $this->tree;
		}
		$out = '';
71
72
73
74
75
76
77
78
79
80
81
82
83
84
		// We need to count the opened <ul>'s every time we dig into another level,
		// so we know how many we have to close when all children are done rendering
		$closeDepth = array();
		foreach ($treeArr as $treeItem) {
			$classAttr = $treeItem['row']['_CSSCLASS'];
			if ($treeItem['isFirst']) {
				$out .= '<ul class="list-tree">';
			}

			// Add CSS classes to the list item
			if ($treeItem['hasSub']) {
				$classAttr .= ' list-tree-control-open';
			}

Wouter Wolters's avatar
Wouter Wolters committed
85
			$selected = '';
86
			if ($GLOBALS['SOBE']->browser->curUrlInfo['act'] == 'page' && $GLOBALS['SOBE']->browser->curUrlInfo['pageid'] == $treeItem['row']['uid'] && $GLOBALS['SOBE']->browser->curUrlInfo['pageid']) {
Wouter Wolters's avatar
Wouter Wolters committed
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>' : '';
Wouter Wolters's avatar
Wouter Wolters committed
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
94
95
			if (!$treeItem['hasSub']) {
				$out .= '</li>';
			}
96

97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
			// We have to remember if this is the last one
			// on level X so the last child on level X+1 closes the <ul>-tag
			if ($treeItem['isLast']) {
				$closeDepth[$treeItem['invertedDepth']] = 1;
			}
			// If this is the last one and does not have subitems, we need to close
			// the tree as long as the upper levels have last items too
			if ($treeItem['isLast'] && !$treeItem['hasSub']) {
				for ($i = $treeItem['invertedDepth']; $closeDepth[$i] == 1; $i++) {
					$closeDepth[$i] = 0;
					$out .= '</ul></li>';
				}
			}

		}
Benni Mack's avatar
Benni Mack committed
112
		$out = '<ul class="list-tree list-tree-root">' . $out . '</ul>';
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
		return $out;
	}

	/**
	 * Returns TRUE if a doktype can be linked.
	 *
	 * @param int $doktype Doktype value to test
	 * @param int $uid uid to test.
	 * @return bool
	 */
	public function ext_isLinkable($doktype, $uid) {
		if ($uid && $doktype < 199) {
			return TRUE;
		}
	}

	/**
	 * Wrap the plus/minus icon in a link
	 *
	 * @param string $icon HTML string to wrap, probably an image tag.
	 * @param string $cmd Command for 'PM' get var
134
	 * @param bool $bMark If set, the link will have an anchor point (=$bMark) and a name attribute (=$bMark)
135
	 * @param bool $isOpen
136
137
	 * @return string Link-wrapped input string
	 */
138
	public function PM_ATagWrap($icon, $cmd, $bMark = '', $isOpen = FALSE) {
139
140
141
		$name = '';
		if ($bMark) {
			$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
150
151
152
153
154
155
156
	}

	/**
	 * Wrapping the image tag, $icon, for the row, $row
	 *
	 * @param string $icon The image tag for the icon
	 * @param array $row The row for the current element
	 * @return string The processed icon input value.
	 */
	public function wrapIcon($icon, $row) {
		if ($this->ext_showPageId) {
157
			$icon .= '[' . $row['uid'] . ']&nbsp;';
158
		}
159
		return $icon;
160
161
162
	}

}