From: Nicolas Boisselier Date: Thu, 4 Jan 2018 01:07:16 +0000 (+0000) Subject: www/dbq/etc/nginx.conf X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=4cf5cd5b733214235eac12f4030271b64b0ad953;p=nb.git www/dbq/etc/nginx.conf --- diff --git a/lib/php/db.php b/lib/php/db.php index fd4fa4bb..67846b75 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -342,8 +342,6 @@ class Db extends nb { return $sth->fetchAll($style); } - /* - */ function query2a($sql) { $r = $this->conn->query($sql,PDO::FETCH_COLUMN); return $r ? $r->fetch() : $r; diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 16276729..15af5d22 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -868,13 +868,16 @@ Class Table extends nb { return ','.join(',',$select); } - /****************************************************************** - Html Output - ******************************************************************/ + public function rows_count() { + $opt = [ 'count' => 1 ]; + return $this->db()->row($this->rows_sql($opt)); + } + public function rows_sql(&$opt=[]) { if (isset($this->orderby)) self::pdef('orderby',$this->orderby); if (self::p('order')) self::pset('orderby',self::p('orderby').' '.self::p('order')); # from Wordpress + $count = empty($opt['count']) ? 0 : 1; // // Select @@ -882,6 +885,7 @@ Class Table extends nb { if (stripos($this->name,' ') !== false) { $sql = $this->name; $limit = $where = ''; + if ($count) $sql = "SELECT count(*) FROM ".$this->sql_name(); } else { @@ -899,12 +903,12 @@ Class Table extends nb { } - $sql = "SELECT ".trim( $select_count[0].' '.join(',',$select_fields) ). $this->select_extras(); + $sql = $count ? "SELECT count(*)" : "SELECT ".trim( $select_count[0].' '.join(',',$select_fields) ). $this->select_extras(); $sql .= " FROM ".$this->sql_name(); $sql .= $where; #bye($sql); - if ($this->p('orderby')) $sql .= ' ORDER BY '.$this->p('orderby'); + if ($this->p('orderby') and !$count) $sql .= ' ORDER BY '.$this->p('orderby'); if ($limit = $this->db()->limit) { $sql .= ' LIMIT '.$limit; @@ -914,6 +918,8 @@ Class Table extends nb { } + if ($count) return $sql; + // // Get results // diff --git a/lib/php/page.php b/lib/php/page.php index 07754a0c..1900cc1f 100644 --- a/lib/php/page.php +++ b/lib/php/page.php @@ -366,7 +366,6 @@ class Page extends nb { public function headers() { if (self::php_cli()) return false; - #header('Content-type: ' . self::$content_type); header('Content-type: '.self::$content_type . (($c = strtoupper ( self::$charset )) ? "; charset=$c" : "")); if (isset($this->expires)) self::headers_cache($this->expires); @@ -374,7 +373,6 @@ class Page extends nb { if (self::p('download-attachment')) header('Content-Disposition: attachment; filename="' . $this->title2filename($this->title,self::$content_type) .'"'); - #self::headers_cache(); return true; } @@ -402,8 +400,6 @@ class Page extends nb { public function head() { $head = ''; - #$head .= ''.NB_EOL; return $head; - if ($this->title) $head .= $this->tag('title',$this->title) . NB_EOL; if (preg_match('/tml$/',self::$content_type)) { @@ -466,7 +462,7 @@ class Page extends nb { } } - #debug($urls); + return $urls; } @@ -485,7 +481,6 @@ class Page extends nb { } public static function nav_parse($array) { - #$v = &$sep; $title = []; $nav = []; $hash = []; diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index e825383a..9e0073e6 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -74,6 +74,7 @@ class DbQ extends nb { '/default'.(PRODUCTION ? '.min' : '').'.js', ]; public $ext; + public $expires; # Others public $expode_args = '&'; @@ -105,7 +106,8 @@ class DbQ extends nb { 'title', 'css', 'js', - 'format_html_ua_exp' + 'format_html_ua_exp', + 'expires', ] as $k) { $env = 'DBQ_'.strtoupper($k); @@ -141,6 +143,7 @@ class DbQ extends nb { 'sep' => $this->sep_title, #'body_class' => 'fixed', ]); + if (isset($this->expires)) $this->page->expires = $this->expires; if ($run) $this->run(); } @@ -1176,6 +1179,9 @@ EOF; } elseif ($action == 'sql') { $this->page(['sql'=>$this->table->sql()]); + } elseif ($action == 'count') { + $this->page(['count'=>$this->table->rows_count()]); + } elseif ($action == 'fields') { $this->page($this->table,'fields_rows'); diff --git a/www/dbq/etc/nginx.conf b/www/dbq/etc/nginx.conf index 768253af..7bc19fb7 100644 --- a/www/dbq/etc/nginx.conf +++ b/www/dbq/etc/nginx.conf @@ -54,4 +54,7 @@ location ~ /index\.php$ { if ($DBQ_ENVS = "") { set $DBQ_ENVS ""; } fastcgi_param DBQ_ENVS $DBQ_ENVS; + + if ($DBQ_EXPIRES = "") { set $DBQ_EXPIRES ""; } + fastcgi_param DBQ_EXPIRES $DBQ_EXPIRES; }