/** * Load a schema (and execute) * * @param string $install_path */ function load_schema($install_path = '', $install_dbms = false) { global $db; global $table_prefix; static $available_dbms = false; if ($install_dbms === false) { global $dbms; $install_dbms = $dbms; } if (!function_exists('get_available_dbms')) { global $phpbb_root_path, $phpEx; include $phpbb_root_path . 'includes/functions_install.' . $phpEx; } if (!$available_dbms) { $available_dbms = get_available_dbms($install_dbms); if ($install_dbms == 'mysql') { if (version_compare($db->mysql_version, '4.1.3', '>=')) { $available_dbms[$install_dbms]['SCHEMA'] .= '_41'; } else { $available_dbms[$install_dbms]['SCHEMA'] .= '_40'; } } } $remove_remarks = $available_dbms[$install_dbms]['COMMENTS']; $delimiter = $available_dbms[$install_dbms]['DELIM']; $dbms_schema = $install_path . $available_dbms[$install_dbms]['SCHEMA'] . '_schema.sql'; if (file_exists($dbms_schema)) { $sql_query = @file_get_contents($dbms_schema); $sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query); $remove_remarks($sql_query); $sql_query = split_sql_file($sql_query, $delimiter); foreach ($sql_query as $sql) { $db->sql_query($sql); } unset($sql_query); } if (file_exists($install_path . 'schema_data.sql')) { $sql_query = file_get_contents($install_path . 'schema_data.sql'); switch ($install_dbms) { case 'mssql': case 'mssql_odbc': $sql_query = preg_replace('#\\# MSSQL IDENTITY (phpbb_[a-z_]+) (ON|OFF) \\##s', 'SET IDENTITY_INSERT \\1 \\2;', $sql_query); break; case 'postgres': $sql_query = preg_replace('#\\# POSTGRES (BEGIN|COMMIT) \\##s', '\\1; ', $sql_query); break; } $sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query); $sql_query = preg_replace_callback('#\\{L_([A-Z0-9\\-_]*)\\}#s', 'adjust_language_keys_callback', $sql_query); remove_remarks($sql_query); $sql_query = split_sql_file($sql_query, ';'); foreach ($sql_query as $sql) { $db->sql_query($sql); } unset($sql_query); } }
/** * Generate the drop down of available database options */ function dbms_select($default = '', $only_20x_options = false) { global $lang; $available_dbms = get_available_dbms(false, false, $only_20x_options); $dbms_options = ''; foreach ($available_dbms as $dbms_name => $details) { $selected = $dbms_name == $default ? ' selected="selected"' : ''; $dbms_options .= '<option value="' . $dbms_name . '"' . $selected . '>' . $lang['DLL_' . strtoupper($dbms_name)] . '</option>'; } return $dbms_options; }
/** * Table Add * * This only supports input from the array format of db_tools or create_schema_files. */ function table_add($table_name, $table_data = array()) { global $dbms, $user; // Multicall if (is_array($table_name)) { foreach ($table_name as $params) { call_user_func_array(array($this, 'table_add'), $params); } return; } /** * $table_data can be empty when uninstalling a mod and table_remove was used, but no 2rd argument was given. * In that case we'll assume that it was a column previously added by the mod (if not the author should specify a 2rd argument) and skip this to prevent an error */ if (empty($table_data)) { return; } $this->get_table_name($table_name); $this->umil_start('TABLE_ADD', $table_name); if ($this->table_exists($table_name)) { return $this->umil_end('TABLE_ALREADY_EXISTS', $table_name); } if (!is_array($table_data)) { return $this->umil_end('NO_TABLE_DATA'); } if (!function_exists('get_available_dbms')) { global $phpbb_root_path, $phpEx; include "{$phpbb_root_path}includes/functions_install.{$phpEx}"; } if (method_exists($this->db_tools, 'sql_create_table')) { // Added in 3.0.5 $this->db_tools->sql_create_table($table_name, $table_data); } else { $available_dbms = get_available_dbms($dbms); $sql_query = $this->create_table_sql($table_name, $table_data); $sql_query = split_sql_file($sql_query, $available_dbms[$dbms]['DELIM']); foreach ($sql_query as $sql) { $this->db->sql_query($sql); } } return $this->umil_end(); }
/** * Build the search index... */ function build_search_index($mode, $sub) { global $db, $lang, $phpbb_root_path, $phpbb_dispatcher, $phpEx, $config, $auth, $user; // Obtain any submitted data $data = $this->get_submitted_data(); $table_prefix = $data['table_prefix']; // If we get here and the extension isn't loaded it should be safe to just go ahead and load it $available_dbms = get_available_dbms($data['dbms']); if (!isset($available_dbms[$data['dbms']])) { // Someone's been silly and tried providing a non-existant dbms $this->p_master->redirect("index.{$phpEx}?mode=install"); } $dbms = $available_dbms[$data['dbms']]['DRIVER']; // Instantiate the database $db = new $dbms(); $db->sql_connect($data['dbhost'], $data['dbuser'], htmlspecialchars_decode($data['dbpasswd']), $data['dbname'], $data['dbport'], false, false); // NOTE: trigger_error does not work here. $db->sql_return_on_error(true); include_once $phpbb_root_path . 'includes/constants.' . $phpEx; include_once $phpbb_root_path . 'phpbb/search/fulltext_native.' . $phpEx; // We need to fill the config to let internal functions correctly work $config = new \phpbb\config\db($db, new \phpbb\cache\driver\dummy(), CONFIG_TABLE); $error = false; $search = new \phpbb\search\fulltext_native($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher); $sql = 'SELECT post_id, post_subject, post_text, poster_id, forum_id FROM ' . POSTS_TABLE; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $search->index('post', $row['post_id'], $row['post_text'], $row['post_subject'], $row['poster_id'], $row['forum_id']); } $db->sql_freeresult($result); }
function repair() { include PHPBB_ROOT_PATH . 'includes/functions_install.' . PHP_EXT; $available_dbms = get_available_dbms(); $error = array(); $data = array('dbms' => isset($_POST['dbms']) ? $_POST['dbms'] : '', 'dbhost' => isset($_POST['dbhost']) ? $_POST['dbhost'] : '', 'dbport' => isset($_POST['dbport']) ? $_POST['dbport'] : '', 'dbname' => isset($_POST['dbname']) ? $_POST['dbname'] : '', 'dbuser' => isset($_POST['dbuser']) ? $_POST['dbuser'] : '', 'dbpasswd' => isset($_POST['dbpasswd']) ? $_POST['dbpasswd'] : '', 'table_prefix' => isset($_POST['table_prefix']) ? $_POST['table_prefix'] : 'phpbb_'); if (isset($_POST['submit'])) { if (!isset($available_dbms[$data['dbms']])) { $error[] = 'Database Connection not available.'; } else { $connect_test = $this->critical_connect_check_db(true, $error, $available_dbms[$data['dbms']], $data['table_prefix'], $data['dbhost'], $data['dbuser'], htmlspecialchars_decode($data['dbpasswd']), $data['dbname'], $data['dbport']); if (!$connect_test) { $error[] = 'Database Connection failed.'; } } } if (isset($_POST['submit']) && empty($error)) { // Time to convert the data provided into a config file $config_data = "<?php\n"; $config_data .= "// phpBB 3.0.x auto-generated configuration file\n// Do not change anything in this file!\n"; $config_data_array = array('dbms' => $available_dbms[$data['dbms']]['DRIVER'], 'dbhost' => $data['dbhost'], 'dbport' => $data['dbport'], 'dbname' => $data['dbname'], 'dbuser' => $data['dbuser'], 'dbpasswd' => htmlspecialchars_decode($data['dbpasswd']), 'table_prefix' => $data['table_prefix'], 'acm_type' => 'file', 'load_extensions' => ''); foreach ($config_data_array as $key => $value) { $config_data .= "\${$key} = '" . str_replace("'", "\\'", str_replace('\\', '\\\\', $value)) . "';\n"; } unset($config_data_array); $config_data .= "\n@define('PHPBB_INSTALLED', true);\n"; $config_data .= "// @define('DEBUG', true);\n"; $config_data .= "// @define('DEBUG_EXTRA', true);\n"; $config_data .= '?' . '>'; // Done this to prevent highlighting editors getting confused! // Assume it will work ... if nothing goes wrong below $written = true; if (!($fp = @fopen(PHPBB_ROOT_PATH . 'config.' . PHP_EXT, 'w'))) { // Something went wrong ... so let's try another method $written = false; } if (!@fwrite($fp, $config_data)) { // Something went wrong ... so let's try another method $written = false; } @fclose($fp); if ($written) { // We may revert back to chmod() if we see problems with users not able to change their config.php file directly phpbb_chmod(PHPBB_ROOT_PATH . 'config.' . PHP_EXT, CHMOD_READ); } else { header('Content-type: text/html; charset=UTF-8'); echo 'ERROR: Could not write config file. Please copy the text below, put it in a file named config.php, and place it in the root directory of your forum.<br /><br />'; echo nl2br(htmlspecialchars($config_data)); exit; } } else { header('Content-type: text/html; charset=UTF-8'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta http-equiv="content-style-type" content="text/css" /> <meta http-equiv="imagetoolbar" content="no" /> <title>Config Repair - Support Toolkit</title> <link href="<?php echo STK_ROOT_PATH; ?> style/style.css" rel="stylesheet" type="text/css" media="screen" /> <link href="<?php echo STK_ROOT_PATH; ?> style/erk_style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body id="errorpage"> <div id="wrap"> <div id="page-header"> </div> <div id="page-body"> <div id="acp"> <div class="panel"> <span class="corners-top"><span></span></span> <div id="content"> <h1>Config Repair</h1> <br /> <p> Through this tool you can regenerate your configuration file. </p> <form id="stk" method="post" action="<?php echo STK_ROOT_PATH . 'index.' . PHP_EXT; ?> " name="support_tool_kit"> <fieldset> <?php if (!empty($error)) { ?> <div class="errorbox"> <h3>Error</h3> <p><?php echo implode('<br />', $error); ?> </p> </div> <?php } ?> <dl> <dt><label for="dbms">Database type:</label></dt> <dd><select name="dbms"> <?php foreach (get_available_dbms() as $dbms => $dbms_data) { ?> <option value="<?php echo $dbms; ?> " <?php if ($data['dbms'] == $dbms) { echo ' selected="selected"'; } ?> ><?php echo $dbms_data['LABEL']; ?> <?php } ?> </select></dd> </dl> <dl> <dt><label for="dbhost">Database server hostname or DSN:</label><br /><span class="explain">DSN stands for Data Source Name and is relevant only for ODBC installs.</span></dt> <dd><input id="dbhost" type="text" value="<?php echo $data['dbhost']; ?> " name="dbhost" maxlength="100" size="25"/></dd> </dl> <dl> <dt><label for="dbport">Database server port:</label><br /><span class="explain">Leave this blank unless you know the server operates on a non-standard port.</span></dt> <dd><input id="dbport" type="text" value="<?php echo $data['dbport']; ?> " name="dbport" maxlength="100" size="25"/></dd> </dl> <dl> <dt><label for="dbname">Database name:</label></dt> <dd><input id="dbname" type="text" value="<?php echo $data['dbname']; ?> " name="dbname" maxlength="100" size="25"/></dd> </dl> <dl> <dt><label for="dbuser">Database username:</label></dt> <dd><input id="dbuser" type="text" value="<?php echo $data['dbuser']; ?> " name="dbuser" maxlength="100" size="25"/></dd> </dl> <dl> <dt><label for="dbpasswd">Database password:</label></dt> <dd><input id="dbpasswd" type="password" value="" name="dbpasswd" maxlength="100" size="25"/></dd> </dl> <dl> <dt><label for="table_prefix">Prefix for tables in database:</label></dt> <dd><input id="table_prefix" type="text" value="<?php echo $data['table_prefix']; ?> " name="table_prefix" maxlength="100" size="25"/></dd> </dl> <p class="submit-buttons"> <input class="button1" type="submit" id="submit" name="submit" value="Submit" /> <input class="button2" type="reset" id="reset" name="reset" value="Reset" /> </p> </fieldset> </form> </div> <span class="corners-bottom"><span></span></span> </div> </div> </div> <div id="page-footer"> Powered by phpBB © 2000, 2002, 2005, 2007 <a href="http://www.phpbb.com/">phpBB Group</a> </div> </div> </body> </html> <?php exit; } }
/** * Update a plugin */ public static function plugin_update($which) { global $auth, $auth_admin, $blog_plugins_path, $cache, $config, $db, $dbmd, $dbms, $db_tool, $phpbb_root_path, $phpEx, $table_prefix, $user; if (!array_key_exists($which, self::$plugins)) { trigger_error('PLUGIN_NOT_INSTALLED'); } $newer_files = false; if (self::$available_plugins[$which]['plugin_version'] != self::$plugins[$which]['plugin_version']) { $version = array('files' => explode('.', self::$available_plugins[$which]['plugin_version']), 'db' => explode('.', self::$plugins[$which]['plugin_version'])); $i = 0; foreach ($version['files'] as $v) { if ($v > $version['db'][$i]) { $newer_files = true; break; } else { if ($v < $version['db'][$i]) { break; } } $i++; } } if ($newer_files) { include $phpbb_root_path . 'includes/functions_install.' . $phpEx; include $phpbb_root_path . 'includes/db/db_tools.' . $phpEx; include $phpbb_root_path . '/includes/acp/auth.' . $phpEx; $auth_admin = new auth_admin(); $db_tool = new phpbb_db_tools($db); $dbmd = get_available_dbms($dbms); define('PLUGIN_UPDATE', true); $current_version = self::$plugins[$which]['plugin_version']; if (file_exists($blog_plugins_path . $which . '/update.' . $phpEx)) { include $blog_plugins_path . $which . '/update.' . $phpEx; } $sql = 'UPDATE ' . BLOGS_PLUGINS_TABLE . ' SET plugin_version = \'' . self::$available_plugins[$which]['plugin_version'] . '\' WHERE plugin_name = \'' . $db->sql_escape($which) . '\''; $db->sql_query($sql); self::$plugins[$which]['plugin_version'] = self::$available_plugins[$which]['plugin_version']; add_log('admin', 'LOG_BLOG_PLUGIN_UPDATED', $which); handle_blog_cache('plugins'); } }
/** * Build the search index... */ function build_search_index($mode, $sub) { global $db, $lang, $phpbb_root_path, $phpEx, $config; // Obtain any submitted data $data = $this->get_submitted_data(); $table_prefix = $data['table_prefix']; // If we get here and the extension isn't loaded it should be safe to just go ahead and load it $available_dbms = get_available_dbms($data['dbms']); if (!isset($available_dbms[$data['dbms']])) { // Someone's been silly and tried providing a non-existant dbms $this->p_master->redirect("index.$phpEx?mode=install"); } $dbms = $available_dbms[$data['dbms']]['DRIVER']; // Load the appropriate database class if not already loaded include($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx); // Instantiate the database $db = new $sql_db(); $db->sql_connect($data['dbhost'], $data['dbuser'], htmlspecialchars_decode($data['dbpasswd']), $data['dbname'], $data['dbport'], false, false); // NOTE: trigger_error does not work here. $db->sql_return_on_error(true); include_once($phpbb_root_path . 'includes/constants.' . $phpEx); include_once($phpbb_root_path . 'includes/search/fulltext_native.' . $phpEx); // Fill the config array - it is needed by those functions we call $sql = 'SELECT * FROM ' . CONFIG_TABLE; $result = $db->sql_query($sql); $config = array(); while ($row = $db->sql_fetchrow($result)) { $config[$row['config_name']] = $row['config_value']; } $db->sql_freeresult($result); $error = false; $search = new fulltext_native($error); $sql = 'SELECT post_id, post_subject, post_text, poster_id, forum_id FROM ' . POSTS_TABLE; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $search->index('post', $row['post_id'], $row['post_text'], $row['post_subject'], $row['poster_id'], $row['forum_id']); } $db->sql_freeresult($result); }
} $dbms = $db->sql_layer; $table = ''; generate_sql($table, $dbms); if (empty($table)) { // Should never happen. trigger_error('This error should not happen'); } $config_items = array('as_interval' => 3600, 'as_prune' => 24 * 14, 'as_max_posts' => 0, 'as_flood_interval' => 15, 'as_version' => VERSION, 'as_ie_nr' => 5, 'as_non_ie_nr' => 20); $config_items_dyn = array('last_as_run' => 0); $permissions = array('global' => array('u_as_post', 'u_as_view', 'u_as_info', 'u_as_delete', 'u_as_edit', 'u_as_smilies', 'u_as_bbcode', 'u_as_mod_edit', 'u_as_ignore_flood', 'a_as_manage')); if (!function_exists('get_available_dbms')) { global $phpbb_root_path, $phpEx; include $phpbb_root_path . 'includes/functions_install.' . $phpEx; } $available_dbms = get_available_dbms(); if ($dbms == 'mysql4' || $dbms == 'mysql') { if (version_compare($db->mysql_version, '4.1.3', '>=')) { $available_dbms['mysql']['SCHEMA'] .= '_41'; $dbms = 'mysql'; } else { $available_dbms[$dbms]['SCHEMA'] .= '_40'; } } $remove_remarks = $available_dbms[$dbms]['COMMENTS']; $delimiter = $available_dbms[$dbms]['DELIM']; $sql_query = preg_replace('#phpbb_#i', $table_prefix, $table); $remove_remarks($sql_query); $sql_query = split_sql_file($sql_query, $delimiter); foreach ($sql_query as $sql) { $db->sql_query($sql);
/** * Run Tool * * Does the actual stuff we want the tool to do after submission */ function run_tool(&$error) { global $cache, $db, $dbms, $table_prefix, $template; if (!check_form_key('sql_query')) { $error[] = 'FORM_INVALID'; return; } $sql_query = utf8_normalize_nfc(request_var('sql_query', '', true)); $sql_query = htmlspecialchars_decode($sql_query); // Need special chars like < and > see bug #59755 // Replace phpbb_ with the correct table prefix. Do the double replace otherwise you can have issues with prefixes like phpbb_3 $sql_query = str_replace('phpbb_', $table_prefix, str_replace($table_prefix, 'phpbb_', $sql_query)); if (!$sql_query) { $error[] = 'NO_SQL_QUERY'; return; } if (!function_exists('remove_comments')) { include PHPBB_ROOT_PATH . 'includes/functions_admin.' . PHP_EXT; } if (!function_exists('split_sql_file')) { include PHPBB_ROOT_PATH . 'includes/functions_install.' . PHP_EXT; } $dbmd = get_available_dbms($dbms); $remove_remarks = $dbmd[$dbms]['COMMENTS']; $delimiter = $dbmd[$dbms]['DELIM']; $remove_remarks($sql_query); $sql_query = split_sql_file($sql_query, $delimiter); // Return on error $db->sql_return_on_error(true); foreach ($sql_query as $sql) { // Run the query and make sure that nothing went wrong $result = $db->sql_query($sql); if ($db->sql_error_triggered) { // Write the error result to the cache and return the user back // to the main page $error[] = $this->_format_sql_error($sql); continue; } if (isset($_POST['show_results'])) { // Display the query $template->assign_block_vars('queries', array('QUERY' => $sql)); $cnt = 0; while ($row = $db->sql_fetchrow($result)) { if ($cnt == 0) { // Assign the return fields foreach (array_keys($row) as $key) { $template->assign_block_vars('queries.headings', array('FIELD_NAME' => $key)); } } // Set row class $template->assign_block_vars('queries.resultdata', array('ROWSTYLE' => $cnt % 2 == 0 ? 1 : 2)); // Output resultset foreach ($row as $value) { $template->assign_block_vars('queries.resultdata.resultdatafields', array('VALUE' => $value)); } $cnt++; } } $db->sql_freeresult($result); } // Purge the cache $cache->purge(); if (empty($error)) { trigger_error('SQL_QUERY_SUCCESS'); } }
/** * Generate the drop down of available database options */ function dbms_select($default = '') { global $lang; $available_dbms = get_available_dbms(false, false); $dbms_options = ''; foreach ($available_dbms as $dbms_name => $details) { $selected = $dbms_name == $default ? ' selected="selected"' : ''; $dbms_options .= '<option value="' . $dbms_name . '"' . $selected . '>' . $details['LABEL'] . '</option>'; } return $dbms_options; }
if (USER_BLOG_MOD_VERSION == $config['user_blog_version']) { trigger_error(sprintf($user->lang['ALREADY_UPDATED'], '<a href="' . append_sid("{$phpbb_root_path}blog.{$phpEx}") . '">', '</a>')); } if (confirm_box(true)) { // This may help... @set_time_limit(120); $sql_array = array(); include $phpbb_root_path . 'includes/functions_admin.' . $phpEx; // Needed for remove_comments function for some DB types include $phpbb_root_path . 'includes/functions_install.' . $phpEx; include $phpbb_root_path . 'includes/db/db_tools.' . $phpEx; include $phpbb_root_path . 'includes/acp/auth.' . $phpEx; include $phpbb_root_path . 'blog/includes/eami.' . $phpEx; $auth_admin = new auth_admin(); $db_tool = new phpbb_db_tools($db); $dbmd = get_available_dbms($dbms); $eami = new eami(); switch ($config['user_blog_version']) { case 'A6': case 'A7': $sql = 'ALTER TABLE ' . BLOGS_TABLE . ' ADD blog_real_reply_count MEDIUMINT( 8 ) NOT NULL DEFAULT \'0\''; $db->sql_query($sql); case 'A8': resync_blog('real_reply_count'); resync_blog('reply_count'); $sql_array[] = 'CREATE TABLE ' . BLOGS_SUBSCRIPTION_TABLE . ' ( sub_user_id mediumint(8) UNSIGNED DEFAULT \'0\' NOT NULL, sub_type tinyint(1) UNSIGNED DEFAULT \'0\' NOT NULL, blog_id mediumint(8) UNSIGNED DEFAULT \'0\' NOT NULL, user_id mediumint(8) UNSIGNED DEFAULT \'0\' NOT NULL, PRIMARY KEY (sub_user_id)
function repair() { global $critical_repair, $user; $critical_repair->user_setup($user); include PHPBB_ROOT_PATH . 'includes/functions_install.' . PHP_EXT; include STK_ROOT_PATH . 'includes/functions.' . PHP_EXT; $available_dbms = get_available_dbms(); $error = array(); $data = array('dbms' => isset($_POST['dbms']) ? $_POST['dbms'] : '', 'dbhost' => isset($_POST['dbhost']) ? $_POST['dbhost'] : '', 'dbport' => isset($_POST['dbport']) ? $_POST['dbport'] : '', 'dbname' => isset($_POST['dbname']) ? $_POST['dbname'] : '', 'dbuser' => isset($_POST['dbuser']) ? $_POST['dbuser'] : '', 'dbpasswd' => isset($_POST['dbpasswd']) ? $_POST['dbpasswd'] : '', 'table_prefix' => isset($_POST['table_prefix']) ? $_POST['table_prefix'] : 'phpbb_'); if (isset($_POST['submit'])) { if (!isset($available_dbms[$data['dbms']])) { $error[] = $user->lang['CONFIG_REPAIR_NO_DBMS']; } else { $connect_test = $this->critical_connect_check_db($user, true, $error, $available_dbms[$data['dbms']], $data['table_prefix'], $data['dbhost'], $data['dbuser'], htmlspecialchars_decode($data['dbpasswd']), $data['dbname'], $data['dbport']); if (!$connect_test) { $error[] = $user->lang['CONFIG_REPAIR_CONNECT_FAIL']; } } } if (isset($_POST['submit']) && empty($error)) { // Time to convert the data provided into a config file $config_data = "<?php\n"; $config_data .= "// phpBB 3.1.x auto-generated configuration file\n// Do not change anything in this file!\n"; $config_data_array = array('dbms' => $available_dbms[$data['dbms']]['DRIVER'], 'dbhost' => $data['dbhost'], 'dbport' => $data['dbport'], 'dbname' => $data['dbname'], 'dbuser' => $data['dbuser'], 'dbpasswd' => htmlspecialchars_decode($data['dbpasswd']), 'table_prefix' => $data['table_prefix'], 'phpbb_adm_relative_path' => 'adm/', 'acm_type' => 'phpbb\\cache\\driver\\file'); foreach ($config_data_array as $key => $value) { $config_data .= "\${$key} = '" . str_replace("'", "\\'", str_replace('\\', '\\\\', $value)) . "';\n"; } unset($config_data_array); $config_data .= "\n@define('PHPBB_INSTALLED', true);\n"; $config_data .= "// @define('PHPBB_DISPLAY_LOAD_TIME', true);\n"; $config_data .= "// @define('DEBUG', true);\n"; $config_data .= "// @define('DEBUG_CONTAINER', true);\n"; $config_data .= '?' . '>'; // Done this to prevent highlighting editors getting confused! // Assume it will work ... if nothing goes wrong below $written = true; if (!($fp = @fopen(PHPBB_ROOT_PATH . 'config.' . PHP_EXT, 'w'))) { // Something went wrong ... so let's try another method $written = false; } if (!@fwrite($fp, $config_data)) { // Something went wrong ... so let's try another method $written = false; } @fclose($fp); if ($written) { // We may revert back to chmod() if we see problems with users not able to change their config.php file directly if (!function_exists('phpbb_chmod')) { include PHPBB_ROOT_PATH . 'includes/functions.' . PHP_EXT; } phpbb_chmod(PHPBB_ROOT_PATH . 'config.' . PHP_EXT, CHMOD_READ); } else { header('Content-type: text/html; charset=UTF-8'); echo $user->lang['CONFIG_REPAIR_WRITE_ERROR']; echo nl2br(htmlspecialchars($config_data)); exit; } } else { header('Content-type: text/html; charset=UTF-8'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta http-equiv="content-style-type" content="text/css" /> <meta http-equiv="imagetoolbar" content="no" /> <title>Config Repair - Support Toolkit</title> <link href="<?php echo STK_ROOT_PATH; ?> style/style.css" rel="stylesheet" type="text/css" media="screen" /> <link href="<?php echo STK_ROOT_PATH; ?> style/erk_style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body id="errorpage"> <div id="wrap"> <div id="page-header"> </div> <div id="page-body"> <div id="acp"> <div class="panel"> <span class="corners-top"><span></span></span> <div id="content"> <h1><?php echo $user->lang['CONFIG_REPAIR']; ?> </h1> <br /> <p> <?php echo $user->lang['CONFIG_REPAIR_EXPLAIN']; ?> </p> <form id="stk" method="post" action="<?php echo STK_ROOT_PATH . 'erk.' . PHP_EXT; ?> " name="support_tool_kit"> <fieldset> <?php if (!empty($error)) { ?> <div class="errorbox"> <h3>Error</h3> <p><?php echo implode('<br />', $error); ?> </p> </div> <?php } ?> <dl> <dt><label for="dbms"><?php echo $user->lang['DBMS']; ?> :</label></dt> <dd><select name="dbms"> <?php foreach (get_available_dbms() as $dbms => $dbms_data) { ?> <option value="<?php echo $dbms; ?> " <?php if ($data['dbms'] == $dbms) { echo ' selected="selected"'; } ?> ><?php echo $dbms_data['LABEL']; ?> <?php } ?> </select></dd> </dl> <dl> <dt><label for="dbhost"><?php echo $user->lang['DB_HOST']; ?> :</label><br /><span class="explain"><?php echo $user->lang['DB_HOST_EXPLAIN']; ?> </span></dt> <dd><input id="dbhost" type="text" value="<?php echo $data['dbhost']; ?> " name="dbhost" maxlength="100" size="25"/></dd> </dl> <dl> <dt><label for="dbport"><?php echo $user->lang['DB_PORT']; ?> :</label><br /><span class="explain"><?php echo $user->lang['DB_PORT_EXPLAIN']; ?> </span></dt> <dd><input id="dbport" type="text" value="<?php echo $data['dbport']; ?> " name="dbport" maxlength="100" size="25"/></dd> </dl> <dl> <dt><label for="dbname"><?php echo $user->lang['DB_NAME']; ?> :</label></dt> <dd><input id="dbname" type="text" value="<?php echo $data['dbname']; ?> " name="dbname" maxlength="100" size="25"/></dd> </dl> <dl> <dt><label for="dbuser"><?php echo $user->lang['DB_USERNAME']; ?> :</label></dt> <dd><input id="dbuser" type="text" value="<?php echo $data['dbuser']; ?> " name="dbuser" maxlength="100" size="25"/></dd> </dl> <dl> <dt><label for="dbpasswd"><?php echo $user->lang['DB_PASSWORD']; ?> :</label></dt> <dd><input id="dbpasswd" type="password" value="" name="dbpasswd" maxlength="100" size="25"/></dd> </dl> <dl> <dt><label for="table_prefix"><?php echo $user->lang['TABLE_PREFIX']; ?> :</label></dt> <dd><input id="table_prefix" type="text" value="<?php echo $data['table_prefix']; ?> " name="table_prefix" maxlength="100" size="25"/></dd> </dl> <p class="submit-buttons"> <input class="button1" type="submit" id="submit" name="submit" value="<?php echo $user->lang['SUBMIT']; ?> " /> <input class="button2" type="reset" id="reset" name="reset" value="<?php echo $user->lang['CANCEL']; ?> " /> </p> </fieldset> </form> </div> <span class="corners-bottom"><span></span></span> </div> </div> </div> <div id="page-footer"> Support Toolkit for phpBB3.1.x ©</a><br /> Powered by <a href="http://www.phpbb.com/">phpBB</a>® Forum Software © phpBB Group - adaptation for phpBB3.1.x by © Sheer </div> </div> </body> </html> <?php exit; } }
/** * Load the contents of the schema into the database and then alter it based on what has been input during the installation */ function load_schema($mode, $sub) { global $db, $lang, $template, $phpbb_root_path, $phpEx, $dbms, $table_prefix; $this->page_title = $lang['STAGE_CREATE_TABLE']; $s_hidden_fields = ''; // Obtain any submitted data $data = $this->get_submitted_data(); //We will just setup $db here rather than try work it in earlier - might need to rethink this though for languages require $phpbb_root_path . 'includes/functions_convert.' . $phpEx; $available_dbms = get_available_dbms($dbms); // If mysql is chosen, we need to adjust the schema filename slightly to reflect the correct version. ;) if ($dbms == 'mysql') { if (version_compare($db->mysql_version, '4.1.3', '>=')) { $available_dbms[$dbms]['SCHEMA'] .= '_41'; } else { $available_dbms[$dbms]['SCHEMA'] .= '_40'; } } // Ok we have the db info go ahead and read in the relevant schema // and work on building the table $create_schema = 'schemas/' . $available_dbms[$dbms]['SCHEMA'] . '_schema.sql'; // How should we treat this schema? $remove_remarks = $available_dbms[$dbms]['COMMENTS']; $delimiter = $available_dbms[$dbms]['DELIM']; $create_query = file_get_contents($create_schema); $create_query = preg_replace('#phpbb_#i', $table_prefix, $create_query); $remove_remarks($create_query); $create_query = split_sql_file($create_query, $delimiter); foreach ($create_query as $sql) { //$sql = trim(str_replace('|', ';', $sql)); if (!$db->sql_query($sql)) { $error = $db->sql_error(); $this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__); } } unset($create_query); // Ok tables have been built, let's fill in the basic information & prepare optional data too $sql_query = file_get_contents('schemas/schema_data.sql'); $make_query = file_get_contents('schemas/schema_make_data.sql'); $category_query = file_get_contents('schemas/schema_category_data.sql'); // Deal with any special comments switch ($dbms) { case 'mssql': case 'mssql_odbc': $sql_query = preg_replace('#\\# MSSQL IDENTITY (phpbb_[a-z_]+) (ON|OFF) \\##s', 'SET IDENTITY_INSERT \\1 \\2;', $sql_query); $make_query = preg_replace('#\\# MSSQL IDENTITY (phpbb_[a-z_]+) (ON|OFF) \\##s', 'SET IDENTITY_INSERT \\1 \\2;', $make_query); $category_query = preg_replace('#\\# MSSQL IDENTITY (phpbb_[a-z_]+) (ON|OFF) \\##s', 'SET IDENTITY_INSERT \\1 \\2;', $category_query); break; case 'postgres': $sql_query = preg_replace('#\\# POSTGRES (BEGIN|COMMIT) \\##s', '\\1; ', $sql_query); $make_query = preg_replace('#\\# POSTGRES (BEGIN|COMMIT) \\##s', '\\1; ', $make_query); $category_query = preg_replace('#\\# POSTGRES (BEGIN|COMMIT) \\##s', '\\1; ', $category_query); break; } // Change prefix $sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query); $make_query = preg_replace('#phpbb_#i', $table_prefix, $make_query); $category_query = preg_replace('#phpbb_#i', $table_prefix, $category_query); // Since we know the comment style and are able to remove it directly with remove_remarks remove_remarks($sql_query); remove_remarks($make_query); remove_remarks($category_query); $sql_query = split_sql_file($sql_query, ';'); $make_query = split_sql_file($make_query, ';'); $category_query = split_sql_file($category_query, ';'); foreach ($sql_query as $sql) { if (!$db->sql_query($sql)) { $error = $db->sql_error(); $this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__); } } unset($sql_query); // Does the user want default makes if ($data['insert_makes']) { foreach ($make_query as $sql) { //$sql = trim(str_replace('|', ';', $sql)); if (!$db->sql_query($sql)) { $error = $db->sql_error(); $this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__); } } unset($make_query); } // Does the user want default categories if ($data['insert_categories']) { foreach ($category_query as $sql) { //$sql = trim(str_replace('|', ';', $sql)); if (!$db->sql_query($sql)) { $error = $db->sql_error(); $this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__); } } unset($category_query); } $schema_changes = array('add_columns' => array(USERS_TABLE => array('user_garage_index_columns' => array('BOOL', 2), 'user_garage_guestbook_email_notify' => array('BOOL', 1), 'user_garage_guestbook_pm_notify' => array('BOOL', 1), 'user_garage_mod_email_optout' => array('BOOL', 0), 'user_garage_mod_pm_optout' => array('BOOL', 0)))); require $phpbb_root_path . 'includes/db/db_tools.' . $phpEx; $mod_db = new phpbb_db_tools($db); $mod_db->perform_schema_changes($schema_changes); $submit = $lang['NEXT_STEP']; $url = $this->p_master->module_url . "?mode={$mode}&sub=create_permissions"; $template->assign_vars(array('BODY' => $lang['STAGE_CREATE_TABLE_EXPLAIN'], 'L_SUBMIT' => $submit, 'S_HIDDEN' => build_hidden_fields($data), 'U_ACTION' => $url)); }
/** * Load the contents of the schema into the database and then alter it based on what has been input during the installation */ function load_schema($mode, $sub) { global $dbms, $db, $user, $template, $table_prefix, $config, $auth, $cache; $this->page_title = $user->lang['INSTALL_KARMA_STAGE_CREATE_TABLE']; $s_hidden_fields = ''; // Obtain any submitted data foreach ($this->request_vars as $var) { $$var = request_var($var, ''); } if (!$karma_time) { $karma_time = $this->admin_config_options['karma_time']['value']; } if (!$karma_posts) { $karma_posts = $this->admin_config_options['karma_posts']['value']; } // If we get here and the extension isn't loaded it should be safe to just go ahead and load it $available_dbms = get_available_dbms($dbms); // If mysql is chosen, we need to adjust the schema filename slightly to reflect the correct version. ;) if ($dbms == 'mysql') { if (version_compare($db->sql_server_version, '4.1.3', '>=')) { $available_dbms[$dbms]['SCHEMA'] .= '_41'; } else { $available_dbms[$dbms]['SCHEMA'] .= '_40'; } } // Ok we have the db info go ahead and read in the relevant schema // and work on building the table $dbms_schema = 'schemas/' . $available_dbms[$dbms]['SCHEMA'] . '_schema.sql'; // How should we treat this schema? $remove_remarks = $available_dbms[$dbms]['COMMENTS']; $delimiter = $available_dbms[$dbms]['DELIM']; $sql_query = @file_get_contents($dbms_schema); $sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query); $remove_remarks($sql_query); $sql_query = split_sql_file($sql_query, $delimiter); foreach ($sql_query as $sql) { //$sql = trim(str_replace('|', ';', $sql)); if (!$db->sql_query($sql)) { $error = $db->sql_error(); $this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__); } } unset($sql_query); // Ok tables have been built, let's fill in the basic information $sql_query = file_get_contents('schemas/schema_data.sql'); // Deal with any special comments switch ($dbms) { case 'mssql': case 'mssql_odbc': $sql_query = preg_replace('#\# MSSQL IDENTITY (phpbb_[a-z_]+) (ON|OFF) \##s', 'SET IDENTITY_INSERT \1 \2;', $sql_query); break; case 'postgres': $sql_query = preg_replace('#\# POSTGRES (BEGIN|COMMIT) \##s', '\1; ', $sql_query); break; } // Change prefix $sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query); // Change language strings... $sql_query = preg_replace_callback('#\{L_([A-Z0-9\-_]*)\}#s', 'adjust_language_keys_callback', $sql_query); // Since there is only one schema file we know the comment style and are able to remove it directly with remove_remarks remove_remarks($sql_query); $sql_query = split_sql_file($sql_query, ';'); foreach ($sql_query as $sql) { //$sql = trim(str_replace('|', ';', $sql)); if (!$db->sql_query($sql)) { $error = $db->sql_error(); $this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__); } } unset($sql_query); // Set default config and post data, this applies to all DB's $sql_ary = array( 'INSERT INTO ' . $table_prefix . "config (config_name, config_value) VALUES ('karma_version', '" . $db->sql_escape($this->version) . "')", 'INSERT INTO ' . $table_prefix . "config (config_name, config_value) VALUES ('karma_enabled_ucp', '" . $db->sql_escape($karma_enabled_ucp) . "')", 'INSERT INTO ' . $table_prefix . "config (config_name, config_value) VALUES ('karma_notify_pm', '" . $config['allow_privmsg'] . "')", 'INSERT INTO ' . $table_prefix . "config (config_name, config_value) VALUES ('karma_notify_email', '" . $config['email_enable'] . "')", 'INSERT INTO ' . $table_prefix . "config (config_name, config_value) VALUES ('karma_notify_jabber', '" . $config['jab_enable'] . "')", 'INSERT INTO ' . $table_prefix . "config (config_name, config_value) VALUES ('karma_drafts', '" . $auth->acl_get('u_savedrafts') . "')", 'INSERT INTO ' . $table_prefix . "config (config_name, config_value) VALUES ('karma_icons', '" . $db->sql_escape($karma_icons) . "')", 'INSERT INTO ' . $table_prefix . "config (config_name, config_value) VALUES ('karma_toplist', '" . $db->sql_escape($karma_toplist) . "')", 'INSERT INTO ' . $table_prefix . "config (config_name, config_value) VALUES ('karma_toplist_users', '" . $db->sql_escape($karma_toplist_users) . "')", 'INSERT INTO ' . $table_prefix . "config (config_name, config_value) VALUES ('karma_time', '" . $db->sql_escape($karma_time) . "')", 'INSERT INTO ' . $table_prefix . "config (config_name, config_value) VALUES ('karma_posts', '" . $db->sql_escape($karma_posts) . "')", 'INSERT INTO ' . $table_prefix . "config (config_name, config_value) VALUES ('karma_comments_per_page', '" . $db->sql_escape($karma_comments_per_page) . "')", 'INSERT INTO ' . $table_prefix . "config (config_name, config_value) VALUES ('karma_power', '" . $db->sql_escape($karma_power) . "')", ); foreach ($sql_ary as $sql) { //$sql = trim(str_replace('|', ';', $sql)); if (!$db->sql_query($sql)) { $error = $db->sql_error(); $this->p_master->db_error($error['message'], $sql, __LINE__, __FILE__); } } // clear the config table cache now $cache->destroy('_global'); foreach ($this->request_vars as $var) { $s_hidden_fields .= '<input type="hidden" name="' . $var . '" value="' . $$var . '" />'; } $submit = $user->lang['NEXT_STEP']; $url = $this->p_master->module_url . "?mode=$mode&sub=final"; $template->assign_vars(array( 'BODY' => $user->lang['STAGE_CREATE_TABLE_EXPLAIN'], 'L_SUBMIT' => $submit, 'S_HIDDEN' => $s_hidden_fields, 'U_ACTION' => $url, )); }
/** */ function get_convert_settings($sub) { global $lang, $language, $template, $db, $phpbb_root_path, $phpEx, $config, $cache; require($phpbb_root_path . 'config.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx); require($phpbb_root_path . 'includes/functions_convert.' . $phpEx); $db = new $sql_db(); $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, true); unset($dbpasswd); $this->page_title = $lang['STAGE_SETTINGS']; // We need to fill the config to let internal functions correctly work $sql = 'SELECT * FROM ' . CONFIG_TABLE; $result = $db->sql_query($sql); $config = array(); while ($row = $db->sql_fetchrow($result)) { $config[$row['config_name']] = $row['config_value']; } $db->sql_freeresult($result); $convertor_tag = request_var('tag', ''); if (empty($convertor_tag)) { $this->p_master->error($lang['NO_CONVERT_SPECIFIED'], __LINE__, __FILE__); } $get_info = true; // check security implications of direct inclusion $convertor_tag = basename($convertor_tag); if (!file_exists('./convertors/convert_' . $convertor_tag . '.' . $phpEx)) { $this->p_master->error($lang['CONVERT_NOT_EXIST'], __LINE__, __FILE__); } include('./convertors/convert_' . $convertor_tag . '.' . $phpEx); // The test_file is a file that should be present in the location of the old board. if (!isset($test_file)) { $this->p_master->error($lang['DEV_NO_TEST_FILE'], __LINE__, __FILE__); } $submit = (isset($_POST['submit'])) ? true : false; $src_dbms = request_var('src_dbms', $convertor_data['dbms']); $src_dbhost = request_var('src_dbhost', $convertor_data['dbhost']); $src_dbport = request_var('src_dbport', $convertor_data['dbport']); $src_dbuser = request_var('src_dbuser', $convertor_data['dbuser']); $src_dbpasswd = request_var('src_dbpasswd', $convertor_data['dbpasswd']); $src_dbname = request_var('src_dbname', $convertor_data['dbname']); $src_table_prefix = request_var('src_table_prefix', $convertor_data['table_prefix']); $forum_path = request_var('forum_path', $convertor_data['forum_path']); $refresh = request_var('refresh', 1); // Default URL of the old board // @todo Are we going to use this for attempting to convert URL references in posts, or should we remove it? // -> We should convert old urls to the new relative urls format // $src_url = request_var('src_url', 'Not in use at the moment'); // strip trailing slash from old forum path $forum_path = (strlen($forum_path) && $forum_path[strlen($forum_path) - 1] == '/') ? substr($forum_path, 0, -1) : $forum_path; $error = array(); if ($submit) { if (!@file_exists('./../' . $forum_path . '/' . $test_file)) { $error[] = sprintf($lang['COULD_NOT_FIND_PATH'], $forum_path); } $connect_test = false; $available_dbms = get_available_dbms(false, true, true); if (!isset($available_dbms[$src_dbms]) || !$available_dbms[$src_dbms]['AVAILABLE']) { $error['db'][] = $lang['INST_ERR_NO_DB']; $connect_test = false; } else { $connect_test = connect_check_db(true, $error, $available_dbms[$src_dbms], $src_table_prefix, $src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd), $src_dbname, $src_dbport, true, ($src_dbms == $dbms) ? false : true, false); } // The forum prefix of the old and the new forum can only be the same if two different databases are used. if ($src_table_prefix == $table_prefix && $src_dbms == $dbms && $src_dbhost == $dbhost && $src_dbport == $dbport && $src_dbname == $dbname) { $error[] = sprintf($lang['TABLE_PREFIX_SAME'], $src_table_prefix); } // Check table prefix if (!sizeof($error)) { // initiate database connection to old db if old and new db differ global $src_db, $same_db; $src_db = $same_db = false; if ($src_dbms != $dbms || $src_dbhost != $dbhost || $src_dbport != $dbport || $src_dbname != $dbname || $src_dbuser != $dbuser) { $sql_db = 'dbal_' . $src_dbms; $src_db = new $sql_db(); $src_db->sql_connect($src_dbhost, $src_dbuser, htmlspecialchars_decode($src_dbpasswd), $src_dbname, $src_dbport, false, true); $same_db = false; } else { $src_db = $db; $same_db = true; } $src_db->sql_return_on_error(true); $db->sql_return_on_error(true); // Try to select one row from the first table to see if the prefix is OK $result = $src_db->sql_query_limit('SELECT * FROM ' . $src_table_prefix . $tables[0], 1); if (!$result) { $prefixes = array(); $tables_existing = get_tables($src_db); $tables_existing = array_map('strtolower', $tables_existing); foreach ($tables_existing as $table_name) { compare_table($tables, $table_name, $prefixes); } unset($tables_existing); foreach ($prefixes as $prefix => $count) { if ($count >= sizeof($tables)) { $possible_prefix = $prefix; break; } } $msg = ''; if (!empty($convertor_data['table_prefix'])) { $msg .= sprintf($lang['DEFAULT_PREFIX_IS'], $convertor_data['forum_name'], $convertor_data['table_prefix']); } if (!empty($possible_prefix)) { $msg .= '<br />'; $msg .= ($possible_prefix == '*') ? $lang['BLANK_PREFIX_FOUND'] : sprintf($lang['PREFIX_FOUND'], $possible_prefix); $src_table_prefix = ($possible_prefix == '*') ? '' : $possible_prefix; } $error[] = $msg; } $src_db->sql_freeresult($result); $src_db->sql_return_on_error(false); } if (!sizeof($error)) { // Save convertor Status set_config('convert_progress', serialize(array( 'step' => '', 'table_prefix' => $src_table_prefix, 'tag' => $convertor_tag, )), true); set_config('convert_db_server', serialize(array( 'dbms' => $src_dbms, 'dbhost' => $src_dbhost, 'dbport' => $src_dbport, 'dbname' => $src_dbname, )), true); set_config('convert_db_user', serialize(array( 'dbuser' => $src_dbuser, 'dbpasswd' => $src_dbpasswd, )), true); // Save options set_config('convert_options', serialize(array('forum_path' => './../' . $forum_path, 'refresh' => $refresh)), true); $template->assign_block_vars('checks', array( 'TITLE' => $lang['VERIFY_OPTIONS'], 'RESULT' => $lang['CONVERT_SETTINGS_VERIFIED'], )); $template->assign_vars(array( 'L_SUBMIT' => $lang['BEGIN_CONVERT'], // 'S_HIDDEN' => $s_hidden_fields, 'U_ACTION' => $this->p_master->module_url . "?mode={$this->mode}&sub=in_progress&tag=$convertor_tag&language=$language", )); return; } else { $template->assign_block_vars('checks', array( 'TITLE' => $lang['VERIFY_OPTIONS'], 'RESULT' => '<b style="color:red">' . implode('<br />', $error) . '</b>', )); } } // end submit foreach ($this->convert_options as $config_key => $vars) { if (!is_array($vars) && strpos($config_key, 'legend') === false) { continue; } if (strpos($config_key, 'legend') !== false) { $template->assign_block_vars('options', array( 'S_LEGEND' => true, 'LEGEND' => $lang[$vars]) ); continue; } $options = isset($vars['options']) ? $vars['options'] : ''; $template->assign_block_vars('options', array( 'KEY' => $config_key, 'TITLE' => $lang[$vars['lang']], 'S_EXPLAIN' => $vars['explain'], 'S_LEGEND' => false, 'TITLE_EXPLAIN' => ($vars['explain']) ? $lang[$vars['lang'] . '_EXPLAIN'] : '', 'CONTENT' => $this->p_master->input_field($config_key, $vars['type'], $$config_key, $options), ) ); } $template->assign_vars(array( 'TITLE' => $lang['STAGE_SETTINGS'], 'BODY' => $lang['CONV_OPTIONS_BODY'], 'L_SUBMIT' => $lang['BEGIN_CONVERT'], 'U_ACTION' => $this->p_master->module_url . "?mode={$this->mode}&sub=settings&tag=$convertor_tag&language=$language", )); }
/** * API function to call */ function process_install_instructions($plugin_data, $instructions) { global $db, $table_prefix; $sql_results = array(); // We need to force this because in MySQL 5.5.5 the new default DB Engine is InnoDB, not MyISAM any more $sql_engine = "SET storage_engine=MYISAM"; $db->sql_return_on_error(true); $db->sql_query($sql_engine); $db->sql_return_on_error(false); if (!function_exists('get_available_dbms')) { include IP_ROOT_PATH . 'includes/functions_install.' . PHP_EXT; } if (!empty($instructions['sql_files'])) { $base_dir = $this->plugins_path . $plugin_data['dir'] . '/install/'; $dbms = 'mysql'; // TODO this needs to change... $available_dbms = get_available_dbms($dbms); $dbms = $available_dbms[$dbms]; $delimiter = $dbms['DELIM']; $delimiter_basic = $dbms['DELIM_BASIC']; foreach ($instructions['sql_files'] as $install_file) { $sql_file = $base_dir . $install_file; $sql_query = file_get_contents($sql_file); $db->remove_remarks($sql_query); $sql_query = $db->split_sql_file($sql_query, $delimiter); for ($i = 0; $i < sizeof($sql_query); $i++) { if (trim($sql_query[$i]) == '') { continue; } $db->sql_return_on_error(true); // TODO the str_replace is from install/install.php, but we might want it smarter // (for example, "`phpbb", or "\bphpbb_") $result = $db->sql_query(str_replace('phpbb_', $table_prefix, $sql_query[$i])); if (!$result) { $error = $db->sql_error(); $message = $error['message']; } // This has to be here, otherwise we are not able to catch all errors by using $db->sql_error() $db->sql_return_on_error(false); $sql_results[] = array('sql' => $sql_query[$i], 'message' => htmlspecialchars($message), 'success' => empty($message) ? true : false); } } } if (!empty($instructions['sql'])) { foreach ($instructions['sql'] as $sql_statement) { $error = array(); $message = ''; $db->sql_return_on_error(true); $result = $db->sql_query($sql_statement); if (!$result) { $error = $db->sql_error(); $message = $error['message']; } // This has to be here, otherwise we are not able to catch all errors by using $db->sql_error() $db->sql_return_on_error(false); $sql_results[] = array('sql' => $sql_statement, 'message' => htmlspecialchars($message), 'success' => empty($message) ? true : false); } } if (!empty($instructions['functions'])) { foreach ($instructions['functions'] as $install_function) { eval($install_function); } } return $sql_results; }
/** * Parse sql * * @param array $sql_query */ function parse_sql(&$sql_query) { global $dbms, $table_prefix; if (!function_exists('get_available_dbms')) { global $phpbb_root_path, $phpEx; include $phpbb_root_path . 'includes/functions_install.' . $phpEx; } static $available_dbms; if (!isset($available_dbms)) { $available_dbms = get_available_dbms($dbms); } $remove_remarks = $available_dbms[$dbms]['COMMENTS']; $delimiter = $available_dbms[$dbms]['DELIM']; if (sizeof($sql_query) == 1) { // do some splitting here $sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query); $remove_remarks($sql_query[0]); $sql_query = split_sql_file($sql_query[0], $delimiter); } else { $query_count = sizeof($sql_query); for ($i = 0; $i < $query_count; $i++) { $sql_query[$i] = preg_replace('#phpbb_#i', $table_prefix, $sql_query[$i]); $remove_remarks($sql_query[$i]); } } //return $sql_query; }
/** * Table Add * * This only supports input from the array format of db_tools or create_schema_files. */ function table_add($table_name, $table_data = array()) { global $dbms, $user; // Multicall if ($this->multicall(__FUNCTION__, $table_name)) { return; } /** * $table_data can be empty when uninstalling a mod and table_remove was used, but no 2rd argument was given. * In that case we'll assume that it was a column previously added by the mod (if not the author should specify a 2rd argument) and skip this to prevent an error */ if (empty($table_data)) { return; } $this->get_table_name($table_name); $this->umil_start('TABLE_ADD', $table_name); if ($this->table_exists($table_name)) { return $this->umil_end('TABLE_ALREADY_EXISTS', $table_name); } if (!is_array($table_data)) { return $this->umil_end('NO_TABLE_DATA'); } if (!function_exists('get_available_dbms')) { include IP_ROOT_PATH . 'includes/functions_install.' . PHP_EXT; } /* * This function has had numerous problems and is currently broken, so until phpBB uses it I will not be anymore if (method_exists($this->db_tools, 'sql_create_table')) { // Added in 3.0.5 $this->db_tools->sql_create_table($table_name, $table_data); } else {*/ $available_dbms = get_available_dbms($dbms); $sql_query = $this->create_table_sql($table_name, $table_data); $sql_query = $this->db->split_sql_file($sql_query, $available_dbms[$dbms]['DELIM']); foreach ($sql_query as $sql) { $this->db->sql_query($sql); } //} return $this->umil_end(); }
} $user->lang = file_exists($quickinstall_path . 'language/' . $language) ? $language : 'en'; qi::add_lang(array('qi', 'phpbb'), $quickinstall_path . 'language/' . $user->lang . '/'); // Probably best place to validate the settings $error = validate_settings($qi_config); $mode = empty($error) ? $mode : ($mode == 'update_settings' ? 'update_settings' : 'settings'); if ($qi_install || $mode == 'update_settings' || $mode == 'settings') { require $quickinstall_path . 'includes/qi_settings.' . $phpEx; } // Just put these here temporary. I'll change to use the constants later... Maybe tomorrow or so... $qi_config['version_check'] = false; $qi_config['qi_version'] = QI_VERSION; $qi_config['phpbb_version'] = PHPBB_VERSION; $qi_config['automod_version'] = AUTOMOD_VERSION; // If we get here and the extension isn't loaded it should be safe to just go ahead and load it $available_dbms = get_available_dbms($dbms); if (!isset($available_dbms[$dbms]['DRIVER'])) { trigger_error("The {$dbms} dbms is either not supported, or the php extension for it could not be loaded.", E_USER_ERROR); } // Load the appropriate database class if not already loaded include $phpbb_root_path . 'includes/db/' . $available_dbms[$dbms]['DRIVER'] . '.' . $phpEx; // now the quickinstall dbal extension include $quickinstall_path . 'includes/db/' . $available_dbms[$dbms]['DRIVER'] . '.' . $phpEx; // Instantiate the database $sql_db = 'dbal_' . $available_dbms[$dbms]['DRIVER'] . '_qi'; $db = new $sql_db(); $db->sql_connect($dbhost, $dbuser, $dbpasswd, false, $dbport, false, false); $db->sql_return_on_error(true); // now create a module_handler object $auth = new auth(); $cache = new cache();
function db_connect($db_data = '') { global $phpbb_root_path, $phpEx, $sql_db, $db, $quickinstall_path, $settings; $db_data = empty($db_data) ? $settings->get_db_data() : $db_data; list($dbms, $dbhost, $dbuser, $dbpasswd, $dbport) = $db_data; // If we get here and the extension isn't loaded it should be safe to just go ahead and load it $available_dbms = get_available_dbms($dbms); if (!isset($available_dbms[$dbms]['DRIVER'])) { trigger_error("The {$dbms} dbms is either not supported, or the php extension for it could not be loaded.", E_USER_ERROR); } // Instantiate the database if (defined('PHPBB_31')) { $dbal = substr($available_dbms[$dbms]['DRIVER'], strrpos($available_dbms[$dbms]['DRIVER'], '\\') + 1); // Load the appropriate database class if not already loaded. if (!class_exists('dbal_' . $dbal . '_qi')) { // now the quickinstall dbal extension include $quickinstall_path . 'includes/db/31/' . $dbal . '.' . $phpEx; } $sql_db = 'dbal_' . $dbal . '_qi'; } else { // Load the appropriate database class if not already loaded. if (!class_exists('dbal_' . $available_dbms[$dbms]['DRIVER'] . '_qi')) { // phpBB dbal class. include $phpbb_root_path . 'includes/db/' . $available_dbms[$dbms]['DRIVER'] . '.' . $phpEx; // now the quickinstall dbal extension include $quickinstall_path . 'includes/db/' . $available_dbms[$dbms]['DRIVER'] . '.' . $phpEx; } $sql_db = 'dbal_' . $available_dbms[$dbms]['DRIVER'] . '_qi'; } $db = new $sql_db(); if (defined('PHPBB_31')) { $db->sql_connect($dbhost, $dbuser, $dbpasswd, $settings->get_config('dbname'), $dbport, false, false); } else { $db->sql_connect($dbhost, $dbuser, $dbpasswd, false, $dbport, false, false); } $db->sql_return_on_error(true); return $db; }