/** * Method to init the framework * @param string $access [optional default null] : Restrict access with an access string. See manual for syntax. Eg. 4|-testgroup|+u:testuser|-uid:4|+gid:20 * @param string $section [optional default null] : Set a section ID */ public static function init($access = null, $section = null) { /** * Timestamp */ BF::$time = time(); /** * Absolute path to framework */ BF::$path_to_framework = strtr(dirname(__FILE__), "\\", "/"); if (BF::$path_to_framework[strlen(BF::$path_to_framework) - 1] != '/') { BF::$path_to_framework .= '/'; } /** * CONFIGURATION */ $_conf =& BF::$conf; if (@(include BF::$path_to_framework . BF_RELATIVE_PATH_TO_CONFIG) === false) { die('<h3>Framework failed loading config file.</h3>Please inform webmaster<br/><br/>Webmaster, make sure <i>config.php</i> exists in the <i>Framework</i> folder and has the right permissions set. Otherwise use <i>Admin Console</i> to regenerate. Refer to doc for more info.'); } /** * Absolute path to website root (server side) */ BF::$path_to_root = substr(BF::gc('path_to_root'), 0, 1) == '/' ? BF::gc('path_to_root') : BF::$path_to_framework . BF::gc('path_to_root'); /* * Set propoer PHP_SELF */ $self = $_SERVER['PHP_SELF']; if (strpos($_SERVER['PHP_SELF'], ':') !== false) { $self = trim(substr($self, strrpos($self, ':'))); } /** * Detect base URL if not manually set in config * Detection need urlrewrite to be on and .htaccess file to be processed */ BF::$path_info = isset($_SERVER['ORIG_PATH_INFO']) ? $_SERVER['ORIG_PATH_INFO'] : (isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : ''); if (!BF::gc("auto_detect_base_url")) { BF::$base_url = BF::gc("base_url"); } else { $self = $_SERVER['PHP_SELF']; if (BF::$path_info) { if (substr($self, -strlen(BF::$path_info)) == BF::$path_info) { $self = substr($self, 0, -strlen(BF::$path_info)); } else { die("<h3>Failed detecting base url</h3>Please make sure your webserver gives proper values for PATH_INFO and PHP_SELF. You can also set this manually in the <i>Admin Console</i>"); } } BF::$base_url = substr($self, 0, strrpos($self, '/') + 1); } /** * Detect /-separated parameters */ if (strlen(BF::$path_info) >= 1 && BF::$path_info[0] == '/') { BF::$path_info_array = explode('/', substr(BF::$path_info, 1)); } // to remove /* if (!BF::gc("auto_detect_base_url")) BF::$base_url = BF::gc("base_url"); elseif ( isset($_SERVER['PHP_SELF']) && isset($_SERVER['RELATIVE_FROM_ROOT'])) { $relative = $_SERVER['RELATIVE_FROM_ROOT']; if ($relative == '') { BF::$base_url = substr($self, 0, strrpos($self, '/')+1); } else { if (substr($self, -strlen($relative)) == $relative ) { BF::$base_url = substr($self, 0, -strlen($relative)); } else { // try adding the index.php if ends with a / if ($relative[strlen($relative)-1] == '/') $relative .= 'index.php'; if (substr($self, -strlen($relative)) == $relative ) { BF::$base_url = substr($self, 0, -strlen($relative)); } else { die ("<h3>Failed detecting base url</h3>Please contact webmaster.<br><br>Webmaster, urlrewrite is on and .htaccess gets parsed, but the data is incorrect. Depending on server configuration you may need to set this manually in the <i>Admin Console</i>"); } } } // if using URL locale, do one more test if (BF::gc('locale_enabled') && BF::gc('locale_use_url')) { $base = BF::$base_url.(isset($_GET['detected_locale'])? $_GET['detected_locale'].'/':''); if (substr($_SERVER['REQUEST_URI'], 0, strlen($base)) != $base) die ("<h3>Improper base url detected/given in config</h3>Please contact webmaster.<br><br>Webmaster, you are using URL to transmit locale, make sure urlrewrite is on and the right .htaccess file gets parsed. Beginning of REQUEST_URI mismatch base url."); } } else { die ("<h3>Failed detecting base url</h3>Please contact webmaster.<br><br>Webmaster, make sure urlrewrite is on and the right .htaccess file gets parsed. Depending on server configuration you may need to set this manually in the <i>Admin Console</i>"); } */ /** * TIMEZONE */ if (function_exists('date_default_timezone_set')) { date_default_timezone_set(BF::gc('time_default_zone')); } /** * ERRORS HANDLING */ // Set error reporting level error_reporting(BF::gc('error_reporting')); // set default exception handler set_exception_handler(array('BF', 'exception_handler')); // set the user defined error handler set_error_handler(array('BF', 'error_handler')); /** * Encoding */ BF::$encoding = BF::gc('encoding'); /** * Session */ if (session_id() == '') { session_start(); } /** * Quoting function */ BF::load_module('q'); // // if we need to keep track of activity time // //if (BF::gc('user_inactivity_time') != 0 && isset($_SESSION['BF_'.BF::gc('project_id').'_activity_time']) && $_SESSION['BF_'.BF::gc('project_id').'_activity_time'] > BF::$time - 3600*BF::gc('user_inactivity_time')) $_SESSION['BF_'.BF::gc('project_id').'_activity_time'] = BF::$time; /** * Clear all slashes added by magic_quote */ if (get_magic_quotes_gpc()) { function BF_stripslashes_deep($value) { return is_array($value) ? array_map('BF_stripslashes_deep', $value) : stripslashes($value); } $_POST = array_map('BF_stripslashes_deep', $_POST); $_GET = array_map('BF_stripslashes_deep', $_GET); $_COOKIE = array_map('BF_stripslashes_deep', $_COOKIE); $_REQUEST = array_map('BF_stripslashes_deep', $_REQUEST); } /** * Load project specific file */ if (BF::gc('general_file_to_load')) { BF::gr(BF::gc('general_file_to_load'))->load(); } /** * ACCESS CHECK */ if ($access !== null && !BF::ga($access)) { throw new BF_forbidden(); } }