]> git.nbdom.net Git - nb.git/commitdiff
download
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 20 Mar 2016 02:31:35 +0000 (02:31 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Sun, 20 Mar 2016 02:31:35 +0000 (02:31 +0000)
etc/dbs.yaml
lib/js/nb.js
lib/php/benchmark.php
lib/php/config.php
lib/php/db.php
lib/php/db/index.php
lib/php/db/table.php
lib/php/functions.php
lib/php/nb.php
lib/php/page.php

index 2114234877fa3b161fd888cfed265ddcdbd8177f..19023ffdeab949846f9cb2879a5ddf1da7ef2961 100644 (file)
@@ -51,6 +51,10 @@ izidev:
   options:
     - "PDO::MYSQL_ATTR_INIT_COMMAND: SET NAMES utf8'"
 
+ui-mem:
+  pdo: 'sqlite:/dev/shm/semantico.db'
+  _conf2h_copy: ui
+
 ui:
   pdo: 'sqlite:/opt/semantico/product/releases/sem_ui/db/semantico.db'
   title: 'Semantico UI'
index 587490b6685bca27d2dfad0d2c85457a3a2a4580..e9a6b53f1ebc2fcc33178c8589bfef42baee0f74 100644 (file)
@@ -25,30 +25,80 @@ function NB() {
 
   }
 
-  this.resize = function() {
+  this.wh = function(s) {
+      var item = $(s);
+      if (!item) return [0,0]
+
+      var width = item.width();
+      var height = item.height();
+
+      /*
+      */
+      width -= $(item).css('paddingLeft').replace(/px/,'');
+      width -= $(item).css('paddingRight').replace(/px/,'');
+      height -= $(item).css('paddingTop').replace(/px/,'');
+      height -= $(item).css('paddingBottom').replace(/px/,'');
+
+      width -= $(item).css('marginLeft').replace(/px/,'');
+      width -= $(item).css('marginRight').replace(/px/,'');
+      height -= $(item).css('marginTop').replace(/px/,'');
+      height -= $(item).css('marginBottom').replace(/px/,'');
+      //console.log(width+'/'+height);
+      return [parseInt(width),parseInt(height)];
+  }
 
-    // table to div
-    if ($('#_responsive').css('content') != 'none') {
-      that.table2div('table.rows');
-      return true;
-    } else {
-      $('table.rows').addClass('t2d');
-      $('.t2d-th').each(function(){
-        $(this).remove();
-      });
+  this.maxhw = function(s) {
+    var height = $('body').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');
+      $(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);
+    });
+  }
 
-    // Max width for blocks
-    var block = $("table, div");
+  this.maxhw_resize = function(s) {
+    var block = $(s);
     if (!block) return false;
 
-    var width = $(window).width();
+    var width = $('body').width();
     var set_width = width - 20;
     block.each(function(){
 
       var first_width = $(this).attr('nb-resize');
       var cur_width = $(this).width();
 
+//$(this).css({ 'border': 'solid 1px yellow', });
       if (cur_width > width) {
         if (!first_width) {
           $(this).attr('nb-resize',cur_width);
@@ -84,6 +134,21 @@ function NB() {
 
   }
 
+  this.resize = function() {
+
+    // table to div
+    if ($('#_responsive').css('content') != 'none') {
+      that.table2div('table.rows');
+      return true;
+    } else {
+      $('table.rows').addClass('t2d');
+      $('.t2d-th').each(function(){ $(this).remove(); });
+    }
+
+    // Max width for blocks
+    that.maxhw_resize('table, div');
+  }
+
   this.table2div = function(find) {
     var th = []
 
index a6d011f3abaa68ffe0ec93a6ce1e2ff24e7da88e..e0ef96ac4460c97ad09674fb91b590a12c0bc65f 100755 (executable)
@@ -18,13 +18,14 @@ echo $first;
 exit;
 */
 
-function __f1(&$ar) { $v=$ar; return; foreach ($ar as $v) { 1; } }
+#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; } }
 $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'); }
-function _f1() { file_exists('/tm'); } nb::benchmark('_f1');
-function _f2() { echo ''; } nb::benchmark('_f2');
+function _f1() { ini_set('display_errors', 'On'); } nb::benchmark('_f1');
+function _f2() { ; } nb::benchmark('_f2');
 
 nb::benchmark(); exit;
 
index aa762d462b9e0ee88f1863b26712dcef9a814f0c..798ac1d059f884600d5703a7e0038b6ed0416153 100644 (file)
@@ -7,7 +7,6 @@
 */
 
 date_default_timezone_set('Europe/London');
-ini_set('display_errors', 'On');
 error_reporting(E_ALL | E_STRICT | E_NOTICE);
 
 # NB 05.03.16 ini_set('include_path', realpath(dirname(__FILE__).'/../lib').':'.realpath(dirname(__FILE__)).':'.ini_get('include_path'));
@@ -18,6 +17,9 @@ ini_set('include_path',''
 
 #define('NB_EOL','');
 #define('NB_PROD',true);
-require_once('nb.php');
+include('nb.php');
 if (nb::php_cli()) argv2request();
+
+ini_set('display_errors', 'On');
+if (nb::php_cli() or nb::p('txt_errors')) ini_set('html_errors', false);
 ?>
index 384b19ad77d1e49f88d2df6a72fba8ee7693701d..3fea979c970561ae895fad3d32769a32c395d56d 100644 (file)
@@ -10,19 +10,6 @@ require_once(dirname(__FILE__).'/nb.php');
 require_once(dirname(__FILE__).'/out.php');
 require_once(dirname(__FILE__).'/db/table.php');
 require_once('out.php');
-if (!defined('DB_HTML_FORM_BUTTONS')) define('DB_HTML_FORM_BUTTONS',''
-  #.'<input type="button" class="button" value="Add" onclick="this.setAttribute(\'type\',\'submit\');this.setAttribute(\'name\',\'edit\')?1:1"/>'
-  #.'<input type="button" class="button" value="Add" onclick="this.setAttribute(\'name\',\'edit\');this.parentElement.submit()?0:0"/>'
-  #.'<input type="button" class="button" onclick="return nb.form_clear(this.parentElement)" value="X"/>'
-// NB 04.08.15   .'<a class="button form_clear" href="#" onclick="nb.form_clear(this.parentElement)?0:0">X</a>'
-  .'<span class="buttons">'
-  .'<input type="submit" class="button submit" value="GO"/>'
-  .'<input type="button" class="button table_add" value="Add" onclick="window.location = \'?action=edit&amp;table=\'+$(\'#table\').val()"/>'
-  .'</span>'
-);
-#if (!defined('DB_HTML_BUTTON_SUBMIT')) define('DB_HTML_BUTTON_SUBMIT','<input type="submit" class="button" value="GO"/>');
-#if (!defined('DB_HTML_BUTTON_ADD'))    define('DB_HTML_BUTTON_ADD','<a class="button" href="?" onclick="nb.form_clear(this.parentElement) ? 0: 0">Add</a>');
-#if (!defined('DB_HTML_BUTTON_ADD'))    define('DB_HTML_BUTTON_ADD','<input type="submit" class="button" value="Add" onclick="this.setAttribute(\'name\',\'edit\')?0:0"/>');
 
 $DB_TYPES = array(
   'tables' => array(
@@ -363,101 +350,6 @@ EOF;
     return $mime;
   }
 
-  function html_menu($table=null) {
-
-    $r = '<form class="db menu" method="get" action="?">'.NB_EOL;
-
-    // Criterias
-    if (!empty($table)) {
-      $r .= '<div class="criterias">';
-      foreach ( array_keys($table->fields()) as $k ) {
-
-        $v = $this->p($k);
-
-        $r .= ''
-          .'<span class="label '.$k.'">'
-          . '<label>'.prettyText($k)
-          .'</label>'
-          . '<input type="text" id="'.$k.'" name="'.$k.'" value="'.$v.'" />'
-          .'</span>'
-        ;
-
-      }
-      $r .= '</div>';
-      #$r .= '<span class=""></span>';
-    }
-
-    //
-    // Hiddens
-    //
-    foreach (array(
-      'db',
-      'debug',
-    ) as $v) {
-      $r .= '<input type="hidden" name="'.$v.'" value="'.$this->p($v).'"/>';
-    }
-
-    //
-    // Options
-    //
-    $r .= '<div class="options">';
-
-    // Tables
-    $r .= '<span class="label">';
-    $r .= '<label for="table">Tables</label>'.html_select_array($this->tables(),array(
-      'html'       => 'class="tables" name="table" id="table"',
-      'selected'   => $this->p('table'),
-      'prettyText' => true,
-    ));
-    $r .= '</span>';
-
-    // Format
-    $r .= '<span class="label">';
-
-  #$criteria[] = html_select_array(ar_map('array($a == "html" ? "" : $a,strtoupper($a))',$this->formats));
-# NB 01.03.16     $r .= '<label for="format">Format</label>'.html_select_array(array(
-# NB 01.03.16       'table','div','csv','xml','json','yaml'
-    $r .= '<label for="format">Format</label>'.html_select_array($this->formats,array(
-      'html'       => 'class="format" name="format" id="format"',
-      'selected'   => $this->p('format'),
-      'prettyText' => true,
-    ));
-    $r .= '</span>';
-
-    // Limit
-    if (!empty($this->limits)) {
-      $r .= '<span class="label">';
-      $r .= '<label for="limit">Limit</label>'.html_select_array($this->limits,array(
-        'html'       => 'class="limit" name="limit" id="limit"',
-        'selected'   => $this->p('limit'),
-        'prettyText' => true,
-      ));
-      $r .= '</span>';
-    }
-
-    // Dbs
-    if (!empty($this->dbs) and count($this->dbs)>1) {
-      $r .= '<span class="label">';
-      $r .= '<label for="db">Db</label>'.html_select_array($this->dbs,array(
-        'html'       => 'class="dbs" onchange="document.location=\''.preg_replace('/\?.*$/','',$_SERVER['REQUEST_URI']).'?db=\'+this.value"',
-        'selected'   => $this->name,
-        'prettyText' => true,
-      ));
-      $r .= '</span>';
-    }
-
-    // Buttons
-    $r .= DB_HTML_FORM_BUTTONS;
-
-    $r .= '</div>';
-
-    ///
-    // Bye
-    ///
-    $r .= '</form>'.NB_EOL;
-    return $r;
-  }
-
   function sql_name($value) {
     if ($this->type == 'mysql') return '`'.$value.'`';
     return '"'.$value.'"';
@@ -620,7 +512,7 @@ EOF;
   * @param [FILES] $files Files to load
   * @return ARRAY the new/existing value of $this->db
   */
-  static function config2h ($files=array(),&$first=false) {
+  static function conf2h ($files=array(),&$first=false) {
     if (empty($files)) return array();
 
     if (!empty($files)) {
@@ -628,19 +520,33 @@ EOF;
       $h = array();
 
       foreach ($files as $file) {
-        if (is_readable($file) and ($yaml = @yaml_parse_file($file))) {
-          #foreach ($yaml as $k=>$v) { $yaml[$k]['_config2h'] = $file; }
+        if (is_readable($file) and ($yaml = yaml_parse_file($file))) {
+          #foreach ($yaml as $k=>$v) { $yaml[$k]['_conf2h'] = $file; }
           #debug($file);
           $h = array_replace_recursive($h,$yaml);
         }
           #debug($file);
         #if ( ($yaml = @yaml_parse_file($file)) ) $h = array_replace_recursive($h,$yaml)
         ;
-        unset($yaml);
         #}
       }
 
-      #debug($h);
+      unset($yaml);
+
+      # Emulate hash pointer
+      foreach ($h as $db=>$o) {
+        foreach ($o as $k => $v) {
+          if ($k != '_conf2h_copy') continue;
+
+          foreach ($h[$v] as $kk => $vv) {
+            if (!isset($o[$kk])) $h[$db][$kk] = $vv;
+          }
+          unset($h[$db][$k]);
+          #bye($h[$db]);
+
+        }
+      }
+
     }
     if (!$h) return false;
     #self::bye($h['puppetdb']);
@@ -664,17 +570,11 @@ EOF;
 
     $Db = new self();
     #bye($_SERVER["PHP_SELF"]); bye($_SERVER);
-    if (!in_array(nb::$root_dir.'/etc/dbs.yaml',$conf)) $conf[] = nb::$root_dir.'/etc/dbs.yaml';
-    if (!in_array('/etc/dbs.yaml',$conf)) $conf[] = '/etc/dbs.yaml';
+# NB 19.03.16     if (!in_array(nb::$root_dir.'/etc/dbs.yaml',$conf)) $conf[] = nb::$root_dir.'/etc/dbs.yaml';
+# NB 19.03.16     if (!in_array('/etc/dbs.yaml',$conf)) $conf[] = '/etc/dbs.yaml';
 
     # Load databases
-    if (! ($dbs = $Db->config2h($conf)) ) return false;
-
-    # Param - Extract dbname from table
-    if (preg_match('/^(\w+)\.(.*?)$/',$Db->p('table'),$m)) {
-      $Db->pset('db',$m[1]);
-      $Db->pset('table',$m[2]);
-    }
+    if (! ($dbs = $Db->conf2h($conf)) ) return false;
     #die (nb::p('db'));
 
     # Param - Default base on order hight num value
@@ -683,10 +583,6 @@ EOF;
       $Db->pset('db',$Db->ar_first($dbs,true));
     }
 
-    # Param - correction / aliases
-    if (($format=$Db->p('format'))) {
-    }
-
     # Connection
     #bye($Db->p('db'));
     if (!isset($dbs[$Db->p('db')])) $Db->bye("Can't find db: `".$Db->p('db')."` in `".join(",",array_keys($dbs))."`",false);
@@ -703,10 +599,9 @@ EOF;
     if (empty($Db)) return false;
     if (!$Db->p('table') and isset($Db->default_table)) $Db->pset('table',$Db->default_table);
     if (!$Db->p('table') and ($v = $Db->tables())) $Db->pset('table',$Db->ar_first($v));
-    if (!$Db->p('table')) return;
 
     # NB 10.01.16 $Table = new table($Db->p('table'),array('db' => $Db));
-    $Table = $Db->table($Db->p('table'));
+    if ($Db->p('table')) $Table = $Db->table($Db->p('table'));
 
     return true;
 
index 99cebe6214e13aa09287a7f378729d072549c603..9ee489f908133bc5bc008c6efd739d6093526ec1 100755 (executable)
@@ -9,7 +9,12 @@
 require_once(dirname(__FILE__).'/../config.php');
 require_once(dirname(__FILE__).'/../db.php');
 
-Db::init(array( '/etc/dbs.yaml' ));
+# Param - Extract dbname from table
+if (preg_match('/^(\w+)\.(.*?)$/',Db::p('table'),$m)) {
+  Db::pset('db',$m[1]);
+  Db::pset('table',$m[2]);
+}
+Db::init(array( nb::$root_dir.'/etc/dbs.yaml','/etc/dbs.yaml' ));
 
 if( defined('DB_JUST_INIT')) return true;
 return $Db->action($Table);
index 7a34f601b4683edb8e2aca0b6f5f0200d27d64c4..e1be11844b376400d25dbc9d859aeedb86d7c34e 100644 (file)
@@ -378,7 +378,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
 
     foreach (array_merge( $this->params, array_keys($fields) ) as $f) {
 
-      if (@strcmp($this->p($f),'')==0) continue;
+      if (strcmp($this->p($f,''),'')==0) continue;
       $params[$f] = $this->p($f);
 
     }
@@ -634,7 +634,10 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
     $st->execute();
 
     if (!isset($opt['is_html'])) $opt['is_html'] = preg_match('/^(table|div)$/',$format)
-      ? ( $this->p('header')!=="0" and $this->p('inc')!=="1")
+      ? (
+        $this->p('header')!=="0"
+        #and $this->p('download')!=="1"
+      )
       : false
     ;
 
@@ -1087,7 +1090,6 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
     } elseif ($action == 'table.count') { return $this->out2($this->count(),'count');
 
     } elseif ($action == 'table.rows' or $action == 'rows') {
-      #if ($this->p('page')==='0') $this->pset('inc',1);
       $this->db->print_header($this->p('format'));
       $this->rows(); return true;
 
@@ -1126,8 +1128,6 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
       return true;
 
     } elseif ($this->p('format') and !preg_match('/^(table|div)$/',$this->p('format'))) {
-    #} elseif ($action == 'table' and $this->p('format') and $this->p('table')) {
-    #} elseif ($is_html) {
 
       $this->rows(array( 'format' => $this->p('format')));
       return true;
@@ -1208,7 +1208,7 @@ FROM pg_catalog.pg_attribute a WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.
     ) as $v) {
       $r .= '<input type="hidden" name="'.$v.'" value="'.$this->p($v).'"/>';
     }
-    $r .= '<input type="hidden" name="inc" value="0"/>'; // Embed for no html format
+    $r .= '<input type="hidden" name="download" value="0"/>'; // Embed for no html format
 
     //
     // Options
index 337862ddd441f4b5813567de7ad7b10b4e0e90cb..97655bc159a6cf611e7d1b1cdc9e636ebe7f2263 100644 (file)
@@ -118,7 +118,8 @@ function err($msg='__err__',$preff='err',$backtrace_deep=0) {
     $msg = $preff_msg.$msg;
   }
 
-  nb::msg( !nb::php_cli()
+  #nb::msg( !nb::php_cli()
+  nb::msg( preg_match('/ml/i',nb::get_header('Content-type'))
     ? '<pre'
         .' class="err'. ( ($preff and $preff!='err') ? " $preff" : '' ).'"'
       .'>'.$msg.'</pre>'.NB_EOL
index eb1534e16aec91a7a074f2b72ff7e5bc48d37d04..d301f1d6039957b975cabaf4c519cb2df2e8bdb5 100644 (file)
@@ -16,7 +16,7 @@ class nb {
   );
 
   public static $content_types = array(
-    'json' => 'application/json',
+    'json' => 'text/json',
     'doc'  => 'application/msword',
     'xls'  => 'application/vnd.ms-excel',
     'xml'  => 'application/xml',
@@ -101,10 +101,24 @@ class nb {
     return prettyText($text);
   }
 
+  public static function mime2ext($mime) {
+
+    static $aliases = null; if ($aliases === null) $aliases = array_combine(array_values(self::$content_types_aliases),array_keys(self::$content_types_aliases));
+    #static $v = array_combine(array_values(self::$content_types_aliases),array_keys(self::$content_types_aliases));
+    foreach (self::$content_types as $e => $c) {
+      if ($mime == $c) return $e;
+    }
+
+    // Aliases
+    if (isset($aliases[$ext])) return self::ext2mime($aliases[$ext]);
+
+  }
+
   /*
-   * Function: prettyText
+   * Function: ext2mime
    * Does what it says
    */
+  #public static function ext2content_type($ext) { return self::ext2mime($ext); }
   public static function ext2mime($ext) {
 
     foreach (self::$content_types as $e => $c) {
@@ -402,6 +416,191 @@ class nb {
     return (!isset($_SERVER['SERVER_SOFTWARE']) && (php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0)));
   }
 
+  public static function no_accent($str){
+    return strtr($str,array(
+'À' => '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'
+    ));
+  }
 } # < Class
 #die(self::ext2mime('csv'));
 ?>
index 0c6ab9e43bccfa6da6a705623905de30f1a0167a..311b26a906a5b58011ca1e338489f22b59e01512 100644 (file)
@@ -83,7 +83,15 @@ class Page extends nb {
     return (is_array($v) ? $v : array($v));
   }
 
-  function filename2title() {
+  public static function title2filename($title,$content_type='') {
+    $ext = $content_type ? self::mime2ext($content_type) : '';
+    $title = self::no_accent($title);
+    $title = preg_replace('/\W+/','_',$title);
+    if ($ext) $title .= '.'.$ext;
+    return $title;
+  }
+
+  public function filename2title() {
     $str = '';
     #$this->title = $GLOBALS['argv'][0]
     if (isset($_SERVER['REQUEST_URI'])) $str = preg_replace('/\?.*$/','',preg_replace(',^.*?([^/]+)(\/?.*)?$,','\1',$_SERVER['REQUEST_URI']));
@@ -269,6 +277,9 @@ class Page extends nb {
                $c = strtoupper ( $this->charset );
 # NB 19.08.15     $this->header('Content-type: ',$this->content_type . ($c ? "; charset=$c" : ""));
                header('Content-type: '.$this->content_type . ($c ? "; charset=$c" : ""));
+    if (self::p('download-attachment')) header('Content-Disposition: attachment; filename="'
+      . $this->title2filename($this->title,$this->content_type)
+    );
 
     return true;
   }