]> git.nbdom.net Git - nb.git/commitdiff
Fix conn bug
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 6 Jul 2015 00:18:07 +0000 (01:18 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 6 Jul 2015 00:18:07 +0000 (01:18 +0100)
lib/php/db.php
lib/php/page.php

index 97229234d2f86c5d67ec810a661619fae723171a..a6b2b3a5158b810e03ac477a1bd11a9732e8b77a 100644 (file)
@@ -13,6 +13,7 @@ class db {
 
   public $tables = array();
   public $conn;
+  public $title;
   public $type;
   public $help_criterias = array(
     ' * or % for wildcar',
@@ -21,12 +22,19 @@ class db {
     ' combine criterias with OR/AND',
   );
 
-  function __construct($pdo) {
-    $this->conn = new PDO($pdo);
-    $this->type = strtolower(preg_replace('/^([^:]+):.*$/','\1',$pdo));
+  function __construct($db) {
+
+    $db = is_scalar($db) ? array('conn' => $db) : $db;
+    foreach ($db as $k=>$v) $this->$k = $v;
+    $this->type = strtolower(preg_replace('/^([^:]+):.*$/','\1',$db['conn']));
+
+    #bye($db['conn']);
+    $this->conn = new PDO($db['conn']);
 
     if ($this->type == 'sqlite') {
 
+      if (empty($this->title)) $this->title = preg_replace('/^.*?:.*(.*?)(\.\w+)?$/','\1',$db['conn']);
+
       $this->conn->sqliteCreateFunction('regexp',
         function ($pattern, $data, $delimiter = '~', $modifiers = 'isuS') {
           if (isset($pattern, $data) === true) {
@@ -148,7 +156,7 @@ EOF;
   function print_header($type) {
 
     if ($this->p('format')=='csv') {
-      header('Content-type: text/plain');
+      header('Content-type: text/csv');
 
     } elseif ($this->p('format')=='yaml') {
       header('Content-type: text/yaml');
@@ -965,13 +973,14 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
   }
 
   function rows_rec_div($row) {
+
     echo '<ul class="border rad bgcolor">';
 
     foreach ($row as $k => $v) {
       echo '<li>'
-        .'<span class="key">'.$k.'</span>'
+        .'<span class="k">'.$k.'</span>'
         .': '
-        .'<span class="value">'.$v.'</span>'
+        .'<span class="v">'.$v.'</span>'
         .'</li>';
     }
 
index de70903514397853b992792cf98f0d65f6f11e5c..995bbd6eea05cfeb2f41d8dc971e8bfe3082df10 100644 (file)
@@ -35,7 +35,7 @@ class Page {
   /*
     Create
   */
-  function Page($opt = array()) {
+  function __construct($opt = array()) {
 
     //// opt
     foreach ($opt as $k => $v) {
@@ -46,7 +46,8 @@ class Page {
     // Defaults
     if ( ! isset($opt['title']) )
       #$this->title = $GLOBALS['argv'][0]
-      $this->title = $this->filename2title($_SERVER['SCRIPT_NAME']);
+      $this->title = $this->filename2title();
+      #bye($this->title);
       #$this->title = preg_replace('@^.*?([^/\.]+)[^/]*@','\1',$_SERVER['SCRIPT_NAME']);
       #die( $this->title);
     ;
@@ -81,8 +82,9 @@ class Page {
     return (is_array($v) ? $v : array($v));
   }
 
-  function filename2title($str) {
-    $str = preg_replace('@^.*?([^/\.]+)(/index)?(\..*?)$@','\1',$_SERVER['SCRIPT_NAME']);
+  function filename2title() {
+    $str = preg_replace(',^.*?([^/]+)(\/?.*)?$,','\1',$_SERVER['REQUEST_URI']);
+    if ($str == '/') $str = preg_replace('@^.*?([^/\.]+)(/index)?(\..*?)$@','\1',$_SERVER['SCRIPT_NAME']);
     $str = preg_replace('@[\'_-]+$@',' ',$str);
     return mb_strtoupper(mb_substr($str,0,1)).mb_strtolower(mb_substr($str,1,mb_strlen($str)));
   }