@@ -1,57 +1,57 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * elFinder Plugin Normalizer |
|
| 4 | - * |
|
| 5 | - * UTF-8 Normalizer of file-name and file-path etc. |
|
| 6 | - * nfc(NFC): Canonical Decomposition followed by Canonical Composition |
|
| 7 | - * nfkc(NFKC): Compatibility Decomposition followed by Canonical |
|
| 8 | - * |
|
| 9 | - * This plugin require Class "Normalizer" (PHP 5 >= 5.3.0, PECL intl >= 1.0.0) |
|
| 10 | - * or PEAR package "I18N_UnicodeNormalizer" |
|
| 11 | - * |
|
| 12 | - * ex. binding, configure on connector options |
|
| 13 | - * $opts = array( |
|
| 14 | - * 'bind' => array( |
|
| 15 | - * 'upload.pre mkdir.pre mkfile.pre rename.pre archive.pre' => array( |
|
| 16 | - * 'Plugin.Normalizer.cmdPreprocess' |
|
| 17 | - * ), |
|
| 18 | - * 'upload.presave' => array( |
|
| 19 | - * 'Plugin.Normalizer.onUpLoadPreSave' |
|
| 20 | - * ) |
|
| 21 | - * ), |
|
| 22 | - * // global configure (optional) |
|
| 23 | - * 'plugin' => array( |
|
| 24 | - * 'Normalizer' => array( |
|
| 25 | - * 'enable' => true, |
|
| 26 | - * 'nfc' => true, |
|
| 27 | - * 'nfkc' => true, |
|
| 28 | - * 'lowercase' => false, |
|
| 29 | - * 'convmap' => array() |
|
| 30 | - * ) |
|
| 31 | - * ), |
|
| 32 | - * // each volume configure (optional) |
|
| 33 | - * 'roots' => array( |
|
| 34 | - * array( |
|
| 35 | - * 'driver' => 'LocalFileSystem', |
|
| 36 | - * 'path' => '/path/to/files/', |
|
| 37 | - * 'URL' => 'http://localhost/to/files/' |
|
| 38 | - * 'plugin' => array( |
|
| 39 | - * 'Normalizer' => array( |
|
| 40 | - * 'enable' => true, |
|
| 41 | - * 'nfc' => true, |
|
| 42 | - * 'nfkc' => true, |
|
| 43 | - * 'lowercase' => false, |
|
| 44 | - * 'convmap' => array() |
|
| 45 | - * ) |
|
| 46 | - * ) |
|
| 47 | - * ) |
|
| 48 | - * ) |
|
| 49 | - * ); |
|
| 50 | - * |
|
| 51 | - * @package elfinder |
|
| 52 | - * @author Naoki Sawada |
|
| 53 | - * @license New BSD |
|
| 54 | - */ |
|
| 3 | + * elFinder Plugin Normalizer |
|
| 4 | + * |
|
| 5 | + * UTF-8 Normalizer of file-name and file-path etc. |
|
| 6 | + * nfc(NFC): Canonical Decomposition followed by Canonical Composition |
|
| 7 | + * nfkc(NFKC): Compatibility Decomposition followed by Canonical |
|
| 8 | + * |
|
| 9 | + * This plugin require Class "Normalizer" (PHP 5 >= 5.3.0, PECL intl >= 1.0.0) |
|
| 10 | + * or PEAR package "I18N_UnicodeNormalizer" |
|
| 11 | + * |
|
| 12 | + * ex. binding, configure on connector options |
|
| 13 | + * $opts = array( |
|
| 14 | + * 'bind' => array( |
|
| 15 | + * 'upload.pre mkdir.pre mkfile.pre rename.pre archive.pre' => array( |
|
| 16 | + * 'Plugin.Normalizer.cmdPreprocess' |
|
| 17 | + * ), |
|
| 18 | + * 'upload.presave' => array( |
|
| 19 | + * 'Plugin.Normalizer.onUpLoadPreSave' |
|
| 20 | + * ) |
|
| 21 | + * ), |
|
| 22 | + * // global configure (optional) |
|
| 23 | + * 'plugin' => array( |
|
| 24 | + * 'Normalizer' => array( |
|
| 25 | + * 'enable' => true, |
|
| 26 | + * 'nfc' => true, |
|
| 27 | + * 'nfkc' => true, |
|
| 28 | + * 'lowercase' => false, |
|
| 29 | + * 'convmap' => array() |
|
| 30 | + * ) |
|
| 31 | + * ), |
|
| 32 | + * // each volume configure (optional) |
|
| 33 | + * 'roots' => array( |
|
| 34 | + * array( |
|
| 35 | + * 'driver' => 'LocalFileSystem', |
|
| 36 | + * 'path' => '/path/to/files/', |
|
| 37 | + * 'URL' => 'http://localhost/to/files/' |
|
| 38 | + * 'plugin' => array( |
|
| 39 | + * 'Normalizer' => array( |
|
| 40 | + * 'enable' => true, |
|
| 41 | + * 'nfc' => true, |
|
| 42 | + * 'nfkc' => true, |
|
| 43 | + * 'lowercase' => false, |
|
| 44 | + * 'convmap' => array() |
|
| 45 | + * ) |
|
| 46 | + * ) |
|
| 47 | + * ) |
|
| 48 | + * ) |
|
| 49 | + * ); |
|
| 50 | + * |
|
| 51 | + * @package elfinder |
|
| 52 | + * @author Naoki Sawada |
|
| 53 | + * @license New BSD |
|
| 54 | + */ |
|
| 55 | 55 | class elFinderPluginNormalizer |
| 56 | 56 | { |
| 57 | 57 | private $opts = array(); |
@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | public function __construct($opts) { |
| 60 | 60 | $defaults = array( |
| 61 | - 'enable' => true, // For control by volume driver |
|
| 62 | - 'nfc' => true, // Canonical Decomposition followed by Canonical Composition |
|
| 63 | - 'nfkc' => true, // Compatibility Decomposition followed by Canonical |
|
| 61 | + 'enable' => true, // For control by volume driver |
|
| 62 | + 'nfc' => true, // Canonical Decomposition followed by Canonical Composition |
|
| 63 | + 'nfkc' => true, // Compatibility Decomposition followed by Canonical |
|
| 64 | 64 | 'lowercase' => false, // Make chars lowercase |
| 65 | 65 | 'convmap' => array()// Convert map ('FROM' => 'TO') array |
| 66 | 66 | ); |
@@ -70,13 +70,13 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | public function cmdPreprocess($cmd, &$args, $elfinder, $volume) { |
| 72 | 72 | $opts = $this->getOpts($volume); |
| 73 | - if (! $opts['enable']) { |
|
| 73 | + if (!$opts['enable']) { |
|
| 74 | 74 | return false; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | if (isset($args['name'])) { |
| 78 | 78 | if (is_array($args['name'])) { |
| 79 | - foreach($args['name'] as $i => $name) { |
|
| 79 | + foreach ($args['name'] as $i => $name) { |
|
| 80 | 80 | $args['name'][$i] = $this->normalize($name, $opts); |
| 81 | 81 | } |
| 82 | 82 | } else { |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | |
| 89 | 89 | public function onUpLoadPreSave(&$path, &$name, $src, $elfinder, $volume) { |
| 90 | 90 | $opts = $this->getOpts($volume); |
| 91 | - if (! $opts['enable']) { |
|
| 91 | + if (!$opts['enable']) { |
|
| 92 | 92 | return false; |
| 93 | 93 | } |
| 94 | 94 | |
@@ -113,12 +113,12 @@ discard block |
||
| 113 | 113 | private function normalize($str, $opts) { |
| 114 | 114 | if ($opts['nfc'] || $opts['nfkc']) { |
| 115 | 115 | if (class_exists('Normalizer', false)) { |
| 116 | - if ($opts['nfc'] && ! Normalizer::isNormalized($str, Normalizer::FORM_C)) |
|
| 116 | + if ($opts['nfc'] && !Normalizer::isNormalized($str, Normalizer::FORM_C)) |
|
| 117 | 117 | $str = Normalizer::normalize($str, Normalizer::FORM_C); |
| 118 | - if ($opts['nfkc'] && ! Normalizer::isNormalized($str, Normalizer::FORM_KC)) |
|
| 118 | + if ($opts['nfkc'] && !Normalizer::isNormalized($str, Normalizer::FORM_KC)) |
|
| 119 | 119 | $str = Normalizer::normalize($str, Normalizer::FORM_KC); |
| 120 | 120 | } else { |
| 121 | - if (! class_exists('I18N_UnicodeNormalizer', false)) { |
|
| 121 | + if (!class_exists('I18N_UnicodeNormalizer', false)) { |
|
| 122 | 122 | @ include_once 'I18N/UnicodeNormalizer.php'; |
| 123 | 123 | } |
| 124 | 124 | if (class_exists('I18N_UnicodeNormalizer', false)) { |