From: Nicolas Boisselier Date: Tue, 6 Dec 2016 12:15:14 +0000 (+0000) Subject: Nav X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=cb0431a66a05aee2d4f834e603c26255ea1f5cfb;p=nb.git Nav --- diff --git a/lib/php/db.php b/lib/php/db.php index 528653ad..c0c40ac7 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -631,6 +631,9 @@ class Db extends nb { $this->out(self::$action_help,['action','description']); $return = true; + } elseif ($action == 'db.ryptkey') { + echo $this->out($this->cryptkey(),['key']); + } elseif ($action == 'db.exec') { $count = 0; diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 6c756d7c..33f72326 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -1676,7 +1676,7 @@ Class Table extends nb { $r .= ''; $r .= ''.html_select_array(array_keys($this->db()->tables()),[ 'html' => 'class="tables" name="table" id="table"', - 'selected' => $this->p('table'), + 'selected' => $this->name, 'prettyText' => true, 'sort' => 'natcasesort', ]); @@ -1687,7 +1687,7 @@ Class Table extends nb { $r .= ''; $r .= ''.html_select_array($this->db()->dbs,[ 'html' => 'class="dbs" id="db" name="db" onchange="document.location=\''.preg_replace('/\?.*$/','',$_SERVER['REQUEST_URI']).'?db=\'+this.value"', - 'selected' => self::p('db'), + 'selected' => $this->db()->name, 'prettyText' => true, 'sort' => 'natcasesort', ]); @@ -1699,7 +1699,7 @@ Class Table extends nb { $r .= ''.html_select_array($this->db()->formats,[ 'html' => 'class="format" name="format" id="format"', - 'selected' => $this->p('format'), + 'selected' => $this->db()->format, 'prettyText' => true, 'sort' => 'natcasesort', ]); diff --git a/lib/php/nb.php b/lib/php/nb.php index 5e80a6f8..d13c947d 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -836,7 +836,7 @@ class NB { } public static function cryptkey($length=32) { - return bin2hex(mcrypt_create_iv($length, MCRYPT_DEV_URANDOM)); + return bin2hex(mcrypt_create_iv($length/2, MCRYPT_DEV_URANDOM)); } public static function encrypt($key,$value) { diff --git a/lib/php/page.php b/lib/php/page.php index 0480aa59..f3251ae9 100644 --- a/lib/php/page.php +++ b/lib/php/page.php @@ -69,8 +69,12 @@ class Page extends nb { if (!$this->content_type()) $this->content_type($this->client_content_type()); // Nav - if (isset($opt['nav'])) list($title,$nav) = self::nav_parse($opt['nav']); - unset($opt['nav']); + if (isset($opt['nav'])) { + list($title,$nav) = self::nav_parse($opt['nav']); + if ( empty($this->h1) ) $this->h1 = join($this->sep,$nav); + unset($opt['nav']); + } +# NB 06.12.16 if ( empty($this->title) ) $this->title = !empty($title) ? join($this->sep,$title) : $this->filename2title(); // Statics foreach ([ @@ -86,8 +90,6 @@ class Page extends nb { parent::__construct($opt); // Defaults -# NB 06.12.16 if ( empty($this->title) ) $this->title = !empty($title) ? join($this->sep,$title) : $this->filename2title(); -# NB 06.12.16 if ( empty($this->h1) ) $this->h1 = !empty($nav) ? join($this->sep,$nav) : $this->title; if ( empty($this->title) ) $this->title = !empty($nav) ? join($this->sep,$nav) : $this->filename2title(); // Call / Print diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index ccfc2584..35edcc6e 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -15,24 +15,41 @@ function dbq_run() { #var_export($params); $ext = $params['format']; if ($params['format'] == 'html') $params['format'] = 'table'; - if (!$params['db']) not_implemented(); + # # Page if (empty($_SERVER['DOCUMENT_ROOT'])) $_SERVER['DOCUMENT_ROOT'] = dirname(__FILE__).'/html'; require_once($_SERVER['DOCUMENT_ROOT'].'/../../../lib/php/page.php'); - #Page::pdef('out',1); + #debug(nb::p()); + #debug($params); + $title = array_filter(array_unique(array_slice(array_values($params),1)),function($v){ return($v=='ls' ? '' : $v); }); + array_unshift($title,'Home'); + $params['ext'] = $ext; + $path = '/'; + $nav = []; + #debug($title); + $i = 0; + foreach ($title as $k=>$v) { + if ($i == 0) { + $nav[] = [$v,'/']; + } else { + $nav[] = [$v,"$path$v.".$params['ext']]; + $path .= "$v/"; + } + $i++; + } + #debug($nav); $Page = new Page([ 'css' => '/default.css', - 'title' => join(' ',array_filter(array_unique(array_slice(array_values($params),1)),function($v){if ($v!=='ls') return $v;})), + 'title' => join(' ',$title), + #'h1' => join(' ',array_map(function($v) use($Page,$params){},$nav)), + 'nav' => $nav, ]); - $params['ext'] = $ext; $Page->content_type($Page->ext2mime($params['format']) ? $Page->ext2mime($params['format']) : 'text/plain'); - #$Page->content_type('text/plain'); if ($Page->is('text') and !$Page->is('html')) $Page->content_type('text/plain'); - #$Page->title = array_values($params)[1]; $Page->headers_no_cache(); $Page->begin(); @@ -50,8 +67,8 @@ function dbq_run() { $Db->out([ [ 'help', 'This help' ], [ 'ls', 'List configured databases' ], - [ 'status', 'Database status' ], [ 'databases', 'List others databases' ], + [ 'cryptkey', 'Generate a new encryption key' ], ],['command','description'], ['row_parse_post'=>function(&$r) use ($Page,$params) { $r['command'] = $Page->tag('a',$r['command'],'href="'.$r['command'].'.'.$params['ext'].'"'); @@ -64,6 +81,9 @@ function dbq_run() { }]); return $Page->end(); + } elseif ($params['db'] == 'cryptkey') { + $Db->out($Db->cryptkey(),['key']); + return $Page->end(); } # @@ -77,6 +97,7 @@ function dbq_run() { if ($params['table'] == 'help') { $Db->out([ [ 'help', 'This help' ], + [ 'status', 'Database status' ], [ 'ls', 'List tables' ], ],['command','description'], ['row_parse_post'=>function(&$r) use ($Page,$params) { @@ -148,10 +169,10 @@ function parse_uri($params=[]) { $path = preg_replace('/\?.*$/','',$_SERVER['REQUEST_URI']); - if (preg_match('/\.(\w+)$/',$_SERVER['REQUEST_URI'],$m)) { - #$path = preg_replace('/\.\w+$/','',$_SERVER['REQUEST_URI']); + if (preg_match('/\.(\w+)$/',$path,$m)) { + #$path = preg_replace('/\.\w+$/','',$path); $values[] = $m[1]; - $path = substr($_SERVER['REQUEST_URI'],0,strlen($_SERVER['REQUEST_URI'])-strlen($m[1])-1); + $path = substr($path,0,strlen($path)-strlen($m[1])-1); } else { $values[] = ''; }