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, $force_ssl;
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
29 if(!isset($_SERVER['HTTPS'])) {
30 header("Location: https://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"], true);
36 ksort($CALL_ME_FUNCTIONS);
37 foreach($CALL_ME_FUNCTIONS as $key => $val) {
38 //// error_log("checking callmefunction $key as $val");
40 if($callme !== false) {
46 // we fell-thru to the main web page builder
47 gwvpmini_goMainPage();
50 function gwvpmini_SendMessage($messagetype, $message)
52 $_SESSION["messagetype"] = $messagetype;
53 $_SESSION["message"] = $message;
56 function gwvpmini_goMainPage($bodyFunction = null)
58 // the main page will look pretty simple, a title, a menu then a body
59 global $WEB_ROOT_FS, $BASE_URL;
61 // a simple web page layout that loads any css and js files that exist in the css and js directories
62 echo "<html><head><title>GWVP</title>";
65 if(file_exists("$WEB_ROOT_FS/css")) {
66 $dh = opendir("$WEB_ROOT_FS/css");
68 while(($file = readdir($dh))!==false) {
69 $mt = preg_match("/.*.css$/", $file);
71 // error_log("loading css $file");
72 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$BASE_URL/css/$file\">";
73 //echo "required $basedir/$file\n";
80 if(file_exists("$WEB_ROOT_FS/js")) {
81 $dh = opendir("$WEB_ROOT_FS/js");
83 while(($file = readdir($dh))!==false) {
84 $mt = preg_match("/.*.js$/", $file);
86 // error_log("loading js $file");
87 echo "<script type=\"text/javascript\" src=\"$BASE_URL/js/$file\"></script>";
88 //echo "required $basedir/$file\n";
98 echo "<h1>Git over Web Via PHP</h1>";
101 echo "<table width=\"100%\">";
103 echo "<tr width=\"100%\" bgcolor=\"#ddddff\"><td colspan=\"2\" align=\"right\">";
104 gwvpmini_SearchBuilder();
108 if(isset($_SESSION["message"])) {
109 echo "<tr width=\"100%\"><td colspan=\"2\">";
110 gwvpmini_MessageBuilder();
114 echo "<tr width=\"100%\" bgcolor=\"#ddffdd\"><td>";
115 gwvpmini_MenuBuilder();
116 echo "</td><td align=\"right\">";
117 gwvpmini_LoginBuilder();
122 echo "<tr width=\"100%\"><td colspan=\"3\">";
124 echo "<table width=\"100%\"><tr width=\"100%\" valign=\"top\"><td>";
125 if($bodyFunction == null) {
126 gwvpmini_BodyBuilder();
128 if(function_exists($bodyFunction)) {
131 // error_log("Got called with non-existant body function, $bodyFunction");
132 gwvpmini_BodyBuilder();
138 /* TODO: taking out chat for now
139 echo "<td align=\"right\">";
141 gwvpmini_ChatBuilder();
144 echo "</tr></table>";
\r
149 gwvpmini_TailBuilder();
150 echo "</td></tr></table></body></html>";
155 // builds the message builder if its needed
156 function gwvpmini_MessageBuilder()
159 $messagetype = "info";
160 if(isset($_SESSION["message"])) $message = $_SESSION["message"];
161 if(isset($_SESSION["messagetype"])) $messagetype = $_SESSION["messagetype"];
164 switch($messagetype) {
166 echo "<table border=\"1\" width=\"100%\"><tr width=\"100%\"><td bgcolor=\"#AAFFAA\">$message</td></tr></table>";
169 echo "<table border=\"1\" width=\"100%\"><tr width=\"100%\"><td bgcolor=\"#FFAAAA\">$message</td></tr></table>";
172 unset($_SESSION["message"]);
173 if(isset($_SESSION["messagetype"])) unset($_SESSION["messagetype"]);
177 function gwvpmini_ChatBuilder()
179 gwvpmini_DisplayChat();
182 // builds the menu structure
183 function gwvpmini_MenuBuilder()
185 global $MENU_ITEMS, $BASE_URL;
189 echo "<table border=\"1\"><tr><td><b><i>Menu</i></b></td>";
190 foreach($MENU_ITEMS as $key => $val) {
191 $link = $val["link"];
192 $text = $val["text"];
194 // TODO: redo this bit with stristr to find urls - special case for home
196 if(isset($_REQUEST["q"])) {
197 $extlink = str_replace("$BASE_URL/", "", $link);
198 // error_log("trying to do replace of $BASE_URL in $link, got $extlink for ".$_REQUEST["q"]);
199 if(stristr($_REQUEST["q"], $extlink)!==false) {
200 $menucolor = " bgcolor=\"#ffdddd\"";
204 // special case for home
205 if($link == $BASE_URL) $menucolor = " bgcolor=\"#ffdddd\"";
211 if(isset($val["userlevel"])) {
212 if(gwvpmini_CheckAuthLevel($val["userlevel"])) {
213 echo "<td$menucolor><a href=\"$link\">$text</a></td>";
217 echo "<td$menucolor><a href=\"$link\">$text</a></td>";
220 echo "</tr></table>";
224 function gwvpmini_LoginBuilder()
226 global $WEB_ROOT_FS, $BASE_URL;
228 $login = gwvpmini_IsLoggedIn();
229 if($login === false) {
230 gwvpmini_SingleLineLoginForm();
232 echo "Hello <a href=\"$BASE_URL/user/".$_SESSION["username"]."\">".$_SESSION["fullname"]."</a> <a href=\"$BASE_URL/logout\">logout</a>";
236 // builds the body structure
237 function gwvpmini_BodyBuilder()
239 global $HOME_PAGE_PROVIDERS;
241 if(isset($HOME_PAGE_PROVIDERS)) {
242 ksort($HOME_PAGE_PROVIDERS);
243 foreach($HOME_PAGE_PROVIDERS as $provider) {
244 // error_log("Loading home_page_provider, $provider");
250 // builds the tail structure
251 function gwvpmini_TailBuilder()
253 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>";
256 function gwvpmini_emailToUserLink($email)
260 $username = gwvpmini_GetUserNameFromEmail($email);
262 if($username !== false) {
263 return "<a href=\"$BASE_URL/user/$username\">$username</a>";
269 function gwvpmini_fourZeroThree()
271 // error_log("403 called");
272 header("HTTP/1.1 403 Permission Denied");
275 function gwvpmini_fourZeroFour()
277 // error_log("404 called");
278 header("HTTP/1.1 404 No Such Thing");
283 * Get either a Gravatar URL or complete image tag for a specified email address.
\r
285 * @param string $email The email address
\r
286 * @param string $s Size in pixels, defaults to 80px [ 1 - 2048 ]
\r
287 * @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
\r
288 * @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
\r
289 * @param boole $img True to return a complete IMG tag False for just the URL
\r
290 * @param array $atts Optional, additional key/value attributes to include in the IMG tag
\r
291 * @return String containing either just a URL or a complete image tag
\r
292 * @source http://gravatar.com/site/implement/images/php/
\r
294 function gwvpmini_HtmlGravatar($email, $size, $htmlappend="")
297 global $use_gravatar;
300 // error_log("call to gravatar with yes");
302 // error_log("call to gravatar with no");
305 if($use_gravatar == false) return "";
306 return get_gravatar( $email, $size, 'mm', 'g', true)."$htmlappend";
309 function get_gravatar( $email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array() ) {
\r
310 $url = 'http://en.gravatar.com/avatar/';
\r
311 $url .= md5( strtolower( trim( $email ) ) );
\r
312 $url .= "?s=$s&d=$d&r=$r";
\r
314 $url = '<img src="' . $url . '"';
\r
315 foreach ( $atts as $key => $val )
\r
316 $url .= ' ' . $key . '="' . $val . '"';
\r