Ejemplo n.º 1
0
 /**
  * \param $title the title for the page
  * \param $equiv_url the equivalent URL on Stack Exchange
  * \param $site the site for the current page
  *
  * Note: it is important to call this method since it also sets a number of
  * special view variables that the main template uses.
  */
 protected function SetPageInfo($title, $equiv_url = null, $site = null)
 {
     // Expose the document root as a view variable
     $this->SetViewVariable('document_root', URLManager::GetDocumentRoot());
     // Provide the view with access to the current page URL
     $this->SetViewVariable('page_url', URLManager::$current_url);
     // If the site is provided, include it in the view variables and substitute
     // the information in some of the other fields.
     if ($site !== null) {
         // Retrieve the site information from the API
         $this->site = API::Site($site)->Info()->Filter(new Filter('!-q8LLJA7'))->Exec()->Fetch();
         // Pass on the site name and API parameter to the views
         $this->SetViewVariable('site', $this->site['site']['api_site_parameter']);
         $this->SetViewVariable('site_name', $this->site['site']['name']);
         $this->SetViewVariable('site_prefix', URLManager::GetDocumentRoot() . '/' . $this->site['site']['api_site_parameter']);
         // Replace '{name}' in page title with the site name
         $title = str_replace('{name}', $this->site['site']['name'], $title);
         // Do the same for the page's equivalent URL
         if ($equiv_url !== null) {
             $equiv_url = str_replace('{url}', $this->site['site']['site_url'], $equiv_url);
         }
     }
     // Set the page title and equivalent URL
     $this->SetViewVariable('page_title', $title);
     if ($equiv_url !== null) {
         $this->SetViewVariable('equiv_url', $equiv_url);
     }
 }
Ejemplo n.º 2
0
 public function Go()
 {
     // Determine whether we can use the default template for displaying errors
     $have_template = is_file('views/template.inc') === TRUE;
     // Everything below is wrapped in a try block that captures
     // any errors that the methods below throw. This allows us to
     // try to display an error page.
     try {
         // Ensure the requirements are met
         $this->CheckRequirements();
         // Initialize the path
         $this->ParsePath();
         // Run the controller
         $view_variables = $this->RunController();
         // As long as $view_variables isn't null, then
         // we display the view.
         if ($view_variables !== null) {
             $this->DisplayView($view_variables);
         }
     } catch (Exception $e) {
         if ($have_template) {
             // Get the document root
             $document_root = URLManager::GetDocumentRoot();
             // Display the default template file with the error
             $page_contents = '<h2>An Error Has Occurred</h2>';
             $page_contents .= $e->getMessage();
             $page_contents .= "<p>If you are seeing this error instead of the page you were looking for, try visiting the <a href='/{$document_root}'>home page</a>.</p>";
             global $config;
             header("Status: 503 Server Error");
             require 'views/template.inc';
         } else {
             echo $e->getMessage();
         }
     }
 }