From 0634f04a46ba34d624de9101d657a14e4eb2bdc9 Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Wed, 16 Mar 2016 00:19:17 +0000 Subject: [PATCH] EOL --- lib/php/benchmark.php | 2 +- lib/php/config.php | 2 + lib/php/db.php | 16 +++---- lib/php/db/field.php | 2 +- lib/php/db/table.php | 97 +++++++++++++++++++++---------------------- lib/php/functions.php | 12 +++--- lib/php/nb.php | 8 +++- lib/php/out.php | 34 +++++++-------- lib/php/page.php | 52 +++++++++++------------ 9 files changed, 114 insertions(+), 111 deletions(-) diff --git a/lib/php/benchmark.php b/lib/php/benchmark.php index 8807c8e0..deea73a1 100755 --- a/lib/php/benchmark.php +++ b/lib/php/benchmark.php @@ -23,7 +23,7 @@ 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() { $html = ''; } nb::benchmark('_f1'); +function _f1() { echo null; } nb::benchmark('_f1'); function _f2() { echo ''; } nb::benchmark('_f2'); nb::benchmark(); exit; diff --git a/lib/php/config.php b/lib/php/config.php index c385af96..aa762d46 100644 --- a/lib/php/config.php +++ b/lib/php/config.php @@ -16,6 +16,8 @@ ini_set('include_path','' .rtrim(':'.ini_get('include_path'),':') ); +#define('NB_EOL',''); +#define('NB_PROD',true); require_once('nb.php'); if (nb::php_cli()) argv2request(); ?> diff --git a/lib/php/db.php b/lib/php/db.php index 0a0a1dbf..e7a9be79 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -361,7 +361,7 @@ EOF; function html_menu($table=null) { - $r = ''.PHP_EOL; + $r .= ''.NB_EOL; return $r; } @@ -465,12 +465,12 @@ EOF; #if (preg_match('/yaml|yml/',$f)) bye($this->yaml_encode($this->object2array($this->fields()))); $mime = $this->print_header($f); - #echo $row.PHP_EOL; + #echo $row.NB_EOL; #bye($f); return true; - if ($f == 'json') { echo json_encode($row).PHP_EOL; } + if ($f == 'json') { echo json_encode($row).NB_EOL; } #elseif ($f == 'csv' and is_array($row)) { echo join("\n",$row)."\n"; } #elseif ($f == 'csv') { echo join("\t",nb::ar_map('json_encode($a)',$row))."\n"; } - #elseif ($f == 'csv') { echo json_encode($row).PHP_EOL; } + #elseif ($f == 'csv') { echo json_encode($row).NB_EOL; } elseif ($f == 'csv') { #if (is_object($data)) echo "$data\n"; #$isHash = array_values($row) !== $row; @@ -519,7 +519,7 @@ EOF; # NB 06.03.16 } #else echo join("\t",array_values($v))."\n"; } - #echo json_encode($row).PHP_EOL; + #echo json_encode($row).NB_EOL; if ($type === 2) { echo "\n"; } @@ -527,8 +527,8 @@ EOF; elseif (preg_match('/yaml|yml/',$f)) { echo $this->yaml_encode($row); } elseif (preg_match('/php|var_export/',$f)) { echo var_export($row,true); } elseif (preg_match('/var_dump/',$f)) { echo var_dump($row,true); } - elseif (is_scalar($row)) { echo($row.PHP_EOL); } - //else { echo($row.PHP_EOL); } + elseif (is_scalar($row)) { echo($row.NB_EOL); } + //else { echo($row.NB_EOL); } else{ echo var_export($row,true); } return true; diff --git a/lib/php/db/field.php b/lib/php/db/field.php index 12abc17e..64cc3447 100644 --- a/lib/php/db/field.php +++ b/lib/php/db/field.php @@ -39,7 +39,7 @@ class field { ? ''.$this->out($value).'' : '' ) - .''.PHP_EOL; + .''.NB_EOL; } diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 764a77f9..5c39aaef 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -15,8 +15,7 @@ if (false and empty($_SERVER['DOCUMENT_ROOT'])) { #print_r($Table->sql()); } -define('TABLE_EOL',defined(NB_EOL) ? NB_EOL : PHP_EOL); -define('TABLE_INDENT',TABLE_EOL ? "\t" : ""); +define('TABLE_INDENT',NB_EOL ? "\t" : ""); define('TABLE_CSV_SEP',nb::p('sep') ? nb::p('sep') : "\t"); if (!defined('DB_HTML_EDIT')) define('DB_HTML_EDIT','Edit'); if (!defined('DB_HTML_DELETE')) define('DB_HTML_DELETE','Delete'); @@ -338,8 +337,8 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. $st = $this->db->conn->prepare($sql); $st->execute(); - echo '
'.TABLE_EOL; - echo '
'.TABLE_EOL; + echo ''.NB_EOL; + echo '
'.NB_EOL; $count = 0; if ( $add or ($row = $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT))) { $count ++; @@ -353,20 +352,20 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. } } - echo '
'.TABLE_EOL; + echo '
'.NB_EOL; echo '' .'
' .( empty($_SERVER['HTTP_REFERER']) ? '' : '') .'' .'' - .'
'.TABLE_EOL + .''.NB_EOL .'' .'' .'' .'' .'' - .'
'.TABLE_EOL; + .''.NB_EOL; } @@ -719,7 +718,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. echo ''.TABLE_EOL + .''.NB_EOL ; } } @@ -761,11 +760,11 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. -----------------------------------------------------------------*/ public function rows_begin_json() { $this->_row_json = null; - return '['.TABLE_EOL; + return '['.NB_EOL; return '' #."// database: ".$this->db->name."\n" #."// table: $this->name\n" - .'['.TABLE_EOL; + .'['.NB_EOL; } public function rows_rec_json(&$row) { @@ -773,14 +772,14 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. $json = ''; $this->_row_json = true; } else { - $json = ','.TABLE_EOL; + $json = ','.NB_EOL; } return $json . json_encode($row); } public function rows_end_json() { unset($this->_row_json); - return TABLE_EOL.']'.TABLE_EOL; + return NB_EOL.']'.NB_EOL; } /*----------------------------------------------------------------- @@ -795,28 +794,28 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. -----------------------------------------------------------------*/ public function rows_begin_xml() { return '' - .''.TABLE_EOL #db->name.'" table="'.$this->name.'" type="'.$this->db->type.'">'.TABLE_EOL - .''.TABLE_EOL + .''.NB_EOL #db->name.'" table="'.$this->name.'" type="'.$this->db->type.'">'.NB_EOL + .''.NB_EOL ; } public function rows_rec_xml(&$row) { $xml = ''; - $xml .= TABLE_INDENT."".TABLE_EOL; + $xml .= TABLE_INDENT."".NB_EOL; foreach ($row as $k=>$v) { if ($v !== '') $xml .= '' . TABLE_INDENT.TABLE_INDENT."<".$k.">" .'' . '' - . TABLE_EOL; + . NB_EOL; } - $xml .= TABLE_INDENT."".TABLE_EOL; + $xml .= TABLE_INDENT."".NB_EOL; return $xml; } public function rows_end_xml() { - return ''.TABLE_EOL; + return ''.NB_EOL; } /*----------------------------------------------------------------- @@ -843,55 +842,55 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. $html = ''; - #$html .= ''.TABLE_EOL; - $html .= '
'.TABLE_EOL; - #if (!empty($opt)) $html .= '' .TABLE_EOL; + #$html .= '
' . $this->nav($opt['count'],$opt['tot'],$opt['limit']) . '
'.NB_EOL; + $html .= '
'.NB_EOL; + #if (!empty($opt)) $html .= '' .NB_EOL; if ($this->p('header')!=="0") { - $html .= ''.TABLE_EOL.''.TABLE_EOL; + $html .= ''.NB_EOL.''.NB_EOL; - if ($this->p('buttons')!=='0' and DB_HTML_EDIT) $html .= ''.TABLE_EOL; + if ($this->p('buttons')!=='0' and DB_HTML_EDIT) $html .= ''.NB_EOL; foreach (array_keys($fields) as $f) { - #$html .= ''.TABLE_EOL; - $html .= ''.TABLE_EOL; + #$html .= ''.NB_EOL; + $html .= ''.NB_EOL; } - if ($this->p('buttons')!=='0' and DB_HTML_DELETE) $html .= ''.TABLE_EOL; - $html .= ''.TABLE_EOL.''.TABLE_EOL; + if ($this->p('buttons')!=='0' and DB_HTML_DELETE) $html .= ''.NB_EOL; + $html .= ''.NB_EOL.''.NB_EOL; } - $html .= ''.TABLE_EOL; + $html .= ''.NB_EOL; return $html; } public function rows_rec_table(&$row) { - $html = ''.TABLE_EOL; + $html = ''.NB_EOL; if ($this->p('buttons')!=='0') $html .= ''.TABLE_EOL; + .'">'.DB_HTML_EDIT.''.NB_EOL; foreach ($row as $k => $v) { if (isset($this->extras[$k])) $k .= " extra"; - $html .= ''.TABLE_EOL; + $html .= ''.NB_EOL; } if ($this->p('buttons')!=='0') $html .= ''.TABLE_EOL; + .'">'.DB_HTML_DELETE.''.NB_EOL; - $html .= ''.TABLE_EOL; + $html .= ''.NB_EOL; return $html; } public function rows_end_table($opt=array()) { $html = ''; - $html .= ''.TABLE_EOL; - $html .= '
' . $this->nav($opt['count'],$opt['tot'],$opt['limit']) . '
'.($this->p('buttons')==='0' ? $f : $this->url_sort($f)).''.($this->p('buttons')==='0' ? $this->prettyText($f) : $this->url_sort($f)).''.($this->p('buttons')==='0' ? $f : $this->url_sort($f)).''.($this->p('buttons')==='0' ? $this->prettyText($f) : $this->url_sort($f)).'
'.DB_HTML_EDIT.''.$v.''.$v.''.DB_HTML_DELETE.'
'.TABLE_EOL; + $html .= ''.NB_EOL; + $html .= ''.NB_EOL; return $html; } @@ -899,30 +898,30 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. Html Div -----------------------------------------------------------------*/ public function rows_begin_div() { - return '
'.TABLE_EOL; + return '
'.NB_EOL; } public function rows_rec_div(&$row) { $html = ''; - $html .= '
    '.TABLE_EOL; + $html .= '
      '.NB_EOL; if ($this->p('buttons')!=='0') { - $html .= '
    • '.TABLE_EOL; - $html .= ''.DB_HTML_EDIT.''.TABLE_EOL; - $html .= ''.DB_HTML_DELETE.''.TABLE_EOL; - $html .= '
    • '.TABLE_EOL; + $html .= '
    • '.NB_EOL; + $html .= ''.DB_HTML_EDIT.''.NB_EOL; + $html .= ''.DB_HTML_DELETE.''.NB_EOL; + $html .= '
    • '.NB_EOL; } foreach ($row as $k => $v) { $html .= '
    • ' .( $k == '0' ? '' : '') .''.$v.'' - .'
    • '.TABLE_EOL; + .''.NB_EOL; } - $html .= '
    '.TABLE_EOL; + $html .= '
'.NB_EOL; return $html; } @@ -952,7 +951,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. ; if (!($query = $this->db->conn->prepare($sql))) { - err('PDO::errorInfo(): ' .join(' ', $this->db->conn->errorInfo()) .TABLE_EOL); + err('PDO::errorInfo(): ' .join(' ', $this->db->conn->errorInfo()) .NB_EOL); return false; } @@ -960,7 +959,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. #debug(array($sql,$values)); if (!($execute = $query->execute())) { - err('PDO::errorInfo(): ' .join(' ', $this->db->conn->errorInfo()) .TABLE_EOL); + err('PDO::errorInfo(): ' .join(' ', $this->db->conn->errorInfo()) .NB_EOL); return false; } @@ -1010,7 +1009,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. $this->debug($sql,1); if (!($query = $this->db->conn->prepare($sql))) { - err('PDO::errorInfo(): ' .join(' ', $this->db->conn->errorInfo()) .TABLE_EOL); + err('PDO::errorInfo(): ' .join(' ', $this->db->conn->errorInfo()) .NB_EOL); return false; } @@ -1025,7 +1024,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. #return $sql; #bye($sql); if (!($execute = $query->execute())) { - err('PDO::errorInfo(): ' .join(' ', $this->db->conn->errorInfo()) .TABLE_EOL); + err('PDO::errorInfo(): ' .join(' ', $this->db->conn->errorInfo()) .NB_EOL); return false; } @@ -1118,7 +1117,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. $replace = array(); foreach ($this->replace as $k=>$v) { $replace[] = "$k.$v"; } - $html .= ''.TABLE_EOL; + $html .= ''.NB_EOL; } diff --git a/lib/php/functions.php b/lib/php/functions.php index 26576cf7..904a475e 100644 --- a/lib/php/functions.php +++ b/lib/php/functions.php @@ -112,7 +112,7 @@ function err($msg,$preff='err',$backtrace_deep=0) { nb::msg( preg_match('/ml/i',nb::get_header('Content-type')) ? '
'.$msg.'
' : strtoupper($preff).": $msg" - ).PHP_EOL; + ).NB_EOL; return false; } @@ -125,7 +125,7 @@ function debug($msg,$level=0) { $msg = '
'
       .(isset($_SERVER['HTTP_HOST']) ? htmlentities($msg) : $msg)
 # NB 16.12.15       .(isset($_SERVER['HTTP_HOST']) ? htmlspecialchars($msg) : $msg)
-    .'
'.PHP_EOL; + .''.NB_EOL; } else { $msg = "DEBUG: $msg\n"; @@ -203,13 +203,13 @@ function html_select_array($data,$opt=array()) { $html = ''; $html .= $opt['blank_lib']; - $html .= ''.PHP_EOL; + $html .= ''.NB_EOL; } foreach ($data as $d) { @@ -226,11 +226,11 @@ function html_select_array($data,$opt=array()) { $html .= ''.PHP_EOL; + .'>'.$lib.''.NB_EOL; } - $html .= ''.PHP_EOL; + $html .= ''.NB_EOL; return $html; diff --git a/lib/php/nb.php b/lib/php/nb.php index 1eefc139..c746897e 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -1,6 +1,10 @@ 'out_csv', ), 'center' => array( - 'enclose' => array("
".OUT_EOL,"
".PHP_EOL), + 'enclose' => array("
".NB_EOL,"
".NB_EOL), 'tag_enclose' => 'div', 'tag' => 'label', 'function' => 'out_tag', 'head' => 'out_tag_head', ), 'table' => array( - 'enclose' => array("".OUT_EOL,"
".PHP_EOL), + 'enclose' => array("".NB_EOL,"
".NB_EOL), 'tag_enclose' => 'tr', 'tag_head' => 'th', 'tag' => 'td', @@ -35,7 +33,7 @@ class Out extends Nb { 'head' => 'out_tag_head', ), 'xml' => array( - 'enclose' => array(''.OUT_EOL."".OUT_EOL,"".PHP_EOL), + 'enclose' => array(''.NB_EOL."".NB_EOL,"".NB_EOL), 'function' => 'out_xml', ), 'yaml' => array( @@ -43,9 +41,9 @@ class Out extends Nb { 'function' => 'out_yaml', ), 'json' => array( - 'enclose' => array('['.OUT_EOL,OUT_EOL.']'), + 'enclose' => array('['.NB_EOL,NB_EOL.']'), 'function.ext' => 'json_encode', - 'eol' => OUT_EOL, + 'eol' => NB_EOL, 'rec' => ',', ), ); @@ -180,7 +178,7 @@ function out_tag_head(&$data,$o) { function out_tag(&$row,$o) { #var_dump($row); return ''; - if (isset($o['tag_enclose'])) echo (OUT_EOL ? ' ' : '').'<'.$o['tag_enclose'].'>'.PHP_EOL; + if (isset($o['tag_enclose'])) echo (NB_EOL ? ' ' : '').'<'.$o['tag_enclose'].'>'.NB_EOL; foreach ($row as $k => $v) { #if (!is_scalar($v)) continue; @@ -192,29 +190,29 @@ function out_tag(&$row,$o) { $class = ''; } echo '' - .(OUT_EOL ? ' ' : '') + .(NB_EOL ? ' ' : '') #.(isset($o['tag_enclose']) ? '<'.$o['tag_enclose'].'>' : '') ."<$k$class>$v" #.(isset($o['tag_enclose']) ? '' : '') - .OUT_EOL + .NB_EOL ; } - if (isset($o['tag_enclose'])) echo (OUT_EOL ? ' ' : '').''.PHP_EOL; + if (isset($o['tag_enclose'])) echo (NB_EOL ? ' ' : '').''.NB_EOL; } function out_xml(&$row,$o) { - echo (OUT_EOL ? ' ' : '')."".OUT_EOL; + echo (NB_EOL ? ' ' : '')."".NB_EOL; foreach ($row as $k => $v) { - echo (OUT_EOL ? ' ' : '')."<$k>".OUT_EOL; + echo (NB_EOL ? ' ' : '')."<$k>".NB_EOL; } - echo (OUT_EOL ? ' ' : '')."".OUT_EOL; + echo (NB_EOL ? ' ' : '')."".NB_EOL; } # < Functions /****************************************************************************/ -#die("A OUT_EOL B \n"); +#die("A NB_EOL B \n"); if (empty($argv) or $argv[1] != 'test') return true; $data = array( 'a' => 1, diff --git a/lib/php/page.php b/lib/php/page.php index 4a356a73..a3aac561 100644 --- a/lib/php/page.php +++ b/lib/php/page.php @@ -163,7 +163,7 @@ class Page extends nb { . "" ; } - return join(PHP_EOL,$tags); + return join(NB_EOL,$tags); return '' . '<' . $tag . ($attrs ? " $attrs" : "") @@ -178,7 +178,7 @@ class Page extends nb { if (is_array($debug) or is_object($debug)) $debug = print_r($debug,true); if (preg_match('/ml$/',$this->content_type)) { #echo ""; - echo "
".htmlentities($debug)."
".PHP_EOL; + echo "
".htmlentities($debug)."
".NB_EOL; } else { echo "DEBUG: $debug\n"; @@ -200,11 +200,11 @@ class Page extends nb { echo $this->doctype(); if (!$this->lang) { - echo ' '.PHP_EOL; + echo ' '.NB_EOL; } elseif ($this->html5) { - echo ' '.PHP_EOL; + echo ' '.NB_EOL; } else { - echo ''.PHP_EOL; + echo ''.NB_EOL; } } @@ -217,10 +217,10 @@ class Page extends nb { echo 'body_class) ? '' : ' class="'.trim($this->body_class).'"') .(empty($this->body_id) ? '' : ' id="'.trim($this->body_id).'"') - .'>' . PHP_EOL; + .'>' . NB_EOL; - if ($this->h1) echo $this->tag('h1',$this->h1).PHP_EOL; - elseif ($this->title) echo $this->tag('h1',$this->title).PHP_EOL; + if ($this->h1) echo $this->tag('h1',$this->h1).NB_EOL; + elseif ($this->title) echo $this->tag('h1',$this->title).NB_EOL; } return true; @@ -230,8 +230,8 @@ class Page extends nb { function end() { if (preg_match('/ml$/',$this->content_type)) { - echo '' . PHP_EOL; - echo '' . PHP_EOL; + echo '' . NB_EOL; + echo '' . NB_EOL; } } @@ -273,16 +273,16 @@ class Page extends nb { $doctype = ''; if (preg_match('/frame/',$content_type)) { - $doctype = ''.PHP_EOL; + $doctype = ''.NB_EOL; } elseif (preg_match('/xhtml/',$content_type)) { - $doctype = ''.PHP_EOL; + $doctype = ''.NB_EOL; } elseif (preg_match('/xml/',$content_type)) { - $doctype = 'charset).'"?>'.PHP_EOL; //charset).'"?>'.NB_EOL; //html5) { # See: http://www.w3.org/TR/html-markup/elements.html $doctype = ''; } else { - $doctype = ''.PHP_EOL; + $doctype = ''.NB_EOL; } return $doctype; @@ -291,42 +291,42 @@ class Page extends nb { function head() { $head = ''; - #$head .= ''.PHP_EOL; return $head; + #$head .= ''.NB_EOL; return $head; - if ($this->title) $head .= $this->tag('title',$this->title) . PHP_EOL; + if ($this->title) $head .= $this->tag('title',$this->title) . NB_EOL; if (preg_match('/tml$/',$this->content_type)) { - if ($this->charset) $head .= ''.PHP_EOL; + if ($this->charset) $head .= ''.NB_EOL; - $head .= ''.PHP_EOL; + $head .= ''.NB_EOL; foreach ($this->to_array($this->css) as $v) { - $head .= ''.PHP_EOL; + $head .= ''.NB_EOL; } if ($this->css_code) $head .= '' - . '' . PHP_EOL + . ' -->' . NB_EOL ; foreach ($this->to_array($this->js) as $v) { - $head .= '' . PHP_EOL; + $head .= '' . NB_EOL; } if ($this->js_code) $head .= '' - . '' . PHP_EOL + . ' -->' . NB_EOL ; } - foreach ($this->to_array($this->head) as $h) $head .= $h.PHP_EOL; + foreach ($this->to_array($this->head) as $h) $head .= $h.NB_EOL; if ($head) { - $head = ''.PHP_EOL.$head.''.PHP_EOL; + $head = ''.NB_EOL.$head.''.NB_EOL; } return $head; -- 2.47.3