From: Nicolas Boisselier Date: Mon, 7 Oct 2024 10:27:06 +0000 (+0200) Subject: update to new php version X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=bff395a0a59388a58473ebcd4e718ed034cd482e;p=nb.git update to new php version --- diff --git a/lib/php/db/field.php b/lib/php/db/field.php index 93d4a10c..8019eb0f 100644 --- a/lib/php/db/field.php +++ b/lib/php/db/field.php @@ -32,9 +32,10 @@ class field extends nb { public function __construct($attr=[]) { if (is_scalar($attr)) $attr = ['name'=>$attr]; - foreach ($attr as $k => $v) { $this->$k = $v; } - #if (isset($attr['type'])) debug($attr['type']); - #debug($this->name.'='.$this->type.nb::debug_backtrace_msg()); + # NB 07.10.24 foreach ($attr as $k => $v) { $this->$k = $v; } + foreach ($attr as $k => $v) { + if (property_exists($this,$k)) $this->$k = $v; + } } public function default2str($default=null) { diff --git a/lib/php/ldap.php b/lib/php/ldap.php index de8e9595..bfe82b47 100644 --- a/lib/php/ldap.php +++ b/lib/php/ldap.php @@ -17,7 +17,10 @@ class Ldap { public function base() { return $this->base; } public function __construct($opt = []) { - foreach ($opt as $k => $v) if ((string)$v !== '') $this->$k = $v; + # NB 07.10.24 foreach ($opt as $k => $v) if ((string)$v !== '') $this->$k = $v; + foreach ($opt as $k => $v) { + if ((string)$v !== '' and property_exists($this,$k)) $this->$k = $v; + } } public function __destruct() { diff --git a/lib/php/nb.php b/lib/php/nb.php index 175c97cd..5d28310c 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -42,9 +42,6 @@ class Nb { public function __sleep() { return(get_class_vars(get_class($this))); # get all -# NB 09.04.16 return array_keys((array)$this); - #debug((array)$this); # publics + private in a weird way ! - #debug(get_object_vars($this)); # non static } #public function __wakeup() { } @@ -581,7 +578,6 @@ class Nb { } public static function php_cli() { -# NB 05.03.16 define('NB_CLI', PHP_SAPI === 'cli'); static $php_cli; if ($php_cli===null or $php_cli==='') $php_cli= ( !isset($_SERVER['SERVER_SOFTWARE']) && (php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0)) diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index bf717f4f..6f6dd501 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -194,9 +194,6 @@ class DbQ extends nb { public function ldap($table='',$attrs=[]) { $this->deniedUnless($this->perm >= self::ADMIN); -# NB 28.01.18 if (!$table) $table = $this->params['table']; -# NB 28.01.18 if (!$attrs) $attrs = ($this->params['action'] ? explode(',',$this->params['action']) : []); - require_once(NB_ROOT.'/lib/php/ldap.php'); #debug($GLOBALS['DBQ_LDAP']); $dn = join(',',$attrs); @@ -452,8 +449,10 @@ class DbQ extends nb { } private function vi_extract_fields() { - $sep = $this->param_args_sep . $this->param_args_sep; - #$sep ='@'; +#debug($_REQUEST); + #bye($this->params); + # NB 07.10.24 why double ??? $sep = $this->param_args_sep . $this->param_args_sep; + $sep = $this->param_args_sep; $fields = []; if (strpos($this->params['args'],$sep) !== false) { @@ -465,22 +464,28 @@ class DbQ extends nb { } public function vi($add=false) { - $all = []; $nosql = $this->db->conf_type('nosql'); $fields = $this->vi_extract_fields(); + $all = []; $keys = $this->table->fields_keys($all); if (!$keys) $keys = $all; $keys = array_keys($keys); + $values = []; # NB 26.08.24 $values = ($_SERVER['REQUEST_METHOD'] == 'POST') ? $_POST : explode($this->param_args_sep,$this->params['args']); if (!empty($_SERVER['REQUEST_METHOD']) and $_SERVER['REQUEST_METHOD'] == 'POST') { $values = $_POST; + } elseif (!empty($_GET)) { } elseif($this->params['args']) { - $values = explode($this->param_args_sep,$this->params['args']); - } else { - $values = $_GET; + # NB 07.10.24 $values = explode($this->param_args_sep,$this->params['args']); + $args = explode($this->param_args_sep,$this->params['args']); + # NB 07.10.24: Handle case: /DB/TABLE/vi/VALUE + for ($i=0;$i$v) { @@ -873,7 +878,8 @@ class DbQ extends nb { } public function error($admin_msg='') { - header('Content-type: text/plain'); + $type = $this->is_html ? 'text/html' : 'text/plain'; + header("Content-type: $type"); $msg = '500 Internal Server Error'; if (empty($_SERVER['SERVER_PROTOCOL'])) $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.0'; @@ -1443,10 +1449,9 @@ EOF; $this->page_table_ls($m[1]); } elseif ($action == 'vi' - # NB 29.08.24 or $action!="" + # NB 29.08.24 or $action!="" # default action will be vi ) { if ($action != 'vi') $this->params['args'] = $action; - #bye($this->params); $this->deniedUnless($this->perm >= self::READ); $this->page($this,'vi'); @@ -1515,6 +1520,7 @@ EOF; #die($_SERVER['REQUEST_URI']."\n"); #die($_SERVER['QUERY_STRING']."\n"); #phpinfo(); exit; +#debug($this->params['args']); $DBQ = new DbQ([ 'run' => true, 'base' => (($base = Dbq::client_header('Dbq-Base')) ? preg_replace(',/+$,','',$base) : ''),