From 3685b3cd705ca492c9aa829e31a578caa368df72 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Fri, 19 Jan 2018 04:17:52 +0000 Subject: [PATCH] etc/profile.d/nb.sh --- etc/profile.d/nb.sh | 2 +- lib/php/db.php | 5 +-- lib/php/nb.php | 83 ++++++++++++++++++++++----------------------- lib/php/page.php | 9 ++--- 4 files changed, 50 insertions(+), 49 deletions(-) diff --git a/etc/profile.d/nb.sh b/etc/profile.d/nb.sh index 91c44fa0..e486f2a7 100644 --- a/etc/profile.d/nb.sh +++ b/etc/profile.d/nb.sh @@ -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 } diff --git a/lib/php/db.php b/lib/php/db.php index ee5c71c0..991abbff 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -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": diff --git a/lib/php/nb.php b/lib/php/nb.php index 96d25a6b..32f402c9 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -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 diff --git a/lib/php/page.php b/lib/php/page.php index 253718b2..23e9d789 100644 --- a/lib/php/page.php +++ b/lib/php/page.php @@ -1,6 +1,7 @@