Dotclear

source: inc/prepend.php @ 2286:c14a5e07a2f7

Revision 2286:c14a5e07a2f7, 11.2 KB checked in by Denis Jean-Chirstian <contact@…>, 12 years ago (diff)

Formalizes themes and plugins provided with the distribution

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

Sites map