Dotclear

source: inc/prepend.php @ 2313:ef1db3d7c388

Revision 2313:ef1db3d7c388, 12.3 KB checked in by Dsls, 12 years ago (diff)

Twig merge - lots of things to adapt yet

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

Sites map