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