function indexAction() { $this->setLayout('shares'); $id = intVal($this->getParam('id')); $this->load->model('item'); $item = $this->item->get(array('id' => $id), true); if (!$item) { $this->forward404($id); } $this->frontend->addExtGroup('toolbar', $this->isIE()); $user_id = 0; $ip = $_SERVER['REMOTE_ADDR']; if ($this->auth->isLogged()) { $this->setLayoutVar('logged_in', true); $user = $this->auth->getUser(); $user_id = $user->id; $this->load->model('viewed_post'); $newView = $this->viewed_post->addViewedPost($item->item_sid, $user_id, $ip); if ($newView) { $this->item->increaseItemViewed($id); } header('Location: ' . $item->link); } else { $this->setLayoutVar('logged_in', false); } $URLManager = new URLManager(); $og_metas = $URLManager->grabOGMeta($item->link); $this->setLayoutVar('og_metas', $og_metas); $this->setLayoutVar('item', $item); }
/** * \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); } }
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(); } } }