views.php
8.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<?php
/**
* @package FrameworkOnFramework
* @subpackage config
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2, or later
*/
defined('FOF_INCLUDED') or die();
/**
* Configuration parser for the view-specific settings
*
* @package FrameworkOnFramework
* @since 2.1
*/
class FOFConfigDomainViews implements FOFConfigDomainInterface
{
/**
* Parse the XML data, adding them to the $ret array
*
* @param SimpleXMLElement $xml The XML data of the component's configuration area
* @param array &$ret The parsed data, in the form of a hash array
*
* @return void
*/
public function parseDomain(SimpleXMLElement $xml, array &$ret)
{
// Initialise
$ret['views'] = array();
// Parse view configuration
$viewData = $xml->xpath('view');
// Sanity check
if (empty($viewData))
{
return;
}
foreach ($viewData as $aView)
{
$key = (string) $aView['name'];
// Parse ACL options
$ret['views'][$key]['acl'] = array();
$aclData = $aView->xpath('acl/task');
if (!empty($aclData))
{
foreach ($aclData as $acl)
{
$k = (string) $acl['name'];
$ret['views'][$key]['acl'][$k] = (string) $acl;
}
}
// Parse taskmap
$ret['views'][$key]['taskmap'] = array();
$taskmapData = $aView->xpath('taskmap/task');
if (!empty($taskmapData))
{
foreach ($taskmapData as $map)
{
$k = (string) $map['name'];
$ret['views'][$key]['taskmap'][$k] = (string) $map;
}
}
// Parse controller configuration
$ret['views'][$key]['config'] = array();
$optionData = $aView->xpath('config/option');
if (!empty($optionData))
{
foreach ($optionData as $option)
{
$k = (string) $option['name'];
$ret['views'][$key]['config'][$k] = (string) $option;
}
}
// Parse the toolbar
$ret['views'][$key]['toolbar'] = array();
$toolBars = $aView->xpath('toolbar');
if (!empty($toolBars))
{
foreach ($toolBars as $toolBar)
{
$taskName = isset($toolBar['task']) ? (string) $toolBar['task'] : '*';
// If a toolbar title is specified, create a title element.
if (isset($toolBar['title']))
{
$ret['views'][$key]['toolbar'][$taskName]['title'] = array(
'value' => (string) $toolBar['title']
);
}
// Parse the toolbar buttons data
$toolbarData = $toolBar->xpath('button');
if (!empty($toolbarData))
{
foreach ($toolbarData as $button)
{
$k = (string) $button['type'];
$ret['views'][$key]['toolbar'][$taskName][$k] = current($button->attributes());
$ret['views'][$key]['toolbar'][$taskName][$k]['value'] = (string) $button;
}
}
}
}
}
}
/**
* Return a configuration variable
*
* @param string &$configuration Configuration variables (hashed array)
* @param string $var The variable we want to fetch
* @param mixed $default Default value
*
* @return mixed The variable's value
*/
public function get(&$configuration, $var, $default)
{
$parts = explode('.', $var);
$view = $parts[0];
$method = 'get' . ucfirst($parts[1]);
if (!method_exists($this, $method))
{
return $default;
}
array_shift($parts);
array_shift($parts);
$ret = $this->$method($view, $configuration, $parts, $default);
return $ret;
}
/**
* Internal function to return the task map for a view
*
* @param string $view The view for which we will be fetching a task map
* @param array &$configuration The configuration parameters hash array
* @param array $params Extra options (not used)
* @param array $default ßDefault task map; empty array if not provided
*
* @return array The task map as a hash array in the format task => method
*/
protected function getTaskmap($view, &$configuration, $params, $default = array())
{
$taskmap = array();
if (isset($configuration['views']['*']) && isset($configuration['views']['*']['taskmap']))
{
$taskmap = $configuration['views']['*']['taskmap'];
}
if (isset($configuration['views'][$view]) && isset($configuration['views'][$view]['taskmap']))
{
$taskmap = array_merge($taskmap, $configuration['views'][$view]['taskmap']);
}
if (empty($taskmap))
{
return $default;
}
return $taskmap;
}
/**
* Internal method to return the ACL mapping (privilege required to access
* a specific task) for the given view's tasks
*
* @param string $view The view for which we will be fetching a task map
* @param array &$configuration The configuration parameters hash array
* @param array $params Extra options; key 0 defines the task we want to fetch
* @param string $default Default ACL option; empty (no ACL check) if not defined
*
* @return string The privilege required to access this view
*/
protected function getAcl($view, &$configuration, $params, $default = '')
{
$aclmap = array();
if (isset($configuration['views']['*']) && isset($configuration['views']['*']['acl']))
{
$aclmap = $configuration['views']['*']['acl'];
}
if (isset($configuration['views'][$view]) && isset($configuration['views'][$view]['acl']))
{
$aclmap = array_merge($aclmap, $configuration['views'][$view]['acl']);
}
$acl = $default;
if (isset($aclmap['*']))
{
$acl = $aclmap['*'];
}
if (isset($aclmap[$params[0]]))
{
$acl = $aclmap[$params[0]];
}
return $acl;
}
/**
* Internal method to return the a configuration option for the view. These
* are equivalent to $config array options passed to the Controller
*
* @param string $view The view for which we will be fetching a task map
* @param array &$configuration The configuration parameters hash array
* @param array $params Extra options; key 0 defines the option variable we want to fetch
* @param mixed $default Default option; null if not defined
*
* @return string The setting for the requested option
*/
protected function getConfig($view, &$configuration, $params, $default = null)
{
$ret = $default;
if (isset($configuration['views']['*'])
&& isset($configuration['views']['*']['config'])
&& isset($configuration['views']['*']['config'][$params[0]]))
{
$ret = $configuration['views']['*']['config'][$params[0]];
}
if (isset($configuration['views'][$view])
&& isset($configuration['views'][$view]['config'])
&& isset($configuration['views'][$view]['config'][$params[0]]))
{
$ret = $configuration['views'][$view]['config'][$params[0]];
}
return $ret;
}
/**
* Internal method to return the toolbar infos.
*
* @param string $view The view for which we will be fetching buttons
* @param array &$configuration The configuration parameters hash array
* @param array $params Extra options
* @param string $default Default option
*
* @return string The toolbar data for this view
*/
protected function getToolbar($view, &$configuration, $params, $default = '')
{
$toolbar = array();
if (isset($configuration['views']['*'])
&& isset($configuration['views']['*']['toolbar'])
&& isset($configuration['views']['*']['toolbar']['*']))
{
$toolbar = $configuration['views']['*']['toolbar']['*'];
}
if (isset($configuration['views']['*'])
&& isset($configuration['views']['*']['toolbar'])
&& isset($configuration['views']['*']['toolbar'][$params[0]]))
{
$toolbar = array_merge($toolbar, $configuration['views']['*']['toolbar'][$params[0]]);
}
if (isset($configuration['views'][$view])
&& isset($configuration['views'][$view]['toolbar'])
&& isset($configuration['views'][$view]['toolbar']['*']))
{
$toolbar = array_merge($toolbar, $configuration['views'][$view]['toolbar']['*']);
}
if (isset($configuration['views'][$view])
&& isset($configuration['views'][$view]['toolbar'])
&& isset($configuration['views'][$view]['toolbar'][$params[0]]))
{
$toolbar = array_merge($toolbar, $configuration['views'][$view]['toolbar'][$params[0]]);
}
if (empty($toolbar))
{
return $default;
}
return $toolbar;
}
}