コード例 #1
0
 /**
  * This function initialises a lot of the basic elements that make up a Symphony
  * backend page such as the default stylesheets and scripts, the navigation and
  * the footer. Any alerts are also appended by this function. `view()` is called to
  * build the actual content of the page. The `InitialiseAdminPageHead` delegate
  * allows extensions to add elements to the `<head>`.
  *
  * @see view()
  * @uses InitialiseAdminPageHead
  * @param array $context
  *  An associative array describing this pages context. This
  *  can include the section handle, the current entry_id, the page
  *  name and any flags such as 'saved' or 'created'. This list is not exhaustive
  *  and extensions can add their own keys to the array.
  * @throws InvalidArgumentException
  * @throws SymphonyErrorPage
  */
 public function build(array $context = array())
 {
     $this->_context = $context;
     if (!$this->canAccessPage()) {
         Administration::instance()->throwCustomError(__('You are not authorised to access this page.'), __('Access Denied'), Page::HTTP_STATUS_UNAUTHORIZED);
     }
     $this->Html->setDTD('<!DOCTYPE html>');
     $this->Html->setAttribute('lang', Lang::get());
     $this->addElementToHead(new XMLElement('meta', null, array('charset' => 'UTF-8')), 0);
     $this->addElementToHead(new XMLElement('meta', null, array('http-equiv' => 'X-UA-Compatible', 'content' => 'IE=edge,chrome=1')), 1);
     $this->addElementToHead(new XMLElement('meta', null, array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1')), 2);
     // Add styles
     $this->addStylesheetToHead(ASSETS_URL . '/css/symphony.min.css', 'screen', 2, false);
     // Calculate timezone offset from UTC
     $timezone = new DateTimeZone(Symphony::Configuration()->get('timezone', 'region'));
     $datetime = new DateTime('now', $timezone);
     $timezoneOffset = intval($timezone->getOffset($datetime)) / 60;
     // Add scripts
     $environment = array('root' => URL, 'symphony' => SYMPHONY_URL, 'path' => '/' . Symphony::Configuration()->get('admin-path', 'symphony'), 'route' => getCurrentPage(), 'version' => Symphony::Configuration()->get('version', 'symphony'), 'lang' => Lang::get(), 'user' => array('fullname' => Symphony::Author()->getFullName(), 'name' => Symphony::Author()->get('first_name'), 'type' => Symphony::Author()->get('user_type'), 'id' => Symphony::Author()->get('id')), 'datetime' => array('formats' => DateTimeObj::getDateFormatMappings(), 'timezone-offset' => $timezoneOffset), 'env' => array_merge(array('page-namespace' => Symphony::getPageNamespace()), $this->_context));
     $this->addElementToHead(new XMLElement('script', json_encode($environment), array('type' => 'application/json', 'id' => 'environment')), 4);
     $this->addScriptToHead(ASSETS_URL . '/js/symphony.min.js', 6, false);
     // Initialise page containers
     $this->Wrapper = new XMLElement('div', null, array('id' => 'wrapper'));
     $this->Header = new XMLElement('header', null, array('id' => 'header'));
     $this->Context = new XMLElement('div', null, array('id' => 'context'));
     $this->Breadcrumbs = new XMLElement('div', null, array('id' => 'breadcrumbs'));
     $this->Contents = new XMLElement('div', null, array('id' => 'contents', 'role' => 'main'));
     $this->Form = Widget::Form(Administration::instance()->getCurrentPageURL(), 'post', null, null, array('role' => 'form'));
     /**
      * Allows developers to insert items into the page HEAD. Use
      * `Administration::instance()->Page` for access to the page object.
      *
      * @since In Symphony 2.3.2 this delegate was renamed from
      *  `InitaliseAdminPageHead` to the correct spelling of
      *  `InitialiseAdminPageHead`. The old delegate is supported
      *  until Symphony 3.0
      *
      * @delegate InitialiseAdminPageHead
      * @param string $context
      *  '/backend/'
      */
     Symphony::ExtensionManager()->notifyMembers('InitialiseAdminPageHead', '/backend/');
     Symphony::ExtensionManager()->notifyMembers('InitaliseAdminPageHead', '/backend/');
     $this->addHeaderToPage('Content-Type', 'text/html; charset=UTF-8');
     $this->addHeaderToPage('Cache-Control', 'no-cache, must-revalidate, max-age=0');
     $this->addHeaderToPage('Expires', 'Mon, 12 Dec 1982 06:14:00 GMT');
     $this->addHeaderToPage('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT');
     $this->addHeaderToPage('Pragma', 'no-cache');
     // If not set by another extension, lock down the backend
     if (!array_key_exists('x-frame-options', $this->headers())) {
         $this->addHeaderToPage('X-Frame-Options', 'SAMEORIGIN');
     }
     if (!array_key_exists('access-control-allow-origin', $this->headers())) {
         $this->addHeaderToPage('Access-Control-Allow-Origin', URL);
     }
     if (isset($_REQUEST['action'])) {
         $this->action();
         Symphony::Profiler()->sample('Page action run', PROFILE_LAP);
     }
     $h1 = new XMLElement('h1');
     $h1->appendChild(Widget::Anchor(Symphony::Configuration()->get('sitename', 'general'), rtrim(URL, '/') . '/'));
     $this->Header->appendChild($h1);
     $this->appendUserLinks();
     $this->appendNavigation();
     // Add Breadcrumbs
     $this->Context->prependChild($this->Breadcrumbs);
     $this->Contents->appendChild($this->Form);
     $this->view();
     $this->appendAlert();
     Symphony::Profiler()->sample('Page content created', PROFILE_LAP);
 }