forked from simoneeconomo/edui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.driver.php
executable file
·295 lines (244 loc) · 7.6 KB
/
extension.driver.php
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
<?php
Class extension_edui extends Extension {
/**
* Name of the extension
* @var string
*/
const EXT_NAME = 'Events, Datasources & Utilities Indexes';
/**
* Key of the pinned data source setting
* @var string
*/
const SETTING_PINNED_DS = 'pinned-datasource';
/**
* Key of the pinned events setting
* @var string
*/
const SETTING_PINNED_EV = 'pinned-events';
/**
* Key of the pinned utilities setting
* @var string
*/
const SETTING_PINNED_UT = 'pinned-utilities';
/**
* Key of the group of setting
* @var string
*/
const SETTING_GROUP = 'edui';
/**
* private variable for holding the errors encountered when saving
* @var array
*/
protected $errors = array();
public function about() {
return array(
'name' => self::EXT_NAME,
'version' => '0.7',
'release-date' => '2011-07-15',
'author' => array(
array(
'name' => 'Simone Economo',
'website' => 'http://www.lineheight.net',
'email' => '[email protected]'
),
array(
'name' => 'Solutions Nitriques',
'website' => 'http://www.nitriques.com/open-source/',
'email' => 'open-source (at) nitriques.com'
)
),
'description' => 'Dinstinct index pages for events, datasources and utilities.'
);
}
public function fetchNavigation() {
return array(
array(
'location' => __('Blueprints'),
'name' => __('Events'),
'link' => '/events/'
),
array(
'location' => __('Blueprints'),
'name' => __('Data Sources'),
'link' => '/datasources/'
),
array(
'location' => __('Blueprints'),
'name' => __('Utilities'),
'link' => '/utilities/'
)
);
}
public function getSubscribedDelegates(){
return array(
array(
'page' => '/backend/',
'delegate' => 'NavigationPreRender',
'callback' => 'deleteComponentsItem'
),
array(
'page' => '/backend/',
'delegate' => 'AdminPagePreGenerate',
'callback' => 'setRedirects'
),
array(
'page' => '/system/preferences/',
'delegate' => 'AddCustomPreferenceFieldsets',
'callback' => 'addCustomPreferenceFieldsets'
),
array(
'page' => '/system/preferences/',
'delegate' => 'Save',
'callback' => 'save'
)
);
}
public function deleteComponentsItem($context) {
foreach ($context['navigation'] as &$menu) {
if ($menu['name'] == __('Blueprints')) {
for ($i = 0; $i < count($menu['children']); ++$i) {
if ($menu['children'][$i]['name'] == __('Components')) {
array_splice($menu['children'], $i, 1);
}
}
}
}
}
public function setRedirects($context) {
$links = array(
'blueprintsdatasources' => 'extension/edui/datasources/',
'blueprintsevents' => 'extension/edui/events/',
'blueprintsutilities' => 'extension/edui/utilities/',
);
$callback = $this->_Parent->getPageCallback();
if ($callback['driver'] == 'blueprintscomponents') {
foreach ($links as $key => $value) {
if (file_exists(TMP . '/' . $key . '.tmp')) {
unlink(TMP . '/' . $key . '.tmp');
redirect(URL . '/symphony/' . $value);
}
}
}
else if (in_array($callback['driver'], array_keys($links))) {
$c = $this->_Parent->Page->Header->getChildren();
if ($callback['context'][2] && (in_array($callback['context'][2], array('saved', 'created')))) {
$c[0]->setValue(str_replace('blueprints/components/', $links[$callback['driver']], $c[0]->getValue()));
}
if ($_POST['action'] && array_key_exists('delete_custom', $_POST['action'])) {
touch(TMP . '/' . $callback['driver'] . '.tmp');
$_POST['action']['delete'] = $_POST['action']['delete_custom'];
if (method_exists($this->_Parent->Page, '__actionEdit'))
$this->_Parent->Page->__actionEdit();
else
$this->_Parent->Page->action();
}
for($i = count($c) - 1; $i > 0 ; --$i) {
$child = &$c[$i];
$attr = $child->getAttributes();
if ($child->getName() == 'div' && $attr['class'] && $attr['class'] == 'actions') {
$actions = $child->getChildren();
foreach($actions as &$a) {
if ($a->getValue() == __('Delete')) {
$a->setAttribute('name', 'action[delete_custom]');
}
}
}
}
}
}
/**
* Delegate handle that adds Custom Preference Fieldsets
* @param string $page
* @param array $context
*/
public function addCustomPreferenceFieldsets($context) {
// creates the field set
$fieldset = new XMLElement('fieldset');
$fieldset->setAttribute('class', 'settings');
$fieldset->appendChild(new XMLElement('legend', self::EXT_NAME));
// create a paragraph for short intructions
$p = new XMLElement('p', __('Define here options for EDUI extension'), array('class' => 'help'));
// append intro paragraph
$fieldset->appendChild($p);
// create a wrapper
$wrapper = new XMLElement('div');
//$wrapper->setAttribute('class', 'group');
// error wrapper
$err_wrapper = new XMLElement('div');
// append labels to field set
$wrapper->appendChild($this->generateField(self::SETTING_PINNED_DS, 'Pinned DS <em>seperated by ,</em>'));
$wrapper->appendChild($this->generateField(self::SETTING_PINNED_EV, 'Pinned Events <em>seperated by ,</em>'));
$wrapper->appendChild($this->generateField(self::SETTING_PINNED_UT, 'Pinned Utilities <em>seperated by ,</em>'));
// append field before errors
$err_wrapper->appendChild($wrapper);
// error management
if (count($this->errors) > 0) {
// set css and anchor
$err_wrapper->setAttribute('class', 'invalid');
$err_wrapper->setAttribute('id', 'error');
foreach ($this->errors as $error) {
// adds error message
$err = new XMLElement('p', $error);
// append to $wrapper
$err_wrapper->appendChild($err);
}
}
// wrapper into fieldset
$fieldset->appendChild($err_wrapper);
// adds the field set to the wrapper
$context['wrapper']->appendChild($fieldset);
}
/**
* Quick utility function to make a input field+label
* @param string $settingName
* @param string $textKey
*/
public function generateField($settingName, $textKey) {
// create the label and the input field
$label = Widget::Label();
$input = Widget::Input(
'settings[' . self::SETTING_GROUP . '][' . $settingName .']',
self::getConfigVal($settingName),
'text'
);
// set the input into the label
$label->setValue(__($textKey). ' ' . $input->generate());
return $label;
}
/**
*
* Utility function that returns settings from this extensions settings group
* @param string $key
*/
public static function getConfigVal($key) {
return Symphony::Configuration()->get($key, self::SETTING_GROUP);
}
/**
* Delegate handle that saves the preferences
* Saves settings and cleans the database acconding to the new settings
* @param array $context
*/
public function save($context){
self::saveOne($context, self::SETTING_PINNED_DS, false);
self::saveOne($context, self::SETTING_PINNED_EV, false);
self::saveOne($context, self::SETTING_PINNED_UT, true);
}
/**
*
* Save one parameter
* @param array $context
* @param string $key
* @param string $autoSave @optional
*/
public static function saveOne($context, $key, $autoSave=true){
// get the input
$input = $context['settings'][self::SETTING_GROUP][$key];
// set config (name, value, group)
Symphony::Configuration()->set($key, $input, self::SETTING_GROUP);
// save it
if ($autoSave) {
Administration::instance()->saveConfig();
}
}
}
?>