]> BookStack Code Mirror - bookstack/commitdiff
Fixed issue with translation loading without theme
authorDan Brown <redacted>
Sat, 3 Jul 2021 10:53:46 +0000 (11:53 +0100)
committerDan Brown <redacted>
Sat, 3 Jul 2021 10:53:46 +0000 (11:53 +0100)
System was using the empty state return from theme_path,
when no theme was configured, for loading in languages
which would result in the root path being looked up upon.

This changes the theme_path helper to return null in cases a theme
is not configured instead of empty string to help prevent assumed
return path will be legitimate, and to help enforce error case
handling.

For #2836

app/Theming/ThemeService.php
app/Translation/FileLoader.php
app/helpers.php

index 895108e3e2aac8ee5791c266bd30c9ba6c1e951e..44605bf3251acca8017011b10291d2076f10410a 100644 (file)
@@ -45,7 +45,7 @@ class ThemeService
     public function readThemeActions()
     {
         $themeActionsFile = theme_path('functions.php');
-        if (file_exists($themeActionsFile)) {
+        if ($themeActionsFile && file_exists($themeActionsFile)) {
             require $themeActionsFile;
         }
     }
index 0b4a93de6bc8dc84b9145378a2830f2645160c88..e6514667734ca00ae27fea02f2e70930dc20f284 100644 (file)
@@ -20,7 +20,8 @@ class FileLoader extends BaseLoader
         }
 
         if (is_null($namespace) || $namespace === '*') {
-            $themeTranslations = $this->loadPath(theme_path('lang'), $locale, $group);
+            $themePath = theme_path('lang');
+            $themeTranslations = $themePath ? $this->loadPath($themePath, $locale, $group) : [];
             $originalTranslations =  $this->loadPath($this->path, $locale, $group);
             return array_merge($originalTranslations, $themeTranslations);
         }
index c1d72b91da4fb7f5bb3efba3a2de46490ec3dce9..a5a04f113dd240ec6daf977139598b84dba5838f 100644 (file)
@@ -94,13 +94,15 @@ function setting(string $key = null, $default = null)
 
 /**
  * Get a path to a theme resource.
+ * Returns null if a theme is not configured and
+ * therefore a full path is not available for use.
  */
-function theme_path(string $path = ''): string
+function theme_path(string $path = ''): ?string
 {
     $theme = config('view.theme');
 
     if (!$theme) {
-        return '';
+        return null;
     }
 
     return base_path('themes/' . $theme .($path ? DIRECTORY_SEPARATOR.$path : $path));