From 17d5412ef5bdde749ce57dbdd627243eb0d701a8 Mon Sep 17 00:00:00 2001 From: paulr Date: Sun, 24 Jul 2011 06:46:57 +1000 Subject: [PATCH] Setting up my convoluted web parsing structure... in short: call index.php, which loads config and webrequestor Web requester loads urlparser which then determines the class handling the page web requester then calls class->go($url) class can then call GLCASPageBuilder(class, function, title) which then builds a static page and then calls class->function(url) to build the body. FUN! --- libglcas/config.php | 69 ++++++++++++++++++++++++++++++++++++++++++++++ libglcas/lib.php | 49 ++++++++++++++++++++++++++++++++ libglcas/urlparser.php | 53 +++++++++++++++++++++++++++++++++++ libglcas/web.php | 68 +++++++++++++++++++++++++++++++++++++++++++++ plugins/admin.php | 24 ++++++++++++++++ plugins/glcas_plugin.php | 10 ++++++ plugins/repo.php | 18 ++++++++++++ plugins/webbase.php | 29 +++++++++++++++++++ www/.htaccess | 8 +++++ www/index.php | 58 ++++++++++++++++++++++++++++++++++++++ 10 files changed, 386 insertions(+), 0 deletions(-) create mode 100644 libglcas/config.php create mode 100644 libglcas/lib.php create mode 100644 libglcas/urlparser.php create mode 100644 libglcas/web.php create mode 100644 plugins/admin.php create mode 100644 plugins/glcas_plugin.php create mode 100644 plugins/repo.php create mode 100644 plugins/webbase.php create mode 100644 www/.htaccess create mode 100644 www/index.php diff --git a/libglcas/config.php b/libglcas/config.php new file mode 100644 index 0000000..634b69a --- /dev/null +++ b/libglcas/config.php @@ -0,0 +1,69 @@ +configPath = ""; + $this->config = ""; + } + + function loadConfig($configpath) + { + error_log("loadConfig $configpath"); + $this->configPath = $configpath; + $flt = file_get_contents($configpath); + $this->config = unserialize(base64_decode($flt)); + + + } + + function setConfigVar($var, $value) + { + if(is_array($this->config)) { + foreach($this->config as $vkey => $val) { + if($vkey == "$var") { + error_log("reset config of $var to $value"); + $this->config[$var] = $value; + return true; + } + } + } else error_log("config isnt array"); + + // otherwise, set it + error_log("set config of $var to $value"); + $this->config[$var] = $value; + } + + function delConfigVar($var) + { + if(is_array($this->config)) { + foreach($this->config as $vkey => $val) { + if($vkey == "$var") { + error_log("remove config of $var to $value"); + unset($this->config[$var]); + return true; + } + } + } else error_log("config isnt array"); + } + + function saveConfig() + { + file_put_contents($this->configPath, base64_encode(serialize($this->config))); + } + + function debug() + { + echo "
";
+		echo "path: ".$this->configPath."\n";
+		print_r($this->config);
+		echo "
"; + } + + private $configPath; + private $config; + +} + +?> \ No newline at end of file diff --git a/libglcas/lib.php b/libglcas/lib.php new file mode 100644 index 0000000..05811a6 --- /dev/null +++ b/libglcas/lib.php @@ -0,0 +1,49 @@ + 0) { + error_log("loading plugin $file"); + require_once("$plpath/$file"); + //echo "required $basedir/$file\n"; + } + } + } + } + } +} + +?> \ No newline at end of file diff --git a/libglcas/urlparser.php b/libglcas/urlparser.php new file mode 100644 index 0000000..89c9bb1 --- /dev/null +++ b/libglcas/urlparser.php @@ -0,0 +1,53 @@ +urlClasses = $urlconfig; + $this->config = $config; + } + + function getClass($url) + { + error_log("getclass for $url"); + //echo "
URL CLasses";
+		//print_r($this->urlClasses);
+		//echo "
"; + $default = ""; + $base = ""; + if(is_array($this->urlClasses)) { + foreach($this->urlClasses as $key => $val) { + error_log("checking url $url against $key, $val"); + if($url == "/") { + $base = $val; + error_log("base set to $val"); + return new $val($this->config); + } + + // TODO: this is quite messy really, need to think about how i do /'s in urls for url parsers + if($key=="*") { + $default = $val; + error_log("catchall set to $val"); + } else if($key != "/") { + // now the rest + if(preg_match("/$key/", $url)) { + error_log("matched $url to $key and $val"); + return new $val($this->config); + } + } + } + } + error_log("get class returns default"); + return new $default($this->config); + } + + private $urlClasses; + private $config; +} + +?> \ No newline at end of file diff --git a/libglcas/web.php b/libglcas/web.php new file mode 100644 index 0000000..6c3723b --- /dev/null +++ b/libglcas/web.php @@ -0,0 +1,68 @@ +config = $config; + } + + function go($urlhandlers) + { + $url = "/"; + if(isset($_REQUEST["q"])) { + $url = $_REQUEST["q"]; + } + + // create a url parser + $urlparser = new GLCASUrlParser($urlhandlers, $this->config); + + // + $call_class = $urlparser->getClass($url); + $call_class->go($url); + } + + private $config; + +} + +function GLCASpageBuilder($bodyClass, $bodyFunction, $title="GLCAS") +{ + global $WEB_ROOT_FS; + + // TODO: load css + // TODO: load js + // header + echo "$title"; + + // page top + echo "

GLCAS


"; + echo "
messages go here
"; + + // menu, then body + echo "
Menu goes here
"; + // body + $url = "/"; + if(isset($_REQUEST["q"])) { + $url = $_REQUEST["q"]; + } + + if($bodyClass != null) { + $bodyClass->$bodyFunction($url); + } else $bodyFunction($url); + echo "
"; + + + // close the big wrap-around table + echo "
"; + + // footer + echo "
Copyright 2011, PJR
"; + +} + + +?> \ No newline at end of file diff --git a/plugins/admin.php b/plugins/admin.php new file mode 100644 index 0000000..4e24665 --- /dev/null +++ b/plugins/admin.php @@ -0,0 +1,24 @@ +config = $config; + error_log("constructor for GLCASAdmin"); + + } + + function go($url) + { + echo "admin page"; + } + + private $config; +} + +?> \ No newline at end of file diff --git a/plugins/glcas_plugin.php b/plugins/glcas_plugin.php new file mode 100644 index 0000000..c0d36b4 --- /dev/null +++ b/plugins/glcas_plugin.php @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/plugins/repo.php b/plugins/repo.php new file mode 100644 index 0000000..804a5ce --- /dev/null +++ b/plugins/repo.php @@ -0,0 +1,18 @@ +config = $config; + } + + function go($url) + { + echo "i am the repo man, i repo the repo"; + } + + private $config; +} + +?> \ No newline at end of file diff --git a/plugins/webbase.php b/plugins/webbase.php new file mode 100644 index 0000000..13dbcc3 --- /dev/null +++ b/plugins/webbase.php @@ -0,0 +1,29 @@ +config = $config; + error_log("construct GLCASWebBase"); + } + + function go($url) + { + error_log("go GLCASWebBase"); + GLCASpageBuilder($this, "body"); + } + + function body($url) + { + echo "i am disturbing"; + } + + private $config; +} + + +?> \ No newline at end of file diff --git a/www/.htaccess b/www/.htaccess new file mode 100644 index 0000000..e1f7b2e --- /dev/null +++ b/www/.htaccess @@ -0,0 +1,8 @@ +RewriteEngine on +RewriteBase /src/eclipse-workspace/glcas/www/ +RewriteRule ^index\.php.* - [L] +RewriteRule ^soap\.php.* - [L] +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] + diff --git a/www/index.php b/www/index.php new file mode 100644 index 0000000..4657e52 --- /dev/null +++ b/www/index.php @@ -0,0 +1,58 @@ +loadConfig($configpath); +$webResponder = new GLCASWeb($glconfig); +$webResponder->go($URL_HANDLERS); +/* + +echo "
";
+$vars = get_defined_vars();
+foreach($vars as $var => $vkey) {
+	echo "VAR $var is:\n";
+	var_dump($$var);
+	echo "\n\n";
+}
+
+echo "
"; +/**/ + +?> \ No newline at end of file -- 1.7.0.4