Dotclear

source: inc/prepend.php @ 1492:a7112dcc916c

Revision 1492:a7112dcc916c, 11.1 KB checked in by Dsls, 11 years ago (diff)

Fusion avec default

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2011 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
13/* ------------------------------------------------------------------------------------------- */
14#  ClearBricks, Twig, DotClear classes auto-loader
15if (@is_dir('/usr/lib/clearbricks')) {
16     define('CLEARBRICKS_PATH','/usr/lib/clearbricks');
17} elseif (is_dir(dirname(__FILE__).'/libs/clearbricks')) {
18     define('CLEARBRICKS_PATH',dirname(__FILE__).'/libs/clearbricks');
19} elseif (isset($_SERVER['CLEARBRICKS_PATH']) && is_dir($_SERVER['CLEARBRICKS_PATH'])) {
20     define('CLEARBRICKS_PATH',$_SERVER['CLEARBRICKS_PATH']);
21}
22
23if (!defined('CLEARBRICKS_PATH') || !is_dir(CLEARBRICKS_PATH)) {
24     exit('No clearbricks path defined');
25}
26
27require CLEARBRICKS_PATH.'/_common.php';
28$__autoload['dcCore']                   = dirname(__FILE__).'/core/class.dc.core.php';
29$__autoload['dcAuth']                   = dirname(__FILE__).'/core/class.dc.auth.php';
30$__autoload['dcBlog']                   = dirname(__FILE__).'/core/class.dc.blog.php';
31$__autoload['dcCategories']             = dirname(__FILE__).'/core/class.dc.categories.php';
32$__autoload['dcError']                  = dirname(__FILE__).'/core/class.dc.error.php';
33$__autoload['dcMeta']                   = dirname(__FILE__).'/core/class.dc.meta.php';
34$__autoload['dcMedia']                  = dirname(__FILE__).'/core/class.dc.media.php';
35$__autoload['dcPostMedia']                   = dirname(__FILE__).'/core/class.dc.postmedia.php';
36$__autoload['dcModules']                = dirname(__FILE__).'/core/class.dc.modules.php';
37$__autoload['dcThemes']                 = dirname(__FILE__).'/core/class.dc.themes.php';
38$__autoload['dcRestServer']             = dirname(__FILE__).'/core/class.dc.rest.php';
39$__autoload['dcNamespace']              = dirname(__FILE__).'/core/class.dc.namespace.php';
40$__autoload['dcSettings']               = dirname(__FILE__).'/core/class.dc.settings.php';
41$__autoload['dcTrackback']              = dirname(__FILE__).'/core/class.dc.trackback.php';
42$__autoload['dcUpdate']                 = dirname(__FILE__).'/core/class.dc.update.php';
43$__autoload['dcUtils']                  = dirname(__FILE__).'/core/class.dc.utils.php';
44$__autoload['dcXmlRpc']                 = dirname(__FILE__).'/core/class.dc.xmlrpc.php';
45$__autoload['dcLog']                    = dirname(__FILE__).'/core/class.dc.log.php';
46$__autoload['dcWorkspace']              = dirname(__FILE__).'/core/class.dc.workspace.php';
47$__autoload['dcPrefs']                  = dirname(__FILE__).'/core/class.dc.prefs.php';
48$__autoload['dcTwigPage']               = dirname(__FILE__).'/core/class.dc.twig.page.php';
49
50$__autoload['rsExtPost']                = dirname(__FILE__).'/core/class.dc.rs.extensions.php';
51$__autoload['rsExtComment']             = dirname(__FILE__).'/core/class.dc.rs.extensions.php';
52$__autoload['rsExtDates']               = dirname(__FILE__).'/core/class.dc.rs.extensions.php';
53$__autoload['rsExtUser']                = dirname(__FILE__).'/core/class.dc.rs.extensions.php';
54
55$__autoload['dcAdminContext']                = dirname(__FILE__).'/admin/class.dc.admincontext.php';
56$__autoload['dcMenu']                   = dirname(__FILE__).'/admin/class.dc.menu.php';
57$__autoload['dcPage']                   = dirname(__FILE__).'/admin/lib.dc.page.php';
58$__autoload['adminGenericList']         = dirname(__FILE__).'/admin/lib.pager.php';
59$__autoload['adminPostList']            = dirname(__FILE__).'/admin/lib.pager.php';
60$__autoload['adminPostMiniList']        = dirname(__FILE__).'/admin/lib.pager.php';
61$__autoload['adminCommentList']         = dirname(__FILE__).'/admin/lib.pager.php';
62$__autoload['adminUserList']            = dirname(__FILE__).'/admin/lib.pager.php';
63
64$__autoload['dcTemplate']               = dirname(__FILE__).'/public/class.dc.template.php';
65$__autoload['context']                  = dirname(__FILE__).'/public/lib.tpl.context.php';
66$__autoload['dcUrlHandlers']            = dirname(__FILE__).'/public/lib.urlhandlers.php';
67$__autoload['dcForm']              = dirname(__FILE__).'/admin/class.dc.form.php';
68$__autoload['dcFormExtension']               = dirname(__FILE__).'/admin/class.dc.form.php';
69$__autoload['dcTabExtension']           = dirname(__FILE__).'/admin/class.dc.tab.php';
70$__autoload['dcItemList']               = dirname(__FILE__).'/admin/class.dc.list.php';
71$__autoload['dcListFetcher']            = dirname(__FILE__).'/admin/class.dc.list.php';
72
73foreach (array('dcFilterSet', 'dcFilter','dcFilterCombo','dcFilterText','dcFilterBoolean') as $c) {
74     $__autoload[$c] = dirname(__FILE__).'/admin/class.dc.filter.php';
75}
76
77# Clearbricks extensions
78html::$absolute_regs[] = '/(<param\s+name="movie"\s+value=")(.*?)(")/msu';
79html::$absolute_regs[] = '/(<param\s+name="FlashVars"\s+value=".*?(?:mp3|flv)=)(.*?)(&|")/msu';
80
81if (@is_dir('/usr/lib/twig')) {
82     define('TWIG_PATH','/usr/lib/Twig');
83} elseif (is_dir(dirname(__FILE__).'/libs/Twig')) {
84     define('TWIG_PATH',dirname(__FILE__).'/libs/Twig');
85} elseif (isset($_SERVER['TWIG_PATH']) && is_dir($_SERVER['TWIG_PATH'])) {
86     define('TWIG_PATH',$_SERVER['TWIG_PATH']);
87}
88
89if (!defined('TWIG_PATH') || !is_dir(TWIG_PATH)) {
90     exit('No Twig path defined');
91}
92require TWIG_PATH.'/Autoloader.php';
93Twig_Autoloader::register();
94
95/* ------------------------------------------------------------------------------------------- */
96
97
98mb_internal_encoding('UTF-8');
99
100# Setting timezone
101dt::setTZ('UTC');
102
103# CLI_MODE, boolean constant that tell if we are in CLI mode
104define('CLI_MODE',PHP_SAPI == 'cli');
105
106# Disallow every special wrapper
107if (function_exists('stream_wrapper_unregister'))
108{
109     foreach (array('http','https','ftp','ftps','ssh2.shell','ssh2.exec',
110     'ssh2.tunnel','ssh2.sftp','ssh2.scp','ogg','expect') as $p) {
111          @stream_wrapper_unregister($p);
112     }
113}
114
115if (isset($_SERVER['DC_RC_PATH'])) {
116     define('DC_RC_PATH',$_SERVER['DC_RC_PATH']);
117} elseif (isset($_SERVER['REDIRECT_DC_RC_PATH'])) {
118     define('DC_RC_PATH',$_SERVER['REDIRECT_DC_RC_PATH']);
119} else {
120     define('DC_RC_PATH',dirname(__FILE__).'/config.php');
121}
122
123if (!is_file(DC_RC_PATH))
124{
125     if (strpos($_SERVER['SCRIPT_FILENAME'],'/admin') === false) {
126          $path = 'admin/install/wizard.php';
127     } else {
128          $path = strpos($_SERVER['PHP_SELF'],'/install') === false ? 'install/wizard.php' : 'wizard.php';
129     }
130     http::redirect($path);
131}
132
133require DC_RC_PATH;
134
135//*== DC_DEBUG ==
136if (!defined('DC_DEBUG')) {
137     define('DC_DEBUG',true);
138}
139if (DC_DEBUG) {
140     ini_set('display_errors',true);
141     error_reporting(E_ALL | E_STRICT);
142}
143//*/
144
145if (!defined('DC_DEBUG')) {
146     define('DC_DEBUG',false);
147}
148
149# Constants
150define('DC_ROOT',path::real(dirname(__FILE__).'/..'));
151define('DC_VERSION','2.99-dev');
152define('DC_DIGESTS',dirname(__FILE__).'/digests');
153define('DC_L10N_ROOT',dirname(__FILE__).'/../locales');
154define('DC_L10N_UPDATE_URL','http://services.dotclear.net/dc2.l10n/?version=%s');
155
156if (!defined('DC_VENDOR_NAME')) {
157     define('DC_VENDOR_NAME','Dotclear');
158}
159
160if (!defined('DC_XMLRPC_URL')) {
161     define('DC_XMLRPC_URL','%1$sxmlrpc/%2$s');
162}
163
164if (!defined('DC_ADMIN_SSL')) {
165     define('DC_ADMIN_SSL',false);
166}
167
168if (defined('DC_FORCE_SCHEME_443') && DC_FORCE_SCHEME_443) {
169     http::$https_scheme_on_443 = true;
170}
171
172if (!defined('DC_DBPERSIST')) {
173     define('DC_DBPERSIST',false);
174}
175
176if (!defined('DC_UPDATE_URL')) {
177     define('DC_UPDATE_URL','http://download.dotclear.org/versions.xml');
178}
179
180if (!defined('DC_UPDATE_VERSION')) {
181     define('DC_UPDATE_VERSION','stable');
182}
183
184l10n::init();
185
186try {
187     $core = new dcCore(DC_DBDRIVER,DC_DBHOST,DC_DBNAME,DC_DBUSER,DC_DBPASSWORD,DC_DBPREFIX,DC_DBPERSIST);
188} catch (Exception $e) {
189     init_prepend_l10n();
190     if (!defined('DC_CONTEXT_ADMIN')) {
191          __error(__('Site temporarily unavailable'),
192               __('<p>We apologize for this temporary unavailability.<br />'.
193               'Thank you for your understanding.</p>'),
194               20);
195     } else {
196          __error(__('Unable to connect to database')
197               ,$e->getCode() == 0 ?
198               sprintf(__('<p>This either means that the username and password information in '.
199               'your <strong>config.php</strong> file is incorrect or we can\'t contact '.
200               'the database server at "<em>%s</em>". This could mean your '.
201               'host\'s database server is down.</p> '.
202               '<ul><li>Are you sure you have the correct username and password?</li>'.
203               '<li>Are you sure that you have typed the correct hostname?</li>'.
204               '<li>Are you sure that the database server is running?</li></ul>'.
205               '<p>If you\'re unsure what these terms mean you should probably contact '.
206               'your host. If you still need help you can always visit the '.
207               '<a href="http://forum.dotclear.net/">Dotclear Support Forums</a>.</p>').
208               (DC_DEBUG ?
209                    __('The following error was encountered while trying to read the database:').'</p><ul><li>'.$e->getMessage().'</li></ul>' :  '')
210               ,(DC_DBHOST != '' ? DC_DBHOST : 'localhost')
211               )
212               : ''
213               ,20);
214     }
215}
216
217# If we have some __top_behaviors, we load them
218if (isset($__top_behaviors) && is_array($__top_behaviors))
219{
220     foreach ($__top_behaviors as $b) {
221          $core->addBehavior($b[0],$b[1]);
222     }
223     unset($b);
224}
225
226http::trimRequest();
227try {
228     http::unsetGlobals();
229} catch (Exception $e) {
230     header('Content-Type: text/plain');
231     echo $e->getMessage();
232     exit;
233}
234
235$core->url->registerDefault(array('dcUrlHandlers','home'));
236$core->url->registerError(array('dcUrlHandlers','default404'));
237$core->url->register('lang','','^([a-zA-Z]{2}(?:-[a-z]{2})?(?:/page/[0-9]+)?)$',array('dcUrlHandlers','lang'));
238$core->url->register('post','post','^post/(.+)$',array('dcUrlHandlers','post'));
239$core->url->register('preview','preview','^preview/(.+)$',array('dcUrlHandlers','preview'));
240$core->url->register('category','category','^category/(.+)$',array('dcUrlHandlers','category'));
241$core->url->register('archive','archive','^archive(/.+)?$',array('dcUrlHandlers','archive'));
242
243$core->url->register('feed','feed','^feed/(.+)$',array('dcUrlHandlers','feed'));
244$core->url->register('trackback','trackback','^trackback/(.+)$',array('dcUrlHandlers','trackback'));
245$core->url->register('rsd','rsd','^rsd$',array('dcUrlHandlers','rsd'));
246$core->url->register('xmlrpc','xmlrpc','^xmlrpc/(.+)$',array('dcUrlHandlers','xmlrpc'));
247
248$core->setPostType('post','post.php?id=%d',$core->url->getURLFor('post','%s'));
249
250# Store upload_max_filesize in bytes
251$u_max_size = files::str2bytes(ini_get('upload_max_filesize'));
252$p_max_size = files::str2bytes(ini_get('post_max_size'));
253if ($p_max_size < $u_max_size) {
254     $u_max_size = $p_max_size;
255}
256define('DC_MAX_UPLOAD_SIZE',$u_max_size);
257unset($u_max_size); unset($p_max_size);
258
259# Shutdown
260register_shutdown_function('__shutdown');
261
262function __shutdown()
263{
264     global $__shutdown;
265     if (is_array($__shutdown)) {
266          foreach ($__shutdown as $f) {
267               if (is_callable($f)) {
268                    call_user_func($f);
269               }
270          }
271     }
272     # Explicitly close session before DB connection
273     try {
274          if (session_id()) {
275               session_write_close();
276          }
277     } catch (Exception $e) {}
278     $GLOBALS['core']->con->close();
279}
280
281function __error($summary,$message,$code=0)
282{
283     # Error codes
284     # 10 : no config file
285     # 20 : database issue
286     # 30 : blog is not defined
287     # 40 : template files creation
288     # 50 : no default theme
289     # 60 : template processing error
290     # 70 : blog is offline
291     
292     if (CLI_MODE)
293     {
294          trigger_error($summary,E_USER_ERROR);
295          exit(1);
296     }
297     else
298     {
299          if (defined('DC_ERRORFILE') && is_file(DC_ERRORFILE)) {
300               include DC_ERRORFILE;
301          } else {
302               include dirname(__FILE__).'/core_error.php';
303          }
304          exit;
305     }
306}
307
308function init_prepend_l10n()
309{
310     # Loading locales for detected language
311     $dlang = http::getAcceptLanguages();
312     foreach($dlang as $l)
313     {
314          if ($l == 'en' || l10n::set(dirname(__FILE__).'/../locales/'.$l.'/main') !== false) {
315               break;
316          }
317     }
318}
319?>
Note: See TracBrowser for help on using the repository browser.

Sites map