From 9e4349e7faac65403de02fd090a837fee92b764a Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Thu, 4 Sep 2008 11:39:25 +0000 Subject: [PATCH 01/16] [feature/remove-db-styles] Removed database storage of style components. The bulk of database storage of templates is removed, rendering template stored in the database as useless. Theme database storage is reduced to a skeleton for full removal soon. This commit was cherry picked from the old feature/ascraeus-experiment branch the old commit hash is 0dbe7e3b6cd450342d3c566eb2caf36ca1b5db8e. PHPBB3-9741 --- phpBB/adm/index.php | 3 - phpBB/adm/style/acp_styles.html | 7 - phpBB/includes/acp/acp_styles.php | 380 ++------------------------ phpBB/includes/constants.php | 1 - phpBB/includes/session.php | 4 +- phpBB/install/index.php | 3 - phpBB/install/install_update.php | 3 - phpBB/install/schemas/schema_data.sql | 2 +- phpBB/language/en/acp/styles.php | 4 - 9 files changed, 32 insertions(+), 375 deletions(-) diff --git a/phpBB/adm/index.php b/phpBB/adm/index.php index 2444a1b597..4f4d9ccedd 100644 --- a/phpBB/adm/index.php +++ b/phpBB/adm/index.php @@ -56,9 +56,6 @@ $template->set_custom_template($phpbb_admin_path . 'style', 'admin'); $template->assign_var('T_ASSETS_PATH', $phpbb_root_path . 'assets'); $template->assign_var('T_TEMPLATE_PATH', $phpbb_admin_path . 'style'); -// the acp template is never stored in the database -$user->theme['template_storedb'] = false; - // Instantiate new module $module = new p_master(); diff --git a/phpBB/adm/style/acp_styles.html b/phpBB/adm/style/acp_styles.html index d503f323e0..4076cf1ba6 100644 --- a/phpBB/adm/style/acp_styles.html +++ b/phpBB/adm/style/acp_styles.html @@ -362,13 +362,6 @@
{THEME_NAME}
- -
-

