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;
6 // the home_page_provders bit is an array
7 global $HOME_PAGE_PROVIDERS;
9 $MENU_ITEMS["00home"]["text"] = "Home";
10 $MENU_ITEMS["00home"]["link"] = "$BASE_URL";
14 function gwvpmini_goWeb()
16 global $CALL_ME_FUNCTIONS;
18 // first we determine if we have a valid setup and run the installer if not
19 /*if(!gwvpmini_issetup()) {
24 // 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
25 // the functions return (i.e. if function returns false, its not it, otherwise it returns a function name we have to call)
26 // this is important for our plugin structure later on - the key on the array serves an an ordering method
27 ksort($CALL_ME_FUNCTIONS);
28 foreach($CALL_ME_FUNCTIONS as $key => $val) {
29 error_log("checking callmefunction $key as $val");
31 if($callme !== false) {
37 // we fell-thru to the main web page builder
38 gwvpmini_goMainPage();
41 function gwvpmini_SendMessage($messagetype, $message)
43 $_SESSION["messagetype"] = $messagetype;
44 $_SESSION["message"] = $message;
47 function gwvpmini_goMainPage($bodyFunction = null)
49 // the main page will look pretty simple, a title, a menu then a body
50 global $WEB_ROOT_FS, $BASE_URL;
52 // a simple web page layout that loads any css and js files that exist in the css and js directories
53 echo "<html><head><title>GWVP Mini</title>";
56 if(file_exists("$WEB_ROOT_FS/css")) {
57 $dh = opendir("$WEB_ROOT_FS/css");
59 while(($file = readdir($dh))!==false) {
60 $mt = preg_match("/.*.css$/", $file);
62 error_log("loading css $file");
63 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$BASE_URL/css/$file\">";
64 //echo "required $basedir/$file\n";
71 if(file_exists("$WEB_ROOT_FS/js")) {
72 $dh = opendir("$WEB_ROOT_FS/js");
74 while(($file = readdir($dh))!==false) {
75 $mt = preg_match("/.*.js$/", $file);
77 error_log("loading js $file");
78 echo "<script type=\"text/javascript\" src=\"$BASE_URL/js/$file\"></script>";
79 //echo "required $basedir/$file\n";
89 echo "<h1>Git over Web Via PHP - Mini Version</h2>";
92 echo "<table width=\"100%\">";
94 echo "<tr width=\"100%\" bgcolor=\"#ddddff\"><td colspan=\"2\" align=\"right\">";
95 gwvpmini_SearchBuilder();
99 if(isset($_SESSION["message"])) {
100 echo "<tr width=\"100%\"><td colspan=\"2\">";
101 gwvpmini_MessageBuilder();
105 echo "<tr width=\"100%\" bgcolor=\"#ddffdd\"><td>";
106 gwvpmini_MenuBuilder();
107 echo "</td><td align=\"right\">";
108 gwvpmini_LoginBuilder();
113 echo "<tr><td colspan=\"2\">";
114 if($bodyFunction == null) {
115 gwvpmini_BodyBuilder();
117 if(function_exists($bodyFunction)) {
120 error_log("Got called with non-existant body function, $bodyFunction");
121 gwvpmini_BodyBuilder();
127 gwvpmini_TailBuilder();
128 echo "</td></tr></table></body></html>";
133 // builds the message builder if its needed
134 function gwvpmini_MessageBuilder()
137 $messagetype = "info";
138 if(isset($_SESSION["message"])) $message = $_SESSION["message"];
139 if(isset($_SESSION["messagetype"])) $messagetype = $_SESSION["messagetype"];
142 switch($messagetype) {
144 echo "<table border=\"1\" width=\"100%\"><tr width=\"100%\"><td bgcolor=\"#AAFFAA\">$message</td></tr></table>";
147 echo "<table border=\"1\" width=\"100%\"><tr width=\"100%\"><td bgcolor=\"#FFAAAA\">$message</td></tr></table>";
150 unset($_SESSION["message"]);
151 if(isset($_SESSION["messagetype"])) unset($_SESSION["messagetype"]);
155 // builds the menu structure
156 function gwvpmini_MenuBuilder()
158 global $MENU_ITEMS, $BASE_URL;
162 echo "<table border=\"1\"><tr><td><b><i>Menu</i></b></td>";
163 foreach($MENU_ITEMS as $key => $val) {
164 $link = $val["link"];
165 $text = $val["text"];
167 // TODO: redo this bit with stristr to find urls - special case for home
169 if(isset($_REQUEST["q"])) {
170 $extlink = str_replace("$BASE_URL/", "", $link);
171 error_log("trying to do replace of $BASE_URL in $link, got $extlink for ".$_REQUEST["q"]);
172 if(stristr($_REQUEST["q"], $extlink)!==false) {
173 $menucolor = " bgcolor=\"#ffdddd\"";
177 // special case for home
178 if($link == $BASE_URL) $menucolor = " bgcolor=\"#ffdddd\"";
184 if(isset($val["userlevel"])) {
185 if(gwvpmini_CheckAuthLevel($val["userlevel"])) {
186 echo "<td$menucolor><a href=\"$link\">$text</a></td>";
190 echo "<td$menucolor><a href=\"$link\">$text</a></td>";
193 echo "</tr></table>";
197 function gwvpmini_LoginBuilder()
199 global $WEB_ROOT_FS, $BASE_URL;
201 $login = gwvpmini_IsLoggedIn();
202 if($login === false) {
203 gwvpmini_SingleLineLoginForm();
205 echo "Hello <a href=\"$BASE_URL/user/".$_SESSION["username"]."\">".$_SESSION["fullname"]."</a> <a href=\"$BASE_URL/logout\">logout</a>";
209 // builds the body structure
210 function gwvpmini_BodyBuilder()
212 global $HOME_PAGE_PROVIDERS;
214 echo "I AM THE MAIN BODY, FEAR ME!!!! - have no idea whats going to go here";
215 if(isset($HOME_PAGE_PROVIDERS)) {
216 ksort($HOME_PAGE_PROVIDERS);
217 foreach($HOME_PAGE_PROVIDERS as $provider) {
218 error_log("Loading home_page_provider, $provider");
224 // builds the tail structure
225 function gwvpmini_TailBuilder()
227 echo "<br><br><hr><font size=\"-1\"><b><a href=\"http://github.com/takigama/GWVP\">GWVP</a></b> - <i>Copyright 2011, 2012 PJR - <a href=\"http://www.gnu.org/copyleft/gpl.html\">GPL</a></i></font>";
230 function gwvpmini_emailToUserLink($email)
234 $username = gwvpmini_GetUserNameFromEmail($email);
236 if($username !== false) {
237 return "<a href=\"$BASE_URL/user/$username\">$username</a>";
243 function gwvpmini_fourZeroThree()
245 error_log("403 called");
246 header("HTTP/1.0 403 Permission Denied");
249 function gwvpmini_fourZeroFour()
251 error_log("404 called");
252 header("HTTP/1.0 404 No Such Thing");
257 * Get either a Gravatar URL or complete image tag for a specified email address.
\r
259 * @param string $email The email address
\r
260 * @param string $s Size in pixels, defaults to 80px [ 1 - 2048 ]
\r
261 * @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
\r
262 * @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
\r
263 * @param boole $img True to return a complete IMG tag False for just the URL
\r
264 * @param array $atts Optional, additional key/value attributes to include in the IMG tag
\r
265 * @return String containing either just a URL or a complete image tag
\r
266 * @source http://gravatar.com/site/implement/images/php/
\r
268 function get_gravatar( $email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array() ) {
\r
269 $url = 'http://en.gravatar.com/avatar/';
\r
270 $url .= md5( strtolower( trim( $email ) ) );
\r
271 $url .= "?s=$s&d=$d&r=$r";
\r
273 $url = '<img src="' . $url . '"';
\r
274 foreach ( $atts as $key => $val )
\r
275 $url .= ' ' . $key . '="' . $val . '"';
\r