Cleanup: Updated copyright comments
[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 class tx_cms_BackendLayout {
29
30 /**
31 * ItemProcFunc for colpos items
32 *
33 * @param array $params
34 * @return void
35 */
36 public function colPosListItemProcFunc(&$params) {
37 $params['items'] = $this->addColPosListLayoutItems($params['row']['pid'], $params['items']);
38 }
39
40 /**
41 * Adds items to a colpos list
42 *
43 * @param int $pageId
44 * @param array $items
45 * @return array
46 */
47 protected function addColPosListLayoutItems($pageId, $items) {
48 $layout = $this->getSelectedBackendLayout($pageId);
49
50 if ($layout && $layout['__items']) {
51 $items = $layout['__items'];
52 }
53
54 return $items;
55 }
56
57 /**
58 * Gets the list of available columns for a given page id
59 *
60 * @param int $id
61 * @return array $tcaItems
62 */
63 public function getColPosListItemsParsed($id) {
64 $tsConfig = t3lib_BEfunc::getModTSconfig($id, 'TCEFORM.tt_content.colPos');
65 $tcaConfig = $GLOBALS['TCA']['tt_content']['columns']['colPos']['config'];
66
67 $tceForms = t3lib_div::makeInstance('t3lib_TCEForms');
68
69 $tcaItems = $tcaConfig['items'];
70 $tcaItems = $tceForms->addItems($tcaItems, $tsConfig['properties']['addItems.']);
71
72 if (isset($tcaConfig['itemsProcFunc']) && $tcaConfig['itemsProcFunc']) {
73 $tcaItems = $this->addColPosListLayoutItems($id, $tcaItems);
74 }
75
76 foreach (t3lib_div::trimExplode(',', $tsConfig['properties']['removeItems'], 1) as $removeId) {
77 unset($tcaItems[$removeId]);
78 }
79
80 return $tcaItems;
81 }
82
83 /**
84 * Gets the selected backend layout
85 *
86 * @param int $id
87 * @return array|null $backendLayout
88 */
89 public function getSelectedBackendLayout($id) {
90 $rootline = t3lib_BEfunc::BEgetRootLine($id);
91 $backendLayoutUid = NULL;
92
93 for ($i = count($rootline); $i > 0; $i--) {
94 $page = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
95 'uid, be_layout, be_layout_next_level',
96 'pages',
97 'uid=' . intval($rootline[$i]['uid'])
98 );
99
100 if (intval($page['be_layout_next_level']) > 0 && $page['uid'] != $id) {
101 $backendLayoutUid = intval($page['be_layout_next_level']);
102 break;
103 } else {
104 if (intval($page['be_layout']) > 0) {
105 $backendLayoutUid = intval($page['be_layout']);
106 break;
107 }
108 }
109 }
110
111 $backendLayout = NULL;
112 if ($backendLayoutUid) {
113 $backendLayout = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
114 '*',
115 'be_layouts',
116 'uid=' . $backendLayoutUid
117 );
118
119 if ($backendLayout) {
120 $parser = t3lib_div::makeInstance('t3lib_TSparser');
121 $parser->parse($backendLayout['config']);
122
123 $backendLayout['__config'] = $parser->setup;
124 $backendLayout['__items'] = array();
125 $backendLayout['__colPosList'] = array();
126
127 // create items and colPosList
128 if ($backendLayout['__config']['be_layout.'] && $backendLayout['__config']['be_layout.']['rows.']) {
129 foreach ($backendLayout['__config']['be_layout.']['rows.'] as $row) {
130 if (isset($row['columns.']) && is_array($row['columns.'])) {
131 foreach ($row['columns.'] as $column) {
132 $backendLayout['__items'][] = array(
133 $column['name'],
134 $column['colPos'],
135 NULL
136 );
137 $backendLayout['__colPosList'][] = $column['colPos'];
138 }
139 }
140 }
141 }
142 }
143 }
144
145 return $backendLayout;
146 }
147
148 }
149
150 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/classes/class.tx_cms_backendlayout.php']) {
151 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/classes/class.tx_cms_backendlayout.php']);
152 }
153
154 ?>