public function view() { // Ensure we have been set $_POST data from Members events if (!array_key_exists('members', $_POST)) { $this->_status = AjaxPage::STATUS_BAD; return; } else { if (!is_writable(CONFIG)) { $this->_status = AjaxPage::STATUS_BAD; $this->_Result->appendChild(new XMLElement('message', __('The Symphony configuration file, <code>/manifest/config.php</code>, is not writable. You will not be able to save changes to preferences.'))); return; } } $settings = $_POST['members']; // Generate Recovery Code if (isset($settings['generate-recovery-code-template'])) { Symphony::Configuration()->set('generate-recovery-code-template', implode(',', array_filter($settings['generate-recovery-code-template'])), 'members'); } else { if ($settings['event'] == 'generate-recovery-code') { Symphony::Configuration()->remove('generate-recovery-code-template', 'members'); } } // Reset Password if (isset($settings['reset-password-template'])) { Symphony::Configuration()->set('reset-password-template', implode(',', array_filter($settings['reset-password-template'])), 'members'); } else { if ($settings['event'] == 'reset-password') { Symphony::Configuration()->remove('reset-password-template', 'members'); } } if ($settings['event'] == 'reset-password') { Symphony::Configuration()->set('reset-password-auto-login', $settings['auto-login'], 'members'); } // Regenerate Activation Code if (isset($settings['regenerate-activation-code-template'])) { Symphony::Configuration()->set('regenerate-activation-code-template', implode(',', array_filter($settings['regenerate-activation-code-template'])), 'members'); } else { if ($settings['event'] == 'regenerate-activation-code') { Symphony::Configuration()->remove('regenerate-activation-code-template', 'members'); } } // Activate Account if (isset($settings['activate-account-template'])) { Symphony::Configuration()->set('activate-account-template', implode(',', array_filter($settings['activate-account-template'])), 'members'); } else { if ($settings['event'] == 'activate-account') { Symphony::Configuration()->remove('activate-account-template', 'members'); } } if ($settings['event'] == 'activate-account') { Symphony::Configuration()->set('activate-account-auto-login', $settings['auto-login'], 'members'); } // Return successful if (Administration::instance()->saveConfig()) { $this->_status = AjaxPage::STATUS_OK; $this->_Result->appendChild(new XMLElement('message', __('Preferences saved.'))); $this->_Result->appendChild(new XMLElement('timestamp', '<![CDATA[' . DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__) . ']]>')); } }
public function appendScriptToHead($context) { $this->static_section_name = ''; $entryManager = new EntryManager($this->_Parent); $sections = $this->_Parent->Database->fetch("SELECT section_id AS id, handle FROM tbl_fields_static_section LEFT JOIN tbl_sections ON tbl_fields_static_section.section_id = tbl_sections.id"); $this->section_data = array('handles' => array(), 'entries' => array()); foreach ($sections as $key => $value) { $this->section_data['handles'][] = $value['handle']; $result = $entryManager->fetch(NULL, $value['id'], NULL, NULL, NULL, NULL, false, false); if (count($result) > 0) { $this->section_data['entries'][] = $result[0]['id']; } else { $this->section_data['entries'][] = NULL; } } $this->_page = Administration::instance()->Page; $section_handle = $this->_page->_context['section_handle']; $context = $this->_page->_context['page']; $url_entry = $this->_page->_context['entry_id']; $flag = $this->_page->_context['flag']; if (isset($section_handle)) { $section = $this->_Parent->Database->fetchRow(0, "SELECT id, name FROM tbl_sections WHERE handle='{$section_handle}'"); $field = $this->_Parent->Database->fetchRow(0, "SELECT id FROM tbl_fields_static_section WHERE section_id=" . $section['id']); if ($field) { $entry = $this->getSectionEntry($section_handle); if ($context == 'new' && $entry) { redirect(URL . '/symphony/publish/' . $section_handle . '/edit/' . $entry . '/'); } if ($context == 'index') { if ($entry) { redirect(URL . '/symphony/publish/' . $section_handle . '/edit/' . $entry . '/'); } else { redirect(URL . '/symphony/publish/' . $section_handle . '/new/'); } } if ($context == 'edit') { if (!$entry) { redirect(URL . '/symphony/publish/' . $section_handle . '/new/'); } if ($url_entry != $entry) { redirect(URL . '/symphony/publish/' . $section_handle . '/edit/' . $entry . '/'); } } if ($flag == 'saved' || $flag == 'created') { $flag_msg = 'Entry updated at %1$s.'; if ($flag == 'created') { $flag_msg = 'Entry created at %1$s.'; } $this->_page->pageAlert(__($flag_msg, array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__))), Alert::SUCCESS); } $this->static_section_name = $section['name']; } } }
public function view() { $about = array(); if ($this->_context[0] && !is_object($this->formatter)) { $this->formatter = $this->_Parent->FormatterManager->create($this->_context[0]); } if (is_object($this->formatter)) { $about = $this->_Parent->FormatterManager->about($this->_context[0]); } if ($_SESSION['templatedtextformatters-alert']) { switch ($_SESSION['templatedtextformatters-alert']) { case 'saved': $this->pageAlert(__('Templated Text Formatter updated at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Templated Text Formatters</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), SYMPHONY_URL . '/extension/templatedtextformatters/edit/', SYMPHONY_URL . '/extension/templatedtextformatters')), Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Templated Text Formatter created at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Templated Text Formatters</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), SYMPHONY_URL . '/extension/templatedtextformatters/edit/', SYMPHONY_URL . '/extension/templatedtextformatters')), Alert::SUCCESS); break; } unset($_SESSION['templatedtextformatters-alert']); } $fields = $_POST['fields']; $this->setPageType('form'); $this->setTitle(__('%1$s – %2$s – %3$s', array(__('Symphony'), __('Templated Text Formatters'), $fields['name'] ? $fields['name'] : $about['name']))); $this->appendSubheading($fields['name'] ? $fields['name'] : ($about['name'] ? $about['name'] : 'Untitled')); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Essentials'))); $div = new XMLElement('div'); $div->setAttribute('class', 'group'); $label = Widget::Label(__('Name')); if (isset($about['name'])) { $label->appendChild(new XMLElement('i', __('Change will disconnect this formatter from any chains and/or fields it may have been added to!'))); } $label->appendChild(Widget::Input('fields[name]', $fields['name'] ? $fields['name'] : $about['name'])); $div->appendChild(isset($this->_errors['name']) ? $this->wrapFormElementWithError($label, $this->_errors['name']) : $label); $label = Widget::Label(__('Type')); $types = $this->_driver->listTypes(); $options = array(); if ($about['templatedtextformatters-type']) { $options[] = array($about['templatedtextformatters-type'], TRUE, $about['templatedtextformatters-type']); } else { foreach ($types as $t => $info) { $options[] = array($t, $fields['type'] ? $fields['type'] == $t : FALSE, $info['name'] ? $info['name'] : $t); } } $label->appendChild(Widget::Select('fields[type]', $options, array('id' => 'context'))); $div->appendChild($label); $fieldset->appendChild($div); $div = new XMLElement('div'); $label = Widget::Label(__('Description')); $label->appendChild(new XMLElement('i', __('Optional'))); $label->appendChild(Widget::Input('fields[description]', General::sanitize(isset($fields['description']) ? $fields['description'] : $about['description']))); $div->appendChild(isset($this->_errors['description']) ? $this->wrapFormElementWithError($label, $this->_errors['description']) : $label); $fieldset->appendChild($div); $this->Form->appendChild($fieldset); if (is_object($this->formatter) && method_exists($this->formatter, 'ttf_form')) { $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Format Options'))); $this->formatter->ttf_form($fieldset, $this); $this->Form->appendChild($fieldset); } if (is_object($this->formatter)) { $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Testing grounds'))); $p = new XMLElement('p', __('For now, You have to save changes each time You want to see updated output')); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $div = new XMLElement('div'); $div->setAttribute('class', 'group'); $label = Widget::Label(__('Test input')); $label->appendChild(Widget::Textarea('fields[testin]', 5, 50, $fields['testin'])); $div->appendChild($label); $label = Widget::Label(__('Test output')); $temp = ''; if ($fields['testin']) { $temp = $this->formatter->run($fields['testin']); } $label->appendChild(Widget::Textarea('fields[testout]', 5, 50, $temp)); $div->appendChild($label); $fieldset->appendChild($div); $this->Form->appendChild($fieldset); } $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $about['handle'] ? __('Save Changes') : __('Create formatter'), 'submit', array('accesskey' => 's'))); if ($about['name']) { $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'confirm delete', 'title' => __('Delete this formatter'))); $div->appendChild($button); } $this->Form->appendChild($div); }
public function __viewEdit() { $section_id = $this->_context[1]; $sectionManager = new SectionManager($this->_Parent); if (!($section = $sectionManager->fetch($section_id))) { $this->_Parent->customError(E_USER_ERROR, __('Unknown Section'), __('The Section you are looking for could not be found.'), false, true); } $meta = $section->get(); $fieldManager = new FieldManager($this->_Parent); $types = array(); $formHasErrors = 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); } if (isset($this->_context[2])) { switch ($this->_context[2]) { case 'saved': $this->pageAlert(__('Section updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Sections</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . '/symphony/blueprints/sections/new/', URL . '/symphony/blueprints/sections/')), Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Section created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Sections</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . '/symphony/blueprints/sections/new/', URL . '/symphony/blueprints/sections/')), 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); } $meta['subsection'] = $meta['subsection'] == 'yes' ? 1 : 0; $meta['entry_order'] = isset($meta['entry_order']) ? $meta['entry_order'] : 'date'; 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(__('Symphony'), __('Sections'), $meta['name']))); $this->appendSubheading($meta['name']); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Essentials'))); $div = new XMLElement('div', NULL, array('class' => 'group')); $namediv = new XMLElement('div', NULL); $label = Widget::Label('Name'); $label->appendChild(Widget::Input('meta[name]', $meta['name'])); if (isset($this->_errors['name'])) { $namediv->appendChild(Widget::wrapFormElementWithError($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 Publish menu', array($input->generate(false)))); $namediv->appendChild($label); $div->appendChild($namediv); $navgroupdiv = new XMLElement('div', NULL); $sectionManager = new SectionManager($this->_Parent); $sections = $sectionManager->fetch(NULL, 'ASC', 'sortorder'); $label = Widget::Label(__('Navigation Group') . ' <i>' . __('Choose only one. Created if does not exist') . '</i>'); $label->appendChild(Widget::Input('meta[navigation_group]', $meta['navigation_group'])); if (isset($this->_errors['navigation_group'])) { $navgroupdiv->appendChild(Widget::wrapFormElementWithError($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); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Fields'))); $div = new XMLElement('div'); $h3 = new XMLElement('h3', __('Fields')); $h3->setAttribute('class', 'label'); $div->appendChild($h3); $ol = new XMLElement('ol'); $ol->setAttribute('id', 'fields-duplicator'); if (is_array($fields) && !empty($fields)) { foreach ($fields as $position => $field) { $wrapper = new XMLElement('li'); $field->set('sortorder', $position); $field->displaySettingsPanel($wrapper, isset($this->_errors[$position]) ? $this->_errors[$position] : NULL); $ol->appendChild($wrapper); } } foreach ($fieldManager->fetchTypes() 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'); $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' => 'confirm delete', 'title' => __('Delete this section'), 'type' => 'submit')); $div->appendChild($button); $this->Form->appendChild($div); }
public function __viewEdit() { if (!($section_id = SectionManager::fetchIDFromHandle($this->_context['section_handle']))) { Administration::instance()->customError(__('Unknown Section'), __('The Section you are looking for, %s, could not be found.', array('<code>' . $this->_context['section_handle'] . '</code>'))); } $section = SectionManager::fetch($section_id); $entry_id = intval($this->_context['entry_id']); EntryManager::setFetchSorting('id', 'DESC'); if (!($existingEntry = EntryManager::fetch($entry_id))) { Administration::instance()->customError(__('Unknown Entry'), __('The entry you are looking for could not be found.')); } $existingEntry = $existingEntry[0]; // If there is post data floating around, due to errors, create an entry object if (isset($_POST['fields'])) { $fields = $_POST['fields']; $entry =& EntryManager::create(); $entry->set('section_id', $existingEntry->get('section_id')); $entry->set('id', $entry_id); $entry->setDataFromPost($fields, $errors, true); } else { $entry = $existingEntry; if (!$section) { $section = SectionManager::fetch($entry->get('section_id')); } } /** * Just prior to rendering of an Entry edit form. * * @delegate EntryPreRender * @param string $context * '/publish/edit/' * @param Section $section * @param Entry $entry * @param array $fields */ Symphony::ExtensionManager()->notifyMembers('EntryPreRender', '/publish/edit/', array('section' => $section, 'entry' => &$entry, 'fields' => $fields)); if (isset($this->_context['flag'])) { $link = 'publish/' . $this->_context['section_handle'] . '/new/'; list($flag, $field_id, $value) = preg_split('/:/i', $this->_context['flag'], 3); if (isset($_REQUEST['prepopulate'])) { $link .= '?'; foreach ($_REQUEST['prepopulate'] as $field_id => $value) { $link .= "prepopulate[{$field_id}]={$value}&"; } $link = preg_replace("/&\$/", '', $link); } // These flags are only relevant if there are no errors if (empty($this->_errors)) { switch ($flag) { case 'saved': $this->pageAlert(__('Entry updated at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/' . $link . '" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/publish/' . $this->_context['section_handle'] . '/" accesskey="a">' . __('View all Entries') . '</a>', Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Entry created at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/' . $link . '" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/publish/' . $this->_context['section_handle'] . '/" accesskey="a">' . __('View all Entries') . '</a>', Alert::SUCCESS); break; } } } // Determine the page title $field_id = Symphony::Database()->fetchVar('id', 0, "SELECT `id` FROM `tbl_fields` WHERE `parent_section` = '" . $section->get('id') . "' ORDER BY `sortorder` LIMIT 1"); $field = FieldManager::fetch($field_id); $title = trim(strip_tags($field->prepareTableValue($existingEntry->getData($field->get('id')), NULL, $entry_id))); if (trim($title) == '') { $title = __('Untitled'); } // Check if there is a field to prepopulate if (isset($_REQUEST['prepopulate'])) { foreach ($_REQUEST['prepopulate'] as $field_id => $value) { $this->Form->prependChild(Widget::Input("prepopulate[{$field_id}]", rawurlencode($value), 'hidden')); } } $this->setPageType('form'); $this->Form->setAttribute('enctype', 'multipart/form-data'); $this->Form->setAttribute('class', 'two columns'); $this->setTitle(__('%1$s – %2$s – %3$s', array($title, $section->get('name'), __('Symphony')))); // Only show the Edit Section button if the Author is a developer. #938 ^BA if (Administration::instance()->Author->isDeveloper()) { $this->appendSubheading($title, Widget::Anchor(__('Edit Section'), SYMPHONY_URL . '/blueprints/sections/edit/' . $section_id, __('Edit Section Configuration'), 'button')); } else { $this->appendSubheading($title); } $this->insertBreadcrumbs(array(Widget::Anchor($section->get('name'), SYMPHONY_URL . '/publish/' . $this->_context['section_handle']))); $this->Form->appendChild(Widget::Input('MAX_FILE_SIZE', Symphony::Configuration()->get('max_upload_size', 'admin'), 'hidden')); $primary = new XMLElement('fieldset'); $primary->setAttribute('class', 'primary column'); $sidebar_fields = $section->fetchFields(NULL, 'sidebar'); $main_fields = $section->fetchFields(NULL, 'main'); if ((!is_array($main_fields) || empty($main_fields)) && (!is_array($sidebar_fields) || empty($sidebar_fields))) { $message = __('Fields must be added to this section before an entry can be created.'); if (Administration::instance()->Author->isDeveloper()) { $message .= ' <a href="' . SYMPHONY_URL . '/blueprints/sections/edit/' . $section->get('id') . '/" accesskey="c">' . __('Add fields') . '</a>'; } $this->pageAlert($message, Alert::ERROR); } else { if (is_array($main_fields) && !empty($main_fields)) { foreach ($main_fields as $field) { $primary->appendChild($this->__wrapFieldWithDiv($field, $entry)); } $this->Form->appendChild($primary); } if (is_array($sidebar_fields) && !empty($sidebar_fields)) { $sidebar = new XMLElement('fieldset'); $sidebar->setAttribute('class', 'secondary column'); foreach ($sidebar_fields as $field) { $sidebar->appendChild($this->__wrapFieldWithDiv($field, $entry)); } $this->Form->appendChild($sidebar); } $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 entry'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this entry?'))); $div->appendChild($button); $this->Form->appendChild($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. <a href="#error">See below for details.</a>'), Alert::ERROR); } if (isset($this->_context[2])) { switch ($this->_context[2]) { case 'saved': $this->pageAlert(__('Event updated at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Events</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), SYMPHONY_URL . '/blueprints/events/new/', SYMPHONY_URL . '/blueprints/components/')), Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Event created at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Events</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), SYMPHONY_URL . '/blueprints/events/new/', SYMPHONY_URL . '/blueprints/components/')), Alert::SUCCESS); break; } } $isEditing = $readonly ? true : false; $fields = array(); $sectionManager = new SectionManager($this->_Parent); if ($this->_context[0] == 'edit' || $this->_context[0] == 'info') { $isEditing = true; $handle = $this->_context[1]; $EventManager = new EventManager($this->_Parent); $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(); $fields['filters'] = $existing->eParamFILTERS; } if (isset($_POST['fields'])) { $fields = $_POST['fields']; } $this->setPageType('form'); $this->setTitle(__($isEditing ? '%1$s – %2$s – %3$s' : '%1$s – %2$s', array(__('Symphony'), __('Events'), $about['name']))); $this->appendSubheading($isEditing ? $about['name'] : __('Untitled')); if (!$readonly) { $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Essentials'))); $group = new XMLElement('div'); $group->setAttribute('class', 'group'); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[name]', General::sanitize($fields['name']))); $div = new XMLElement('div'); if (isset($this->_errors['name'])) { $div->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['name'])); } else { $div->appendChild($label); } $group->appendChild($div); $label = Widget::Label(__('Source')); $sections = $sectionManager->fetch(NULL, 'ASC', 'name'); $options = array(); if (is_array($sections) && !empty($sections)) { foreach ($sections as $s) { $options[] = array($s->get('id'), $fields['source'] == $s->get('id'), General::sanitize($s->get('name'))); } } $label->appendChild(Widget::Select('fields[source]', $options, array('id' => 'context'))); $div = new XMLElement('div'); if (isset($this->_errors['source'])) { $div->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['source'])); } else { $div->appendChild($label); } $group->appendChild($div); $fieldset->appendChild($group); $label = Widget::Label(__('Filter Options')); $filters = is_array($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)); $label->appendChild(Widget::Select('fields[filters][]', $options, array('multiple' => 'multiple'))); $fieldset->appendChild($label); $this->Form->appendChild($fieldset); } if ($isEditing) { $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $doc = $existing->documentation(); $fieldset->setValue('<legend>' . __('Description') . '</legend>' . self::CRLF . General::tabsToSpaces(is_object($doc) ? $doc->generate(true) : $doc, 2)); $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); } }
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 __viewEdit() { $sectionManager = new SectionManager($this->_Parent); if (!($section_id = $sectionManager->fetchIDFromHandle($this->_context['section_handle']))) { Administration::instance()->customError(__('Unknown Section'), __('The Section you are looking for, <code>%s</code>, could not be found.', array($this->_context['section_handle']))); } $section = $sectionManager->fetch($section_id); $entry_id = intval($this->_context['entry_id']); $entryManager = new EntryManager($this->_Parent); $entryManager->setFetchSorting('id', 'DESC'); if (!($existingEntry = $entryManager->fetch($entry_id))) { Administration::instance()->customError(__('Unknown Entry'), __('The entry you are looking for could not be found.')); } $existingEntry = $existingEntry[0]; // If there is post data floating around, due to errors, create an entry object if (isset($_POST['fields'])) { $fields = $_POST['fields']; $entry =& $entryManager->create(); $entry->set('section_id', $existingEntry->get('section_id')); $entry->set('id', $entry_id); $entry->setDataFromPost($fields, $error, true); } else { $entry = $existingEntry; if (!$section) { $section = $sectionManager->fetch($entry->get('section_id')); } } /** * Just prior to rendering of an Entry edit form. * * @delegate EntryPreRender * @param string $context * '/publish/new/' * @param Section $section * @param Entry $entry * @param array $fields */ Symphony::ExtensionManager()->notifyMembers('EntryPreRender', '/publish/edit/', array('section' => $section, 'entry' => &$entry, 'fields' => $fields)); if (isset($this->_context['flag'])) { $link = 'publish/' . $this->_context['section_handle'] . '/new/'; list($flag, $field_id, $value) = preg_split('/:/i', $this->_context['flag'], 3); if (is_numeric($field_id) && $value) { $link .= "?prepopulate[{$field_id}]={$value}"; $this->Form->prependChild(Widget::Input("prepopulate[{$field_id}]", rawurlencode($value), 'hidden')); } switch ($flag) { case 'saved': $this->pageAlert(__('Entry updated at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Entries</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), SYMPHONY_URL . "/{$link}", SYMPHONY_URL . '/publish/' . $this->_context['section_handle'] . '/')), Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Entry created at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Entries</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), SYMPHONY_URL . "/{$link}", SYMPHONY_URL . '/publish/' . $this->_context['section_handle'] . '/')), Alert::SUCCESS); break; } } ### Determine the page title $field_id = Symphony::Database()->fetchVar('id', 0, "SELECT `id` FROM `tbl_fields` WHERE `parent_section` = '" . $section->get('id') . "' ORDER BY `sortorder` LIMIT 1"); $field = $entryManager->fieldManager->fetch($field_id); $title = trim(strip_tags($field->prepareTableValue($existingEntry->getData($field->get('id')), NULL, $entry_id))); if (trim($title) == '') { $title = 'Untitled'; } // Check if there is a field to prepopulate if (isset($_REQUEST['prepopulate'])) { $field_id = array_shift(array_keys($_REQUEST['prepopulate'])); $value = stripslashes(rawurldecode(array_shift($_REQUEST['prepopulate']))); $this->Form->prependChild(Widget::Input("prepopulate[{$field_id}]", rawurlencode($value), 'hidden')); } $this->setPageType('form'); $this->Form->setAttribute('enctype', 'multipart/form-data'); $this->setTitle(__('%1$s – %2$s – %3$s', array(__('Symphony'), $section->get('name'), $title))); $this->appendSubheading($title); $this->Form->appendChild(Widget::Input('MAX_FILE_SIZE', Symphony::Configuration()->get('max_upload_size', 'admin'), 'hidden')); ### $primary = new XMLElement('fieldset'); $primary->setAttribute('class', 'primary'); $sidebar_fields = $section->fetchFields(NULL, 'sidebar'); $main_fields = $section->fetchFields(NULL, 'main'); if ((!is_array($main_fields) || empty($main_fields)) && (!is_array($sidebar_fields) || empty($sidebar_fields))) { $primary->appendChild(new XMLElement('p', __('It looks like you\'re trying to create an entry. Perhaps you want fields first? <a href="%s">Click here to create some.</a>', array(SYMPHONY_URL . '/blueprints/sections/edit/' . $section->get('id') . '/')))); } else { if (is_array($main_fields) && !empty($main_fields)) { foreach ($main_fields as $field) { $primary->appendChild($this->__wrapFieldWithDiv($field, $entry)); } $this->Form->appendChild($primary); } if (is_array($sidebar_fields) && !empty($sidebar_fields)) { $sidebar = new XMLElement('fieldset'); $sidebar->setAttribute('class', 'secondary'); foreach ($sidebar_fields as $field) { $sidebar->appendChild($this->__wrapFieldWithDiv($field, $entry)); } $this->Form->appendChild($sidebar); } } $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 entry'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this entry?'))); $div->appendChild($button); $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); }
function __viewEdit() { $sectionManager = new SectionManager($this->_Parent); if (!($section_id = $sectionManager->fetchIDFromHandle($this->_context['section_handle']))) { $this->_Parent->customError(E_USER_ERROR, __('Unknown Section'), __('The Section you are looking for, <code>%s</code>, could not be found.', array($this->_context['section_handle'])), false, true); } $section = $sectionManager->fetch($section_id); $entry_id = intval($this->_context['entry_id']); $entryManager = new EntryManager($this->_Parent); $entryManager->setFetchSorting('id', 'DESC'); if (!($existingEntry = $entryManager->fetch($entry_id))) { $this->_Parent->customError(E_USER_ERROR, __('Unknown Entry'), __('The entry you are looking for could not be found.'), false, true); } $existingEntry = $existingEntry[0]; // If there is post data floating around, due to errors, create an entry object if (isset($_POST['fields'])) { $fields = $_POST['fields']; $entry =& $entryManager->create(); $entry->set('section_id', $existingEntry->get('section_id')); $entry->set('id', $entry_id); $entry->setDataFromPost($fields, $error, true); } else { $entry = $existingEntry; if (!$section) { $section = $sectionManager->fetch($entry->get('section_id')); } } if (isset($this->_context['flag'])) { $link = 'publish/' . $this->_context['section_handle'] . '/new/'; list($flag, $field_id, $value) = preg_split('/:/i', $this->_context['flag'], 3); if (is_numeric($field_id) && $value) { $link .= "?prepopulate[{$field_id}]={$value}"; } switch ($flag) { case 'saved': $this->pageAlert(__('Entry updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Entries</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . "/symphony/{$link}", URL . '/symphony/publish/' . $this->_context['section_handle'] . '/')), Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Entry created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Entries</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . "/symphony/{$link}", URL . '/symphony/publish/' . $this->_context['section_handle'] . '/')), Alert::SUCCESS); break; } } ### Determine the page title $field_id = $this->_Parent->Database->fetchVar('id', 0, "SELECT `id` FROM `tbl_fields` WHERE `parent_section` = '" . $section->get('id') . "' ORDER BY `sortorder` LIMIT 1"); $field = $entryManager->fieldManager->fetch($field_id); $title = trim(strip_tags($field->prepareTableValue($existingEntry->getData($field->get('id')), NULL, $entry_id))); if (trim($title) == '') { $title = 'Untitled'; } $this->setPageType('form'); $this->Form->setAttribute('enctype', 'multipart/form-data'); $this->setTitle(__('%1$s – %2$s – %3$s', array(__('Symphony'), $section->get('name'), $title))); $this->appendSubheading($title); $this->Form->appendChild(Widget::Input('MAX_FILE_SIZE', $this->_Parent->Configuration->get('max_upload_size', 'admin'), 'hidden')); ### $primary = new XMLElement('fieldset'); $primary->setAttribute('class', 'primary'); $sidebar_fields = $section->fetchFields(NULL, 'sidebar'); $main_fields = $section->fetchFields(NULL, 'main'); if ((!is_array($main_fields) || empty($main_fields)) && (!is_array($sidebar_fields) || empty($sidebar_fields))) { $primary->appendChild(new XMLElement('p', __('It looks like your trying to create an entry. Perhaps you want custom fields first? <a href="%s">Click here to create some.</a>', array(URL . '/symphony/blueprints/sections/edit/' . $section->get('id') . '/')))); } else { if (is_array($main_fields) && !empty($main_fields)) { foreach ($main_fields as $field) { $primary->appendChild($this->__wrapFieldWithDiv($field, $entry)); } $this->Form->appendChild($primary); } if (is_array($sidebar_fields) && !empty($sidebar_fields)) { $sidebar = new XMLElement('fieldset'); $sidebar->setAttribute('class', 'secondary'); foreach ($sidebar_fields as $field) { $sidebar->appendChild($this->__wrapFieldWithDiv($field, $entry)); } $this->Form->appendChild($sidebar); } } $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' => 'confirm delete', 'title' => __('Delete this entry'))); $div->appendChild($button); $this->Form->appendChild($div); }
public function __viewEdit() { $layout = new Layout(); $left = $layout->createColumn(Layout::LARGE); $right = $layout->createColumn(Layout::SMALL); $this->_existing_file = isset($this->_context[1]) ? $this->_context[1] . '.xsl' : NULL; ## Handle unknown context if (!in_array($this->_context[0], array('new', 'edit'))) { throw new AdministrationPageNotFoundException(); } ## Edit Utility context if ($this->_context[0] == 'edit') { $file_abs = UTILITIES . '/' . $this->_existing_file; $filename = $this->_existing_file; if (!is_file($file_abs) && !is_readable($file_abs)) { redirect(ADMIN_URL . '/blueprints/utilities/new/'); } $fields['name'] = $filename; $fields['template'] = file_get_contents($file_abs); $this->Form->setAttribute('action', ADMIN_URL . '/blueprints/utilities/edit/' . $this->_context[1] . '/'); } else { $fields['name'] = ''; $fields['template'] = file_get_contents(TEMPLATES . '/template.utility.txt'); $filename = ''; } $formHasErrors = $this->errors->valid(); if ($formHasErrors) { $this->alerts()->append(__('An error occurred while processing this form. <a href="#error">See below for details.</a>'), AlertStack::ERROR); } if (isset($this->_context[2])) { switch ($this->_context[2]) { case 'saved': $this->alerts()->append(__('Utility updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), ADMIN_URL . '/blueprints/utilities/new/', ADMIN_URL . '/blueprints/utilities/')), AlertStack::SUCCESS); break; case 'created': $this->alerts()->append(__('Utility created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), ADMIN_URL . '/blueprints/utilities/new/', ADMIN_URL . '/blueprints/utilities/')), AlertStack::SUCCESS); break; } } $this->setTitle(__($this->_context[0] == 'new' ? '%1$s – %2$s' : '%1$s – %2$s – %3$s', array(__('Symphony'), __('Utilities'), $filename))); $this->appendSubheading($this->_context[0] == 'new' ? __('New Utility') : $filename); if (!empty($_POST)) { $fields = $_POST['fields']; } $fieldset = Widget::Fieldset(__('Essentials')); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[name]', $fields['name'])); $fieldset->appendChild(isset($this->errors->name) ? Widget::wrapFormElementWithError($label, $this->errors->name) : $label); $label = Widget::Label(__('XSLT')); $label->appendChild(Widget::Textarea('fields[template]', $fields['template'], array('rows' => 30, 'cols' => 80, 'class' => 'code'))); $fieldset->appendChild(isset($this->errors->template) ? Widget::wrapFormElementWithError($label, $this->errors->template) : $label); $left->appendChild($fieldset); $utilities = General::listStructure(UTILITIES, array('xsl'), false, 'asc', UTILITIES); $utilities = $utilities['filelist']; if (is_array($utilities) && !empty($utilities)) { $fieldset = Widget::Fieldset(__('Utilities')); $ul = $this->createElement('ul'); $ul->setAttribute('id', 'utilities'); $i = 0; foreach ($utilities as $util) { $li = $this->createElement('li'); if ($i++ % 2 != 1) { $li->setAttribute('class', 'odd'); } $li->appendChild(Widget::Anchor($util, ADMIN_URL . '/blueprints/utilities/edit/' . str_replace('.xsl', '', $util) . '/', array())); $ul->appendChild($li); } $fieldset->appendChild($ul); $right->appendChild($fieldset); } $layout->appendTo($this->Form); $div = $this->createElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Submit('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : __('Create Utility'), array('accesskey' => 's'))); if ($this->_context[0] == 'edit') { $div->appendChild(Widget::Submit('action[delete]', __('Delete'), array('class' => 'confirm delete', 'title' => __('Delete this utility')))); } $this->Form->appendChild($div); }
public function __form() { $formHasErrors = is_array($this->_errors) && !empty($this->_errors); if ($formHasErrors) { $this->pageAlert(__('An error occurred while processing this form. See below for details.'), Alert::ERROR); } else { if (isset($this->_context[2])) { switch ($this->_context[2]) { case 'saved': $this->pageAlert(__('Data source updated at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/blueprints/datasources/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/blueprints/datasources/" accesskey="a">' . __('View all Data sources') . '</a>', Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Data source created at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/blueprints/datasources/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/blueprints/datasources/" accesskey="a">' . __('View all Data sources') . '</a>', Alert::SUCCESS); break; } } } $providers = Symphony::ExtensionManager()->getProvidersOf('data-sources'); if (isset($_POST['fields'])) { $fields = $_POST['fields']; $fields['paginate_results'] = $fields['paginate_results'] == 'on' ? 'yes' : 'no'; if (!in_array($fields['source'], array('authors', 'navigation', 'dynamic_xml', 'static_xml')) && is_array($fields['filter']) && !empty($fields['filter'])) { $filters = array(); foreach ($fields['filter'] as $f) { foreach ($f as $key => $val) { $filters[$key] = $val; } } $fields['filter'][$fields['source']] = $filters; } if (!isset($fields['xml_elements']) || !is_array($fields['xml_elements'])) { $fields['xml_elements'] = array(); } } else { if ($this->_context[0] == 'edit') { $isEditing = true; $handle = $this->_context[1]; $existing =& DatasourceManager::create($handle, array(), false); $cache_id = null; if (!$existing->allowEditorToParse()) { redirect(SYMPHONY_URL . '/blueprints/datasources/info/' . $handle . '/'); } $about = $existing->about(); $cache = new Cacheable(Symphony::Database()); $fields['name'] = $about['name']; $fields['order'] = $existing->dsParamORDER == 'rand' ? 'random' : $existing->dsParamORDER; $fields['param'] = $existing->dsParamPARAMOUTPUT; $fields['required_url_param'] = trim($existing->dsParamREQUIREDPARAM); if (isset($existing->dsParamINCLUDEDELEMENTS) && is_array($existing->dsParamINCLUDEDELEMENTS)) { $fields['xml_elements'] = $existing->dsParamINCLUDEDELEMENTS; } else { $fields['xml_elements'] = array(); } $fields['sort'] = $existing->dsParamSORT; $fields['paginate_results'] = isset($existing->dsParamPAGINATERESULTS) ? $existing->dsParamPAGINATERESULTS : 'yes'; $fields['page_number'] = $existing->dsParamSTARTPAGE; $fields['group'] = isset($existing->dsParamGROUP) ? $existing->dsParamGROUP : null; $fields['html_encode'] = isset($existing->dsParamHTMLENCODE) ? $existing->dsParamHTMLENCODE : 'no'; $fields['associated_entry_counts'] = $existing->dsParamASSOCIATEDENTRYCOUNTS; if (is_null($fields['associated_entry_counts'])) { $fields['associated_entry_counts'] = 'yes'; } if ($existing->dsParamREDIRECTONEMPTY == 'yes') { $fields['redirect_on_empty'] = 'yes'; } if (!is_array($existing->dsParamFILTERS)) { $existing->dsParamFILTERS = array(); } if (!empty($existing->dsParamFILTERS)) { $existing->dsParamFILTERS = array_map('stripslashes', $existing->dsParamFILTERS); } $fields['source'] = $existing->getSource(); $provided = false; if (!empty($providers)) { foreach ($providers as $providerClass => $provider) { if ($fields['source'] == call_user_func(array($providerClass, 'getClass'))) { $fields = array_merge($fields, $existing->settings()); $provided = true; break; } } } if ($provided == false) { switch ($fields['source']) { case 'authors': $fields['filter']['author'] = $existing->dsParamFILTERS; break; case 'navigation': $fields['filter']['navigation'] = $existing->dsParamFILTERS; break; case 'dynamic_xml': $fields['dynamic_xml']['namespace'] = $existing->dsParamFILTERS; $fields['dynamic_xml']['url'] = $existing->dsParamURL; $fields['dynamic_xml']['xpath'] = $existing->dsParamXPATH; $fields['dynamic_xml']['cache'] = $existing->dsParamCACHE; $fields['dynamic_xml']['timeout'] = isset($existing->dsParamTIMEOUT) ? $existing->dsParamTIMEOUT : 6; break; case 'static_xml': $existing->grab(); if (!isset($existing->dsParamSTATIC)) { $fields['static_xml'] = trim($existing->dsSTATIC); } else { $fields['static_xml'] = trim($existing->dsParamSTATIC); } break; break; default: $fields['filter'][$fields['source']] = $existing->dsParamFILTERS; $fields['max_records'] = $existing->dsParamLIMIT; break; } } } else { $fields['dynamic_xml']['url'] = ''; $fields['dynamic_xml']['cache'] = '30'; $fields['dynamic_xml']['xpath'] = '/'; $fields['dynamic_xml']['timeout'] = '6'; $fields['dynamic_xml']['format'] = 'XML'; $fields['paginate_results'] = 'yes'; $fields['max_records'] = '20'; $fields['page_number'] = '1'; $fields['order'] = 'desc'; $fields['associated_entry_counts'] = NULL; } } $this->setPageType('form'); $this->setTitle(__($isEditing ? '%1$s – %2$s – %3$s' : '%2$s – %3$s', array($about['name'], __('Data Sources'), __('Symphony')))); $this->appendSubheading($isEditing ? $about['name'] : __('Untitled')); $this->insertBreadcrumbs(array(Widget::Anchor(__('Data Sources'), SYMPHONY_URL . '/blueprints/datasources/'))); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Essentials'))); $group = new XMLElement('div'); $group->setAttribute('class', 'two columns'); $div = new XMLElement('div', NULL, array('class' => 'column')); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[name]', General::sanitize($fields['name']))); if (isset($this->_errors['name'])) { $div->appendChild(Widget::Error($label, $this->_errors['name'])); } else { $div->appendChild($label); } $group->appendChild($div); $div = new XMLElement('div', NULL, array('class' => 'column')); $label = Widget::Label(__('Source')); $sections = SectionManager::fetch(NULL, 'ASC', 'name'); if (!is_array($sections)) { $sections = array(); } $field_groups = array(); foreach ($sections as $section) { $field_groups[$section->get('id')] = array('fields' => $section->fetchFields(), 'section' => $section); } $options = array(array('label' => __('System'), 'options' => array(array('authors', $fields['source'] == 'authors', __('Authors')), array('navigation', $fields['source'] == 'navigation', __('Navigation')))), array('label' => __('Custom XML'), 'options' => array(array('dynamic_xml', $fields['source'] == 'dynamic_xml', __('Dynamic XML')), array('static_xml', $fields['source'] == 'static_xml', __('Static XML'))))); // Loop over the datasource providers if (!empty($providers)) { $p = array('label' => __('From extensions'), 'options' => array()); foreach ($providers as $providerClass => $provider) { $p['options'][] = array($providerClass, $fields['source'] == $providerClass, $provider); } $options[] = $p; } // Add Sections if (is_array($sections) && !empty($sections)) { array_unshift($options, array('label' => __('Sections'), 'options' => array())); foreach ($sections as $s) { $options[0]['options'][] = array($s->get('id'), $fields['source'] == $s->get('id'), General::sanitize($s->get('name'))); } } $label->appendChild(Widget::Select('fields[source]', $options, array('id' => 'ds-context'))); $div->appendChild($label); $group->appendChild($div); $fieldset->appendChild($group); $this->Form->appendChild($fieldset); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings contextual authors navigation ' . __('Sections') . ' ' . __('System')); $fieldset->appendChild(new XMLElement('legend', __('Filter Results'))); $p = new XMLElement('p', __('Use %s syntax to filter by page parameters.', array('<code>{' . __('$param') . '}</code>'))); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); foreach ($field_groups as $section_id => $section_data) { $div = new XMLElement('div'); $div->setAttribute('class', 'contextual ' . $section_data['section']->get('id')); $ol = new XMLElement('ol'); $ol->setAttribute('class', 'filters-duplicator'); $ol->setAttribute('data-add', __('Add filter')); $ol->setAttribute('data-remove', __('Remove filter')); // Add system:id filter if (isset($fields['filter'][$section_data['section']->get('id')]['id'])) { $li = new XMLElement('li'); $li->setAttribute('class', 'unique'); $li->setAttribute('data-type', 'id'); $li->appendChild(new XMLElement('header', '<h4>' . __('System ID') . '</h4>')); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][' . $section_data['section']->get('id') . '][id]', General::sanitize($fields['filter'][$section_data['section']->get('id')]['id']))); $li->appendChild($label); $ol->appendChild($li); } $li = new XMLElement('li'); $li->setAttribute('class', 'unique template'); $li->setAttribute('data-type', 'id'); $li->appendChild(new XMLElement('header', '<h4>' . __('System ID') . '</h4>')); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][' . $section_data['section']->get('id') . '][id]')); $li->appendChild($label); $ol->appendChild($li); // Add system:date filter if (isset($fields['filter'][$section_data['section']->get('id')]['system:date'])) { $li = new XMLElement('li'); $li->setAttribute('class', 'unique'); $li->setAttribute('data-type', 'system:date'); $li->appendChild(new XMLElement('header', '<h4>' . __('System Date') . '</h4>')); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][' . $section_data['section']->get('id') . '][system:date]', General::sanitize($fields['filter'][$section_data['section']->get('id')]['system:date']))); $li->appendChild($label); $ol->appendChild($li); } $li = new XMLElement('li'); $li->setAttribute('class', 'unique template'); $li->setAttribute('data-type', 'system:date'); $li->appendChild(new XMLElement('header', '<h4>' . __('System Date') . '</h4>')); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][' . $section_data['section']->get('id') . '][system:date]')); $li->appendChild($label); $ol->appendChild($li); if (is_array($section_data['fields']) && !empty($section_data['fields'])) { foreach ($section_data['fields'] as $input) { if (!$input->canFilter()) { continue; } if (isset($fields['filter'][$section_data['section']->get('id')][$input->get('id')])) { $wrapper = new XMLElement('li'); $wrapper->setAttribute('class', 'unique'); $wrapper->setAttribute('data-type', $input->get('element_name')); $input->displayDatasourceFilterPanel($wrapper, $fields['filter'][$section_data['section']->get('id')][$input->get('id')], $this->_errors[$input->get('id')], $section_data['section']->get('id')); $ol->appendChild($wrapper); } $wrapper = new XMLElement('li'); $wrapper->setAttribute('class', 'unique template'); $wrapper->setAttribute('data-type', $input->get('element_name')); $input->displayDatasourceFilterPanel($wrapper, NULL, NULL, $section_data['section']->get('id')); $ol->appendChild($wrapper); } } $div->appendChild($ol); $fieldset->appendChild($div); } $div = new XMLElement('div'); $div->setAttribute('class', 'contextual authors'); $ol = new XMLElement('ol'); $ol->setAttribute('class', 'filters-duplicator'); $ol->setAttribute('data-add', __('Add filter')); $ol->setAttribute('data-remove', __('Remove filter')); $this->__appendAuthorFilter($ol, __('ID'), 'id', $fields['filter']['author']['id'], !isset($fields['filter']['author']['id'])); $this->__appendAuthorFilter($ol, __('Username'), 'username', $fields['filter']['author']['username'], !isset($fields['filter']['author']['username'])); $this->__appendAuthorFilter($ol, __('First Name'), 'first_name', $fields['filter']['author']['first_name'], !isset($fields['filter']['author']['first_name'])); $this->__appendAuthorFilter($ol, __('Last Name'), 'last_name', $fields['filter']['author']['last_name'], !isset($fields['filter']['author']['last_name'])); $this->__appendAuthorFilter($ol, __('Email'), 'email', $fields['filter']['author']['email'], !isset($fields['filter']['author']['email'])); $this->__appendAuthorFilter($ol, __('User Type'), 'user_type', $fields['filter']['author']['user_type'], !isset($fields['filter']['author']['user_type'])); $div->appendChild($ol); $fieldset->appendChild($div); $div = new XMLElement('div'); $div->setAttribute('class', 'contextual navigation'); $ol = new XMLElement('ol'); $ol->setAttribute('class', 'filters-duplicator'); $ol->setAttribute('data-add', __('Add filter')); $ol->setAttribute('data-remove', __('Remove filter')); $ul = new XMLElement('ul'); $ul->setAttribute('class', 'tags'); $pages = PageManager::fetch(false, array('*'), array(), 'title ASC'); foreach ($pages as $page) { $ul->appendChild(new XMLElement('li', preg_replace('/\\/{2,}/i', '/', '/' . $page['path'] . '/' . $page['handle']))); } if (isset($fields['filter']['navigation']['parent'])) { $li = new XMLElement('li'); $li->setAttribute('class', 'unique'); $li->setAttribute('data-type', 'parent'); $li->appendChild(new XMLElement('header', '<h4>' . __('Parent Page') . '</h4>')); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][navigation][parent]', General::sanitize($fields['filter']['navigation']['parent']))); $li->appendChild($label); $li->appendChild($ul); $ol->appendChild($li); } $li = new XMLElement('li'); $li->setAttribute('class', 'unique template'); $li->setAttribute('data-type', 'parent'); $li->appendChild(new XMLElement('header', '<h4>' . __('Parent Page') . '</h4>')); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][navigation][parent]')); $li->appendChild($label); $li->appendChild($ul); $ol->appendChild($li); $ul = new XMLElement('ul'); $ul->setAttribute('class', 'tags'); if ($types = PageManager::fetchAvailablePageTypes()) { foreach ($types as $type) { $ul->appendChild(new XMLElement('li', $type)); } } if (isset($fields['filter']['navigation']['type'])) { $li = new XMLElement('li'); $li->setAttribute('class', 'unique'); $li->setAttribute('data-type', 'type'); $li->appendChild(new XMLElement('header', '<h4>' . __('Page Type') . '</h4>')); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][navigation][type]', General::sanitize($fields['filter']['navigation']['type']))); $li->appendChild($label); $li->appendChild($ul); $ol->appendChild($li); } $li = new XMLElement('li'); $li->setAttribute('class', 'unique template'); $li->appendChild(new XMLElement('header', '<h4>' . __('Page Type') . '</h4>')); $li->setAttribute('data-type', 'type'); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][navigation][type]')); $li->appendChild($label); $li->appendChild($ul); $ol->appendChild($li); $div->appendChild($ol); $fieldset->appendChild($div); $this->Form->appendChild($fieldset); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings contextual inverse navigation authors static_xml dynamic_xml From_extensions'); $fieldset->appendChild(new XMLElement('legend', __('Sorting and Limiting'))); $p = new XMLElement('p', __('Use %s syntax to limit by page parameters.', array('<code>{' . __('$param') . '}</code>'))); $p->setAttribute('class', 'help contextual inverse navigation'); $fieldset->appendChild($p); $div = new XMLElement('div'); $div->setAttribute('class', 'two columns contextual sections ' . __('Sections')); $label = Widget::Label(__('Sort By'), NULL, 'column'); $options = array(array('label' => __('Authors'), 'options' => array(array('id', $fields['source'] == 'authors' && $fields['sort'] == 'id', __('Author ID')), array('username', $fields['source'] == 'authors' && $fields['sort'] == 'username', __('Username')), array('first-name', $fields['source'] == 'authors' && $fields['sort'] == 'first-name', __('First Name')), array('last-name', $fields['source'] == 'authors' && $fields['sort'] == 'last-name', __('Last Name')), array('email', $fields['source'] == 'authors' && $fields['sort'] == 'email', __('Email')), array('status', $fields['source'] == 'authors' && $fields['sort'] == 'status', __('Status')))), array('label' => __('Navigation'), 'options' => array(array('id', $fields['source'] == 'navigation' && $fields['sort'] == 'id', __('Page ID')), array('handle', $fields['source'] == 'navigation' && $fields['sort'] == 'handle', __('Handle')), array('sortorder', $fields['source'] == 'navigation' && $fields['sort'] == 'sortorder', __('Sort Order'))))); foreach ($field_groups as $section_id => $section_data) { $optgroup = array('label' => General::sanitize($section_data['section']->get('name')), 'options' => array(array('system:id', $fields['source'] == $section_data['section']->get('id') && $fields['sort'] == 'system:id', __('System ID')), array('system:date', $fields['source'] == $section_data['section']->get('id') && $fields['sort'] == 'system:date', __('System Date')))); if (is_array($section_data['fields']) && !empty($section_data['fields'])) { foreach ($section_data['fields'] as $input) { if (!$input->isSortable()) { continue; } $optgroup['options'][] = array($input->get('element_name'), $fields['source'] == $section_data['section']->get('id') && $input->get('element_name') == $fields['sort'], $input->get('label')); } } $options[] = $optgroup; } $label->appendChild(Widget::Select('fields[sort]', $options, array('class' => 'filtered'))); $div->appendChild($label); $label = Widget::Label(__('Sort Order'), NULL, 'column'); $options = array(array('asc', 'asc' == $fields['order'], __('ascending')), array('desc', 'desc' == $fields['order'], __('descending')), array('random', 'random' == $fields['order'], __('random'))); // Retain custom sort order if (!in_array($fields['order'], array('asc', 'desc', 'random'))) { $options[] = array($fields['order'], true, $fields['order']); } $label->appendChild(Widget::Select('fields[order]', $options)); $div->appendChild($label); $fieldset->appendChild($div); $label = Widget::Label(); $input = array(Widget::Input('fields[paginate_results]', NULL, 'checkbox', $fields['paginate_results'] == 'yes' ? array('checked' => 'checked') : NULL), Widget::Input('fields[max_records]', $fields['max_records'], 'text', array('size' => '6')), Widget::Input('fields[page_number]', $fields['page_number'], 'text', array('size' => '6'))); $label->setValue(__('%1$s Paginate results, limiting to %2$s entries per page. Return page %3$s', array($input[0]->generate(false), $input[1]->generate(false), $input[2]->generate(false)))); if (isset($this->_errors['max_records'])) { $fieldset->appendChild(Widget::Error($label, $this->_errors['max_records'])); } else { if (isset($this->_errors['page_number'])) { $fieldset->appendChild(Widget::Error($label, $this->_errors['page_number'])); } else { $fieldset->appendChild($label); } } $p = new XMLElement('p', __('Failing to paginate may degrade performance if the number of entries returned is very high.'), array('class' => 'help')); $fieldset->appendChild($p); $this->Form->appendChild($fieldset); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings contextual inverse navigation static_xml dynamic_xml From_extensions'); $fieldset->appendChild(new XMLElement('legend', __('Output Options'))); $label = Widget::Label(__('Required URL Parameter')); $label->appendChild(new XMLElement('i', __('Optional'))); $label->appendChild(Widget::Input('fields[required_url_param]', trim($fields['required_url_param']), 'text', array('placeholder' => __('$param')))); $fieldset->appendChild($label); $p = new XMLElement('p', __('An empty result will be returned when this parameter does not have a value.')); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $label = Widget::Label(); $input = Widget::Input('fields[redirect_on_empty]', 'yes', 'checkbox', isset($fields['redirect_on_empty']) ? array('checked' => 'checked') : NULL); $label->setValue(__('%s Redirect to 404 page when no results are found', array($input->generate(false)))); $fieldset->appendChild($label); $div = new XMLElement('div', NULL, array('class' => 'two columns')); $subfieldset = new XMLElement('fieldset', NULL, array('class' => 'column')); $subfieldset->appendChild(new XMLElement('legend', __('Output Parameters'))); // Support multiple parameters if (!is_array($fields['param'])) { $fields['param'] = array($fields['param']); } $label = Widget::Label(__('Use Fields')); $prefix = '$ds-' . (isset($this->_context[1]) ? Lang::createHandle($fields['name']) : '?') . '.'; $options = array(array('label' => __('Authors'), 'options' => array())); foreach (array('id', 'username', 'name', 'email', 'user_type') as $p) { $options[0]['options'][] = array($p, $fields['source'] == 'authors' && in_array($p, $fields['param']), $prefix . $p); } foreach ($field_groups as $section_id => $section_data) { $optgroup = array('label' => $section_data['section']->get('name'), 'options' => array()); foreach (array('id', 'date', 'author') as $p) { $optgroup['options'][] = array('system:' . $p, $fields['source'] == $section_data['section']->get('id') && in_array('system:' . $p, $fields['param']), $prefix . 'system-' . $p); } $authorOverride = false; if (is_array($section_data['fields']) && !empty($section_data['fields'])) { foreach ($section_data['fields'] as $input) { if (!$input->allowDatasourceParamOutput()) { continue; } $optgroup['options'][] = array($input->get('element_name'), $fields['source'] == $section_data['section']->get('id') && in_array($input->get('element_name'), $fields['param']), $prefix . $input->get('element_name')); } } $options[] = $optgroup; } $label->appendChild(Widget::Select('fields[param][]', $options, array('class' => 'filtered', 'multiple' => 'multiple'))); $subfieldset->appendChild($label); $div->appendChild($subfieldset); $subfieldset = new XMLElement('fieldset', NULL, array('class' => 'column')); $subfieldset->appendChild(new XMLElement('legend', __('XML Output'))); $label = Widget::Label(__('Group By')); $options = array(array('', NULL, __('None'))); foreach ($field_groups as $section_id => $section_data) { $optgroup = array('label' => $section_data['section']->get('name'), 'options' => array()); $authorOverride = false; if (is_array($section_data['fields']) && !empty($section_data['fields'])) { foreach ($section_data['fields'] as $input) { if (!$input->allowDatasourceOutputGrouping()) { continue; } if ($input->get('element_name') == 'author') { $authorOverride = true; } $optgroup['options'][] = array($input->get('id'), $fields['source'] == $section_data['section']->get('id') && $fields['group'] == $input->get('id'), $input->get('label')); } } if (!$authorOverride) { $optgroup['options'][] = array('author', $fields['source'] == $section_data['section']->get('id') && $fields['group'] == 'author', __('Author')); } $options[] = $optgroup; } $label->appendChild(Widget::Select('fields[group]', $options, array('class' => 'filtered'))); $subfieldset->appendChild($label); $label = Widget::Label(__('Included Elements')); $options = array(array('label' => __('Authors'), 'options' => array(array('username', $fields['source'] == 'authors' && in_array('username', $fields['xml_elements']), 'username'), array('name', $fields['source'] == 'authors' && in_array('name', $fields['xml_elements']), 'name'), array('email', $fields['source'] == 'authors' && in_array('email', $fields['xml_elements']), 'email'), array('author-token', $fields['source'] == 'authors' && in_array('author-token', $fields['xml_elements']), 'author-token'), array('default-area', $fields['source'] == 'authors' && in_array('default-area', $fields['xml_elements']), 'default-area')))); foreach ($field_groups as $section_id => $section_data) { $optgroup = array('label' => General::sanitize($section_data['section']->get('name')), 'options' => array(array('system:pagination', $fields['source'] == $section_data['section']->get('id') && in_array('system:pagination', $fields['xml_elements']), 'system: pagination'))); if (is_array($section_data['fields']) && !empty($section_data['fields'])) { foreach ($section_data['fields'] as $field) { $elements = $field->fetchIncludableElements(); if (is_array($elements) && !empty($elements)) { foreach ($elements as $name) { $selected = false; if ($fields['source'] == $section_data['section']->get('id') && in_array($name, $fields['xml_elements'])) { $selected = true; } $optgroup['options'][] = array($name, $selected, $name); } } } } $options[] = $optgroup; } $label->appendChild(Widget::Select('fields[xml_elements][]', $options, array('multiple' => 'multiple', 'class' => 'filtered'))); $subfieldset->appendChild($label); $label = Widget::Label(); $label->setAttribute('class', 'contextual inverse authors'); $input = Widget::Input('fields[associated_entry_counts]', 'yes', 'checkbox', isset($fields['associated_entry_counts']) && $fields['associated_entry_counts'] == 'yes' ? array('checked' => 'checked') : NULL); $label->setValue(__('%s Include a count of entries in associated sections', array($input->generate(false)))); $subfieldset->appendChild($label); $label = Widget::Label(); $label->setAttribute('class', 'contextual inverse authors'); $input = Widget::Input('fields[html_encode]', 'yes', 'checkbox', isset($fields['html_encode']) && $fields['html_encode'] == 'yes' ? array('checked' => 'checked') : NULL); $label->setValue(__('%s HTML-encode text', array($input->generate(false)))); $subfieldset->appendChild($label); $div->appendChild($subfieldset); $fieldset->appendChild($div); $this->Form->appendChild($fieldset); // Dynamic XML $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings contextual dynamic_xml'); $fieldset->appendChild(new XMLElement('legend', __('Dynamic XML'))); $label = Widget::Label(__('URL')); $label->appendChild(Widget::Input('fields[dynamic_xml][url]', General::sanitize($fields['dynamic_xml']['url']))); if (isset($this->_errors['dynamic_xml']['url'])) { $fieldset->appendChild(Widget::Error($label, $this->_errors['dynamic_xml']['url'])); } else { $fieldset->appendChild($label); } $p = new XMLElement('p', __('Use %s syntax to specify dynamic portions of the URL.', array('<code>{' . __('$param') . '}</code>'))); $p->setAttribute('class', 'help'); $label->appendChild($p); $div = new XMLElement('div'); $p = new XMLElement('p', __('Namespace Declarations')); $p->appendChild(new XMLElement('i', __('Optional'))); $p->setAttribute('class', 'label'); $div->appendChild($p); $ol = new XMLElement('ol'); $ol->setAttribute('class', 'filters-duplicator'); $ol->setAttribute('data-add', __('Add namespace')); $ol->setAttribute('data-remove', __('Remove namespace')); if (is_array($fields['dynamic_xml']['namespace'])) { $i = 0; foreach ($fields['dynamic_xml']['namespace'] as $name => $uri) { // Namespaces get saved to the file as $name => $uri, however in // the $_POST they are represented as $index => array. This loop // patches the difference. if (is_array($uri)) { $name = $uri['name']; $uri = $uri['uri']; } $li = new XMLElement('li'); $li->appendChild(new XMLElement('header', '<h4>' . __('Namespace') . '</h4>')); $group = new XMLElement('div'); $group->setAttribute('class', 'group'); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[dynamic_xml][namespace][' . $i . '][name]', General::sanitize($name))); $group->appendChild($label); $label = Widget::Label(__('URI')); $label->appendChild(Widget::Input('fields[dynamic_xml][namespace][' . $i . '][uri]', General::sanitize($uri))); $group->appendChild($label); $li->appendChild($group); $ol->appendChild($li); $i++; } } $li = new XMLElement('li'); $li->setAttribute('class', 'template'); $li->setAttribute('data-type', 'namespace'); $li->appendChild(new XMLElement('header', '<h4>' . __('Namespace') . '</h4>')); $group = new XMLElement('div'); $group->setAttribute('class', 'group'); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[dynamic_xml][namespace][-1][name]')); $group->appendChild($label); $label = Widget::Label(__('URI')); $label->appendChild(Widget::Input('fields[dynamic_xml][namespace][-1][uri]')); $group->appendChild($label); $li->appendChild($group); $ol->appendChild($li); $div->appendChild($ol); $fieldset->appendChild($div); $label = Widget::Label(__('Included Elements')); $label->appendChild(Widget::Input('fields[dynamic_xml][xpath]', General::sanitize($fields['dynamic_xml']['xpath']))); if (isset($this->_errors['dynamic_xml']['xpath'])) { $fieldset->appendChild(Widget::Error($label, $this->_errors['dynamic_xml']['xpath'])); } else { $fieldset->appendChild($label); } $p = new XMLElement('p', __('Use an XPath expression to select which elements from the source XML to include.')); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $label = Widget::Label(); $input = Widget::Input('fields[dynamic_xml][cache]', (string) max(1, intval($fields['dynamic_xml']['cache'])), 'text', array('size' => '6')); $label->setValue(__('Update cached result every %s minutes', array($input->generate(false)))); if (isset($this->_errors['dynamic_xml']['cache'])) { $fieldset->appendChild(Widget::Error($label, $this->_errors['dynamic_xml']['cache'])); } else { $fieldset->appendChild($label); } $label = Widget::Label(); $input = Widget::Input('fields[dynamic_xml][timeout]', (string) max(1, intval($fields['dynamic_xml']['timeout'])), 'text', array('type' => 'hidden')); $label->appendChild($input); $fieldset->appendChild($label); $this->Form->appendChild($fieldset); // Static XML $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings contextual static_xml'); $fieldset->appendChild(new XMLElement('legend', __('Static XML'))); $label = Widget::Label(__('Body')); $label->appendChild(Widget::Textarea('fields[static_xml]', 12, 50, General::sanitize(stripslashes($fields['static_xml'])), array('class' => 'code'))); if (isset($this->_errors['static_xml'])) { $fieldset->appendChild(Widget::Error($label, $this->_errors['static_xml'])); } else { $fieldset->appendChild($label); } $this->Form->appendChild($fieldset); // Call the provided datasources to let them inject their filters // @todo Ideally when a new Datasource is chosen an AJAX request will fire // to get the HTML from the extension. This is hardcoded for now into // creating a 'big' page and then hiding the fields with JS if (!empty($providers)) { foreach ($providers as $providerClass => $provider) { call_user_func(array($providerClass, 'buildEditor'), $this->Form, &$this->_errors, $fields, $handle); } } $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $isEditing ? __('Save Changes') : __('Create Data Source'), 'submit', array('accesskey' => 's'))); if ($isEditing) { $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this data source'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this data source?'))); $div->appendChild($button); } $this->Form->appendChild($div); }
protected function __viewForm() { // Show page alert: if ($this->failed) { $this->alerts()->append(__('An error occurred while processing this form. <a href="#error">See below for details.</a>'), AlertStack::ERROR); } else { if (!is_null($this->status)) { switch ($this->status) { case 'saved': $this->alerts()->append(__('Data source updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), ADMIN_URL . '/blueprints/datasources/new/', ADMIN_URL . '/blueprints/datasources/')), AlertStack::SUCCESS); break; case 'created': $this->alerts()->append(__('Data source created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), ADMIN_URL . '/blueprints/datasources/new/', ADMIN_URL . '/blueprints/datasources/')), AlertStack::SUCCESS); break; } } } if (!$this->datasource instanceof Datasource || is_null($this->datasource->about()->name) || strlen(trim($this->datasource->about()->name)) == 0) { $this->setTitle(__('%1$s – %2$s – %3$s', array(__('Symphony'), __('Data Sources'), __('Untitled')))); $this->appendSubheading(General::sanitize(__('Data Source'))); } else { $this->setTitle(__('%1$s – %2$s – %3$s', array(__('Symphony'), __('Data Sources'), $this->datasource->about()->name))); $this->appendSubheading(General::sanitize($this->datasource->about()->name)); } // Track type with a hidden field: if ($this->editing || $this->editing && isset($_POST['type'])) { $input = Widget::Input('type', $this->type, 'hidden'); $this->Form->appendChild($input); } else { $header = $this->xpath('//h2')->item(0); $options = array(); foreach ($this->types as $type) { $options[] = array($type->class, $this->type == $type->class, $type->name); } usort($options, 'General::optionsSort'); $select = Widget::Select('type', $options); $header->prependChild($select); $header->prependChild(new DOMText(__('New'))); } if ($this->datasource instanceof Datasource) { $this->datasource->view($this->Form, $this->errors); } $actions = $this->createElement('div'); $actions->setAttribute('class', 'actions'); $save = Widget::Submit('action[save]', $this->editing ? __('Save Changes') : __('Create Data Source'), array('accesskey' => 's')); if (!$this->datasource instanceof Datasource) { $save->setAttribute('disabled', 'disabled'); } $actions->appendChild($save); if ($this->editing == true) { $actions->appendChild(Widget::Submit('action[delete]', __('Delete'), array('class' => 'confirm delete', 'title' => __('Delete this data source')))); } $this->Form->appendChild($actions); }
public function view() { if (!($role_id = $this->_context[0])) { redirect(extension_members::baseURL()); } if (!($existing = $this->_driver->fetchRole($role_id, true))) { throw new SymphonyErrorPage(__('The role you requested to edit does not exist.'), __('Role not found'), 'error'); } if (isset($this->_context[1])) { switch ($this->_context[1]) { case 'saved': $this->pageAlert(__('Role updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Roles</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), extension_members::baseURL() . 'roles_new/', extension_members::baseURL() . 'roles/')), Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Role created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Roles</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), extension_members::baseURL() . 'roles_new/', extension_members::baseURL() . 'roles/')), Alert::SUCCESS); break; } } Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/members/assets/styles.css', 'screen', 9125341); Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/members/assets/jquery-ui.css', 'screen', 9125342); Administration::instance()->Page->addScriptToHead(URL . '/extensions/members/assets/jquery-ui.js', 9126342); Administration::instance()->Page->addScriptToHead(URL . '/extensions/members/assets/members.js', 9126343); $formHasErrors = 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>'), AdministrationPage::PAGE_ALERT_ERROR); } $this->setPageType('form'); $this->setTitle('Symphony – Member Roles – ' . $existing->name()); $this->appendSubheading($existing->name()); $fields = array(); if (isset($_POST['fields'])) { $fields = $_POST['fields']; } else { $fields['name'] = $existing->name(); $fields['permissions'] = $existing->eventPermissions(); $fields['page_access'] = $existing->forbiddenPages(); } $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings type-file'); $fieldset->appendChild(new XMLElement('legend', 'Essentials')); $label = Widget::Label('Name'); $label->appendChild(Widget::Input('fields[name]', General::sanitize($fields['name']))); if (isset($this->_errors['name'])) { $fieldset->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['name'])); } else { $fieldset->appendChild($label); } $this->Form->appendChild($fieldset); $EventManager = new EventManager($this->_Parent); $events = $EventManager->listAll(); if (is_array($events) && !empty($events)) { foreach ($events as $handle => $e) { $show_in_role_permissions = method_exists("event{$handle}", 'showInRolePermissions') && call_user_func(array("event{$handle}", 'showInRolePermissions')) === true ? true : false; if (!$e['can_parse'] && !$show_in_role_permissions) { unset($events[$handle]); } } } $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings type-file'); $fieldset->appendChild(new XMLElement('legend', 'Event Level Permissions')); $aTableHead = array(array('Event', 'col'), array('Create', 'col'), array('Edit', 'col')); $aTableBody = array(); /* <tr class="global"> <td>Set Global Permissions</td> <td class="add"> <input type="checkbox" name="add-global" value="no"/> </td> <td class="edit"> <p class="global-slider"></p> <span>n/a</span> </td> <!--<td class="delete"> <p class="global-slider"></p> <span>n/a</span> </td>--> </tr> */ ## Setup each cell $td1 = Widget::TableData('Global Permissions'); $td2 = Widget::TableData(Widget::Input('global-add', '1', 'checkbox'), 'add'); $td3 = Widget::TableData(NULL, 'edit'); $td3->appendChild(new XMLElement('p', NULL, array('class' => 'global-slider'))); $td3->appendChild(new XMLElement('span', 'n/a')); $td4 = Widget::TableData(NULL, 'delete'); $td4->appendChild(new XMLElement('p', NULL, array('class' => 'global-slider'))); $td4->appendChild(new XMLElement('span', 'n/a')); ## Add a row to the body array, assigning each cell to the row $aTableBody[] = Widget::TableRow(array($td1, $td2, $td3), 'global'); //, $td4 if (is_array($events) && !empty($events)) { foreach ($events as $event_handle => $event) { $permissions = $fields['permissions'][$event_handle]; ## Setup each cell $td1 = Widget::TableData($event['name']); $td2 = Widget::TableData(Widget::Input("fields[permissions][{$event_handle}][create]", '1', 'checkbox', $permissions['create'] == 1 ? array('checked' => 'checked') : NULL), 'add'); $td3 = Widget::TableData(NULL, 'edit'); $td3->appendChild(new XMLElement('p', NULL, array('class' => 'slider'))); $span = new XMLElement('span'); $span->setSelfClosingTag(false); $td3->appendChild($span); $td3->appendChild(Widget::Input('fields[permissions][' . $event_handle . '][edit]', isset($permissions['edit']) ? $permissions['edit'] : '0', 'hidden')); $td4 = Widget::TableData(NULL, 'delete'); $td4->appendChild(new XMLElement('p', NULL, array('class' => 'slider'))); $span = new XMLElement('span'); $span->setSelfClosingTag(false); $td4->appendChild($span); $td4->appendChild(Widget::Input('fields[permissions][' . $event_handle . '][delete]', isset($permissions['delete']) ? $permissions['delete'] : '0', 'hidden')); /* <tr> <td>{EVENT-NAME}</td> <td class="add"> <input type="checkbox" name="{ANY NAME}" value="{EXISTING STATE:No}"/> </td> <td class="edit"> <p class="slider"></p> <span></span> <input type="hidden" name="{ANY NAME}" value="{EXISTING-VALUE:1}"/> </td> <!--<td class="delete"> <p class="slider"></p> <span></span> <input type="hidden" name="{ANY NAME}" value="{EXISTING-VALUE:1}"/> </td>--> </tr> */ ## Add a row to the body array, assigning each cell to the row $aTableBody[] = Widget::TableRow(array($td1, $td2, $td3)); //, $td4)); } } $table = Widget::Table(Widget::TableHead($aTableHead), NULL, Widget::TableBody($aTableBody), 'role-permissions'); $fieldset->appendChild($table); $this->Form->appendChild($fieldset); #### # Delegate: MemberRolePermissionFieldsetsEdit # Description: Add custom fieldsets to the role page Administration::instance()->ExtensionManager->notifyMembers('MemberRolePermissionFieldsetsEdit', '/extension/members/roles_edit/', array('form' => &$this->Form, 'permissions' => $fields['permissions'])); ##### $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings type-file'); $fieldset->appendChild(new XMLElement('legend', 'Page Level Permissions')); $pages = ASDCLoader::instance()->query(sprintf("SELECT * FROM `tbl_pages` %s ORDER BY `title` ASC", $this->_context[0] == 'edit' ? "WHERE `id` != '{$page_id}' " : NULL)); $label = Widget::Label('Deny Access'); $options = array(); if ($pages->length() > 0) { foreach ($pages as $page) { $options[] = array($page->id, in_array($page->id, $fields['page_access']), '/' . Administration::instance()->resolvePagePath($page->id)); } } $label->appendChild(Widget::Select('fields[page_access][]', $options, array('multiple' => 'multiple'))); $fieldset->appendChild($label); $this->Form->appendChild($fieldset); $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', 'Save Changes', 'submit', array('accesskey' => 's'))); $this->Form->appendChild($div); }
public function __actionIndex() { if (@isset($_POST['action']['save'])) { // extract the settings $settings = @$_POST['settings']; // extract all the pages $this->_pages = $this->__getPages(); // create an empty datasource array for each page $page_datasources = array(); foreach ($this->_pages as $page) { $page_datasources[$page['id']] = array(); } // loop through the datasources and add to each page foreach ($settings as $datasource => $pages) { foreach ($pages as $page) { $page_datasources[$page][] = $datasource; } } // loop through the final datasources and add to the database $error = false; foreach ($page_datasources as $page => $datasources) { // create the fields to be updated $fields = array('data_sources' => @implode(',', $datasources)); // update the fields if (!Symphony::Database()->update($fields, 'tbl_pages', "`id` = '{$page}'")) { $error = true; break; } } // show the success message if (!$error) { $this->pageAlert(__('Datasources updated at %1$s.', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__))), Alert::SUCCESS); return; } // show the error message $this->pageAlert(__('Unknown errors occurred while attempting to save. Please check your <a href="%s">activity log</a>.', array(URL . '/symphony/system/log/')), Alert::ERROR); } }
public function __viewEdit() { $this->setPageType('form'); $fields = array("title" => null, "handle" => null, "parent" => null, "params" => null, "type" => null, "data_sources" => null); $existing = $fields; $nesting = Symphony::Configuration()->get('pages_table_nest_children', 'symphony') == 'yes'; // Verify page exists: if ($this->_context[0] == 'edit') { if (!($page_id = (int) $this->_context[1])) { redirect(SYMPHONY_URL . '/blueprints/pages/'); } $existing = PageManager::fetchPageByID($page_id); if (!$existing) { Administration::instance()->errorPageNotFound(); } else { $existing['type'] = PageManager::fetchPageTypes($page_id); } } // Status message: if (isset($this->_context[2])) { $flag = $this->_context[2]; $link_suffix = ''; if (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) { $link_suffix = "?parent=" . $_REQUEST['parent']; } else { if ($nesting == true && isset($existing) && !is_null($existing['parent'])) { $link_suffix = '?parent=' . $existing['parent']; } } switch ($flag) { case 'saved': $this->pageAlert(__('Page updated at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/blueprints/pages/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/blueprints/pages/" accesskey="a">' . __('View all Pages') . '</a>', Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Page created at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/blueprints/pages/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/blueprints/pages/" accesskey="a">' . __('View all Pages') . '</a>', Alert::SUCCESS); } } // Find values: if (isset($_POST['fields'])) { $fields = $_POST['fields']; } elseif ($this->_context[0] == 'edit') { $fields = $existing; if (!is_null($fields['type'])) { $fields['type'] = implode(', ', $fields['type']); } $fields['data_sources'] = preg_split('/,/i', $fields['data_sources'], -1, PREG_SPLIT_NO_EMPTY); $fields['events'] = preg_split('/,/i', $fields['events'], -1, PREG_SPLIT_NO_EMPTY); } elseif (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) { $fields['parent'] = $_REQUEST['parent']; } $title = $fields['title']; if (trim($title) == '') { $title = $existing['title']; } $this->setTitle(__($title ? '%1$s – %2$s – %3$s' : '%2$s – %3$s', array($title, __('Pages'), __('Symphony')))); $page_id = isset($page_id) ? $page_id : null; if (!empty($title)) { $template_name = $fields['handle']; $page_url = URL . '/' . PageManager::resolvePagePath($page_id) . '/'; if ($existing['parent']) { $parents = PageManager::resolvePagePath($existing['parent']); $template_name = PageManager::createFilePath($parents, $fields['handle']); } $this->appendSubheading($title, array(Widget::Anchor(__('View Page'), $page_url, __('View Page on Frontend'), 'button', NULL, array('target' => '_blank', 'accesskey' => 'v')), Widget::Anchor(__('Edit Page Template'), SYMPHONY_URL . '/blueprints/pages/template/' . $template_name, __('Edit Page Template'), 'button', NULL, array('accesskey' => 't')))); } else { $this->appendSubheading(!empty($title) ? $title : __('Untitled')); } if (isset($page_id)) { $this->insertBreadcrumbsUsingPageIdentifier($page_id, false); } else { $_GET['parent'] = isset($_GET['parent']) ? $_GET['parent'] : null; $this->insertBreadcrumbsUsingPageIdentifier((int) $_GET['parent'], true); } // Title -------------------------------------------------------------- $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Page Settings'))); $label = Widget::Label(__('Title')); $label->appendChild(Widget::Input('fields[title]', General::sanitize($fields['title']))); if (isset($this->_errors['title'])) { $label = Widget::Error($label, $this->_errors['title']); } $fieldset->appendChild($label); // Handle ------------------------------------------------------------- $group = new XMLElement('div'); $group->setAttribute('class', 'two columns'); $column = new XMLElement('div'); $column->setAttribute('class', 'column'); $label = Widget::Label(__('URL Handle')); $label->appendChild(Widget::Input('fields[handle]', $fields['handle'])); if (isset($this->_errors['handle'])) { $label = Widget::Error($label, $this->_errors['handle']); } $column->appendChild($label); // Parent --------------------------------------------------------- $label = Widget::Label(__('Parent Page')); $where = array(sprintf('id != %d', $page_id)); $pages = PageManager::fetch(false, array('id'), $where, 'title ASC'); $options = array(array('', false, '/')); if (!empty($pages)) { if (!function_exists('__compare_pages')) { function __compare_pages($a, $b) { return strnatcasecmp($a[2], $b[2]); } } foreach ($pages as $page) { $options[] = array($page['id'], $fields['parent'] == $page['id'], '/' . PageManager::resolvePagePath($page['id'])); } usort($options, '__compare_pages'); } $label->appendChild(Widget::Select('fields[parent]', $options)); $column->appendChild($label); $group->appendChild($column); // Parameters --------------------------------------------------------- $column = new XMLElement('div'); $column->setAttribute('class', 'column'); $label = Widget::Label(__('URL Parameters')); $label->appendChild(Widget::Input('fields[params]', $fields['params'], 'text', array('placeholder' => 'param1/param2'))); $column->appendChild($label); // Type ----------------------------------------------------------- $label = Widget::Label(__('Page Type')); $label->appendChild(Widget::Input('fields[type]', $fields['type'])); if (isset($this->_errors['type'])) { $label = Widget::Error($label, $this->_errors['type']); } $column->appendChild($label); $tags = new XMLElement('ul'); $tags->setAttribute('class', 'tags'); $types = PageManager::fetchAvailablePageTypes(); foreach ($types as $type) { $tags->appendChild(new XMLElement('li', $type)); } $column->appendChild($tags); $group->appendChild($column); $fieldset->appendChild($group); $this->Form->appendChild($fieldset); // Events ------------------------------------------------------------- $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Page Resources'))); $group = new XMLElement('div'); $group->setAttribute('class', 'two columns'); $label = Widget::Label(__('Events')); $label->setAttribute('class', 'column'); $events = ResourceManager::fetch(RESOURCE_TYPE_EVENT, array(), array(), 'name ASC'); $options = array(); if (is_array($events) && !empty($events)) { if (!isset($fields['events'])) { $fields['events'] = array(); } foreach ($events as $name => $about) { $options[] = array($name, in_array($name, $fields['events']), $about['name']); } } $label->appendChild(Widget::Select('fields[events][]', $options, array('multiple' => 'multiple'))); $group->appendChild($label); // Data Sources ------------------------------------------------------- $label = Widget::Label(__('Data Sources')); $label->setAttribute('class', 'column'); $datasources = ResourceManager::fetch(RESOURCE_TYPE_DS, array(), array(), 'name ASC'); $options = array(); if (is_array($datasources) && !empty($datasources)) { if (!isset($fields['data_sources'])) { $fields['data_sources'] = array(); } foreach ($datasources as $name => $about) { $options[] = array($name, in_array($name, $fields['data_sources']), $about['name']); } } $label->appendChild(Widget::Select('fields[data_sources][]', $options, array('multiple' => 'multiple'))); $group->appendChild($label); $fieldset->appendChild($group); $this->Form->appendChild($fieldset); // Controls ----------------------------------------------------------- /** * After all Page related Fields have been added to the DOM, just before the * actions. * * @delegate AppendPageContent * @param string $context * '/blueprints/pages/' * @param XMLElement $form * @param array $fields * @param array $errors */ Symphony::ExtensionManager()->notifyMembers('AppendPageContent', '/blueprints/pages/', array('form' => &$this->Form, 'fields' => &$fields, 'errors' => $this->_errors)); $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : __('Create Page'), 'submit', array('accesskey' => 's'))); if ($this->_context[0] == 'edit') { $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this page'), 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this page?'))); $div->appendChild($button); } $this->Form->appendChild($div); if (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) { $this->Form->appendChild(new XMLElement('input', NULL, array('type' => 'hidden', 'name' => 'parent', 'value' => $_REQUEST['parent']))); } }
public function __form() { $this->setPageType('form'); $this->_existing_file = isset($this->_context[1]) ? $this->_context[1] . '.xsl' : NULL; $this->Form->setAttribute('class', 'columns'); $filename = $this->_existing_file; // Handle unknown context if (!in_array($this->_context[0], array('new', 'edit'))) { Administration::instance()->errorPageNotFound(); } // Edit Utility context if ($this->_context[0] == 'edit') { $file_abs = UTILITIES . '/' . $this->_existing_file; if (!is_file($file_abs)) { redirect(SYMPHONY_URL . '/blueprints/utilities/new/'); } $fields['name'] = $filename; $fields['body'] = @file_get_contents($file_abs); $this->Form->setAttribute('action', SYMPHONY_URL . '/blueprints/utilities/edit/' . $this->_context[1] . '/'); } else { $fields['body'] = file_get_contents(PageManager::getTemplate('blueprints.utility')); } $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 if (isset($this->_context[2])) { switch ($this->_context[2]) { case 'saved': $this->pageAlert(__('Utility updated at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/blueprints/utilities/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/blueprints/utilities/" accesskey="a">' . __('View all Utilities') . '</a>', Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Utility created at %s.', array(DateTimeObj::getTimeAgo())) . ' <a href="' . SYMPHONY_URL . '/blueprints/utilities/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/blueprints/utilities/" accesskey="a">' . __('View all Utilities') . '</a>', Alert::SUCCESS); break; } } $this->setTitle(__($this->_context[0] == 'new' ? '%2$s – %3$s' : '%1$s – %2$s – %3$s', array($filename, __('Utilities'), __('Symphony')))); $this->appendSubheading($this->_context[0] == 'new' ? __('Untitled') : $filename); $this->insertBreadcrumbs(array(Widget::Anchor(__('Utilities'), SYMPHONY_URL . '/blueprints/utilities/'))); if (!empty($_POST)) { $fields = $_POST['fields']; } $fields['body'] = htmlentities($fields['body'], ENT_COMPAT, 'UTF-8'); $fields['name'] = isset($fields['name']) ? $fields['name'] : null; $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'primary column'); $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(__('Body')); $label->appendChild(Widget::Textarea('fields[body]', 30, 80, $fields['body'], array('class' => 'code'))); $fieldset->appendChild(isset($this->_errors['body']) ? Widget::Error($label, $this->_errors['body']) : $label); $this->Form->appendChild($fieldset); $utilities = General::listStructure(UTILITIES, array('xsl'), false, 'asc', UTILITIES); $utilities = $utilities['filelist']; if (is_array($utilities) && !empty($utilities)) { $this->Form->setAttribute('class', 'two columns'); $div = new XMLElement('div'); $div->setAttribute('class', 'secondary column'); $p = new XMLElement('p', __('Utilities')); $p->setAttribute('class', 'label'); $div->appendChild($p); $frame = new XMLElement('div', null, array('class' => 'frame')); $ul = new XMLElement('ul'); $ul->setAttribute('id', 'utilities'); foreach ($utilities as $util) { $li = new XMLElement('li'); $li->appendChild(Widget::Anchor($util, SYMPHONY_URL . '/blueprints/utilities/edit/' . str_replace('.xsl', '', $util) . '/', NULL)); $ul->appendChild($li); } $frame->appendChild($ul); $div->appendChild($frame); $this->Form->appendChild($div); } $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : __('Create Utility'), 'submit', array('accesskey' => 's'))); if ($this->_context[0] == 'edit') { $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this utility'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this Utility?'))); $div->appendChild($button); } $this->Form->appendChild($div); }
private function __form() { $layout = new Layout(); $left = $layout->createColumn(Layout::SMALL); $center = $layout->createColumn(Layout::LARGE); $right = $layout->createColumn(Layout::SMALL); require_once LIB . '/class.field.php'; ## Handle unknow context if (!in_array($this->_context[0], array('new', 'edit'))) { throw new AdministrationPageNotFoundException(); } $callback = Administration::instance()->getPageCallback(); if (isset($callback['flag'])) { switch ($callback['flag']) { case 'saved': $this->alerts()->append(__('User updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), ADMIN_URL . '/system/users/new/', ADMIN_URL . '/system/users/')), AlertStack::SUCCESS); break; case 'created': $this->alerts()->append(__('User created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), ADMIN_URL . '/system/users/new/', ADMIN_URL . '/system/users/')), AlertStack::SUCCESS); break; } } $isOwner = false; /*if(isset($_POST['fields'])) $user = $this->user; elseif($this->_context[0] == 'edit'){ if(!$user_id = $this->_context[1]) redirect(ADMIN_URL . '/system/users/'); if(!$user = UserManager::fetchByID($user_id)){ throw new SymphonyErrorPage('The user profile you requested does not exist.', 'User not found'); } } else */ if ($this->_context[0] == 'edit' && $this->user->id == Administration::instance()->User->id) { $isOwner = true; } $this->setTitle(__($this->_context[0] == 'new' ? '%1$s – %2$s – Untitled' : '%1$s – %2$s – %3$s', array(__('Symphony'), __('Users'), $this->user->getFullName()))); $this->appendSubheading($this->_context[0] == 'new' ? __('New User') : $this->user->getFullName()); ### Essentials ### $fieldset = Widget::Fieldset(__('Essentials')); $label = Widget::Label(__('First Name')); $label->appendChild(Widget::Input('fields[first_name]', $this->user->{'first_name'})); $fieldset->appendChild(isset($this->errors->{'first-name'}) ? Widget::wrapFormElementWithError($label, $this->errors->{'first-name'}) : $label); $label = Widget::Label(__('Last Name')); $label->appendChild(Widget::Input('fields[last_name]', $this->user->{'last_name'})); $fieldset->appendChild(isset($this->errors->{'last-name'}) ? Widget::wrapFormElementWithError($label, $this->errors->{'last-name'}) : $label); $label = Widget::Label(__('Email Address')); $label->appendChild(Widget::Input('fields[email]', $this->user->email)); $fieldset->appendChild(isset($this->errors->email) ? Widget::wrapFormElementWithError($label, $this->errors->email) : $label); $left->appendChild($fieldset); ### ### Login Details ### $fieldset = Widget::Fieldset(__('Login Details')); $label = Widget::Label(__('Username')); $label->appendChild(Widget::Input('fields[username]', $this->user->username, NULL)); $fieldset->appendChild(isset($this->errors->username) ? Widget::wrapFormElementWithError($label, $this->errors->username) : $label); if ($this->_context[0] == 'edit') { $fieldset->setAttribute('id', 'change-password'); } $label = Widget::Label($this->_context[0] == 'edit' ? __('New Password') : __('Password')); $label->appendChild(Widget::Input('fields[password]', NULL, 'password')); $fieldset->appendChild(isset($this->errors->password) ? Widget::wrapFormElementWithError($label, $this->errors->password) : $label); $label = Widget::Label($this->_context[0] == 'edit' ? __('Confirm New Password') : __('Confirm Password')); if (isset($this->errors->{'password-confirmation'})) { $label->setAttributeArray(array('class' => 'contains-error', 'title' => $this->errors->{'password-confirmation'})); } $label->appendChild(Widget::Input('fields[password-confirmation]', NULL, 'password')); $fieldset->appendChild($label); if ($this->_context[0] == 'edit') { $fieldset->appendChild($this->createElement('p', __('Leave password fields blank to keep the current password'), array('class' => 'help'))); } $label = Widget::Label(); $input = Widget::Input('fields[auth_token_active]', 'yes', 'checkbox'); if ($this->user->auth_token_active == 'yes') { $input->setAttribute('checked', 'checked'); } $temp = ADMIN_URL . '/login/' . $this->user->createAuthToken() . '/'; $label->appendChild($input); $label->appendChild(new DOMText(__('Allow remote login via '))); $label->appendChild(Widget::Anchor($temp, $temp)); $fieldset->appendChild($label); $center->appendChild($fieldset); ### Default Section ### $fieldset = Widget::Fieldset(__('Custom Preferences')); $label = Widget::Label(__('Default Section')); //$sections = SectionManager::instance()->fetch(NULL, 'ASC', 'sortorder'); $options = array(); //if(is_array($sections) && !empty($sections)) foreach (new SectionIterator() as $s) { $options[] = array($s->handle, $this->user->default_section == $s->handle, $s->name); } $label->appendChild(Widget::Select('fields[default_section]', $options)); $fieldset->appendChild($label); ### Custom Language Selection ### $languages = Lang::getAvailableLanguages(true); if (count($languages > 1)) { // Get language names asort($languages); $label = Widget::Label(__('Language')); $options = array(array(NULL, is_null($this->user->language), __('System Default'))); foreach ($languages as $code => $name) { $options[] = array($code, $code == $this->user->language, $name); } $select = Widget::Select('fields[language]', $options); $label->appendChild($select); $fieldset->appendChild($label); $right->appendChild($fieldset); $layout->appendTo($this->Form); } ### $div = $this->createElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Submit('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : __('Create User'), array('accesskey' => 's'))); if ($this->_context[0] == 'edit' && !$isOwner) { $div->appendChild(Widget::Submit('action[delete]', __('Delete'), array('class' => 'confirm delete', 'title' => __('Delete this user')))); } $this->Form->appendChild($div); }
public function view() { if (!($email_template_id = $this->_context[0])) { redirect(extension_members::baseURL()); } if (!($existing = EmailTemplate::loadFromID($email_template_id))) { throw new SymphonyErrorPage(__('The email template you requested to edit does not exist.'), __('Email Template not found'), 'error'); } if (isset($this->_context[1])) { switch ($this->_context[1]) { case 'saved': $this->pageAlert(__('Email Template updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Email Template</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), extension_members::baseURL() . 'email_templates_new/', extension_members::baseURL() . 'email_templates/')), Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Email Template created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Email Template</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), extension_members::baseURL() . 'email_templates_new/', extension_members::baseURL() . 'email_templates/')), Alert::SUCCESS); break; } } Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/members/assets/styles.css', 'screen', 9125341); $formHasErrors = 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>'), AdministrationPage::PAGE_ALERT_ERROR); } $this->setPageType('form'); $this->setTitle('Symphony – Member Roles – ' . $existing->subject); $this->appendSubheading($existing->subject); $fields = array(); if (isset($_POST['fields'])) { $fields = $_POST['fields']; } else { $fields['subject'] = $existing->subject; $fields['body'] = $existing->body; $fields['type'] = $existing->type; $fields['roles'] = NULL; foreach ($existing->roles() as $role_id => $r) { $fields['roles'] .= $r->name() . ", "; } $fields['roles'] = trim($fields['roles'], ', '); } $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'primary'); $label = Widget::Label('Subject'); $label->appendChild(Widget::Input('fields[subject]', General::sanitize($fields['subject']))); if (isset($this->_errors['subject'])) { $fieldset->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['subject'])); } else { $fieldset->appendChild($label); } $label = Widget::Label('Body'); $label->appendChild(Widget::Textarea('fields[body]', 15, 75, General::sanitize($fields['body']))); if (isset($this->_errors['body'])) { $fieldset->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['body'])); } else { $fieldset->appendChild($label); } $fieldset->appendChild(new XMLElement('p', 'Dynamic fields and parameters can be included in the subject or body of the email using the <code>{$param}</code> syntax. Please see the <a href="http://github.com/symphony/members/blob/master/README.markdown">readme</a> for a complete list of available parameters.', array('class' => 'help'))); $this->Form->appendChild($fieldset); $sidebar = new XMLElement('fieldset'); $sidebar->setAttribute('class', 'secondary'); $label = Widget::Label('Type'); $options = array(array(NULL, false, NULL), array('reset-password', $fields['type'] == 'reset-password', 'Reset Password'), array('new-password', $fields['type'] == 'new-password', 'New Password'), array('activate-account', $fields['type'] == 'activate-account', 'Activate Account'), array('welcome', $fields['type'] == 'welcome', 'Welcome Email')); $label->appendChild(Widget::Select('fields[type]', $options)); if (isset($this->_errors['type'])) { $sidebar->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['type'])); } else { $sidebar->appendChild($label); } $label = Widget::Label('Roles'); $label->appendChild(Widget::Input('fields[roles]', $fields['roles'])); if (isset($this->_errors['roles'])) { $sidebar->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['roles'])); } else { $sidebar->appendChild($label); } $roles = DatabaseUtilities::resultColumn(ASDCLoader::instance()->query("SELECT `name` FROM `tbl_members_roles` ORDER BY `name` ASC"), 'name'); if (is_array($roles) && !empty($roles)) { $taglist = new XMLElement('ul'); $taglist->setAttribute('class', 'tags'); foreach ($roles as $tag) { $taglist->appendChild(new XMLElement('li', $tag)); } $sidebar->appendChild($taglist); } $this->Form->appendChild($sidebar); $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' => 'confirm delete', 'title' => __('Delete this email template'))); $div->appendChild($button); $this->Form->appendChild($div); }
function __form() { require_once TOOLKIT . '/class.field.php'; ## Handle unknow context if (!in_array($this->_context[0], array('new', 'edit'))) { $this->_Parent->errorPageNotFound(); } if ($this->_context[0] == 'new' && !Administration::instance()->Author->isDeveloper()) { $this->_Parent->customError(E_USER_ERROR, '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 %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Authors</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . '/symphony/system/authors/new/', URL . '/symphony/system/authors/')), Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Author created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Authors</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . '/symphony/system/authors/new/', URL . '/symphony/system/authors/')), Alert::SUCCESS); break; } } $this->setPageType('form'); $isOwner = false; if (isset($_POST['fields'])) { $author = $this->_Author; } elseif ($this->_context[0] == 'edit') { if (!($author_id = $this->_context[1])) { redirect(URL . '/symphony/system/authors/'); } if (!($author = AuthorManager::fetchByID($author_id))) { $this->_Parent->customError(E_USER_ERROR, '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()) { $this->_Parent->customError(E_USER_ERROR, 'Access Denied', 'You are not authorised to edit other authors.'); } $this->setTitle(__($this->_context[0] == 'new' ? '%1$s – %2$s – %3$s' : '%1$s – %2$s', array(__('Symphony'), __('Authors'), $author->getFullName()))); $this->appendSubheading($this->_context[0] == 'new' ? __('Untitled') : $author->getFullName()); ### Essentials ### $group = new XMLElement('fieldset'); $group->setAttribute('class', 'settings'); $group->appendChild(new XMLElement('legend', __('Essentials'))); $div = new XMLElement('div'); $div->setAttribute('class', 'group'); $label = Widget::Label(__('First Name')); $label->appendChild(Widget::Input('fields[first_name]', $author->get('first_name'))); $div->appendChild(isset($this->_errors['first_name']) ? $this->wrapFormElementWithError($label, $this->_errors['first_name']) : $label); $label = Widget::Label(__('Last Name')); $label->appendChild(Widget::Input('fields[last_name]', $author->get('last_name'))); $div->appendChild(isset($this->_errors['last_name']) ? $this->wrapFormElementWithError($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']) ? $this->wrapFormElementWithError($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'); $div->setAttribute('class', 'group'); $label = Widget::Label(__('Username')); $label->appendChild(Widget::Input('fields[username]', $author->get('username'), NULL)); $div->appendChild(isset($this->_errors['username']) ? $this->wrapFormElementWithError($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()) { $label = Widget::Label(__('User Type')); $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); $div = new XMLElement('div', NULL, array('class' => 'group')); if ($this->_context[0] == 'edit') { $div->setAttribute('id', 'change-password'); if (!Administration::instance()->Author->isDeveloper() || $isOwner === true) { $div->setAttribute('class', 'triple group'); $label = Widget::Label(__('Old Password')); if (isset($this->_errors['old-password'])) { $label->setAttributeArray(array('class' => 'contains-error', 'title' => $this->_errors['old-password'])); } $label->appendChild(Widget::Input('fields[old-password]', NULL, 'password')); $div->appendChild(isset($this->_errors['old-password']) ? $this->wrapFormElementWithError($label, $this->_errors['old-password']) : $label); } } $label = Widget::Label($this->_context[0] == 'edit' ? __('New Password') : __('Password')); $label->appendChild(Widget::Input('fields[password]', NULL, 'password')); $div->appendChild(isset($this->_errors['password']) ? $this->wrapFormElementWithError($label, $this->_errors['password']) : $label); $label = Widget::Label($this->_context[0] == 'edit' ? __('Confirm New Password') : __('Confirm Password')); if (isset($this->_errors['password-confirmation'])) { $label->setAttributeArray(array('class' => 'contains-error', 'title' => $this->_errors['password-confirmation'])); } $label->appendChild(Widget::Input('fields[password-confirmation]', NULL, 'password')); $div->appendChild($label); $group->appendChild($div); if ($this->_context[0] == 'edit') { $group->appendChild(new XMLElement('p', __('Leave password fields blank to keep the current password'), array('class' => 'help'))); } if (Administration::instance()->Author->isDeveloper()) { $label = Widget::Label(); $input = Widget::Input('fields[auth_token_active]', 'yes', 'checkbox'); if ($author->get('auth_token_active') == 'yes') { $input->setAttribute('checked', 'checked'); } $temp = URL . '/symphony/login/' . $author->createAuthToken() . '/'; $label->setValue(__('%1$s Allow remote login via <a href="%2$s">%2$s</a>', array($input->generate(), $temp))); $group->appendChild($label); } $label = Widget::Label(__('Default Section')); $sectionManager = new SectionManager($this->_Parent); $sections = $sectionManager->fetch(NULL, 'ASC', 'sortorder'); $options = array(); if (is_array($sections) && !empty($sections)) { foreach ($sections as $s) { $options[] = array($s->get('id'), $author->get('default_section') == $s->get('id'), $s->get('name')); } } $label->appendChild(Widget::Select('fields[default_section]', $options)); $group->appendChild($label); $this->Form->appendChild($group); ### ### Custom Language Selection ### $languages = Lang::getAvailableLanguages(Administration::instance()->ExtensionManager); if (count($languages) > 1) { // Get language names asort($languages); $group = new XMLElement('fieldset'); $group->setAttribute('class', 'settings'); $group->appendChild(new XMLElement('legend', __('Custom Preferences'))); $div = new XMLElement('div'); $div->setAttribute('class', 'group'); $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' => 'confirm delete', 'title' => __('Delete this author'), 'type' => 'submit')); $div->appendChild($button); } $this->Form->appendChild($div); }
function __form($readonly = false) { $formHasErrors = 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); } if (isset($this->_context[2])) { switch ($this->_context[2]) { case 'saved': $this->pageAlert(__('Event updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Events</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . '/symphony/blueprints/events/new/', URL . '/symphony/blueprints/components/')), Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Event created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Events</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . '/symphony/blueprints/events/new/', URL . '/symphony/blueprints/components/')), Alert::SUCCESS); break; } } $isEditing = $readonly ? true : false; $fields = array(); $sectionManager = new SectionManager($this->_Parent); if ($this->_context[0] == 'edit' || $this->_context[0] == 'info') { $isEditing = true; $handle = $this->_context[1]; $EventManager = new EventManager($this->_Parent); $existing =& $EventManager->create($handle); $about = $existing->about(); $fields['name'] = $about['name']; $fields['source'] = $existing->getSource(); $fields['filters'] = $existing->eParamFILTERS; } if (isset($_POST['fields'])) { $fields = $_POST['fields']; } $this->setPageType('form'); $this->setTitle(__($isEditing ? '%1$s – %2$s – %3$s' : '%1$s – %2$s', array(__('Symphony'), __('Events'), $about['name']))); $this->appendSubheading($isEditing ? $about['name'] : __('Untitled')); if (!$readonly) { $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Essentials'))); $div = new XMLElement('div'); $div->setAttribute('class', 'group'); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[name]', General::sanitize($fields['name']))); if (isset($this->_errors['name'])) { $div->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['name'])); } else { $div->appendChild($label); } $label = Widget::Label(__('Source')); $sections = $sectionManager->fetch(NULL, 'ASC', 'name'); $options = array(); if (is_array($sections) && !empty($sections)) { foreach ($sections as $s) { $options[] = array($s->get('id'), $fields['source'] == $s->get('id'), $s->get('name')); } } $label->appendChild(Widget::Select('fields[source]', $options, array('id' => 'context'))); $div->appendChild($label); $fieldset->appendChild($div); $label = Widget::Label(__('Filter Rules')); $options = array(array('admin-only', @in_array('admin-only', $fields['filters']), __('Admin Only')), array('send-email', @in_array('send-email', $fields['filters']), __('Send Email')), array('expect-multiple', @in_array('expect-multiple', $fields['filters']), __('Allow Multiple'))); ### # Delegate: AppendEventFilter # Description: Allows adding of new filter rules to the Event filter rule select box. A reference to the $options array is provided, and selected filters $this->_Parent->ExtensionManager->notifyMembers('AppendEventFilter', '/blueprints/events/' . $this->_context[0] . '/', array('selected' => $fields['filters'], 'options' => &$options)); $label->appendChild(Widget::Select('fields[filters][]', $options, array('multiple' => 'multiple'))); $fieldset->appendChild($label); $fieldset->appendChild(new XMLElement('p', __('This event will not be processed if any of these rules return true.'), array('class' => 'help'))); $this->Form->appendChild($fieldset); } if ($isEditing) { $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $doc = $existing->documentation(); $fieldset->setValue('<legend>' . __('Description') . '</legend>' . self::CRLF . General::tabsToSpaces(is_object($doc) ? $doc->generate(true) : $doc, 2)); $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' => 'confirm delete', 'title' => __('Delete this event'), 'type' => 'submit')); $div->appendChild($button); } if (!$readonly) { $this->Form->appendChild($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); } else { if (isset($this->_context[2])) { switch ($this->_context[2]) { case 'saved': $this->pageAlert(__('Event updated at %s.', array(DateTimeObj::getTimeAgo())) . ' <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(DateTimeObj::getTimeAgo())) . ' <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; } } else { if ($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']; } else { if (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 picker'); $fieldset->appendChild(new XMLElement('legend', __('Essentials'))); $group = new XMLElement('div'); $group->setAttribute('class', 'two columns'); // Name $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); // Source $label = Widget::Label(__('Source')); $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; } $label->appendChild(Widget::Select('fields[source]', $options, array('id' => 'event-context', 'class' => 'picker'))); $div = new XMLElement('div'); $div->setAttribute('class', 'column'); if (isset($this->_errors['source'])) { $div->appendChild(Widget::Error($label, $this->_errors['source'])); } else { $div->appendChild($label); } $group->appendChild($div); $fieldset->appendChild($group); $this->Form->appendChild($fieldset); // Filters $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('id', 'sections'); $fieldset->setAttribute('class', 'settings pickable'); $fieldset->setAttribute('data-relation', 'event-context'); $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'))); $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'])); } else { if (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__))))); } else { if (!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 if ($isEditing && method_exists($existing, 'documentation')) { // Description $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $doc = $existing->documentation(); if ($doc) { $fieldset->setValue('<legend>' . __('Description') . '</legend>' . PHP_EOL . General::tabsToSpaces(is_object($doc) ? $doc->generate(true) : $doc, 2)); $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); } }
public function view() { $this->_existing_file = isset($this->_context[1]) ? $this->_context[1] . '.xsl' : NULL; ## Handle unknown context if (!in_array($this->_context[0], array('new', 'edit'))) { Administration::instance()->errorPageNotFound(); } ## Edit Utility context if ($this->_context[0] == 'edit') { $file_abs = UTILITIES . '/' . $this->_existing_file; $filename = $this->_existing_file; if (!is_file($file_abs)) { redirect(SYMPHONY_URL . '/blueprints/utilities/new/'); } $fields['name'] = $filename; $fields['body'] = @file_get_contents($file_abs); $this->Form->setAttribute('action', SYMPHONY_URL . '/blueprints/utilities/edit/' . $this->_context[1] . '/'); } else { $fields['body'] = '<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template name=""> </xsl:template> </xsl:stylesheet>'; } $formHasErrors = 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); } if (isset($this->_context[2])) { switch ($this->_context[2]) { case 'saved': $this->pageAlert(__('Utility updated at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Utilities</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), SYMPHONY_URL . '/blueprints/utilities/new/', SYMPHONY_URL . '/blueprints/components/')), Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Utility created at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Utilities</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), SYMPHONY_URL . '/blueprints/utilities/new/', SYMPHONY_URL . '/blueprints/components/')), Alert::SUCCESS); break; } } $this->setTitle(__($this->_context[0] == 'new' ? '%1$s – %2$s' : '%1$s – %2$s – %3$s', array(__('Symphony'), __('Utilities'), $filename))); $this->appendSubheading($this->_context[0] == 'new' ? __('Untitled') : $filename); if (!empty($_POST)) { $fields = $_POST['fields']; } $fields['body'] = General::sanitize($fields['body']); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'primary'); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[name]', $fields['name'])); $fieldset->appendChild(isset($this->_errors['name']) ? Widget::wrapFormElementWithError($label, $this->_errors['name']) : $label); $label = Widget::Label(__('Body')); $label->appendChild(Widget::Textarea('fields[body]', 30, 80, $fields['body'], array('class' => 'code'))); $fieldset->appendChild(isset($this->_errors['body']) ? Widget::wrapFormElementWithError($label, $this->_errors['body']) : $label); $this->Form->appendChild($fieldset); $utilities = General::listStructure(UTILITIES, array('xsl'), false, 'asc', UTILITIES); $utilities = $utilities['filelist']; if (is_array($utilities) && !empty($utilities)) { $div = new XMLElement('div'); $div->setAttribute('class', 'secondary'); $p = new XMLElement('p', __('Utilities')); $p->setAttribute('class', 'label'); $div->appendChild($p); $ul = new XMLElement('ul'); $ul->setAttribute('id', 'utilities'); $i = 0; foreach ($utilities as $util) { $li = new XMLElement('li'); if ($i++ % 2 != 1) { $li->setAttribute('class', 'odd'); } $li->appendChild(Widget::Anchor($util, SYMPHONY_URL . '/blueprints/utilities/edit/' . str_replace('.xsl', '', $util) . '/', NULL)); $ul->appendChild($li); } $div->appendChild($ul); $this->Form->appendChild($div); } $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : __('Create Utility'), 'submit', array('accesskey' => 's'))); if ($this->_context[0] == 'edit') { $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this utility'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this Utility?'))); $div->appendChild($button); } $this->Form->appendChild($div); }
private function __form(Section $existing = null) { // Status message: $callback = Administration::instance()->getPageCallback(); if (isset($callback['flag']) && !is_null($callback['flag'])) { switch ($callback['flag']) { case 'saved': $this->alerts()->append(__('Section updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), ADMIN_URL . '/blueprints/sections/new/', ADMIN_URL . '/blueprints/sections/')), AlertStack::SUCCESS); break; case 'created': $this->alerts()->append(__('Section created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), ADMIN_URL . '/blueprints/sections/new/', ADMIN_URL . '/blueprints/sections/')), AlertStack::SUCCESS); break; } } if (!$this->alerts()->valid() and $existing instanceof Section) { $this->appendSyncAlert(); } $layout = new Layout(); $left = $layout->createColumn(Layout::SMALL); $right = $layout->createColumn(Layout::LARGE); $this->setTitle(__('%1$s – %2$s', array(__('Symphony'), __('Sections')))); $this->appendSubheading($existing instanceof Section ? $existing->name : __('New Section')); if ($existing instanceof Section) { $this->appendViewOptions(); } // Essentials: $fieldset = $this->createElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild($this->createElement('h3', __('Essentials'))); $label = Widget::Label('Name'); $label->appendChild(Widget::Input('essentials[name]', $this->section->name)); $fieldset->appendChild(isset($this->errors->name) ? Widget::wrapFormElementWithError($label, $this->errors->name) : $label); $label = Widget::Label(__('Navigation Group')); $label->appendChild($this->createElement('em', __('Created if does not exist'))); $label->appendChild(Widget::Input('essentials[navigation-group]', $this->section->{"navigation-group"})); $fieldset->appendChild(isset($this->errors->{'navigation-group'}) ? Widget::wrapFormElementWithError($label, $this->errors->{'navigation-group'}) : $label); $navigation_groups = Section::fetchUsedNavigationGroups(); if (is_array($navigation_groups) && !empty($navigation_groups)) { $ul = $this->createElement('ul', NULL, array('class' => 'tags singular')); foreach ($navigation_groups as $g) { $ul->appendChild($this->createElement('li', $g)); } $fieldset->appendChild($ul); } $input = Widget::Input('essentials[hidden-from-publish-menu]', 'yes', 'checkbox', $this->section->{'hidden-from-publish-menu'} == 'yes' ? array('checked' => 'checked') : array()); $label = Widget::Label(__('Hide this section from the Publish menu')); $label->prependChild($input); $fieldset->appendChild($label); $left->appendChild($fieldset); // Fields $fieldset = $this->createElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild($this->createElement('h3', __('Fields'))); $div = $this->createElement('div'); $h3 = $this->createElement('h3', __('Fields')); $h3->setAttribute('class', 'label'); $div->appendChild($h3); $duplicator = new Duplicator(__('Add Field')); $duplicator->setAttribute('id', 'section-duplicator'); $fields = $this->section->fields; $types = array(); foreach (new FieldIterator() as $pathname) { $type = preg_replace(array('/^field\\./', '/\\.php$/'), NULL, basename($pathname)); $types[$type] = Field::load($pathname); } // To Do: Sort this list based on how many times a field has been used across the system uasort($types, create_function('$a, $b', 'return strnatcasecmp($a->name(), $b->name());')); if (is_array($types)) { foreach ($types as $type => $field) { $defaults = array(); $field->findDefaultSettings($defaults); $field->section = $this->section->handle; foreach ($defaults as $key => $value) { $field->{$key} = $value; } $item = $duplicator->createTemplate($field->name()); $field->displaySettingsPanel($item, new MessageStack()); } } if (is_array($fields)) { foreach ($fields as $position => $field) { $field->sortorder = $position; if ($this->errors->{"field::{$position}"}) { $messages = $this->errors->{"field::{$position}"}; } else { $messages = new MessageStack(); } $item = $duplicator->createInstance($field->name, $field->name()); $field->displaySettingsPanel($item, $messages); } } $duplicator->appendTo($fieldset); $right->appendChild($fieldset); $layout->appendTo($this->Form); $div = $this->createElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Submit('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : 'Create Section', array('accesskey' => 's'))); if ($this->_context[0] == 'edit') { $div->appendChild(Widget::Submit('action[delete]', __('Delete'), array('class' => 'confirm delete', 'title' => __('Delete this section')))); } $this->Form->appendChild($div); }
public function __form(Entry $existing = NULL) { $callback = Administration::instance()->getPageCallback(); $section = Section::load(sprintf('%s/%s.xml', SECTIONS, $callback['context']['section_handle'])); // Check that a layout and fields exist if (isset($section->fields)) { $this->alerts()->append(__('It looks like you\'re trying to create an entry. Perhaps you want fields first? <a href="%s">Click here to create some.</a>', array(ADMIN_URL . '/blueprints/sections/edit/' . $section->handle . '/')), AlertStack::ERROR); } $this->Form->setAttribute('enctype', 'multipart/form-data'); $this->setTitle(__('%1$s – %2$s', array(__('Symphony'), $section->name))); $subheading = __('New Entry'); if (!is_null($existing) && $existing instanceof Entry) { if (is_null($this->entry) || !$this->entry instanceof Entry) { $this->entry = $existing; } // Grab the first field in the section $first_field = $section->fields[0]; $field_data = (object) array(); if (!is_null($existing->data()->{$first_field->{'element-name'}})) { $field_data = $existing->data()->{$first_field->{'element-name'}}; } $subheading = $first_field->prepareTableValue($field_data); } if (is_null($this->entry) || !$this->entry instanceof Entry) { $this->entry = new Entry(); } $this->entry->section = $callback['context']['section_handle']; $this->appendSubheading($subheading); $this->entry->findDefaultFieldData(); $this->Form->appendChild(Widget::Input('MAX_FILE_SIZE', Symphony::Configuration()->core()->symphony->{'maximum-upload-size'}, 'hidden')); // Check if there is a field to prepopulate if (isset($_REQUEST['prepopulate']) && strlen(trim($_REQUEST['prepopulate'])) > 0) { $field_handle = key($_REQUEST['prepopulate']); $value = stripslashes(rawurldecode($_REQUEST['prepopulate'][$field_handle])); $prepopulate_filter = "?prepopulate[{$field_handle}]=" . rawurlencode($value); $this->Form->setAttribute('action', Administration::instance()->getCurrentPageURL() . $prepopulate_filter); if (is_null($existing)) { $this->entry->data()->{$field_handle}->value = $value; } } // Status message: if (isset($callback['flag']) and !is_null($callback['flag'])) { switch ($callback['flag']) { case 'saved': $this->alerts()->append(__('Entry updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Entries</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), ADMIN_URL . '/publish/' . $callback['context']['section_handle'] . '/new/' . $prepopulate_filter, ADMIN_URL . '/publish/' . $callback['context']['section_handle'] . '/')), AlertStack::SUCCESS); break; case 'created': $this->alerts()->append(__('Entry created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Entries</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), ADMIN_URL . '/publish/' . $callback['context']['section_handle'] . '/new/' . $prepopulate_filter, ADMIN_URL . '/publish/' . $callback['context']['section_handle'] . '/')), AlertStack::SUCCESS); break; } } // Load all the fields for this section $section_fields = array(); foreach ($section->fields as $index => $field) { $section_fields[$field->{'element-name'}] = $field; } $layout = new Layout(); if (is_array($section->layout) && !empty($section->layout)) { foreach ($section->layout as $data) { $column = $layout->createColumn($data->size); foreach ($data->fieldsets as $data) { $fieldset = $this->createElement('fieldset'); if (isset($data->collapsed) && $data->collapsed == 'yes') { $fieldset->setAttribute('class', 'collapsed'); } if (isset($data->name) && strlen(trim($data->name)) > 0) { $fieldset->appendChild($this->createElement('h3', $data->name)); } foreach ($data->fields as $handle) { $field = $section_fields[$handle]; if (!$field instanceof Field) { continue; } $div = $this->createElement('div', NULL, array('class' => trim(sprintf('field field-%s %s %s', $field->handle(), $this->__calculateWidth($field->width), $field->required == 'yes' ? 'required' : '')))); $field->displayPublishPanel($div, isset($this->errors->{$field->{'element-name'}}) ? $this->errors->{$field->{'element-name'}} : new MessageStack(), $this->entry, $this->entry->data()->{$field->{'element-name'}}); $fieldset->appendChild($div); } $column->appendChild($fieldset); } $layout->appendTo($this->Form); } } else { $this->alerts()->append(__('You haven\'t set any section layout rules. <a href="%s">Click here to define a layout.</a>', array(ADMIN_URL . '/blueprints/sections/layout/' . $section->handle . '/')), AlertStack::ERROR); $column = $layout->createColumn(Layout::LARGE); $fieldset = $this->createElement('fieldset'); $header = $this->createElement('h3', __('Untitled')); $fieldset->appendChild($header); if (is_array($section->fields)) { foreach ($section->fields as $field) { $div = $this->createElement('div', NULL, array('class' => trim(sprintf('field field-%s %s %s', $field->handle(), $this->__calculateWidth($field->width), $field->required == 'yes' ? 'required' : 'optional')))); $field->displayPublishPanel($div, isset($this->errors->{$field->{'element-name'}}) ? $this->errors->{$field->{'element-name'}} : new MessageStack(), $this->entry, $this->entry->data()->{$field->{'element-name'}}); $fieldset->appendChild($div); } } $column->appendChild($fieldset); $layout->appendTo($this->Form); } $div = $this->createElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Submit('action[save]', $existing ? __('Save Changes') : __('Create Entry'), array('accesskey' => 's'))); if (!is_null($existing)) { $div->appendChild(Widget::Submit('action[delete]', __('Delete'), array('class' => 'confirm delete', 'title' => __('Delete this entry')))); } $this->Form->appendChild($div); }
public function __viewExtensions() { $this->appendSubheading(__('Settings')); $this->appendTabs(); $path = ADMIN_URL . '/symphony/system/settings/'; // No settings for extensions here if (Extension::delegateSubscriptionCount('AddSettingsFieldsets', '/system/settings/extensions/') <= 0) { redirect($path); } // Status message: $callback = Administration::instance()->getPageCallback(); if (isset($callback['flag']) && !is_null($callback['flag'])) { switch ($callback['flag']) { case 'saved': $this->alerts()->append(__('System settings saved at %1$s.', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__))), AlertStack::SUCCESS); break; } } $extension_fieldsets = array(); ### # Delegate: AddSettingsFieldsets # Description: Add Extension settings fieldsets. Append fieldsets to the array provided. They will be distributed evenly accross the 3 columns Extension::notify('AddSettingsFieldsets', '/system/settings/extensions/', array('fieldsets' => &$extension_fieldsets)); if (empty($extension_fieldsets)) { redirect($path); } $layout = new Layout(); $left = $layout->createColumn(Layout::LARGE); $center = $layout->createColumn(Layout::LARGE); $right = $layout->createColumn(Layout::LARGE); foreach ($extension_fieldsets as $index => $fieldset) { $index += 1; if ($index % 3 == 0) { $right->appendChild($fieldset); } elseif ($index % 2 == 0) { $center->appendChild($fieldset); } else { $left->appendChild($fieldset); } } $layout->appendTo($this->Form); $div = $this->createElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Submit('action[save]', __('Save Changes'), array('accesskey' => 's'))); $this->Form->appendChild($div); }
function __form() { $formHasErrors = 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); } if (isset($this->_context[2])) { switch ($this->_context[2]) { case 'saved': $this->pageAlert(__('Data source updated at %1$s. <a href="%2$s">Create another?</a> <a href="%2$s">View all Data sources</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . '/symphony/blueprints/datasources/new/', URL . '/symphony/blueprints/components/')), Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Data source created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Data source</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . '/symphony/blueprints/datasources/new/', URL . '/symphony/blueprints/components/')), Alert::SUCCESS); break; } } $sectionManager = new SectionManager($this->_Parent); if (isset($_POST['fields'])) { $fields = $_POST['fields']; if (!in_array($fields['source'], array('authors', 'navigation', 'dynamic_xml', 'static_xml')) && is_array($fields['filter']) && !empty($fields['filter'])) { $filters = array(); foreach ($fields['filter'] as $f) { foreach ($f as $key => $val) { $filters[$key] = $val; } } $fields['filter'][$fields['source']] = $filters; } } elseif ($this->_context[0] == 'edit') { $isEditing = true; $handle = $this->_context[1]; $datasourceManager = new DatasourceManager($this->_Parent); $existing =& $datasourceManager->create($handle, NULL, false); if (!$existing->allowEditorToParse()) { redirect(URL . '/symphony/blueprints/datasources/info/' . $handle . '/'); } $about = $existing->about(); $fields['name'] = $about['name']; $fields['order'] = $existing->dsParamORDER; $fields['param'] = $existing->dsParamPARAMOUTPUT; $fields['required_url_param'] = $existing->dsParamREQUIREDPARAM; $fields['xml_elements'] = $existing->dsParamINCLUDEDELEMENTS; $fields['sort'] = $existing->dsParamSORT; $fields['page_number'] = $existing->dsParamSTARTPAGE; $fields['limit_type'] = $existing->dsParamLIMITTYPE; $fields['group'] = $existing->dsParamGROUP; $fields['html_encode'] = $existing->dsParamHTMLENCODE; if ($existing->dsParamREDIRECTONEMPTY == 'yes') { $fields['redirect_on_empty'] = 'yes'; } $existing->dsParamFILTERS = @array_map('stripslashes', $existing->dsParamFILTERS); $fields['source'] = $existing->getSource(); switch ($fields['source']) { case 'authors': $fields['filter']['author'] = $existing->dsParamFILTERS; $fields['max_records'] = $existing->dsParamLIMIT; break; case 'navigation': $fields['filter']['navigation'] = $existing->dsParamFILTERS; break; case 'dynamic_xml': $namespaces = $existing->dsParamFILTERS; $fields['dynamic_xml'] = array('namespace' => array()); $fields['dynamic_xml']['namespace']['name'] = @array_keys($namespaces); $fields['dynamic_xml']['namespace']['uri'] = @array_values($namespaces); $fields['dynamic_xml']['url'] = $existing->dsParamURL; $fields['dynamic_xml']['xpath'] = $existing->dsParamXPATH; $fields['dynamic_xml']['cache'] = $existing->dsParamCACHE; break; case 'static_xml': $fields['static_xml'] = trim($existing->grab()); break; default: $fields['filter'][$fields['source']] = $existing->dsParamFILTERS; $fields['max_records'] = $existing->dsParamLIMIT; break; } } else { $fields['dynamic_xml']['url'] = 'http://'; $fields['dynamic_xml']['cache'] = '30'; $fields['dynamic_xml']['xpath'] = '/'; $fields['max_records'] = '20'; $fields['page_number'] = '1'; $fields['order'] = 'desc'; $fields['limit_type'] = 'entries'; } $this->setPageType('form'); $this->setTitle(__($isEditing ? '%1$s – %2$s – %3$s' : '%1$s – %2$s', array(__('Symphony'), __('Data Sources'), $about['name']))); $this->appendSubheading($isEditing ? $about['name'] : __('Untitled')); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Essentials'))); $div = new XMLElement('div'); $div->setAttribute('class', 'group'); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[name]', General::sanitize($fields['name']))); if (isset($this->_errors['name'])) { $div->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['name'])); } else { $div->appendChild($label); } $label = Widget::Label(__('Source')); $sections = $sectionManager->fetch(NULL, 'ASC', 'name'); foreach ($sections as $section) { $field_groups[$section->get('id')] = array('fields' => $section->fetchFields(), 'section' => $section); } $options = array(array('label' => __('System'), 'options' => array(array(__('authors'), $fields['source'] == __('authors'), __('Authors')), array(__('navigation'), $fields['source'] == __('navigation'), __('Navigation')))), array('label' => __('Custom XML'), 'options' => array(array(__('dynamic_xml'), $fields['source'] == __('dynamic_xml'), __('Dynamic XML')), array(__('static_xml'), $fields['source'] == __('static_xml'), __('Static XML'))))); if (is_array($sections) && !empty($sections)) { array_unshift($options, array('label' => __('Sections'), 'options' => array())); foreach ($sections as $s) { $options[0]['options'][] = array($s->get('id'), $fields['source'] == $s->get('id'), $s->get('name')); } } $label->appendChild(Widget::Select('fields[source]', $options, array('id' => 'context'))); $div->appendChild($label); $fieldset->appendChild($div); $this->Form->appendChild($fieldset); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings contextual ' . __('sections') . ' ' . __('authors') . ' ' . __('navigation') . ' ' . __('Sections') . ' ' . __('System')); $fieldset->appendChild(new XMLElement('legend', __('Filter Results'))); $p = new XMLElement('p', __('Use <code>{$param}</code> syntax to filter by page parameters.')); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); foreach ($field_groups as $section_id => $section_data) { $div = new XMLElement('div'); $div->setAttribute('class', 'subsection contextual ' . $section_data['section']->get('id')); $div->appendChild(new XMLElement('h3', __('Filter %s by', array($section_data['section']->get('name'))))); $ol = new XMLElement('ol'); if (isset($fields['filter'][$section_data['section']->get('id')]['id'])) { $li = new XMLElement('li'); $li->setAttribute('class', 'unique'); $li->appendChild(new XMLElement('h4', __('System ID'))); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][' . $section_data['section']->get('id') . '][id]', General::sanitize($fields['filter'][$section_data['section']->get('id')]['id']))); $li->appendChild($label); $ol->appendChild($li); } $li = new XMLElement('li'); $li->setAttribute('class', 'unique template'); $li->appendChild(new XMLElement('h4', __('System ID'))); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][' . $section_data['section']->get('id') . '][id]')); $li->appendChild($label); $ol->appendChild($li); foreach ($section_data['fields'] as $input) { if (!$input->canFilter()) { continue; } if (isset($fields['filter'][$section_data['section']->get('id')][$input->get('id')])) { $wrapper = new XMLElement('li'); $wrapper->setAttribute('class', 'unique'); $input->displayDatasourceFilterPanel($wrapper, $fields['filter'][$section_data['section']->get('id')][$input->get('id')], $this->_errors[$input->get('id')], $section_data['section']->get('id')); $ol->appendChild($wrapper); } $wrapper = new XMLElement('li'); $wrapper->setAttribute('class', 'unique template'); $input->displayDatasourceFilterPanel($wrapper, NULL, NULL, $section_data['section']->get('id')); $ol->appendChild($wrapper); } $div->appendChild($ol); $fieldset->appendChild($div); } $div = new XMLElement('div'); $div->setAttribute('class', 'subsection contextual ' . __('authors')); $div->appendChild(new XMLElement('h3', __('Filter Authors by'))); $ol = new XMLElement('ol'); $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', 'subsection contextual ' . __('navigation')); $div->appendChild(new XMLElement('h3', __('Filter Navigation by'))); $ol = new XMLElement('ol'); $pages = $this->_Parent->Database->fetch("SELECT * FROM `tbl_pages` ORDER BY `title` ASC"); $ul = new XMLElement('ul'); $ul->setAttribute('class', 'tags'); 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->appendChild(new XMLElement('h4', __('Parent Page'))); $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->appendChild(new XMLElement('h4', __('Parent Page'))); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][navigation][parent]')); $li->appendChild($label); $li->appendChild($ul); $ol->appendChild($li); $ul = new XMLElement('ul'); $ul->setAttribute('class', 'tags'); if ($types = $this->__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->appendChild(new XMLElement('h4', __('Page Type'))); $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('h4', __('Page Type'))); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter][navigation][type]')); $li->appendChild($label); $li->appendChild($ul); $ol->appendChild($li); $div->appendChild($ol); $fieldset->appendChild($div); $this->Form->appendChild($fieldset); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings contextual inverse ' . __('static_xml') . ' ' . __('dynamic_xml')); $fieldset->appendChild(new XMLElement('legend', __('Sorting and Limiting'))); $p = new XMLElement('p', __('Use <code>{$param}</code> syntax to limit by page parameters.')); $p->setAttribute('class', 'help contextual inverse ' . __('navigation')); $fieldset->appendChild($p); $div = new XMLElement('div'); $div->setAttribute('class', 'group contextual ' . __('sections') . ' ' . __('Sections')); $label = Widget::Label(__('Sort By')); $options = array(array('label' => __('Authors'), 'options' => array(array('id', $fields['source'] == 'authors' && $fields['sort'] == 'id', __('Author ID')), array('username', $fields['source'] == 'authors' && $fields['sort'] == 'username', __('Username')), array('first-name', $fields['source'] == 'authors' && $fields['sort'] == 'first-name', __('First Name')), array('last-name', $fields['source'] == 'authors' && $fields['sort'] == 'last-name', __('Last Name')), array('email', $fields['source'] == 'authors' && $fields['sort'] == 'email', __('Email')), array('status', $fields['source'] == 'authors' && $fields['sort'] == 'status', __('Status')))), array('label' => __('Navigation'), 'options' => array(array('id', $fields['source'] == 'navigation' && $fields['sort'] == 'id', __('Page ID')), array('handle', $fields['source'] == 'navigation' && $fields['sort'] == 'handle', __('Handle')), array('sortorder', $fields['source'] == 'navigation' && $fields['sort'] == 'sortorder', __('Sort Order'))))); foreach ($field_groups as $section_id => $section_data) { $optgroup = array('label' => $section_data['section']->get('name'), 'options' => array(array('system:id', $fields['source'] == $section_data['section']->get('id') && $fields['sort'] == 'system:id', __('System ID')), array('system:date', $fields['source'] == $section_data['section']->get('id') && $fields['sort'] == 'system:date', __('System Date')))); foreach ($section_data['fields'] as $input) { if (!$input->isSortable()) { continue; } $optgroup['options'][] = array($input->get('element_name'), $fields['source'] == $section_data['section']->get('id') && $input->get('element_name') == $fields['sort'], $input->get('label')); } $options[] = $optgroup; } $label->appendChild(Widget::Select('fields[sort]', $options, array('class' => 'filtered'))); $div->appendChild($label); $label = Widget::Label(__('Sort Order')); $options = array(array('asc', 'asc' == $fields['order'], __('ascending')), array('desc', 'desc' == $fields['order'], __('descending')), array('rand', 'rand' == $fields['order'], __('random'))); $label->appendChild(Widget::Select('fields[order]', $options)); $div->appendChild($label); $fieldset->appendChild($div); $div = new XMLElement('div'); $div->setAttribute('class', 'group contextual inverse ' . __('navigation')); $label = Widget::Label(); $input = Widget::Input('fields[max_records]', $fields['max_records'], NULL, array('size' => '6')); $label->setValue(__('Show a maximum of %s results', array($input->generate(false)))); if (isset($this->_errors['max_records'])) { $div->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['max_records'])); } else { $div->appendChild($label); } $label = Widget::Label(); $input = Widget::Input('fields[page_number]', $fields['page_number'], NULL, array('size' => '6')); $label->setValue(__('Show page %s of results', array($input->generate(false)))); if (isset($this->_errors['page_number'])) { $div->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['page_number'])); } else { $div->appendChild($label); } $fieldset->appendChild($div); $label = Widget::Label(__('Required URL Parameter <i>Optional</i>')); $label->appendChild(Widget::Input('fields[required_url_param]', $fields['required_url_param'])); $fieldset->appendChild($label); $p = new XMLElement('p', __('An empty result will be returned when this parameter does not have a value.')); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $label = Widget::Label(); $input = Widget::Input('fields[redirect_on_empty]', 'yes', 'checkbox', isset($fields['redirect_on_empty']) ? array('checked' => 'checked') : NULL); $label->setValue(__('%s Redirect to 404 page when no results are found', array($input->generate(false)))); $fieldset->appendChild($label); $this->Form->appendChild($fieldset); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings contextual inverse ' . __('navigation') . ' ' . __('static_xml') . ' ' . __('dynamic_xml')); $fieldset->appendChild(new XMLElement('legend', __('Output Options'))); $ul = new XMLElement('ul'); $ul->setAttribute('class', 'group'); $li = new XMLElement('li'); $li->appendChild(new XMLElement('h3', __('Parameter Output'))); $label = Widget::Label(__('Use Field')); $options = array(array('', false, __('None')), array('label' => __('Authors'), 'options' => array(array('id', $fields['source'] == 'authors' && $fields['param'] == 'id', __('Author ID')), array('username', $fields['source'] == 'authors' && $fields['param'] == 'username', __('Username')), array('name', $fields['source'] == 'authors' && $fields['param'] == 'name', __('Name')), array('email', $fields['source'] == 'authors' && $fields['param'] == 'email', __('Email')), array('user_type', $fields['source'] == 'authors' && $fields['param'] == 'user_type', __('User type'))))); foreach ($field_groups as $section_id => $section_data) { $optgroup = array('label' => $section_data['section']->get('name'), 'options' => array(array('system:id', $fields['source'] == $section_data['section']->get('id') && $fields['param'] == 'system:id', __('System ID')), array('system:date', $fields['source'] == $section_data['section']->get('id') && $fields['param'] == 'system:date', __('System Date')), array('system:author', $fields['source'] == $section_data['section']->get('id') && $fields['param'] == 'system:author', __('System Author')))); $authorOverride = false; foreach ($section_data['fields'] as $input) { if (!$input->allowDatasourceParamOutput()) { continue; } $optgroup['options'][] = array($input->get('element_name'), $fields['source'] == $section_data['section']->get('id') && $fields['param'] == $input->get('element_name'), $input->get('label')); } $options[] = $optgroup; } $label->appendChild(Widget::Select('fields[param]', $options, array('class' => 'filtered'))); $li->appendChild($label); $p = new XMLElement('p', __('The parameter <code id="output-param-name">$ds-%s</code> will be created with this field\'s value for XSLT or other data sources to use.', array($this->_context[0] == 'edit' ? $existing->dsParamROOTELEMENT : __('Untitled')))); $p->setAttribute('class', 'help'); $li->appendChild($p); $ul->appendChild($li); $li = new XMLElement('li'); $li->appendChild(new XMLElement('h3', __('XML Output'))); $label = Widget::Label(__('Group By')); $options = array(array('', NULL, __('None'))); foreach ($field_groups as $section_id => $section_data) { $optgroup = array('label' => $section_data['section']->get('name'), 'options' => array()); $authorOverride = false; foreach ($section_data['fields'] as $input) { if (!$input->allowDatasourceOutputGrouping()) { continue; } if ($input->get('element_name') == 'author') { $authorOverride = true; } $optgroup['options'][] = array($input->get('id'), $fields['source'] == $section_data['section']->get('id') && $fields['group'] == $input->get('id'), $input->get('label')); } if (!$authorOverride) { $optgroup['options'][] = array('author', $fields['source'] == $section_data['section']->get('id') && $fields['group'] == 'author', __('Author')); } $options[] = $optgroup; } $label->appendChild(Widget::Select('fields[group]', $options, array('class' => 'filtered'))); $li->appendChild($label); $label = Widget::Label(__('Included Elements')); $options = array(array('label' => __('Authors'), 'options' => array(array('username', $fields['source'] == 'authors' && in_array('username', $fields['xml_elements']), 'username'), array('name', $fields['source'] == 'authors' && in_array('name', $fields['xml_elements']), 'name'), array('email', $fields['source'] == 'authors' && in_array('email', $fields['xml_elements']), 'email'), array('author-token', $fields['source'] == 'authors' && in_array('author-token', $fields['xml_elements']), 'author-token'), array('default-section', $fields['source'] == 'authors' && in_array('default-section', $fields['xml_elements']), 'default-section'), array('formatting-preference', $fields['source'] == 'authors' && in_array('formatting-preference', $fields['xml_elements']), 'formatting-preference')))); foreach ($field_groups as $section_id => $section_data) { $optgroup = array('label' => $section_data['section']->get('name'), 'options' => array()); $optgroup['options'][] = array('system:pagination', $fields['source'] == $section_data['section']->get('id') && @in_array('system:pagination', $fields['xml_elements']), 'pagination'); foreach ($section_data['fields'] as $input) { $elements = $input->fetchIncludableElements(); foreach ($elements as $e) { $optgroup['options'][] = array($e, $fields['source'] == $section_data['section']->get('id') && @in_array($e, $fields['xml_elements']), $e); } } $options[] = $optgroup; } $label->appendChild(Widget::Select('fields[xml_elements][]', $options, array('multiple' => 'multiple', 'class' => 'filtered'))); $li->appendChild($label); $label = Widget::Label(); $label->setAttribute('class', 'contextual inverse ' . __('authors')); $input = Widget::Input('fields[html_encode]', 'yes', 'checkbox', isset($fields['html_encode']) ? array('checked' => 'checked') : NULL); $label->setValue(__('%s HTML-encode text', array($input->generate(false)))); $li->appendChild($label); $ul->appendChild($li); $fieldset->appendChild($ul); $this->Form->appendChild($fieldset); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings contextual ' . __('dynamic_xml')); $fieldset->appendChild(new XMLElement('legend', __('Dynamic XML'))); $label = Widget::Label(__('URL')); $label->appendChild(Widget::Input('fields[dynamic_xml][url]', General::sanitize($fields['dynamic_xml']['url']))); if (isset($this->_errors['dynamic_xml']['url'])) { $fieldset->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['dynamic_xml']['url'])); } else { $fieldset->appendChild($label); } $p = new XMLElement('p', __('Use <code>{$param}</code> syntax to specify dynamic portions of the URL.')); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $div = new XMLElement('div'); $div->setAttribute('class', 'subsection'); $div->appendChild(new XMLElement('h3', __('Namespace Declarations <i>Optional</i>'))); $ol = new XMLElement('ol'); if (is_array($fields['dynamic_xml']['namespace']['name'])) { $namespaces = $fields['dynamic_xml']['namespace']['name']; $uri = $fields['dynamic_xml']['namespace']['uri']; for ($ii = 0; $ii < count($namespaces); $ii++) { $li = new XMLElement('li'); $li->appendChild(new XMLElement('h4', 'Namespace')); $group = new XMLElement('div'); $group->setAttribute('class', 'group'); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[dynamic_xml][namespace][name][]', General::sanitize($namespaces[$ii]))); $group->appendChild($label); $label = Widget::Label(__('URI')); $label->appendChild(Widget::Input('fields[dynamic_xml][namespace][uri][]', General::sanitize($uri[$ii]))); $group->appendChild($label); $li->appendChild($group); $ol->appendChild($li); } } $li = new XMLElement('li'); $li->setAttribute('class', 'template'); $li->appendChild(new XMLElement('h4', __('Namespace'))); $group = new XMLElement('div'); $group->setAttribute('class', 'group'); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[dynamic_xml][namespace][name][]')); $group->appendChild($label); $label = Widget::Label(__('URI')); $label->appendChild(Widget::Input('fields[dynamic_xml][namespace][uri][]')); $group->appendChild($label); $li->appendChild($group); $ol->appendChild($li); $div->appendChild($ol); $fieldset->appendChild($div); $label = Widget::Label(__('Included Elements')); $label->appendChild(Widget::Input('fields[dynamic_xml][xpath]', General::sanitize($fields['dynamic_xml']['xpath']))); if (isset($this->_errors['dynamic_xml']['xpath'])) { $fieldset->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['dynamic_xml']['xpath'])); } else { $fieldset->appendChild($label); } $p = new XMLElement('p', __('Use an XPath expression to select which elements from the source XML to include.')); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $label = Widget::Label(); $input = Widget::Input('fields[dynamic_xml][cache]', max(1, intval($fields['dynamic_xml']['cache'])), NULL, array('size' => '6')); $label->setValue('Update cached result every ' . $input->generate(false) . ' minutes'); if (isset($this->_errors['dynamic_xml']['cache'])) { $fieldset->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['dynamic_xml']['cache'])); } else { $fieldset->appendChild($label); } $this->Form->appendChild($fieldset); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings contextual ' . __('static_xml')); $fieldset->appendChild(new XMLElement('legend', __('Static XML'))); $label = Widget::Label(__('Body')); $label->appendChild(Widget::Textarea('fields[static_xml]', 12, 50, General::sanitize($fields['static_xml']), array('class' => 'code'))); if (isset($this->_errors['static_xml'])) { $fieldset->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['static_xml'])); } else { $fieldset->appendChild($label); } $this->Form->appendChild($fieldset); $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' => 'confirm delete', 'title' => __('Delete this data source'))); $div->appendChild($button); } $this->Form->appendChild($div); }
public function __viewEdit() { $this->setPageType('form'); $fields = array(); $nesting = Symphony::Configuration()->get('pages_table_nest_children', 'symphony') == 'yes'; // Verify page exists: if ($this->_context[0] == 'edit') { if (!($page_id = $this->_context[1])) { redirect(SYMPHONY_URL . '/blueprints/pages/'); } $existing = Symphony::Database()->fetchRow(0, "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tp.*\n\t\t\t\t\tFROM\n\t\t\t\t\t\t`tbl_pages` AS p\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tp.id = '{$page_id}'\n\t\t\t\t\tLIMIT 1\n\t\t\t\t"); if (!$existing) { Administration::instance()->errorPageNotFound(); } } // Status message: $flag = $this->_context[2]; if (isset($flag)) { if (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) { $link_suffix = "?parent=" . $_REQUEST['parent']; } elseif ($nesting == true && isset($existing) && !is_null($existing['parent'])) { $link_suffix = '?parent=' . $existing['parent']; } switch ($flag) { case 'saved': $this->pageAlert(__('Page updated at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Pages</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), SYMPHONY_URL . '/blueprints/pages/new/' . $link_suffix, SYMPHONY_URL . '/blueprints/pages/' . $link_suffix)), Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Page created at %1$s. <a href="%2$s" accesskey="c">Create another?</a> <a href="%3$s" accesskey="a">View all Pages</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), SYMPHONY_URL . '/blueprints/pages/new/' . $link_suffix, SYMPHONY_URL . '/blueprints/pages/' . $link_suffix)), Alert::SUCCESS); break; } } // Find values: if (isset($_POST['fields'])) { $fields = $_POST['fields']; } elseif ($this->_context[0] == 'edit') { $fields = $existing; $types = Symphony::Database()->fetchCol('type', "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tp.type\n\t\t\t\t\tFROM\n\t\t\t\t\t\t`tbl_pages_types` AS p\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tp.page_id = '{$page_id}'\n\t\t\t\t\tORDER BY\n\t\t\t\t\t\tp.type ASC\n\t\t\t\t"); $fields['type'] = @implode(', ', $types); $fields['data_sources'] = preg_split('/,/i', $fields['data_sources'], -1, PREG_SPLIT_NO_EMPTY); $fields['events'] = preg_split('/,/i', $fields['events'], -1, PREG_SPLIT_NO_EMPTY); } elseif (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) { $fields['parent'] = $_REQUEST['parent']; } $title = $fields['title']; if (trim($title) == '') { $title = $existing['title']; } $this->setTitle(__($title ? '%1$s – %2$s – %3$s' : '%1$s – %2$s', array(__('Symphony'), __('Pages'), $title))); if ($existing) { $template_name = $fields['handle']; if ($existing['parent']) { $parents = $this->__getParent($existing['parent']); $template_name = $parents . '_' . $fields['handle']; } $this->appendSubheading(__($title ? $title : __('Untitled')), Widget::Anchor(__('Edit Template'), SYMPHONY_URL . '/blueprints/pages/template/' . $template_name, __('Edit Page Template'), 'button', NULL, array('accesskey' => 't'))); } else { $this->appendSubheading($title ? $title : __('Untitled')); } // Title -------------------------------------------------------------- $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Page Settings'))); $label = Widget::Label(__('Title')); $label->appendChild(Widget::Input('fields[title]', General::sanitize($fields['title']))); if (isset($this->_errors['title'])) { $label = $this->wrapFormElementWithError($label, $this->_errors['title']); } $fieldset->appendChild($label); // Handle ------------------------------------------------------------- $group = new XMLElement('div'); $group->setAttribute('class', 'group'); $column = new XMLElement('div'); $label = Widget::Label(__('URL Handle')); $label->appendChild(Widget::Input('fields[handle]', $fields['handle'])); if (isset($this->_errors['handle'])) { $label = $this->wrapFormElementWithError($label, $this->_errors['handle']); } $column->appendChild($label); // Parent --------------------------------------------------------- $label = Widget::Label(__('Parent Page')); $pages = Symphony::Database()->fetch("\n\t\t\t\tSELECT\n\t\t\t\t\tp.*\n\t\t\t\tFROM\n\t\t\t\t\t`tbl_pages` AS p\n\t\t\t\tWHERE\n\t\t\t\t\tp.id != '{$page_id}'\n\t\t\t\tORDER BY\n\t\t\t\t\tp.title ASC\n\t\t\t"); $options = array(array('', false, '/')); if (is_array($pages) && !empty($pages)) { if (!function_exists('__compare_pages')) { function __compare_pages($a, $b) { return strnatcasecmp($a[2], $b[2]); } } foreach ($pages as $page) { $options[] = array($page['id'], $fields['parent'] == $page['id'], '/' . Administration::instance()->resolvePagePath($page['id'])); } usort($options, '__compare_pages'); } $label->appendChild(Widget::Select('fields[parent]', $options)); $column->appendChild($label); $group->appendChild($column); // Parameters --------------------------------------------------------- $column = new XMLElement('div'); $label = Widget::Label(__('URL Parameters')); $label->appendChild(Widget::Input('fields[params]', $fields['params'])); $column->appendChild($label); // Type ----------------------------------------------------------- $label = Widget::Label(__('Page Type')); $label->appendChild(Widget::Input('fields[type]', $fields['type'])); if (isset($this->_errors['type'])) { $label = $this->wrapFormElementWithError($label, $this->_errors['type']); } $column->appendChild($label); $tags = new XMLElement('ul'); $tags->setAttribute('class', 'tags'); if ($types = $this->__fetchAvailablePageTypes()) { foreach ($types as $type) { $tags->appendChild(new XMLElement('li', $type)); } } $column->appendChild($tags); $group->appendChild($column); $fieldset->appendChild($group); $this->Form->appendChild($fieldset); // Events ------------------------------------------------------------- $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Page Resources'))); $group = new XMLElement('div'); $group->setAttribute('class', 'group'); $label = Widget::Label(__('Events')); $manager = new EventManager($this->_Parent); $events = $manager->listAll(); $options = array(); if (is_array($events) && !empty($events)) { if (!is_array($fields['events'])) { $fields['events'] = array(); } foreach ($events as $name => $about) { $options[] = array($name, in_array($name, $fields['events']), $about['name']); } } $label->appendChild(Widget::Select('fields[events][]', $options, array('multiple' => 'multiple'))); $group->appendChild($label); // Data Sources ------------------------------------------------------- $label = Widget::Label(__('Data Sources')); $manager = new DatasourceManager($this->_Parent); $datasources = $manager->listAll(); $options = array(); if (is_array($datasources) && !empty($datasources)) { if (!is_array($fields['data_sources'])) { $fields['data_sources'] = array(); } foreach ($datasources as $name => $about) { $options[] = array($name, in_array($name, $fields['data_sources']), $about['name']); } } $label->appendChild(Widget::Select('fields[data_sources][]', $options, array('multiple' => 'multiple'))); $group->appendChild($label); $fieldset->appendChild($group); $this->Form->appendChild($fieldset); // Controls ----------------------------------------------------------- /** * After all Page related Fields have been added to the DOM, just before the * actions. * * @delegate AppendPageContent * @param string $context * '/blueprints/pages/' * @param XMLElement $form * @param array $fields * @param array $errors */ Symphony::ExtensionManager()->notifyMembers('AppendPageContent', '/blueprints/pages/', array('form' => &$this->Form, 'fields' => &$fields, 'errors' => $this->_errors)); $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : __('Create Page'), 'submit', array('accesskey' => 's'))); if ($this->_context[0] == 'edit') { $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this page'), 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this page?'))); $div->appendChild($button); } $this->Form->appendChild($div); if (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) { $this->Form->appendChild(new XMLElement('input', NULL, array('type' => 'hidden', 'name' => 'parent', 'value' => $_REQUEST['parent']))); } }
public function __viewEdit() { $this->setPageType('form'); $fields = array(); // Verify page exists: if ($this->_context[0] == 'edit') { if (!($page_id = $this->_context[1])) { redirect(URL . '/symphony/blueprints/pages/'); } $existing = $this->_Parent->Database->fetchRow(0, "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tp.*\n\t\t\t\t\tFROM\n\t\t\t\t\t\t`tbl_pages` AS p\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tp.id = '{$page_id}'\n\t\t\t\t\tLIMIT 1\n\t\t\t\t"); if (!$existing) { $this->_Parent->customError(E_USER_ERROR, __('Page not found'), __('The page you requested to edit does not exist.'), false, true, 'error', array('header' => 'HTTP/1.0 404 Not Found')); } } // Status message: if (isset($this->_context[2])) { $this->pageAlert(__('%s %s at %s. <a href="%s">Create another?</a> <a href="%s">View all %s</a>', array(__('Page'), $this->_context[2] == 'saved' ? 'updated' : 'created', DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), URL . '/symphony/blueprints/pages/new/', URL . '/symphony/blueprints/pages/', __('Pages'))), Alert::SUCCESS); } // Find values: if (isset($_POST['fields'])) { $fields = $_POST['fields']; } else { if ($this->_context[0] == 'edit') { $fields = $existing; $types = $this->_Parent->Database->fetchCol('type', "\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tp.type\n\t\t\t\t\tFROM\n\t\t\t\t\t\t`tbl_pages_types` AS p\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tp.page_id = '{$page_id}'\n\t\t\t\t\tORDER BY\n\t\t\t\t\t\tp.type ASC\n\t\t\t\t"); $fields['type'] = @implode(', ', $types); $fields['data_sources'] = preg_split('/,/i', $fields['data_sources'], -1, PREG_SPLIT_NO_EMPTY); $fields['events'] = preg_split('/,/i', $fields['events'], -1, PREG_SPLIT_NO_EMPTY); } } $title = $fields['title']; if (trim($title) == '') { $title = $existing['title']; } $this->setTitle(__($title ? '%1$s – %2$s – %3$s' : '%1$s – %2$s', array(__('Symphony'), __('Pages'), $title))); $this->appendSubheading($title ? $title : __('Untitled')); // Title -------------------------------------------------------------- $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Page Settings'))); $label = Widget::Label(__('Title')); $label->appendChild(Widget::Input('fields[title]', General::sanitize($fields['title']))); if (isset($this->_errors['title'])) { $label = $this->wrapFormElementWithError($label, $this->_errors['title']); } $fieldset->appendChild($label); // Handle ------------------------------------------------------------- $group = new XMLElement('div'); $group->setAttribute('class', 'group'); $column = new XMLElement('div'); $label = Widget::Label(__('URL Handle')); $label->appendChild(Widget::Input('fields[handle]', $fields['handle'])); if (isset($this->_errors['handle'])) { $label = $this->wrapFormElementWithError($label, $this->_errors['handle']); } $column->appendChild($label); // Parent --------------------------------------------------------- $label = Widget::Label(__('Parent Page')); $pages = $this->_Parent->Database->fetch("\n\t\t\t\tSELECT\n\t\t\t\t\tp.*\n\t\t\t\tFROM\n\t\t\t\t\t`tbl_pages` AS p\n\t\t\t\tWHERE\n\t\t\t\t\tp.id != '{$page_id}'\n\t\t\t\tORDER BY\n\t\t\t\t\tp.title ASC\n\t\t\t"); $options = array(array('', false, '/')); if (is_array($pages) && !empty($pages)) { if (!function_exists('__compare_pages')) { function __compare_pages($a, $b) { return strnatcasecmp($a[2], $b[2]); } } foreach ($pages as $page) { $options[] = array($page['id'], $fields['parent'] == $page['id'], '/' . $this->_Parent->resolvePagePath($page['id'])); } usort($options, '__compare_pages'); } $label->appendChild(Widget::Select('fields[parent]', $options)); $column->appendChild($label); $group->appendChild($column); // Parameters --------------------------------------------------------- $column = new XMLElement('div'); $label = Widget::Label(__('URL Parameters')); $label->appendChild(Widget::Input('fields[params]', $fields['params'])); $column->appendChild($label); // Type ----------------------------------------------------------- $label = Widget::Label(__('Page Type')); $label->appendChild(Widget::Input('fields[type]', $fields['type'])); if (isset($this->_errors['type'])) { $label = $this->wrapFormElementWithError($label, $this->_errors['type']); } $column->appendChild($label); $tags = new XMLElement('ul'); $tags->setAttribute('class', 'tags'); if ($types = $this->__fetchAvailablePageTypes()) { foreach ($types as $type) { $tags->appendChild(new XMLElement('li', $type)); } } $column->appendChild($tags); $group->appendChild($column); $fieldset->appendChild($group); $this->Form->appendChild($fieldset); // Events ------------------------------------------------------------- $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Page Resources'))); $group = new XMLElement('div'); $group->setAttribute('class', 'group'); $label = Widget::Label(__('Events')); $manager = new EventManager($this->_Parent); $events = $manager->listAll(); $options = array(); if (is_array($events) && !empty($events)) { foreach ($events as $name => $about) { $options[] = array($name, @in_array($name, $fields['events']), $about['name']); } } $label->appendChild(Widget::Select('fields[events][]', $options, array('multiple' => 'multiple'))); $group->appendChild($label); // Data Sources ------------------------------------------------------- $label = Widget::Label(__('Data Sources')); $manager = new DatasourceManager($this->_Parent); $datasources = $manager->listAll(); $options = array(); if (is_array($datasources) && !empty($datasources)) { foreach ($datasources as $name => $about) { $options[] = array($name, @in_array($name, $fields['data_sources']), $about['name']); } } $label->appendChild(Widget::Select('fields[data_sources][]', $options, array('multiple' => 'multiple'))); $group->appendChild($label); $fieldset->appendChild($group); $this->Form->appendChild($fieldset); // Controls ----------------------------------------------------------- $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : __('Create Page'), 'submit', array('accesskey' => 's'))); if ($this->_context[0] == 'edit') { $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'confirm delete', 'title' => __('Delete this page'))); $div->appendChild($button); } $this->Form->appendChild($div); }
private function __form() { $this->insertNodeIntoHead($this->createStylesheetElement(URL . '/extensions/aac/assets/roles.css')); $this->insertNodeIntoHead($this->createScriptElement(URL . '/extensions/aac/assets/roles.js')); // The "symphony.selectable.js" messes up the checkboxes, so remove it foreach ($this->xpath("//head/script[contains(@src, 'symphony/assets/js/symphony.selectable.js')]") as $element) { $element->parentNode->removeChild($element); } if (!in_array($this->_context[0], array('new', 'edit'))) { throw new AdministrationPageNotFoundException(); } $callback = Administration::instance()->getPageCallback(); if (isset($callback['flag'])) { switch ($callback['flag']) { case 'saved': $this->alerts()->append(__('Role updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Roles</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), ADMIN_URL . '/extension/aac/roles/new/', ADMIN_URL . '/extension/aac/roles/')), AlertStack::SUCCESS); break; case 'created': $this->alerts()->append(__('Role created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Roles</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), ADMIN_URL . '/extension/aac/roles/new/', ADMIN_URL . '/extension/aac/roles/')), AlertStack::SUCCESS); break; } } /********** INSERT logic for determining the current role and whether the user has permission to edit it **********/ $this->setTitle(__($this->_context[0] == 'new' ? '%1$s – %2$s – Untitled' : '%1$s – %2$s – %3$s', array(__('Symphony'), __('Roles'), $this->role->name))); $this->appendSubheading($this->_context[0] == 'new' ? __('Untitled') : $this->role->name); // SETUP PAGE $layout = new Layout(); $left = $layout->createColumn(Layout::SMALL); $middle = $layout->createColumn(Layout::LARGE); $right = $layout->createColumn(Layout::LARGE); /** ESSENTIALS **/ $fieldset = Widget::Fieldset(__('Essentials')); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[name]', $this->role->name)); $fieldset->appendChild(isset($this->errors->name) ? Widget::wrapFormElementWithError($label, $this->errors->name) : $label); $label = Widget::Label(__('Description')); $label->appendChild(Widget::Textarea('fields[description]', $this->role->description, array('rows' => 7, 'cols' => 50))); $fieldset->appendChild(isset($this->errors->description) ? Widget::wrapFormElementWithError($label, $this->errors->description) : $label); $left->appendChild($fieldset); /// PUBLISHING PERMISSIONS $fieldset = Widget::Fieldset(__('Publishing Permissions')); $sections = new SectionIterator(); if ($sections->length() <= 0) { $p = $this->createElement('p', 'No sections exist. '); $p->appendChild(Widget::Anchor(__('Create one'), ADMIN_URL . '/sections/new/')); $fieldset->appendChild($p); } else { $thead = array(array(__('Section'), 'col'), array(__('Create'), 'col', array('class' => 'checkbox')), array(__('Edit'), 'col', array('class' => 'checkbox'))); $tbody = array(); /* // TODO: Global permissions set all permissions $td1 = Widget::TableData(__('Global Permissions')); $td2 = Widget::TableData( Widget::Input('global-add', '1', 'checkbox'), array('class' => 'checkbox') ); $td3 = Widget::TableData(NULL, array('class' => 'edit')); $td3->appendChild($this->createElement('p', NULL, array('class' => 'global-slider'))); $td3->appendChild($this->createElement('span', 'n/a')); $tbody[] = Widget::TableRow(array($td1, $td2, $td3), array('class' => 'global')); */ foreach ($sections as $section) { $td1 = Widget::TableData($section->name); // TODO: Remove this and implement sliders $td2 = Widget::TableData(); $td2->appendChild(Widget::Input("fields[permissions][publish::{$section->handle}][create]", '0', 'checkbox', array('checked' => 'checked', 'style' => 'display: none;'))); $td2->appendChild(Widget::Input("fields[permissions][publish::{$section->handle}][create]", '1', 'checkbox', (int) $this->role->permissions()->{"publish::{$section->handle}.create"} > 0 ? array('checked' => 'checked') : NULL)); $edit_level = (int) $this->role->permissions()->{"publish::{$section->handle}.edit"}; $td3 = Widget::TableData(Widget::Select("fields[permissions][publish::{$section->handle}][edit]", array(array('0', false, 'None'), array(1, $edit_level == 1, 'Own'), array(2, $edit_level == 2, 'All')))); /* $td2 = Widget::TableData( Widget::Input( "fields[permissions][{$section->handle}][create]", '1', 'checkbox', ($permissions['create'] == 1 ? array('checked' => 'checked') : array()) ), array('class' => 'checkbox') ); $td3 = Widget::TableData(NULL, array('class' => 'edit')); $td3->appendChild($this->createElement('p', NULL, array('class' => 'slider'))); $td3->appendChild( $this->createElement('span', '') ); $td3->appendChild( Widget::Input('fields[permissions][' . $section->handle .'][edit]', (isset($permissions['edit']) ? $permissions['edit'] : '0'), 'hidden' ) ); */ $tbody[] = Widget::TableRow(array($td1, $td2, $td3)); } $table = Widget::Table(Widget::TableHead($thead), NULL, Widget::TableBody($tbody), array('id' => 'role-permissions')); $fieldset->appendChild($table); $right->appendChild($fieldset); } /// BLUEPRINTS PERMISSIONS $fieldset = Widget::Fieldset(__('Blueprints Permissions')); $thead = array(array(__('Area'), 'col'), array(__('Create'), 'col', array('class' => 'checkbox')), array(__('Edit'), 'col', array('class' => 'checkbox'))); $tbody = array(); $areas = array('sections' => 'Sections', 'datasources' => 'Data Sources', 'events' => 'Events', 'views' => 'Views', 'utilities' => 'Utilities'); foreach ($areas as $key => $name) { $td1 = Widget::TableData($name); $td2 = Widget::TableData(Widget::Input("fields[permissions][blueprints::{$key}][create]", '1', 'checkbox', (int) $this->role->permissions()->{"blueprints::{$key}.create"} > 0 ? array('checked' => 'checked') : NULL)); $td3 = Widget::TableData(Widget::Input("fields[permissions][blueprints::{$key}][edit]", '1', 'checkbox', (int) $this->role->permissions()->{"blueprints::{$key}.edit"} > 0 ? array('checked' => 'checked') : NULL)); $tbody[] = Widget::TableRow(array($td1, $td2, $td3)); } $table = Widget::Table(Widget::TableHead($thead), NULL, Widget::TableBody($tbody), array('id' => 'role-permissions')); $fieldset->appendChild($table); $middle->appendChild($fieldset); /// SYSTEM PERMISSIONS $fieldset = Widget::Fieldset(__('System Permissions')); $tbody = array(); $items = array('Access Settings' => array('settings', 'access', 1), 'Access Extensions' => array('extensions', 'access', 1), 'Create New Users' => array('users', 'create', 1)); foreach ($items as $name => $item) { list($key, $type, $level) = $item; $td1 = Widget::TableData($name); $td2 = Widget::TableData(Widget::Input("fields[permissions][system::{$key}][{$type}]", (string) $level, 'checkbox', (int) $this->role->permissions()->{"system::{$key}.{$type}"} > 0 ? array('checked' => 'checked') : NULL)); $tbody[] = Widget::TableRow(array($td1, $td2)); } $user_edit_level = (int) $this->role->permissions()->{"system::users.edit"}; $td1 = Widget::TableData('Edit User Profiles'); $td2 = Widget::TableData(Widget::Select("fields[permissions][system::users][edit]", array(array('0', false, 'None'), array(1, $user_edit_level == 1, 'Own'), array(2, $user_edit_level == 2, 'All')))); $tbody[] = Widget::TableRow(array($td1, $td2)); $td1 = Widget::TableData('Change Users Role'); $td2 = Widget::TableData(Widget::Input("fields[permissions][system::users][change-role]", (string) $level, 'checkbox', (int) $this->role->permissions()->{"system::users.change-role"} > 0 ? array('checked' => 'checked') : NULL)); $tbody[] = Widget::TableRow(array($td1, $td2)); $table = Widget::Table(NULL, NULL, Widget::TableBody($tbody), array('id' => 'role-permissions')); $fieldset->appendChild($table); $middle->appendChild($fieldset); /********** BUILD view list and set up permissions interface **********/ $layout->appendTo($this->Form); /** FORM ACTIONS **/ $div = $this->createElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Submit('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : __('Create Role'), array('accesskey' => 's'))); if ($this->_context[0] == 'edit' && !$isOwner) { $div->appendChild(Widget::Submit('action[delete]', __('Delete'), array('class' => 'confirm delete', 'title' => __('Delete this role')))); } $this->Form->appendChild($div); }