/** * Standard code module initialisation function. */ function init__database() { if (defined('DB_MAX_KEY_SIZE')) { return; } global $QUERY_LIST, $QUERY_COUNT, $NO_QUERY_LIMIT, $NO_DB_SCOPE_CHECK, $QUERY_FILE_LOG, $SITE_INFO; $QUERY_LIST = array(); $QUERY_COUNT = 0; $NO_QUERY_LIMIT = false; $NO_DB_SCOPE_CHECK = false; if ((!isset($SITE_INFO['no_extra_logs']) || $SITE_INFO['no_extra_logs'] == '0') && is_file(get_custom_file_base() . '/data_custom/queries.log')) { $QUERY_FILE_LOG = fopen(get_custom_file_base() . '/data_custom/queries.log', 'at'); } else { $QUERY_FILE_LOG = NULL; } // This will be generalised some-time require_code('database/' . get_db_type()); $GLOBALS['DB_STATIC_OBJECT'] = object_factory('Database_Static_' . get_db_type()); // Create our main database objects global $TABLE_LANG_FIELDS; $TABLE_LANG_FIELDS = array(); if (array_key_exists('db_site', $SITE_INFO) || array_key_exists('db_site_user', $SITE_INFO)) { $GLOBALS['SITE_DB'] = new database_driver(get_db_site(), get_db_site_host(), get_db_site_user(), get_db_site_password(), get_table_prefix()); } // Limits (we also limit field names to not conflict with keywords - those defined in database_action.php) define('DB_MAX_KEY_SIZE', 500); define('DB_MAX_PRIMARY_KEY_SIZE', 251); define('DB_MAX_ROW_SIZE', 8000); define('DB_MAX_FIELD_IDENTIFIER_SIZE', 31); define('DB_MAX_IDENTIFIER_SIZE', 32); // We have to take into account that chars might take 3 bytes - but we'll assume unicode is only used on db's with higher limits define('DB_MAX_KEY_SIZE_UNICODE', 1000); define('DB_MAX_ROW_SIZE_UNICODE', 24000); global $UPON_QUERY_HOOKS; $UPON_QUERY_HOOKS = NULL; }
/** * Standard code module initialisation function. */ function init__users() { global $MEMBERS_BLOCKED, $MEMBERS_BLOCKING_US; $MEMBERS_BLOCKED = NULL; $MEMBERS_BLOCKING_US = NULL; global $SESSION_CACHE, $MEMBER_CACHED, $ADMIN_GROUP_CACHE, $MODERATOR_GROUP_CACHE, $USERGROUP_LIST_CACHE; global $USER_NAME_CACHE, $MEMBER_EMAIL_CACHE, $USERS_GROUPS_CACHE; global $SESSION_CONFIRMED, $GETTING_MEMBER, $EMOTICON_CACHE, $CACHED_THEME, $EMOTICON_LEVELS, $EMOTICON_SET_DIR; $EMOTICON_LEVELS = NULL; $USER_NAME_CACHE = array(); $MEMBER_EMAIL_CACHE = array(); $USERGROUP_LIST_CACHE = NULL; $USERS_GROUPS_CACHE = array(); $ADMIN_GROUP_CACHE = NULL; $MODERATOR_GROUP_CACHE = NULL; $MEMBER_CACHED = NULL; $SESSION_CONFIRMED = 0; $GETTING_MEMBER = false; $EMOTICON_CACHE = NULL; $CACHED_THEME = NULL; $EMOTICON_SET_DIR = NULL; global $IS_ACTUALLY_ADMIN; $IS_ACTUALLY_ADMIN = false; global $IS_A_COOKIE_LOGIN; $IS_A_COOKIE_LOGIN = false; // Load all sessions into memory, if possible if (get_value('session_prudence') !== '1') { $SESSION_CACHE = persistant_cache_get('SESSION_CACHE'); } else { $SESSION_CACHE = NULL; } global $IN_MINIKERNEL_VERSION; if (!is_array($SESSION_CACHE) && $IN_MINIKERNEL_VERSION == 0) { if (get_value('session_prudence') !== '1') { $where = ''; } else { $where = ' WHERE the_session=' . strval(get_session_id()) . ' OR ' . db_string_equal_to('ip', get_ip_address()); } $SESSION_CACHE = array(); if (get_forum_type() == 'ocf' && get_db_site() == get_db_forums() && get_db_site_host() == get_db_forums_host()) { $GLOBALS['NO_DB_SCOPE_CHECK'] = true; $_s = $GLOBALS['SITE_DB']->query('SELECT s.*,m.m_primary_group FROM ' . get_table_prefix() . 'sessions s LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'f_members m ON m.id=s.the_user' . $where); $SESSION_CACHE = list_to_map('the_session', $_s); $GLOBALS['NO_DB_SCOPE_CHECK'] = false; } else { $SESSION_CACHE = list_to_map('the_session', $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'sessions' . $where)); } if (get_value('session_prudence') !== '1') { persistant_cache_set('SESSION_CACHE', $SESSION_CACHE); } } // Canonicalise various disparities in how HTTP auth environment variables are set if (array_key_exists('REDIRECT_REMOTE_USER', $_SERVER)) { $_SERVER['PHP_AUTH_USER'] = preg_replace('#@.*$#', '', $_SERVER['REDIRECT_REMOTE_USER']); } if (array_key_exists('PHP_AUTH_USER', $_SERVER)) { $_SERVER['PHP_AUTH_USER'] = preg_replace('#@.*$#', '', $_SERVER['PHP_AUTH_USER']); } if (array_key_exists('REMOTE_USER', $_SERVER)) { $_SERVER['PHP_AUTH_USER'] = preg_replace('#@.*$#', '', $_SERVER['REMOTE_USER']); } }
/** * The actualiser to do an import. * * @return tempcode The UI */ function do_import() { $refresh_url = get_self_url(true, false, array('type' => 'import'), true); $refresh_time = either_param_integer('refresh_time', 15); // Shouldn't default, but reported on some systems to do so if (function_exists('set_time_limit')) { @set_time_limit($refresh_time); } header('Content-type: text/html; charset=' . get_charset()); @ini_set('log_errors', '0'); global $I_REFRESH_URL; $I_REFRESH_URL = $refresh_url; require_code('database_action'); $title = get_page_title('IMPORT'); $importer = get_param('importer'); require_code('hooks/modules/admin_import/' . filter_naughty_harsh($importer)); $object = object_factory('Hook_' . filter_naughty_harsh($importer)); // Get data $old_base_dir = either_param('old_base_dir'); if (method_exists($object, 'verify_base_path') && !$object->verify_base_path($old_base_dir)) { warn_exit(do_lang_tempcode('BAD_IMPORT_PATH', escape_html($old_base_dir))); } if (method_exists($object, 'probe_db_access')) { list($db_name, $db_user, $db_password, $db_table_prefix) = $object->probe_db_access(either_param('old_base_dir')); } else { $db_name = either_param('db_name'); $db_user = either_param('db_user'); $db_password = either_param('db_password'); $db_table_prefix = either_param('db_table_prefix'); } if ($db_name == get_db_site() && $importer == 'ocp_merge' && $db_table_prefix == $GLOBALS['SITE_DB']->get_table_prefix()) { warn_exit(do_lang_tempcode('IMPORT_SELF_NO')); } $import_source = is_null($db_name) ? NULL : new database_driver($db_name, get_db_site_host(), $db_user, $db_password, $db_table_prefix); // Some preliminary tests $happy = get_param_integer('happy', 0); if (method_exists($object, 'pre_import_tests') && $happy == 0) { $ui = $object->pre_import_tests($import_source, $db_table_prefix, $old_base_dir); if (!is_null($ui)) { return $ui; } } // Save data $GLOBALS['SITE_DB']->query_delete('import_session', array('imp_session' => get_session_id()), '', 1); $GLOBALS['SITE_DB']->query_insert('import_session', array('imp_hook' => '', 'imp_old_base_dir' => $old_base_dir, 'imp_db_name' => is_null($db_name) ? '' : $db_name, 'imp_db_user' => is_null($db_user) ? '' : $db_user, 'imp_db_table_prefix' => is_null($db_table_prefix) ? '' : $db_table_prefix, 'imp_refresh_time' => $refresh_time, 'imp_session' => get_session_id())); $info = $object->info(); $_import_list = $info['import']; $out = new ocp_tempcode(); $parts_done = collapse_2d_complexity('imp_id', 'imp_session', $GLOBALS['SITE_DB']->query_select('import_parts_done', array('imp_id', 'imp_session'), array('imp_session' => get_session_id()))); $import_last = '-1'; if (get_forum_type() != 'ocf') { require_code('forum/ocf'); $GLOBALS['OCF_DRIVER'] = new forum_driver_ocf(); $GLOBALS['OCF_DRIVER']->connection = $GLOBALS['SITE_DB']; $GLOBALS['OCF_DRIVER']->MEMBER_ROWS_CACHED = array(); } $_import_list[] = 'ocf_switch'; $all_skipped = true; $lang_array = array(); $hooks = find_all_hooks('modules', 'admin_import_types'); foreach (array_keys($hooks) as $hook) { require_code('hooks/modules/admin_import_types/' . filter_naughty_harsh($hook)); $_hook = object_factory('Hook_admin_import_types_' . filter_naughty_harsh($hook)); $lang_array += $_hook->run(); } foreach ($_import_list as $import) { $import_this = either_param_integer('import_' . $import, 0); if ($import_this == 1) { $dependency = NULL; if (array_key_exists('dependencies', $info) && array_key_exists($import, $info['dependencies'])) { foreach ($info['dependencies'][$import] as $_dependency) { if (!array_key_exists($_dependency, $parts_done) && isset($lang_array[$_dependency])) { $dependency = $_dependency; } } } if (is_null($dependency)) { if ($import == 'ocf_switch') { $out->attach($this->ocf_switch()); } else { $function_name = 'import_' . $import; ocf_over_local(); $func_output = call_user_func_array(array($object, $function_name), array($import_source, $db_table_prefix, $old_base_dir)); if (!is_null($func_output)) { $out->attach($func_output); } ocf_over_msn(); } $parts_done[$import] = get_session_id(); $import_last = $import; $all_skipped = false; $GLOBALS['SITE_DB']->query_delete('import_parts_done', array('imp_id' => $import, 'imp_session' => get_session_id()), '', 1); $GLOBALS['SITE_DB']->query_insert('import_parts_done', array('imp_id' => $import, 'imp_session' => get_session_id())); } else { $out->attach(do_template('IMPORT_MESSAGE', array('_GUID' => 'b2a853f5fb93beada51a3eb8fbd1575f', 'MESSAGE' => do_lang_tempcode('IMPORT_OF_SKIPPED', escape_html($import), escape_html($dependency))))); } } } if (!$all_skipped) { $lang_code = 'SUCCESS'; if (count($GLOBALS['ATTACHED_MESSAGES_RAW']) != 0) { $lang_code = 'SOME_ERRORS_OCCURRED'; } $out->attach(do_template('IMPORT_MESSAGE', array('_GUID' => '4c4860d021814ffd1df6e21e712c7b44', 'MESSAGE' => do_lang_tempcode($lang_code)))); } log_it('IMPORT'); // Quick and simple decacheing. No need to be smart about this. delete_value('ocf_member_count'); delete_value('ocf_topic_count'); delete_value('ocf_post_count'); breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('IMPORT')), array('_SELF:_SELF:session', do_lang_tempcode('IMPORT_SESSION')), array('_SELF:_SELF:hook:importer=' . $importer . ':session=' . get_param('session'), do_lang_tempcode('IMPORT')))); breadcrumb_set_self(do_lang_tempcode('START')); $back_url = build_url(array('page' => '_SELF', 'type' => 'hook', 'importer' => get_param('importer'), 'just' => $import_last), '_SELF'); $_GET['just'] = $import_last; return $this->choose_actions($out); }
/** * Upgrade shared installs. */ function upgrade_sharedinstall_sites() { global $CURRENT_SHARE_USER, $SITE_INFO, $TABLE_LANG_FIELDS; // Find sites $sites = array(); foreach (array_keys($SITE_INFO) as $key) { $matches = array(); if (preg_match('#^custom_user_(.*)#', $key, $matches) != 0) { $sites[] = $matches[1]; } } disable_php_memory_limit(); foreach ($sites as $i => $site) { if (function_exists('set_time_limit')) { @set_time_limit(0); } // Change active site $CURRENT_SHARE_USER = $site; $TABLE_LANG_FIELDS = array(); _general_db_init(); // Reset DB $GLOBALS['SITE_DB'] = new database_driver(get_db_site(), get_db_site_host(), get_db_site_user(), get_db_site_password(), get_table_prefix()); $GLOBALS['FORUM_DB'] = $GLOBALS['SITE_DB']; // NB: File path will be ok // NB: Other internal caching could need changing in the future, but works at time of writing // Go! automate_upgrade(); echo 'Upgraded ' . htmlentities($site) . '<br />'; flush(); } }
// Via addon_registry hooks (bundled ones) $files = array(); $files = array_merge($files, get_directory_contents($path, '', false, false)); if (file_exists(str_replace('/sources/', '/sources_custom/', $path))) { $files = array_merge($files, get_directory_contents(str_replace('/sources/', '/sources_custom/', $path), '', false, false)); } foreach ($files as $file) { if (substr($file, -4) == '.php') { $auto_probe[] = basename($file, '.php'); } } // Via addons table (non-bundled ones) global $SITE_INFO; $backup = $SITE_INFO; require_once $probe_dir . '/info.php'; $linked_db = new database_driver(get_db_site(), get_db_site_host(), get_db_site_user(), get_db_site_password(), get_table_prefix()); $auto_probe += collapse_1d_complexity('addon_name', $linked_db->query_select('addons', array('addon_name'))); $SITE_INFO = $backup; // Via filesystem (non-bundled ones) foreach ($addons['non_bundled'] as $addon => $files) { foreach ($files as $file) { if (file_exists($probe_dir . '/' . $file)) { $auto_probe[] = $addon; } } } $auto_probe = array_unique($auto_probe); // Find oldest modified file that has been modified since $cutoff_days = 0; $files = get_directory_contents($probe_dir); foreach ($files as $file) {