Working on Web Admin

This commit is contained in:
Jérôme Schneider 2012-04-05 14:09:33 +02:00
parent 1a268588b3
commit d2b2cb31ff
13 changed files with 82 additions and 98 deletions

View file

@ -59,11 +59,14 @@ require_once(BAIKAL_PATH_SPECIFIC . "config.php");
require_once(BAIKAL_PATH_SPECIFIC . "config.system.php"); require_once(BAIKAL_PATH_SPECIFIC . "config.system.php");
# Determining baikal protocol, domain and uri-path (looking at BAIKAL_URI) # Determining baikal protocol, domain and uri-path (looking at BAIKAL_URI)
$aUrlInfo = parse_url(BAIKAL_URI); if($GLOBALS["_SERVER"]["SERVER_NAME"] === "mongoose") { # And not using MONGOOSE_SERVER constant, as it will be defined by Flake, later in the process
define("BAIKAL_DOMAIN", "");
define("BAIKAL_DOMAIN", $aUrlInfo["host"]); define("BAIKAL_URIPATH", "");
define("BAIKAL_URIPROTOCOL", $aUrlInfo["scheme"]); } else {
define("BAIKAL_URIPATH", $aUrlInfo["path"]); $aUrlInfo = parse_url(BAIKAL_URI);
define("BAIKAL_DOMAIN", $aUrlInfo["host"]);
define("BAIKAL_URIPATH", $aUrlInfo["path"]);
}
date_default_timezone_set(BAIKAL_TIMEZONE); date_default_timezone_set(BAIKAL_TIMEZONE);

View file

@ -8,6 +8,13 @@ class Details extends \Flake\Core\Controler {
} }
function render() { function render() {
return "<h2>Details !</h2>"; $aParams = $GLOBALS["ROUTER"]::getURLParams();
if(($iUser = intval($aParams[0])) === 0) {
throw new \Exception("BaikalAdmin\Controler\Details::render(): User get-parameter not found.");
}
$oUser = new \Baikal\Model\User($iUser);
return "<h2>Details for user " . $oUser->getLabel() . "</h2>";
} }
} }

View file

@ -2,7 +2,7 @@
define("BAIKALADMIN_PATH_ROOT", dirname(dirname(__FILE__)) . "/"); define("BAIKALADMIN_PATH_ROOT", dirname(dirname(__FILE__)) . "/");
# Bootstrap Baikal Core # Bootstrap Baïkal Core
require_once(dirname(dirname(dirname(__FILE__))) . "/Baikal/Core/Bootstrap.php"); # ../../, symlink-safe require_once(dirname(dirname(dirname(__FILE__))) . "/Baikal/Core/Bootstrap.php"); # ../../, symlink-safe
# Bootstrap Flake # Bootstrap Flake
@ -15,7 +15,8 @@ require_once(dirname(dirname(dirname(__FILE__))) . "/Formal/Core/Bootstrap.php")
require_once(dirname(__FILE__) . '/ClassLoader.php'); require_once(dirname(__FILE__) . '/ClassLoader.php');
\BaikalAdmin\Core\ClassLoader::register(); \BaikalAdmin\Core\ClassLoader::register();
define("BAIKALADMIN_URIPATH", \Flake\Util\Tools::trimSlashes(dirname($_SERVER["SCRIPT_NAME"])) . "/"); # Relative to BAIKAL_URI; so that BAIKAL_URI . BAIKALADMIN_URIPATH corresponds to the full URL to Baïkal admin
define("BAIKALADMIN_URIPATH", "admin/");
# Include BaikalAdmin Framework config # Include BaikalAdmin Framework config
require_once(BAIKALADMIN_PATH_ROOT . "config.php"); require_once(BAIKALADMIN_PATH_ROOT . "config.php");

View file

