--- /dev/null
+<?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']);
+?>
*
* 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;
<?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":
#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;
* 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)) {
);
}
+ if (!$is_html) return join("\n",(array)$content);
+
if ($content===null) {
self::tag_end($tag);
return '<' . $tag . ($attrs ? " $attrs" : "") . '>';
;
}
+ 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);
}
- 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)) {
}
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