From: Nicolas Boisselier Date: Tue, 13 Sep 2016 15:04:54 +0000 (+0200) Subject: db includes X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=85ff6179697d99b50740d2da99c6052d56be2111;p=nb.git db includes --- diff --git a/lib/php/db/config.php b/lib/php/db/config.php new file mode 100644 index 00000000..da838cc9 --- /dev/null +++ b/lib/php/db/config.php @@ -0,0 +1,9 @@ + diff --git a/lib/php/db/index.php b/lib/php/db/index.php index 38556f33..beaf177e 100755 --- a/lib/php/db/index.php +++ b/lib/php/db/index.php @@ -6,15 +6,16 @@ * * lib/php/db/index.php */ -require_once(realpath(dirname(__FILE__).'/../config.php')); -require_once(realpath(dirname(__FILE__).'/../db.php')); - -Db::pinit(); - -if(defined('DB_NO_INIT') and DB_NO_INIT) return true; -#bye(Db::conf_load(array( Db::ROOT_DIR.'/etc/dbs.yaml','/etc/dbs.yaml' ))); -#$conf = Db::conf_load(array( Db::ROOT_DIR.'/etc/dbs.yaml','/etc/dbs.yaml' )); Db::init($conf); -Db::init([Db::ROOT_DIR.'/etc/dbs.yaml',Db::ROOT_DIR.'/etc/dbs.php','/etc/dbs.yaml']); +require_once(realpath(dirname(__FILE__).'/config.php')); +# NB 13.09.16 require_once(realpath(dirname(__FILE__).'/../config.php')); +# NB 13.09.16 require_once(realpath(dirname(__FILE__).'/../db.php')); +# NB 13.09.16 +# NB 13.09.16 Db::pinit(); +# NB 13.09.16 +# NB 13.09.16 if(defined('DB_NO_INIT') and DB_NO_INIT) return true; +# NB 13.09.16 #bye(Db::conf_load(array( Db::ROOT_DIR.'/etc/dbs.yaml','/etc/dbs.yaml' ))); +# NB 13.09.16 #$conf = Db::conf_load(array( Db::ROOT_DIR.'/etc/dbs.yaml','/etc/dbs.yaml' )); Db::init($conf); +# NB 13.09.16 Db::init([Db::ROOT_DIR.'/etc/dbs.yaml',Db::ROOT_DIR.'/etc/dbs.php','/etc/dbs.yaml']); if(defined('DB_NO_ACTION') and DB_NO_ACTION) return true; diff --git a/lib/php/db/page.php b/lib/php/db/page.php index df7b3120..476370b5 100644 --- a/lib/php/db/page.php +++ b/lib/php/db/page.php @@ -1,18 +1,16 @@ type); -#Page::pdef('db','puppetdb'); +require_once(dirname(__FILE__).'/../db/config.php'); $Page = new Page([ - #'title' => 'Test', + 'title' => ($Db->title ? $Db->title : Db::prettyText($Db->name)), 'content_type' => Page::content_type_and_set_format(), - #'content_type' => ((Page::php_cli() and !Page::p('web') )? 'text/plain' : 'text/html'), 'call' => array( 'begin', - ['out', "Hello World !!!\n"], + #['out', "Hello World !!!\n"], function($page){ + global $Db, $Table; #$type = $page->mime2ext($page->content_type()); switch ($page->mime2ext($page->content_type())) { case "html": @@ -25,16 +23,18 @@ $Page = new Page([ #bye($type); $page->pdef('format','csv'); } - #echo Page::p('db')."\n"; return; -#echo 'zaza'; return; if ($page->action()) 1; - else require_once(dirname(__FILE__).'/index.php'); - #else if (!empty($page->db)) $page->db->action($page->db->p('action'),empty($Table) ? null : $Table); + else return $Db->action($Db->p('action'),$Table); + #else require_once(dirname(__FILE__).'/index.php'); + }, + function($page){ + global $Db; + if (!empty($Db)) echo $page->tag('div class="db-infos"',join(' | ',[ + $Db->type, + $Db->host, + ($Db->name ? $Db->name : null), + ])); }, -/* -*/ - #array('out', print_r($_SERVER,true)), 'end', ), ]); -#$Page->db = $Db; diff --git a/lib/php/page.php b/lib/php/page.php index 3b52600b..385e30b0 100644 --- a/lib/php/page.php +++ b/lib/php/page.php @@ -181,6 +181,8 @@ class Page extends nb { * Return html code for a tag */ public static function tag($tag,$content='',$attrs='') { + static $is_html = null; + if ($is_html === null) $is_html = preg_match('/ml$/',self::content_type()) ? true : false; # Extract attrs from tag if (preg_match('/^([\w-]+)\s+(.*?)$/',$tag,$m)) { @@ -195,6 +197,8 @@ class Page extends nb { ); } + if (!$is_html) return join("\n",(array)$content); + if ($content===null) { self::tag_end($tag); return '<' . $tag . ($attrs ? " $attrs" : "") . '>'; @@ -227,6 +231,17 @@ class Page extends nb { ; } + public static function tag_end($tag=null) { + static $tags = []; + if ($tag !== null) return array_unshift($tags,$tag); + foreach ($tags as $t) echo "".NB_EOL; + $tags = []; + return $tags; + return join('',self::ar_map('',$tags)); + if ($tag === null) return $tags; + array_unshift($tags,$tag); + } + static function debug($debug,$level=0) { if (is_array($debug) or is_object($debug)) $debug = print_r($debug,true); @@ -280,17 +295,6 @@ class Page extends nb { } - public static function tag_end($tag=null) { - static $tags = []; - if ($tag !== null) return array_unshift($tags,$tag); - foreach ($tags as $t) echo "".NB_EOL; - $tags = []; - return $tags; - return join('',self::ar_map('',$tags)); - if ($tag === null) return $tags; - array_unshift($tags,$tag); - } - public static function end() { if (preg_match('/ml$/',self::$content_type)) { @@ -528,8 +532,9 @@ class Page extends nb { } if (!$content_type and $format) $content_type = self::ext2mime($format); - if (!$content_type and self::php_cli()) $content_type = 'text/plain'; - if ($content_type) return $content_type; + if (!$content_type and !$format and self::php_cli()) $content_type = 'text/plain'; + if (!$content_type) $content_type = self::content_type(); + return $content_type; } } return; # < Class