Conditions | 146 |
Paths | > 20000 |
Total Lines | 985 |
Code Lines | 667 |
Lines | 143 |
Ratio | 14.52 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
34 | public function __form() |
||
35 | { |
||
36 | $formHasErrors = (is_array($this->_errors) && !empty($this->_errors)); |
||
37 | |||
38 | if ($formHasErrors) { |
||
39 | $this->pageAlert( |
||
40 | __('An error occurred while processing this form. See below for details.'), |
||
41 | Alert::ERROR |
||
42 | ); |
||
43 | |||
44 | // These alerts are only valid if the form doesn't have errors |
||
45 | } elseif (isset($this->_context[2])) { |
||
46 | $time = Widget::Time(); |
||
47 | |||
48 | switch ($this->_context[2]) { |
||
49 | case 'saved': |
||
50 | $message = __('Data Source updated at %s.', array($time->generate())); |
||
51 | break; |
||
52 | case 'created': |
||
53 | $message = __('Data Source created at %s.', array($time->generate())); |
||
54 | } |
||
55 | |||
56 | $this->pageAlert( |
||
57 | $message |
||
|
|||
58 | . ' <a href="' . SYMPHONY_URL . '/blueprints/datasources/new/" accesskey="c">' |
||
59 | . __('Create another?') |
||
60 | . '</a> <a href="' . SYMPHONY_URL . '/blueprints/datasources/" accesskey="a">' |
||
61 | . __('View all Data Sources') |
||
62 | . '</a>', |
||
63 | Alert::SUCCESS |
||
64 | ); |
||
65 | } |
||
66 | |||
67 | $providers = Symphony::ExtensionManager()->getProvidersOf(iProvider::DATASOURCE); |
||
68 | $canonical_link = null; |
||
69 | $isEditing = false; |
||
70 | $about = $handle = null; |
||
71 | $fields = array( |
||
72 | 'name' => null, |
||
73 | 'source' => null, |
||
74 | 'filter'=> null, |
||
75 | 'required_url_param' => null, |
||
76 | 'negate_url_param' => null, |
||
77 | 'param' => null, |
||
78 | ); |
||
79 | |||
80 | if (isset($_POST['fields'])) { |
||
81 | $fields = $_POST['fields']; |
||
82 | |||
83 | if ( |
||
84 | !in_array($fields['source'], array('authors', 'navigation', 'static_xml')) |
||
85 | && !empty($fields['filter']) && is_array($fields['filter']) |
||
86 | ) { |
||
87 | $filters = array(); |
||
88 | foreach ($fields['filter'] as $f) { |
||
89 | foreach ($f as $key => $val) { |
||
90 | $filters[$key] = $val; |
||
91 | } |
||
92 | } |
||
93 | |||
94 | $fields['filter'][$fields['source']] = $filters; |
||
95 | } |
||
96 | |||
97 | if (!isset($fields['xml_elements']) || !is_array($fields['xml_elements'])) { |
||
98 | $fields['xml_elements'] = array(); |
||
99 | } |
||
100 | |||
101 | if ($this->_context[0] == 'edit') { |
||
102 | $isEditing = true; |
||
103 | } |
||
104 | } elseif ($this->_context[0] == 'edit') { |
||
105 | $isEditing = true; |
||
106 | $handle = $this->_context[1]; |
||
107 | $existing = DatasourceManager::create($handle, array(), false); |
||
108 | $order = isset($existing->dsParamORDER) ? stripslashes($existing->dsParamORDER) : 'asc'; |
||
109 | $canonical_link = '/blueprints/datasources/edit/' . $handle . '/'; |
||
110 | |||
111 | if (!$existing->allowEditorToParse()) { |
||
112 | redirect(SYMPHONY_URL . '/blueprints/datasources/info/' . $handle . '/'); |
||
113 | } |
||
114 | |||
115 | $about = General::array_map_recursive('stripslashes', $existing->about()); |
||
116 | $fields['name'] = $about['name']; |
||
117 | |||
118 | $fields['order'] = ($order == 'rand') ? 'random' : $order; |
||
119 | $fields['param'] = isset($existing->dsParamPARAMOUTPUT) ? array_map('stripslashes', $existing->dsParamPARAMOUTPUT) : null; |
||
120 | $fields['required_url_param'] = isset($existing->dsParamREQUIREDPARAM) ? stripslashes(trim($existing->dsParamREQUIREDPARAM)) : null; |
||
121 | $fields['negate_url_param'] = isset($existing->dsParamNEGATEPARAM) ? stripslashes(trim($existing->dsParamNEGATEPARAM)) : null; |
||
122 | |||
123 | if (isset($existing->dsParamINCLUDEDELEMENTS) && is_array($existing->dsParamINCLUDEDELEMENTS)) { |
||
124 | $fields['xml_elements'] = array_map('stripslashes', $existing->dsParamINCLUDEDELEMENTS); |
||
125 | } else { |
||
126 | $fields['xml_elements'] = array(); |
||
127 | } |
||
128 | |||
129 | $fields['sort'] = isset($existing->dsParamSORT) ? stripslashes($existing->dsParamSORT) : null; |
||
130 | $fields['paginate_results'] = isset($existing->dsParamPAGINATERESULTS) ? stripslashes($existing->dsParamPAGINATERESULTS) : 'yes'; |
||
131 | $fields['page_number'] = isset($existing->dsParamSTARTPAGE) ? stripslashes($existing->dsParamSTARTPAGE) : '1'; |
||
132 | $fields['group'] = isset($existing->dsParamGROUP) ? stripslashes($existing->dsParamGROUP) : null; |
||
133 | $fields['html_encode'] = isset($existing->dsParamHTMLENCODE) ? stripslashes($existing->dsParamHTMLENCODE) : 'no'; |
||
134 | $fields['associated_entry_counts'] = isset($existing->dsParamASSOCIATEDENTRYCOUNTS) ? stripslashes($existing->dsParamASSOCIATEDENTRYCOUNTS) : 'no'; |
||
135 | $fields['redirect_on_empty'] = isset($existing->dsParamREDIRECTONEMPTY) ? stripslashes($existing->dsParamREDIRECTONEMPTY) : 'no'; |
||
136 | $fields['redirect_on_forbidden'] = isset($existing->dsParamREDIRECTONFORBIDDEN) ? stripslashes($existing->dsParamREDIRECTONFORBIDDEN) : 'no'; |
||
137 | $fields['redirect_on_required'] = isset($existing->dsParamREDIRECTONREQUIRED) ? stripslashes($existing->dsParamREDIRECTONREQUIRED) : 'no'; |
||
138 | |||
139 | if (!isset($existing->dsParamFILTERS) || !is_array($existing->dsParamFILTERS)) { |
||
140 | $existing->dsParamFILTERS = array(); |
||
141 | } |
||
142 | |||
143 | if (!empty($existing->dsParamFILTERS)) { |
||
144 | $existing->dsParamFILTERS = array_map('stripslashes', $existing->dsParamFILTERS); |
||
145 | } |
||
146 | |||
147 | $fields['source'] = stripslashes($existing->getSource()); |
||
148 | |||
149 | $provided = false; |
||
150 | |||
151 | if (!empty($providers)) { |
||
152 | foreach ($providers as $providerClass => $provider) { |
||
153 | if ($fields['source'] == call_user_func(array($providerClass, 'getClass'))) { |
||
154 | $fields = array_merge($fields, $existing->settings()); |
||
155 | $provided = true; |
||
156 | break; |
||
157 | } |
||
158 | } |
||
159 | } |
||
160 | |||
161 | if ($provided === false) { |
||
162 | switch ($fields['source']) { |
||
163 | case 'authors': |
||
164 | $fields['filter']['author'] = $existing->dsParamFILTERS; |
||
165 | break; |
||
166 | case 'navigation': |
||
167 | $fields['filter']['navigation'] = $existing->dsParamFILTERS; |
||
168 | break; |
||
169 | case 'static_xml': |
||
170 | // Symphony 2.3+ |
||
171 | if (isset($existing->dsParamSTATIC)) { |
||
172 | $fields['static_xml'] = stripslashes(trim($existing->dsParamSTATIC)); |
||
173 | |||
174 | // Handle Symphony 2.2.2 to 2.3 DS's |
||
175 | // This is deprecated and will be removed in Symphony 3.0.0 |
||
176 | } elseif (isset($existing->dsSTATIC)) { |
||
177 | $fields['static_xml'] = stripslashes(trim($existing->dsSTATIC)); |
||
178 | |||
179 | // Handle pre Symphony 2.2.1 Static DS's |
||
180 | // This is deprecated and will be removed in Symphony 3.0.0 |
||
181 | } else { |
||
182 | $fields['static_xml'] = trim($existing->grab()); |
||
183 | } |
||
184 | break; |
||
185 | default: |
||
186 | $fields['filter'][$fields['source']] = $existing->dsParamFILTERS; |
||
187 | $fields['max_records'] = stripslashes($existing->dsParamLIMIT); |
||
188 | break; |
||
189 | } |
||
190 | } |
||
191 | } else { |
||
192 | $fields['max_records'] = '20'; |
||
193 | $fields['page_number'] = '1'; |
||
194 | $fields['order'] = 'desc'; |
||
195 | } |
||
196 | |||
197 | // Handle name on edited changes, or from reading an edited datasource |
||
198 | if (isset($about['name'])) { |
||
199 | $name = $about['name']; |
||
200 | } elseif (isset($fields['name'])) { |
||
201 | $name = $fields['name']; |
||
202 | } |
||
203 | |||
204 | $this->setPageType('form'); |
||
205 | $this->setTitle(__(($isEditing ? '%1$s – %2$s – %3$s' : '%2$s – %3$s'), array($name, __('Data Sources'), __('Symphony')))); |
||
206 | if ($canonical_link) { |
||
207 | $this->addElementToHead(new XMLElement('link', null, array( |
||
208 | 'rel' => 'canonical', |
||
209 | 'href' => SYMPHONY_URL . $canonical_link, |
||
210 | ))); |
||
211 | } |
||
212 | $this->appendSubheading(($isEditing ? $name : __('Untitled'))); |
||
213 | $this->insertBreadcrumbs(array( |
||
214 | Widget::Anchor(__('Data Sources'), SYMPHONY_URL . '/blueprints/datasources/'), |
||
215 | )); |
||
216 | |||
217 | // Sources |
||
218 | $sources = new XMLElement('div', null, array('class' => 'apply actions')); |
||
219 | $div = new XMLElement('div'); |
||
220 | $label = Widget::Label(__('Source'), null, 'apply-label-left'); |
||
221 | $sources->appendChild($label); |
||
222 | $sources->appendChild($div); |
||
223 | |||
224 | $sections = SectionManager::fetch(null, 'ASC', 'name'); |
||
225 | |||
226 | if (!is_array($sections)) { |
||
227 | $sections = array(); |
||
228 | } |
||
229 | |||
230 | $field_groups = array(); |
||
231 | |||
232 | foreach ($sections as $section) { |
||
233 | $field_groups[$section->get('id')] = array('fields' => $section->fetchFields(), 'section' => $section); |
||
234 | } |
||
235 | |||
236 | $options = array( |
||
237 | array('label' => __('System'), 'data-label' => 'system', 'options' => array( |
||
238 | array('authors', ($fields['source'] == 'authors'), __('Authors'), null, null, array('data-context' => 'authors')), |
||
239 | array('navigation', ($fields['source'] == 'navigation'), __('Navigation'), null, null, array('data-context' => 'navigation')), |
||
240 | )), |
||
241 | array('label' => __('Custom XML'), 'data-label' => 'custom-xml', 'options' => array( |
||
242 | array('static_xml', ($fields['source'] == 'static_xml'), __('Static XML'), null, null, array('data-context' => 'static-xml')), |
||
243 | )), |
||
244 | ); |
||
245 | |||
246 | // Loop over the datasource providers |
||
247 | if (!empty($providers)) { |
||
248 | $p = array('label' => __('From extensions'), 'data-label' => 'from_extensions', 'options' => array()); |
||
249 | |||
250 | foreach ($providers as $providerClass => $provider) { |
||
251 | $p['options'][] = array( |
||
252 | $providerClass, ($fields['source'] == $providerClass), $provider, null, null, array('data-context' => Lang::createHandle($provider)) |
||
253 | ); |
||
254 | } |
||
255 | |||
256 | $options[] = $p; |
||
257 | } |
||
258 | |||
259 | // Add Sections |
||
260 | if (is_array($sections) && !empty($sections)) { |
||
261 | array_unshift($options, array('label' => __('Sections'), 'data-label' => 'sections', 'options' => array())); |
||
262 | |||
263 | foreach ($sections as $s) { |
||
264 | $options[0]['options'][] = array($s->get('id'), ($fields['source'] == $s->get('id')), General::sanitize($s->get('name'))); |
||
265 | } |
||
266 | } |
||
267 | |||
268 | $div->appendChild(Widget::Select('source', $options, array('id' => 'ds-context'))); |
||
269 | $this->Context->prependChild($sources); |
||
270 | |||
271 | $this->Form->appendChild( |
||
272 | Widget::Input('fields[source]', null, 'hidden', array('id' => 'ds-source')) |
||
273 | ); |
||
274 | |||
275 | // Name |
||
276 | $fieldset = new XMLElement('fieldset'); |
||
277 | $fieldset->setAttribute('class', 'settings'); |
||
278 | $fieldset->appendChild(new XMLElement('legend', __('Essentials'))); |
||
279 | |||
280 | $group = new XMLElement('div'); |
||
281 | |||
282 | $label = Widget::Label(__('Name')); |
||
283 | $label->appendChild(Widget::Input('fields[name]', General::sanitize($fields['name']))); |
||
284 | |||
285 | if (isset($this->_errors['name'])) { |
||
286 | $group->appendChild(Widget::Error($label, $this->_errors['name'])); |
||
287 | } else { |
||
288 | $group->appendChild($label); |
||
289 | } |
||
290 | |||
291 | $fieldset->appendChild($group); |
||
292 | $this->Form->appendChild($fieldset); |
||
293 | |||
294 | // Conditions |
||
295 | $fieldset = new XMLElement('fieldset'); |
||
296 | $this->setContext($fieldset, array('sections', 'system')); |
||
297 | $fieldset->appendChild(new XMLElement('legend', __('Execution Conditions'))); |
||
298 | $p = new XMLElement('p', __('Leaving these fields empty will always execute the data source.')); |
||
299 | $p->setAttribute('class', 'help'); |
||
300 | $fieldset->appendChild($p); |
||
301 | |||
302 | $group = new XMLElement('div'); |
||
303 | $group->setAttribute('class', 'two columns'); |
||
304 | |||
305 | $label = Widget::Label(__('Required Parameter')); |
||
306 | $label->setAttribute('class', 'column ds-param'); |
||
307 | $label->appendChild(new XMLElement('i', __('Optional'))); |
||
308 | $input = Widget::Input('fields[required_url_param]', General::sanitize(trim($fields['required_url_param'])), 'text', array( |
||
309 | 'placeholder' => __('$param'), |
||
310 | 'data-search-types' => 'parameters', |
||
311 | 'data-trigger' => '$' |
||
312 | )); |
||
313 | $label->appendChild($input); |
||
314 | $group->appendChild($label); |
||
315 | |||
316 | $label = Widget::Label(__('Forbidden Parameter')); |
||
317 | $label->setAttribute('class', 'column ds-param'); |
||
318 | $label->appendChild(new XMLElement('i', __('Optional'))); |
||
319 | $input = Widget::Input('fields[negate_url_param]', General::sanitize(trim($fields['negate_url_param'])), 'text', array( |
||
320 | 'placeholder' => __('$param'), |
||
321 | 'data-search-types' => 'parameters', |
||
322 | 'data-trigger' => '$' |
||
323 | )); |
||
324 | $label->appendChild($input); |
||
325 | $group->appendChild($label); |
||
326 | |||
327 | $fieldset->appendChild($group); |
||
328 | |||
329 | $this->Form->appendChild($fieldset); |
||
330 | |||
331 | $fieldset = new XMLElement('fieldset'); |
||
332 | $this->setContext($fieldset, array('sections', 'system')); |
||
333 | $fieldset->appendChild(new XMLElement('legend', __('Error Conditions'))); |
||
334 | $p = new XMLElement('p', __('Meeting one of these conditions will cause a <code>404 Not Found</code> response.')); |
||
335 | $p->setAttribute('class', 'help'); |
||
336 | $fieldset->appendChild($p); |
||
337 | $group = new XMLElement('div'); |
||
338 | |||
339 | $label = Widget::Checkbox('fields[redirect_on_required]', $fields['redirect_on_required'], __('The required parameter is missing')); |
||
340 | $group->appendChild($label); |
||
341 | |||
342 | $label = Widget::Checkbox('fields[redirect_on_forbidden]', $fields['redirect_on_forbidden'], __('The forbidden parameter is present')); |
||
343 | $group->appendChild($label); |
||
344 | |||
345 | $label = Widget::Checkbox('fields[redirect_on_empty]', $fields['redirect_on_empty'], __('No results are found')); |
||
346 | $group->appendChild($label); |
||
347 | |||
348 | $fieldset->appendChild($group); |
||
349 | |||
350 | $this->Form->appendChild($fieldset); |
||
351 | |||
352 | // Filters |
||
353 | $fieldset = new XMLElement('fieldset'); |
||
354 | $this->setContext($fieldset, array('sections', 'system')); |
||
355 | $fieldset->appendChild(new XMLElement('legend', __('Filters'))); |
||
356 | $p = new XMLElement('p', |
||
357 | __('Use %s syntax to filter by page parameters. A default value can be set using %s.', array( |
||
358 | '<code>{' . __('$param') . '}</code>', |
||
359 | '<code>{' . __('$param:default') . '}</code>' |
||
360 | )) |
||
361 | ); |
||
362 | $p->setAttribute('class', 'help'); |
||
363 | $fieldset->appendChild($p); |
||
364 | |||
365 | foreach ($field_groups as $section_id => $section_data) { |
||
366 | $div = new XMLElement('div'); |
||
367 | $div->setAttribute('class', 'contextual frame filters-duplicator'); |
||
368 | $div->setAttribute('data-context', 'section-' . $section_id); |
||
369 | $div->setAttribute('data-interactive', 'data-interactive'); |
||
370 | |||
371 | $ol = new XMLElement('ol'); |
||
372 | $ol->setAttribute('class', 'suggestable'); |
||
373 | $ol->setAttribute('data-interactive', 'data-interactive'); |
||
374 | $ol->setAttribute('data-add', __('Add filter')); |
||
375 | $ol->setAttribute('data-remove', __('Remove filter')); |
||
376 | |||
377 | // Add system:id filter |
||
378 | if ( |
||
379 | isset($fields['filter'][$section_id]['system:id']) |
||
380 | || isset($fields['filter'][$section_id]['id']) |
||
381 | ) { |
||
382 | $id = isset($fields['filter'][$section_id]['system:id']) |
||
383 | ? $fields['filter'][$section_id]['system:id'] |
||
384 | : $fields['filter'][$section_id]['id']; |
||
385 | |||
386 | $li = new XMLElement('li'); |
||
387 | $li->setAttribute('class', 'unique'); |
||
388 | $li->setAttribute('data-type', 'system:id'); |
||
389 | $li->appendChild(new XMLElement('header', '<h4>' . __('System ID') . '</h4>')); |
||
390 | $label = Widget::Label(__('Value')); |
||
391 | $input = Widget::Input('fields[filter]['.$section_id.'][system:id]', General::sanitize($id)); |
||
392 | $input->setAttribute('data-search-types', 'parameters'); |
||
393 | $input->setAttribute('data-trigger', '{$'); |
||
394 | $label->appendChild($input); |
||
395 | $li->appendChild($label); |
||
396 | $ol->appendChild($li); |
||
397 | } |
||
398 | |||
399 | $li = new XMLElement('li'); |
||
400 | $li->setAttribute('class', 'unique template'); |
||
401 | $li->setAttribute('data-type', 'system:id'); |
||
402 | $li->appendChild(new XMLElement('header', '<h4>' . __('System ID') . '</h4>')); |
||
403 | $label = Widget::Label(__('Value')); |
||
404 | $input = Widget::Input('fields[filter]['.$section_id.'][system:id]', General::sanitize($id)); |
||
405 | $input->setAttribute('data-search-types', 'parameters'); |
||
406 | $input->setAttribute('data-trigger', '{$'); |
||
407 | $label->appendChild($input); |
||
408 | $li->appendChild($label); |
||
409 | $ol->appendChild($li); |
||
410 | |||
411 | // Add system:date filter |
||
412 | if ( |
||
413 | isset($fields['filter'][$section_id]['system:creation-date']) |
||
414 | || isset($fields['filter'][$section_id]['system:date']) |
||
415 | ) { |
||
416 | $creation_date = isset($fields['filter'][$section_id]['system:creation-date']) |
||
417 | ? $fields['filter'][$section_id]['system:creation-date'] |
||
418 | : $fields['filter'][$section_id]['system:date']; |
||
419 | |||
420 | $li = new XMLElement('li'); |
||
421 | $li->setAttribute('class', 'unique'); |
||
422 | $li->setAttribute('data-type', 'system:creation-date'); |
||
423 | $li->appendChild(new XMLElement('header', '<h4>' . __('System Creation Date') . '</h4>')); |
||
424 | $label = Widget::Label(__('Value')); |
||
425 | $input = Widget::Input('fields[filter]['.$section_id.'][system:creation-date]', General::sanitize($creation_date)); |
||
426 | $input->setAttribute('data-search-types', 'parameters'); |
||
427 | $input->setAttribute('data-trigger', '{$'); |
||
428 | $label->appendChild($input); |
||
429 | $li->appendChild($label); |
||
430 | $ol->appendChild($li); |
||
431 | } |
||
432 | |||
433 | $li = new XMLElement('li'); |
||
434 | $li->setAttribute('class', 'unique template'); |
||
435 | $li->setAttribute('data-type', 'system:creation-date'); |
||
436 | $li->appendChild(new XMLElement('header', '<h4>' . __('System Creation Date') . '</h4>')); |
||
437 | $label = Widget::Label(__('Value')); |
||
438 | $input = Widget::Input('fields[filter]['.$section_id.'][system:creation-date]'); |
||
439 | $input->setAttribute('data-search-types', 'parameters'); |
||
440 | $input->setAttribute('data-trigger', '{$'); |
||
441 | $label->appendChild($input); |
||
442 | $li->appendChild($label); |
||
443 | $ol->appendChild($li); |
||
444 | |||
445 | if (isset($fields['filter'][$section_id]['system:modification-date'])) { |
||
446 | $li = new XMLElement('li'); |
||
447 | $li->setAttribute('class', 'unique'); |
||
448 | $li->setAttribute('data-type', 'system:modification-date'); |
||
449 | $li->appendChild(new XMLElement('header', '<h4>' . __('System Modification Date') . '</h4>')); |
||
450 | $label = Widget::Label(__('Value')); |
||
451 | $input = Widget::Input('fields[filter]['.$section_id.'][system:modification-date]', General::sanitize($fields['filter'][$section_id]['system:modification-date'])); |
||
452 | $input->setAttribute('data-search-types', 'parameters'); |
||
453 | $input->setAttribute('data-trigger', '{$'); |
||
454 | $label->appendChild($input); |
||
455 | $li->appendChild($label); |
||
456 | $ol->appendChild($li); |
||
457 | } |
||
458 | |||
459 | $li = new XMLElement('li'); |
||
460 | $li->setAttribute('class', 'unique template'); |
||
461 | $li->setAttribute('data-type', 'system:modification-date'); |
||
462 | $li->appendChild(new XMLElement('header', '<h4>' . __('System Modification Date') . '</h4>')); |
||
463 | $label = Widget::Label(__('Value')); |
||
464 | $input = Widget::Input('fields[filter]['.$section_id.'][system:modification-date]'); |
||
465 | $input->setAttribute('data-search-types', 'parameters'); |
||
466 | $input->setAttribute('data-trigger', '{$'); |
||
467 | $label->appendChild($input); |
||
468 | $li->appendChild($label); |
||
469 | $ol->appendChild($li); |
||
470 | |||
471 | if (is_array($section_data['fields']) && !empty($section_data['fields'])) { |
||
472 | foreach ($section_data['fields'] as $field) { |
||
473 | if (!$field->canFilter()) { |
||
474 | continue; |
||
475 | } |
||
476 | |||
477 | if (isset($fields['filter'][$section_id], $fields['filter'][$section_id][$field->get('id')])) { |
||
478 | $wrapper = new XMLElement('li'); |
||
479 | $wrapper->setAttribute('class', 'unique'); |
||
480 | $wrapper->setAttribute('data-type', $field->get('element_name')); |
||
481 | $errors = isset($this->_errors[$field->get('id')]) |
||
482 | ? $this->_errors[$field->get('id')] |
||
483 | : array(); |
||
484 | |||
485 | $field->displayDatasourceFilterPanel($wrapper, $fields['filter'][$section_id][$field->get('id')], $errors, $section_id); |
||
486 | $ol->appendChild($wrapper); |
||
487 | } |
||
488 | |||
489 | $wrapper = new XMLElement('li'); |
||
490 | $wrapper->setAttribute('class', 'unique template'); |
||
491 | $wrapper->setAttribute('data-type', $field->get('element_name')); |
||
492 | $field->displayDatasourceFilterPanel($wrapper, null, null, $section_id); |
||
493 | $ol->appendChild($wrapper); |
||
494 | } |
||
495 | } |
||
496 | |||
497 | $div->appendChild($ol); |
||
498 | |||
499 | $fieldset->appendChild($div); |
||
500 | } |
||
501 | |||
502 | $div = new XMLElement('div'); |
||
503 | $div->setAttribute('class', 'contextual frame filters-duplicator'); |
||
504 | $div->setAttribute('data-context', 'authors'); |
||
505 | $div->setAttribute('data-interactive', 'data-interactive'); |
||
506 | |||
507 | $ol = new XMLElement('ol'); |
||
508 | $ol->setAttribute('class', 'suggestable'); |
||
509 | $ol->setAttribute('data-interactive', 'data-interactive'); |
||
510 | $ol->setAttribute('data-add', __('Add filter')); |
||
511 | $ol->setAttribute('data-remove', __('Remove filter')); |
||
512 | |||
513 | if (!isset($fields['filter']['author'])) { |
||
514 | $fields['filter']['author'] = array( |
||
515 | 'id' => null, |
||
516 | 'username' => null, |
||
517 | 'first_name' => null, |
||
518 | 'last_name' => null, |
||
519 | 'email' => null, |
||
520 | 'user_type' => null |
||
521 | ); |
||
522 | } |
||
523 | |||
524 | $this->__appendAuthorFilter($ol, __('ID'), 'id', $fields['filter']['author']['id'], (!isset($fields['filter']['author']['id']))); |
||
525 | $this->__appendAuthorFilter($ol, __('Username'), 'username', $fields['filter']['author']['username'], (!isset($fields['filter']['author']['username']))); |
||
526 | $this->__appendAuthorFilter($ol, __('First Name'), 'first_name', $fields['filter']['author']['first_name'], (!isset($fields['filter']['author']['first_name']))); |
||
527 | $this->__appendAuthorFilter($ol, __('Last Name'), 'last_name', $fields['filter']['author']['last_name'], (!isset($fields['filter']['author']['last_name']))); |
||
528 | $this->__appendAuthorFilter($ol, __('Email'), 'email', $fields['filter']['author']['email'], (!isset($fields['filter']['author']['email']))); |
||
529 | $this->__appendAuthorFilter($ol, __('User Type'), 'user_type', $fields['filter']['author']['user_type'], (!isset($fields['filter']['author']['user_type']))); |
||
530 | |||
531 | $div->appendChild($ol); |
||
532 | |||
533 | $fieldset->appendChild($div); |
||
534 | |||
535 | $div = new XMLElement('div'); |
||
536 | $div->setAttribute('class', 'contextual frame filters-duplicator'); |
||
537 | $div->setAttribute('data-context', 'navigation'); |
||
538 | $div->setAttribute('data-interactive', 'data-interactive'); |
||
539 | |||
540 | $ol = new XMLElement('ol'); |
||
541 | $ol->setAttribute('class', 'suggestable'); |
||
542 | $ol->setAttribute('data-interactive', 'data-interactive'); |
||
543 | $ol->setAttribute('data-add', __('Add filter')); |
||
544 | $ol->setAttribute('data-remove', __('Remove filter')); |
||
545 | |||
546 | $ul = new XMLElement('ul'); |
||
547 | $ul->setAttribute('class', 'tags'); |
||
548 | $ul->setAttribute('data-interactive', 'data-interactive'); |
||
549 | |||
550 | $pages = PageManager::fetch(false, array('*'), array(), 'title ASC'); |
||
551 | |||
552 | foreach ($pages as $page) { |
||
553 | $ul->appendChild(new XMLElement('li', preg_replace('/\/{2,}/i', '/', '/' . $page['path'] . '/' . $page['handle']))); |
||
554 | } |
||
555 | |||
556 | if (isset($fields['filter']['navigation']['parent'])) { |
||
557 | $li = new XMLElement('li'); |
||
558 | $li->setAttribute('class', 'unique'); |
||
559 | $li->setAttribute('data-type', 'parent'); |
||
560 | $li->appendChild(new XMLElement('header', '<h4>' . __('Parent Page') . '</h4>')); |
||
561 | $label = Widget::Label(__('Value')); |
||
562 | $label->appendChild(Widget::Input('fields[filter][navigation][parent]', General::sanitize($fields['filter']['navigation']['parent']))); |
||
563 | $li->appendChild($label); |
||
564 | $li->appendChild($ul); |
||
565 | $ol->appendChild($li); |
||
566 | } |
||
567 | |||
568 | $li = new XMLElement('li'); |
||
569 | $li->setAttribute('class', 'unique template'); |
||
570 | $li->setAttribute('data-type', 'parent'); |
||
571 | $li->appendChild(new XMLElement('header', '<h4>' . __('Parent Page') . '</h4>')); |
||
572 | $label = Widget::Label(__('Value')); |
||
573 | $label->appendChild(Widget::Input('fields[filter][navigation][parent]')); |
||
574 | $li->appendChild($label); |
||
575 | $li->appendChild($ul); |
||
576 | $ol->appendChild($li); |
||
577 | |||
578 | $ul = new XMLElement('ul'); |
||
579 | $ul->setAttribute('class', 'tags'); |
||
580 | $ul->setAttribute('data-interactive', 'data-interactive'); |
||
581 | |||
582 | if ($types = PageManager::fetchAvailablePageTypes()) { |
||
583 | foreach ($types as $type) { |
||
584 | $ul->appendChild(new XMLElement('li', $type)); |
||
585 | } |
||
586 | } |
||
587 | |||
588 | if (isset($fields['filter']['navigation']['type'])) { |
||
589 | $li = new XMLElement('li'); |
||
590 | $li->setAttribute('class', 'unique'); |
||
591 | $li->setAttribute('data-type', 'type'); |
||
592 | $li->appendChild(new XMLElement('header', '<h4>' . __('Page Type') . '</h4>')); |
||
593 | $label = Widget::Label(__('Value')); |
||
594 | $label->appendChild(Widget::Input('fields[filter][navigation][type]', General::sanitize($fields['filter']['navigation']['type']))); |
||
595 | $li->appendChild($label); |
||
596 | $li->appendChild($ul); |
||
597 | $ol->appendChild($li); |
||
598 | } |
||
599 | |||
600 | $li = new XMLElement('li'); |
||
601 | $li->setAttribute('class', 'unique template'); |
||
602 | $li->appendChild(new XMLElement('header', '<h4>' . __('Page Type') . '</h4>')); |
||
603 | $li->setAttribute('data-type', 'type'); |
||
604 | $label = Widget::Label(__('Value')); |
||
605 | $label->appendChild(Widget::Input('fields[filter][navigation][type]')); |
||
606 | $li->appendChild($label); |
||
607 | $li->appendChild($ul); |
||
608 | $ol->appendChild($li); |
||
609 | |||
610 | $div->appendChild($ol); |
||
611 | |||
612 | $fieldset->appendChild($div); |
||
613 | $this->Form->appendChild($fieldset); |
||
614 | |||
615 | // Sorting |
||
616 | $fieldset = new XMLElement('fieldset'); |
||
617 | $this->setContext($fieldset, array('sections', 'system')); |
||
618 | $fieldset->appendChild(new XMLElement('legend', __('Sorting'))); |
||
619 | |||
620 | $p = new XMLElement('p', |
||
621 | __('Use %s syntax to order by page parameters.', array( |
||
622 | '<code>{' . __('$param') . '}</code>' |
||
623 | )) |
||
624 | ); |
||
625 | $p->setAttribute('class', 'help'); |
||
626 | $fieldset->appendChild($p); |
||
627 | |||
628 | $div = new XMLElement('div'); |
||
629 | |||
630 | $label = Widget::Label(__('Sort By')); |
||
631 | |||
632 | $options = array( |
||
633 | array('label' => __('Authors'), 'data-label' => 'authors', 'options' => array( |
||
634 | array('id', ($fields['source'] == 'authors' && $fields['sort'] == 'id'), __('Author ID')), |
||
635 | array('username', ($fields['source'] == 'authors' && $fields['sort'] == 'username'), __('Username')), |
||
636 | array('first-name', ($fields['source'] == 'authors' && $fields['sort'] == 'first-name'), __('First Name')), |
||
637 | array('last-name', ($fields['source'] == 'authors' && $fields['sort'] == 'last-name'), __('Last Name')), |
||
638 | array('email', ($fields['source'] == 'authors' && $fields['sort'] == 'email'), __('Email')), |
||
639 | array('status', ($fields['source'] == 'authors' && $fields['sort'] == 'status'), __('Status')), |
||
640 | ) |
||
641 | ), |
||
642 | |||
643 | array('label' => __('Navigation'), 'data-label' => 'navigation', 'options' => array( |
||
644 | array('id', ($fields['source'] == 'navigation' && $fields['sort'] == 'id'), __('Page ID')), |
||
645 | array('handle', ($fields['source'] == 'navigation' && $fields['sort'] == 'handle'), __('Handle')), |
||
646 | array('sortorder', ($fields['source'] == 'navigation' && $fields['sort'] == 'sortorder'), __('Sort Order')), |
||
647 | ) |
||
648 | ), |
||
649 | ); |
||
650 | |||
651 | foreach ($field_groups as $section_id => $section_data) { |
||
652 | $optgroup = array('label' => General::sanitize($section_data['section']->get('name')), 'data-label' => 'section-' . $section_data['section']->get('id'), 'options' => array( |
||
653 | array('system:id', ($fields['source'] == $section_id && $fields['sort'] == 'system:id'), __('System ID')), |
||
654 | array('system:creation-date', ($fields['source'] == $section_id && ($fields['sort'] == 'system:creation-date' || $fields['sort'] == 'system:date')), __('System Creation Date')), |
||
655 | array('system:modification-date', ($fields['source'] == $section_id && $fields['sort'] == 'system:modification-date'), __('System Modification Date')), |
||
656 | )); |
||
657 | |||
658 | if (is_array($section_data['fields']) && !empty($section_data['fields'])) { |
||
659 | foreach ($section_data['fields'] as $input) { |
||
660 | if (!$input->isSortable()) { |
||
661 | continue; |
||
662 | } |
||
663 | |||
664 | $optgroup['options'][] = array( |
||
665 | $input->get('element_name'), |
||
666 | ($fields['source'] == $section_id && $input->get('element_name') == $fields['sort']), |
||
667 | $input->get('label') |
||
668 | ); |
||
669 | } |
||
670 | } |
||
671 | |||
672 | $options[] = $optgroup; |
||
673 | } |
||
674 | |||
675 | $label->appendChild(Widget::Select('fields[sort]', $options)); |
||
676 | $div->appendChild($label); |
||
677 | |||
678 | $label = Widget::Label(__('Sort Order')); |
||
679 | $label->setAttribute('class', 'ds-param'); |
||
680 | |||
681 | $input = Widget::Input('fields[order]', General::sanitize(trim($fields['order'])), 'text', array( |
||
682 | 'placeholder' => __('{$param}'), |
||
683 | 'data-search-types' => 'parameters', |
||
684 | 'data-trigger' => '{$' |
||
685 | )); |
||
686 | $label->appendChild($input); |
||
687 | $div->appendChild($label); |
||
688 | |||
689 | $orders = new XMLElement('ul'); |
||
690 | $orders->setAttribute('class', 'tags singular'); |
||
691 | $orders->setAttribute('data-interactive', 'data-interactive'); |
||
692 | $orders->appendChild(new XMLElement('li', 'asc')); |
||
693 | $orders->appendChild(new XMLElement('li', 'desc')); |
||
694 | $orders->appendChild(new XMLElement('li', 'random')); |
||
695 | $div->appendChild($orders); |
||
696 | |||
697 | $fieldset->appendChild($div); |
||
698 | $this->Form->appendChild($fieldset); |
||
699 | |||
700 | // Grouping |
||
701 | $fieldset = new XMLElement('fieldset'); |
||
702 | $this->setContext($fieldset, array('sections', 'authors')); |
||
703 | $fieldset->appendChild(new XMLElement('legend', __('Grouping'))); |
||
704 | |||
705 | $label = Widget::Label(__('Group By')); |
||
706 | $options = array( |
||
707 | array('', null, __('None')), |
||
708 | ); |
||
709 | |||
710 | foreach ($field_groups as $section_id => $section_data) { |
||
711 | $optgroup = array('label' => $section_data['section']->get('name'), 'data-label' => 'section-' . $section_data['section']->get('id'), 'options' => array()); |
||
712 | |||
713 | if (is_array($section_data['fields']) && !empty($section_data['fields'])) { |
||
714 | foreach ($section_data['fields'] as $input) { |
||
715 | if (!$input->allowDatasourceOutputGrouping()) { |
||
716 | continue; |
||
717 | } |
||
718 | |||
719 | $optgroup['options'][] = array($input->get('id'), ($fields['source'] == $section_id && $fields['group'] == $input->get('id')), $input->get('label')); |
||
720 | } |
||
721 | } |
||
722 | |||
723 | $options[] = $optgroup; |
||
724 | } |
||
725 | |||
726 | $label->appendChild(Widget::Select('fields[group]', $options)); |
||
727 | $fieldset->appendChild($label); |
||
728 | |||
729 | $this->Form->appendChild($fieldset); |
||
730 | |||
731 | // Pagination |
||
732 | $fieldset = new XMLElement('fieldset'); |
||
733 | $this->setContext($fieldset, array('sections')); |
||
734 | $fieldset->appendChild(new XMLElement('legend', __('Pagination'))); |
||
735 | |||
736 | $p = new XMLElement('p', |
||
737 | __('Use %s syntax to limit by page parameters.', array( |
||
738 | '<code>{' . __('$param') . '}</code>' |
||
739 | )) |
||
740 | ); |
||
741 | $p->setAttribute('class', 'help'); |
||
742 | $fieldset->appendChild($p); |
||
743 | |||
744 | $group = new XMLElement('div'); |
||
745 | $group->setAttribute('class', 'two columns pagination'); |
||
746 | |||
747 | $label = Widget::Label(__('Entries per Page')); |
||
748 | $label->setAttribute('class', 'column ds-param'); |
||
749 | $input = Widget::Input('fields[max_records]', isset($fields['max_records']) ? General::sanitize(trim($fields['max_records'])) : '10', 'text', array( |
||
750 | 'placeholder' => __('{$param}'), |
||
751 | 'data-search-types' => 'parameters', |
||
752 | 'data-trigger' => '{$' |
||
753 | )); |
||
754 | $label->appendChild($input); |
||
755 | if (isset($this->_errors['max_records'])) { |
||
756 | $group->appendChild(Widget::Error($label, $this->_errors['max_records'])); |
||
757 | } else { |
||
758 | $group->appendChild($label); |
||
759 | } |
||
760 | |||
761 | $label = Widget::Label(__('Page Number')); |
||
762 | $label->setAttribute('class', 'column ds-param'); |
||
763 | $input = Widget::Input('fields[page_number]', General::sanitize(trim($fields['page_number'])), 'text', array( |
||
764 | 'placeholder' => __('{$param}'), |
||
765 | 'data-search-types' => 'parameters', |
||
766 | 'data-trigger' => '{$' |
||
767 | )); |
||
768 | $label->appendChild($input); |
||
769 | if (isset($this->_errors['page_number'])) { |
||
770 | $group->appendChild(Widget::Error($label, $this->_errors['page_number'])); |
||
771 | } else { |
||
772 | $group->appendChild($label); |
||
773 | } |
||
774 | |||
775 | $fieldset->appendChild($group); |
||
776 | |||
777 | $label = Widget::Checkbox('fields[paginate_results]', $fields['paginate_results'], __('Enable pagination')); |
||
778 | $fieldset->appendChild($label); |
||
779 | $this->Form->appendChild($fieldset); |
||
780 | |||
781 | // Content |
||
782 | $fieldset = new XMLElement('fieldset'); |
||
783 | $this->setContext($fieldset, array('sections', 'authors')); |
||
784 | $fieldset->appendChild(new XMLElement('legend', __('Content'))); |
||
785 | |||
786 | // XML |
||
787 | $group = new XMLElement('div', null, array('class' => 'two columns')); |
||
788 | |||
789 | $label = Widget::Label(__('Included Elements')); |
||
790 | $label->setAttribute('class', 'column'); |
||
791 | |||
792 | $options = array( |
||
793 | array('label' => __('Authors'), 'data-label' => 'authors', 'options' => array( |
||
794 | array('username', ($fields['source'] == 'authors' && in_array('username', $fields['xml_elements'])), 'username'), |
||
795 | array('name', ($fields['source'] == 'authors' && in_array('name', $fields['xml_elements'])), 'name'), |
||
796 | array('email', ($fields['source'] == 'authors' && in_array('email', $fields['xml_elements'])), 'email'), |
||
797 | array('author-token', ($fields['source'] == 'authors' && in_array('author-token', $fields['xml_elements'])), 'author-token'), |
||
798 | array('default-area', ($fields['source'] == 'authors' && in_array('default-area', $fields['xml_elements'])), 'default-area'), |
||
799 | )), |
||
800 | ); |
||
801 | |||
802 | foreach ($field_groups as $section_id => $section_data) { |
||
803 | $optgroup = array( |
||
804 | 'label' => General::sanitize($section_data['section']->get('name')), |
||
805 | 'data-label' => 'section-' . $section_data['section']->get('id'), |
||
806 | 'options' => array( |
||
807 | array( |
||
808 | 'system:pagination', |
||
809 | ($fields['source'] == $section_id && in_array('system:pagination', $fields['xml_elements'])), |
||
810 | 'system: pagination' |
||
811 | ), |
||
812 | array( |
||
813 | 'system:date', |
||
814 | ($fields['source'] == $section_id && in_array('system:date', $fields['xml_elements'])), |
||
815 | 'system: date' |
||
816 | ) |
||
817 | ) |
||
818 | ); |
||
819 | |||
820 | if (is_array($section_data['fields']) && !empty($section_data['fields'])) { |
||
821 | foreach ($section_data['fields'] as $field) { |
||
822 | $elements = $field->fetchIncludableElements(); |
||
823 | |||
824 | if (is_array($elements) && !empty($elements)) { |
||
825 | foreach ($elements as $name) { |
||
826 | $selected = false; |
||
827 | |||
828 | if ($fields['source'] == $section_id && in_array($name, $fields['xml_elements'])) { |
||
829 | $selected = true; |
||
830 | } |
||
831 | |||
832 | $optgroup['options'][] = array($name, $selected, $name); |
||
833 | } |
||
834 | } |
||
835 | } |
||
836 | } |
||
837 | |||
838 | $options[] = $optgroup; |
||
839 | } |
||
840 | |||
841 | $label->appendChild(Widget::Select('fields[xml_elements][]', $options, array('multiple' => 'multiple'))); |
||
842 | $group->appendChild($label); |
||
843 | |||
844 | // Support multiple parameters |
||
845 | if (!isset($fields['param'])) { |
||
846 | $fields['param'] = array(); |
||
847 | } elseif (!is_array($fields['param'])) { |
||
848 | $fields['param'] = array($fields['param']); |
||
849 | } |
||
850 | |||
851 | $label = Widget::Label(__('Parameters')); |
||
852 | $label->setAttribute('class', 'column'); |
||
853 | $prefix = '$ds-' . (isset($this->_context[1]) ? Lang::createHandle($fields['name']) : __('untitled')) . '.'; |
||
854 | |||
855 | $options = array( |
||
856 | array('label' => __('Authors'), 'data-label' => 'authors', 'options' => array()) |
||
857 | ); |
||
858 | |||
859 | foreach (array('id', 'username', 'name', 'email', 'user_type') as $p) { |
||
860 | $options[0]['options'][] = array( |
||
861 | $p, |
||
862 | ($fields['source'] == 'authors' && in_array($p, $fields['param'])), |
||
863 | $prefix . $p, |
||
864 | null, |
||
865 | null, |
||
866 | array( |
||
867 | 'data-handle' => $p |
||
868 | ) |
||
869 | ); |
||
870 | } |
||
871 | |||
872 | foreach ($field_groups as $section_id => $section_data) { |
||
873 | $optgroup = array('label' => $section_data['section']->get('name'), 'data-label' => 'section-' . $section_data['section']->get('id'), 'options' => array()); |
||
874 | |||
875 | foreach (array('id', 'creation-date', 'modification-date', 'author') as $p) { |
||
876 | $option = array( |
||
877 | 'system:' . $p, |
||
878 | ($fields['source'] == $section_id && in_array('system:' . $p, $fields['param'])), |
||
879 | $prefix . 'system-' . $p, |
||
880 | null, |
||
881 | null, |
||
882 | array( |
||
883 | 'data-handle' => 'system-' . $p |
||
884 | ) |
||
885 | ); |
||
886 | |||
887 | // Handle 'system:date' as an output paramater (backwards compatibility) |
||
888 | if ($p === 'creation-date') { |
||
889 | if ($fields['source'] == $section_id && in_array('system:date', $fields['param'])) { |
||
890 | $option[1] = true; |
||
891 | } |
||
892 | } |
||
893 | |||
894 | $optgroup['options'][] = $option; |
||
895 | } |
||
896 | |||
897 | if (is_array($section_data['fields']) && !empty($section_data['fields'])) { |
||
898 | foreach ($section_data['fields'] as $input) { |
||
899 | if (!$input->allowDatasourceParamOutput()) { |
||
900 | continue; |
||
901 | } |
||
902 | |||
903 | $optgroup['options'][] = array( |
||
904 | $input->get('element_name'), |
||
905 | ($fields['source'] == $section_id && in_array($input->get('element_name'), $fields['param'])), |
||
906 | $prefix . $input->get('element_name'), |
||
907 | null, |
||
908 | null, |
||
909 | array( |
||
910 | 'data-handle' => $input->get('element_name') |
||
911 | ) |
||
912 | ); |
||
913 | } |
||
914 | } |
||
915 | |||
916 | $options[] = $optgroup; |
||
917 | } |
||
918 | |||
919 | $label->appendChild(Widget::Select('fields[param][]', $options, array('multiple' => 'multiple'))); |
||
920 | $group->appendChild($label); |
||
921 | |||
922 | $fieldset->appendChild($group); |
||
923 | |||
924 | // Associations |
||
925 | $label = Widget::Checkbox('fields[associated_entry_counts]', $fields['associated_entry_counts'], __('Include a count of entries in associated sections')); |
||
926 | $this->setContext($label, array('sections')); |
||
927 | $fieldset->appendChild($label); |
||
928 | |||
929 | // Encoding |
||
930 | $label = Widget::Checkbox('fields[html_encode]', $fields['html_encode'], __('HTML-encode text')); |
||
931 | $this->setContext($label, array('sections')); |
||
932 | $fieldset->appendChild($label); |
||
933 | |||
934 | $this->Form->appendChild($fieldset); |
||
935 | |||
936 | // Static XML |
||
937 | if (!isset($fields['static_xml'])) { |
||
938 | $fields['static_xml'] = null; |
||
939 | } |
||
940 | |||
941 | $fieldset = new XMLElement('fieldset'); |
||
942 | $this->setContext($fieldset, array('static-xml')); |
||
943 | $fieldset->appendChild(new XMLElement('legend', __('Static XML'))); |
||
944 | $p = new XMLElement('p', __('Enter valid XML, exclude XML declaration')); |
||
945 | $p->setAttribute('class', 'help'); |
||
946 | $fieldset->appendChild($p); |
||
947 | |||
948 | $label = Widget::Label(); |
||
949 | $static_xml = htmlspecialchars( |
||
950 | $fields['static_xml'], |
||
951 | ENT_XML1|ENT_COMPAT, |
||
952 | 'UTF-8' |
||
953 | ); |
||
954 | $label->appendChild(Widget::Textarea('fields[static_xml]', 12, 50, $static_xml, array('class' => 'code', 'placeholder' => '<static>content</static>'))); |
||
955 | |||
956 | if (isset($this->_errors['static_xml'])) { |
||
957 | $fieldset->appendChild(Widget::Error($label, $this->_errors['static_xml'])); |
||
958 | } else { |
||
959 | $fieldset->appendChild($label); |
||
960 | } |
||
961 | |||
962 | $this->Form->appendChild($fieldset); |
||
963 | |||
964 | // Connections |
||
965 | $fieldset = new XMLElement('fieldset'); |
||
966 | $fieldset->setAttribute('class', 'settings'); |
||
967 | $fieldset->appendChild(new XMLElement('legend', __('Attach to Pages'))); |
||
968 | $p = new XMLElement('p', __('The data will only be available on the selected pages.')); |
||
969 | $p->setAttribute('class', 'help'); |
||
970 | $fieldset->appendChild($p); |
||
971 | |||
972 | $div = new XMLElement('div'); |
||
973 | $label = Widget::Label(__('Pages')); |
||
974 | |||
975 | $pages = PageManager::fetch(); |
||
976 | $ds_handle = str_replace('-', '_', Lang::createHandle($fields['name'])); |
||
977 | $connections = ResourceManager::getAttachedPages(ResourceManager::RESOURCE_TYPE_DS, $ds_handle); |
||
978 | $selected = array(); |
||
979 | |||
980 | foreach ($connections as $connection) { |
||
981 | $selected[] = $connection['id']; |
||
982 | } |
||
983 | |||
984 | $options = array(); |
||
985 | |||
986 | foreach ($pages as $page) { |
||
987 | $options[] = array($page['id'], in_array($page['id'], $selected), PageManager::resolvePageTitle($page['id'])); |
||
988 | } |
||
989 | |||
990 | $label->appendChild(Widget::Select('fields[connections][]', $options, array('multiple' => 'multiple'))); |
||
991 | $div->appendChild($label); |
||
992 | |||
993 | $fieldset->appendChild($div); |
||
994 | $this->Form->appendChild($fieldset); |
||
995 | |||
996 | |||
997 | // Call the provided datasources to let them inject their filters |
||
998 | // @todo Ideally when a new Datasource is chosen an AJAX request will fire |
||
999 | // to get the HTML from the extension. This is hardcoded for now into |
||
1000 | // creating a 'big' page and then hiding the fields with JS |
||
1001 | if (!empty($providers)) { |
||
1002 | foreach ($providers as $providerClass => $provider) { |
||
1003 | call_user_func_array(array($providerClass, 'buildEditor'), array($this->Form, &$this->_errors, $fields, $handle)); |
||
1004 | } |
||
1005 | } |
||
1006 | |||
1007 | $div = new XMLElement('div'); |
||
1008 | $div->setAttribute('class', 'actions'); |
||
1009 | $div->appendChild(Widget::Input('action[save]', ($isEditing ? __('Save Changes') : __('Create Data Source')), 'submit', array('accesskey' => 's'))); |
||
1010 | |||
1011 | if ($isEditing) { |
||
1012 | $button = new XMLElement('button', __('Delete')); |
||
1013 | $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this data source'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this data source?'))); |
||
1014 | $div->appendChild($button); |
||
1015 | } |
||
1016 | |||
1017 | $this->Form->appendChild($div); |
||
1018 | } |
||
1019 | |||
1681 |