/** * Returns a string containing the value that should be used for the theme_data column in the theme database table. * Includes contents of files loaded via @import * * @param array $theme_row is an associative array containing the theme's current database entry * @param mixed $stylesheet can either be the new content for the stylesheet or false to load from the standard file * @param string $root_path should only be used in case you want to use a different root path than "{$phpbb_root_path}styles/{$theme_row['theme_path']}" * * @return string Stylesheet data for theme_data column in the theme table */ function db_theme_data($theme_row, $stylesheet = false, $root_path = '') { global $phpbb_root_path; if (!$root_path) { $root_path = $phpbb_root_path . 'styles/' . $theme_row['theme_path']; } if (!$stylesheet) { $stylesheet = ''; if (file_exists($root_path . '/theme/stylesheet.css')) { $stylesheet = file_get_contents($root_path . '/theme/stylesheet.css'); } } // Match CSS imports $matches = array(); preg_match_all('/@import url\\(["\'](.*)["\']\\);/i', $stylesheet, $matches); if (sizeof($matches)) { foreach ($matches[0] as $idx => $match) { $stylesheet = str_replace($match, acp_styles::load_css_file($theme_row['theme_path'], $matches[1][$idx]), $stylesheet); } } // adjust paths return str_replace('./', 'styles/' . $theme_row['theme_path'] . '/theme/', $stylesheet); }
/** * Install a style on the demo board. * * @param string $phpbb_root_path * @param mixed contrib object */ public function install_demo_style($phpbb_root_path, $contrib) { phpbb::$user->add_lang('acp/styles'); if ($phpbb_root_path[strlen($phpbb_root_path) - 1] != '/') { $phpbb_root_path .= '/'; } if (!is_dir($phpbb_root_path) || !file_exists($phpbb_root_path . 'config.' . PHP_EXT)) { $this->error[] = 'PATH_INVALID'; return false; } include $phpbb_root_path . 'config.' . PHP_EXT; $sql_db = !empty($dbms) ? 'dbal_' . basename($dbms) : 'dbal'; // Is this DBAL loaded? phpbb::_include('db/' . $dbms, false, $sql_db); // Instantiate DBAL class $db = new $sql_db(); // Connect to demo board DB $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport); // We do not need this any longer, unset for safety purposes unset($dbpasswd); if (empty($this->unzip_dir)) { // Extract zip. $this->unzip_dir = titania::$config->contrib_temp_path . basename($this->original_zip, 'zip') . '/'; // Clear out old stuff if there is anything here... $this->rmdir_recursive($this->unzip_dir); // Unzip to our temp directory $this->extract($this->original_zip, $this->unzip_dir); } $package_root = $this->find_root(false, 'style.cfg'); $stylecfg = parse_cfg_file($this->unzip_dir . $package_root . '/style.cfg'); $style_root = $phpbb_root_path . 'styles/' . $contrib->contrib_id . '/'; $this->mvdir_recursive($this->unzip_dir . $package_root, $style_root, false); $this->rmdir_recursive($this->unzip_dir); $variables = array('db', 'phpbb_root_path'); // Let's get lazy. foreach ($variables as $variable) { ${'_' . $variable} = $GLOBALS[$variable]; $GLOBALS[$variable] = ${$variable}; } // Get the acp_styles class. phpbb::_include('acp/acp_styles', false, 'acp_styles'); if (!defined('TEMPLATE_BITFIELD')) { // Hardcoded template bitfield to add for new templates $bitfield = new bitfield(); $bitfield->set(0); $bitfield->set(1); $bitfield->set(2); $bitfield->set(3); $bitfield->set(4); $bitfield->set(8); $bitfield->set(9); $bitfield->set(11); $bitfield->set(12); define('TEMPLATE_BITFIELD', $bitfield->get_base64()); unset($bitfield); } $styles = new acp_styles(); // Fill the configuration variables $styles->style_cfg = $styles->template_cfg = $styles->theme_cfg = $styles->imageset_cfg = ' # # phpBB {MODE} configuration file # # @package phpBB3 # @copyright (c) 2005 phpBB Group # @license http://opensource.org/licenses/gpl-license.php GNU Public License # # # At the left is the name, please do not change this # At the right the value is entered # For on/off options the valid values are on, off, 1, 0, true and false # # Values get trimmed, if you want to add a space in front or at the end of # the value, then enclose the value with single or double quotes. # Single and double quotes do not need to be escaped. # # # General Information about this {MODE} name = {NAME} copyright = {COPYRIGHT} version = {VERSION} '; $styles->theme_cfg .= ' # Some configuration options # # You have to turn this option on if you want to use the # path template variables ({T_IMAGESET_PATH} for example) within # your css file. # This is mostly the case if you want to use language specific # images within your css file. # parse_css_file = {PARSE_CSS_FILE} '; $styles->template_cfg .= ' # Some configuration options # # You can use this function to inherit templates from another template. # The template of the given name has to be installed. # Templates cannot inherit from inheriting templates. #'; $styles->imageset_keys = array('logos' => array('site_logo'), 'buttons' => array('icon_back_top', 'icon_contact_aim', 'icon_contact_email', 'icon_contact_icq', 'icon_contact_jabber', 'icon_contact_msnm', 'icon_contact_pm', 'icon_contact_yahoo', 'icon_contact_www', 'icon_post_delete', 'icon_post_edit', 'icon_post_info', 'icon_post_quote', 'icon_post_report', 'icon_user_online', 'icon_user_offline', 'icon_user_profile', 'icon_user_search', 'icon_user_warn', 'button_pm_forward', 'button_pm_new', 'button_pm_reply', 'button_topic_locked', 'button_topic_new', 'button_topic_reply'), 'icons' => array('icon_post_target', 'icon_post_target_unread', 'icon_topic_attach', 'icon_topic_latest', 'icon_topic_newest', 'icon_topic_reported', 'icon_topic_unapproved', 'icon_friend', 'icon_foe'), 'forums' => array('forum_link', 'forum_read', 'forum_read_locked', 'forum_read_subforum', 'forum_unread', 'forum_unread_locked', 'forum_unread_subforum', 'subforum_read', 'subforum_unread'), 'folders' => array('topic_moved', 'topic_read', 'topic_read_mine', 'topic_read_hot', 'topic_read_hot_mine', 'topic_read_locked', 'topic_read_locked_mine', 'topic_unread', 'topic_unread_mine', 'topic_unread_hot', 'topic_unread_hot_mine', 'topic_unread_locked', 'topic_unread_locked_mine', 'sticky_read', 'sticky_read_mine', 'sticky_read_locked', 'sticky_read_locked_mine', 'sticky_unread', 'sticky_unread_mine', 'sticky_unread_locked', 'sticky_unread_locked_mine', 'announce_read', 'announce_read_mine', 'announce_read_locked', 'announce_read_locked_mine', 'announce_unread', 'announce_unread_mine', 'announce_unread_locked', 'announce_unread_locked_mine', 'global_read', 'global_read_mine', 'global_read_locked', 'global_read_locked_mine', 'global_unread', 'global_unread_mine', 'global_unread_locked', 'global_unread_locked_mine', 'pm_read', 'pm_unread'), 'polls' => array('poll_left', 'poll_center', 'poll_right'), 'ui' => array('upload_bar'), 'user' => array('user_icon1', 'user_icon2', 'user_icon3', 'user_icon4', 'user_icon5', 'user_icon6', 'user_icon7', 'user_icon8', 'user_icon9', 'user_icon10')); // Define references. $error = array(); $style_id = 0; $style_row = array('install_name' => $stylecfg['name'], 'install_copyright' => $stylecfg['copyright'], 'template_id' => 0, 'template_name' => $stylecfg['name'], 'template_copyright' => $stylecfg['copyright'], 'theme_id' => 0, 'theme_name' => $stylecfg['name'], 'theme_copyright' => $stylecfg['copyright'], 'imageset_id' => 0, 'imageset_name' => $stylecfg['name'], 'imageset_copyright' => $stylecfg['copyright'], 'store_db' => 0, 'style_active' => 1, 'style_default' => 0); // Install the style. // (&$error, $action, $root_path, &$id, $name, $path, $copyright, $active, $default, &$style_row, $template_root_path = false, $template_path = false, $theme_root_path = false, $theme_path = false, $imageset_root_path = false, $imageset_path = false) if (!$styles->install_style($error, 'install', $style_root, $style_id, $stylecfg['name'], $contrib->contrib_id, $stylecfg['copyright'], true, false, $style_row)) { if ($error != array(phpbb::$user->lang['STYLE_ERR_NAME_EXIST'])) { $this->error = array_merge($this->error, $error); } else { $sql = 'SELECT style_id FROM ' . STYLES_TABLE . "\n\t\t\t\t\tWHERE style_name = '" . $db->sql_escape(basename($stylecfg['name'])) . "'"; $db->sql_query($sql); $style_id = $db->sql_fetchfield('style_id'); $db->sql_freeresult(); } } // Have UMIL refresh the template, theme, imageset phpbb::_include('../umil/umil', false, 'umil'); $umil = new umil(true, $db); $umil->cache_purge('template', $style_id); $umil->cache_purge('theme', $style_id); $umil->cache_purge('imageset', $style_id); foreach ($variables as $variable) { $GLOBALS[$variable] = ${'_' . $variable}; } return $style_id; }
function refresh_all_themes() { global $config, $db, $auth, $template, $phpbb_root_path, $cache, $user; // Refresh theme data stored in the database $sql = 'SELECT * FROM ' . STYLES_THEME_TABLE . ''; $result = $db->sql_query($sql); while ($theme_row = $db->sql_fetchrow($result)) { if (!$theme_row) { trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING); } if (!$theme_row['theme_storedb']) { trigger_error($user->lang['THEME_ERR_REFRESH_FS'] . adm_back_link($this->u_action), E_USER_WARNING); } if ($theme_row['theme_storedb'] && file_exists("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css")) { // Save CSS contents $sql_ary = array('theme_mtime' => (int) filemtime("{$phpbb_root_path}styles/{$theme_row['theme_path']}/theme/stylesheet.css"), 'theme_data' => acp_styles::db_theme_data($theme_row)); $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\r\n\t\t\t\t\tWHERE theme_id = '" . $theme_row['theme_id'] . "'"; $db->sql_query($sql); $cache->destroy('sql', STYLES_THEME_TABLE); } } $db->sql_freeresult($result); add_log('admin', 'LOG_THEME_REFRESHED', 'Called from the PBWoW ACP module'); trigger_error($user->lang['THEME_REFRESHED'] . adm_back_link($this->u_action)); }
$dir = @opendir("{$phpbb_root_path}styles/{$theme['theme_path']}/theme"); if ($dir) { while (($entry = readdir($dir)) !== false) { if (substr(strrchr($entry, '.'), 1) == 'css' && $last_change < @filemtime("{$phpbb_root_path}styles/{$theme['theme_path']}/theme/{$entry}")) { $recache = true; break; } } closedir($dir); } } } } if ($recache) { include_once $phpbb_root_path . 'includes/acp/acp_styles.' . $phpEx; $theme['theme_data'] = acp_styles::db_theme_data($theme); $theme['theme_mtime'] = $update_time; // Save CSS contents $sql_ary = array('theme_mtime' => $theme['theme_mtime'], 'theme_data' => $theme['theme_data']); $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\tWHERE theme_id = {$theme['theme_id']}"; $db->sql_query($sql); $cache->destroy('sql', STYLES_THEME_TABLE); } // Only set the expire time if the theme changed data is older than 30 minutes - to cope with changes from the ACP if ($recache || $theme['theme_mtime'] > time() - 1800) { header('Expires: 0'); } else { header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + $expire_time)); } header('Content-type: text/css; charset=UTF-8'); // Parse Theme Data
function main($mode, $sub) { global $template, $phpEx, $phpbb_root_path, $user, $db, $config, $cache, $auth; $this->tpl_name = 'install_update'; $this->page_title = 'UPDATE_INSTALLATION'; $this->unequal_version = false; $this->old_location = $phpbb_root_path . 'install/update/old/'; $this->new_location = $phpbb_root_path . 'install/update/new/'; // Init DB require($phpbb_root_path . 'config.' . $phpEx); require($phpbb_root_path . 'includes/db/' . $dbms . '.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); // Special options for conflicts/modified files define('MERGE_NO_MERGE_NEW', 1); define('MERGE_NO_MERGE_MOD', 2); define('MERGE_NEW_FILE', 3); define('MERGE_MOD_FILE', 4); $db = new $sql_db(); // Connect to DB $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false); // We do not need this any longer, unset for safety purposes unset($dbpasswd); $config = array(); $sql = 'SELECT config_name, config_value FROM ' . CONFIG_TABLE; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $config[$row['config_name']] = $row['config_value']; } $db->sql_freeresult($result); // Force template recompile $config['load_tplcompile'] = 1; // First of all, init the user session $user->session_begin(); $auth->acl($user->data); $user->setup('install'); // If we are within the intro page we need to make sure we get up-to-date version info if ($sub == 'intro') { $cache->destroy('_version_info'); } // Set custom template again. ;) $template->set_custom_template('../adm/style', 'admin'); // still, the acp template is never stored in the database $user->theme['template_storedb'] = false; // Get current and latest version if (($latest_version = $cache->get('_version_info')) === false) { $this->latest_version = $this->get_file('version_info'); $cache->put('_version_info', $this->latest_version); } else { $this->latest_version = $latest_version; } // For the current version we trick a bit. ;) $this->current_version = (!empty($config['version_update_from'])) ? $config['version_update_from'] : $config['version']; $up_to_date = (version_compare(str_replace('rc', 'RC', strtolower($this->current_version)), str_replace('rc', 'RC', strtolower($this->latest_version)), '<')) ? false : true; // Check for a valid update directory, else point the user to the phpbb.com website if (!file_exists($phpbb_root_path . 'install/update') || !file_exists($phpbb_root_path . 'install/update/index.' . $phpEx) || !file_exists($this->old_location) || !file_exists($this->new_location)) { $template->assign_vars(array( 'S_ERROR' => true, 'ERROR_MSG' => ($up_to_date) ? $user->lang['NO_UPDATE_FILES_UP_TO_DATE'] : sprintf($user->lang['NO_UPDATE_FILES_OUTDATED'], $config['version'], $this->current_version, $this->latest_version)) ); return; } $this->update_info = $this->get_file('update_info'); // Make sure the update directory holds the correct information // Since admins are able to run the update/checks more than once we only check if the current version is lower or equal than the version to which we update to. if (version_compare(str_replace('rc', 'RC', strtolower($this->current_version)), str_replace('rc', 'RC', strtolower($this->update_info['version']['to'])), '>')) { $template->assign_vars(array( 'S_ERROR' => true, 'ERROR_MSG' => sprintf($user->lang['INCOMPATIBLE_UPDATE_FILES'], $config['version'], $this->update_info['version']['from'], $this->update_info['version']['to'])) ); return; } // Check if the update files stored are for the latest version... if ($this->latest_version != $this->update_info['version']['to']) { $this->unequal_version = true; $template->assign_vars(array( 'S_WARNING' => true, 'WARNING_MSG' => sprintf($user->lang['OLD_UPDATE_FILES'], $this->update_info['version']['from'], $this->update_info['version']['to'], $this->latest_version)) ); } if ($this->test_update === false) { // Got the updater template itself updated? If so, we are able to directly use it - but only if all three files are present if (in_array('adm/style/install_update.html', $this->update_info['files'])) { $this->tpl_name = '../../install/update/new/adm/style/install_update'; } // What about the language file? Got it updated? if (in_array('language/en/install.php', $this->update_info['files'])) { $lang = array(); include($this->new_location . 'language/en/install.php'); // only add new keys to user's language in english $new_keys = array_diff(array_keys($lang), array_keys($user->lang)); foreach ($new_keys as $i => $new_key) { $user->lang[$new_key] = $lang[$new_key]; } } } // Include renderer and engine $this->include_file('includes/diff/diff.' . $phpEx); $this->include_file('includes/diff/engine.' . $phpEx); $this->include_file('includes/diff/renderer.' . $phpEx); // Make sure we stay at the file check if checking the files again if (!empty($_POST['check_again'])) { $sub = $this->p_master->sub = 'file_check'; } switch ($sub) { case 'intro': $this->page_title = 'UPDATE_INSTALLATION'; $template->assign_vars(array( 'S_INTRO' => true, 'U_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=version_check"), )); // Make sure the update list is destroyed. $cache->destroy('_update_list'); $cache->destroy('_diff_files'); break; case 'version_check': $this->page_title = 'STAGE_VERSION_CHECK'; $template->assign_vars(array( 'S_UP_TO_DATE' => $up_to_date, 'S_VERSION_CHECK' => true, 'U_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=file_check"), 'U_DB_UPDATE_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=update_db"), 'LATEST_VERSION' => $this->latest_version, 'CURRENT_VERSION' => $this->current_version) ); // Print out version the update package updates to if ($this->unequal_version) { $template->assign_var('PACKAGE_VERSION', $this->update_info['version']['to']); } break; case 'update_db': // Make sure the database update is valid for the latest version $valid = false; $updates_to_version = ''; if (file_exists($phpbb_root_path . 'install/database_update.' . $phpEx)) { include_once($phpbb_root_path . 'install/database_update.' . $phpEx); if ($updates_to_version === $this->update_info['version']['to']) { $valid = true; } } // Should not happen at all if (!$valid) { trigger_error($user->lang['DATABASE_UPDATE_INFO_OLD'], E_USER_ERROR); } // Just a precaution $cache->purge(); // Redirect the user to the database update script with some explanations... $template->assign_vars(array( 'S_DB_UPDATE' => true, 'S_DB_UPDATE_FINISHED' => ($config['version'] == $this->update_info['version']['to']) ? true : false, 'U_DB_UPDATE' => append_sid($phpbb_root_path . 'install/database_update.' . $phpEx, 'type=1&language=' . $user->data['user_lang']), 'U_DB_UPDATE_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=update_db"), 'U_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=file_check"), )); break; case 'file_check': // Make sure the previous file collection is no longer valid... $cache->destroy('_diff_files'); $this->page_title = 'STAGE_FILE_CHECK'; // Now make sure our update list is correct if the admin refreshes $action = request_var('action', ''); // We are directly within an update. To make sure our update list is correct we check its status. $update_list = (!empty($_POST['check_again'])) ? false : $cache->get('_update_list'); $modified = ($update_list !== false) ? @filemtime($cache->cache_dir . 'data_update_list.' . $phpEx) : 0; // Make sure the list is up-to-date if ($update_list !== false) { $get_new_list = false; foreach ($this->update_info['files'] as $file) { if (file_exists($phpbb_root_path . $file) && filemtime($phpbb_root_path . $file) > $modified) { $get_new_list = true; break; } } } else { $get_new_list = true; } if (!$get_new_list && $update_list['status'] != -1) { $get_new_list = true; } if ($get_new_list) { $this->get_update_structure($update_list); $cache->put('_update_list', $update_list); // Refresh the page if we are still not finished... if ($update_list['status'] != -1) { $refresh_url = append_sid($this->p_master->module_url, "mode=$mode&sub=file_check"); meta_refresh(2, $refresh_url); $template->assign_vars(array( 'S_IN_PROGRESS' => true, 'S_COLLECTED' => (int) $update_list['status'], 'S_TO_COLLECT' => sizeof($this->update_info['files']), 'L_IN_PROGRESS' => $user->lang['COLLECTING_FILE_DIFFS'], 'L_IN_PROGRESS_EXPLAIN' => sprintf($user->lang['NUMBER_OF_FILES_COLLECTED'], (int) $update_list['status'], sizeof($this->update_info['files'])), )); return; } } if ($action == 'diff') { $this->show_diff($update_list); return; } if (sizeof($update_list['no_update'])) { $template->assign_vars(array( 'S_NO_UPDATE_FILES' => true, 'NO_UPDATE_FILES' => implode(', ', array_map('htmlspecialchars', $update_list['no_update']))) ); } // Now assign the list to the template foreach ($update_list as $status => $filelist) { if ($status == 'no_update' || !sizeof($filelist) || $status == 'status') { continue; } $template->assign_block_vars('files', array( 'S_STATUS' => true, 'STATUS' => $status, 'L_STATUS' => $user->lang['STATUS_' . strtoupper($status)], 'TITLE' => $user->lang['FILES_' . strtoupper($status)], 'EXPLAIN' => $user->lang['FILES_' . strtoupper($status) . '_EXPLAIN'], ) ); foreach ($filelist as $file_struct) { $s_binary = (!empty($this->update_info['binary']) && in_array($file_struct['filename'], $this->update_info['binary'])) ? true : false; $filename = htmlspecialchars($file_struct['filename']); if (strrpos($filename, '/') !== false) { $dir_part = substr($filename, 0, strrpos($filename, '/') + 1); $file_part = substr($filename, strrpos($filename, '/') + 1); } else { $dir_part = ''; $file_part = $filename; } $diff_url = append_sid($this->p_master->module_url, "mode=$mode&sub=file_check&action=diff&status=$status&file=" . urlencode($file_struct['filename'])); $template->assign_block_vars('files', array( 'STATUS' => $status, 'FILENAME' => $filename, 'DIR_PART' => $dir_part, 'FILE_PART' => $file_part, 'NUM_CONFLICTS' => (isset($file_struct['conflicts'])) ? $file_struct['conflicts'] : 0, 'S_CUSTOM' => ($file_struct['custom']) ? true : false, 'S_BINARY' => $s_binary, 'CUSTOM_ORIGINAL' => ($file_struct['custom']) ? $file_struct['original'] : '', 'U_SHOW_DIFF' => $diff_url, 'L_SHOW_DIFF' => ($status != 'up_to_date') ? $user->lang['SHOW_DIFF_' . strtoupper($status)] : '', 'U_VIEW_MOD_FILE' => $diff_url . '&op=' . MERGE_MOD_FILE, 'U_VIEW_NEW_FILE' => $diff_url . '&op=' . MERGE_NEW_FILE, 'U_VIEW_NO_MERGE_MOD' => $diff_url . '&op=' . MERGE_NO_MERGE_MOD, 'U_VIEW_NO_MERGE_NEW' => $diff_url . '&op=' . MERGE_NO_MERGE_NEW, )); } } $all_up_to_date = true; foreach ($update_list as $status => $filelist) { if ($status != 'up_to_date' && $status != 'custom' && $status != 'status' && sizeof($filelist)) { $all_up_to_date = false; break; } } $template->assign_vars(array( 'S_FILE_CHECK' => true, 'S_ALL_UP_TO_DATE' => $all_up_to_date, 'S_VERSION_UP_TO_DATE' => $up_to_date, 'U_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=file_check"), 'U_UPDATE_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=update_files"), 'U_DB_UPDATE_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=update_db"), )); if ($all_up_to_date) { // Add database update to log add_log('admin', 'LOG_UPDATE_PHPBB', $this->current_version, $this->latest_version); // Refresh prosilver css data - this may cause some unhappy users, but $sql = 'SELECT * FROM ' . STYLES_THEME_TABLE . " WHERE theme_name = 'prosilver'"; $result = $db->sql_query($sql); $theme = $db->sql_fetchrow($result); $db->sql_freeresult($result); if ($theme) { $recache = (empty($theme['theme_data'])) ? true : false; $update_time = time(); // We test for stylesheet.css because it is faster and most likely the only file changed on common themes if (!$recache && $theme['theme_mtime'] < @filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css')) { $recache = true; $update_time = @filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css'); } else if (!$recache) { $last_change = $theme['theme_mtime']; $dir = @opendir("{$phpbb_root_path}styles/{$theme['theme_path']}/theme"); if ($dir) { while (($entry = readdir($dir)) !== false) { if (substr(strrchr($entry, '.'), 1) == 'css' && $last_change < @filemtime("{$phpbb_root_path}styles/{$theme['theme_path']}/theme/{$entry}")) { $recache = true; break; } } closedir($dir); } } if ($recache) { include_once($phpbb_root_path . 'includes/acp/acp_styles.' . $phpEx); $theme['theme_data'] = acp_styles::db_theme_data($theme); $theme['theme_mtime'] = $update_time; // Save CSS contents $sql_ary = array( 'theme_mtime' => $theme['theme_mtime'], 'theme_data' => $theme['theme_data'] ); $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE theme_id = ' . $theme['theme_id']; $db->sql_query($sql); $cache->destroy('sql', STYLES_THEME_TABLE); } } $db->sql_return_on_error(true); $db->sql_query('DELETE FROM ' . CONFIG_TABLE . " WHERE config_name = 'version_update_from'"); $db->sql_return_on_error(false); $cache->purge(); } break; case 'update_files': $this->page_title = 'STAGE_UPDATE_FILES'; $s_hidden_fields = ''; $params = array(); $conflicts = request_var('conflict', array('' => 0)); $modified = request_var('modified', array('' => 0)); foreach ($conflicts as $filename => $merge_option) { $s_hidden_fields .= '<input type="hidden" name="conflict[' . htmlspecialchars($filename) . ']" value="' . $merge_option . '" />'; $params[] = 'conflict[' . urlencode($filename) . ']=' . urlencode($merge_option); } foreach ($modified as $filename => $merge_option) { if (!$merge_option) { continue; } $s_hidden_fields .= '<input type="hidden" name="modified[' . htmlspecialchars($filename) . ']" value="' . $merge_option . '" />'; $params[] = 'modified[' . urlencode($filename) . ']=' . urlencode($merge_option); } $no_update = request_var('no_update', array(0 => '')); foreach ($no_update as $index => $filename) { $s_hidden_fields .= '<input type="hidden" name="no_update[]" value="' . htmlspecialchars($filename) . '" />'; $params[] = 'no_update[]=' . urlencode($filename); } // Before the user is choosing his preferred method, let's create the content list... $update_list = $cache->get('_update_list'); if ($update_list === false) { trigger_error($user->lang['NO_UPDATE_INFO'], E_USER_ERROR); } // Check if the conflicts data is valid if (sizeof($conflicts)) { $conflict_filenames = array(); foreach ($update_list['conflict'] as $files) { $conflict_filenames[] = $files['filename']; } $new_conflicts = array(); foreach ($conflicts as $filename => $diff_method) { if (in_array($filename, $conflict_filenames)) { $new_conflicts[$filename] = $diff_method; } } $conflicts = $new_conflicts; } // Build list for modifications if (sizeof($modified)) { $modified_filenames = array(); foreach ($update_list['modified'] as $files) { $modified_filenames[] = $files['filename']; } $new_modified = array(); foreach ($modified as $filename => $diff_method) { if (in_array($filename, $modified_filenames)) { $new_modified[$filename] = $diff_method; } } $modified = $new_modified; } // Check number of conflicting files, they need to be equal. For modified files the number can differ if (sizeof($update_list['conflict']) != sizeof($conflicts)) { trigger_error($user->lang['MERGE_SELECT_ERROR'], E_USER_ERROR); } // Before we do anything, let us diff the files and store the raw file information "somewhere" $get_files = false; $file_list = $cache->get('_diff_files'); if ($file_list === false || $file_list['status'] != -1) { $get_files = true; } if ($get_files) { if ($file_list === false) { $file_list = array( 'status' => 0, ); } $processed = 0; foreach ($update_list as $status => $files) { if (!is_array($files)) { continue; } foreach ($files as $file_struct) { // Skip this file if the user selected to not update it if (in_array($file_struct['filename'], $no_update)) { continue; } // Already handled... then skip of course... if (isset($file_list[$file_struct['filename']])) { continue; } // Refresh if we reach 5 diffs... if ($processed >= 5) { $cache->put('_diff_files', $file_list); if (!empty($_REQUEST['download'])) { $params[] = 'download=1'; } $redirect_url = append_sid($this->p_master->module_url, "mode=$mode&sub=update_files&" . implode('&', $params)); meta_refresh(3, $redirect_url); $template->assign_vars(array( 'S_IN_PROGRESS' => true, 'L_IN_PROGRESS' => $user->lang['MERGING_FILES'], 'L_IN_PROGRESS_EXPLAIN' => $user->lang['MERGING_FILES_EXPLAIN'], )); return; } $original_filename = ($file_struct['custom']) ? $file_struct['original'] : $file_struct['filename']; switch ($status) { case 'modified': $option = (isset($modified[$file_struct['filename']])) ? $modified[$file_struct['filename']] : 0; switch ($option) { case MERGE_NO_MERGE_NEW: $contents = file_get_contents($this->new_location . $original_filename); break; case MERGE_NO_MERGE_MOD: $contents = file_get_contents($phpbb_root_path . $file_struct['filename']); break; default: $diff = $this->return_diff($this->old_location . $original_filename, $phpbb_root_path . $file_struct['filename'], $this->new_location . $original_filename); $contents = implode("\n", $diff->merged_output()); unset($diff); break; } $file_list[$file_struct['filename']] = '_file_' . md5($file_struct['filename']); $cache->put($file_list[$file_struct['filename']], base64_encode($contents)); $file_list['status']++; $processed++; break; case 'conflict': $option = $conflicts[$file_struct['filename']]; $contents = ''; switch ($option) { case MERGE_NO_MERGE_NEW: $contents = file_get_contents($this->new_location . $original_filename); break; case MERGE_NO_MERGE_MOD: $contents = file_get_contents($phpbb_root_path . $file_struct['filename']); break; default: $diff = $this->return_diff($this->old_location . $original_filename, $phpbb_root_path . $file_struct['filename'], $this->new_location . $original_filename); if ($option == MERGE_NEW_FILE) { $contents = implode("\n", $diff->merged_new_output()); } else if ($option == MERGE_MOD_FILE) { $contents = implode("\n", $diff->merged_orig_output()); } else { unset($diff); break 2; } unset($diff); break; } $file_list[$file_struct['filename']] = '_file_' . md5($file_struct['filename']); $cache->put($file_list[$file_struct['filename']], base64_encode($contents)); $file_list['status']++; $processed++; break; } } } } $file_list['status'] = -1; $cache->put('_diff_files', $file_list); if (!empty($_REQUEST['download'])) { $this->include_file('includes/functions_compress.' . $phpEx); $use_method = request_var('use_method', ''); $methods = array('.tar'); $available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib'); foreach ($available_methods as $type => $module) { if (!@extension_loaded($module)) { continue; } $methods[] = $type; } // Let the user decide in which format he wants to have the pack if (!$use_method) { $this->page_title = 'SELECT_DOWNLOAD_FORMAT'; $radio_buttons = ''; foreach ($methods as $method) { $radio_buttons .= '<label><input type="radio"' . ((!$radio_buttons) ? ' id="use_method"' : '') . ' class="radio" value="' . $method . '" name="use_method" /> ' . $method . '</label>'; } $template->assign_vars(array( 'S_DOWNLOAD_FILES' => true, 'U_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=update_files"), 'RADIO_BUTTONS' => $radio_buttons, 'S_HIDDEN_FIELDS' => $s_hidden_fields) ); // To ease the update process create a file location map $update_list = $cache->get('_update_list'); $script_path = ($config['force_server_vars']) ? (($config['script_path'] == '/') ? '/' : $config['script_path'] . '/') : $user->page['root_script_path']; foreach ($update_list as $status => $files) { if ($status == 'up_to_date' || $status == 'no_update' || $status == 'status') { continue; } foreach ($files as $file_struct) { if (in_array($file_struct['filename'], $no_update)) { continue; } $template->assign_block_vars('location', array( 'SOURCE' => htmlspecialchars($file_struct['filename']), 'DESTINATION' => $script_path . htmlspecialchars($file_struct['filename']), )); } } return; } if (!in_array($use_method, $methods)) { $use_method = '.tar'; } $update_mode = 'download'; } else { $this->include_file('includes/functions_transfer.' . $phpEx); // Choose FTP, if not available use fsock... $method = basename(request_var('method', '')); $submit = (isset($_POST['submit'])) ? true : false; $test_ftp_connection = request_var('test_connection', ''); if (!$method || !class_exists($method)) { $method = 'ftp'; $methods = transfer::methods(); if (!in_array('ftp', $methods)) { $method = $methods[0]; } } $test_connection = false; if ($test_ftp_connection || $submit) { $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); $test_connection = $transfer->open_session(); // Make sure that the directory is correct by checking for the existence of common.php if ($test_connection === true) { // Check for common.php file if (!$transfer->file_exists($phpbb_root_path, 'common.' . $phpEx)) { $test_connection = 'ERR_WRONG_PATH_TO_PHPBB'; } } $transfer->close_session(); // Make sure the login details are correct before continuing if ($submit && $test_connection !== true) { $submit = false; $test_ftp_connection = true; } } $s_hidden_fields .= build_hidden_fields(array('method' => $method)); if (!$submit) { $this->page_title = 'SELECT_FTP_SETTINGS'; if (!class_exists($method)) { trigger_error('Method does not exist.', E_USER_ERROR); } $requested_data = call_user_func(array($method, 'data')); foreach ($requested_data as $data => $default) { $template->assign_block_vars('data', array( 'DATA' => $data, 'NAME' => $user->lang[strtoupper($method . '_' . $data)], 'EXPLAIN' => $user->lang[strtoupper($method . '_' . $data) . '_EXPLAIN'], 'DEFAULT' => (!empty($_REQUEST[$data])) ? request_var($data, '') : $default )); } $template->assign_vars(array( 'S_CONNECTION_SUCCESS' => ($test_ftp_connection && $test_connection === true) ? true : false, 'S_CONNECTION_FAILED' => ($test_ftp_connection && $test_connection !== true) ? true : false, 'ERROR_MSG' => ($test_ftp_connection && $test_connection !== true) ? $user->lang[$test_connection] : '', 'S_FTP_UPLOAD' => true, 'UPLOAD_METHOD' => $method, 'U_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=update_files"), 'U_DOWNLOAD_METHOD' => append_sid($this->p_master->module_url, "mode=$mode&sub=update_files&download=1"), 'S_HIDDEN_FIELDS' => $s_hidden_fields, )); return; } $update_mode = 'upload'; } // Now update the installation or download the archive... $download_filename = 'update_' . $this->update_info['version']['from'] . '_to_' . $this->update_info['version']['to']; $archive_filename = $download_filename . '_' . time() . '_' . unique_id(); // Now init the connection if ($update_mode == 'download') { if ($use_method == '.zip') { $compress = new compress_zip('w', $phpbb_root_path . 'store/' . $archive_filename . $use_method); } else { $compress = new compress_tar('w', $phpbb_root_path . 'store/' . $archive_filename . $use_method, $use_method); } } else { $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); $transfer->open_session(); } // Ok, go through the update list and do the operations based on their status foreach ($update_list as $status => $files) { if (!is_array($files)) { continue; } foreach ($files as $file_struct) { // Skip this file if the user selected to not update it if (in_array($file_struct['filename'], $no_update)) { continue; } $original_filename = ($file_struct['custom']) ? $file_struct['original'] : $file_struct['filename']; switch ($status) { case 'new': case 'new_conflict': case 'not_modified': if ($update_mode == 'download') { $compress->add_custom_file($this->new_location . $original_filename, $file_struct['filename']); } else { if ($status != 'new') { $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak'); } // New directory too? $dirname = dirname($file_struct['filename']); if ($dirname && !file_exists($phpbb_root_path . $dirname)) { $transfer->make_dir($dirname); } $transfer->copy_file($this->new_location . $original_filename, $file_struct['filename']); } break; case 'modified': $contents = base64_decode($cache->get($file_list[$file_struct['filename']])); if ($update_mode == 'download') { $compress->add_data($contents, $file_struct['filename']); } else { // @todo add option to specify if a backup file should be created? $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak'); $transfer->write_file($file_struct['filename'], $contents); } break; case 'conflict': $contents = base64_decode($cache->get($file_list[$file_struct['filename']])); if ($update_mode == 'download') { $compress->add_data($contents, $file_struct['filename']); } else { $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak'); $transfer->write_file($file_struct['filename'], $contents); } break; } } } if ($update_mode == 'download') { $compress->close(); $compress->download($archive_filename, $download_filename); @unlink($phpbb_root_path . 'store/' . $archive_filename . $use_method); exit; } else { $transfer->close_session(); $template->assign_vars(array( 'S_UPLOAD_SUCCESS' => true, 'U_ACTION' => append_sid($this->p_master->module_url, "mode=$mode&sub=file_check")) ); return; } break; } }
/** * Returns a string containing the value that should be used for the theme_data column in the theme database table. * Includes contents of files loaded via @import * * @param array $theme_row is an associative array containing the theme's current database entry * @param mixed $stylesheet can either be the new content for the stylesheet or false to load from the standard file * @param string $root_path should only be used in case you want to use a different root path than "{$phpbb_root_path}styles/{$theme_row['theme_path']}" * * @return string Stylesheet data for theme_data column in the theme table */ function db_theme_data($theme_row, $stylesheet = false, $root_path = '') { global $phpbb_root_path; if (!$root_path) { $root_path = $phpbb_root_path . 'styles/' . $theme_row['theme_path']; } if (!$stylesheet) { $stylesheet = ''; if (file_exists($root_path . '/theme/stylesheet.css')) { $stylesheet = file_get_contents($root_path . '/theme/stylesheet.css'); } } // Match CSS imports $matches = array(); preg_match_all('/@import url\\((["\'])(.*)\\1\\);/i', $stylesheet, $matches); // remove commented stylesheets (very simple parser, allows only whitespace // around an @import statement) preg_match_all('#/\\*\\s*@import url\\((["\'])(.*)\\1\\);\\s\\*/#i', $stylesheet, $commented); $matches[2] = array_diff($matches[2], $commented[2]); if (sizeof($matches)) { foreach ($matches[0] as $idx => $match) { if (isset($matches[2][$idx])) { $stylesheet = str_replace($match, acp_styles::load_css_file($theme_row['theme_path'], $matches[2][$idx]), $stylesheet); } } } // adjust paths return str_replace('./', 'styles/' . $theme_row['theme_path'] . '/theme/', $stylesheet); }
function main($mode, $sub) { global $lang, $template, $language, $phpbb_root_path, $phpEx, $config, $db, $table_prefix, $db, $auth, $cache, $user; $this->old_location = $phpbb_root_path . 'garage/install/install/old/'; $this->new_location = $phpbb_root_path . 'garage/install/install/new/'; // Special options for conflicts/modified files define('MERGE_NO_MERGE_NEW', 1); define('MERGE_NO_MERGE_MOD', 2); define('MERGE_NEW_FILE', 3); define('MERGE_MOD_FILE', 4); $this->install_info = $this->get_file('install_info'); // Include renderer and engine $this->include_file('includes/diff/diff.' . $phpEx); $this->include_file('includes/diff/engine.' . $phpEx); $this->include_file('includes/diff/renderer.' . $phpEx); // Make sure we stay at the file check if checking the files again if (!empty($_POST['check_again'])) { $sub = $this->p_master->sub = 'file_check'; } $this->tpl_name = 'garage_install_install'; switch ($sub) { case 'intro': $this->page_title = $lang['SUB_INTRO']; $template->assign_vars(array('TITLE' => $lang['INSTALL_INTRO'], 'BODY' => $lang['INSTALL_INTRO_BODY'], 'L_SUBMIT' => $lang['NEXT_STEP'], 'U_ACTION' => $this->p_master->module_url . "?mode={$mode}&sub=requirements&language={$language}")); break; case 'requirements': $this->check_server_requirements($mode, $sub); break; case 'optional': $this->obtain_optional_settings($mode, $sub); break; case 'create_table': $this->load_schema($mode, $sub); break; case 'create_permissions': $this->add_permissions($mode, $sub); $this->update_group_permissions($mode, $sub); $this->update_role_permissions($mode, $sub); $submit = $lang['NEXT_STEP']; $url = $this->p_master->module_url . "?mode={$mode}&sub=install_modules"; $template->assign_vars(array('BODY' => $lang['STAGE_CREATE_PERMISSIONS_EXPLAIN'], 'L_SUBMIT' => $submit, 'U_ACTION' => $url)); break; case 'install_modules': $this->add_modules($mode, $sub); $submit = $lang['NEXT_STEP']; $url = $this->p_master->module_url . "?mode={$mode}&sub=file_check"; $template->assign_vars(array('BODY' => $lang['STAGE_INSTALL_MODULES_EXPLAIN'], 'L_SUBMIT' => $submit, 'U_ACTION' => $url)); break; // Last step is just a re-check of files... // Last step is just a re-check of files... case 'final': case 'file_check': $this->tpl_name = 'garage_install_update'; $this->page_title = 'STAGE_FILE_CHECK'; // Now make sure our install list is correct if the admin refreshes $action = request_var('action', ''); // We are directly within an update. To make sure our install list is correct we check its status. $install_list = !empty($_POST['check_again']) ? false : $cache->get('_install_list'); $modified = $install_list !== false ? @filemtime($cache->cache_dir . 'data_install_list.' . $phpEx) : 0; // Make sure the list is up-to-date if ($install_list !== false) { $get_new_list = false; foreach ($this->install_info['files'] as $file) { if (file_exists($phpbb_root_path . $file) && filemtime($phpbb_root_path . $file) > $modified) { $get_new_list = true; break; } } } else { $get_new_list = true; } if ($get_new_list) { $install_list = $this->get_install_structure(); $cache->put('_install_list', $install_list); } if ($action == 'diff') { $this->show_diff($install_list); return; } // Now assign the list to the template foreach ($install_list as $status => $filelist) { if ($status == 'no_update' || !sizeof($filelist)) { continue; } $template->assign_block_vars('files', array('S_STATUS' => true, 'STATUS' => $status, 'L_STATUS' => $user->lang['STATUS_' . strtoupper($status)], 'TITLE' => $user->lang['FILES_' . strtoupper($status)], 'EXPLAIN' => $user->lang['FILES_' . strtoupper($status) . '_EXPLAIN'])); foreach ($filelist as $file_struct) { $filename = htmlspecialchars($file_struct['filename']); if (strrpos($filename, '/') !== false) { $dir_part = substr($filename, 0, strrpos($filename, '/') + 1); $file_part = substr($filename, strrpos($filename, '/') + 1); } else { $dir_part = ''; $file_part = $filename; } $diff_url = append_sid($this->p_master->module_url, "mode={$mode}&sub=file_check&action=diff&status={$status}&file=" . urlencode($file_struct['filename'])); $template->assign_block_vars('files', array('STATUS' => $status, 'FILENAME' => $filename, 'DIR_PART' => $dir_part, 'FILE_PART' => $file_part, 'NUM_CONFLICTS' => isset($file_struct['conflicts']) ? $file_struct['conflicts'] : 0, 'S_CUSTOM' => $file_struct['custom'] ? true : false, 'CUSTOM_ORIGINAL' => $file_struct['custom'] ? $file_struct['original'] : '', 'U_SHOW_DIFF' => $diff_url, 'L_SHOW_DIFF' => $status != 'up_to_date' ? $user->lang['SHOW_DIFF_' . strtoupper($status)] : '', 'U_VIEW_MOD_FILE' => $diff_url . '&op=' . MERGE_MOD_FILE, 'U_VIEW_NEW_FILE' => $diff_url . '&op=' . MERGE_NEW_FILE, 'U_VIEW_NO_MERGE_MOD' => $diff_url . '&op=' . MERGE_NO_MERGE_MOD, 'U_VIEW_NO_MERGE_NEW' => $diff_url . '&op=' . MERGE_NO_MERGE_NEW)); } } $all_up_to_date = true; foreach ($install_list as $status => $filelist) { if ($status != 'up_to_date' && $status != 'custom' && sizeof($filelist)) { $all_up_to_date = false; break; } } $template->assign_vars(array('S_FILE_CHECK' => true, 'S_ALL_UP_TO_DATE' => $all_up_to_date, 'U_ACTION' => append_sid($this->p_master->module_url, "mode={$mode}&sub=file_check"), 'U_UPDATE_ACTION' => append_sid($this->p_master->module_url, "mode={$mode}&sub=update_files"))); if ($all_up_to_date and $sub == 'final') { // Remove the lock file @unlink($phpbb_root_path . 'cache/install_lock'); } // Make sure we stay at the final if we checked_again and all is now up to date if (!empty($_POST['check_again']) && $all_up_to_date) { $sub = $this->p_master->sub = 'final'; } if ($all_up_to_date) { // Refresh any style css data we updated - this may cause some unhappy users, but $sql = 'SELECT * FROM ' . STYLES_THEME_TABLE; $result = $db->sql_query($sql); while ($theme = $db->sql_fetchrow($result)) { //Check For Themes Updated By Installer if (file_exists($phpbb_root_path . "garage/install/install/styles/{$theme['theme_name']}/theme/index." . $phpEx)) { $recache = empty($theme['theme_data']) ? true : false; $update_time = time(); // We test for stylesheet.css because it is faster and most likely the only file changed on common themes if (!$recache && $theme['theme_mtime'] < @filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css')) { $recache = true; $update_time = @filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css'); } else { if (!$recache) { $last_change = $theme['theme_mtime']; $dir = @opendir("{$phpbb_root_path}styles/{$theme['theme_path']}/theme"); if ($dir) { while (($entry = readdir($dir)) !== false) { if (substr(strrchr($entry, '.'), 1) == 'css' && $last_change < @filemtime("{$phpbb_root_path}styles/{$theme['theme_path']}/theme/{$entry}")) { $recache = true; break; } } closedir($dir); } } } if ($recache) { include_once $phpbb_root_path . 'includes/acp/acp_styles.' . $phpEx; $theme['theme_data'] = acp_styles::db_theme_data($theme); $theme['theme_mtime'] = $update_time; // Save CSS contents $sql_ary = array('theme_mtime' => $theme['theme_mtime'], 'theme_data' => $theme['theme_data']); $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE theme_id = ' . $theme['theme_id']; $db->sql_query($sql); $cache->destroy('sql', STYLES_THEME_TABLE); } } } $db->sql_freeresult($result); // Refresh any imageset data we updated - but only for garage images $sql = 'SELECT * FROM ' . STYLES_IMAGESET_TABLE; $result = $db->sql_query($sql); while ($imageset = $db->sql_fetchrow($result)) { $sql_ary = array(); $db->sql_transaction('begin'); if (!class_exists('garage_template')) { include $phpbb_root_path . 'includes/mods/class_garage_template.' . $phpEx; $garage_template = new garage_template(); } //We need to build the imageset_keys now only for garage keys $imageset_keys = array(); $imageset_keys['buttons'] = array(); $imageset_keys = $garage_template->update_imageset_keys($imageset_keys); $imageset_definitions = array(); foreach ($imageset_keys as $topic => $key_array) { $imageset_definitions = array_merge($imageset_definitions, $key_array); } //Check For Imageset Updated By Installer if (file_exists($phpbb_root_path . "garage/install/install/new/styles/{$imageset['imageset_path']}/imageset/imageset.cfg")) { $cfg_data_imageset = parse_cfg_file("{$phpbb_root_path}styles/{$imageset['imageset_path']}/imageset/imageset.cfg"); $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . ' WHERE imageset_id = ' . $imageset['imageset_id'] . ' AND ' . $db->sql_in_set('image_name', $imageset_keys['garage']); $db->sql_query($sql); foreach ($cfg_data_imageset as $image_name => $value) { //Lets cut to the chase and make sure we only work with garage images $image_wanted = substr($image_name, 4); if (!in_array($image_wanted, $imageset_keys['garage'])) { continue; } if (strpos($value, '*') !== false) { if (substr($value, -1, 1) === '*') { list($image_filename, $image_height) = explode('*', $value); $image_width = 0; } else { list($image_filename, $image_height, $image_width) = explode('*', $value); } } else { $image_filename = $value; $image_height = $image_width = 0; } if (strpos($image_name, 'img_') === 0 && $image_filename) { $image_name = substr($image_name, 4); if (in_array($image_name, $imageset_definitions)) { $sql_ary[] = array('image_name' => (string) $image_name, 'image_filename' => (string) $image_filename, 'image_height' => (int) $image_height, 'image_width' => (int) $image_width, 'imageset_id' => (int) $imageset['imageset_id'], 'image_lang' => ''); } } } } $sql2 = 'SELECT lang_dir FROM ' . LANG_TABLE; $result2 = $db->sql_query($sql2); while ($language = $db->sql_fetchrow($result2)) { //Check For Language Imageset Updated By Installer if (file_exists($phpbb_root_path . "garage/install/install/new/styles/{$imageset['imageset_path']}/imageset/{$language['lang_dir']}/imageset.cfg")) { $cfg_data_imageset_data = parse_cfg_file("{$phpbb_root_path}styles/{$imageset['imageset_path']}/imageset/{$language['lang_dir']}/imageset.cfg"); $sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . ' WHERE imageset_id = ' . $imageset['imageset_id'] . ' AND ' . $db->sql_in_set('image_name', $imageset_keys['buttons']) . "\n\t\t\t\t\t\t\t\t\t\tAND image_lang = '{$language['lang_dir']}'"; $db->sql_query($sql); foreach ($cfg_data_imageset_data as $image_name => $value) { //Lets cut to the chase and make sure we only work with garage images $image_wanted = substr($image_name, 4); if (!in_array($image_wanted, $imageset_keys['buttons'])) { continue; } if (strpos($value, '*') !== false) { if (substr($value, -1, 1) === '*') { list($image_filename, $image_height) = explode('*', $value); $image_width = 0; } else { list($image_filename, $image_height, $image_width) = explode('*', $value); } } else { $image_filename = $value; $image_height = $image_width = 0; } if (strpos($image_name, 'img_') === 0 && $image_filename) { $image_name = substr($image_name, 4); if (in_array($image_name, $imageset_definitions)) { $sql_ary[] = array('image_name' => (string) $image_name, 'image_filename' => (string) $image_filename, 'image_height' => (int) $image_height, 'image_width' => (int) $image_width, 'imageset_id' => (int) $imageset['imageset_id'], 'image_lang' => (string) $language['lang_dir']); } } } } } $db->sql_freeresult($result2); $db->sql_multi_insert(STYLES_IMAGESET_DATA_TABLE, $sql_ary); $db->sql_transaction('commit'); } $db->sql_freeresult($result); $cache->destroy('sql', STYLES_IMAGESET_DATA_TABLE); add_log('admin', 'LOG_IMAGESET_REFRESHED', $imageset['imageset_name']); $db->sql_return_on_error(true); $db->sql_query('DELETE FROM ' . GARAGE_CONFIG_TABLE . " WHERE config_name = 'version_update_from'"); $db->sql_return_on_error(false); $cache->purge(); } break; case 'update_files': $this->tpl_name = 'garage_install_update'; $this->page_title = 'STAGE_UPDATE_FILES'; $s_hidden_fields = ''; $conflicts = request_var('conflict', array('' => 0)); $modified = request_var('modified', array('' => 0)); foreach ($conflicts as $filename => $merge_option) { $s_hidden_fields .= '<input type="hidden" name="conflict[' . htmlspecialchars($filename) . ']" value="' . $merge_option . '" />'; } foreach ($modified as $filename => $merge_option) { if (!$merge_option) { continue; } $s_hidden_fields .= '<input type="hidden" name="modified[' . htmlspecialchars($filename) . ']" value="' . $merge_option . '" />'; } $no_update = request_var('no_update', array(0 => '')); foreach ($no_update as $index => $filename) { $s_hidden_fields .= '<input type="hidden" name="no_update[]" value="' . htmlspecialchars($filename) . '" />'; } if (!empty($_POST['download'])) { $this->include_file('includes/functions_compress.' . $phpEx); $use_method = request_var('use_method', ''); $methods = array('.tar'); $available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib'); foreach ($available_methods as $type => $module) { if (!@extension_loaded($module)) { continue; } $methods[] = $type; } // Let the user decide in which format he wants to have the pack if (!$use_method) { $this->page_title = 'SELECT_DOWNLOAD_FORMAT'; $radio_buttons = ''; foreach ($methods as $method) { $radio_buttons .= '<label><input type="radio"' . (!$radio_buttons ? ' id="use_method"' : '') . ' class="radio" value="' . $method . '" name="use_method" /> ' . $method . '</label>'; } $template->assign_vars(array('S_DOWNLOAD_FILES' => true, 'U_ACTION' => append_sid($this->p_master->module_url, "mode={$mode}&sub=update_files"), 'RADIO_BUTTONS' => $radio_buttons, 'S_HIDDEN_FIELDS' => $s_hidden_fields)); // To ease the update process create a file location map $install_list = $cache->get('_install_list'); $script_path = $config['force_server_vars'] ? $config['script_path'] == '/' ? '/' : $config['script_path'] . '/' : $user->page['root_script_path']; foreach ($install_list as $status => $files) { if ($status == 'up_to_date' || $status == 'no_update') { continue; } foreach ($files as $file_struct) { if (in_array($file_struct['filename'], $no_update)) { continue; } $template->assign_block_vars('location', array('SOURCE' => htmlspecialchars($file_struct['filename']), 'DESTINATION' => $script_path . htmlspecialchars($file_struct['filename']))); } } return; } if (!in_array($use_method, $methods)) { $use_method = '.tar'; } $update_mode = 'download'; } else { $this->include_file('includes/functions_transfer.' . $phpEx); // Choose FTP, if not available use fsock... $method = request_var('method', ''); $submit = isset($_POST['submit']) ? true : false; $test_ftp_connection = request_var('test_connection', ''); if (!$method) { $method = 'ftp'; $methods = transfer::methods(); if (!in_array('ftp', $methods)) { $method = $methods[0]; } } $test_connection = false; if ($test_ftp_connection || $submit) { $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); $test_connection = $transfer->open_session(); // Make sure that the directory is correct by checking for the existence of common.php if ($test_connection === true) { // Check for common.php file if (!$transfer->file_exists($phpbb_root_path, 'common.' . $phpEx)) { $test_connection = 'ERR_WRONG_PATH_TO_PHPBB'; } } $transfer->close_session(); // Make sure the login details are correct before continuing if ($submit && $test_connection !== true) { $submit = false; $test_ftp_connection = true; } } if (!$submit) { $this->page_title = 'SELECT_FTP_SETTINGS'; if (!class_exists($method)) { trigger_error('Method does not exist.', E_USER_ERROR); } $requested_data = call_user_func(array($method, 'data')); foreach ($requested_data as $data => $default) { $template->assign_block_vars('data', array('DATA' => $data, 'NAME' => $user->lang[strtoupper($method . '_' . $data)], 'EXPLAIN' => $user->lang[strtoupper($method . '_' . $data) . '_EXPLAIN'], 'DEFAULT' => !empty($_REQUEST[$data]) ? request_var($data, '') : $default)); } $s_hidden_fields .= build_hidden_fields(array('method' => $method)); $template->assign_vars(array('S_CONNECTION_SUCCESS' => $test_ftp_connection && $test_connection === true ? true : false, 'S_CONNECTION_FAILED' => $test_ftp_connection && $test_connection !== true ? true : false, 'ERROR_MSG' => $test_ftp_connection && $test_connection !== true ? $user->lang[$test_connection] : '', 'S_FTP_UPLOAD' => true, 'UPLOAD_METHOD' => $method, 'U_ACTION' => append_sid($this->p_master->module_url, "mode={$mode}&sub=update_files"), 'S_HIDDEN_FIELDS' => $s_hidden_fields)); return; } $update_mode = 'upload'; } // Now update the installation or download the archive... $download_filename = 'install_phpbbgarage_' . $this->install_info['version']['install']; $archive_filename = $download_filename . '_' . time() . '_' . unique_id(); $install_list = $cache->get('_install_list'); $conflicts = request_var('conflict', array('' => 0)); $modified = request_var('modified', array('' => 0)); if ($install_list === false) { trigger_error($user->lang['NO_UPDATE_INFO'], E_USER_ERROR); } // Check if the conflicts data is valid if (sizeof($conflicts)) { $conflict_filenames = array(); foreach ($install_list['conflict'] as $files) { $conflict_filenames[] = $files['filename']; } $new_conflicts = array(); foreach ($conflicts as $filename => $diff_method) { if (in_array($filename, $conflict_filenames)) { $new_conflicts[$filename] = $diff_method; } } $conflicts = $new_conflicts; } // Build list for modifications if (sizeof($modified)) { $modified_filenames = array(); foreach ($install_list['modified'] as $files) { $modified_filenames[] = $files['filename']; } $new_modified = array(); foreach ($modified as $filename => $diff_method) { if (in_array($filename, $modified_filenames)) { $new_modified[$filename] = $diff_method; } } $modified = $new_modified; } // Check number of conflicting files, they need to be equal. For modified files the number can differ if (sizeof($install_list['conflict']) != sizeof($conflicts)) { trigger_error($user->lang['MERGE_SELECT_ERROR'], E_USER_ERROR); } // Now init the connection if ($update_mode == 'download') { if ($use_method == '.zip') { $compress = new compress_zip('w', $phpbb_root_path . 'store/' . $archive_filename . $use_method); } else { $compress = new compress_tar('w', $phpbb_root_path . 'store/' . $archive_filename . $use_method, $use_method); } } else { $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); $transfer->open_session(); } // Ok, go through the update list and do the operations based on their status foreach ($install_list as $status => $files) { foreach ($files as $file_struct) { // Skip this file if the user selected to not update it if (in_array($file_struct['filename'], $no_update)) { continue; } $original_filename = $file_struct['custom'] ? $file_struct['original'] : $file_struct['filename']; switch ($status) { case 'new': case 'new_conflict': case 'not_modified': if ($update_mode == 'download') { $compress->add_custom_file($this->new_location . $original_filename, $file_struct['filename']); } else { if ($status != 'new') { $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak'); } $transfer->copy_file($this->new_location . $original_filename, $file_struct['filename']); } break; case 'modified': $option = isset($modified[$file_struct['filename']]) ? $modified[$file_struct['filename']] : 0; switch ($option) { case MERGE_NO_MERGE_NEW: $contents = file_get_contents($this->new_location . $original_filename); break; case MERGE_NO_MERGE_MOD: $contents = file_get_contents($phpbb_root_path . $file_struct['filename']); break; default: $diff = $this->return_diff($this->old_location . $original_filename, $phpbb_root_path . $file_struct['filename'], $this->new_location . $original_filename); $contents = implode("\n", $diff->merged_output()); unset($diff); break; } if ($update_mode == 'download') { $compress->add_data($contents, $file_struct['filename']); } else { // @todo add option to specify if a backup file should be created? $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak'); $transfer->write_file($file_struct['filename'], $contents); } break; case 'conflict': $option = $conflicts[$file_struct['filename']]; $contents = ''; switch ($option) { case MERGE_NO_MERGE_NEW: $contents = file_get_contents($this->new_location . $original_filename); break; case MERGE_NO_MERGE_MOD: $contents = file_get_contents($phpbb_root_path . $file_struct['filename']); break; default: $diff = $this->return_diff($this->old_location . $original_filename, $phpbb_root_path . $file_struct['filename'], $this->new_location . $original_filename); if ($option == MERGE_NEW_FILE) { $contents = implode("\n", $diff->merged_new_output()); } else { if ($option == MERGE_MOD_FILE) { $contents = implode("\n", $diff->merged_orig_output()); } else { unset($diff); break 2; } } unset($diff); break; } if ($update_mode == 'download') { $compress->add_data($contents, $file_struct['filename']); } else { $transfer->rename($file_struct['filename'], $file_struct['filename'] . '.bak'); $transfer->write_file($file_struct['filename'], $contents); } break; } } } if ($update_mode == 'download') { $compress->close(); $compress->download($archive_filename, $download_filename); @unlink($phpbb_root_path . 'store/' . $archive_filename . $use_method); exit; } else { $transfer->close_session(); $template->assign_vars(array('S_UPLOAD_SUCCESS' => true, 'U_ACTION' => append_sid($this->p_master->module_url, "mode={$mode}&sub=final"))); return; } break; } switch ($sub) { case 'final': $this->tpl_name = 'garage_install_install'; // Remove the lock file @unlink($phpbb_root_path . 'cache/install_lock'); $sql = $db->sql_build_query('SELECT', array('SELECT' => 'c.config_name, c.config_value', 'FROM' => array(GARAGE_CONFIG_TABLE => 'c'))); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $garage_config[$row['config_name']] = $row['config_value']; } $db->sql_freeresult($result); add_log('admin', 'LOG_GARAGE_INSTALL', $garage_config['version']); $template->assign_vars(array('S_FILE_CHECK' => false, 'TITLE' => $lang['INSTALL_CONGRATS'], 'BODY' => sprintf($lang['INSTALL_CONGRATS_EXPLAIN'], $garage_config['version'], append_sid($phpbb_root_path . 'garage/install/index.' . $phpEx, 'mode=convert&'), '../docs/README.html'))); $sql = 'INSERT INTO ' . GARAGE_CONFIG_TABLE . ' ' . $db->sql_build_array('INSERT', array('config_name' => 'installed', 'config_value' => 1)); $db->sql_query($sql); $cache->purge(); break; } }
function installStyle($styleName) { global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix; if (preg_match('/([^a-z0-9_]+)/iS',$styleName)) throw new Exception('Style name is not valid',1001); $res = $db->sql_query( "SELECT * FROM {$table_prefix}styles WHERE style_name = '{$styleName}'" ); $styles = new acp_styles(); if ($db->sql_affectedrows()) { $row = $db->sql_fetchrow(); $db->sql_query( "UPDATE {$table_prefix}styles SET style_active = 0" ); $db->sql_query( "UPDATE {$table_prefix}styles SET style_name = '{$styleName}', style_active = 1 WHERE style_id = {$row['style_id']}" ); $db->sql_query( "UPDATE {$table_prefix}users SET user_style = " . $row['style_id'] ); set_config('default_style', $row['style_id']); } else { // getting instalation config $installcfg = parse_cfg_file( $phpbb_root_path . 'styles' . DIRECTORY_SEPARATOR . $styleName . DIRECTORY_SEPARATOR . 'style.cfg' ); // prepare data to install $error = array(); $action = 'install'; $root_path = $phpbb_root_path . 'styles/' . $styleName . '/'; $id = 0; $name = $styleName; $path = $styleName; $copyright = $installcfg['copyright']; $active = 1; $default = 1; $style_row = array(); if (!is_dir($root_path)) throw new Exception('Directory not found',1002); $element_ary = array( 'template' => STYLES_TEMPLATE_TABLE, 'theme' => STYLES_THEME_TABLE, 'imageset' => STYLES_IMAGESET_TABLE ); $style_row = array( 'style_id' => 0, 'style_name' => $installcfg['name'], 'style_copyright' => $installcfg['copyright'] ); $reqd_template = (isset($installcfg['required_template'])) ? $installcfg['required_template'] : false; $reqd_theme = (isset($installcfg['required_theme'])) ? $installcfg['required_theme'] : false; $reqd_imageset = (isset($installcfg['required_imageset'])) ? $installcfg['required_imageset'] : false; // Getting related info foreach ($element_ary as $element => $table) { $style_row = array_merge( $style_row, array( $element . '_id' => 0, $element . '_name' => '', $element . '_copyright' => '' ) ); $styles->test_installed( $element, $error, (${'reqd_' . $element}) ? $phpbb_root_path . 'styles/' . $reqd_template .'/' : $root_path, ${'reqd_' . $element}, $style_row[$element . '_id'], $style_row[$element . '_name'], $style_row[$element . '_copyright'] ); if (!$style_row[$element . '_name']) $style_row[$element . '_name'] = $reqd_template; } // Install $styles->install_style( $error, $action, $root_path, $id, $name, $path, $copyright, $active, $default, $style_row ); } }
public function __construct() { global $db, $user, $auth, $cache; global $quickinstall_path, $phpbb_root_path, $phpEx, $config, $qi_config, $msg_title; // include installation functions include $quickinstall_path . 'includes/functions_install.' . $phpEx; // include($quickinstall_path . 'includes/qi_functions.' . $phpEx); $config = array_merge($config, array('rand_seed' => md5(mt_rand()), 'rand_seed_last_update' => time())); // load installer lang qi::add_lang('phpbb'); // phpbb's install uses $lang instead of $user->lang // need to use $GLOBALS here $GLOBALS['lang'] =& $user->lang; global $lang; // request variables $dbname = htmlspecialchars_decode(request_var('dbname', '', true)); $redirect = request_var('redirect', false); $drop_db = request_var('drop_db', false); $delete_files = request_var('delete_files', false); $automod = request_var('automod', false); $make_writable = request_var('make_writable', false); $populate = request_var('populate', false); $subsilver = request_var('subsilver', 0); $alt_env = request_var('alt_env', ''); $pop_data = request_var('pop_data', array('' => '')); // Some populate checking if ($populate) { if (empty($pop_data['num_users']) && empty($pop_data['num_cats']) && empty($pop_data['num_forums']) && empty($pop_data['num_topics']) && empty($pop_data['num_replies'])) { // populate with nothing? $populate = false; } else { $pop_data['email_domain'] = trim($pop_data['email_domain']); if (!empty($pop_data['num_users']) && empty($pop_data['email_domain'])) { trigger_error($user->lang['NEED_EMAIL_DOMAIN'], E_USER_ERROR); } } } foreach (array('site_name', 'site_desc', 'table_prefix', 'admin_name', 'admin_pass') as $r) { if ($_r = request_var($r, '', true)) { $qi_config[$r] = $_r; } } if ($alt_env !== '' && !file_exists($quickinstall_path . 'sources/phpBB3_alt/' . $alt_env)) { trigger_error('NO_ALT_ENV'); } // Set up our basic founder. $user->data['user_id'] = 2; // $user->data['username'] = $qi_config['admin_name']; $user->data['user_colour'] = 'AA0000'; // overwrite some of them ;) $user->lang = array_merge($user->lang, array('CONFIG_SITE_DESC' => $qi_config['site_desc'], 'CONFIG_SITENAME' => $qi_config['site_name'])); // smaller ^^ list($dbms, $table_prefix) = array(&$qi_config['dbms'], &$qi_config['table_prefix']); // check if we have a board db (and folder) name if (!$dbname) { trigger_error('NO_DB'); } // Set the new board as root path. $board_dir = $quickinstall_path . 'boards/' . $dbname . '/'; $phpbb_root_path = $board_dir; if (!defined('PHPBB_ROOT_PATH')) { define('PHPBB_ROOT_PATH', $board_dir); } if (file_exists($board_dir)) { if ($delete_files) { file_functions::delete_dir($board_dir); } else { trigger_error(sprintf($user->lang['DIR_EXISTS'], $board_dir)); } } // copy all of our files file_functions::copy_dir($quickinstall_path . 'sources/' . ($alt_env === '' ? 'phpBB3/' : "phpBB3_alt/{$alt_env}/"), $board_dir); if ($make_writable) { chmod($board_dir, 0777); } // Now make sure we have a valid db-name and prefix $qi_config['db_prefix'] = validate_dbname($qi_config['db_prefix'], true); $dbname = validate_dbname($dbname); // copy qi's lang file for the log if (file_exists("{$quickinstall_path}language/{$qi_config['qi_lang']}/info_acp_qi.{$phpEx}") && file_exists($board_dir . 'language/' . $qi_config['qi_lang'])) { copy("{$quickinstall_path}language/{$qi_config['qi_lang']}/info_acp_qi.{$phpEx}", "{$board_dir}language/{$qi_config['qi_lang']}/mods/info_acp_qi.{$phpEx}"); } else { copy("{$quickinstall_path}language/en/info_acp_qi.{$phpEx}", "{$board_dir}language/en/mods/info_acp_qi.{$phpEx}"); } if ($dbms == 'sqlite' || $dbms == 'firebird') { $qi_config['dbhost'] = $qi_config['db_prefix'] . $dbname; // temp remove some list($qi_config['db_prefix'], $dbname, $temp1, $temp2) = array('', '', &$qi_config['db_prefix'], &$dbname); } // Set the new board as language path to get language files from outside phpBB $user->set_custom_lang_path($phpbb_root_path . 'language/'); // Write to config.php ;) $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' => $dbms, 'dbhost' => $qi_config['dbhost'], 'dbport' => $qi_config['dbport'], 'dbname' => $qi_config['db_prefix'] . $dbname, 'dbuser' => $qi_config['dbuser'], 'dbpasswd' => htmlspecialchars_decode($qi_config['dbpasswd']), 'table_prefix' => $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! file_put_contents($board_dir . 'config.' . $phpEx, $config_data); if ($dbms == 'sqlite' || $dbms == 'firebird') { // and now restore list($qi_config['db_prefix'], $dbname) = array(&$temp1, &$temp2); } // update phpbb_root_path $phpbb_root_path = $board_dir; if ($drop_db) { $db->sql_query('DROP DATABASE IF EXISTS ' . $qi_config['db_prefix'] . $dbname); } else { // Check if the database exists. if ($dbms == 'sqlite' || $dbms == 'firebird') { $db_check = $db->sql_select_db($quickinstall_path . 'cache/' . $qi_config['db_prefix'] . $dbname); } else { $db_check = $db->sql_select_db($qi_config['db_prefix'] . $dbname); } if ($db_check) { trigger_error(sprintf($user->lang['DB_EXISTS'], $qi_config['db_prefix'] . $dbname)); } } if ($dbms == 'sqlite' || $dbms == 'firebird') { $db->sql_query('CREATE DATABASE ' . $quickinstall_path . 'cache/' . $qi_config['db_prefix'] . $dbname); $db->sql_select_db($quickinstall_path . 'cache/' . $qi_config['db_prefix'] . $dbname); } else { $db->sql_query('CREATE DATABASE ' . $qi_config['db_prefix'] . $dbname); $db->sql_select_db($qi_config['db_prefix'] . $dbname); } // include install lang fom phpbb qi::add_lang('install', $phpbb_root_path . 'language/' . $qi_config['default_lang'] . '/'); // perform sql load_schema($phpbb_root_path . 'install/schemas/', $dbms); $current_time = time(); $user_ip = !empty($_SERVER['REMOTE_ADDR']) ? htmlspecialchars($_SERVER['REMOTE_ADDR']) : ''; $script_path = !empty($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF'); if (!$script_path) { $script_path = !empty($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : getenv('REQUEST_URI'); } // Replace backslashes and doubled slashes (could happen on some proxy setups) $script_path = str_replace(array('\\', '//'), '/', $script_path); $script_path = trim(dirname($script_path)); // add the dbname to script path $script_path .= '/boards/' . $dbname; $config_ary = array('board_startdate' => $current_time, 'default_lang' => $qi_config['default_lang'], 'server_name' => $qi_config['server_name'], 'server_port' => $qi_config['server_port'], 'board_email' => $qi_config['board_email'], 'board_contact' => $qi_config['board_email'], 'cookie_domain' => $qi_config['cookie_domain'], 'default_dateformat' => $user->lang['default_dateformat'], 'email_enable' => $qi_config['email_enable'], 'smtp_delivery' => $qi_config['smtp_delivery'], 'smtp_host' => $qi_config['smtp_host'], 'smtp_auth_method' => $qi_config['smtp_auth'], 'smtp_username' => $qi_config['smtp_user'], 'smtp_password' => $qi_config['smtp_pass'], 'cookie_secure' => $qi_config['cookie_secure'], 'script_path' => $script_path, 'server_protocol' => !empty($qi_config['server_protocol']) ? $qi_config['server_protocol'] : 'http://', 'newest_username' => $qi_config['admin_name'], 'avatar_salt' => md5(mt_rand()), 'cookie_name' => 'phpbb3_' . strtolower(gen_rand_string(5))); if (@extension_loaded('gd') || can_load_dll('gd')) { $config_ary['captcha_gd'] = 1; } foreach ($config_ary as $config_name => $config_value) { set_config($config_name, $config_value); } // Set default config and post data, this applies to all DB's $sql_ary = array("UPDATE {$table_prefix}users\n\t\t\t\tSET username = '******'admin_name']) . "', user_password='******'admin_pass'])) . "', user_ip = '" . $db->sql_escape($user_ip) . "', user_lang = '" . $db->sql_escape($qi_config['default_lang']) . "', user_email='" . $db->sql_escape($qi_config['board_email']) . "', user_dateformat='" . $db->sql_escape($user->lang['default_dateformat']) . "', user_email_hash = " . (crc32($qi_config['board_email']) . strlen($qi_config['board_email'])) . ", username_clean = '" . $db->sql_escape(utf8_clean_string($qi_config['admin_name'])) . "'\n\t\t\t\tWHERE username = '******'", "UPDATE {$table_prefix}moderator_cache\n\t\t\t\tSET username = '******'admin_name']) . "'\n\t\t\t\tWHERE username = '******'", "UPDATE {$table_prefix}forums\n\t\t\t\tSET forum_last_poster_name = '" . $db->sql_escape($qi_config['admin_name']) . "'\n\t\t\t\tWHERE forum_last_poster_name = 'Admin'", "UPDATE {$table_prefix}topics\n\t\t\t\tSET topic_first_poster_name = '" . $db->sql_escape($qi_config['admin_name']) . "', topic_last_poster_name = '" . $db->sql_escape($qi_config['admin_name']) . "'\n\t\t\t\tWHERE topic_first_poster_name = 'Admin'\n\t\t\t\t\tOR topic_last_poster_name = 'Admin'", "UPDATE {$table_prefix}users\n\t\t\t\tSET user_regdate = {$current_time}", "UPDATE {$table_prefix}posts\n\t\t\t\tSET post_time = {$current_time}, poster_ip = '" . $db->sql_escape($user_ip) . "'", "UPDATE {$table_prefix}topics\n\t\t\t\tSET topic_time = {$current_time}, topic_last_post_time = {$current_time}", "UPDATE {$table_prefix}forums\n\t\t\t\tSET forum_last_post_time = {$current_time}", "UPDATE {$table_prefix}config\n\t\t\t\tSET config_value = '" . $db->sql_escape($qi_config['site_name']) . "'\n\t\t\t\tWHERE config_name = 'sitename'", "UPDATE {$table_prefix}config\n\t\t\t\tSET config_value = '" . $db->sql_escape($qi_config['site_desc']) . "'\n\t\t\t\tWHERE config_name = 'site_desc'", "UPDATE {$table_prefix}config\n\t\t\t\tSET config_value = '1'\n\t\t\t\tWHERE config_name = 'load_tplcompile'"); foreach ($sql_ary as $sql) { if (!$db->sql_query($sql)) { $error = $db->sql_error(); trigger_error($error['message']); } } // main sql is done, let's get a fresh $config array $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); // no templates though :P $config['load_tplcompile'] = '1'; // build search index include_once $phpbb_root_path . 'includes/search/fulltext_native.' . $phpEx; $search = new fulltext_native($error = false); $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); // extended phpbb install script include $phpbb_root_path . 'install/install_install.' . $phpEx; include $quickinstall_path . 'includes/install_install_qi.' . $phpEx; $install = new install_install_qi($p_master = new p_master_dummy()); $install->set_data(array('dbms' => $dbms, 'dbhost' => $qi_config['dbhost'], 'dbport' => $qi_config['dbport'], 'dbuser' => $qi_config['dbuser'], 'dbpasswd' => $qi_config['dbpasswd'], 'dbname' => $dbname, 'table_prefix' => $table_prefix, 'default_lang' => $qi_config['default_lang'], 'admin_name' => $qi_config['admin_name'], 'admin_pass1' => $qi_config['admin_pass'], 'admin_pass2' => $qi_config['admin_pass'], 'board_email1' => $qi_config['board_email'], 'board_email2' => $qi_config['board_email'], 'email_enable' => $qi_config['email_enable'], 'smtp_delivery' => $qi_config['smtp_delivery'], 'smtp_host' => $qi_config['smtp_host'], 'smtp_auth' => $qi_config['smtp_auth'], 'smtp_user' => $qi_config['smtp_user'], 'smtp_pass' => $qi_config['smtp_pass'], 'cookie_secure' => $qi_config['cookie_secure'], 'server_protocol' => !empty($qi_config['server_protocol']) ? $qi_config['server_protocol'] : 'http://', 'server_name' => $qi_config['server_name'], 'server_port' => $qi_config['server_port'], 'script_path' => $script_path)); $install->add_modules(false, false); $install->add_language(false, false); $install->add_bots(false, false); // login $user->session_begin(); $auth->login($qi_config['admin_name'], $qi_config['admin_pass'], false, true, true); // now automod (easymod) if ($automod) { include $quickinstall_path . 'includes/functions_install_automod.' . $phpEx; automod_installer::install_automod($board_dir, $make_writable); } if ($dbms == 'sqlite' || $dbms == 'firebird') { // copy the temp db over file_functions::copy_file($quickinstall_path . 'cache/' . $qi_config['db_prefix'] . $dbname, $board_dir . $qi_config['db_prefix'] . $dbname); $db->sql_select_db($board_dir . $qi_config['db_prefix'] . $dbname); } // clean up file_functions::delete_files($board_dir, array('Thumbs.db', 'DS_Store', 'CVS', '.svn', '.git')); // remove install dir, develop and umil file_functions::delete_dir($board_dir . 'install/'); file_functions::delete_dir($board_dir . 'develop/'); file_functions::delete_dir($board_dir . 'umil/'); // copy extra user added files file_functions::copy_dir($quickinstall_path . 'sources/extra/', $board_dir); // Install Subsilver2 if ($subsilver) { if (!class_exists('bitfield')) { include $phpbb_root_path . 'includes/functions_content.' . $phpEx; } include $phpbb_root_path . 'includes/acp/acp_styles.' . $phpEx; $acp_styles = new acp_styles(); $acp_styles->main(0, ''); // Mostly copied from includes/acp/acp_styles.php $reqd_template = $reqd_theme = $reqd_imageset = false; $error = $installcfg = $style_row = array(); $element_ary = array('template' => STYLES_TEMPLATE_TABLE, 'theme' => STYLES_THEME_TABLE, 'imageset' => STYLES_IMAGESET_TABLE); $install_path = 'subsilver2'; $root_path = $phpbb_root_path . 'styles/subsilver2/'; $cfg_file = $root_path . 'style.cfg'; $installcfg = parse_cfg_file($cfg_file); if (!sizeof($installcfg)) { continue; } $name = $installcfg['name']; $copyright = $installcfg['copyright']; $version = $installcfg['version']; $style_row = array('style_id' => 0, 'template_id' => 0, 'theme_id' => 0, 'imageset_id' => 0, 'style_name' => $installcfg['name'], 'template_name' => $installcfg['name'], 'theme_name' => $installcfg['name'], 'imageset_name' => $installcfg['name'], 'template_copyright' => $installcfg['copyright'], 'theme_copyright' => $installcfg['copyright'], 'imageset_copyright' => $installcfg['copyright'], 'style_copyright' => $installcfg['copyright'], 'store_db' => 0, 'style_active' => 1, 'style_default' => $subsilver == 2 ? 1 : 0); $acp_styles->install_style($error, 'install', $root_path, $style_row['style_id'], $style_row['style_name'], $install_path, $style_row['style_copyright'], $style_row['style_active'], $style_row['style_default'], $style_row); unset($error); } // Add some random users and posts. if ($populate) { include $quickinstall_path . 'includes/functions_populate.' . $phpEx; new populate($pop_data); } // add log entry :D $user->ip =& $user_ip; add_log('admin', 'LOG_INSTALL_INSTALLED_QI', $qi_config['qi_version']); // purge cache $cache->purge(); // Make all files world writable. if ($make_writable) { file_functions::make_writable($board_dir); } // if he wants to be redirected, redirect him if ($redirect) { qi::redirect($board_dir); } // On succces just return to main page. qi::redirect('index.' . $phpEx); }