[FEATURE] UI changes to "Page" module
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / classes / class.tx_cms_backendlayout.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 GridView Team
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 /**
29 * Backend layout for CMS
30 *
31 * @author GridView Team
32 * @package TYPO3
33 * @subpackage core
34 */
35 class tx_cms_BackendLayout {
36
37 /**
38 * ItemProcFunc for colpos items
39 *
40 * @param array $params
41 * @return void
42 */
43 public function colPosListItemProcFunc(&$params) {
44 if ($params['row']['pid'] > 0) {
45 $params['items'] = $this->addColPosListLayoutItems($params['row']['pid'], $params['items']);
46 } else {
47 // Negative uid_pid values indicate that the element has been inserted after an existing element
48 // so there is no pid to get the backendLayout for and we have to get that first
49 $existingElement = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('pid', 'tt_content', 'uid=' . -(intval($params['row']['pid'])));
50 if ($existingElement['pid'] > 0) {
51 $params['items'] = $this->addColPosListLayoutItems($existingElement['pid'], $params['items']);
52 }
53 }
54 }
55
56 /**
57 * Adds items to a colpos list
58 *
59 * @param integer $pageId
60 * @param array $items
61 * @return array
62 */
63 protected function addColPosListLayoutItems($pageId, $items) {
64 $layout = $this->getSelectedBackendLayout($pageId);
65
66 if ($layout && $layout['__items']) {
67 $items = $layout['__items'];
68 }
69
70 return $items;
71 }
72
73 /**
74 * Gets the list of available columns for a given page id
75 *
76 * @param integer $id
77 * @return array $tcaItems
78 */
79 public function getColPosListItemsParsed($id) {
80 $tsConfig = t3lib_BEfunc::getModTSconfig($id, 'TCEFORM.tt_content.colPos');
81 $tcaConfig = $GLOBALS['TCA']['tt_content']['columns']['colPos']['config'];
82
83 /** @var $tceForms t3lib_TCEForms */
84 $tceForms = t3lib_div::makeInstance('t3lib_TCEForms');
85
86 $tcaItems = $tcaConfig['items'];
87 $tcaItems = $tceForms->addItems($tcaItems, $tsConfig['properties']['addItems.']);
88
89 if (isset($tcaConfig['itemsProcFunc']) && $tcaConfig['itemsProcFunc']) {
90 $tcaItems = $this->addColPosListLayoutItems($id, $tcaItems);
91 }
92
93 foreach (t3lib_div::trimExplode(',', $tsConfig['properties']['removeItems'], 1) as $removeId) {
94 foreach ($tcaItems as $key => $item) {
95 if ($item[1] == $removeId) {
96 unset($tcaItems[$key]);
97 }
98 }
99 }
100
101 return $tcaItems;
102 }
103
104 /**
105 * Gets the selected backend layout
106 *
107 * @param integer $id
108 * @return array|NULL $backendLayout
109 */
110 public function getSelectedBackendLayout($id) {
111 $rootline = t3lib_BEfunc::BEgetRootLine($id);
112 $backendLayoutUid = NULL;
113
114 for ($i = count($rootline); $i > 0; $i--) {
115 $page = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
116 // pid is needed here for workspaceOL()
117 'uid, pid, backend_layout, backend_layout_next_level',
118 'pages',
119 'uid=' . intval($rootline[$i]['uid'])
120 );
121 t3lib_BEfunc::workspaceOL('pages', $page);
122
123 $selectedBackendLayout = intval($page['backend_layout']);
124 $selectedBackendLayoutNextLevel = intval($page['backend_layout_next_level']);
125 if ($selectedBackendLayout != 0 && $page['uid'] == $id) {
126 if ($selectedBackendLayout > 0) {
127 // Backend layout for current page is set
128 $backendLayoutUid = $selectedBackendLayout;
129 }
130 break;
131 } elseif ($selectedBackendLayoutNextLevel == -1 && $page['uid'] != $id) {
132 // Some previous page in our rootline sets layout_next to "None"
133 break;
134 } elseif ($selectedBackendLayoutNextLevel > 0 && $page['uid'] != $id) {
135 // Some previous page in our rootline sets some backend_layout, use it
136 $backendLayoutUid = $selectedBackendLayoutNextLevel;
137 break;
138 }
139 }
140
141 $backendLayout = NULL;
142 if ($backendLayoutUid) {
143 $backendLayout = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
144 '*',
145 'backend_layout',
146 'uid=' . $backendLayoutUid
147 );
148 } else {
149 $backendLayout['config'] = $this->getDefaultColumnLayout();
150 }
151
152 if ($backendLayout) {
153 /** @var $parser t3lib_TSparser */
154 $parser = t3lib_div::makeInstance('t3lib_TSparser');
155 $parser->parse($backendLayout['config']);
156
157 $backendLayout['__config'] = $parser->setup;
158 $backendLayout['__items'] = array();
159 $backendLayout['__colPosList'] = array();
160
161 // create items and colPosList
162 if ($backendLayout['__config']['backend_layout.'] && $backendLayout['__config']['backend_layout.']['rows.']) {
163 foreach ($backendLayout['__config']['backend_layout.']['rows.'] as $row) {
164 if (isset($row['columns.']) && is_array($row['columns.'])) {
165 foreach ($row['columns.'] as $column) {
166 $backendLayout['__items'][] = array(
167 t3lib_div::isFirstPartOfStr($column['name'], 'LLL:') ? $GLOBALS['LANG']->sL($column['name']) : $column['name'],
168 $column['colPos'],
169 NULL
170 );
171 $backendLayout['__colPosList'][] = $column['colPos'];
172 }
173 }
174 }
175 }
176 }
177
178 return $backendLayout;
179 }
180
181 /**
182 * Get default columns layout
183 *
184 * @return string Default four column layout
185 */
186 public function getDefaultColumnLayout() {
187 return '
188 backend_layout {
189 colCount = 4
190 rowCount = 1
191 rows {
192 1 {
193 columns {
194 1 {
195 name = LLL:EXT:cms/locallang_ttc.xlf:colPos.I.0
196 colPos = 1
197 }
198 2 {
199 name = LLL:EXT:cms/locallang_ttc.xlf:colPos.I.1
200 colPos = 0
201 }
202 3 {
203 name = LLL:EXT:cms/locallang_ttc.xlf:colPos.I.2
204 colPos = 2
205 }
206 4 {
207 name = LLL:EXT:cms/locallang_ttc.xlf:colPos.I.3
208 colPos = 3
209 }
210 }
211 }
212 }
213 }
214 ';
215 }
216
217 }
218
219 ?>