adding some framework bits.
[anyhammer.git] / libanyhammer / web.php
1 <?php
2
3 class AHWeb {
4         function __construct($config)
5         {
6                 $this->config = $config;
7         }
8         
9         function go($url)
10         {
11                 echo "hello, $url";
12                 error_log("called as $url");
13         }
14         
15         
16         
17         private $config;
18 }
19
20
21 function AHpageBuilder($bodyClass, $bodyFunction, $bodycontent=null, $title="AnyHammer")
22 {
23         global $WEB_ROOT_FS, $BASE_URL;
24         
25         // TODO: load css
26         // header
27         echo "<html><head><title>$title</title>";
28         
29         // load css
30         if(file_exists("$WEB_ROOT_FS/css")) {
31                 $dh = opendir("$WEB_ROOT_FS/css");
32                 if($dh) {
33                         while(($file = readdir($dh))!==false) {
34                                 $mt = preg_match("/.*.css$/", $file);
35                                 if($mt > 0) {
36                                         error_log("loading css $file");
37                                         echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$BASE_URL/css/$file\">";
38                                         //echo "required $basedir/$file\n";
39                                 }
40                         }
41                 }               
42         }
43
44         // load js
45         if(file_exists("$WEB_ROOT_FS/js")) {
46                 $dh = opendir("$WEB_ROOT_FS/js");
47                 if($dh) {
48                         while(($file = readdir($dh))!==false) {
49                                 $mt = preg_match("/.*.js$/", $file);
50                                 if($mt > 0) {
51                                         error_log("loading js $file");
52                                         echo "<script type=\"text/javascript\" src=\"$BASE_URL/js/$file\"></script>";
53                                         //echo "required $basedir/$file\n";
54                                 }
55                         }
56                 }               
57         }
58         
59         
60         // start body
61         echo "</head><body>";
62         
63         // page top
64         echo "<h1>$title</h1><br>";
65         echo "<table><tr><td>";
66         AHMessageBuilder();
67         echo "<td></tr><tr><td>";
68         
69         // menu, then body
70         echo "<table><tr><td>";
71         AHMenuBuilder();
72         echo "</td></tr><tr><td>";
73         // body
74         $url = "/";
75         if(isset($_REQUEST["q"])) {
76                 $url = $_REQUEST["q"];
77         }
78         
79         if($bodyClass != null) {
80                 $bodyClass->$bodyFunction($url);
81         } else if( $bodyFunction != null) {
82                 $bodyFunction($url);
83         } else echo $bodycontent;
84         echo "</td></tr></table>";
85         
86         
87         // close the big wrap-around table
88         echo "</td></tr></table>";
89         
90         // footer
91         echo "<br><font size=\"-1\">Copyright 2011, PJR</font><br></body></html>";
92         
93 }
94 ?>