BrowseTreeView.php 5.87 KB
Newer Older
1
2
3
<?php
namespace TYPO3\CMS\Backend\Tree\View;

4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
8
9
 * 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.
10
 *
11
12
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
15
 * The TYPO3 project - inspiring people to share!
 */
Christian Kuhn's avatar
Christian Kuhn committed
16

Nicole Cordes's avatar
Nicole Cordes committed
17
use TYPO3\CMS\Backend\Utility\BackendUtility;
18
use TYPO3\CMS\Core\Database\ConnectionPool;
19
use TYPO3\CMS\Core\Type\Bitmask\Permission;
20
use TYPO3\CMS\Core\Utility\GeneralUtility;
Nicole Cordes's avatar
Nicole Cordes committed
21

22
23
24
/**
 * Generate a page-tree, browsable.
 */
25
26
27
28
29
class BrowseTreeView extends AbstractTreeView
{
    /**
     * @var array
     */
30
    public $fieldArray = [
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
        'uid',
        'pid',
        'title',
        'doktype',
        'nav_title',
        'mount_pid',
        'php_tree_stop',
        't3ver_id',
        't3ver_state',
        'hidden',
        'starttime',
        'endtime',
        'fe_group',
        'module',
        'extendToSubpages',
        'nav_hide',
        't3ver_wsid',
        't3ver_move_id',
        'is_siteroot'
50
    ];
Thomas Schlumberger's avatar
Thomas Schlumberger committed
51

52
53
54
55
56
    /**
     * override to use this treeName
     * @var string
     */
    public $treeName = 'browsePages';
Thomas Schlumberger's avatar
Thomas Schlumberger committed
57

58
59
60
61
62
    /**
     * override to use this table
     * @var string
     */
    public $table = 'pages';
Thomas Schlumberger's avatar
Thomas Schlumberger committed
63

64
65
66
67
68
    /**
     * override to use this domIdPrefix
     * @var string
     */
    public $domIdPrefix = 'pages';
Thomas Schlumberger's avatar
Thomas Schlumberger committed
69

70
71
72
73
74
    /**
     * @var bool
     */
    public $ext_showNavTitle = false;

75
76
77
78
79
80
81
82
83
    /**
     * Initialize, setting what is necessary for browsing pages.
     * Using the current user.
     *
     * @param string $clause Additional clause for selecting pages.
     * @param string $orderByFields record ORDER BY field
     */
    public function init($clause = '', $orderByFields = '')
    {
84
        // This will hide records from display - it has nothing to do with user rights!!
85
        $clauseExcludePidList = '';
86
        if ($pidList = $this->getBackendUser()->getTSConfigVal('options.hideRecords.pages')) {
87
            if ($pidList = implode(',', GeneralUtility::intExplode(',', $pidList))) {
88
89
90
91
                $clauseExcludePidList = ' AND pages.uid NOT IN (' . $pidList . ')';
            }
        }
        // This is very important for making trees of pages: Filtering out deleted pages, pages with no access to and sorting them correctly:
92
        parent::init(' AND ' . $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW) . ' ' . $clause . $clauseExcludePidList, 'sorting');
93
        $this->title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
94
        $this->MOUNTS = $this->getBackendUser()->returnWebmounts();
95
96
97
98
99
100
        if ($pidList) {
            // Remove mountpoint if explicitly set in options.hideRecords.pages (see above)
            $hideList = explode(',', $pidList);
            $this->MOUNTS = array_diff($this->MOUNTS, $hideList);
        }
    }
101

102
103
104
105
106
107
108
109
110
111
112
    /**
     * Creates title attribute content for pages.
     * Uses API function in \TYPO3\CMS\Backend\Utility\BackendUtility which will retrieve lots of useful information for pages.
     *
     * @param array $row The table row.
     * @return string
     */
    public function getTitleAttrib($row)
    {
        return BackendUtility::titleAttribForPages($row, '1=1 ' . $this->clause, 0);
    }
113

114
115
116
117
118
119
120
121
122
123
124
125
126
    /**
     * Wrapping the image tag, $icon, for the row, $row (except for mount points)
     *
     * @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.
     * @access private
     */
    public function wrapIcon($icon, $row)
    {
        // Wrap icon in click-menu link.
        $theIcon = '';
        if (!$this->ext_IconMode) {
127
            $theIcon = BackendUtility::wrapClickMenuOnIcon($icon, $this->treeName, $this->getId($row), 0);
128
        } elseif ($this->ext_IconMode === 'titlelink') {
129
130
            $aOnClick = 'return jumpTo(' . GeneralUtility::quoteJSvalue($this->getJumpToParam($row)) . ',this,'
                        . GeneralUtility::quoteJSvalue($this->domIdPrefix . $this->getId($row)) . ',' . $this->bank . ');';
131
132
133
134
            $theIcon = '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '">' . $icon . '</a>';
        }
        return $theIcon;
    }
135

136
137
138
139
140
141
142
143
144
145
    /**
     * Returns the title for the input record. If blank, a "no title" label (localized) will be returned.
     * Do NOT htmlspecialchar the string from this function - has already been done.
     *
     * @param array $row The input row array (where the key "title" is used for the title)
     * @param int $titleLen Title length (30)
     * @return string The title.
     */
    public function getTitleStr($row, $titleLen = 30)
    {
146
147
148
149
150
151
        if ($this->ext_showNavTitle && isset($row['nav_title']) && trim($row['nav_title']) !== '') {
            $title = parent::getTitleStr(['title' => $row['nav_title']], $titleLen);
        } else {
            $title = parent::getTitleStr($row, $titleLen);
        }
        if (!empty($row['is_siteroot']) && $this->getBackendUser()->getTSConfigVal('options.pageTree.showDomainNameWithTitle')) {
152
153
154
155
            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_domain');
            $row = $queryBuilder
                ->select('domainName', 'sorting')
                ->from('sys_domain')
156
157
158
159
160
161
                ->where(
                    $queryBuilder->expr()->eq(
                        'pid',
                        $queryBuilder->createNamedParameter($row['uid'], \PDO::PARAM_INT)
                    )
                )
162
163
164
165
166
167
168
                ->orderBy('sorting')
                ->setMaxResults(1)
                ->execute()
                ->fetch();

            if ($row !== false) {
                $title = sprintf('%s [%s]', $title, htmlspecialchars($row['domainName']));
169
170
171
172
            }
        }
        return $title;
    }
173
}