|
| 1 | +<?php |
| 2 | + |
| 3 | + |
| 4 | +namespace ModStart\Core\View; |
| 5 | + |
| 6 | + |
| 7 | +use Illuminate\Support\Facades\Input; |
| 8 | +use Illuminate\Support\Facades\Session; |
| 9 | +use Illuminate\Support\Str; |
| 10 | +use Module\Vendor\Provider\SiteTemplate\SiteTemplateProvider; |
| 11 | + |
| 12 | +class ResponsiveView |
| 13 | +{ |
| 14 | + public static function templateRoot() |
| 15 | + { |
| 16 | + static $provider = null; |
| 17 | + static $templateRoot = null; |
| 18 | + if (null !== $templateRoot) { |
| 19 | + return $templateRoot; |
| 20 | + } |
| 21 | + static $templateName = 'default'; |
| 22 | + $msSiteTemplate = Input::get('msSiteTemplate', null); |
| 23 | + if (!empty($msSiteTemplate)) { |
| 24 | + $provider = SiteTemplateProvider::get($msSiteTemplate); |
| 25 | + if (!empty($provider)) { |
| 26 | + Session::put('msSiteTemplate', $msSiteTemplate); |
| 27 | + } |
| 28 | + } |
| 29 | + if (empty($provider)) { |
| 30 | + $msSiteTemplate = Session::get('msSiteTemplate', null); |
| 31 | + if (!empty($msSiteTemplate)) { |
| 32 | + $provider = SiteTemplateProvider::get($msSiteTemplate); |
| 33 | + if (empty($provider)) { |
| 34 | + Session::forget('msSiteTemplate'); |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + if (empty($provider)) { |
| 39 | + $templateName = modstart_config()->getWithEnv('siteTemplate', 'default'); |
| 40 | + $provider = SiteTemplateProvider::get($templateName); |
| 41 | + } |
| 42 | + if ($provider && $provider->root()) { |
| 43 | + $templateRoot = $provider->root(); |
| 44 | + } else { |
| 45 | + $templateRoot = "theme.$templateName"; |
| 46 | + } |
| 47 | + return $templateRoot; |
| 48 | + } |
| 49 | + |
| 50 | + public static function templateRootRealpath($module) |
| 51 | + { |
| 52 | + $root = self::templateRoot(); |
| 53 | + if (Str::startsWith($root, 'module::')) { |
| 54 | + $root = str_replace(['::', '.'], '/', $root); |
| 55 | + $root = base_path($root); |
| 56 | + } else if (Str::startsWith($root, 'theme.')) { |
| 57 | + $root = 'resources/views/' . str_replace(['.'], '/', $root); |
| 58 | + $root = base_path($root); |
| 59 | + if (!file_exists($root)) { |
| 60 | + $root = base_path('module/' . $module . '/View'); |
| 61 | + } |
| 62 | + if (!file_exists($root)) { |
| 63 | + $root = base_path('resources/views/theme/default'); |
| 64 | + } |
| 65 | + } else { |
| 66 | + $root = base_path($root); |
| 67 | + } |
| 68 | + return rtrim($root, '\\/') . '/'; |
| 69 | + } |
| 70 | +} |
0 commit comments