Created
March 3, 2011 14:15
-
-
Save lytithwyn/852824 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ob_clean(); | |
$smarty->assign("error_message", $errorMessage); | |
$pageOutput = $smarty->fetch("error.tpl"); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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