{L_LOCATION_DISABLED_EXPLAIN}{L_LOCATION_EXPLAIN}
-
-
-
- diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 82878cfadb..8bd75c6ab9 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -207,7 +207,7 @@ version = {VERSION} switch ($action) { - // Refresh template data stored in db and clear cache + // Clear cache case 'refresh': $sql = 'SELECT * @@ -224,49 +224,13 @@ version = {VERSION} if (confirm_box(true)) { - $template_refreshed = ''; - - // Only refresh database if the template is stored in the database - if ($template_row['template_storedb'] && file_exists("{$phpbb_root_path}styles/{$template_row['template_path']}/template/")) - { - $filelist = array('' => array()); - - $sql = 'SELECT template_filename, template_mtime - FROM ' . STYLES_TEMPLATE_DATA_TABLE . " - WHERE template_id = $style_id"; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { -// if (@filemtime("{$phpbb_root_path}styles/{$template_row['template_path']}/template/" . $row['template_filename']) > $row['template_mtime']) -// { - // get folder info from the filename - if (($slash_pos = strrpos($row['template_filename'], '/')) === false) - { - $filelist[''][] = $row['template_filename']; - } - else - { - $filelist[substr($row['template_filename'], 0, $slash_pos + 1)][] = substr($row['template_filename'], $slash_pos + 1, strlen($row['template_filename']) - $slash_pos - 1); - } -// } - } - $db->sql_freeresult($result); - - $this->store_templates('update', $style_id, $template_row['template_path'], $filelist); - unset($filelist); - - $template_refreshed = $user->lang['TEMPLATE_REFRESHED'] . '
'; - add_log('admin', 'LOG_TEMPLATE_REFRESHED', $template_row['template_name']); - } - $this->clear_template_cache($template_row); - trigger_error($template_refreshed . $user->lang['TEMPLATE_CACHE_CLEARED'] . adm_back_link($this->u_action)); + trigger_error($user->lang['TEMPLATE_CACHE_CLEARED'] . adm_back_link($this->u_action)); } else { - confirm_box(false, ($template_row['template_storedb']) ? $user->lang['CONFIRM_TEMPLATE_REFRESH'] : $user->lang['CONFIRM_TEMPLATE_CLEAR_CACHE'], build_hidden_fields(array( + confirm_box(false, $user->lang['CONFIRM_TEMPLATE_CLEAR_CACHE'], build_hidden_fields(array( 'i' => $id, 'mode' => $mode, 'action' => $action, @@ -526,7 +490,7 @@ version = {VERSION} $template_file = preg_replace('#\.{2,}#', '.', $template_file); // Retrieve some information about the template - $sql = 'SELECT template_storedb, template_path, template_name + $sql = 'SELECT template_path, template_name FROM ' . STYLES_TEMPLATE_TABLE . " WHERE template_id = $template_id"; $result = $db->sql_query($sql); @@ -554,8 +518,8 @@ version = {VERSION} $file = "{$phpbb_root_path}styles/{$template_info['template_path']}/template/$template_file"; $additional = ''; - // If the template is stored on the filesystem try to write the file else store it in the database - if (!$safe_mode && !$template_info['template_storedb'] && file_exists($file) && phpbb_is_writable($file)) + // Try to write the file + if (!$safe_mode && file_exists($file) && phpbb_is_writable($file)) { if (!($fp = @fopen($file, 'wb'))) { @@ -567,32 +531,8 @@ version = {VERSION} } else { - $db->sql_transaction('begin'); - - // If it's not stored in the db yet, then update the template setting and store all template files in the db - if (!$template_info['template_storedb']) - { - if ($super = $this->get_super('template', $template_id)) - { - $this->store_in_db('template', $super['template_id']); - } - else - { - $this->store_in_db('template', $template_id); - } - - add_log('admin', 'LOG_TEMPLATE_EDIT_DETAILS', $template_info['template_name']); - $additional .= '
' . $user->lang['EDIT_TEMPLATE_STORED_DB']; - } - - // Update the template_data table entry for this template file - $sql = 'UPDATE ' . STYLES_TEMPLATE_DATA_TABLE . " - SET template_data = '" . $db->sql_escape($template_data) . "', template_mtime = " . time() . " - WHERE template_id = $template_id - AND template_filename = '" . $db->sql_escape($template_file) . "'"; - $db->sql_query($sql); - - $db->sql_transaction('commit'); + // @todo + trigger_error('Cannot write template file.', E_USER_ERROR); } // destroy the cached version of the template (filename without extension) @@ -605,53 +545,18 @@ version = {VERSION} } // Generate a category array containing template filenames - if (!$template_info['template_storedb']) + $template_path = "{$phpbb_root_path}styles/{$template_info['template_path']}/template"; + + $filelist = filelist($template_path, '', 'html'); + $filelist[''] = array_diff($filelist[''], array('bbcode.html')); + + if ($template_file) { - $template_path = "{$phpbb_root_path}styles/{$template_info['template_path']}/template"; - - $filelist = filelist($template_path, '', 'html'); - $filelist[''] = array_diff($filelist[''], array('bbcode.html')); - - if ($template_file) + if (!file_exists($template_path . "/$template_file") || !($template_data = file_get_contents($template_path . "/$template_file"))) { - if (!file_exists($template_path . "/$template_file") || !($template_data = file_get_contents($template_path . "/$template_file"))) - { - trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING); - } + trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING); } } - else - { - $sql = 'SELECT * - FROM ' . STYLES_TEMPLATE_DATA_TABLE . " - WHERE template_id = $template_id"; - $result = $db->sql_query($sql); - - $filelist = array('' => array()); - while ($row = $db->sql_fetchrow($result)) - { - $file_info = pathinfo($row['template_filename']); - - if (($file_info['basename'] != 'bbcode') && ($file_info['extension'] == 'html')) - { - if (($file_info['dirname'] == '.') || empty($file_info['dirname'])) - { - $filelist[''][] = $row['template_filename']; - } - else - { - $filelist[$file_info['dirname'] . '/'][] = $file_info['basename']; - } - } - - if ($row['template_filename'] == $template_file) - { - $template_data = $row['template_data']; - } - } - $db->sql_freeresult($result); - unset($file_info); - } if (empty($filelist[''])) { @@ -821,35 +726,6 @@ version = {VERSION} adm_page_footer(); } - $filemtime = array(); - if ($template_row['template_storedb']) - { - $ids = array(); - if (isset($template_row['template_inherits_id']) && $template_row['template_inherits_id']) - { - $ids[] = $template_row['template_inherits_id']; - } - $ids[] = $template_row['template_id']; - - $filemtime = array(); - $file_template_db = array(); - - foreach ($ids as $id) - { - $sql = 'SELECT template_filename, template_mtime - FROM ' . STYLES_TEMPLATE_DATA_TABLE . " - WHERE template_id = $id"; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $filemtime[$row['template_filename']] = $row['template_mtime']; - $file_template_db[$row['template_filename']] = $id; - } - $db->sql_freeresult($result); - } - } - // Get a list of cached template files and then retrieve additional information about them $file_ary = $this->template_cache_filelist($template_row['template_path']); @@ -905,10 +781,9 @@ version = {VERSION} 'FILENAME' => $file, 'FILENAME_PATH' => $file_tpl, 'FILESIZE' => get_formatted_filesize(filesize("{$phpbb_root_path}cache/$filename")), - 'MODIFIED' => $user->format_date((!$template_row['template_storedb']) ? filemtime($file_tpl) : $filemtime[$file . '.html'])) - ); + 'MODIFIED' => $user->format_date(filemtime($file_tpl)), + )); } - unset($filemtime); $template->assign_vars(array( 'S_CACHE' => true, @@ -1123,7 +998,7 @@ version = {VERSION} case 'template': $sql_from = STYLES_TEMPLATE_TABLE; - $sql_select = 'template_id, template_name, template_path, template_storedb'; + $sql_select = 'template_id, template_name, template_path'; break; case 'theme': @@ -1491,7 +1366,7 @@ version = {VERSION} trigger_error($user->lang['NO_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING); } - $var_ary = array('style_id', 'style_name', 'style_copyright', 'template_id', 'template_name', 'template_path', 'template_copyright', 'template_storedb', 'template_inherits_id', 'bbcode_bitfield', 'theme_id', 'theme_name', 'theme_path', 'theme_copyright', 'theme_storedb', 'theme_mtime', 'theme_data'); + $var_ary = array('style_id', 'style_name', 'style_copyright', 'template_id', 'template_name', 'template_path', 'template_copyright', 'template_inherits_id', 'bbcode_bitfield', 'theme_id', 'theme_name', 'theme_path', 'theme_copyright', 'theme_storedb', 'theme_mtime', 'theme_data'); foreach ($var_ary as $var) { @@ -1546,31 +1421,12 @@ version = {VERSION} ); // This is potentially nasty memory-wise ... - if (!$style_row['template_storedb']) - { - $files[] = array( - 'src' => "styles/{$style_row['template_path']}/template/", - 'prefix-' => "styles/{$style_row['template_path']}/", - 'prefix+' => false, - 'exclude' => 'template.cfg' - ); - } - else - { - $sql = 'SELECT template_filename, template_data - FROM ' . STYLES_TEMPLATE_DATA_TABLE . " - WHERE template_id = {$style_row['template_id']}"; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $data[] = array( - 'src' => $row['template_data'], - 'prefix' => 'template/' . $row['template_filename'] - ); - } - $db->sql_freeresult($result); - } + $files[] = array( + 'src' => "styles/{$style_row['template_path']}/template/", + 'prefix-' => "styles/{$style_row['template_path']}/", + 'prefix+' => false, + 'exclude' => 'template.cfg' + ); unset($template_cfg); } @@ -1772,7 +1628,6 @@ version = {VERSION} $style_active = request_var('style_active', 0); $style_default = request_var('style_default', 0); - $store_db = request_var('store_db', 0); // If the admin selected the style to be the default style, but forgot to activate it... we will do it for him if ($style_default) @@ -1803,23 +1658,6 @@ version = {VERSION} $error[] = $user->lang[$l_type . '_ERR_STYLE_NAME']; } - if ($mode === 'theme' || $mode === 'template') - { - // a rather elaborate check we have to do here once to avoid trouble later - $check = "{$phpbb_root_path}styles/" . $style_row["{$mode}_path"] . (($mode === 'theme') ? '/theme/stylesheet.css' : '/template'); - if (($style_row["{$mode}_storedb"] != $store_db) && !$store_db && ($safe_mode || !phpbb_is_writable($check))) - { - $error[] = $user->lang['EDIT_' . strtoupper($mode) . '_STORED_DB']; - $store_db = 1; - } - - // themes which have to be parsed have to go into db - if ($mode == 'theme') - { - $cfg = parse_cfg_file("{$phpbb_root_path}styles/" . $style_row["{$mode}_path"] . "/theme/theme.cfg"); - } - } - if (!sizeof($error)) { // Check length settings @@ -1841,7 +1679,6 @@ version = {VERSION} 'template_id' => $template_id, 'theme_id' => $theme_id, 'style_active' => $style_active, - $mode . '_storedb' => $store_db, $mode . '_name' => $name, $mode . '_copyright' => $copyright) ); @@ -1867,72 +1704,9 @@ version = {VERSION} break; case 'theme': - - if ($style_row['theme_storedb'] != $store_db) - { - $theme_data = ''; - - if (!$style_row['theme_storedb']) - { - $theme_data = $this->db_theme_data($style_row); - } - else if (!$store_db && !$safe_mode && phpbb_is_writable("{$phpbb_root_path}styles/{$style_row['theme_path']}/theme/stylesheet.css")) - { - $store_db = 1; - $theme_data = $style_row['theme_data']; - - if ($fp = @fopen("{$phpbb_root_path}styles/{$style_row['theme_path']}/theme/stylesheet.css", 'wb')) - { - $store_db = (@fwrite($fp, str_replace("styles/{$style_row['theme_path']}/theme/", './', $theme_data))) ? 0 : 1; - } - fclose($fp); - } - - $sql_ary += array( - 'theme_mtime' => ($store_db) ? filemtime("{$phpbb_root_path}styles/{$style_row['theme_path']}/theme/stylesheet.css") : 0, - 'theme_storedb' => $store_db, - 'theme_data' => ($store_db) ? $theme_data : '', - ); - } break; case 'template': - - if ($style_row['template_storedb'] != $store_db) - { - if ($super = $this->get_super($mode, $style_row['template_id'])) - { - $error[] = (sprintf($user->lang["{$l_type}_INHERITS"], $super['template_name'])); - $sql_ary = array(); - } - else - { - if (!$store_db && !$safe_mode && phpbb_is_writable("{$phpbb_root_path}styles/{$style_row['template_path']}/template")) - { - $err = $this->store_in_fs('template', $style_row['template_id']); - if ($err) - { - $error += $err; - } - } - else if ($store_db) - { - $this->store_in_db('template', $style_row['template_id']); - } - else - { - // We no longer store within the db, but are also not able to update the file structure - // Since the admin want to switch this, we adhere to his decision. But we also need to remove the cache - $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . " - WHERE template_id = $style_id"; - $db->sql_query($sql); - } - - $sql_ary += array( - 'template_storedb' => $store_db, - ); - } - } break; } @@ -1999,8 +1773,6 @@ version = {VERSION} 'S_STYLE' => ($mode == 'style') ? true : false, 'S_TEMPLATE' => ($mode == 'template') ? true : false, 'S_THEME' => ($mode == 'theme') ? true : false, - 'S_STORE_DB' => (isset($style_row[$mode . '_storedb'])) ? $style_row[$mode . '_storedb'] : 0, - 'S_STORE_DB_DISABLED' => (isset($style_row[$mode . '_inherits_id'])) ? $style_row[$mode . '_inherits_id'] : 0, 'S_STYLE_ACTIVE' => (isset($style_row['style_active'])) ? $style_row['style_active'] : 0, 'S_STYLE_DEFAULT' => (isset($style_row['style_default'])) ? $style_row['style_default'] : 0, 'S_SUPERTEMPLATE' => (isset($style_row[$mode . '_inherits_id']) && $style_row[$mode . '_inherits_id']) ? $super['template_name'] : 0, @@ -2101,84 +1873,6 @@ version = {VERSION} return str_replace('./', 'styles/' . $theme_row['theme_path'] . '/theme/', $stylesheet); } - /** - * Store template files into db - */ - function store_templates($mode, $style_id, $template_path, $filelist) - { - global $phpbb_root_path, $phpEx, $db; - - $template_path = $template_path . '/template/'; - $includes = array(); - foreach ($filelist as $pathfile => $file_ary) - { - foreach ($file_ary as $file) - { - if (!($fp = @fopen("{$phpbb_root_path}styles/$template_path$pathfile$file", 'r'))) - { - trigger_error("Could not open {$phpbb_root_path}styles/$template_path$pathfile$file", E_USER_ERROR); - } - - $filesize = filesize("{$phpbb_root_path}styles/$template_path$pathfile$file"); - - if ($filesize) - { - $template_data = fread($fp, $filesize); - } - - fclose($fp); - - if (!$filesize) - { - // File is empty - continue; - } - - if (preg_match_all('##is', $template_data, $matches)) - { - foreach ($matches[1] as $match) - { - $includes[trim($match)][] = $file; - } - } - } - } - - foreach ($filelist as $pathfile => $file_ary) - { - foreach ($file_ary as $file) - { - // Skip index. - if (strpos($file, 'index.') === 0) - { - continue; - } - - // We could do this using extended inserts ... but that could be one - // heck of a lot of data ... - $sql_ary = array( - 'template_id' => (int) $style_id, - 'template_filename' => "$pathfile$file", - 'template_included' => (isset($includes[$file])) ? implode(':', $includes[$file]) . ':' : '', - 'template_mtime' => (int) filemtime("{$phpbb_root_path}styles/$template_path$pathfile$file"), - 'template_data' => (string) file_get_contents("{$phpbb_root_path}styles/$template_path$pathfile$file"), - ); - - if ($mode == 'insert') - { - $sql = 'INSERT INTO ' . STYLES_TEMPLATE_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); - } - else - { - $sql = 'UPDATE ' . STYLES_TEMPLATE_DATA_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE template_id = $style_id - AND template_filename = '" . $db->sql_escape("$pathfile$file") . "'"; - } - $db->sql_query($sql); - } - } - } - /** * Returns an array containing all template filenames for one template that are currently cached. * @@ -2361,7 +2055,6 @@ version = {VERSION} trigger_error($user->lang['NO_' . $l_type] . adm_back_link($this->u_action), E_USER_WARNING); } - $style_row['store_db'] = request_var('store_db', 0); $style_row['style_active'] = request_var('style_active', 1); $style_row['style_default'] = request_var('style_default', 0); @@ -2379,15 +2072,14 @@ version = {VERSION} } else { - $style_row['store_db'] = $this->install_element($mode, $error, 'install', $root_path, $style_row[$mode . '_id'], $style_row[$mode . '_name'], $install_path, $style_row[$mode . '_copyright'], $style_row['store_db']); + $this->install_element($mode, $error, 'install', $root_path, $style_row[$mode . '_id'], $style_row[$mode . '_name'], $install_path, $style_row[$mode . '_copyright']); } if (!sizeof($error)) { $cache->destroy('sql', STYLES_TABLE); - $message = ($style_row['store_db']) ? '_ADDED_DB' : '_ADDED'; - trigger_error($user->lang[$l_type . $message] . adm_back_link($this->u_action)); + trigger_error($user->lang[$l_type . '_ADDED'] . adm_back_link($this->u_action)); } } @@ -2403,7 +2095,6 @@ version = {VERSION} 'S_SUPERTEMPLATE' => (isset($installcfg['inherit_from'])) ? $installcfg['inherit_from'] : '', 'S_THEME' => ($mode == 'theme') ? true : false, - 'S_STORE_DB' => (isset($style_row[$mode . '_storedb'])) ? $style_row[$mode . '_storedb'] : 0, 'S_STYLE_ACTIVE' => (isset($style_row['style_active'])) ? $style_row['style_active'] : 0, 'S_STYLE_DEFAULT' => (isset($style_row['style_default'])) ? $style_row['style_default'] : 0, @@ -2440,7 +2131,6 @@ version = {VERSION} $mode . '_copyright' => utf8_normalize_nfc(request_var('copyright', '', true)), 'template_id' => 0, 'theme_id' => 0, - 'store_db' => request_var('store_db', 0), 'style_active' => request_var('style_active', 1), 'style_default' => request_var('style_default', 0), ); @@ -2512,8 +2202,7 @@ version = {VERSION} { $cache->destroy('sql', STYLES_TABLE); - $message = ($style_row['store_db']) ? '_ADDED_DB' : '_ADDED'; - trigger_error($user->lang[$l_type . $message] . adm_back_link($this->u_action)); + trigger_error($user->lang[$l_type . '_ADDED'] . adm_back_link($this->u_action)); } } @@ -2547,7 +2236,6 @@ version = {VERSION} 'S_THEME' => ($mode == 'theme') ? true : false, 'S_BASIS' => ($basis) ? true : false, - 'S_STORE_DB' => (isset($style_row['storedb'])) ? $style_row['storedb'] : 0, 'S_STYLE_ACTIVE' => (isset($style_row['style_active'])) ? $style_row['style_active'] : 0, 'S_STYLE_DEFAULT' => (isset($style_row['style_default'])) ? $style_row['style_default'] : 0, 'S_TEMPLATE_OPTIONS' => ($mode == 'style') ? $template_options : '', @@ -2853,10 +2541,6 @@ version = {VERSION} $sql_ary['bbcode_bitfield'] = $this->template_bitfield; } - // We set a pre-defined bitfield here which we may use further in 3.2 - $sql_ary += array( - 'template_storedb' => $store_db, - ); if (isset($cfg_data['inherit_from']) && $cfg_data['inherit_from']) { $sql_ary += array( @@ -2885,12 +2569,6 @@ version = {VERSION} $id = $db->sql_nextid(); - if ($mode == 'template' && $store_db) - { - $filelist = filelist("{$root_path}template", '', 'html'); - $this->store_templates('insert', $id, $path, $filelist); - } - $db->sql_transaction('commit'); $log = ($store_db) ? 'LOG_' . $l_type . '_ADD_DB' : 'LOG_' . $l_type . '_ADD_FS'; diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index 8ef1a4655d..cbe488fccc 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -262,7 +262,6 @@ define('SITELIST_TABLE', $table_prefix . 'sitelist'); define('SMILIES_TABLE', $table_prefix . 'smilies'); define('STYLES_TABLE', $table_prefix . 'styles'); define('STYLES_TEMPLATE_TABLE', $table_prefix . 'styles_template'); -define('STYLES_TEMPLATE_DATA_TABLE',$table_prefix . 'styles_template_data'); define('STYLES_THEME_TABLE', $table_prefix . 'styles_theme'); define('STYLES_IMAGESET_TABLE', $table_prefix . 'styles_imageset'); define('STYLES_IMAGESET_DATA_TABLE',$table_prefix . 'styles_imageset_data'); diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index 206b88a73e..c66bf89b47 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -1655,7 +1655,7 @@ class user extends session $style = ($style) ? $style : ((!$config['override_user_style']) ? $this->data['user_style'] : $config['default_style']); } - $sql = 'SELECT s.style_id, t.template_storedb, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_name, c.theme_storedb, c.theme_id + $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_name, c.theme_storedb, c.theme_id FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . " c WHERE s.style_id = $style AND t.template_id = s.template_id @@ -1674,7 +1674,7 @@ class user extends session WHERE user_id = {$this->data['user_id']}"; $db->sql_query($sql); - $sql = 'SELECT s.style_id, t.template_storedb, t.template_path, t.template_id, t.bbcode_bitfield, c.theme_path, c.theme_name, c.theme_storedb, c.theme_id + $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, c.theme_path, c.theme_name, c.theme_storedb, c.theme_id FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . " c WHERE s.style_id = $style AND t.template_id = s.template_id diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 059b46650c..a4ff93e701 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -205,9 +205,6 @@ $template->set_custom_template('../adm/style', 'admin'); $template->assign_var('T_ASSETS_PATH', '../assets'); $template->assign_var('T_TEMPLATE_PATH', '../adm/style'); -// the acp template is never stored in the database -$user->theme['template_storedb'] = false; - $install = new module(); $install->create('install', "index.$phpEx", $mode, $sub); diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index 5c3a38d237..926b7cad46 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -134,9 +134,6 @@ class install_update extends module // 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; - $template->assign_vars(array( 'S_USER_LANG' => $user->lang['USER_LANG'], 'S_CONTENT_DIRECTION' => $user->lang['DIRECTION'], diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index 0d6409991f..cd4e80ba13 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -437,7 +437,7 @@ INSERT INTO phpbb_acl_roles (role_name, role_description, role_type, role_order) INSERT INTO phpbb_styles (style_name, style_copyright, style_active, template_id, theme_id) VALUES ('prosilver', '© phpBB Group', 1, 1, 1); # -- phpbb_styles_template -INSERT INTO phpbb_styles_template (template_name, template_copyright, template_path, bbcode_bitfield, template_storedb) VALUES ('prosilver', '© phpBB Group', 'prosilver', 'lNg=', 0); +INSERT INTO phpbb_styles_template (template_name, template_copyright, template_path, bbcode_bitfield) VALUES ('prosilver', '© phpBB Group', 'prosilver', 'lNg='); # -- phpbb_styles_theme INSERT INTO phpbb_styles_theme (theme_name, theme_copyright, theme_path, theme_storedb, theme_data) VALUES ('prosilver', '© phpBB Group', 'prosilver', 1, ''); diff --git a/phpBB/language/en/acp/styles.php b/phpBB/language/en/acp/styles.php index c450dcadeb..32c82de45d 100644 --- a/phpBB/language/en/acp/styles.php +++ b/phpBB/language/en/acp/styles.php @@ -60,7 +60,6 @@ $lang = array_merge($lang, array( 'CACHE_FILESIZE' => 'File size', 'CACHE_MODIFIED' => 'Modified', 'CONFIRM_TEMPLATE_CLEAR_CACHE' => 'Are you sure you wish to clear all cached versions of your template files?', - 'CONFIRM_TEMPLATE_REFRESH' => 'Are you sure you wish to refresh all template data in the database with the contents of the template files on the filesystem? This will overwrite all modifications which have been carried out with the template editor while the template was stored in the database.', 'CONFIRM_THEME_REFRESH' => 'Are you sure you wish to refresh the theme data stored in the database with the contents of the theme on the filesystem? This will overwrite all modifications which have been carried out with the theme editor while the theme was stored in the database.', 'COPYRIGHT' => 'Copyright', 'CREATE_STYLE' => 'Create new style', @@ -88,7 +87,6 @@ $lang = array_merge($lang, array( 'EDIT_DETAILS_THEME_EXPLAIN' => 'Here you can edit certain theme details such as its name. You may also have the option to switch storage of the stylesheet from the filesystem to the database and vice versa. This option depends on your PHP configuration and whether your stylesheet can be written to by the web server.', 'EDIT_TEMPLATE' => 'Edit template', 'EDIT_TEMPLATE_EXPLAIN' => 'Here you can edit your template set directly. Please remember that these edits are permanent and cannot be undone once submitted. If PHP can write to the template files in your styles directory any changes here will be written directly to those files. If PHP cannot write to those files they will be copied into the database and all changes will only be reflected there. Please take care when editing your template set, remember to close all replacement variable terms {XXXX} and conditional statements.', - 'EDIT_TEMPLATE_STORED_DB' => 'The template file was unwritable so the template set is now stored in the database containing the modified file.', 'EDIT_THEME' => 'Edit theme', 'EDIT_THEME_EXPLAIN' => 'Here you can edit the selected theme, changing colours, images, etc.', 'EDIT_THEME_STORED_DB' => 'The stylesheet file was unwritable so the stylesheet is now stored in the database containing your modification.', @@ -326,7 +324,6 @@ $lang = array_merge($lang, array( 'STYLE_USED_BY' => 'Used by (including robots)', 'TEMPLATE_ADDED' => 'Template set added and stored on filesystem.', - 'TEMPLATE_ADDED_DB' => 'Template set added and stored in database.', 'TEMPLATE_CACHE' => 'Template cache', 'TEMPLATE_CACHE_EXPLAIN' => 'By default phpBB caches the compiled version of its templates. This decreases the load on the server each time a page is viewed and thus may reduce the page generation time. Here you can view the cache status of each file and delete individual files or the entire cache.', 'TEMPLATE_CACHE_CLEARED' => 'Template cache cleared successfully.', @@ -356,7 +353,6 @@ $lang = array_merge($lang, array( 'TEMPLATE_LOCATION_EXPLAIN' => 'Images are always stored on the filesystem.', 'TEMPLATE_NAME' => 'Template name', 'TEMPLATE_FILE_NOT_WRITABLE'=> 'Unable to write to template file %s. Please check the permissions for the directory and the files.', - 'TEMPLATE_REFRESHED' => 'Template refreshed successfully.', 'THEME_ADDED' => 'New theme added on filesystem.', 'THEME_ADDED_DB' => 'New theme added to database.', From 23415170cb8e8c923c540bca84345bfb8f9e92c3 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Sep 2011 18:04:18 +0100 Subject: [PATCH 02/16] [feature/remove-db-styles] Removing unused methods from acp_style. These got left behind in 6854d47. PHPBB3-9741 --- phpBB/includes/acp/acp_styles.php | 176 ------------------------------ 1 file changed, 176 deletions(-) diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 8bd75c6ab9..7ab2061141 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -2684,180 +2684,4 @@ version = {VERSION} return false; } - - /** - * Moves a template set and its subtemplates to the database - * - * @access public - * @param string $mode The component to move - only template is supported - * @param int $id The template id - */ - function store_in_db($mode, $id) - { - global $db, $user; - - $error = array(); - $l_type = strtoupper($mode); - if ($super = $this->get_super($mode, $id)) - { - $error[] = (sprintf($user->lang["{$l_type}_INHERITS"], $super['template_name'])); - return $error; - } - - $sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path - FROM " . STYLES_TEMPLATE_TABLE . ' - WHERE template_id = ' . (int) $id; - - $result = $db->sql_query_limit($sql, 1); - if ($row = $db->sql_fetchrow($result)) - { - $db->sql_freeresult($result); - $subs = $this->check_inheritance($mode, $id); - - $this->_store_in_db($mode, $id, $row["{$mode}_path"]); - if ($subs && sizeof($subs)) - { - foreach ($subs as $sub_id => $sub) - { - if ($err = $this->_store_in_db($mode, $sub["{$mode}_id"], $sub["{$mode}_path"])) - { - $error[] = $err; - } - } - } - } - if (sizeof($error)) - { - return $error; - } - - return false; - } - - /** - * Moves a template set to the database - * - * @access private - * @param string $mode The component to move - only template is supported - * @param int $id The template id - * @param string $path TThe path to the template files - */ - function _store_in_db($mode, $id, $path) - { - global $phpbb_root_path, $db; - - $filelist = filelist("{$phpbb_root_path}styles/{$path}/template", '', 'html'); - $this->store_templates('insert', $id, $path, $filelist); - - // Okay, we do the query here -shouldn't be triggered often. - $sql = 'UPDATE ' . STYLES_TEMPLATE_TABLE . ' - SET template_storedb = 1 - WHERE template_id = ' . $id; - $db->sql_query($sql); - } - - /** - * Moves a template set and its subtemplates to the filesystem - * - * @access public - * @param string $mode The component to move - only template is supported - * @param int $id The template id - */ - function store_in_fs($mode, $id) - { - global $db, $user; - - $error = array(); - $l_type = strtoupper($mode); - if ($super = $this->get_super($mode, $id)) - { - $error[] = (sprintf($user->lang["{$l_type}_INHERITS"], $super['template_name'])); - return($error); - } - - $sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path - FROM " . STYLES_TEMPLATE_TABLE . ' - WHERE template_id = ' . (int) $id; - - $result = $db->sql_query_limit($sql, 1); - if ($row = $db->sql_fetchrow($result)) - { - $db->sql_freeresult($result); - if (!sizeof($error)) - { - $subs = $this->check_inheritance($mode, $id); - - $this->_store_in_fs($mode, $id, $row["{$mode}_path"]); - - if ($subs && sizeof($subs)) - { - foreach ($subs as $sub_id => $sub) - { - $this->_store_in_fs($mode, $sub["{$mode}_id"], $sub["{$mode}_path"]); - } - } - } - if (sizeof($error)) - { - $this->store_in_db($id, $mode); - return $error; - } - } - return false; - } - - /** - * Moves a template set to the filesystem - * - * @access private - * @param string $mode The component to move - only template is supported - * @param int $id The template id - * @param string $path The path to the template - */ - function _store_in_fs($mode, $id, $path) - { - global $phpbb_root_path, $db, $user, $safe_mode; - - $store_db = 0; - $error = array(); - if (!$safe_mode && phpbb_is_writable("{$phpbb_root_path}styles/{$path}/template")) - { - $sql = 'SELECT * - FROM ' . STYLES_TEMPLATE_DATA_TABLE . " - WHERE template_id = $id"; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - if (!($fp = @fopen("{$phpbb_root_path}styles/{$path}/template/" . $row['template_filename'], 'wb'))) - { - $store_db = 1; - $error[] = $user->lang['EDIT_TEMPLATE_STORED_DB']; - break; - } - - fwrite($fp, $row['template_data']); - fclose($fp); - } - $db->sql_freeresult($result); - - if (!$store_db) - { - $sql = 'DELETE FROM ' . STYLES_TEMPLATE_DATA_TABLE . " - WHERE template_id = $id"; - $db->sql_query($sql); - } - } - if (sizeof($error)) - { - return $error; - } - $sql = 'UPDATE ' . STYLES_TEMPLATE_TABLE . ' - SET template_storedb = 0 - WHERE template_id = ' . $id; - $db->sql_query($sql); - - return false; - } - } From ad11565ace0ef60bd98b2e368aeeffa67b6b1f49 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Sep 2011 18:46:45 +0100 Subject: [PATCH 03/16] [feature/remove-db-styles] Missed a few template DB bits in acp_styles. PHPBB3-9741 --- phpBB/includes/acp/acp_styles.php | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 7ab2061141..389bbee483 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -748,30 +748,10 @@ version = {VERSION} $file_tpl = "{$phpbb_root_path}styles/{$template_row['template_path']}/template/$tpl_file.html"; $inherited = false; - if (isset($template_row['template_inherits_id']) && $template_row['template_inherits_id']) + if (isset($template_row['template_inherits_id']) && $template_row['template_inherits_id'] && !file_exists($file_tpl)) { - if (!$template_row['template_storedb']) - { - if (!file_exists($file_tpl)) - { - $file_tpl = "{$phpbb_root_path}styles/{$template_row['template_inherit_path']}/template/$tpl_file.html"; - $inherited = true; - } - } - else - { - if ($file_template_db[$file . '.html'] == $template_row['template_inherits_id']) - { - $file_tpl = "{$phpbb_root_path}styles/{$template_row['template_inherit_path']}/template/$tpl_file.html"; - $inherited = true; - } - } - } - - // Correct the filename if it is stored in database and the file is in a subfolder. - if ($template_row['template_storedb']) - { - $file = str_replace('.', '/', $file); + $file_tpl = "{$phpbb_root_path}styles/{$template_row['template_inherit_path']}/template/$tpl_file.html"; + $inherited = true; } $template->assign_block_vars('file', array( From c2d6c613d3992f243477fe291e53f8bdb029999c Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Sep 2011 19:25:21 +0100 Subject: [PATCH 04/16] [feature/remove-db-styles] ACP has forgotten how to store themes in the DB. PHPBB3-9741 --- phpBB/includes/acp/acp_styles.php | 144 +++++------------------------- 1 file changed, 23 insertions(+), 121 deletions(-) diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 389bbee483..c4c01fbc44 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -245,63 +245,7 @@ version = {VERSION} break; case 'theme': - - switch ($action) - { - // Refresh theme data stored in the database - case 'refresh': - - $sql = 'SELECT * - FROM ' . STYLES_THEME_TABLE . " - WHERE theme_id = $style_id"; - $result = $db->sql_query($sql); - $theme_row = $db->sql_fetchrow($result); - $db->sql_freeresult($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 (confirm_box(true)) - { - 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' => '', - 'theme_storedb' => 0 - ); - - $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE theme_id = $style_id"; - $db->sql_query($sql); - - $cache->destroy('sql', STYLES_THEME_TABLE); - - add_log('admin', 'LOG_THEME_REFRESHED', $theme_row['theme_name']); - trigger_error($user->lang['THEME_REFRESHED'] . adm_back_link($this->u_action)); - } - } - else - { - confirm_box(false, $user->lang['CONFIRM_THEME_REFRESH'], build_hidden_fields(array( - 'i' => $id, - 'mode' => $mode, - 'action' => $action, - 'id' => $style_id - ))); - } - break; - } - - $this->frontend('theme', array('edit', 'details'), array('refresh', 'export', 'delete')); + $this->frontend('theme', array('edit', 'details'), array('export', 'delete')); break; } } @@ -797,7 +741,7 @@ version = {VERSION} $theme_file = str_replace('..', '.', $theme_file); // Retrieve some information about the theme - $sql = 'SELECT theme_storedb, theme_path, theme_name, theme_data + $sql = 'SELECT theme_path, theme_name FROM ' . STYLES_THEME_TABLE . " WHERE theme_id = $theme_id"; $result = $db->sql_query($sql); @@ -816,8 +760,7 @@ version = {VERSION} $additional = ''; $message = $user->lang['THEME_UPDATED']; - // If the theme is stored on the filesystem try to write the file else store it in the database - if (!$safe_mode && !$theme_info['theme_storedb'] && file_exists($file) && phpbb_is_writable($file)) + if (!$safe_mode && file_exists($file) && phpbb_is_writable($file)) { if (!($fp = @fopen($file, 'wb'))) { @@ -828,51 +771,28 @@ version = {VERSION} } else { - // Write stylesheet to db - $sql_ary = array( - 'theme_mtime' => time(), - 'theme_storedb' => 1, - 'theme_data' => $this->db_theme_data($theme_info, $theme_data), - ); - $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE theme_id = ' . $theme_id; - $db->sql_query($sql); - - $cache->destroy('sql', STYLES_THEME_TABLE); - - // notify the user if the theme was not stored in the db before his modification - if (!$theme_info['theme_storedb']) - { - add_log('admin', 'LOG_THEME_EDIT_DETAILS', $theme_info['theme_name']); - $message .= '
' . $user->lang['EDIT_THEME_STORED_DB']; - } + // @todo Proper error + trigger_error('Cannot write to theme file.', E_USER_ERROR); } + $cache->destroy('sql', STYLES_THEME_TABLE); - add_log('admin', (!$theme_info['theme_storedb']) ? 'LOG_THEME_EDIT_FILE' : 'LOG_THEME_EDIT', $theme_info['theme_name'], (!$theme_info['theme_storedb']) ? $theme_file : ''); + add_log('admin', 'LOG_THEME_EDIT_FILE', $theme_info['theme_name'], $theme_file); trigger_error($message . adm_back_link($this->u_action . "&action=edit&id=$theme_id&template_file=$theme_file&text_rows=$text_rows")); } // Generate a category array containing theme filenames - if (!$theme_info['theme_storedb']) + $theme_path = "{$phpbb_root_path}styles/{$theme_info['theme_path']}/theme"; + + $filelist = filelist($theme_path, '', 'css'); + + if ($theme_file) { - $theme_path = "{$phpbb_root_path}styles/{$theme_info['theme_path']}/theme"; - - $filelist = filelist($theme_path, '', 'css'); - - if ($theme_file) + if (!file_exists($theme_path . "/$theme_file") || !($theme_data = file_get_contents($theme_path . "/$theme_file"))) { - if (!file_exists($theme_path . "/$theme_file") || !($theme_data = file_get_contents($theme_path . "/$theme_file"))) - { - trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING); - } + trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING); } } - else - { - $theme_data = &$theme_info['theme_data']; - } // Now create the categories $filelist_cats[''] = array(); @@ -935,7 +855,6 @@ version = {VERSION} $template->assign_vars(array( 'S_EDIT_THEME' => true, 'S_HIDDEN_FIELDS' => build_hidden_fields(array('template_file' => $theme_file)), - 'S_THEME_IN_DB' => $theme_info['theme_storedb'], 'S_TEMPLATES' => $tpl_options, 'U_ACTION' => $this->u_action . "&action=edit&id=$theme_id&text_rows=$text_rows", @@ -953,8 +872,8 @@ version = {VERSION} 'SELECTED_TEMPLATE' => $theme_info['theme_name'], 'TEMPLATE_FILE' => $theme_file, 'TEMPLATE_DATA' => utf8_htmlspecialchars($theme_data), - 'TEXT_ROWS' => $text_rows) - ); + 'TEXT_ROWS' => $text_rows, + )); } /** @@ -983,7 +902,7 @@ version = {VERSION} case 'theme': $sql_from = STYLES_THEME_TABLE; - $sql_select = 'theme_id, theme_name, theme_path, theme_storedb'; + $sql_select = 'theme_id, theme_name, theme_path'; break; } @@ -1346,7 +1265,7 @@ version = {VERSION} trigger_error($user->lang['NO_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING); } - $var_ary = array('style_id', 'style_name', 'style_copyright', 'template_id', 'template_name', 'template_path', 'template_copyright', 'template_inherits_id', 'bbcode_bitfield', 'theme_id', 'theme_name', 'theme_path', 'theme_copyright', 'theme_storedb', 'theme_mtime', 'theme_data'); + $var_ary = array('style_id', 'style_name', 'style_copyright', 'template_id', 'template_name', 'template_path', 'template_copyright', 'template_inherits_id', 'bbcode_bitfield', 'theme_id', 'theme_name', 'theme_path', 'theme_copyright', 'theme_mtime'); foreach ($var_ary as $var) { @@ -1423,23 +1342,14 @@ version = {VERSION} 'src' => "styles/{$style_row['theme_path']}/theme/", 'prefix-' => "styles/{$style_row['theme_path']}/", 'prefix+' => false, - 'exclude' => ($style_row['theme_storedb']) ? 'stylesheet.css,theme.cfg' : 'theme.cfg' + 'exclude' => 'theme.cfg', ); $data[] = array( 'src' => $theme_cfg, - 'prefix' => 'theme/theme.cfg' + 'prefix' => 'theme/theme.cfg', ); - if ($style_row['theme_storedb']) - { - $style_row['theme_data'] = str_replace("styles/{$style_row['theme_path']}/theme/", './', $style_row['theme_data']); - $data[] = array( - 'src' => $style_row['theme_data'], - 'prefix' => 'theme/stylesheet.css' - ); - } - unset($items, $theme_cfg); } @@ -2399,7 +2309,7 @@ version = {VERSION} /** * Install/add an element, doing various checks as we go */ - function install_element($mode, &$error, $action, $root_path, &$id, $name, $path, $copyright, $store_db = 0) + function install_element($mode, &$error, $action, $root_path, &$id, $name, $path, $copyright) { global $phpbb_root_path, $db, $user; @@ -2466,7 +2376,7 @@ version = {VERSION} $select_bf = ''; } - $sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path, {$mode}_storedb $select_bf + $sql = "SELECT {$mode}_id, {$mode}_name, {$mode}_path, $select_bf FROM $sql_from WHERE {$mode}_name = '" . $db->sql_escape($cfg_data['inherit_from']) . "' AND {$mode}_inherits_id = 0"; @@ -2482,8 +2392,6 @@ version = {VERSION} $inherit_id = $row["{$mode}_id"]; $inherit_path = $row["{$mode}_path"]; $inherit_bf = ($mode === 'template') ? $row["bbcode_bitfield"] : false; - $cfg_data['store_db'] = $row["{$mode}_storedb"]; - $store_db = $row["{$mode}_storedb"]; } } else @@ -2534,8 +2442,6 @@ version = {VERSION} // We are only interested in the theme configuration for now $sql_ary += array( - 'theme_storedb' => $store_db, - 'theme_data' => ($store_db) ? $this->db_theme_data($sql_ary, false, $root_path) : '', 'theme_mtime' => (int) filemtime("{$phpbb_root_path}styles/$path/theme/stylesheet.css") ); break; @@ -2551,11 +2457,7 @@ version = {VERSION} $db->sql_transaction('commit'); - $log = ($store_db) ? 'LOG_' . $l_type . '_ADD_DB' : 'LOG_' . $l_type . '_ADD_FS'; - add_log('admin', $log, $name); - - // Return store_db in case it had to be altered - return $store_db; + add_log('admin', 'LOG_' . $l_type . '_ADD_FS', $name); } /** From 267daf0c3990e7e065fc44c260aaf7d31f2b5022 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Sep 2011 19:27:11 +0100 Subject: [PATCH 05/16] [feature/remove-db-styles] Remove DB theme handling code from session. PHPBB3-9741 --- phpBB/includes/session.php | 51 ++------------------------------------ 1 file changed, 2 insertions(+), 49 deletions(-) diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index c66bf89b47..bd2257c139 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -1655,7 +1655,7 @@ class user extends session $style = ($style) ? $style : ((!$config['override_user_style']) ? $this->data['user_style'] : $config['default_style']); } - $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_name, c.theme_storedb, c.theme_id + $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_name, c.theme_id FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . " c WHERE s.style_id = $style AND t.template_id = s.template_id @@ -1674,7 +1674,7 @@ class user extends session WHERE user_id = {$this->data['user_id']}"; $db->sql_query($sql); - $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, c.theme_path, c.theme_name, c.theme_storedb, c.theme_id + $sql = 'SELECT s.style_id, t.template_path, t.template_id, t.bbcode_bitfield, c.theme_path, c.theme_name, c.theme_id FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . " c WHERE s.style_id = $style AND t.template_id = s.template_id @@ -1696,7 +1696,6 @@ class user extends session $parsed_items = $parsed_items['theme']; $check_for = array( - 'parse_css_file' => (int) 0, 'pagination_sep' => (string) ', ' ); @@ -1711,52 +1710,6 @@ class user extends session } } - // If the style author specified the theme needs to be cached - // (because of the used paths and variables) than make sure it is the case. - // For example, if the theme uses language-specific images it needs to be stored in db. - if (!$this->theme['theme_storedb'] && $this->theme['parse_css_file']) - { - $this->theme['theme_storedb'] = 1; - - $stylesheet = file_get_contents("{$phpbb_root_path}styles/{$this->theme['theme_path']}/theme/stylesheet.css"); - // Match CSS imports - $matches = array(); - preg_match_all('/@import url\(["\'](.*)["\']\);/i', $stylesheet, $matches); - - if (sizeof($matches)) - { - $content = ''; - foreach ($matches[0] as $idx => $match) - { - if ($content = @file_get_contents("{$phpbb_root_path}styles/{$this->theme['theme_path']}/theme/" . $matches[1][$idx])) - { - $content = trim($content); - } - else - { - $content = ''; - } - $stylesheet = str_replace($match, $content, $stylesheet); - } - unset($content); - } - - $stylesheet = str_replace('./', 'styles/' . $this->theme['theme_path'] . '/theme/', $stylesheet); - - $sql_ary = array( - 'theme_data' => $stylesheet, - 'theme_mtime' => time(), - 'theme_storedb' => 1 - ); - - $sql = 'UPDATE ' . STYLES_THEME_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' - WHERE theme_id = ' . $this->theme['theme_id']; - $db->sql_query($sql); - - unset($sql_ary); - } - $template->set_template(); $this->img_lang = $this->lang_name; From b1df91db806f814d24948db773c27f15a731147e Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Sep 2011 19:29:36 +0100 Subject: [PATCH 06/16] [feature/remove-db-styles] Remove parse_css_file option from themes. PHPBB3-9741 --- phpBB/styles/prosilver/theme/theme.cfg | 4 ---- phpBB/styles/subsilver2/theme/theme.cfg | 3 --- 2 files changed, 7 deletions(-) diff --git a/phpBB/styles/prosilver/theme/theme.cfg b/phpBB/styles/prosilver/theme/theme.cfg index f02d5fcc05..e27ba1c3a6 100644 --- a/phpBB/styles/prosilver/theme/theme.cfg +++ b/phpBB/styles/prosilver/theme/theme.cfg @@ -14,12 +14,8 @@ # the value, then enclose the value with single or double quotes. # Single and double quotes do not need to be escaped. # -# Available and used values: -# parse_css_file -# # General Information about this theme name = prosilver copyright = © phpBB Group, 2007 version = 3.1.0-dev - diff --git a/phpBB/styles/subsilver2/theme/theme.cfg b/phpBB/styles/subsilver2/theme/theme.cfg index 207e1b6650..c560dabae2 100644 --- a/phpBB/styles/subsilver2/theme/theme.cfg +++ b/phpBB/styles/subsilver2/theme/theme.cfg @@ -14,9 +14,6 @@ # the value, then enclose the value with single or double quotes. # Single and double quotes do not need to be escaped. # -# Available and used values: -# parse_css_file -# # General Information about this theme name = subsilver2 From 934a9da313fd6af6986b5320314a2859a1526a1b Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Sep 2011 20:00:21 +0100 Subject: [PATCH 07/16] [feature/remove-db-styles] Remove style.php DB storage. Removed all use of the DB for serving/caching the theme from style.php, acp_style no longer stores the theme modified time either. As a consequence currently all stylesheets will be served through style.php (with no caching) until imagesets are removed [PHPBB3-10336], then they can we served as static files by HTTPd. PHPBB3-9741 --- phpBB/includes/acp/acp_styles.php | 7 +--- phpBB/includes/functions.php | 2 +- phpBB/style.php | 66 ++----------------------------- 3 files changed, 6 insertions(+), 69 deletions(-) diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index c4c01fbc44..388f340e07 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -1265,7 +1265,7 @@ version = {VERSION} trigger_error($user->lang['NO_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING); } - $var_ary = array('style_id', 'style_name', 'style_copyright', 'template_id', 'template_name', 'template_path', 'template_copyright', 'template_inherits_id', 'bbcode_bitfield', 'theme_id', 'theme_name', 'theme_path', 'theme_copyright', 'theme_mtime'); + $var_ary = array('style_id', 'style_name', 'style_copyright', 'template_id', 'template_name', 'template_path', 'template_copyright', 'template_inherits_id', 'bbcode_bitfield', 'theme_id', 'theme_name', 'theme_path', 'theme_copyright'); foreach ($var_ary as $var) { @@ -2439,11 +2439,6 @@ version = {VERSION} break; case 'theme': - // We are only interested in the theme configuration for now - - $sql_ary += array( - 'theme_mtime' => (int) filemtime("{$phpbb_root_path}styles/$path/theme/stylesheet.css") - ); break; } diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 2fa0f89436..23f3e88be4 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4566,7 +4566,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'T_ICONS_PATH' => "{$web_path}{$config['icons_path']}/", 'T_RANKS_PATH' => "{$web_path}{$config['ranks_path']}/", 'T_UPLOAD_PATH' => "{$web_path}{$config['upload_path']}/", - 'T_STYLESHEET_LINK' => (!$user->theme['theme_storedb']) ? "{$web_path}styles/" . $user->theme['theme_path'] . '/theme/stylesheet.css' : append_sid("{$phpbb_root_path}style.$phpEx", 'id=' . $user->theme['style_id'] . '&lang=' . $user->lang_name), + 'T_STYLESHEET_LINK' => append_sid("{$phpbb_root_path}style.$phpEx", 'id=' . $user->theme['style_id'] . '&lang=' . $user->lang_name), 'T_STYLESHEET_LANG_LINK' => "{$web_path}styles/" . $user->theme['theme_path'] . '/theme/' . $user->lang_name . '/stylesheet.css', 'T_STYLESHEET_NAME' => $user->theme['theme_name'], diff --git a/phpBB/style.php b/phpBB/style.php index 7f7b71d753..c84713f267 100644 --- a/phpBB/style.php +++ b/phpBB/style.php @@ -112,7 +112,7 @@ if ($id) $user = array('user_id' => ANONYMOUS); } - $sql = 'SELECT s.style_id, c.theme_id, c.theme_data, c.theme_path, c.theme_name, c.theme_mtime, t.template_path + $sql = 'SELECT s.style_id, c.theme_id, c.theme_path, c.theme_name, t.template_path FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c WHERE s.style_id = ' . $id . ' AND t.template_id = s.template_id @@ -145,70 +145,12 @@ if ($id) // Expire time of seven days if not recached $expire_time = 7*86400; - $recache = false; - // Re-cache stylesheet data if necessary - if ($recompile || empty($theme['theme_data'])) - { - $recache = (empty($theme['theme_data'])) ? true : false; - $update_time = time(); + include_once($phpbb_root_path . 'includes/acp/acp_styles.' . $phpEx); - // 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); - } - - // 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)); - } + $theme['theme_data'] = acp_styles::db_theme_data($theme); + header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + $expire_time)); header('Content-type: text/css; charset=UTF-8'); // Echo Theme Data From 270cd839a6519e54ac7f3a02a132854dbc4107af Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Sep 2011 20:08:27 +0100 Subject: [PATCH 08/16] [feature/remove-db-styles] Update database schemas. Removes: * styles_template_data table * template_storedb on styles_template table * On styles_theme table: - theme_storedb - theme_mtime - theme_data PHPBB3-9741 --- phpBB/develop/create_schema_files.php | 18 --------------- phpBB/install/schemas/firebird_schema.sql | 18 +-------------- phpBB/install/schemas/mssql_schema.sql | 27 ++--------------------- phpBB/install/schemas/mysql_40_schema.sql | 16 -------------- phpBB/install/schemas/mysql_41_schema.sql | 16 -------------- phpBB/install/schemas/oracle_schema.sql | 21 ------------------ phpBB/install/schemas/postgres_schema.sql | 18 --------------- phpBB/install/schemas/schema_data.sql | 2 +- phpBB/install/schemas/sqlite_schema.sql | 18 +-------------- 9 files changed, 5 insertions(+), 149 deletions(-) diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index 213354fcb9..2057d292b7 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -1657,7 +1657,6 @@ function get_schema_struct() 'template_copyright' => array('VCHAR_UNI', ''), 'template_path' => array('VCHAR:100', ''), 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), - 'template_storedb' => array('BOOL', 0), 'template_inherits_id' => array('UINT:4', 0), 'template_inherit_path' => array('VCHAR', ''), ), @@ -1667,29 +1666,12 @@ function get_schema_struct() ), ); - $schema_data['phpbb_styles_template_data'] = array( - 'COLUMNS' => array( - 'template_id' => array('UINT', 0), - 'template_filename' => array('VCHAR:100', ''), - 'template_included' => array('TEXT', ''), - 'template_mtime' => array('TIMESTAMP', 0), - 'template_data' => array('MTEXT_UNI', ''), - ), - 'KEYS' => array( - 'tid' => array('INDEX', 'template_id'), - 'tfn' => array('INDEX', 'template_filename'), - ), - ); - $schema_data['phpbb_styles_theme'] = array( 'COLUMNS' => array( 'theme_id' => array('UINT', NULL, 'auto_increment'), 'theme_name' => array('VCHAR_UNI:255', ''), 'theme_copyright' => array('VCHAR_UNI', ''), 'theme_path' => array('VCHAR:100', ''), - 'theme_storedb' => array('BOOL', 0), - 'theme_mtime' => array('TIMESTAMP', 0), - 'theme_data' => array('MTEXT_UNI', ''), ), 'PRIMARY_KEY' => 'theme_id', 'KEYS' => array( diff --git a/phpBB/install/schemas/firebird_schema.sql b/phpBB/install/schemas/firebird_schema.sql index b5a081bce4..67e5547bb6 100644 --- a/phpBB/install/schemas/firebird_schema.sql +++ b/phpBB/install/schemas/firebird_schema.sql @@ -1104,7 +1104,6 @@ CREATE TABLE phpbb_styles_template ( template_copyright VARCHAR(255) CHARACTER SET UTF8 DEFAULT '' NOT NULL COLLATE UNICODE, template_path VARCHAR(100) CHARACTER SET NONE DEFAULT '' NOT NULL, bbcode_bitfield VARCHAR(255) CHARACTER SET NONE DEFAULT 'kNg=' NOT NULL, - template_storedb INTEGER DEFAULT 0 NOT NULL, template_inherits_id INTEGER DEFAULT 0 NOT NULL, template_inherit_path VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL );; @@ -1124,27 +1123,12 @@ BEGIN END;; -# Table: 'phpbb_styles_template_data' -CREATE TABLE phpbb_styles_template_data ( - template_id INTEGER DEFAULT 0 NOT NULL, - template_filename VARCHAR(100) CHARACTER SET NONE DEFAULT '' NOT NULL, - template_included BLOB SUB_TYPE TEXT CHARACTER SET NONE DEFAULT '' NOT NULL, - template_mtime INTEGER DEFAULT 0 NOT NULL, - template_data BLOB SUB_TYPE TEXT CHARACTER SET UTF8 DEFAULT '' NOT NULL -);; - -CREATE INDEX phpbb_styles_template_data_tid ON phpbb_styles_template_data(template_id);; -CREATE INDEX phpbb_styles_template_data_tfn ON phpbb_styles_template_data(template_filename);; - # Table: 'phpbb_styles_theme' CREATE TABLE phpbb_styles_theme ( theme_id INTEGER NOT NULL, theme_name VARCHAR(255) CHARACTER SET UTF8 DEFAULT '' NOT NULL COLLATE UNICODE, theme_copyright VARCHAR(255) CHARACTER SET UTF8 DEFAULT '' NOT NULL COLLATE UNICODE, - theme_path VARCHAR(100) CHARACTER SET NONE DEFAULT '' NOT NULL, - theme_storedb INTEGER DEFAULT 0 NOT NULL, - theme_mtime INTEGER DEFAULT 0 NOT NULL, - theme_data BLOB SUB_TYPE TEXT CHARACTER SET UTF8 DEFAULT '' NOT NULL + theme_path VARCHAR(100) CHARACTER SET NONE DEFAULT '' NOT NULL );; ALTER TABLE phpbb_styles_theme ADD PRIMARY KEY (theme_id);; diff --git a/phpBB/install/schemas/mssql_schema.sql b/phpBB/install/schemas/mssql_schema.sql index d0260ce9c5..fe69670ded 100644 --- a/phpBB/install/schemas/mssql_schema.sql +++ b/phpBB/install/schemas/mssql_schema.sql @@ -1337,7 +1337,6 @@ CREATE TABLE [phpbb_styles_template] ( [template_copyright] [varchar] (255) DEFAULT ('') NOT NULL , [template_path] [varchar] (100) DEFAULT ('') NOT NULL , [bbcode_bitfield] [varchar] (255) DEFAULT ('kNg=') NOT NULL , - [template_storedb] [int] DEFAULT (0) NOT NULL , [template_inherits_id] [int] DEFAULT (0) NOT NULL , [template_inherit_path] [varchar] (255) DEFAULT ('') NOT NULL ) ON [PRIMARY] @@ -1354,25 +1353,6 @@ CREATE UNIQUE INDEX [tmplte_nm] ON [phpbb_styles_template]([template_name]) ON GO -/* - Table: 'phpbb_styles_template_data' -*/ -CREATE TABLE [phpbb_styles_template_data] ( - [template_id] [int] DEFAULT (0) NOT NULL , - [template_filename] [varchar] (100) DEFAULT ('') NOT NULL , - [template_included] [varchar] (8000) DEFAULT ('') NOT NULL , - [template_mtime] [int] DEFAULT (0) NOT NULL , - [template_data] [text] DEFAULT ('') NOT NULL -) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] -GO - -CREATE INDEX [tid] ON [phpbb_styles_template_data]([template_id]) ON [PRIMARY] -GO - -CREATE INDEX [tfn] ON [phpbb_styles_template_data]([template_filename]) ON [PRIMARY] -GO - - /* Table: 'phpbb_styles_theme' */ @@ -1380,11 +1360,8 @@ CREATE TABLE [phpbb_styles_theme] ( [theme_id] [int] IDENTITY (1, 1) NOT NULL , [theme_name] [varchar] (255) DEFAULT ('') NOT NULL , [theme_copyright] [varchar] (255) DEFAULT ('') NOT NULL , - [theme_path] [varchar] (100) DEFAULT ('') NOT NULL , - [theme_storedb] [int] DEFAULT (0) NOT NULL , - [theme_mtime] [int] DEFAULT (0) NOT NULL , - [theme_data] [text] DEFAULT ('') NOT NULL -) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] + [theme_path] [varchar] (100) DEFAULT ('') NOT NULL +) ON [PRIMARY] GO ALTER TABLE [phpbb_styles_theme] WITH NOCHECK ADD diff --git a/phpBB/install/schemas/mysql_40_schema.sql b/phpBB/install/schemas/mysql_40_schema.sql index 276a2cb2a2..da6ce35be3 100644 --- a/phpBB/install/schemas/mysql_40_schema.sql +++ b/phpBB/install/schemas/mysql_40_schema.sql @@ -766,7 +766,6 @@ CREATE TABLE phpbb_styles_template ( template_copyright blob NOT NULL, template_path varbinary(100) DEFAULT '' NOT NULL, bbcode_bitfield varbinary(255) DEFAULT 'kNg=' NOT NULL, - template_storedb tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, template_inherits_id int(4) UNSIGNED DEFAULT '0' NOT NULL, template_inherit_path varbinary(255) DEFAULT '' NOT NULL, PRIMARY KEY (template_id), @@ -774,27 +773,12 @@ CREATE TABLE phpbb_styles_template ( ); -# Table: 'phpbb_styles_template_data' -CREATE TABLE phpbb_styles_template_data ( - template_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, - template_filename varbinary(100) DEFAULT '' NOT NULL, - template_included blob NOT NULL, - template_mtime int(11) UNSIGNED DEFAULT '0' NOT NULL, - template_data mediumblob NOT NULL, - KEY tid (template_id), - KEY tfn (template_filename) -); - - # Table: 'phpbb_styles_theme' CREATE TABLE phpbb_styles_theme ( theme_id mediumint(8) UNSIGNED NOT NULL auto_increment, theme_name blob NOT NULL, theme_copyright blob NOT NULL, theme_path varbinary(100) DEFAULT '' NOT NULL, - theme_storedb tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, - theme_mtime int(11) UNSIGNED DEFAULT '0' NOT NULL, - theme_data mediumblob NOT NULL, PRIMARY KEY (theme_id), UNIQUE theme_name (theme_name(255)) ); diff --git a/phpBB/install/schemas/mysql_41_schema.sql b/phpBB/install/schemas/mysql_41_schema.sql index b3f903e0fb..cdbe377178 100644 --- a/phpBB/install/schemas/mysql_41_schema.sql +++ b/phpBB/install/schemas/mysql_41_schema.sql @@ -766,7 +766,6 @@ CREATE TABLE phpbb_styles_template ( template_copyright varchar(255) DEFAULT '' NOT NULL, template_path varchar(100) DEFAULT '' NOT NULL, bbcode_bitfield varchar(255) DEFAULT 'kNg=' NOT NULL, - template_storedb tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, template_inherits_id int(4) UNSIGNED DEFAULT '0' NOT NULL, template_inherit_path varchar(255) DEFAULT '' NOT NULL, PRIMARY KEY (template_id), @@ -774,27 +773,12 @@ CREATE TABLE phpbb_styles_template ( ) CHARACTER SET `utf8` COLLATE `utf8_bin`; -# Table: 'phpbb_styles_template_data' -CREATE TABLE phpbb_styles_template_data ( - template_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, - template_filename varchar(100) DEFAULT '' NOT NULL, - template_included text NOT NULL, - template_mtime int(11) UNSIGNED DEFAULT '0' NOT NULL, - template_data mediumtext NOT NULL, - KEY tid (template_id), - KEY tfn (template_filename) -) CHARACTER SET `utf8` COLLATE `utf8_bin`; - - # Table: 'phpbb_styles_theme' CREATE TABLE phpbb_styles_theme ( theme_id mediumint(8) UNSIGNED NOT NULL auto_increment, theme_name varchar(255) DEFAULT '' NOT NULL, theme_copyright varchar(255) DEFAULT '' NOT NULL, theme_path varchar(100) DEFAULT '' NOT NULL, - theme_storedb tinyint(1) UNSIGNED DEFAULT '0' NOT NULL, - theme_mtime int(11) UNSIGNED DEFAULT '0' NOT NULL, - theme_data mediumtext NOT NULL, PRIMARY KEY (theme_id), UNIQUE theme_name (theme_name) ) CHARACTER SET `utf8` COLLATE `utf8_bin`; diff --git a/phpBB/install/schemas/oracle_schema.sql b/phpBB/install/schemas/oracle_schema.sql index be71095724..8797457e87 100644 --- a/phpBB/install/schemas/oracle_schema.sql +++ b/phpBB/install/schemas/oracle_schema.sql @@ -1467,7 +1467,6 @@ CREATE TABLE phpbb_styles_template ( template_copyright varchar2(765) DEFAULT '' , template_path varchar2(100) DEFAULT '' , bbcode_bitfield varchar2(255) DEFAULT 'kNg=' NOT NULL, - template_storedb number(1) DEFAULT '0' NOT NULL, template_inherits_id number(4) DEFAULT '0' NOT NULL, template_inherit_path varchar2(255) DEFAULT '' , CONSTRAINT pk_phpbb_styles_template PRIMARY KEY (template_id), @@ -1492,23 +1491,6 @@ END; / -/* - Table: 'phpbb_styles_template_data' -*/ -CREATE TABLE phpbb_styles_template_data ( - template_id number(8) DEFAULT '0' NOT NULL, - template_filename varchar2(100) DEFAULT '' , - template_included clob DEFAULT '' , - template_mtime number(11) DEFAULT '0' NOT NULL, - template_data clob DEFAULT '' -) -/ - -CREATE INDEX phpbb_styles_template_data_tid ON phpbb_styles_template_data (template_id) -/ -CREATE INDEX phpbb_styles_template_data_tfn ON phpbb_styles_template_data (template_filename) -/ - /* Table: 'phpbb_styles_theme' */ @@ -1517,9 +1499,6 @@ CREATE TABLE phpbb_styles_theme ( theme_name varchar2(765) DEFAULT '' , theme_copyright varchar2(765) DEFAULT '' , theme_path varchar2(100) DEFAULT '' , - theme_storedb number(1) DEFAULT '0' NOT NULL, - theme_mtime number(11) DEFAULT '0' NOT NULL, - theme_data clob DEFAULT '' , CONSTRAINT pk_phpbb_styles_theme PRIMARY KEY (theme_id), CONSTRAINT u_phpbb_theme_name UNIQUE (theme_name) ) diff --git a/phpBB/install/schemas/postgres_schema.sql b/phpBB/install/schemas/postgres_schema.sql index 13a00d2ebc..3c79aacd6b 100644 --- a/phpBB/install/schemas/postgres_schema.sql +++ b/phpBB/install/schemas/postgres_schema.sql @@ -1001,7 +1001,6 @@ CREATE TABLE phpbb_styles_template ( template_copyright varchar(255) DEFAULT '' NOT NULL, template_path varchar(100) DEFAULT '' NOT NULL, bbcode_bitfield varchar(255) DEFAULT 'kNg=' NOT NULL, - template_storedb INT2 DEFAULT '0' NOT NULL CHECK (template_storedb >= 0), template_inherits_id INT4 DEFAULT '0' NOT NULL CHECK (template_inherits_id >= 0), template_inherit_path varchar(255) DEFAULT '' NOT NULL, PRIMARY KEY (template_id) @@ -1009,20 +1008,6 @@ CREATE TABLE phpbb_styles_template ( CREATE UNIQUE INDEX phpbb_styles_template_tmplte_nm ON phpbb_styles_template (template_name); -/* - Table: 'phpbb_styles_template_data' -*/ -CREATE TABLE phpbb_styles_template_data ( - template_id INT4 DEFAULT '0' NOT NULL CHECK (template_id >= 0), - template_filename varchar(100) DEFAULT '' NOT NULL, - template_included varchar(8000) DEFAULT '' NOT NULL, - template_mtime INT4 DEFAULT '0' NOT NULL CHECK (template_mtime >= 0), - template_data TEXT DEFAULT '' NOT NULL -); - -CREATE INDEX phpbb_styles_template_data_tid ON phpbb_styles_template_data (template_id); -CREATE INDEX phpbb_styles_template_data_tfn ON phpbb_styles_template_data (template_filename); - /* Table: 'phpbb_styles_theme' */ @@ -1033,9 +1018,6 @@ CREATE TABLE phpbb_styles_theme ( theme_name varchar(255) DEFAULT '' NOT NULL, theme_copyright varchar(255) DEFAULT '' NOT NULL, theme_path varchar(100) DEFAULT '' NOT NULL, - theme_storedb INT2 DEFAULT '0' NOT NULL CHECK (theme_storedb >= 0), - theme_mtime INT4 DEFAULT '0' NOT NULL CHECK (theme_mtime >= 0), - theme_data TEXT DEFAULT '' NOT NULL, PRIMARY KEY (theme_id) ); diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index cd4e80ba13..5506922e17 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -440,7 +440,7 @@ INSERT INTO phpbb_styles (style_name, style_copyright, style_active, template_id INSERT INTO phpbb_styles_template (template_name, template_copyright, template_path, bbcode_bitfield) VALUES ('prosilver', '© phpBB Group', 'prosilver', 'lNg='); # -- phpbb_styles_theme -INSERT INTO phpbb_styles_theme (theme_name, theme_copyright, theme_path, theme_storedb, theme_data) VALUES ('prosilver', '© phpBB Group', 'prosilver', 1, ''); +INSERT INTO phpbb_styles_theme (theme_name, theme_copyright, theme_path) VALUES ('prosilver', '© phpBB Group', 'prosilver'); # -- Forums INSERT INTO phpbb_forums (forum_name, forum_desc, left_id, right_id, parent_id, forum_type, forum_posts, forum_topics, forum_topics_real, forum_last_post_id, forum_last_poster_id, forum_last_poster_name, forum_last_poster_colour, forum_last_post_time, forum_link, forum_password, forum_image, forum_rules, forum_rules_link, forum_rules_uid, forum_desc_uid, prune_days, prune_viewed, forum_parents) VALUES ('{L_FORUMS_FIRST_CATEGORY}', '', 1, 4, 0, 0, 1, 1, 1, 1, 2, 'Admin', 'AA0000', 972086460, '', '', '', '', '', '', '', 0, 0, ''); diff --git a/phpBB/install/schemas/sqlite_schema.sql b/phpBB/install/schemas/sqlite_schema.sql index ce9bad13ce..e0631160fd 100644 --- a/phpBB/install/schemas/sqlite_schema.sql +++ b/phpBB/install/schemas/sqlite_schema.sql @@ -741,34 +741,18 @@ CREATE TABLE phpbb_styles_template ( template_copyright varchar(255) NOT NULL DEFAULT '', template_path varchar(100) NOT NULL DEFAULT '', bbcode_bitfield varchar(255) NOT NULL DEFAULT 'kNg=', - template_storedb INTEGER UNSIGNED NOT NULL DEFAULT '0', template_inherits_id INTEGER UNSIGNED NOT NULL DEFAULT '0', template_inherit_path varchar(255) NOT NULL DEFAULT '' ); CREATE UNIQUE INDEX phpbb_styles_template_tmplte_nm ON phpbb_styles_template (template_name); -# Table: 'phpbb_styles_template_data' -CREATE TABLE phpbb_styles_template_data ( - template_id INTEGER UNSIGNED NOT NULL DEFAULT '0', - template_filename varchar(100) NOT NULL DEFAULT '', - template_included text(65535) NOT NULL DEFAULT '', - template_mtime INTEGER UNSIGNED NOT NULL DEFAULT '0', - template_data mediumtext(16777215) NOT NULL DEFAULT '' -); - -CREATE INDEX phpbb_styles_template_data_tid ON phpbb_styles_template_data (template_id); -CREATE INDEX phpbb_styles_template_data_tfn ON phpbb_styles_template_data (template_filename); - # Table: 'phpbb_styles_theme' CREATE TABLE phpbb_styles_theme ( theme_id INTEGER PRIMARY KEY NOT NULL , theme_name varchar(255) NOT NULL DEFAULT '', theme_copyright varchar(255) NOT NULL DEFAULT '', - theme_path varchar(100) NOT NULL DEFAULT '', - theme_storedb INTEGER UNSIGNED NOT NULL DEFAULT '0', - theme_mtime INTEGER UNSIGNED NOT NULL DEFAULT '0', - theme_data mediumtext(16777215) NOT NULL DEFAULT '' + theme_path varchar(100) NOT NULL DEFAULT '' ); CREATE UNIQUE INDEX phpbb_styles_theme_theme_name ON phpbb_styles_theme (theme_name); From 364a69adc21c4fd9235a6693e0b8137e5779a925 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Sep 2011 20:59:29 +0100 Subject: [PATCH 09/16] [feature/remove-db-styles] Readd table constant for upgrades etc. Removed in f23b224b946b37c171add5953e832641bbb3a5c3. PHPBB3-9741 --- phpBB/includes/constants.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index cbe488fccc..8ef1a4655d 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -262,6 +262,7 @@ define('SITELIST_TABLE', $table_prefix . 'sitelist'); define('SMILIES_TABLE', $table_prefix . 'smilies'); define('STYLES_TABLE', $table_prefix . 'styles'); define('STYLES_TEMPLATE_TABLE', $table_prefix . 'styles_template'); +define('STYLES_TEMPLATE_DATA_TABLE',$table_prefix . 'styles_template_data'); define('STYLES_THEME_TABLE', $table_prefix . 'styles_theme'); define('STYLES_IMAGESET_TABLE', $table_prefix . 'styles_imageset'); define('STYLES_IMAGESET_DATA_TABLE',$table_prefix . 'styles_imageset_data'); From cb245f5d04bcd36dd1ad8d3a95d7718ef5b15858 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Sep 2011 21:04:17 +0100 Subject: [PATCH 10/16] [feature/remove-db-styles] Add schema changes sinces 3.0.x. PHPBB3-9741 --- phpBB/install/database_update.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 7f542974d9..18741191d8 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -1062,13 +1062,22 @@ function database_update_info() ), ), 'drop_columns' => array( - STYLES_TABLE => array( + STYLES_TABLE => array( 'imageset_id', ), + STYLES_TEMPLATE_TABLE => array( + 'template_storedb', + ), + STYLES_THEME_TABLE => array( + 'theme_storedb', + 'theme_mtime', + 'theme_data', + ), ), 'drop_tables' => array( STYLES_IMAGESET_TABLE, STYLES_IMAGESET_DATA_TABLE, + STYLES_TEMPLATE_DATA_TABLE, ), ), ); From 6d24a7191f2f4ba0b4cb8c079dfa0a78c3dc3ef0 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Sep 2011 22:18:06 +0100 Subject: [PATCH 11/16] [feature/remove-db-styles] Add error if template/theme file is unwritable. PHPBB3-9741 --- phpBB/includes/acp/acp_styles.php | 54 ++++++++++++++----------------- phpBB/language/en/acp/styles.php | 1 + 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 388f340e07..be442c96d9 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -446,6 +446,14 @@ version = {VERSION} trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING); } + // Get the filesystem location of the current file + $file = "{$phpbb_root_path}styles/{$template_info['template_path']}/template/$template_file"; + + if ($template_file && ($safe_mode || !is_file($file) || !phpbb_is_writable($file))) + { + trigger_error(sprintf($user->lang['TEMPLATE_FILE_NOT_WRITABLE'], htmlspecialchars($template_file)) . adm_back_link($this->u_action), E_USER_WARNING); + } + if ($save_changes && !check_form_key('acp_styles')) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); @@ -458,26 +466,16 @@ version = {VERSION} // save changes to the template if the user submitted any if ($save_changes && $template_file) { - // Get the filesystem location of the current file - $file = "{$phpbb_root_path}styles/{$template_info['template_path']}/template/$template_file"; $additional = ''; // Try to write the file - if (!$safe_mode && file_exists($file) && phpbb_is_writable($file)) + if (!($fp = @fopen($file, 'wb'))) { - if (!($fp = @fopen($file, 'wb'))) - { - // File exists and is writeable, but still not able to be written to - trigger_error(sprintf($user->lang['TEMPLATE_FILE_NOT_WRITABLE'], htmlspecialchars($template_file)) . adm_back_link($this->u_action), E_USER_WARNING); - } - fwrite($fp, $template_data); - fclose($fp); - } - else - { - // @todo - trigger_error('Cannot write template file.', E_USER_ERROR); + // File exists and is writeable, but still not able to be written to + trigger_error(sprintf($user->lang['TEMPLATE_FILE_NOT_WRITABLE'], htmlspecialchars($template_file)) . adm_back_link($this->u_action), E_USER_WARNING); } + fwrite($fp, $template_data); + fclose($fp); // destroy the cached version of the template (filename without extension) $this->clear_template_cache($template_info, array(substr($template_file, 0, -5))); @@ -752,28 +750,26 @@ version = {VERSION} } $db->sql_freeresult($result); + // Get the filesystem location of the current file + $file = "{$phpbb_root_path}styles/{$theme_info['theme_path']}/theme/$theme_file"; + + if ($theme_file && ($safe_mode || !is_file($file) || !phpbb_is_writable($file))) + { + trigger_error(sprintf($user->lang['THEME_FILE_NOT_WRITABLE'], htmlspecialchars($theme_file)) . adm_back_link($this->u_action), E_USER_WARNING); + } + // save changes to the theme if the user submitted any if ($save_changes) { - // Get the filesystem location of the current file - $file = "{$phpbb_root_path}styles/{$theme_info['theme_path']}/theme/$theme_file"; $additional = ''; $message = $user->lang['THEME_UPDATED']; - if (!$safe_mode && file_exists($file) && phpbb_is_writable($file)) + if (!($fp = @fopen($file, 'wb'))) { - if (!($fp = @fopen($file, 'wb'))) - { - trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING); - } - fwrite($fp, $theme_data); - fclose($fp); - } - else - { - // @todo Proper error - trigger_error('Cannot write to theme file.', E_USER_ERROR); + trigger_error(sprintf($user->lang['THEME_FILE_NOT_WRITABLE'], htmlspecialchars($theme_file)) . adm_back_link($this->u_action), E_USER_WARNING); } + fwrite($fp, $theme_data); + fclose($fp); $cache->destroy('sql', STYLES_THEME_TABLE); add_log('admin', 'LOG_THEME_EDIT_FILE', $theme_info['theme_name'], $theme_file); diff --git a/phpBB/language/en/acp/styles.php b/phpBB/language/en/acp/styles.php index 32c82de45d..b1a158d357 100644 --- a/phpBB/language/en/acp/styles.php +++ b/phpBB/language/en/acp/styles.php @@ -372,6 +372,7 @@ $lang = array_merge($lang, array( 'THEME_ERR_REFRESH_FS' => 'This theme is stored on the filesystem so there is no need to refresh it.', 'THEME_ERR_STYLE_NAME' => 'You must supply a name for this theme.', 'THEME_FILE' => 'Theme file', + 'THEME_FILE_NOT_WRITABLE' => 'Unable to write to theme file %s. Please check the permissions for the directory and the files.', 'THEME_EXPORT' => 'Export Theme', 'THEME_EXPORT_EXPLAIN' => 'Here you can export a theme in the form of an archive. This archive will contain all the data necessary to install the theme on another board. You may select whether to download the file directly or to place it in your store folder for download later or via FTP.', 'THEME_EXPORTED' => 'Theme exported successfully and stored in %s.', From 58c3556e193d98d15557fe7da029829c83a08163 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Sep 2011 22:42:17 +0100 Subject: [PATCH 12/16] [feature/remove-db-styles] Mark log entrys as deprecated. PHPBB3-9741 --- phpBB/language/en/acp/common.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php index cca928831f..0bc27b780d 100644 --- a/phpBB/language/en/acp/common.php +++ b/phpBB/language/en/acp/common.php @@ -675,22 +675,28 @@ $lang = array_merge($lang, array( 'LOG_STYLE_EDIT_DETAILS' => 'Edited style
» %s', 'LOG_STYLE_EXPORT' => 'Exported style
» %s', + // @deprecated 3.1 'LOG_TEMPLATE_ADD_DB' => 'Added new template set to database
» %s', + // @deprecated 3.1 'LOG_TEMPLATE_ADD_FS' => 'Add new template set on filesystem
» %s', 'LOG_TEMPLATE_CACHE_CLEARED' => 'Deleted cached versions of template files in template set %1$s
» %2$s', 'LOG_TEMPLATE_DELETE' => 'Deleted template set
» %s', 'LOG_TEMPLATE_EDIT' => 'Edited template set %1$s
» %2$s', 'LOG_TEMPLATE_EDIT_DETAILS' => 'Edited template details
» %s', 'LOG_TEMPLATE_EXPORT' => 'Exported template set
» %s', + // @deprecated 3.1 'LOG_TEMPLATE_REFRESHED' => 'Refreshed template set
» %s', + // @deprecated 3.1 'LOG_THEME_ADD_DB' => 'Added new theme to database
» %s', + // @deprecated 3.1 'LOG_THEME_ADD_FS' => 'Add new theme on filesystem
» %s', 'LOG_THEME_DELETE' => 'Theme deleted
» %s', 'LOG_THEME_EDIT_DETAILS' => 'Edited theme details
» %s', 'LOG_THEME_EDIT' => 'Edited theme %1$s', 'LOG_THEME_EDIT_FILE' => 'Edited theme %1$s
» Modified file %2$s', 'LOG_THEME_EXPORT' => 'Exported theme
» %s', + // @deprecated 3.1 'LOG_THEME_REFRESHED' => 'Refreshed theme
» %s', 'LOG_UPDATE_DATABASE' => 'Updated Database from version %1$s to version %2$s', From 8b219832225bdad9e046a93c966e89c923c6e11e Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Sep 2011 22:42:52 +0100 Subject: [PATCH 13/16] [feature/remove-db-styles] Update language to reflect removal of db storage. PHPBB3-9741 --- phpBB/language/en/acp/styles.php | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/phpBB/language/en/acp/styles.php b/phpBB/language/en/acp/styles.php index b1a158d357..16b499e7f0 100644 --- a/phpBB/language/en/acp/styles.php +++ b/phpBB/language/en/acp/styles.php @@ -60,7 +60,6 @@ $lang = array_merge($lang, array( 'CACHE_FILESIZE' => 'File size', 'CACHE_MODIFIED' => 'Modified', 'CONFIRM_TEMPLATE_CLEAR_CACHE' => 'Are you sure you wish to clear all cached versions of your template files?', - 'CONFIRM_THEME_REFRESH' => 'Are you sure you wish to refresh the theme data stored in the database with the contents of the theme on the filesystem? This will overwrite all modifications which have been carried out with the theme editor while the theme was stored in the database.', 'COPYRIGHT' => 'Copyright', 'CREATE_STYLE' => 'Create new style', 'CREATE_TEMPLATE' => 'Create new template set', @@ -82,15 +81,13 @@ $lang = array_merge($lang, array( 'EDIT_DETAILS_STYLE' => 'Edit style', 'EDIT_DETAILS_STYLE_EXPLAIN' => 'Using the form below you can modify this existing style. You may alter the combination of template and theme which define the style itself. You may also make the style the default one.', 'EDIT_DETAILS_TEMPLATE' => 'Edit template details', - 'EDIT_DETAILS_TEMPLATE_EXPLAIN' => 'Here you can edit certain template details such as its name. You may also have the option to switch storage of the stylesheet from the filesystem to the database and vice versa. This option depends on your PHP configuration and whether your template set can be written to by the web server.', + 'EDIT_DETAILS_TEMPLATE_EXPLAIN' => 'Here you can edit certain template details such as its name.', 'EDIT_DETAILS_THEME' => 'Edit theme details', - 'EDIT_DETAILS_THEME_EXPLAIN' => 'Here you can edit certain theme details such as its name. You may also have the option to switch storage of the stylesheet from the filesystem to the database and vice versa. This option depends on your PHP configuration and whether your stylesheet can be written to by the web server.', + 'EDIT_DETAILS_THEME_EXPLAIN' => 'Here you can edit certain theme details such as its name.', 'EDIT_TEMPLATE' => 'Edit template', - 'EDIT_TEMPLATE_EXPLAIN' => 'Here you can edit your template set directly. Please remember that these edits are permanent and cannot be undone once submitted. If PHP can write to the template files in your styles directory any changes here will be written directly to those files. If PHP cannot write to those files they will be copied into the database and all changes will only be reflected there. Please take care when editing your template set, remember to close all replacement variable terms {XXXX} and conditional statements.', + 'EDIT_TEMPLATE_EXPLAIN' => 'Here you can edit your template set directly. Please remember that these edits are permanent and cannot be undone once submitted. Please take care when editing your template set, remember to close all replacement variable terms {XXXX} and conditional statements.', 'EDIT_THEME' => 'Edit theme', 'EDIT_THEME_EXPLAIN' => 'Here you can edit the selected theme, changing colours, images, etc.', - 'EDIT_THEME_STORED_DB' => 'The stylesheet file was unwritable so the stylesheet is now stored in the database containing your modification.', - 'EDIT_THEME_STORE_PARSED' => 'The theme requires that its stylesheet is parsed. This is only possible if it’s stored in the database.', 'EDITOR_DISABLED' => 'The template editor is disabled.', 'EXPORT' => 'Export', @@ -256,7 +253,6 @@ $lang = array_merge($lang, array( 'LINE_SPACING' => 'Line spacing', 'LOCALISED_IMAGES' => 'Localised', - 'LOCATION_DISABLED_EXPLAIN' => 'This setting is inherited and cannot be changed.', 'NO_CLASS' => 'Cannot find class in stylesheet.', 'NO_IMAGE' => 'No image', @@ -297,7 +293,6 @@ $lang = array_merge($lang, array( 'SELECTED_TEMPLATE_FILE' => 'Selected template file', 'SELECTED_THEME' => 'Selected theme', 'SELECTED_THEME_FILE' => 'Selected theme file', - 'STORE_DATABASE' => 'Database', 'STORE_FILESYSTEM' => 'Filesystem', 'STYLE_ACTIVATE' => 'Activate', 'STYLE_ACTIVE' => 'Active', @@ -323,14 +318,14 @@ $lang = array_merge($lang, array( 'STYLE_THEME' => 'Theme', 'STYLE_USED_BY' => 'Used by (including robots)', - 'TEMPLATE_ADDED' => 'Template set added and stored on filesystem.', + 'TEMPLATE_ADDED' => 'Template set added.', 'TEMPLATE_CACHE' => 'Template cache', 'TEMPLATE_CACHE_EXPLAIN' => 'By default phpBB caches the compiled version of its templates. This decreases the load on the server each time a page is viewed and thus may reduce the page generation time. Here you can view the cache status of each file and delete individual files or the entire cache.', 'TEMPLATE_CACHE_CLEARED' => 'Template cache cleared successfully.', 'TEMPLATE_CACHE_EMPTY' => 'There are no cached templates.', 'TEMPLATE_DELETED' => 'Template set deleted successfully.', 'TEMPLATE_DELETE_DEPENDENT' => 'The template set cannot be deleted as there are one or more other template sets inheriting from it:', - 'TEMPLATE_DELETED_FS' => 'Template set removed from database but some files may remain on the filesystem.', + 'TEMPLATE_DELETED_FS' => 'Template set removed from database but files remain on the filesystem.', 'TEMPLATE_DETAILS_UPDATED' => 'Template details successfully updated.', 'TEMPLATE_EDITOR' => 'Raw HTML template editor', 'TEMPLATE_EDITOR_HEIGHT' => 'Template editor height', @@ -349,13 +344,10 @@ $lang = array_merge($lang, array( 'TEMPLATE_FILE' => 'Template file', 'TEMPLATE_FILE_UPDATED' => 'Template file updated successfully.', 'TEMPLATE_INHERITS' => 'This template sets inherits from %s and thus cannot have a different storage setting than its super template.', - 'TEMPLATE_LOCATION' => 'Store templates in', - 'TEMPLATE_LOCATION_EXPLAIN' => 'Images are always stored on the filesystem.', 'TEMPLATE_NAME' => 'Template name', 'TEMPLATE_FILE_NOT_WRITABLE'=> 'Unable to write to template file %s. Please check the permissions for the directory and the files.', - 'THEME_ADDED' => 'New theme added on filesystem.', - 'THEME_ADDED_DB' => 'New theme added to database.', + 'THEME_ADDED' => 'New theme added.', 'THEME_CLASS_ADDED' => 'Custom class added successfully.', 'THEME_DELETED' => 'Theme deleted successfully.', 'THEME_DELETED_FS' => 'Theme removed from database but files remain on the filesystem.', @@ -369,17 +361,13 @@ $lang = array_merge($lang, array( 'THEME_ERR_NAME_EXIST' => 'A theme with that name already exists.', 'THEME_ERR_NAME_LONG' => 'The theme name can be no longer than 30 characters.', 'THEME_ERR_NOT_THEME' => 'The archive you specified does not contain a valid theme.', - 'THEME_ERR_REFRESH_FS' => 'This theme is stored on the filesystem so there is no need to refresh it.', 'THEME_ERR_STYLE_NAME' => 'You must supply a name for this theme.', 'THEME_FILE' => 'Theme file', 'THEME_FILE_NOT_WRITABLE' => 'Unable to write to theme file %s. Please check the permissions for the directory and the files.', 'THEME_EXPORT' => 'Export Theme', 'THEME_EXPORT_EXPLAIN' => 'Here you can export a theme in the form of an archive. This archive will contain all the data necessary to install the theme on another board. You may select whether to download the file directly or to place it in your store folder for download later or via FTP.', 'THEME_EXPORTED' => 'Theme exported successfully and stored in %s.', - 'THEME_LOCATION' => 'Store stylesheet in', - 'THEME_LOCATION_EXPLAIN' => 'Images are always stored on the filesystem.', 'THEME_NAME' => 'Theme name', - 'THEME_REFRESHED' => 'Theme refreshed successfully.', 'THEME_UPDATED' => 'Theme updated successfully.', 'UNDERLINE' => 'Underline', From ee994b2968492e5d4cf461ba2d2fa8c79a22e295 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Sep 2011 23:01:55 +0100 Subject: [PATCH 14/16] [feature/remove-db-styles] Rework filesystem permission checks from 6d24a71. PHPBB3-9741 --- phpBB/includes/acp/acp_styles.php | 70 +++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 18 deletions(-) diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index be442c96d9..360534d03a 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -447,11 +447,29 @@ version = {VERSION} } // Get the filesystem location of the current file - $file = "{$phpbb_root_path}styles/{$template_info['template_path']}/template/$template_file"; + $template_path = "{$phpbb_root_path}styles/{$template_info['template_path']}/template"; + $file = "$template_path/$template_file"; - if ($template_file && ($safe_mode || !is_file($file) || !phpbb_is_writable($file))) + if ($template_file) { - trigger_error(sprintf($user->lang['TEMPLATE_FILE_NOT_WRITABLE'], htmlspecialchars($template_file)) . adm_back_link($this->u_action), E_USER_WARNING); + $l_not_writable = sprintf($user->lang['TEMPLATE_FILE_NOT_WRITABLE'], htmlspecialchars($template_file)) . adm_back_link($this->u_action); + + if ($safe_mode) + { + trigger_error($l_not_writable, E_USER_WARNING); + } + + if (file_exists($file) && is_file($file) && is_readable($file)) + { + if (!phpbb_is_writable($file)) + { + trigger_error($l_not_writable, E_USER_WARNING); + } + } + else + { + trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING); + } } if ($save_changes && !check_form_key('acp_styles')) @@ -466,13 +484,11 @@ version = {VERSION} // save changes to the template if the user submitted any if ($save_changes && $template_file) { - $additional = ''; - // Try to write the file if (!($fp = @fopen($file, 'wb'))) { // File exists and is writeable, but still not able to be written to - trigger_error(sprintf($user->lang['TEMPLATE_FILE_NOT_WRITABLE'], htmlspecialchars($template_file)) . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($l_not_writable, E_USER_WARNING); } fwrite($fp, $template_data); fclose($fp); @@ -483,18 +499,19 @@ version = {VERSION} $cache->destroy('sql', STYLES_TABLE); add_log('admin', 'LOG_TEMPLATE_EDIT', $template_info['template_name'], $template_file); - trigger_error($user->lang['TEMPLATE_FILE_UPDATED'] . $additional . adm_back_link($this->u_action . "&action=edit&id=$template_id&text_rows=$text_rows&template_file=$template_file")); + trigger_error($user->lang['TEMPLATE_FILE_UPDATED'] . adm_back_link($this->u_action . "&action=edit&id=$template_id&text_rows=$text_rows&template_file=$template_file")); } // Generate a category array containing template filenames - $template_path = "{$phpbb_root_path}styles/{$template_info['template_path']}/template"; $filelist = filelist($template_path, '', 'html'); $filelist[''] = array_diff($filelist[''], array('bbcode.html')); if ($template_file) { - if (!file_exists($template_path . "/$template_file") || !($template_data = file_get_contents($template_path . "/$template_file"))) + $template_data = file_get_contents($file); + + if (!$template_data) { trigger_error($user->lang['NO_TEMPLATE'] . adm_back_link($this->u_action), E_USER_WARNING); } @@ -751,22 +768,39 @@ version = {VERSION} $db->sql_freeresult($result); // Get the filesystem location of the current file - $file = "{$phpbb_root_path}styles/{$theme_info['theme_path']}/theme/$theme_file"; + $theme_path = "{$phpbb_root_path}styles/{$theme_info['theme_path']}/theme"; + $file = "$theme_path/$theme_file"; - if ($theme_file && ($safe_mode || !is_file($file) || !phpbb_is_writable($file))) + if ($theme_file) { - trigger_error(sprintf($user->lang['THEME_FILE_NOT_WRITABLE'], htmlspecialchars($theme_file)) . adm_back_link($this->u_action), E_USER_WARNING); + $l_not_writable = sprintf($user->lang['THEME_FILE_NOT_WRITABLE'], htmlspecialchars($theme_file)) . adm_back_link($this->u_action); + + if ($safe_mode) + { + trigger_error($l_not_writable, E_USER_WARNING); + } + + if (file_exists($file) && is_file($file) && is_readable($file)) + { + if (!phpbb_is_writable($file)) + { + trigger_error($l_not_writable, E_USER_WARNING); + } + } + else + { + trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING); + } } // save changes to the theme if the user submitted any - if ($save_changes) + if ($save_changes && $theme_file) { - $additional = ''; $message = $user->lang['THEME_UPDATED']; if (!($fp = @fopen($file, 'wb'))) { - trigger_error(sprintf($user->lang['THEME_FILE_NOT_WRITABLE'], htmlspecialchars($theme_file)) . adm_back_link($this->u_action), E_USER_WARNING); + trigger_error($l_not_writable, E_USER_WARNING); } fwrite($fp, $theme_data); fclose($fp); @@ -778,13 +812,13 @@ version = {VERSION} } // Generate a category array containing theme filenames - $theme_path = "{$phpbb_root_path}styles/{$theme_info['theme_path']}/theme"; - $filelist = filelist($theme_path, '', 'css'); if ($theme_file) { - if (!file_exists($theme_path . "/$theme_file") || !($theme_data = file_get_contents($theme_path . "/$theme_file"))) + $theme_data = file_get_contents($file); + + if (!$theme_data) { trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING); } From c184fb86c9c6fb6a9dfdb731e785a145069a33ab Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Sep 2011 23:12:07 +0100 Subject: [PATCH 15/16] [feature/remove-db-styles] Removed style.php! Finally sanity has arrived! No more delivering CSS through PHP. Better 3 years late than never. PHPBB3-9741 --- phpBB/includes/functions.php | 2 +- phpBB/style.php | 164 ----------------------------------- 2 files changed, 1 insertion(+), 165 deletions(-) delete mode 100644 phpBB/style.php diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 23f3e88be4..5ccb9edd07 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4566,7 +4566,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'T_ICONS_PATH' => "{$web_path}{$config['icons_path']}/", 'T_RANKS_PATH' => "{$web_path}{$config['ranks_path']}/", 'T_UPLOAD_PATH' => "{$web_path}{$config['upload_path']}/", - 'T_STYLESHEET_LINK' => append_sid("{$phpbb_root_path}style.$phpEx", 'id=' . $user->theme['style_id'] . '&lang=' . $user->lang_name), + 'T_STYLESHEET_LINK' => "{$web_path}styles/" . $user->theme['theme_path'] . '/theme/stylesheet.css', 'T_STYLESHEET_LANG_LINK' => "{$web_path}styles/" . $user->theme['theme_path'] . '/theme/' . $user->lang_name . '/stylesheet.css', 'T_STYLESHEET_NAME' => $user->theme['theme_name'], diff --git a/phpBB/style.php b/phpBB/style.php deleted file mode 100644 index c84713f267..0000000000 --- a/phpBB/style.php +++ /dev/null @@ -1,164 +0,0 @@ -register(); - - // set up caching - $cache_factory = new phpbb_cache_factory($acm_type); - $cache = $cache_factory->get_service(); - $class_loader->set_cache($cache->get_driver()); - - $request = new phpbb_request(); - $db = new $sql_db(); - - // make sure request_var uses this request instance - request_var('', 0, false, false, $request); // "dependency injection" for a function - - // Connect to DB - if (!@$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false)) - { - exit; - } - unset($dbpasswd); - - $config = new phpbb_config_db($db, $cache->get_driver(), CONFIG_TABLE); - set_config(null, null, null, $config); - set_config_count(null, null, null, $config); - - $user = false; - - // try to get a session ID from REQUEST array - $sid = request_var('sid', ''); - - if (!$sid) - { - // if that failed, then look in the cookies - $sid = request_var($config['cookie_name'] . '_sid', '', false, true); - } - - if (strspn($sid, 'abcdefABCDEF0123456789') !== strlen($sid)) - { - $sid = ''; - } - - if ($sid) - { - $sql = 'SELECT u.user_id, u.user_lang - FROM ' . SESSIONS_TABLE . ' s, ' . USERS_TABLE . " u - WHERE s.session_id = '" . $db->sql_escape($sid) . "' - AND s.session_user_id = u.user_id"; - $result = $db->sql_query($sql); - $user = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - } - - $recompile = $config['load_tplcompile']; - if (!$user) - { - $id = ($id) ? $id : $config['default_style']; -// Commented out because calls do not always include the SID anymore -// $recompile = false; - $user = array('user_id' => ANONYMOUS); - } - - $sql = 'SELECT s.style_id, c.theme_id, c.theme_path, c.theme_name, t.template_path - FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' t, ' . STYLES_THEME_TABLE . ' c - WHERE s.style_id = ' . $id . ' - AND t.template_id = s.template_id - AND c.theme_id = s.theme_id'; - $result = $db->sql_query($sql, 300); - $theme = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$theme) - { - exit; - } - - if ($user['user_id'] == ANONYMOUS) - { - $user['user_lang'] = $config['default_lang']; - } - - // gzip_compression - if ($config['gzip_compress']) - { - // IE6 is not able to compress the style (do not ask us why!) - $browser = strtolower($request->header('User-Agent')); - - if ($browser && strpos($browser, 'msie 6.0') === false && @extension_loaded('zlib') && !headers_sent()) - { - ob_start('ob_gzhandler'); - } - } - - // Expire time of seven days if not recached - $expire_time = 7*86400; - - include_once($phpbb_root_path . 'includes/acp/acp_styles.' . $phpEx); - - $theme['theme_data'] = acp_styles::db_theme_data($theme); - - header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + $expire_time)); - header('Content-type: text/css; charset=UTF-8'); - - // Echo Theme Data - echo $theme['theme_data']; - - if (!empty($cache)) - { - $cache->unload(); - } - $db->sql_close(); -} From 7b7a56dc4a5f70f8e7ced66fef210e9591bbd929 Mon Sep 17 00:00:00 2001 From: Chris Smith Date: Tue, 20 Sep 2011 23:15:30 +0100 Subject: [PATCH 16/16] [feature/remove-db-styles] Remove forgotten template variables. PHPBB3-9741 --- phpBB/includes/acp/acp_styles.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/phpBB/includes/acp/acp_styles.php b/phpBB/includes/acp/acp_styles.php index 360534d03a..fc9acbbcb8 100644 --- a/phpBB/includes/acp/acp_styles.php +++ b/phpBB/includes/acp/acp_styles.php @@ -1706,8 +1706,6 @@ version = {VERSION} 'L_TITLE' => $user->lang[$this->page_title], 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'], 'L_NAME' => $user->lang[$l_type . '_NAME'], - 'L_LOCATION' => ($mode == 'template' || $mode == 'theme') ? $user->lang[$l_type . '_LOCATION'] : '', - 'L_LOCATION_EXPLAIN' => ($mode == 'template' || $mode == 'theme') ? $user->lang[$l_type . '_LOCATION_EXPLAIN'] : '', 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', 'NAME' => $style_row[$mode . '_name'], @@ -2024,8 +2022,6 @@ version = {VERSION} 'L_TITLE' => $user->lang[$this->page_title], 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'], 'L_NAME' => $user->lang[$l_type . '_NAME'], - 'L_LOCATION' => ($mode == 'template' || $mode == 'theme') ? $user->lang[$l_type . '_LOCATION'] : '', - 'L_LOCATION_EXPLAIN' => ($mode == 'template' || $mode == 'theme') ? $user->lang[$l_type . '_LOCATION_EXPLAIN'] : '', 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', 'NAME' => $style_row[$mode . '_name'], @@ -2167,8 +2163,6 @@ version = {VERSION} 'L_TITLE' => $user->lang[$this->page_title], 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'], 'L_NAME' => $user->lang[$l_type . '_NAME'], - 'L_LOCATION' => ($mode == 'template' || $mode == 'theme') ? $user->lang[$l_type . '_LOCATION'] : '', - 'L_LOCATION_EXPLAIN' => ($mode == 'template' || $mode == 'theme') ? $user->lang[$l_type . '_LOCATION_EXPLAIN'] : '', 'ERROR_MSG' => (sizeof($error)) ? implode('
', $error) : '', 'NAME' => $style_row[$mode . '_name'],