]> git.nbdom.net Git - nb.git/commitdiff
Bed
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 11 Apr 2016 01:05:28 +0000 (02:05 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 11 Apr 2016 01:05:28 +0000 (02:05 +0100)
etc/dbs.php
etc/dbs.yaml
lib/php/db.php
lib/php/db/field.php
lib/php/db/table.php
lib/php/functions.php
lib/php/nb.php
lib/php/out.php
lib/php/page.php

index 6facc4d988b42b04bf492eb70d25f325a88ddac9..74fb80f275dc2b0bddb1eb397ca7f3f3d6510d2e 100644 (file)
 <?php
+$CONF = array();
+require_once(dirname(__FILE__).'/dbs/postfix.php');
+require_once(dirname(__FILE__).'/dbs/nb.php');
+require_once(dirname(__FILE__).'/dbs/rent.php');
+require_once(dirname(__FILE__).'/dbs/puppetdb.php');
 /*
 */
-$CONF = array (
-  'nb' => array (
+  /*
+  $CONF2 = array(
+  array (
+    'host' => 'big.cascais.loc',
+    'title' => 'Mysql Izi on Big',
+    'default_table' => 'process',
+    'user' => 'nico',
+    'name' => 'izi',
+    'tables' => 
+    array (
+      'site' => 
+      array (
+        'replace' => 
+        array (
+          'idlang' => 'lang.id',
+        ),
+      ),
+    ),
+    'type' => 'mysql',
+  ),
+  array (
     'host' => 'admin.izideal.vpn',
     'type' => 'mysql',
     'name' => 'nb',
     'user' => 'nico',
-    '_import' => '_nico',
+    'Title' => 'Rent',
+    'notice' => 'Micro foncier 4BE',
     'default_table' => 'rent',
-    'tables' => array(
-      'rent' => array(
+    'tables' => 
+    array (
+      'place' => 
+      array (
+        'replace' => 
+        array (
+          'id' => 'addr.addr',
+        ),
+      ),
+      'rent' => 
+      array (
         'orderby' => 'start desc, end desc',
-        'replace' => array (
+        'replace' => 
+        array (
           'idtenant' => 'tenant.name',
           'idplace' => 'addr.addr',
         ),
-        'row_parse_pre' => function(&$r) {
-          #extra: "rent * (1 + ( strftime('%m',end)+12*strftime('%Y',end) ) -  ( strftime('%m',start)+12*strftime('%Y',start) ))"
-          #$r['rent_year'] = $r['rent'] * (1 + ( date('m',strtotime($r['end']))+12
-          $r['Total'] = $r['rent'] + $r['charge'];
-          if (1) $r['rent_year'] = sprintf('%.2f',$r['rent'] * (1 +
-            ( date('m',strtotime($r['end'])) + 12 * date('Y',strtotime($r['end'])) )
-            - 
-            ( date('m',strtotime($r['start'])) + 12 * date('Y',strtotime($r['start'])) )
-          ));
-        },
-        'row_parse_post' => function(&$r) {
-          $r['revision'] = join(' ',array(
-            '<a href="template/?id=quittance.html&amp;idplace='.$r['idplace'].'&amp;idtenant='.$r['idtenant'].'&amp;start=2015-04-01">quittance</a>',
-            '<a href="template/?id=revision.txt&amp;idplace='.$r['idplace'].'&amp;idtenant='.$r['idtenant'].'&amp;start=2015-04-01">revision</a>',
-          ));
-        },
+        'row_parse_pre' => 
+        Closure::__set_state(array(
+        )),
+        'row_parse_post' => 
+        Closure::__set_state(array(
+        )),
+      ),
+    ),
+  ),
+  array (
+    'title' => 'Mysql Izi on Admin',
+    'host' => 'admin.izideal.vpn',
+    'default_table' => 'process',
+    'user' => 'izideal',
+    'name' => 'izi',
+    'tables' => 
+    array (
+      'site' => 
+      array (
+        'replace' => 
+        array (
+          'idlang' => 'lang.id',
+        ),
+      ),
+    ),
+    'type' => 'mysql',
+  ),
+  array (
+    'title' => 'Mysql Izi',
+    'host' => 'sql.izideal.vpn',
+    'default_table' => 'process',
+    'user' => 'izideal',
+    'name' => 'izi',
+    'tables' => 
+    array (
+      'site' => 
+      array (
+        'replace' => 
+        array (
+          'idlang' => 'lang.id',
+        ),
       ),
     ),
+    'type' => 'mysql',
   ),
+  array (
+    'title' => 'Puppetdb',
+    'host' => 'big',
+    'type' => 'pgsql',
+    'user' => 'puppetdb',
+    'default_table' => 'view_hosts',
+    'tables' => 
+    array (
+      'hosts' => 
+      array (
+        'extras' => 
+        array (
+          'last_compile' => 
+          array (
+            'type' => 'text',
+            'extra' => 'to_char(hosts.last_compile, \'YYYY-MM-DD HH:mm:ss\'::text)',
+          ),
+          'last_freshcheck' => 
+          array (
+            'type' => 'text',
+            'extra' => 'to_char(hosts.last_freshcheck, \'YYYY-MM-DD HH:mm:ss\'::text)',
+          ),
+          'updated_at' => 
+          array (
+            'type' => 'text',
+            'extra' => 'to_char(hosts.updated_at, \'YYYY-MM-DD HH:mm:ss\'::text)',
+          ),
+          'created_at' => 
+          array (
+            'type' => 'text',
+            'extra' => 'to_char(hosts.created_at, \'YYYY-MM-DD HH:mm:ss\'::text)',
+          ),
+          'test' => 
+          array (
+            'type' => 'int',
+            'extra' => 1,
+          ),
+        ),
+      ),
+    ),
+    'name' => 'puppetdb',
+  ),
+  array (
+    'pdo' => 'sqlite:/opt/semantico/product/releases/sem_ui/db/semantico.db',
+    'title' => 'Semantico UI',
+    'default_table' => 'node',
+    'tables' => 
+    array (
+      'node' => 
+      array (
+        'orderby' => '(SELECT value FROM fact WHERE idnode=id AND name=\'date_install\') DESC',
+        'replace_' => 
+        array (
+          'iddc' => 'dc.id',
+        ),
+      ),
+    ),
+    'replace' => 
+    array (
+      'SELECT name FROM dc WHERE id=\'@id\'' => '.node td.iddc',
+    ),
+    'name' => 'ui',
+  ),
+  array (
+    'title' => 'RT',
+    'name' => 'rt',
+  ),
+  array (
+    'pdo' => 'sqlite:/dev/shm/crypt.db',
+    'name' => 'crypt',
+  ),
+  array (
+    'host' => 'admin.izideal.vpn',
+    'user' => 'nico',
+    'type' => 'mysql',
+    'name' => 'wp',
+  )
 );
+*/
 ?>
index ab9818e132cd8db04c2b53ed8cff8dcff9e56e2c..e55fe28cc69a157891d5c1b9b44c7be74e0fe498 100644 (file)
@@ -9,42 +9,9 @@ crypt:
 
 wp:
   host: admin.izideal.vpn
+  type: mysql
   _import:
     - _nico
-    - _mysql
-___nb:
-  host: admin.izideal.vpn
-  _import:
-    - _nico
-    - _mysql
-    #- _rent
-
-puppetdb:
-  #pdo: 'pgsql:host=big;dbname=puppetdb;user=puppetdb;password='
-  title: Puppetdb
-  host: big
-  type: pgsql
-  user: puppetdb
-  default_table: view_hosts
-  tables:
-    hosts:
-      extras:
-        last_compile:
-          type: text
-          extra: to_char(hosts.last_compile, 'YYYY-MM-DD HH:mm:ss'::text)
-        last_freshcheck:
-          type: text
-          extra: to_char(hosts.last_freshcheck, 'YYYY-MM-DD HH:mm:ss'::text)
-        updated_at:
-          type: text
-          extra: to_char(hosts.updated_at, 'YYYY-MM-DD HH:mm:ss'::text)
-        created_at:
-          type: text
-          extra: to_char(hosts.created_at, 'YYYY-MM-DD HH:mm:ss'::text)
-        test:
-          type: "int"
-          extra: 1
-
 ui:
   pdo: 'sqlite:/opt/semantico/product/releases/sem_ui/db/semantico.db'
   title: 'Semantico UI'
@@ -58,50 +25,10 @@ ui:
   replace:
     "SELECT name FROM dc WHERE id='@id'": ".node td.iddc"
 
-ui-mem:
-  pdo: 'sqlite:/dev/shm/semantico.db'
-  _import: ui
-
 rt:
   pdo: 'pgsql:host=db.rt.semantico.net;port=5432;dbname=rtdb;user=rtuser;password='
   title: 'RT'
 
-rent:
-  order: 1
-  pdo: 'sqlite:/opt/rent/rent.db'
-  _import:
-    - _rent
-
-_rent:
-  title: 'Rent'
-  notice: 'Micro foncier 4BE'
-  default_table: 'rent'
-
-# NEW- NB 10.01.16
-  tables:
-
-# NB 08.03.16     template:
-# NB 08.03.16       View: "'<a href=\"/template/'||id||'\">'||id||'</a>'"
-
-    place:
-      replace:
-        id: addr.addr
-
-    rent:
-      orderby: "start desc, end desc"
-      replace:
-        idtenant: tenant.name
-        idplace: addr.addr
-      extras:
-        total:
-          type: "float(8,2)"
-          extra: "ROUND(rent+charge,2)"
-        rent_year:
-          type: "float(8,2)"
-          extra: "rent * (1 + ( strftime('%m',end)+12*strftime('%Y',end) ) -  ( strftime('%m',start)+12*strftime('%Y',start) ))"
-          #extra: "rent * (1 + ( date_format(end,'%m')+12*date_format(end,'%Y') ) -  ( date_format(start,'%m')+12*date_format(start,'%Y') ))"
-        #revision: (SELECT GROUP_CONCAT('<a href="template/?id='||id||'&amp;idplace='||idplace||'&amp;idtenant='||idtenant||'&amp;start='||start||'">'||substr(id,0,instr(id,'.'))||'</a>',' ') FROM template)
-
 izi:
   #pdo: 'mysql:host=admin.izideal.com;port=3306;dbname=izi'
   title: Mysql Izi
@@ -109,8 +36,7 @@ izi:
   default_table: process
   user: izideal
   name: izi
-  _import:
-    - _mysql
+  type: mysql
   tables:
     site:
       replace:
@@ -133,8 +59,8 @@ izidev:
 media:
   host: media.izideal.vpn
   name: mysql
+  type: mysql
   _import:
-    - _mysql
     - _nico
 
 postfix:
@@ -142,5 +68,4 @@ postfix:
   title: Postfix on Izideal
   host: media.izideal.vpn
   user: postfix
-  _import:
-    - _mysql
+  type: mysql
index 06cb62afed1fa13baea305fd4da3cc586932c362..3a264c0d21dd5241d71634bb6ffb9bf86c0968d7 100644 (file)
@@ -30,6 +30,7 @@ class Db extends nb {
   public $name;
   public $type;
   public $tables;
+  public $row_parse; # Function to call in rows()
 
   # Objects
 # NB 28.03.16   public $table;
@@ -380,93 +381,7 @@ EOF;
     return '"'.$value.'"';
   }
 
-# TODEL - NB 01.04.16
-/*
-  function out($row,$head=false) {
-    if (!$this->p('header',1) and $head) $head = false;
-    $f = $this->p('format','json');
-    #if (preg_match('/yaml|yml/',$f)) bye($this->yaml_encode($this->object2array($this->fields())));
-    $mime = $this->print_header($f);
-
-    #echo $row.NB_EOL;
-    #bye($f); return true;
-    if ($f == 'json') { echo json_encode($row).NB_EOL; }
-    #elseif ($f == 'csv' and is_array($row)) { echo join("\n",$row)."\n"; }
-    #elseif ($f == 'csv') { echo join("\t",nb::ar_map('json_encode($a)',$row))."\n"; }
-    #elseif ($f == 'csv') { echo json_encode($row).NB_EOL; }
-    elseif ($f == 'csv') {
-      #if (is_object($data)) echo "$data\n";
-      #$isHash = array_values($row) !== $row;
-      if ($head) {
-        if ($head === true) {
-          $first = self::ar_first($row);
-          $first = array_keys($first);
-        } else {
-          $first = $head;
-        }
-        self::out($first);
-      }
-      if (is_scalar($row)) {
-        echo $row."\n";
-        return true;
-      }
-      if (is_array($row) and !self::is_hash($row)) {
-        echo join("\t",array_values($row))."\n";
-        return true;
-      }
-      $type = 0;
-      foreach ($row as $k => $v) {
-
-# NB 06.03.16         if ($type == 1 or $k === 0) {
-# NB 06.03.16           # Normal array
-# NB 06.03.16           $type = 1;
-# NB 06.03.16           echo "$v\n";
-# NB 06.03.16 
-# NB 06.03.16         } elseif ($type == 2 or self::is_hash($row[$k])) {
-# NB 06.03.16           echo ($type === 2 ? "\t" : "").$v;
-# NB 06.03.16           $type = 2;
-# NB 06.03.16 
-# NB 06.03.16         } elseif ($type == 3 or is_scalar($v)) {
-# NB 06.03.16           $type = 3;
-# NB 06.03.16           echo "$v\n";
-# NB 06.03.16 
-        if (is_scalar($v)) {
-          echo "$v\n";
-        } else {
-          #debug($v);
-          echo join("\t",array_values($v))."\n";
-        }
-        #} elseif ($type == 2 or $k === 0) {
-# NB 06.03.16         elseif (nb::is_hash($v)) {
-# NB 06.03.16           echo join("\t",array_values($v);
-# NB 06.03.16         }
-        #else echo join("\t",array_values($v))."\n";
-      }
-      #echo json_encode($row).NB_EOL;
-      if ($type === 2) {
-        echo "\n";
-      }
-    }
-    elseif (preg_match('/yaml|yml/',$f)) { echo $this->yaml_encode($row); }
-    elseif (preg_match('/php|var_export/',$f)) { echo var_export($row,true); }
-    elseif (preg_match('/var_dump/',$f)) { echo var_dump($row,true); }
-    elseif (is_scalar($row)) { echo($row.NB_EOL); }
-    //else { echo($row.NB_EOL); }
-    else{ echo var_export($row,true); }
-
-    return true;
-
-  }
-*/
-
   public function out2($rows,$head=array()) {
-    #if (is_scalar($head)) bye(var_dump($head,true));
-
-# NB 09.03.16     elseif (count($rows)) {
-# NB 09.03.16       $first = self::ar_first($row);
-# NB 09.03.16       #if (self::is_hash($first))
-# NB 09.03.16       $head = array($head);
-# NB 09.03.16     }
 
     out::rows($this->p('format',out::php_cli() ? 'csv' : 'table'),$rows,$head);
     return true;
@@ -503,12 +418,15 @@ EOF;
           foreach ($this->tables() as $t) { $rows[] = $t->infos(); }
           $return = $this->out2($rows);
 
+        } elseif ($action == 'db.conf') {
+          $return = $this->out2(array_values($this->conf));
+
         } elseif ($action == 'db.dbs' or $action == 'dbs') {
           if (self::p('hash')) $return = $this->out2($this->conf);
           else $return = $this->out2($this->dbs,"name");
 
-        } elseif (preg_match('/^db\.(\w+)/',$action,$m)) {
-          if ($rows = $this->$m[1]()) $return = $this->out2($rows,(is_scalar($rows) ? $m[1] : array()));
+        } elseif ($r=self::class_action_out($this,$action)) {
+          return $r;
 
         } elseif($table) {
           if ($r=$table->action($action)) $return = $r;
@@ -579,6 +497,7 @@ EOF;
     # Sort
 
     self::hksort($h,'order');
+    #uasort($h,create_function('$a,$b','$a_=isset($a["'.$k.'"])?$a["'.$k.'"]:-1;$b_=isset($b["'.$k.'"])?$b["'.$k.'"]:-1; return($b_-$a_);'));
     if (!$h) return false;
     #self::bye($h['puppetdb']);
     #if ($first !== false) debug ( self::ar_first($h) );
index b2b53d5e3e3071a6aefb0953592d326a0adc1116..ccb7198ef4900ea7feadfa3a3d60b9020b3e1926 100644 (file)
@@ -192,7 +192,8 @@ class field {
     # See: http://php.net/manual/en/pdostatement.bindparam.php
     if ($name === null) $name = ':'.$this->name;
 #debug($this->name . " | $name | $value | $this->type | " .  $this->size()."<br/>");
-    if (strpos($this->type,'float') !== false) {
+# NB 11.04.16     if (strpos($this->type,'float') !== false) {
+    if ($this->numeric() and strpos($this->type,'int') === false) {
       $value = strval($value);
       return $sth->bindParam($name, $value, PDO::PARAM_STR);
     }
index 1a75c10a00d145be5f4fa6aca69d3cf9f8654959..945291937113b78cc5ee7221f3106c64faedc4e6 100644 (file)
@@ -25,6 +25,7 @@ Class Table extends nb {
   public $replace = array(); # replace by javascript
   public $extras = array();
   public $row_parse_pre; # Function to call in rows()
+  public $row_parse_post; # Function to call in rows()
   public $count;
   public $engine;
   public $created;
@@ -615,6 +616,11 @@ Class Table extends nb {
     while ($row = $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT)) {
 
       $count++;
+      $call = null;
+
+      if (!empty($this->db()->row_parse)) {
+        $call = $this->db()->row_parse; $call($row);
+      }
 
       if (!empty($this->row_parse_pre)) {
         $call = $this->row_parse_pre; $call($row);
@@ -636,7 +642,7 @@ Class Table extends nb {
       if ($count === 1) {
         if ($opt['is_html']) echo $this->html_rows_top();
 
-        if (!empty($this->row_parse_pre) or !empty($this->row_parse_post)) {
+        if ($call) {
           foreach (array_keys($row) as $name) {
             if (!$this->fields($name)) {
               $this->fields[$name] = new Field($name);
@@ -1190,12 +1196,14 @@ Class Table extends nb {
       $this->out2($e);
       return true;
 
-    } elseif (preg_match('/^table\.(\w+)/',$action,$m)) {
-      if ($rows = $this->$m[1]() and !empty($rows)) {
-        $return = $this->out2($rows,(is_scalar($rows) ? $m[1] : array()));
-      } else {
-        $return = true;
-      }
+    } elseif ($r=self::class_action_out($this,$action)) {
+      return $r;
+# NB 10.04.16     } elseif (preg_match('/^table\.(\w+)/',$action,$m)) {
+# NB 10.04.16       if ($rows = $this->$m[1]() and !empty($rows)) {
+# NB 10.04.16         $return = $this->out2($rows,(is_scalar($rows) ? $m[1] : array()));
+# NB 10.04.16       } else {
+# NB 10.04.16         $return = true;
+# NB 10.04.16       }
 
     } elseif ($this->p('format') and !preg_match('/^(table|div)$/',$this->p('format'))) {
 
@@ -1287,6 +1295,7 @@ Class Table extends nb {
       'html'       => 'class="tables" name="table" id="table"',
       'selected'   => $this->p('table'),
       'prettyText' => true,
+      'sort' => 'natcasesort',
     ));
     $r .= '</span>';
 
@@ -1297,6 +1306,7 @@ Class Table extends nb {
         'html'       => 'class="dbs" id="db" name="db" onchange="document.location=\''.preg_replace('/\?.*$/','',$_SERVER['REQUEST_URI']).'?db=\'+this.value"',
         'selected'   => self::p('db'),
         'prettyText' => true,
+        'sort' => 'natcasesort',
       ));
       $r .= '</span>';
     }
@@ -1311,6 +1321,7 @@ Class Table extends nb {
       'html'       => 'class="format" name="format" id="format"',
       'selected'   => $this->p('format'),
       'prettyText' => true,
+      'sort' => 'natcasesort',
     ));
     $r .= '</span>';
 
index 727b8ba99878aa5f009ec3b57e20c65782fb9cbe..80718d2859a207de1cb507b04b4889ba56ddc6fb 100644 (file)
@@ -228,6 +228,11 @@ function html_select_array($data,$opt=array()) {
     $html .= '</option>'.NB_EOL;
   }
 
+  if (!empty($opt['sort'])) {
+    if (is_bool($opt['sort'] )) natcasesort($data);
+    else $opt['sort']($data);
+  }
+
   foreach ($data as $d) {
 
     if (is_array($d)) {
index 49baa7b74f3ebcaf4aeb71b8bae30317dd5683ae..a938b34a4d8942d22f8e9830204b36c2ff3d0e77 100644 (file)
@@ -479,6 +479,22 @@ class NB {
       'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', 'Ā' => 'A', 'ā' => 'a', 'Ă' => 'A', 'ă' => 'a', 'Ą' => 'A', 'ą' => 'a', 'Ç' => 'C', 'ç' => 'c', 'Ć' => 'C', 'ć' => 'c', 'Ĉ' => 'C', 'ĉ' => 'c', 'Ċ' => 'C', 'ċ' => 'c', 'Č' => 'C', 'č' => 'c', 'Ð' => 'D', 'ð' => 'd', 'Ď' => 'D', 'ď' => 'd', 'Đ' => 'D', 'đ' => 'd', 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'Ē' => 'E', 'ē' => 'e', 'Ĕ' => 'E', 'ĕ' => 'e', 'Ė' => 'E', 'ė' => 'e', 'Ę' => 'E', 'ę' => 'e', 'Ě' => 'E', 'ě' => 'e', 'Ĝ' => 'G', 'ĝ' => 'g', 'Ğ' => 'G', 'ğ' => 'g', 'Ġ' => 'G', 'ġ' => 'g', 'Ģ' => 'G', 'ģ' => 'g', 'Ĥ' => 'H', 'ĥ' => 'h', 'Ħ' => 'H', 'ħ' => 'h', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'Ĩ' => 'I', 'ĩ' => 'i', 'Ī' => 'I', 'ī' => 'i', 'Ĭ' => 'I', 'ĭ' => 'i', 'Į' => 'I', 'į' => 'i', 'İ' => 'I', 'ı' => 'i', 'Ĵ' => 'J', 'ĵ' => 'j', 'Ķ' => 'K', 'ķ' => 'k', 'ĸ' => 'k', 'Ĺ' => 'L', 'ĺ' => 'l', 'Ļ' => 'L', 'ļ' => 'l', 'Ľ' => 'L', 'ľ' => 'l', 'Ŀ' => 'L', 'ŀ' => 'l', 'Ł' => 'L', 'ł' => 'l', 'Ñ' => 'N', 'ñ' => 'n', 'Ń' => 'N', 'ń' => 'n', 'Ņ' => 'N', 'ņ' => 'n', 'Ň' => 'N', 'ň' => 'n', 'ʼn' => 'n', 'Ŋ' => 'N', 'ŋ' => 'n', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ø' => 'O', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ø' => 'o', 'Ō' => 'O', 'ō' => 'o', 'Ŏ' => 'O', 'ŏ' => 'o', 'Ő' => 'O', 'ő' => 'o', 'Ŕ' => 'R', 'ŕ' => 'r', 'Ŗ' => 'R', 'ŗ' => 'r', 'Ř' => 'R', 'ř' => 'r', 'Ś' => 'S', 'ś' => 's', 'Ŝ' => 'S', 'ŝ' => 's', 'Ş' => 'S', 'ş' => 's', 'Š' => 'S', 'š' => 's', 'ſ' => 's', 'Ţ' => 'T', 'ţ' => 't', 'Ť' => 'T', 'ť' => 't', 'Ŧ' => 'T', 'ŧ' => 't', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 'Ũ' => 'U', 'ũ' => 'u', 'Ū' => 'U', 'ū' => 'u', 'Ŭ' => 'U', 'ŭ' => 'u', 'Ů' => 'U', 'ů' => 'u', 'Ű' => 'U', 'ű' => 'u', 'Ų' => 'U', 'ų' => 'u', 'Ŵ' => 'W', 'ŵ' => 'w', 'Ý' => 'Y', 'ý' => 'y', 'ÿ' => 'y', 'Ŷ' => 'Y', 'ŷ' => 'y', 'Ÿ' => 'Y', 'Ź' => 'Z', 'ź' => 'z', 'Ż' => 'Z', 'ż' => 'z', 'Ž' => 'Z', 'ž' => 'z'
     ));
   }
+
+  public static function class_action_out($class,$action) {
+    $class_name = strtolower(get_class($class));
+
+    if (!preg_match('/^'.$class_name.'\.(\w+)/',$action,$m)) return false;
+    $name = $m[1];
+
+    $rows = array();
+    if (in_array($name,get_class_methods($class))) $rows = $class->$name();
+    else $rows = $class->$name;
+    if (!$rows) return false;
+
+    return out::rows(self::p('format',self::php_cli() ? 'csv' : 'table'),$rows,(is_scalar($rows) ? $name : array()));
+    return self::object2array($rows);
+    return $class->out2(self::object2array($rows),(is_scalar($rows) ? $name : array()));
+  }
 } # < Class
 #die(self::ext2mime('csv'));
 ?>
index 260a1600cacb35069801c56f36188de854f9335a..e04890235944a89719b9e1442254eb2969df3c9f 100644 (file)
@@ -13,13 +13,22 @@ Class Out extends Nb {
       #'php' => array( 'function' => function(&$r) {var_dump($r);},),
       'php' => array(
         #'enclose' => array('$VAR=array(',');'),
-        'enclose' => array('$CONF = ',';'),
-        #'eol' => NB_EOL,
+        'enclose' => array('$CONF = array('.NB_EOL,NB_EOL.');'),
+        'eol' => NB_EOL,
         'rec' => ',',
         #'function' => function(&$r) { echo preg_replace('/[\r\n]/','',var_dump($r,true));},
         #'function' => function(&$r) {print_r($r);}
         #'function' => function(&$r) {var_dump($r);}
-        'function' => function(&$r) { echo preg_replace('/(=>\s*)\n\s+/m','\1',var_export($r,true));}
+        'function' => function(&$r) {
+          return var_export($r);
+          echo preg_replace(array(
+            '/(=>\s*)\n\s+/m',
+            '/\),\s*array/m',
+          ),array(
+            '\1',
+            "),".NB_EOL."array"
+          ),var_export($r,true));
+        }
         #'function' => function(&$r) { echo preg_replace('/\n/','',var_export($r,true));}
         #'function' => function(&$r) {var_export($r);}
       ),
@@ -194,10 +203,11 @@ Class Out extends Nb {
     foreach ($row as $k => $v) {
       echo sprintf("%"
         .(!empty($o['head_max_len']) ? '-'.($o['head_max_len']+1) : '')
-        ."s: %s\n",$k,self::escape($v)
+        ."s: %s\n",$k,preg_replace('/\n(\w)/m'
+          ,"\n".str_repeat(' ',(empty($o['head_max_len']) ? strlen($k) : $o['head_max_len']+1)+2).'\1'
+        ,self::format($v))
       );
     }
-    #foreach ($row as $k => $v) { echo "$k: ".self::escape($v)."\n"; }
 
     return true;
   }
@@ -281,7 +291,8 @@ Class Out extends Nb {
     return;
   }
 
-  public static function format($v) {
+  public static function format($v,$type=null) {
+    if ($type === null) $type = self::$type;
     $is_scalar = is_scalar($v);
     $v = self::scalar($v);
     if ($v==='') $is_scalar = true;
@@ -403,7 +414,7 @@ function out_tag(&$row,&$o) {
 
   foreach ($row as $k => $v) {
 
-    $v = out::escape($v);
+    $v = out::format($v);
 
     # Inside tag, ex: label
     if (isset($o['tag_key'])) {
index e839c980de31648ca1c31480e78e5d72b81b1523..5c2c4a88df5fdba082a58e0f303936fc88ef4051 100644 (file)
@@ -26,6 +26,7 @@ class Page extends nb {
   public static $charset = 'utf-8';
   public static $lang = 'en';
   public static $html5 = true;
+  public static $expires; # Seconds to cache, no cache if 0, no head if null
 
   public $title = '';
   public $css = array();
@@ -158,6 +159,10 @@ class Page extends nb {
     return htmlspecialchars($v,$replace_flags,$charset);
   }
 
+  /*
+   * Function: tag
+   * Return html code for a tag
+   */
   public static function tag($tag,$content='',$attrs='') {
     
     # Extract attrs from tag
@@ -166,6 +171,13 @@ class Page extends nb {
       $attrs = trim($attrs.' '.$m[2]);
     }
 
+    if (is_array($attrs)) {
+      $attrs = array_map(function($k,$v){return "$k=\"$v\"";}
+        ,array_keys($attrs)
+        ,array_values($attrs)
+      );
+    }
+
     if ($content===null) {
       self::tag_end($tag);
       return '<' . $tag . ($attrs ? " $attrs" : "") . '>';
@@ -295,6 +307,7 @@ class Page extends nb {
   }
 
   public static function headers_cache($seconds_to_cache=3600) {
+    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");
     header("Pragma: cache");
@@ -306,6 +319,8 @@ class Page extends nb {
     #header('Content-type: ' . self::$content_type);
                header('Content-type: '.self::$content_type . (($c = strtoupper ( self::$charset )) ? "; charset=$c" : ""));
 
+    if (isset($this->expires)) self::headers_cache($this->expires);
+
     if (self::p('download-attachment')) header('Content-Disposition: attachment; filename="'
       . $this->title2filename($this->title,self::$content_type)
     );
@@ -438,11 +453,19 @@ class Page extends nb {
       }
 
       if (is_array($v)) {
-        $nav[] = '<a href="'.$v[1].'">'.$v[0].'</a>';
-        $title[] = $v[0];
+
+        if (count($v)==3) {
+          $title[] = $v[0];
+          $nav[] = self::tag('a',$v[1],'href="'.$v[2].'"');
+        } else {
+          $title[] = $v[0];
+          $nav[] = self::tag('a',$v[0],'href="'.$v[1].'"');
+        }
+
       } else {
-        $nav[] = '<span>'.$v.'</span>';
         $title[] = $v;
+        $nav[] = self::tag('span',$v);
+
       }
 
     }
@@ -509,9 +532,8 @@ class Page extends nb {
     } elseif ($action == 'page.phpinfo' or $action == 'phpinfo') {
       echo $this->phpinfo(); return true;
 
-    } elseif (preg_match('/^page\.(\w+)/',$action,$m)) {
-#bye($this->$m[1]());
-      if ($rows = $this->$m[1]()) return $this->out2($rows,(is_scalar($rows) ? $m[1] : array()));
+    } elseif ($r=self::class_action_out($this,$action)) {
+      return $r;
 
     }