/** * The UI to choose what to import. * * @param mixed Output to show from last action (blank: none) * @return tempcode The UI */ function choose_actions($extra = '') { $title = get_page_title('IMPORT'); $session = either_param_integer('session', get_session_id()); $importer = filter_naughty(get_param('importer')); require_code('hooks/modules/admin_import/' . filter_naughty_harsh($importer)); $object = object_factory('Hook_' . filter_naughty_harsh($importer)); // Test import source is good 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); unset($import_source); $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(); } $info = $object->info(); $session_row = $GLOBALS['SITE_DB']->query_select('import_session', array('*'), array('imp_session' => get_session_id()), '', 1); if (array_key_exists(0, $session_row)) { $old_base_dir = $session_row[0]['imp_old_base_dir']; $db_name = $session_row[0]['imp_db_name']; $db_user = $session_row[0]['imp_db_user']; $db_table_prefix = $session_row[0]['imp_db_table_prefix']; $refresh_time = $session_row[0]['imp_refresh_time']; } else { $old_base_dir = get_file_base() . '/old'; $db_name = get_db_site(); $db_user = get_db_site_user(); $db_table_prefix = array_key_exists('prefix', $info) ? $info['prefix'] : $GLOBALS['SITE_DB']->get_table_prefix(); $refresh_time = 15; } $_import_list = $info['import']; $_import_list_2 = array(); foreach ($_import_list as $import) { if (is_null($import)) { continue; } if (!array_key_exists($import, $lang_array)) { continue; } if (is_null($lang_array[$import])) { continue; } $text = do_lang(strtolower($lang_array[$import]) != $lang_array[$import] ? $lang_array[$import] : strtoupper($lang_array[$import])); $_import_list_2[$import] = $text; } if (array_key_exists('ocf_members', $_import_list_2) && get_forum_type() == $importer && $db_name == get_db_forums() && $db_table_prefix == $GLOBALS['FORUM_DB']->get_table_prefix()) { $_import_list_2['ocf_switch'] = do_lang_tempcode('SWITCH_TO_OCF'); } $import_list = new ocp_tempcode(); // asort($_import_list_2); Let's preserve order here $just = get_param('just', NULL); $first = true; $skip_hidden = array(); $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()))); foreach ($_import_list_2 as $import => $text) { if (array_key_exists($import, $parts_done)) { $import_list->attach(do_template('IMPORT_ACTION_LINE', array('CHECKED' => false, 'DISABLED' => true, 'NAME' => 'import_' . $import, 'TEXT' => $text, 'ADVANCED_URL' => $info['supports_advanced_import'] ? build_url(array('page' => '_SELF', 'type' => 'advanced_hook', 'session' => $session, 'content_type' => $import, 'importer' => $importer), '_SELF') : new ocp_tempcode()))); } else { $checked = is_null($just) && $first; $import_list->attach(do_template('IMPORT_ACTION_LINE', array('_GUID' => 'f2215115f920200a0a1ba6bc776ad945', 'CHECKED' => $checked, 'NAME' => 'import_' . $import, 'TEXT' => $text, 'ADVANCED_URL' => $info['supports_advanced_import'] ? build_url(array('page' => '_SELF', 'type' => 'advanced_hook', 'session' => $session, 'content_type' => $import, 'importer' => $importer), '_SELF') : new ocp_tempcode()))); } if ($just == $import) { $first = true; $just = NULL; } else { $first = false; } $skip_hidden[] = 'import_' . $import; } $message = array_key_exists('message', $info) ? $info['message'] : ''; if (count($parts_done) == count($_import_list_2)) { inform_exit(do_lang_tempcode($message === '' ? '_IMPORT_ALL_FINISHED' : 'IMPORT_ALL_FINISHED', $message)); } $url = build_url(array('page' => '_SELF', 'type' => 'import', 'session' => $session, 'importer' => $importer), '_SELF'); breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('IMPORT')), array('_SELF:_SELF:session:importer=' . $importer, do_lang_tempcode('IMPORT_SESSION')))); $hidden = new ocp_tempcode(); $hidden->attach(build_keep_post_fields($skip_hidden)); $hidden->attach(build_keep_form_fields('', true)); return do_template('IMPORT_ACTION_SCREEN', array('_GUID' => 'a3a69637e541923ad76e9e7e6ec7e1af', 'EXTRA' => $extra, 'MESSAGE' => $message, 'TITLE' => $title, 'FIELDS' => '', 'HIDDEN' => $hidden, 'IMPORTER' => $importer, 'IMPORT_LIST' => $import_list, 'URL' => $url)); }
/** * Get the forum database username. * * @return string The forum database username */ function get_db_forums_user() { global $SITE_INFO; if (!array_key_exists('db_forums_user', $SITE_INFO)) { return get_db_site_user(); } if ($GLOBALS['CURRENT_SHARE_USER'] !== NULL) { return substr(md5($SITE_INFO['db_forums_user'] . '_' . $GLOBALS['CURRENT_SHARE_USER']), 0, 16); } return $SITE_INFO['db_forums_user']; }
/** * 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) {