Exemplo n.º 1
0
Arquivo: vb.php Projeto: Kheros/MMOver
 /**
  * Initializes the vB framework.
  * All framework level objects and services are created so that they are available
  * throughout the application.  This is only done once per actual request.
  *
  * Note: If the framework is used this way then there are several limitations.
  *  - If no vB_Bootstrap was created (ie, the admincp), then you cannot render any
  *    views created by the framework.
  *  - VB_ENTRY must be defined to a valid request script that runs the framework
  *    with vB::Main()
  *  - If you are rendering views, try to create all of the views that will be
  *    used before rendering any of them.  This optimises template and phrase
  *    fetching.
  */
 public static function init($relative_path = false)
 {
     global $vbulletin, $vbphrase;
     if (self::$initialized) {
         return;
     }
     // Reference legacy registry
     self::$vbulletin = $vbulletin;
     // Legacy DB
     self::$db = $vbulletin->db;
     // Set a top level exception handler
     set_exception_handler(array('vB', 'handleException'));
     // Set unserializer to use spl registered autoloader
     ini_set('unserialize_callback_func', 'spl_autoload_call');
     // Set class autoloader
     spl_autoload_register(array('vB', 'autoload'));
     // Legacy language
     vB_Phrase::setLanguage(!empty(self::$vbulletin->session->vars['languageid']) ? self::$vbulletin->session->vars['languageid'] : intval(self::$vbulletin->options['languageid']));
     vB_Phrase::preCache($vbphrase, $GLOBALS['phrasegroups']);
     // Ensure we have friendly url class
     require_once DIR . '/includes/class_friendly_url.php';
     if ($relative_path) {
         vB_Router::setRelativePath($relative_path);
     }
     // Done
     self::$initialized = true;
 }
Exemplo n.º 2
0
 /**
  * Initializes the vB framework.
  * All framework level objects and services are created so that they are available
  * throughout the application.  This is only done once per actual request.
  *
  * Note: If the framework is used this way then there are several limitations.
  *  - If no vB_Bootstrap was created (ie, the admincp), then you cannot render any
  *    views created by the framework.
  *  - VB_ENTRY must be defined to a valid request script that runs the framework
  *    with vB::Main()
  *  - If you are rendering views, try to create all of the views that will be
  *    used before rendering any of them.  This optimises template and phrase
  *    fetching.
  */
 public static function init($relative_path = false)
 {
     if (self::$initialized) {
         return;
     }
     /**
      *	Set a bunch of constants.
      */
     //We were getting CWD defined as something like '<install location>/vb5/..'
     //This causes problems when uploading a default avatar, where we need to parse the path
     //. It's much easier to decode if the path is just <install location>
     if (!defined('CWD')) {
         if (is_link(dirname($_SERVER["SCRIPT_FILENAME"]))) {
             $cwd = dirname($_SERVER["SCRIPT_FILENAME"]) . DIRECTORY_SEPARATOR . 'core';
         } else {
             $cwd = dirname(__FILE__);
         }
         if (($pos = strrpos($cwd, DIRECTORY_SEPARATOR)) === false) {
             //we can't figure this out.
             define('CWD', dirname(__FILE__) . DIRECTORY_SEPARATOR . '..');
         } else {
             define('CWD', substr($cwd, 0, $pos));
         }
     }
     if (!defined('DIR')) {
         define('DIR', CWD);
     }
     if (!defined('VB_PATH')) {
         define('VB_PATH', DIR . '/vb/');
     }
     if (!defined('VB5_PATH')) {
         define('VB5_PATH', DIR . '/vb5/');
     }
     if (!defined('VB_PKG_PATH')) {
         define('VB_PKG_PATH', realpath(VB_PATH . '../packages') . '/');
     }
     if (!defined('VB_ENTRY')) {
         define('VB_ENTRY', 1);
     }
     if (!defined('SIMPLE_VERSION')) {
         define('SIMPLE_VERSION', '519');
     }
     /***
      *	Clean up the php environment
      */
     if (isset($_REQUEST['GLOBALS']) or isset($_FILES['GLOBALS'])) {
         echo 'Request tainting attempted.';
         exit(4);
     }
     @ini_set('pcre.backtrack_limit', -1);
     /* The min requirement for vB5 is 5.3.0,
        so version checking here isnt necessary */
     @date_default_timezone_set(date_default_timezone_get());
     // Disabling magic quotes at runtime
     // Code copied from PHP Manual: http://www.php.net/manual/en/security.magicquotes.disabling.php
     if (get_magic_quotes_gpc()) {
         $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
         while (list($key, $val) = each($process)) {
             foreach ($val as $k => $v) {
                 unset($process[$key][$k]);
                 if (is_array($v)) {
                     $process[$key][stripslashes($k)] = $v;
                     $process[] =& $process[$key][stripslashes($k)];
                 } else {
                     $process[$key][stripslashes($k)] = stripslashes($v);
                 }
             }
         }
         unset($process);
     }
     // overwrite GET[x] and REQUEST[x] with POST[x] if it exists (overrides server's GPC order preference)
     if (isset($_SERVER['REQUEST_METHOD']) and $_SERVER['REQUEST_METHOD'] == 'POST') {
         foreach (array_keys($_POST) as $key) {
             if (isset($_GET["{$key}"])) {
                 $_GET["{$key}"] = $_REQUEST["{$key}"] = $_POST["{$key}"];
             }
         }
     }
     // deal with cookies that may conflict with _GET and _POST data, and create our own _REQUEST with no _COOKIE input
     foreach (array_keys($_COOKIE) as $varname) {
         unset($_REQUEST["{$varname}"]);
         if (isset($_POST["{$varname}"])) {
             $_REQUEST["{$varname}"] =& $_POST["{$varname}"];
         } else {
             if (isset($_GET["{$varname}"])) {
                 $_REQUEST["{$varname}"] =& $_GET["{$varname}"];
             }
         }
     }
     /***
      *	Register Callback functions
      */
     //we want to have an exception handler defined (the default handler has bad habit of
     //leaking information that shouldn't be leaked), but we don't want to override any frontend handler,
     //that might be set.  PHP doesn't allow us to check the current handler, but we can change it and
     //then change it back if we don't like the result.
     if (null !== set_exception_handler(array('vB', 'handleException'))) {
         restore_exception_handler();
     }
     if (null !== set_error_handler(array('vB', 'handleError'))) {
         restore_error_handler();
     }
     // Set unserializer to use spl registered autoloader
     ini_set('unserialize_callback_func', 'spl_autoload_call');
     // Set class autoloader
     spl_autoload_register(array('vB', 'autoload'));
     // Set shutdown function
     register_shutdown_function(array('vB', 'shutdown'));
     // Done
     self::$initialized = true;
 }