some framework stuff
[gwvp.git] / gwvplib / gwvpweb.php
1 <?php
2
3 // this function is the initial insertion point for the web calls, here we need to determine where we go
4 global $CALL_ME_FUNCTIONS;
5
6 $MENU_ITEMS["00home"]["text"] = "Home";
7 $MENU_ITEMS["00home"]["link"] = "$BASE_URL";
8
9
10
11 function gwvp_goWebBegin()
12 {
13         global $CALL_ME_FUNCTIONS;
14         
15         // first we determine if we have a valid setup and run the installer if not
16         if(!gwvp_issetup()) {
17                 gwvp_goSetup();
18                 return;
19         }
20         
21         // next, we go thru the CALL_ME_FUNCTIONS - the purpose of call_me_functions is to determine if a function should be called based on
22         // the functions return (i.e. if function returns false, its not it, otherwise it returns a function name we have to call)
23         // this is important for our plugin structure later on
24         foreach($CALL_ME_FUNCTIONS as $key => $val) {
25                 error_log("checking callmefunction $key as $val");
26                 $callme = $val();
27                 if($callme !== false) {
28                         $callme();
29                         return;
30                 }
31         }
32         
33         // we fell-thru to the main web page builder
34         gwvp_goMainPage();
35 }
36
37 function gwvp_goMainPage($bodyFunction = null)
38 {
39         // the main page will look pretty simple, a title, a menu then a body
40         global $WEB_ROOT_FS, $BASE_URL;
41         
42         // a simple web page layout that loads any css and js files that exist in the css and js directories
43         echo "<html><head><title>GWVP</title>";
44         
45         // load css
46         if(file_exists("$WEB_ROOT_FS/css")) {
47                 $dh = opendir("$WEB_ROOT_FS/css");
48                 if($dh) {
49                         while(($file = readdir($dh))!==false) {
50                                 $mt = preg_match("/.*.css$/", $file);
51                                 if($mt > 0) {
52                                         error_log("loading css $file");
53                                         echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$BASE_URL/css/$file\">";
54                                         //echo "required $basedir/$file\n";
55                                 }
56                         }
57                 }               
58         }
59
60         // load js
61         if(file_exists("$WEB_ROOT_FS/js")) {
62                 $dh = opendir("$WEB_ROOT_FS/js");
63                 if($dh) {
64                         while(($file = readdir($dh))!==false) {
65                                 $mt = preg_match("/.*.js$/", $file);
66                                 if($mt > 0) {
67                                         error_log("loading js $file");
68                                         echo "<script type=\"text/javascript\" src=\"$BASE_URL/js/$file\"></script>";
69                                         //echo "required $basedir/$file\n";
70                                 }
71                         }
72                 }               
73         }
74         
75         
76         // start body
77         echo "</head><body>";
78         
79         echo "<h1>Git over Web Via PHP</h2>";
80         
81         
82         echo "<table width=\"100%\"><tr width=\"100%\"><td>";
83         gwvp_MenuBuilder();
84         echo "</td></tr>";
85         
86         echo "<tr><td>";
87         if($bodyFunction == null) {
88                 gwvp_BodyBuilder();
89         } else {
90                 if(function_exists($bodyFunction)) {
91                         $bodyFunction();
92                 } else {
93                         error_log("Got called with non-existant body function");
94                         gwvp_BodyBuilder();
95                 }
96         }
97         echo "</td></tr>";
98         
99         echo "<tr><td>";
100         gwvp_TailBuilder();
101         echo "</td></tr></table></body></html>";
102         
103 }
104
105 // builds the menu structure
106 function gwvp_MenuBuilder()
107 {
108         global $MENU_ITEMS;
109         
110         ksort($MENU_ITEMS);
111         
112         echo "<table border=\"1\"><tr><td>Menu</td>";
113         foreach($MENU_ITEMS as $key => $val) {
114                 $link = $val["link"];
115                 $text = $val["text"];
116                 echo "<td><a href=\"$link\">$text</a></td>";
117         }
118         echo "</tr></table>";
119         
120 }
121
122 // builds the body structure
123 function gwvp_BodyBuilder()
124 {
125         echo "I AM THE MAIN BODY, FEAR ME!!!!";
126 }
127
128 // builds the tail structure
129 function gwvp_TailBuilder()
130 {
131         echo "<font size=\"-1\"><i>Copyright 2011, PJR - licensed under GPL</i></font>";
132 }
133
134 ?>