<?php
+$CONF = array();
+require_once(dirname(__FILE__).'/dbs/postfix.php');
+require_once(dirname(__FILE__).'/dbs/nb.php');
+require_once(dirname(__FILE__).'/dbs/rent.php');
+require_once(dirname(__FILE__).'/dbs/puppetdb.php');
/*
*/
-$CONF = array (
- 'nb' => array (
+ /*
+ $CONF2 = array(
+ array (
+ 'host' => 'big.cascais.loc',
+ 'title' => 'Mysql Izi on Big',
+ 'default_table' => 'process',
+ 'user' => 'nico',
+ 'name' => 'izi',
+ 'tables' =>
+ array (
+ 'site' =>
+ array (
+ 'replace' =>
+ array (
+ 'idlang' => 'lang.id',
+ ),
+ ),
+ ),
+ 'type' => 'mysql',
+ ),
+ array (
'host' => 'admin.izideal.vpn',
'type' => 'mysql',
'name' => 'nb',
'user' => 'nico',
- '_import' => '_nico',
+ 'Title' => 'Rent',
+ 'notice' => 'Micro foncier 4BE',
'default_table' => 'rent',
- 'tables' => array(
- 'rent' => array(
+ 'tables' =>
+ array (
+ 'place' =>
+ array (
+ 'replace' =>
+ array (
+ 'id' => 'addr.addr',
+ ),
+ ),
+ 'rent' =>
+ array (
'orderby' => 'start desc, end desc',
- 'replace' => array (
+ 'replace' =>
+ array (
'idtenant' => 'tenant.name',
'idplace' => 'addr.addr',
),
- 'row_parse_pre' => function(&$r) {
- #extra: "rent * (1 + ( strftime('%m',end)+12*strftime('%Y',end) ) - ( strftime('%m',start)+12*strftime('%Y',start) ))"
- #$r['rent_year'] = $r['rent'] * (1 + ( date('m',strtotime($r['end']))+12
- $r['Total'] = $r['rent'] + $r['charge'];
- if (1) $r['rent_year'] = sprintf('%.2f',$r['rent'] * (1 +
- ( date('m',strtotime($r['end'])) + 12 * date('Y',strtotime($r['end'])) )
- -
- ( date('m',strtotime($r['start'])) + 12 * date('Y',strtotime($r['start'])) )
- ));
- },
- 'row_parse_post' => function(&$r) {
- $r['revision'] = join(' ',array(
- '<a href="template/?id=quittance.html&idplace='.$r['idplace'].'&idtenant='.$r['idtenant'].'&start=2015-04-01">quittance</a>',
- '<a href="template/?id=revision.txt&idplace='.$r['idplace'].'&idtenant='.$r['idtenant'].'&start=2015-04-01">revision</a>',
- ));
- },
+ 'row_parse_pre' =>
+ Closure::__set_state(array(
+ )),
+ 'row_parse_post' =>
+ Closure::__set_state(array(
+ )),
+ ),
+ ),
+ ),
+ array (
+ 'title' => 'Mysql Izi on Admin',
+ 'host' => 'admin.izideal.vpn',
+ 'default_table' => 'process',
+ 'user' => 'izideal',
+ 'name' => 'izi',
+ 'tables' =>
+ array (
+ 'site' =>
+ array (
+ 'replace' =>
+ array (
+ 'idlang' => 'lang.id',
+ ),
+ ),
+ ),
+ 'type' => 'mysql',
+ ),
+ array (
+ 'title' => 'Mysql Izi',
+ 'host' => 'sql.izideal.vpn',
+ 'default_table' => 'process',
+ 'user' => 'izideal',
+ 'name' => 'izi',
+ 'tables' =>
+ array (
+ 'site' =>
+ array (
+ 'replace' =>
+ array (
+ 'idlang' => 'lang.id',
+ ),
),
),
+ 'type' => 'mysql',
),
+ array (
+ 'title' => 'Puppetdb',
+ 'host' => 'big',
+ 'type' => 'pgsql',
+ 'user' => 'puppetdb',
+ 'default_table' => 'view_hosts',
+ 'tables' =>
+ array (
+ 'hosts' =>
+ array (
+ 'extras' =>
+ array (
+ 'last_compile' =>
+ array (
+ 'type' => 'text',
+ 'extra' => 'to_char(hosts.last_compile, \'YYYY-MM-DD HH:mm:ss\'::text)',
+ ),
+ 'last_freshcheck' =>
+ array (
+ 'type' => 'text',
+ 'extra' => 'to_char(hosts.last_freshcheck, \'YYYY-MM-DD HH:mm:ss\'::text)',
+ ),
+ 'updated_at' =>
+ array (
+ 'type' => 'text',
+ 'extra' => 'to_char(hosts.updated_at, \'YYYY-MM-DD HH:mm:ss\'::text)',
+ ),
+ 'created_at' =>
+ array (
+ 'type' => 'text',
+ 'extra' => 'to_char(hosts.created_at, \'YYYY-MM-DD HH:mm:ss\'::text)',
+ ),
+ 'test' =>
+ array (
+ 'type' => 'int',
+ 'extra' => 1,
+ ),
+ ),
+ ),
+ ),
+ 'name' => 'puppetdb',
+ ),
+ array (
+ 'pdo' => 'sqlite:/opt/semantico/product/releases/sem_ui/db/semantico.db',
+ 'title' => 'Semantico UI',
+ 'default_table' => 'node',
+ 'tables' =>
+ array (
+ 'node' =>
+ array (
+ 'orderby' => '(SELECT value FROM fact WHERE idnode=id AND name=\'date_install\') DESC',
+ 'replace_' =>
+ array (
+ 'iddc' => 'dc.id',
+ ),
+ ),
+ ),
+ 'replace' =>
+ array (
+ 'SELECT name FROM dc WHERE id=\'@id\'' => '.node td.iddc',
+ ),
+ 'name' => 'ui',
+ ),
+ array (
+ 'title' => 'RT',
+ 'name' => 'rt',
+ ),
+ array (
+ 'pdo' => 'sqlite:/dev/shm/crypt.db',
+ 'name' => 'crypt',
+ ),
+ array (
+ 'host' => 'admin.izideal.vpn',
+ 'user' => 'nico',
+ 'type' => 'mysql',
+ 'name' => 'wp',
+ )
);
+*/
?>
wp:
host: admin.izideal.vpn
+ type: mysql
_import:
- _nico
- - _mysql
-___nb:
- host: admin.izideal.vpn
- _import:
- - _nico
- - _mysql
- #- _rent
-
-puppetdb:
- #pdo: 'pgsql:host=big;dbname=puppetdb;user=puppetdb;password='
- title: Puppetdb
- host: big
- type: pgsql
- user: puppetdb
- default_table: view_hosts
- tables:
- hosts:
- extras:
- last_compile:
- type: text
- extra: to_char(hosts.last_compile, 'YYYY-MM-DD HH:mm:ss'::text)
- last_freshcheck:
- type: text
- extra: to_char(hosts.last_freshcheck, 'YYYY-MM-DD HH:mm:ss'::text)
- updated_at:
- type: text
- extra: to_char(hosts.updated_at, 'YYYY-MM-DD HH:mm:ss'::text)
- created_at:
- type: text
- extra: to_char(hosts.created_at, 'YYYY-MM-DD HH:mm:ss'::text)
- test:
- type: "int"
- extra: 1
-
ui:
pdo: 'sqlite:/opt/semantico/product/releases/sem_ui/db/semantico.db'
title: 'Semantico UI'
replace:
"SELECT name FROM dc WHERE id='@id'": ".node td.iddc"
-ui-mem:
- pdo: 'sqlite:/dev/shm/semantico.db'
- _import: ui
-
rt:
pdo: 'pgsql:host=db.rt.semantico.net;port=5432;dbname=rtdb;user=rtuser;password='
title: 'RT'
-rent:
- order: 1
- pdo: 'sqlite:/opt/rent/rent.db'
- _import:
- - _rent
-
-_rent:
- title: 'Rent'
- notice: 'Micro foncier 4BE'
- default_table: 'rent'
-
-# NEW- NB 10.01.16
- tables:
-
-# NB 08.03.16 template:
-# NB 08.03.16 View: "'<a href=\"/template/'||id||'\">'||id||'</a>'"
-
- place:
- replace:
- id: addr.addr
-
- rent:
- orderby: "start desc, end desc"
- replace:
- idtenant: tenant.name
- idplace: addr.addr
- extras:
- total:
- type: "float(8,2)"
- extra: "ROUND(rent+charge,2)"
- rent_year:
- type: "float(8,2)"
- extra: "rent * (1 + ( strftime('%m',end)+12*strftime('%Y',end) ) - ( strftime('%m',start)+12*strftime('%Y',start) ))"
- #extra: "rent * (1 + ( date_format(end,'%m')+12*date_format(end,'%Y') ) - ( date_format(start,'%m')+12*date_format(start,'%Y') ))"
- #revision: (SELECT GROUP_CONCAT('<a href="template/?id='||id||'&idplace='||idplace||'&idtenant='||idtenant||'&start='||start||'">'||substr(id,0,instr(id,'.'))||'</a>',' ') FROM template)
-
izi:
#pdo: 'mysql:host=admin.izideal.com;port=3306;dbname=izi'
title: Mysql Izi
default_table: process
user: izideal
name: izi
- _import:
- - _mysql
+ type: mysql
tables:
site:
replace:
media:
host: media.izideal.vpn
name: mysql
+ type: mysql
_import:
- - _mysql
- _nico
postfix:
title: Postfix on Izideal
host: media.izideal.vpn
user: postfix
- _import:
- - _mysql
+ type: mysql
public $name;
public $type;
public $tables;
+ public $row_parse; # Function to call in rows()
# Objects
# NB 28.03.16 public $table;
return '"'.$value.'"';
}
-# TODEL - NB 01.04.16
-/*
- function out($row,$head=false) {
- if (!$this->p('header',1) and $head) $head = false;
- $f = $this->p('format','json');
- #if (preg_match('/yaml|yml/',$f)) bye($this->yaml_encode($this->object2array($this->fields())));
- $mime = $this->print_header($f);
-
- #echo $row.NB_EOL;
- #bye($f); return true;
- 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).NB_EOL; }
- elseif ($f == 'csv') {
- #if (is_object($data)) echo "$data\n";
- #$isHash = array_values($row) !== $row;
- if ($head) {
- if ($head === true) {
- $first = self::ar_first($row);
- $first = array_keys($first);
- } else {
- $first = $head;
- }
- self::out($first);
- }
- if (is_scalar($row)) {
- echo $row."\n";
- return true;
- }
- if (is_array($row) and !self::is_hash($row)) {
- echo join("\t",array_values($row))."\n";
- return true;
- }
- $type = 0;
- foreach ($row as $k => $v) {
-
-# NB 06.03.16 if ($type == 1 or $k === 0) {
-# NB 06.03.16 # Normal array
-# NB 06.03.16 $type = 1;
-# NB 06.03.16 echo "$v\n";
-# NB 06.03.16
-# NB 06.03.16 } elseif ($type == 2 or self::is_hash($row[$k])) {
-# NB 06.03.16 echo ($type === 2 ? "\t" : "").$v;
-# NB 06.03.16 $type = 2;
-# NB 06.03.16
-# NB 06.03.16 } elseif ($type == 3 or is_scalar($v)) {
-# NB 06.03.16 $type = 3;
-# NB 06.03.16 echo "$v\n";
-# NB 06.03.16
- if (is_scalar($v)) {
- echo "$v\n";
- } else {
- #debug($v);
- echo join("\t",array_values($v))."\n";
- }
- #} elseif ($type == 2 or $k === 0) {
-# NB 06.03.16 elseif (nb::is_hash($v)) {
-# NB 06.03.16 echo join("\t",array_values($v);
-# NB 06.03.16 }
- #else echo join("\t",array_values($v))."\n";
- }
- #echo json_encode($row).NB_EOL;
- if ($type === 2) {
- echo "\n";
- }
- }
- 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.NB_EOL); }
- //else { echo($row.NB_EOL); }
- else{ echo var_export($row,true); }
-
- return true;
-
- }
-*/
-
public function out2($rows,$head=array()) {
- #if (is_scalar($head)) bye(var_dump($head,true));
-
-# NB 09.03.16 elseif (count($rows)) {
-# NB 09.03.16 $first = self::ar_first($row);
-# NB 09.03.16 #if (self::is_hash($first))
-# NB 09.03.16 $head = array($head);
-# NB 09.03.16 }
out::rows($this->p('format',out::php_cli() ? 'csv' : 'table'),$rows,$head);
return true;
foreach ($this->tables() as $t) { $rows[] = $t->infos(); }
$return = $this->out2($rows);
+ } elseif ($action == 'db.conf') {
+ $return = $this->out2(array_values($this->conf));
+
} elseif ($action == 'db.dbs' or $action == 'dbs') {
if (self::p('hash')) $return = $this->out2($this->conf);
else $return = $this->out2($this->dbs,"name");
- } elseif (preg_match('/^db\.(\w+)/',$action,$m)) {
- if ($rows = $this->$m[1]()) $return = $this->out2($rows,(is_scalar($rows) ? $m[1] : array()));
+ } elseif ($r=self::class_action_out($this,$action)) {
+ return $r;
} elseif($table) {
if ($r=$table->action($action)) $return = $r;
# Sort
self::hksort($h,'order');
+ #uasort($h,create_function('$a,$b','$a_=isset($a["'.$k.'"])?$a["'.$k.'"]:-1;$b_=isset($b["'.$k.'"])?$b["'.$k.'"]:-1; return($b_-$a_);'));
if (!$h) return false;
#self::bye($h['puppetdb']);
#if ($first !== false) debug ( self::ar_first($h) );
# See: http://php.net/manual/en/pdostatement.bindparam.php
if ($name === null) $name = ':'.$this->name;
#debug($this->name . " | $name | $value | $this->type | " . $this->size()."<br/>");
- if (strpos($this->type,'float') !== false) {
+# NB 11.04.16 if (strpos($this->type,'float') !== false) {
+ if ($this->numeric() and strpos($this->type,'int') === false) {
$value = strval($value);
return $sth->bindParam($name, $value, PDO::PARAM_STR);
}
public $replace = array(); # replace by javascript
public $extras = array();
public $row_parse_pre; # Function to call in rows()
+ public $row_parse_post; # Function to call in rows()
public $count;
public $engine;
public $created;
while ($row = $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT)) {
$count++;
+ $call = null;
+
+ if (!empty($this->db()->row_parse)) {
+ $call = $this->db()->row_parse; $call($row);
+ }
if (!empty($this->row_parse_pre)) {
$call = $this->row_parse_pre; $call($row);
if ($count === 1) {
if ($opt['is_html']) echo $this->html_rows_top();
- if (!empty($this->row_parse_pre) or !empty($this->row_parse_post)) {
+ if ($call) {
foreach (array_keys($row) as $name) {
if (!$this->fields($name)) {
$this->fields[$name] = new Field($name);
$this->out2($e);
return true;
- } elseif (preg_match('/^table\.(\w+)/',$action,$m)) {
- if ($rows = $this->$m[1]() and !empty($rows)) {
- $return = $this->out2($rows,(is_scalar($rows) ? $m[1] : array()));
- } else {
- $return = true;
- }
+ } elseif ($r=self::class_action_out($this,$action)) {
+ return $r;
+# NB 10.04.16 } elseif (preg_match('/^table\.(\w+)/',$action,$m)) {
+# NB 10.04.16 if ($rows = $this->$m[1]() and !empty($rows)) {
+# NB 10.04.16 $return = $this->out2($rows,(is_scalar($rows) ? $m[1] : array()));
+# NB 10.04.16 } else {
+# NB 10.04.16 $return = true;
+# NB 10.04.16 }
} elseif ($this->p('format') and !preg_match('/^(table|div)$/',$this->p('format'))) {
'html' => 'class="tables" name="table" id="table"',
'selected' => $this->p('table'),
'prettyText' => true,
+ 'sort' => 'natcasesort',
));
$r .= '</span>';
'html' => 'class="dbs" id="db" name="db" onchange="document.location=\''.preg_replace('/\?.*$/','',$_SERVER['REQUEST_URI']).'?db=\'+this.value"',
'selected' => self::p('db'),
'prettyText' => true,
+ 'sort' => 'natcasesort',
));
$r .= '</span>';
}
'html' => 'class="format" name="format" id="format"',
'selected' => $this->p('format'),
'prettyText' => true,
+ 'sort' => 'natcasesort',
));
$r .= '</span>';
$html .= '</option>'.NB_EOL;
}
+ if (!empty($opt['sort'])) {
+ if (is_bool($opt['sort'] )) natcasesort($data);
+ else $opt['sort']($data);
+ }
+
foreach ($data as $d) {
if (is_array($d)) {
'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', 'Ā' => 'A', 'ā' => 'a', 'Ă' => 'A', 'ă' => 'a', 'Ą' => 'A', 'ą' => 'a', 'Ç' => 'C', 'ç' => 'c', 'Ć' => 'C', 'ć' => 'c', 'Ĉ' => 'C', 'ĉ' => 'c', 'Ċ' => 'C', 'ċ' => 'c', 'Č' => 'C', 'č' => 'c', 'Ð' => 'D', 'ð' => 'd', 'Ď' => 'D', 'ď' => 'd', 'Đ' => 'D', 'đ' => 'd', 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'Ē' => 'E', 'ē' => 'e', 'Ĕ' => 'E', 'ĕ' => 'e', 'Ė' => 'E', 'ė' => 'e', 'Ę' => 'E', 'ę' => 'e', 'Ě' => 'E', 'ě' => 'e', 'Ĝ' => 'G', 'ĝ' => 'g', 'Ğ' => 'G', 'ğ' => 'g', 'Ġ' => 'G', 'ġ' => 'g', 'Ģ' => 'G', 'ģ' => 'g', 'Ĥ' => 'H', 'ĥ' => 'h', 'Ħ' => 'H', 'ħ' => 'h', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'Ĩ' => 'I', 'ĩ' => 'i', 'Ī' => 'I', 'ī' => 'i', 'Ĭ' => 'I', 'ĭ' => 'i', 'Į' => 'I', 'į' => 'i', 'İ' => 'I', 'ı' => 'i', 'Ĵ' => 'J', 'ĵ' => 'j', 'Ķ' => 'K', 'ķ' => 'k', 'ĸ' => 'k', 'Ĺ' => 'L', 'ĺ' => 'l', 'Ļ' => 'L', 'ļ' => 'l', 'Ľ' => 'L', 'ľ' => 'l', 'Ŀ' => 'L', 'ŀ' => 'l', 'Ł' => 'L', 'ł' => 'l', 'Ñ' => 'N', 'ñ' => 'n', 'Ń' => 'N', 'ń' => 'n', 'Ņ' => 'N', 'ņ' => 'n', 'Ň' => 'N', 'ň' => 'n', 'ʼn' => 'n', 'Ŋ' => 'N', 'ŋ' => 'n', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ø' => 'O', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ø' => 'o', 'Ō' => 'O', 'ō' => 'o', 'Ŏ' => 'O', 'ŏ' => 'o', 'Ő' => 'O', 'ő' => 'o', 'Ŕ' => 'R', 'ŕ' => 'r', 'Ŗ' => 'R', 'ŗ' => 'r', 'Ř' => 'R', 'ř' => 'r', 'Ś' => 'S', 'ś' => 's', 'Ŝ' => 'S', 'ŝ' => 's', 'Ş' => 'S', 'ş' => 's', 'Š' => 'S', 'š' => 's', 'ſ' => 's', 'Ţ' => 'T', 'ţ' => 't', 'Ť' => 'T', 'ť' => 't', 'Ŧ' => 'T', 'ŧ' => 't', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 'Ũ' => 'U', 'ũ' => 'u', 'Ū' => 'U', 'ū' => 'u', 'Ŭ' => 'U', 'ŭ' => 'u', 'Ů' => 'U', 'ů' => 'u', 'Ű' => 'U', 'ű' => 'u', 'Ų' => 'U', 'ų' => 'u', 'Ŵ' => 'W', 'ŵ' => 'w', 'Ý' => 'Y', 'ý' => 'y', 'ÿ' => 'y', 'Ŷ' => 'Y', 'ŷ' => 'y', 'Ÿ' => 'Y', 'Ź' => 'Z', 'ź' => 'z', 'Ż' => 'Z', 'ż' => 'z', 'Ž' => 'Z', 'ž' => 'z'
));
}
+
+ public static function class_action_out($class,$action) {
+ $class_name = strtolower(get_class($class));
+
+ if (!preg_match('/^'.$class_name.'\.(\w+)/',$action,$m)) return false;
+ $name = $m[1];
+
+ $rows = array();
+ if (in_array($name,get_class_methods($class))) $rows = $class->$name();
+ else $rows = $class->$name;
+ if (!$rows) return false;
+
+ return out::rows(self::p('format',self::php_cli() ? 'csv' : 'table'),$rows,(is_scalar($rows) ? $name : array()));
+ return self::object2array($rows);
+ return $class->out2(self::object2array($rows),(is_scalar($rows) ? $name : array()));
+ }
} # < Class
#die(self::ext2mime('csv'));
?>
#'php' => array( 'function' => function(&$r) {var_dump($r);},),
'php' => array(
#'enclose' => array('$VAR=array(',');'),
- 'enclose' => array('$CONF = ',';'),
- #'eol' => NB_EOL,
+ 'enclose' => array('$CONF = array('.NB_EOL,NB_EOL.');'),
+ 'eol' => NB_EOL,
'rec' => ',',
#'function' => function(&$r) { echo preg_replace('/[\r\n]/','',var_dump($r,true));},
#'function' => function(&$r) {print_r($r);}
#'function' => function(&$r) {var_dump($r);}
- 'function' => function(&$r) { echo preg_replace('/(=>\s*)\n\s+/m','\1',var_export($r,true));}
+ 'function' => function(&$r) {
+ return var_export($r);
+ echo preg_replace(array(
+ '/(=>\s*)\n\s+/m',
+ '/\),\s*array/m',
+ ),array(
+ '\1',
+ "),".NB_EOL."array"
+ ),var_export($r,true));
+ }
#'function' => function(&$r) { echo preg_replace('/\n/','',var_export($r,true));}
#'function' => function(&$r) {var_export($r);}
),
foreach ($row as $k => $v) {
echo sprintf("%"
.(!empty($o['head_max_len']) ? '-'.($o['head_max_len']+1) : '')
- ."s: %s\n",$k,self::escape($v)
+ ."s: %s\n",$k,preg_replace('/\n(\w)/m'
+ ,"\n".str_repeat(' ',(empty($o['head_max_len']) ? strlen($k) : $o['head_max_len']+1)+2).'\1'
+ ,self::format($v))
);
}
- #foreach ($row as $k => $v) { echo "$k: ".self::escape($v)."\n"; }
return true;
}
return;
}
- public static function format($v) {
+ public static function format($v,$type=null) {
+ if ($type === null) $type = self::$type;
$is_scalar = is_scalar($v);
$v = self::scalar($v);
if ($v==='') $is_scalar = true;
foreach ($row as $k => $v) {
- $v = out::escape($v);
+ $v = out::format($v);
# Inside tag, ex: label
if (isset($o['tag_key'])) {
public static $charset = 'utf-8';
public static $lang = 'en';
public static $html5 = true;
+ public static $expires; # Seconds to cache, no cache if 0, no head if null
public $title = '';
public $css = array();
return htmlspecialchars($v,$replace_flags,$charset);
}
+ /*
+ * Function: tag
+ * Return html code for a tag
+ */
public static function tag($tag,$content='',$attrs='') {
# Extract attrs from tag
$attrs = trim($attrs.' '.$m[2]);
}
+ if (is_array($attrs)) {
+ $attrs = array_map(function($k,$v){return "$k=\"$v\"";}
+ ,array_keys($attrs)
+ ,array_values($attrs)
+ );
+ }
+
if ($content===null) {
self::tag_end($tag);
return '<' . $tag . ($attrs ? " $attrs" : "") . '>';
}
public static function headers_cache($seconds_to_cache=3600) {
+ if ($seconds_to_cache === 0) return headers_no_cache();
$ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";
header("Expires: $ts");
header("Pragma: cache");
#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);
+
if (self::p('download-attachment')) header('Content-Disposition: attachment; filename="'
. $this->title2filename($this->title,self::$content_type)
);
}
if (is_array($v)) {
- $nav[] = '<a href="'.$v[1].'">'.$v[0].'</a>';
- $title[] = $v[0];
+
+ if (count($v)==3) {
+ $title[] = $v[0];
+ $nav[] = self::tag('a',$v[1],'href="'.$v[2].'"');
+ } else {
+ $title[] = $v[0];
+ $nav[] = self::tag('a',$v[0],'href="'.$v[1].'"');
+ }
+
} else {
- $nav[] = '<span>'.$v.'</span>';
$title[] = $v;
+ $nav[] = self::tag('span',$v);
+
}
}
} elseif ($action == 'page.phpinfo' or $action == 'phpinfo') {
echo $this->phpinfo(); return true;
- } elseif (preg_match('/^page\.(\w+)/',$action,$m)) {
-#bye($this->$m[1]());
- if ($rows = $this->$m[1]()) return $this->out2($rows,(is_scalar($rows) ? $m[1] : array()));
+ } elseif ($r=self::class_action_out($this,$action)) {
+ return $r;
}