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");
# Determining baikal protocol, domain and uri-path (looking at BAIKAL_URI)
$aUrlInfo = parse_url(BAIKAL_URI);
define("BAIKAL_DOMAIN", $aUrlInfo["host"]);
define("BAIKAL_URIPROTOCOL", $aUrlInfo["scheme"]);
define("BAIKAL_URIPATH", $aUrlInfo["path"]);
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_URIPATH", "");
} else {
$aUrlInfo = parse_url(BAIKAL_URI);
define("BAIKAL_DOMAIN", $aUrlInfo["host"]);
define("BAIKAL_URIPATH", $aUrlInfo["path"]);
}
date_default_timezone_set(BAIKAL_TIMEZONE);

View file

@ -8,6 +8,13 @@ class Details extends \Flake\Core\Controler {
}
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__)) . "/");
# Bootstrap Baikal Core
# Bootstrap Baïkal Core
require_once(dirname(dirname(dirname(__FILE__))) . "/Baikal/Core/Bootstrap.php"); # ../../, symlink-safe
# Bootstrap Flake
@ -15,7 +15,8 @@ require_once(dirname(dirname(dirname(__FILE__))) . "/Formal/Core/Bootstrap.php")
require_once(dirname(__FILE__) . '/ClassLoader.php');
\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
require_once(BAIKALADMIN_PATH_ROOT . "config.php");

View file

@ -1,21 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta charset="utf-8" />
<title>{pagetitle}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<base href="{baseurl}" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="" />
<meta name="author" content="" />
<!-- Le styles -->
<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/TwitterBootstrap/css/bootstrap.css" rel="stylesheet" />
<link href="res/core/BaikalAdmin/Templates/Page/style.css" rel="stylesheet" />
<style>
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}
</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 -->
<!--[if lt IE 9]>
@ -53,8 +54,8 @@
<!-- Le javascript
================================================== -->
<!-- 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/bootstrap.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>
{javascript}
</body>
</html>

View file

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

View file

@ -13,6 +13,7 @@ PATH_CONFIGFILE=$PATH_SPECIFIC"config.php"
MONGOOSE_BUILDS=$PATH_SCRIPTDIR"builds/"
MONGOOSE_CGI=$PATH_SCRIPTDIR"cgi/"
MONGOOSE_SERVERNAME="mongoose"
function whichOS() {
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_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
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__)) . "/"); # ../
// les notices PHP ne sont pas affichées
@ -34,7 +40,6 @@ $GLOBALS["ROUTER"] = \Flake\Util\Tools::router();
if(!\Flake\Util\Tools::isCliPhp()) {
ini_set("html_errors", TRUE);
session_start();
\Flake\Util\Tools::decode_GET();
}
setlocale(LC_ALL, FLAKE_LOCALE);

View file

@ -79,6 +79,13 @@ abstract class Router extends \Flake\Core\FLObject {
return "/" . $sRoute . "/" . $sParams;
}
public static abstract function getCurrentRoute();
public static abstract function getURLParams();
# should be abstract, but is not, because of PHP's strict standards
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() {
$sUrl = \Flake\Util\Tools::trimSlashes($GLOBALS["_SERVER"]["REQUEST_URI"]); # REDIRECT_URL for ServerRewrite
$sScriptDir = \Flake\Util\Tools::appendSlash(dirname($GLOBALS["_SERVER"]["SCRIPT_NAME"]));
$sUrl = \Flake\Util\Tools::trimSlashes(
\Flake\Util\Tools::getCurrentUrl()
);
if(trim($sUrl) === "") {
return "default";
@ -43,7 +44,7 @@ class QuestionMarkRewrite extends \Flake\Util\Router {
return $sRoute;
}
public static function buildRoute(/* undetermined number of parameters */) {
public static function buildRoute($sRoute /* [, $sParam, $sParam2, ...] */) {
$aParams = func_get_args();
$sUrl = call_user_func_array("parent::buildRoute", $aParams);
return "?" . $sUrl;
@ -57,7 +58,18 @@ class QuestionMarkRewrite extends \Flake\Util\Router {
# Pos+0 = position of "?"
# Pos+1 = position of "route"
# 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();

View file

@ -5,7 +5,16 @@ namespace Flake\Util;
class Tools extends \Flake\Core\FLObject {
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() {
@ -28,27 +37,6 @@ class Tools extends \Flake\Core\FLObject {
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) {
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) {
return substr(md5(FLAKE_SAFEHASH_SALT . ":" . $sString), 0, 5);
}
@ -213,19 +170,6 @@ class Tools extends \Flake\Core\FLObject {
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) {
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_WWWROOT", BAIKAL_PATH_WWWROOT);
define("FLAKE_SAFEHASH_SALT", "une-clef-super-secrete");
define("FLAKE_LOCALE", "fr_FR.UTF-8");
# TODO: CHANGE THIS
define("FLAKE_BASEURL", "http://baikal.jeromeschneider.fr/");
define("FLAKE_LOCALE", "fr_FR.UTF-8");

View file

@ -9,7 +9,13 @@
define("BAIKAL_TIMEZONE", "Europe/Paris");
# 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