]> git.nbdom.net Git - nb.git/commitdiff
Bed
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 7 Sep 2016 01:12:38 +0000 (02:12 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 7 Sep 2016 01:12:38 +0000 (02:12 +0100)
etc/profile.d/aliases
lib/php/db/index.php
lib/php/db/table.php
lib/php/nb.php
lib/php/out.php
lib/php/page.php

index 77f5856dcfd38c41933f59d27968ac1f91a1c6d9..94912f1c734f2318daaab9da4bd8f652d291d0e4 100644 (file)
@@ -18,6 +18,7 @@ alias nmap-ping="nmap -sP -PE -PS443 -PA21,22,23,80,3389"
 alias arp-list="arp -an"
 alias pdf2jpegs='gs -dNOPAUSE -sDEVICE=jpeg -dFirstPage=1 -dLastPage=5 -sOutputFile=pdf2jpegs%d.jpg -dJPEGQ=100 -r500 -c quit'
 alias nb-maildir-make="maildirmake -S Maildir; for d in Spam Trash Sent;do maildirmake -f $d Maildir; done"
+alias grep='grep --color=auto'
 
 #[ "$UID" = "0" ] && grep -q '^_\?postgres:' /etc/passwd && alias psql='sudo -u postgres psql'
 
index 02656a599a9f78f48e961ec76c8a24fb974eed83..b6656f48fbe03b2c2b3d36cb022b65669b4135b6 100755 (executable)
@@ -20,5 +20,9 @@ if(defined('DB_NO_INIT') and DB_NO_INIT) return true;
 Db::init([Db::ROOT_DIR.'/etc/dbs.yaml',Db::ROOT_DIR.'/etc/dbs.php','/etc/dbs.yaml']);
 
 if(defined('DB_NO_ACTION') and DB_NO_ACTION) return true;
+
+# Happend when include from a function
+if (!isset($Db)) global $Db, $Table;
+
 return $Db->action($Db->p('action'),$Table);
 ?>
index 30b4ef044ca7a277820003a762a8f4e24a65238d..5e87274b3a4c0ca5084cf810a29bdf41d75f66ac 100644 (file)
@@ -1473,7 +1473,10 @@ Class Table extends nb {
   public function html_row_buttons(&$row) {
     return array(
       '<a class="edit button" href="'.$this->url_keys($row,'action=edit').'">'.DB_HTML_EDIT.'</a>'.NB_EOL,
-      '<a class="delete button" href="'.$this->url_keys($row,'action=delete').'&amp;referer='.urlencode($_SERVER['REQUEST_URI']).'">'.DB_HTML_DELETE.'</a>'.NB_EOL,
+      '<a class="delete button" href="'.$this->url_keys($row,'action=delete')
+        .'&amp;referer='
+        .( isset($_SERVER['REQUEST_URI']) ? urlencode($_SERVER['REQUEST_URI']) : '' )
+      .'">'.DB_HTML_DELETE.'</a>'.NB_EOL,
     );
   }
 
index 7e0e8457aab528c431d38952ca4b8aa2bc808a15..4d8c83c28a00b06ce929efd1e26b635b59a76bfd 100644 (file)
@@ -33,10 +33,20 @@ class NB {
   #public static function zaza() { return (is_object($this) ? 'TRUE' : 'FALSE'); }
   #public static function test() { return 'TEST'; }
   public function __construct($opt = array()) {
+
+    # Deep merge of vars
     foreach ($opt as $k => $v) {
       if ( ! array_key_exists($k,$this) ) self::bye("Unknow param $k = `$v`");
-      $this->$k = is_array($v) ? $v : trim($v);
+
+      if ($v === null) continue;
+
+      if (is_array($this->$k)) {
+        $this->$k = array_merge_recursive((array)$this->$k, is_array($v) ? $v : [$v]);
+      } else {
+        $this->$k = $v;
+      }
     }
+
   }
 
   public function __sleep() {
@@ -100,6 +110,7 @@ class NB {
    * Set a value for param, delete it if null
    */
   public static function bye($msg='',$backtrace_deep=0) {
+    #throw new Exception($msg);
     return bye($msg,$backtrace_deep+1);
   }
 
index 88bece4d285019d630502b2e99516bf98281f8c3..2e1462007b92684a493c46461f9f19ef1bffc23a 100644 (file)
@@ -565,7 +565,7 @@ function out_human_end(&$o) {
   if (!$count) return;
 
   echo $sep_line;
-  echo "$count Records\n";
+  if ($header) echo "$count Records\n";
 
 }
 # < Functions
index 9f97b7ee436a23b5f942c999187c02cce4f0fc54..f2038b666f2b5575c05b1a1f533177cc5f32c4a9 100644 (file)
@@ -9,7 +9,7 @@ $Page = new Page(array(
   #'title' => 'Test',
   'call' => array(
     'begin',
-    array('out', 'Hello World !!!'),
+    ['out', 'Hello World !!!'],
     #array('out', print_r($_SERVER,true)),
     'end',
   ),
@@ -19,7 +19,7 @@ $Page = new Page(array(
 
 class Page extends nb {
 
-  public $call = array();
+  public $call = [];
 # NB 04.08.15 wtf ??? public $output;
 
   protected static $content_type = 'text/html';
@@ -29,44 +29,54 @@ class Page extends nb {
   public static $expires; # Seconds to cache, no cache if 0, no head if null
 
   public $title = '';
-  public $css = array();
-  public $head = array();
+  public $css = [];
+  public $head = [];
   public $css_code = '';
 
-  public $js = array();
+  public $js = [];
   public $js_code = '';
 
   public $body_class = '';
   public $body_id = '';
 
   public $h1 = '';
+  public $sep = ' / ';
 
   /*
-    Create
+    New
   */
-  public function __construct($opt = array()) {
+  public function __construct($opt = []) {
 
-    //// opt
-    foreach ($opt as $k => $v) {
-      if ( ! array_key_exists($k,$this) ) die ("Page->new(): unknow param $k = $v");
-      $this->$k = is_array($v) ? $v : trim($v);
-    }
+    // Nav
+    if (isset($opt['nav'])) list($title,$nav) = Page::nav_parse($opt['nav']);
+    unset($opt['nav']);
+
+    // Content-type
+    if (isset($opt['content_type'])) $this->content_type($opt['content_type']);
+    elseif($this->php_cli()) $this->content_type('text/html');
+    unset($opt['content_type']);
+
+    // Opt
+    parent::__construct($opt);
     
     // Defaults
-    if ( empty($this->title) ) $this->title = $this->filename2title();
+    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;
 
-    //// Default
-    #print_r($this);
+    // Call
+    foreach ($this->to_array($this->call) as $call) {
 
-    //// Call
-    foreach ($this->to_array($this->call) as $v) {
+      if (is_scalar($call)) {
+        $this->$call();
 
-      if ( is_array($v) ) {
-        $k = $v[0]; $v = $v[1];
-        $this->$k($v);
+      } elseif ( is_array($call) ) {
+        $k = $call[0];
+        $this->$k($call[1]);
+
+      } elseif (is_callable($call)) {
+        $call($this);
 
       } else {
-        $this->$v();
 
       }
 
@@ -82,7 +92,7 @@ class Page extends nb {
   }
 
   public static function to_array($v) {
-    return (is_array($v) ? $v : array($v));
+    return (is_array($v) ? $v : [$v]);
   }
 
   public static function title2filename($title,$content_type='') {
@@ -183,8 +193,8 @@ class Page extends nb {
       return '<' . $tag . ($attrs ? " $attrs" : "") . '>';
     }
 
-    if (!is_array($content)) $content = array($content);
-    $tags = array();
+    if (!is_array($content)) $content = [$content];
+    $tags = [];
 
     foreach ($content as $c) {
 
@@ -264,10 +274,10 @@ class Page extends nb {
   }
 
   public static function tag_end($tag=null) {
-    static $tags = array();
+    static $tags = [];
     if ($tag !== null) return array_unshift($tags,$tag);
     foreach ($tags as $t) echo "</$t>".NB_EOL;
-    $tags = array();
+    $tags = [];
     return $tags;
     return join('',self::ar_map('',$tags));
     if ($tag === null) return $tags;
@@ -405,49 +415,13 @@ class Page extends nb {
     return preg_replace('/\?.*$/','',$_SERVER['REQUEST_URI']);
   }
 
-  /**
-  * @copyright (C) 2016 Nicolas Boisselier
-  * @author Nicolas Boisselier nicolas.boisselier@gmail.com
-  * Does what the name says
-  *
-  * @param datatype1|datatype2 \$paramname description
-  * @return datatype1|datatype2 description
-  */
-  public static function init($param) {
-    global $Page;
-    if (isset($Page)) self::bye("Page.init(): GLOBALS['Page'] already exists !");
-    if (!self::is_hash($param)) $param = array('nav' => $param);
-
-    $Page = new self(array(
-
-    #  'head' => array(
-    #    '<meta name="viewport" content="initial-scale=1, maximum-scale=1" />',
-    #  ),
-      'body_class' => 'db',
-
-      'css' => false ? array() : array(
-        #'/jquery/jquery.mobile.css',
-        #'/jquery/jquery-ui.css',
-        '/css/reset.css',
-        '/css/block.css',
-        '/css/button.css',
-        '/css/db.css',
-      ),
-
-      'js' => array(
-        '/jquery/jquery.js',
-        '/jquery/jquery-ui.js',
-        #'/jquery/jquery.mobile.js',
-        '/js/nb.js',
-      ),
-
-    ));
-    if (isset($param['js'])) foreach ($param['js'] as $v) { $Page->js[] = $v; }
-    if (isset($param['css'])) foreach ($param['css'] as $v) { $Page->css[] = $v; }
-
-    $title = $nav = array();
-
-    if (isset($param['nav'])) foreach ($param['nav'] as $k => $v) {
+  public static function files_concat($files) {
+    
+  }
+
+  public static function nav_parse($array) {
+    #$v = &$sep;
+    foreach ($array as $k => $v) {
       if ($v === '' or $v === null or empty($v[0])) {
         continue;
       }
@@ -456,10 +430,10 @@ class Page extends nb {
 
         if (count($v)==3) {
           $title[] = $v[0];
-          $nav[] = self::tag('a',$v[1],'href="'.$v[2].'"');
+          $nav[] = empty($v[2]) ? $v[1] : self::tag('a',$v[1],'href="'.$v[2].'"');
         } else {
           $title[] = $v[0];
-          $nav[] = self::tag('a',$v[0],'href="'.$v[1].'"');
+          $nav[] = empty($v[1]) ? $v[0] : self::tag('a',$v[0],'href="'.$v[1].'"');
         }
 
       } else {
@@ -469,16 +443,14 @@ class Page extends nb {
       }
 
     }
-
-    #debug(array($nav,$title)); return;
-    $Page->h1 = join(' / ',$nav);
-
-    $Page->title = join(' / ',$title);
-
-    return $Page;
+    return [$title,$nav];
+    return [
+      'title' => $title,
+      'title' => $title,
+    ];
   }
 
-  public function phpinfo() {
+  public static function phpinfo() {
     ob_start();
     phpinfo(INFO_ALL - INFO_LICENSE);
     $phpinfo = ob_get_contents();
@@ -506,7 +478,7 @@ class Page extends nb {
 
   public function infos() {
     $out = array(
-      'path' => $this->path()
+      'path' => self::path()
     );
     foreach (get_class_vars(get_class($this)) as $k=>$v) {
       if (!empty($this->$k)) $out[$k] = is_scalar($this->$k) ? $this->$k : out::scalar($this->$k);
@@ -515,7 +487,7 @@ class Page extends nb {
     #foreach ($_SERVER as $k=>$v) $out['_SERVER.'.$k] = $v;
     #foreach ($_ENV as $k=>$v) $out['_ENV.'.$k] = $v;
 
-    $out = array_map(function($k, $v) { return array("name"=>$k,"value"=>$v); },array_keys($out),$out);
+    $out = array_map(function($k, $v) { return ["name"=>$k,"value"=>$v]; },array_keys($out),$out);
     return $out;
   }
 
@@ -525,12 +497,12 @@ class Page extends nb {
     $is_html = out::is_html($format);
 
     if ($action == 'page.infos') {
-      $out = $this->infos();
+      $out = self::infos();
       out::rows($format,$out);
       return true;
 
     } elseif ($action == 'page.phpinfo' or $action == 'phpinfo') {
-      echo $this->phpinfo(); return true;
+      echo self::phpinfo(); return true;
 
     } elseif ($r=self::class_action_out($this,$action)) {
       return $r;