From 1ec34139395e0725483d66975bb26f4a6d9575e5 Mon Sep 17 00:00:00 2001 From: Slim Amamou Date: Wed, 6 Feb 2008 11:57:37 +0100 Subject: [PATCH] j'ai ajoute un message d'erreur pour le cas ou la base n'est pas ouverte en ecriture. j'ai corrige un bug dans ini.php avec les parametres get dans l'url. pour ce faire j'ai ameliore LocalResource --- bazdig/bazdig.css | 6 ++++++ bazdig/console/index.php | 7 ++++++- bazdig/db/set/index.php | 8 ++++---- bazdig/history/index.php | 4 ++-- ini.php | 24 ++++++++++++++---------- lib/database.php | 7 +++++++ lib/localresource.php | 24 +++++++++++------------- 7 files changed, 50 insertions(+), 30 deletions(-) diff --git a/bazdig/bazdig.css b/bazdig/bazdig.css index 6bc50ae..3450343 100644 --- a/bazdig/bazdig.css +++ b/bazdig/bazdig.css @@ -7,6 +7,12 @@ body { h3 { display: inline; } +#error { + background-color: yellow; + border: 2px solid red; + padding: 10px; + margin: 10px; +} #nav a { border: 1px outset silver ; padding: 5px 10px; diff --git a/bazdig/console/index.php b/bazdig/console/index.php index 259d8be..7364af6 100644 --- a/bazdig/console/index.php +++ b/bazdig/console/index.php @@ -18,7 +18,12 @@ - +getparam('db')->file; + if (!is_writable($bazdig_db)) { + echo '
WARNING your history database is not writeable. chmod 777 '. $bazdig->file .' && chmod 666 '. $bazdig_db .'
'; + } +?> diff --git a/bazdig/db/set/index.php b/bazdig/db/set/index.php index a14b50f..0afb7d5 100644 --- a/bazdig/db/set/index.php +++ b/bazdig/db/set/index.php @@ -4,10 +4,10 @@ define('WARAQ_ROOT', '../../..'); require_once WARAQ_ROOT .'/'. 'ini.php'; - $_SESSION['db_type'] = $_GET['dbt']; - $_SESSION['db_name'] = $_GET['dbn']; - $_SESSION['db_host'] = $_GET['dbh']; - $_SESSION['db_user'] = $_GET['dbu']; + $_SESSION['db_type'] = $_GET['dbt']; + $_SESSION['db_name'] = $_GET['dbn']; + $_SESSION['db_host'] = $_GET['dbh']; + $_SESSION['db_user'] = $_GET['dbu']; $_SESSION['db_password'] = $_GET['dbp']; header('Location: '. $bazdig->get('/console')->url ); diff --git a/bazdig/history/index.php b/bazdig/history/index.php index 258b3bd..e56de50 100644 --- a/bazdig/history/index.php +++ b/bazdig/history/index.php @@ -5,9 +5,9 @@ require "code.php"; - $dbFile = $bazdig->get("/bazdig.db"); + $dbFile = $bazdig->getparam("db")->file; $console = $bazdig->get("/console"); - SqlCode::set_db("sqlite:". $dbFile->get_file()); + SqlCode::set_db("sqlite:". $dbFile); if ($_GET['q']) { $queries = SqlCode::search($_GET['q']); diff --git a/ini.php b/ini.php index 2a0e0b7..d1fb154 100644 --- a/ini.php +++ b/ini.php @@ -1,25 +1,29 @@ get(WARAQ_ROOT); + $bazdigService = $requestedService->get(WARAQ_ROOT . '/bazdig'); + $GLOBALS['bazdig'] = new WaraqService($bazdigService->url, $bazdigService->file); $bazdig =& $GLOBALS['bazdig']; - $bazdig->setparam("db", $bazdig->get('/bazdig.db')); + $bazdig->setparam("db", $bazdig->get('bazdig.db')); -function columnNames($row) +function firstWord($string) { - return array_keys($row); + $string = trim($string); + return str_trunkate($string, ' '); } -function firstWord($string) +function str_trunkate($haystack, $needle) { - $string = trim($string); - if (!$pos = strpos($string, ' ')) return $string; - return substr($string, 0, $pos); + if (!$pos = strpos($haystack, $needle)) return $haystack; + return substr($haystack, 0, $pos); } + diff --git a/lib/database.php b/lib/database.php index d935486..87445da 100755 --- a/lib/database.php +++ b/lib/database.php @@ -107,3 +107,10 @@ $this->type = $type; } } + + +function columnNames($row) +{ + return array_keys($row); +} + diff --git a/lib/localresource.php b/lib/localresource.php index 96751fc..37b01bb 100755 --- a/lib/localresource.php +++ b/lib/localresource.php @@ -6,19 +6,20 @@ function __construct($url, $file) { - $this->url = $url; - $this->file = $file; - } - - function LocalResource($url, $file) - { - $this->__construct($url, $file); + $this->url = absolutize($url); + $this->file = absolutize($file); } function get($path) { - $u = absolutize($this->url .'/'. $path); - $f = absolutize($this->file .'/'. $path); + $f = $this->file .'/'. $path; + if (strpos($this->url, '?')) { + $u = str_replace('?', "/$path?", $this->url ); + } else if (strpos($this->url, '#')) { + $u = str_replace('#', "/$path#", $this->url ); + } else { + $u = $this->url .'/'. $path; + } $r = new LocalResource($u, $f); return $r; } @@ -37,10 +38,7 @@ function absolutize($path) { $path = ereg_replace('/\./', '/', $path); - while (ereg('/[^/.]+/\.\./', $path)) { - $path = ereg_replace('/[^/.]+/\.\./', '/', $path); - } + $path = ereg_replace('/[^/.]+/+\.\./', '/', $path); return $path; } -?> -- 2.11.4.GIT