public function test_column() { $this->db = $this->new_dbal(); $db_tools = new \phpbb\db\tools($this->db); $this->assertTrue($db_tools->sql_column_exists(USERS_TABLE, 'user_acme'), 'Asserting that column "user_acme" exists'); $this->assertFalse($db_tools->sql_column_exists(USERS_TABLE, 'user_acme_demo'), 'Asserting that column "user_acme_demo" does not exist'); }
public function test_column() { $this->db = $this->new_dbal(); $db_tools = new \phpbb\db\tools($this->db); $this->assertTrue($db_tools->sql_column_exists(USERS_TABLE, 'user_acme')); $this->assertFalse($db_tools->sql_column_exists(USERS_TABLE, 'user_acme_demo')); }
public function test_convert() { $this->migration->update_timezones(0); $sql = 'SELECT user_id, user_timezone FROM phpbb_users ORDER BY user_id ASC'; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $this->assertEquals($this->expected_results[$row['user_id']], $row['user_timezone']); } $this->db->sql_freeresult($result); $db_tools = new \phpbb\db\tools($this->db); // Remove the user_dst field again $db_tools->sql_column_remove('phpbb_users', 'user_dst'); }
public function test_install() { $db_tools = new \phpbb\db\tools($this->db); $this->assertTrue($db_tools->sql_table_exists('phpbb_gallery_albums')); $this->assertTrue($db_tools->sql_table_exists('phpbb_gallery_albums_track')); $this->assertTrue($db_tools->sql_table_exists('phpbb_gallery_comments')); $this->assertTrue($db_tools->sql_table_exists('phpbb_gallery_contests')); $this->assertTrue($db_tools->sql_table_exists('phpbb_gallery_favorites')); $this->assertTrue($db_tools->sql_table_exists('phpbb_gallery_images')); $this->assertTrue($db_tools->sql_table_exists('phpbb_gallery_modscache')); $this->assertTrue($db_tools->sql_table_exists('phpbb_gallery_permissions')); $this->assertTrue($db_tools->sql_table_exists('phpbb_gallery_rates')); $this->assertTrue($db_tools->sql_table_exists('phpbb_gallery_reports')); $this->assertTrue($db_tools->sql_table_exists('phpbb_gallery_roles')); $this->assertTrue($db_tools->sql_table_exists('phpbb_gallery_users')); $this->assertTrue($db_tools->sql_table_exists('phpbb_gallery_watch')); $this->assertTrue($db_tools->sql_table_exists('phpbb_gallery_log')); }
public function test_install() { $db_tools = new \phpbb\db\tools($this->db); $this->assertTrue($db_tools->sql_table_exists('phpbb_posts_likes')); }
/** * Compile the correct schema filename (as per create_schema_files) and * load it into the database. */ protected function load_schema_from_file($directory, \phpbb\db\driver\driver_interface $db) { $schema = $this->dbms['SCHEMA']; if ($this->config['dbms'] == 'phpbb\\db\\driver\\mysql') { $sth = $this->pdo->query('SELECT VERSION() AS version'); $row = $sth->fetch(PDO::FETCH_ASSOC); if (version_compare($row['version'], '4.1.3', '>=')) { $schema .= '_41'; } else { $schema .= '_40'; } } $filename = $directory . $schema . '_schema.sql'; if (file_exists($filename)) { $queries = file_get_contents($filename); $sql = phpbb_remove_comments($queries); $sql = split_sql_file($sql, $this->dbms['DELIM']); foreach ($sql as $query) { $this->pdo->exec($query); } } // Ok we have the db info go ahead and work on building the table if (file_exists($directory . 'schema.json')) { $db_table_schema = file_get_contents($directory . 'schema.json'); $db_table_schema = json_decode($db_table_schema, true); } else { global $phpbb_root_path, $phpEx, $table_prefix; $finder = new \phpbb\finder(new \phpbb\filesystem(), $phpbb_root_path, null, $phpEx); $classes = $finder->core_path('phpbb/db/migration/data/')->get_classes(); $db = new \phpbb\db\driver\sqlite(); $schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, new \phpbb\db\tools($db, true), $phpbb_root_path, $phpEx, $table_prefix); $db_table_schema = $schema_generator->get_schema(); } $db_tools = new \phpbb\db\tools($db, true); foreach ($db_table_schema as $table_name => $table_data) { $queries = $db_tools->sql_create_table($table_name, $table_data); foreach ($queries as $query) { if ($query === 'begin') { $this->pdo->beginTransaction(); } else { if ($query === 'commit') { $this->pdo->commit(); } else { $this->pdo->exec($query); } } } } }
/** * API function - set up shop */ function install() { global $db; $db_tool = new \phpbb\db\tools($db); $schemas = array($this->table_captcha_questions => array('COLUMNS' => array('question_id' => array('UINT', null, 'auto_increment'), 'strict' => array('BOOL', 0), 'lang_id' => array('UINT', 0), 'lang_iso' => array('VCHAR:30', ''), 'question_text' => array('TEXT_UNI', '')), 'PRIMARY_KEY' => 'question_id', 'KEYS' => array('lang' => array('INDEX', 'lang_iso'))), $this->table_captcha_answers => array('COLUMNS' => array('question_id' => array('UINT', 0), 'answer_text' => array('STEXT_UNI', '')), 'KEYS' => array('qid' => array('INDEX', 'question_id'))), $this->table_qa_confirm => array('COLUMNS' => array('session_id' => array('CHAR:32', ''), 'confirm_id' => array('CHAR:32', ''), 'lang_iso' => array('VCHAR:30', ''), 'question_id' => array('UINT', 0), 'attempts' => array('UINT', 0), 'confirm_type' => array('USINT', 0)), 'KEYS' => array('session_id' => array('INDEX', 'session_id'), 'lookup' => array('INDEX', array('confirm_id', 'session_id', 'lang_iso'))), 'PRIMARY_KEY' => 'confirm_id')); foreach ($schemas as $table => $schema) { if (!$db_tool->sql_table_exists($table)) { $db_tool->sql_create_table($table, $schema); } } }
$sql = 'DESCRIBE ' . POSTS_TABLE . ' post_text'; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $mysql_indexer = $drop_index = false; if (strtolower($row['Type']) === 'mediumtext') { $mysql_indexer = true; } if (strtolower($row['Key']) === 'mul') { $drop_index = true; } echo "USE {$dbname};{$newline}{$newline}"; @set_time_limit(0); require $phpbb_root_path . 'includes/db/schema_data.' . $phpEx; require $phpbb_root_path . 'phpbb/db/tools.' . $phpEx; $dbms_type_map = phpbb\db\tools::get_dbms_type_map(); foreach ($schema_data as $table_name => $table_data) { $table_name = str_replace('phpbb_', $prefix, $table_name); // Write comment about table echo "# Table: '{$table_name}'{$newline}"; // Create Table statement $generator = $textimage = false; // Do we need to DROP a fulltext index before we alter the table? if ($table_name == $prefix . 'posts' && $drop_index) { echo "ALTER TABLE {$table_name}{$newline}"; echo "DROP INDEX post_text,{$newline}DROP INDEX post_subject,{$newline}DROP INDEX post_content;{$newline}{$newline}"; } $line = "ALTER TABLE {$table_name} {$newline}"; // Table specific so we don't get overlap $modded_array = array(); // Write columns one by one...
function load_schema_31($install_path = '', $install_dbms = false) { global $db, $settings, $table_prefix, $phpbb_root_path, $phpEx; static $available_dbms = false; if ($install_dbms === false) { $dbms = $settings->get_config('dbms'); $install_dbms = $dbms; } if (!$available_dbms) { $available_dbms = get_available_dbms($install_dbms); // If mysql is chosen, we need to adjust the schema filename slightly to reflect the correct version. ;) if ($install_dbms == 'mysql') { if (version_compare($db->sql_server_info(true), '4.1.3', '>=')) { $available_dbms[$install_dbms]['SCHEMA'] .= '_41'; } else { $available_dbms[$install_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 = $install_path . $available_dbms[$install_dbms]['SCHEMA'] . '_schema.sql'; // How should we treat this schema? $delimiter = $available_dbms[$install_dbms]['DELIM']; if (file_exists($dbms_schema)) { $sql_query = file_get_contents($dbms_schema); $sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query); $sql_query = phpbb_remove_comments($sql_query); $sql_query = split_sql_file($sql_query, $delimiter); foreach ($sql_query as $sql) { $db->sql_query($sql); } unset($sql_query); } // Ok we have the db info go ahead and work on building the table if (file_exists($install_path . 'schema.json')) { $db_table_schema = file_get_contents($install_path . 'schema.json'); $db_table_schema = json_decode($db_table_schema, true); } else { $table_prefix = 'phpbb_'; if (!defined('CONFIG_TABLE')) { // We need to include the constants file for the table constants // when we generate the schema from the migration files. include $phpbb_root_path . 'includes/constants.' . $phpEx; } $finder = new \phpbb\finder(new \phpbb\filesystem(), $phpbb_root_path, null, $phpEx); $classes = $finder->core_path('phpbb/db/migration/data/')->get_classes(); $sqlite_db = new \phpbb\db\driver\sqlite(); $schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $sqlite_db, new \phpbb\db\tools($sqlite_db, true), $phpbb_root_path, $phpEx, $table_prefix); $db_table_schema = $schema_generator->get_schema(); } if (!defined('CONFIG_TABLE')) { // CONFIG_TABLE is required by sql_create_index() to check the // length of index names. However table_prefix is not defined // here yet, so we need to create the constant ourselves. define('CONFIG_TABLE', $table_prefix . 'config'); } $db_tools = new \phpbb\db\tools($db); foreach ($db_table_schema as $table_name => $table_data) { $db_tools->sql_create_table($table_prefix . substr($table_name, 6), $table_data); } // Ok tables have been built, let's fill in the basic information $sql_query = file_get_contents($install_path . 'schema_data.sql'); // Deal with any special comments and characters switch ($install_dbms) { case 'mssql': case 'mssql_odbc': case 'mssqlnative': $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; case 'mysql': case 'mysqli': $sql_query = str_replace('\\', '\\\\', $sql_query); break; } // Change prefix $sql_query = preg_replace('# phpbb_([^\\s]*) #i', ' ' . $table_prefix . '\\1 ', $sql_query); // Change language strings... $sql_query = preg_replace_callback('#\\{L_([A-Z0-9\\-_]*)\\}#s', 'adjust_language_keys_callback', $sql_query); $sql_query = phpbb_remove_comments($sql_query); $sql_query = split_sql_file($sql_query, ';'); foreach ($sql_query as $sql) { $db->sql_query($sql); } unset($sql_query); }
/** * Get tables of a database * * @deprecated */ function get_tables(&$db) { $db_tools = new \phpbb\db\tools($db); return $db_tools->sql_list_tables(); }
public static function top10($start = 0, $uaction = '') { global $db, $config, $sconfig, $user, $table_prefix, $tables, $request, $template, $phpbb_container; $module_aray = array(0 => 'COUNTRIES', 1 => 'REFERRALS', 2 => 'SEARCHENG', 3 => 'SEARCHTERMS', 4 => 'BROWSERS', 5 => 'CRAWLERS', 6 => 'SYSTEMS', 7 => 'MODULES', 8 => 'RESOLUTIONS', 9 => 'USERS', 10 => 'FL_DATE', 11 => 'POSTS', 12 => 'UNIQUE'); $modules = self::get_modules(); $db_tools = new \phpbb\db\tools($db); $searchresulttabel = $db_tools->sql_table_exists($table_prefix . 'searchresults'); $sql_aray[] = 'SELECT d.description AS name, o.hits FROM ' . $tables['archive'] . ' o LEFT JOIN ' . $tables['domain'] . ' d ON (d.domain = o.name) WHERE cat = 4 GROUP BY o.name ORDER BY hits DESC'; $sql_aray[] = 'SELECT name, hits FROM ' . $tables['archive'] . ' WHERE cat = 7 ORDER BY hits DESC'; $sql_aray[] = 'SELECT name, hits FROM ' . $tables['archive'] . ' WHERE cat = 7 ORDER BY hits DESC'; $sql_aray[] = 'SELECT name, hits FROM ' . $tables['archive'] . ' WHERE cat = 8 ORDER BY hits DESC'; $sql_aray[] = 'SELECT name, hits FROM ' . $tables['archive'] . ' WHERE cat = 2 ORDER BY hits DESC'; $sql_aray[] = 'SELECT a.name, a.hits FROM ' . $tables['archive'] . ' a LEFT JOIN ' . BOTS_TABLE . ' b ON a.name = b.bot_name WHERE a.cat = 5 AND b.bot_name IS NOT NULL ORDER BY hits DESC'; $sql_aray[] = 'SELECT name, hits FROM ' . $tables['archive'] . ' WHERE cat = 3 ORDER BY hits DESC'; $sql_aray[] = 'SELECT name, hits FROM ' . $tables['archive'] . ' WHERE cat = 1 ORDER BY hits DESC'; $sql_aray[] = 'SELECT name, hits FROM ' . $tables['archive'] . ' WHERE cat = 6 ORDER BY hits DESC'; $sql_aray[] = 'SELECT a.name, a.hits FROM ' . $tables['archive'] . ' a LEFT JOIN ' . USERS_TABLE . ' b ON a.name = b.username WHERE a.cat = 5 AND b.username IS NOT NULL ORDER BY hits DESC'; $sql_aray[] = 'SELECT "First startdate" AS name, MIN(first) AS hits FROM ' . $tables['archive'] . ' UNION SELECT "Last startdate" AS name, MAX(last) AS hits FROM ' . $tables['archive'] . ' UNION SELECT "Rows" AS name, ROUND(COUNT(id), 0) AS hits FROM ' . $tables['archive'] . ' UNION SELECT "Table size" AS name, CASE WHEN data_length + index_length < 1024 THEN CONCAT(ROUND(((data_length + index_length)), 1), " B") WHEN data_length + index_length BETWEEN 1024 AND 1048576 THEN CONCAT(ROUND(((data_length + index_length) / 1024), 1), " Kb") WHEN data_length + index_length > 1048576 THEN CONCAT(ROUND(((data_length + index_length) / 1024 / 1024), 1), " Mb") END AS hits FROM information_schema.TABLES WHERE table_schema = "' . $db->get_db_name() . '" AND table_name = "' . $tables['archive'] . '"' . ($searchresulttabel ? ' UNION SELECT "Searchwords" AS name, COUNT(search_key) AS hits FROM ' . $table_prefix . 'searchresults' : ''); $sql_aray[] = ''; $sql_aray[] = 'SELECT name, hits FROM ' . $tables['archive'] . ' WHERE cat = 9 ORDER BY hits DESC'; $pagination = $phpbb_container->get('pagination'); $base_url = $uaction . '&screen=top10'; $pagination->generate_template_pagination($base_url, 'pagination', 'start', 13, 6, $start); for ($i = $start; $i < min($start + 6, sizeof($module_aray)); $i++) { $template->assign_block_vars('blocks', array('KEY' => $i, 'TITLE' => $user->lang[$module_aray[$i]])); if ($i < 12) { $result = $db->sql_query_limit($sql_aray[$i], 10, 0); $counter = 0; while ($row = $db->sql_fetchrow($result)) { $counter += 1; $template->assign_block_vars('blocks.block', array('COUNTER' => $counter, 'NAME' => $i == 7 ? isset($modules[$row['name']]) ? $modules[$row['name']] : 'Not found' : $row['name'], 'HITS' => $i == 10 && isset($row['hits']) && $counter < 3 ? $user->format_date($row['hits'], 'd m \'y') : self::roundk($row['hits']), 'THITS' => $i == 10 && isset($row['hits']) && $counter < 3 ? $user->format_date($row['hits']) : $row['hits'])); } if ($counter < 10) { for ($counter + 1; $counter + 1 <= 10; $counter++) { if ($i == 11) { $aray[0] = array('name' => 'Posts per day', 'hits' => round($config['num_posts'] / ((time() - $config['board_startdate']) / 86400), 1)); $aray[1] = array('name' => 'Posts per month', 'hits' => round($config['num_posts'] / ((time() - $config['board_startdate']) / 2440800), 1)); $aray[2] = array('name' => 'Topics per day', 'hits' => round($config['num_topics'] / ((time() - $config['board_startdate']) / 86400), 1)); $aray[3] = array('name' => 'Topics per month', 'hits' => round($config['num_topics'] / ((time() - $config['board_startdate']) / 2440800), 1)); $aray[4] = array('name' => 'Forumdays', 'hits' => floor((time() - $config['board_startdate']) / 86400)); $aray[5] = array('name' => 'Average posts per topic', 'hits' => floor($config['num_posts'] / $config['num_topics'])); $aray[6] = array('name' => 'Average posts per user', 'hits' => floor($config['num_posts'] / $config['num_users'])); } $template->assign_block_vars('blocks.block', array('COUNTER' => $counter + 1, 'NAME' => $i == 11 && isset($aray[$counter]) ? $aray[$counter]['name'] : '', 'HITS' => $i == 11 && isset($aray[$counter]) ? $aray[$counter]['hits'] : '')); } } } else { $result = $db->sql_query_limit($sql_aray[$i], 10, 0); $counter = 0; while ($row = $db->sql_fetchrow($result)) { $counter += 1; $template->assign_block_vars('blocks.block', array('COUNTER' => $counter, 'NAME' => $user->format_date($row['name'], 'd F \'y'), 'HITS' => self::roundk($row['hits']), 'THITS' => $row['hits'])); } } } $template->assign_vars(array('U_ACTION' => $uaction, 'SUB_DISPLAY' => 'top10')); }
public function effectively_installed() { // This handles upgrades from the phpBB Digests mod for phpBB 3.0.x to this extension, allowing configuration and user settings to be preserved // if possible. Versions 2.2.6 through 2.2.27 are supported. global $user, $cache, $phpbb_root_path, $phpEx; $user->add_lang_ext('phpbbservices/digests', array('info_acp_common', 'common')); if (!$this->config['digests_version']) { return false; // Digests not previously installed, so go ahead and do a clean install } // If the version of the digests mod is old (prior to 2.2.6, the first officially approved digests mod for 3.0) or is more than the last version // 2.2.27 then this migrator cannot be used. if (version_compare($this->config['digests_version'], '2.2.6') === -1 && version_compare($this->config['digests_version'], '2.2.27') === 1) { $message_type = E_USER_WARNING; trigger_error($user->lang('DIGESTS_MIGRATE_UNSUPPORTED_VERSION', $this->config['digests_version']), $message_type); return false; } // To upgrade from 2.2.6 or greater, the basic approach is to compare arrays of configuration variables and database column names. // Remove what has gone away, add what is missing. // Load the new configuration values array $new_config = array('digests_block_images' => 0, 'digests_cron_task_last_gc' => 0, 'digests_cron_task_gc' => 60 * 60, 'digests_custom_stylesheet_path' => 'prosilver/theme/digest_stylesheet.css', 'digests_enable_auto_subscriptions' => 0, 'digests_enable_custom_stylesheets' => 0, 'digests_enable_log' => 0, 'digests_enable_subscribe_unsubscribe' => '0', 'digests_exclude_forums' => '0', 'digests_from_email_name' => '', 'digests_from_email_address' => '', 'digests_host' => 'phpbbservices.com', 'digests_include_admins' => '0', 'digests_include_forums' => '0', 'digests_max_items' => 0, 'digests_notify_on_admin_changes', '1', 'digests_page_url' => 'https://phpbbservices.com/digests_wp/', 'digests_registration_field' => 0, 'digests_reply_to_email_address' => '', 'digests_show_email' => 0, 'digests_subscribe_all' => '1', 'digests_test' => 0, 'digests_test_clear_spool' => 1, 'digests_test_day' => 1, 'digests_test_email_address' => '', 'digests_test_hour' => 0, 'digests_test_month' => 1, 'digests_test_send_to_admin' => 0, 'digests_test_spool' => 0, 'digests_test_time_use' => 0, 'digests_test_year' => 2016, 'digests_time_zone' => make_tz_offset($this->config['board_timezone']), 'digests_user_check_all_forums' => 1, 'digests_user_digest_attachments' => 1, 'digests_user_digest_block_images' => 0, 'digests_user_digest_filter_type' => 'ALL', 'digests_user_digest_format' => 'HTML', 'digests_user_digest_max_display_words' => -1, 'digests_user_digest_max_posts' => 0, 'digests_user_digest_min_words' => 0, 'digests_user_digest_new_posts_only' => 0, 'digests_user_digest_no_post_text' => 0, 'digests_user_digest_pm_mark_read' => 0, 'digests_user_digest_registration' => 0, 'digests_user_digest_remove_foes' => 0, 'digests_user_digest_reset_lastvisit' => 0, 'digests_user_digest_send_hour_gmt' => -1, 'digests_user_digest_send_on_no_posts' => 0, 'digests_user_digest_show_mine' => 1, 'digests_user_digest_show_pms' => 1, 'digests_user_digest_sortby' => 'board', 'digests_user_digest_toc' => 0, 'digests_user_digest_type' => 'DAY', 'digests_users_per_page' => 20, 'digests_weekly_digest_day' => 0); $remove_config = array(); // If the old configuration value exists, keep its value but it must change its name to add the vendor name as a prefix foreach ($this->config as $key => $value) { if (substr($key, 0, 8) == 'digests_') { if (array_key_exists($key, $new_config)) { // add the new config value with vendor in the config_name $this->config->set('phpbbservices_' . $key, $value); } // mark the old config value for deletion once outside of the loop $remove_config[] = $key; } } // Remove the old configuration variables, i.e. digests_* rather than phpbbservices_digests_* foreach ($remove_config as $key => $value) { $this->config->delete($value); } // Add in any new configuration variables using the defaults. These were introduced by later versions of digests or are new in the extension // and all must have phpbbservices_ as a prefix. foreach ($new_config as $key => $value) { if (array_key_exists($key, $this->config) === false) { $this->config->set('phpbbservices_' . $key, $value); } } // Modify problematic configuration variables explicitly. The digests page is now in Wordpress. $this->config->set('phpbbservices_digests_page_url', 'https://phpbbservices.com/digests_wp/'); // ----- Fix users table ----- // $new_columns = array('user_digest_attachments' => array('TINT:4', 1), 'user_digest_block_images' => array('TINT:4', 0), 'user_digest_filter_type' => array('VCHAR:3', 'ALL'), 'user_digest_format' => array('VCHAR:4', 'HTML'), 'user_digest_has_unsubscribed' => array('TINT:4', 0), 'user_digest_last_sent' => array('UINT:11', 0), 'user_digest_max_display_words' => array('INT:4', 0), 'user_digest_max_posts' => array('UINT', 0), 'user_digest_min_words' => array('UINT', 0), 'user_digest_new_posts_only' => array('TINT:4', 0), 'user_digest_no_post_text' => array('TINT:4', 0), 'user_digest_pm_mark_read' => array('TINT:4', 0), 'user_digest_remove_foes' => array('TINT:4', 0), 'user_digest_reset_lastvisit' => array('TINT:4', 1), 'user_digest_send_hour_gmt' => array('DECIMAL', '0.00'), 'user_digest_send_on_no_posts' => array('TINT:4', 0), 'user_digest_show_mine' => array('TINT:4', 1), 'user_digest_show_pms' => array('TINT:4', 1), 'user_digest_sortby' => array('VCHAR:13', 'board'), 'user_digest_toc' => array('TINT:4', 0), 'user_digest_type' => array('VCHAR:4', 'NONE')); // Get a succinct array of new column names without metadata to make it easier to find missing columns $new_column_names = array_keys($new_columns); $found_digest_columns = array(); // The tools class has some convenient methods we will use to add and remove columns $tools = new \phpbb\db\tools($this->db); // Get a list of the current columns in the phpbb_users table. $user_table_columns = array_keys($tools->sql_list_columns($this->table_prefix . 'users')); // Note the columns found that start with "user_digest_" foreach ($user_table_columns as $key => $value) { if (substr($value, 0, 12) == 'user_digest_') { $found_digest_columns[] = $value; } } // Delete those columns in the phpbb_users table for digests that are no longer used $columns_to_remove = array_diff($found_digest_columns, $new_column_names); foreach ($columns_to_remove as $key => $value) { $tools->sql_column_remove($this->table_prefix . 'users', $value); } // Add those digest columns to the phpbb_users table were not in the version of the mod previously installed $columns_to_add = array_diff($new_column_names, $found_digest_columns); foreach ($columns_to_add as $key => $value) { $tools->sql_column_add($this->table_prefix . 'users', $value, array($new_columns[$value][0], $new_columns[$value][1])); } // ----- Remove old ACP Modules ----- // // Use the module class to conveniently remove dead modules as well as add new ones $modules_table = $this->table_prefix . 'modules'; $modules_tool = new \phpbb\db\migration\tool\module($this->db, $cache, $user, $phpbb_root_path, $phpEx, $modules_table); // Remove ACP modules if they exist. if ($modules_tool->exists('acp', 'ACP_DIGEST_SETTINGS', 'ACP_DIGEST_GENERAL_SETTINGS')) { $modules_tool->remove('acp', 'ACP_DIGEST_SETTINGS', 'ACP_DIGEST_GENERAL_SETTINGS'); } if ($modules_tool->exists('acp', 'ACP_DIGEST_SETTINGS', 'ACP_DIGEST_USER_DEFAULT_SETTINGS')) { $modules_tool->remove('acp', 'ACP_DIGEST_SETTINGS', 'ACP_DIGEST_USER_DEFAULT_SETTINGS'); } if ($modules_tool->exists('acp', 'ACP_DIGEST_SETTINGS', 'ACP_DIGEST_EDIT_SUBSCRIBERS')) { $modules_tool->remove('acp', 'ACP_DIGEST_SETTINGS', 'ACP_DIGEST_EDIT_SUBSCRIBERS'); } if ($modules_tool->exists('acp', 'ACP_DIGEST_SETTINGS', 'ACP_DIGEST_BALANCE_LOAD')) { $modules_tool->remove('acp', 'ACP_DIGEST_SETTINGS', 'ACP_DIGEST_BALANCE_LOAD'); } if ($modules_tool->exists('acp', 'ACP_DIGEST_SETTINGS', 'ACP_DIGEST_MASS_SUBSCRIBE_UNSUBSCRIBE')) { $modules_tool->remove('acp', 'ACP_DIGEST_SETTINGS', 'ACP_DIGEST_MASS_SUBSCRIBE_UNSUBSCRIBE'); } // Remove the digests ACP module category, originally on the general tab. It will move to the extensions tab. if ($modules_tool->exists('acp', 'ACP_CAT_GENERAL', 'ACP_DIGEST_SETTINGS')) { $modules_tool->remove('acp', 'ACP_CAT_GENERAL', 'ACP_DIGEST_SETTINGS'); } // ----- Remove UCP modules ----- // if ($modules_tool->exists('ucp', 'UCP_DIGESTS', 'UCP_DIGESTS_BASICS')) { $modules_tool->remove('ucp', 'UCP_DIGESTS', 'UCP_DIGESTS_BASICS'); } if ($modules_tool->exists('ucp', 'UCP_DIGESTS', 'UCP_DIGESTS_POSTS_SELECTION')) { $modules_tool->remove('ucp', 'UCP_DIGESTS', 'UCP_DIGESTS_POSTS_SELECTION'); } if ($modules_tool->exists('ucp', 'UCP_DIGESTS', 'UCP_DIGESTS_FORUMS_SELECTION')) { $modules_tool->remove('ucp', 'UCP_DIGESTS', 'UCP_DIGESTS_FORUMS_SELECTION'); } if ($modules_tool->exists('ucp', 'UCP_DIGESTS', 'UCP_DIGESTS_POST_FILTERS')) { $modules_tool->remove('ucp', 'UCP_DIGESTS', 'UCP_DIGESTS_POST_FILTERS'); } if ($modules_tool->exists('ucp', 'UCP_DIGESTS', 'UCP_DIGESTS_ADDITIONAL_CRITERIA')) { $modules_tool->remove('ucp', 'UCP_DIGESTS', 'UCP_DIGESTS_ADDITIONAL_CRITERIA'); } // Remove the digests UCP module category if ($modules_tool->exists('ucp', 0, 'UCP_DIGESTS')) { $modules_tool->remove('ucp', 0, 'UCP_DIGESTS'); } // ----- Add New ACP Modules ----- // // We need the module_id for the extensions tab to add a new category for Digests within the ACP $sql_array = array('SELECT' => 'module_id', 'FROM' => array($this->table_prefix . 'modules' => 'm'), 'WHERE' => "module_langname = 'ACP_CAT_DOT_MODS'"); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $rowset = $this->db->sql_fetchrowset($result); $module_id = $rowset[0]['module_id']; $this->db->sql_freeresult(); // Add Digests category $modules_tool->add('acp', 'ACP_CAT_DOT_MODS', array('module_enabled' => 1, 'module_display' => 1, 'module_basename' => '', 'module_class' => 'acp', 'parent_id' => (int) $module_id, 'module_langname' => 'ACP_CAT_DIGESTS', 'module_mode' => '', 'module_auth' => '')); // We need the module_id for the newly created Digests category //$sql = 'SELECT module_id FROM ' . $this->table_prefix . "modules WHERE module_langname = 'ACP_CAT_DIGESTS'"; $sql_array = array('SELECT' => 'module_id', 'FROM' => array($this->table_prefix . 'modules' => 'm'), 'WHERE' => "module_langname = 'ACP_CAT_DIGESTS'"); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $rowset = $this->db->sql_fetchrowset($result); $module_id = $rowset[0]['module_id']; $this->db->sql_freeresult(); // Add General Settings ACP module $modules_tool->add('acp', 'ACP_CAT_DIGESTS', array('module_enabled' => 1, 'module_display' => 1, 'module_basename' => '\\phpbbservices\\digests\\acp\\main_module', 'module_class' => 'acp', 'parent_id' => (int) $module_id, 'module_langname' => 'ACP_DIGESTS_GENERAL_SETTINGS', 'module_mode' => 'digests_general', 'module_auth' => 'ext_phpbbservices/digests && acl_a_board')); // Add User Default Settings ACP module $modules_tool->add('acp', 'ACP_CAT_DIGESTS', array('module_enabled' => 1, 'module_display' => 1, 'module_basename' => '\\phpbbservices\\digests\\acp\\main_module', 'module_class' => 'acp', 'parent_id' => (int) $module_id, 'module_langname' => 'ACP_DIGESTS_USER_DEFAULT_SETTINGS', 'module_mode' => 'digests_user_defaults', 'module_auth' => 'ext_phpbbservices/digests && acl_a_board')); // Add Edit Subscribers ACP module $modules_tool->add('acp', 'ACP_CAT_DIGESTS', array('module_enabled' => 1, 'module_display' => 1, 'module_basename' => '\\phpbbservices\\digests\\acp\\main_module', 'module_class' => 'acp', 'parent_id' => (int) $module_id, 'module_langname' => 'ACP_DIGESTS_EDIT_SUBSCRIBERS', 'module_mode' => 'digests_edit_subscribers', 'module_auth' => 'ext_phpbbservices/digests && acl_a_board')); // Add Balance Load ACP module $modules_tool->add('acp', 'ACP_CAT_DIGESTS', array('module_enabled' => 1, 'module_display' => 1, 'module_basename' => '\\phpbbservices\\digests\\acp\\main_module', 'module_class' => 'acp', 'parent_id' => (int) $module_id, 'module_langname' => 'ACP_DIGESTS_BALANCE_LOAD', 'module_mode' => 'digests_balance_load', 'module_auth' => 'ext_phpbbservices/digests && acl_a_board')); // Add Mass subscribe/unsubscribe ACP module $modules_tool->add('acp', 'ACP_CAT_DIGESTS', array('module_enabled' => 1, 'module_display' => 1, 'module_basename' => '\\phpbbservices\\digests\\acp\\main_module', 'module_class' => 'acp', 'parent_id' => (int) $module_id, 'module_langname' => 'ACP_DIGESTS_MASS_SUBSCRIBE_UNSUBSCRIBE', 'module_mode' => 'digests_mass_subscribe_unsubscribe', 'module_auth' => 'ext_phpbbservices/digests && acl_a_board')); // Add Digests Tests ACP module $modules_tool->add('acp', 'ACP_CAT_DIGESTS', array('module_enabled' => 1, 'module_display' => 1, 'module_basename' => '\\phpbbservices\\digests\\acp\\main_module', 'module_class' => 'acp', 'parent_id' => (int) $module_id, 'module_langname' => 'ACP_DIGESTS_TEST', 'module_mode' => 'digests_test', 'module_auth' => 'ext_phpbbservices/digests && acl_a_board')); // ----- Add New UCP Modules ----- // // Add Digests category $modules_tool->add('ucp', 0, array('module_enabled' => 1, 'module_display' => 1, 'module_basename' => '', 'module_class' => 'ucp', 'parent_id' => 0, 'module_langname' => 'UCP_DIGESTS', 'module_mode' => '', 'module_auth' => 'ext_phpbbservices/digest')); // We need the module_id for the new Digests category $sql_array = array('SELECT' => 'module_id', 'FROM' => array($this->table_prefix . 'modules' => 'm'), 'WHERE' => "module_langname = 'UCP_DIGESTS'"); $sql = $this->db->sql_build_query('SELECT', $sql_array); $result = $this->db->sql_query($sql); $rowset = $this->db->sql_fetchrowset($result); $module_id = $rowset[0]['module_id']; $this->db->sql_freeresult(); // Add Digests basics UCP module $modules_tool->add('ucp', 'UCP_DIGESTS', array('module_enabled' => 1, 'module_display' => 1, 'module_basename' => '\\phpbbservices\\digests\\ucp\\main_module', 'module_class' => 'ucp', 'parent_id' => (int) $module_id, 'module_langname' => 'UCP_DIGESTS_BASICS', 'module_mode' => 'basics', 'module_auth' => 'ext_phpbbservices/digests')); // Add Digests forums selection UCP module $modules_tool->add('ucp', 'UCP_DIGESTS', array('module_enabled' => 1, 'module_display' => 1, 'module_basename' => '\\phpbbservices\\digests\\ucp\\main_module', 'module_class' => 'ucp', 'parent_id' => (int) $module_id, 'module_langname' => 'UCP_DIGESTS_FORUMS_SELECTION', 'module_mode' => 'forums_selection', 'module_auth' => 'ext_phpbbservices/digests')); // Add Digests post filters UCP module $modules_tool->add('ucp', 'UCP_DIGESTS', array('module_enabled' => 1, 'module_display' => 1, 'module_basename' => '\\phpbbservices\\digests\\ucp\\main_module', 'module_class' => 'ucp', 'parent_id' => (int) $module_id, 'module_langname' => 'UCP_DIGESTS_POST_FILTERS', 'module_mode' => 'post_filters', 'module_auth' => 'ext_phpbbservices/digests')); // Add Digests additional criteria UCP module $modules_tool->add('ucp', 'UCP_DIGESTS', array('module_enabled' => 1, 'module_display' => 1, 'module_basename' => '\\phpbbservices\\digests\\ucp\\main_module', 'module_class' => 'ucp', 'parent_id' => (int) $module_id, 'module_langname' => 'UCP_DIGESTS_ADDITIONAL_CRITERIA', 'module_mode' => 'additional_criteria', 'module_auth' => 'ext_phpbbservices/digests')); // At this point we should be effectively installed. All the configuration variable for digests, columns in the users table for digests, and ACP and UCP // categories and modules exist and behave exactly as if a fresh install of this extension were made. All the phpBB 3.0 mod detritus should be gone. // Any digest cron that was set up will need to be removed manually, however. return true; }
/** * 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, $request; $this->page_title = $lang['STAGE_CREATE_TABLE']; $s_hidden_fields = ''; // Obtain any submitted data $data = $this->get_submitted_data(); if ($data['dbms'] == '') { // Someone's been silly and tried calling this page direct // So we send them back to the start to do it again properly $this->p_master->redirect("index.{$phpEx}?mode=install"); } // HTTP_HOST is having the correct browser url in most cases... $server_name = strtolower(htmlspecialchars_decode($request->header('Host', $request->server('SERVER_NAME')))); $referer = strtolower($request->header('Referer')); // HTTP HOST can carry a port number... if (strpos($server_name, ':') !== false) { $server_name = substr($server_name, 0, strpos($server_name, ':')); } $cookie_domain = $data['server_name'] != '' ? $data['server_name'] : $server_name; // Try to come up with the best solution for cookie domain... if (strpos($cookie_domain, 'www.') === 0) { $cookie_domain = str_replace('www.', '.', $cookie_domain); } // 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); // If mysql is chosen, we need to adjust the schema filename slightly to reflect the correct version. ;) if ($data['dbms'] == 'mysql') { if (version_compare($db->sql_server_info(true), '4.1.3', '>=')) { $available_dbms[$data['dbms']]['SCHEMA'] .= '_41'; } else { $available_dbms[$data['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[$data['dbms']]['SCHEMA'] . '_schema.sql'; // How should we treat this schema? $delimiter = $available_dbms[$data['dbms']]['DELIM']; if (file_exists($dbms_schema)) { $sql_query = @file_get_contents($dbms_schema); $sql_query = preg_replace('#phpbb_#i', $data['table_prefix'], $sql_query); $sql_query = phpbb_remove_comments($sql_query); $sql_query = split_sql_file($sql_query, $delimiter); foreach ($sql_query as $sql) { // Ignore errors when the functions or types already exist // to allow installing phpBB twice in the same database with // a different prefix $db->sql_query($sql); } unset($sql_query); } // Ok we have the db info go ahead and work on building the table if (file_exists('schemas/schema.json')) { $db_table_schema = @file_get_contents('schemas/schema.json'); $db_table_schema = json_decode($db_table_schema, true); } else { global $phpbb_root_path, $phpEx, $table_prefix; $table_prefix = 'phpbb_'; if (!defined('CONFIG_TABLE')) { // We need to include the constants file for the table constants // when we generate the schema from the migration files. include $phpbb_root_path . 'includes/constants.' . $phpEx; } $finder = new \phpbb\finder(new \phpbb\filesystem(), $phpbb_root_path, null, $phpEx); $classes = $finder->core_path('phpbb/db/migration/data/')->get_classes(); $sqlite_db = new \phpbb\db\driver\sqlite(); $schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $sqlite_db, new \phpbb\db\tools($sqlite_db, true), $phpbb_root_path, $phpEx, $table_prefix); $db_table_schema = $schema_generator->get_schema(); } if (!defined('CONFIG_TABLE')) { // CONFIG_TABLE is required by sql_create_index() to check the // length of index names. However table_prefix is not defined // here yet, so we need to create the constant ourselves. define('CONFIG_TABLE', $data['table_prefix'] . 'config'); } $db_tools = new \phpbb\db\tools($db); foreach ($db_table_schema as $table_name => $table_data) { $db_tools->sql_create_table($data['table_prefix'] . substr($table_name, 6), $table_data); } // 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 and characters switch ($data['dbms']) { case 'mssql': case 'mssql_odbc': case 'mssqlnative': $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; case 'mysql': case 'mysqli': $sql_query = str_replace('\\', '\\\\', $sql_query); break; } // Change prefix $sql_query = preg_replace('# phpbb_([^\\s]*) #i', ' ' . $data['table_prefix'] . '\\1 ', $sql_query); // Change language strings... $sql_query = preg_replace_callback('#\\{L_([A-Z0-9\\-_]*)\\}#s', 'adjust_language_keys_callback', $sql_query); $sql_query = phpbb_remove_comments($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); $current_time = time(); $user_ip = $request->server('REMOTE_ADDR') ? phpbb_ip_normalise($request->server('REMOTE_ADDR')) : ''; if ($data['script_path'] !== '/') { // Adjust destination path (no trailing slash) if (substr($data['script_path'], -1) == '/') { $data['script_path'] = substr($data['script_path'], 0, -1); } $data['script_path'] = str_replace(array('../', './'), '', $data['script_path']); if ($data['script_path'][0] != '/') { $data['script_path'] = '/' . $data['script_path']; } } // Set default config and post data, this applies to all DB's $sql_ary = array('INSERT INTO ' . $data['table_prefix'] . "config (config_name, config_value)\n\t\t\t\tVALUES ('board_startdate', '{$current_time}')", 'INSERT INTO ' . $data['table_prefix'] . "config (config_name, config_value)\n\t\t\t\tVALUES ('default_lang', '" . $db->sql_escape($data['default_lang']) . "')", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['img_imagick']) . "'\n\t\t\t\tWHERE config_name = 'img_imagick'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['server_name']) . "'\n\t\t\t\tWHERE config_name = 'server_name'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['server_port']) . "'\n\t\t\t\tWHERE config_name = 'server_port'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['board_email']) . "'\n\t\t\t\tWHERE config_name = 'board_email'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['board_email']) . "'\n\t\t\t\tWHERE config_name = 'board_contact'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($cookie_domain) . "'\n\t\t\t\tWHERE config_name = 'cookie_domain'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($lang['default_dateformat']) . "'\n\t\t\t\tWHERE config_name = 'default_dateformat'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['email_enable']) . "'\n\t\t\t\tWHERE config_name = 'email_enable'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['smtp_delivery']) . "'\n\t\t\t\tWHERE config_name = 'smtp_delivery'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['smtp_host']) . "'\n\t\t\t\tWHERE config_name = 'smtp_host'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['smtp_auth']) . "'\n\t\t\t\tWHERE config_name = 'smtp_auth_method'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['smtp_user']) . "'\n\t\t\t\tWHERE config_name = 'smtp_username'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['smtp_pass']) . "'\n\t\t\t\tWHERE config_name = 'smtp_password'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['cookie_secure']) . "'\n\t\t\t\tWHERE config_name = 'cookie_secure'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['force_server_vars']) . "'\n\t\t\t\tWHERE config_name = 'force_server_vars'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['script_path']) . "'\n\t\t\t\tWHERE config_name = 'script_path'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['server_protocol']) . "'\n\t\t\t\tWHERE config_name = 'server_protocol'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($data['admin_name']) . "'\n\t\t\t\tWHERE config_name = 'newest_username'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . md5(mt_rand()) . "'\n\t\t\t\tWHERE config_name = 'avatar_salt'", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . md5(mt_rand()) . "'\n\t\t\t\tWHERE config_name = 'plupload_salt'", 'UPDATE ' . $data['table_prefix'] . "users\n\t\t\t\tSET username = '******'admin_name']) . "', user_password='******'admin_pass1'])) . "', user_ip = '" . $db->sql_escape($user_ip) . "', user_lang = '" . $db->sql_escape($data['default_lang']) . "', user_email='" . $db->sql_escape($data['board_email']) . "', user_dateformat='" . $db->sql_escape($lang['default_dateformat']) . "', user_email_hash = " . $db->sql_escape(phpbb_email_hash($data['board_email'])) . ", username_clean = '" . $db->sql_escape(utf8_clean_string($data['admin_name'])) . "'\n\t\t\t\tWHERE username = '******'", 'UPDATE ' . $data['table_prefix'] . "moderator_cache\n\t\t\t\tSET username = '******'admin_name']) . "'\n\t\t\t\tWHERE username = '******'", 'UPDATE ' . $data['table_prefix'] . "forums\n\t\t\t\tSET forum_last_poster_name = '" . $db->sql_escape($data['admin_name']) . "'\n\t\t\t\tWHERE forum_last_poster_name = 'Admin'", 'UPDATE ' . $data['table_prefix'] . "topics\n\t\t\t\tSET topic_first_poster_name = '" . $db->sql_escape($data['admin_name']) . "', topic_last_poster_name = '" . $db->sql_escape($data['admin_name']) . "'\n\t\t\t\tWHERE topic_first_poster_name = 'Admin'\n\t\t\t\t\tOR topic_last_poster_name = 'Admin'", 'UPDATE ' . $data['table_prefix'] . "users\n\t\t\t\tSET user_regdate = {$current_time}", 'UPDATE ' . $data['table_prefix'] . "posts\n\t\t\t\tSET post_time = {$current_time}, poster_ip = '" . $db->sql_escape($user_ip) . "'", 'UPDATE ' . $data['table_prefix'] . "topics\n\t\t\t\tSET topic_time = {$current_time}, topic_last_post_time = {$current_time}", 'UPDATE ' . $data['table_prefix'] . "forums\n\t\t\t\tSET forum_last_post_time = {$current_time}", 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '" . $db->sql_escape($db->sql_server_info(true)) . "'\n\t\t\t\tWHERE config_name = 'dbms_version'"); if (@extension_loaded('gd')) { $sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = 'core.captcha.plugins.gd'\n\t\t\t\tWHERE config_name = 'captcha_plugin'"; $sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '1'\n\t\t\t\tWHERE config_name = 'captcha_gd'"; } $ref = substr($referer, strpos($referer, '://') + 3); if (!(stripos($ref, $server_name) === 0)) { $sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\t\tSET config_value = '0'\n\t\t\t\tWHERE config_name = 'referer_validation'"; } // We set a (semi-)unique cookie name to bypass login issues related to the cookie name. $cookie_name = 'phpbb3_'; $rand_str = md5(mt_rand()); $rand_str = str_replace('0', 'z', base_convert($rand_str, 16, 35)); $rand_str = substr($rand_str, 0, 5); $cookie_name .= strtolower($rand_str); $sql_ary[] = 'UPDATE ' . $data['table_prefix'] . "config\n\t\t\tSET config_value = '" . $db->sql_escape($cookie_name) . "'\n\t\t\tWHERE config_name = 'cookie_name'"; 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__); } } $submit = $lang['NEXT_STEP']; $url = $this->p_master->module_url . "?mode={$mode}&sub=final"; $template->assign_vars(array('BODY' => $lang['STAGE_CREATE_TABLE_EXPLAIN'], 'L_SUBMIT' => $submit, 'S_HIDDEN' => build_hidden_fields($data), 'U_ACTION' => $url)); }
function main($id, $mode) { global $config, $db, $user, $template, $request; global $phpbb_root_path, $phpbb_admin_path, $phpEx; global $phpbb_container; $this->config = $config; $this->core = $phpbb_container->get('phpbbseo.usu.core'); $this->db = $db; $this->request = $request; $this->template = $template; $this->user = $user; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $phpEx; $this->user->add_lang_ext('phpbbseo/usu', 'acp_usu'); $action = $this->request->variable('action', ''); $submit = $this->request->is_set_post('submit'); $cancel = $this->request->variable('cancel', ''); $form_key = 'acp_seo_usu'; add_form_key($form_key); $display_vars = array(); // --> Zero Dupe if (@isset($this->core->seo_opt['zero_dupe'])) { $this->multiple_options['zero_dupe']['post_redir_values'] = array('off' => 'off', 'post' => 'post', 'guest' => 'guest', 'all' => 'all'); // do not change $this->multiple_options['zero_dupe']['post_redir_lang'] = array('off' => $this->user->lang['ACP_ZERO_DUPE_OFF'], 'post' => $this->user->lang['ACP_ZERO_DUPE_MSG'], 'guest' => $this->user->lang['ACP_ZERO_DUPE_GUEST'], 'all' => $this->user->lang['ACP_ZERO_DUPE_ALL']); } // <-- Mod rewrite selector if ($this->core->modrtype == 1) { $this->seo_unset_opts = array('cache_layer', 'rem_ids'); } else { if (!$this->core->seo_opt['cache_layer']) { $this->seo_unset_opts = array('rem_ids'); } } $this->modrtype_lang = $this->set_phpbb_seo_links(); $this->multiple_options['modrtype_lang'] = $this->modrtype_lang['titles']; if (@isset($this->core->seo_opt['modrtype'])) { $this->multiple_options['modrtype_values'] = array(1 => 1, 2 => 2, 3 => 3); // do not change; } // <-- Mod rewrite selector foreach ($this->seo_unset_opts as $opt) { if ($optkey = array_search($opt, $this->core->cache_config['dynamic_options'])) { unset($this->core->cache_config['dynamic_options'][$optkey]); } } // We need shorter URLs with Virtual Folder Trick if ($this->core->seo_opt['virtual_folder']) { $this->lengh_limit = 20; $this->word_limit = 3; } else { $this->lengh_limit = 30; $this->word_limit = 5; } $related_installed = false; switch ($mode) { case 'settings': $display_vars['title'] = 'ACP_PHPBB_SEO_CLASS'; $this->user->lang['ACP_PHPBB_SEO_CLASS_EXPLAIN'] = sprintf($this->user->lang['ACP_PHPBB_SEO_CLASS_EXPLAIN'], $this->modrtype_lang['ulink'], $this->modrtype_lang['uforumlink'], '</p><hr/><p><b>' . $this->user->lang['ACP_PHPBB_SEO_MODE'] . ' : ' . $this->modrtype_lang['link'] . ' - ( ' . $this->modrtype_lang['forumlink'] . ' )</b></p><hr/><p>'); $display_vars['vars'] = array(); $i = 2; $display_vars['vars']['legend1'] = 'ACP_PHPBB_SEO_CLASS'; foreach ($this->core->cache_config['dynamic_options'] as $optionname => $optionvalue) { if (@is_bool($this->core->seo_opt[$optionvalue])) { if ($optionvalue == 'virtual_root') { if (!$this->core->seo_path['phpbb_script']) { continue; } if (empty($this->config['force_server_vars'])) { // we assume that the force server var will not break everything // since this is in use in all cases in USU set_config('force_server_vars', 1); } } $display_vars['vars'][$optionvalue] = array('lang' => $optionvalue, 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true, 'lang_explain' => $optionvalue . '_explain'); $this->new_config[$optionvalue] = $this->core->seo_opt[$optionvalue]; } else { if (@isset($this->multiple_options[$optionvalue . '_values'])) { $this->dyn_select[$optionvalue] = $this->multiple_options[$optionvalue . '_values']; $display_vars['vars'][$optionvalue] = array('lang' => $optionvalue, 'validate' => 'string', 'type' => 'select', 'method' => 'select_string', 'explain' => true, 'lang_explain' => $optionvalue . '_explain'); $this->new_config[$optionvalue] = $this->core->seo_opt[$optionvalue]; } else { if (is_array($optionvalue)) { $display_vars['vars']['legend' . $i] = $optionname; $i++; foreach ($optionvalue as $key => $value) { $this->array_type_cfg[$optionname . '_' . $key] = array('main' => $optionname, 'sub' => $key); if (is_bool($value)) { $display_vars['vars'][$optionname . '_' . $key] = array('lang' => $optionname . '_' . $key, 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true, 'lang_explain' => $optionname . '_' . $key . '_explain'); $this->new_config[$optionname . '_' . $key] = $this->core->seo_opt[$optionname][$key]; } else { if (@isset($this->multiple_options[$optionname][$key . '_values'])) { $this->dyn_select[$optionname . '_' . $key] = $this->multiple_options[$optionname][$key . '_values']; $display_vars['vars'][$optionname . '_' . $key] = array('lang' => $optionname . '_' . $key, 'validate' => 'string', 'type' => 'select', 'method' => 'select_string', 'explain' => true, 'lang_explain' => $optionname . '_' . $key . '_explain'); $this->new_config[$optionname . '_' . $key] = $this->core->seo_opt[$optionname][$key]; } else { $display_vars['vars'][$optionname . '_' . $key] = array('lang' => $optionname . '_' . $key, 'validate' => 'string:0:50', 'type' => 'text:50:50', 'explain' => true, 'lang_explain' => $optionname . '_' . $key . '_explain'); $this->new_config[$optionname . '_' . $key] = $this->core->seo_opt[$optionname][$key]; } } } } } } } break; case 'forum_url': $forbidden = array($this->core->seo_static['forum'], $this->core->seo_static['global_announce'], $this->core->seo_static['user'], $this->core->seo_static['topic'], $this->core->seo_static['atopic'], $this->core->seo_static['utopic'], $this->core->seo_static['leaders'], $this->core->seo_static['post'], $this->core->seo_static['group'], $this->core->seo_static['npost'], $this->core->seo_static['index']); if ($this->core->modrtype == 1 || !$this->core->seo_opt['cache_layer']) { trigger_error($this->user->lang['ACP_NO_FORUM_URL'] . preg_replace('`(&|&|\\?)mode=forum_url`i', '', adm_back_link($this->u_action))); break; } $display_vars['title'] = 'ACP_FORUM_URL'; $this->user->lang['ACP_FORUM_URL_EXPLAIN'] .= '</p><hr/><p><b>' . $this->user->lang['ACP_PHPBB_SEO_VERSION'] . ' : ' . $this->modrtype_lang['link'] . ' - ( ' . $this->modrtype_lang['forumlink'] . ' )</b></p><hr/><p>'; $display_vars['vars'] = array(); $display_vars['vars']['legend1'] = 'ACP_FORUM_URL'; $sql = "SELECT forum_id, forum_name\n\t\t\t\t\tFROM " . FORUMS_TABLE . "\n\t\t\t\t\tORDER BY left_id ASC"; $result = $this->db->sql_query($sql); $forum_url_title = $error_cust = ''; while ($row = $this->db->sql_fetchrow($result)) { $this->forum_ids[$row['forum_id']] = $row['forum_name']; } $this->db->sql_freeresult($result); // take care of deleted forums foreach ($this->core->cache_config['forum_urls'] as $fid => $null) { if (!isset($this->forum_ids[$fid])) { unset($this->core->cache_config['forum_urls'][$fid]); } } foreach ($this->forum_ids as $forum_id => $forum_name) { $error_cust = ''; // Is the URL cached already ? if (empty($this->core->cache_config['forum_urls'][$forum_id])) { // Suggest the one from the title $forum_url_title = $this->core->format_url($forum_name, $this->core->seo_static['forum']); if (!in_array($forum_url_title, $forbidden)) { if (array_search($forum_url_title, $this->core->cache_config['forum_urls'])) { $this->new_config['forum_url' . $forum_id] = $forum_url_title . $this->core->seo_delim['forum'] . $forum_id; $error_cust = '<li> ' . sprintf($this->user->lang['SEO_ADVICE_DUPE'], $forum_url_title) . '</li>'; } else { $this->new_config['forum_url' . $forum_id] = $forum_url_title . (@$this->core->cache_config['settings']['rem_ids'] ? '' : $this->core->seo_delim['forum'] . $forum_id); } } else { $this->new_config['forum_url' . $forum_id] = $forum_url_title . $this->core->seo_delim['forum'] . $forum_id; $error_cust = '<li> ' . sprintf($this->user->lang['SEO_ADVICE_RESERVED'], $forum_url_title) . '</li>'; } $title = '<b style="color:red">' . $forum_name . ' - ID ' . $forum_id . '</b>'; $status_msg = '<b style="color:red">' . $this->user->lang['SEO_CACHE_URL_NOT_OK'] . '</b>'; $status_msg .= '<br/><span style="color:red">' . $this->user->lang['SEO_CACHE_URL'] . ' :</span> ' . $this->new_config['forum_url' . $forum_id] . $this->core->seo_ext['forum']; $display_vars['vars']['forum_url' . $forum_id] = array('lang' => $title, 'validate' => 'string', 'type' => 'custom', 'method' => 'forum_url_input', 'explain' => true, 'lang_explain_custom' => $status_msg, 'append' => $this->seo_advices($this->new_config['forum_url' . $forum_id], $forum_id, false, $error_cust)); } else { // Cached $this->new_config['forum_url' . $forum_id] = $this->core->cache_config['forum_urls'][$forum_id]; $title = '<b style="color:green">' . $forum_name . ' - ID ' . $forum_id . '</b>'; $status_msg = '<span style="color:green">' . $this->user->lang['SEO_CACHE_URL_OK'] . ' :</span> <b style="color:green">' . $this->new_config['forum_url' . $forum_id] . '</b>'; $status_msg .= '<br/><span style="color:green">' . $this->user->lang['SEO_CACHE_URL'] . ' :</span> ' . $this->new_config['forum_url' . $forum_id] . $this->core->seo_ext['forum']; $display_vars['vars']['forum_url' . $forum_id] = array('lang' => $title, 'validate' => 'string:0:100', 'type' => 'custom', 'method' => 'forum_url_input', 'explain' => true, 'lang_explain_custom' => $status_msg, 'append' => $this->seo_advices($this->new_config['forum_url' . $forum_id], $forum_id, true)); } } break; case 'server': $display_vars['title'] = 'ACP_REWRITE_CONF'; $this->user->lang['ACP_REWRITE_CONF_EXPLAIN'] .= '</p><hr/><p><b>' . $this->user->lang['ACP_PHPBB_SEO_VERSION'] . ' : ' . $this->modrtype_lang['link'] . ' - ( ' . $this->modrtype_lang['forumlink'] . ' )</b></p><p>'; $display_vars['vars'] = array(); $display_vars['vars']['legend1'] = 'ACP_REWRITE_CONF'; if ($this->core->seo_path['phpbb_script'] && !$this->core->seo_opt['virtual_root']) { $display_vars['vars']['rbase'] = array('lang' => 'SEO_SERVER_CONF_RBASE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true); } $display_vars['vars']['save'] = array('lang' => 'SEO_SERVER_CONF_SAVE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true); $display_vars['vars']['more_options'] = array('lang' => 'SEO_MORE_OPTION', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true); $this->new_config['save'] = false; $cfg_array = $this->request->is_set('config') ? utf8_normalize_nfc($this->request->variable('config', array('' => ''), true)) : $this->new_config; $this->new_config['more_options'] = isset($cfg_array['more_options']) ? $cfg_array['more_options'] : false; $this->new_config['slash'] = isset($cfg_array['slash']) ? $cfg_array['slash'] : false; $this->new_config['wslash'] = isset($cfg_array['wslash']) ? $cfg_array['wslash'] : false; $this->new_config['rbase'] = isset($cfg_array['rbase']) ? $cfg_array['rbase'] : false; if ($this->new_config['more_options']) { $display_vars['vars']['slash'] = array('lang' => 'SEO_SERVER_CONF_SLASH', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true); $display_vars['vars']['wslash'] = array('lang' => 'SEO_SERVER_CONF_WSLASH', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true); } // Dirty yet simple templating $this->user->lang['ACP_REWRITE_CONF_EXPLAIN'] .= $this->seo_server_conf(); $this->template->assign_vars(array('S_SEO_HTACCESS' => 1)); break; case 'extended': $display_vars = array('title' => 'ACP_SEO_EXTENDED', 'vars' => array('legend1' => 'SEO_EXTERNAL_LINKS', 'seo_ext_links' => array('lang' => 'SEO_EXTERNAL_LINKS', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true, 'default' => 1), 'seo_ext_subdomain' => array('lang' => 'SEO_EXTERNAL_SUBDOMAIN', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true, 'default' => 0), 'seo_ext_classes' => array('lang' => 'SEO_EXTERNAL_CLASSES', 'validate' => 'string', 'type' => 'text:40:250', 'explain' => true, 'default' => ''))); // Related topics if (!empty($this->config['seo_related_on'])) { $related_installed = true; $this->user->add_lang_ext('phpbbseo/usu', 'acp_usu_install'); $display_vars['vars'] += array('legend2' => 'SEO_RELATED_TOPICS', 'seo_related' => array('lang' => 'SEO_RELATED', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true, 'append' => !empty($this->config['seo_related']) ? '<br/>' . (!empty($this->config['seo_related_fulltext']) ? $this->user->lang['FULLTEXT_INSTALLED'] : $this->user->lang['FULLTEXT_NOT_INSTALLED']) : '', 'default' => 0), 'seo_related_check_ignore' => array('lang' => 'SEO_RELATED_CHECK_IGNORE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true, 'default' => 0), 'seo_related_limit' => array('lang' => 'SEO_RELATED_LIMIT', 'validate' => 'int:2:25', 'type' => 'text:3:4', 'explain' => true, 'default' => 5), 'seo_related_allforums' => array('lang' => 'SEO_RELATED_ALLFORUMS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true, 'default' => 0)); } // dynamic meta tag mod if (!empty($this->config['seo_meta_on'])) { $display_vars['vars'] += array('legend3' => 'SEO_META', 'seo_meta_title' => array('lang' => 'SEO_META_TITLE', 'validate' => 'string:0:225', 'type' => 'text:40:250', 'explain' => true, 'default' => $this->config['sitename']), 'seo_meta_desc' => array('lang' => 'SEO_META_DESC', 'validate' => 'string:0:225', 'type' => 'text:40:250', 'explain' => true, 'default' => $this->config['site_desc']), 'seo_meta_desc_limit' => array('lang' => 'SEO_META_DESC_LIMIT', 'validate' => 'int:5:40', 'type' => 'text:3:4', 'explain' => true, 'default' => 25), 'seo_meta_bbcode_filter' => array('lang' => 'SEO_META_BBCODE_FILTER', 'validate' => 'string:0:225', 'type' => 'text:40:250', 'explain' => true, 'default' => 'img|url|flash|code'), 'seo_meta_keywords' => array('lang' => 'SEO_META_KEYWORDS', 'validate' => 'string:0:225', 'type' => 'text:40:250', 'explain' => true, 'default' => $this->config['site_desc']), 'seo_meta_keywords_limit' => array('lang' => 'SEO_META_KEYWORDS_LIMIT', 'validate' => 'int:5:40', 'type' => 'text:3:4', 'explain' => true, 'default' => 15), 'seo_meta_min_len' => array('lang' => 'SEO_META_MIN_LEN', 'validate' => 'int:0:10', 'type' => 'text:3:4', 'explain' => true, 'default' => 2), 'seo_meta_check_ignore' => array('lang' => 'SEO_META_CHECK_IGNORE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true, 'default' => 0), 'seo_meta_lang' => array('lang' => 'SEO_META_LANG', 'validate' => 'lang', 'type' => 'select', 'method' => 'language_select', 'params' => array('{CONFIG_VALUE}'), 'explain' => true, 'default' => $this->config['default_lang']), 'seo_meta_copy' => array('lang' => 'SEO_META_COPY', 'validate' => 'string:0:225', 'type' => 'text:40:250', 'explain' => true, 'default' => $this->config['sitename']), 'seo_meta_file_filter' => array('lang' => 'SEO_META_FILE_FILTER', 'validate' => 'string:0:225', 'type' => 'text:40:250', 'explain' => true, 'default' => 'ucp'), 'seo_meta_get_filter' => array('lang' => 'SEO_META_GET_FILTER', 'validate' => 'string:0:225', 'type' => 'text:40:250', 'explain' => true, 'default' => 'style,hilit,sid'), 'seo_meta_robots' => array('lang' => 'SEO_META_ROBOTS', 'validate' => 'string:0:225', 'type' => 'text:25:150', 'explain' => true, 'default' => 'index,follow'), 'seo_meta_noarchive' => array('lang' => 'SEO_META_NOARCHIVE', 'validate' => 'string:0:225', 'multiple_validate' => 'int', 'type' => 'custom', 'method' => 'select_multiple', 'params' => array('{CONFIG_VALUE}', '{KEY}', $this->forum_select()), 'explain' => true, 'default' => ''), 'seo_meta_og' => array('lang' => 'SEO_META_OG', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true, 'default' => 0)); // Open Graph if (!empty($this->config['seo_meta_og'])) { $display_vars['vars'] += array('fb_app_id' => array('lang' => 'SEO_META_FB_APP_ID', 'validate' => 'string:0:225', 'type' => 'text:40:250', 'explain' => true, 'default' => '')); } } // Optimal title if (!empty($this->config['seo_optimal_title_on'])) { $display_vars['vars'] += array('legend' => 'SEO_PAGE_TITLES', 'seo_append_sitename' => array('lang' => 'SEO_APPEND_SITENAME', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true, 'default' => 0)); } // install if necessary foreach ($display_vars['vars'] as $config_name => $config_setup) { if (strpos($config_name, 'legend') !== false) { continue; } if (!isset($this->config[$config_name])) { set_config($config_name, $config_setup['default']); unset($display_vars['vars'][$config_name]['default']); } } $this->new_config = $this->config; break; case 'sync_url': $sync_url = $this->request->variable('sync', ''); $redirect_url = "{$phpbb_admin_path}index.{$phpEx}?i=-phpbbseo-usu-acp-usu&mode=sync_url"; $go = max(0, $this->request->variable('go', 0)); if ($cancel || !$go) { trigger_error($this->user->lang['SYNC_WARN'] . '<br/><br/><b> • <a href="' . append_sid($redirect_url, "go=1&sync=sync") . '">' . $this->user->lang['SYNC_TOPIC_URLS'] . '</a><br/><br/> • <a href="' . append_sid($redirect_url, "go=1&sync=reset") . '" >' . $this->user->lang['SYNC_RESET_TOPIC_URLS'] . '</a></b>'); } $starttime = microtime(true); $start = max(0, $this->request->variable('start', 0)); $limit = max(100, $this->request->variable('limit', 0)); // Do not go over 1000 topic in a row $limit = min(1000, $limit); $poll_processed = 0; $forum_data = array(); $url_updated = 0; if ($sync_url === 'sync') { // get all forum info $sql = 'SELECT forum_id, forum_name FROM ' . FORUMS_TABLE; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $forum_data[$row['forum_id']] = $row['forum_name']; $this->core->set_url($row['forum_name'], $row['forum_id'], $this->core->seo_static['forum']); } $db->sql_freeresult($result); // let's work $sql = 'SELECT * FROM ' . TOPICS_TABLE . ' ORDER BY topic_id ASC'; $result = $db->sql_query_limit($sql, $limit, $start); while ($row = $db->sql_fetchrow($result)) { $forum_id = (int) $row['forum_id']; $topic_id = (int) $row['topic_id']; $_parent = $row['topic_type'] == POST_GLOBAL ? $this->core->seo_static['global_announce'] : $this->core->seo_url['forum'][$forum_id]; if (!$this->core->check_url('topic', $row['topic_url'], $_parent)) { if (!empty($row['topic_url'])) { // Here we get rid of the seo delim (-t) and put it back even in simple mod // to be able to handle all cases at once $_url = preg_replace('`' . $this->core->seo_delim['topic'] . '$`i', '', $row['topic_url']); $_title = $this->core->get_url_info('topic', $_url . $this->core->seo_delim['topic'] . $topic_id, 'title'); } else { $_title = $this->core->modrtype > 2 ? censor_text($row['topic_title']) : ''; } unset($this->core->seo_url['topic'][$topic_id]); $row['topic_url'] = $this->core->get_url_info('topic', $this->core->prepare_url('topic', $_title, $topic_id, $_parent, empty($_title) || $_title == $this->core->seo_static['topic'] ? true : false), 'url'); unset($this->core->seo_url['topic'][$topic_id]); if ($row['topic_url']) { // Update the topic_url field for later re-use $sql = "UPDATE " . TOPICS_TABLE . " SET topic_url = '" . $db->sql_escape($row['topic_url']) . "'\n\t\t\t\t\t\t\t\t\tWHERE topic_id = {$topic_id}"; $db->sql_query($sql); $url_updated++; } } } $db->sql_freeresult($result); $sql = 'SELECT count(topic_id) as topic_cnt FROM ' . TOPICS_TABLE; $result = $db->sql_query($sql); $cnt = $db->sql_fetchrow($result); $db->sql_freeresult($result); if ($cnt['topic_cnt'] > $start + $limit) { $endtime = microtime(true); $duration = $endtime - $starttime; $speed = round($limit / $duration, 2); $percent = round(($start + $limit) / $cnt['topic_cnt'] * 100, 2); $message = sprintf($user->lang['SYNC_PROCESSING'], $percent, $start + $limit, $cnt['topic_cnt'], $limit, $speed, round($duration, 2), round(($cnt['topic_cnt'] - $start) / $speed / 60, 2)); if ($url_updated) { $message .= sprintf($user->lang['SYNC_ITEM_UPDATED'], '<br/>' . $url_updated); } $new_limit = $duration < 10 ? $limit + 50 : $limit - 10; meta_refresh(1, append_sid($redirect_url, 'go=1&start=' . ($start + $limit) . "&limit={$new_limit}&sync=sync")); trigger_error("{$message}<br/>"); } else { trigger_error($user->lang['SYNC_COMPLETE'] . sprintf($user->lang['RETURN_INDEX'], '<br/><br/><a href="' . append_sid($redirect_url) . '" >', '</a>')); } } else { if ($sync_url === 'reset') { if (confirm_box(true)) { $sql = "UPDATE " . TOPICS_TABLE . " SET topic_url = ''"; $db->sql_query($sql); trigger_error($user->lang['SYNC_RESET_COMPLETE'] . '<br/><br/><b> • <a href="' . append_sid($redirect_url, "go=1&sync=sync") . '">' . $user->lang['SYNC_TOPIC_URLS'] . '</a><br/><br/> • ' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid($redirect_url) . '" >', '</a></b>')); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('go' => '1', 'sync' => 'reset')), 'confirm_body.html'); } } else { trigger_error($user->lang['SYNC_WARN'] . '<br/><br/><b> • <a href="' . append_sid($redirect_url, "go=1&sync=sync") . '">' . $user->lang['SYNC_TOPIC_URLS'] . '</a><br/><br/> • <a href="' . append_sid($redirect_url, "go=1&sync=reset") . '" >' . $user->lang['SYNC_RESET_TOPIC_URLS'] . '</a></b>'); } } break; default: trigger_error('NO_MODE', E_USER_ERROR); break; } $error = array(); $seo_msg = array(); $cfg_array = $this->request->is_set('config') ? utf8_normalize_nfc($this->request->variable('config', array('' => ''), true)) : $this->new_config; if ($submit && !check_form_key($form_key)) { $error[] = $this->user->lang['FORM_INVALID']; } // We validate the complete config if whished validate_config_vars($display_vars['vars'], $cfg_array, $error); // Do not write values if there is an error if (!empty($error)) { $submit = false; } $additional_notes = ''; // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to... foreach ($display_vars['vars'] as $config_name => $cfg_setup) { if (!isset($cfg_array[$config_name]) && @$cfg_setup['method'] != 'select_multiple' || strpos($config_name, 'legend') !== false) { continue; } // Handle multiple select options if (!empty($cfg_setup['method']) && $cfg_setup['method'] == 'select_multiple') { if (isset($_POST['multiple_' . $config_name])) { $m_values = utf8_normalize_nfc($this->request->variable('multiple_' . $config_name, array('' => ''))); $validate_int = !empty($cfg_setup['multiple_validate']) && $cfg_setup['multiple_validate'] == 'int' ? true : false; foreach ($m_values as $k => $v) { if ($validate_int) { $v = max(0, (int) $v); } if (empty($v)) { unset($m_values[$k]); } else { $m_values[$k] = $v; } } sort($m_values); $this->new_config[$config_name] = $m_values; $config_value = implode(',', $m_values); if (strlen($config_value) > 255) { $error[] = sprintf($this->user->lang['SETTING_TOO_LONG'], $this->user->lang[$cfg_setup['lang']], 255); } $submit = empty($error); } else { if ($submit) { $this->new_config[$config_name] = array(); $config_value = ''; } else { $config_value = $this->new_config[$config_name]; $this->new_config[$config_name] = !empty($config_value) ? explode(',', $config_value) : array(); } } } else { $this->new_config[$config_name] = $config_value = $cfg_array[$config_name]; } if ($submit) { // In case we deal with forum URLs if ($mode == 'forum_url' && preg_match('`^forum_url([0-9]+)$`', $config_name, $matches)) { // Check if this is an actual forum_id if (isset($this->forum_ids[$matches[1]])) { $forum_id = intval($matches[1]); $config_value = $this->core->format_url($config_value, $this->core->seo_static['forum']); // Remove delim if required while (preg_match('`^[a-z0-9_-]+' . $this->core->seo_delim['forum'] . '[0-9]+$`i', $config_value)) { $config_value = preg_replace('`^([a-z0-9_-]+)' . $this->core->seo_delim['forum'] . '[0-9]+$`i', '\\1', $config_value); if (@$this->core->cache_config['settings']['rem_ids']) { $seo_msg['SEO_ADVICE_DELIM_REM'] = '<li> ' . $this->user->lang['SEO_ADVICE_DELIM_REM'] . '</li>'; } } // Forums cannot end with the pagination param while (preg_match('`^[a-z0-9_-]+' . $this->core->seo_delim['start'] . '[0-9]+$`i', $config_value)) { $config_value = preg_replace('`^([a-z0-9_-]+)' . $this->core->seo_delim['start'] . '[0-9]+$`i', "\\1", $config_value); $seo_msg['SEO_ADVICE_START'] = '<li> ' . $this->user->lang['SEO_ADVICE_START'] . '</li>'; } // Only update if the value is not a static one for forums if (!in_array($config_value, $forbidden)) { // and updated (sic) if ($config_value != @$this->core->cache_config['forum_urls'][$forum_id]) { // and if not already set if (!array_search($config_value, $this->core->cache_config['forum_urls'])) { $this->core->cache_config['forum_urls'][$forum_id] = $config_value . (@$this->core->cache_config['settings']['rem_ids'] ? '' : $this->core->seo_delim['forum'] . $forum_id); } else { $seo_msg['SEO_ADVICE_DUPE_' . $forum_id] = '<li> ' . sprintf($this->user->lang['SEO_ADVICE_DUPE'], $config_value) . '</li>'; } } } else { $seo_msg['SEO_ADVICE_RESERVED_' . $forum_id] = '<li> ' . sprintf($this->user->lang['SEO_ADVICE_RESERVED'], $config_value) . '</li>'; } } } else { if ($mode == 'settings') { if (isset($this->array_type_cfg[$config_name]) && isset($this->core->seo_opt[$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']])) { if (is_bool($this->core->seo_opt[$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']])) { $this->core->cache_config['settings'][$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']] = $config_value == 1 ? true : false; } else { if (is_numeric($this->core->seo_opt[$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']])) { $this->core->cache_config['settings'][$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']] = intval($config_value); } else { if (is_string($this->core->seo_opt[$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']])) { $this->core->cache_config['settings'][$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']] = $config_value; } } } } else { if (isset($this->core->seo_opt[$config_name])) { if (is_bool($this->core->seo_opt[$config_name])) { $this->core->cache_config['settings'][$config_name] = $config_value == 1 ? true : false; } else { if (is_numeric($this->core->seo_opt[$config_name])) { $this->core->cache_config['settings'][$config_name] = intval($config_value); } else { if (is_string($this->core->seo_opt[$config_name])) { $this->core->cache_config['settings'][$config_name] = $config_value; } } } } } // Let's make sure that the proper field was added to the topic table if ($config_name === 'sql_rewrite' && $config_value == 1 && !$this->core->seo_opt['sql_rewrite']) { $db_tools = new \phpbb\db\tools($this->db); $db_tools->db->sql_return_on_error(true); if (!$db_tools->sql_column_exists(TOPICS_TABLE, 'topic_url')) { $db_tools->sql_column_add(TOPICS_TABLE, 'topic_url', array('VCHAR:255', '')); } $additional_notes = sprintf($this->user->lang['SYNC_TOPIC_URL_NOTE'], '<a href="' . append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=-phpbbseo-usu-acp-usu&mode=sync_url') . '">', '</a>'); if ($db_tools->db->get_sql_error_triggered()) { $error[] = '<b>' . $this->user->lang['sql_rewrite'] . '</b> : ' . $this->user->lang['SEO_SQL_ERROR'] . ' [ ' . $db_tools->db->get_sql_layer() . ' ] : ' . $db_tools->db->sql_error_returned['message'] . ' [' . $db_tools->db->sql_error_returned['code'] . ']' . '<br/>' . $this->user->lang['SEO_SQL_TRY_MANUALLY'] . '<br/>' . $db_tools->db->sql_error_sql; $submit = false; } $db_tools->db->sql_return_on_error(false); } } else { if ($mode == 'extended') { set_config($config_name, $config_value); } } } } } if (sizeof($error)) { $submit = false; } if ($submit) { if ($mode == 'server') { if ($this->new_config['save']) { $this->seo_server_conf(false); add_log('admin', 'SEO_LOG_CONFIG_' . strtoupper($mode)); } } else { if ($mode == 'extended') { add_log('admin', 'SEO_LOG_CONFIG_' . strtoupper($mode)); trigger_error($this->user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action)); } else { // config $file = $this->core->cache_config['file']; ksort($this->core->cache_config['forum_urls']); $update = '<' . '?php' . "\n" . '/**' . "\n" . '* phpBB SEO' . "\n" . '* www.phpBB-SEO.com' . "\n" . '* @package phpBB SEO USU' . "\n" . '*/' . "\n" . 'if (!defined(\'IN_PHPBB\')) {' . "\n\t" . 'exit;' . "\n" . '}' . "\n"; $update .= '$settings = ' . preg_replace('`[\\s]+`', ' ', var_export($this->core->cache_config['settings'], true)) . ';' . "\n"; $update .= '$forum_urls = ' . preg_replace('`[\\s]+`', ' ', var_export($this->core->cache_config['forum_urls'], true)) . ';'; if ($this->write_cache($file, $update)) { global $msg_long_text; add_log('admin', 'SEO_LOG_CONFIG_' . strtoupper($mode)); $msg = !empty($seo_msg) ? '<br /><h1 style="color:red;text-align:left;">' . $this->user->lang['SEO_VALIDATE_INFO'] . '</h1><ul style="text-align:left;">' . implode(' ', $seo_msg) . '</ul><br />' : ''; $msg_long_text = $this->user->lang['SEO_CACHE_MSG_OK'] . $msg . adm_back_link($this->u_action); if ($additional_notes) { $msg_long_text .= "<br/><br/>{$additional_notes}"; } trigger_error(false); } else { trigger_error($this->user->lang['SEO_CACHE_MSG_FAIL'] . adm_back_link($this->u_action)); } } } } $this->tpl_name = 'acp_board'; $this->page_title = $display_vars['title']; $l_title_explain = $this->user->lang[$display_vars['title'] . '_EXPLAIN']; if ($mode != 'extended') { $l_title_explain .= $mode == 'server' ? '' : $this->check_cache_folder($this->core->seo_opt['cache_folder']); } $this->template->assign_vars(array('L_TITLE' => $this->user->lang[$display_vars['title']], 'L_TITLE_EXPLAIN' => $l_title_explain, 'S_ERROR' => sizeof($error) ? true : false, 'ERROR_MSG' => implode('<br />', $error), 'U_ACTION' => $this->u_action)); // Output relevant page foreach ($display_vars['vars'] as $config_key => $vars) { if (!is_array($vars) && strpos($config_key, 'legend') === false) { continue; } if (strpos($config_key, 'legend') !== false) { $this->template->assign_block_vars('options', array('S_LEGEND' => true, 'LEGEND' => isset($this->user->lang[$vars]) ? $this->user->lang[$vars] : $vars)); continue; } $type = explode(':', $vars['type']); $l_explain = ''; if ($vars['explain'] && isset($vars['lang_explain'])) { $l_explain = isset($this->user->lang[$vars['lang_explain']]) ? $this->user->lang[$vars['lang_explain']] : $vars['lang_explain']; } else { if ($vars['explain'] && isset($vars['lang_explain_custom'])) { $l_explain = $vars['lang_explain_custom']; } else { if ($vars['explain']) { $l_explain = isset($this->user->lang[$vars['lang'] . '_EXPLAIN']) ? $this->user->lang[$vars['lang'] . '_EXPLAIN'] : ''; } } } $this->template->assign_block_vars('options', array('KEY' => $config_key, 'TITLE' => isset($this->user->lang[$vars['lang']]) ? $this->user->lang[$vars['lang']] : $vars['lang'], 'S_EXPLAIN' => $vars['explain'], 'TITLE_EXPLAIN' => $l_explain, 'CONTENT' => build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars))); unset($display_vars['vars'][$config_key]); } }