From a96b3599c809a5bb4eb2b0afd3736b3a870490d0 Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Wed, 15 Jun 2011 21:14:26 +0100 Subject: [PATCH 1/3] Updates Page/RequestParser to support custom directory structures --- source/lib/SihnonFramework/Page.class.php | 2 +- .../SihnonFramework/RequestParser.class.php | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/source/lib/SihnonFramework/Page.class.php b/source/lib/SihnonFramework/Page.class.php index 37b51c4..ab8be43 100644 --- a/source/lib/SihnonFramework/Page.class.php +++ b/source/lib/SihnonFramework/Page.class.php @@ -52,7 +52,7 @@ class SihnonFramework_Page { } // Include the template code file, which will do all the work for this page - $real_code_filename = './source/pages/' . $code_filename; + $real_code_filename = $this->request->template_code_dir() . DIRECTORY_SEPARATOR . $code_filename; if ($code_filename && file_exists($real_code_filename)) { include $real_code_filename; } diff --git a/source/lib/SihnonFramework/RequestParser.class.php b/source/lib/SihnonFramework/RequestParser.class.php index 95b64fa..86f3e7e 100644 --- a/source/lib/SihnonFramework/RequestParser.class.php +++ b/source/lib/SihnonFramework/RequestParser.class.php @@ -5,9 +5,14 @@ class SihnonFramework_RequestParser { private $request_string; private $page = array(); private $vars = array(); + + private $template_dir; + private $template_code_dir; - public function __construct($request_string) { - $this->request_string = $request_string; + public function __construct($request_string, $template_dir = './source/templates', $template_code_dir = './source/pages') { + $this->request_string = $request_string; + $this->template_dir = $template_dir; + $this->template_code_dir = $template_code_dir; $this->parse(); } @@ -25,7 +30,7 @@ class SihnonFramework_RequestParser { // Read through the components list looking for elements matching known directories and files // to determine which page this request is for - $base_dir = './source/templates'; + $base_dir = $this->template_dir; while (true) { if ($components && ! $components[0]) { // Skip over any empty components before we find a page @@ -117,6 +122,14 @@ class SihnonFramework_RequestParser { public function request_string() { return $this->request_string; } + + public function template_dir() { + return $this->template_dir; + } + + public function template_code_dir() { + return $this->template_code_dir; + } }; From 5735e0df75374fea2a8efa660e43fc8e27495592 Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Sun, 19 Jun 2011 00:56:52 +0100 Subject: [PATCH 2/3] Fix redirection to https:// links --- source/lib/SihnonFramework/Main.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/lib/SihnonFramework/Main.class.php b/source/lib/SihnonFramework/Main.class.php index d236422..c473aa5 100644 --- a/source/lib/SihnonFramework/Main.class.php +++ b/source/lib/SihnonFramework/Main.class.php @@ -91,7 +91,7 @@ class SihnonFramework_Main { } public function absoluteUrl($relative_url) { - $secure = isset($_SERVER['secure']); + $secure = isset($_SERVER['SECURE']); $port = $_SERVER['SERVER_PORT']; return 'http' . ($secure ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . (($port == 80 || ($secure && $port == 443)) ? '' : ':' . $port) From d31613c9ec2fa45c662f1b70fc31ad30d5b56550 Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Sun, 19 Jun 2011 01:47:06 +0100 Subject: [PATCH 3/3] Additional tests for HTTPS in redirects --- source/lib/SihnonFramework/Main.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/lib/SihnonFramework/Main.class.php b/source/lib/SihnonFramework/Main.class.php index c473aa5..fc1df5c 100644 --- a/source/lib/SihnonFramework/Main.class.php +++ b/source/lib/SihnonFramework/Main.class.php @@ -91,7 +91,7 @@ class SihnonFramework_Main { } public function absoluteUrl($relative_url) { - $secure = isset($_SERVER['SECURE']); + $secure = isset($_SERVER['SECURE']) || (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'); $port = $_SERVER['SERVER_PORT']; return 'http' . ($secure ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . (($port == 80 || ($secure && $port == 443)) ? '' : ':' . $port)