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