[feature/remove-db-styles] Add error if template/theme file is unwritable.

PHPBB3-9741
This commit is contained in:
Chris Smith 2011-09-20 22:18:06 +01:00
parent cb245f5d04
commit 6d24a7191f
2 changed files with 26 additions and 29 deletions

View file

@ -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,13 +466,9 @@ 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')))
{
// File exists and is writeable, but still not able to be written to
@ -472,12 +476,6 @@ version = {VERSION}
}
fwrite($fp, $template_data);
fclose($fp);
}
else
{
// @todo
trigger_error('Cannot write template file.', E_USER_ERROR);
}
// 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')))
{
trigger_error($user->lang['NO_THEME'] . adm_back_link($this->u_action), E_USER_WARNING);
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);
}
else
{
// @todo Proper error
trigger_error('Cannot write to theme file.', E_USER_ERROR);
}
$cache->destroy('sql', STYLES_THEME_TABLE);
add_log('admin', 'LOG_THEME_EDIT_FILE', $theme_info['theme_name'], $theme_file);

View file

@ -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.',