diff options
author | Filipp Lepalaan <filipp@mekanisti.fi> | 2009-11-08 23:35:59 +0200 |
---|---|---|
committer | Filipp Lepalaan <filipp@mekanisti.fi> | 2009-11-08 23:35:59 +0200 |
commit | 71eebcefb57763451d3cc2749d2ed9e181887157 (patch) | |
tree | 1059305e84d5f5889e8306df0302398e736931ab /App.php | |
parent | f0bb7133827d4e36067333f70ba046e08cd53cd9 (diff) | |
download | main-71eebcefb57763451d3cc2749d2ed9e181887157.tar.gz main-71eebcefb57763451d3cc2749d2ed9e181887157.tar.bz2 main-71eebcefb57763451d3cc2749d2ed9e181887157.zip |
Lots of fixes, better url parsing
Diffstat (limited to 'App.php')
-rw-r--r-- | App.php | 61 |
1 files changed, 37 insertions, 24 deletions
@@ -20,10 +20,12 @@ class App @list($controller, $param, $action) = App::url(); + // No action given, read default one if (empty($param)) { - $controller = self::conf("defaults.action"); + $action = self::conf("defaults.action"); } + // No controller given, read default one if (!$controller) { $controller = self::conf("defaults.controller"); } @@ -56,21 +58,33 @@ class App } - static function param() - { - $url = App::url(); - return $url[1]; - } - - // Requests should always be in the form: controller/action/parameters.type - // Strip type info since it's not needed at this point + /** + * Requests should always be in the form: controller/action/parameters.type + * Strip type info since it's not needed at this point + */ static function url($index = null) { - $req = ltrim($_SERVER['REQUEST_URI'], "/"); + $url = parse_url($_SERVER['REQUEST_URI']); + if ($index == "query") { + return $url['query']; + } + $req = ltrim($url['path'], "/"); $array = explode("/", preg_replace('/\.\w+$/', '', $req)); return (is_numeric($index)) ? $array[$index] : $array; } + /** + * + */ + static function param() + { + $url = App::url(); + return $url[1]; + } + + /** + * Return configuration data from ini file + */ static function conf($key = null) { $cpath = realpath("../system/config.ini"); @@ -89,7 +103,7 @@ class App $type = ltrim(strrchr($last, "."), "."); $contentTypes = array("html", "rss", "xml", "tpl", "pdf", "jpg"); - + if (in_array($type, $contentTypes)) { return $type; } @@ -110,14 +124,14 @@ class App // Send error to client self::json($msg); // And log it locally - self::log($msg); + self::log($msg); } static function json($msg) { $json = json_encode($msg); header("Content-Type: application/json"); - header("Content-Length: " . strlen($json)); + header("Content-Length: " . mb_strlen($json)); print $json; } @@ -130,15 +144,9 @@ class App $msg = print_r($msg, true); } - $c = self::conf("app.error_log"); - - if (!$c) { - return false; - } - - $file = realpath(__FILE__."/../../../../data/$c"); - - if (!$file) { + $file = self::conf("app.error_log"); + + if (!is_file($file)) { return false; } @@ -175,8 +183,14 @@ class App header("Location: $url"); } + /** + * Determine locale from USER_AGENT + */ static function locale() { + if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { + return false; + } // Set language to whatever the browser is set to list($loc, $lang) = explode("-", $_SERVER['HTTP_ACCEPT_LANGUAGE']); return sprintf("%s_%s", $loc, strtoupper($lang)); @@ -274,8 +288,7 @@ class App { if (!isset($_SERVER['PHP_AUTH_USER'])) { - $header = sprintf('WWW-Authenticate: Basic realm="%s"', $realm) - header($header); + header(sprintf('WWW-Authenticate: Basic realm="%s"', $realm)); header("HTTP/1.0 401 Unauthorized"); return false; } else { |