diff options
author | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-08-25 14:45:49 +0000 |
---|---|---|
committer | marcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-08-25 14:45:49 +0000 |
commit | 7b62937942d4506c2d2a23c4a7211adbeccd83d1 (patch) | |
tree | 13f185f0a38f1d2cf5469eaa3863ff9b4677b361 /engine/lib/filestore.php | |
parent | 1793406d859437dee279a6a8f9870565834c3e7c (diff) | |
download | elgg-7b62937942d4506c2d2a23c4a7211adbeccd83d1.tar.gz elgg-7b62937942d4506c2d2a23c4a7211adbeccd83d1.tar.bz2 |
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
Diffstat (limited to 'engine/lib/filestore.php')
-rw-r--r-- | engine/lib/filestore.php | 44 |
1 files changed, 40 insertions, 4 deletions
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 @@ -260,6 +260,39 @@ } /** + * 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. * * @param string $filename @@ -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() |