From 7b62937942d4506c2d2a23c4a7211adbeccd83d1 Mon Sep 17 00:00:00 2001 From: marcus Date: Mon, 25 Aug 2008 14:45:49 +0000 Subject: Closes #254: If mb_string is installed then internationalised usernames are supported in file system. Because of this I have raised mbstring from recommended to a (non-fatal) core requirement. Because of the lack of a unicode ctype_alnum function the validation occurs at username input. Because of this I have improved the user registration code: This code now validates for special chars etc in the username. I have also introduced the following new plugin hooks (which are run after primary validation) which provide plugins with the ability to add other requirements (extra security etc). 'registeruser:validate:password' 'registeruser:validate:username' 'registeruser:validate:email' Marcus Povey 25/8/08 git-svn-id: https://code.elgg.org/elgg/trunk@2040 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/filestore.php | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) (limited to 'engine/lib/filestore.php') diff --git a/engine/lib/filestore.php b/engine/lib/filestore.php index e959d6c9e..daed925f5 100644 --- a/engine/lib/filestore.php +++ b/engine/lib/filestore.php @@ -259,6 +259,39 @@ return true; } + /** + * Multibyte string tokeniser. + * + * Splits a string into an array. Will fail safely if mbstring is not installed (although this may still + * not handle . + * + * @param string $string String + * @param string $charset The charset, defaults to UTF8 + * @return array + */ + private function mb_str_split($string, $charset = 'UTF8') + { + if (is_callable('mb_substr')) + { + $length = mb_strlen($string); + $array = array(); + + while ($length) + { + $array[] = mb_substr($string, 0, 1, $charset); + $string = mb_substr($string, 1, $length, $charset); + + $length = mb_strlen($string); + } + + return $array; + } + else + return str_split($string); + + return false; + } + /** * Construct the filename matrix. * @@ -268,16 +301,19 @@ { $matrix = ""; - $len = strlen($filename); + $name = $filename; + $filename = $this->mb_str_split($filename); + if (!$filename) return false; + + $len = count($filename); if ($len>$this->matrix_depth) $len = $this->matrix_depth; for ($n = 0; $n < $len; $n++) { - if (ctype_alnum($filename[$n])) - $matrix .= $filename[$n] . "/"; + $matrix .= $filename[$n] . "/"; } - return $matrix.$filename."/"; + return $matrix.$name."/"; } public function getParameters() -- cgit v1.2.3