public function __actionEdit() { if ($this->_context[0] != 'new' && !($page_id = (int) $this->_context[1])) { redirect(SYMPHONY_URL . '/blueprints/pages/'); } $parent_link_suffix = NULL; if (isset($_REQUEST['parent']) && is_numeric($_REQUEST['parent'])) { $parent_link_suffix = '?parent=' . $_REQUEST['parent']; } if (@array_key_exists('delete', $_POST['action'])) { $this->__actionDelete($page_id, SYMPHONY_URL . '/blueprints/pages/' . $parent_link_suffix); } if (@array_key_exists('save', $_POST['action'])) { $fields = $_POST['fields']; $this->_errors = array(); $autogenerated_handle = false; if (!isset($fields['title']) || trim($fields['title']) == '') { $this->_errors['title'] = __('This is a required field'); } if (trim($fields['type']) != '' && preg_match('/(index|404|403)/i', $fields['type'])) { $types = preg_split('/\\s*,\\s*/', strtolower($fields['type']), -1, PREG_SPLIT_NO_EMPTY); if (in_array('index', $types) && PageManager::hasPageTypeBeenUsed($page_id, 'index')) { $this->_errors['type'] = __('An index type page already exists.'); } elseif (in_array('404', $types) && PageManager::hasPageTypeBeenUsed($page_id, '404')) { $this->_errors['type'] = __('A 404 type page already exists.'); } elseif (in_array('403', $types) && PageManager::hasPageTypeBeenUsed($page_id, '403')) { $this->_errors['type'] = __('A 403 type page already exists.'); } } if (trim($fields['handle']) == '') { $fields['handle'] = $fields['title']; $autogenerated_handle = true; } $fields['handle'] = PageManager::createHandle($fields['handle']); if (empty($fields['handle']) && !isset($this->_errors['title'])) { $this->_errors['handle'] = __('Please ensure handle contains at least one Latin-based character.'); } /** * Just after the Symphony validation has run, allows Developers * to run custom validation logic on a Page * * @delegate PagePostValidate * @since Symphony 2.2 * @param string $context * '/blueprints/pages/' * @param array $fields * The `$_POST['fields']` array. This should be read-only and not changed * through this delegate. * @param array $errors * An associative array of errors, with the key matching a key in the * `$fields` array, and the value being the string of the error. `$errors` * is passed by reference. */ Symphony::ExtensionManager()->notifyMembers('PagePostValidate', '/blueprints/pages/', array('fields' => $fields, 'errors' => &$errors)); if (empty($this->_errors)) { $autogenerated_handle = false; if ($fields['params']) { $fields['params'] = trim(preg_replace('@\\/{2,}@', '/', $fields['params']), '/'); } // Clean up type list $types = preg_split('/\\s*,\\s*/', $fields['type'], -1, PREG_SPLIT_NO_EMPTY); $types = @array_map('trim', $types); unset($fields['type']); $fields['parent'] = $fields['parent'] != __('None') ? $fields['parent'] : null; $fields['data_sources'] = is_array($fields['data_sources']) ? implode(',', $fields['data_sources']) : NULL; $fields['events'] = is_array($fields['events']) ? implode(',', $fields['events']) : NULL; $fields['path'] = null; if ($fields['parent']) { $fields['path'] = PageManager::resolvePagePath((int) $fields['parent']); } // Check for duplicates: $current = PageManager::fetchPageByID($page_id); if (empty($current)) { $fields['sortorder'] = PageManager::fetchNextSortOrder(); } $where = array(); if (!empty($current)) { $where[] = "p.id != {$page_id}"; } $where[] = "p.handle = '" . $fields['handle'] . "'"; $where[] = is_null($fields['path']) ? "p.path IS NULL" : "p.path = '" . $fields['path'] . "'"; $duplicate = PageManager::fetch(false, array('*'), $where); // If duplicate if (!empty($duplicate)) { if ($autogenerated_handle) { $this->_errors['title'] = __('A page with that title already exists'); } else { $this->_errors['handle'] = __('A page with that handle already exists'); } } else { // New page? if (empty($current)) { $file_created = PageManager::createPageFiles($fields['path'], $fields['handle']); } else { $file_created = PageManager::createPageFiles($fields['path'], $fields['handle'], $current['path'], $current['handle']); } // If the file wasn't created, it's usually permissions related if (!$file_created) { $redirect = null; return $this->pageAlert(__('Page Template could not be written to disk.') . ' ' . __('Please check permissions on %s.', array('<code>/workspace/pages</code>')), Alert::ERROR); } // Insert the new data: if (empty($current)) { /** * Just prior to creating a new Page record in `tbl_pages`, provided * with the `$fields` associative array. Use with caution, as no * duplicate page checks are run after this delegate has fired * * @delegate PagePreCreate * @since Symphony 2.2 * @param string $context * '/blueprints/pages/' * @param array $fields * The `$_POST['fields']` array passed by reference */ Symphony::ExtensionManager()->notifyMembers('PagePreCreate', '/blueprints/pages/', array('fields' => &$fields)); if (!($page_id = PageManager::add($fields))) { $this->pageAlert(__('Unknown errors occurred while attempting to save.') . '<a href="' . SYMPHONY_URL . '/system/log/">' . __('Check your activity log') . '</a>.', Alert::ERROR); } else { /** * Just after the creation of a new page in `tbl_pages` * * @delegate PagePostCreate * @since Symphony 2.2 * @param string $context * '/blueprints/pages/' * @param integer $page_id * The ID of the newly created Page * @param array $fields * An associative array of data that was just saved for this page */ Symphony::ExtensionManager()->notifyMembers('PagePostCreate', '/blueprints/pages/', array('page_id' => $page_id, 'fields' => &$fields)); $redirect = "/blueprints/pages/edit/{$page_id}/created/{$parent_link_suffix}"; } } else { /** * Just prior to updating a Page record in `tbl_pages`, provided * with the `$fields` associative array. Use with caution, as no * duplicate page checks are run after this delegate has fired * * @delegate PagePreEdit * @since Symphony 2.2 * @param string $context * '/blueprints/pages/' * @param integer $page_id * The ID of the Page that is about to be updated * @param array $fields * The `$_POST['fields']` array passed by reference */ Symphony::ExtensionManager()->notifyMembers('PagePreEdit', '/blueprints/pages/', array('page_id' => $page_id, 'fields' => &$fields)); if (!PageManager::edit($page_id, $fields, true)) { return $this->pageAlert(__('Unknown errors occurred while attempting to save.') . '<a href="' . SYMPHONY_URL . '/system/log/">' . __('Check your activity log') . '</a>.', Alert::ERROR); } else { /** * Just after updating a page in `tbl_pages` * * @delegate PagePostEdit * @since Symphony 2.2 * @param string $context * '/blueprints/pages/' * @param integer $page_id * The ID of the Page that was just updated * @param array $fields * An associative array of data that was just saved for this page */ Symphony::ExtensionManager()->notifyMembers('PagePostEdit', '/blueprints/pages/', array('page_id' => $page_id, 'fields' => $fields)); $redirect = "/blueprints/pages/edit/{$page_id}/saved/{$parent_link_suffix}"; } } } // Only proceed if there was no errors saving/creating the page if (empty($this->_errors)) { /** * Just before the page's types are saved into `tbl_pages_types`. * Use with caution as no further processing is done on the `$types` * array to prevent duplicate `$types` from occurring (ie. two index * page types). Your logic can use the PageManger::hasPageTypeBeenUsed * function to perform this logic. * * @delegate PageTypePreCreate * @since Symphony 2.2 * @see toolkit.PageManager#hasPageTypeBeenUsed * @param string $context * '/blueprints/pages/' * @param integer $page_id * The ID of the Page that was just created or updated * @param array $types * An associative array of the types for this page passed by reference. */ Symphony::ExtensionManager()->notifyMembers('PageTypePreCreate', '/blueprints/pages/', array('page_id' => $page_id, 'types' => &$types)); // Assign page types: PageManager::addPageTypesToPage($page_id, $types); // Find and update children: if ($this->_context[0] == 'edit') { PageManager::editPageChildren($page_id, $fields['path'] . '/' . $fields['handle']); } if ($redirect) { redirect(SYMPHONY_URL . $redirect); } } } // If there was any errors, either with pre processing or because of a // duplicate page, return. if (is_array($this->_errors) && !empty($this->_errors)) { return $this->pageAlert(__('An error occurred while processing this form. See below for details.'), Alert::ERROR); } } }
public function __viewIndexDSPages($context) { $pages = PageManager::fetch(false, array(), array(), 'sortorder ASC'); $options = array(); foreach ($pages as $page) { $selected = $this->driver->isDSPageSelected($page['id']); $options[] = array($page['id'], $selected, '/' . PageManager::resolvePagePath($page['id'])); } $section = Widget::Label(__('Excluded Pages')); $section->setAttribute('class', 'column'); $section->appendChild(Widget::Select('settings[ds-pages][]', $options, array('multiple' => 'multiple'))); $context->appendChild($section); }
/** * The render function will take a `FrontendPageNotFoundException` Exception and * output a HTML page. This function first checks to see if their is a page in Symphony * that has been given the '404' page type, otherwise it will just use the default * Symphony error page template to output the exception * * @param FrontendPageNotFoundException $e * The Exception object * @return string * An HTML string */ public static function render(Exception $e) { $page = PageManager::fetchPageByType('404'); if (is_null($page['id'])) { parent::render(new SymphonyErrorPage($e->getMessage(), __('Page Not Found'), 'generic', array('header' => 'HTTP/1.0 404 Not Found'))); } else { $url = '/' . PageManager::resolvePagePath($page['id']) . '/'; $output = Frontend::instance()->display($url); header(sprintf('Content-Length: %d', strlen($output))); echo $output; exit; } }
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); }
/** * The render function will take a `FrontendPageNotFoundException` Exception and * output a HTML page. This function first checks to see if their is a page in Symphony * that has been given the '404' page type, otherwise it will just use the default * Symphony error page template to output the exception * * @param Exception $e * The Exception object * @throws FrontendPageNotFoundException * @throws SymphonyErrorPage * @return string * An HTML string */ public static function render(Exception $e) { $page = PageManager::fetchPageByType('404'); $previous_exception = Frontend::instance()->getException(); // No 404 detected, throw default Symphony error page if (is_null($page['id'])) { parent::render(new SymphonyErrorPage($e->getMessage(), __('Page Not Found'), 'generic', array(), Page::HTTP_STATUS_NOT_FOUND)); // Recursive 404 } elseif (isset($previous_exception)) { parent::render(new SymphonyErrorPage(__('This error occurred whilst attempting to resolve the 404 page for the original request.') . ' ' . $e->getMessage(), __('Page Not Found'), 'generic', array(), Page::HTTP_STATUS_NOT_FOUND)); // Handle 404 page } else { $url = '/' . PageManager::resolvePagePath($page['id']) . '/'; Frontend::instance()->setException($e); $output = Frontend::instance()->display($url); echo $output; exit; } }