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