From 8c37193ba89f9325c9dfdf02083ec005d585d63c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Schneider?= Date: Sat, 24 Mar 2012 00:58:09 +0100 Subject: [PATCH] Pursuing work on web interface. BaikalAdmin is now a Framework, and is based on Flake Former-commit-id: 75a971dac2564011a0740e7fc88210b4aad26006 --- .../Baikal_0.1/Frameworks/Baikal/Includes.php | 33 - .../Frameworks/Baikal/lib/BaikalAdmin.php | 120 ---- .../Frameworks/Baikal/lib/BaikalTemplate.php | 59 -- .../Frameworks/Baikal/lib/BaikalTools.php | 71 --- .../BaikalAdmin/Controler/User/Listing.php | 19 + .../Frameworks/BaikalAdmin/Core/Auth.php | 73 +++ .../Frameworks/BaikalAdmin/Core/Bootstrap.php | 4 + .../BaikalAdmin/Core/ClassLoader.php | 42 ++ .../Frameworks/BaikalAdmin/Model/User.php | 8 + .../Resources/Templates/Page/index.html} | 21 +- .../Resources/Templates/Page/style.css | 28 + .../Resources/Templates/User/Listing.html | 17 + .../BaikalAdmin/Route/User/Listing.php | 10 + .../BaikalAdmin/View/User/Listing.php | 13 + .../Frameworks/BaikalAdmin/config.php | 19 + .../BaikalAdmin}/index.php | 36 +- .../Frameworks/Flake/Controler/Cli.php | 130 ++++ .../Frameworks/Flake/Controler/HtmlBlock.php | 18 + .../Flake/Controler/HtmlBlockTemplated.php | 20 + .../Frameworks/Flake/Controler/Kickstart.php | 37 ++ .../Frameworks/Flake/Controler/Page.php | 119 ++++ .../Baikal_0.1/Frameworks/Flake/Core/Auth.php | 11 + .../Frameworks/Flake/Core/Bootstrap.php | 37 ++ .../Frameworks/Flake/Core/ClassLoader.php | 46 ++ .../Frameworks/Flake/Core/Collection.php | 179 ++++++ .../Frameworks/Flake/Core/CollectionTyped.php | 33 + .../Frameworks/Flake/Core/Controler.php | 22 + .../Frameworks/Flake/Core/Database.php | 161 +++++ .../Frameworks/Flake/Core/Database/Mysql.php | 54 ++ .../Frameworks/Flake/Core/Database/Sqlite.php | 50 ++ .../Frameworks/Flake/Core/FLObject.php | 17 + .../Frameworks/Flake/Core/Model.php | 20 + .../Frameworks/Flake/Core/Model/Db.php | 49 ++ .../Frameworks/Flake/Core/Model/NoDb.php | 11 + .../Flake/Core/Render/Container.php | 28 + .../Frameworks/Flake/Core/Render/Zone.php | 17 + .../Frameworks/Flake/Core/Requester.php | 201 ++++++ .../Frameworks/Flake/Core/Template.php | 36 ++ .../Baikal_0.1/Frameworks/Flake/Core/View.php | 27 + .../Frameworks/Flake/Route/Kickstart/Main.php | 10 + .../Frameworks/Flake/Util/Router.php | 78 +++ .../Frameworks/Flake/Util/Tools.php | 587 ++++++++++++++++++ .../Baikal_0.1/Resources/Web/BaikalAdmin | 1 + .../Baikal_0.1/Resources/Web/README.md | 1 + .../res => Resources/Web}/TwitterBootstrap | 0 .../Baikal_0.1/Resources/baikal.empty.sqlite | Bin 14336 -> 0 bytes INSTALL.md | 0 LICENSE.txt | 0 README.md | 0 html/admin | 1 - html/admin/index.php | 1 + html/res | 1 - html/res/core | 1 + 53 files changed, 2278 insertions(+), 299 deletions(-) delete mode 100644 CoreVersions/Baikal_0.1/Frameworks/Baikal/Includes.php delete mode 100644 CoreVersions/Baikal_0.1/Frameworks/Baikal/lib/BaikalAdmin.php delete mode 100644 CoreVersions/Baikal_0.1/Frameworks/Baikal/lib/BaikalTemplate.php delete mode 100644 CoreVersions/Baikal_0.1/Frameworks/Baikal/lib/BaikalTools.php create mode 100644 CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Controler/User/Listing.php create mode 100644 CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Core/Auth.php create mode 100644 CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Core/Bootstrap.php create mode 100644 CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Core/ClassLoader.php create mode 100644 CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Model/User.php rename CoreVersions/Baikal_0.1/Frameworks/{Baikal/res/template.html => BaikalAdmin/Resources/Templates/Page/index.html} (72%) create mode 100644 CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Resources/Templates/Page/style.css create mode 100644 CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Resources/Templates/User/Listing.html create mode 100644 CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Route/User/Listing.php create mode 100644 CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/View/User/Listing.php create mode 100644 CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/config.php rename CoreVersions/Baikal_0.1/{WWWRoot/admin => Frameworks/BaikalAdmin}/index.php (55%) create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Controler/Cli.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Controler/HtmlBlock.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Controler/HtmlBlockTemplated.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Controler/Kickstart.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Controler/Page.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Auth.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Bootstrap.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Core/ClassLoader.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Collection.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Core/CollectionTyped.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Controler.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Database.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Database/Mysql.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Database/Sqlite.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Core/FLObject.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Model.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Model/Db.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Model/NoDb.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Render/Container.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Render/Zone.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Requester.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Template.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Core/View.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Route/Kickstart/Main.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Util/Router.php create mode 100755 CoreVersions/Baikal_0.1/Frameworks/Flake/Util/Tools.php create mode 120000 CoreVersions/Baikal_0.1/Resources/Web/BaikalAdmin create mode 100644 CoreVersions/Baikal_0.1/Resources/Web/README.md rename CoreVersions/Baikal_0.1/{WWWRoot/res => Resources/Web}/TwitterBootstrap (100%) delete mode 100755 CoreVersions/Baikal_0.1/Resources/baikal.empty.sqlite mode change 100644 => 100755 INSTALL.md mode change 100644 => 100755 LICENSE.txt mode change 100644 => 100755 README.md delete mode 120000 html/admin create mode 120000 html/admin/index.php delete mode 120000 html/res create mode 120000 html/res/core diff --git a/CoreVersions/Baikal_0.1/Frameworks/Baikal/Includes.php b/CoreVersions/Baikal_0.1/Frameworks/Baikal/Includes.php deleted file mode 100644 index 77b90ed..0000000 --- a/CoreVersions/Baikal_0.1/Frameworks/Baikal/Includes.php +++ /dev/null @@ -1,33 +0,0 @@ - -* 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! -***************************************************************/ - -define("BAIKAL_FRAMEWORK_ROOT", dirname(__FILE__) . "/"); -define("BAIKAL_FRAMEWORK_LIBDIR", BAIKAL_FRAMEWORK_ROOT . "lib/"); -define("BAIKAL_FRAMEWORK_RESDIR", BAIKAL_FRAMEWORK_ROOT . "res/"); - -require_once(BAIKAL_FRAMEWORK_LIBDIR . "BaikalTemplate.php"); -require_once(BAIKAL_FRAMEWORK_LIBDIR . "BaikalAdmin.php"); -require_once(BAIKAL_FRAMEWORK_LIBDIR . "BaikalTools.php"); \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Baikal/lib/BaikalAdmin.php b/CoreVersions/Baikal_0.1/Frameworks/Baikal/lib/BaikalAdmin.php deleted file mode 100644 index b2daa1a..0000000 --- a/CoreVersions/Baikal_0.1/Frameworks/Baikal/lib/BaikalAdmin.php +++ /dev/null @@ -1,120 +0,0 @@ - -* 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! -***************************************************************/ - -require_once(BAIKAL_PATH_FRAMEWORKS . "Tabulator/Tabulator.html.php"); - -class BaikalAdmin { - - static function assertEnabled() { - if(!defined("BAIKAL_ADMIN_ENABLED") || BAIKAL_ADMIN_ENABLED !== TRUE) { - die("

Baïkal Admin is disabled.

To enable it, set BAIKAL_ADMIN_ENABLED to TRUE in Specific/config.php"); - } - - $bLocked = TRUE; - $sEnableFile = BAIKAL_PATH_SPECIFIC . "ENABLE_ADMIN"; - if(file_exists($sEnableFile)) { - - clearstatcache(); - $iTime = intval(filemtime($sEnableFile)); - if((time() - $iTime) < 3600) { - // file has been created more than an hour ago - // delete and declare locked - - $bLocked = FALSE; - } else { - if(!@unlink($sEnableFile)) { - die("

Baïkal Admin is locked.

To unlock it, delete and re-create an empty file named ENABLE_ADMIN in Specific/config.php"); - } - } - } - - if($bLocked) { - die("

Baïkal Admin is locked.

To unlock it, create an empty file named ENABLE_ADMIN in Specific/"); - } else { - // update filemtime - @touch($sEnableFile); - } - } - - static function assertAuthentified() { - if(!self::isAuthentified()) { - header(utf8_decode('WWW-Authenticate: Basic realm="Baïkal admin"')); - header('HTTP/1.0 401 Unauthorized'); - die("Please authenticate."); - } - - return TRUE; - } - - static function isAuthentified() { - - if(array_key_exists("PHP_AUTH_USER", $_SERVER)) { - $sUser = $_SERVER["PHP_AUTH_USER"]; - } else { - $sUser = FALSE; - } - - if(array_key_exists("PHP_AUTH_PW", $_SERVER)) { - $sPass = $_SERVER["PHP_AUTH_PW"]; - } else { - $sPass = FALSE; - } - - $sPassHash = self::hashAdminPassword($sPass); - - if($sUser === "admin" && $sPassHash === BAIKAL_ADMIN_PASSWORDHASH) { - return TRUE; - } - - return FALSE; - } - - static function hashAdminPassword($sPassword) { - return md5('admin:' . BAIKAL_AUTH_REALM . ':' . $sPassword); - } - - static function wrapWithInterface($sHtml) { - $oTemplate = new BaikalTemplate(BAIKAL_FRAMEWORK_RESDIR . "template.html"); - return $oTemplate->parse(array( - "pagetitle" => "Users", - "pagecontent" => $sHtml - )); - } - - static function displayUsers() { - $aUsers = BaikalTools::getUsers(); - - $oTabulator = new TabulatorHtml("table table-bordered"); - $oTabulator->addColumn(self::makeColumn("id", "Id", "numeric")); - $oTabulator->addColumn(self::makeColumn("username", "Username")); - return $oTabulator->render($aUsers); - } - - static function &makeColumn($sName, $sHeader = "", $sType = "text") { - $oColumn = new TabulatorColumnHtml($sName, $sHeader, $sType); - return $oColumn; - } -} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Baikal/lib/BaikalTemplate.php b/CoreVersions/Baikal_0.1/Frameworks/Baikal/lib/BaikalTemplate.php deleted file mode 100644 index 6a310f6..0000000 --- a/CoreVersions/Baikal_0.1/Frameworks/Baikal/lib/BaikalTemplate.php +++ /dev/null @@ -1,59 +0,0 @@ - -* 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! -***************************************************************/ - -class BaikalTemplate { - - private $sAbsPath = ""; - private $sHtml = ""; - - public function __construct($sAbsPath) { - $this->sAbsPath = $sAbsPath; - $this->sHtml = self::getTemplateFile( - $this->sAbsPath - ); - } - - public function parse($aMarkers = array()) { - return self::parseTemplateCodePhp( - $this->sHtml, - $aMarkers - ); - } - - protected static function getTemplateFile($sAbsPath) { - return file_get_contents($sAbsPath); - } - - protected static function parseTemplateCodePhp($sCode, $aMarkers) { - extract($aMarkers); - ob_start(); - echo eval('?>' . $sCode . ' -* 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! -***************************************************************/ - -class BaikalTools { - public static function &db() { - return $GLOBALS["pdo"]; - } - - public static function getUsers() { - - $aUsers = array(); - - # Fetching user - $stmt = BaikalTools::db()->prepare("SELECT * FROM users"); - $stmt->execute(); - while(($user = $stmt->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_FIRST)) !== FALSE) { - $aUsers[] = $user; - } - - reset($aUsers); - return $aUsers; - } - - static function bashPrompt($prompt) { - print $prompt; - @flush(); - @ob_flush(); - $confirmation = @trim(fgets(STDIN)); - return $confirmation; - } - - static function bashPromptSilent($prompt = "Enter Password:") { - $command = "/usr/bin/env bash -c 'echo OK'"; - - if(rtrim(shell_exec($command)) !== 'OK') { - trigger_error("Can't invoke bash"); - return; - } - - $command = "/usr/bin/env bash -c 'read -s -p \"" - . addslashes($prompt) - . "\" mypassword && echo \$mypassword'"; - - $password = rtrim(shell_exec($command)); - echo "\n"; - return $password; - } -} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Controler/User/Listing.php b/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Controler/User/Listing.php new file mode 100644 index 0000000..7569834 --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Controler/User/Listing.php @@ -0,0 +1,19 @@ +execute(); + $oView = new \BaikalAdmin\View\User\Listing(); + $oView->setData("users", $oUsers); + + return $oView->render(); + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Core/Auth.php b/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Core/Auth.php new file mode 100644 index 0000000..55830e3 --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Core/Auth.php @@ -0,0 +1,73 @@ +Baïkal Admin is disabled.To enable it, set BAIKAL_ADMIN_ENABLED to TRUE in Specific/config.php"); + } + + $bLocked = TRUE; + $sEnableFile = BAIKAL_PATH_SPECIFIC . "ENABLE_ADMIN"; + if(file_exists($sEnableFile)) { + + clearstatcache(); + $iTime = intval(filemtime($sEnableFile)); + if((time() - $iTime) < 3600) { + // file has been created more than an hour ago + // delete and declare locked + + $bLocked = FALSE; + } else { + if(!@unlink($sEnableFile)) { + die("

Baïkal Admin is locked.

To unlock it, delete and re-create an empty file named ENABLE_ADMIN in Specific/config.php"); + } + } + } + + if($bLocked) { + die("

Baïkal Admin is locked.

To unlock it, create an empty file named ENABLE_ADMIN in Specific/"); + } else { + // update filemtime + @touch($sEnableFile); + } + } + + static function assertAuthentified() { + if(!self::isAuthentified()) { + header(utf8_decode('WWW-Authenticate: Basic realm="Baïkal admin"')); + header('HTTP/1.0 401 Unauthorized'); + die("Please authenticate."); + } + + return TRUE; + } + + static function isAuthentified() { + + if(array_key_exists("PHP_AUTH_USER", $_SERVER)) { + $sUser = $_SERVER["PHP_AUTH_USER"]; + } else { + $sUser = FALSE; + } + + if(array_key_exists("PHP_AUTH_PW", $_SERVER)) { + $sPass = $_SERVER["PHP_AUTH_PW"]; + } else { + $sPass = FALSE; + } + + $sPassHash = self::hashAdminPassword($sPass); + + if($sUser === "admin" && $sPassHash === BAIKAL_ADMIN_PASSWORDHASH) { + return TRUE; + } + + return FALSE; + } + + static function hashAdminPassword($sPassword) { + return md5('admin:' . BAIKAL_AUTH_REALM . ':' . $sPassword); + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Core/Bootstrap.php b/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Core/Bootstrap.php new file mode 100644 index 0000000..f29b021 --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Core/Bootstrap.php @@ -0,0 +1,4 @@ +PHP Autoload Error. Cannot find ' . $sFullClassName . ''; + echo "
" . print_r(debug_backtrace(), TRUE) . "
"; + die(); + } + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Model/User.php b/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Model/User.php new file mode 100644 index 0000000..e422041 --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Model/User.php @@ -0,0 +1,8 @@ + - Baïkal Admin + {pagetitle} + - + + - + + + {head} @@ -45,17 +49,14 @@
- -

-

Use this document as a way to quick start any new project.
All you get is this message and a barebones HTML document.

- - + {Payload}
- - + + + {javascript} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Resources/Templates/Page/style.css b/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Resources/Templates/Page/style.css new file mode 100644 index 0000000..01e072d --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Resources/Templates/Page/style.css @@ -0,0 +1,28 @@ +/* Jumbotrons +-------------------------------------------------- */ +.jumbotron { + position: relative; +} +.jumbotron h1 { + margin-bottom: 9px; + font-size: 81px; + font-weight: bold; + letter-spacing: -1px; + line-height: 1; +} +.jumbotron p { + margin-bottom: 18px; + font-weight: 300; +} +.jumbotron .btn-large { + font-size: 20px; + font-weight: normal; + padding: 14px 24px; + margin-right: 10px; + -webkit-border-radius: 6px; + -moz-border-radius: 6px; + border-radius: 6px; +} +.jumbotron .btn-large small { + font-size: 14px; +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Resources/Templates/User/Listing.html b/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Resources/Templates/User/Listing.html new file mode 100644 index 0000000..624b86a --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Resources/Templates/User/Listing.html @@ -0,0 +1,17 @@ +
+

Users

+

List, browse, create, update and delete Baïkal user accounts.

+
+ + + + + + + + + + + + +
idusername
get("id"); ?>get("username"); ?>
\ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Route/User/Listing.php b/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Route/User/Listing.php new file mode 100644 index 0000000..5158631 --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/Route/User/Listing.php @@ -0,0 +1,10 @@ +zone("Payload")->addBlock(new \BaikalAdmin\Controler\User\Listing()); + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/View/User/Listing.php b/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/View/User/Listing.php new file mode 100644 index 0000000..1ea433d --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/View/User/Listing.php @@ -0,0 +1,13 @@ +parse(array( + "users" => $this->get("users"), + )); + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/config.php b/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/config.php new file mode 100644 index 0000000..4feeefd --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/config.php @@ -0,0 +1,19 @@ + "\BaikalAdmin\Route\User\Listing", +); \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/WWWRoot/admin/index.php b/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/index.php similarity index 55% rename from CoreVersions/Baikal_0.1/WWWRoot/admin/index.php rename to CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/index.php index 7574518..4eb5a45 100644 --- a/CoreVersions/Baikal_0.1/WWWRoot/admin/index.php +++ b/CoreVersions/Baikal_0.1/Frameworks/BaikalAdmin/index.php @@ -26,13 +26,41 @@ ini_set("display_errors", 1); error_reporting(E_ALL); + define("BAIKAL_CONTEXT", TRUE); define("BAIKAL_CONTEXT_ADMIN", TRUE); +define("PATH_ENTRYDIR", dirname(__FILE__) . "/"); -require_once(dirname(dirname(dirname(__FILE__))) . "/Bootstrap.php"); # ../../, symlink-safe -require_once(BAIKAL_PATH_FRAMEWORKS . "Baikal/Includes.php"); +# Bootstrap Baikal Core +require_once(dirname(dirname(dirname(dirname(PATH_ENTRYDIR)))) . "/Core/Bootstrap.php"); # ../../../../, symlink-safe + +# Include BaikalAdmin config files +require_once(PATH_ENTRYDIR . "config.php"); + +# Bootstrap BaikalAdmin +require_once(PATH_ENTRYDIR . "Core/Bootstrap.php"); + +# Bootstrap Flake +require_once(FLAKE_PATH_ROOT . "Core/Bootstrap.php"); + +# Evaluate assertions +\BaikalAdmin\Core\Auth::assertEnabled(); +\BaikalAdmin\Core\Auth::assertAuthentified(); + +# 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); + +# Route the request +\Flake\Util\Router::route($oPage); + +# Render the page +echo $oPage->render(); + +/*require_once(BAIKAL_PATH_FRAMEWORKS . "Baikal/Includes.php"); BaikalAdmin::assertEnabled(); BaikalAdmin::assertAuthentified(); - -echo BaikalAdmin::wrapWithInterface(BaikalAdmin::displayUsers()); \ No newline at end of file +BaikalAdmin::handleRequest();*/ \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Flake/Controler/Cli.php b/CoreVersions/Baikal_0.1/Frameworks/Flake/Controler/Cli.php new file mode 100755 index 0000000..afed270 --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/Flake/Controler/Cli.php @@ -0,0 +1,130 @@ +sys_init(); + $this->init(); + + $this->echoFlush($this->notice("process started @" . strftime("%d/%m/%Y %H:%M:%S"))); + $this->execute(); + $this->echoFlush($this->notice("process ended @" . strftime("%d/%m/%Y %H:%M:%S")) . "\n\n"); + } + + function execute() { + reset($this->aSequence); + while(list($sKey,) = each($this->aSequence)) { + $this->aSequence[$sKey]["block"]->execute(); + } + } + + /**************************************************************************/ + + var $sLog = ""; + + function sys_init() { + $this->rawLine("Command line: " . (implode(" ", $_SERVER["argv"]))); + $this->initArgs(); + } + + function init() { + } + + function initArgs() { + $sShortOpts = ""; + $sShortOpts .= "h"; // help; pas de valeur + $sShortOpts .= "w:"; // author; valeur obligatoire + + $aLongOpts = array( + "help", // help; pas de valeur + "helloworld", // author; pas de valeur + ); + + $this->aArgs = getopt($sShortOpts, $aLongOpts); + } + + function getScriptPath() { + return realpath($_SERVER['argv'][0]); + } + + function getSyntax() { + return $this->getScriptPath(); + } + + function syntaxError() { + $sStr = $this->rawLine("Syntax error.\nUsage: " . $this->getSyntax()); + die("\n\n" . $sStr . "\n\n"); + } + + function log($sStr) { + $this->sLog .= $sStr; + } + + function header($sMsg) { + + $sStr = "\n" . str_repeat("#", 80); + $sStr .= "\n" . "#" . str_repeat(" ", 78) . "#"; + $sStr .= "\n" . "#" . str_pad(strtoupper($sMsg), 78, " ", STR_PAD_BOTH) . "#"; + $sStr .= "\n" . "#" . str_repeat(" ", 78) . "#"; + $sStr .= "\n" . str_repeat("#", 80); + $sStr .= "\n"; + + $this->log($sStr); + return $sStr; + } + + function subHeader($sMsg) { + $sStr = "\n\n# " . str_pad(strtoupper($sMsg) . " ", 78, "-", STR_PAD_RIGHT) . "\n"; + $this->log($sStr); + return $sStr; + } + + function subHeader2($sMsg) { + $sStr = "\n# # " . str_pad($sMsg . " ", 76, "-", STR_PAD_RIGHT) . "\n"; + $this->log($sStr); + return $sStr; + } + + function textLine($sMsg) { + $sStr = ". " . $sMsg . "\n"; + $this->log($sStr); + return $sStr; + } + + function rawLine($sMsg) { + $sStr = $sMsg . "\n"; + $this->log($sStr); + return $sStr; + } + + function notice($sMsg) { + $sStr = "\n" . str_pad($sMsg, 80, ".", STR_PAD_BOTH) . "\n"; + $this->log($sStr); + return $sStr; + } + + function getLog() { + return $this->sLog; + } + + function file_writeBin($sPath, $sData, $bUTF8 = TRUE) { + + $rFile = fopen($sPath, "wb"); + + if($bUTF8 === TRUE) { + fputs($rFile, "\xEF\xBB\xBF" . $sData); + } else { + fputs($rFile, $sData); + } + + fclose($rFile); + } + + function echoFlush($sString = "") { + echo $sString; + ob_flush(); + flush(); + } +} diff --git a/CoreVersions/Baikal_0.1/Frameworks/Flake/Controler/HtmlBlock.php b/CoreVersions/Baikal_0.1/Frameworks/Flake/Controler/HtmlBlock.php new file mode 100755 index 0000000..aaf9669 --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/Flake/Controler/HtmlBlock.php @@ -0,0 +1,18 @@ +sHtml = $sHtml; + } + + function execute() { + + } + + function render() { + return $this->sHtml; + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Flake/Controler/HtmlBlockTemplated.php b/CoreVersions/Baikal_0.1/Frameworks/Flake/Controler/HtmlBlockTemplated.php new file mode 100755 index 0000000..803aa67 --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/Flake/Controler/HtmlBlockTemplated.php @@ -0,0 +1,20 @@ +sTemplatePath = $sTemplatePath; + $this->aMarkers = $aMarkers; + } + + function render() { + $oTemplate = new \Flake\Core\Template($this->sTemplatePath); + $sHtml = $oTemplate->parse( + $this->aMarkers + ); + + return $sHtml; + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Flake/Controler/Kickstart.php b/CoreVersions/Baikal_0.1/Frameworks/Flake/Controler/Kickstart.php new file mode 100755 index 0000000..2c03b96 --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/Flake/Controler/Kickstart.php @@ -0,0 +1,37 @@ +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 !")); + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Flake/Controler/Page.php b/CoreVersions/Baikal_0.1/Frameworks/Flake/Controler/Page.php new file mode 100755 index 0000000..9fb1a1b --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/Flake/Controler/Page.php @@ -0,0 +1,119 @@ +sTemplatePath = $sTemplatePath; + } + + function setTitle($sTitle) { + $this->sTitle = $sTitle; + } + + function setMetaKeywords($sKeywords) { + $this->sMetaKeywords = $sKeywords; + } + + function setMetaDescription($sDescription) { + $this->sMetaDescription = $sDescription; + } + + function getTitle() { + return $this->sTitle; + } + + 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() { + return $this->sMetaDescription; + } + + function setBaseUrl($sBaseUrl) { + $this->sBaseUrl = $sBaseUrl; + } + + 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; + } + + function injectHTTPHeaders() { + header("Content-Type: text/html; charset=utf-8"); + } + + function render() { + $this->execute(); + + $aRenderedBlocks = $this->renderBlocks(); + $aRenderedBlocks["pagetitle"] = $this->getTitle(); + $aRenderedBlocks["pagemetakeywords"] = $this->getMetaKeywords(); + $aRenderedBlocks["pagemetadescription"] = $this->getMetaDescription(); + $aRenderedBlocks["baseurl"] = $this->getBaseUrl(); + + $oTemplate = new \Flake\Core\Template($this->sTemplatePath); + $sHtml = $oTemplate->parse( + $aRenderedBlocks + ); + + return $sHtml; + } + + function execute() { + reset($this->aSequence); + while(list($sKey,) = each($this->aSequence)) { + $this->aSequence[$sKey]["block"]->execute(); + } + } + + 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); + } + } + + \Frameworks\LessPHP\Delegate::compileCss($sCssAbsPath, $sCompiledFilePath); + $sCssUrl = \Flake\Util\Tools::serverToRelativeWebPath($sCompiledFilePath); + + $sHtml = ""; + $this->zone("head")->addBlock(new \Flake\Controler\HtmlBlock($sHtml)); + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Auth.php b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Auth.php new file mode 100755 index 0000000..cd731aa --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Auth.php @@ -0,0 +1,11 @@ +init(FLAKE_DB_FILEPATH); + +$GLOBALS["TEMPLATESTACK"] = array(); \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/ClassLoader.php b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/ClassLoader.php new file mode 100755 index 0000000..053ccb1 --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/ClassLoader.php @@ -0,0 +1,46 @@ +PHP Autoload Error. Cannot find ' . $sFullClassName . ''; + echo "
" . print_r(debug_backtrace(), TRUE) . "
"; + die(); + } + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Collection.php b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Collection.php new file mode 100755 index 0000000..ed91998 --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Collection.php @@ -0,0 +1,179 @@ +aCollection); + } + + public function key() { + return key($this->aCollection); + } + + public function next() { + return next($this->aCollection); + } + + public function rewind() { + $this->reset(); + } + + public function valid() { + $key = key($this->aCollection); + return ($key !== NULL && $key !== FALSE); + } + + public function &each() { + list($key, $val) = each($this->aCollection); + return $val; + } + + public function reset() { + reset($this->aCollection); + } + + public function prev() { + return prev($this->aCollection); + } + + /* + * Retourne le nombre d'élémént + * + * @return int nombre l'éléments + */ + public function count() { + return count($this->aCollection); + } + + /* + * Retourne le tableau des clés + * + * @return array tableau des clés + */ + public function keys() { + return array_keys($this->aCollection); + } + + /* + * Vérifie si la collection est vide + * + * @return bool TRUE si la collection est vide + */ + public function isEmpty() { + return $this->count() === 0; + } + + public function isAtFirst() { + return $this->key() === array_shift($this->keys()); + } + + public function isAtLast() { + return $this->key() === array_pop($this->keys()); + } + + /* + * Insère un élément dans la collection + * + * @param $mMixed valeur à insérer dans la collection + * @return void + */ + public function push(&$mMixed) { + array_push($this->aCollection, $mMixed); + } + + /* + * Vide la collection + * + * @return void + */ + public function flush() { + unset($this->aCollection); + $this->aCollection = array(); + } + + /* + * Retourne le premier élément de la collection + * + * @return mixed premier élément de la collection + */ + public function &first() { + if(!$this->isEmpty()) { + $aKeys = $this->keys(); + return $this->aCollection[array_shift($aKeys)]; + } + + return null; + } + + public function &last() { + if(!$this->isEmpty()) { + $aKeys = $this->keys(); + return $this->aCollection[array_pop($aKeys)]; + } + + return null; + } + + /* + * Converti la collection en tableau + * + * @return array collection sous forme de tableau + */ + public function toArray() { + return $this->aCollection; + } + + /* + * Méthode magique __call + * + * @param $sName string nom de la méthode + * @param $aArguments array argument passé initialement + * @return mixed valeur de la collection correspond + */ + public function &__call($sName, $aArguments) { + if( + strlen($sName) > 7 && + $sName{0} === "s" && + $sName{1} === "e" && + $sName{2} === "t" && + $sName{3} === "M" && + $sName{4} === "e" && + $sName{5} === "t" && + $sName{6} === "a" + ) { + $sKey = strtolower(substr($sName, 7, 1)) . substr($sName, 8); + $mValue =& $aArguments[0]; + + if(is_null($mValue)) { + if(array_key_exists($sKey, $this->aMeta)) { + unset($this->aMeta[$sKey]); + } + } else { + $this->aMeta[$sKey] =& $mValue; + } + + } elseif( + strlen($sName) > 7 && + $sName{0} === "g" && + $sName{1} === "e" && + $sName{2} === "t" && + $sName{3} === "M" && + $sName{4} === "e" && + $sName{5} === "t" && + $sName{6} === "a" + ) { + $sKey = strtolower(substr($sName, 7, 1)) . substr($sName, 8); + if(array_key_exists($sKey, $this->aMeta)) { + return $this->aMeta[$sKey]; + } else { + return null; + } + } else { + throw new \Exception("Method " . $sName . "() not found on " . self::getClass()); + } + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/CollectionTyped.php b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/CollectionTyped.php new file mode 100755 index 0000000..9879777 --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/CollectionTyped.php @@ -0,0 +1,33 @@ +sTypeClassOrProtocol = $sTypeClassOrProtocol; + $this->setMetaType($this->sTypeClassOrProtocol); + } + + /* + * Insère un élément dans la collection + * + * @param $mMixed mixed valeur à insérer dans la collection + * @return void + */ + public function push(&$mMixed) { + if(!\Flake\Util\Tools::is_a($mMixed, $this->sTypeClassOrProtocol)) { + throw new \Exception("\Flake\Core\CollectionTyped<" . $this->sTypeClassOrProtocol . ">: Given object is not correctly typed."); + } + + parent::push($mMixed); + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Controler.php b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Controler.php new file mode 100755 index 0000000..ce6b6ff --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Controler.php @@ -0,0 +1,22 @@ +aParams = $aParams; + } + + abstract function execute(); + abstract function render(); + + public static function buildRouteWithParams() { + $aParams = func_get_args(); + $sControler = "\\" . get_called_class(); + array_unshift($aParams, $sControler); + return call_user_func_array("\Flake\Util\Router::buildRouteForControlerWithParams", $aParams); + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Database.php b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Database.php new file mode 100755 index 0000000..e54ef76 --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Database.php @@ -0,0 +1,161 @@ +" . get_class($this) . ": " . $sMessage . ""; + die($sError); + } + + function exec_INSERTquery($table,$fields_values,$no_quote_fields=FALSE) { + return $this->query($this->INSERTquery($table,$fields_values,$no_quote_fields)); + } + + function INSERTquery($table,$fields_values,$no_quote_fields=FALSE) { + + // Table and fieldnames should be "SQL-injection-safe" when supplied to this function (contrary to values in the arrays which may be insecure). + if (is_array($fields_values) && count($fields_values)) { + + // quote and escape values + $fields_values = $this->fullQuoteArray($fields_values,$table,$no_quote_fields); + + // Build query: + $query = 'INSERT INTO '.$table.' + ( + '.implode(', + ',array_keys($fields_values)).' + ) VALUES ( + '.implode(', + ',$fields_values).' + )'; + + // Return query: + if ($this->debugOutput || $this->store_lastBuiltQuery) $this->debug_lastBuiltQuery = $query; + return $query; + } + } + + function exec_UPDATEquery($table,$where,$fields_values,$no_quote_fields=FALSE) { + return $this->query($this->UPDATEquery($table,$where,$fields_values,$no_quote_fields)); + } + + function UPDATEquery($table,$where,$fields_values,$no_quote_fields=FALSE) { + + // Table and fieldnames should be "SQL-injection-safe" when supplied to this function (contrary to values in the arrays which may be insecure). + if (is_string($where)) { + if (is_array($fields_values) && count($fields_values)) { + + // quote and escape values + $nArr = $this->fullQuoteArray($fields_values,$table,$no_quote_fields); + + $fields = array(); + foreach ($nArr as $k => $v) { + $fields[] = $k.'='.$v; + } + + // Build query: + $query = 'UPDATE '.$table.' + SET + '.implode(', + ',$fields). + (strlen($where)>0 ? ' + WHERE + '.$where : ''); + + // Return query: + if ($this->debugOutput || $this->store_lastBuiltQuery) $this->debug_lastBuiltQuery = $query; + return $query; + } + } else { + die('Fatal Error: "Where" clause argument for UPDATE query was not a string in $this->UPDATEquery() !'); + } + } + + function exec_DELETEquery($table,$where) { + return $this->query($this->DELETEquery($table,$where)); + } + + function DELETEquery($table,$where) { + if (is_string($where)) { + + // Table and fieldnames should be "SQL-injection-safe" when supplied to this function + $query = 'DELETE FROM '.$table. + (strlen($where)>0 ? ' + WHERE + '.$where : ''); + + if ($this->debugOutput || $this->store_lastBuiltQuery) $this->debug_lastBuiltQuery = $query; + return $query; + } else { + die('Fatal Error: "Where" clause argument for DELETE query was not a string in $this->DELETEquery() !'); + } + } + + function exec_SELECTquery($select_fields,$from_table,$where_clause,$groupBy='',$orderBy='',$limit='') { + return $this->query($this->SELECTquery($select_fields,$from_table,$where_clause,$groupBy,$orderBy,$limit)); + } + + function SELECTquery($select_fields,$from_table,$where_clause,$groupBy='',$orderBy='',$limit='') { + + // Table and fieldnames should be "SQL-injection-safe" when supplied to this function + // Build basic query: + $query = 'SELECT '.$select_fields.' + FROM '.$from_table. + (strlen($where_clause)>0 ? ' + WHERE + '.$where_clause : ''); + + // Group by: + if (strlen($groupBy)>0) { + $query.= ' + GROUP BY '.$groupBy; + } + // Order by: + if (strlen($orderBy)>0) { + $query.= ' + ORDER BY '.$orderBy; + } + // Group by: + if (strlen($limit)>0) { + $query.= ' + LIMIT '.$limit; + } + + // Return query: + if ($this->debugOutput || $this->store_lastBuiltQuery) $this->debug_lastBuiltQuery = $query; + return $query; + } + + function fullQuoteStr($str, $table) { + return '\''.$this->quoteStr($str, $table).'\''; + } + + function fullQuoteArray($arr, $table, $noQuote=FALSE) { + if (is_string($noQuote)) { + $noQuote = explode(',',$noQuote); + } elseif (!is_array($noQuote)) { // sanity check + $noQuote = FALSE; + } + + foreach($arr as $k => $v) { + if ($noQuote===FALSE || !in_array($k,$noQuote)) { + $arr[$k] = $this->fullQuoteStr($v, $table); + } + } + return $arr; + } + + /* fonctions abstraites */ + + abstract function query($sSql); + + abstract function fetch($rSql); + + abstract function sql_insert_id(); + + abstract function quoteStr($str, $table); +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Database/Mysql.php b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Database/Mysql.php new file mode 100755 index 0000000..87c1317 --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Database/Mysql.php @@ -0,0 +1,54 @@ +link)) { + $this->messageAndDie("DB already initialized"); + } + + $this->link = mysql_connect( + $sHost, + $sLogin, + $sPassword + ) OR $this->messageAndDie("invalid DB credentials."); + + mysql_select_db($sDatabase, $this->link) OR $this->messageAndDie("could not select DB"); + + // on initialise la connection UTF-8 aux données + mysql_query("set character_set_database='utf8'", $this->link); + mysql_query("set character_set_client='utf8'", $this->link); + mysql_query("set character_set_connection='utf8'", $this->link); + mysql_query("set character_set_results='utf8'", $this->link); + mysql_query("set character_set_server='utf8'", $this->link); + } + + function query($sSql) { + return mysql_query($sSql, $this->link); + } + + function fetch($rSql) { + if(is_resource($rSql)) { + return mysql_fetch_assoc($rSql); + } + + return FALSE; + } + + function sql_insert_id() { + return mysql_insert_id($this->link); + } + + function quoteStr($str, $table) { + return mysql_real_escape_string($str, $this->link); + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Database/Sqlite.php b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Database/Sqlite.php new file mode 100755 index 0000000..273fc92 --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Database/Sqlite.php @@ -0,0 +1,50 @@ +oDb)) { + $this->messageAndDie("DB already initialized"); + } + + $this->sDbPath = $sDbPath; + $this->oDb = new \SQLite3($this->sDbPath); + } + + function query($sSql) { + return $this->oDb->query($sSql); + } + + function fetch($rSql) { + if(is_object($rSql)) { + return $rSql->fetchArray(SQLITE3_ASSOC); + } + + return FALSE; + } + + function sql_insert_id() { + $rSql = $this->query("SELECT last_insert_rowid() as uid"); + if(($aRes = $this->fetch($rSql)) !== FALSE) { + return intval($aRes["uid"]); + } + + return FALSE; + } + + function quoteStr($str, $table=FALSE) { + if(function_exists("sqlite_escape_string")) { + return sqlite_escape_string($str); + } + + return addslashes($str); + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/FLObject.php b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/FLObject.php new file mode 100755 index 0000000..06f2490 --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/FLObject.php @@ -0,0 +1,17 @@ +aData); + return $this->aData; + } + + public function get($sWhat) { + if(array_key_exists($sWhat, $this->aData)) { + return $this->aData[$sWhat]; + } + + return FALSE; + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Model/Db.php b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Model/Db.php new file mode 100755 index 0000000..84efb41 --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Model/Db.php @@ -0,0 +1,49 @@ +aData = $this->getRecordByPrimary($sPrimary)) === FALSE) { + throw new \Exception("\Flake\Core\Model '" . $sPrimary . "' not found"); + } + } + + public static function &getBaseRequester() { + $oRequester = new \Flake\Core\Requester(self::getClass()); + $oRequester->setDataTable(self::getDataTable()); + + return $oRequester; + } + + public static function &getByRequest(\FS\Core\Requester $oRequester) { + // renvoie une collection de la classe du modèle courant (this) + return $oRequester->execute(); + } + + public static function getDataTable() { + $sClass = self::getClass(); + return $sClass::DATATABLE; + } + + public static function getPrimaryKey() { + $sClass = self::getClass(); + return $sClass::PRIMARYKEY; + } + + protected function getRecordByPrimary($sPrimary) { + $rSql = $GLOBALS["DB"]->exec_SELECTquery( + "*", + self::getDataTable(), + self::getPrimaryKey() . "='" . $GLOBALS["DB"]->quoteStr($sPrimary) . "'" + ); + + if(($aRs = $GLOBALS["DB"]->fetch($rSql)) !== FALSE) { + reset($aRs); + return $aRs; + } + + return FALSE; + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Model/NoDb.php b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Model/NoDb.php new file mode 100755 index 0000000..8ef1571 --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Model/NoDb.php @@ -0,0 +1,11 @@ +aData = $aData; + } + +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Render/Container.php b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Render/Container.php new file mode 100755 index 0000000..8b5654a --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Render/Container.php @@ -0,0 +1,28 @@ + &$oBlock, + "rendu" => "", + ); + $this->aSequence[] =& $aTemp; + $this->aBlocks[$sZone][] =& $aTemp["rendu"]; + } + + function &zone($sZone) { + if(!array_key_exists($sZone, $this->aZones)) { + $this->aZones[$sZone] = new \Flake\Core\Render\Zone($this, $sZone); + } + + return $this->aZones[$sZone]; + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Render/Zone.php b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Render/Zone.php new file mode 100755 index 0000000..0aa3321 --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Render/Zone.php @@ -0,0 +1,17 @@ +oZonableObject =& $oZonableObject; + $this->sZone = $sZone; + } + + function addBlock(&$oBlock) { + $this->oZonableObject->addBlock( + $oBlock, + $this->sZone + ); + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Requester.php b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Requester.php new file mode 100755 index 0000000..e4bab68 --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Requester.php @@ -0,0 +1,201 @@ +sModelClass = $sModelClass; + } + + public function setDataTable($sDataTable) { + $this->sDataTable = $sDataTable; + return $this; + } + + public function addClause($sField, $sValue) { + $this->addClauseEquals($sField, $sValue); + return $this; + } + + public function addClauseEquals($sField, $sValue) { + $sWrap = "{field}='{value}'"; + $this->addClauseWrapped($sField, $sValue, $sWrap); + return $this; + } + + public function addClauseNotEquals($sField, $sValue) { + $sWrap = "{field}!='{value}'"; + $this->addClauseWrapped($sField, $sValue, $sWrap); + return $this; + } + + public function addClauseLike($sField, $sValue) { + $sWrap = "{field} LIKE '%{value}%'"; + $this->addClauseWrapped($sField, $sValue, $sWrap); + return $this; + } + + public function addClauseLikeBeginning($sField, $sValue) { + $sWrap = "{field} LIKE '{value}%'"; + $this->addClauseWrapped($sField, $sValue, $sWrap); + return $this; + } + + public function addClauseLikeEnd($sField, $sValue) { + $sWrap = "{field} LIKE '%{value}'"; + $this->addClauseWrapped($sField, $sValue, $sWrap); + return $this; + } + + public function addClauseNotLike($sField, $sValue) { + $sWrap = "{field} NOT LIKE '%{value}%'"; + $this->addClauseWrapped($sField, $sValue, $sWrap); + return $this; + } + + public function addClauseNotLikeBeginning($sField, $sValue) { + $sWrap = "{field} NOT LIKE '{value}%'"; + $this->addClauseWrapped($sField, $sValue, $sWrap); + return $this; + } + + public function addClauseNotLikeEnd($sField, $sValue) { + $sWrap = "{field} NOT LIKE '%{value}'"; + $this->addClauseWrapped($sField, $sValue, $sWrap); + return $this; + } + + public function addClauseIn($sField, $sValue) { + $sWrap = "{field} IN ({value})"; + $this->addClauseWrapped($sField, $sValue, $sWrap); + return $this; + } + + public function addClauseNotIn($sField, $sValue) { + $sWrap = "{field} NOT IN ({value})"; + $this->addClauseWrapped($sField, $sValue, $sWrap); + return $this; + } + + public function orderBy($sOrderField, $sOrderDirection = "ASC") { + $this->sOrderField = $sOrderField; + $this->sOrderDirection = $sOrderDirection; + return $this; + } + + public function limit($iStart, $iNumber = FALSE) { + if($iNumber !== FALSE) { + return $this->setLimitStart($iStart)->setLimitNumber($iLimitNumber); + } + + return $this->setLimitStart($iStart); + } + + public function setLimitStart($iLimitStart) { + $this->iLimitStart = $iLimitStart; + return $this; + } + + public function setLimitNumber($iLimitNumber) { + $this->iLimitNumber = $iLimitNumber; + return $this; + } + + protected function addClauseWrapped($sField, $sValue, $sWrap) { + $sValue = $this->escapeSqlValue($sValue); + $sClause = str_replace( + array( + "{field}", + "{value}", + ), + array( + $sField, + $sValue + ), + $sWrap + ); + + $this->addClauseLiteral($sClause); + return $this; + } + + public function addClauseLiteral($sClause) { + $this->aClauses[] = $sClause; + return $this; + } + + protected function escapeSqlValue($sValue) { + return $GLOBALS["DB"]->quoteStr( + $sValue, + $this->sDataTable + ); + } + + protected function &reify($aData) { + $sTemp = $this->sModelClass; + return new $sTemp($aData[$sTemp::getPrimaryKey()]); + } + + public function hasBeenExecuted() { + return $this->bHasBeenExecuted; + } + + public function getQuery() { + if(empty($this->aClauses)) { + $sWhere = "1=1"; + } else { + $sWhere = implode(" AND ", $this->aClauses); + } + + if(trim($this->sOrderField) !== "") { + $sOrderBy = $this->sOrderField . " " . $this->sOrderDirection; + } + + $sLimit = ""; + + if($this->iLimitStart !== FALSE) { + if($this->iLimitNumber !== FALSE) { + $sLimit = $this->iLimitStart . ", " . $this->iLimitNumber; + } else { + $sLimit = $this->iLimitStart; + } + } elseif($this->iLimitNumber !== FALSE) { + $sLimit = "0, " . $this->iLimitNumber; + } + + return $GLOBALS["DB"]->SELECTquery( + "*", + $this->sDataTable, + $sWhere, + "", + $sOrderBy, + $sLimit + ); + } + + public function execute() { + $oCollection = new \Flake\Core\CollectionTyped($this->sModelClass); + $sSql = $this->getQuery(); + + $rSql = $GLOBALS["DB"]->query($sSql); + while(($aRs = $GLOBALS["DB"]->fetch($rSql)) !== FALSE) { + $oCollection->push( + $this->reify($aRs) + ); + } + + $this->bHasBeenExecuted = TRUE; + + return $oCollection; + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Template.php b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Template.php new file mode 100755 index 0000000..d57fc6b --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/Template.php @@ -0,0 +1,36 @@ +sAbsPath = $sAbsPath; + $this->bPhp = $bPhp; + $this->sHtml = $this->getTemplateFile( + $this->sAbsPath + ); + } + + private function getTemplateFile($sAbsPath) { + return file_get_contents($sAbsPath); + } + + function parse($aMarkers = array()) { + if($this->bPhp) { + return \Flake\Util\Tools::parseTemplateCodePhp( + $this->sHtml, + $aMarkers + ); + } else { + return \Flake\Util\Tools::parseTemplateCode( + $this->sHtml, + $aMarkers + ); + } + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/View.php b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/View.php new file mode 100755 index 0000000..ff3380f --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/Flake/Core/View.php @@ -0,0 +1,27 @@ +aData = array(); + } + + public function setData($sName, $mData) { + $this->aData[$sName] = $mData; + } + + public function getData() { + return $this->aData; + } + + public function get($sWhat) { + if(array_key_exists($sWhat, $this->aData)) { + return $this->aData[$sWhat]; + } + + return FALSE; + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Flake/Route/Kickstart/Main.php b/CoreVersions/Baikal_0.1/Frameworks/Flake/Route/Kickstart/Main.php new file mode 100755 index 0000000..d3c6bde --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/Flake/Route/Kickstart/Main.php @@ -0,0 +1,10 @@ +zone("Payload")->addBlock(new \Flake\Controler\Kickstart()); + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Frameworks/Flake/Util/Router.php b/CoreVersions/Baikal_0.1/Frameworks/Flake/Util/Router.php new file mode 100755 index 0000000..5dbf5eb --- /dev/null +++ b/CoreVersions/Baikal_0.1/Frameworks/Flake/Util/Router.php @@ -0,0 +1,78 @@ +'; + if (!count($array_in)) {$result.= ''.htmlspecialchars("EMPTY!").'';} + while (list($key,$val)=each($array_in)) { + $result.= ''.htmlspecialchars((string)$key).''; + if (is_array($array_in[$key])) { + $result.= \Flake\Util\Tools::view_array($array_in[$key]); + } else + $result.= ''.nl2br(htmlspecialchars((string)$val)).'
'; + $result.= ''; + } + $result.= ''; + } else { + $result = ' + + + +
'.nl2br(htmlspecialchars((string)$array_in)).'
'; // Output it as a string. + } + return $result; + } + + static function debug($var="",$brOrHeader=0) { + if($brOrHeader === 0) { + $trail = debug_backtrace(); + $trail = array_reverse($trail); + array_pop($trail); // la ligne d'appel à debug + array_pop($trail); // la ligne d'appel à debug + $aLastNode = array_pop($trail); // l'appel qui nous intéresse + $brOrHeader = $aLastNode['class'].$aLastNode['type'].$aLastNode['function']; + } + + if ($brOrHeader) { + echo '
'.htmlspecialchars((string)$brOrHeader).'
'; + } + + if (is_array($var)) { + echo \Flake\Util\Tools::view_array($var); + } elseif (is_object($var)) { + echo '|Object:
';
+			print_r($var);
+			echo '
|
'; + } elseif ((string)$var!='') { + echo '|'.htmlspecialchars((string)$var).'|'; + } else { + echo '| debug |'; + } + + if ($brOrHeader) { + echo '
'; + } + } + + static function debug_trail() { + $trail = debug_backtrace(); + $trail = array_reverse($trail); + array_pop($trail); + + $path = array(); + foreach($trail as $dat) { + $path[] = $dat['class'].$dat['type'].$dat['function']; + } + + return implode(' // ',$path); + } + + static function POST($sVar = FALSE) { + if($sVar !== FALSE) { + $aData = \Flake\Util\Tools::POST(); + if(array_key_exists($sVar, $aData)) { + return $aData[$sVar]; + } + + return ""; + } + + return is_array($GLOBALS["_POST"]) ? $GLOBALS["_POST"] : array(); + } + + static function GET($sVar = FALSE) { + if($sVar !== FALSE) { + $aData = \Flake\Util\Tools::GET(); + if(array_key_exists($sVar, $aData)) { + return $aData[$sVar]; + } + + return ""; + } + + return is_array($GLOBALS["_GET"]) ? $GLOBALS["_GET"] : array(); + } + + static function GP($sVar = FALSE) { + if($sVar !== FALSE) { + $aData = \Flake\Util\Tools::GP(); + if(array_key_exists($sVar, $aData)) { + return $aData[$sVar]; + } + + return ""; + } + + return array_merge( + \Flake\Util\Tools::GET(), + \Flake\Util\Tools::POST() + ); + } + + 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; + } + } + } + + function safelock($sString) { + return substr(md5(FLAKE_SAFEHASH_SALT . ":" . $sString), 0, 5); + } + + function redirect($sUrl) { + header("Location: " . $sUrl); + exit(0); + } + + function refreshPage() { + header("Location: " . \Flake\Util\Tools::getCurrentUrl()); + exit(0); + } + + 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"]); + } + + function validEmail($sEmail) { + return (filter_var($sEmail, FILTER_VALIDATE_EMAIL) !== FALSE); + } + + function filterFormInput($sInput) { + return strip_tags($sInput); + } + + function getHumanDate($iStamp) { + return ucwords(strftime("%A, %d %B %Y", $iStamp)); + } + + function getHumanTime($iStamp) { + return strftime("%Hh%M", $iStamp); + } + + public static function trimExplode($string, $delim=",", $removeEmptyValues = false, $limit = 0) { + $explodedValues = explode($delim, $string); + + $result = array_map('trim', $explodedValues); + + if ($removeEmptyValues) { + $temp = array(); + foreach($result as $value) { + if ($value !== '') { + $temp[] = $value; + } + } + $result = $temp; + } + + if ($limit != 0) { + if ($limit < 0) { + $result = array_slice($result, 0, $limit); + } elseif (count($result) > $limit) { + $lastElements = array_slice($result, $limit - 1); + $result = array_slice($result, 0, $limit - 1); + $result[] = implode($delim, $lastElements); + } + } + + return $result; + } + + /** + * Taken from TYPO3 + * Returns true if the first part of $str matches the string $partStr + * Usage: 59 + * + * @param string Full string to check + * @param string Reference string which must be found as the "first part" of the full string + * @return boolean True if $partStr was found to be equal to the first part of $str + */ + public static function isFirstPartOfStr($str,$partStr) { + // Returns true, if the first part of a $str equals $partStr and $partStr is not '' + $psLen = strlen($partStr); + if ($psLen) { + return substr($str,0,$psLen)==(string)$partStr; + } else return false; + } + + /** + * Binary-reads a file + * + * @param string $sPath: absolute server path to file + * @return string file contents + */ + public static function file_readBin($sPath) { + $sData = ""; + $rFile = fopen($sPath, "rb"); + while(!feof($rFile)) { + $sData .= fread($rFile, 1024); + } + fclose($rFile); + + return $sData; + } + + /** + * Binary-writes a file + * + * @param string $sPath: absolute server path to file + * @param string $sData: file contents + * @param boolean $bUTF8: add UTF8-BOM or not ? + * @return void + */ + function file_writeBin($sPath, $sData) { + $rFile=fopen($sPath, "wb"); + fputs($rFile, $sData); + fclose($rFile); + } + + public static function sendHtmlMail($sToAddress, $sSubject, $sBody, $sFromName, $sFromAddress, $sReplyToName, $sReplyToAddress) { + + $sMessage = << + + + Email + + + {$sBody} + + +TEST; + + $sHeaders = "From: " . $sFromName . "<" . $sFromAddress . ">" . "\r\n"; + $sHeaders .= "Reply-To: " . $sReplyToName . "<" . $sReplyToAddress . ">" . "\r\n"; + $sHeaders .= "Bcc: " . $sReplyToName . "<" . $sReplyToAddress . ">" . "\r\n"; + $sHeaders .= "Content-Type: text/html" . "\r\n"; + + mail($sToAddress, $sSubject, $sMessage, $sHeaders); + } + + public static function shortMD5($sValue) { + return strtolower(substr(md5($sValue), 0, 5)); + } + + public static function overrideFirstWithSecond($sFirst, $sSecond) { + if(trim($sSecond) !== "") { + return $sSecond; + } + + return "" . $sFirst; + } + + public function parseTemplateCodePhp($sCode, $aMarkers) { + extract($aMarkers); + ob_start(); + echo eval('?>' . $sCode . 'getData(); + } + + if(!array_key_exists($sSearchPart, $aMarkers)) { + return ""; + } + + if(count($aSearchParts) > 0) { + return self::resolveForTemplate(implode(".", $aSearchParts), $aMarkers[$sSearchPart]); + } + + return $aMarkers[$sSearchPart]; + } + + public static function is_a($object, $class) { + if(is_object($object)) return $object instanceof $class; + if(is_string($object)){ + if(is_object($class)) $class=get_class($class); + + if(class_exists($class)) return is_subclass_of($object, $class) || $object==$class; + if(interface_exists($class)) { + $reflect = new \ReflectionClass($object); + return $reflect->implementsInterface($class); + } + + } + return false; + } + + public static function HTTPStatus($iCode, $sMessage) { + header("HTTP/1.1 404 Not Found"); + header("Status: 404 Not Found"); + die("

HTTP Status " . $iCode . " : " . $sMessage . "

"); + } + + public static function number2Rank($a) { + $a = intval($a); + + if ($a === 1) { + return "premier"; + } elseif($a === 2) { + return "second"; + } + + $sNumber = self::number2Human($a); + + $sLastLetter = substr($sNumber, -1, 1); + if($sLastLetter === "e") { + $sNumber = substr($sNumber, 0, -1); + } elseif($sLastLetter === "q") { + $sNumber = $sNumber . "u"; + } elseif($sLastLetter === "f") { + $sNumber = substr($sNumber, 0, -1) . "v"; + } + + return $sNumber . "ième"; + } + + public static function number2Human($a) { + $temp = explode('.',$a); + if (isset($temp[1]) && $temp[1]!='') { + return self::number2Human($temp[0]).' virgule '.self::number2Human($temp[1]) ; + } + + if ($a<0) return 'moins '.self::number2Human(-$a); + + if ($a<17) { + switch ($a) { + case 0: return 'zero'; + case 1: return 'un'; + case 2: return 'deux'; + case 3: return 'trois'; + case 4: return 'quatre'; + case 5: return 'cinq'; + case 6: return 'six'; + case 7: return 'sept'; + case 8: return 'huit'; + case 9: return 'neuf'; + case 10: return 'dix'; + case 11: return 'onze'; + case 12: return 'douze'; + case 13: return 'treize'; + case 14: return 'quatorze'; + case 15: return 'quinze'; + case 16: return 'seize'; + } + } else if ($a<20) { + return 'dix-' . self::number2Human($a-10); + } else if ($a<100) { + if ($a%10==0) { + switch($a) { + case 20: return 'vingt'; + case 30: return 'trente'; + case 40: return 'quarante'; + case 50: return 'cinquante'; + case 60: return 'soixante'; + case 70: return 'soixante-dix'; + case 80: return 'quatre-vingt'; + case 90: return 'quatre-vingt-dix'; + } + } elseif(substr($a, -1) == 1) { + if( ((int)($a/10)*10)<70 ) { + return self::number2Human((int)($a/10)*10).'-et-un'; + } elseif ($a==71) { + return 'soixante-et-onze'; + } elseif ($a==81) { + return 'quatre-vingt-un'; + } elseif ($a==91) { + return 'quatre-vingt-onze'; + } + } elseif ($a<70) { + return self::number2Human($a-$a%10).'-'.self::number2Human($a%10); + } elseif ($a<80) { + return self::number2Human(60).'-'.self::number2Human($a%20); + } else { + return self::number2Human(80).'-'.self::number2Human($a%20); + } + } else if ($a==100) { + return 'cent'; + } else if ($a<200) { + return self::number2Human(100).' '.self::number2Human($a%100); + } else if ($a<1000) { + return self::number2Human((int)($a/100)).' '.self::number2Human(100).' '.self::number2Human($a%100); + } else if ($a==1000) { + return 'mille'; + } else if ($a<2000) { + return self::number2Human(1000).' '.self::number2Human($a%1000).' '; + } else if ($a<1000000) { + return self::number2Human((int)($a/1000)).' '.self::number2Human(1000).' '.self::number2Human($a%1000); + } + } + + public static function stringToUrlToken($sString) { + + # Taken from TYPO3 extension realurl + + $space = "-"; + $sString = strtr($sString, ' -+_\'', $space . $space . $space . $space . $space); // convert spaces + + $sString = iconv('UTF-8', 'ASCII//TRANSLIT', $sString); + $sString = strtolower($sString); + + $sString = preg_replace('/[^a-zA-Z0-9\\' . $space . ']/', '', $sString); + $sString = preg_replace('/\\' . $space . '{2,}/', $space, $sString); // Convert multiple 'spaces' to a single one + $sString = trim($sString, $space); + + return $sString; + } + + public static function isCliPhp() { + return strtolower(php_sapi_name()) === "cli"; + } + + public static function getIP() { + + $alt_ip = $_SERVER['REMOTE_ADDR']; + + if(isset($_SERVER['HTTP_CLIENT_IP'])) { + $alt_ip = $_SERVER['HTTP_CLIENT_IP']; + } else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) { + + // make sure we dont pick up an internal IP defined by RFC1918 + foreach($matches[0] AS $ip) { + if (!preg_match('#^(10|172\.16|192\.168)\.#', $ip)) { + $alt_ip = $ip; + break; + } + } + } else if (isset($_SERVER['HTTP_FROM'])) { + $alt_ip = $_SERVER['HTTP_FROM']; + } + + return $alt_ip; + } + + public static function getUserAgent() { + return $_SERVER['HTTP_USER_AGENT']; + } +} \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Resources/Web/BaikalAdmin b/CoreVersions/Baikal_0.1/Resources/Web/BaikalAdmin new file mode 120000 index 0000000..dd61f23 --- /dev/null +++ b/CoreVersions/Baikal_0.1/Resources/Web/BaikalAdmin @@ -0,0 +1 @@ +../../Frameworks/BaikalAdmin/Resources \ No newline at end of file diff --git a/CoreVersions/Baikal_0.1/Resources/Web/README.md b/CoreVersions/Baikal_0.1/Resources/Web/README.md new file mode 100644 index 0000000..4c3f2f8 --- /dev/null +++ b/CoreVersions/Baikal_0.1/Resources/Web/README.md @@ -0,0 +1 @@ +# Resources must be symlinked relatively to this folder diff --git a/CoreVersions/Baikal_0.1/WWWRoot/res/TwitterBootstrap b/CoreVersions/Baikal_0.1/Resources/Web/TwitterBootstrap similarity index 100% rename from CoreVersions/Baikal_0.1/WWWRoot/res/TwitterBootstrap rename to CoreVersions/Baikal_0.1/Resources/Web/TwitterBootstrap diff --git a/CoreVersions/Baikal_0.1/Resources/baikal.empty.sqlite b/CoreVersions/Baikal_0.1/Resources/baikal.empty.sqlite deleted file mode 100755 index c08b67f2f31533a2e57d079a6f838ae8b3545ed2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 14336 zcmeHN&2G~`5Vn&vsokFg7mEYxR-&R&!y)PcsZu3Ev8t-2qG^igDcaaeFtNSCyAdrC zhlFS0Df%3|0H@w~04}UIwquu8p@+z+G?rrT&W?A!@7tN(NXhBRk;4i4Km!kRw5^mB zRaIUhq$tZZMNwA8C%$yiP~*;xcFLS?iaDPDT3ZO6i+{p_#qlHU18qgbuIVd21L@>a|MmnO7{bZsi$6vv5g zggKnX#vG%LOFNM*0X(MbV#YmcJ0Bd9C?jC*6)VQpmO9#vV7kP&aX>qth{XlqOt*9c zdS>wdNW?Qv0UNvhL-ckQqt#NySX)!S_cAOJ{A}S??UVEyHtF+^X+vC=qV^t@E5`b|I;0YOvLCTYOUuxh*hS)o8^*zL%iK4c=xy`h zO`~~^4$X7aINb|jg<)Fe`&LcYh=(0F?xc6OX#DK>;N;BQ6mL}Z>UO1U?60eer$9wi;$)p?5LEj@@hXgF$UdpgZk4)jCYe}&7gtnkI z4wAJ+bkc9sP~s>kzR=3X;l^DQ)3Dn0bZ_~aE|YC|E?EwkpeJuD8D7#95xV;X(n2?R z#zd=NJ6*y!uEz@%uS(=5a95Yg#;$P}ZW*>+mycEW{{JAhF8~P&%tV3kPd)Ja|4gKX zNkM_RR{+lcxnCjx2nx(h0XY9>CM`@13e3F%aQ@Hz5&=L^U}g%y`9CvhVPa5V?iKh8 D>X03W diff --git a/INSTALL.md b/INSTALL.md old mode 100644 new mode 100755 diff --git a/LICENSE.txt b/LICENSE.txt old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/html/admin b/html/admin deleted file mode 120000 index ae007d0..0000000 --- a/html/admin +++ /dev/null @@ -1 +0,0 @@ -../Core/WWWRoot/admin \ No newline at end of file diff --git a/html/admin/index.php b/html/admin/index.php new file mode 120000 index 0000000..dac9adc --- /dev/null +++ b/html/admin/index.php @@ -0,0 +1 @@ +../../Core/Frameworks/BaikalAdmin/index.php \ No newline at end of file diff --git a/html/res b/html/res deleted file mode 120000 index 00a27c8..0000000 --- a/html/res +++ /dev/null @@ -1 +0,0 @@ -../Core/WWWRoot/res \ No newline at end of file diff --git a/html/res/core b/html/res/core new file mode 120000 index 0000000..2985272 --- /dev/null +++ b/html/res/core @@ -0,0 +1 @@ +../../Core/Resources/Web \ No newline at end of file