Skip to content

Instantly share code, notes, and snippets.

@lytithwyn
Created March 3, 2011 14:15
Show Gist options
  • Save lytithwyn/852824 to your computer and use it in GitHub Desktop.
Save lytithwyn/852824 to your computer and use it in GitHub Desktop.
<?php
$pageOutput = "";
try
{
if(!isset($_GET['page_name']) || empty($_GET['page_name'])) throw(new UserErrorException("This page received an invalid request."));
$database = mysql_db::get();
$pageName = $_GET['page_name'];
$safePageName = $database->escape($pageName);
//page names aren't allowed to have special characters
if($safePageName !== $pageName) throw(new UserErrorException("This page received an invalid request."));
$page = $myContentManager->getPageByName($safePageName);
$myContentManager->assignSmartyFieldsForPage($page, $smarty);
$pageOutput = $smarty->fetch($page->template . ".tpl");
} catch(RuntimeException $e) {
$log = new log("page_loader");
$log->logMessage(new message(MESSAGE_ERROR, "Page Loader", "Loading page", $e->getMessage()));
$errorMessage = "";
if($e instanceof UserErrorException)
{
$errorMessage = $e->getMessage();
} else {
//we do this to hide potentially dangerous info from the user (aka, database layout, etc.)
$errorMessage = "An unresolved error has occurred. Please try back later.";
}
$smarty->assign("error_message", $errorMessage);
$pageOutput = $smarty->fetch("error.tpl");
}
print($pageOutput);
?>
<?php
ob_clean();
$smarty->assign("error_message", $errorMessage);
$pageOutput = $smarty->fetch("error.tpl");
?>
<?php
public function fetch($templateName) {
ob_start();
parseTheTemplate($templateName);
return ob_get_clean();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment