]> git.nbdom.net Git - nb.git/commitdiff
etc/profile.d/nb.sh
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Fri, 19 Jan 2018 04:17:52 +0000 (04:17 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Fri, 19 Jan 2018 04:17:52 +0000 (04:17 +0000)
etc/profile.d/nb.sh
lib/php/db.php
lib/php/nb.php
lib/php/page.php

index 91c44fa07473f1759aa428062faba37127e4ac81..e486f2a734f0e35723fdabd49f8488d801b1adf5 100644 (file)
@@ -87,7 +87,7 @@ nb_api() {
                curl -su "$NB_AUTH" "https://api.nbdom.net$uri" "$@"
        else
                #curl -su "$NB_AUTH" "https://api.nbdom.net$uri" "$@"
-               curl --netrc-optional "https://api.nbdom.net$uri" "$@"
+               curl -s --netrc-optional "https://api.nbdom.net$uri" "$@"
        fi
 }
 
index ee5c71c0db8073af228d69643b7274f507d6f463..991abbff4c95c20aba4655a36bf2afb8ae4b733d 100644 (file)
@@ -10,6 +10,7 @@ require_once(realpath(dirname(__FILE__).'/nb.php'));
 require_once(NB_ROOT.'/lib/php/out.php');
 require_once(NB_ROOT.'/lib/php/db/table.php');
 require_once(NB_ROOT.'/lib/php/db/field.php');
+require_once(NB_ROOT.'/lib/php/mime.php');
 $DB_TYPES = []; # See db/types/*.php
 #$arr = ['rent'=>'Rent','nb'=>'Nb'];
 #if (!empty($argv) and $argv[1] == 'zaza') bye($arr);
@@ -522,7 +523,7 @@ class Db extends nb {
 
     if ($value!==null) return header("$format: $value");
 
-    if (!$mime=self::ext2mime($format)) return false;
+    if (!$mime=mime::get($format)) return false;
     header('Content-type: '.$mime);
 
     return $mime;
@@ -1312,7 +1313,7 @@ class Db extends nb {
 
   public static function content_type2format($content_type=null) {
     if (empty($content_type)) $content_type = self::client_content_type();
-    switch (self::mime2ext($content_type)) {
+    switch (mime::ext($content_type)) {
       case "html":
         return 'table';
       case "txt":
index 96d25a6b07ec40523ba372cb5ea038b068120008..32f402c9563bc5cc882ecdcabb2a877c2ab291bd 100644 (file)
@@ -7,7 +7,6 @@ if (!defined('NB_EOL')) define('NB_EOL',(defined('NB_PROD') and NB_PROD) ? '' :
 if (!defined('NB_P_GET')) define('NB_P_GET',true);
 
 require_once(NB_ROOT.'/lib/php/functions.php');
-require_once(NB_ROOT.'/lib/php/mime.php');
 
 if (class_exists('NB')) return; # protect against double include
 class NB {
@@ -25,17 +24,17 @@ class NB {
        );
 
        # NB 19.01.18: TODEL 
-       protected static $content_types = array(
-               'json' => 'text/json',
-               'doc'  => 'application/msword',
-               'xls'  => 'application/vnd.ms-excel',
-               'xml'  => 'application/xml',
-               'txt'  => 'text/plain',
-               'csv'  => 'text/csv',
-               'html' => 'text/html',
-               'yaml' => 'text/yaml',
-               'php'  => 'text/x-php',
-       );
+# NB 19.01.18  protected static $content_types = array(
+# NB 19.01.18          'json' => 'text/json',
+# NB 19.01.18          'doc'  => 'application/msword',
+# NB 19.01.18          'xls'  => 'application/vnd.ms-excel',
+# NB 19.01.18          'xml'  => 'application/xml',
+# NB 19.01.18          'txt'  => 'text/plain',
+# NB 19.01.18          'csv'  => 'text/csv',
+# NB 19.01.18          'html' => 'text/html',
+# NB 19.01.18          'yaml' => 'text/yaml',
+# NB 19.01.18          'php'  => 'text/x-php',
+# NB 19.01.18  );
 
        #public static function zaza() { return (is_object($this) ? 'TRUE' : 'FALSE'); }
        #public static function test() { return 'TEST'; }
@@ -229,46 +228,46 @@ class NB {
         * Function: prettyText
         * Does what it says
         */
-       # NB 19.01.18: TODEL 
        public static function prettyText($text) {
                return prettyText($text);
        }
 
-       # NB 19.01.18: TODEL 
-       public static function mime2ext($mime) {
-               return Mime::ext($mime);
-
-               static $aliases = null;
-               if ($aliases === null) $aliases = array_combine(
-                       array_values(self::$content_types_aliases),
-                       array_keys(self::$content_types_aliases)
-               );
-
-               foreach (self::$content_types as $e => $c) {
-                       if ($mime == $c) return $e;
-               }
-
-               // Aliases
-               if (isset($aliases[$mime])) return self::ext2mime($aliases[$mime]);
-
-       }
+# NB 19.01.18  public static function mime2ext($mime) {
+# NB 19.01.18          require_once(NB_ROOT.'/lib/php/mime.php');
+# NB 19.01.18          return Mime::ext($mime);
+# NB 19.01.18 
+# NB 19.01.18          static $aliases = null;
+# NB 19.01.18          if ($aliases === null) $aliases = array_combine(
+# NB 19.01.18                  array_values(self::$content_types_aliases),
+# NB 19.01.18                  array_keys(self::$content_types_aliases)
+# NB 19.01.18          );
+# NB 19.01.18 
+# NB 19.01.18          foreach (self::$content_types as $e => $c) {
+# NB 19.01.18                  if ($mime == $c) return $e;
+# NB 19.01.18          }
+# NB 19.01.18 
+# NB 19.01.18          // Aliases
+# NB 19.01.18          if (isset($aliases[$mime])) return self::ext2mime($aliases[$mime]);
+# NB 19.01.18 
+# NB 19.01.18  }
 
        /*
         * Function: ext2mime
         * Does what it says
         */
        #public static function ext2content_type($ext) { return self::ext2mime($ext); }
-       public static function ext2mime($ext) {
-               return Mime::get($ext);
-
-               foreach (self::$content_types as $e => $c) {
-                       if ($ext == $e) return $c;
-               }
-
-               // Aliases
-               if (isset(self::$content_types_aliases[$ext])) return self::ext2mime(self::$content_types_aliases[$ext]);
-
-       }
+# NB 19.01.18  public static function ext2mime($ext) {
+# NB 19.01.18          require_once(NB_ROOT.'/lib/php/mime.php');
+# NB 19.01.18          return Mime::get($ext);
+# NB 19.01.18 
+# NB 19.01.18          foreach (self::$content_types as $e => $c) {
+# NB 19.01.18                  if ($ext == $e) return $c;
+# NB 19.01.18          }
+# NB 19.01.18 
+# NB 19.01.18          // Aliases
+# NB 19.01.18          if (isset(self::$content_types_aliases[$ext])) return self::ext2mime(self::$content_types_aliases[$ext]);
+# NB 19.01.18 
+# NB 19.01.18  }
 
        /*
         * Function: ar_first
index 253718b2e1cb995b2732e6b72a1348a6957e22b9..23e9d789bab53bd762bcdade17ff6815ecff2ba7 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 require_once(realpath(dirname(__FILE__)).'/nb.php');
 require_once(NB_ROOT.'/lib/php/out.php');
+require_once(NB_ROOT.'/lib/php/mime.php');
 /*
 if (
   !@$_SERVER['DOCUMENT_ROOT'] and (realpath($argv[0]) == __FILE__)
@@ -94,7 +95,7 @@ class Page extends nb {
   public static function out($v) { echo $v; }
 
   public static function title2filename($title,$content_type='') {
-    $ext = $content_type ? self::mime2ext($content_type) : '';
+    $ext = $content_type ? mime::ext($content_type) : '';
     $title = self::no_accent($title);
     $title = preg_replace('/\W+/','_',$title);
     if ($ext) $title .= '.'.$ext;
@@ -603,14 +604,14 @@ class Page extends nb {
     $content_type = self::p('content_type');
 
     if (!$format and $content_type) {
-      self::p('format',self::mime2ext($content_type));
+      self::p('format',mime::ext($content_type));
 
     } elseif (!$format and ($client_type = self::client_content_type())) {
-      self::p('format',self::mime2ext($client_type));
+      self::p('format',mime::ext($client_type));
 
     }
 
-    if (!$content_type and $format) $content_type = self::ext2mime($format);
+    if (!$content_type and $format) $content_type = mime::get($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()]);