public function __form() { $formHasErrors = is_array($this->_errors) && !empty($this->_errors); if ($formHasErrors) { $this->pageAlert(__('An error occurred while processing this form. See below for details.'), Alert::ERROR); // These alerts are only valid if the form doesn't have errors } elseif (isset($this->_context[2])) { $time = Widget::Time(); switch ($this->_context[2]) { case 'saved': $message = __('Data Source updated at %s.', array($time->generate())); break; case 'created': $message = __('Data Source created at %s.', array($time->generate())); } $this->pageAlert($message . ' <a href="' . SYMPHONY_URL . '/blueprints/datasources/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/blueprints/datasources/" accesskey="a">' . __('View all Data Sources') . '</a>', Alert::SUCCESS); } $providers = Symphony::ExtensionManager()->getProvidersOf(iProvider::DATASOURCE); $isEditing = false; $about = $handle = null; $fields = array('name' => null, 'source' => null, 'filter' => null, 'required_url_param' => null, 'negate_url_param' => null, 'param' => null); if (isset($_POST['fields'])) { $fields = $_POST['fields']; if (!in_array($fields['source'], array('authors', 'navigation', 'static_xml')) && !empty($fields['filter']) && is_array($fields['filter'])) { $filters = array(); foreach ($fields['filter'] as $f) { foreach ($f as $key => $val) { $filters[$key] = $val; } } $fields['filter'][$fields['source']] = $filters; } if (!isset($fields['xml_elements']) || !is_array($fields['xml_elements'])) { $fields['xml_elements'] = array(); } if ($this->_context[0] == 'edit') { $isEditing = true; } } elseif ($this->_context[0] == 'edit') { $isEditing = true; $handle = $this->_context[1]; $existing = DatasourceManager::create($handle, array(), false); $order = isset($existing->dsParamORDER) ? $existing->dsParamORDER : 'asc'; if (!$existing->allowEditorToParse()) { redirect(SYMPHONY_URL . '/blueprints/datasources/info/' . $handle . '/'); } $about = $existing->about(); $fields['name'] = $about['name']; $fields['order'] = $order == 'rand' ? 'random' : $order; $fields['param'] = isset($existing->dsParamPARAMOUTPUT) ? $existing->dsParamPARAMOUTPUT : null; $fields['required_url_param'] = isset($existing->dsParamREQUIREDPARAM) ? trim($existing->dsParamREQUIREDPARAM) : null; $fields['negate_url_param'] = isset($existing->dsParamNEGATEPARAM) ? trim($existing->dsParamNEGATEPARAM) : null; if (isset($existing->dsParamINCLUDEDELEMENTS) && is_array($existing->dsParamINCLUDEDELEMENTS)) { $fields['xml_elements'] = $existing->dsParamINCLUDEDELEMENTS; } else { $fields['xml_elements'] = array(); } $fields['sort'] = isset($existing->dsParamSORT) ? $existing->dsParamSORT : null; $fields['paginate_results'] = isset($existing->dsParamPAGINATERESULTS) ? $existing->dsParamPAGINATERESULTS : 'yes'; $fields['page_number'] = isset($existing->dsParamSTARTPAGE) ? $existing->dsParamSTARTPAGE : '1'; $fields['group'] = isset($existing->dsParamGROUP) ? $existing->dsParamGROUP : null; $fields['html_encode'] = isset($existing->dsParamHTMLENCODE) ? $existing->dsParamHTMLENCODE : 'no'; $fields['associated_entry_counts'] = isset($existing->dsParamASSOCIATEDENTRYCOUNTS) ? $existing->dsParamASSOCIATEDENTRYCOUNTS : 'no'; $fields['redirect_on_empty'] = isset($existing->dsParamREDIRECTONEMPTY) ? $existing->dsParamREDIRECTONEMPTY : 'no'; $fields['redirect_on_forbidden'] = isset($existing->dsParamREDIRECTONFORBIDDEN) ? $existing->dsParamREDIRECTONFORBIDDEN : 'no'; $fields['redirect_on_required'] = isset($existing->dsParamREDIRECTONREQUIRED) ? $existing->dsParamREDIRECTONREQUIRED : 'no'; if (!isset($existing->dsParamFILTERS) || !is_array($existing->dsParamFILTERS)) { $existing->dsParamFILTERS = array(); } if (!empty($existing->dsParamFILTERS)) { $existing->dsParamFILTERS = array_map('stripslashes', $existing->dsParamFILTERS); } $fields['source'] = $existing->getSource(); $provided = false; if (!empty($providers)) { foreach ($providers as $providerClass => $provider) { if ($fields['source'] == call_user_func(array($providerClass, 'getClass'))) { $fields = array_merge($fields, $existing->settings()); $provided = true; break; } } } if ($provided === false) { switch ($fields['source']) { case 'authors': $fields['filter']['author'] = $existing->dsParamFILTERS; break; case 'navigation': $fields['filter']['navigation'] = $existing->dsParamFILTERS; break; case 'static_xml': // Symphony 2.3+ if (isset($existing->dsParamSTATIC)) { $fields['static_xml'] = trim($existing->dsParamSTATIC); // Handle Symphony 2.2.2 to 2.3 DS's } elseif (isset($existing->dsSTATIC)) { $fields['static_xml'] = trim($existing->dsSTATIC); // Handle pre Symphony 2.2.1 Static DS's } else { $fields['static_xml'] = trim($existing->grab()); } break; default: $fields['filter'][$fields['source']] = $existing->dsParamFILTERS; $fields['max_records'] = $existing->dsParamLIMIT; break; } } } else { $fields['max_records'] = '20'; $fields['page_number'] = '1'; $fields['order'] = 'desc'; } // Handle name on edited changes, or from reading an edited datasource if (isset($about['name'])) { $name = $about['name']; } elseif (isset($fields['name'])) { $name = $fields['name']; } $this->setPageType('form'); $this->setTitle(__($isEditing ? '%1$s – %2$s – %3$s' : '%2$s – %3$s', array($name, __('Data Sources'), __('Symphony')))); $this->appendSubheading($isEditing ? $name : __('Untitled')); $this->insertBreadcrumbs(array(Widget::Anchor(__('Data Sources'), SYMPHONY_URL . '/blueprints/datasources/'))); // Sources $sources = new XMLElement('div', null, array('class' => 'apply actions')); $div = new XMLElement('div'); $label = Widget::Label(__('Source'), null, 'apply-label-left'); $sources->appendChild($label); $sources->appendChild($div); $sections = SectionManager::fetch(null, 'ASC', 'name'); if (!is_array($sections)) { $sections = array(); } $field_groups = array(); foreach ($sections as $section) { $field_groups[$section->get('id')] = array('fields' => $section->fetchFields(), 'section' => $section); } $options = array(array('label' => __('System'), 'data-label' => 'system', 'options' => array(array('authors', $fields['source'] == 'authors', __('Authors'), null, null, array('data-context' => 'authors')), array('navigation', $fields['source'] == 'navigation', __('Navigation'), null, null, array('data-context' => 'navigation')))), array('label' => __('Custom XML'), 'data-label' => 'custom-xml', 'options' => array(array('static_xml', $fields['source'] == 'static_xml', __('Static XML'), null, null, array('data-context' => 'static-xml'))))); // Loop over the datasource providers if (!empty($providers)) { $p = array('label' => __('From extensions'), 'data-label' => 'from_extensions', 'options' => array()); foreach ($providers as $providerClass => $provider) { $p['options'][] = array($providerClass, $fields['source'] == $providerClass, $provider, null, null, array('data-context' => Lang::createHandle($provider))); } $options[] = $p; } // Add Sections if (is_array($sections) && !empty($sections)) { array_unshift($options, array('label' => __('Sections'), 'data-label' => 'sections', 'options' => array())); foreach ($sections as $s) { $options[0]['options'][] = array($s->get('id'), $fields['source'] == $s->get('id'), General::sanitize($s->get('name'))); } } $div->appendChild(Widget::Select('source', $options, array('id' => 'ds-context'))); $this->Context->prependChild($sources); $this->Form->appendChild(Widget::Input('fields[source]', null, 'hidden', array('id' => 'ds-source'))); // Name $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Essentials'))); $group = new XMLElement('div'); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[name]', General::sanitize($fields['name']))); if (isset($this->_errors['name'])) { $group->appendChild(Widget::Error($label, $this->_errors['name'])); } else { $group->appendChild($label); } $fieldset->appendChild($group); $this->Form->appendChild($fieldset); // Conditions $fieldset = new XMLElement('fieldset'); $this->setContext($fieldset, array('sections', 'system', 'custom-xml')); $fieldset->appendChild(new XMLElement('legend', __('Conditions'))); $p = new XMLElement('p', __('Leaving these fields empty will always execute the data source.')); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $group = new XMLElement('div'); $group->setAttribute('class', 'two columns'); $label = Widget::Label(__('Required Parameter')); $label->setAttribute('class', 'column ds-param'); $label->appendChild(new XMLElement('i', __('Optional'))); $input = Widget::Input('fields[required_url_param]', trim($fields['required_url_param']), 'text', array('placeholder' => __('$param'), 'data-search-types' => 'parameters', 'data-trigger' => '$')); $label->appendChild($input); $group->appendChild($label); $label = Widget::Label(__('Forbidden Parameter')); $label->setAttribute('class', 'column ds-param'); $label->appendChild(new XMLElement('i', __('Optional'))); $input = Widget::Input('fields[negate_url_param]', trim($fields['negate_url_param']), 'text', array('placeholder' => __('$param'), 'data-search-types' => 'parameters', 'data-trigger' => '$')); $label->appendChild($input); $group->appendChild($label); $fieldset->appendChild($group); $group = new XMLElement('div'); $group->setAttribute('class', 'two columns ds-param'); $label = Widget::Checkbox('fields[redirect_on_required]', $fields['redirect_on_required'], __('Redirect to 404 page when the required parameter is not present')); $label->setAttribute('class', 'column'); $group->appendChild($label); $label = Widget::Checkbox('fields[redirect_on_forbidden]', $fields['redirect_on_forbidden'], __('Redirect to 404 page when the forbidden parameter is present')); $label->setAttribute('class', 'column'); $group->appendChild($label); $fieldset->appendChild($group); $label = Widget::Checkbox('fields[redirect_on_empty]', $fields['redirect_on_empty'], __('Redirect to 404 page when no results are found')); $label->setAttribute('class', 'column'); $fieldset->appendChild($label); $this->Form->appendChild($fieldset); // Filters $fieldset = new XMLElement('fieldset'); $this->setContext($fieldset, array('sections', 'system')); $fieldset->appendChild(new XMLElement('legend', __('Filters'))); $p = new XMLElement('p', __('Use %s syntax to filter by page parameters. A default value can be set using %s.', array('<code>{' . __('$param') . '}</code>', '<code>{' . __('$param:default') . '}</code>'))); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); foreach ($field_groups as $section_id => $section_data) { $div = new XMLElement('div'); $div->setAttribute('class', 'contextual frame filters-duplicator'); $div->setAttribute('data-context', 'section-' . $section_id); $div->setAttribute('data-interactive', 'data-interactive'); $ol = new XMLElement('ol'); $ol->setAttribute('class', 'suggestable'); $ol->setAttribute('data-interactive', 'data-interactive'); $ol->setAttribute('data-add', __('Add filter')); $ol->setAttribute('data-remove', __('Remove filter')); // Add system:id filter if (isset($fields['filter'][$section_id]['system:id']) || isset($fields['filter'][$section_id]['id'])) { $id = isset($fields['filter'][$section_id]['system:id']) ? $fields['filter'][$section_id]['system:id'] : $fields['filter'][$section_id]['id']; $li = new XMLElement('li'); $li->setAttribute('class', 'unique'); $li->setAttribute('data-type', 'system:id'); $li->appendChild(new XMLElement('header', '<h4>' . __('System ID') . '</h4>')); $label = Widget::Label(__('Value')); $input = Widget::Input('fields[filter][' . $section_id . '][system:id]', General::sanitize($id)); $input->setAttribute('data-search-types', 'parameters'); $input->setAttribute('data-trigger', '{$'); $label->appendChild($input); $li->appendChild($label); $ol->appendChild($li); } $li = new XMLElement('li'); $li->setAttribute('class', 'unique template'); $li->setAttribute('data-type', 'system:id'); $li->appendChild(new XMLElement('header', '<h4>' . __('System ID') . '</h4>')); $label = Widget::Label(__('Value')); $input = Widget::Input('fields[filter][' . $section_id . '][system:id]', General::sanitize($id)); $input->setAttribute('data-search-types', 'parameters'); $input->setAttribute('data-trigger', '{$'); $label->appendChild($input); $li->appendChild($label); $ol->appendChild($li); // Add system:date filter if (isset($fields['filter'][$section_id]['system:creation-date']) || isset($fields['filter'][$section_id]['system:date'])) { $creation_date = isset($fields['filter'][$section_id]['system:creation-date']) ? $fields['filter'][$section_id]['system:creation-date'] : $fields['filter'][$section_id]['system:date']; $li = new XMLElement('li'); $li->setAttribute('class', 'unique'); $li->setAttribute('data-type', 'system:creation-date'); $li->appendChild(new XMLElement('header', '<h4>' . __('System Creation Date') . '</h4>')); $label = Widget::Label(__('Value')); $input = Widget::Input('fields[filter][' . $section_id . '][system:creation-date]', General::sanitize($creation_date)); $input->setAttribute('data-search-types', 'parameters'); $input->setAttribute('data-trigger', '{$'); $label->appendChild($input); $li->appendChild($label); $ol->appendChild($li); } $li = new XMLElement('li'); $li->setAttribute('class', 'unique template'); $li->setAttribute('data-type', 'system:creation-date'); $li->appendChild(new XMLElement('header', '<h4>' . __('System Creation Date') . '</h4>')); $label = Widget::Label(__('Value')); $input = Widget::Input('fields[filter][' . $section_id . '][system:creation-date]'); $input->setAttribute('data-search-types', 'parameters'); $input->setAttribute('data-trigger', '{$'); $label->appendChild($input); $li->appendChild($label); $ol->appendChild($li); if (isset($fields['filter'][$section_id]['system:modification-date'])) { $li = new XMLElement('li'); $li->setAttribute('class', 'unique'); $li->setAttribute('data-type', 'system:modification-date'); $li->appendChild(new XMLElement('header', '<h4>' . __('System Modification Date') . '</h4>')); $label = Widget::Label(__('Value')); $input = Widget::Input('fields[filter][' . $section_id . '][system:modification-date]', General::sanitize($fields['filter'][$section_id]['system:modification-date'])); $input->setAttribute('data-search-types', 'parameters'); $input->setAttribute('data-trigger', '{$'); $label->appendChild($input); $li->appendChild($label); $ol->appendChild($li); } $li = new XMLElement('li'); $li->setAttribute('class', 'unique template'); $li->setAttribute('data-type', 'system:modification-date'); $li->appendChild(new XMLElement('header', '<h4>' . __('System Modification Date') . '</h4>')); $label = Widget::Label(__('Value')); $input = Widget::Input('fields[filter][' . $section_id . '][system:modification-date]'); $input->setAttribute('data-search-types', 'parameters'); $input->setAttribute('data-trigger', '{$'); $label->appendChild($input); $li->appendChild($label); $ol->appendChild($li); if (is_array($section_data['fields']) && !empty($section_data['fields'])) { foreach ($section_data['fields'] as $field) { if (!$field->canFilter()) { continue; } if (isset($fields['filter'][$section_id], $fields['filter'][$section_id][$field->get('id')])) { $wrapper = new XMLElement('li'); $wrapper->setAttribute('class', 'unique'); $wrapper->setAttribute('data-type', $field->get('element_name')); $errors = isset($this->_errors[$field->get('id')]) ? $this->_errors[$field->get('id')] : array(); $field->displayDatasourceFilterPanel($wrapper, $fields['filter'][$section_id][$field->get('id')], $errors, $section_id); $ol->appendChild($wrapper); } $wrapper = new XMLElement('li'); $wrapper->setAttribute('class', 'unique template'); $wrapper->setAttribute('data-type', $field->get('element_name')); $field->displayDatasourceFilterPanel($wrapper, null, null, $section_id); $ol->appendChild($wrapper); } } $div->appendChild($ol); $fieldset->appendChild($div); } $div = new XMLElement('div'); $div->setAttribute('class', 'contextual frame filters-duplicator'); $div->setAttribute('data-context', 'authors'); $div->setAttribute('data-interactive', 'data-interactive'); $ol = new XMLElement('ol'); $ol->setAttribute('class', 'suggestable'); $ol->setAttribute('data-interactive', 'data-interactive'); $ol->setAttribute('data-add', __('Add filter')); $ol->setAttribute('data-remove', __('Remove filter')); if (!isset($fields['filter']['author'])) { $fields['filter']['author'] = array('id' => null, 'username' => null, 'first_name' => null, 'last_name' => null, 'email' => null, 'user_type' => null); } $this->__appendAuthorFilter($ol, __('ID'), 'id', $fields['filter']['author']['id'], !isset($fields['filter']['author']['id'])); $this->__appendAuthorFilter($ol, __('Username'), 'username', $fields['filter']['author']['username'], !isset($fields['filter']['author']['username'])); $this->__appendAuthorFilter($ol, __('First Name'), 'first_name', $fields['filter']['author']['first_name'], !isset($fields['filter']['author']['first_name'])); $this->__appendAuthorFilter($ol, __('Last Name'), 'last_name', $fields['filter']['author']['last_name'], !isset($fields['filter']['author']['last_name'])); $this->__appendAuthorFilter($ol, __('Email'), 'email', $fields['filter']['author']['email'], !isset($fields['filter']['author']['email'])); $this->__appendAuthorFilter($ol, __('User Type'), 'user_type', $fields['filter']['author']['user_type'], !isset($fields['filter']['author']['user_type'])); $div->appendChild($ol); $fieldset->appendChild($div); $div = new XMLElement('div'); $div->setAttribute('class', 'contextual frame filters-duplicator'); $div->setAttribute('data-context', 'navigation'); $div->setAttribute('data-interactive', 'data-interactive'); $ol = new XMLElement('ol'); $ol->setAttribute('class', 'suggestable'); $ol->setAttribute('data-interactive', 'data-interactive'); $ol->setAttribute('data-add', __('Add filter')); $ol->setAttribute('data-remove', __('Remove filter')); $ul = new XMLElement('ul'); $ul->setAttribute('class', 'tags'); $ul->setAttribute('data-interactive', 'data-interactive'); $pages = PageManager::fetch(false, array('*'), array(), 'title ASC'); foreach ($pages as $page) { $ul->appendChild(new XMLElement('li', preg_replace('/\\/{2,}/i', '/', '/' . $page['path'] . '/' . $page['handle']))); } if (isset($fields['filter']['navigation']['parent'])) { $li = new XMLElement('li'); $li->setAttribute('class', 'unique'); $li->setAttribute('data-type', 'parent'); $li->appendChild(new XMLElement('header', '<h4>' . __('Parent Page') . '</h4>')); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][navigation][parent]', General::sanitize($fields['filter']['navigation']['parent']))); $li->appendChild($label); $li->appendChild($ul); $ol->appendChild($li); } $li = new XMLElement('li'); $li->setAttribute('class', 'unique template'); $li->setAttribute('data-type', 'parent'); $li->appendChild(new XMLElement('header', '<h4>' . __('Parent Page') . '</h4>')); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][navigation][parent]')); $li->appendChild($label); $li->appendChild($ul); $ol->appendChild($li); $ul = new XMLElement('ul'); $ul->setAttribute('class', 'tags'); $ul->setAttribute('data-interactive', 'data-interactive'); if ($types = PageManager::fetchAvailablePageTypes()) { foreach ($types as $type) { $ul->appendChild(new XMLElement('li', $type)); } } if (isset($fields['filter']['navigation']['type'])) { $li = new XMLElement('li'); $li->setAttribute('class', 'unique'); $li->setAttribute('data-type', 'type'); $li->appendChild(new XMLElement('header', '<h4>' . __('Page Type') . '</h4>')); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][navigation][type]', General::sanitize($fields['filter']['navigation']['type']))); $li->appendChild($label); $li->appendChild($ul); $ol->appendChild($li); } $li = new XMLElement('li'); $li->setAttribute('class', 'unique template'); $li->appendChild(new XMLElement('header', '<h4>' . __('Page Type') . '</h4>')); $li->setAttribute('data-type', 'type'); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][navigation][type]')); $li->appendChild($label); $li->appendChild($ul); $ol->appendChild($li); $div->appendChild($ol); $fieldset->appendChild($div); $this->Form->appendChild($fieldset); // Sorting $fieldset = new XMLElement('fieldset'); $this->setContext($fieldset, array('sections', 'system')); $fieldset->appendChild(new XMLElement('legend', __('Sorting'))); $p = new XMLElement('p', __('Use %s syntax to order by page parameters.', array('<code>{' . __('$param') . '}</code>'))); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $div = new XMLElement('div'); $label = Widget::Label(__('Sort By')); $options = array(array('label' => __('Authors'), 'data-label' => 'authors', 'options' => array(array('id', $fields['source'] == 'authors' && $fields['sort'] == 'id', __('Author ID')), array('username', $fields['source'] == 'authors' && $fields['sort'] == 'username', __('Username')), array('first-name', $fields['source'] == 'authors' && $fields['sort'] == 'first-name', __('First Name')), array('last-name', $fields['source'] == 'authors' && $fields['sort'] == 'last-name', __('Last Name')), array('email', $fields['source'] == 'authors' && $fields['sort'] == 'email', __('Email')), array('status', $fields['source'] == 'authors' && $fields['sort'] == 'status', __('Status')))), array('label' => __('Navigation'), 'data-label' => 'navigation', 'options' => array(array('id', $fields['source'] == 'navigation' && $fields['sort'] == 'id', __('Page ID')), array('handle', $fields['source'] == 'navigation' && $fields['sort'] == 'handle', __('Handle')), array('sortorder', $fields['source'] == 'navigation' && $fields['sort'] == 'sortorder', __('Sort Order'))))); foreach ($field_groups as $section_id => $section_data) { $optgroup = array('label' => General::sanitize($section_data['section']->get('name')), 'data-label' => 'section-' . $section_data['section']->get('id'), 'options' => array(array('system:id', $fields['source'] == $section_id && $fields['sort'] == 'system:id', __('System ID')), array('system:creation-date', $fields['source'] == $section_id && ($fields['sort'] == 'system:creation-date' || $fields['sort'] == 'system:date'), __('System Creation Date')), array('system:modification-date', $fields['source'] == $section_id && $fields['sort'] == 'system:modification-date', __('System Modification Date')))); if (is_array($section_data['fields']) && !empty($section_data['fields'])) { foreach ($section_data['fields'] as $input) { if (!$input->isSortable()) { continue; } $optgroup['options'][] = array($input->get('element_name'), $fields['source'] == $section_id && $input->get('element_name') == $fields['sort'], $input->get('label')); } } $options[] = $optgroup; } $label->appendChild(Widget::Select('fields[sort]', $options)); $div->appendChild($label); $label = Widget::Label(__('Sort Order')); $label->setAttribute('class', 'ds-param'); $input = Widget::Input('fields[order]', $fields['order'], 'text', array('placeholder' => __('{$param}'), 'data-search-types' => 'parameters', 'data-trigger' => '{$')); $label->appendChild($input); $div->appendChild($label); $orders = new XMLElement('ul'); $orders->setAttribute('class', 'tags singular'); $orders->setAttribute('data-interactive', 'data-interactive'); $orders->appendChild(new XMLElement('li', 'asc')); $orders->appendChild(new XMLElement('li', 'desc')); $orders->appendChild(new XMLElement('li', 'random')); $div->appendChild($orders); $fieldset->appendChild($div); $this->Form->appendChild($fieldset); // Grouping $fieldset = new XMLElement('fieldset'); $this->setContext($fieldset, array('sections', 'authors')); $fieldset->appendChild(new XMLElement('legend', __('Grouping'))); $label = Widget::Label(__('Group By')); $options = array(array('', null, __('None'))); foreach ($field_groups as $section_id => $section_data) { $optgroup = array('label' => $section_data['section']->get('name'), 'data-label' => 'section-' . $section_data['section']->get('id'), 'options' => array()); if (is_array($section_data['fields']) && !empty($section_data['fields'])) { foreach ($section_data['fields'] as $input) { if (!$input->allowDatasourceOutputGrouping()) { continue; } $optgroup['options'][] = array($input->get('id'), $fields['source'] == $section_id && $fields['group'] == $input->get('id'), $input->get('label')); } } $options[] = $optgroup; } $label->appendChild(Widget::Select('fields[group]', $options)); $fieldset->appendChild($label); $this->Form->appendChild($fieldset); // Pagination $fieldset = new XMLElement('fieldset'); $this->setContext($fieldset, array('sections')); $fieldset->appendChild(new XMLElement('legend', __('Pagination'))); $p = new XMLElement('p', __('Use %s syntax to limit by page parameters.', array('<code>{' . __('$param') . '}</code>'))); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $group = new XMLElement('div'); $group->setAttribute('class', 'two columns pagination'); $label = Widget::Label(__('Entries per Page')); $label->setAttribute('class', 'column ds-param'); $input = Widget::Input('fields[max_records]', isset($fields['max_records']) ? $fields['max_records'] : '10', 'text', array('placeholder' => __('{$param}'), 'data-search-types' => 'parameters', 'data-trigger' => '{$')); $label->appendChild($input); $group->appendChild($label); $label = Widget::Label(__('Page Number')); $label->setAttribute('class', 'column ds-param'); $input = Widget::Input('fields[page_number]', $fields['page_number'], 'text', array('placeholder' => __('{$param}'), 'data-search-types' => 'parameters', 'data-trigger' => '{$')); $label->appendChild($input); $group->appendChild($label); $fieldset->appendChild($group); $label = Widget::Checkbox('fields[paginate_results]', $fields['paginate_results'], __('Enable pagination')); $fieldset->appendChild($label); $this->Form->appendChild($fieldset); // Content $fieldset = new XMLElement('fieldset'); $this->setContext($fieldset, array('sections', 'authors')); $fieldset->appendChild(new XMLElement('legend', __('Content'))); // XML $group = new XMLElement('div', null, array('class' => 'two columns')); $label = Widget::Label(__('Included Elements')); $label->setAttribute('class', 'column'); $options = array(array('label' => __('Authors'), 'data-label' => 'authors', 'options' => array(array('username', $fields['source'] == 'authors' && in_array('username', $fields['xml_elements']), 'username'), array('name', $fields['source'] == 'authors' && in_array('name', $fields['xml_elements']), 'name'), array('email', $fields['source'] == 'authors' && in_array('email', $fields['xml_elements']), 'email'), array('author-token', $fields['source'] == 'authors' && in_array('author-token', $fields['xml_elements']), 'author-token'), array('default-area', $fields['source'] == 'authors' && in_array('default-area', $fields['xml_elements']), 'default-area')))); foreach ($field_groups as $section_id => $section_data) { $optgroup = array('label' => General::sanitize($section_data['section']->get('name')), 'data-label' => 'section-' . $section_data['section']->get('id'), 'options' => array(array('system:pagination', $fields['source'] == $section_id && in_array('system:pagination', $fields['xml_elements']), 'system: pagination'), array('system:date', $fields['source'] == $section_id && in_array('system:date', $fields['xml_elements']), 'system: date'))); if (is_array($section_data['fields']) && !empty($section_data['fields'])) { foreach ($section_data['fields'] as $field) { $elements = $field->fetchIncludableElements(); if (is_array($elements) && !empty($elements)) { foreach ($elements as $name) { $selected = false; if ($fields['source'] == $section_id && in_array($name, $fields['xml_elements'])) { $selected = true; } $optgroup['options'][] = array($name, $selected, $name); } } } } $options[] = $optgroup; } $label->appendChild(Widget::Select('fields[xml_elements][]', $options, array('multiple' => 'multiple'))); $group->appendChild($label); // Support multiple parameters if (!isset($fields['param'])) { $fields['param'] = array(); } elseif (!is_array($fields['param'])) { $fields['param'] = array($fields['param']); } $label = Widget::Label(__('Parameters')); $label->setAttribute('class', 'column'); $prefix = '$ds-' . (isset($this->_context[1]) ? Lang::createHandle($fields['name']) : __('untitled')) . '.'; $options = array(array('label' => __('Authors'), 'data-label' => 'authors', 'options' => array())); foreach (array('id', 'username', 'name', 'email', 'user_type') as $p) { $options[0]['options'][] = array($p, $fields['source'] == 'authors' && in_array($p, $fields['param']), $prefix . $p, null, null, array('data-handle' => $p)); } foreach ($field_groups as $section_id => $section_data) { $optgroup = array('label' => $section_data['section']->get('name'), 'data-label' => 'section-' . $section_data['section']->get('id'), 'options' => array()); foreach (array('id', 'creation-date', 'modification-date', 'author') as $p) { $option = array('system:' . $p, $fields['source'] == $section_id && in_array('system:' . $p, $fields['param']), $prefix . 'system-' . $p, null, null, array('data-handle' => 'system-' . $p)); // Handle 'system:date' as an output paramater (backwards compatibility) if ($p === 'creation-date') { if ($fields['source'] == $section_id && in_array('system:date', $fields['param'])) { $option[1] = true; } } $optgroup['options'][] = $option; } if (is_array($section_data['fields']) && !empty($section_data['fields'])) { foreach ($section_data['fields'] as $input) { if (!$input->allowDatasourceParamOutput()) { continue; } $optgroup['options'][] = array($input->get('element_name'), $fields['source'] == $section_id && in_array($input->get('element_name'), $fields['param']), $prefix . $input->get('element_name'), null, null, array('data-handle' => $input->get('element_name'))); } } $options[] = $optgroup; } $label->appendChild(Widget::Select('fields[param][]', $options, array('multiple' => 'multiple'))); $group->appendChild($label); $fieldset->appendChild($group); // Associations $label = Widget::Checkbox('fields[associated_entry_counts]', $fields['associated_entry_counts'], __('Include a count of entries in associated sections')); $this->setContext($label, array('sections')); $fieldset->appendChild($label); // Encoding $label = Widget::Checkbox('fields[html_encode]', $fields['html_encode'], __('HTML-encode text')); $this->setContext($label, array('sections')); $fieldset->appendChild($label); $this->Form->appendChild($fieldset); // Static XML if (!isset($fields['static_xml'])) { $fields['static_xml'] = null; } $fieldset = new XMLElement('fieldset'); $this->setContext($fieldset, array('static-xml')); $fieldset->appendChild(new XMLElement('legend', __('Static XML'))); $p = new XMLElement('p', __('Enter valid XML, exclude XML declaration')); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $label = Widget::Label(); $label->appendChild(Widget::Textarea('fields[static_xml]', 12, 50, General::sanitize(stripslashes($fields['static_xml'])), array('class' => 'code', 'placeholder' => '<static>content</static>'))); if (isset($this->_errors['static_xml'])) { $fieldset->appendChild(Widget::Error($label, $this->_errors['static_xml'])); } else { $fieldset->appendChild($label); } $this->Form->appendChild($fieldset); // Connections $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Attach to Pages'))); $p = new XMLElement('p', __('The data will only be available on the selected pages.')); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $div = new XMLElement('div'); $label = Widget::Label(__('Pages')); $pages = PageManager::fetch(); $ds_handle = str_replace('-', '_', Lang::createHandle($fields['name'])); $connections = ResourceManager::getAttachedPages(ResourceManager::RESOURCE_TYPE_DS, $ds_handle); $selected = array(); foreach ($connections as $connection) { $selected[] = $connection['id']; } $options = array(); foreach ($pages as $page) { $options[] = array($page['id'], in_array($page['id'], $selected), PageManager::resolvePageTitle($page['id'])); } $label->appendChild(Widget::Select('fields[connections][]', $options, array('multiple' => 'multiple'))); $div->appendChild($label); $fieldset->appendChild($div); $this->Form->appendChild($fieldset); // Call the provided datasources to let them inject their filters // @todo Ideally when a new Datasource is chosen an AJAX request will fire // to get the HTML from the extension. This is hardcoded for now into // creating a 'big' page and then hiding the fields with JS if (!empty($providers)) { foreach ($providers as $providerClass => $provider) { call_user_func_array(array($providerClass, 'buildEditor'), array($this->Form, &$this->_errors, $fields, $handle)); } } $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $isEditing ? __('Save Changes') : __('Create Data Source'), 'submit', array('accesskey' => 's'))); if ($isEditing) { $button = new XMLElement('button', __('Delete')); $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?'))); $div->appendChild($button); } $this->Form->appendChild($div); }
/** * Returns all the page types that exist in this Symphony install. * There are 5 default system page types, and new types can be added * by Developers via the Page Editor. * * @deprecated This function will be removed in Symphony 2.4. * The preferred way to access the page types is via * `PageManager::fetchAvailablePageTypes()` * @see toolkit.PageManager#fetchAvailablePageTypes * @return array * An array of strings of the page types used in this Symphony * install. At the minimum, this will be an array with the values * 'index', 'XML', 'admin', '404' and '403'. */ public function __fetchAvailablePageTypes() { return PageManager::fetchAvailablePageTypes(); }
public function __viewEdit() { $this->setPageType('form'); $fields = array("title" => null, "handle" => null, "parent" => null, "params" => null, "type" => null, "data_sources" => null); $existing = $fields; $nesting = Symphony::Configuration()->get('pages_table_nest_children', 'symphony') == 'yes'; // Verify page exists: if ($this->_context[0] == 'edit') { if (!($page_id = (int) $this->_context[1])) { redirect(SYMPHONY_URL . '/blueprints/pages/'); } $existing = PageManager::fetchPageByID($page_id); if (!$existing) { Administration::instance()->errorPageNotFound(); } else { $existing['type'] = PageManager::fetchPageTypes($page_id); } } // Status message: if (isset($this->_context[2])) { $flag = $this->_context[2]; $link_suffix = ''; if (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) { $link_suffix = "?parent=" . $_REQUEST['parent']; } else { if ($nesting == true && isset($existing) && !is_null($existing['parent'])) { $link_suffix = '?parent=' . $existing['parent']; } } switch ($flag) { case 'saved': $this->pageAlert(__('Page updated at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/blueprints/pages/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/blueprints/pages/" accesskey="a">' . __('View all Pages') . '</a>', Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Page created at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/blueprints/pages/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/blueprints/pages/" accesskey="a">' . __('View all Pages') . '</a>', Alert::SUCCESS); } } // Find values: if (isset($_POST['fields'])) { $fields = $_POST['fields']; } elseif ($this->_context[0] == 'edit') { $fields = $existing; if (!is_null($fields['type'])) { $fields['type'] = implode(', ', $fields['type']); } $fields['data_sources'] = preg_split('/,/i', $fields['data_sources'], -1, PREG_SPLIT_NO_EMPTY); $fields['events'] = preg_split('/,/i', $fields['events'], -1, PREG_SPLIT_NO_EMPTY); } elseif (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) { $fields['parent'] = $_REQUEST['parent']; } $title = $fields['title']; if (trim($title) == '') { $title = $existing['title']; } $this->setTitle(__($title ? '%1$s – %2$s – %3$s' : '%2$s – %3$s', array($title, __('Pages'), __('Symphony')))); $page_id = isset($page_id) ? $page_id : null; if (!empty($title)) { $template_name = $fields['handle']; $page_url = URL . '/' . PageManager::resolvePagePath($page_id) . '/'; if ($existing['parent']) { $parents = PageManager::resolvePagePath($existing['parent']); $template_name = PageManager::createFilePath($parents, $fields['handle']); } $this->appendSubheading($title, array(Widget::Anchor(__('View Page'), $page_url, __('View Page on Frontend'), 'button', NULL, array('target' => '_blank', 'accesskey' => 'v')), Widget::Anchor(__('Edit Page Template'), SYMPHONY_URL . '/blueprints/pages/template/' . $template_name, __('Edit Page Template'), 'button', NULL, array('accesskey' => 't')))); } else { $this->appendSubheading(!empty($title) ? $title : __('Untitled')); } if (isset($page_id)) { $this->insertBreadcrumbsUsingPageIdentifier($page_id, false); } else { $_GET['parent'] = isset($_GET['parent']) ? $_GET['parent'] : null; $this->insertBreadcrumbsUsingPageIdentifier((int) $_GET['parent'], true); } // Title -------------------------------------------------------------- $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Page Settings'))); $label = Widget::Label(__('Title')); $label->appendChild(Widget::Input('fields[title]', General::sanitize($fields['title']))); if (isset($this->_errors['title'])) { $label = Widget::Error($label, $this->_errors['title']); } $fieldset->appendChild($label); // Handle ------------------------------------------------------------- $group = new XMLElement('div'); $group->setAttribute('class', 'two columns'); $column = new XMLElement('div'); $column->setAttribute('class', 'column'); $label = Widget::Label(__('URL Handle')); $label->appendChild(Widget::Input('fields[handle]', $fields['handle'])); if (isset($this->_errors['handle'])) { $label = Widget::Error($label, $this->_errors['handle']); } $column->appendChild($label); // Parent --------------------------------------------------------- $label = Widget::Label(__('Parent Page')); $where = array(sprintf('id != %d', $page_id)); $pages = PageManager::fetch(false, array('id'), $where, 'title ASC'); $options = array(array('', false, '/')); if (!empty($pages)) { if (!function_exists('__compare_pages')) { function __compare_pages($a, $b) { return strnatcasecmp($a[2], $b[2]); } } foreach ($pages as $page) { $options[] = array($page['id'], $fields['parent'] == $page['id'], '/' . PageManager::resolvePagePath($page['id'])); } usort($options, '__compare_pages'); } $label->appendChild(Widget::Select('fields[parent]', $options)); $column->appendChild($label); $group->appendChild($column); // Parameters --------------------------------------------------------- $column = new XMLElement('div'); $column->setAttribute('class', 'column'); $label = Widget::Label(__('URL Parameters')); $label->appendChild(Widget::Input('fields[params]', $fields['params'], 'text', array('placeholder' => 'param1/param2'))); $column->appendChild($label); // Type ----------------------------------------------------------- $label = Widget::Label(__('Page Type')); $label->appendChild(Widget::Input('fields[type]', $fields['type'])); if (isset($this->_errors['type'])) { $label = Widget::Error($label, $this->_errors['type']); } $column->appendChild($label); $tags = new XMLElement('ul'); $tags->setAttribute('class', 'tags'); $types = PageManager::fetchAvailablePageTypes(); foreach ($types as $type) { $tags->appendChild(new XMLElement('li', $type)); } $column->appendChild($tags); $group->appendChild($column); $fieldset->appendChild($group); $this->Form->appendChild($fieldset); // Events ------------------------------------------------------------- $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Page Resources'))); $group = new XMLElement('div'); $group->setAttribute('class', 'two columns'); $label = Widget::Label(__('Events')); $label->setAttribute('class', 'column'); $events = ResourceManager::fetch(RESOURCE_TYPE_EVENT, array(), array(), 'name ASC'); $options = array(); if (is_array($events) && !empty($events)) { if (!isset($fields['events'])) { $fields['events'] = array(); } foreach ($events as $name => $about) { $options[] = array($name, in_array($name, $fields['events']), $about['name']); } } $label->appendChild(Widget::Select('fields[events][]', $options, array('multiple' => 'multiple'))); $group->appendChild($label); // Data Sources ------------------------------------------------------- $label = Widget::Label(__('Data Sources')); $label->setAttribute('class', 'column'); $datasources = ResourceManager::fetch(RESOURCE_TYPE_DS, array(), array(), 'name ASC'); $options = array(); if (is_array($datasources) && !empty($datasources)) { if (!isset($fields['data_sources'])) { $fields['data_sources'] = array(); } foreach ($datasources as $name => $about) { $options[] = array($name, in_array($name, $fields['data_sources']), $about['name']); } } $label->appendChild(Widget::Select('fields[data_sources][]', $options, array('multiple' => 'multiple'))); $group->appendChild($label); $fieldset->appendChild($group); $this->Form->appendChild($fieldset); // Controls ----------------------------------------------------------- /** * After all Page related Fields have been added to the DOM, just before the * actions. * * @delegate AppendPageContent * @param string $context * '/blueprints/pages/' * @param XMLElement $form * @param array $fields * @param array $errors */ Symphony::ExtensionManager()->notifyMembers('AppendPageContent', '/blueprints/pages/', array('form' => &$this->Form, 'fields' => &$fields, 'errors' => $this->_errors)); $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : __('Create Page'), 'submit', array('accesskey' => 's'))); if ($this->_context[0] == 'edit') { $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this page'), 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this page?'))); $div->appendChild($button); } $this->Form->appendChild($div); if (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) { $this->Form->appendChild(new XMLElement('input', NULL, array('type' => 'hidden', 'name' => 'parent', 'value' => $_REQUEST['parent']))); } }
public function __form() { $formHasErrors = is_array($this->_errors) && !empty($this->_errors); if ($formHasErrors) { $this->pageAlert(__('An error occurred while processing this form. See below for details.'), Alert::ERROR); } else { if (isset($this->_context[2])) { switch ($this->_context[2]) { case 'saved': $this->pageAlert(__('Data source updated at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/blueprints/datasources/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/blueprints/datasources/" accesskey="a">' . __('View all Data sources') . '</a>', Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Data source created at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/blueprints/datasources/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/blueprints/datasources/" accesskey="a">' . __('View all Data sources') . '</a>', Alert::SUCCESS); break; } } } $providers = Symphony::ExtensionManager()->getProvidersOf('data-sources'); if (isset($_POST['fields'])) { $fields = $_POST['fields']; $fields['paginate_results'] = $fields['paginate_results'] == 'on' ? 'yes' : 'no'; if (!in_array($fields['source'], array('authors', 'navigation', 'dynamic_xml', 'static_xml')) && is_array($fields['filter']) && !empty($fields['filter'])) { $filters = array(); foreach ($fields['filter'] as $f) { foreach ($f as $key => $val) { $filters[$key] = $val; } } $fields['filter'][$fields['source']] = $filters; } if (!isset($fields['xml_elements']) || !is_array($fields['xml_elements'])) { $fields['xml_elements'] = array(); } } else { if ($this->_context[0] == 'edit') { $isEditing = true; $handle = $this->_context[1]; $existing =& DatasourceManager::create($handle, array(), false); $cache_id = null; if (!$existing->allowEditorToParse()) { redirect(SYMPHONY_URL . '/blueprints/datasources/info/' . $handle . '/'); } $about = $existing->about(); $cache = new Cacheable(Symphony::Database()); $fields['name'] = $about['name']; $fields['order'] = $existing->dsParamORDER == 'rand' ? 'random' : $existing->dsParamORDER; $fields['param'] = $existing->dsParamPARAMOUTPUT; $fields['required_url_param'] = trim($existing->dsParamREQUIREDPARAM); if (isset($existing->dsParamINCLUDEDELEMENTS) && is_array($existing->dsParamINCLUDEDELEMENTS)) { $fields['xml_elements'] = $existing->dsParamINCLUDEDELEMENTS; } else { $fields['xml_elements'] = array(); } $fields['sort'] = $existing->dsParamSORT; $fields['paginate_results'] = isset($existing->dsParamPAGINATERESULTS) ? $existing->dsParamPAGINATERESULTS : 'yes'; $fields['page_number'] = $existing->dsParamSTARTPAGE; $fields['group'] = isset($existing->dsParamGROUP) ? $existing->dsParamGROUP : null; $fields['html_encode'] = isset($existing->dsParamHTMLENCODE) ? $existing->dsParamHTMLENCODE : 'no'; $fields['associated_entry_counts'] = $existing->dsParamASSOCIATEDENTRYCOUNTS; if (is_null($fields['associated_entry_counts'])) { $fields['associated_entry_counts'] = 'yes'; } if ($existing->dsParamREDIRECTONEMPTY == 'yes') { $fields['redirect_on_empty'] = 'yes'; } if (!is_array($existing->dsParamFILTERS)) { $existing->dsParamFILTERS = array(); } if (!empty($existing->dsParamFILTERS)) { $existing->dsParamFILTERS = array_map('stripslashes', $existing->dsParamFILTERS); } $fields['source'] = $existing->getSource(); $provided = false; if (!empty($providers)) { foreach ($providers as $providerClass => $provider) { if ($fields['source'] == call_user_func(array($providerClass, 'getClass'))) { $fields = array_merge($fields, $existing->settings()); $provided = true; break; } } } if ($provided == false) { switch ($fields['source']) { case 'authors': $fields['filter']['author'] = $existing->dsParamFILTERS; break; case 'navigation': $fields['filter']['navigation'] = $existing->dsParamFILTERS; break; case 'dynamic_xml': $fields['dynamic_xml']['namespace'] = $existing->dsParamFILTERS; $fields['dynamic_xml']['url'] = $existing->dsParamURL; $fields['dynamic_xml']['xpath'] = $existing->dsParamXPATH; $fields['dynamic_xml']['cache'] = $existing->dsParamCACHE; $fields['dynamic_xml']['timeout'] = isset($existing->dsParamTIMEOUT) ? $existing->dsParamTIMEOUT : 6; break; case 'static_xml': $existing->grab(); if (!isset($existing->dsParamSTATIC)) { $fields['static_xml'] = trim($existing->dsSTATIC); } else { $fields['static_xml'] = trim($existing->dsParamSTATIC); } break; break; default: $fields['filter'][$fields['source']] = $existing->dsParamFILTERS; $fields['max_records'] = $existing->dsParamLIMIT; break; } } } else { $fields['dynamic_xml']['url'] = ''; $fields['dynamic_xml']['cache'] = '30'; $fields['dynamic_xml']['xpath'] = '/'; $fields['dynamic_xml']['timeout'] = '6'; $fields['dynamic_xml']['format'] = 'XML'; $fields['paginate_results'] = 'yes'; $fields['max_records'] = '20'; $fields['page_number'] = '1'; $fields['order'] = 'desc'; $fields['associated_entry_counts'] = NULL; } } $this->setPageType('form'); $this->setTitle(__($isEditing ? '%1$s – %2$s – %3$s' : '%2$s – %3$s', array($about['name'], __('Data Sources'), __('Symphony')))); $this->appendSubheading($isEditing ? $about['name'] : __('Untitled')); $this->insertBreadcrumbs(array(Widget::Anchor(__('Data Sources'), SYMPHONY_URL . '/blueprints/datasources/'))); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Essentials'))); $group = new XMLElement('div'); $group->setAttribute('class', 'two columns'); $div = new XMLElement('div', NULL, array('class' => 'column')); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[name]', General::sanitize($fields['name']))); if (isset($this->_errors['name'])) { $div->appendChild(Widget::Error($label, $this->_errors['name'])); } else { $div->appendChild($label); } $group->appendChild($div); $div = new XMLElement('div', NULL, array('class' => 'column')); $label = Widget::Label(__('Source')); $sections = SectionManager::fetch(NULL, 'ASC', 'name'); if (!is_array($sections)) { $sections = array(); } $field_groups = array(); foreach ($sections as $section) { $field_groups[$section->get('id')] = array('fields' => $section->fetchFields(), 'section' => $section); } $options = array(array('label' => __('System'), 'options' => array(array('authors', $fields['source'] == 'authors', __('Authors')), array('navigation', $fields['source'] == 'navigation', __('Navigation')))), array('label' => __('Custom XML'), 'options' => array(array('dynamic_xml', $fields['source'] == 'dynamic_xml', __('Dynamic XML')), array('static_xml', $fields['source'] == 'static_xml', __('Static XML'))))); // Loop over the datasource providers if (!empty($providers)) { $p = array('label' => __('From extensions'), 'options' => array()); foreach ($providers as $providerClass => $provider) { $p['options'][] = array($providerClass, $fields['source'] == $providerClass, $provider); } $options[] = $p; } // Add Sections if (is_array($sections) && !empty($sections)) { array_unshift($options, array('label' => __('Sections'), 'options' => array())); foreach ($sections as $s) { $options[0]['options'][] = array($s->get('id'), $fields['source'] == $s->get('id'), General::sanitize($s->get('name'))); } } $label->appendChild(Widget::Select('fields[source]', $options, array('id' => 'ds-context'))); $div->appendChild($label); $group->appendChild($div); $fieldset->appendChild($group); $this->Form->appendChild($fieldset); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings contextual authors navigation ' . __('Sections') . ' ' . __('System')); $fieldset->appendChild(new XMLElement('legend', __('Filter Results'))); $p = new XMLElement('p', __('Use %s syntax to filter by page parameters.', array('<code>{' . __('$param') . '}</code>'))); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); foreach ($field_groups as $section_id => $section_data) { $div = new XMLElement('div'); $div->setAttribute('class', 'contextual ' . $section_data['section']->get('id')); $ol = new XMLElement('ol'); $ol->setAttribute('class', 'filters-duplicator'); $ol->setAttribute('data-add', __('Add filter')); $ol->setAttribute('data-remove', __('Remove filter')); // Add system:id filter if (isset($fields['filter'][$section_data['section']->get('id')]['id'])) { $li = new XMLElement('li'); $li->setAttribute('class', 'unique'); $li->setAttribute('data-type', 'id'); $li->appendChild(new XMLElement('header', '<h4>' . __('System ID') . '</h4>')); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][' . $section_data['section']->get('id') . '][id]', General::sanitize($fields['filter'][$section_data['section']->get('id')]['id']))); $li->appendChild($label); $ol->appendChild($li); } $li = new XMLElement('li'); $li->setAttribute('class', 'unique template'); $li->setAttribute('data-type', 'id'); $li->appendChild(new XMLElement('header', '<h4>' . __('System ID') . '</h4>')); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][' . $section_data['section']->get('id') . '][id]')); $li->appendChild($label); $ol->appendChild($li); // Add system:date filter if (isset($fields['filter'][$section_data['section']->get('id')]['system:date'])) { $li = new XMLElement('li'); $li->setAttribute('class', 'unique'); $li->setAttribute('data-type', 'system:date'); $li->appendChild(new XMLElement('header', '<h4>' . __('System Date') . '</h4>')); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][' . $section_data['section']->get('id') . '][system:date]', General::sanitize($fields['filter'][$section_data['section']->get('id')]['system:date']))); $li->appendChild($label); $ol->appendChild($li); } $li = new XMLElement('li'); $li->setAttribute('class', 'unique template'); $li->setAttribute('data-type', 'system:date'); $li->appendChild(new XMLElement('header', '<h4>' . __('System Date') . '</h4>')); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][' . $section_data['section']->get('id') . '][system:date]')); $li->appendChild($label); $ol->appendChild($li); if (is_array($section_data['fields']) && !empty($section_data['fields'])) { foreach ($section_data['fields'] as $input) { if (!$input->canFilter()) { continue; } if (isset($fields['filter'][$section_data['section']->get('id')][$input->get('id')])) { $wrapper = new XMLElement('li'); $wrapper->setAttribute('class', 'unique'); $wrapper->setAttribute('data-type', $input->get('element_name')); $input->displayDatasourceFilterPanel($wrapper, $fields['filter'][$section_data['section']->get('id')][$input->get('id')], $this->_errors[$input->get('id')], $section_data['section']->get('id')); $ol->appendChild($wrapper); } $wrapper = new XMLElement('li'); $wrapper->setAttribute('class', 'unique template'); $wrapper->setAttribute('data-type', $input->get('element_name')); $input->displayDatasourceFilterPanel($wrapper, NULL, NULL, $section_data['section']->get('id')); $ol->appendChild($wrapper); } } $div->appendChild($ol); $fieldset->appendChild($div); } $div = new XMLElement('div'); $div->setAttribute('class', 'contextual authors'); $ol = new XMLElement('ol'); $ol->setAttribute('class', 'filters-duplicator'); $ol->setAttribute('data-add', __('Add filter')); $ol->setAttribute('data-remove', __('Remove filter')); $this->__appendAuthorFilter($ol, __('ID'), 'id', $fields['filter']['author']['id'], !isset($fields['filter']['author']['id'])); $this->__appendAuthorFilter($ol, __('Username'), 'username', $fields['filter']['author']['username'], !isset($fields['filter']['author']['username'])); $this->__appendAuthorFilter($ol, __('First Name'), 'first_name', $fields['filter']['author']['first_name'], !isset($fields['filter']['author']['first_name'])); $this->__appendAuthorFilter($ol, __('Last Name'), 'last_name', $fields['filter']['author']['last_name'], !isset($fields['filter']['author']['last_name'])); $this->__appendAuthorFilter($ol, __('Email'), 'email', $fields['filter']['author']['email'], !isset($fields['filter']['author']['email'])); $this->__appendAuthorFilter($ol, __('User Type'), 'user_type', $fields['filter']['author']['user_type'], !isset($fields['filter']['author']['user_type'])); $div->appendChild($ol); $fieldset->appendChild($div); $div = new XMLElement('div'); $div->setAttribute('class', 'contextual navigation'); $ol = new XMLElement('ol'); $ol->setAttribute('class', 'filters-duplicator'); $ol->setAttribute('data-add', __('Add filter')); $ol->setAttribute('data-remove', __('Remove filter')); $ul = new XMLElement('ul'); $ul->setAttribute('class', 'tags'); $pages = PageManager::fetch(false, array('*'), array(), 'title ASC'); foreach ($pages as $page) { $ul->appendChild(new XMLElement('li', preg_replace('/\\/{2,}/i', '/', '/' . $page['path'] . '/' . $page['handle']))); } if (isset($fields['filter']['navigation']['parent'])) { $li = new XMLElement('li'); $li->setAttribute('class', 'unique'); $li->setAttribute('data-type', 'parent'); $li->appendChild(new XMLElement('header', '<h4>' . __('Parent Page') . '</h4>')); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][navigation][parent]', General::sanitize($fields['filter']['navigation']['parent']))); $li->appendChild($label); $li->appendChild($ul); $ol->appendChild($li); } $li = new XMLElement('li'); $li->setAttribute('class', 'unique template'); $li->setAttribute('data-type', 'parent'); $li->appendChild(new XMLElement('header', '<h4>' . __('Parent Page') . '</h4>')); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][navigation][parent]')); $li->appendChild($label); $li->appendChild($ul); $ol->appendChild($li); $ul = new XMLElement('ul'); $ul->setAttribute('class', 'tags'); if ($types = PageManager::fetchAvailablePageTypes()) { foreach ($types as $type) { $ul->appendChild(new XMLElement('li', $type)); } } if (isset($fields['filter']['navigation']['type'])) { $li = new XMLElement('li'); $li->setAttribute('class', 'unique'); $li->setAttribute('data-type', 'type'); $li->appendChild(new XMLElement('header', '<h4>' . __('Page Type') . '</h4>')); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][navigation][type]', General::sanitize($fields['filter']['navigation']['type']))); $li->appendChild($label); $li->appendChild($ul); $ol->appendChild($li); } $li = new XMLElement('li'); $li->setAttribute('class', 'unique template'); $li->appendChild(new XMLElement('header', '<h4>' . __('Page Type') . '</h4>')); $li->setAttribute('data-type', 'type'); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][navigation][type]')); $li->appendChild($label); $li->appendChild($ul); $ol->appendChild($li); $div->appendChild($ol); $fieldset->appendChild($div); $this->Form->appendChild($fieldset); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings contextual inverse navigation authors static_xml dynamic_xml From_extensions'); $fieldset->appendChild(new XMLElement('legend', __('Sorting and Limiting'))); $p = new XMLElement('p', __('Use %s syntax to limit by page parameters.', array('<code>{' . __('$param') . '}</code>'))); $p->setAttribute('class', 'help contextual inverse navigation'); $fieldset->appendChild($p); $div = new XMLElement('div'); $div->setAttribute('class', 'two columns contextual sections ' . __('Sections')); $label = Widget::Label(__('Sort By'), NULL, 'column'); $options = array(array('label' => __('Authors'), 'options' => array(array('id', $fields['source'] == 'authors' && $fields['sort'] == 'id', __('Author ID')), array('username', $fields['source'] == 'authors' && $fields['sort'] == 'username', __('Username')), array('first-name', $fields['source'] == 'authors' && $fields['sort'] == 'first-name', __('First Name')), array('last-name', $fields['source'] == 'authors' && $fields['sort'] == 'last-name', __('Last Name')), array('email', $fields['source'] == 'authors' && $fields['sort'] == 'email', __('Email')), array('status', $fields['source'] == 'authors' && $fields['sort'] == 'status', __('Status')))), array('label' => __('Navigation'), 'options' => array(array('id', $fields['source'] == 'navigation' && $fields['sort'] == 'id', __('Page ID')), array('handle', $fields['source'] == 'navigation' && $fields['sort'] == 'handle', __('Handle')), array('sortorder', $fields['source'] == 'navigation' && $fields['sort'] == 'sortorder', __('Sort Order'))))); foreach ($field_groups as $section_id => $section_data) { $optgroup = array('label' => General::sanitize($section_data['section']->get('name')), 'options' => array(array('system:id', $fields['source'] == $section_data['section']->get('id') && $fields['sort'] == 'system:id', __('System ID')), array('system:date', $fields['source'] == $section_data['section']->get('id') && $fields['sort'] == 'system:date', __('System Date')))); if (is_array($section_data['fields']) && !empty($section_data['fields'])) { foreach ($section_data['fields'] as $input) { if (!$input->isSortable()) { continue; } $optgroup['options'][] = array($input->get('element_name'), $fields['source'] == $section_data['section']->get('id') && $input->get('element_name') == $fields['sort'], $input->get('label')); } } $options[] = $optgroup; } $label->appendChild(Widget::Select('fields[sort]', $options, array('class' => 'filtered'))); $div->appendChild($label); $label = Widget::Label(__('Sort Order'), NULL, 'column'); $options = array(array('asc', 'asc' == $fields['order'], __('ascending')), array('desc', 'desc' == $fields['order'], __('descending')), array('random', 'random' == $fields['order'], __('random'))); // Retain custom sort order if (!in_array($fields['order'], array('asc', 'desc', 'random'))) { $options[] = array($fields['order'], true, $fields['order']); } $label->appendChild(Widget::Select('fields[order]', $options)); $div->appendChild($label); $fieldset->appendChild($div); $label = Widget::Label(); $input = array(Widget::Input('fields[paginate_results]', NULL, 'checkbox', $fields['paginate_results'] == 'yes' ? array('checked' => 'checked') : NULL), Widget::Input('fields[max_records]', $fields['max_records'], 'text', array('size' => '6')), Widget::Input('fields[page_number]', $fields['page_number'], 'text', array('size' => '6'))); $label->setValue(__('%1$s Paginate results, limiting to %2$s entries per page. Return page %3$s', array($input[0]->generate(false), $input[1]->generate(false), $input[2]->generate(false)))); if (isset($this->_errors['max_records'])) { $fieldset->appendChild(Widget::Error($label, $this->_errors['max_records'])); } else { if (isset($this->_errors['page_number'])) { $fieldset->appendChild(Widget::Error($label, $this->_errors['page_number'])); } else { $fieldset->appendChild($label); } } $p = new XMLElement('p', __('Failing to paginate may degrade performance if the number of entries returned is very high.'), array('class' => 'help')); $fieldset->appendChild($p); $this->Form->appendChild($fieldset); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings contextual inverse navigation static_xml dynamic_xml From_extensions'); $fieldset->appendChild(new XMLElement('legend', __('Output Options'))); $label = Widget::Label(__('Required URL Parameter')); $label->appendChild(new XMLElement('i', __('Optional'))); $label->appendChild(Widget::Input('fields[required_url_param]', trim($fields['required_url_param']), 'text', array('placeholder' => __('$param')))); $fieldset->appendChild($label); $p = new XMLElement('p', __('An empty result will be returned when this parameter does not have a value.')); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $label = Widget::Label(); $input = Widget::Input('fields[redirect_on_empty]', 'yes', 'checkbox', isset($fields['redirect_on_empty']) ? array('checked' => 'checked') : NULL); $label->setValue(__('%s Redirect to 404 page when no results are found', array($input->generate(false)))); $fieldset->appendChild($label); $div = new XMLElement('div', NULL, array('class' => 'two columns')); $subfieldset = new XMLElement('fieldset', NULL, array('class' => 'column')); $subfieldset->appendChild(new XMLElement('legend', __('Output Parameters'))); // Support multiple parameters if (!is_array($fields['param'])) { $fields['param'] = array($fields['param']); } $label = Widget::Label(__('Use Fields')); $prefix = '$ds-' . (isset($this->_context[1]) ? Lang::createHandle($fields['name']) : '?') . '.'; $options = array(array('label' => __('Authors'), 'options' => array())); foreach (array('id', 'username', 'name', 'email', 'user_type') as $p) { $options[0]['options'][] = array($p, $fields['source'] == 'authors' && in_array($p, $fields['param']), $prefix . $p); } foreach ($field_groups as $section_id => $section_data) { $optgroup = array('label' => $section_data['section']->get('name'), 'options' => array()); foreach (array('id', 'date', 'author') as $p) { $optgroup['options'][] = array('system:' . $p, $fields['source'] == $section_data['section']->get('id') && in_array('system:' . $p, $fields['param']), $prefix . 'system-' . $p); } $authorOverride = false; if (is_array($section_data['fields']) && !empty($section_data['fields'])) { foreach ($section_data['fields'] as $input) { if (!$input->allowDatasourceParamOutput()) { continue; } $optgroup['options'][] = array($input->get('element_name'), $fields['source'] == $section_data['section']->get('id') && in_array($input->get('element_name'), $fields['param']), $prefix . $input->get('element_name')); } } $options[] = $optgroup; } $label->appendChild(Widget::Select('fields[param][]', $options, array('class' => 'filtered', 'multiple' => 'multiple'))); $subfieldset->appendChild($label); $div->appendChild($subfieldset); $subfieldset = new XMLElement('fieldset', NULL, array('class' => 'column')); $subfieldset->appendChild(new XMLElement('legend', __('XML Output'))); $label = Widget::Label(__('Group By')); $options = array(array('', NULL, __('None'))); foreach ($field_groups as $section_id => $section_data) { $optgroup = array('label' => $section_data['section']->get('name'), 'options' => array()); $authorOverride = false; if (is_array($section_data['fields']) && !empty($section_data['fields'])) { foreach ($section_data['fields'] as $input) { if (!$input->allowDatasourceOutputGrouping()) { continue; } if ($input->get('element_name') == 'author') { $authorOverride = true; } $optgroup['options'][] = array($input->get('id'), $fields['source'] == $section_data['section']->get('id') && $fields['group'] == $input->get('id'), $input->get('label')); } } if (!$authorOverride) { $optgroup['options'][] = array('author', $fields['source'] == $section_data['section']->get('id') && $fields['group'] == 'author', __('Author')); } $options[] = $optgroup; } $label->appendChild(Widget::Select('fields[group]', $options, array('class' => 'filtered'))); $subfieldset->appendChild($label); $label = Widget::Label(__('Included Elements')); $options = array(array('label' => __('Authors'), 'options' => array(array('username', $fields['source'] == 'authors' && in_array('username', $fields['xml_elements']), 'username'), array('name', $fields['source'] == 'authors' && in_array('name', $fields['xml_elements']), 'name'), array('email', $fields['source'] == 'authors' && in_array('email', $fields['xml_elements']), 'email'), array('author-token', $fields['source'] == 'authors' && in_array('author-token', $fields['xml_elements']), 'author-token'), array('default-area', $fields['source'] == 'authors' && in_array('default-area', $fields['xml_elements']), 'default-area')))); foreach ($field_groups as $section_id => $section_data) { $optgroup = array('label' => General::sanitize($section_data['section']->get('name')), 'options' => array(array('system:pagination', $fields['source'] == $section_data['section']->get('id') && in_array('system:pagination', $fields['xml_elements']), 'system: pagination'))); if (is_array($section_data['fields']) && !empty($section_data['fields'])) { foreach ($section_data['fields'] as $field) { $elements = $field->fetchIncludableElements(); if (is_array($elements) && !empty($elements)) { foreach ($elements as $name) { $selected = false; if ($fields['source'] == $section_data['section']->get('id') && in_array($name, $fields['xml_elements'])) { $selected = true; } $optgroup['options'][] = array($name, $selected, $name); } } } } $options[] = $optgroup; } $label->appendChild(Widget::Select('fields[xml_elements][]', $options, array('multiple' => 'multiple', 'class' => 'filtered'))); $subfieldset->appendChild($label); $label = Widget::Label(); $label->setAttribute('class', 'contextual inverse authors'); $input = Widget::Input('fields[associated_entry_counts]', 'yes', 'checkbox', isset($fields['associated_entry_counts']) && $fields['associated_entry_counts'] == 'yes' ? array('checked' => 'checked') : NULL); $label->setValue(__('%s Include a count of entries in associated sections', array($input->generate(false)))); $subfieldset->appendChild($label); $label = Widget::Label(); $label->setAttribute('class', 'contextual inverse authors'); $input = Widget::Input('fields[html_encode]', 'yes', 'checkbox', isset($fields['html_encode']) && $fields['html_encode'] == 'yes' ? array('checked' => 'checked') : NULL); $label->setValue(__('%s HTML-encode text', array($input->generate(false)))); $subfieldset->appendChild($label); $div->appendChild($subfieldset); $fieldset->appendChild($div); $this->Form->appendChild($fieldset); // Dynamic XML $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings contextual dynamic_xml'); $fieldset->appendChild(new XMLElement('legend', __('Dynamic XML'))); $label = Widget::Label(__('URL')); $label->appendChild(Widget::Input('fields[dynamic_xml][url]', General::sanitize($fields['dynamic_xml']['url']))); if (isset($this->_errors['dynamic_xml']['url'])) { $fieldset->appendChild(Widget::Error($label, $this->_errors['dynamic_xml']['url'])); } else { $fieldset->appendChild($label); } $p = new XMLElement('p', __('Use %s syntax to specify dynamic portions of the URL.', array('<code>{' . __('$param') . '}</code>'))); $p->setAttribute('class', 'help'); $label->appendChild($p); $div = new XMLElement('div'); $p = new XMLElement('p', __('Namespace Declarations')); $p->appendChild(new XMLElement('i', __('Optional'))); $p->setAttribute('class', 'label'); $div->appendChild($p); $ol = new XMLElement('ol'); $ol->setAttribute('class', 'filters-duplicator'); $ol->setAttribute('data-add', __('Add namespace')); $ol->setAttribute('data-remove', __('Remove namespace')); if (is_array($fields['dynamic_xml']['namespace'])) { $i = 0; foreach ($fields['dynamic_xml']['namespace'] as $name => $uri) { // Namespaces get saved to the file as $name => $uri, however in // the $_POST they are represented as $index => array. This loop // patches the difference. if (is_array($uri)) { $name = $uri['name']; $uri = $uri['uri']; } $li = new XMLElement('li'); $li->appendChild(new XMLElement('header', '<h4>' . __('Namespace') . '</h4>')); $group = new XMLElement('div'); $group->setAttribute('class', 'group'); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[dynamic_xml][namespace][' . $i . '][name]', General::sanitize($name))); $group->appendChild($label); $label = Widget::Label(__('URI')); $label->appendChild(Widget::Input('fields[dynamic_xml][namespace][' . $i . '][uri]', General::sanitize($uri))); $group->appendChild($label); $li->appendChild($group); $ol->appendChild($li); $i++; } } $li = new XMLElement('li'); $li->setAttribute('class', 'template'); $li->setAttribute('data-type', 'namespace'); $li->appendChild(new XMLElement('header', '<h4>' . __('Namespace') . '</h4>')); $group = new XMLElement('div'); $group->setAttribute('class', 'group'); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[dynamic_xml][namespace][-1][name]')); $group->appendChild($label); $label = Widget::Label(__('URI')); $label->appendChild(Widget::Input('fields[dynamic_xml][namespace][-1][uri]')); $group->appendChild($label); $li->appendChild($group); $ol->appendChild($li); $div->appendChild($ol); $fieldset->appendChild($div); $label = Widget::Label(__('Included Elements')); $label->appendChild(Widget::Input('fields[dynamic_xml][xpath]', General::sanitize($fields['dynamic_xml']['xpath']))); if (isset($this->_errors['dynamic_xml']['xpath'])) { $fieldset->appendChild(Widget::Error($label, $this->_errors['dynamic_xml']['xpath'])); } else { $fieldset->appendChild($label); } $p = new XMLElement('p', __('Use an XPath expression to select which elements from the source XML to include.')); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $label = Widget::Label(); $input = Widget::Input('fields[dynamic_xml][cache]', (string) max(1, intval($fields['dynamic_xml']['cache'])), 'text', array('size' => '6')); $label->setValue(__('Update cached result every %s minutes', array($input->generate(false)))); if (isset($this->_errors['dynamic_xml']['cache'])) { $fieldset->appendChild(Widget::Error($label, $this->_errors['dynamic_xml']['cache'])); } else { $fieldset->appendChild($label); } $label = Widget::Label(); $input = Widget::Input('fields[dynamic_xml][timeout]', (string) max(1, intval($fields['dynamic_xml']['timeout'])), 'text', array('type' => 'hidden')); $label->appendChild($input); $fieldset->appendChild($label); $this->Form->appendChild($fieldset); // Static XML $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings contextual static_xml'); $fieldset->appendChild(new XMLElement('legend', __('Static XML'))); $label = Widget::Label(__('Body')); $label->appendChild(Widget::Textarea('fields[static_xml]', 12, 50, General::sanitize(stripslashes($fields['static_xml'])), array('class' => 'code'))); if (isset($this->_errors['static_xml'])) { $fieldset->appendChild(Widget::Error($label, $this->_errors['static_xml'])); } else { $fieldset->appendChild($label); } $this->Form->appendChild($fieldset); // Call the provided datasources to let them inject their filters // @todo Ideally when a new Datasource is chosen an AJAX request will fire // to get the HTML from the extension. This is hardcoded for now into // creating a 'big' page and then hiding the fields with JS if (!empty($providers)) { foreach ($providers as $providerClass => $provider) { call_user_func(array($providerClass, 'buildEditor'), $this->Form, &$this->_errors, $fields, $handle); } } $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $isEditing ? __('Save Changes') : __('Create Data Source'), 'submit', array('accesskey' => 's'))); if ($isEditing) { $button = new XMLElement('button', __('Delete')); $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?'))); $div->appendChild($button); } $this->Form->appendChild($div); }