From 125dffeba17d448ef13b216aae94b286fa128644 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Thu, 30 Jun 2016 16:48:58 +0100 Subject: [PATCH] str_match --- etc/dbs/ui.php | 1 + lib/php/db.php | 21 ++++++++++++--------- lib/php/nb.php | 13 +------------ 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/etc/dbs/ui.php b/etc/dbs/ui.php index 575d2a87..8a6ed537 100644 --- a/etc/dbs/ui.php +++ b/etc/dbs/ui.php @@ -5,6 +5,7 @@ $CONF['_ui'] = array( 'default_table' => 'node', 'sql_replace' => function($sql) { + if (!Db::p('db.type')) return $sql; $r = []; $r["CAST(started as char(30)),duration||' seconds'"] = "from_unixtime(UNIX_TIMESTAMP(started)+duration)"; diff --git a/lib/php/db.php b/lib/php/db.php index 67b97375..3633f80d 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -401,9 +401,8 @@ class Db extends nb { $type = self::p('type',''); foreach ($this->tables() as $t) { -# NB 27.06.16 if (!empty($name) and strpos($t->name,$name) === false) continue; - if (!empty($name) and !preg_match('/'.$name.'/',$t->name)) continue; - if (!empty($type) and strpos($t->type,$type) === false) continue; + if (!empty($name) and !$this->str_match($t->name,$name)) continue; + if (!empty($type) and !$this->str_match($t->type,$type)) continue; $rows[] = $t->infos(); } @@ -414,24 +413,29 @@ class Db extends nb { } elseif ($action == 'db.dbs' or $action == 'dbs') { if (self::p('hash') or self::p('all')) { + $fields = ['id','name','host','type']; $dbs = []; $name = self::p('name',''); $type = self::p('type',''); + foreach ($this->conf as $id => $attr) { $d = new Db(); foreach ($attr as $k=>$v) $d->$k = $v; $d->connect_init(); $db = []; $d->id = $id; + foreach ($fields as $k) { if (!isset($d->$k)) continue; $db[$k] = $d->$k; } -# NB 27.06.16 if (!empty($name) and strpos($db['name'],$name) === false) continue; - if (!empty($name) and !preg_match('/'.$name.'/',$db['name'])) continue; - if (!empty($type) and strpos($db['type'],$type) === false) continue; + + if (!empty($name) and !$this->str_match($db['name'],$name)) continue; + if (!empty($type) and !$this->str_match($db['type'],$type)) continue; $dbs[] = $db; } + $return = $this->out($dbs,$fields); + } else $return = $this->out($this->dbs,"id"); @@ -626,9 +630,8 @@ class Db extends nb { foreach ($tables as $t) { if (!empty($tables) and empty($tables[$t->name])) continue; - if (!empty($type) and strpos($t->type,$type) === false) continue; -# NB 27.06.16 if (!empty($name) and strpos($t->name,$name) === false) continue; - if (!empty($name) and !preg_match('/'.$name.'/',$t->name)) continue; + if (!empty($name) and !$this->str_match($t->name,$name)) continue; + if (!empty($type) and !$this->str_match($t->type,$type)) continue; if ($insert) { echo "\n-- ".strtoupper($t->type).": ".$t->name."\n"; diff --git a/lib/php/nb.php b/lib/php/nb.php index c5470a1c..63aee7ff 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -3,17 +3,6 @@ if (!defined('NB_ROOT')) define('NB_ROOT',realpath(dirname(__FILE__).'/../..')); if (!defined('NB_EOL')) define('NB_EOL',defined('NB_PROD') ? '' : "\n"); require_once(realpath(dirname(__FILE__).'/functions.php')); #$nb = new NB(); debug($nb->test()); -/* -if (empty($_SERVER['DOCUMENT_ROOT'])) var_export([ - '~0 : 0' => nb::str_match('~0','0'), - 'null : 0' => nb::str_match('null','0'), - 'null : ""' => nb::str_match('null',''), - '!null : ""' => nb::str_match('!null',''), - '!~zaz : "zaza"' => nb::str_match('!~zaz','zaza'), - '~zaz : "zaza"' => nb::str_match('~zaz','zaza'), - 'za* : "zaza"' => nb::str_match('za*','zaza'), -]); -*/ if (class_exists('NB')) return; class NB { @@ -537,7 +526,7 @@ class NB { } } - public static function str_match($pattern,$string) { + public static function str_match($string,$pattern) { $match = false; // No empty values -- 2.47.3