From: Nicolas Boisselier Date: Tue, 30 Aug 2016 10:54:22 +0000 (+0200) Subject: mode nb.rb X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=917161988ec801011b389cba060e1f6b6930d775;p=nb.git mode nb.rb --- diff --git a/etc/dbs/nb.php b/etc/dbs/nb.php index 4cd914e5..733aa334 100644 --- a/etc/dbs/nb.php +++ b/etc/dbs/nb.php @@ -11,7 +11,7 @@ $CONF['nb'] = array( ); $CONF['nb-sqlite'] = array ( - 'pdo' => 'sqlite:/opt/rent/nb.db', + 'pdo' => 'sqlite:'.nb::untilde('~nico/ownCloud/var/lib/sqlite/nb.db'), '_import' => '_rent', ); diff --git a/etc/dbs/rent.php b/etc/dbs/rent.php index 519cb423..b3c09644 100644 --- a/etc/dbs/rent.php +++ b/etc/dbs/rent.php @@ -64,17 +64,6 @@ $CONF['_rent'] = array( return 1; -function untilde($path) { - if (!function_exists('posix_getuid')) return $path; - return preg_replace_callback('/^(~)(\w+)?/',function($m){ - - $uid = fileowner(!empty($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : __FILE__); - if (!empty($m[2])) return str_replace($m[2],posix_getpwnam($uid)['dir'],$m[0]); - - return str_replace($m[1],posix_getpwuid(posix_getuid())['dir'],$m[0]); - },$path); -} - function tenant_doc(&$r) { return rent_doc('tenant',$r); } function place_doc(&$r) { return rent_doc('place',$r); } @@ -103,7 +92,7 @@ function rent_doc($table,&$r) { # Absolute path or ( - ( $dir = untilde($r['doc']) ) + ( $dir = nb::untilde($r['doc']) ) and file_exists($dir) and is_dir($dir) and ($url='' or 1) ) diff --git a/lib/php/nb.php b/lib/php/nb.php index 21ec6816..76703ca2 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -596,5 +596,14 @@ class NB { } + public static function untilde($path) { + if (!function_exists('posix_getuid')) return $path; + return preg_replace_callback('/^(~)(\w+)?/',function($m){ + + if (!empty($m[2])) return str_replace($m[1].$m[2],posix_getpwnam($m[2])['dir'],$m[0]); + + return str_replace($m[1],posix_getpwuid(posix_getuid())['dir'],$m[0]); + },$path); + } } # < Class ?>