public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null) { // Check 'mode' exists; otherwise set manually from 'editable' $mode = $this->get('mode'); if (!$mode) { if ($this->get('editable') == 'yes') { $mode = 'normal'; } else { $mode = 'hidden'; } } // Render the field only if it's not hidden if ($mode != 'hidden') { $name = $this->get('element_name'); $edited_local = DateTimeObj::get(__SYM_DATETIME_FORMAT__, $data['local']); $current_local = DateTimeObj::get(__SYM_DATETIME_FORMAT__, null); $label = Widget::Label($this->get('label')); if ($mode == 'disabled') { $input = Widget::Input("{$name}-display", $edited_local); $input->setAttribute('disabled', 'disabled'); } else { $note = new XMLElement('i', __('Previous value: %s', array($edited_local))); $label->appendChild($note); $input = Widget::Input("fields{$fieldnamePrefix}[{$name}]", $current_local); } $label->appendChild($input); $label->setAttribute('class', 'date'); if (!is_null($flagWithError)) { $label = Widget::Error($label, $error); } $wrapper->appendChild($label); } }
function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null) { $note = isset($data['value']) ? $data['value'] : $this->get('note'); $editable = $this->get('editable'); # Add <div> $div = new XMLElement("div", $note, array("id" => Lang::createHandle($this->get('label')), "class" => "publishnotes-note")); $wrapper->appendChild($div); # Editable if (isset($editable) && $editable) { $wrapper->setAttribute('class', $wrapper->getAttribute('class') . " editable"); $edit = new XMLElement("a", __("Edit note"), array("class" => "publishnotes-edit", "href" => "#edit")); $wrapper->appendChild($edit); # Add <textarea> $label = Widget::Label("Edit: " . $this->get('label'), NULL, Lang::createHandle($this->get('label'))); $textarea = Widget::Textarea('fields' . $fieldnamePrefix . '[' . $this->get('element_name') . ']' . $fieldnamePostfix, 8, 50, strlen($note) != 0 ? General::sanitize($note) : NULL); $label->appendChild($textarea); $control = new XMLElement("div", '<input type="submit" value="Change note"/> or <a href="#">cancel</a>', array("class" => "control")); $label->appendChild($control); if ($flagWithError != NULL) { $wrapper->appendChild(Widget::Error($label, $flagWithError)); } else { $wrapper->appendChild($label); } } }
public function displayPublishPanel(&$wrapper, $data = NULL, $flagWithError = NULL, $fieldnamePrefix = NULL, $fieldnamePostfix = NULL) { $value = $data['value']; $label = Widget::Label($this->get('label')); $label->appendChild(Widget::Input('fields' . $fieldnamePrefix . '[' . $this->get('element_name') . ']' . $fieldnamePostfix, (string) (strlen($value) != 0 ? $value : $this->getNewNumber()), 'text', array('readonly' => 'readonly'))); if ($flagWithError != NULL) { $wrapper->appendChild(Widget::Error($label, $flagWithError)); } else { $wrapper->appendChild($label); } }
public function buildSummaryBlock($errors = null) { $order = $this->get('sortorder'); $div = new XMLElement('div'); $div->appendChild(Widget::Input("fields[{$order}][location]", 'main', 'hidden')); $label = Widget::Label(__('Label')); $label->appendChild(Widget::Input("fields[{$order}][label]", $this->get('label'))); if (isset($errors['label'])) { $label = Widget::Error($label, $errors['label']); } $div->appendChild($label); return $div; }
public function displayPublishPanel(&$wrapper, $data = NULL, $flagWithError = NULL, $fieldnamePrefix = NULL, $fieldnamePostfix = NULL) { $label = Widget::Label($this->get('label')); $label->appendChild(new XMLElement('a', __('Select Link'), array('style' => 'float: right;', 'onclick' => "\n document.getElementById('unique_link_" . $this->get('id') . "').select(); return false;\n "))); $link = str_replace('[URL]', URL, $this->get('link')); $link = str_replace('[CODE]', $data['code'], $link); $value = $data === null ? __('A link will automaticly be generated when you save this entry') : $link; $label->appendChild(Widget::Input('fields' . $fieldnamePrefix . '[' . $this->get('element_name') . ']' . $fieldnamePostfix, $value, 'text', array('id' => 'unique_link_' . $this->get('id'), 'readonly' => 'readonly', 'style' => 'background: #eee; color: #666; border: 1px solid #ccc;'))); if ($flagWithError != NULL) { $wrapper->appendChild(Widget::Error($label, $flagWithError)); } else { $wrapper->appendChild($label); } }
public function displayPublishPanel(XMLElement &$wrapper, $data = null, $error = null, $prefix = null, $postfix = null, $entry_id = null) { $field_id = $this->get('id'); $handle = $this->get('element_name'); // Identity $label = Widget::Label($this->get('label')); if (!($this->get('required') == 'yes')) { $label->appendChild(new XMLElement('i', __('Optional'))); } $label->appendChild(Widget::Input("fields{$prefix}[{$handle}]{$postfix}", $data['value'])); // Error? if (!is_null($error)) { $wrapper->appendChild(Widget::Error($label, $error)); } else { $wrapper->appendChild($label); } }
public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null) { Extension_ExpressionField::appendAssets(); $handle = $this->get('element_name'); // Defaults ----------------------------------------------------------- $wrapper->appendChild(Widget::Input("fields{$fieldnamePrefix}[{$handle}][is_cased]{$fieldnamePostfix}", 'no', 'hidden')); $wrapper->appendChild(Widget::Input("fields{$fieldnamePrefix}[{$handle}][is_regexp]{$fieldnamePostfix}", 'no', 'hidden')); // Expression --------------------------------------------------------- $label = Widget::Label(__('Expression')); $label->appendChild(Widget::Input("fields{$fieldnamePrefix}[{$handle}][value]{$fieldnamePostfix}", General::sanitize($data['value']))); if (isset($error)) { $label = Widget::Error($label, $flagWithError); } $wrapper->appendChild($label); $help = new XMLElement('p'); $help->setAttribute('class', 'help'); $help->setValue(__('Use %s as a wild-card unless regular expressions are enabled.', array('<code>*</code>'))); $wrapper->appendChild($help); // Cased? ------------------------------------------------------------- $settings = new XMLElement('div', null, array('class' => 'frame')); $input = Widget::Input("fields{$fieldnamePrefix}[{$handle}][is_cased]{$fieldnamePostfix}", 'yes', 'checkbox', $data['is_cased'] == 'yes' ? array('checked' => 'checked') : null); $label = Widget::Label(__('%s Case sensitive?', array($input->generate()))); $settings->appendChild($label); $help = new XMLElement('p'); $help->setAttribute('class', 'help'); $help->setValue(__('Treat upper case and lower case letters differently.')); $settings->appendChild($help); // Regexp? ------------------------------------------------------------ $input = Widget::Input("fields{$fieldnamePrefix}[{$handle}][is_regexp]{$fieldnamePostfix}", 'yes', 'checkbox', $data['is_regexp'] == 'yes' ? array('checked' => 'checked') : null); $label = Widget::Label(__('%s Regular expressions?', array($input->generate()))); $settings->appendChild($label); $help = new XMLElement('p'); $help->setAttribute('class', 'help'); $help->setValue(__('Advanced matching with <a href="%s">Perl compatible regular expressions</a>.', array(SYMPHONY_URL . '/extension/expressionfield/documentation/'))); $settings->appendChild($help); $wrapper->appendChild($settings); }
public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null) { $value = null; if (isset($data['value'])) { $value = is_array($data['value']) ? self::__tagArrayToString($data['value']) : $data['value']; } $label = Widget::Label($this->get('label')); if ($this->get('required') != 'yes') { $label->appendChild(new XMLElement('i', __('Optional'))); } $label->appendChild(Widget::Input('fields' . $fieldnamePrefix . '[' . $this->get('element_name') . ']' . $fieldnamePostfix, strlen($value) != 0 ? General::sanitize($value) : null)); if ($flagWithError != null) { $wrapper->appendChild(Widget::Error($label, $flagWithError)); } else { $wrapper->appendChild($label); } if ($this->get('pre_populate_source') != null) { $existing_tags = $this->getToggleStates(); if (is_array($existing_tags) && !empty($existing_tags)) { $taglist = new XMLElement('ul'); $taglist->setAttribute('class', 'tags'); $taglist->setAttribute('data-interactive', 'data-interactive'); foreach ($existing_tags as $tag) { $taglist->appendChild(new XMLElement('li', General::sanitize($tag))); } $wrapper->appendChild($taglist); } } }
public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null) { $value = isset($data['author_id']) ? $data['author_id'] : null; if ($this->get('default_to_current_user') === 'yes' && empty($data) && empty($_POST)) { $value = array(Symphony::Author()->get('id')); } if (!is_array($value)) { $value = array($value); } $options = array(); if ($this->get('required') !== 'yes') { $options[] = array(null, false, null); } // Custom where to only show Authors based off the Author Types setting $types = $this->get('author_types'); if (!empty($types)) { $types = implode('","', $this->get('author_types')); $where = 'user_type IN ("' . $types . '")'; } $authors = AuthorManager::fetch('id', 'ASC', null, null, $where); $found = false; foreach ($authors as $a) { if (in_array($a->get('id'), $value)) { $found = true; } $options[] = array($a->get('id'), in_array($a->get('id'), $value), $a->getFullName()); } // Ensure the selected Author is included in the options (incase // the settings change after the original entry was created) if (!$found && !is_null($value)) { $authors = AuthorManager::fetchByID($value); foreach ($authors as $a) { $options[] = array($a->get('id'), in_array($a->get('id'), $value), $a->getFullName()); } } $fieldname = 'fields' . $fieldnamePrefix . '[' . $this->get('element_name') . ']' . $fieldnamePostfix; if ($this->get('allow_multiple_selection') === 'yes') { $fieldname .= '[]'; } $label = Widget::Label($this->get('label')); if ($this->get('required') !== 'yes') { $label->appendChild(new XMLElement('i', __('Optional'))); } $label->appendChild(Widget::Select($fieldname, $options, $this->get('allow_multiple_selection') === 'yes' ? array('multiple' => 'multiple') : null)); if ($flagWithError != null) { $wrapper->appendChild(Widget::Error($label, $flagWithError)); } else { $wrapper->appendChild($label); } }
/** * Construct the html block to display a summary of this field, which is the field * Label and it's location within the section. Any error messages generated are * appended to the optional input error array. This function calls * `buildLocationSelect` once it is completed * * @see buildLocationSelect() * @param array $errors (optional) * an array to append html formatted error messages to. this defaults to null. * @return XMLElement * the root XML element of the html display of this. */ public function buildSummaryBlock($errors = null) { $div = new XMLElement('div'); // Publish label $label = Widget::Label(__('Label')); $label->appendChild(Widget::Input('fields[' . $this->get('sortorder') . '][label]', $this->get('label'))); if (isset($errors['label'])) { $div->appendChild(Widget::Error($label, $errors['label'])); } else { $div->appendChild($label); } // Handle + placement $group = new XMLElement('div'); $group->setAttribute('class', 'two columns'); $label = Widget::Label(__('Handle')); $label->setAttribute('class', 'column'); $label->appendChild(Widget::Input('fields[' . $this->get('sortorder') . '][element_name]', $this->get('element_name'))); if (isset($errors['element_name'])) { $group->appendChild(Widget::Error($label, $errors['element_name'])); } else { $group->appendChild($label); } // Location $group->appendChild($this->buildLocationSelect($this->get('location'), 'fields[' . $this->get('sortorder') . '][location]')); $div->appendChild($group); return $div; }
public function __form($readonly = false) { $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': $this->pageAlert(__('Event updated at %s.', array($time->generate())) . ' <a href="' . SYMPHONY_URL . '/blueprints/events/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/blueprints/events/" accesskey="a">' . __('View all Events') . '</a>', Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Event created at %s.', array($time->generate())) . ' <a href="' . SYMPHONY_URL . '/blueprints/events/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/blueprints/events/" accesskey="a">' . __('View all Events') . '</a>', Alert::SUCCESS); break; } } $isEditing = $readonly ? true : false; $fields = array("name" => null, "filters" => null); $about = array("name" => null); $providers = Symphony::ExtensionManager()->getProvidersOf(iProvider::EVENT); if (isset($_POST['fields'])) { $fields = $_POST['fields']; if ($this->_context[0] == 'edit') { $isEditing = true; } } elseif ($this->_context[0] == 'edit' || $this->_context[0] == 'info') { $isEditing = true; $handle = $this->_context[1]; $existing = EventManager::create($handle); $about = $existing->about(); if ($this->_context[0] == 'edit' && !$existing->allowEditorToParse()) { redirect(SYMPHONY_URL . '/blueprints/events/info/' . $handle . '/'); } $fields['name'] = $about['name']; $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) { if (isset($existing->eParamFILTERS)) { $fields['filters'] = $existing->eParamFILTERS; } } } // 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($about['name'], __('Events'), __('Symphony')))); $this->appendSubheading($isEditing ? $about['name'] : __('Untitled')); $this->insertBreadcrumbs(array(Widget::Anchor(__('Events'), SYMPHONY_URL . '/blueprints/events/'))); if (!$readonly) { $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Essentials'))); // Target $sources = new XMLElement('div', null, array('class' => 'apply actions')); $div = new XMLElement('div'); $label = Widget::Label(__('Target'), null, 'apply-label-left'); $sources->appendChild($label); $sources->appendChild($div); $sections = SectionManager::fetch(null, 'ASC', 'name'); $options = array(); $section_options = array(); $source = isset($fields['source']) ? $fields['source'] : null; if (is_array($sections) && !empty($sections)) { $section_options = array('label' => __('Sections'), 'options' => array()); foreach ($sections as $s) { $section_options['options'][] = array($s->get('id'), $source == $s->get('id'), General::sanitize($s->get('name'))); } } $options[] = $section_options; // Loop over the event 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; } $div->appendChild(Widget::Select('source', $options, array('id' => 'event-context'))); if (isset($this->_errors['source'])) { $this->Context->prependChild(Widget::Error($sources, $this->_errors['source'])); } else { $this->Context->prependChild($sources); } $this->Form->appendChild(Widget::Input('fields[source]', $options[0]['options'][0][0], 'hidden', array('id' => 'event-source'))); // Name $group = new XMLElement('div'); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[name]', General::sanitize($fields['name']))); $div = new XMLElement('div'); $div->setAttribute('class', 'column'); if (isset($this->_errors['name'])) { $div->appendChild(Widget::Error($label, $this->_errors['name'])); } else { $div->appendChild($label); } $group->appendChild($div); $fieldset->appendChild($group); $this->Form->appendChild($fieldset); // Filters $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings pickable'); $fieldset->appendChild(new XMLElement('legend', __('Filters'))); $p = new XMLElement('p', __('Event Filters add additional conditions or actions to an event.')); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $filters = isset($fields['filters']) ? $fields['filters'] : array(); $options = array(array('admin-only', in_array('admin-only', $filters), __('Admin Only')), array('send-email', in_array('send-email', $filters), __('Send Notification Email')), array('expect-multiple', in_array('expect-multiple', $filters), __('Allow Multiple'))); /** * Allows adding of new filter rules to the Event filter rule select box * * @delegate AppendEventFilter * @param string $context * '/blueprints/events/(edit|new|info)/' * @param array $selected * An array of all the selected filters for this Event * @param array $options * An array of all the filters that are available, passed by reference */ Symphony::ExtensionManager()->notifyMembers('AppendEventFilter', '/blueprints/events/' . $this->_context[0] . '/', array('selected' => $filters, 'options' => &$options)); $fieldset->appendChild(Widget::Select('fields[filters][]', $options, array('multiple' => 'multiple', 'id' => 'event-filters'))); $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 event 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(); $event_handle = str_replace('-', '_', Lang::createHandle($fields['name'])); $connections = ResourceManager::getAttachedPages(RESOURCE_TYPE_EVENT, $event_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); // Providers if (!empty($providers)) { foreach ($providers as $providerClass => $provider) { if ($isEditing && $fields['source'] !== call_user_func(array($providerClass, 'getSource'))) { continue; } call_user_func_array(array($providerClass, 'buildEditor'), array($this->Form, &$this->_errors, $fields, $handle)); } } } else { // Author if (isset($about['author']['website'])) { $link = Widget::Anchor($about['author']['name'], General::validateURL($about['author']['website'])); } elseif (isset($about['author']['email'])) { $link = Widget::Anchor($about['author']['name'], 'mailto:' . $about['author']['email']); } else { $link = $about['author']['name']; } if ($link) { $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Author'))); $fieldset->appendChild(new XMLElement('p', $link->generate(false))); $this->Form->appendChild($fieldset); } // Version $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Version'))); $version = array_key_exists('version', $about) ? $about['version'] : null; $release_date = array_key_exists('release-date', $about) ? $about['release-date'] : filemtime(EventManager::__getDriverPath($handle)); if (preg_match('/^\\d+(\\.\\d+)*$/', $version)) { $fieldset->appendChild(new XMLElement('p', __('%1$s released on %2$s', array($version, DateTimeObj::format($release_date, __SYM_DATE_FORMAT__))))); } elseif (!is_null($version)) { $fieldset->appendChild(new XMLElement('p', __('Created by %1$s at %2$s', array($version, DateTimeObj::format($release_date, __SYM_DATE_FORMAT__))))); } else { $fieldset->appendChild(new XMLElement('p', __('Last modified on %s', array(DateTimeObj::format($release_date, __SYM_DATE_FORMAT__))))); } $this->Form->appendChild($fieldset); } // If we are editing an event, it assumed that the event has documentation $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('id', 'event-documentation'); $fieldset->setAttribute('class', 'settings'); if ($isEditing && method_exists($existing, 'documentation')) { $doc = $existing->documentation(); if ($doc) { $fieldset->setValue('<legend>' . __('Documentation') . '</legend>' . PHP_EOL . General::tabsToSpaces(is_object($doc) ? $doc->generate(true, 4) : $doc)); } } $this->Form->appendChild($fieldset); $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $isEditing ? __('Save Changes') : __('Create Event'), 'submit', array('accesskey' => 's'))); if ($isEditing) { $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this event'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this event?'))); $div->appendChild($button); } if (!$readonly) { $this->Form->appendChild($div); } }
function render() { $this->setPageType('form'); $fields = array(); // If we're editing, make sure the item exists if ($this->_context[0]) { if (!($doc_id = $this->_context[0])) { redirect(URL . '/symphony/extension/documenter/manage'); } $existing = Symphony::Database()->fetchRow(0, "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\td.*\n\t\t\t\t\tFROM\n\t\t\t\t\t\t`tbl_documentation` AS d\n\t\t\t\t\tWHERE\n\t\t\t\t\t\td.id = '{$doc_id}'\n\t\t\t\t\tLIMIT 1\n\t\t\t\t"); if (!$existing) { $this->_Parent->customError(E_USER_ERROR, __('Documentation Item not found'), __('The documentation item you requested to edit does not exist.'), false, true, 'error', array('header' => 'HTTP/1.0 404 Not Found')); } } // Build the status message if (isset($this->_context[1])) { if ($this->_context[1] == 'saved') { $this->pageAlert(__('Documentation Item updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Documentation</a>', array(Widget::Time()->generate(__SYM_TIME_FORMAT__), URL . '/symphony/extension/documenter/new/', URL . '/symphony/extension/documenter/')), Alert::SUCCESS); } else { $this->pageAlert(__('Documentation Item created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Documentation</a>', array(Widget::Time()->generate(__SYM_TIME_FORMAT__), URL . '/symphony/extension/documenter/new/', URL . '/symphony/extension/documenter/')), Alert::SUCCESS); } } // Find values if (isset($_POST['fields'])) { $fields = $_POST['fields']; } else { if ($this->_context[0]) { $fields = $existing; $fields['content'] = General::sanitize($fields['content']); } } $title = $fields['title']; if (trim($title) == '') { $title = $existing['title']; } // Start building the page $this->setTitle(__($title ? '%1$s – %2$s – %3$s' : '%1$s – %2$s', array(__('Symphony'), __('Documentation'), $title))); $this->appendSubheading($title ? $title : __('Untitled')); // Start building the fieldsets $this->Form->setAttribute('class', 'two columns'); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'primary column'); // Title text input $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); // Content textarea $label = Widget::Label(__('Content')); $content = Widget::Textarea('fields[content]', 30, 80, $fields['content']); if (Symphony::Configuration()->get('text-formatter', 'documentation') != 'none') { $content->setAttribute('class', Symphony::Configuration()->get('text-formatter', 'documentation')); } $label->appendChild($content); $fieldset->appendChild(isset($this->_errors['content']) ? Widget::Error($label, $this->_errors['content']) : $label); $fieldset->appendChild(Widget::Input('autogenerate', __('Auto-generate content according to selected section(s)'), 'button', array('class' => 'button'))); $this->Form->appendChild($fieldset); // Pages multi-select $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'secondary column'); $label = Widget::Label(__('Pages')); if (!is_array($fields['pages'])) { $pages_array = explode(',', $fields['pages']); } else { $pages_array = $fields['pages']; } $options = array(); // Generate a list of sectionField-data for auto-generation of documentation: $arr = array(); // Build the options list using the navigation array foreach (Administration::instance()->Page->_navigation as $menu) { $items = array(); foreach ($menu['children'] as $item) { $items[] = array($item['link'], in_array($item['link'], $pages_array), $menu['name'] . " > " . $item['name']); // If it's a section, add New and Edit pages // NOTE: This will likely break when extensions add custom nav groups if ($menu['name'] != 'Blueprints' and $menu['name'] != 'System') { $items[] = array($item['link'] . 'new/', in_array($item['link'] . 'new/', $pages_array), $menu['name'] . " > " . $item['name'] . " New"); $items[] = array($item['link'] . 'edit/', in_array($item['link'] . 'edit/', $pages_array), $menu['name'] . " > " . $item['name'] . " Edit"); } // Generate a list of sectionField-data for auto-generation of documentation: if ($item['type'] == 'section') { $arr2 = array('name' => $item['name'], 'link' => $item['link'], 'items' => array()); $fields = FieldManager::fetch(null, $item['section']['id']); foreach ($fields as $field) { /* @var $field Field */ $arr2['items'][] = array('label' => $field->get('label')); } $arr[] = $arr2; } } $options[] = array('label' => $menu['name'], 'options' => $items); } Administration::instance()->Page->addElementToHead(new XMLElement('script', 'var sectionFields = ' . json_encode($arr) . ';', array('type' => 'text/javascript'))); $label->appendChild(Widget::Select('fields[pages][]', $options, array('multiple' => 'multiple', 'id' => 'documenter-pagelist'))); if (isset($this->_errors['pages'])) { $label = Widget::Error($label, $this->_errors['pages']); } $fieldset->appendChild($label); $this->Form->appendChild($fieldset); // Form actions $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $this->_context[0] ? __('Save Changes') : __('Document It'), 'submit', array('accesskey' => 's'))); if ($this->_context[0]) { $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'confirm delete', 'title' => __('Delete this template'))); $div->appendChild($button); } $this->Form->appendChild($div); }
public function __form() { require_once TOOLKIT . '/class.field.php'; // Handle unknown context if (!in_array($this->_context[0], array('new', 'edit'))) { Administration::instance()->errorPageNotFound(); } if ($this->_context[0] == 'new' && !Administration::instance()->Author->isDeveloper()) { Administration::instance()->customError(__('Access Denied'), __('You are not authorised to access this page.')); } if (isset($this->_context[2])) { switch ($this->_context[2]) { case 'saved': $this->pageAlert(__('Author updated at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/system/authors/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/system/authors/" accesskey="a">' . __('View all Authors') . '</a>', Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Author created at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/system/authors/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/system/authors/" accesskey="a">' . __('View all Authors') . '</a>', Alert::SUCCESS); break; } } $this->setPageType('form'); $isOwner = false; if (isset($_POST['fields'])) { $author = $this->_Author; } else { if ($this->_context[0] == 'edit') { if (!($author_id = $this->_context[1])) { redirect(SYMPHONY_URL . '/system/authors/'); } if (!($author = AuthorManager::fetchByID($author_id))) { Administration::instance()->customError(__('Author not found'), __('The author profile you requested does not exist.')); } } else { $author = new Author(); } } if ($this->_context[0] == 'edit' && $author->get('id') == Administration::instance()->Author->get('id')) { $isOwner = true; } if ($this->_context[0] == 'edit' && !$isOwner && !Administration::instance()->Author->isDeveloper()) { Administration::instance()->customError(__('Access Denied'), __('You are not authorised to edit other authors.')); } $this->setTitle(__($this->_context[0] == 'new' ? '%2$s – %3$s' : '%1$s – %2$s – %3$s', array($author->getFullName(), __('Authors'), __('Symphony')))); $this->appendSubheading($this->_context[0] == 'new' ? __('Untitled') : $author->getFullName()); $this->insertBreadcrumbs(array(Widget::Anchor(__('Authors'), SYMPHONY_URL . '/system/authors/'))); // Essentials $group = new XMLElement('fieldset'); $group->setAttribute('class', 'settings'); $group->appendChild(new XMLElement('legend', __('Essentials'))); $div = new XMLElement('div'); $div->setAttribute('class', 'two columns'); $label = Widget::Label(__('First Name'), NULL, 'column'); $label->appendChild(Widget::Input('fields[first_name]', $author->get('first_name'))); $div->appendChild(isset($this->_errors['first_name']) ? Widget::Error($label, $this->_errors['first_name']) : $label); $label = Widget::Label(__('Last Name'), NULL, 'column'); $label->appendChild(Widget::Input('fields[last_name]', $author->get('last_name'))); $div->appendChild(isset($this->_errors['last_name']) ? Widget::Error($label, $this->_errors['last_name']) : $label); $group->appendChild($div); $label = Widget::Label(__('Email Address')); $label->appendChild(Widget::Input('fields[email]', $author->get('email'))); $group->appendChild(isset($this->_errors['email']) ? Widget::Error($label, $this->_errors['email']) : $label); $this->Form->appendChild($group); // Login Details $group = new XMLElement('fieldset'); $group->setAttribute('class', 'settings'); $group->appendChild(new XMLElement('legend', __('Login Details'))); $div = new XMLElement('div'); $label = Widget::Label(__('Username')); $label->appendChild(Widget::Input('fields[username]', $author->get('username'))); $div->appendChild(isset($this->_errors['username']) ? Widget::Error($label, $this->_errors['username']) : $label); // Only developers can change the user type. Primary account should NOT be able to change this if (Administration::instance()->Author->isDeveloper() && !$author->isPrimaryAccount()) { // Create columns $div->setAttribute('class', 'two columns'); $label->setAttribute('class', 'column'); // User type $label = Widget::Label(__('User Type'), NULL, 'column'); $options = array(array('author', false, __('Author')), array('developer', $author->isDeveloper(), __('Developer'))); $label->appendChild(Widget::Select('fields[user_type]', $options)); $div->appendChild($label); } $group->appendChild($div); // Password $fieldset = new XMLElement('fieldset', NULL, array('class' => 'two columns', 'id' => 'password')); $legend = new XMLElement('legend', __('Password')); $help = new XMLElement('i', __('Leave password fields blank to keep the current password')); $fieldset->appendChild($legend); $fieldset->appendChild($help); // Password reset if ($this->_context[0] == 'edit' && (!Administration::instance()->Author->isDeveloper() || $isOwner === true)) { $fieldset->setAttribute('class', 'three columns'); $label = Widget::Label(NULL, NULL, 'column'); $label->appendChild(Widget::Input('fields[old-password]', NULL, 'password', array('placeholder' => __('Old Password')))); $fieldset->appendChild(isset($this->_errors['old-password']) ? Widget::Error($label, $this->_errors['password']) : $label); } // New password $callback = Administration::instance()->getPageCallback(); $placeholder = $callback['context'][0] == 'edit' ? __('New Password') : __('Password'); $label = Widget::Label(NULL, NULL, 'column'); $label->appendChild(Widget::Input('fields[password]', NULL, 'password', array('placeholder' => $placeholder))); $fieldset->appendChild(isset($this->_errors['password']) ? Widget::Error($label, $this->_errors['password']) : $label); // Confirm password $label = Widget::Label(NULL, NULL, 'column'); $label->appendChild(Widget::Input('fields[password-confirmation]', NULL, 'password', array('placeholder' => __('Confirm Password')))); $fieldset->appendChild(isset($this->_errors['password-confirmation']) ? Widget::Error($label, $this->_errors['password']) : $label); $group->appendChild($fieldset); // Auth token if (Administration::instance()->Author->isDeveloper()) { $label = Widget::Label(); $input = Widget::Input('fields[auth_token_active]', 'yes', 'checkbox'); if ($author->isTokenActive()) { $input->setAttribute('checked', 'checked'); } $temp = SYMPHONY_URL . '/login/' . $author->createAuthToken() . '/'; $label->setValue(__('%s Allow remote login via', array($input->generate())) . ' <a href="' . $temp . '">' . $temp . '</a>'); $group->appendChild($label); } $label = Widget::Label(__('Default Area')); $sections = SectionManager::fetch(NULL, 'ASC', 'sortorder'); $options = array(); // If the Author is the Developer, allow them to set the Default Area to // be the Sections Index. if ($author->isDeveloper()) { $options[] = array('/blueprints/sections/', $author->get('default_area') == '/blueprints/sections/', __('Sections Index')); } if (is_array($sections) && !empty($sections)) { foreach ($sections as $s) { $options[] = array($s->get('id'), $author->get('default_area') == $s->get('id'), $s->get('name')); } } /** * Allows injection or manipulation of the Default Area dropdown for an Author. * Take care with adding in options that are only valid for Developers, as if a * normal Author is set to that option, they will be redirected to their own * Author record. * * * @delegate AddDefaultAuthorAreas * @since Symphony 2.2 * @param string $context * '/system/authors/' * @param array $options * An associative array of options, suitable for use for the Widget::Select * function. By default this will be an array of the Sections in the current * installation. New options should be the path to the page after the `SYMPHONY_URL` * constant. * @param string $default_area * The current `default_area` for this Author. */ Symphony::ExtensionManager()->notifyMembers('AddDefaultAuthorAreas', '/system/authors/', array('options' => &$options, 'default_area' => $author->get('default_area'))); $label->appendChild(Widget::Select('fields[default_area]', $options)); $group->appendChild($label); $this->Form->appendChild($group); // Custom Language Selection $languages = Lang::getAvailableLanguages(); if (count($languages) > 1) { // Get language names asort($languages); $group = new XMLElement('fieldset'); $group->setAttribute('class', 'settings'); $group->appendChild(new XMLElement('legend', __('Custom Preferences'))); $label = Widget::Label(__('Language')); $options = array(array(NULL, is_null($author->get('language')), __('System Default'))); foreach ($languages as $code => $name) { $options[] = array($code, $code == $author->get('language'), $name); } $select = Widget::Select('fields[language]', $options); $label->appendChild($select); $group->appendChild($label); $this->Form->appendChild($group); } $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : __('Create Author'), 'submit', array('accesskey' => 's'))); if ($this->_context[0] == 'edit' && !$isOwner && !$author->isPrimaryAccount()) { $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this author'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this author?'))); $div->appendChild($button); } $this->Form->appendChild($div); /** * Allows the injection of custom form fields given the current `$this->Form` * object. Please note that this custom data should be saved in own extension * tables and that modifying `tbl_authors` to house your data is highly discouraged. * * @delegate AddElementstoAuthorForm * @since Symphony 2.2 * @param string $context * '/system/authors/' * @param XMLElement $form * The contents of `$this->Form` after all the default form elements have been appended. * @param Author $author * The current Author object that is being edited */ Symphony::ExtensionManager()->notifyMembers('AddElementstoAuthorForm', '/system/authors/', array('form' => &$this->Form, 'author' => $author)); }
public function __viewIndex() { $this->setPageType('form'); $this->setTitle(__('%1$s – %2$s – %3$s', array(__("New"), __('Cron'), __('Symphony')))); $this->appendSubheading(__('Untitled')); $formHasErrors = (bool) (is_array($this->_errors) && !empty($this->_errors)); if ($formHasErrors) { $this->pageAlert(__('An error occurred while processing this form. <a href="#error">See below for details.</a>'), Alert::ERROR); } // Essentials $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Essentials'))); if (!empty($_POST)) { $fields = $_POST['fields']; } else { $fields = ['interval' => 60]; } $label = Widget::Label('Name'); $label->appendChild(Widget::Input('fields[name]', $fields['name'])); $fieldset->appendChild(isset($this->_errors['name']) ? Widget::Error($label, $this->_errors['name']) : $label); $label = Widget::Label('Command'); $label->appendChild(Widget::Input('fields[command]', $fields['command'])); $fieldset->appendChild(isset($this->_errors['command']) ? Widget::Error($label, $this->_errors['command']) : $label); $p = new XMLElement('p', '↑ This is any command that can be executed from the command line.'); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $label = Widget::Label('Description <i>Optional</i>'); $label->appendChild(Widget::Input('fields[description]', $fields['description'])); $fieldset->appendChild(isset($this->_errors['description']) ? Widget::Error($label, $this->_errors['description']) : $label); $label = Widget::Label(); $input = Widget::Input('fields[interval]', (string) max(1, $fields['interval']), null, array('size' => '6')); $options = [['minute', $fields['interval'] == 'minute', 'minutes'], ['hour', $fields['interval'] == 'hour', 'hours'], ['day', $fields['interval'] == 'day', 'days'], ['week', $fields['interval'] == 'week', 'weeks']]; $select = Widget::Select('fields[interval-type]', $options, ['class' => 'inline', 'style' => 'display: inline; width: auto;']); $label->setValue(__('Run this task every %s %s', [$input->generate(false), $select->generate(false)])); if (isset($this->_errors['interval'])) { $fieldset->appendChild(Widget::Error($label, $this->_errors['interval'])); } else { $fieldset->appendChild($label); } $label = Widget::Label(); $input = Widget::Input('fields[enabled]', 'yes', 'checkbox', isset($fields['enabled']) ? array('checked' => 'checked') : null); $label->setValue(__('%s Enable this task', array($input->generate(false)))); $fieldset->appendChild($label); $p = new XMLElement('p', '↑ Unless a <strong>start date</strong> has been specified, this task will be executed once the current date plus the interval specified has passed.'); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $this->Form->appendChild($fieldset); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Timing'))); $group = new XMLElement('div', null, array('class' => 'group')); $label = Widget::Label('Start Date <i>Optional</i>'); $label->appendChild(Widget::Input('fields[start]', $fields['start'])); $group->appendChild(isset($this->_errors['start']) ? Widget::Error($label, $this->_errors['start']) : $label); $label = Widget::Label('Finish Date <i>Optional</i>'); $label->appendChild(Widget::Input('fields[finish]', $fields['finish'])); $group->appendChild(isset($this->_errors['finish']) ? Widget::Error($label, $this->_errors['finish']) : $label); $fieldset->appendChild($group); $p = new XMLElement('p', 'This task will be not run until after the <strong>start date</strong>, and will cease to trigger beyond the <strong>finish date</strong>.'); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $this->Form->appendChild($fieldset); $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', 'Create', 'submit', array('accesskey' => 's'))); $this->Form->appendChild($div); }
public function __viewEdit() { $section_id = $this->_context[1]; if (!($section = SectionManager::fetch($section_id))) { Administration::instance()->throwCustomError(__('The Section, %s, could not be found.', array($section_id)), __('Unknown Section'), Page::HTTP_STATUS_NOT_FOUND); } $meta = $section->get(); $section_id = $meta['id']; $types = array(); $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(__('Section updated at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/blueprints/sections/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/blueprints/sections/" accesskey="a">' . __('View all Sections') . '</a>', Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Section created at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/blueprints/sections/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/blueprints/sections/" accesskey="a">' . __('View all Sections') . '</a>', Alert::SUCCESS); break; } } } if (isset($_POST['fields'])) { $fields = array(); if (is_array($_POST['fields']) && !empty($_POST['fields'])) { foreach ($_POST['fields'] as $position => $data) { if ($fields[$position] = FieldManager::create($data['type'])) { $fields[$position]->setArray($data); $fields[$position]->set('sortorder', $position); } } } } else { $fields = FieldManager::fetch(NULL, $section_id); $fields = array_values($fields); } if (isset($_POST['meta'])) { $meta = $_POST['meta']; $meta['hidden'] = isset($meta['hidden']) ? 'yes' : 'no'; if ($meta['name'] == '') { $meta['name'] = $section->get('name'); } } $this->setPageType('form'); $this->setTitle(__('%1$s – %2$s – %3$s', array($meta['name'], __('Sections'), __('Symphony')))); $this->appendSubheading($meta['name'], Widget::Anchor(__('View Entries'), SYMPHONY_URL . '/publish/' . $section->get('handle'), __('View Section Entries'), 'button')); $this->insertBreadcrumbs(array(Widget::Anchor(__('Sections'), SYMPHONY_URL . '/blueprints/sections/'))); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Essentials'))); $div = new XMLElement('div', NULL, array('class' => 'two columns')); $namediv = new XMLElement('div', NULL, array('class' => 'column')); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('meta[name]', General::sanitize($meta['name']))); if (isset($this->_errors['name'])) { $namediv->appendChild(Widget::Error($label, $this->_errors['name'])); } else { $namediv->appendChild($label); } $label = Widget::Label(); $input = Widget::Input('meta[hidden]', 'yes', 'checkbox', $meta['hidden'] == 'yes' ? array('checked' => 'checked') : NULL); $label->setValue(__('%s Hide this section from the back-end menu', array($input->generate(false)))); $namediv->appendChild($label); $div->appendChild($namediv); $navgroupdiv = new XMLElement('div', NULL, array('class' => 'column')); $sections = SectionManager::fetch(NULL, 'ASC', 'sortorder'); $label = Widget::Label(__('Navigation Group')); $label->appendChild(Widget::Input('meta[navigation_group]', $meta['navigation_group'])); if (isset($this->_errors['navigation_group'])) { $navgroupdiv->appendChild(Widget::Error($label, $this->_errors['navigation_group'])); } else { $navgroupdiv->appendChild($label); } if (is_array($sections) && !empty($sections)) { $ul = new XMLElement('ul', NULL, array('class' => 'tags singular')); $groups = array(); foreach ($sections as $s) { if (in_array($s->get('navigation_group'), $groups)) { continue; } $ul->appendChild(new XMLElement('li', $s->get('navigation_group'))); $groups[] = $s->get('navigation_group'); } $navgroupdiv->appendChild($ul); } $div->appendChild($navgroupdiv); $fieldset->appendChild($div); $this->Form->appendChild($fieldset); /** * Allows extensions to add elements to the header of the Section Editor * form. Usually for section settings, this delegate is passed the current * `$meta` array and the `$this->_errors` array. * * @delegate AddSectionElements * @since Symphony 2.2 * @param string $context * '/blueprints/sections/' * @param XMLElement $form * An XMLElement of the current `$this->Form`, just after the Section * settings have been appended, but before the Fields duplicator * @param array $meta * The current $_POST['meta'] array * @param array $errors * The current errors array */ Symphony::ExtensionManager()->notifyMembers('AddSectionElements', '/blueprints/sections/', array('form' => &$this->Form, 'meta' => &$meta, 'errors' => &$this->_errors)); $fieldset = new XMLElement('fieldset', null, array('id' => 'fields', 'class' => 'settings')); $fieldset->appendChild(new XMLElement('legend', __('Fields'))); $div = new XMLElement('div', null, array('class' => 'frame')); $ol = new XMLElement('ol'); $ol->setAttribute('id', 'fields-duplicator'); $ol->setAttribute('data-add', __('Add field')); $ol->setAttribute('data-remove', __('Remove field')); if (is_array($fields) && !empty($fields)) { foreach ($fields as $position => $field) { $wrapper = new XMLElement('li', NULL, array('class' => 'field-' . $field->handle() . ($field->mustBeUnique() ? ' unique' : NULL))); $wrapper->setAttribute('data-type', $field->handle()); $field->set('sortorder', $position); $field->displaySettingsPanel($wrapper, isset($this->_errors[$position]) ? $this->_errors[$position] : NULL); $ol->appendChild($wrapper); } } foreach (FieldManager::listAll() as $type) { if ($type = FieldManager::create($type)) { array_push($types, $type); } } uasort($types, create_function('$a, $b', 'return strnatcasecmp($a->_name, $b->_name);')); foreach ($types as $type) { $defaults = array(); $type->findDefaults($defaults); $type->setArray($defaults); $wrapper = new XMLElement('li'); $wrapper->setAttribute('class', 'template field-' . $type->handle() . ($type->mustBeUnique() ? ' unique' : NULL)); $wrapper->setAttribute('data-type', $type->handle()); $type->set('sortorder', '-1'); $type->displaySettingsPanel($wrapper); $ol->appendChild($wrapper); } $div->appendChild($ol); $fieldset->appendChild($div); $this->Form->appendChild($fieldset); $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', __('Save Changes'), 'submit', array('accesskey' => 's'))); $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this section'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this section?'))); $div->appendChild($button); $this->Form->appendChild($div); }
public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null) { $value = General::sanitize(isset($data['value']) ? $data['value'] : null); $label = Widget::Label($this->get('label')); if ($this->get('required') !== 'yes') { $label->appendChild(new XMLElement('i', __('Optional'))); } $label->appendChild(Widget::Input('fields' . $fieldnamePrefix . '[' . $this->get('element_name') . ']' . $fieldnamePostfix, strlen($value) != 0 ? $value : null)); if ($flagWithError != null) { $wrapper->appendChild(Widget::Error($label, $flagWithError)); } else { $wrapper->appendChild($label); } }
/** * Will wrap a `<div>` around a desired element to trigger the default * Symphony error styling. * * @deprecated Since Symphony 2.3. This function will be removed in a * future Symphony release. Use `Widget::Error` instead. * @see core.Widget#Error() * @param XMLElement $element * The element that should be wrapped with an error * @param string $message * The text for this error. This will be appended after the $element, * but inside the wrapping `<div>` * @return XMLElement */ public static function wrapFormElementWithError(XMLElement $element, $message) { return Widget::Error($element, $message); }
/** * Displays settings panel in section editor * * @param XMLElement $wrapper - parent element wrapping the field * @param array $errors - array with field errors, $errors['name-of-field-element'] */ public function displaySettingsPanel(&$wrapper, $errors = NULL) { // initialize field settings based on class defaults (name, placement) parent::displaySettingsPanel($wrapper, $errors); // build selector for email templates $all_templates = EmailTemplateManager::listAll(); $options = array(); if (!empty($all_templates) && is_array($all_templates)) { $templates = $this->get('templates'); if (is_array($templates)) { $templates = implode(',', $templates); } foreach ($all_templates as $template) { $about = $template->about; $handle = $template->getHandle(); $options[] = array($handle, in_array($handle, explode(',', $templates)), $about['name']); } } $group = new XMLElement('div', NULL, array('class' => 'group')); $label = Widget::Label(__('Email Templates')); $label->appendChild(Widget::Select('fields[' . $this->get('sortorder') . '][templates][]', $options, array('multiple' => 'multiple'))); if (isset($errors['templates'])) { $group->appendChild(Widget::Error($label, $errors['templates'])); } else { $group->appendChild($label); } $wrapper->appendChild($group); // build selector for senders $all_senders = SenderManager::listAll(); $options = array(); if (!empty($all_senders) && is_array($all_senders)) { $senders = $this->get('senders'); if (is_array($senders)) { $senders = implode(',', $senders); } foreach ($all_senders as $sender) { $options[] = array($sender['handle'], in_array($sender['handle'], explode(',', $senders)), $sender['name']); } } $group = new XMLElement('div', NULL, array('class' => 'group')); $label = Widget::Label(__('Newsletter Senders')); $label->appendChild(Widget::Select('fields[' . $this->get('sortorder') . '][senders][]', $options, array('multiple' => 'multiple'))); if (isset($errors['senders'])) { $group->appendChild(Widget::Error($label, $errors['senders'])); } else { $group->appendChild($label); } // build selector for recipient groups $recipient_group_manager = new RecipientgroupManager(Symphony::Engine()); $all_recipient_groups = $recipient_group_manager->listAll(); $options = array(); if (!empty($all_recipient_groups) && is_array($all_recipient_groups)) { $recipient_groups = $this->get('recipient_groups'); if (is_array($recipient_groups)) { $recipient_groups = implode(',', $recipient_groups); } foreach ($all_recipient_groups as $recipient_group) { $options[] = array($recipient_group['handle'], in_array($recipient_group['handle'], (array) explode(',', $recipient_groups)), $recipient_group['name']); } } $label = Widget::Label(__('Newsletter Recipient Groups')); $label->appendChild(Widget::Select('fields[' . $this->get('sortorder') . '][recipient_groups][]', $options, array('multiple' => 'multiple'))); if (isset($errors['recipient_groups'])) { $group->appendChild(Widget::Error($label, $errors['recipient_groups'])); } else { $group->appendChild($label); } $wrapper->appendChild($group); // append 'show column' checkbox $this->appendShowColumnCheckbox($wrapper); }
public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null) { $name = $this->get('element_name'); $value = null; // New entry if ((is_null($data) || empty($data)) && is_null($flagWithError) && $this->get('pre_populate') == 'yes') { $value = DateTimeObj::format('now', DateTimeObj::getSetting('datetime_format')); } else { if (!is_null($flagWithError)) { $value = $_POST['fields'][$name]; } else { if (isset($data['value'])) { $value = DateTimeObj::format($data['value'], DateTimeObj::getSetting('datetime_format')); } } } $label = Widget::Label($this->get('label')); if ($this->get('required') != 'yes') { $label->appendChild(new XMLElement('i', __('Optional'))); } $label->appendChild(Widget::Input("fields{$fieldnamePrefix}[{$name}]", $value)); $label->setAttribute('class', 'date'); if (!is_null($flagWithError)) { $label = Widget::Error($label, $flagWithError); } $wrapper->appendChild($label); }
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); }
public function view() { if (isset($this->_context[0]) && in_array(strlen($this->_context[0]), array(6, 8, 16))) { if (!$this->__loginFromToken($this->_context[0])) { if (Administration::instance()->isLoggedIn()) { // Redirect to the Author's profile. RE: #1801 redirect(SYMPHONY_URL . '/system/authors/edit/' . Symphony::Author()->get('id') . '/reset-password/'); } } } $this->Form = Widget::Form(SYMPHONY_URL . '/login/', 'post'); $this->Form->setAttribute('class', 'frame'); $this->Form->appendChild(new XMLElement('h1', Symphony::Configuration()->get('sitename', 'general'))); $fieldset = new XMLElement('fieldset'); // Display retrieve password UI if (isset($this->_context[0]) && $this->_context[0] == 'retrieve-password') { $this->Form->setAttribute('action', SYMPHONY_URL . '/login/retrieve-password/'); // Successful reset if (isset($this->_email_sent) && $this->_email_sent) { $fieldset->appendChild(new XMLElement('p', __('An email containing a customised login link has been sent to %s. It will expire in 2 hours.', array('<code>' . $this->_email_sent_to . '</code>')))); $fieldset->appendChild(new XMLElement('p', Widget::Anchor(__('Login'), SYMPHONY_URL . '/login/', null))); $this->Form->appendChild($fieldset); // Default, get the email address for reset } else { $fieldset->appendChild(new XMLElement('p', __('Enter your email address or username to be sent further instructions for logging in.'))); $label = Widget::Label(__('Email Address or Username')); $label->appendChild(Widget::Input('email', General::sanitize($_POST['email']), 'text', array('autofocus' => 'autofocus'))); if (isset($this->_email_sent) && !$this->_email_sent) { $label = Widget::Error($label, __('Unfortunately no account was found using this information.')); } else { // Email exception if (isset($this->_email_error) && $this->_email_error) { $label = Widget::Error($label, __('This Symphony instance has not been set up for emailing, %s', array('<code>' . $this->_email_error . '</code>'))); } } $fieldset->appendChild($label); $this->Form->appendChild($fieldset); $div = new XMLElement('div', null, array('class' => 'actions')); $div->appendChild(new XMLElement('button', __('Send Email'), array('name' => 'action[reset]', 'type' => 'submit', 'accesskey' => 's'))); $div->appendChild(Widget::Anchor(__('Cancel'), SYMPHONY_URL . '/login/', null, 'action-link')); $this->Form->appendChild($div); } // Normal login } else { $fieldset->appendChild(new XMLElement('legend', __('Login'), array('role' => 'heading'))); // Display error message if ($this->failedLoginAttempt) { $p = new XMLElement('p'); $p = Widget::Error($p, __('The login details provided are incorrect.')); $fieldset->appendChild($p); } // Username $label = Widget::Label(__('Username')); $username = Widget::Input('username', isset($_POST['username']) ? General::sanitize($_POST['username']) : null); if (!$this->failedLoginAttempt) { $username->setAttribute('autofocus', 'autofocus'); } $label->appendChild($username); if (isset($_POST['action'], $_POST['action']['login']) && empty($_POST['username'])) { $username->setAttribute('autofocus', 'autofocus'); $label = Widget::Error($label, __('No username was entered.')); } $fieldset->appendChild($label); // Password $label = Widget::Label(__('Password')); $password = Widget::Input('password', null, 'password'); $label->appendChild($password); if (isset($_POST['action'], $_POST['action']['login']) && empty($_POST['password'])) { $password->setAttribute('autofocus', 'autofocus'); $label = Widget::Error($label, __('No password was entered.')); } elseif ($this->failedLoginAttempt) { $password->setAttribute('autofocus', 'autofocus'); } $fieldset->appendChild($label); $this->Form->appendChild($fieldset); // Actions $div = new XMLElement('div', null, array('class' => 'actions')); $div->appendChild(new XMLElement('button', __('Login'), array('name' => 'action[login]', 'type' => 'submit', 'accesskey' => 'l'))); $div->appendChild(Widget::Anchor(__('Retrieve password?'), SYMPHONY_URL . '/login/retrieve-password/', null, 'action-link')); $this->Form->appendChild($div); if (isset($this->_context['redirect'])) { $this->Form->appendChild(Widget::Input('redirect', SYMPHONY_URL . General::sanitize($this->_context['redirect']), 'hidden')); } } $this->Body->appendChild($this->Form); }
public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null) { $states = $this->getToggleStates(); if (!is_array($data['value'])) { $data['value'] = array($data['value']); } $options = array(array(NULL, false, NULL)); foreach ($states as $handle => $v) { $options[] = array(General::sanitize($v), in_array($v, $data['value']), General::sanitize($v)); } $fieldname = 'fields' . $fieldnamePrefix . '[' . $this->get('element_name') . ']' . $fieldnamePostfix; if ($this->get('allow_multiple_selection') == 'yes') { $fieldname .= '[]'; } $label = Widget::Label($this->get('label')); if ($this->get('required') != 'yes') { $label->appendChild(new XMLElement('i', __('Optional'))); } $label->appendChild(Widget::Select($fieldname, $options, $this->get('allow_multiple_selection') == 'yes' ? array('multiple' => 'multiple') : NULL)); if ($flagWithError != NULL) { $wrapper->appendChild(Widget::Error($label, $flagWithError)); } else { $wrapper->appendChild($label); } }
public static function buildEditor(XMLElement $wrapper, array &$errors = array(), array $settings = null, $handle = null) { if (!is_null($handle) && isset($settings[self::getClass()])) { $cache = Symphony::ExtensionManager()->getCacheProvider('remotedatasource'); $cache_id = self::buildCacheID($settings[self::getClass()]); } // If `clear_cache` is set, clear it.. if (isset($cache_id) && in_array('clear_cache', Administration::instance()->Page->getContext())) { $cache->forceExpiry($cache_id); Administration::instance()->Page->pageAlert(__('Data source cache cleared at %s.', array(Widget::Time()->generate())) . '<a href="' . SYMPHONY_URL . '/blueprints/datasources/" accesskey="a">' . __('View all Data sources') . '</a>', Alert::SUCCESS); } $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings contextual ' . __CLASS__); $fieldset->setAttribute('data-context', Lang::createHandle(self::getName())); $fieldset->appendChild(new XMLElement('legend', self::getName())); $p = new XMLElement('p', __('Use %s syntax to specify dynamic portions of the URL.', array('<code>{' . __('$param') . '}</code>'))); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); // URL $label = Widget::Label(__('URL')); $url = isset($settings[self::getClass()]['url']) ? General::sanitize($settings[self::getClass()]['url']) : null; $label->appendChild(Widget::Input('fields[' . self::getClass() . '][url]', $url, 'text', array('placeholder' => 'http://'))); if (isset($errors[self::getClass()]['url'])) { $fieldset->appendChild(Widget::Error($label, $errors[self::getClass()]['url'])); } else { $fieldset->appendChild($label); } // Included Elements $label = Widget::Label(__('Included Elements')); $help = new XMLElement('i', __('xPath expression')); $label->appendChild($help); $xpath = isset($settings[self::getClass()]['xpath']) ? stripslashes($settings[self::getClass()]['xpath']) : null; $label->appendChild(Widget::Input('fields[' . self::getClass() . '][xpath]', $xpath, 'text', array('placeholder' => '/'))); if (isset($errors[self::getClass()]['xpath'])) { $fieldset->appendChild(Widget::Error($label, $errors[self::getClass()]['xpath'])); } else { $fieldset->appendChild($label); } // Timeout $group = new XMLElement('div', null, array('class' => 'three columns')); $fieldset->appendChild($group); $label = Widget::Label(__('Timeout')); $label->setAttribute('class', 'column'); $help = new XMLElement('i', __('in seconds')); $label->appendChild($help); $timeout_time = isset($settings[self::getClass()]['timeout']) ? max(1, intval($settings[self::getClass()]['timeout'])) : 6; $label->appendChild(Widget::Input('fields[' . self::getClass() . '][timeout]', (string) $timeout_time, 'text')); if (isset($errors[self::getClass()]['timeout'])) { $group->appendChild(Widget::Error($label, $errors[self::getClass()]['timeout'])); } else { $group->appendChild($label); } // Caching $label = Widget::Label(__('Cache expiration')); $label->setAttribute('class', 'column'); $help = new XMLElement('i', __('in minutes')); $label->appendChild($help); $cache_time = isset($settings[self::getClass()]['cache']) ? max(0, intval($settings[self::getClass()]['cache'])) : 5; $input = Widget::Input('fields[' . self::getClass() . '][cache]', (string) $cache_time); $label->appendChild($input); if (isset($errors[self::getClass()]['cache'])) { $group->appendChild(Widget::Error($label, $errors[self::getClass()]['cache'])); } else { $group->appendChild($label); } // Format $label = Widget::Label(__('Format')); $label->setAttribute('class', 'column'); $format = isset($settings[self::getClass()]['format']) ? $settings[self::getClass()]['format'] : null; $label->appendChild(Widget::Select('fields[' . self::getClass() . '][format]', array(array('xml', $settings[self::getClass()]['format'] == 'xml', 'XML'), array('json', $settings[self::getClass()]['format'] == 'json', 'JSON'), array('csv', $settings[self::getClass()]['format'] == 'csv', 'CSV'), array('txt', $settings[self::getClass()]['format'] == 'txt', 'TEXT')), array('class' => 'picker'))); if (isset($errors[self::getClass()]['format'])) { $group->appendChild(Widget::Error($label, $errors[self::getClass()]['format'])); } else { $group->appendChild($label); } // Namespaces $div = new XMLElement('div', false, array('id' => 'xml', 'class' => 'pickable')); $p = new XMLElement('p', __('Namespace Declarations')); $p->appendChild(new XMLElement('i', __('optional'))); $p->setAttribute('class', 'label'); $div->appendChild($p); $frame = new XMLElement('div', null, array('class' => 'frame filters-duplicator')); $frame->setAttribute('data-interactive', 'data-interactive'); $ol = new XMLElement('ol'); $ol->setAttribute('data-add', __('Add namespace')); $ol->setAttribute('data-remove', __('Remove namespace')); if (isset($settings[self::getClass()], $settings[self::getClass()]['namespaces']) && is_array($settings[self::getClass()]['namespaces']) && !empty($settings[self::getClass()]['namespaces'])) { $ii = 0; foreach ($settings[self::getClass()]['namespaces'] 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->setAttribute('class', 'instance'); $header = new XMLElement('header'); $header->appendChild(new XMLElement('h4', __('Namespace'))); $li->appendChild($header); $group = new XMLElement('div'); $group->setAttribute('class', 'two columns'); $label = Widget::Label(__('Name')); $label->setAttribute('class', 'column'); $label->appendChild(Widget::Input("fields[" . self::getClass() . "][namespaces][{$ii}][name]", General::sanitize($name))); $group->appendChild($label); $label = Widget::Label(__('URI')); $label->setAttribute('class', 'column'); $label->appendChild(Widget::Input("fields[" . self::getClass() . "][namespaces][{$ii}][uri]", General::sanitize($uri))); $group->appendChild($label); $li->appendChild($group); $ol->appendChild($li); $ii++; } } $li = new XMLElement('li'); $li->setAttribute('class', 'template'); $li->setAttribute('data-type', 'namespace'); $header = new XMLElement('header'); $header->appendChild(new XMLElement('h4', __('Namespace'))); $li->appendChild($header); $group = new XMLElement('div'); $group->setAttribute('class', 'two columns'); $label = Widget::Label(__('Name')); $label->setAttribute('class', 'column'); $label->appendChild(Widget::Input('fields[' . self::getClass() . '][namespaces][-1][name]')); $group->appendChild($label); $label = Widget::Label(__('URI')); $label->setAttribute('class', 'column'); $label->appendChild(Widget::Input('fields[' . self::getClass() . '][namespaces][-1][uri]')); $group->appendChild($label); $li->appendChild($group); $ol->appendChild($li); $frame->appendChild($ol); $div->appendChild($frame); $fieldset->appendChild($div); // Check for existing Cache objects if (isset($cache_id)) { self::buildCacheInformation($fieldset, $cache, $cache_id); } $wrapper->appendChild($fieldset); }
public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null) { $name = $this->get('element_name'); $value = null; // New entry if ((is_null($data) || empty($data)) && is_null($flagWithError) && !is_null($this->get('pre_populate')) && $this->get('pre_populate') !== 'no') { $prepopulate = $this->get('pre_populate') === 'yes' ? 'now' : $this->get('pre_populate'); $date = self::parseDate($prepopulate); $date = $date['start']; $value = $this->formatDate($date); // Error entry, display original data } elseif (!is_null($flagWithError)) { $value = $_POST['fields'][$name]; // Empty entry } elseif (isset($data['value'])) { $value = $this->formatDate($data['value']); } $label = Widget::Label($this->get('label')); if ($this->get('required') !== 'yes') { $label->appendChild(new XMLElement('i', __('Optional'))); } // Input $label->appendChild(Widget::Input("fields{$fieldnamePrefix}[{$name}]", $value)); $label->setAttribute('class', 'date'); if (!is_null($flagWithError)) { $label = Widget::Error($label, $flagWithError); } // Calendar if ($this->get('calendar') === 'yes') { $wrapper->setAttribute('data-interactive', 'data-interactive'); $ul = new XMLElement('ul'); $ul->setAttribute('class', 'suggestions'); $ul->setAttribute('data-field-id', $this->get('id')); $ul->setAttribute('data-search-types', 'date'); $calendar = new XMLElement('li'); $calendar->appendChild(Widget::Calendar($this->get('time') === 'yes')); $ul->appendChild($calendar); $label->appendChild($ul); } $wrapper->appendChild($label); }
public function displayDatasourceFilterPanel(&$wrapper, $data = NULL, $errors = NULL, $fieldnamePrefix = NULL, $fieldnamePostfix = NULL) { if ($data == NULL) { $data = '(if value of (param_or_value_here) is (param_or_value_here))'; } $e = Conditionalizer::parse($data); if (empty($e)) { // Strip all parameters just to see if there was invalid expression there or none at all $e = preg_replace(array('@{(([^}:]+)|[^}]+?:([^}:]+))?}@i', '@{\\$[^}]+}@i', '@{([^}\\$]+)}@i'), array('{$2$3}', 'yes', '$1'), $data); $e = array_map('trim', preg_split('/(?<!\\\\)[,\\+] /', $e, -1, PREG_SPLIT_NO_EMPTY)); if (!empty($e)) { $e = array_diff($e, array('yes', 'no')); // Make array non-empty if all values are either 'yes' or 'no', otherwise make it empty to mark wrong syntax $e = count($e) > 0 ? array() : array('ok'); } } // Copy content generated by parent::displayDatasourceFilterPanel(), so we can wrap it with error if needed $wrapper->appendChild(new XMLElement('header', '<h4>' . $this->get('label') . '</h4> <span>' . $this->name() . '</span>', array('data-name' => $this->get('label') . ' (' . $this->name() . ')'))); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter]' . ($fieldnamePrefix ? '[' . $fieldnamePrefix . ']' : '') . '[' . $this->get('id') . ']' . ($fieldnamePostfix ? '[' . $fieldnamePostfix . ']' : ''), $data ? General::sanitize($data) : null)); $wrapper->appendChild(empty($e) ? Widget::Error($label, __('Invalid syntax')) : $label); $params = Conditionalizer::listParams(); if (empty($params)) { return; } $optionlist = new XMLElement('ul'); $optionlist->setAttribute('class', 'tags'); $optionlist->appendChild(new XMLElement('li', 'yes', array('title' => 'Exact string value'))); $optionlist->appendChild(new XMLElement('li', 'no', array('title' => 'Exact string value'))); foreach ($params as $param => $value) { $optionlist->appendChild(new XMLElement('li', $param, array('class' => '{' . $param . '}', 'title' => $value ? __('Value of %s returned from another data source', array($value)) : __('Value found in URL path')))); } $wrapper->appendChild($optionlist); }
/** * * Builds the UI for the publish page * @param XMLElement $wrapper * @param mixed $data * @param mixed $flagWithError * @param string $fieldnamePrefix * @param string $fieldnamePostfix */ public function displayPublishPanel(&$wrapper, $data = NULL, $flagWithError = NULL, $fieldnamePrefix = NULL, $fieldnamePostfix = NULL, $entry_id = null) { $entriesId = array(); $sectionsId = $this->getSelectedSectionsArray(); if ($data['entries'] != null) { $entriesId = static::getEntries($data); } $sectionsId = array_map(array('General', 'intval'), $sectionsId); $sections = SectionManager::fetch($sectionsId); $label = Widget::Label($this->get('label')); $notes = ''; // min note if ($this->getInt('min_entries') > 0) { $notes .= __('Minimum number of entries: <b>%s</b>. ', array($this->get('min_entries'))); } // max note if ($this->getInt('max_entries') > 0) { $notes .= __('Maximum number of entries: <b>%s</b>. ', array($this->get('max_entries'))); } // not required note if (!$this->isRequired()) { $notes .= __('Optional'); } // append notes if ($notes) { $label->appendChild(new XMLElement('i', $notes)); } // label error management if ($flagWithError != NULL) { $wrapper->appendChild(Widget::Error($label, $flagWithError)); } else { $wrapper->appendChild($label); } $wrapper->appendChild($this->createEntriesList($entriesId)); $wrapper->appendChild($this->createPublishMenu($sections)); $wrapper->appendChild($this->createEntriesHiddenInput($data)); $wrapper->setAttribute('data-value', $data['entries']); $wrapper->setAttribute('data-field-id', $this->get('id')); $wrapper->setAttribute('data-field-label', $this->get('label')); $wrapper->setAttribute('data-min', $this->get('min_entries')); $wrapper->setAttribute('data-max', $this->get('max_entries')); if (isset($_REQUEST['debug'])) { $wrapper->setAttribute('data-debug', true); } }
public function displayPublishPanel(XMLElement &$wrapper, $data = null, $flagWithError = null, $fieldnamePrefix = null, $fieldnamePostfix = null, $entry_id = null) { Extension_TextBoxField::appendHeaders(Extension_TextBoxField::PUBLISH_HEADERS); $sortorder = $this->get('sortorder'); $element_name = $this->get('element_name'); $classes = array(); $label = Widget::Label($this->get('label')); $optional = ''; if ($this->get('required') != 'yes') { if ((int) $this->get('text_length') > 0) { $optional = __('$1 of $2 remaining') . ' – ' . __('Optional'); } else { $optional = __('Optional'); } } else { if ((int) $this->get('text_length') > 0) { $optional = __('$1 of $2 remaining'); } } if ($optional) { $label->appendChild(new XMLElement('i', $optional)); } // Input box: if ($this->get('text_size') == 'single') { $input = Widget::Input("fields{$fieldnamePrefix}[{$element_name}]{$fieldnamePostfix}", General::sanitize($data['value'])); ### # Delegate: ModifyTextBoxInlineFieldPublishWidget # Description: Allows developers modify the textbox before it is rendered in the publish forms $delegate = 'ModifyTextBoxInlineFieldPublishWidget'; } else { $input = Widget::Textarea("fields{$fieldnamePrefix}[{$element_name}]{$fieldnamePostfix}", 20, 50, General::sanitize($data['value'])); ### # Delegate: ModifyTextBoxFullFieldPublishWidget # Description: Allows developers modify the textbox before it is rendered in the publish forms $delegate = 'ModifyTextBoxFullFieldPublishWidget'; } // Add classes: $classes[] = 'size-' . $this->get('text_size'); if ($this->get('text_formatter') != 'none') { $classes[] = $this->get('text_formatter'); } $input->setAttribute('class', implode(' ', $classes)); $input->setAttribute('length', (int) $this->get('text_length')); Symphony::ExtensionManager()->notifyMembers($delegate, '/backend/', array('field' => $this, 'label' => $label, 'input' => $input, 'textarea' => $input)); if (is_null($label)) { return; } $label->appendChild($input); if ($flagWithError != null) { $label = Widget::Error($label, $flagWithError); } $wrapper->appendChild($label); }
public function displayPublishPanel(&$wrapper, $data = NULL, $flagWithError = NULL, $fieldnamePrefix = NULL, $fieldnamePostfix = NULL) { $label = Widget::Label($this->get('label')); $class = 'file'; $label->setAttribute('class', $class); if ($this->get('required') != 'yes') { $label->appendChild(new XMLElement('i', __('Optional'))); } $span = new XMLElement('span'); $span->setAttribute('class', 'frame'); if ($data['file']) { $span->appendChild(Widget::Anchor($this->getUrl($data['file']), $this->getUrl($data['file']))); } $span->appendChild(Widget::Input('fields' . $fieldnamePrefix . '[' . $this->get('element_name') . ']' . $fieldnamePostfix, $data['file'], $data['file'] ? 'hidden' : 'file')); $label->appendChild($span); if ($flagWithError != NULL) { $wrapper->appendChild(Widget::Error($label, $flagWithError)); } else { $wrapper->appendChild($label); } }
private function __appendError(array $codes, XMLElement &$element, $message = null) { if (is_null($message)) { $message = __('The following errors have been reported:'); } foreach ($codes as $i => $c) { if (!isset($this->_params['errors'][$c])) { unset($codes[$i]); } } if (!empty($codes)) { if (count($codes) > 1) { $ul = new XMLElement('ul'); foreach ($codes as $c) { if (isset($this->_params['errors'][$c])) { $ul->appendChild(new XMLElement('li', $this->_params['errors'][$c]['details'])); } } $element = Widget::Error($element, $message); $element->appendChild($ul); } else { $code = array_pop($codes); if (isset($this->_params['errors'][$code])) { $element = Widget::Error($element, $this->_params['errors'][$code]['details']); } } } }
/** * Append a validator selector to a given `XMLElement`. Note that this * function differs from the other two similarly named build functions in * that it takes an `XMLElement` to append the Validator to as a parameter, * and does not return anything. * * @param XMLElement $wrapper * the parent element to append the XMLElement of the Validation select to, * passed by reference. * @param string $selected (optional) * the current validator selection if there is one. defaults to null if there * isn't. * @param string $name (optional) * the form element name of this field. this defaults to "fields[validator]". * @param string $type (optional) * the type of input for the validation to apply to. this defaults to 'input' * but also accepts 'upload'. * @param array $errors (optional) * an associative array of errors * @throws InvalidArgumentException */ public function buildValidationSelect(XMLElement &$wrapper, $selected = null, $name = 'fields[validator]', $type = 'input', array $errors = null) { include TOOLKIT . '/util.validators.php'; $rules = $type == 'upload' ? $upload : $validators; $label = Widget::Label(__('Validation Rule')); $label->setAttribute('class', 'column'); $label->appendChild(new XMLElement('i', __('Optional'))); $label->appendChild(Widget::Input($name, $selected)); $ul = new XMLElement('ul', null, array('class' => 'tags singular', 'data-interactive' => 'data-interactive')); foreach ($rules as $name => $rule) { $ul->appendChild(new XMLElement('li', $name, array('class' => $rule))); } if (isset($errors['validator'])) { $div = new XMLElement('div'); $div->appendChild($label); $div->appendChild($ul); $wrapper->appendChild(Widget::Error($div, $errors['validator'])); } else { $wrapper->appendChild($label); $wrapper->appendChild($ul); } }