]> git.nbdom.net Git - nb.git/commitdiff
db includes
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 13 Sep 2016 15:04:54 +0000 (17:04 +0200)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 13 Sep 2016 15:04:54 +0000 (17:04 +0200)
lib/php/db/config.php [new file with mode: 0644]
lib/php/db/index.php
lib/php/db/page.php
lib/php/page.php

diff --git a/lib/php/db/config.php b/lib/php/db/config.php
new file mode 100644 (file)
index 0000000..da838cc
--- /dev/null
@@ -0,0 +1,9 @@
+<?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;
+Db::init([Db::ROOT_DIR.'/etc/dbs.yaml',Db::ROOT_DIR.'/etc/dbs.php','/etc/dbs.yaml']);
+?>
index 38556f335e874501e4b05d50028a513668873a15..beaf177e9195718d338da296af08c8c472ee59e6 100755 (executable)
@@ -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;
 
index df7b312055ff8f9026b989cdcc576031200a834e..476370b55d1104f8f4f759ea0f49f03c8a533d77 100644 (file)
@@ -1,18 +1,16 @@
 <?php
 require_once(dirname(__FILE__).'/../config.php');
 require_once(dirname(__FILE__).'/../page.php');
-#$o = new out();
-#bye($o->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;
index 3b52600b13216eaa9038252e839df4eba1cdd7a5..385e30b050b425c3fe8d3228555f8f9b35e3b111 100644 (file)
@@ -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 "</$t>".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 "</$t>".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