@ -1,21 +1,22 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8" />
<title>{pagetitle}</title> <title>{pagetitle}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <base href="{baseurl}" />
<meta name="description" content=""> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="author" content=""> <meta name="description" content="" />
<meta name="author" content="" />
<!-- Le styles --> <!-- Le styles -->
<link href="/res/core/TwitterBootstrap/css/bootstrap.css" rel="stylesheet"> <link href="res/core/TwitterBootstrap/css/bootstrap.css" rel="stylesheet" />
<link href="/res/core/BaikalAdmin/Templates/Page/style.css" rel="stylesheet"> <link href="res/core/BaikalAdmin/Templates/Page/style.css" rel="stylesheet" />
<style> <style>
body { body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */ padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
} }
</style> </style>
<link href="/res/core/TwitterBootstrap/css/bootstrap-responsive.css" rel="stylesheet"> <link href="res/core/TwitterBootstrap/css/bootstrap-responsive.css" rel="stylesheet" />
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements --> <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]> <!--[if lt IE 9]>
@ -53,8 +54,8 @@
<!-- Le javascript <!-- Le javascript
================================================== --> ================================================== -->
<!-- Placed at the end of the document so the pages load faster --> <!-- Placed at the end of the document so the pages load faster -->
<script src="/res/core/TwitterBootstrap/js/jquery-1.7.1.min.js"></script> <script src="res/core/TwitterBootstrap/js/jquery-1.7.1.min.js"></script>
<script src="/res/core/TwitterBootstrap/js/bootstrap.min.js"></script> <script src="res/core/TwitterBootstrap/js/bootstrap.min.js"></script>
{javascript} {javascript}
</body> </body>
</html> </html>

View file

@ -40,8 +40,8 @@ require_once(dirname(__FILE__) . "/Core/Bootstrap.php");
# Create and setup a page object # Create and setup a page object
$oPage = new \Flake\Controler\Page(BAIKALADMIN_PATH_TEMPLATES . "Page/index.html"); $oPage = new \Flake\Controler\Page(BAIKALADMIN_PATH_TEMPLATES . "Page/index.html");
$oPage->injectHTTPHeaders(); $oPage->injectHTTPHeaders();
$oPage->setTitle(FLAKE_BASEURL); $oPage->setTitle("Baïkal Web Admin");
$oPage->setBaseUrl(FLAKE_BASEURL); $oPage->setBaseUrl(BAIKAL_URI);
# Route the request # Route the request
$GLOBALS["ROUTER"]::route($oPage); $GLOBALS["ROUTER"]::route($oPage);

View file

@ -13,6 +13,7 @@ PATH_CONFIGFILE=$PATH_SPECIFIC"config.php"
MONGOOSE_BUILDS=$PATH_SCRIPTDIR"builds/" MONGOOSE_BUILDS=$PATH_SCRIPTDIR"builds/"
MONGOOSE_CGI=$PATH_SCRIPTDIR"cgi/" MONGOOSE_CGI=$PATH_SCRIPTDIR"cgi/"
MONGOOSE_SERVERNAME="mongoose"
function whichOS() { function whichOS() {
echo $(uname -s) echo $(uname -s)
@ -70,4 +71,4 @@ echo "Serving Standalone Baïkal $BAIKAL_VERSION on port $BAIKAL_STANDALONE_PORT
MONGOOSE_BIN="$MONGOOSE_BUILDS""$MONGOOSE_BINDIST""/mongoose" MONGOOSE_BIN="$MONGOOSE_BUILDS""$MONGOOSE_BINDIST""/mongoose"
MONGOOSE_CGIBIN="$MONGOOSE_CGI""$MONGOOSE_BINDIST""/php-cgi" MONGOOSE_CGIBIN="$MONGOOSE_CGI""$MONGOOSE_BINDIST""/php-cgi"
`$MONGOOSE_BIN -d no -p $BAIKAL_STANDALONE_PORT -I $MONGOOSE_CGIBIN -i index.html,index.php -r $PATH_DOCROOT` `$MONGOOSE_BIN -d no -p $BAIKAL_STANDALONE_PORT -I $MONGOOSE_CGIBIN -i index.html,index.php -r $PATH_DOCROOT -R $MONGOOSE_SERVERNAME`

View file

@ -1,5 +1,11 @@
<?php <?php
if(array_key_exists("SERVER_NAME", $_SERVER) && $_SERVER["SERVER_NAME"] === "mongoose") {
define("MONGOOSE_SERVER", TRUE);
} else {
define("MONGOOSE_SERVER", FALSE);
}
define("FLAKE_PATH_ROOT", dirname(dirname(__FILE__)) . "/"); # ../ define("FLAKE_PATH_ROOT", dirname(dirname(__FILE__)) . "/"); # ../
// les notices PHP ne sont pas affichées // les notices PHP ne sont pas affichées
@ -34,7 +40,6 @@ $GLOBALS["ROUTER"] = \Flake\Util\Tools::router();
if(!\Flake\Util\Tools::isCliPhp()) { if(!\Flake\Util\Tools::isCliPhp()) {
ini_set("html_errors", TRUE); ini_set("html_errors", TRUE);
session_start(); session_start();
\Flake\Util\Tools::decode_GET();
} }
setlocale(LC_ALL, FLAKE_LOCALE); setlocale(LC_ALL, FLAKE_LOCALE);

View file

@ -79,6 +79,13 @@ abstract class Router extends \Flake\Core\FLObject {
return "/" . $sRoute . "/" . $sParams; return "/" . $sRoute . "/" . $sParams;
} }
public static abstract function getCurrentRoute(); # should be abstract, but is not, because of PHP's strict standards
public static abstract function getURLParams(); public static function getCurrentRoute() {
}
# should be abstract, but is not, because of PHP's strict standards
public static function getURLParams() {
}
} }

