# PDO Connection
# NB 22.09.16 public static $encoding = 'utf-8';
-# NB 22.09.16: TODO
- public static $table_rows_dump = [
- 'praser' => false,
- ];
+# NB 10.09.18 # NB 22.09.16: TODO
+# NB 10.09.18 public static $table_rows_dump = [
+# NB 10.09.18 'praser' => false,
+# NB 10.09.18 ];
public $conn;
public $pdo;
public $tables = [];
public $types = [];
public $conf = [];
+ static $dbq = []; # NB 10.09.18: For internal use in /etc/dbq* files
public $attach = []; # for sqlite
public $row_parse_pre; # Function to call in table.rows()
public $row_parse_post; # Function to call in table.rows()
if (!empty($this->$p)) $msg .= " $p=".$this->$p;
}
- $msg .= "\n ".$e->getMessage();
+ #$msg .= "\n ".$e->getMessage();
+ $msg .= ": ".$e->getMessage();
#throw new Exception($msg, (int)$e->getCode());
self::bye($msg);
}
if (empty($files)) return [];
#
- # Load all files into a $dbs if #files is not a hash
+ # Load all files into a self::$dbq if #files is not a hash
#
$DBQ = [];
- $dbs = [];
+# NB 10.09.18 $dbs = [];
$done = [];
foreach ((array)$files as $file) {
if (!is_readable($file)) continue;
if (preg_match('/\.(yaml|yml)$/i',$file) and ($yaml = self::yaml_parse_file($file))) {
- $dbs = self::ar_merge($dbs,$yaml);
+ self::$dbq = self::ar_merge(self::$dbq,$yaml);
} elseif (preg_match('/\.php$/i',$file)) {
$DBQ = [];
require($file);
- if (!empty($DBQ)) $dbs = self::ar_merge($dbs,$DBQ);
+ if (!empty($DBQ)) self::$dbq = self::ar_merge(self::$dbq,$DBQ);
}
}
unset($yaml,$DBQ);
- if (!$dbs) return false;
+ if (!self::$dbq) return false;
#
# First iteration: Import database conf with key _import
#
- foreach ($dbs as $id=>$params) {
+ foreach (self::$dbq as $id=>$params) {
$params = (array)$params;
foreach ($params as $k => $v) {
$import = is_array($v) ? $v : explode(',',$v);
foreach ($import as $v) {
if ($id == $v) self::bye("Infinite loop: _import $id = $v");
- if (empty($dbs[$v])) continue;
+ if (empty(self::$dbq[$v])) continue;
- foreach ($dbs[$v] as $kk => $vv) {
- if (!isset($params[$kk])) $dbs[$id][$kk] = $vv;
+ foreach (self::$dbq[$v] as $kk => $vv) {
+ if (!isset($params[$kk])) self::$dbq[$id][$kk] = $vv;
}
}
- unset($dbs[$id][$k]);
+ unset(self::$dbq[$id][$k]);
}
}
- $default = isset($dbs['_default']) ? $dbs['_default'] : [];
+ $default = isset(self::$dbq['_default']) ? self::$dbq['_default'] : [];
#
# Second iteration: Remove db starting with _
#
- foreach ($dbs as $db=>$params) { if (preg_match('/^_/',$db)) unset($dbs[$db]); }
+ foreach (self::$dbq as $db=>$params) { if (preg_match('/^_/',$db)) unset(self::$dbq[$db]); }
- if (!$dbs) return false;
+ if (!self::$dbq) return false;
#
# Third iteration: Add missing and default
#
- foreach ($dbs as $db=>$params) {
- if (empty($params['name'])) $dbs[$db]['name'] = $db;
- if (empty($params['id'])) $dbs[$db]['id'] = $db;
+ foreach (self::$dbq as $db=>$params) {
+ if (empty($params['name'])) self::$dbq[$db]['name'] = $db;
+ if (empty($params['id'])) self::$dbq[$db]['id'] = $db;
# Ignore incomplete
if (empty($params['type'])) {
- unset($dbs[$db]);
+ unset(self::$dbq[$db]);
continue;
}
- foreach ($default as $k=>$v) if (!isset($params[$k])) $dbs[$db][$k] = $v;
+ foreach ($default as $k=>$v) if (!isset($params[$k])) self::$dbq[$db][$k] = $v;
}
#
# Sort by `order`, min first
#
- uasort($dbs,function($a,$b){
+ uasort(self::$dbq,function($a,$b){
if (empty($a['order']) and empty($b['order'])) return strcmp($a['id'],$b['id']);
$a_ = !empty($a['order']) ? $a['order'] : 9999999;
$b_ = !empty($b['order']) ? $b['order'] : 9999999;
#
# Return
#
- if (!$dbs) return false;
- if ($first !== false) $first = self::ar_first($dbs);
- return $dbs;
+ if (!self::$dbq) return false;
+ if ($first !== false) $first = self::ar_first(self::$dbq);
+
+ return self::$dbq;
+ #self::$dbq = array_merge(self::$dbq,$dbs);
}
/**
$html = '';
- $html .= '<table class="rows wp-list-table widefat striped">'.NB_EOL;
+ $html .= '<table class="table table-bordered rows wp-list-table widefat striped">'.NB_EOL;
if ($this->show_header) {
$html .= '<thead>'.NB_EOL;
static $Spyc;
if (!isset($Spyc)) {
- if (!function_exists('yaml_emit')) {
+ # NB 10.09.18: Can't trust devian package php-yaml
+ if (true or !function_exists('yaml_emit')) {
require_once(NB_ROOT.'/lib/php/Spyc.php');
- function yaml_emit($data) { return Spyc::YAMLDump($data, false, false, true); }
- function yaml_parse_file($file) { return Spyc::YAMLLoad($file); }
- function yaml_parse($str) { return Spyc::YAMLLoadString($str); }
+ function _yaml_emit($data) { return Spyc::YAMLDump($data, false, false, true); }
+ function _yaml_parse_file($file) { return Spyc::YAMLLoad($file); }
+ function _yaml_parse($str) { return Spyc::YAMLLoadString($str); }
+ } else {
+ function _yaml_emit($data) { return yaml_emit($data, false, false, true); }
+ function _yaml_parse_file($file) { return yaml_parse_file($file); }
+ function _yaml_parse($str) { return yaml_parse($str); }
}
$Spyc = true;
public static function yaml_parse_file($file) {
self::yaml_init();
- return yaml_parse_file($file);
+ return _yaml_parse_file($file);
}
/*
*/
public static function yaml_encode($row) {
self::yaml_init();
- $yaml = yaml_emit($row);
+ $yaml = _yaml_emit($row);
$yaml = preg_replace('/^---\s*/','',$yaml);
$yaml = preg_replace('/\n\.\.\.$/','',$yaml);
$yaml = trim($yaml);
public static function yaml_decode($str) {
self::yaml_init();
- return yaml_parse($str);
+ return _yaml_parse($str);
}
/*
<?php
return [
'is_html' => true,
- 'enclose' => array("<table class=\"rows widefat striped\">".NB_EOL,"</table>".NB_EOL),
+ 'enclose' => array("<table class=\"table table-bordered rows widefat striped\">".NB_EOL,"</table>".NB_EOL),
'tag_enclose' => 'tr class="row"',
'tag_head' => 'th',
'tag' => 'td',
public $page;
public $table;
public $db;
+ private $conf;
public function __construct($opt=[]) {
//
// Write output
if ($this->expires and !preg_match('/^(dump|insert|update|replace|rm|vi)$/',$this->params['action'])) $this->page->expires = $this->expires;
$this->page->headers_no_cache();
+
+ // Conf for js or info
+ $this->conf = [
+ 'db.base' => ( empty($this->db) ? '' : $this->db->base ),
+ 'table.base' => ( empty($this->table) ? '' : $this->table->base ),
+ 'default.format' => $this->format_html,
+ 'default.limit' => $this->default_limit,
+ 'param.format' => $this->params['format'],
+ 'param.db' => $this->params['db'],
+ 'param.table' => $this->params['table'],
+ 'param.action' => $this->params['action'],
+ 'param.args' => $this->params['args'],
+ 'param.deep' => $this->params_deep,
+ 'text.add' => 'Add New',
+ 'text.clear' => 'Clear',
+ 'perm' => $this->perm,
+ 'perms' => $this->perms,
+ ];
+
if (empty($this->_nopage)) {
- $this->conf = [
- 'db.base' => ( empty($this->db) ? '' : $this->db->base ),
- 'table.base' => ( empty($this->table) ? '' : $this->table->base ),
- 'default.format' => $this->format_html,
- 'default.limit' => $this->default_limit,
- 'param.format' => $this->params['format'],
- 'param.db' => $this->params['db'],
- 'param.table' => $this->params['table'],
- 'param.action' => $this->params['action'],
- 'param.args' => $this->params['args'],
- 'param.deep' => $this->params_deep,
- 'text.add' => 'Add New',
- 'text.clear' => 'Clear',
- 'perm' => $this->perm,
- 'perms' => $this->perms,
- ];
$this->page->js_code = 'window._dbq = '.json_encode($this->conf);
if ($obj != 'logout') {
} elseif ($action == 'cryptkey') { $this->page($this->cryptkey());
} elseif ($action == 'status') { $this->page($this,'status');
} elseif ($action == 'conf') { $this->page($this,'conf');
- } elseif ($action == 'conf') { $this->page($this,'conf');
} elseif ($action == 'html') { $this->page(Mime::html($arg));
} elseif ($action == 'types') {