diff options
author | Christopher Smith <chris@jalakai.co.uk> | 2013-12-01 16:23:02 +0000 |
---|---|---|
committer | Christopher Smith <chris@jalakai.co.uk> | 2013-12-01 16:23:02 +0000 |
commit | c9454ee3a82b29418a7ee59f0bb35006ea6a7fb1 (patch) | |
tree | 03f8e39f6c30d3f19a4203e51f18efe6fae19a8b /lib/plugins/usermanager/admin.php | |
parent | 211955bef84071b025e83bdeeefe496a5002fdd8 (diff) | |
download | rpg-c9454ee3a82b29418a7ee59f0bb35006ea6a7fb1.tar.gz rpg-c9454ee3a82b29418a7ee59f0bb35006ea6a7fb1.tar.bz2 |
Per FS#2884, implement a local version of str_getcsv() to maintain
compatibility with php 5.2.x (str_getcsv() is only available in
php 5.3+ and is used by user manager import feature.
Diffstat (limited to 'lib/plugins/usermanager/admin.php')
-rw-r--r-- | lib/plugins/usermanager/admin.php | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/plugins/usermanager/admin.php b/lib/plugins/usermanager/admin.php index 782443ee1..156037f09 100644 --- a/lib/plugins/usermanager/admin.php +++ b/lib/plugins/usermanager/admin.php @@ -847,7 +847,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { if (!utf8_check($csv)) { $csv = utf8_encode($csv); } - $raw = str_getcsv($csv); + $raw = $this->_getcsv($csv); $error = ''; // clean out any errors from the previous line // data checks... if (1 == ++$line) { @@ -983,4 +983,30 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { return is_uploaded_file($file); } + /** + * wrapper for str_getcsv() to simplify maintaining compatibility with php 5.2 + * + * @deprecated remove when dokuwiki php requirement increases to 5.3+ + * also associated unit test & mock access method + */ + protected function _getcsv($csv) { + return function_exists('str_getcsv') ? str_getcsv($csv) : $this->str_getcsv($csv); + } + + /** + * replacement str_getcsv() function for php < 5.3 + * loosely based on www.php.net/str_getcsv#88311 + * + * @deprecated remove when dokuwiki php requirement increases to 5.3+ + */ + protected function str_getcsv($str) { + $fp = fopen("php://temp/maxmemory:1048576", 'r+'); // 1MiB + fputs($fp, $str); + rewind($fp); + + $data = fgetcsv($fp); + + fclose($fp); + return $data; + } } |