margin-bottom: 0.5em;
padding: 0.2em;
}
+.Zdb div.rows .row li {
+}
@media screen and (min-width: 400px) {
.db div.rows .row {
width: 24%;
display: inline-block;
overflow: auto;
+ min-width: 190px;
}
}
}
this.maxhw = function(s) {
- var height = $('body').height();
+ var height = $(window).height();
var width = $(window).width();
- /*
- var prev = $(s).prev();
- for (var i=0;i<50 && prev;i++) {
- prev = $(prev).prev();
- if (prev) {
- try {
- height -= that.wh(prev)[1];
- } catch (e) {
- prev = undefined;
- break;
- }
- }
- }
- */
-//console.log('total: '+width+'/'+height);
-
- //if (prev) height -= that.wh(prev)[1];
- //if (prev) height -= $(prev).height();
$(s).each(function(){
- w = width;// - that.wh(this)[0];
- h = height;// - that.wh(this)[1];
- //if ($(this).height() > h) $(this).height(h);
- //if ($(this).width() > w) $(this).width(w);
-//$(this).css('border','solid 1px red');
+ w = width;
+ h = height;
+
+ // fixed margins
+ h -= 20; w -= 20;
+
+ // remove what is above
+ var pos = $(this).position(); if (pos) h -= parseInt(pos.top);
+
+ // remove what is after
+ $(this).next().
+ add($(this).parent().next())
+ .each(function(){ h -= $(this).height(); });
+
+ // apply
$(this).height(h); $(this).width(w);
- /*
- if (1 || $(this).height() > h || $(this).width() > w) $(this).css({
- //'display': 'block',
- 'overflow': 'scroll',
- 'border': 'solid 2px blue',
- });
- */
-//console.log(w+'/'+h);
+ $(this).css('overflow','auto');
});
}
.' strlen: '.(strlen('text/html')-strlen('ml'))
);
require(dirname(__FILE__).'/nb.php');
+$_GET['var'] = 'sldkfhlsakhlshglzkdhzfgldznfdznbldzknb';
/*
$a = array('a' => 'A');
exit;
*/
-#function __f1(&$ar) { $v=$ar; return; foreach ($ar as $v) { 1; } }
-function __f1(&$ar) { return; foreach ($ar as $v) { 1; } }
-function __f2($ar) { return; foreach ($ar as $v) { 1; } }
+#function _preg_match() { preg_match('/zaza/',$_GET['var']); } nb::benchmark('_preg_match');
+#function _strpos() { strpos('zaza',$_GET['var']) !== false; } nb::benchmark('_strpos');
+#function _static() { static $var = null; if ($var===null) $var='zaza'; } nb::benchmark('_static');
+#function _global() { if ($_GLOBAL['var'] === null) $var='zaza'; } nb::benchmark('_global');
+function _empty() { empty($var); } nb::benchmark('_empty');
+function _isset() { isset($var); } nb::benchmark('_isset');
+nb::benchmark(); exit;
+
+#function __f1(&$ar) { return; foreach ($ar as $v) { 1; } }
+#function __f2($ar) { return; foreach ($ar as $v) { 1; } }
$array = array_fill(0,100000,"a");
#if (function_exists('__f1')) { function _f1() { __f1($array); } nb::benchmark('_f1'); }
#if (function_exists('__f2')) { function _f2() { __f2($array); } nb::benchmark('_f2'); }
return true;
}
- public function action($table) {
+ public function action($table=null) {
#if ($this->p('format') == 'table') $this->pset('format','');
$this->pdef('format',($this->php_cli() ? 'csv' : ''));
$actions = explode(',',$this->p('action'));
;
$return = true;
- } else {
+ } elseif($table) {
if ($r=$table->action($action)) $return = $r;
}
require_once(dirname(__FILE__).'/../config.php');
require_once(dirname(__FILE__).'/../db.php');
+if($format = out::client_type()) Db::pdef('format',$format);
+
# Param - Extract dbname from table
if (preg_match('/^(\w+)\.(.*?)$/',Db::p('table'),$m)) {
Db::pset('db',$m[1]);
if (!isset($opt['is_html'])) $opt['is_html'] = preg_match('/^(table|div)$/',$format)
? (
$this->p('header')!=="0"
- #and $this->p('download')!=="1"
)
: false
;
# Use the module out when format unknow
$out_conf = null;
if ($this->p('out') or !preg_match('/^('.join('|',
- array( 'table','div','csv','xml','json','yaml','sql' )
+ array( 'table','sql','div','_csv','_xml','_json','_yaml' )
).')$/',$format))
{
$this->params += array_values(out::$types);
if (empty($out_conf['enclose'])) $out_conf['enclose'] = array('','');
- debug('Using out module!');
+ debug('Using out module!',1);
}
Yaml
-----------------------------------------------------------------*/
public function rows_begin_yaml() { return "---\n"; }
- public function rows_rec_yaml(&$row) { return $this->yaml_encode($row); }
+ #public function rows_rec_yaml(&$row) { return $this->yaml_encode($row); }
+ public function rows_rec_yaml(&$row) { out::row(array("function"=>"out_yaml"),$row); }
public function rows_end_yaml() { return ''; }
/*-----------------------------------------------------------------
$this->rows(array( 'format' => $this->p('format')));
return true;
+
+ } elseif ($action == 'edit') {
+ return $this->html_edit();
+
+ } elseif ($this->p('table')) {
+ # NB 17.03.16 } else {
+ $this->pdef('limit','20');
+
+ // Rows
+ return $this->rows();
+
}
return false;
}
#nb::msg( !nb::php_cli()
- nb::msg( preg_match('/ml/i',nb::get_header('Content-type'))
+ nb::msg( nb::client_header('Accept','ml')
? '<pre'
.' class="err'. ( ($preff and $preff!='err') ? " $preff" : '' ).'"'
.'>'.$msg.'</pre>'.NB_EOL
if ($level and $level>DEBUG) return;
$msg = is_scalar($msg) ? $msg : print_r($msg,true);
- if (preg_match('/ml/i',nb::get_header('Content-type'))) {
+ if (nb::client_header('Accept','ml')) {
$msg = '<pre class="debug">'
.(isset($_SERVER['HTTP_HOST']) ? htmlentities($msg) : $msg)
# NB 16.12.15 .(isset($_SERVER['HTTP_HOST']) ? htmlspecialchars($msg) : $msg)
}
/*
- * Function: get_header
+ * Function: server_header
+ */
+ public static function server_header($name=null,$match=null) {
+ static $header = null;
+ if ( $header === null ) {
+ $header = array();
+ foreach (headers_list() as $h) {
+ if ( preg_match("/^([^:]+)\s*:\s+(.*?)\s*$/",$h,$m) ) $header[$m[1]] = $m[2];
+ }
+ }
+
+ # Array
+ if ($name === null) return $header;
+
+ # Search
+ if ($match) {
+ foreach ($header as $k=>$v) { if (strpos($v,$match) !== false) return $v; }
+ return false;
+ }
+
+ # Key
+ return isset($header[$name]) ? $header[$name] : null;
+ }
+
+ /*
+ * Function: client_header
* Return a client header
*/
- public static function get_header($name,$value=null) {
- foreach (headers_list() as $a) {
- if ( preg_match("/^$name:\s+(.*)/i",$a,$m) ) return $m[1];
+ public static function client_header($name=null,$match=null) {
+ static $header = null;
+ if ( $header === null ) {
+ $header = function_exists('getallheaders') ? getallheaders() : array();
}
- return null;
+
+ # Array
+ if ($name === null) return $header;
+
+ # Search
+ if ($match) {
+ foreach ($header as $k=>$v) { if (strpos($v,$match) !== false) return $v; }
+ return false;
+ }
+
+ # Key
+ return isset($header[$name]) ? $header[$name] : null;
}
/*
class Out extends Nb {
- public static $types = null; public static function types() {
+ public static $types; public static function types() {
self::$types = array(
'sql' => array(
),
- 'divs' => array(
+ 'div' => array(
'is_html' => true,
'enclose' => array("<div class=\"rows\">".NB_EOL,"</div>".NB_EOL),
'tag_enclose' => 'div class="row"',
- #'tag_head' => 'span',
- #'tag_head_enclose' => 'span class="row"',
'tag' => 'div',
+ 'tag_key' => 'label',
'function' => 'out_tag',
'head' => 'out_tag_head',
),
'center' => array(
'is_html' => true,
- 'enclose' => array("<center>".NB_EOL,"</center>".NB_EOL),
- 'tag_enclose' => 'div',
- 'tag' => 'label',
+ 'enclose' => array("<center class=\"rows\">".NB_EOL,"</center>".NB_EOL),
+ 'tag_enclose' => 'div class="row"',
+ 'tag' => 'tag',
'function' => 'out_tag',
'head' => 'out_tag_head',
),
'yaml' => array(
'enclose' => array("---\n",""),
'function' => 'out_yaml',
+ #'function' => 'yaml_emit',
),
'json' => array(
'enclose' => array('['.NB_EOL,NB_EOL.']'),
public static function begin($o,$head,$data=array()) {
#if (self::p('header')==="0") return;
- if (!empty($o['enclose'])) echo $o['enclose'][0];
+ if (isset($o['enclose'])) echo $o['enclose'][0];
if (!isset($o['head'])) return;
#var_dump($head); return;
if (isset($o['function'])) {
if (preg_match('/^out_/',$o['function'])) {
- echo $o['function']($row,$o);
+ $o['function']($row,$o);
} else {
echo $o['function']($row);
}
}
public static function concat($o) {
- if (!empty($o['rec'])) echo $o['rec'];
- if (!empty($o['eol'])) echo $o['eol'];
+ if (isset($o['rec'])) echo $o['rec'];
+ if (isset($o['eol'])) echo $o['eol'];
}
public static function end($o) {
- if (!empty($o['enclose'])) echo $o['enclose'][1];
+ if (isset($o['enclose'])) echo $o['enclose'][1];
}
public static function rows($type,&$data,$head=array()) {
if ($count) self::end($conf);
}
- public static function type($name,$key='') {
+ public static function type($name=null,$key='') {
if (empty(self::$types[$name])) return null;
$type = self::$types[$name];
if ($key) return( (array_key_exists($key,$type)) ? $type[$key] : null );
return $type;
}
+ public static function client_type() {
+ foreach (array_keys(self::$types) as $t) {
+ if (preg_match("@^\w+/$t@",self::client_header('Accept'))) return $t;
+ #if (preg_match("@^\w+/$t@",self::client_header('Accept'),$m)) bye( $m );
+ #if (self::client_header('Accept',$t)) return $t;
+ }
+ return;
+ }
+
} Out::types() ; # < Class
/****************************************************************************/
#echo out::yaml_encode($row); return;
$yaml = '- '.out::yaml_encode($row);
#$yaml = (out::is_hash($row) ? ' ' : '- ') . out::yaml_encode($row);
- echo preg_replace("/^(?!-)/m"," ",$yaml);
+ $yaml = preg_replace("/^(?!-)/m"," ",$yaml);
+ echo $yaml;
}
function out_csv(&$row,$o) {
#function out_tag_head(&$row,$o) { return ''; }
function out_tag_head(&$data,$o) {
#return var_dump($row,true); return '';
+ #if (isset($o['tag_key'])) return ''; # No header, field will be in rows - NB 24.03.16
if (isset($o['tag_head'])) $o['tag'] = $o['tag_head'];
$row = out::ar_first($data);
if (!out::is_hash($row)) $row = $data;
if (isset($o['tag_enclose'])) echo (NB_EOL ? ' ' : '').'<'.$o['tag_enclose'].'>'.NB_EOL;
foreach ($row as $k => $v) {
- #if (!is_scalar($v)) continue;
-# NB 07.03.16 if (!is_scalar($v)) return var_export($row,true);
- if (!empty($o['tag'])) {
+
+ # Inside tag, ex: label
+ if (isset($o['tag_key'])) {
+ $v = '<'.$o['tag_key'].'>'.$k.'</'.$o['tag_key'].'>'.$v;
+ }
+
+ # Tag = o[tag] or key
+ if (isset($o['tag'])) {
$class = ' class="'.$k.'"';
$k = $o['tag'];
} else {
$class = '';
}
+
echo ''
.(NB_EOL ? ' ' : '')
."<$k$class>$v</$k>"
$Page->title = join(' / ',$title);
}
-} return;
+ public static function html_embed($iframe,$mime='text/html') {
+ return '<iframe class="embed" src="'.$iframe.'"></iframe>'.NB_EOL;
+ return ''
+ .'<object class="embed" data="'.$iframe.'" type="'.$mime.'">'.NB_EOL
+ .'<embed src="'.$iframe.'" type="'.$mime.'" />'.NB_EOL
+ .'</object>'.NB_EOL
+ ;
+ #echo '<embed src="'.$iframe.'" />'.NB_EOL;
+ #echo '<object class="data border" data="'.$iframe.'" />'.NB_EOL;
+ }
+
+} return; # < Class
?>