View file

@ -6,8 +6,9 @@ class QuestionMarkRewrite extends \Flake\Util\Router {
public static function getCurrentRoute() { public static function getCurrentRoute() {
$sUrl = \Flake\Util\Tools::trimSlashes($GLOBALS["_SERVER"]["REQUEST_URI"]); # REDIRECT_URL for ServerRewrite $sUrl = \Flake\Util\Tools::trimSlashes(
$sScriptDir = \Flake\Util\Tools::appendSlash(dirname($GLOBALS["_SERVER"]["SCRIPT_NAME"])); \Flake\Util\Tools::getCurrentUrl()
);
if(trim($sUrl) === "") { if(trim($sUrl) === "") {
return "default"; return "default";
@ -43,7 +44,7 @@ class QuestionMarkRewrite extends \Flake\Util\Router {
return $sRoute; return $sRoute;
} }
public static function buildRoute(/* undetermined number of parameters */) { public static function buildRoute($sRoute /* [, $sParam, $sParam2, ...] */) {
$aParams = func_get_args(); $aParams = func_get_args();
$sUrl = call_user_func_array("parent::buildRoute", $aParams); $sUrl = call_user_func_array("parent::buildRoute", $aParams);
return "?" . $sUrl; return "?" . $sUrl;
@ -57,7 +58,18 @@ class QuestionMarkRewrite extends \Flake\Util\Router {
# Pos+0 = position of "?" # Pos+0 = position of "?"
# Pos+1 = position of "route" # Pos+1 = position of "route"
# Pos+2 = position of first param # Pos+2 = position of first param
return array_slice($aTokens, $iPosQuestionMark + 2); $sRouteUrl = implode("/", array_slice($aTokens, $iPosQuestionMark + 1));
$sCurrentRoute = $GLOBALS["ROUTER"]::getCurrentRoute();
if(strpos($sRouteUrl, $sCurrentRoute) === FALSE) {
throw new \Exception("Flake\Util\Router\QuestionMarkRewrite::getURLParams(): unrecognized route.");
}
$sParams = \Flake\Util\Tools::trimSlashes(substr($sRouteUrl, strlen($sCurrentRoute)));
if($sParams !== "") {
return explode("/", $sParams);
}
} }
return array(); return array();

View file

@ -5,7 +5,16 @@ namespace Flake\Util;
class Tools extends \Flake\Core\FLObject { class Tools extends \Flake\Core\FLObject {
public static function getCurrentUrl() { public static function getCurrentUrl() {
return $_SERVER["REQUEST_URI"]; if(MONGOOSE_SERVER) {
$sUrl = $GLOBALS["_SERVER"]["REQUEST_URI"];
if(trim($GLOBALS["_SERVER"]["QUERY_STRING"]) !== "") {
$sUrl .= "?" . $GLOBALS["_SERVER"]["QUERY_STRING"];
}
} else {
$sUrl = $GLOBALS["_SERVER"]["REQUEST_URI"]; # Would be REDIRECT_URL for ServerRewrite
}
return $sUrl;
} }
public static function getUrlTokens() { public static function getUrlTokens() {
@ -28,27 +37,6 @@ class Tools extends \Flake\Core\FLObject {
return str_replace($sSep, $sGlue, $sRes); return str_replace($sSep, $sGlue, $sRes);
} }
public static function absolutizeURL($sUrl) {
$aUrl = parse_url($sUrl);
if($aUrl["scheme"] !== "http" && $aUrl["scheme"] !== "https") {
if($sUrl{0} === "/") {
$sUrl = substr($sUrl, 1);
}
return FLAKE_BASEURL . $sUrl;
}
return $sUrl;
}
public static function serverToAbsoluteWebPath($sAbsoluteServerPath) {
if(substr($sAbsoluteServerPath, 0, strlen(FLAKE_PATH_WWWROOT)) === FLAKE_PATH_WWWROOT) {
return FLAKE_BASEURL . substr($sAbsoluteServerPath, strlen(FLAKE_PATH_WWWROOT));
}
return $sAbsoluteServerPath;
}
public static function serverToRelativeWebPath($sAbsPath) { public static function serverToRelativeWebPath($sAbsPath) {
return "/" . str_replace(FLAKE_PATH_WWWROOT, "", $sAbsPath); return "/" . str_replace(FLAKE_PATH_WWWROOT, "", $sAbsPath);
} }
@ -162,37 +150,6 @@ class Tools extends \Flake\Core\FLObject {
); );
} }
public static function makeLink($sAction, $aAdditionalParams = FALSE) {
if($aAdditionalParams === FALSE) {
// aucun paramètre additionnel
if(trim($sAction) === "home") {
return FLAKE_BASEURL;
} else {
return FLAKE_BASEURL . "?action=" . rawurlencode($sAction);
}
} else {
$aTemp = array();
while(list($sKey,) = each($aAdditionalParams)) {
if($sKey{0} === "u" && $sKey{1} === "_") {
// il s'agit d'un message textuel; on l'encode en base 64
$aTemp[] = rawurlencode($sKey) . "=" . rawurlencode(base64_encode($aAdditionalParams[$sKey]));
} else {
$aTemp[] = rawurlencode($sKey) . "=" . rawurlencode($aAdditionalParams[$sKey]);
}
}
$sAdditionalParams = implode("&", $aTemp);
if(trim($sAction) === "home") {
return FLAKE_BASEURL . "?" . $sAdditionalParams;
} else {
return FLAKE_BASEURL . "?action=" . $sAction . "&" . $sAdditionalParams;
}
}
}
public static function safelock($sString) { public static function safelock($sString) {
return substr(md5(FLAKE_SAFEHASH_SALT . ":" . $sString), 0, 5); return substr(md5(FLAKE_SAFEHASH_SALT . ":" . $sString), 0, 5);
} }
@ -213,19 +170,6 @@ class Tools extends \Flake\Core\FLObject {
exit(0); exit(0);
} }
public static function decode_GET() {
$aGet = \Flake\Util\Tools::GET();
$aKeys = array_keys($aGet);
while(list(,$sKey) = each($aKeys)) {
if($sKey{0} === "u" && $sKey{1} === "_") {
$aGet[$sKey] = base64_decode($aGet[$sKey]);
}
}
$GLOBALS["_GET"] = $aGet;
reset($GLOBALS["_GET"]);
}
public static function validEmail($sEmail) { public static function validEmail($sEmail) {
return (filter_var($sEmail, FILTER_VALIDATE_EMAIL) !== FALSE); return (filter_var($sEmail, FILTER_VALIDATE_EMAIL) !== FALSE);
} }

View file

@ -5,7 +5,4 @@ define("FLAKE_TIMEZONE", BAIKAL_TIMEZONE);
define("FLAKE_PATH_FRAMEWORKS", BAIKAL_PATH_FRAMEWORKS); define("FLAKE_PATH_FRAMEWORKS", BAIKAL_PATH_FRAMEWORKS);
define("FLAKE_PATH_WWWROOT", BAIKAL_PATH_WWWROOT); define("FLAKE_PATH_WWWROOT", BAIKAL_PATH_WWWROOT);
define("FLAKE_SAFEHASH_SALT", "une-clef-super-secrete"); define("FLAKE_SAFEHASH_SALT", "une-clef-super-secrete");
define("FLAKE_LOCALE", "fr_FR.UTF-8"); define("FLAKE_LOCALE", "fr_FR.UTF-8");
# TODO: CHANGE THIS
define("FLAKE_BASEURL", "http://baikal.jeromeschneider.fr/");

View file

@ -9,7 +9,13 @@
define("BAIKAL_TIMEZONE", "Europe/Paris"); define("BAIKAL_TIMEZONE", "Europe/Paris");
# Absolute Baïkal URI; end with slash; includes protocol (http:// or https://), port (optional) and subfolders if any # Absolute Baïkal URI; end with slash; includes protocol (http:// or https://), port (optional) and subfolders if any
define("BAIKAL_URI", "http://baikal.jeromeschneider.fr/"); if($_SERVER["SERVER_NAME"] === "mongoose") {
define("BAIKAL_URI", "/");
} elseif(array_key_exists("HTTP_HOST", $_SERVER) && $_SERVER["HTTP_HOST"] === "subbaikal.jeromeschneider.fr") {
define("BAIKAL_URI", "http://subbaikal.jeromeschneider.fr/html/");
} else {
define("BAIKAL_URI", "http://baikal.jeromeschneider.fr/");
}
############################################################################## ##############################################################################
# In this section: Optional configuration: you *may* customize these settings # In this section: Optional configuration: you *may* customize these settings