From ca8195c53a0f7537b33ad702483c4fbb272329de Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Wed, 5 Aug 2015 00:41:41 +0100 Subject: [PATCH] js --- etc/vim/source/functions.vim | 2 +- lib/css/db.css | 11 +++++---- lib/js/{tools.js => nb.js} | 29 ++++++++++++++++++++++++ lib/php/db.php | 32 +++++++++++++++----------- lib/php/db/field.php | 10 ++++---- lib/php/db/table.php | 44 +++++++++++++++++++++++++----------- lib/php/page.php | 30 +++++++++++++----------- 7 files changed, 109 insertions(+), 49 deletions(-) rename lib/js/{tools.js => nb.js} (68%) diff --git a/etc/vim/source/functions.vim b/etc/vim/source/functions.vim index 6614e3ed..d190251b 100644 --- a/etc/vim/source/functions.vim +++ b/etc/vim/source/functions.vim @@ -91,7 +91,7 @@ func! FileInit(...) let g:File['c'] = '//' elseif (g:File['type'] == 'php') - let g:File['c'] = '//' + let g:File['c'] = '#' elseif (g:File['type'] == 'sql') let g:File['c'] = '--' diff --git a/lib/css/db.css b/lib/css/db.css index a2312007..9eafc649 100644 --- a/lib/css/db.css +++ b/lib/css/db.css @@ -13,14 +13,14 @@ form label margin: 0.3em 0.3em 0.3em 0; } + /* form label { display: inline-block; - width: 8em; + width: 7em; text-align: right; } + */ -/* -*/ /* List */ @@ -50,7 +50,8 @@ div.rows .row { margin-bottom: 0.5em; padding: 0.2em; display: inline-block; - width: 22em; + width: 21em; + width: 16em; } div.rows .nav { @@ -116,6 +117,8 @@ form.db.edit { form.db.edit label { width: 20%; margin-bottom: 0.3em; + display: inline-block; + text-align: right; } form.db.edit span, diff --git a/lib/js/tools.js b/lib/js/nb.js similarity index 68% rename from lib/js/tools.js rename to lib/js/nb.js index f92a2474..cb8c8ef2 100644 --- a/lib/js/tools.js +++ b/lib/js/nb.js @@ -2,6 +2,7 @@ * NB JavaScript Library v0.0.0 * * Date: 28.03.15 + * See: http://www.w3schools.com/jquery/jquery_ref_selectors.asp */ function NB() { @@ -78,6 +79,34 @@ function NB() { }; + this.str2a = function(elems,compact=true,class_exp_file='dir|path') { + $(elems).each(function(){ + + html = $(this).html(); + if (html == '') return; + + // Search /home + url = html + if (html.match(/^~/)) { + ua = navigator.userAgent + if (ua.match(/Macintosh/)) { url = url.replace(/^~/,'/Users/') } + else { url = url.replace(/^~/,'/home/') } + //console.log(url); + } + + if (class_exp_file) { + var re = new RegExp(class_exp_file); + if (this.className.match(re) && !url.match(/^\w+:/)) url = 'file://'+encodeURI(url); + } + + if (compact) html = html.replace(/^((?:\w+:\/+)?[^\/]+\/)(.*?)(\/?[^\/]+)$/,'$1..$3'); + + $(this).html(''+html+''); + + }); + + }; + }; //NB.prototype.your_method = function() { } diff --git a/lib/php/db.php b/lib/php/db.php index c3dd045d..1533ceef 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -10,12 +10,14 @@ require_once(dirname(__FILE__).'/functions.php'); require_once(dirname(__FILE__).'/db/table.php'); require_once(dirname(__FILE__).'/db/field.php'); if (!defined('DB_HTML_FORM_BUTTONS')) define('DB_HTML_FORM_BUTTONS','' - .'' #.'' #.'' #.'' - .'X' - .'' +// NB 04.08.15 .'X' + .'' + .'' + .'' + .'' ); #if (!defined('DB_HTML_BUTTON_SUBMIT')) define('DB_HTML_BUTTON_SUBMIT',''); #if (!defined('DB_HTML_BUTTON_ADD')) define('DB_HTML_BUTTON_ADD','Add'); @@ -263,30 +265,29 @@ EOF; function html_menu($table=null) { - $html = ' onchange="this.parentElement.submit()"'; - $r = ''.PHP_EOL; return $r; diff --git a/lib/php/db/field.php b/lib/php/db/field.php index 59a3ce43..f7ea589d 100644 --- a/lib/php/db/field.php +++ b/lib/php/db/field.php @@ -34,13 +34,12 @@ class field { function html_edit($value) { - $value = htmlspecialchars($value); - return '' + return '' .($this->extra - ? "$value" + ? ''.$this->out($value).'' : '' ) - .PHP_EOL; + .''.PHP_EOL; } @@ -142,9 +141,10 @@ class field { function out($value,$html_escape=false) { + #if ($value === null) return ''; static $sqlite = null; if ($sqlite === null) $sqlite = $this->db()->type == 'sqlite'; - # Anoying ! + # Anoying, sqlite does not format properly ! if ($sqlite and preg_match('/^float\((?:\d+,)?(\d+)\)/',$this->type,$m)) { $value = sprintf('%.'.$m[1].'f',$value); } diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 1bfae686..16a152ce 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -23,8 +23,8 @@ class table { public $name; public $db; public $sql; - public $fields = array(); - public $fields_keys = array(); + public $fields = null; + public $fields_keys = null; public $extras = array(); public $params = array( 'table', @@ -92,7 +92,7 @@ class table { */ function fields($name=null) { - if (!$this->fields) { + if ($this->fields === null) { if ($this->db->type == 'sqlite') { $sql = "PRAGMA table_info('$this->name')"; @@ -121,6 +121,15 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. foreach ($rows as $row) { + $row = array_change_key_case($row,CASE_LOWER); + + // Mysql field name + if (isset($row['field'])) { + $row['name'] = $row['field']; + unset($row['field']); + } + +#bye($row); $field = array( 'name' => $row['name'], 'extra' => null, @@ -141,7 +150,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. # Autoincrement # mysql autoincrement - if (isset($row['Extra']) and $row['Extra'] == 'auto_increment') { + if (isset($row['extra']) and $row['extra'] == 'auto_increment') { $field['autoincrement'] = true; # sqlite autoincrement @@ -173,17 +182,19 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. $field['default'] = $row[$f]; } - foreach (array('pk','Key') as $f) { + foreach (array('pk','key') as $f) { if (!isset($row[$f])) continue; $field['key'] = preg_match('/^1|yes|t/i',$row[$f]) ? 1 : 0; } - $this->fields[$row['name']] = new field($field); + $this->fields[$field['name']] = new field($field); } + if (empty($this->fields)) bye($this->name." does not exists!"); } +#bye($this->fields); if ($name !== null ) { if (!isset($this->fields[$name])) return null; return $this->fields[$name]; @@ -206,6 +217,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. ; } + if (($v = $this->db->p('db'))) $url[] = 'db='.$this->db->p('db'); return $url ? '?table='.$this->db->p('table').$sep.join($sep,$url) : ''; } @@ -266,7 +278,8 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. .'
' .'' .'' - .'' + .'' + .'' .'' .( empty($_SERVER['HTTP_REFERER']) ? '' : '') .'
'.PHP_EOL @@ -372,7 +385,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. } function form_criterias($opt=array()) { - // Legacy from sem - NB 25.07.15 + // Legacy from sem - NB 25.07.15 !!!!!!!!!!!!!!!!!!! echo '
'.PHP_EOL; echo '
Use: '.join(' | ',$this->db->help_criterias).'
'.PHP_EOL; @@ -389,8 +402,10 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. $v = empty($_REQUEST[$k]) ? '' : $_REQUEST[$k]; $criteria[] = '' - . '' + .'' + . '' . '' + .'' ; } @@ -589,7 +604,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. if (!isset($opt['is_html'])) $opt['is_html'] = preg_match('/^(table|div)$/',$format) ? true : false; $escape = preg_match('/^(table|row|xml)$/',$format) ? true : false; - if (preg_match('/^(1)?$/',$this->db->p('header'))) echo $this->{"rows_begin_$format"}($opt); + if (preg_match('/^(1)?$/',$this->db->p('header'))) echo $this->{"rows_begin_$format"}($this->fields()); $count = 0; while ($row = $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT)) { @@ -597,8 +612,11 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. $count_fields = 0; foreach ($this->fields() as $f => $field) { + #foreach ($row as $f => $value) { + #$field = $this->fields($f); #echo '
'; var_dump($field); echo '
'; +#bye(array($field,$row)); $row[$f] = $field->out($row[$f]); // NB 02.08.15 if ($escape and empty($this->extra)) $row[$f] = htmlspecialchars($row[$f]); @@ -703,8 +721,8 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. /*----------------------------------------------------------------- Csv -----------------------------------------------------------------*/ - function rows_begin_csv() { - return join("\t",array_keys($this->fields()))."\n"; + function rows_begin_csv($fields) { + return join("\t",array_keys($fields))."\n"; } function rows_rec_csv($row) { @@ -803,7 +821,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog. foreach ($row as $k => $v) { $html .= '
  • ' .( $k == '0' ? '' : '') - .''.$v.'' + .''.$v.'' .'
  • '; } diff --git a/lib/php/page.php b/lib/php/page.php index dea7980d..664608d0 100644 --- a/lib/php/page.php +++ b/lib/php/page.php @@ -19,7 +19,7 @@ $Page = new Page(array( class Page { public $call = array(); - public $output = ''; +# NB 04.08.15 wtf ??? public $output; public $charset = 'utf-8'; public $content_type = 'text/html'; @@ -32,8 +32,10 @@ class Page { public $js = array(); public $js_code = ''; - public $body_class; - public $body_id; + public $body_class = ''; + public $body_id = ''; + + public $h1 = ''; /* Create @@ -47,13 +49,7 @@ class Page { } // Defaults - if ( ! isset($opt['title']) ) - #$this->title = $GLOBALS['argv'][0] - $this->title = $this->filename2title(); - #bye($this->title); - #$this->title = preg_replace('@^.*?([^/\.]+)[^/]*@','\1',$_SERVER['SCRIPT_NAME']); - #die( $this->title); - ; + if ( empty($this->title) ) $this->title = $this->filename2title(); //// Default #print_r($this); @@ -87,6 +83,7 @@ class Page { function filename2title() { $str = ''; + #$this->title = $GLOBALS['argv'][0] if (isset($_SERVER['REQUEST_URI'])) $str = preg_replace('/\?.*$/','',preg_replace(',^.*?([^/]+)(\/?.*)?$,','\1',$_SERVER['REQUEST_URI'])); if ($str == '' or $str == '/') $str = preg_replace('@^.*?([^/\.]+)(/index)?(\..*?)$@','\1',$_SERVER['SCRIPT_NAME']); $str = preg_replace('@[\'_-]+$@',' ',$str); @@ -150,7 +147,8 @@ class Page { return htmlspecialchars($v,$replace_flags,$charset); } - function tag($content='',$tag,$attrs='') { +# NB 04.08.15 function tag($content='',$tag,$attrs='') { + function tag($tag,$content='',$attrs='') { if (!is_array($content)) $content = array($content); $tags = array(); @@ -207,7 +205,9 @@ class Page { .(empty($this->body_class) ? '' : ' class="'.$this->body_class.'"') .(empty($this->body_id) ? '' : ' id="'.$this->body_id.'"') .'>' . PHP_EOL; - if ($this->title) echo $this->tag($this->title,'h1').PHP_EOL; + + if ($this->h1) echo $this->tag('h1',$this->h1).PHP_EOL; + elseif ($this->title) echo $this->tag('h1',$this->title).PHP_EOL; } } @@ -273,7 +273,7 @@ class Page { $head .= ''.PHP_EOL; #$head .= ''.PHP_EOL; return $head; - if ($this->title) $head .= $this->tag($this->title,'title') . PHP_EOL; + if ($this->title) $head .= $this->tag('title',$this->title) . PHP_EOL; if ($this->charset) $head .= ''.PHP_EOL; if (preg_match('/tml$/',$this->content_type)) { @@ -314,5 +314,9 @@ class Page { die("Db->is(): unknow argument '$is'. Accepted values are xhtml, html, xml"); } + function path() { + return preg_replace('/\?.*$/','',$_SERVER['REQUEST_URI']); + } + } return; ?> -- 2.47.3