From: Nicolas Boisselier Date: Wed, 6 Apr 2016 21:31:22 +0000 (+0100) Subject: Fix bugs X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=a8cc556b81f99b4cca8c8242275987542c428131;p=nb.git Fix bugs --- diff --git a/lib/php/benchmark.php b/lib/php/benchmark.php index 47b02021..94716afc 100755 --- a/lib/php/benchmark.php +++ b/lib/php/benchmark.php @@ -8,6 +8,7 @@ require(dirname(__FILE__).'/nb.php'); $_GET['var'] = 'sldkfhlsakhlshglzkdhzfgldznfdznbldzknb'; $array = array_fill(0,100000,"a"); $hash = array(); for ($i=0;$i<100000;$i++) $hash[$i] = $i; +$a = $b = ''; echo "Start benchmark\n"; /* @@ -30,6 +31,9 @@ exit; #function _isset() { isset($var); } nb::benchmark('_isset',5000000); #function _in_array() { in_array(5000,$GLOBALS['array']); } nb::benchmark('_in_array',1000); #function _in_hash() { isset($GLOBALS['hash'][5000]); } nb::benchmark('_in_hash',1000); +function _and() { $a='' and $b=''; } nb::benchmark('_and',9999999); +function _sig_and() { $a='' and $b=''; } nb::benchmark('_sig_and',9999999); +nb::benchmark(); exit; function _1() { date_default_timezone_set('Europe/London'); } nb::benchmark('_1'); function _2() { error_reporting(E_ALL | E_STRICT | E_NOTICE); } nb::benchmark('_2'); function _3() { ini_set('include_path','.'); } nb::benchmark('_3'); diff --git a/lib/php/db/table.php b/lib/php/db/table.php index b5ef096b..698d3ac5 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -594,13 +594,14 @@ Class Table extends nb { } #debug($fields); #bye($this->name); - if (!$this->p('action')) echo $this->html_menu(); if (!isset($opt['is_html'])) $opt['is_html'] = preg_match('/^(table|div)$/',$format) ? ( $this->p('header')!=="0") : false ; + if ($opt['is_html'] and !$this->p('action')) echo $this->html_menu(); + # Use the module out when format unknow $out_conf = null; if ($this->p('out') or !preg_match('/^('.join('|', diff --git a/lib/php/nb.php b/lib/php/nb.php index d039f61e..a0580a4c 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -249,7 +249,7 @@ class NB { if ($function === null) { $prev = $_benchmark['.']; - echo "Iteration: $limit\n"; + echo "Results: $limit\n"; foreach ($_benchmark as $lib => $sec) { if ($lib === '.') continue; printf("%-30s %s\n",$lib,($sec-$prev)); @@ -262,6 +262,7 @@ class NB { $function(); } + echo "Completed: $function\n"; $_benchmark[$function] = microtime(true); } diff --git a/lib/php/out.php b/lib/php/out.php index 20605692..076389a4 100644 --- a/lib/php/out.php +++ b/lib/php/out.php @@ -1,10 +1,5 @@ $v) { echo sprintf("%-".(!empty($o['head_max_len']) ? $o['head_max_len']+1 : 10)."s: %s\n",$k,out::escape($v)); } - #foreach ($row as $k => $v) { echo "$k: ".out::escape($v)."\n"; } + foreach ($row as $k => $v) { echo sprintf("%-".(!empty($o['head_max_len']) ? $o['head_max_len']+1 : 10)."s: %s\n",$k,self::escape($v)); } + #foreach ($row as $k => $v) { echo "$k: ".self::escape($v)."\n"; } return true; } @@ -221,7 +216,7 @@ Class Out extends Nb { $head = self::head($conf,$head,$data); foreach ($data as $row) { - if ($count>0) out::concat($conf); + if ($count>0) self::concat($conf); $count++; # Transform simple array into hash @@ -264,7 +259,7 @@ Class Out extends Nb { static $replace_flags = null; $is_scalar = is_scalar($v); - $v = out::scalar($v); + $v = self::scalar($v); if ($v==='') $is_scalar = true; if ($replace_flags === null) { @@ -298,7 +293,7 @@ Class Out extends Nb { } $v = htmlspecialchars($v,$replace_flags,strtoupper(self::$charset)); - if (!$is_scalar) $v = '
'.NB_EOL.$v.NB_EOL.'
'; + if (!$is_scalar and strpos($type,'html') !== false) $v = '
'.NB_EOL.$v.NB_EOL.'
'; return $v; } @@ -322,7 +317,8 @@ function out_csv(&$row,$o) { $values = array(); foreach (array_values($row) as $k=>$v) { - $values[] = preg_replace('/zAZA/','',out::scalar($v)); +# NB 06.04.16 $values[] = preg_replace('/zAZA/','',out::scalar($v)); + $values[] = out::scalar($v); #$values[] = preg_replace('/\r?\n/','',out::scalar($v)); } @@ -367,7 +363,7 @@ function out_tag(&$row,&$o) { # Inside tag, ex: label if (isset($o['tag_key'])) { - $v = '<'.$o['tag_key'].'>'.$k.''.$v; + $v = '<'.$o['tag_key'].'>'.$k.''.$v; } # Tag = o[tag] or key @@ -386,7 +382,7 @@ function out_tag(&$row,&$o) { ; } - if (isset($o['tag_enclose'])) echo (NB_EOL ? ' ' : '').''.NB_EOL; + if (isset($o['tag_enclose'])) echo (NB_EOL ? ' ' : '').''.NB_EOL; } function out_xml(&$row,$o) { diff --git a/lib/php/page.php b/lib/php/page.php index 9e8d630e..d0c02abb 100644 --- a/lib/php/page.php +++ b/lib/php/page.php @@ -303,9 +303,8 @@ class Page extends nb { public function headers() { #header('Content-type: ' . self::$content_type); - $c = strtoupper ( self::$charset ); -# NB 19.08.15 $this->header('Content-type: ',self::$content_type . ($c ? "; charset=$c" : "")); - header('Content-type: '.self::$content_type . ($c ? "; charset=$c" : "")); + header('Content-type: '.self::$content_type . (($c = strtoupper ( self::$charset )) ? "; charset=$c" : "")); + if (self::p('download-attachment')) header('Content-Disposition: attachment; filename="' . $this->title2filename($this->title,self::$content_type) );