]> git.nbdom.net Git - nb.git/commitdiff
bdq
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 29 Nov 2016 00:27:16 +0000 (00:27 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 29 Nov 2016 00:27:16 +0000 (00:27 +0000)
lib/php/db/page.php
lib/php/functions.php
lib/php/nb.php
lib/php/page.php
src/Docker/Compose/dbq/docker-compose.yaml

index 6f2056d27df5f3b7d4244594528bb87b472e7d06..bb098f5b0aebce24710385e90a9e9d2c9e7a9b5b 100644 (file)
@@ -24,6 +24,9 @@ if (!empty($_SERVER['DOCUMENT_ROOT'])) {
   #debug([$js,$css]);
 }
 
+function auto_doc_root() {
+}
+
 $Page = new Page([
   'title' => ($Db->title ? $Db->title : Db::prettyText($Db->name)),
   'css' => $css,
index 62cef74b8a520905af12a05329a9620660e89712..2c5d8f4b67095bb34f7a65d5f6a4fd32dabe0314 100644 (file)
@@ -52,6 +52,7 @@ function ar_map($return,$array,$as_hash=false) {
 }
 
 function txt2md($txt) {
+# NB 28.11.16: TODO rename as nb::md2html 
   global $_txt2md;
   if ($_txt2md === null) {
     require_once(dirname(__FILE__).'/parsedown/Parsedown.php');
index 82ce3a518e1b8fc9848fcf322e7ee84e42cc9646..0c275cca43e7500345fcd83fb701a3ba5c6e6b6b 100644 (file)
@@ -16,6 +16,7 @@ class NB {
   # Sql: elect type,ext from mime_type where ext in ('json','csv','txt','yaml','xml','html','doc','xls');
   protected static $content_types_aliases = array(
     'text' => 'txt',
+    'human' => 'txt',
   );
 
   protected static $content_types = array(
@@ -802,6 +803,10 @@ class NB {
     return $rows;
   }
 
+  public static function strlen($v,$encoding='UTF-8') {
+    return mb_strlen($v,$encoding);
+  }
+
   public static function mb_str_pad($input, $pad_length, $pad_string=' ', $pad_type=STR_PAD_RIGHT,$encoding='UTF-8'){
     $mb_diff=mb_strlen($input, $encoding)-strlen($input);
     return str_pad($input,$pad_length-$mb_diff,$pad_string,$pad_type);
index 59bda74bb05627df6db5ae25362d0d8368b4a45e..5e756cec9a01e6b1fc93dc3c5e0076384613bbf4 100644 (file)
@@ -47,16 +47,15 @@ class Page extends nb {
   */
   public function __construct($opt = []) {
 
-    // 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']);
     if (!$this->content_type()) $this->content_type($this->client_content_type());
 
+    // Nav
+    if (isset($opt['nav'])) list($title,$nav) = self::nav_parse($opt['nav']);
+    unset($opt['nav']);
+
     // Statics
     foreach ([
       'charset',
@@ -74,7 +73,9 @@ class Page extends nb {
     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;
 
-    // Call
+    // Call / Print
+
+    // Nav
     foreach ((array)($this->call) as $call) {
 
       if (is_scalar($call)) {
@@ -197,7 +198,30 @@ class Page extends nb {
       );
     }
 
-    if (!$is_html) return join("\n",(array)$content);
+    # NB 28.11.16: Proper Markdown yould be great  !
+    #if (!$is_html) return (preg_match('/^(span|a|inline|label|input|select)$/',strtolower($tag))?"":"\n").join("\n",(array)$content);
+    // Markdonw to html
+    if (!$is_html) return join("\n",array_map(function($e) use($tag){
+
+      if (preg_match('/^(li|dd)$/',$tag)) {
+        $e = "- $e";
+      } elseif ($tag == 'h1') {
+        $e .= str_pad("\n",mb_strlen($e,self::$charset)+1,'=');
+      } elseif ($tag == 'h2') {
+        $e .= str_pad("\n",mb_strlen($e,self::$charset)+1,'-');
+      } elseif ($tag == 'code') {
+        $e = "```\n$e\n```\n";
+      } elseif ($tag == 'a') {
+        $e = "[$e]\n";
+      }
+
+      return ''
+        .(preg_match('/^(p|div)$/',$tag)?"\n":'')
+        .$e
+        .(preg_match('/^(p|div)$/',$tag)?"\n":'')
+      ;
+
+    },(array)$content));
 
     if ($content===null) {
       self::tag_end($tag);
@@ -365,12 +389,15 @@ class Page extends nb {
 
     if (preg_match('/tml$/',self::$content_type)) {
 
+      // META
       if (self::$charset) $head .= '<meta http-equiv="Content-Type" content="text/html; charset='.self::$charset.'" />'.NB_EOL;
-
       $head .= '<meta name="viewport" content="width=device-width, initial-scale=1" />'.NB_EOL;
 
-      foreach ((array)($this->css) as $v) {
-        $head .= '<link type="text/css" rel="stylesheet" href="' . $v . '" />'.NB_EOL;
+      // CSS
+      foreach ((array)($this->css) as $vv) {
+        foreach ($this->path2url($vv) as $v) {
+          $head .= '<link type="text/css" rel="stylesheet" href="' . $v . '" />'.NB_EOL;
+        }
       }
 
       if ($this->css_code) $head .=  ''
@@ -379,9 +406,13 @@ class Page extends nb {
         . ' --></style>' . NB_EOL
       ;
 
-      foreach ((array)($this->js) as $v) {
-        $head .= '<script src="' . $v . '" type="text/javascript"></script>' . NB_EOL;
+      // JS
+      foreach ((array)($this->js) as $vv) {
+        foreach ($this->path2url($vv) as $v) {
+          $head .= '<script src="' . $v . '" type="text/javascript"></script>' . NB_EOL;
+        }
       }
+
       if ($this->js_code) $head .=  ''
         . '<script type="text/javascript"><!-- ' . NB_EOL
         . trim($this->js_code)."\n"
@@ -400,6 +431,26 @@ class Page extends nb {
     return $head;
   }
 
+  public static function path2url($paths) {
+    #$_SERVER['DOCUMENT_ROOT'] = '/opt/rent/www';
+    $urls = [];
+    foreach ((array)$paths as $p) {
+
+      if (preg_match('/[\*\?]/',$p)) {
+        foreach (glob($_SERVER['DOCUMENT_ROOT'].$p) as $pp) {
+          $urls[] = substr($pp, strlen($_SERVER['DOCUMENT_ROOT']));
+        }
+
+      } else {
+        $urls[] = $p;
+
+      }
+
+    }
+    #debug($urls);
+    return $urls;
+  }
+
   public static function is($is) {
     if ($is == 'xhtml') return preg_match('/xhtml$/',self::$content_type);
     if ($is == 'html') return preg_match('/html$/',self::$content_type);
@@ -517,6 +568,7 @@ class Page extends nb {
   }
 
   public static function content_type($set=null){
+    #if ($set) bye($set);
     if ($set) return (self::$content_type = $set);
     return self::$content_type;
   }
@@ -534,6 +586,7 @@ class Page extends nb {
     if (!$content_type and $format) $content_type = self::ext2mime($format);
     if (!$content_type and !$format and self::php_cli()) $content_type = 'text/plain';
     if (!$content_type) $content_type = self::content_type();
+    #debug([$content_type,self::content_type()]);
     return $content_type;
   }
 
index c76256fbce9993dd37e92b264fed8191667360fe..c9af50544b819713ec1e56637ec2bd411a83aa24 100644 (file)
@@ -19,6 +19,6 @@ nginx:
   volumes_from:
     - php
   ports:
-    - 80:80
+    - "8080:80"
   links:
     - php