]> git.nbdom.net Git - nb.git/commitdiff
etc/dbq/pub.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 7 Jan 2018 04:48:15 +0000 (04:48 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 7 Jan 2018 04:48:15 +0000 (04:48 +0000)
etc/dbq/pub.php
lib/php/db.php
lib/php/db/table.php
lib/php/maps.php
www/dbq/dbq.php

index 3fdcec2648bb239d451daad340be53d1c2670b9e..16f7e092feb30a725e24fabf99b241edde74ac91 100644 (file)
@@ -1,18 +1,8 @@
 <?php
 require_once(realpath(dirname(__FILE__).'/../../lib/php/maps.php'));
-function pub_map(&$r) {
-       debug($r);
-       if (empty($r['latitude'])) return;
-       if (empty($r['longiture'])) return;
-       $r['maps'] = '<a href="'.Maps::link($r['latitude'],$r['latitude']).'">'
-               .Maps::img($r['latitude'],$r['latitude'])
-       .'</a>';
-}
 
+$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); },
 ];
 ?>
index 3db5c74867f67ad45a833af041f94c622a0c0efe..0369108689ce47017ad1115beaba6fc131e6794c 100644 (file)
@@ -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;
index 3d517ecfbb5e817f4a692541ca9be1f7ba718e3b..ec53ca03101374d5da2d2d0d3883da29cdc2de5d 100644 (file)
@@ -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()
index 58497bb43d4d9d12e33dc5f6c0b72561b2bf3ba6..1d1871e557e580e6b2b00ae6be0b62da1b2985a2 100644 (file)
@@ -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'] = '<a href="'.Maps::link($r['latitude'],$r['latitude']).'">'
+                       .'<img src="'.Maps::img($r['latitude'],$r['latitude']).'" />'
+               .'</a>';
+       }
+
 }
 ?>
index 777048b18150efc57a728707f2436075e4013ef7..8fe08cf8b1afc0a190ff5f6376061cd269937e8a 100644 (file)
@@ -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);