Added support for redirects in Page class
This commit is contained in:
@@ -13,6 +13,7 @@ class HandBrakeCluster_Exception_ConfigException extends HandBrakeCluster
|
||||
class HandBrakeCluster_Exception_UnknownSetting extends HandBrakeCluster_Exception_ConfigException {};
|
||||
|
||||
class HandBrakeCluster_Exception_TemplateException extends HandBrakeCluster_Exception {};
|
||||
class HandBrakeCluster_Exception_AbortEntirePage extends HandBrakeCluster_Exception_TemplateException {};
|
||||
class HandBrakeCluster_Exception_Unauthorized extends HandBrakeCluster_Exception_TemplateException {};
|
||||
class HandBrakeCluster_Exception_FileNotFound extends HandBrakeCluster_Exception_TemplateException {};
|
||||
class HandBrakeCluster_Exception_InvalidParameters extends HandBrakeCluster_Exception_TemplateException {};
|
||||
|
||||
@@ -12,6 +12,8 @@ class HandBrakeCluster_Main {
|
||||
private $log;
|
||||
private $request;
|
||||
private $cache;
|
||||
|
||||
private $base_uri;
|
||||
|
||||
private function __construct() {
|
||||
$request_string = isset($_GET['l']) ? $_GET['l'] : '';
|
||||
@@ -31,10 +33,16 @@ class HandBrakeCluster_Main {
|
||||
$this->smarty->config_fir = './config';
|
||||
|
||||
$this->smarty->assign('version', '0.1');
|
||||
$this->smarty->assign('base_uri', dirname($_SERVER['SCRIPT_NAME']) . '/');
|
||||
|
||||
$this->base_uri = dirname($_SERVER['SCRIPT_NAME']) . '/';
|
||||
$this->smarty->assign('base_uri', $this->base_uri);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return HandBrakeCluster_Main
|
||||
*/
|
||||
public static function instance() {
|
||||
if (!self::$instance) {
|
||||
self::$instance = new HandBrakeCluster_Main();
|
||||
@@ -47,25 +55,57 @@ class HandBrakeCluster_Main {
|
||||
return $this->smarty;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return HandBrakeCluster_Config
|
||||
*/
|
||||
public function config() {
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return HandBrakeCluster_Database
|
||||
*/
|
||||
public function database() {
|
||||
return $this->database;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return HandBrakeCluster_Log
|
||||
*/
|
||||
public function log() {
|
||||
return $this->log;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return HandBrakeCluster_RequestParser
|
||||
*/
|
||||
public function request() {
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return HandBrakeCluster_Cache
|
||||
*/
|
||||
public function cache() {
|
||||
return $this->cache;
|
||||
}
|
||||
|
||||
public function baseUri() {
|
||||
return $this->base_uri;
|
||||
}
|
||||
|
||||
public function absoluteUrl($relative_url) {
|
||||
$secure = isset($_SERVER['secure']);
|
||||
$port = $_SERVER['HTTP_PORT'];
|
||||
return 'http' . ($secure ? 's' : '') . '://'
|
||||
. $_SERVER['HTTP_HOST'] . (($port == 80 || ($secure && $port == 443)) ? '' : ':' . $port)
|
||||
. '/' . $this->base_uri . $relative_url;
|
||||
}
|
||||
|
||||
public static function initialise() {
|
||||
spl_autoload_register(array('HandBrakeCluster_Main','autoload'));
|
||||
@@ -120,12 +160,13 @@ class HandBrakeCluster_Main {
|
||||
return $var;
|
||||
}
|
||||
|
||||
if (is_subclass_of($default, HandBrakeCluster_Exception)) {
|
||||
throw new $e();
|
||||
if (preg_match('/^HandBrakeCluster_Exception/', $default) && class_exists($default) && is_subclass_of($default, HandBrakeCluster_Exception)) {
|
||||
throw new $default();
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
HandBrakeCluster_Main::initialise();
|
||||
|
||||
@@ -27,13 +27,17 @@ class HandBrakeCluster_Page {
|
||||
|
||||
try {
|
||||
$this->render($template_filename, $code_filename, $template_variables);
|
||||
} catch (HandBrakeCluster_Exception_AbortEntirePage $e) {
|
||||
return false;
|
||||
} catch (HandBrakeCluster_Exception_FileNotFound $e) {
|
||||
$this->render('errors/404.tpl', 'errors/404.php');
|
||||
} catch (HandBrakeCluster_Exception_TemplateException $e) {
|
||||
} catch (HandBrakeCluster_Exception $e) {
|
||||
$this->render('errors/unhandled-exception.tpl', 'errors/unhandled-exception.php', array(
|
||||
'exception' => $e,
|
||||
));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function render($template_filename, $code_filename = null, $template_variables = array()) {
|
||||
@@ -56,6 +60,14 @@ class HandBrakeCluster_Page {
|
||||
// Now execute the template itself, which will render the results of the code file
|
||||
$this->smarty->assign('page_content', $this->smarty->fetch($template_filename));
|
||||
}
|
||||
|
||||
public static function redirect($relative_url) {
|
||||
$absolute_url = HandBrakeCluster_Main::instance()->absoluteUrl($relative_url);
|
||||
|
||||
header("Location: $absolute_url");
|
||||
|
||||
throw new HandBrakeCluster_Exception_AbortEntirePage();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user