]> git.nbdom.net Git - nb.git/commitdiff
Nav
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 6 Dec 2016 12:15:14 +0000 (12:15 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 6 Dec 2016 12:15:14 +0000 (12:15 +0000)
lib/php/db.php
lib/php/db/table.php
lib/php/nb.php
lib/php/page.php
www/dbq/dbq.php

index 528653ad03be90e177ba5e805d2c48457d2c8167..c0c40ac7a762e57cfb44e453071e4c2219ce0f8f 100644 (file)
@@ -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;
index 6c756d7cacedad8aecaa64ec3f4cc5fb7b1c22ae..33f72326b68fd5d212e9e4c7e5c79181e0108238 100644 (file)
@@ -1676,7 +1676,7 @@ Class Table extends nb {
       $r .= '<span class="label">';
       $r .= '<label for="table">Tables</label>'.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 .= '<span class="label">';
         $r .= '<label for="db">Db</label>'.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 .= '<label for="format">Format</label>'.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',
       ]);
index 5e80a6f8b02de5a622f71175e49d85049b304787..d13c947da390d2e35060b3d4af7d7704a932bd60 100644 (file)
@@ -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) {
index 0480aa597fddcaddd39e14379bb9d7ea9ec299bf..f3251ae95a038ec928256074e174179365b56d5d 100644 (file)
@@ -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
index ccfc2584925a9b580c3f7d819f28ec0bdddda1d1..35edcc6ee24ad6c02501d48aae5aa3284dca4567 100644 (file)
@@ -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[] = '';
   }