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);
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;
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":
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 {
);
# 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'; }
* 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
<?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__)
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;
$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()]);