From 6a14d64c781ea83949bba549493ceb4620c4567a Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Sun, 7 Jan 2018 04:48:15 +0000 Subject: [PATCH] etc/dbq/pub.php --- etc/dbq/pub.php | 14 ++------------ lib/php/db.php | 3 +-- lib/php/db/table.php | 8 ++++---- lib/php/maps.php | 8 ++++++++ www/dbq/dbq.php | 33 ++++++++++++++++++++++++--------- 5 files changed, 39 insertions(+), 27 deletions(-) diff --git a/etc/dbq/pub.php b/etc/dbq/pub.php index 3fdcec26..16f7e092 100644 --- a/etc/dbq/pub.php +++ b/etc/dbq/pub.php @@ -1,18 +1,8 @@ ' - .Maps::img($r['latitude'],$r['latitude']) - .''; -} +$nohtml = (bool)( self::php_cli() or self::client_content_type('text/plain') != 'text/html' ); $DBQ['pub'] = [ - 'row_parse_post' => function(&$r,&$t) { - #debug('zaza'); - #pub_map($r); - }, + 'row_parse_post' => $nohtml ? null : function(&$r,&$t) { Maps::html($r); }, ]; ?> diff --git a/lib/php/db.php b/lib/php/db.php index 3db5c748..03691086 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -719,6 +719,7 @@ class Db extends nb { } } + unset($yaml,$DBQ); if (!$dbs) return false; @@ -777,8 +778,6 @@ class Db extends nb { # # Return # - #debug($file); - #bye($dbs['nb']); if (!$dbs) return false; if ($first !== false) $first = self::ar_first($dbs); return $dbs; diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 3d517ecf..ec53ca03 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -985,13 +985,13 @@ Class Table extends nb { // Post // if ($parser and !empty($this->row_parse_post)) { - $call = $this->row_parse_post; - $call($row,$this); + $fct = $this->row_parse_post; + $fct($row,$this); } if ($parser and !empty($this->db()->row_parse_post)) { - $call = $this->db()->row_parse_post; - $call($row,$this); + $fct = $this->db()->row_parse_post; + $fct($row,$this); } # Passed param on rows() diff --git a/lib/php/maps.php b/lib/php/maps.php index 58497bb4..1d1871e5 100644 --- a/lib/php/maps.php +++ b/lib/php/maps.php @@ -17,5 +17,13 @@ class Maps { return 'http://maps.google.com/?q='.$longitude.','.$latitude; } + public static function html(&$r) { + if (empty($r['latitude'])) return; + if (empty($r['longitude'])) return; + $r['maps'] = '' + .'' + .''; + } + } ?> diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index 777048b1..8fe08cf8 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -439,26 +439,41 @@ class DbQ extends nb { ); } + private function row_parse_pre(&$r=[]) { + static $row_parse_pre; + if (empty($r)) { + $row_parse_pre = $this->db()->row_parse_pre; + return; + } + if (empty($row_parse_pre)) return; + $row_parse_pre($r,$this->table); + } + + private function row_parse_post(&$r=[]) { + static $row_parse_post; + if (empty($r)) { + $row_parse_post = $this->db()->row_parse_post; + return; + } + if (empty($row_parse_post)) return; + $row_parse_post($r,$this->table); + } + public function table_rows($fct=null) { $this->db->limit = $this->limit(); - if (!empty($this->db()->row_parse_pre)) { - $row_parse_pre = $this->db()->row_parse_pre; - } - - if (!empty($this->db()->row_parse_post)) { - $row_parse_post = $this->db()->row_parse_post; - } + $this->row_parse_pre(); + $this->row_parse_post(); $opt = ($this->page->is('html') and $this->table_rw() ) ? [ 'row_parse_pre' => function(&$r){ - if (!empty($row_parse_pre)) $row_parse_pre($r,$this); + $this->row_parse_pre($r); $GLOBALS['dbq_args'] = urlencode( join($this->param_args_sep,$this->table->fields_keys_values($r)) ); }, 'row_parse_post' => function(&$r){ - if (!empty($row_parse_post)) $row_parse_post($r,$this); + $this->row_parse_post($r); $args = $GLOBALS['dbq_args']; $hidden = $this->form_hidden($r); -- 2.47.3