]> git.nbdom.net Git - nb.git/commitdiff
fix content type bug
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 4 Dec 2016 21:32:47 +0000 (21:32 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 4 Dec 2016 21:32:47 +0000 (21:32 +0000)
etc/dbq/crypt.yaml
etc/dbq/zzz-all.php
lib/php/config.php
lib/php/db.php
lib/php/nb.php
lib/php/page.php
www/dbq/html/index.php

index ba97cdeec85e04bef7d8668f5bebf3bfc8b8ec71..ab86bdc6cd08b7e3cc939174a16d9ea0d0ac91bf 100644 (file)
@@ -1,3 +1,4 @@
 crypt:
   type: sqlite
   host: /dev/shm/crypt.db
+  default_table: credential
index 37f1a7028d26a3b825cef116379f3531d0b47e58..fb25631c73a9218aa35f7fda497f4d74a37edd26 100644 (file)
@@ -79,4 +79,3 @@ foreach ($DBQ as $id => $db) {
   $DBQ['all']['_import'][] = $id;
 
 }
-if (nb::p('db')!='nb') $DBQ['all']['_import'][] = 'nb';
index 570d834b15990cde7d5f64778ad6beaa7b7e180a..0a33302a644dbad948418dd40a5e60ab60ae9069 100644 (file)
@@ -9,6 +9,7 @@
 #define('NB_PROD',true);
 if (empty($_SERVER['PROD'])) error_reporting(E_ALL | E_STRICT | E_NOTICE);
 
+// Base lib
 require(dirname(__FILE__).'/nb.php');
 
 // Cli
@@ -18,13 +19,14 @@ if (nb::php_cli()) {
   ini_set('log_errors', false);
   if (nb::p('txt_errors')) ini_set('html_errors', false);
 }
+
 // Web
 else {
   ini_set('display_errors',empty($_SERVER['PROD']));
   ini_set('html_errors',empty($_SERVER['PROD']));
 }
 
-// Should be done in php.ini for performance
+// Should be done in php.ini for performance ?
 if (!ini_get('UTC')) date_default_timezone_set('UTC');
 
 ini_set('include_path',''
index ce8ea2188748f07625d046e84078fe46f7fb65af..97f0a713d03843bea88216b277463561815973b9 100644 (file)
@@ -814,10 +814,18 @@ class Db extends nb {
     if (isset($Table)) self::bye("Table.init(): GLOBALS['Table'] already exists !");
     if (isset($Db)) self::bye("Db.init(): GLOBALS['Db'] already exists !");
 
+    #
+    # Db
+    #
     $Db = new self();
-    $Db->pinit();
     if (empty($Db)) return false;
 
+    #
+    # Params
+    $Db->pinit();
+
+    #
+    # Load conf
     $db = $Db->conf_search_db($conf);
     if ($Db->p('localFile')) {
       foreach ($Db->localFile($db['name']) as $k=>$v) {
@@ -825,13 +833,14 @@ class Db extends nb {
       }
     }
 
+    #
     # Connection
     $Db->__construct($db);
     $Db->connect();
 
-    /*
-      Table
-    */
+    #
+    # Table
+    #
     if (self::p('action') and
       !self::p('table') and
       !preg_match('/^(table\.\w+|rows|insert|edit|delete|update)$/',self::p('action'))
index ec349bf827cb63c48037217ee23daa8e79bce473..e9a06cd33ff702bdd6dd0f952d24b489e7ffe869 100644 (file)
@@ -95,7 +95,7 @@ class NB {
    * Return the value set or existing
    */
   public static function pdef($name,$value) {
-    if (preg_match('/^\s*$/',self::p($name))) return self::pset($name,is_callable($value) ? $value() : $value);
+    if (preg_match('/^\s*$/',self::p($name))) return self::pset($name,(!is_scalar($value) and is_callable($value)) ? $value() : $value);
     return self::p($name);
   }
 
index 884da78a80430ba392b38c9faa669854e83261c5..2d3f32cdf4cbdcf90bf40efbadc6f38c96ffab70 100644 (file)
@@ -328,6 +328,7 @@ class Page extends nb {
   }
 
   public static function headers_no_cache() {
+    if (self::php_cli()) return false;
     $ts = gmdate("D, d M Y H:i:s") . " GMT";
     header("Expires: $ts");
     header("Last-Modified: $ts");
@@ -336,6 +337,7 @@ class Page extends nb {
   }
 
   public static function headers_cache($seconds_to_cache=3600) {
+    if (self::php_cli()) return false;
     if ($seconds_to_cache === 0) return headers_no_cache();
     $ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";
     header("Expires: $ts");
@@ -344,9 +346,9 @@ class Page extends nb {
   }
 
   public function headers() {
+    if (self::php_cli()) return false;
 
     #header('Content-type: ' . self::$content_type);
-    self::$content_type = 'text/plain';
                header('Content-type: '.self::$content_type . (($c = strtoupper ( self::$charset )) ? "; charset=$c" : ""));
 
     if (isset($this->expires)) self::headers_cache($this->expires);
index f907dd8c6efe7d4e712e7e24bfc45bfe8a477118..8ac3a3d281903acc81de26decdb70296bcde6873 100644 (file)
@@ -1,9 +1,30 @@
 <?php
 if (empty($_SERVER['DOCUMENT_ROOT'])) $_SERVER['DOCUMENT_ROOT'] = dirname(__FILE__);
 if (empty($_SERVER['REQUEST_URI'])) $_SERVER['REQUEST_URI'] = '';
+function parse_uri() {
+  $path = preg_replace('/\?.*$/','',$_SERVER['REQUEST_URI']);
+  $values = explode('/',trim($path,'/'));
+
+  $P = [
+    'db' => '',
+    'table' => '',
+    'action' => '',
+    'format' => '',
+  ];
+
+  $i=0;
+  $count = count($values);
+  foreach ($P as $p => $default) {
+    if ($i>=$count) break;
+    $P[$p] = $values[$i];
+    $i++;
+  }
+
+}
+#var_dump(parse_uri());
 
 $params = [
-  #'db',
+  'db',
   'table',
   'action',
   'format',
@@ -26,10 +47,10 @@ foreach ($values as $k=>$v) {
 }
 
 Page::pdef('format','human');
-#Page::pdef('action','db.ls');
+Page::pdef('action','db.ls');
 
 require_once($_SERVER['DOCUMENT_ROOT'].'/../../../lib/php/db/init.php');
-header('Content-type: text/plain');
+#header('Content-type: text/plain');
 $Page = $Db->page();
 $Page->headers_no_cache();
 $Page->call([