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