Working on web admin

Former-commit-id: 86769a0a4b
This commit is contained in:
Jérôme Schneider 2012-04-25 23:58:28 +02:00
parent 9c679bbe1c
commit f58f9c7ab1
12 changed files with 85 additions and 253 deletions

View file

@ -142,14 +142,12 @@ if(
$bShouldCheckEnv = ((!defined("BAIKAL_CONTEXT_CLI") || BAIKAL_CONTEXT_CLI === FALSE) && (!defined("BAIKAL_CONTEXT_ADMIN") || BAIKAL_CONTEXT_ADMIN === FALSE));
if($bShouldCheckEnv === TRUE) {
# Mapping PHP errors to exceptions
# Mapping PHP errors to exceptions; needed by SabreDAV
function exception_error_handler($errno, $errstr, $errfile, $errline) {
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler("exception_error_handler");
} else {
error_reporting(E_ALL ^ E_NOTICE);
}
unset($bShouldCheckEnv);

View file

@ -34,7 +34,7 @@ class Topbar extends \Flake\Core\Controller {
public function render() {
$sCurrentRoute = $GLOBALS["ROUTER"]::getCurrentRoute();
$sActiveHome = $sActiveUsers = $sActiveSettings = $sActiveSystemSettings = "";
$sActiveHome = $sActiveUsers = $sActiveSettingsStandard = $sActiveSettingsSystem = "";
$sControllerForDefaultRoute = $GLOBALS["ROUTER"]::getControllerForRoute("default");
$sHomeLink = $sControllerForDefaultRoute::link();

View file

@ -164,12 +164,12 @@ class AddressBooks extends \Flake\Core\Controller {
protected static function newRequested() {
$aParams = $GLOBALS["ROUTER"]::getURLParams();
return $aParams[1] === "new";
return (count($aParams) >= 2) && $aParams[1] === "new";
}
protected static function editRequested() {
$aParams = $GLOBALS["ROUTER"]::getURLParams();
if(($aParams[1] === "edit") && intval($aParams[2]) > 0) {
if((count($aParams) >= 3) && ($aParams[1] === "edit") && intval($aParams[2]) > 0) {
return intval($aParams[2]);
}
@ -178,7 +178,7 @@ class AddressBooks extends \Flake\Core\Controller {
protected static function deleteRequested() {
$aParams = $GLOBALS["ROUTER"]::getURLParams();
if(($aParams[1] === "delete") && intval($aParams[2]) > 0) {
if((count($aParams) >= 3) && ($aParams[1] === "delete") && intval($aParams[2]) > 0) {
return intval($aParams[2]);
}
@ -191,7 +191,7 @@ class AddressBooks extends \Flake\Core\Controller {
}
$aParams = $GLOBALS["ROUTER"]::getURLParams();
if($aParams[3] === "confirm") {
if((count($aParams) >= 4) && $aParams[3] === "confirm") {
return $iPrimary;
}

View file

@ -169,12 +169,12 @@ class Calendars extends \Flake\Core\Controller {
protected static function newRequested() {
$aParams = $GLOBALS["ROUTER"]::getURLParams();
return $aParams[1] === "new";
return (count($aParams) >= 2) && $aParams[1] === "new";
}
protected static function editRequested() {
$aParams = $GLOBALS["ROUTER"]::getURLParams();
if(($aParams[1] === "edit") && intval($aParams[2]) > 0) {
if((count($aParams) >= 3) && ($aParams[1] === "edit") && intval($aParams[2]) > 0) {
return intval($aParams[2]);
}
@ -183,7 +183,7 @@ class Calendars extends \Flake\Core\Controller {
protected static function deleteRequested() {
$aParams = $GLOBALS["ROUTER"]::getURLParams();
if(($aParams[1] === "delete") && intval($aParams[2]) > 0) {
if((count($aParams) >= 3) && ($aParams[1] === "delete") && intval($aParams[2]) > 0) {
return intval($aParams[2]);
}
@ -196,7 +196,7 @@ class Calendars extends \Flake\Core\Controller {
}
$aParams = $GLOBALS["ROUTER"]::getURLParams();
if($aParams[3] === "confirm") {
if((count($aParams) >= 4) && $aParams[3] === "confirm") {
return $iPrimary;
}

View file

@ -134,7 +134,7 @@ class Users extends \Flake\Core\Controller {
protected static function editRequested() {
$aParams = $GLOBALS["ROUTER"]::getURLParams();
if(($aParams[0] === "edit") && intval($aParams[1]) > 0) {
if((count($aParams) >= 2) && ($aParams[0] === "edit") && intval($aParams[1]) > 0) {
return intval($aParams[1]);
}
@ -143,7 +143,7 @@ class Users extends \Flake\Core\Controller {
protected static function deleteRequested() {
$aParams = $GLOBALS["ROUTER"]::getURLParams();
if(($aParams[0] === "delete") && intval($aParams[1]) > 0) {
if((count($aParams) >= 2) && ($aParams[0] === "delete") && intval($aParams[1]) > 0) {
return intval($aParams[1]);
}
@ -156,7 +156,7 @@ class Users extends \Flake\Core\Controller {
}
$aParams = $GLOBALS["ROUTER"]::getURLParams();
if($aParams[2] === "confirm") {
if((count($aParams) >= 3) && $aParams[2] === "confirm") {
return $iUser;
}
@ -165,7 +165,7 @@ class Users extends \Flake\Core\Controller {
protected static function newRequested() {
$aParams = $GLOBALS["ROUTER"]::getURLParams();
return $aParams[0] === "new";
return (count($aParams) >= 1) && $aParams[0] === "new";
}
public static function linkNew() {

View file

@ -37,7 +37,7 @@ class Auth {
static function assertUnlocked() {
if(defined("BAIKAL_CONTEXT_INSTALL") || BAIKAL_CONTEXT_INSTALL !== TRUE) {
if(defined("BAIKAL_CONTEXT_INSTALL") && BAIKAL_CONTEXT_INSTALL === TRUE) {
$sToolName = "Baïkal Install Tool";
} else {
$sToolName = "Baïkal Admin";

View file

@ -1,59 +0,0 @@
<?php
/***************************************************************
* Copyright notice
*
* (c) 2012 Jérôme Schneider <mail@jeromeschneider.fr>
* All rights reserved
*
* http://baikal.codr.fr
*
* This script is part of the Baïkal Server project. The Baïkal
* Server project is free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
namespace Flake\Controller;
class Kickstart extends \Flake\Core\Controller {
public function execute() {
if(array_key_exists("helloworld", self::cli()->aArgs)) {
$this->action_helloworld();
}
}
public static function &cli() {
return $GLOBALS["oCli"];
}
public function __call($sName, $aArguments) {
if(substr($sName, 0, 4) === "cli_") {
$sCallName = substr($sName, 4);
if(method_exists(self::cli(), $sCallName)) {
return call_user_func_array(array(self::cli(), $sCallName), $aArguments);
}
}
die("Undefined method " . $sName);
}
public function render() {
}
public function action_helloworld() {
$this->cli_echoFlush($this->cli_header("Hello, World !"));
}
}

View file

@ -28,71 +28,54 @@ namespace Flake\Controller;
class Page extends \Flake\Core\Render\Container {
var $sTitle = "";
var $sMetaKeywords = "";
var $sMetaDescription = "";
var $sTemplatePath = "";
protected $sTitle = "";
protected $sMetaKeywords = "";
protected $sMetaDescription = "";
protected $sTemplatePath = "";
function __construct($sTemplatePath) {
public function __construct($sTemplatePath) {
$this->sTemplatePath = $sTemplatePath;
}
function setTitle($sTitle) {
public function setTitle($sTitle) {
$this->sTitle = $sTitle;
}
function setMetaKeywords($sKeywords) {
public function setMetaKeywords($sKeywords) {
$this->sMetaKeywords = $sKeywords;
}
function setMetaDescription($sDescription) {
public function setMetaDescription($sDescription) {
$this->sMetaDescription = $sDescription;
}
function getTitle() {
public function getTitle() {
return $this->sTitle;
}
function getMetaKeywords() {
public function getMetaKeywords() {
$sString = str_replace(array("le", "la", "les", "de", "des", "un", "une"), " ", $this->sMetaKeywords);
$sString = \Flake\Util\Tools::stringToUrlToken($sString);
return implode(", ", explode("-", $sString));
}
function getMetaDescription() {
public function getMetaDescription() {
return $this->sMetaDescription;
}
function setBaseUrl($sBaseUrl) {
public function setBaseUrl($sBaseUrl) {
$this->sBaseUrl = $sBaseUrl;
}
function getBaseUrl() {
public function getBaseUrl() {
return $this->sBaseUrl;
}
function renderBlocks() {
$aHtml = array();
reset($this->aSequence);
while(list($sKey,) = each($this->aSequence)) {
$this->aSequence[$sKey]["rendu"] = $this->aSequence[$sKey]["block"]->render();
}
$aHtml = array();
reset($this->aBlocks);
while(list($sZone,) = each($this->aBlocks)) {
$aHtml[$sZone] = implode("", $this->aBlocks[$sZone]);
}
reset($aHtml);
return $aHtml;
public function injectHTTPHeaders() {
header("Content-Type: text/html; charset=UTF-8");
}
function injectHTTPHeaders() {
header("Content-Type: text/html; charset=utf-8");
}
function render() {
public function render() {
$this->execute();
$aRenderedBlocks = $this->renderBlocks();
@ -109,35 +92,56 @@ class Page extends \Flake\Core\Render\Container {
return $sHtml;
}
function execute() {
public function execute() {
reset($this->aSequence);
while(list($sKey,) = each($this->aSequence)) {
$this->aSequence[$sKey]["block"]->execute();
}
}
function addCss($sCssAbsPath) {
public function addCss($sCssAbsPath) {
$sCompiledPath = PATH_buildcss;
$sFileName = basename($sCssAbsPath);
$sCompiledFilePath = $sCompiledPath . \Flake\Util\Tools::shortMD5($sFileName) . "_" . $sFileName;
if(substr(strtolower($sCompiledFilePath), -4) !== ".css") {
$sCompiledFilePath .= ".css";
}
if(!file_exists($sCompiledPath)) {
@mkdir($sCompiledPath);
if(!file_exists($sCompiledPath)) {
die("Page: Cannot create " . $sCompiledPath);
if(\Flake\Util\Frameworks::enabled("LessPHP")) {
$sCompiledPath = PATH_buildcss;
$sFileName = basename($sCssAbsPath);
$sCompiledFilePath = $sCompiledPath . \Flake\Util\Tools::shortMD5($sFileName) . "_" . $sFileName;
if(substr(strtolower($sCompiledFilePath), -4) !== ".css") {
$sCompiledFilePath .= ".css";
}
if(!file_exists($sCompiledPath)) {
@mkdir($sCompiledPath);
if(!file_exists($sCompiledPath)) {
die("Page: Cannot create " . $sCompiledPath);
}
}
\Frameworks\LessPHP\Delegate::compileCss($sCssAbsPath, $sCompiledFilePath);
$sCssUrl = \Flake\Util\Tools::serverToRelativeWebPath($sCompiledFilePath);
} else {
$sCssUrl = \Flake\Util\Tools::serverToRelativeWebPath($sCssAbsPath);
}
\Frameworks\LessPHP\Delegate::compileCss($sCssAbsPath, $sCompiledFilePath);
$sCssUrl = \Flake\Util\Tools::serverToRelativeWebPath($sCompiledFilePath);
$sHtml = "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . $sCssUrl . "\" media=\"all\"/>";
$this->zone("head")->addBlock(new \Flake\Controller\HtmlBlock($sHtml));
}
protected function renderBlocks() {
$aHtml = array();
reset($this->aSequence);
while(list($sKey,) = each($this->aSequence)) {
$this->aSequence[$sKey]["rendu"] = $this->aSequence[$sKey]["block"]->render();
}
$aHtml = array();
reset($this->aBlocks);
while(list($sZone,) = each($this->aBlocks)) {
$aHtml[$sZone] = implode("", $this->aBlocks[$sZone]);
}
reset($aHtml);
return $aHtml;
}
}

View file

@ -162,7 +162,8 @@ class Sql extends \Flake\Core\FLObject {
protected function &reify($aData) {
$sTemp = $this->sModelClass;
return new $sTemp($aData[$sTemp::getPrimaryKey()]);
$res = new $sTemp($aData[$sTemp::getPrimaryKey()]);
return $res; # To address 'Notice: Only variable references should be returned by reference'
}
public function hasBeenExecuted() {
@ -170,9 +171,11 @@ class Sql extends \Flake\Core\FLObject {
}
public function getQuery() {
if(empty($this->aClauses)) {
$sWhere = "1=1";
} else {
$sWhere = "1=1";
$sOrderBy = "";
$sLimit = "";
if(!empty($this->aClauses)) {
$sWhere = implode(" AND ", $this->aClauses);
}
@ -180,8 +183,6 @@ class Sql extends \Flake\Core\FLObject {
$sOrderBy = $this->sOrderField . " " . $this->sOrderDirection;
}
$sLimit = "";
if($this->iLimitStart !== FALSE) {
if($this->iLimitNumber !== FALSE) {
$sLimit = $this->iLimitStart . ", " . $this->iLimitNumber;

View file

@ -1,117 +0,0 @@
<?php
/***************************************************************
* Copyright notice
*
* (c) 2012 Jérôme Schneider <mail@jeromeschneider.fr>
* All rights reserved
*
* http://baikal.codr.fr
*
* This script is part of the Baïkal Server project. The Baïkal
* Server project is free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
namespace Flake\Core\Requester;
class Universal extends \Flake\Core\Requester {
protected $aClauses = array(
"equals" => array(),
"notequals" => array(),
"like" => array(),
"likebeginning" => array(),
"likeend" => array(),
"notlike" => array(),
"notlikebeginning" => array(),
"notlikeend" => array(),
"in" => array(),
"notin" => array(),
);
protected $sModelClass = "";
protected $sOrderField = "";
protected $sOrderDirection = "ASC";
protected $iLimitStart = FALSE;
protected $iLimitNumber = FALSE;
protected $bHasBeenExecuted = FALSE;
public function __call($sName, $aArguments) {
if(substr(strtolower($sName), 0, 9) === "addclause") {
array_unshift($aArguments, substr(strtolower($sName), 9));
return call_user_func_array(array($this, "addClause"), $aArguments);
} elseif(substr(strtolower($sName), 0, 10) === "getclauses") {
return call_user_func_array(array($this, "getClauses"), array(substr(strtolower($sName), 10)));
}
throw new \Exception("__get(): method " . htmlspecialchars($sName) . " not found");
}
public function addClause($sClauseType, $sPropName, $sPropValue) {
if(is_numeric($sClauseType) || !array_key_exists($sClauseType, $this->aClauses)) {
throw new \Exception("Undefined clause type: " . htmlspecialchars($sClauseType));
}
if(!array_key_exists($sPropName, $this->aClauses[$sClauseType])) {
$this->aClauses[$sClauseType][$sPropName] = array();
}
$this->aClauses[$sClauseType][$sPropName][] = $sPropValue;
return $this;
}
public function getClauses($sClauseType) {
if(is_numeric($sClauseType) || !array_key_exists($sClauseType, $this->aClauses)) {
throw new \Exception("Undefined clause type: " . htmlspecialchars($sClauseType));
}
reset($this->aClauses[$sClauseType]);
return $this->aClauses[$sClauseType];
}
public function orderBy($sOrderField, $sOrderDirection = "ASC") {
$this->sOrderField = $sOrderField;
$this->sOrderDirection = $sOrderDirection;
return $this;
}
public function setLimitStart($iLimitStart) {
$this->iLimitStart = $iLimitStart;
return $this;
}
public function setLimitNumber($iLimitNumber) {
$this->iLimitNumber = $iLimitNumber;
return $this;
}
protected function &reify($aData) {
die(__FILE__ . ":" . __LINE__ . ": À implémenter");
$sTemp = $this->sModelClass;
return new $sTemp($aData[$sTemp::getPrimaryKey()]);
}
public function hasBeenExecuted() {
return $this->bHasBeenExecuted;
}
public function execute() {
$oCollection = new \Flake\Core\CollectionTyped($this->sModelClass);
$this->bHasBeenExecuted = TRUE;
return $oCollection;
}
}

View file

@ -37,10 +37,15 @@ class QuestionMarkRewrite extends \Flake\Util\Router {
if(trim($sUrl) === "") {
return "default";
} else {
$aMatches = array();
$aURI = parse_url($sUrl);
$sRoutePart = \Flake\Util\Tools::stripBeginSlash($aURI["query"]);
$aMatches = array();
if(array_key_exists("query", $aURI)) {
$sRoutePart = \Flake\Util\Tools::stripBeginSlash($aURI["query"]);
} else {
$sRoutePart = "";
}
$aRoutes = self::getRoutes();
reset($aRoutes);

Binary file not shown.