| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * @package Dotclear |
|---|
| 4 | * @subpackage Core |
|---|
| 5 | * |
|---|
| 6 | * @copyright Olivier Meunier & Association Dotclear |
|---|
| 7 | * @copyright GPL-2.0-only |
|---|
| 8 | */ |
|---|
| 9 | |
|---|
| 10 | /* Start tick */ |
|---|
| 11 | define('DC_START_TIME', microtime(true)); |
|---|
| 12 | |
|---|
| 13 | /* ------------------------------------------------------------------------------------------- */ |
|---|
| 14 | # ClearBricks, DotClear classes auto-loader |
|---|
| 15 | if (@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 | |
|---|
| 23 | if (!defined('CLEARBRICKS_PATH') || !is_dir(CLEARBRICKS_PATH)) { |
|---|
| 24 | exit('No clearbricks path defined'); |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | require CLEARBRICKS_PATH . '/_common.php'; |
|---|
| 28 | |
|---|
| 29 | $__autoload['dcCore'] = dirname(__FILE__) . '/core/class.dc.core.php'; |
|---|
| 30 | $__autoload['dcAuth'] = dirname(__FILE__) . '/core/class.dc.auth.php'; |
|---|
| 31 | $__autoload['dcBlog'] = dirname(__FILE__) . '/core/class.dc.blog.php'; |
|---|
| 32 | $__autoload['dcCategories'] = dirname(__FILE__) . '/core/class.dc.categories.php'; |
|---|
| 33 | $__autoload['dcError'] = dirname(__FILE__) . '/core/class.dc.error.php'; |
|---|
| 34 | $__autoload['dcMeta'] = dirname(__FILE__) . '/core/class.dc.meta.php'; |
|---|
| 35 | $__autoload['dcMedia'] = dirname(__FILE__) . '/core/class.dc.media.php'; |
|---|
| 36 | $__autoload['dcPostMedia'] = dirname(__FILE__) . '/core/class.dc.postmedia.php'; |
|---|
| 37 | $__autoload['dcModules'] = dirname(__FILE__) . '/core/class.dc.modules.php'; |
|---|
| 38 | $__autoload['dcPlugins'] = dirname(__FILE__) . '/core/class.dc.plugins.php'; |
|---|
| 39 | $__autoload['dcThemes'] = dirname(__FILE__) . '/core/class.dc.themes.php'; |
|---|
| 40 | $__autoload['dcRestServer'] = dirname(__FILE__) . '/core/class.dc.rest.php'; |
|---|
| 41 | $__autoload['dcNamespace'] = dirname(__FILE__) . '/core/class.dc.namespace.php'; |
|---|
| 42 | $__autoload['dcSettings'] = dirname(__FILE__) . '/core/class.dc.settings.php'; |
|---|
| 43 | $__autoload['dcTrackback'] = dirname(__FILE__) . '/core/class.dc.trackback.php'; |
|---|
| 44 | $__autoload['dcUpdate'] = dirname(__FILE__) . '/core/class.dc.update.php'; |
|---|
| 45 | $__autoload['dcUtils'] = dirname(__FILE__) . '/core/class.dc.utils.php'; |
|---|
| 46 | $__autoload['dcXmlRpc'] = dirname(__FILE__) . '/core/class.dc.xmlrpc.php'; |
|---|
| 47 | $__autoload['dcLog'] = dirname(__FILE__) . '/core/class.dc.log.php'; |
|---|
| 48 | $__autoload['dcWorkspace'] = dirname(__FILE__) . '/core/class.dc.workspace.php'; |
|---|
| 49 | $__autoload['dcPrefs'] = dirname(__FILE__) . '/core/class.dc.prefs.php'; |
|---|
| 50 | $__autoload['dcStore'] = dirname(__FILE__) . '/core/class.dc.store.php'; |
|---|
| 51 | $__autoload['dcStoreReader'] = dirname(__FILE__) . '/core/class.dc.store.reader.php'; |
|---|
| 52 | $__autoload['dcStoreParser'] = dirname(__FILE__) . '/core/class.dc.store.parser.php'; |
|---|
| 53 | $__autoload['dcSqlStatement'] = dirname(__FILE__) . '/core/class.dc.sql.statement.php'; |
|---|
| 54 | $__autoload['dcSelectStatement'] = dirname(__FILE__) . '/core/class.dc.sql.statement.php'; |
|---|
| 55 | $__autoload['dcUpdateStatement'] = dirname(__FILE__) . '/core/class.dc.sql.statement.php'; |
|---|
| 56 | $__autoload['dcDeleteStatement'] = dirname(__FILE__) . '/core/class.dc.sql.statement.php'; |
|---|
| 57 | $__autoload['dcInsertStatement'] = dirname(__FILE__) . '/core/class.dc.sql.statement.php'; |
|---|
| 58 | $__autoload['rsExtPost'] = dirname(__FILE__) . '/core/class.dc.rs.extensions.php'; |
|---|
| 59 | $__autoload['rsExtComment'] = dirname(__FILE__) . '/core/class.dc.rs.extensions.php'; |
|---|
| 60 | $__autoload['rsExtDates'] = dirname(__FILE__) . '/core/class.dc.rs.extensions.php'; |
|---|
| 61 | $__autoload['rsExtUser'] = dirname(__FILE__) . '/core/class.dc.rs.extensions.php'; |
|---|
| 62 | |
|---|
| 63 | $__autoload['dcUpgrade'] = dirname(__FILE__) . '/dbschema/upgrade.php'; |
|---|
| 64 | |
|---|
| 65 | $__autoload['dcMenu'] = dirname(__FILE__) . '/admin/class.dc.menu.php'; |
|---|
| 66 | $__autoload['dcFavorites'] = dirname(__FILE__) . '/admin/class.dc.favorites.php'; |
|---|
| 67 | $__autoload['dcNotices'] = dirname(__FILE__) . '/admin/class.dc.notices.php'; |
|---|
| 68 | $__autoload['dcPage'] = dirname(__FILE__) . '/admin/lib.dc.page.php'; |
|---|
| 69 | $__autoload['adminGenericList'] = dirname(__FILE__) . '/admin/lib.pager.php'; |
|---|
| 70 | $__autoload['adminPostList'] = dirname(__FILE__) . '/admin/lib.pager.php'; |
|---|
| 71 | $__autoload['adminPostMiniList'] = dirname(__FILE__) . '/admin/lib.pager.php'; |
|---|
| 72 | $__autoload['adminCommentList'] = dirname(__FILE__) . '/admin/lib.pager.php'; |
|---|
| 73 | $__autoload['adminBlogList'] = dirname(__FILE__) . '/admin/lib.pager.php'; |
|---|
| 74 | $__autoload['adminUserList'] = dirname(__FILE__) . '/admin/lib.pager.php'; |
|---|
| 75 | $__autoload['dcPager'] = dirname(__FILE__) . '/admin/lib.pager.php'; |
|---|
| 76 | $__autoload['dcAdminCombos'] = dirname(__FILE__) . '/admin/lib.admincombos.php'; |
|---|
| 77 | $__autoload['adminModulesList'] = dirname(__FILE__) . '/admin/lib.moduleslist.php'; |
|---|
| 78 | $__autoload['adminThemesList'] = dirname(__FILE__) . '/admin/lib.moduleslist.php'; |
|---|
| 79 | $__autoload['dcThemeConfig'] = dirname(__FILE__) . '/admin/lib.themeconfig.php'; |
|---|
| 80 | $__autoload['dcAdminURL'] = dirname(__FILE__) . '/admin/lib.dc.adminurl.php'; |
|---|
| 81 | $__autoload['dcPostsActionsPage'] = dirname(__FILE__) . '/admin/actions/class.dcactionposts.php'; |
|---|
| 82 | $__autoload['dcCommentsActionsPage'] = dirname(__FILE__) . '/admin/actions/class.dcactioncomments.php'; |
|---|
| 83 | $__autoload['dcBlogsActionsPage'] = dirname(__FILE__) . '/admin/actions/class.dcactionblogs.php'; |
|---|
| 84 | $__autoload['dcActionsPage'] = dirname(__FILE__) . '/admin/actions/class.dcaction.php'; |
|---|
| 85 | |
|---|
| 86 | $__autoload['dcTemplate'] = dirname(__FILE__) . '/public/class.dc.template.php'; |
|---|
| 87 | $__autoload['context'] = dirname(__FILE__) . '/public/lib.tpl.context.php'; |
|---|
| 88 | $__autoload['dcUrlHandlers'] = dirname(__FILE__) . '/public/lib.urlhandlers.php'; |
|---|
| 89 | |
|---|
| 90 | # Clearbricks extensions |
|---|
| 91 | html::$absolute_regs[] = '/(<param\s+name="movie"\s+value=")(.*?)(")/msu'; |
|---|
| 92 | html::$absolute_regs[] = '/(<param\s+name="FlashVars"\s+value=".*?(?:mp3|flv)=)(.*?)(&|")/msu'; |
|---|
| 93 | /* ------------------------------------------------------------------------------------------- */ |
|---|
| 94 | |
|---|
| 95 | mb_internal_encoding('UTF-8'); |
|---|
| 96 | |
|---|
| 97 | # Setting timezone |
|---|
| 98 | dt::setTZ('UTC'); |
|---|
| 99 | |
|---|
| 100 | # CLI_MODE, boolean constant that tell if we are in CLI mode |
|---|
| 101 | define('CLI_MODE', PHP_SAPI == 'cli'); |
|---|
| 102 | |
|---|
| 103 | # Disallow every special wrapper |
|---|
| 104 | if (function_exists('stream_wrapper_unregister')) { |
|---|
| 105 | $special_wrappers = array_intersect(['http', 'https', 'ftp', 'ftps', 'ssh2.shell', 'ssh2.exec', |
|---|
| 106 | 'ssh2.tunnel', 'ssh2.sftp', 'ssh2.scp', 'ogg', 'expect', 'phar'], stream_get_wrappers()); |
|---|
| 107 | foreach ($special_wrappers as $p) { |
|---|
| 108 | @stream_wrapper_unregister($p); |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | if (isset($_SERVER['DC_RC_PATH'])) { |
|---|
| 113 | define('DC_RC_PATH', $_SERVER['DC_RC_PATH']); |
|---|
| 114 | } elseif (isset($_SERVER['REDIRECT_DC_RC_PATH'])) { |
|---|
| 115 | define('DC_RC_PATH', $_SERVER['REDIRECT_DC_RC_PATH']); |
|---|
| 116 | } else { |
|---|
| 117 | define('DC_RC_PATH', dirname(__FILE__) . '/config.php'); |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | if (!is_file(DC_RC_PATH)) { |
|---|
| 121 | if (strpos($_SERVER['SCRIPT_FILENAME'], '/admin') === false) { |
|---|
| 122 | $path = 'admin/install/wizard.php'; |
|---|
| 123 | } else { |
|---|
| 124 | $path = strpos($_SERVER['PHP_SELF'], '/install') === false ? 'install/wizard.php' : 'wizard.php'; |
|---|
| 125 | } |
|---|
| 126 | http::redirect($path); |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | require DC_RC_PATH; |
|---|
| 130 | |
|---|
| 131 | //*== DC_DEBUG == |
|---|
| 132 | if (!defined('DC_DEBUG')) { |
|---|
| 133 | define('DC_DEBUG', true); |
|---|
| 134 | } |
|---|
| 135 | if (DC_DEBUG) { |
|---|
| 136 | ini_set('display_errors', true); |
|---|
| 137 | error_reporting(E_ALL | E_STRICT); |
|---|
| 138 | } |
|---|
| 139 | //*/ |
|---|
| 140 | |
|---|
| 141 | if (!defined('DC_DEBUG')) { |
|---|
| 142 | define('DC_DEBUG', false); |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | # Constants |
|---|
| 146 | define('DC_ROOT', path::real(dirname(__FILE__) . '/..')); |
|---|
| 147 | define('DC_VERSION', '2.15-dev'); |
|---|
| 148 | define('DC_DIGESTS', dirname(__FILE__) . '/digests'); |
|---|
| 149 | define('DC_L10N_ROOT', dirname(__FILE__) . '/../locales'); |
|---|
| 150 | define('DC_L10N_UPDATE_URL', 'http://services.dotclear.net/dc2.l10n/?version=%s'); |
|---|
| 151 | define('DC_DISTRIB_PLUGINS', 'aboutConfig,akismet,antispam,attachments,blogroll,blowupConfig,dclegacy,fairTrackbacks,importExport,maintenance,pages,pings,simpleMenu,tags,themeEditor,userPref,widgets,dcLegacyEditor,dcCKEditor,breadcrumb'); |
|---|
| 152 | define('DC_DISTRIB_THEMES', 'berlin,blueSilence,blowupConfig,customCSS,default,ductile'); |
|---|
| 153 | define('DC_DEFAULT_TPLSET', 'mustek'); |
|---|
| 154 | define('DC_DEFAULT_JQUERY', '2.2.4'); |
|---|
| 155 | |
|---|
| 156 | if (!defined('DC_NEXT_REQUIRED_PHP')) { |
|---|
| 157 | define('DC_NEXT_REQUIRED_PHP', '5.6'); |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | if (!defined('DC_VENDOR_NAME')) { |
|---|
| 161 | define('DC_VENDOR_NAME', 'Dotclear'); |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | if (!defined('DC_XMLRPC_URL')) { |
|---|
| 165 | define('DC_XMLRPC_URL', '%1$sxmlrpc/%2$s'); |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | if (!defined('DC_SESSION_TTL')) { |
|---|
| 169 | define('DC_SESSION_TTL', null); |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | if (!defined('DC_ADMIN_SSL')) { |
|---|
| 173 | define('DC_ADMIN_SSL', false); |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | if (defined('DC_FORCE_SCHEME_443') && DC_FORCE_SCHEME_443) { |
|---|
| 177 | http::$https_scheme_on_443 = true; |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | if (!defined('DC_DBPERSIST')) { |
|---|
| 181 | define('DC_DBPERSIST', false); |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | if (!defined('DC_UPDATE_URL')) { |
|---|
| 185 | define('DC_UPDATE_URL', 'http://download.dotclear.org/versions.xml'); |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | if (!defined('DC_UPDATE_VERSION')) { |
|---|
| 189 | define('DC_UPDATE_VERSION', 'stable'); |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | if (!defined('DC_NOT_UPDATE')) { |
|---|
| 193 | define('DC_NOT_UPDATE', false); |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | if (!defined('DC_ALLOW_MULTI_MODULES')) { |
|---|
| 197 | define('DC_ALLOW_MULTI_MODULES', false); |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | if (!defined('DC_CRYPT_ALGO')) { |
|---|
| 201 | define('DC_CRYPT_ALGO', 'sha1'); // As in Dotclear 2.9 and previous |
|---|
| 202 | } else { |
|---|
| 203 | // Check length of cryptographic algorithm result and exit if less than 40 characters long |
|---|
| 204 | if (strlen(crypt::hmac(DC_MASTER_KEY, DC_VENDOR_NAME, DC_CRYPT_ALGO)) < 40) { |
|---|
| 205 | if (!defined('DC_CONTEXT_ADMIN')) { |
|---|
| 206 | __error('Server error', 'Site temporarily unavailable'); |
|---|
| 207 | } else { |
|---|
| 208 | __error('Dotclear error', DC_CRYPT_ALGO . ' cryptographic algorithm configured is not strong enough, please change it.'); |
|---|
| 209 | } |
|---|
| 210 | exit; |
|---|
| 211 | } |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | if (!defined('DC_VAR')) { |
|---|
| 215 | define('DC_VAR', path::real(dirname(__FILE__) . '/..') . '/var'); |
|---|
| 216 | } |
|---|
| 217 | // Check existence of var directory |
|---|
| 218 | if (!is_dir(DC_VAR)) { |
|---|
| 219 | // Try to create it |
|---|
| 220 | @files::makeDir(DC_VAR); |
|---|
| 221 | if (!is_dir(DC_VAR)) { |
|---|
| 222 | // Admin must create it |
|---|
| 223 | if (!defined('DC_CONTEXT_ADMIN')) { |
|---|
| 224 | __error('Server error', 'Site temporarily unavailable'); |
|---|
| 225 | } else { |
|---|
| 226 | __error('Dotclear error', DC_VAR . ' directory does not exist. Please create it.'); |
|---|
| 227 | } |
|---|
| 228 | exit; |
|---|
| 229 | } |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | l10n::init(); |
|---|
| 233 | |
|---|
| 234 | try { |
|---|
| 235 | $core = new dcCore(DC_DBDRIVER, DC_DBHOST, DC_DBNAME, DC_DBUSER, DC_DBPASSWORD, DC_DBPREFIX, DC_DBPERSIST); |
|---|
| 236 | } catch (Exception $e) { |
|---|
| 237 | init_prepend_l10n(); |
|---|
| 238 | if (!defined('DC_CONTEXT_ADMIN')) { |
|---|
| 239 | __error(__('Site temporarily unavailable'), |
|---|
| 240 | __('<p>We apologize for this temporary unavailability.<br />' . |
|---|
| 241 | 'Thank you for your understanding.</p>'), |
|---|
| 242 | 20); |
|---|
| 243 | } else { |
|---|
| 244 | __error(__('Unable to connect to database') |
|---|
| 245 | , $e->getCode() == 0 ? |
|---|
| 246 | sprintf(__('<p>This either means that the username and password information in ' . |
|---|
| 247 | 'your <strong>config.php</strong> file is incorrect or we can\'t contact ' . |
|---|
| 248 | 'the database server at "<em>%s</em>". This could mean your ' . |
|---|
| 249 | 'host\'s database server is down.</p> ' . |
|---|
| 250 | '<ul><li>Are you sure you have the correct username and password?</li>' . |
|---|
| 251 | '<li>Are you sure that you have typed the correct hostname?</li>' . |
|---|
| 252 | '<li>Are you sure that the database server is running?</li></ul>' . |
|---|
| 253 | '<p>If you\'re unsure what these terms mean you should probably contact ' . |
|---|
| 254 | 'your host. If you still need help you can always visit the ' . |
|---|
| 255 | '<a href="http://forum.dotclear.net/">Dotclear Support Forums</a>.</p>') . |
|---|
| 256 | (DC_DEBUG ? |
|---|
| 257 | __('The following error was encountered while trying to read the database:') . '</p><ul><li>' . $e->getMessage() . '</li></ul>' : '') |
|---|
| 258 | , (DC_DBHOST != '' ? DC_DBHOST : 'localhost') |
|---|
| 259 | ) |
|---|
| 260 | : '' |
|---|
| 261 | , 20); |
|---|
| 262 | } |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | # If we have some __top_behaviors, we load them |
|---|
| 266 | if (isset($__top_behaviors) && is_array($__top_behaviors)) { |
|---|
| 267 | foreach ($__top_behaviors as $b) { |
|---|
| 268 | $core->addBehavior($b[0], $b[1]); |
|---|
| 269 | } |
|---|
| 270 | unset($b); |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | http::trimRequest(); |
|---|
| 274 | try { |
|---|
| 275 | http::unsetGlobals(); |
|---|
| 276 | } catch (Exception $e) { |
|---|
| 277 | header('Content-Type: text/plain'); |
|---|
| 278 | echo $e->getMessage(); |
|---|
| 279 | exit; |
|---|
| 280 | } |
|---|
| 281 | |
|---|
| 282 | $core->url->registerDefault(['dcUrlHandlers', 'home']); |
|---|
| 283 | $core->url->registerError(['dcUrlHandlers', 'default404']); |
|---|
| 284 | $core->url->register('lang', '', '^([a-zA-Z]{2}(?:-[a-z]{2})?(?:/page/[0-9]+)?)$', ['dcUrlHandlers', 'lang']); |
|---|
| 285 | $core->url->register('post', 'post', '^post/(.+)$', ['dcUrlHandlers', 'post']); |
|---|
| 286 | $core->url->register('preview', 'preview', '^preview/(.+)$', ['dcUrlHandlers', 'preview']); |
|---|
| 287 | $core->url->register('category', 'category', '^category/(.+)$', ['dcUrlHandlers', 'category']); |
|---|
| 288 | $core->url->register('archive', 'archive', '^archive(/.+)?$', ['dcUrlHandlers', 'archive']); |
|---|
| 289 | |
|---|
| 290 | $core->url->register('feed', 'feed', '^feed/(.+)$', ['dcUrlHandlers', 'feed']); |
|---|
| 291 | $core->url->register('trackback', 'trackback', '^trackback/(.+)$', ['dcUrlHandlers', 'trackback']); |
|---|
| 292 | $core->url->register('webmention', 'webmention', '^webmention(/.+)?$', ['dcUrlHandlers', 'webmention']); |
|---|
| 293 | $core->url->register('rsd', 'rsd', '^rsd$', ['dcUrlHandlers', 'rsd']); |
|---|
| 294 | $core->url->register('xmlrpc', 'xmlrpc', '^xmlrpc/(.+)$', ['dcUrlHandlers', 'xmlrpc']); |
|---|
| 295 | |
|---|
| 296 | // Should use dcAdminURL class, but only in admin -> to be moved to public/prepend.php and admin/prepend.php ? |
|---|
| 297 | $core->setPostType('post', 'post.php?id=%d', $core->url->getURLFor('post', '%s'), 'Posts'); |
|---|
| 298 | |
|---|
| 299 | # Store upload_max_filesize in bytes |
|---|
| 300 | $u_max_size = files::str2bytes(ini_get('upload_max_filesize')); |
|---|
| 301 | $p_max_size = files::str2bytes(ini_get('post_max_size')); |
|---|
| 302 | if ($p_max_size < $u_max_size) { |
|---|
| 303 | $u_max_size = $p_max_size; |
|---|
| 304 | } |
|---|
| 305 | define('DC_MAX_UPLOAD_SIZE', $u_max_size); |
|---|
| 306 | unset($u_max_size);unset($p_max_size); |
|---|
| 307 | |
|---|
| 308 | # Register supplemental mime types |
|---|
| 309 | files::registerMimeTypes([ |
|---|
| 310 | // Audio |
|---|
| 311 | 'aac' => 'audio/aac', |
|---|
| 312 | 'ogg' => 'audio/ogg', |
|---|
| 313 | 'weba' => 'audio/webm', |
|---|
| 314 | 'm4a' => 'audio/mp4', |
|---|
| 315 | // Video |
|---|
| 316 | 'mp4' => 'video/mp4', |
|---|
| 317 | 'm4p' => 'video/mp4', |
|---|
| 318 | 'webm' => 'video/webm' |
|---|
| 319 | ]); |
|---|
| 320 | |
|---|
| 321 | # Shutdown |
|---|
| 322 | register_shutdown_function('__shutdown'); |
|---|
| 323 | |
|---|
| 324 | function __shutdown() |
|---|
| 325 | { |
|---|
| 326 | global $__shutdown; |
|---|
| 327 | if (is_array($__shutdown)) { |
|---|
| 328 | foreach ($__shutdown as $f) { |
|---|
| 329 | if (is_callable($f)) { |
|---|
| 330 | call_user_func($f); |
|---|
| 331 | } |
|---|
| 332 | } |
|---|
| 333 | } |
|---|
| 334 | # Explicitly close session before DB connection |
|---|
| 335 | try { |
|---|
| 336 | if (session_id()) { |
|---|
| 337 | session_write_close(); |
|---|
| 338 | } |
|---|
| 339 | } catch (Exception $e) {} |
|---|
| 340 | $GLOBALS['core']->con->close(); |
|---|
| 341 | } |
|---|
| 342 | |
|---|
| 343 | function __error($summary, $message, $code = 0) |
|---|
| 344 | { |
|---|
| 345 | # Error codes |
|---|
| 346 | # 10 : no config file |
|---|
| 347 | # 20 : database issue |
|---|
| 348 | # 30 : blog is not defined |
|---|
| 349 | # 40 : template files creation |
|---|
| 350 | # 50 : no default theme |
|---|
| 351 | # 60 : template processing error |
|---|
| 352 | # 70 : blog is offline |
|---|
| 353 | |
|---|
| 354 | if (CLI_MODE) { |
|---|
| 355 | trigger_error($summary, E_USER_ERROR); |
|---|
| 356 | exit(1); |
|---|
| 357 | } else { |
|---|
| 358 | if (defined('DC_ERRORFILE') && is_file(DC_ERRORFILE)) { |
|---|
| 359 | include DC_ERRORFILE; |
|---|
| 360 | } else { |
|---|
| 361 | include dirname(__FILE__) . '/core_error.php'; |
|---|
| 362 | } |
|---|
| 363 | exit; |
|---|
| 364 | } |
|---|
| 365 | } |
|---|
| 366 | |
|---|
| 367 | function init_prepend_l10n() |
|---|
| 368 | { |
|---|
| 369 | # Loading locales for detected language |
|---|
| 370 | $dlang = http::getAcceptLanguages(); |
|---|
| 371 | foreach ($dlang as $l) { |
|---|
| 372 | if ($l == 'en' || l10n::set(dirname(__FILE__) . '/../locales/' . $l . '/main') !== false) { |
|---|
| 373 | l10n::lang($l); |
|---|
| 374 | break; |
|---|
| 375 | } |
|---|
| 376 | } |
|---|
| 377 | } |
|---|