Changeset View
Changeset View
Standalone View
Standalone View
src/app/Http/Controllers/ContentController.php
Show All 11 Lines | class ContentController extends Controller | ||||
* @return \Illuminate\View\View | * @return \Illuminate\View\View | ||||
*/ | */ | ||||
public function pageContent(string $page) | public function pageContent(string $page) | ||||
{ | { | ||||
if (empty($page) || !preg_match('/^[a-z\/]+$/', $page)) { | if (empty($page) || !preg_match('/^[a-z\/]+$/', $page)) { | ||||
abort(404); | abort(404); | ||||
} | } | ||||
$theme = \config('app.theme'); | |||||
$page = str_replace('/', '.', $page); | $page = str_replace('/', '.', $page); | ||||
$file = sprintf('themes/%s/pages/%s.blade.php', \config('app.theme'), $page); | $file = sprintf('themes/%s/pages/%s.blade.php', $theme, $page); | ||||
$view = sprintf('%s.pages.%s', \config('app.theme'), $page); | $view = sprintf('%s.pages.%s', $theme, $page); | ||||
if (!file_exists(resource_path($file))) { | if (!file_exists(resource_path($file))) { | ||||
abort(404); | abort(404); | ||||
} | } | ||||
self::loadLocale($theme); | |||||
return view($view)->with('env', \App\Utils::uiEnv()); | return view($view)->with('env', \App\Utils::uiEnv()); | ||||
} | } | ||||
/** | /** | ||||
* Get the list of FAQ entries for the specified page | * Get the list of FAQ entries for the specified page | ||||
* | * | ||||
* @param string $page Page path | * @param string $page Page path | ||||
* | * | ||||
Show All 18 Lines | public function faqContent(string $page) | ||||
$faq = $theme['faq'][$page]; | $faq = $theme['faq'][$page]; | ||||
} | } | ||||
// TODO: Support pages with variables, e.g. users/<user-id> | // TODO: Support pages with variables, e.g. users/<user-id> | ||||
} | } | ||||
return response()->json(['status' => 'success', 'faq' => $faq]); | return response()->json(['status' => 'success', 'faq' => $faq]); | ||||
} | } | ||||
/** | |||||
* Register localization files from the theme. | |||||
* | |||||
* @param string $theme Theme name | |||||
*/ | |||||
protected static function loadLocale(string $theme): void | |||||
{ | |||||
$path = resource_path(sprintf('themes/%s/lang', $theme)); | |||||
\app('translator')->addNamespace('theme', $path); | |||||
} | |||||
} | } |