adding some framework bits.
[anyhammer.git] / libanyhammer / web.php
diff --git a/libanyhammer/web.php b/libanyhammer/web.php
new file mode 100644 (file)
index 0000000..87f7867
--- /dev/null
@@ -0,0 +1,94 @@
+<?php
+
+class AHWeb {
+       function __construct($config)
+       {
+               $this->config = $config;
+       }
+       
+       function go($url)
+       {
+               echo "hello, $url";
+               error_log("called as $url");
+       }
+       
+       
+       
+       private $config;
+}
+
+
+function AHpageBuilder($bodyClass, $bodyFunction, $bodycontent=null, $title="AnyHammer")
+{
+       global $WEB_ROOT_FS, $BASE_URL;
+       
+       // TODO: load css
+       // header
+       echo "<html><head><title>$title</title>";
+       
+       // load css
+       if(file_exists("$WEB_ROOT_FS/css")) {
+               $dh = opendir("$WEB_ROOT_FS/css");
+               if($dh) {
+                       while(($file = readdir($dh))!==false) {
+                               $mt = preg_match("/.*.css$/", $file);
+                               if($mt > 0) {
+                                       error_log("loading css $file");
+                                       echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$BASE_URL/css/$file\">";
+                                       //echo "required $basedir/$file\n";
+                               }
+                       }
+               }               
+       }
+
+       // load js
+       if(file_exists("$WEB_ROOT_FS/js")) {
+               $dh = opendir("$WEB_ROOT_FS/js");
+               if($dh) {
+                       while(($file = readdir($dh))!==false) {
+                               $mt = preg_match("/.*.js$/", $file);
+                               if($mt > 0) {
+                                       error_log("loading js $file");
+                                       echo "<script type=\"text/javascript\" src=\"$BASE_URL/js/$file\"></script>";
+                                       //echo "required $basedir/$file\n";
+                               }
+                       }
+               }               
+       }
+       
+       
+       // start body
+       echo "</head><body>";
+       
+       // page top
+       echo "<h1>$title</h1><br>";
+       echo "<table><tr><td>";
+       AHMessageBuilder();
+       echo "<td></tr><tr><td>";
+       
+       // menu, then body
+       echo "<table><tr><td>";
+       AHMenuBuilder();
+       echo "</td></tr><tr><td>";
+       // body
+       $url = "/";
+       if(isset($_REQUEST["q"])) {
+               $url = $_REQUEST["q"];
+       }
+       
+       if($bodyClass != null) {
+               $bodyClass->$bodyFunction($url);
+       } else if( $bodyFunction != null) {
+               $bodyFunction($url);
+       } else echo $bodycontent;
+       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