X-Git-Url: http://git.pjr.cc/?p=gwvp.git;a=blobdiff_plain;f=gwvplib%2Fgwvpweb.php;h=f01e53751651bba4091252be213b342c36d6e23f;hp=8148e00848e1bfe43fe3f0966e80e89d847b62c6;hb=942b821d861aba1da43ef6c999141853e9f8b3a8;hpb=34740c9fa804277f1f51c1fb3c0f2c9645f3840f diff --git a/gwvplib/gwvpweb.php b/gwvplib/gwvpweb.php index 8148e00..f01e537 100644 --- a/gwvplib/gwvpweb.php +++ b/gwvplib/gwvpweb.php @@ -1,9 +1,239 @@ $val) { + error_log("checking callmefunction $key as $val"); + $callme = $val(); + if($callme !== false) { + $callme(); + return; + } + } + + // we fell-thru to the main web page builder + gwvp_goMainPage(); +} + +function gwvp_SendMessage($messagetype, $message) +{ + $_SESSION["messagetype"] = $messagetype; + $_SESSION["message"] = $message; +} + +function gwvp_goMainPage($bodyFunction = null) +{ + // the main page will look pretty simple, a title, a menu then a body + global $WEB_ROOT_FS, $BASE_URL; + + // a simple web page layout that loads any css and js files that exist in the css and js directories + echo "GWVP"; + + // 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 ""; + //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 ""; + //echo "required $basedir/$file\n"; + } + } + } + } + + + // start body + echo ""; + + echo "

Git over Web Via PHP

"; + + + echo ""; + + if(isset($_SESSION["message"])) { + echo ""; + } + + echo ""; + + echo ""; + + echo ""; + + echo "
"; + gwvp_MessageBuilder(); + echo "
"; + gwvp_MenuBuilder(); + echo ""; + gwvp_LoginBuilder(); + echo "
"; + if($bodyFunction == null) { + gwvp_BodyBuilder(); + } else { + if(function_exists($bodyFunction)) { + $bodyFunction(); + } else { + error_log("Got called with non-existant body function, $bodyFunction"); + gwvp_BodyBuilder(); + } + } + echo "
"; + gwvp_TailBuilder(); + echo "
"; + +} + + +// builds the message builder if its needed +function gwvp_MessageBuilder() +{ + $message = ""; + $messagetype = "info"; + if(isset($_SESSION["message"])) $message = $_SESSION["message"]; + if(isset($_SESSION["messagetype"])) $messagetype = $_SESSION["messagetype"]; + + if($message != "") { + switch($messagetype) { + case "info": + echo "
$message
"; + break; + case "error": + echo "
$message
"; + break; + } + unset($_SESSION["message"]); + if(isset($_SESSION["messagetype"])) unset($_SESSION["messagetype"]); + } +} + +// builds the menu structure +function gwvp_MenuBuilder() +{ + global $MENU_ITEMS, $BASE_URL; + + ksort($MENU_ITEMS); + + echo ""; + foreach($MENU_ITEMS as $key => $val) { + $link = $val["link"]; + $text = $val["text"]; + + // TODO: redo this bit with stristr to find urls - special case for home + $menucolor = ""; + if(isset($_REQUEST["q"])) { + $extlink = str_replace("$BASE_URL/", "", $link); + error_log("trying to do replace of $BASE_URL in $link, got $extlink for ".$_REQUEST["q"]); + if(stristr($_REQUEST["q"], $extlink)!==false) { + $menucolor = " bgcolor=\"#ffdddd\""; + + } + } else { + // special case for home + if($link == $BASE_URL) $menucolor = " bgcolor=\"#ffdddd\""; + } + + + + + if(isset($val["userlevel"])) { + if(gwvp_CheckAuthLevel($val["userlevel"])) { + echo "$text"; + } + + } else { + echo "$text"; + } + } + echo "
Menu
"; + +} + +function gwvp_LoginBuilder() +{ + global $WEB_ROOT_FS, $BASE_URL; + + $login = gwvp_IsLoggedIn(); + if($login === false) { + gwvp_SingleLineLoginForm(); + } else { + echo "Hello, ".gwvp_GetFullName($login)." logout"; + } +} + +// builds the body structure +function gwvp_BodyBuilder() { + global $HOME_PAGE_PROVIDERS; + echo "I AM THE MAIN BODY, FEAR ME!!!! - have no idea whats going to go here"; + if(isset($HOME_PAGE_PROVIDERS)) { + ksort($HOME_PAGE_PROVIDERS); + foreach($HOME_PAGE_PROVIDERS as $provider) { + error_log("Loading home_page_provider, $provider"); + $provider(); + } + } +} + +// builds the tail structure +function gwvp_TailBuilder() +{ + echo "Copyright 2011, PJR - licensed under GPL"; +} + +function gwvp_fourZeroThree() +{ + error_log("403 called"); + header("HTTP/1.0 403 Permission Denied"); } +function gwvp_fourZeroFour() +{ + error_log("404 called"); + header("HTTP/1.0 404 No Such Thing"); +} + + + ?> \ No newline at end of file