[TASK] Introduce Enum constants for t3ver_state
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Tree / View / BrowseTreeView.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tree\View;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Backend\Utility\BackendUtility;
31
32 /**
33 * Generate a page-tree, browsable.
34 *
35 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
36 * @coauthor René Fritz <r.fritz@colorcube.de>
37 */
38 class BrowseTreeView extends \TYPO3\CMS\Backend\Tree\View\AbstractTreeView {
39
40 /**
41 * Initialize, setting what is necessary for browsing pages.
42 * Using the current user.
43 *
44 * @param string $clause Additional clause for selecting pages.
45 * @param string $orderByFields record ORDER BY field
46 * @return void
47 * @todo Define visibility
48 */
49 public function init($clause = '', $orderByFields = '') {
50 // This will hide records from display - it has nothing todo with user rights!!
51 $clauseExcludePidList = '';
52 if ($pidList = $GLOBALS['BE_USER']->getTSConfigVal('options.hideRecords.pages')) {
53 if ($pidList = $GLOBALS['TYPO3_DB']->cleanIntList($pidList)) {
54 $clauseExcludePidList = ' AND pages.uid NOT IN (' . $pidList . ')';
55 }
56 }
57 // This is very important for making trees of pages: Filtering out deleted pages, pages with no access to and sorting them correctly:
58 parent::init(' AND ' . $GLOBALS['BE_USER']->getPagePermsClause(1) . ' ' . $clause . $clauseExcludePidList, 'sorting');
59 $this->table = 'pages';
60 $this->setTreeName('browsePages');
61 $this->domIdPrefix = 'pages';
62 $this->iconName = '';
63 $this->title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
64 $this->MOUNTS = $GLOBALS['WEBMOUNTS'];
65 if ($pidList) {
66 // Remove mountpoint if explicitly set in options.hideRecords.pages (see above)
67 $hideList = explode(',', $pidList);
68 $this->MOUNTS = array_diff($this->MOUNTS, $hideList);
69 }
70 $this->fieldArray = array_merge($this->fieldArray, array('doktype', 'php_tree_stop', 't3ver_id', 't3ver_state', 't3ver_wsid', 't3ver_move_id'));
71 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('cms')) {
72 $this->fieldArray = array_merge($this->fieldArray, array('hidden', 'starttime', 'endtime', 'fe_group', 'module', 'extendToSubpages', 'is_siteroot', 'nav_hide'));
73 }
74 }
75
76 /**
77 * Creates title attribute content for pages.
78 * Uses API function in \TYPO3\CMS\Backend\Utility\BackendUtility which will retrieve lots of useful information for pages.
79 *
80 * @param array $row The table row.
81 * @return string
82 * @todo Define visibility
83 */
84 public function getTitleAttrib($row) {
85 return BackendUtility::titleAttribForPages($row, '1=1 ' . $this->clause, 0);
86 }
87
88 /**
89 * Wrapping the image tag, $icon, for the row, $row (except for mount points)
90 *
91 * @param string $icon The image tag for the icon
92 * @param array $row The row for the current element
93 * @return string The processed icon input value.
94 * @access private
95 * @todo Define visibility
96 */
97 public function wrapIcon($icon, $row) {
98 // Add title attribute to input icon tag
99 $theIcon = $this->addTagAttributes($icon, $this->titleAttrib ? $this->titleAttrib . '="' . $this->getTitleAttrib($row) . '"' : '');
100 // Wrap icon in click-menu link.
101 if (!$this->ext_IconMode) {
102 $theIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theIcon, $this->treeName, $this->getId($row), 0);
103 } elseif (!strcmp($this->ext_IconMode, 'titlelink')) {
104 $aOnClick = 'return jumpTo(\'' . $this->getJumpToParam($row) . '\',this,\'' . $this->domIdPrefix . $this->getId($row) . '\',' . $this->bank . ');';
105 $theIcon = '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '">' . $theIcon . '</a>';
106 }
107 return $theIcon;
108 }
109
110 /**
111 * Returns the title for the input record. If blank, a "no title" label (localized) will be returned.
112 * Do NOT htmlspecialchar the string from this function - has already been done.
113 *
114 * @param array $row The input row array (where the key "title" is used for the title)
115 * @param integer $titleLen Title length (30)
116 * @return string The title.
117 * @todo Define visibility
118 */
119 public function getTitleStr($row, $titleLen = 30) {
120 $title = parent::getTitleStr($row, $titleLen);
121 if (isset($row['is_siteroot']) && $row['is_siteroot'] != 0 && $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showDomainNameWithTitle')) {
122 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('domainName,sorting', 'sys_domain', 'pid=' . $GLOBALS['TYPO3_DB']->quoteStr(($row['uid'] . BackendUtility::deleteClause('sys_domain') . BackendUtility::BEenableFields('sys_domain')), 'sys_domain'), '', 'sorting', 1);
123 if (is_array($rows) && count($rows) > 0) {
124 $title = sprintf('%s [%s]', $title, htmlspecialchars($rows[0]['domainName']));
125 }
126 }
127 return $title;
128 }
129
130 /**
131 * Adds a red "+" to the input string, $str, if the field "php_tree_stop" in the $row (pages) is set
132 *
133 * @param string $str Input string, like a page title for the tree
134 * @param array $row Record row with "php_tree_stop" field
135 * @return string Modified string
136 * @access private
137 * @todo Define visibility
138 */
139 public function wrapStop($str, $row) {
140 if ($row['php_tree_stop']) {
141 $str .= '<span class="typo3-red">
142 <a href="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('setTempDBmount' => $row['uid']))) . '" class="typo3-red">+</a>
143 </span>';
144 }
145 return $str;
146 }
147
148 }