コード例 #1
0
 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 &ndash; %2$s &ndash; %3$s' : '%2$s &ndash; %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'])));
     }
 }
コード例 #2
0
 /**
  * Resolves the path to this page's XSLT file. The Symphony convention
  * is that they are stored in the `PAGES` folder. If this page has a parent
  * it will be as if all the / in the URL have been replaced with _. ie.
  * /articles/read/ will produce a file `articles_read.xsl`
  *
  * @see toolkit.PageManager#createFilePath()
  * @param string $path
  *  The URL path to this page, excluding the current page. ie, /articles/read
  *  would make `$path` become articles/
  * @param string $handle
  *  The handle of the page.
  * @return string
  *  The path to the XSLT of the page
  */
 public static function resolvePageFileLocation($path, $handle)
 {
     return PAGES . '/' . PageManager::createFilePath($path, $handle) . '.xsl';
 }
コード例 #3
0
 public function __viewIndex()
 {
     $this->setPageType('table');
     $this->setTitle(__('%1$s &ndash; %2$s', array(__('Pages'), __('Symphony'))));
     $nesting = Symphony::Configuration()->get('pages_table_nest_children', 'symphony') == 'yes';
     if ($nesting && isset($_GET['parent']) && is_numeric($_GET['parent'])) {
         $parent = PageManager::fetchPageByID((int) $_GET['parent'], array('title', 'id'));
     }
     $this->appendSubheading(isset($parent) ? $parent['title'] : __('Pages'), Widget::Anchor(__('Create New'), Administration::instance()->getCurrentPageURL() . 'new/' . ($nesting && isset($parent) ? "?parent={$parent['id']}" : null), __('Create a new page'), 'create button', null, array('accesskey' => 'c')));
     if (isset($parent)) {
         $this->insertBreadcrumbsUsingPageIdentifier($parent['id'], false);
     }
     $aTableHead = array(array(__('Name'), 'col'), array(__('Template'), 'col'), array('<abbr title="' . __('Universal Resource Locator') . '">' . __('URL') . '</abbr>', 'col'), array(__('Parameters'), 'col'), array(__('Type'), 'col'));
     $aTableBody = array();
     if ($nesting) {
         $aTableHead[] = array(__('Children'), 'col');
         $where = array('parent ' . (isset($parent) ? " = {$parent['id']} " : ' IS NULL '));
     } else {
         $where = array();
     }
     $pages = PageManager::fetch(true, array('*'), $where);
     if (!is_array($pages) || empty($pages)) {
         $aTableBody = array(Widget::TableRow(array(Widget::TableData(__('None found.'), 'inactive', null, count($aTableHead))), 'odd'));
     } else {
         foreach ($pages as $page) {
             $class = array();
             $page_title = $nesting ? $page['title'] : PageManager::resolvePageTitle($page['id']);
             $page_url = URL . '/' . PageManager::resolvePagePath($page['id']) . '/';
             $page_edit_url = Administration::instance()->getCurrentPageURL() . 'edit/' . $page['id'] . '/';
             $page_template = PageManager::createFilePath($page['path'], $page['handle']);
             $col_title = Widget::TableData(Widget::Anchor($page_title, $page_edit_url, $page['handle']));
             $col_title->appendChild(Widget::Label(__('Select Page %s', array($page_title)), null, 'accessible', null, array('for' => 'page-' . $page['id'])));
             $col_title->appendChild(Widget::Input('items[' . $page['id'] . ']', 'on', 'checkbox', array('id' => 'page-' . $page['id'])));
             $col_template = Widget::TableData($page_template . '.xsl');
             $col_url = Widget::TableData(Widget::Anchor($page_url, $page_url));
             if ($page['params']) {
                 $col_params = Widget::TableData(trim($page['params'], '/'));
             } else {
                 $col_params = Widget::TableData(__('None'), 'inactive');
             }
             if (!empty($page['type'])) {
                 $col_types = Widget::TableData(implode(', ', $page['type']));
             } else {
                 $col_types = Widget::TableData(__('None'), 'inactive');
             }
             if (in_array($page['id'], $this->_hilights)) {
                 $class[] = 'failed';
             }
             $columns = array($col_title, $col_template, $col_url, $col_params, $col_types);
             if ($nesting) {
                 if (PageManager::hasChildPages($page['id'])) {
                     $col_children = Widget::TableData(Widget::Anchor(PageManager::getChildPagesCount($page['id']) . ' &rarr;', SYMPHONY_URL . '/blueprints/pages/?parent=' . $page['id']));
                 } else {
                     $col_children = Widget::TableData(__('None'), 'inactive');
                 }
                 $columns[] = $col_children;
             }
             $aTableBody[] = Widget::TableRow($columns, implode(' ', $class));
         }
     }
     $table = Widget::Table(Widget::TableHead($aTableHead), null, Widget::TableBody($aTableBody), 'orderable selectable', null, array('role' => 'directory', 'aria-labelledby' => 'symphony-subheading', 'data-interactive' => 'data-interactive'));
     $this->Form->appendChild($table);
     $version = new XMLElement('p', 'Symphony ' . Symphony::Configuration()->get('version', 'symphony'), array('id' => 'version'));
     $this->Form->appendChild($version);
     $tableActions = new XMLElement('div');
     $tableActions->setAttribute('class', 'actions');
     $options = array(array(null, false, __('With Selected...')), array('delete', false, __('Delete'), 'confirm', null, array('data-message' => __('Are you sure you want to delete the selected pages?'))));
     /**
      * Allows an extension to modify the existing options for this page's
      * With Selected menu. If the `$options` parameter is an empty array,
      * the 'With Selected' menu will not be rendered.
      *
      * @delegate AddCustomActions
      * @since Symphony 2.3.2
      * @param string $context
      * '/blueprints/pages/'
      * @param array $options
      *  An array of arrays, where each child array represents an option
      *  in the With Selected menu. Options should follow the same format
      *  expected by `Widget::__SelectBuildOption`. Passed by reference.
      */
     Symphony::ExtensionManager()->notifyMembers('AddCustomActions', '/blueprints/pages/', array('options' => &$options));
     if (!empty($options)) {
         $tableActions->appendChild(Widget::Apply($options));
         $this->Form->appendChild($tableActions);
     }
 }