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