--- /dev/null
+<?php
+
+class GLCASConfig {
+
+ function __construct()
+ {
+ $this->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 "<pre>";
+ echo "path: ".$this->configPath."\n";
+ print_r($this->config);
+ echo "</pre>";
+ }
+
+ private $configPath;
+ private $config;
+
+}
+
+?>
\ No newline at end of file
--- /dev/null
+<?php
+/*
+ *
+ * The Main lib.php file.
+ *
+ */
+
+//require_once();
+
+// get the lib root, and set include path from it
+$LIB_ROOT_FS = realpath(dirname(__FILE__));
+global $LIB_ROOT_FS;
+
+/*
+ * I shouldnt ever need to do this bit, but its here, just in case
+$adpath = realpath($LIB_ROOT_FS."/../");
+error_log("added libglcas path as $adpath");
+set_include_path(get_include_path().PATH_SEPARATOR.$adpath);
+
+*/
+require_once("libglcas/urlparser.php");
+require_once("libglcas/web.php");
+require_once("libglcas/config.php");
+
+function glcas_pluginLoader($path="")
+{
+ global $LIB_ROOT_FS;
+ if($path == "") {
+ // try and find it
+ $plpath = realpath($LIB_ROOT_FS."/../plugins/");
+ if(file_exists($plpath."/glcas_plugin.php")) {
+ // here it is, load away
+ error_log("attempting to load plugins from $plpath");
+ $dh = opendir("$plpath");
+ if($dh) {
+ while(($file = readdir($dh))!==false) {
+ $mt = preg_match("/.*.php$/", $file);
+ if($mt > 0) {
+ error_log("loading plugin $file");
+ require_once("$plpath/$file");
+ //echo "required $basedir/$file\n";
+ }
+ }
+ }
+ }
+ }
+}
+
+?>
\ No newline at end of file
--- /dev/null
+<?php
+
+// the purpose of this plugin is to take a url and figure out the owning class that should be called
+error_log("glcasurlparser loaded");
+
+class GLCASUrlParser {
+ function __construct($urlconfig, $config)
+ {
+ $v = print_r($urlconfig, true);
+ error_log("constructor for urlparser, $v");
+ $this->urlClasses = $urlconfig;
+ $this->config = $config;
+ }
+
+ function getClass($url)
+ {
+ error_log("getclass for $url");
+ //echo "<pre>URL CLasses";
+ //print_r($this->urlClasses);
+ //echo "</pre>";
+ $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
--- /dev/null
+<?php
+
+// if i believed in name spacing in php, i'd use it.
+error_log("glcasweb loaded");
+
+class GLCASWeb {
+
+ function __construct($config)
+ {
+ $this->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 "<html><title>$title</title><body>";
+
+ // page top
+ echo "<h1>GLCAS</h1><br>";
+ echo "<table><tr><td>messages go here<td></tr><tr><td>";
+
+ // menu, then body
+ echo "<table><tr><td>Menu goes here</td></tr><tr><td>";
+ // body
+ $url = "/";
+ if(isset($_REQUEST["q"])) {
+ $url = $_REQUEST["q"];
+ }
+
+ if($bodyClass != null) {
+ $bodyClass->$bodyFunction($url);
+ } else $bodyFunction($url);
+ echo "</td></tr></table>";
+
+
+ // close the big wrap-around table
+ echo "</td></tr></table>";
+
+ // footer
+ echo "<br><font size=\"-1\">Copyright 2011, PJR</font><br></body></html>";
+
+}
+
+
+?>
\ No newline at end of file
--- /dev/null
+<?php
+
+error_log("admin loaded");
+
+global $URL_HANDLERS;
+$URL_HANDLERS["admin.*"] = "GLCASAdmin";
+
+class GLCASAdmin {
+ function __construct($config)
+ {
+ $this->config = $config;
+ error_log("constructor for GLCASAdmin");
+
+ }
+
+ function go($url)
+ {
+ echo "admin page";
+ }
+
+ private $config;
+}
+
+?>
\ No newline at end of file
--- /dev/null
+<?php
+
+// this is a plugin just to show the plugin path.
+error_log("glcase_plugin loaded");
+
+global $URL_HANDLERS;
+
+$URL_HANDLERS["repo"] = "repo";
+
+?>
\ No newline at end of file
--- /dev/null
+<?php
+$URL_HANDLERS["*"] = "GLCASRepo";
+
+class GLCASRepo {
+ function __construct($config)
+ {
+ $this->config = $config;
+ }
+
+ function go($url)
+ {
+ echo "i am the repo man, i repo the repo";
+ }
+
+ private $config;
+}
+
+?>
\ No newline at end of file
--- /dev/null
+<?php
+
+global $URL_HANDLERS;
+$URL_HANDLERS["/"] = "GLCASWebBase";
+
+
+class GLCASWebBase {
+ function __construct($config)
+ {
+ $this->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
--- /dev/null
+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]
+
--- /dev/null
+<?php
+
+$WEB_ROOT_FS = realpath(dirname(__FILE__));
+
+global $WEB_ROOT_FS, $URL_HANDLERS;
+
+// add libglcas as if it were a path in ../libglcas
+if(file_exists("../libglcas")) {
+ $path = realpath($WEB_ROOT_FS."/../");
+ error_log("added glcas path as $path");
+ set_include_path(get_include_path().PATH_SEPARATOR.$path);
+}
+
+// include the based library
+require_once("libglcas/lib.php");
+
+// load plugins
+glcas_pluginLoader();
+
+// find our config
+$configpath = "";
+
+// TODO: do this better
+if(file_exists($WEB_ROOT_FS."/../var")) {
+
+ // is it there?
+ if(file_exists($WEB_ROOT_FS."/../var/glcas/webconfig")) {
+ $configpath = realpath("$WEB_ROOT_FS/../var/glcas/webconfig");
+ } else {
+ // if not, attempt to create
+ if(!file_exists($WEB_ROOT_FS."/../var/glcas")) {
+ mkdir($WEB_ROOT_FS."/../var/glcas");
+ }
+ // success!
+ touch("$WEB_ROOT_FS/../var/glcas/webconfig");
+ $configpath = realpath("$WEB_ROOT_FS/../var/glcas/webconfig");
+ }
+}
+
+
+$glconfig = new GLCASConfig();
+$glconfig->loadConfig($configpath);
+$webResponder = new GLCASWeb($glconfig);
+$webResponder->go($URL_HANDLERS);
+/*
+
+echo "<pre>";
+$vars = get_defined_vars();
+foreach($vars as $var => $vkey) {
+ echo "VAR $var is:\n";
+ var_dump($$var);
+ echo "\n\n";
+}
+
+echo "</pre>";
+/**/
+
+?>
\ No newline at end of file