From 9eca035c3f554b8f71dcfb92768820b4f9931a1b Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Sun, 27 Apr 2014 21:05:19 -0500 Subject: [PATCH] updating framework --- system/engine/config-default.php | 1 + system/engine/controller.php | 6 ++++ system/engine/core.php | 55 +++++++++++++++++++++++++------ system/vendor/StackTracePrint.php | 3 ++ system/vendor/isvarset.php | 6 ++++ 5 files changed, 61 insertions(+), 10 deletions(-) create mode 100644 system/vendor/isvarset.php diff --git a/system/engine/config-default.php b/system/engine/config-default.php index d2bd78e..0120424 100644 --- a/system/engine/config-default.php +++ b/system/engine/config-default.php @@ -10,5 +10,6 @@ $config["SMTP_FROM"] = "HF-noreply@yoursite.com"; $config["DEBUG"] = true; $config["USE_HF_SMTP"] = true; $config["SITE_NAME"] = "default"; +$config["SITE_URL"] = ""; return $config; \ No newline at end of file diff --git a/system/engine/controller.php b/system/engine/controller.php index 76209e0..c32d5e1 100644 --- a/system/engine/controller.php +++ b/system/engine/controller.php @@ -12,4 +12,10 @@ class HF_Controller $this->core = $core; } + public function loadRender($template, $parameters=array()) + { + $this->tpl->loadTemplate($template); + return $this->tpl->render($parameters); + } + } \ No newline at end of file diff --git a/system/engine/core.php b/system/engine/core.php index 7171cf0..9f186c3 100644 --- a/system/engine/core.php +++ b/system/engine/core.php @@ -23,27 +23,60 @@ class HF_Core $this->config = array_merge($config, $newconfig); if ($this->config["USE_H20_TPL"]) $this->tpl = new H2o(null, array( - "searchpath" => getcwd() . "/application/views/", "cache_dir" => "application/tmp/", + "searchpath" => getcwd() . "/application/views/", + "cache_dir" => "application/tmp/", + 'cache' => 'file' )); set_error_handler("HF_Core::error_handler"); $this->findController(); } + + public function siteURL() + { + if (isvarset($this->config["SITE_URL"])) + { + return $this->config["SITE_URL"]; + } + $path = explode("/", $_SERVER["REQUEST_URI"]); + $path = array_filter($path, 'strlen'); + if (count($path) == 0) + { + return $_SERVER["HTTP_HOST"] . "/"; + } else { + if (in_array($this->classname, $path)) + { + $newpath = implode("/", array_splice($path, 0, -2)); + return $_SERVER["HTTP_HOST"] . "/" . $newpath . "/"; + } else { + $newpath = implode("/", $path); + return $_SERVER["HTTP_HOST"] . "/" . $newpath . "/"; + } + } + } private function findController() { try { - $request = $_SERVER["PHP_SELF"]; - $splitreq = explode("/", $request); - $request = ""; - for($i = 0; $i < count($splitreq); $i++) + if (isvarset($_SERVER["PATH_INFO"])) { - if ($splitreq[$i] == "index.php") + $request = $_SERVER["PATH_INFO"]; + //$request = $_SERVER["PHP_SELF"]; + $splitreq = explode("/", $request); + /*$request = ""; + for($i = 0; $i < count($splitreq); $i++) { - $request = implode("/", array_splice($splitreq, $i+1)); - } + if ($splitreq[$i] == "index.php") + { + $request = implode("/", array_splice($splitreq, $i+1)); + } + }*/ + //print $request; + //$request = substr($request, 1); + //$request = substr($request, 0, -1); + } else { + $request = ""; } - if ($request == "" || $request == "/") { require("application/controllers/" . $this->config["DEFAULT_ROUTE"] . ".php"); @@ -74,7 +107,9 @@ class HF_Core continue; } - $this->load404Controller(); + include($path . $this->config["DEFAULT_ROUTE"] . ".php"); + $this->loadController(new $this->config["DEFAULT_ROUTE"]($this->config, $this, $this->tpl), $this->config["DEFAULT_ROUTE"], "index"); + //$this->load404Controller(); break; // throw exception controller not found } diff --git a/system/vendor/StackTracePrint.php b/system/vendor/StackTracePrint.php index df4506d..f576bc0 100644 --- a/system/vendor/StackTracePrint.php +++ b/system/vendor/StackTracePrint.php @@ -19,6 +19,9 @@ function vdump() { foreach ($args as $arg) var_dump($arg); + var_dump($_SERVER); + var_dump($_COOKIE); + $str = ob_get_contents(); ob_end_clean(); diff --git a/system/vendor/isvarset.php b/system/vendor/isvarset.php new file mode 100644 index 0000000..27f1a65 --- /dev/null +++ b/system/vendor/isvarset.php @@ -0,0 +1,6 @@ +