Dotclear

source: inc/public/prepend.php @ 3059:163797a9e57c

Revision 3059:163797a9e57c, 4.5 KB checked in by franck <carnet.franck.paul@…>, 10 years ago (diff)

Set default locale depending on context (admin=user, public=blog), adresses #1850

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

Sites map