]> git.nbdom.net Git - nb.git/commitdiff
fix bugs
authorNicolas Boisselier <nicolas.boisselier@semantico.com>
Thu, 8 Sep 2016 11:07:27 +0000 (12:07 +0100)
committerNicolas Boisselier <nicolas.boisselier@semantico.com>
Thu, 8 Sep 2016 11:07:27 +0000 (12:07 +0100)
etc/dbs/ui.php
lib/php/db.php
lib/php/db/page.php
lib/php/nb.php
lib/php/page.php

index a698b6b7adc6fb4cf29ecd489cd46e2730228418..69bbef08ed2716396d8ac7cb4aa225511db1078e 100644 (file)
@@ -165,6 +165,8 @@ $CONF['_ui'] = array(
 );
 $CONF['ui'] = array(
   '_import' => array('_ui'),
+  'order' => (preg_match('/^(dev|isp|ist)/',php_uname('n')) ? 1 : null),
+  #'order' => 1,
 );
 $CONF['ui-pgsql'] = array(
   'host' => 'ui.semantico.net',
index 21512d3b3cafbf24fe6542241397cb00e1a747f9..78d5be664e334d1f68cf005ea7775ddd78f594f2 100644 (file)
@@ -961,10 +961,12 @@ class Db extends nb {
     $dbs = [];
     $name = self::p('name','');
     $type = self::p('type','');
+    $has_order = false;
 
     foreach ($this->conf as $id => $attr) {
       $attr['_no_connect'] = true;
       $attr['id'] = $id;
+      if (isset($attr['id'])) $has_order = true;
       $d = new Db($attr);
       $db = [];
 
@@ -978,6 +980,7 @@ class Db extends nb {
       $dbs[] = $db;
     }
 
+    if ($has_order) foreach ($dbs as $i=>$db) if (!isset($db['order'])) $dbs[$i]['order'] = '';
     return $dbs;
   }
 
index 027e452f3eb134ea1ae4381df294b7983d5dc613..bb2916ea8c5dfcae8b4814e350d962b421a9cb4e 100644 (file)
@@ -6,7 +6,8 @@ require_once(dirname(__FILE__).'/../page.php');
 
 $Page = new Page([
   #'title' => 'Test',
-  'content_type' => ((Page::php_cli() and !Page::p('web') )? 'text/plain' : 'text/html'),
+  'content_type' => Page::content_type_and_set_format(),
+  #'content_type' => ((Page::php_cli() and !Page::p('web') )? 'text/plain' : 'text/html'),
   'call' => array(
     'begin',
     ['out', "Hello World !!!\n"],
@@ -23,10 +24,14 @@ $Page = new Page([
           #bye($type);
           $page->pdef('format','csv');
       }
+      #echo Page::p('db')."\n"; return;
+#echo 'zaza'; return;
       if ($page->action()) 1;
       else require_once(dirname(__FILE__).'/index.php');
       #else if (!empty($page->db)) $page->db->action($page->db->p('action'),empty($Table) ? null : $Table);
     },
+/*
+*/
     #array('out', print_r($_SERVER,true)),
     'end',
   ),
index ca5abe8e2ffa797dcda40080fb07e44853c77b64..d71a3fa8d27e96f0f8e364c32e6a443cbd4b5c14 100644 (file)
@@ -248,7 +248,6 @@ class NB {
     }
 
     $new_argv = array();
-   
     for ($i=1;$i<count($argv);$i++) {
 
       if (preg_match('/^([\w_\-\.]+)=(.+)\s*$/',$argv[$i],$f)) {
@@ -761,5 +760,19 @@ class NB {
     debug($CONF);
   }
 
+  /*
+   * Function client_content_type
+   * Return the head Accept from the client
+   */
+  public static function client_content_type() {
+    $headers = self::client_header();
+    if (0
+      or !isset($headers['Accept'])
+      or $headers['Accept'] == '*/*'
+    ) return '';
+    $v = explode(',', $headers['Accept']);
+    return $v ? $v[0] : '';
+  }
+
 } # < Class
 ?>
index fe470cf4d15cb171c2335f8263b08f46f2818af6..44a4de13caa137bb40266fd5e378c71c3e85db01 100644 (file)
@@ -55,6 +55,7 @@ class Page extends nb {
     if (isset($opt['content_type'])) $this->content_type($opt['content_type']);
     #elseif($this->php_cli()) $this->content_type('text/html');
     unset($opt['content_type']);
+    if (!$this->content_type()) $this->content_type($this->client_content_type());
 
     // Statics
     foreach ([
@@ -68,7 +69,7 @@ class Page extends nb {
 
     // Opt
     parent::__construct($opt);
-    
+
     // Defaults
     if ( empty($this->title) ) $this->title = !empty($title) ? join($this->sep,$title) : $this->filename2title();
     if ( empty($this->h1) ) $this->h1 = !empty($nav) ? join($this->sep,$nav) : $this->title;
@@ -304,20 +305,6 @@ class Page extends nb {
 
   }
 
-  /*
-   * Function client_content_type
-   * Return the head Accept from the client
-   */
-  public static function client_content_type() {
-    $headers = getallheaders();
-    if (0
-      or !isset($headers['Accept'])
-      or $headers['Accept'] == '*/*'
-    ) return '';
-    $v = explode(',', $headers['Accept']);
-    return $v ? $v[0] : '';
-  }
-
   public static function headers_no_cache() {
     $ts = gmdate("D, d M Y H:i:s") . " GMT";
     header("Expires: $ts");
@@ -425,10 +412,6 @@ class Page extends nb {
     return preg_replace('/\?.*$/','',$_SERVER['REQUEST_URI']);
   }
 
-  public static function files_concat($files) {
-    
-  }
-
   public static function nav_parse($array) {
     #$v = &$sep;
     foreach ($array as $k => $v) {
@@ -538,5 +521,20 @@ class Page extends nb {
     return self::$content_type;
   }
 
+  public static function content_type_and_set_format() {
+    $format = self::p('format');
+    $content_type = self::p('content_type');
+
+    if (!$format and $content_type) {
+      self::p('format',self::mime2ext($content_type));
+    } elseif (!$format and ($client_type = self::client_content_type())) {
+      self::p('format',self::mime2ext($client_type));
+    }
+
+    if (!$content_type and $format) $content_type = self::ext2mime($format);
+    if (!$content_type and self::php_cli()) $content_type = 'text/plain';
+    if ($content_type) return $content_type;
+  }
+
 } return; # < Class
 ?>