@@ -90,8 +90,8 @@ discard block |
||
| 90 | 90 | break; |
| 91 | 91 | |
| 92 | 92 | case 'openssl': |
| 93 | - $prettyVersion = preg_replace_callback('{^(?:OpenSSL\s*)?([0-9.]+)([a-z]?).*}', function ($match) { |
|
| 94 | - return $match[1] . (empty($match[2]) ? '' : '.' . (ord($match[2]) - 96)); |
|
| 93 | + $prettyVersion = preg_replace_callback('{^(?:OpenSSL\s*)?([0-9.]+)([a-z]?).*}', function($match) { |
|
| 94 | + return $match[1].(empty($match[2]) ? '' : '.'.(ord($match[2]) - 96)); |
|
| 95 | 95 | }, OPENSSL_VERSION_TEXT); |
| 96 | 96 | break; |
| 97 | 97 | |
@@ -166,19 +166,19 @@ discard block |
||
| 166 | 166 | return '9999999-dev'; |
| 167 | 167 | } |
| 168 | 168 | if ('dev-' === strtolower(substr($version, 0, 4))) { |
| 169 | - return 'dev-' . substr($version, 4); |
|
| 169 | + return 'dev-'.substr($version, 4); |
|
| 170 | 170 | } |
| 171 | 171 | // match classical versioning |
| 172 | - if (preg_match('{^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?' . self::$modifierRegex . '$}i', $version, $matches)) { |
|
| 172 | + if (preg_match('{^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?'.self::$modifierRegex.'$}i', $version, $matches)) { |
|
| 173 | 173 | $version = $matches[1] |
| 174 | 174 | . (!empty($matches[2]) ? $matches[2] : '.0') |
| 175 | 175 | . (!empty($matches[3]) ? $matches[3] : '.0') |
| 176 | 176 | . (!empty($matches[4]) ? $matches[4] : '.0'); |
| 177 | 177 | $index = 5; |
| 178 | - } elseif (preg_match('{^v?(\d{4}(?:[.:-]?\d{2}){1,6}(?:[.:-]?\d{1,3})?)' . self::$modifierRegex . '$}i', $version, $matches)) { // match date-based versioning |
|
| 178 | + } elseif (preg_match('{^v?(\d{4}(?:[.:-]?\d{2}){1,6}(?:[.:-]?\d{1,3})?)'.self::$modifierRegex.'$}i', $version, $matches)) { // match date-based versioning |
|
| 179 | 179 | $version = preg_replace('{\D}', '-', $matches[1]); |
| 180 | 180 | $index = 2; |
| 181 | - } elseif (preg_match('{^v?(\d{4,})(\.\d+)?(\.\d+)?(\.\d+)?' . self::$modifierRegex . '$}i', $version, $matches)) { |
|
| 181 | + } elseif (preg_match('{^v?(\d{4,})(\.\d+)?(\.\d+)?(\.\d+)?'.self::$modifierRegex.'$}i', $version, $matches)) { |
|
| 182 | 182 | $version = $matches[1] |
| 183 | 183 | . (!empty($matches[2]) ? $matches[2] : '.0') |
| 184 | 184 | . (!empty($matches[3]) ? $matches[3] : '.0') |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | if ('stable' === $matches[$index]) { |
| 192 | 192 | return $version; |
| 193 | 193 | } |
| 194 | - $version .= '-' . $this->expandStability($matches[$index]) . (!empty($matches[$index + 1]) ? $matches[$index + 1] : ''); |
|
| 194 | + $version .= '-'.$this->expandStability($matches[$index]).(!empty($matches[$index + 1]) ? $matches[$index + 1] : ''); |
|
| 195 | 195 | } |
| 196 | 196 | if (!empty($matches[$index + 2])) { |
| 197 | 197 | $version .= '-dev'; |
@@ -199,12 +199,12 @@ discard block |
||
| 199 | 199 | return $version; |
| 200 | 200 | } |
| 201 | 201 | $extraMessage = ''; |
| 202 | - if (preg_match('{ +as +' . preg_quote($version) . '$}', $fullVersion)) { |
|
| 203 | - $extraMessage = ' in "' . $fullVersion . '", the alias must be an exact version'; |
|
| 204 | - } elseif (preg_match('{^' . preg_quote($version) . ' +as +}', $fullVersion)) { |
|
| 205 | - $extraMessage = ' in "' . $fullVersion . '", the alias source must be an exact version, if it is a branch name you should prefix it with dev-'; |
|
| 202 | + if (preg_match('{ +as +'.preg_quote($version).'$}', $fullVersion)) { |
|
| 203 | + $extraMessage = ' in "'.$fullVersion.'", the alias must be an exact version'; |
|
| 204 | + } elseif (preg_match('{^'.preg_quote($version).' +as +}', $fullVersion)) { |
|
| 205 | + $extraMessage = ' in "'.$fullVersion.'", the alias source must be an exact version, if it is a branch name you should prefix it with dev-'; |
|
| 206 | 206 | } |
| 207 | - throw new \UnexpectedValueException('Invalid version string "' . $version . '"' . $extraMessage); |
|
| 207 | + throw new \UnexpectedValueException('Invalid version string "'.$version.'"'.$extraMessage); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -31,196 +31,196 @@ |
||
| 31 | 31 | * @package OC\App |
| 32 | 32 | */ |
| 33 | 33 | class PlatformRepository { |
| 34 | - public function __construct() { |
|
| 35 | - $this->packages = $this->initialize(); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - protected function initialize() { |
|
| 39 | - $loadedExtensions = get_loaded_extensions(); |
|
| 40 | - $packages = []; |
|
| 41 | - |
|
| 42 | - // Extensions scanning |
|
| 43 | - foreach ($loadedExtensions as $name) { |
|
| 44 | - if (in_array($name, ['standard', 'Core'])) { |
|
| 45 | - continue; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - $ext = new \ReflectionExtension($name); |
|
| 49 | - try { |
|
| 50 | - $prettyVersion = $ext->getVersion(); |
|
| 51 | - $prettyVersion = $this->normalizeVersion($prettyVersion); |
|
| 52 | - } catch (\UnexpectedValueException $e) { |
|
| 53 | - $prettyVersion = '0'; |
|
| 54 | - $prettyVersion = $this->normalizeVersion($prettyVersion); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - $packages[$this->buildPackageName($name)] = $prettyVersion; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - foreach ($loadedExtensions as $name) { |
|
| 61 | - $prettyVersion = null; |
|
| 62 | - switch ($name) { |
|
| 63 | - case 'curl': |
|
| 64 | - $curlVersion = curl_version(); |
|
| 65 | - $prettyVersion = $curlVersion['version']; |
|
| 66 | - break; |
|
| 67 | - |
|
| 68 | - case 'intl': |
|
| 69 | - $name = 'ICU'; |
|
| 70 | - if (defined('INTL_ICU_VERSION')) { |
|
| 71 | - $prettyVersion = INTL_ICU_VERSION; |
|
| 72 | - } else { |
|
| 73 | - $reflector = new \ReflectionExtension('intl'); |
|
| 74 | - |
|
| 75 | - ob_start(); |
|
| 76 | - $reflector->info(); |
|
| 77 | - $output = ob_get_clean(); |
|
| 78 | - |
|
| 79 | - preg_match('/^ICU version => (.*)$/m', $output, $matches); |
|
| 80 | - $prettyVersion = $matches[1]; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - break; |
|
| 84 | - |
|
| 85 | - case 'libxml': |
|
| 86 | - $prettyVersion = LIBXML_DOTTED_VERSION; |
|
| 87 | - break; |
|
| 88 | - |
|
| 89 | - case 'openssl': |
|
| 90 | - $prettyVersion = preg_replace_callback('{^(?:OpenSSL\s*)?([0-9.]+)([a-z]?).*}', function ($match) { |
|
| 91 | - return $match[1] . (empty($match[2]) ? '' : '.' . (ord($match[2]) - 96)); |
|
| 92 | - }, OPENSSL_VERSION_TEXT); |
|
| 93 | - break; |
|
| 94 | - |
|
| 95 | - case 'pcre': |
|
| 96 | - $prettyVersion = preg_replace('{^(\S+).*}', '$1', PCRE_VERSION); |
|
| 97 | - break; |
|
| 98 | - |
|
| 99 | - case 'uuid': |
|
| 100 | - $prettyVersion = phpversion('uuid'); |
|
| 101 | - break; |
|
| 102 | - |
|
| 103 | - case 'xsl': |
|
| 104 | - $prettyVersion = LIBXSLT_DOTTED_VERSION; |
|
| 105 | - break; |
|
| 106 | - |
|
| 107 | - default: |
|
| 108 | - // None handled extensions have no special cases, skip |
|
| 109 | - continue 2; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - try { |
|
| 113 | - $prettyVersion = $this->normalizeVersion($prettyVersion); |
|
| 114 | - } catch (\UnexpectedValueException $e) { |
|
| 115 | - continue; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - $packages[$this->buildPackageName($name)] = $prettyVersion; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - return $packages; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - private function buildPackageName($name) { |
|
| 125 | - return str_replace(' ', '-', $name); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @param $name |
|
| 130 | - * @return string |
|
| 131 | - */ |
|
| 132 | - public function findLibrary($name) { |
|
| 133 | - $extName = $this->buildPackageName($name); |
|
| 134 | - if (isset($this->packages[$extName])) { |
|
| 135 | - return $this->packages[$extName]; |
|
| 136 | - } |
|
| 137 | - return null; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - private static $modifierRegex = '[._-]?(?:(stable|beta|b|RC|alpha|a|patch|pl|p)(?:[.-]?(\d+))?)?([.-]?dev)?'; |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Normalizes a version string to be able to perform comparisons on it |
|
| 144 | - * |
|
| 145 | - * https://github.com/composer/composer/blob/master/src/Composer/Package/Version/VersionParser.php#L94 |
|
| 146 | - * |
|
| 147 | - * @param string $version |
|
| 148 | - * @param string $fullVersion optional complete version string to give more context |
|
| 149 | - * @throws \UnexpectedValueException |
|
| 150 | - * @return string |
|
| 151 | - */ |
|
| 152 | - public function normalizeVersion($version, $fullVersion = null) { |
|
| 153 | - $version = trim($version); |
|
| 154 | - if (null === $fullVersion) { |
|
| 155 | - $fullVersion = $version; |
|
| 156 | - } |
|
| 157 | - // ignore aliases and just assume the alias is required instead of the source |
|
| 158 | - if (preg_match('{^([^,\s]+) +as +([^,\s]+)$}', $version, $match)) { |
|
| 159 | - $version = $match[1]; |
|
| 160 | - } |
|
| 161 | - // match master-like branches |
|
| 162 | - if (preg_match('{^(?:dev-)?(?:master|trunk|default)$}i', $version)) { |
|
| 163 | - return '9999999-dev'; |
|
| 164 | - } |
|
| 165 | - if ('dev-' === strtolower(substr($version, 0, 4))) { |
|
| 166 | - return 'dev-' . substr($version, 4); |
|
| 167 | - } |
|
| 168 | - // match classical versioning |
|
| 169 | - if (preg_match('{^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?' . self::$modifierRegex . '$}i', $version, $matches)) { |
|
| 170 | - $version = $matches[1] |
|
| 171 | - . (!empty($matches[2]) ? $matches[2] : '.0') |
|
| 172 | - . (!empty($matches[3]) ? $matches[3] : '.0') |
|
| 173 | - . (!empty($matches[4]) ? $matches[4] : '.0'); |
|
| 174 | - $index = 5; |
|
| 175 | - } elseif (preg_match('{^v?(\d{4}(?:[.:-]?\d{2}){1,6}(?:[.:-]?\d{1,3})?)' . self::$modifierRegex . '$}i', $version, $matches)) { // match date-based versioning |
|
| 176 | - $version = preg_replace('{\D}', '-', $matches[1]); |
|
| 177 | - $index = 2; |
|
| 178 | - } elseif (preg_match('{^v?(\d{4,})(\.\d+)?(\.\d+)?(\.\d+)?' . self::$modifierRegex . '$}i', $version, $matches)) { |
|
| 179 | - $version = $matches[1] |
|
| 180 | - . (!empty($matches[2]) ? $matches[2] : '.0') |
|
| 181 | - . (!empty($matches[3]) ? $matches[3] : '.0') |
|
| 182 | - . (!empty($matches[4]) ? $matches[4] : '.0'); |
|
| 183 | - $index = 5; |
|
| 184 | - } |
|
| 185 | - // add version modifiers if a version was matched |
|
| 186 | - if (isset($index)) { |
|
| 187 | - if (!empty($matches[$index])) { |
|
| 188 | - if ('stable' === $matches[$index]) { |
|
| 189 | - return $version; |
|
| 190 | - } |
|
| 191 | - $version .= '-' . $this->expandStability($matches[$index]) . (!empty($matches[$index + 1]) ? $matches[$index + 1] : ''); |
|
| 192 | - } |
|
| 193 | - if (!empty($matches[$index + 2])) { |
|
| 194 | - $version .= '-dev'; |
|
| 195 | - } |
|
| 196 | - return $version; |
|
| 197 | - } |
|
| 198 | - $extraMessage = ''; |
|
| 199 | - if (preg_match('{ +as +' . preg_quote($version) . '$}', $fullVersion)) { |
|
| 200 | - $extraMessage = ' in "' . $fullVersion . '", the alias must be an exact version'; |
|
| 201 | - } elseif (preg_match('{^' . preg_quote($version) . ' +as +}', $fullVersion)) { |
|
| 202 | - $extraMessage = ' in "' . $fullVersion . '", the alias source must be an exact version, if it is a branch name you should prefix it with dev-'; |
|
| 203 | - } |
|
| 204 | - throw new \UnexpectedValueException('Invalid version string "' . $version . '"' . $extraMessage); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * @param string $stability |
|
| 209 | - */ |
|
| 210 | - private function expandStability($stability) { |
|
| 211 | - $stability = strtolower($stability); |
|
| 212 | - switch ($stability) { |
|
| 213 | - case 'a': |
|
| 214 | - return 'alpha'; |
|
| 215 | - case 'b': |
|
| 216 | - return 'beta'; |
|
| 217 | - case 'p': |
|
| 218 | - case 'pl': |
|
| 219 | - return 'patch'; |
|
| 220 | - case 'rc': |
|
| 221 | - return 'RC'; |
|
| 222 | - default: |
|
| 223 | - return $stability; |
|
| 224 | - } |
|
| 225 | - } |
|
| 34 | + public function __construct() { |
|
| 35 | + $this->packages = $this->initialize(); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + protected function initialize() { |
|
| 39 | + $loadedExtensions = get_loaded_extensions(); |
|
| 40 | + $packages = []; |
|
| 41 | + |
|
| 42 | + // Extensions scanning |
|
| 43 | + foreach ($loadedExtensions as $name) { |
|
| 44 | + if (in_array($name, ['standard', 'Core'])) { |
|
| 45 | + continue; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + $ext = new \ReflectionExtension($name); |
|
| 49 | + try { |
|
| 50 | + $prettyVersion = $ext->getVersion(); |
|
| 51 | + $prettyVersion = $this->normalizeVersion($prettyVersion); |
|
| 52 | + } catch (\UnexpectedValueException $e) { |
|
| 53 | + $prettyVersion = '0'; |
|
| 54 | + $prettyVersion = $this->normalizeVersion($prettyVersion); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + $packages[$this->buildPackageName($name)] = $prettyVersion; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + foreach ($loadedExtensions as $name) { |
|
| 61 | + $prettyVersion = null; |
|
| 62 | + switch ($name) { |
|
| 63 | + case 'curl': |
|
| 64 | + $curlVersion = curl_version(); |
|
| 65 | + $prettyVersion = $curlVersion['version']; |
|
| 66 | + break; |
|
| 67 | + |
|
| 68 | + case 'intl': |
|
| 69 | + $name = 'ICU'; |
|
| 70 | + if (defined('INTL_ICU_VERSION')) { |
|
| 71 | + $prettyVersion = INTL_ICU_VERSION; |
|
| 72 | + } else { |
|
| 73 | + $reflector = new \ReflectionExtension('intl'); |
|
| 74 | + |
|
| 75 | + ob_start(); |
|
| 76 | + $reflector->info(); |
|
| 77 | + $output = ob_get_clean(); |
|
| 78 | + |
|
| 79 | + preg_match('/^ICU version => (.*)$/m', $output, $matches); |
|
| 80 | + $prettyVersion = $matches[1]; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + break; |
|
| 84 | + |
|
| 85 | + case 'libxml': |
|
| 86 | + $prettyVersion = LIBXML_DOTTED_VERSION; |
|
| 87 | + break; |
|
| 88 | + |
|
| 89 | + case 'openssl': |
|
| 90 | + $prettyVersion = preg_replace_callback('{^(?:OpenSSL\s*)?([0-9.]+)([a-z]?).*}', function ($match) { |
|
| 91 | + return $match[1] . (empty($match[2]) ? '' : '.' . (ord($match[2]) - 96)); |
|
| 92 | + }, OPENSSL_VERSION_TEXT); |
|
| 93 | + break; |
|
| 94 | + |
|
| 95 | + case 'pcre': |
|
| 96 | + $prettyVersion = preg_replace('{^(\S+).*}', '$1', PCRE_VERSION); |
|
| 97 | + break; |
|
| 98 | + |
|
| 99 | + case 'uuid': |
|
| 100 | + $prettyVersion = phpversion('uuid'); |
|
| 101 | + break; |
|
| 102 | + |
|
| 103 | + case 'xsl': |
|
| 104 | + $prettyVersion = LIBXSLT_DOTTED_VERSION; |
|
| 105 | + break; |
|
| 106 | + |
|
| 107 | + default: |
|
| 108 | + // None handled extensions have no special cases, skip |
|
| 109 | + continue 2; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + try { |
|
| 113 | + $prettyVersion = $this->normalizeVersion($prettyVersion); |
|
| 114 | + } catch (\UnexpectedValueException $e) { |
|
| 115 | + continue; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + $packages[$this->buildPackageName($name)] = $prettyVersion; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + return $packages; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + private function buildPackageName($name) { |
|
| 125 | + return str_replace(' ', '-', $name); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @param $name |
|
| 130 | + * @return string |
|
| 131 | + */ |
|
| 132 | + public function findLibrary($name) { |
|
| 133 | + $extName = $this->buildPackageName($name); |
|
| 134 | + if (isset($this->packages[$extName])) { |
|
| 135 | + return $this->packages[$extName]; |
|
| 136 | + } |
|
| 137 | + return null; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + private static $modifierRegex = '[._-]?(?:(stable|beta|b|RC|alpha|a|patch|pl|p)(?:[.-]?(\d+))?)?([.-]?dev)?'; |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Normalizes a version string to be able to perform comparisons on it |
|
| 144 | + * |
|
| 145 | + * https://github.com/composer/composer/blob/master/src/Composer/Package/Version/VersionParser.php#L94 |
|
| 146 | + * |
|
| 147 | + * @param string $version |
|
| 148 | + * @param string $fullVersion optional complete version string to give more context |
|
| 149 | + * @throws \UnexpectedValueException |
|
| 150 | + * @return string |
|
| 151 | + */ |
|
| 152 | + public function normalizeVersion($version, $fullVersion = null) { |
|
| 153 | + $version = trim($version); |
|
| 154 | + if (null === $fullVersion) { |
|
| 155 | + $fullVersion = $version; |
|
| 156 | + } |
|
| 157 | + // ignore aliases and just assume the alias is required instead of the source |
|
| 158 | + if (preg_match('{^([^,\s]+) +as +([^,\s]+)$}', $version, $match)) { |
|
| 159 | + $version = $match[1]; |
|
| 160 | + } |
|
| 161 | + // match master-like branches |
|
| 162 | + if (preg_match('{^(?:dev-)?(?:master|trunk|default)$}i', $version)) { |
|
| 163 | + return '9999999-dev'; |
|
| 164 | + } |
|
| 165 | + if ('dev-' === strtolower(substr($version, 0, 4))) { |
|
| 166 | + return 'dev-' . substr($version, 4); |
|
| 167 | + } |
|
| 168 | + // match classical versioning |
|
| 169 | + if (preg_match('{^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?' . self::$modifierRegex . '$}i', $version, $matches)) { |
|
| 170 | + $version = $matches[1] |
|
| 171 | + . (!empty($matches[2]) ? $matches[2] : '.0') |
|
| 172 | + . (!empty($matches[3]) ? $matches[3] : '.0') |
|
| 173 | + . (!empty($matches[4]) ? $matches[4] : '.0'); |
|
| 174 | + $index = 5; |
|
| 175 | + } elseif (preg_match('{^v?(\d{4}(?:[.:-]?\d{2}){1,6}(?:[.:-]?\d{1,3})?)' . self::$modifierRegex . '$}i', $version, $matches)) { // match date-based versioning |
|
| 176 | + $version = preg_replace('{\D}', '-', $matches[1]); |
|
| 177 | + $index = 2; |
|
| 178 | + } elseif (preg_match('{^v?(\d{4,})(\.\d+)?(\.\d+)?(\.\d+)?' . self::$modifierRegex . '$}i', $version, $matches)) { |
|
| 179 | + $version = $matches[1] |
|
| 180 | + . (!empty($matches[2]) ? $matches[2] : '.0') |
|
| 181 | + . (!empty($matches[3]) ? $matches[3] : '.0') |
|
| 182 | + . (!empty($matches[4]) ? $matches[4] : '.0'); |
|
| 183 | + $index = 5; |
|
| 184 | + } |
|
| 185 | + // add version modifiers if a version was matched |
|
| 186 | + if (isset($index)) { |
|
| 187 | + if (!empty($matches[$index])) { |
|
| 188 | + if ('stable' === $matches[$index]) { |
|
| 189 | + return $version; |
|
| 190 | + } |
|
| 191 | + $version .= '-' . $this->expandStability($matches[$index]) . (!empty($matches[$index + 1]) ? $matches[$index + 1] : ''); |
|
| 192 | + } |
|
| 193 | + if (!empty($matches[$index + 2])) { |
|
| 194 | + $version .= '-dev'; |
|
| 195 | + } |
|
| 196 | + return $version; |
|
| 197 | + } |
|
| 198 | + $extraMessage = ''; |
|
| 199 | + if (preg_match('{ +as +' . preg_quote($version) . '$}', $fullVersion)) { |
|
| 200 | + $extraMessage = ' in "' . $fullVersion . '", the alias must be an exact version'; |
|
| 201 | + } elseif (preg_match('{^' . preg_quote($version) . ' +as +}', $fullVersion)) { |
|
| 202 | + $extraMessage = ' in "' . $fullVersion . '", the alias source must be an exact version, if it is a branch name you should prefix it with dev-'; |
|
| 203 | + } |
|
| 204 | + throw new \UnexpectedValueException('Invalid version string "' . $version . '"' . $extraMessage); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * @param string $stability |
|
| 209 | + */ |
|
| 210 | + private function expandStability($stability) { |
|
| 211 | + $stability = strtolower($stability); |
|
| 212 | + switch ($stability) { |
|
| 213 | + case 'a': |
|
| 214 | + return 'alpha'; |
|
| 215 | + case 'b': |
|
| 216 | + return 'beta'; |
|
| 217 | + case 'p': |
|
| 218 | + case 'pl': |
|
| 219 | + return 'patch'; |
|
| 220 | + case 'rc': |
|
| 221 | + return 'RC'; |
|
| 222 | + default: |
|
| 223 | + return $stability; |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | 226 | } |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | * @return string Formatted date and time string |
| 238 | 238 | */ |
| 239 | 239 | public function formatDateTime($timestamp, $formatDate = 'long', $formatTime = 'medium', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null) { |
| 240 | - return $this->format($timestamp, 'datetime', $formatDate . '|' . $formatTime, $timeZone, $l); |
|
| 240 | + return $this->format($timestamp, 'datetime', $formatDate.'|'.$formatTime, $timeZone, $l); |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | /** |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | $formatDate .= '^'; |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - return $this->format($timestamp, 'datetime', $formatDate . '|' . $formatTime, $timeZone, $l); |
|
| 259 | + return $this->format($timestamp, 'datetime', $formatDate.'|'.$formatTime, $timeZone, $l); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -26,294 +26,294 @@ |
||
| 26 | 26 | namespace OC; |
| 27 | 27 | |
| 28 | 28 | class DateTimeFormatter implements \OCP\IDateTimeFormatter { |
| 29 | - /** @var \DateTimeZone */ |
|
| 30 | - protected $defaultTimeZone; |
|
| 29 | + /** @var \DateTimeZone */ |
|
| 30 | + protected $defaultTimeZone; |
|
| 31 | 31 | |
| 32 | - /** @var \OCP\IL10N */ |
|
| 33 | - protected $defaultL10N; |
|
| 32 | + /** @var \OCP\IL10N */ |
|
| 33 | + protected $defaultL10N; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Constructor |
|
| 37 | - * |
|
| 38 | - * @param \DateTimeZone $defaultTimeZone Set the timezone for the format |
|
| 39 | - * @param \OCP\IL10N $defaultL10N Set the language for the format |
|
| 40 | - */ |
|
| 41 | - public function __construct(\DateTimeZone $defaultTimeZone, \OCP\IL10N $defaultL10N) { |
|
| 42 | - $this->defaultTimeZone = $defaultTimeZone; |
|
| 43 | - $this->defaultL10N = $defaultL10N; |
|
| 44 | - } |
|
| 35 | + /** |
|
| 36 | + * Constructor |
|
| 37 | + * |
|
| 38 | + * @param \DateTimeZone $defaultTimeZone Set the timezone for the format |
|
| 39 | + * @param \OCP\IL10N $defaultL10N Set the language for the format |
|
| 40 | + */ |
|
| 41 | + public function __construct(\DateTimeZone $defaultTimeZone, \OCP\IL10N $defaultL10N) { |
|
| 42 | + $this->defaultTimeZone = $defaultTimeZone; |
|
| 43 | + $this->defaultL10N = $defaultL10N; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Get TimeZone to use |
|
| 48 | - * |
|
| 49 | - * @param \DateTimeZone $timeZone The timezone to use |
|
| 50 | - * @return \DateTimeZone The timezone to use, falling back to the current user's timezone |
|
| 51 | - */ |
|
| 52 | - protected function getTimeZone($timeZone = null) { |
|
| 53 | - if ($timeZone === null) { |
|
| 54 | - $timeZone = $this->defaultTimeZone; |
|
| 55 | - } |
|
| 46 | + /** |
|
| 47 | + * Get TimeZone to use |
|
| 48 | + * |
|
| 49 | + * @param \DateTimeZone $timeZone The timezone to use |
|
| 50 | + * @return \DateTimeZone The timezone to use, falling back to the current user's timezone |
|
| 51 | + */ |
|
| 52 | + protected function getTimeZone($timeZone = null) { |
|
| 53 | + if ($timeZone === null) { |
|
| 54 | + $timeZone = $this->defaultTimeZone; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - return $timeZone; |
|
| 58 | - } |
|
| 57 | + return $timeZone; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Get \OCP\IL10N to use |
|
| 62 | - * |
|
| 63 | - * @param \OCP\IL10N $l The locale to use |
|
| 64 | - * @return \OCP\IL10N The locale to use, falling back to the current user's locale |
|
| 65 | - */ |
|
| 66 | - protected function getLocale($l = null) { |
|
| 67 | - if ($l === null) { |
|
| 68 | - $l = $this->defaultL10N; |
|
| 69 | - } |
|
| 60 | + /** |
|
| 61 | + * Get \OCP\IL10N to use |
|
| 62 | + * |
|
| 63 | + * @param \OCP\IL10N $l The locale to use |
|
| 64 | + * @return \OCP\IL10N The locale to use, falling back to the current user's locale |
|
| 65 | + */ |
|
| 66 | + protected function getLocale($l = null) { |
|
| 67 | + if ($l === null) { |
|
| 68 | + $l = $this->defaultL10N; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - return $l; |
|
| 72 | - } |
|
| 71 | + return $l; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Generates a DateTime object with the given timestamp and TimeZone |
|
| 76 | - * |
|
| 77 | - * @param mixed $timestamp |
|
| 78 | - * @param \DateTimeZone $timeZone The timezone to use |
|
| 79 | - * @return \DateTime |
|
| 80 | - */ |
|
| 81 | - protected function getDateTime($timestamp, \DateTimeZone $timeZone = null) { |
|
| 82 | - if ($timestamp === null) { |
|
| 83 | - return new \DateTime('now', $timeZone); |
|
| 84 | - } elseif (!$timestamp instanceof \DateTime) { |
|
| 85 | - $dateTime = new \DateTime('now', $timeZone); |
|
| 86 | - $dateTime->setTimestamp($timestamp); |
|
| 87 | - return $dateTime; |
|
| 88 | - } |
|
| 89 | - if ($timeZone) { |
|
| 90 | - $timestamp->setTimezone($timeZone); |
|
| 91 | - } |
|
| 92 | - return $timestamp; |
|
| 93 | - } |
|
| 74 | + /** |
|
| 75 | + * Generates a DateTime object with the given timestamp and TimeZone |
|
| 76 | + * |
|
| 77 | + * @param mixed $timestamp |
|
| 78 | + * @param \DateTimeZone $timeZone The timezone to use |
|
| 79 | + * @return \DateTime |
|
| 80 | + */ |
|
| 81 | + protected function getDateTime($timestamp, \DateTimeZone $timeZone = null) { |
|
| 82 | + if ($timestamp === null) { |
|
| 83 | + return new \DateTime('now', $timeZone); |
|
| 84 | + } elseif (!$timestamp instanceof \DateTime) { |
|
| 85 | + $dateTime = new \DateTime('now', $timeZone); |
|
| 86 | + $dateTime->setTimestamp($timestamp); |
|
| 87 | + return $dateTime; |
|
| 88 | + } |
|
| 89 | + if ($timeZone) { |
|
| 90 | + $timestamp->setTimezone($timeZone); |
|
| 91 | + } |
|
| 92 | + return $timestamp; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Formats the date of the given timestamp |
|
| 97 | - * |
|
| 98 | - * @param int|\DateTime $timestamp Either a Unix timestamp or DateTime object |
|
| 99 | - * @param string $format Either 'full', 'long', 'medium' or 'short' |
|
| 100 | - * full: e.g. 'EEEE, MMMM d, y' => 'Wednesday, August 20, 2014' |
|
| 101 | - * long: e.g. 'MMMM d, y' => 'August 20, 2014' |
|
| 102 | - * medium: e.g. 'MMM d, y' => 'Aug 20, 2014' |
|
| 103 | - * short: e.g. 'M/d/yy' => '8/20/14' |
|
| 104 | - * The exact format is dependent on the language |
|
| 105 | - * @param \DateTimeZone $timeZone The timezone to use |
|
| 106 | - * @param \OCP\IL10N $l The locale to use |
|
| 107 | - * @return string Formatted date string |
|
| 108 | - */ |
|
| 109 | - public function formatDate($timestamp, $format = 'long', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null) { |
|
| 110 | - return $this->format($timestamp, 'date', $format, $timeZone, $l); |
|
| 111 | - } |
|
| 95 | + /** |
|
| 96 | + * Formats the date of the given timestamp |
|
| 97 | + * |
|
| 98 | + * @param int|\DateTime $timestamp Either a Unix timestamp or DateTime object |
|
| 99 | + * @param string $format Either 'full', 'long', 'medium' or 'short' |
|
| 100 | + * full: e.g. 'EEEE, MMMM d, y' => 'Wednesday, August 20, 2014' |
|
| 101 | + * long: e.g. 'MMMM d, y' => 'August 20, 2014' |
|
| 102 | + * medium: e.g. 'MMM d, y' => 'Aug 20, 2014' |
|
| 103 | + * short: e.g. 'M/d/yy' => '8/20/14' |
|
| 104 | + * The exact format is dependent on the language |
|
| 105 | + * @param \DateTimeZone $timeZone The timezone to use |
|
| 106 | + * @param \OCP\IL10N $l The locale to use |
|
| 107 | + * @return string Formatted date string |
|
| 108 | + */ |
|
| 109 | + public function formatDate($timestamp, $format = 'long', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null) { |
|
| 110 | + return $this->format($timestamp, 'date', $format, $timeZone, $l); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * Formats the date of the given timestamp |
|
| 115 | - * |
|
| 116 | - * @param int|\DateTime $timestamp Either a Unix timestamp or DateTime object |
|
| 117 | - * @param string $format Either 'full', 'long', 'medium' or 'short' |
|
| 118 | - * full: e.g. 'EEEE, MMMM d, y' => 'Wednesday, August 20, 2014' |
|
| 119 | - * long: e.g. 'MMMM d, y' => 'August 20, 2014' |
|
| 120 | - * medium: e.g. 'MMM d, y' => 'Aug 20, 2014' |
|
| 121 | - * short: e.g. 'M/d/yy' => '8/20/14' |
|
| 122 | - * The exact format is dependent on the language |
|
| 123 | - * Uses 'Today', 'Yesterday' and 'Tomorrow' when applicable |
|
| 124 | - * @param \DateTimeZone $timeZone The timezone to use |
|
| 125 | - * @param \OCP\IL10N $l The locale to use |
|
| 126 | - * @return string Formatted relative date string |
|
| 127 | - */ |
|
| 128 | - public function formatDateRelativeDay($timestamp, $format = 'long', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null) { |
|
| 129 | - if (substr($format, -1) !== '*' && substr($format, -1) !== '*') { |
|
| 130 | - $format .= '^'; |
|
| 131 | - } |
|
| 113 | + /** |
|
| 114 | + * Formats the date of the given timestamp |
|
| 115 | + * |
|
| 116 | + * @param int|\DateTime $timestamp Either a Unix timestamp or DateTime object |
|
| 117 | + * @param string $format Either 'full', 'long', 'medium' or 'short' |
|
| 118 | + * full: e.g. 'EEEE, MMMM d, y' => 'Wednesday, August 20, 2014' |
|
| 119 | + * long: e.g. 'MMMM d, y' => 'August 20, 2014' |
|
| 120 | + * medium: e.g. 'MMM d, y' => 'Aug 20, 2014' |
|
| 121 | + * short: e.g. 'M/d/yy' => '8/20/14' |
|
| 122 | + * The exact format is dependent on the language |
|
| 123 | + * Uses 'Today', 'Yesterday' and 'Tomorrow' when applicable |
|
| 124 | + * @param \DateTimeZone $timeZone The timezone to use |
|
| 125 | + * @param \OCP\IL10N $l The locale to use |
|
| 126 | + * @return string Formatted relative date string |
|
| 127 | + */ |
|
| 128 | + public function formatDateRelativeDay($timestamp, $format = 'long', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null) { |
|
| 129 | + if (substr($format, -1) !== '*' && substr($format, -1) !== '*') { |
|
| 130 | + $format .= '^'; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - return $this->format($timestamp, 'date', $format, $timeZone, $l); |
|
| 134 | - } |
|
| 133 | + return $this->format($timestamp, 'date', $format, $timeZone, $l); |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * Gives the relative date of the timestamp |
|
| 138 | - * Only works for past dates |
|
| 139 | - * |
|
| 140 | - * @param int|\DateTime $timestamp Either a Unix timestamp or DateTime object |
|
| 141 | - * @param int|\DateTime $baseTimestamp Timestamp to compare $timestamp against, defaults to current time |
|
| 142 | - * @return string Dates returned are: |
|
| 143 | - * < 1 month => Today, Yesterday, n days ago |
|
| 144 | - * < 13 month => last month, n months ago |
|
| 145 | - * >= 13 month => last year, n years ago |
|
| 146 | - * @param \OCP\IL10N $l The locale to use |
|
| 147 | - * @return string Formatted date span |
|
| 148 | - */ |
|
| 149 | - public function formatDateSpan($timestamp, $baseTimestamp = null, \OCP\IL10N $l = null) { |
|
| 150 | - $l = $this->getLocale($l); |
|
| 151 | - $timestamp = $this->getDateTime($timestamp); |
|
| 152 | - $timestamp->setTime(0, 0, 0); |
|
| 136 | + /** |
|
| 137 | + * Gives the relative date of the timestamp |
|
| 138 | + * Only works for past dates |
|
| 139 | + * |
|
| 140 | + * @param int|\DateTime $timestamp Either a Unix timestamp or DateTime object |
|
| 141 | + * @param int|\DateTime $baseTimestamp Timestamp to compare $timestamp against, defaults to current time |
|
| 142 | + * @return string Dates returned are: |
|
| 143 | + * < 1 month => Today, Yesterday, n days ago |
|
| 144 | + * < 13 month => last month, n months ago |
|
| 145 | + * >= 13 month => last year, n years ago |
|
| 146 | + * @param \OCP\IL10N $l The locale to use |
|
| 147 | + * @return string Formatted date span |
|
| 148 | + */ |
|
| 149 | + public function formatDateSpan($timestamp, $baseTimestamp = null, \OCP\IL10N $l = null) { |
|
| 150 | + $l = $this->getLocale($l); |
|
| 151 | + $timestamp = $this->getDateTime($timestamp); |
|
| 152 | + $timestamp->setTime(0, 0, 0); |
|
| 153 | 153 | |
| 154 | - if ($baseTimestamp === null) { |
|
| 155 | - $baseTimestamp = time(); |
|
| 156 | - } |
|
| 157 | - $baseTimestamp = $this->getDateTime($baseTimestamp); |
|
| 158 | - $baseTimestamp->setTime(0, 0, 0); |
|
| 159 | - $dateInterval = $timestamp->diff($baseTimestamp); |
|
| 154 | + if ($baseTimestamp === null) { |
|
| 155 | + $baseTimestamp = time(); |
|
| 156 | + } |
|
| 157 | + $baseTimestamp = $this->getDateTime($baseTimestamp); |
|
| 158 | + $baseTimestamp->setTime(0, 0, 0); |
|
| 159 | + $dateInterval = $timestamp->diff($baseTimestamp); |
|
| 160 | 160 | |
| 161 | - if ($dateInterval->y == 0 && $dateInterval->m == 0 && $dateInterval->d == 0) { |
|
| 162 | - return $l->t('today'); |
|
| 163 | - } elseif ($dateInterval->y == 0 && $dateInterval->m == 0 && $dateInterval->d == 1) { |
|
| 164 | - if ($timestamp > $baseTimestamp) { |
|
| 165 | - return $l->t('tomorrow'); |
|
| 166 | - } else { |
|
| 167 | - return $l->t('yesterday'); |
|
| 168 | - } |
|
| 169 | - } elseif ($dateInterval->y == 0 && $dateInterval->m == 0) { |
|
| 170 | - if ($timestamp > $baseTimestamp) { |
|
| 171 | - return $l->n('in %n day', 'in %n days', $dateInterval->d); |
|
| 172 | - } else { |
|
| 173 | - return $l->n('%n day ago', '%n days ago', $dateInterval->d); |
|
| 174 | - } |
|
| 175 | - } elseif ($dateInterval->y == 0 && $dateInterval->m == 1) { |
|
| 176 | - if ($timestamp > $baseTimestamp) { |
|
| 177 | - return $l->t('next month'); |
|
| 178 | - } else { |
|
| 179 | - return $l->t('last month'); |
|
| 180 | - } |
|
| 181 | - } elseif ($dateInterval->y == 0) { |
|
| 182 | - if ($timestamp > $baseTimestamp) { |
|
| 183 | - return $l->n('in %n month', 'in %n months', $dateInterval->m); |
|
| 184 | - } else { |
|
| 185 | - return $l->n('%n month ago', '%n months ago', $dateInterval->m); |
|
| 186 | - } |
|
| 187 | - } elseif ($dateInterval->y == 1) { |
|
| 188 | - if ($timestamp > $baseTimestamp) { |
|
| 189 | - return $l->t('next year'); |
|
| 190 | - } else { |
|
| 191 | - return $l->t('last year'); |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - if ($timestamp > $baseTimestamp) { |
|
| 195 | - return $l->n('in %n year', 'in %n years', $dateInterval->y); |
|
| 196 | - } else { |
|
| 197 | - return $l->n('%n year ago', '%n years ago', $dateInterval->y); |
|
| 198 | - } |
|
| 199 | - } |
|
| 161 | + if ($dateInterval->y == 0 && $dateInterval->m == 0 && $dateInterval->d == 0) { |
|
| 162 | + return $l->t('today'); |
|
| 163 | + } elseif ($dateInterval->y == 0 && $dateInterval->m == 0 && $dateInterval->d == 1) { |
|
| 164 | + if ($timestamp > $baseTimestamp) { |
|
| 165 | + return $l->t('tomorrow'); |
|
| 166 | + } else { |
|
| 167 | + return $l->t('yesterday'); |
|
| 168 | + } |
|
| 169 | + } elseif ($dateInterval->y == 0 && $dateInterval->m == 0) { |
|
| 170 | + if ($timestamp > $baseTimestamp) { |
|
| 171 | + return $l->n('in %n day', 'in %n days', $dateInterval->d); |
|
| 172 | + } else { |
|
| 173 | + return $l->n('%n day ago', '%n days ago', $dateInterval->d); |
|
| 174 | + } |
|
| 175 | + } elseif ($dateInterval->y == 0 && $dateInterval->m == 1) { |
|
| 176 | + if ($timestamp > $baseTimestamp) { |
|
| 177 | + return $l->t('next month'); |
|
| 178 | + } else { |
|
| 179 | + return $l->t('last month'); |
|
| 180 | + } |
|
| 181 | + } elseif ($dateInterval->y == 0) { |
|
| 182 | + if ($timestamp > $baseTimestamp) { |
|
| 183 | + return $l->n('in %n month', 'in %n months', $dateInterval->m); |
|
| 184 | + } else { |
|
| 185 | + return $l->n('%n month ago', '%n months ago', $dateInterval->m); |
|
| 186 | + } |
|
| 187 | + } elseif ($dateInterval->y == 1) { |
|
| 188 | + if ($timestamp > $baseTimestamp) { |
|
| 189 | + return $l->t('next year'); |
|
| 190 | + } else { |
|
| 191 | + return $l->t('last year'); |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + if ($timestamp > $baseTimestamp) { |
|
| 195 | + return $l->n('in %n year', 'in %n years', $dateInterval->y); |
|
| 196 | + } else { |
|
| 197 | + return $l->n('%n year ago', '%n years ago', $dateInterval->y); |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * Formats the time of the given timestamp |
|
| 203 | - * |
|
| 204 | - * @param int|\DateTime $timestamp Either a Unix timestamp or DateTime object |
|
| 205 | - * @param string $format Either 'full', 'long', 'medium' or 'short' |
|
| 206 | - * full: e.g. 'h:mm:ss a zzzz' => '11:42:13 AM GMT+0:00' |
|
| 207 | - * long: e.g. 'h:mm:ss a z' => '11:42:13 AM GMT' |
|
| 208 | - * medium: e.g. 'h:mm:ss a' => '11:42:13 AM' |
|
| 209 | - * short: e.g. 'h:mm a' => '11:42 AM' |
|
| 210 | - * The exact format is dependent on the language |
|
| 211 | - * @param \DateTimeZone $timeZone The timezone to use |
|
| 212 | - * @param \OCP\IL10N $l The locale to use |
|
| 213 | - * @return string Formatted time string |
|
| 214 | - */ |
|
| 215 | - public function formatTime($timestamp, $format = 'medium', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null) { |
|
| 216 | - return $this->format($timestamp, 'time', $format, $timeZone, $l); |
|
| 217 | - } |
|
| 201 | + /** |
|
| 202 | + * Formats the time of the given timestamp |
|
| 203 | + * |
|
| 204 | + * @param int|\DateTime $timestamp Either a Unix timestamp or DateTime object |
|
| 205 | + * @param string $format Either 'full', 'long', 'medium' or 'short' |
|
| 206 | + * full: e.g. 'h:mm:ss a zzzz' => '11:42:13 AM GMT+0:00' |
|
| 207 | + * long: e.g. 'h:mm:ss a z' => '11:42:13 AM GMT' |
|
| 208 | + * medium: e.g. 'h:mm:ss a' => '11:42:13 AM' |
|
| 209 | + * short: e.g. 'h:mm a' => '11:42 AM' |
|
| 210 | + * The exact format is dependent on the language |
|
| 211 | + * @param \DateTimeZone $timeZone The timezone to use |
|
| 212 | + * @param \OCP\IL10N $l The locale to use |
|
| 213 | + * @return string Formatted time string |
|
| 214 | + */ |
|
| 215 | + public function formatTime($timestamp, $format = 'medium', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null) { |
|
| 216 | + return $this->format($timestamp, 'time', $format, $timeZone, $l); |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - /** |
|
| 220 | - * Gives the relative past time of the timestamp |
|
| 221 | - * |
|
| 222 | - * @param int|\DateTime $timestamp Either a Unix timestamp or DateTime object |
|
| 223 | - * @param int|\DateTime $baseTimestamp Timestamp to compare $timestamp against, defaults to current time |
|
| 224 | - * @return string Dates returned are: |
|
| 225 | - * < 60 sec => seconds ago |
|
| 226 | - * < 1 hour => n minutes ago |
|
| 227 | - * < 1 day => n hours ago |
|
| 228 | - * < 1 month => Yesterday, n days ago |
|
| 229 | - * < 13 month => last month, n months ago |
|
| 230 | - * >= 13 month => last year, n years ago |
|
| 231 | - * @param \OCP\IL10N $l The locale to use |
|
| 232 | - * @return string Formatted time span |
|
| 233 | - */ |
|
| 234 | - public function formatTimeSpan($timestamp, $baseTimestamp = null, \OCP\IL10N $l = null) { |
|
| 235 | - $l = $this->getLocale($l); |
|
| 236 | - $timestamp = $this->getDateTime($timestamp); |
|
| 237 | - if ($baseTimestamp === null) { |
|
| 238 | - $baseTimestamp = time(); |
|
| 239 | - } |
|
| 240 | - $baseTimestamp = $this->getDateTime($baseTimestamp); |
|
| 219 | + /** |
|
| 220 | + * Gives the relative past time of the timestamp |
|
| 221 | + * |
|
| 222 | + * @param int|\DateTime $timestamp Either a Unix timestamp or DateTime object |
|
| 223 | + * @param int|\DateTime $baseTimestamp Timestamp to compare $timestamp against, defaults to current time |
|
| 224 | + * @return string Dates returned are: |
|
| 225 | + * < 60 sec => seconds ago |
|
| 226 | + * < 1 hour => n minutes ago |
|
| 227 | + * < 1 day => n hours ago |
|
| 228 | + * < 1 month => Yesterday, n days ago |
|
| 229 | + * < 13 month => last month, n months ago |
|
| 230 | + * >= 13 month => last year, n years ago |
|
| 231 | + * @param \OCP\IL10N $l The locale to use |
|
| 232 | + * @return string Formatted time span |
|
| 233 | + */ |
|
| 234 | + public function formatTimeSpan($timestamp, $baseTimestamp = null, \OCP\IL10N $l = null) { |
|
| 235 | + $l = $this->getLocale($l); |
|
| 236 | + $timestamp = $this->getDateTime($timestamp); |
|
| 237 | + if ($baseTimestamp === null) { |
|
| 238 | + $baseTimestamp = time(); |
|
| 239 | + } |
|
| 240 | + $baseTimestamp = $this->getDateTime($baseTimestamp); |
|
| 241 | 241 | |
| 242 | - $diff = $timestamp->diff($baseTimestamp); |
|
| 243 | - if ($diff->y > 0 || $diff->m > 0 || $diff->d > 0) { |
|
| 244 | - return $this->formatDateSpan($timestamp, $baseTimestamp, $l); |
|
| 245 | - } |
|
| 242 | + $diff = $timestamp->diff($baseTimestamp); |
|
| 243 | + if ($diff->y > 0 || $diff->m > 0 || $diff->d > 0) { |
|
| 244 | + return $this->formatDateSpan($timestamp, $baseTimestamp, $l); |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - if ($diff->h > 0) { |
|
| 248 | - if ($timestamp > $baseTimestamp) { |
|
| 249 | - return $l->n('in %n hour', 'in %n hours', $diff->h); |
|
| 250 | - } else { |
|
| 251 | - return $l->n('%n hour ago', '%n hours ago', $diff->h); |
|
| 252 | - } |
|
| 253 | - } elseif ($diff->i > 0) { |
|
| 254 | - if ($timestamp > $baseTimestamp) { |
|
| 255 | - return $l->n('in %n minute', 'in %n minutes', $diff->i); |
|
| 256 | - } else { |
|
| 257 | - return $l->n('%n minute ago', '%n minutes ago', $diff->i); |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - if ($timestamp > $baseTimestamp) { |
|
| 261 | - return $l->t('in a few seconds'); |
|
| 262 | - } else { |
|
| 263 | - return $l->t('seconds ago'); |
|
| 264 | - } |
|
| 265 | - } |
|
| 247 | + if ($diff->h > 0) { |
|
| 248 | + if ($timestamp > $baseTimestamp) { |
|
| 249 | + return $l->n('in %n hour', 'in %n hours', $diff->h); |
|
| 250 | + } else { |
|
| 251 | + return $l->n('%n hour ago', '%n hours ago', $diff->h); |
|
| 252 | + } |
|
| 253 | + } elseif ($diff->i > 0) { |
|
| 254 | + if ($timestamp > $baseTimestamp) { |
|
| 255 | + return $l->n('in %n minute', 'in %n minutes', $diff->i); |
|
| 256 | + } else { |
|
| 257 | + return $l->n('%n minute ago', '%n minutes ago', $diff->i); |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + if ($timestamp > $baseTimestamp) { |
|
| 261 | + return $l->t('in a few seconds'); |
|
| 262 | + } else { |
|
| 263 | + return $l->t('seconds ago'); |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - /** |
|
| 268 | - * Formats the date and time of the given timestamp |
|
| 269 | - * |
|
| 270 | - * @param int|\DateTime $timestamp Either a Unix timestamp or DateTime object |
|
| 271 | - * @param string $formatDate See formatDate() for description |
|
| 272 | - * @param string $formatTime See formatTime() for description |
|
| 273 | - * @param \DateTimeZone $timeZone The timezone to use |
|
| 274 | - * @param \OCP\IL10N $l The locale to use |
|
| 275 | - * @return string Formatted date and time string |
|
| 276 | - */ |
|
| 277 | - public function formatDateTime($timestamp, $formatDate = 'long', $formatTime = 'medium', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null) { |
|
| 278 | - return $this->format($timestamp, 'datetime', $formatDate . '|' . $formatTime, $timeZone, $l); |
|
| 279 | - } |
|
| 267 | + /** |
|
| 268 | + * Formats the date and time of the given timestamp |
|
| 269 | + * |
|
| 270 | + * @param int|\DateTime $timestamp Either a Unix timestamp or DateTime object |
|
| 271 | + * @param string $formatDate See formatDate() for description |
|
| 272 | + * @param string $formatTime See formatTime() for description |
|
| 273 | + * @param \DateTimeZone $timeZone The timezone to use |
|
| 274 | + * @param \OCP\IL10N $l The locale to use |
|
| 275 | + * @return string Formatted date and time string |
|
| 276 | + */ |
|
| 277 | + public function formatDateTime($timestamp, $formatDate = 'long', $formatTime = 'medium', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null) { |
|
| 278 | + return $this->format($timestamp, 'datetime', $formatDate . '|' . $formatTime, $timeZone, $l); |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - /** |
|
| 282 | - * Formats the date and time of the given timestamp |
|
| 283 | - * |
|
| 284 | - * @param int|\DateTime $timestamp Either a Unix timestamp or DateTime object |
|
| 285 | - * @param string $formatDate See formatDate() for description |
|
| 286 | - * Uses 'Today', 'Yesterday' and 'Tomorrow' when applicable |
|
| 287 | - * @param string $formatTime See formatTime() for description |
|
| 288 | - * @param \DateTimeZone $timeZone The timezone to use |
|
| 289 | - * @param \OCP\IL10N $l The locale to use |
|
| 290 | - * @return string Formatted relative date and time string |
|
| 291 | - */ |
|
| 292 | - public function formatDateTimeRelativeDay($timestamp, $formatDate = 'long', $formatTime = 'medium', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null) { |
|
| 293 | - if (substr($formatDate, -1) !== '^' && substr($formatDate, -1) !== '*') { |
|
| 294 | - $formatDate .= '^'; |
|
| 295 | - } |
|
| 281 | + /** |
|
| 282 | + * Formats the date and time of the given timestamp |
|
| 283 | + * |
|
| 284 | + * @param int|\DateTime $timestamp Either a Unix timestamp or DateTime object |
|
| 285 | + * @param string $formatDate See formatDate() for description |
|
| 286 | + * Uses 'Today', 'Yesterday' and 'Tomorrow' when applicable |
|
| 287 | + * @param string $formatTime See formatTime() for description |
|
| 288 | + * @param \DateTimeZone $timeZone The timezone to use |
|
| 289 | + * @param \OCP\IL10N $l The locale to use |
|
| 290 | + * @return string Formatted relative date and time string |
|
| 291 | + */ |
|
| 292 | + public function formatDateTimeRelativeDay($timestamp, $formatDate = 'long', $formatTime = 'medium', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null) { |
|
| 293 | + if (substr($formatDate, -1) !== '^' && substr($formatDate, -1) !== '*') { |
|
| 294 | + $formatDate .= '^'; |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | - return $this->format($timestamp, 'datetime', $formatDate . '|' . $formatTime, $timeZone, $l); |
|
| 298 | - } |
|
| 297 | + return $this->format($timestamp, 'datetime', $formatDate . '|' . $formatTime, $timeZone, $l); |
|
| 298 | + } |
|
| 299 | 299 | |
| 300 | - /** |
|
| 301 | - * Formats the date and time of the given timestamp |
|
| 302 | - * |
|
| 303 | - * @param int|\DateTime $timestamp Either a Unix timestamp or DateTime object |
|
| 304 | - * @param string $type One of 'date', 'datetime' or 'time' |
|
| 305 | - * @param string $format Format string |
|
| 306 | - * @param \DateTimeZone $timeZone The timezone to use |
|
| 307 | - * @param \OCP\IL10N $l The locale to use |
|
| 308 | - * @return string Formatted date and time string |
|
| 309 | - */ |
|
| 310 | - protected function format($timestamp, $type, $format, \DateTimeZone $timeZone = null, \OCP\IL10N $l = null) { |
|
| 311 | - $l = $this->getLocale($l); |
|
| 312 | - $timeZone = $this->getTimeZone($timeZone); |
|
| 313 | - $timestamp = $this->getDateTime($timestamp, $timeZone); |
|
| 300 | + /** |
|
| 301 | + * Formats the date and time of the given timestamp |
|
| 302 | + * |
|
| 303 | + * @param int|\DateTime $timestamp Either a Unix timestamp or DateTime object |
|
| 304 | + * @param string $type One of 'date', 'datetime' or 'time' |
|
| 305 | + * @param string $format Format string |
|
| 306 | + * @param \DateTimeZone $timeZone The timezone to use |
|
| 307 | + * @param \OCP\IL10N $l The locale to use |
|
| 308 | + * @return string Formatted date and time string |
|
| 309 | + */ |
|
| 310 | + protected function format($timestamp, $type, $format, \DateTimeZone $timeZone = null, \OCP\IL10N $l = null) { |
|
| 311 | + $l = $this->getLocale($l); |
|
| 312 | + $timeZone = $this->getTimeZone($timeZone); |
|
| 313 | + $timestamp = $this->getDateTime($timestamp, $timeZone); |
|
| 314 | 314 | |
| 315 | - return $l->l($type, $timestamp, [ |
|
| 316 | - 'width' => $format, |
|
| 317 | - ]); |
|
| 318 | - } |
|
| 315 | + return $l->l($type, $timestamp, [ |
|
| 316 | + 'width' => $format, |
|
| 317 | + ]); |
|
| 318 | + } |
|
| 319 | 319 | } |
@@ -28,41 +28,41 @@ |
||
| 28 | 28 | use OCP\Preview\IProvider; |
| 29 | 29 | |
| 30 | 30 | abstract class Provider implements IProvider { |
| 31 | - private $options; |
|
| 31 | + private $options; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Constructor |
|
| 35 | - * |
|
| 36 | - * @param array $options |
|
| 37 | - */ |
|
| 38 | - public function __construct(array $options = []) { |
|
| 39 | - $this->options = $options; |
|
| 40 | - } |
|
| 33 | + /** |
|
| 34 | + * Constructor |
|
| 35 | + * |
|
| 36 | + * @param array $options |
|
| 37 | + */ |
|
| 38 | + public function __construct(array $options = []) { |
|
| 39 | + $this->options = $options; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @return string Regex with the mimetypes that are supported by this provider |
|
| 44 | - */ |
|
| 45 | - abstract public function getMimeType(); |
|
| 42 | + /** |
|
| 43 | + * @return string Regex with the mimetypes that are supported by this provider |
|
| 44 | + */ |
|
| 45 | + abstract public function getMimeType(); |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Check if a preview can be generated for $path |
|
| 49 | - * |
|
| 50 | - * @param \OCP\Files\FileInfo $file |
|
| 51 | - * @return bool |
|
| 52 | - */ |
|
| 53 | - public function isAvailable(\OCP\Files\FileInfo $file) { |
|
| 54 | - return true; |
|
| 55 | - } |
|
| 47 | + /** |
|
| 48 | + * Check if a preview can be generated for $path |
|
| 49 | + * |
|
| 50 | + * @param \OCP\Files\FileInfo $file |
|
| 51 | + * @return bool |
|
| 52 | + */ |
|
| 53 | + public function isAvailable(\OCP\Files\FileInfo $file) { |
|
| 54 | + return true; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Generates thumbnail which fits in $maxX and $maxY and keeps the aspect ratio, for file at path $path |
|
| 59 | - * |
|
| 60 | - * @param string $path Path of file |
|
| 61 | - * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 62 | - * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 63 | - * @param bool $scalingup Disable/Enable upscaling of previews |
|
| 64 | - * @param \OC\Files\View $fileview fileview object of user folder |
|
| 65 | - * @return bool|\OCP\IImage false if no preview was generated |
|
| 66 | - */ |
|
| 67 | - abstract public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview); |
|
| 57 | + /** |
|
| 58 | + * Generates thumbnail which fits in $maxX and $maxY and keeps the aspect ratio, for file at path $path |
|
| 59 | + * |
|
| 60 | + * @param string $path Path of file |
|
| 61 | + * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 62 | + * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image |
|
| 63 | + * @param bool $scalingup Disable/Enable upscaling of previews |
|
| 64 | + * @param \OC\Files\View $fileview fileview object of user folder |
|
| 65 | + * @return bool|\OCP\IImage false if no preview was generated |
|
| 66 | + */ |
|
| 67 | + abstract public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview); |
|
| 68 | 68 | } |
@@ -27,12 +27,12 @@ |
||
| 27 | 27 | |
| 28 | 28 | class ModuleAlreadyExistsException extends GenericEncryptionException { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @param string $id |
|
| 32 | - * @param string $name |
|
| 33 | - */ |
|
| 34 | - public function __construct($id, $name) { |
|
| 35 | - parent::__construct('Id "' . $id . '" already used by encryption module "' . $name . '"'); |
|
| 36 | - } |
|
| 30 | + /** |
|
| 31 | + * @param string $id |
|
| 32 | + * @param string $name |
|
| 33 | + */ |
|
| 34 | + public function __construct($id, $name) { |
|
| 35 | + parent::__construct('Id "' . $id . '" already used by encryption module "' . $name . '"'); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | } |
@@ -32,7 +32,7 @@ |
||
| 32 | 32 | * @param string $name |
| 33 | 33 | */ |
| 34 | 34 | public function __construct($id, $name) { |
| 35 | - parent::__construct('Id "' . $id . '" already used by encryption module "' . $name . '"'); |
|
| 35 | + parent::__construct('Id "'.$id.'" already used by encryption module "'.$name.'"'); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | } |
@@ -27,10 +27,10 @@ |
||
| 27 | 27 | |
| 28 | 28 | class EncryptionHeaderKeyExistsException extends GenericEncryptionException { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @param string $key |
|
| 32 | - */ |
|
| 33 | - public function __construct($key) { |
|
| 34 | - parent::__construct('header key "'. $key . '" already reserved by ownCloud'); |
|
| 35 | - } |
|
| 30 | + /** |
|
| 31 | + * @param string $key |
|
| 32 | + */ |
|
| 33 | + public function __construct($key) { |
|
| 34 | + parent::__construct('header key "'. $key . '" already reserved by ownCloud'); |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -31,6 +31,6 @@ |
||
| 31 | 31 | * @param string $key |
| 32 | 32 | */ |
| 33 | 33 | public function __construct($key) { |
| 34 | - parent::__construct('header key "'. $key . '" already reserved by ownCloud'); |
|
| 34 | + parent::__construct('header key "'.$key.'" already reserved by ownCloud'); |
|
| 35 | 35 | } |
| 36 | 36 | } |
@@ -274,7 +274,7 @@ |
||
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | // check if key storage is mounted correctly |
| 277 | - if ($this->rootView->file_exists($rootDir . '/' . Storage::KEY_STORAGE_MARKER)) { |
|
| 277 | + if ($this->rootView->file_exists($rootDir.'/'.Storage::KEY_STORAGE_MARKER)) { |
|
| 278 | 278 | return true; |
| 279 | 279 | } |
| 280 | 280 | |
@@ -38,231 +38,231 @@ |
||
| 38 | 38 | |
| 39 | 39 | class Manager implements IManager { |
| 40 | 40 | |
| 41 | - /** @var array */ |
|
| 42 | - protected $encryptionModules; |
|
| 43 | - |
|
| 44 | - /** @var IConfig */ |
|
| 45 | - protected $config; |
|
| 46 | - |
|
| 47 | - /** @var ILogger */ |
|
| 48 | - protected $logger; |
|
| 49 | - |
|
| 50 | - /** @var Il10n */ |
|
| 51 | - protected $l; |
|
| 52 | - |
|
| 53 | - /** @var View */ |
|
| 54 | - protected $rootView; |
|
| 55 | - |
|
| 56 | - /** @var Util */ |
|
| 57 | - protected $util; |
|
| 58 | - |
|
| 59 | - /** @var ArrayCache */ |
|
| 60 | - protected $arrayCache; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @param IConfig $config |
|
| 64 | - * @param ILogger $logger |
|
| 65 | - * @param IL10N $l10n |
|
| 66 | - * @param View $rootView |
|
| 67 | - * @param Util $util |
|
| 68 | - * @param ArrayCache $arrayCache |
|
| 69 | - */ |
|
| 70 | - public function __construct(IConfig $config, ILogger $logger, IL10N $l10n, View $rootView, Util $util, ArrayCache $arrayCache) { |
|
| 71 | - $this->encryptionModules = []; |
|
| 72 | - $this->config = $config; |
|
| 73 | - $this->logger = $logger; |
|
| 74 | - $this->l = $l10n; |
|
| 75 | - $this->rootView = $rootView; |
|
| 76 | - $this->util = $util; |
|
| 77 | - $this->arrayCache = $arrayCache; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Check if encryption is enabled |
|
| 82 | - * |
|
| 83 | - * @return bool true if enabled, false if not |
|
| 84 | - */ |
|
| 85 | - public function isEnabled() { |
|
| 86 | - $installed = $this->config->getSystemValue('installed', false); |
|
| 87 | - if (!$installed) { |
|
| 88 | - return false; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - $enabled = $this->config->getAppValue('core', 'encryption_enabled', 'no'); |
|
| 92 | - return $enabled === 'yes'; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * check if new encryption is ready |
|
| 97 | - * |
|
| 98 | - * @return bool |
|
| 99 | - * @throws ServiceUnavailableException |
|
| 100 | - */ |
|
| 101 | - public function isReady() { |
|
| 102 | - if ($this->isKeyStorageReady() === false) { |
|
| 103 | - throw new ServiceUnavailableException('Key Storage is not ready'); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return true; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @param string $user |
|
| 111 | - */ |
|
| 112 | - public function isReadyForUser($user) { |
|
| 113 | - if (!$this->isReady()) { |
|
| 114 | - return false; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - foreach ($this->getEncryptionModules() as $module) { |
|
| 118 | - /** @var IEncryptionModule $m */ |
|
| 119 | - $m = call_user_func($module['callback']); |
|
| 120 | - if (!$m->isReadyForUser($user)) { |
|
| 121 | - return false; |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return true; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Registers an callback function which must return an encryption module instance |
|
| 130 | - * |
|
| 131 | - * @param string $id |
|
| 132 | - * @param string $displayName |
|
| 133 | - * @param callable $callback |
|
| 134 | - * @throws Exceptions\ModuleAlreadyExistsException |
|
| 135 | - */ |
|
| 136 | - public function registerEncryptionModule($id, $displayName, callable $callback) { |
|
| 137 | - if (isset($this->encryptionModules[$id])) { |
|
| 138 | - throw new Exceptions\ModuleAlreadyExistsException($id, $displayName); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - $this->encryptionModules[$id] = [ |
|
| 142 | - 'id' => $id, |
|
| 143 | - 'displayName' => $displayName, |
|
| 144 | - 'callback' => $callback, |
|
| 145 | - ]; |
|
| 146 | - |
|
| 147 | - $defaultEncryptionModuleId = $this->getDefaultEncryptionModuleId(); |
|
| 148 | - |
|
| 149 | - if (empty($defaultEncryptionModuleId)) { |
|
| 150 | - $this->setDefaultEncryptionModule($id); |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Unregisters an encryption module |
|
| 156 | - * |
|
| 157 | - * @param string $moduleId |
|
| 158 | - */ |
|
| 159 | - public function unregisterEncryptionModule($moduleId) { |
|
| 160 | - unset($this->encryptionModules[$moduleId]); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * get a list of all encryption modules |
|
| 165 | - * |
|
| 166 | - * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]] |
|
| 167 | - */ |
|
| 168 | - public function getEncryptionModules() { |
|
| 169 | - return $this->encryptionModules; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * get a specific encryption module |
|
| 174 | - * |
|
| 175 | - * @param string $moduleId |
|
| 176 | - * @return IEncryptionModule |
|
| 177 | - * @throws Exceptions\ModuleDoesNotExistsException |
|
| 178 | - */ |
|
| 179 | - public function getEncryptionModule($moduleId = '') { |
|
| 180 | - if (empty($moduleId)) { |
|
| 181 | - return $this->getDefaultEncryptionModule(); |
|
| 182 | - } |
|
| 183 | - if (isset($this->encryptionModules[$moduleId])) { |
|
| 184 | - return call_user_func($this->encryptionModules[$moduleId]['callback']); |
|
| 185 | - } |
|
| 186 | - $message = "Module with ID: $moduleId does not exist."; |
|
| 187 | - $hint = $this->l->t('Module with ID: %s does not exist. Please enable it in your apps settings or contact your administrator.', [$moduleId]); |
|
| 188 | - throw new Exceptions\ModuleDoesNotExistsException($message, $hint); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * get default encryption module |
|
| 193 | - * |
|
| 194 | - * @return \OCP\Encryption\IEncryptionModule |
|
| 195 | - * @throws Exceptions\ModuleDoesNotExistsException |
|
| 196 | - */ |
|
| 197 | - protected function getDefaultEncryptionModule() { |
|
| 198 | - $defaultModuleId = $this->getDefaultEncryptionModuleId(); |
|
| 199 | - if (empty($defaultModuleId)) { |
|
| 200 | - $message = 'No default encryption module defined'; |
|
| 201 | - throw new Exceptions\ModuleDoesNotExistsException($message); |
|
| 202 | - } |
|
| 203 | - if (isset($this->encryptionModules[$defaultModuleId])) { |
|
| 204 | - return call_user_func($this->encryptionModules[$defaultModuleId]['callback']); |
|
| 205 | - } |
|
| 206 | - $message = 'Default encryption module not loaded'; |
|
| 207 | - throw new Exceptions\ModuleDoesNotExistsException($message); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * set default encryption module Id |
|
| 212 | - * |
|
| 213 | - * @param string $moduleId |
|
| 214 | - * @return bool |
|
| 215 | - */ |
|
| 216 | - public function setDefaultEncryptionModule($moduleId) { |
|
| 217 | - try { |
|
| 218 | - $this->getEncryptionModule($moduleId); |
|
| 219 | - } catch (\Exception $e) { |
|
| 220 | - return false; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - $this->config->setAppValue('core', 'default_encryption_module', $moduleId); |
|
| 224 | - return true; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * get default encryption module Id |
|
| 229 | - * |
|
| 230 | - * @return string |
|
| 231 | - */ |
|
| 232 | - public function getDefaultEncryptionModuleId() { |
|
| 233 | - return $this->config->getAppValue('core', 'default_encryption_module'); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * Add storage wrapper |
|
| 238 | - */ |
|
| 239 | - public function setupStorage() { |
|
| 240 | - // If encryption is disabled and there are no loaded modules it makes no sense to load the wrapper |
|
| 241 | - if (!empty($this->encryptionModules) || $this->isEnabled()) { |
|
| 242 | - $encryptionWrapper = new EncryptionWrapper($this->arrayCache, $this, $this->logger); |
|
| 243 | - Filesystem::addStorageWrapper('oc_encryption', [$encryptionWrapper, 'wrapStorage'], 2); |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * check if key storage is ready |
|
| 250 | - * |
|
| 251 | - * @return bool |
|
| 252 | - */ |
|
| 253 | - protected function isKeyStorageReady() { |
|
| 254 | - $rootDir = $this->util->getKeyStorageRoot(); |
|
| 255 | - |
|
| 256 | - // the default root is always valid |
|
| 257 | - if ($rootDir === '') { |
|
| 258 | - return true; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - // check if key storage is mounted correctly |
|
| 262 | - if ($this->rootView->file_exists($rootDir . '/' . Storage::KEY_STORAGE_MARKER)) { |
|
| 263 | - return true; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - return false; |
|
| 267 | - } |
|
| 41 | + /** @var array */ |
|
| 42 | + protected $encryptionModules; |
|
| 43 | + |
|
| 44 | + /** @var IConfig */ |
|
| 45 | + protected $config; |
|
| 46 | + |
|
| 47 | + /** @var ILogger */ |
|
| 48 | + protected $logger; |
|
| 49 | + |
|
| 50 | + /** @var Il10n */ |
|
| 51 | + protected $l; |
|
| 52 | + |
|
| 53 | + /** @var View */ |
|
| 54 | + protected $rootView; |
|
| 55 | + |
|
| 56 | + /** @var Util */ |
|
| 57 | + protected $util; |
|
| 58 | + |
|
| 59 | + /** @var ArrayCache */ |
|
| 60 | + protected $arrayCache; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @param IConfig $config |
|
| 64 | + * @param ILogger $logger |
|
| 65 | + * @param IL10N $l10n |
|
| 66 | + * @param View $rootView |
|
| 67 | + * @param Util $util |
|
| 68 | + * @param ArrayCache $arrayCache |
|
| 69 | + */ |
|
| 70 | + public function __construct(IConfig $config, ILogger $logger, IL10N $l10n, View $rootView, Util $util, ArrayCache $arrayCache) { |
|
| 71 | + $this->encryptionModules = []; |
|
| 72 | + $this->config = $config; |
|
| 73 | + $this->logger = $logger; |
|
| 74 | + $this->l = $l10n; |
|
| 75 | + $this->rootView = $rootView; |
|
| 76 | + $this->util = $util; |
|
| 77 | + $this->arrayCache = $arrayCache; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Check if encryption is enabled |
|
| 82 | + * |
|
| 83 | + * @return bool true if enabled, false if not |
|
| 84 | + */ |
|
| 85 | + public function isEnabled() { |
|
| 86 | + $installed = $this->config->getSystemValue('installed', false); |
|
| 87 | + if (!$installed) { |
|
| 88 | + return false; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + $enabled = $this->config->getAppValue('core', 'encryption_enabled', 'no'); |
|
| 92 | + return $enabled === 'yes'; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * check if new encryption is ready |
|
| 97 | + * |
|
| 98 | + * @return bool |
|
| 99 | + * @throws ServiceUnavailableException |
|
| 100 | + */ |
|
| 101 | + public function isReady() { |
|
| 102 | + if ($this->isKeyStorageReady() === false) { |
|
| 103 | + throw new ServiceUnavailableException('Key Storage is not ready'); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return true; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @param string $user |
|
| 111 | + */ |
|
| 112 | + public function isReadyForUser($user) { |
|
| 113 | + if (!$this->isReady()) { |
|
| 114 | + return false; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + foreach ($this->getEncryptionModules() as $module) { |
|
| 118 | + /** @var IEncryptionModule $m */ |
|
| 119 | + $m = call_user_func($module['callback']); |
|
| 120 | + if (!$m->isReadyForUser($user)) { |
|
| 121 | + return false; |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return true; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Registers an callback function which must return an encryption module instance |
|
| 130 | + * |
|
| 131 | + * @param string $id |
|
| 132 | + * @param string $displayName |
|
| 133 | + * @param callable $callback |
|
| 134 | + * @throws Exceptions\ModuleAlreadyExistsException |
|
| 135 | + */ |
|
| 136 | + public function registerEncryptionModule($id, $displayName, callable $callback) { |
|
| 137 | + if (isset($this->encryptionModules[$id])) { |
|
| 138 | + throw new Exceptions\ModuleAlreadyExistsException($id, $displayName); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + $this->encryptionModules[$id] = [ |
|
| 142 | + 'id' => $id, |
|
| 143 | + 'displayName' => $displayName, |
|
| 144 | + 'callback' => $callback, |
|
| 145 | + ]; |
|
| 146 | + |
|
| 147 | + $defaultEncryptionModuleId = $this->getDefaultEncryptionModuleId(); |
|
| 148 | + |
|
| 149 | + if (empty($defaultEncryptionModuleId)) { |
|
| 150 | + $this->setDefaultEncryptionModule($id); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Unregisters an encryption module |
|
| 156 | + * |
|
| 157 | + * @param string $moduleId |
|
| 158 | + */ |
|
| 159 | + public function unregisterEncryptionModule($moduleId) { |
|
| 160 | + unset($this->encryptionModules[$moduleId]); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * get a list of all encryption modules |
|
| 165 | + * |
|
| 166 | + * @return array [id => ['id' => $id, 'displayName' => $displayName, 'callback' => callback]] |
|
| 167 | + */ |
|
| 168 | + public function getEncryptionModules() { |
|
| 169 | + return $this->encryptionModules; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * get a specific encryption module |
|
| 174 | + * |
|
| 175 | + * @param string $moduleId |
|
| 176 | + * @return IEncryptionModule |
|
| 177 | + * @throws Exceptions\ModuleDoesNotExistsException |
|
| 178 | + */ |
|
| 179 | + public function getEncryptionModule($moduleId = '') { |
|
| 180 | + if (empty($moduleId)) { |
|
| 181 | + return $this->getDefaultEncryptionModule(); |
|
| 182 | + } |
|
| 183 | + if (isset($this->encryptionModules[$moduleId])) { |
|
| 184 | + return call_user_func($this->encryptionModules[$moduleId]['callback']); |
|
| 185 | + } |
|
| 186 | + $message = "Module with ID: $moduleId does not exist."; |
|
| 187 | + $hint = $this->l->t('Module with ID: %s does not exist. Please enable it in your apps settings or contact your administrator.', [$moduleId]); |
|
| 188 | + throw new Exceptions\ModuleDoesNotExistsException($message, $hint); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * get default encryption module |
|
| 193 | + * |
|
| 194 | + * @return \OCP\Encryption\IEncryptionModule |
|
| 195 | + * @throws Exceptions\ModuleDoesNotExistsException |
|
| 196 | + */ |
|
| 197 | + protected function getDefaultEncryptionModule() { |
|
| 198 | + $defaultModuleId = $this->getDefaultEncryptionModuleId(); |
|
| 199 | + if (empty($defaultModuleId)) { |
|
| 200 | + $message = 'No default encryption module defined'; |
|
| 201 | + throw new Exceptions\ModuleDoesNotExistsException($message); |
|
| 202 | + } |
|
| 203 | + if (isset($this->encryptionModules[$defaultModuleId])) { |
|
| 204 | + return call_user_func($this->encryptionModules[$defaultModuleId]['callback']); |
|
| 205 | + } |
|
| 206 | + $message = 'Default encryption module not loaded'; |
|
| 207 | + throw new Exceptions\ModuleDoesNotExistsException($message); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * set default encryption module Id |
|
| 212 | + * |
|
| 213 | + * @param string $moduleId |
|
| 214 | + * @return bool |
|
| 215 | + */ |
|
| 216 | + public function setDefaultEncryptionModule($moduleId) { |
|
| 217 | + try { |
|
| 218 | + $this->getEncryptionModule($moduleId); |
|
| 219 | + } catch (\Exception $e) { |
|
| 220 | + return false; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + $this->config->setAppValue('core', 'default_encryption_module', $moduleId); |
|
| 224 | + return true; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * get default encryption module Id |
|
| 229 | + * |
|
| 230 | + * @return string |
|
| 231 | + */ |
|
| 232 | + public function getDefaultEncryptionModuleId() { |
|
| 233 | + return $this->config->getAppValue('core', 'default_encryption_module'); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * Add storage wrapper |
|
| 238 | + */ |
|
| 239 | + public function setupStorage() { |
|
| 240 | + // If encryption is disabled and there are no loaded modules it makes no sense to load the wrapper |
|
| 241 | + if (!empty($this->encryptionModules) || $this->isEnabled()) { |
|
| 242 | + $encryptionWrapper = new EncryptionWrapper($this->arrayCache, $this, $this->logger); |
|
| 243 | + Filesystem::addStorageWrapper('oc_encryption', [$encryptionWrapper, 'wrapStorage'], 2); |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * check if key storage is ready |
|
| 250 | + * |
|
| 251 | + * @return bool |
|
| 252 | + */ |
|
| 253 | + protected function isKeyStorageReady() { |
|
| 254 | + $rootDir = $this->util->getKeyStorageRoot(); |
|
| 255 | + |
|
| 256 | + // the default root is always valid |
|
| 257 | + if ($rootDir === '') { |
|
| 258 | + return true; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + // check if key storage is mounted correctly |
|
| 262 | + if ($this->rootView->file_exists($rootDir . '/' . Storage::KEY_STORAGE_MARKER)) { |
|
| 263 | + return true; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + return false; |
|
| 267 | + } |
|
| 268 | 268 | } |
@@ -117,8 +117,8 @@ |
||
| 117 | 117 | if ($aChunk !== $bChunk) { |
| 118 | 118 | // test first character (character comparison, not number comparison) |
| 119 | 119 | if ($aChunk[0] >= '0' && $aChunk[0] <= '9' && $bChunk[0] >= '0' && $bChunk[0] <= '9') { |
| 120 | - $aNum = (int)$aChunk; |
|
| 121 | - $bNum = (int)$bChunk; |
|
| 120 | + $aNum = (int) $aChunk; |
|
| 121 | + $bNum = (int) $bChunk; |
|
| 122 | 122 | return $aNum - $bNum; |
| 123 | 123 | } |
| 124 | 124 | return self::getCollator()->compare($aChunk, $bChunk); |
@@ -31,112 +31,112 @@ |
||
| 31 | 31 | use OCP\ILogger; |
| 32 | 32 | |
| 33 | 33 | class NaturalSort { |
| 34 | - private static $instance; |
|
| 35 | - private $collator; |
|
| 36 | - private $cache = []; |
|
| 34 | + private static $instance; |
|
| 35 | + private $collator; |
|
| 36 | + private $cache = []; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Instantiate a new \OC\NaturalSort instance. |
|
| 40 | - * @param object $injectedCollator |
|
| 41 | - */ |
|
| 42 | - public function __construct($injectedCollator = null) { |
|
| 43 | - // inject an instance of \Collator('en_US') to force using the php5-intl Collator |
|
| 44 | - // or inject an instance of \OC\NaturalSort_DefaultCollator to force using Owncloud's default collator |
|
| 45 | - if (isset($injectedCollator)) { |
|
| 46 | - $this->collator = $injectedCollator; |
|
| 47 | - \OCP\Util::writeLog('core', 'forced use of '.get_class($injectedCollator), ILogger::DEBUG); |
|
| 48 | - } |
|
| 49 | - } |
|
| 38 | + /** |
|
| 39 | + * Instantiate a new \OC\NaturalSort instance. |
|
| 40 | + * @param object $injectedCollator |
|
| 41 | + */ |
|
| 42 | + public function __construct($injectedCollator = null) { |
|
| 43 | + // inject an instance of \Collator('en_US') to force using the php5-intl Collator |
|
| 44 | + // or inject an instance of \OC\NaturalSort_DefaultCollator to force using Owncloud's default collator |
|
| 45 | + if (isset($injectedCollator)) { |
|
| 46 | + $this->collator = $injectedCollator; |
|
| 47 | + \OCP\Util::writeLog('core', 'forced use of '.get_class($injectedCollator), ILogger::DEBUG); |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Split the given string in chunks of numbers and strings |
|
| 53 | - * @param string $t string |
|
| 54 | - * @return array of strings and number chunks |
|
| 55 | - */ |
|
| 56 | - private function naturalSortChunkify($t) { |
|
| 57 | - // Adapted and ported to PHP from |
|
| 58 | - // http://my.opera.com/GreyWyvern/blog/show.dml/1671288 |
|
| 59 | - if (isset($this->cache[$t])) { |
|
| 60 | - return $this->cache[$t]; |
|
| 61 | - } |
|
| 62 | - $tz = []; |
|
| 63 | - $x = 0; |
|
| 64 | - $y = -1; |
|
| 65 | - $n = null; |
|
| 51 | + /** |
|
| 52 | + * Split the given string in chunks of numbers and strings |
|
| 53 | + * @param string $t string |
|
| 54 | + * @return array of strings and number chunks |
|
| 55 | + */ |
|
| 56 | + private function naturalSortChunkify($t) { |
|
| 57 | + // Adapted and ported to PHP from |
|
| 58 | + // http://my.opera.com/GreyWyvern/blog/show.dml/1671288 |
|
| 59 | + if (isset($this->cache[$t])) { |
|
| 60 | + return $this->cache[$t]; |
|
| 61 | + } |
|
| 62 | + $tz = []; |
|
| 63 | + $x = 0; |
|
| 64 | + $y = -1; |
|
| 65 | + $n = null; |
|
| 66 | 66 | |
| 67 | - while (isset($t[$x])) { |
|
| 68 | - $c = $t[$x]; |
|
| 69 | - // only include the dot in strings |
|
| 70 | - $m = ((!$n && $c === '.') || ($c >= '0' && $c <= '9')); |
|
| 71 | - if ($m !== $n) { |
|
| 72 | - // next chunk |
|
| 73 | - $y++; |
|
| 74 | - $tz[$y] = ''; |
|
| 75 | - $n = $m; |
|
| 76 | - } |
|
| 77 | - $tz[$y] .= $c; |
|
| 78 | - $x++; |
|
| 79 | - } |
|
| 80 | - $this->cache[$t] = $tz; |
|
| 81 | - return $tz; |
|
| 82 | - } |
|
| 67 | + while (isset($t[$x])) { |
|
| 68 | + $c = $t[$x]; |
|
| 69 | + // only include the dot in strings |
|
| 70 | + $m = ((!$n && $c === '.') || ($c >= '0' && $c <= '9')); |
|
| 71 | + if ($m !== $n) { |
|
| 72 | + // next chunk |
|
| 73 | + $y++; |
|
| 74 | + $tz[$y] = ''; |
|
| 75 | + $n = $m; |
|
| 76 | + } |
|
| 77 | + $tz[$y] .= $c; |
|
| 78 | + $x++; |
|
| 79 | + } |
|
| 80 | + $this->cache[$t] = $tz; |
|
| 81 | + return $tz; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Returns the string collator |
|
| 86 | - * @return \Collator string collator |
|
| 87 | - */ |
|
| 88 | - private function getCollator() { |
|
| 89 | - if (!isset($this->collator)) { |
|
| 90 | - // looks like the default is en_US_POSIX which yields wrong sorting with |
|
| 91 | - // German umlauts, so using en_US instead |
|
| 92 | - if (class_exists('Collator')) { |
|
| 93 | - $this->collator = new \Collator('en_US'); |
|
| 94 | - } else { |
|
| 95 | - $this->collator = new \OC\NaturalSort_DefaultCollator(); |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - return $this->collator; |
|
| 99 | - } |
|
| 84 | + /** |
|
| 85 | + * Returns the string collator |
|
| 86 | + * @return \Collator string collator |
|
| 87 | + */ |
|
| 88 | + private function getCollator() { |
|
| 89 | + if (!isset($this->collator)) { |
|
| 90 | + // looks like the default is en_US_POSIX which yields wrong sorting with |
|
| 91 | + // German umlauts, so using en_US instead |
|
| 92 | + if (class_exists('Collator')) { |
|
| 93 | + $this->collator = new \Collator('en_US'); |
|
| 94 | + } else { |
|
| 95 | + $this->collator = new \OC\NaturalSort_DefaultCollator(); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + return $this->collator; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Compare two strings to provide a natural sort |
|
| 103 | - * @param string $a first string to compare |
|
| 104 | - * @param string $b second string to compare |
|
| 105 | - * @return int -1 if $b comes before $a, 1 if $a comes before $b |
|
| 106 | - * or 0 if the strings are identical |
|
| 107 | - */ |
|
| 108 | - public function compare($a, $b) { |
|
| 109 | - // Needed because PHP doesn't sort correctly when numbers are enclosed in |
|
| 110 | - // parenthesis, even with NUMERIC_COLLATION enabled. |
|
| 111 | - // For example it gave ["test (2).txt", "test.txt"] |
|
| 112 | - // instead of ["test.txt", "test (2).txt"] |
|
| 113 | - $aa = self::naturalSortChunkify($a); |
|
| 114 | - $bb = self::naturalSortChunkify($b); |
|
| 101 | + /** |
|
| 102 | + * Compare two strings to provide a natural sort |
|
| 103 | + * @param string $a first string to compare |
|
| 104 | + * @param string $b second string to compare |
|
| 105 | + * @return int -1 if $b comes before $a, 1 if $a comes before $b |
|
| 106 | + * or 0 if the strings are identical |
|
| 107 | + */ |
|
| 108 | + public function compare($a, $b) { |
|
| 109 | + // Needed because PHP doesn't sort correctly when numbers are enclosed in |
|
| 110 | + // parenthesis, even with NUMERIC_COLLATION enabled. |
|
| 111 | + // For example it gave ["test (2).txt", "test.txt"] |
|
| 112 | + // instead of ["test.txt", "test (2).txt"] |
|
| 113 | + $aa = self::naturalSortChunkify($a); |
|
| 114 | + $bb = self::naturalSortChunkify($b); |
|
| 115 | 115 | |
| 116 | - for ($x = 0; isset($aa[$x]) && isset($bb[$x]); $x++) { |
|
| 117 | - $aChunk = $aa[$x]; |
|
| 118 | - $bChunk = $bb[$x]; |
|
| 119 | - if ($aChunk !== $bChunk) { |
|
| 120 | - // test first character (character comparison, not number comparison) |
|
| 121 | - if ($aChunk[0] >= '0' && $aChunk[0] <= '9' && $bChunk[0] >= '0' && $bChunk[0] <= '9') { |
|
| 122 | - $aNum = (int)$aChunk; |
|
| 123 | - $bNum = (int)$bChunk; |
|
| 124 | - return $aNum - $bNum; |
|
| 125 | - } |
|
| 126 | - return self::getCollator()->compare($aChunk, $bChunk); |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - return count($aa) - count($bb); |
|
| 130 | - } |
|
| 116 | + for ($x = 0; isset($aa[$x]) && isset($bb[$x]); $x++) { |
|
| 117 | + $aChunk = $aa[$x]; |
|
| 118 | + $bChunk = $bb[$x]; |
|
| 119 | + if ($aChunk !== $bChunk) { |
|
| 120 | + // test first character (character comparison, not number comparison) |
|
| 121 | + if ($aChunk[0] >= '0' && $aChunk[0] <= '9' && $bChunk[0] >= '0' && $bChunk[0] <= '9') { |
|
| 122 | + $aNum = (int)$aChunk; |
|
| 123 | + $bNum = (int)$bChunk; |
|
| 124 | + return $aNum - $bNum; |
|
| 125 | + } |
|
| 126 | + return self::getCollator()->compare($aChunk, $bChunk); |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + return count($aa) - count($bb); |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * Returns a singleton |
|
| 134 | - * @return \OC\NaturalSort instance |
|
| 135 | - */ |
|
| 136 | - public static function getInstance() { |
|
| 137 | - if (!isset(self::$instance)) { |
|
| 138 | - self::$instance = new \OC\NaturalSort(); |
|
| 139 | - } |
|
| 140 | - return self::$instance; |
|
| 141 | - } |
|
| 132 | + /** |
|
| 133 | + * Returns a singleton |
|
| 134 | + * @return \OC\NaturalSort instance |
|
| 135 | + */ |
|
| 136 | + public static function getInstance() { |
|
| 137 | + if (!isset(self::$instance)) { |
|
| 138 | + self::$instance = new \OC\NaturalSort(); |
|
| 139 | + } |
|
| 140 | + return self::$instance; |
|
| 141 | + } |
|
| 142 | 142 | } |
@@ -26,8 +26,8 @@ |
||
| 26 | 26 | $server = \OC::$server; |
| 27 | 27 | |
| 28 | 28 | $controller = new \OC\OCS\Provider( |
| 29 | - 'ocs_provider', |
|
| 30 | - $server->getRequest(), |
|
| 31 | - $server->getAppManager() |
|
| 29 | + 'ocs_provider', |
|
| 30 | + $server->getRequest(), |
|
| 31 | + $server->getAppManager() |
|
| 32 | 32 | ); |
| 33 | 33 | echo $controller->buildProviderList()->render(); |
@@ -19,7 +19,7 @@ |
||
| 19 | 19 | * |
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | -require_once __DIR__ . '/../lib/base.php'; |
|
| 22 | +require_once __DIR__.'/../lib/base.php'; |
|
| 23 | 23 | |
| 24 | 24 | header('Content-Type: application/json'); |
| 25 | 25 | |
@@ -117,12 +117,12 @@ |
||
| 117 | 117 | try { |
| 118 | 118 | $success = $user->setPassword($password); |
| 119 | 119 | } catch (\Exception $e) { |
| 120 | - $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
| 120 | + $output->writeln('<error>'.$e->getMessage().'</error>'); |
|
| 121 | 121 | return 1; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | if ($success) { |
| 125 | - $output->writeln("<info>Successfully reset password for " . $username . "</info>"); |
|
| 125 | + $output->writeln("<info>Successfully reset password for ".$username."</info>"); |
|
| 126 | 126 | } else { |
| 127 | 127 | $output->writeln("<error>Error while resetting password!</error>"); |
| 128 | 128 | return 1; |
@@ -41,98 +41,98 @@ |
||
| 41 | 41 | |
| 42 | 42 | class ResetPassword extends Command { |
| 43 | 43 | |
| 44 | - /** @var IUserManager */ |
|
| 45 | - protected $userManager; |
|
| 46 | - |
|
| 47 | - public function __construct(IUserManager $userManager) { |
|
| 48 | - $this->userManager = $userManager; |
|
| 49 | - parent::__construct(); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - protected function configure() { |
|
| 53 | - $this |
|
| 54 | - ->setName('user:resetpassword') |
|
| 55 | - ->setDescription('Resets the password of the named user') |
|
| 56 | - ->addArgument( |
|
| 57 | - 'user', |
|
| 58 | - InputArgument::REQUIRED, |
|
| 59 | - 'Username to reset password' |
|
| 60 | - ) |
|
| 61 | - ->addOption( |
|
| 62 | - 'password-from-env', |
|
| 63 | - null, |
|
| 64 | - InputOption::VALUE_NONE, |
|
| 65 | - 'read password from environment variable OC_PASS' |
|
| 66 | - ) |
|
| 67 | - ; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 71 | - $username = $input->getArgument('user'); |
|
| 72 | - |
|
| 73 | - $user = $this->userManager->get($username); |
|
| 74 | - if (is_null($user)) { |
|
| 75 | - $output->writeln('<error>User does not exist</error>'); |
|
| 76 | - return 1; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - if ($input->getOption('password-from-env')) { |
|
| 80 | - $password = getenv('OC_PASS'); |
|
| 81 | - if (!$password) { |
|
| 82 | - $output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>'); |
|
| 83 | - return 1; |
|
| 84 | - } |
|
| 85 | - } elseif ($input->isInteractive()) { |
|
| 86 | - /** @var QuestionHelper $helper */ |
|
| 87 | - $helper = $this->getHelper('question'); |
|
| 88 | - |
|
| 89 | - if (\OCP\App::isEnabled('encryption')) { |
|
| 90 | - $output->writeln( |
|
| 91 | - '<error>Warning: Resetting the password when using encryption will result in data loss!</error>' |
|
| 92 | - ); |
|
| 93 | - |
|
| 94 | - $question = new ConfirmationQuestion('Do you want to continue?'); |
|
| 95 | - if (!$helper->ask($input, $output, $question)) { |
|
| 96 | - return 1; |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - $question = new Question('Enter a new password: '); |
|
| 101 | - $question->setHidden(true); |
|
| 102 | - $password = $helper->ask($input, $output, $question); |
|
| 103 | - |
|
| 104 | - if ($password === null) { |
|
| 105 | - $output->writeln("<error>Password cannot be empty!</error>"); |
|
| 106 | - return 1; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - $question = new Question('Confirm the new password: '); |
|
| 110 | - $question->setHidden(true); |
|
| 111 | - $confirm = $helper->ask($input, $output, $question); |
|
| 112 | - |
|
| 113 | - if ($password !== $confirm) { |
|
| 114 | - $output->writeln("<error>Passwords did not match!</error>"); |
|
| 115 | - return 1; |
|
| 116 | - } |
|
| 117 | - } else { |
|
| 118 | - $output->writeln("<error>Interactive input or --password-from-env is needed for entering a new password!</error>"); |
|
| 119 | - return 1; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - |
|
| 123 | - try { |
|
| 124 | - $success = $user->setPassword($password); |
|
| 125 | - } catch (\Exception $e) { |
|
| 126 | - $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
| 127 | - return 1; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - if ($success) { |
|
| 131 | - $output->writeln("<info>Successfully reset password for " . $username . "</info>"); |
|
| 132 | - } else { |
|
| 133 | - $output->writeln("<error>Error while resetting password!</error>"); |
|
| 134 | - return 1; |
|
| 135 | - } |
|
| 136 | - return 0; |
|
| 137 | - } |
|
| 44 | + /** @var IUserManager */ |
|
| 45 | + protected $userManager; |
|
| 46 | + |
|
| 47 | + public function __construct(IUserManager $userManager) { |
|
| 48 | + $this->userManager = $userManager; |
|
| 49 | + parent::__construct(); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + protected function configure() { |
|
| 53 | + $this |
|
| 54 | + ->setName('user:resetpassword') |
|
| 55 | + ->setDescription('Resets the password of the named user') |
|
| 56 | + ->addArgument( |
|
| 57 | + 'user', |
|
| 58 | + InputArgument::REQUIRED, |
|
| 59 | + 'Username to reset password' |
|
| 60 | + ) |
|
| 61 | + ->addOption( |
|
| 62 | + 'password-from-env', |
|
| 63 | + null, |
|
| 64 | + InputOption::VALUE_NONE, |
|
| 65 | + 'read password from environment variable OC_PASS' |
|
| 66 | + ) |
|
| 67 | + ; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 71 | + $username = $input->getArgument('user'); |
|
| 72 | + |
|
| 73 | + $user = $this->userManager->get($username); |
|
| 74 | + if (is_null($user)) { |
|
| 75 | + $output->writeln('<error>User does not exist</error>'); |
|
| 76 | + return 1; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + if ($input->getOption('password-from-env')) { |
|
| 80 | + $password = getenv('OC_PASS'); |
|
| 81 | + if (!$password) { |
|
| 82 | + $output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>'); |
|
| 83 | + return 1; |
|
| 84 | + } |
|
| 85 | + } elseif ($input->isInteractive()) { |
|
| 86 | + /** @var QuestionHelper $helper */ |
|
| 87 | + $helper = $this->getHelper('question'); |
|
| 88 | + |
|
| 89 | + if (\OCP\App::isEnabled('encryption')) { |
|
| 90 | + $output->writeln( |
|
| 91 | + '<error>Warning: Resetting the password when using encryption will result in data loss!</error>' |
|
| 92 | + ); |
|
| 93 | + |
|
| 94 | + $question = new ConfirmationQuestion('Do you want to continue?'); |
|
| 95 | + if (!$helper->ask($input, $output, $question)) { |
|
| 96 | + return 1; |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + $question = new Question('Enter a new password: '); |
|
| 101 | + $question->setHidden(true); |
|
| 102 | + $password = $helper->ask($input, $output, $question); |
|
| 103 | + |
|
| 104 | + if ($password === null) { |
|
| 105 | + $output->writeln("<error>Password cannot be empty!</error>"); |
|
| 106 | + return 1; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + $question = new Question('Confirm the new password: '); |
|
| 110 | + $question->setHidden(true); |
|
| 111 | + $confirm = $helper->ask($input, $output, $question); |
|
| 112 | + |
|
| 113 | + if ($password !== $confirm) { |
|
| 114 | + $output->writeln("<error>Passwords did not match!</error>"); |
|
| 115 | + return 1; |
|
| 116 | + } |
|
| 117 | + } else { |
|
| 118 | + $output->writeln("<error>Interactive input or --password-from-env is needed for entering a new password!</error>"); |
|
| 119 | + return 1; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + |
|
| 123 | + try { |
|
| 124 | + $success = $user->setPassword($password); |
|
| 125 | + } catch (\Exception $e) { |
|
| 126 | + $output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
| 127 | + return 1; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + if ($success) { |
|
| 131 | + $output->writeln("<info>Successfully reset password for " . $username . "</info>"); |
|
| 132 | + } else { |
|
| 133 | + $output->writeln("<error>Error while resetting password!</error>"); |
|
| 134 | + return 1; |
|
| 135 | + } |
|
| 136 | + return 0; |
|
| 137 | + } |
|
| 138 | 138 | } |