From: Nicolas Boisselier Date: Sun, 20 Mar 2016 02:31:35 +0000 (+0000) Subject: download X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=01b8f71eaadc8e49e40599a80f0f43df5197c2a6;p=nb.git download --- diff --git a/etc/dbs.yaml b/etc/dbs.yaml index 21142348..19023ffd 100644 --- a/etc/dbs.yaml +++ b/etc/dbs.yaml @@ -51,6 +51,10 @@ izidev: options: - "PDO::MYSQL_ATTR_INIT_COMMAND: SET NAMES utf8'" +ui-mem: + pdo: 'sqlite:/dev/shm/semantico.db' + _conf2h_copy: ui + ui: pdo: 'sqlite:/opt/semantico/product/releases/sem_ui/db/semantico.db' title: 'Semantico UI' diff --git a/lib/js/nb.js b/lib/js/nb.js index 587490b6..e9a6b53f 100644 --- a/lib/js/nb.js +++ b/lib/js/nb.js @@ -25,30 +25,80 @@ function NB() { } - this.resize = function() { + this.wh = function(s) { + var item = $(s); + if (!item) return [0,0] + + var width = item.width(); + var height = item.height(); + + /* + */ + width -= $(item).css('paddingLeft').replace(/px/,''); + width -= $(item).css('paddingRight').replace(/px/,''); + height -= $(item).css('paddingTop').replace(/px/,''); + height -= $(item).css('paddingBottom').replace(/px/,''); + + width -= $(item).css('marginLeft').replace(/px/,''); + width -= $(item).css('marginRight').replace(/px/,''); + height -= $(item).css('marginTop').replace(/px/,''); + height -= $(item).css('marginBottom').replace(/px/,''); + //console.log(width+'/'+height); + return [parseInt(width),parseInt(height)]; + } - // table to div - if ($('#_responsive').css('content') != 'none') { - that.table2div('table.rows'); - return true; - } else { - $('table.rows').addClass('t2d'); - $('.t2d-th').each(function(){ - $(this).remove(); - }); + this.maxhw = function(s) { + var height = $('body').height(); + var width = $(window).width(); + + /* + var prev = $(s).prev(); + for (var i=0;i<50 && prev;i++) { + prev = $(prev).prev(); + if (prev) { + try { + height -= that.wh(prev)[1]; + } catch (e) { + prev = undefined; + break; + } + } } + */ +//console.log('total: '+width+'/'+height); + + //if (prev) height -= that.wh(prev)[1]; + //if (prev) height -= $(prev).height(); + $(s).each(function(){ + w = width;// - that.wh(this)[0]; + h = height;// - that.wh(this)[1]; + //if ($(this).height() > h) $(this).height(h); + //if ($(this).width() > w) $(this).width(w); +//$(this).css('border','solid 1px red'); + $(this).height(h); $(this).width(w); + /* + if (1 || $(this).height() > h || $(this).width() > w) $(this).css({ + //'display': 'block', + 'overflow': 'scroll', + 'border': 'solid 2px blue', + }); + */ +//console.log(w+'/'+h); + }); + } - // Max width for blocks - var block = $("table, div"); + this.maxhw_resize = function(s) { + var block = $(s); if (!block) return false; - var width = $(window).width(); + var width = $('body').width(); var set_width = width - 20; block.each(function(){ var first_width = $(this).attr('nb-resize'); var cur_width = $(this).width(); +//$(this).css({ 'border': 'solid 1px yellow', }); if (cur_width > width) { if (!first_width) { $(this).attr('nb-resize',cur_width); @@ -84,6 +134,21 @@ function NB() { } + this.resize = function() { + + // table to div + if ($('#_responsive').css('content') != 'none') { + that.table2div('table.rows'); + return true; + } else { + $('table.rows').addClass('t2d'); + $('.t2d-th').each(function(){ $(this).remove(); }); + } + + // Max width for blocks + that.maxhw_resize('table, div'); + } + this.table2div = function(find) { var th = [] diff --git a/lib/php/benchmark.php b/lib/php/benchmark.php index a6d011f3..e0ef96ac 100755 --- a/lib/php/benchmark.php +++ b/lib/php/benchmark.php @@ -18,13 +18,14 @@ echo $first; exit; */ -function __f1(&$ar) { $v=$ar; return; foreach ($ar as $v) { 1; } } +#function __f1(&$ar) { $v=$ar; return; foreach ($ar as $v) { 1; } } +function __f1(&$ar) { return; foreach ($ar as $v) { 1; } } function __f2($ar) { return; foreach ($ar as $v) { 1; } } $array = array_fill(0,100000,"a"); #if (function_exists('__f1')) { function _f1() { __f1($array); } nb::benchmark('_f1'); } #if (function_exists('__f2')) { function _f2() { __f2($array); } nb::benchmark('_f2'); } -function _f1() { file_exists('/tm'); } nb::benchmark('_f1'); -function _f2() { echo ''; } nb::benchmark('_f2'); +function _f1() { ini_set('display_errors', 'On'); } nb::benchmark('_f1'); +function _f2() { ; } nb::benchmark('_f2'); nb::benchmark(); exit; diff --git a/lib/php/config.php b/lib/php/config.php index aa762d46..798ac1d0 100644 --- a/lib/php/config.php +++ b/lib/php/config.php @@ -7,7 +7,6 @@ */ date_default_timezone_set('Europe/London'); -ini_set('display_errors', 'On'); error_reporting(E_ALL | E_STRICT | E_NOTICE); # NB 05.03.16 ini_set('include_path', realpath(dirname(__FILE__).'/../lib').':'.realpath(dirname(__FILE__)).':'.ini_get('include_path')); @@ -18,6 +17,9 @@ ini_set('include_path','' #define('NB_EOL',''); #define('NB_PROD',true); -require_once('nb.php'); +include('nb.php'); if (nb::php_cli()) argv2request(); + +ini_set('display_errors', 'On'); +if (nb::php_cli() or nb::p('txt_errors')) ini_set('html_errors', false); ?> diff --git a/lib/php/db.php b/lib/php/db.php index 384b19ad..3fea979c 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -10,19 +10,6 @@ require_once(dirname(__FILE__).'/nb.php'); require_once(dirname(__FILE__).'/out.php'); require_once(dirname(__FILE__).'/db/table.php'); require_once('out.php'); -if (!defined('DB_HTML_FORM_BUTTONS')) define('DB_HTML_FORM_BUTTONS','' - #.'' - #.'' - #.'' -// NB 04.08.15 .'X' - .'' - .'' - .'' - .'' -); -#if (!defined('DB_HTML_BUTTON_SUBMIT')) define('DB_HTML_BUTTON_SUBMIT',''); -#if (!defined('DB_HTML_BUTTON_ADD')) define('DB_HTML_BUTTON_ADD','Add'); -#if (!defined('DB_HTML_BUTTON_ADD')) define('DB_HTML_BUTTON_ADD',''); $DB_TYPES = array( 'tables' => array( @@ -363,101 +350,6 @@ EOF; return $mime; } - function html_menu($table=null) { - - $r = ''.NB_EOL; - return $r; - } - function sql_name($value) { if ($this->type == 'mysql') return '`'.$value.'`'; return '"'.$value.'"'; @@ -620,7 +512,7 @@ EOF; * @param [FILES] $files Files to load * @return ARRAY the new/existing value of $this->db */ - static function config2h ($files=array(),&$first=false) { + static function conf2h ($files=array(),&$first=false) { if (empty($files)) return array(); if (!empty($files)) { @@ -628,19 +520,33 @@ EOF; $h = array(); foreach ($files as $file) { - if (is_readable($file) and ($yaml = @yaml_parse_file($file))) { - #foreach ($yaml as $k=>$v) { $yaml[$k]['_config2h'] = $file; } + if (is_readable($file) and ($yaml = yaml_parse_file($file))) { + #foreach ($yaml as $k=>$v) { $yaml[$k]['_conf2h'] = $file; } #debug($file); $h = array_replace_recursive($h,$yaml); } #debug($file); #if ( ($yaml = @yaml_parse_file($file)) ) $h = array_replace_recursive($h,$yaml) ; - unset($yaml); #} } - #debug($h); + unset($yaml); + + # Emulate hash pointer + foreach ($h as $db=>$o) { + foreach ($o as $k => $v) { + if ($k != '_conf2h_copy') continue; + + foreach ($h[$v] as $kk => $vv) { + if (!isset($o[$kk])) $h[$db][$kk] = $vv; + } + unset($h[$db][$k]); + #bye($h[$db]); + + } + } + } if (!$h) return false; #self::bye($h['puppetdb']); @@ -664,17 +570,11 @@ EOF; $Db = new self(); #bye($_SERVER["PHP_SELF"]); bye($_SERVER); - if (!in_array(nb::$root_dir.'/etc/dbs.yaml',$conf)) $conf[] = nb::$root_dir.'/etc/dbs.yaml'; - if (!in_array('/etc/dbs.yaml',$conf)) $conf[] = '/etc/dbs.yaml'; +# NB 19.03.16 if (!in_array(nb::$root_dir.'/etc/dbs.yaml',$conf)) $conf[] = nb::$root_dir.'/etc/dbs.yaml'; +# NB 19.03.16 if (!in_array('/etc/dbs.yaml',$conf)) $conf[] = '/etc/dbs.yaml'; # Load databases - if (! ($dbs = $Db->config2h($conf)) ) return false; - - # Param - Extract dbname from table - if (preg_match('/^(\w+)\.(.*?)$/',$Db->p('table'),$m)) { - $Db->pset('db',$m[1]); - $Db->pset('table',$m[2]); - } + if (! ($dbs = $Db->conf2h($conf)) ) return false; #die (nb::p('db')); # Param - Default base on order hight num value @@ -683,10 +583,6 @@ EOF; $Db->pset('db',$Db->ar_first($dbs,true)); } - # Param - correction / aliases - if (($format=$Db->p('format'))) { - } - # Connection #bye($Db->p('db')); if (!isset($dbs[$Db->p('db')])) $Db->bye("Can't find db: `".$Db->p('db')."` in `".join(",",array_keys($dbs))."`",false); @@ -703,10 +599,9 @@ EOF; if (empty($Db)) return false; if (!$Db->p('table') and isset($Db->default_table)) $Db->pset('table',$Db->default_table); if (!$Db->p('table') and ($v = $Db->tables())) $Db->pset('table',$Db->ar_first($v)); - if (!$Db->p('table')) return; # NB 10.01.16 $Table = new table($Db->p('table'),array('db' => $Db)); - $Table = $Db->table($Db->p('table')); + if ($Db->p('table')) $Table = $Db->table($Db->p('table')); return true; diff --git a/lib/php/db/index.php b/lib/php/db/index.php index 99cebe62..9ee489f9 100755 --- a/lib/php/db/index.php +++ b/lib/php/db/index.php @@ -9,7 +9,12 @@ require_once(dirname(__FILE__).'/../config.php'); require_once(dirname(__FILE__).'/../db.php'); -Db::init(array( '/etc/dbs.yaml' )); +# Param - Extract dbname from table +if (preg_match('/^(\w+)\.(.*?)$/',Db::p('table'),$m)) { + Db::pset('db',$m[1]); + Db::pset('table',$m[2]); +} +Db::init(array( nb::$root_dir.'/etc/dbs.yaml','/etc/dbs.yaml' )); if( defined('DB_JUST_INIT')) return true; return $Db->action($Table); diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 7a34f601..e1be1184 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -378,7 +378,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. foreach (array_merge( $this->params, array_keys($fields) ) as $f) { - if (@strcmp($this->p($f),'')==0) continue; + if (strcmp($this->p($f,''),'')==0) continue; $params[$f] = $this->p($f); } @@ -634,7 +634,10 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. $st->execute(); if (!isset($opt['is_html'])) $opt['is_html'] = preg_match('/^(table|div)$/',$format) - ? ( $this->p('header')!=="0" and $this->p('inc')!=="1") + ? ( + $this->p('header')!=="0" + #and $this->p('download')!=="1" + ) : false ; @@ -1087,7 +1090,6 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. } elseif ($action == 'table.count') { return $this->out2($this->count(),'count'); } elseif ($action == 'table.rows' or $action == 'rows') { - #if ($this->p('page')==='0') $this->pset('inc',1); $this->db->print_header($this->p('format')); $this->rows(); return true; @@ -1126,8 +1128,6 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. return true; } elseif ($this->p('format') and !preg_match('/^(table|div)$/',$this->p('format'))) { - #} elseif ($action == 'table' and $this->p('format') and $this->p('table')) { - #} elseif ($is_html) { $this->rows(array( 'format' => $this->p('format'))); return true; @@ -1208,7 +1208,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. ) as $v) { $r .= ''; } - $r .= ''; // Embed for no html format + $r .= ''; // Embed for no html format // // Options diff --git a/lib/php/functions.php b/lib/php/functions.php index 337862dd..97655bc1 100644 --- a/lib/php/functions.php +++ b/lib/php/functions.php @@ -118,7 +118,8 @@ function err($msg='__err__',$preff='err',$backtrace_deep=0) { $msg = $preff_msg.$msg; } - nb::msg( !nb::php_cli() + #nb::msg( !nb::php_cli() + nb::msg( preg_match('/ml/i',nb::get_header('Content-type')) ? ''.$msg.''.NB_EOL diff --git a/lib/php/nb.php b/lib/php/nb.php index eb1534e1..d301f1d6 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -16,7 +16,7 @@ class nb { ); public static $content_types = array( - 'json' => 'application/json', + 'json' => 'text/json', 'doc' => 'application/msword', 'xls' => 'application/vnd.ms-excel', 'xml' => 'application/xml', @@ -101,10 +101,24 @@ class nb { return prettyText($text); } + public static function mime2ext($mime) { + + static $aliases = null; if ($aliases === null) $aliases = array_combine(array_values(self::$content_types_aliases),array_keys(self::$content_types_aliases)); + #static $v = 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[$ext])) return self::ext2mime($aliases[$ext]); + + } + /* - * Function: prettyText + * Function: ext2mime * Does what it says */ + #public static function ext2content_type($ext) { return self::ext2mime($ext); } public static function ext2mime($ext) { foreach (self::$content_types as $e => $c) { @@ -402,6 +416,191 @@ class nb { return (!isset($_SERVER['SERVER_SOFTWARE']) && (php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0))); } + public static function no_accent($str){ + return strtr($str,array( +'À' => 'A', +'Á' => 'A', +'Â' => 'A', +'Ã' => 'A', +'Ä' => 'A', +'Å' => 'A', +'à' => 'a', +'á' => 'a', +'â' => 'a', +'ã' => 'a', +'ä' => 'a', +'å' => 'a', +'Ā' => 'A', +'ā' => 'a', +'Ă' => 'A', +'ă' => 'a', +'Ą' => 'A', +'ą' => 'a', +'Ç' => 'C', +'ç' => 'c', +'Ć' => 'C', +'ć' => 'c', +'Ĉ' => 'C', +'ĉ' => 'c', +'Ċ' => 'C', +'ċ' => 'c', +'Č' => 'C', +'č' => 'c', +'Ð' => 'D', +'ð' => 'd', +'Ď' => 'D', +'ď' => 'd', +'Đ' => 'D', +'đ' => 'd', +'È' => 'E', +'É' => 'E', +'Ê' => 'E', +'Ë' => 'E', +'è' => 'e', +'é' => 'e', +'ê' => 'e', +'ë' => 'e', +'Ē' => 'E', +'ē' => 'e', +'Ĕ' => 'E', +'ĕ' => 'e', +'Ė' => 'E', +'ė' => 'e', +'Ę' => 'E', +'ę' => 'e', +'Ě' => 'E', +'ě' => 'e', +'Ĝ' => 'G', +'ĝ' => 'g', +'Ğ' => 'G', +'ğ' => 'g', +'Ġ' => 'G', +'ġ' => 'g', +'Ģ' => 'G', +'ģ' => 'g', +'Ĥ' => 'H', +'ĥ' => 'h', +'Ħ' => 'H', +'ħ' => 'h', +'Ì' => 'I', +'Í' => 'I', +'Î' => 'I', +'Ï' => 'I', +'ì' => 'i', +'í' => 'i', +'î' => 'i', +'ï' => 'i', +'Ĩ' => 'I', +'ĩ' => 'i', +'Ī' => 'I', +'ī' => 'i', +'Ĭ' => 'I', +'ĭ' => 'i', +'Į' => 'I', +'į' => 'i', +'İ' => 'I', +'ı' => 'i', +'Ĵ' => 'J', +'ĵ' => 'j', +'Ķ' => 'K', +'ķ' => 'k', +'ĸ' => 'k', +'Ĺ' => 'L', +'ĺ' => 'l', +'Ļ' => 'L', +'ļ' => 'l', +'Ľ' => 'L', +'ľ' => 'l', +'Ŀ' => 'L', +'ŀ' => 'l', +'Ł' => 'L', +'ł' => 'l', +'Ñ' => 'N', +'ñ' => 'n', +'Ń' => 'N', +'ń' => 'n', +'Ņ' => 'N', +'ņ' => 'n', +'Ň' => 'N', +'ň' => 'n', +'ʼn' => 'n', +'Ŋ' => 'N', +'ŋ' => 'n', +'Ò' => 'O', +'Ó' => 'O', +'Ô' => 'O', +'Õ' => 'O', +'Ö' => 'O', +'Ø' => 'O', +'ò' => 'o', +'ó' => 'o', +'ô' => 'o', +'õ' => 'o', +'ö' => 'o', +'ø' => 'o', +'Ō' => 'O', +'ō' => 'o', +'Ŏ' => 'O', +'ŏ' => 'o', +'Ő' => 'O', +'ő' => 'o', +'Ŕ' => 'R', +'ŕ' => 'r', +'Ŗ' => 'R', +'ŗ' => 'r', +'Ř' => 'R', +'ř' => 'r', +'Ś' => 'S', +'ś' => 's', +'Ŝ' => 'S', +'ŝ' => 's', +'Ş' => 'S', +'ş' => 's', +'Š' => 'S', +'š' => 's', +'ſ' => 's', +'Ţ' => 'T', +'ţ' => 't', +'Ť' => 'T', +'ť' => 't', +'Ŧ' => 'T', +'ŧ' => 't', +'Ù' => 'U', +'Ú' => 'U', +'Û' => 'U', +'Ü' => 'U', +'ù' => 'u', +'ú' => 'u', +'û' => 'u', +'ü' => 'u', +'Ũ' => 'U', +'ũ' => 'u', +'Ū' => 'U', +'ū' => 'u', +'Ŭ' => 'U', +'ŭ' => 'u', +'Ů' => 'U', +'ů' => 'u', +'Ű' => 'U', +'ű' => 'u', +'Ų' => 'U', +'ų' => 'u', +'Ŵ' => 'W', +'ŵ' => 'w', +'Ý' => 'Y', +'ý' => 'y', +'ÿ' => 'y', +'Ŷ' => 'Y', +'ŷ' => 'y', +'Ÿ' => 'Y', +'Ź' => 'Z', +'ź' => 'z', +'Ż' => 'Z', +'ż' => 'z', +'Ž' => 'Z', +'ž' => 'z' + )); + } } # < Class #die(self::ext2mime('csv')); ?> diff --git a/lib/php/page.php b/lib/php/page.php index 0c6ab9e4..311b26a9 100644 --- a/lib/php/page.php +++ b/lib/php/page.php @@ -83,7 +83,15 @@ class Page extends nb { return (is_array($v) ? $v : array($v)); } - function filename2title() { + public static function title2filename($title,$content_type='') { + $ext = $content_type ? self::mime2ext($content_type) : ''; + $title = self::no_accent($title); + $title = preg_replace('/\W+/','_',$title); + if ($ext) $title .= '.'.$ext; + return $title; + } + + public function filename2title() { $str = ''; #$this->title = $GLOBALS['argv'][0] if (isset($_SERVER['REQUEST_URI'])) $str = preg_replace('/\?.*$/','',preg_replace(',^.*?([^/]+)(\/?.*)?$,','\1',$_SERVER['REQUEST_URI'])); @@ -269,6 +277,9 @@ class Page extends nb { $c = strtoupper ( $this->charset ); # NB 19.08.15 $this->header('Content-type: ',$this->content_type . ($c ? "; charset=$c" : "")); header('Content-type: '.$this->content_type . ($c ? "; charset=$c" : "")); + if (self::p('download-attachment')) header('Content-Disposition: attachment; filename="' + . $this->title2filename($this->title,$this->content_type) + ); return true; }