/** * Find which special CPF's to enable. * * @return array A list of CPF's to enable */ function to_enable() { global $SITE_INFO; $cpf = array(); if ($SITE_INFO['forum_type'] != 'ocf' || get_db_forums() != get_db_site() || $GLOBALS['FORUM_DRIVER']->get_drivered_table_prefix() != get_table_prefix()) { $cpf['role'] = 1; if (get_option('signup_fullname') == '0') { $cpf['fullname'] = 1; } $cpf['sites'] = 1; } return $cpf; }
/** * Get all the image IDs (both already known, and those uncached) of a certain type (i.e. under a subdirectory). * * @param ID_TEXT The type of image (e.g. 'ocf_emoticons') * @param boolean Whether to search recursively; i.e. in subdirectories of the type subdirectory * @param ?object The database connection to work over (NULL: site db) * @param ?ID_TEXT The theme to search in, in addition to the default theme (NULL: current theme) * @param boolean Whether to only return directories (advanced option, rarely used) * @param boolean Whether to only return from the database (advanced option, rarely used) * @return array The list of image IDs */ function get_all_image_ids_type($type, $recurse = false, $db = NULL, $theme = NULL, $dirs_only = false, $db_only = false) { if (is_null($db)) { $db = $GLOBALS['SITE_DB']; } if (is_null($theme)) { $theme = $GLOBALS['FORUM_DRIVER']->get_theme(); } if (substr($type, 0, 4) == 'ocf_' && file_exists(get_file_base() . '/themes/default/images/avatars/index.html')) { $type = substr($type, 4); } if (substr($type, -1) == '/') { $type = substr($type, 0, strlen($type) - 1); } $ids = array(); if (!$db_only && ($db->connection_write == $GLOBALS['SITE_DB']->connection_write || $dirs_only || get_db_forums() == get_db_site())) { _get_all_image_ids_type($ids, get_file_base() . '/themes/default/images/' . ($type == '' ? '' : $type . '/'), $type, $recurse, $dirs_only); _get_all_image_ids_type($ids, get_file_base() . '/themes/default/images/' . get_site_default_lang() . '/' . ($type == '' ? '' : $type . '/'), $type, $recurse, $dirs_only); if ($theme != 'default') { _get_all_image_ids_type($ids, get_custom_file_base() . '/themes/' . $theme . '/images/' . ($type == '' ? '' : $type . '/'), $type, $recurse, $dirs_only); _get_all_image_ids_type($ids, get_custom_file_base() . '/themes/' . $theme . '/images/' . get_site_default_lang() . '/' . ($type == '' ? '' : $type . '/'), $type, $recurse, $dirs_only); } _get_all_image_ids_type($ids, get_file_base() . '/themes/default/images_custom/' . ($type == '' ? '' : $type . '/'), $type, $recurse, $dirs_only); _get_all_image_ids_type($ids, get_file_base() . '/themes/default/images_custom/' . get_site_default_lang() . '/' . ($type == '' ? '' : $type . '/'), $type, $recurse, $dirs_only); if ($theme != 'default') { _get_all_image_ids_type($ids, get_custom_file_base() . '/themes/' . $theme . '/images_custom/' . ($type == '' ? '' : $type . '/'), $type, $recurse, $dirs_only); _get_all_image_ids_type($ids, get_custom_file_base() . '/themes/' . $theme . '/images_custom/' . get_site_default_lang() . '/' . ($type == '' ? '' : $type . '/'), $type, $recurse, $dirs_only); } } if (!$dirs_only) { $query = 'SELECT DISTINCT id,path FROM ' . $db->get_table_prefix() . 'theme_images WHERE '; if (!$db_only) { $query .= 'path NOT LIKE \'' . db_encode_like('themes/default/images/%') . '\' AND ' . db_string_not_equal_to('path', 'themes/default/images/blank.gif') . ' AND '; } $query .= '(' . db_string_equal_to('theme', $theme) . ' OR ' . db_string_equal_to('theme', 'default') . ') AND id LIKE \'' . db_encode_like($type . '%') . '\' ORDER BY path'; $rows = $db->query($query); foreach ($rows as $row) { if ($row['path'] == '') { continue; } if (url_is_local($row['path']) && !file_exists((substr($row['path'], 0, 15) == 'themes/default/' ? get_file_base() : get_custom_file_base()) . '/' . rawurldecode($row['path']))) { continue; } if ($row['path'] != 'themes/default/images/blank.gif') { $ids[] = $row['id']; } else { $key = array_search($row['id'], $ids); if (is_integer($key)) { unset($ids[$key]); } } } } sort($ids); return array_unique($ids); }
/** * 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); }
/** * Load stuff that allows user code to work. */ function load_user_stuff() { if (!array_key_exists('FORUM_DRIVER', $GLOBALS) || $GLOBALS['FORUM_DRIVER'] === NULL) { global $SITE_INFO; require_code('forum_stub'); if (!array_key_exists('forum_type', $SITE_INFO)) { $SITE_INFO['forum_type'] = 'ocf'; } require_code('forum/' . $SITE_INFO['forum_type']); // So we can at least get user details $GLOBALS['FORUM_DRIVER'] = object_factory('forum_driver_' . filter_naughty_harsh($SITE_INFO['forum_type'])); if ($SITE_INFO['forum_type'] == 'ocf' && get_db_forums() == get_db_site() && $GLOBALS['FORUM_DRIVER']->get_drivered_table_prefix() == get_table_prefix() && !$GLOBALS['DEBUG_MODE']) { $GLOBALS['FORUM_DRIVER']->connection = $GLOBALS['SITE_DB']; } elseif ($SITE_INFO['forum_type'] != 'none') { $GLOBALS['FORUM_DRIVER']->connection = new database_driver(get_db_forums(), get_db_forums_host(), get_db_forums_user(), get_db_forums_password(), $GLOBALS['FORUM_DRIVER']->get_drivered_table_prefix()); } $GLOBALS['FORUM_DRIVER']->MEMBER_ROWS_CACHED = array(); $GLOBALS['FORUM_DB'] =& $GLOBALS['FORUM_DRIVER']->connection; } }
/** * 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(); } }
/** * Get the name of the forum database. * * @return string The forum database site */ function get_db_forums() { global $SITE_INFO; if (!array_key_exists('db_forums', $SITE_INFO)) { return get_db_site(); } return $SITE_INFO['db_forums'] . ($GLOBALS['CURRENT_SHARE_USER'] === NULL ? '' : '_' . $GLOBALS['CURRENT_SHARE_USER']); }
/** * Script to handle XML DB/MySQL chain synching. */ function xml_dump_script() { // Run checks and set up chain DB if (get_db_type() != 'xml') { warn_exit('It makes no sense to run this script if you are not running the XML database driver.'); } global $SITE_INFO; if (array_key_exists('db_chain_type', $SITE_INFO)) { require_code('database/' . $SITE_INFO['db_chain_type']); $chain_db = new database_driver($SITE_INFO['db_chain'], $SITE_INFO['db_chain_host'], $SITE_INFO['db_chain_user'], $SITE_INFO['db_chain_password'], get_table_prefix(), false, object_factory('Database_Static_' . $SITE_INFO['db_chain_type'])); } else { warn_exit('It makes no sense to run this script if you have not set up the following config options in info.php: db_chain_type, db_chain_host, db_chain_user, db_chain_password, db_chain'); } $chain_connection =& $chain_db->connection_write; if (count($chain_connection) > 4) { $chain_connection = call_user_func_array(array($chain_db->static_ob, 'db_get_connection'), $chain_connection); _general_db_init(); } if (function_exists('set_time_limit')) { @set_time_limit(0); } $GLOBALS['DEBUG_MODE'] = false; $GLOBALS['SEMI_DEBUG_MODE'] = false; @ini_set('ocproducts.xss_detect', '0'); if (strtolower(ocp_srv('REQUEST_METHOD')) == 'get') { $from = get_param('from', NULL); $skip = get_param('skip', NULL); $only = get_param('only', NULL); echo ' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>XML/MySQL DB syncher</title> </head> <body> '; echo '<p>Select the tables to sync below. Tables have been auto-ticked based on what seems to need re-synching.</p>'; $keep = symbol_tempcode('KEEP', array('1')); echo '<form title="Choose tables" method="post" action="' . escape_html(find_script('xml_db_import') . $keep->evaluate()) . '">'; $tables = array_keys(find_all_tables($GLOBALS['SITE_DB'])); $mysql_status = list_to_map('Name', $chain_db->query('SHOW TABLE STATUS')); $mysql_tables = array_keys($mysql_status); foreach ($tables as $table_name) { $default_selected = (!is_null($from) && $table_name >= $from || !is_null($only) && in_array($table_name, explode(',', $only))) && (!is_null($skip) || !in_array($table_name, explode(',', $skip))); $missing = !in_array(get_table_prefix() . $table_name, $mysql_tables); $count_mismatch = !$missing && $chain_db->query_value($table_name, 'COUNT(*)') != $GLOBALS['SITE_DB']->query_value($table_name, 'COUNT(*)'); $date_mismatch = false; if (!$missing && !$count_mismatch) { $last_m_time = NULL; $path = get_custom_file_base() . '/uploads/website_specific/' . get_db_site() . '/' . get_table_prefix() . $table_name; $dh = @opendir($path); if ($dh !== false) { while (($f = readdir($dh)) !== false) { if (substr($f, -4) == '.dat' || substr($f, -4) == '.xml') { $last_m_time = @max($last_m_time, filemtime($path . '/' . $f)); } // @ because of the 255 read filepath limit on Windows } closedir($dh); } if (!is_null($last_m_time)) { $mysql_time = strtotime($mysql_status[get_table_prefix() . $table_name]['Update_time']); $date_mismatch = $mysql_time < $last_m_time; // We can't do "!=" as last m-time for MySQL could well by the last sync time } } $needs_doing = $count_mismatch || $date_mismatch || $missing || $default_selected; echo ' <div style="width: 500px"> <span style="float: right; font-style: italic"> ' . ($missing ? '[table is missing]' : '') . ' ' . ($count_mismatch ? '[different record-counts]' : '') . ' ' . ($date_mismatch ? '[different last-modified-time]' : '') . ' </span> <input ' . ($needs_doing ? 'checked="checked" ' : '') . 'type="checkbox" name="table_' . htmlentities($table_name) . '" id="table_' . htmlentities($table_name) . '" value="1" /> <label for="table_' . htmlentities($table_name) . '">' . htmlentities($table_name) . '</label> </div> '; } echo '<p><input type="submit" value="Sync" /> [<a href="#" onclick="var form=document.getElementsByTagName(\'form\')[0]; for (var i=0;i<form.elements.length;i++) if (form.elements[i].checked) form.elements[i].checked=false; return false;">un-tick all</a>]</p>'; echo '</form>'; echo ' </body> </html> '; exit; } // Actualiser $from = NULL; $skip = NULL; $only = ''; foreach (array_keys($_POST) as $key) { if (substr($key, 0, 6) == 'table_') { if ($only != '') { $only .= ','; } $only .= substr($key, 6); } } if ($only == '') { $only = NULL; } @header('Content-type: text/plain'); @ob_end_clean(); $sql = get_sql_dump(true, true, $from, is_null($skip) ? array() : explode(',', $skip), is_null($only) ? NULL : explode(',', $only)); $cnt = count($sql); foreach ($sql as $i => $s) { print 'Executing query ' . strval($i + 1) . '/' . strval($cnt) . ' ... ' . $s . "\n\n"; flush(); $fail_ok = substr($s, 0, 5) == 'ALTER'; $chain_db->static_ob->db_query($s, $chain_connection, NULL, NULL, $fail_ok, false); } print '!!Done!!'; }
// 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) {