@@ -32,128 +32,128 @@ |
||
| 32 | 32 | use Psr\Log\LoggerInterface; |
| 33 | 33 | |
| 34 | 34 | class JSResourceLocator extends ResourceLocator { |
| 35 | - protected JSCombiner $jsCombiner; |
|
| 36 | - protected IAppManager $appManager; |
|
| 37 | - |
|
| 38 | - public function __construct(LoggerInterface $logger, JSCombiner $JSCombiner, IAppManager $appManager) { |
|
| 39 | - parent::__construct($logger); |
|
| 40 | - |
|
| 41 | - $this->jsCombiner = $JSCombiner; |
|
| 42 | - $this->appManager = $appManager; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @param string $script |
|
| 47 | - */ |
|
| 48 | - public function doFind($script) { |
|
| 49 | - $theme_dir = 'themes/'.$this->theme.'/'; |
|
| 50 | - |
|
| 51 | - // Extracting the appId and the script file name |
|
| 52 | - $app = substr($script, 0, strpos($script, '/')); |
|
| 53 | - $scriptName = basename($script); |
|
| 54 | - |
|
| 55 | - if (strpos($script, '/l10n/') !== false) { |
|
| 56 | - // For language files we try to load them all, so themes can overwrite |
|
| 57 | - // single l10n strings without having to translate all of them. |
|
| 58 | - $found = 0; |
|
| 59 | - $found += $this->appendScriptIfExist($this->serverroot, 'core/'.$script); |
|
| 60 | - $found += $this->appendScriptIfExist($this->serverroot, $theme_dir.'core/'.$script); |
|
| 61 | - $found += $this->appendScriptIfExist($this->serverroot, $script); |
|
| 62 | - $found += $this->appendScriptIfExist($this->serverroot, $theme_dir.$script); |
|
| 63 | - $found += $this->appendScriptIfExist($this->serverroot, 'apps/'.$script); |
|
| 64 | - $found += $this->appendScriptIfExist($this->serverroot, $theme_dir.'apps/'.$script); |
|
| 65 | - |
|
| 66 | - if ($found) { |
|
| 67 | - return; |
|
| 68 | - } |
|
| 69 | - } elseif ($this->appendScriptIfExist($this->serverroot, $theme_dir.'apps/'.$script) |
|
| 70 | - || $this->appendScriptIfExist($this->serverroot, $theme_dir.$script) |
|
| 71 | - || $this->appendScriptIfExist($this->serverroot, $script) |
|
| 72 | - || $this->appendScriptIfExist($this->serverroot, $theme_dir."dist/$app-$scriptName") |
|
| 73 | - || $this->appendScriptIfExist($this->serverroot, "dist/$app-$scriptName") |
|
| 74 | - || $this->appendScriptIfExist($this->serverroot, 'apps/'.$script) |
|
| 75 | - || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, $script.'.json') |
|
| 76 | - || $this->appendScriptIfExist($this->serverroot, $theme_dir.'core/'.$script) |
|
| 77 | - || $this->appendScriptIfExist($this->serverroot, 'core/'.$script) |
|
| 78 | - || (strpos($scriptName, '/') === -1 && ($this->appendScriptIfExist($this->serverroot, $theme_dir."dist/core-$scriptName") |
|
| 79 | - || $this->appendScriptIfExist($this->serverroot, "dist/core-$scriptName"))) |
|
| 80 | - || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, 'core/'.$script.'.json') |
|
| 81 | - ) { |
|
| 82 | - return; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - $script = substr($script, strpos($script, '/') + 1); |
|
| 86 | - $app_url = null; |
|
| 87 | - |
|
| 88 | - try { |
|
| 89 | - $app_url = $this->appManager->getAppWebPath($app); |
|
| 90 | - } catch (AppPathNotFoundException) { |
|
| 91 | - // pass |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - try { |
|
| 95 | - $app_path = $this->appManager->getAppPath($app); |
|
| 96 | - |
|
| 97 | - // Account for the possibility of having symlinks in app path. Only |
|
| 98 | - // do this if $app_path is set, because an empty argument to realpath |
|
| 99 | - // gets turned into cwd. |
|
| 100 | - $app_path = realpath($app_path); |
|
| 101 | - |
|
| 102 | - // missing translations files will be ignored |
|
| 103 | - if (strpos($script, 'l10n/') === 0) { |
|
| 104 | - $this->appendScriptIfExist($app_path, $script, $app_url); |
|
| 105 | - return; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) { |
|
| 109 | - $this->appendScriptIfExist($app_path, $script, $app_url); |
|
| 110 | - } |
|
| 111 | - } catch (AppPathNotFoundException) { |
|
| 112 | - $this->logger->error('Could not find resource {resource} to load', [ |
|
| 113 | - 'resource' => $app . '/' . $script . '.js', |
|
| 114 | - 'app' => 'jsresourceloader', |
|
| 115 | - ]); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @param string $script |
|
| 121 | - */ |
|
| 122 | - public function doFindTheme($script) { |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Try to find ES6 script file (`.mjs`) with fallback to plain javascript (`.js`) |
|
| 127 | - * @see appendIfExist() |
|
| 128 | - */ |
|
| 129 | - protected function appendScriptIfExist(string $root, string $file, string $webRoot = null) { |
|
| 130 | - if (!$this->appendIfExist($root, $file . '.mjs', $webRoot)) { |
|
| 131 | - return $this->appendIfExist($root, $file . '.js', $webRoot); |
|
| 132 | - } |
|
| 133 | - return true; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - protected function cacheAndAppendCombineJsonIfExist($root, $file, $app = 'core') { |
|
| 137 | - if (is_file($root.'/'.$file)) { |
|
| 138 | - if ($this->jsCombiner->process($root, $file, $app)) { |
|
| 139 | - $this->append($this->serverroot, $this->jsCombiner->getCachedJS($app, $file), false, false); |
|
| 140 | - } else { |
|
| 141 | - // Add all the files from the json |
|
| 142 | - $files = $this->jsCombiner->getContent($root, $file); |
|
| 143 | - $app_url = null; |
|
| 144 | - try { |
|
| 145 | - $app_url = $this->appManager->getAppWebPath($app); |
|
| 146 | - } catch (AppPathNotFoundException) { |
|
| 147 | - // pass |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - foreach ($files as $jsFile) { |
|
| 151 | - $this->append($root, $jsFile, $app_url); |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - return true; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - return false; |
|
| 158 | - } |
|
| 35 | + protected JSCombiner $jsCombiner; |
|
| 36 | + protected IAppManager $appManager; |
|
| 37 | + |
|
| 38 | + public function __construct(LoggerInterface $logger, JSCombiner $JSCombiner, IAppManager $appManager) { |
|
| 39 | + parent::__construct($logger); |
|
| 40 | + |
|
| 41 | + $this->jsCombiner = $JSCombiner; |
|
| 42 | + $this->appManager = $appManager; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @param string $script |
|
| 47 | + */ |
|
| 48 | + public function doFind($script) { |
|
| 49 | + $theme_dir = 'themes/'.$this->theme.'/'; |
|
| 50 | + |
|
| 51 | + // Extracting the appId and the script file name |
|
| 52 | + $app = substr($script, 0, strpos($script, '/')); |
|
| 53 | + $scriptName = basename($script); |
|
| 54 | + |
|
| 55 | + if (strpos($script, '/l10n/') !== false) { |
|
| 56 | + // For language files we try to load them all, so themes can overwrite |
|
| 57 | + // single l10n strings without having to translate all of them. |
|
| 58 | + $found = 0; |
|
| 59 | + $found += $this->appendScriptIfExist($this->serverroot, 'core/'.$script); |
|
| 60 | + $found += $this->appendScriptIfExist($this->serverroot, $theme_dir.'core/'.$script); |
|
| 61 | + $found += $this->appendScriptIfExist($this->serverroot, $script); |
|
| 62 | + $found += $this->appendScriptIfExist($this->serverroot, $theme_dir.$script); |
|
| 63 | + $found += $this->appendScriptIfExist($this->serverroot, 'apps/'.$script); |
|
| 64 | + $found += $this->appendScriptIfExist($this->serverroot, $theme_dir.'apps/'.$script); |
|
| 65 | + |
|
| 66 | + if ($found) { |
|
| 67 | + return; |
|
| 68 | + } |
|
| 69 | + } elseif ($this->appendScriptIfExist($this->serverroot, $theme_dir.'apps/'.$script) |
|
| 70 | + || $this->appendScriptIfExist($this->serverroot, $theme_dir.$script) |
|
| 71 | + || $this->appendScriptIfExist($this->serverroot, $script) |
|
| 72 | + || $this->appendScriptIfExist($this->serverroot, $theme_dir."dist/$app-$scriptName") |
|
| 73 | + || $this->appendScriptIfExist($this->serverroot, "dist/$app-$scriptName") |
|
| 74 | + || $this->appendScriptIfExist($this->serverroot, 'apps/'.$script) |
|
| 75 | + || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, $script.'.json') |
|
| 76 | + || $this->appendScriptIfExist($this->serverroot, $theme_dir.'core/'.$script) |
|
| 77 | + || $this->appendScriptIfExist($this->serverroot, 'core/'.$script) |
|
| 78 | + || (strpos($scriptName, '/') === -1 && ($this->appendScriptIfExist($this->serverroot, $theme_dir."dist/core-$scriptName") |
|
| 79 | + || $this->appendScriptIfExist($this->serverroot, "dist/core-$scriptName"))) |
|
| 80 | + || $this->cacheAndAppendCombineJsonIfExist($this->serverroot, 'core/'.$script.'.json') |
|
| 81 | + ) { |
|
| 82 | + return; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + $script = substr($script, strpos($script, '/') + 1); |
|
| 86 | + $app_url = null; |
|
| 87 | + |
|
| 88 | + try { |
|
| 89 | + $app_url = $this->appManager->getAppWebPath($app); |
|
| 90 | + } catch (AppPathNotFoundException) { |
|
| 91 | + // pass |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + try { |
|
| 95 | + $app_path = $this->appManager->getAppPath($app); |
|
| 96 | + |
|
| 97 | + // Account for the possibility of having symlinks in app path. Only |
|
| 98 | + // do this if $app_path is set, because an empty argument to realpath |
|
| 99 | + // gets turned into cwd. |
|
| 100 | + $app_path = realpath($app_path); |
|
| 101 | + |
|
| 102 | + // missing translations files will be ignored |
|
| 103 | + if (strpos($script, 'l10n/') === 0) { |
|
| 104 | + $this->appendScriptIfExist($app_path, $script, $app_url); |
|
| 105 | + return; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + if (!$this->cacheAndAppendCombineJsonIfExist($app_path, $script.'.json', $app)) { |
|
| 109 | + $this->appendScriptIfExist($app_path, $script, $app_url); |
|
| 110 | + } |
|
| 111 | + } catch (AppPathNotFoundException) { |
|
| 112 | + $this->logger->error('Could not find resource {resource} to load', [ |
|
| 113 | + 'resource' => $app . '/' . $script . '.js', |
|
| 114 | + 'app' => 'jsresourceloader', |
|
| 115 | + ]); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @param string $script |
|
| 121 | + */ |
|
| 122 | + public function doFindTheme($script) { |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Try to find ES6 script file (`.mjs`) with fallback to plain javascript (`.js`) |
|
| 127 | + * @see appendIfExist() |
|
| 128 | + */ |
|
| 129 | + protected function appendScriptIfExist(string $root, string $file, string $webRoot = null) { |
|
| 130 | + if (!$this->appendIfExist($root, $file . '.mjs', $webRoot)) { |
|
| 131 | + return $this->appendIfExist($root, $file . '.js', $webRoot); |
|
| 132 | + } |
|
| 133 | + return true; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + protected function cacheAndAppendCombineJsonIfExist($root, $file, $app = 'core') { |
|
| 137 | + if (is_file($root.'/'.$file)) { |
|
| 138 | + if ($this->jsCombiner->process($root, $file, $app)) { |
|
| 139 | + $this->append($this->serverroot, $this->jsCombiner->getCachedJS($app, $file), false, false); |
|
| 140 | + } else { |
|
| 141 | + // Add all the files from the json |
|
| 142 | + $files = $this->jsCombiner->getContent($root, $file); |
|
| 143 | + $app_url = null; |
|
| 144 | + try { |
|
| 145 | + $app_url = $this->appManager->getAppWebPath($app); |
|
| 146 | + } catch (AppPathNotFoundException) { |
|
| 147 | + // pass |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + foreach ($files as $jsFile) { |
|
| 151 | + $this->append($root, $jsFile, $app_url); |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + return true; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + return false; |
|
| 158 | + } |
|
| 159 | 159 | } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * |
| 36 | 36 | */ |
| 37 | 37 | function p($string) { |
| 38 | - print(\OCP\Util::sanitizeHTML($string)); |
|
| 38 | + print(\OCP\Util::sanitizeHTML($string)); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | |
@@ -45,14 +45,14 @@ discard block |
||
| 45 | 45 | * @param string $opts, additional optional options |
| 46 | 46 | */ |
| 47 | 47 | function emit_css_tag($href, $opts = '') { |
| 48 | - $s = '<link rel="stylesheet"'; |
|
| 49 | - if (!empty($href)) { |
|
| 50 | - $s .= ' href="' . $href .'"'; |
|
| 51 | - } |
|
| 52 | - if (!empty($opts)) { |
|
| 53 | - $s .= ' '.$opts; |
|
| 54 | - } |
|
| 55 | - print_unescaped($s.">\n"); |
|
| 48 | + $s = '<link rel="stylesheet"'; |
|
| 49 | + if (!empty($href)) { |
|
| 50 | + $s .= ' href="' . $href .'"'; |
|
| 51 | + } |
|
| 52 | + if (!empty($opts)) { |
|
| 53 | + $s .= ' '.$opts; |
|
| 54 | + } |
|
| 55 | + print_unescaped($s.">\n"); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -60,12 +60,12 @@ discard block |
||
| 60 | 60 | * @param array $obj all the script information from template |
| 61 | 61 | */ |
| 62 | 62 | function emit_css_loading_tags($obj) { |
| 63 | - foreach ($obj['cssfiles'] as $css) { |
|
| 64 | - emit_css_tag($css); |
|
| 65 | - } |
|
| 66 | - foreach ($obj['printcssfiles'] as $css) { |
|
| 67 | - emit_css_tag($css, 'media="print"'); |
|
| 68 | - } |
|
| 63 | + foreach ($obj['cssfiles'] as $css) { |
|
| 64 | + emit_css_tag($css); |
|
| 65 | + } |
|
| 66 | + foreach ($obj['printcssfiles'] as $css) { |
|
| 67 | + emit_css_tag($css, 'media="print"'); |
|
| 68 | + } |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -75,24 +75,24 @@ discard block |
||
| 75 | 75 | * @param string $content_type the type of the source (e.g. 'module') |
| 76 | 76 | */ |
| 77 | 77 | function emit_script_tag(string $src, string $script_content = '', string $content_type = '') { |
| 78 | - $nonceManager = \OC::$server->get(\OC\Security\CSP\ContentSecurityPolicyNonceManager::class); |
|
| 78 | + $nonceManager = \OC::$server->get(\OC\Security\CSP\ContentSecurityPolicyNonceManager::class); |
|
| 79 | 79 | |
| 80 | - $defer_str = ' defer'; |
|
| 81 | - $type = $content_type !== '' ? ' type="' . $content_type . '"' : ''; |
|
| 80 | + $defer_str = ' defer'; |
|
| 81 | + $type = $content_type !== '' ? ' type="' . $content_type . '"' : ''; |
|
| 82 | 82 | |
| 83 | - $s = '<script nonce="' . $nonceManager->getNonce() . '"'; |
|
| 84 | - if (!empty($src)) { |
|
| 85 | - // emit script tag for deferred loading from $src |
|
| 86 | - $s .= $defer_str.' src="' . $src .'"' . $type . '>'; |
|
| 87 | - } elseif ($script_content !== '') { |
|
| 88 | - // emit script tag for inline script from $script_content without defer (see MDN) |
|
| 89 | - $s .= ">\n".$script_content."\n"; |
|
| 90 | - } else { |
|
| 91 | - // no $src nor $src_content, really useless empty tag |
|
| 92 | - $s .= '>'; |
|
| 93 | - } |
|
| 94 | - $s .= '</script>'; |
|
| 95 | - print_unescaped($s."\n"); |
|
| 83 | + $s = '<script nonce="' . $nonceManager->getNonce() . '"'; |
|
| 84 | + if (!empty($src)) { |
|
| 85 | + // emit script tag for deferred loading from $src |
|
| 86 | + $s .= $defer_str.' src="' . $src .'"' . $type . '>'; |
|
| 87 | + } elseif ($script_content !== '') { |
|
| 88 | + // emit script tag for inline script from $script_content without defer (see MDN) |
|
| 89 | + $s .= ">\n".$script_content."\n"; |
|
| 90 | + } else { |
|
| 91 | + // no $src nor $src_content, really useless empty tag |
|
| 92 | + $s .= '>'; |
|
| 93 | + } |
|
| 94 | + $s .= '</script>'; |
|
| 95 | + print_unescaped($s."\n"); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -100,13 +100,13 @@ discard block |
||
| 100 | 100 | * @param array $obj all the script information from template |
| 101 | 101 | */ |
| 102 | 102 | function emit_script_loading_tags($obj) { |
| 103 | - foreach ($obj['jsfiles'] as $jsfile) { |
|
| 104 | - $type = str_ends_with($jsfile, '.mjs') ? 'module' : ''; |
|
| 105 | - emit_script_tag($jsfile, '', $type); |
|
| 106 | - } |
|
| 107 | - if (!empty($obj['inline_ocjs'])) { |
|
| 108 | - emit_script_tag('', $obj['inline_ocjs']); |
|
| 109 | - } |
|
| 103 | + foreach ($obj['jsfiles'] as $jsfile) { |
|
| 104 | + $type = str_ends_with($jsfile, '.mjs') ? 'module' : ''; |
|
| 105 | + emit_script_tag($jsfile, '', $type); |
|
| 106 | + } |
|
| 107 | + if (!empty($obj['inline_ocjs'])) { |
|
| 108 | + emit_script_tag('', $obj['inline_ocjs']); |
|
| 109 | + } |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | * @param string|array $string the string which will be printed as it is |
| 116 | 116 | */ |
| 117 | 117 | function print_unescaped($string) { |
| 118 | - print($string); |
|
| 118 | + print($string); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -131,13 +131,13 @@ discard block |
||
| 131 | 131 | * if an array is given it will add all scripts |
| 132 | 132 | */ |
| 133 | 133 | function script($app, $file = null) { |
| 134 | - if (is_array($file)) { |
|
| 135 | - foreach ($file as $script) { |
|
| 136 | - Util::addScript($app, $script, 'core'); |
|
| 137 | - } |
|
| 138 | - } else { |
|
| 139 | - Util::addScript($app, $file, 'core'); |
|
| 140 | - } |
|
| 134 | + if (is_array($file)) { |
|
| 135 | + foreach ($file as $script) { |
|
| 136 | + Util::addScript($app, $script, 'core'); |
|
| 137 | + } |
|
| 138 | + } else { |
|
| 139 | + Util::addScript($app, $file, 'core'); |
|
| 140 | + } |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -147,13 +147,13 @@ discard block |
||
| 147 | 147 | * if an array is given it will add all scripts |
| 148 | 148 | */ |
| 149 | 149 | function vendor_script($app, $file = null) { |
| 150 | - if (is_array($file)) { |
|
| 151 | - foreach ($file as $f) { |
|
| 152 | - OC_Util::addVendorScript($app, $f); |
|
| 153 | - } |
|
| 154 | - } else { |
|
| 155 | - OC_Util::addVendorScript($app, $file); |
|
| 156 | - } |
|
| 150 | + if (is_array($file)) { |
|
| 151 | + foreach ($file as $f) { |
|
| 152 | + OC_Util::addVendorScript($app, $f); |
|
| 153 | + } |
|
| 154 | + } else { |
|
| 155 | + OC_Util::addVendorScript($app, $file); |
|
| 156 | + } |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -163,13 +163,13 @@ discard block |
||
| 163 | 163 | * if an array is given it will add all styles |
| 164 | 164 | */ |
| 165 | 165 | function style($app, $file = null) { |
| 166 | - if (is_array($file)) { |
|
| 167 | - foreach ($file as $f) { |
|
| 168 | - OC_Util::addStyle($app, $f); |
|
| 169 | - } |
|
| 170 | - } else { |
|
| 171 | - OC_Util::addStyle($app, $file); |
|
| 172 | - } |
|
| 166 | + if (is_array($file)) { |
|
| 167 | + foreach ($file as $f) { |
|
| 168 | + OC_Util::addStyle($app, $f); |
|
| 169 | + } |
|
| 170 | + } else { |
|
| 171 | + OC_Util::addStyle($app, $file); |
|
| 172 | + } |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
@@ -179,13 +179,13 @@ discard block |
||
| 179 | 179 | * if an array is given it will add all styles |
| 180 | 180 | */ |
| 181 | 181 | function vendor_style($app, $file = null) { |
| 182 | - if (is_array($file)) { |
|
| 183 | - foreach ($file as $f) { |
|
| 184 | - OC_Util::addVendorStyle($app, $f); |
|
| 185 | - } |
|
| 186 | - } else { |
|
| 187 | - OC_Util::addVendorStyle($app, $file); |
|
| 188 | - } |
|
| 182 | + if (is_array($file)) { |
|
| 183 | + foreach ($file as $f) { |
|
| 184 | + OC_Util::addVendorStyle($app, $f); |
|
| 185 | + } |
|
| 186 | + } else { |
|
| 187 | + OC_Util::addVendorStyle($app, $file); |
|
| 188 | + } |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | * if an array is given it will add all styles |
| 195 | 195 | */ |
| 196 | 196 | function translation($app) { |
| 197 | - OC_Util::addTranslations($app); |
|
| 197 | + OC_Util::addTranslations($app); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -204,15 +204,15 @@ discard block |
||
| 204 | 204 | * if an array is given it will add all components |
| 205 | 205 | */ |
| 206 | 206 | function component($app, $file) { |
| 207 | - if (is_array($file)) { |
|
| 208 | - foreach ($file as $f) { |
|
| 209 | - $url = link_to($app, 'component/' . $f . '.html'); |
|
| 210 | - OC_Util::addHeader('link', ['rel' => 'import', 'href' => $url]); |
|
| 211 | - } |
|
| 212 | - } else { |
|
| 213 | - $url = link_to($app, 'component/' . $file . '.html'); |
|
| 214 | - OC_Util::addHeader('link', ['rel' => 'import', 'href' => $url]); |
|
| 215 | - } |
|
| 207 | + if (is_array($file)) { |
|
| 208 | + foreach ($file as $f) { |
|
| 209 | + $url = link_to($app, 'component/' . $f . '.html'); |
|
| 210 | + OC_Util::addHeader('link', ['rel' => 'import', 'href' => $url]); |
|
| 211 | + } |
|
| 212 | + } else { |
|
| 213 | + $url = link_to($app, 'component/' . $file . '.html'); |
|
| 214 | + OC_Util::addHeader('link', ['rel' => 'import', 'href' => $url]); |
|
| 215 | + } |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | * For further information have a look at \OCP\IURLGenerator::linkTo |
| 226 | 226 | */ |
| 227 | 227 | function link_to($app, $file, $args = []) { |
| 228 | - return \OC::$server->getURLGenerator()->linkTo($app, $file, $args); |
|
| 228 | + return \OC::$server->getURLGenerator()->linkTo($app, $file, $args); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | * @return string url to the online documentation |
| 234 | 234 | */ |
| 235 | 235 | function link_to_docs($key) { |
| 236 | - return \OC::$server->getURLGenerator()->linkToDocs($key); |
|
| 236 | + return \OC::$server->getURLGenerator()->linkToDocs($key); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | * For further information have a look at \OCP\IURLGenerator::imagePath |
| 246 | 246 | */ |
| 247 | 247 | function image_path($app, $image) { |
| 248 | - return \OC::$server->getURLGenerator()->imagePath($app, $image); |
|
| 248 | + return \OC::$server->getURLGenerator()->imagePath($app, $image); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | * @return string link to the image |
| 255 | 255 | */ |
| 256 | 256 | function mimetype_icon($mimetype) { |
| 257 | - return \OC::$server->getMimeTypeDetector()->mimeTypeIcon($mimetype); |
|
| 257 | + return \OC::$server->getMimeTypeDetector()->mimeTypeIcon($mimetype); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | /** |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | * @return string link to the preview |
| 265 | 265 | */ |
| 266 | 266 | function preview_icon($path) { |
| 267 | - return \OC::$server->getURLGenerator()->linkToRoute('core.Preview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path]); |
|
| 267 | + return \OC::$server->getURLGenerator()->linkToRoute('core.Preview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path]); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | /** |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | * @return string |
| 274 | 274 | */ |
| 275 | 275 | function publicPreview_icon($path, $token) { |
| 276 | - return \OC::$server->getURLGenerator()->linkToRoute('files_sharing.PublicPreview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path, 'token' => $token]); |
|
| 276 | + return \OC::$server->getURLGenerator()->linkToRoute('files_sharing.PublicPreview.getPreview', ['x' => 32, 'y' => 32, 'file' => $path, 'token' => $token]); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | /** |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | * For further information have a look at OC_Helper::humanFileSize |
| 285 | 285 | */ |
| 286 | 286 | function human_file_size($bytes) { |
| 287 | - return OC_Helper::humanFileSize($bytes); |
|
| 287 | + return OC_Helper::humanFileSize($bytes); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -293,9 +293,9 @@ discard block |
||
| 293 | 293 | * @return int timestamp without time value |
| 294 | 294 | */ |
| 295 | 295 | function strip_time($timestamp) { |
| 296 | - $date = new \DateTime("@{$timestamp}"); |
|
| 297 | - $date->setTime(0, 0, 0); |
|
| 298 | - return (int)$date->format('U'); |
|
| 296 | + $date = new \DateTime("@{$timestamp}"); |
|
| 297 | + $date->setTime(0, 0, 0); |
|
| 298 | + return (int)$date->format('U'); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | /** |
@@ -307,39 +307,39 @@ discard block |
||
| 307 | 307 | * @return string timestamp |
| 308 | 308 | */ |
| 309 | 309 | function relative_modified_date($timestamp, $fromTime = null, $dateOnly = false) { |
| 310 | - /** @var \OC\DateTimeFormatter $formatter */ |
|
| 311 | - $formatter = \OC::$server->query('DateTimeFormatter'); |
|
| 310 | + /** @var \OC\DateTimeFormatter $formatter */ |
|
| 311 | + $formatter = \OC::$server->query('DateTimeFormatter'); |
|
| 312 | 312 | |
| 313 | - if ($dateOnly) { |
|
| 314 | - return $formatter->formatDateSpan($timestamp, $fromTime); |
|
| 315 | - } |
|
| 316 | - return $formatter->formatTimeSpan($timestamp, $fromTime); |
|
| 313 | + if ($dateOnly) { |
|
| 314 | + return $formatter->formatDateSpan($timestamp, $fromTime); |
|
| 315 | + } |
|
| 316 | + return $formatter->formatTimeSpan($timestamp, $fromTime); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | function html_select_options($options, $selected, $params = []) { |
| 320 | - if (!is_array($selected)) { |
|
| 321 | - $selected = [$selected]; |
|
| 322 | - } |
|
| 323 | - if (isset($params['combine']) && $params['combine']) { |
|
| 324 | - $options = array_combine($options, $options); |
|
| 325 | - } |
|
| 326 | - $value_name = $label_name = false; |
|
| 327 | - if (isset($params['value'])) { |
|
| 328 | - $value_name = $params['value']; |
|
| 329 | - } |
|
| 330 | - if (isset($params['label'])) { |
|
| 331 | - $label_name = $params['label']; |
|
| 332 | - } |
|
| 333 | - $html = ''; |
|
| 334 | - foreach ($options as $value => $label) { |
|
| 335 | - if ($value_name && is_array($label)) { |
|
| 336 | - $value = $label[$value_name]; |
|
| 337 | - } |
|
| 338 | - if ($label_name && is_array($label)) { |
|
| 339 | - $label = $label[$label_name]; |
|
| 340 | - } |
|
| 341 | - $select = in_array($value, $selected) ? ' selected="selected"' : ''; |
|
| 342 | - $html .= '<option value="' . \OCP\Util::sanitizeHTML($value) . '"' . $select . '>' . \OCP\Util::sanitizeHTML($label) . '</option>'."\n"; |
|
| 343 | - } |
|
| 344 | - return $html; |
|
| 320 | + if (!is_array($selected)) { |
|
| 321 | + $selected = [$selected]; |
|
| 322 | + } |
|
| 323 | + if (isset($params['combine']) && $params['combine']) { |
|
| 324 | + $options = array_combine($options, $options); |
|
| 325 | + } |
|
| 326 | + $value_name = $label_name = false; |
|
| 327 | + if (isset($params['value'])) { |
|
| 328 | + $value_name = $params['value']; |
|
| 329 | + } |
|
| 330 | + if (isset($params['label'])) { |
|
| 331 | + $label_name = $params['label']; |
|
| 332 | + } |
|
| 333 | + $html = ''; |
|
| 334 | + foreach ($options as $value => $label) { |
|
| 335 | + if ($value_name && is_array($label)) { |
|
| 336 | + $value = $label[$value_name]; |
|
| 337 | + } |
|
| 338 | + if ($label_name && is_array($label)) { |
|
| 339 | + $label = $label[$label_name]; |
|
| 340 | + } |
|
| 341 | + $select = in_array($value, $selected) ? ' selected="selected"' : ''; |
|
| 342 | + $html .= '<option value="' . \OCP\Util::sanitizeHTML($value) . '"' . $select . '>' . \OCP\Util::sanitizeHTML($label) . '</option>'."\n"; |
|
| 343 | + } |
|
| 344 | + return $html; |
|
| 345 | 345 | } |