| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * @package Dotclear |
|---|
| 4 | * @subpackage Public |
|---|
| 5 | * |
|---|
| 6 | * @copyright Olivier Meunier & Association Dotclear |
|---|
| 7 | * @copyright GPL-2.0-only |
|---|
| 8 | */ |
|---|
| 9 | |
|---|
| 10 | if (!empty($_GET['pf'])) { |
|---|
| 11 | require dirname(__FILE__) . '/../load_plugin_file.php'; |
|---|
| 12 | exit; |
|---|
| 13 | } |
|---|
| 14 | |
|---|
| 15 | if (!empty($_GET['vf'])) { |
|---|
| 16 | require dirname(__FILE__) . '/../load_var_file.php'; |
|---|
| 17 | exit; |
|---|
| 18 | } |
|---|
| 19 | |
|---|
| 20 | if (!isset($_SERVER['PATH_INFO'])) { |
|---|
| 21 | $_SERVER['PATH_INFO'] = ''; |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | require_once dirname(__FILE__) . '/../prepend.php'; |
|---|
| 25 | require_once dirname(__FILE__) . '/rs.extension.php'; |
|---|
| 26 | |
|---|
| 27 | # Loading blog |
|---|
| 28 | if (defined('DC_BLOG_ID')) { |
|---|
| 29 | try { |
|---|
| 30 | $core->setBlog(DC_BLOG_ID); |
|---|
| 31 | } catch (Exception $e) { |
|---|
| 32 | init_prepend_l10n(); |
|---|
| 33 | __error(__('Database problem') |
|---|
| 34 | , DC_DEBUG ? |
|---|
| 35 | __('The following error was encountered while trying to read the database:') . '</p><ul><li>' . $e->getMessage() . '</li></ul>' : |
|---|
| 36 | __('Something went wrong while trying to read the database.') |
|---|
| 37 | , 620); |
|---|
| 38 | } |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | if ($core->blog->id == null) { |
|---|
| 42 | __error(__('Blog is not defined.') |
|---|
| 43 | , __('Did you change your Blog ID?') |
|---|
| 44 | , 630); |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | if ((boolean) !$core->blog->status) { |
|---|
| 48 | $core->unsetBlog(); |
|---|
| 49 | __error(__('Blog is offline.') |
|---|
| 50 | , __('This blog is offline. Please try again later.') |
|---|
| 51 | , 670); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | # Loading media |
|---|
| 55 | try { |
|---|
| 56 | $core->media = new dcMedia($core); |
|---|
| 57 | } catch (Exception $e) {} |
|---|
| 58 | |
|---|
| 59 | # Creating template context |
|---|
| 60 | $_ctx = new context(); |
|---|
| 61 | try { |
|---|
| 62 | $core->tpl = new dcTemplate(DC_TPL_CACHE, '$core->tpl', $core); |
|---|
| 63 | } catch (Exception $e) { |
|---|
| 64 | __error(__('Can\'t create template files.') |
|---|
| 65 | , $e->getMessage() |
|---|
| 66 | , 640); |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | # Loading locales |
|---|
| 70 | $_lang = $core->blog->settings->system->lang; |
|---|
| 71 | $_lang = preg_match('/^[a-z]{2}(-[a-z]{2})?$/', $_lang) ? $_lang : 'en'; |
|---|
| 72 | |
|---|
| 73 | l10n::lang($_lang); |
|---|
| 74 | if (l10n::set(dirname(__FILE__) . '/../../locales/' . $_lang . '/date') === false && $_lang != 'en') { |
|---|
| 75 | l10n::set(dirname(__FILE__) . '/../../locales/en/date'); |
|---|
| 76 | } |
|---|
| 77 | l10n::set(dirname(__FILE__) . '/../../locales/' . $_lang . '/public'); |
|---|
| 78 | l10n::set(dirname(__FILE__) . '/../../locales/' . $_lang . '/plugins'); |
|---|
| 79 | |
|---|
| 80 | // Set lexical lang |
|---|
| 81 | dcUtils::setlexicalLang('public', $_lang); |
|---|
| 82 | |
|---|
| 83 | # Loading plugins |
|---|
| 84 | try { |
|---|
| 85 | $core->plugins->loadModules(DC_PLUGINS_ROOT, 'public', $_lang); |
|---|
| 86 | } catch (Exception $e) {} |
|---|
| 87 | |
|---|
| 88 | # Loading themes |
|---|
| 89 | $core->themes = new dcThemes($core); |
|---|
| 90 | $core->themes->loadModules($core->blog->themes_path); |
|---|
| 91 | |
|---|
| 92 | # Defining theme if not defined |
|---|
| 93 | if (!isset($__theme)) { |
|---|
| 94 | $__theme = $core->blog->settings->system->theme; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | if (!$core->themes->moduleExists($__theme)) { |
|---|
| 98 | $__theme = $core->blog->settings->system->theme = 'default'; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | $__parent_theme = $core->themes->moduleInfo($__theme, 'parent'); |
|---|
| 102 | if ($__parent_theme) { |
|---|
| 103 | if (!$core->themes->moduleExists($__parent_theme)) { |
|---|
| 104 | $__theme = $core->blog->settings->system->theme = 'default'; |
|---|
| 105 | $__parent_theme = null; |
|---|
| 106 | } |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | # If theme doesn't exist, stop everything |
|---|
| 110 | if (!$core->themes->moduleExists($__theme)) { |
|---|
| 111 | __error(__('Default theme not found.') |
|---|
| 112 | , __('This either means you removed your default theme or set a wrong theme ' . |
|---|
| 113 | 'path in your blog configuration. Please check theme_path value in ' . |
|---|
| 114 | 'about:config module or reinstall default theme. (' . $__theme . ')') |
|---|
| 115 | , 650); |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | # Loading _public.php file for selected theme |
|---|
| 119 | $core->themes->loadNsFile($__theme, 'public'); |
|---|
| 120 | |
|---|
| 121 | # Loading translations for selected theme |
|---|
| 122 | if ($__parent_theme) { |
|---|
| 123 | $core->themes->loadModuleL10N($__parent_theme, $_lang, 'main'); |
|---|
| 124 | } |
|---|
| 125 | $core->themes->loadModuleL10N($__theme, $_lang, 'main'); |
|---|
| 126 | |
|---|
| 127 | # --BEHAVIOR-- publicPrepend |
|---|
| 128 | $core->callBehavior('publicPrepend', $core); |
|---|
| 129 | |
|---|
| 130 | # Prepare the HTTP cache thing |
|---|
| 131 | $mod_files = get_included_files(); |
|---|
| 132 | $mod_ts = []; |
|---|
| 133 | $mod_ts[] = $core->blog->upddt; |
|---|
| 134 | |
|---|
| 135 | $__theme_tpl_path = [ |
|---|
| 136 | $core->blog->themes_path . '/' . $__theme . '/tpl' |
|---|
| 137 | ]; |
|---|
| 138 | if ($__parent_theme) { |
|---|
| 139 | $__theme_tpl_path[] = $core->blog->themes_path . '/' . $__parent_theme . '/tpl'; |
|---|
| 140 | } |
|---|
| 141 | $tplset = $core->themes->moduleInfo($core->blog->settings->system->theme, 'tplset'); |
|---|
| 142 | if (!empty($tplset) && is_dir(dirname(__FILE__) . '/default-templates/' . $tplset)) { |
|---|
| 143 | $core->tpl->setPath( |
|---|
| 144 | $__theme_tpl_path, |
|---|
| 145 | dirname(__FILE__) . '/default-templates/' . $tplset, |
|---|
| 146 | $core->tpl->getPath()); |
|---|
| 147 | } else { |
|---|
| 148 | $core->tpl->setPath( |
|---|
| 149 | $__theme_tpl_path, |
|---|
| 150 | $core->tpl->getPath()); |
|---|
| 151 | } |
|---|
| 152 | $core->url->mode = $core->blog->settings->system->url_scan; |
|---|
| 153 | |
|---|
| 154 | try { |
|---|
| 155 | # --BEHAVIOR-- publicBeforeDocument |
|---|
| 156 | $core->callBehavior('publicBeforeDocument', $core); |
|---|
| 157 | |
|---|
| 158 | $core->url->getDocument(); |
|---|
| 159 | |
|---|
| 160 | # --BEHAVIOR-- publicAfterDocument |
|---|
| 161 | $core->callBehavior('publicAfterDocument', $core); |
|---|
| 162 | } catch (Exception $e) { |
|---|
| 163 | __error($e->getMessage() |
|---|
| 164 | , __('Something went wrong while loading template file for your blog.') |
|---|
| 165 | , 660); |
|---|
| 166 | } |
|---|