/** * The processEvents function executes all Events attached to the resolved * page in the correct order determined by `__findEventOrder()`. The results * from the Events are appended to the page's XML. Events execute first, * before Datasources. * * @uses FrontendProcessEvents * @uses FrontendEventPostProcess * @param string $events * A string of all the Events attached to this page, comma separated. * @param XMLElement $wrapper * The XMLElement to append the Events results to. Event results are * contained in a root XMLElement that is the handlised version of * their name. */ private function processEvents($events, XMLElement &$wrapper) { /** * Manipulate the events array and event element wrapper * @delegate FrontendProcessEvents * @param string $context * '/frontend/' * @param array $env * @param string $events * A string of all the Events attached to this page, comma separated. * @param XMLElement $wrapper * The XMLElement to append the Events results to. Event results are * contained in a root XMLElement that is the handlised version of * their name. * @param array $page_data * An associative array of page meta data */ $this->ExtensionManager->notifyMembers('FrontendProcessEvents', '/frontend/', array('env' => $this->_env, 'events' => &$events, 'wrapper' => &$wrapper, 'page_data' => $this->_pageData)); if (strlen(trim($events)) > 0) { $events = preg_split('/,\\s*/i', $events, -1, PREG_SPLIT_NO_EMPTY); $events = array_map('trim', $events); if (!is_array($events) || empty($events)) { return; } $pool = array(); foreach ($events as $handle) { $pool[$handle] = $this->EventManager->create($handle, array('env' => $this->_env, 'param' => $this->_param)); } uasort($pool, array($this, '__findEventOrder')); foreach ($pool as $handle => $event) { Frontend::instance()->Profiler->seed(); $dbstats = Symphony::Database()->getStatistics(); $queries = $dbstats['queries']; if ($xml = $event->load()) { if (is_object($xml)) { $wrapper->appendChild($xml); } else { $wrapper->setValue($wrapper->getValue() . self::CRLF . ' ' . trim($xml)); } } $dbstats = Symphony::Database()->getStatistics(); $queries = $dbstats['queries'] - $queries; Frontend::instance()->Profiler->sample($handle, PROFILE_LAP, 'Event', $queries); } } /** * Just after the page events have triggered. Provided with the XML object * @delegate FrontendEventPostProcess * @param string $context * '/frontend/' * @param XMLElement $xml * The XMLElement to append the Events results to. Event results are * contained in a root XMLElement that is the handlised version of * their name. */ $this->ExtensionManager->notifyMembers('FrontendEventPostProcess', '/frontend/', array('xml' => &$wrapper)); }
private function injectFields(XMLElement &$form, array $callback) { // skip when creating new events if ($callback['context'][0] == 'new') { return $this->injectDefault($form); } $event = EventManager::create($callback['context'][1]); $event_source = null; if (method_exists($event, 'getSource')) { $event_source = $event->getSource(); } // This isn't a typical event, so return if (!is_numeric($event_source)) { return null; } $section = SectionManager::fetch($event_source); // For whatever reason, the Section doesn't exist anymore if (!$section instanceof Section) { return null; } $this->injectDefaultValues($form, $event, $section); }
public function __form($readonly = false) { $formHasErrors = is_array($this->_errors) && !empty($this->_errors); if ($formHasErrors) { $this->pageAlert(__('An error occurred while processing this form. See below for details.'), Alert::ERROR); // These alerts are only valid if the form doesn't have errors } elseif (isset($this->_context[2])) { $time = Widget::Time(); switch ($this->_context[2]) { case 'saved': $this->pageAlert(__('Event updated at %s.', array($time->generate())) . ' <a href="' . SYMPHONY_URL . '/blueprints/events/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/blueprints/events/" accesskey="a">' . __('View all Events') . '</a>', Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Event created at %s.', array($time->generate())) . ' <a href="' . SYMPHONY_URL . '/blueprints/events/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . SYMPHONY_URL . '/blueprints/events/" accesskey="a">' . __('View all Events') . '</a>', Alert::SUCCESS); break; } } $isEditing = $readonly ? true : false; $fields = array("name" => null, "filters" => null); $about = array("name" => null); $providers = Symphony::ExtensionManager()->getProvidersOf(iProvider::EVENT); if (isset($_POST['fields'])) { $fields = $_POST['fields']; if ($this->_context[0] == 'edit') { $isEditing = true; } } elseif ($this->_context[0] == 'edit' || $this->_context[0] == 'info') { $isEditing = true; $handle = $this->_context[1]; $existing = EventManager::create($handle); $about = $existing->about(); if ($this->_context[0] == 'edit' && !$existing->allowEditorToParse()) { redirect(SYMPHONY_URL . '/blueprints/events/info/' . $handle . '/'); } $fields['name'] = $about['name']; $fields['source'] = $existing->getSource(); $provided = false; if (!empty($providers)) { foreach ($providers as $providerClass => $provider) { if ($fields['source'] == call_user_func(array($providerClass, 'getClass'))) { $fields = array_merge($fields, $existing->settings()); $provided = true; break; } } } if (!$provided) { if (isset($existing->eParamFILTERS)) { $fields['filters'] = $existing->eParamFILTERS; } } } // Handle name on edited changes, or from reading an edited datasource if (isset($about['name'])) { $name = $about['name']; } elseif (isset($fields['name'])) { $name = $fields['name']; } $this->setPageType('form'); $this->setTitle(__($isEditing ? '%1$s – %2$s – %3$s' : '%2$s – %3$s', array($about['name'], __('Events'), __('Symphony')))); $this->appendSubheading($isEditing ? $about['name'] : __('Untitled')); $this->insertBreadcrumbs(array(Widget::Anchor(__('Events'), SYMPHONY_URL . '/blueprints/events/'))); if (!$readonly) { $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Essentials'))); // Target $sources = new XMLElement('div', null, array('class' => 'apply actions')); $div = new XMLElement('div'); $label = Widget::Label(__('Target'), null, 'apply-label-left'); $sources->appendChild($label); $sources->appendChild($div); $sections = SectionManager::fetch(null, 'ASC', 'name'); $options = array(); $section_options = array(); $source = isset($fields['source']) ? $fields['source'] : null; if (is_array($sections) && !empty($sections)) { $section_options = array('label' => __('Sections'), 'options' => array()); foreach ($sections as $s) { $section_options['options'][] = array($s->get('id'), $source == $s->get('id'), General::sanitize($s->get('name'))); } } $options[] = $section_options; // Loop over the event providers if (!empty($providers)) { $p = array('label' => __('From extensions'), 'options' => array()); foreach ($providers as $providerClass => $provider) { $p['options'][] = array($providerClass, $fields['source'] == $providerClass, $provider); } $options[] = $p; } $div->appendChild(Widget::Select('source', $options, array('id' => 'event-context'))); if (isset($this->_errors['source'])) { $this->Context->prependChild(Widget::Error($sources, $this->_errors['source'])); } else { $this->Context->prependChild($sources); } $this->Form->appendChild(Widget::Input('fields[source]', $options[0]['options'][0][0], 'hidden', array('id' => 'event-source'))); // Name $group = new XMLElement('div'); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[name]', General::sanitize($fields['name']))); $div = new XMLElement('div'); $div->setAttribute('class', 'column'); if (isset($this->_errors['name'])) { $div->appendChild(Widget::Error($label, $this->_errors['name'])); } else { $div->appendChild($label); } $group->appendChild($div); $fieldset->appendChild($group); $this->Form->appendChild($fieldset); // Filters $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings pickable'); $fieldset->appendChild(new XMLElement('legend', __('Filters'))); $p = new XMLElement('p', __('Event Filters add additional conditions or actions to an event.')); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $filters = isset($fields['filters']) ? $fields['filters'] : array(); $options = array(array('admin-only', in_array('admin-only', $filters), __('Admin Only')), array('send-email', in_array('send-email', $filters), __('Send Notification Email')), array('expect-multiple', in_array('expect-multiple', $filters), __('Allow Multiple'))); /** * Allows adding of new filter rules to the Event filter rule select box * * @delegate AppendEventFilter * @param string $context * '/blueprints/events/(edit|new|info)/' * @param array $selected * An array of all the selected filters for this Event * @param array $options * An array of all the filters that are available, passed by reference */ Symphony::ExtensionManager()->notifyMembers('AppendEventFilter', '/blueprints/events/' . $this->_context[0] . '/', array('selected' => $filters, 'options' => &$options)); $fieldset->appendChild(Widget::Select('fields[filters][]', $options, array('multiple' => 'multiple', 'id' => 'event-filters'))); $this->Form->appendChild($fieldset); // Connections $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Attach to Pages'))); $p = new XMLElement('p', __('The event will only be available on the selected pages.')); $p->setAttribute('class', 'help'); $fieldset->appendChild($p); $div = new XMLElement('div'); $label = Widget::Label(__('Pages')); $pages = PageManager::fetch(); $event_handle = str_replace('-', '_', Lang::createHandle($fields['name'])); $connections = ResourceManager::getAttachedPages(RESOURCE_TYPE_EVENT, $event_handle); $selected = array(); foreach ($connections as $connection) { $selected[] = $connection['id']; } $options = array(); foreach ($pages as $page) { $options[] = array($page['id'], in_array($page['id'], $selected), PageManager::resolvePageTitle($page['id'])); } $label->appendChild(Widget::Select('fields[connections][]', $options, array('multiple' => 'multiple'))); $div->appendChild($label); $fieldset->appendChild($div); $this->Form->appendChild($fieldset); // Providers if (!empty($providers)) { foreach ($providers as $providerClass => $provider) { if ($isEditing && $fields['source'] !== call_user_func(array($providerClass, 'getSource'))) { continue; } call_user_func_array(array($providerClass, 'buildEditor'), array($this->Form, &$this->_errors, $fields, $handle)); } } } else { // Author if (isset($about['author']['website'])) { $link = Widget::Anchor($about['author']['name'], General::validateURL($about['author']['website'])); } elseif (isset($about['author']['email'])) { $link = Widget::Anchor($about['author']['name'], 'mailto:' . $about['author']['email']); } else { $link = $about['author']['name']; } if ($link) { $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Author'))); $fieldset->appendChild(new XMLElement('p', $link->generate(false))); $this->Form->appendChild($fieldset); } // Version $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings'); $fieldset->appendChild(new XMLElement('legend', __('Version'))); $version = array_key_exists('version', $about) ? $about['version'] : null; $release_date = array_key_exists('release-date', $about) ? $about['release-date'] : filemtime(EventManager::__getDriverPath($handle)); if (preg_match('/^\\d+(\\.\\d+)*$/', $version)) { $fieldset->appendChild(new XMLElement('p', __('%1$s released on %2$s', array($version, DateTimeObj::format($release_date, __SYM_DATE_FORMAT__))))); } elseif (!is_null($version)) { $fieldset->appendChild(new XMLElement('p', __('Created by %1$s at %2$s', array($version, DateTimeObj::format($release_date, __SYM_DATE_FORMAT__))))); } else { $fieldset->appendChild(new XMLElement('p', __('Last modified on %s', array(DateTimeObj::format($release_date, __SYM_DATE_FORMAT__))))); } $this->Form->appendChild($fieldset); } // If we are editing an event, it assumed that the event has documentation $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('id', 'event-documentation'); $fieldset->setAttribute('class', 'settings'); if ($isEditing && method_exists($existing, 'documentation')) { $doc = $existing->documentation(); if ($doc) { $fieldset->setValue('<legend>' . __('Documentation') . '</legend>' . PHP_EOL . General::tabsToSpaces(is_object($doc) ? $doc->generate(true, 4) : $doc)); } } $this->Form->appendChild($fieldset); $div = new XMLElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Input('action[save]', $isEditing ? __('Save Changes') : __('Create Event'), 'submit', array('accesskey' => 's'))); if ($isEditing) { $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this event'), 'type' => 'submit', 'accesskey' => 'd', 'data-message' => __('Are you sure you want to delete this event?'))); $div->appendChild($button); } if (!$readonly) { $this->Form->appendChild($div); } }
<?php /*** * * Symphony web publishing system * * Copyright 2004–2006 Twenty One Degrees Pty. Ltd. * * @version 1.7 * @licence https://github.com/symphonycms/symphony-1.7/blob/master/LICENCE * ***/ $EM = new EventManager(array('parent' => &$Admin)); $oEvent =& $EM->create($_REQUEST['file']); $about = $oEvent->about(); $GLOBALS['pageTitle'] = 'Events > ' . $about['name']; $date = $Admin->getDateObj(); $link = $about['author']['name']; if (isset($about['author']['website'])) { $link = '<a href="' . General::validateURL($about['author']['website']) . '">' . $about['author']['name'] . '</a>'; } elseif (isset($about['author']['email'])) { $link = '<a href="mailto:' . $about['author']['email'] . '">' . $about['author']['name'] . '</a>'; } ?> <form id="controller" action="" method="post"> <h2><?php print $about['name']; ?> </h2>
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); } }
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 EventManager() { return $this->_event_manager ? $this->_event_manager : ($this->_event_manager = EventManager::create($this)); }
public function __viewEdit() { $isNew = true; $time = Widget::Time(); // Verify role exists if ($this->_context[0] == 'edit') { $isNew = false; if (!($role_id = $this->_context[1])) { redirect(extension_Members::baseURL() . 'roles/'); } if (!($existing = RoleManager::fetch($role_id))) { throw new SymphonyErrorPage(__('The role you requested to edit does not exist.'), __('Role not found')); } } // Add in custom assets Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/members/assets/members.roles.css', 'screen', 101); Administration::instance()->Page->addScriptToHead(URL . '/extensions/members/assets/members.roles.js', 104); // Append any Page Alerts from the form's if (isset($this->_context[2])) { switch ($this->_context[2]) { case 'saved': $this->pageAlert(__('Role updated at %s.', array($time->generate())) . ' <a href="' . extension_members::baseURL() . 'roles/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . extension_members::baseURL() . 'roles/" accesskey="a">' . __('View all Roles') . '</a>', Alert::SUCCESS); break; case 'created': $this->pageAlert(__('Role created at %s.', array($time->generate())) . ' <a href="' . extension_members::baseURL() . 'roles/new/" accesskey="c">' . __('Create another?') . '</a> <a href="' . extension_members::baseURL() . 'roles/" accesskey="a">' . __('View all Roles') . '</a>', Alert::SUCCESS); break; } } // Has the form got any errors? $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); } $this->setPageType('form'); if ($isNew) { $this->setTitle(__('Symphony – Member Roles')); $this->appendSubheading(__('Untitled')); $fields = array('name' => null, 'permissions' => null, 'page_access' => null); } else { $this->setTitle(__('Symphony – Member Roles – ') . $existing->get('name')); $this->appendSubheading($existing->get('name')); if (isset($_POST['fields'])) { $fields = $_POST['fields']; } else { $fields = array('name' => $existing->get('name'), 'permissions' => $existing->get('event_permissions'), 'page_access' => $existing->get('forbidden_pages')); } } $this->insertBreadcrumbs(array(Widget::Anchor(__('Member Roles'), extension_members::baseURL() . 'roles/'))); $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::Error($label, $this->_errors['name'])); } else { $fieldset->appendChild($label); } $this->Form->appendChild($fieldset); $events = EventManager::listAll(); $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings type-file'); $fieldset->appendChild(new XMLElement('legend', __('Event Level Permissions'))); $aTableBody = array(); if (is_array($events) && !empty($events)) { foreach ($events as $event_handle => $event) { $permissions = $fields['permissions'][$event_handle]; $td_name = Widget::TableData($event['name'], 'name'); $td_permission_create = Widget::TableData(sprintf('<label title="%s">%s <span>%s</span></label>', __('User can create new entries'), Widget::Input("fields[permissions][{$event_handle}][create]", (string) EventPermissions::CREATE, 'checkbox', $permissions['create'] == EventPermissions::CREATE ? array('checked' => 'checked') : NULL)->generate(), 'Create'), 'create'); $td_permission_none = Widget::TableData(sprintf('<label title="%s">%s <span>%s</span></label>', __('User cannot edit existing entries'), Widget::Input("fields[permissions][{$event_handle}][edit]", (string) EventPermissions::NO_PERMISSIONS, 'radio', $permissions['edit'] == EventPermissions::NO_PERMISSIONS ? array('checked' => 'checked') : NULL)->generate(), 'None')); $td_permission_own = Widget::TableData(sprintf('<label title="%s">%s <span>%s</span></label>', __('User can edit their own entries only'), Widget::Input("fields[permissions][{$event_handle}][edit]", (string) EventPermissions::OWN_ENTRIES, 'radio', $permissions['edit'] == EventPermissions::OWN_ENTRIES ? array('checked' => 'checked') : NULL)->generate(), 'Own')); $td_permission_all = Widget::TableData(sprintf('<label title="%s">%s <span>%s</span></label>', __('User can edit all entries'), Widget::Input("fields[permissions][{$event_handle}][edit]", (string) EventPermissions::ALL_ENTRIES, 'radio', $permissions['edit'] == EventPermissions::ALL_ENTRIES ? array('checked' => 'checked') : NULL)->generate(), 'All')); // Create an Event instance $ev = EventManager::create($event_handle, array()); $aTableBody[] = Widget::TableRow(array($td_name, $td_permission_create, $td_permission_none, $td_permission_own, $td_permission_all), method_exists($ev, 'ignoreRolePermissions') && $ev->ignoreRolePermissions() == true ? 'inactive' : ''); unset($ev); } } $thead = Widget::TableHead(array(array(__('Event'), 'col', array('class' => 'name')), array(__('Create New'), 'col', array('class' => 'new', 'title' => __('Toggle all'))), array(__('No Edit'), 'col', array('class' => 'edit', 'title' => __('Toggle all'))), array(__('Edit Own'), 'col', array('class' => 'edit', 'title' => __('Toggle all'))), array(__('Edit All'), 'col', array('class' => 'edit', 'title' => __('Toggle all'))))); $table = Widget::Table($thead, NULL, Widget::TableBody($aTableBody), 'role-permissions'); $fieldset->appendChild($table); $this->Form->appendChild($fieldset); // Add Page Permissions [simple Deny/Allow] $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings type-file'); $fieldset->appendChild(new XMLElement('legend', __('Page Level Permissions'))); $label = Widget::Label(__('Deny Access')); if (!is_array($fields['page_access'])) { $fields['page_access'] = array(); } $options = array(); $pages = PageManager::fetch(false, array('id')); if (!empty($pages)) { foreach ($pages as $page) { $options[] = array($page['id'], in_array($page['id'], $fields['page_access']), '/' . PageManager::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'))); if (!$isNew && $existing->get('id') != Role::PUBLIC_ROLE) { $button = new XMLElement('button', __('Delete')); $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'button confirm delete', 'title' => __('Delete this Role'), 'type' => 'submit', 'accesskey' => 'd')); $div->appendChild($button); } $this->Form->appendChild($div); }
public function preInjectXML($context) { $EventManager = new EventManager($this->_Parent); // we have to load the events twice to look for a lock-entry event attached if (strlen(trim($context['events'])) > 0) { $events = preg_split('/,\\s*/i', $context['events'], -1, PREG_SPLIT_NO_EMPTY); $events = array_map('trim', $events); if (!is_array($events) || empty($events)) { return; } foreach ($events as $handle) { $event = $EventManager->create($handle); if ($event->eParamFILTERS && in_array("lock-entry", $event->eParamFILTERS)) { $this->locked = true; return; } } } }
/** * @covers ::create * @covers ::observe */ public function testCreate() { $this->cnt = 0; $em = EventManager::create(); return $em; }