exists($path)) { return view($path, $params); } // Append demo folder for layout view if (Str::startsWith($path, 'layout')) { $path = str_replace('layout', 'layout/' . self::$demo, $path); } $view = view($path, $params); // Special fix to print _mega-menu content for Core/Theme.php if (strpos($path, '_mega-menu') !== false) { echo $view; } return $view; } /** * Print fonts in the HTML head * * @param string $value */ public static function includeFonts($value = '') { if (self::hasOption('assets', 'fonts/google')) { $fonts = self::getOption('assets', 'fonts/google'); echo ''; } } /** * Check if the option has a value * * @param $scope * @param false $path * * @return bool */ public static function hasOption($scope, $path = false) { return (bool) self::getOption($scope, $path); } /** * Get the option's value from config * * @param $scope * @param false $path * @param null $default * * @return mixed|string */ public static function getOption($scope, $path = false, $default = null) { $demo = self::getDemo() ?? 'demo1'; // Map the config path if (array_key_exists($scope, config($demo . '.general', []))) { $scope = 'general.' . $scope; } if (in_array($scope, ['page', 'pages'])) { $scope = 'pages'; $segments = request()->segments(); $scope .= '.' . implode('.', $segments); } // Get current page path $deepPath = ''; if (!empty($path)) { $deepPath = '.' . str_replace('/', '.', $path); } // Demo config $demoConfig = config($demo . '.' . $scope . $deepPath, $default); // check if it is a callback if (is_callable($demoConfig) && !is_string($demoConfig)) { $demoConfig = $demoConfig(); } return $demoConfig; } /** * Get current demo * * @return string */ public static function getDemo() { if (class_exists('request')) { return request()->input('demo', self::$demo); } return self::$demo; } /** * Get the product name string wrapped with the tag * * @return string */ public static function getProductNameHtml() { return '' . self::getProductName() . ' Laravel '; } /** * Get plain product name text * * @return mixed|string */ public static function getProductName() { return self::getOption('product', 'name'); } /** * Get the version number string from config file * * @return mixed */ public static function getVersion() { $versions = array_keys(config('changelog', [])); if (isset($versions[0])) { return str_replace('v', '', $versions[0]); } return null; } /** * Get the current page title from config page.php */ public static function getPageTitle() { return theme()->getOption('page', 'title'); } /** * Get current route name and replace with a new route name * * @param $name * * @return string */ public static function subRoute($name) { $routes = explode('.', Route::currentRouteName()); array_pop($routes); $parent = implode('.', $routes); return $parent . '.' . $name; } public static function putProVersionTooltip($attr = array()) { ob_start(); // Call the function from core Theme parent::putProVersionTooltip($attr); return ob_get_clean(); } public static function getIllustrationUrl($file, $dark = true) { if ($dark === true) { if (self::isDarkMode()) { $file = str_replace(".svg", "-dark.svg", $file); $file = str_replace(".png", "-dark.png", $file); $file = str_replace(".jpg", "-dark.jpg", $file); } } $folder = 'illustrations/' . self::getOption('layout', 'illustrations/set'); return self::getMediaUrlPath() . $folder . '/' . $file; } /** * Check dark mode * * @return mixed|string */ public static function isDarkMode() { return self::getCurrentMode() === 'dark'; } /** * Get current skin * * @return mixed|string */ public static function getCurrentMode() { if (self::isDarkModeEnabled() && isset($_REQUEST['mode']) && $_REQUEST['mode']) { return $_REQUEST['mode']; } return 'light'; } /** * Check if current theme has dark mode * * @return bool */ public static function isDarkModeEnabled() { return (bool) self::getOption('layout', 'main/dark-mode-enabled'); } /** * Get media path * * @return string */ public static function getMediaUrlPath() { return theme()->getDemo() . '/media/'; } public static function getImageUrl($folder, $file, $dark = true) { if ($dark) { if (self::isDarkMode()) { $file = str_replace(".svg", "-dark.svg", $file); $file = str_replace(".png", "-dark.png", $file); $file = str_replace(".jpg", "-dark.jpg", $file); } } return self::getMediaUrlPath() . $folder . '/' . $file; } /** * Rebuild config and merge with main and page config level in boot */ public function initConfig() { $mainConfig = collect(config('global')); $demoConfig = config(Theme::$demo); $mergedConfig = $mainConfig->replaceRecursive($demoConfig); config([Theme::$demo => $mergedConfig->all()]); self::$config = $mergedConfig->all(); // Get config by url path $configPath = Theme::$demo . '.pages.' . str_replace('/', '.', Theme::getPagePath()); $pageConfig = collect(config($configPath)); // Merge group config with child config $pageGroupOptions = Theme::getPageGroupOptions(config(Theme::$demo . '.pages'), Theme::getPagePath()); if ($pageGroupOptions) { $overridenConfig = $pageConfig->replaceRecursive($pageGroupOptions); config([$configPath => $overridenConfig->all()]); } $generalConfig = collect(config(Theme::$demo . '.general')); // Merge general config with page level config config([Theme::$demo . '.general' => $generalConfig->replaceRecursive(config($configPath))->all()]); } /** * Get current page path * * @return mixed */ public static function getPagePath() { // Override page path $segments = request()->segments(); if (!empty($segments)) { \App\Core\Theme::$page = implode('/', $segments); } return \App\Core\Theme::getPagePath(); } /** * Get menu array from config * * @return array */ public function getMenu() { $menus = self::getOption('menu'); $output = []; foreach ($menus as $menu) { if (is_array($menu)) { $this->iterateMenu($menu, $output); } } return $output; } /** * Iterate menu array for self::getMenu() function * * @param $menus * @param $output */ private function iterateMenu($menus, &$output) { if (!is_array($menus)) { return; } if (isset($menus['path'])) { $output[] = $menus; } if (is_array($menus)) { foreach ($menus as $menu) { $this->iterateMenu($menu, $output); } } } public static function getDemosTotal() { $total = 0; foreach (self::getOption('product', 'demos') as $id => $demo) { if ($demo['published'] === true) { $total++; } } return $total; } }