mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-26 20:08:55 +00:00
[ticket/9675] Put the code into methods to avoid code duplication.
PHPBB3-9675
This commit is contained in:
parent
18fedfce17
commit
0e02f5cb0b
3 changed files with 163 additions and 125 deletions
|
@ -23,16 +23,17 @@
|
||||||
<dd><select id="new_id" name="new_id">{S_REPLACE_OPTIONS}</select></dd>
|
<dd><select id="new_id" name="new_id">{S_REPLACE_OPTIONS}</select></dd>
|
||||||
</dl>
|
</dl>
|
||||||
<!-- IF S_DELETE_STYLE -->
|
<!-- IF S_DELETE_STYLE -->
|
||||||
|
<hr />
|
||||||
<dl>
|
<dl>
|
||||||
<dt><label for="new_template_id">{L_REPLACE_TEMPLATE}:</label><br /><span>{L_REPLACE_TEMPLATE_EXPLAIN}</span></dt>
|
<dt><label for="new_template_id">{L_DELETE_TEMPLATE}:</label><br /><span>{L_REPLACE_TEMPLATE_EXPLAIN}</span></dt>
|
||||||
<dd><select id="new_template_id" name="new_template_id">{S_REPLACE_TEMPLATE_OPTIONS}</select></dd>
|
<dd><select id="new_template_id" name="new_template_id">{S_REPLACE_TEMPLATE_OPTIONS}</select></dd>
|
||||||
</dl>
|
</dl>
|
||||||
<dl>
|
<dl>
|
||||||
<dt><label for="new_theme_id">{L_REPLACE_THEME}:</label><br /><span>{L_REPLACE_THEME_EXPLAIN}</span></dt>
|
<dt><label for="new_theme_id">{L_DELETE_THEME}:</label><br /><span>{L_REPLACE_THEME_EXPLAIN}</span></dt>
|
||||||
<dd><select id="new_theme_id" name="new_theme_id">{S_REPLACE_THEME_OPTIONS}</select></dd>
|
<dd><select id="new_theme_id" name="new_theme_id">{S_REPLACE_THEME_OPTIONS}</select></dd>
|
||||||
</dl>
|
</dl>
|
||||||
<dl>
|
<dl>
|
||||||
<dt><label for="new_imageset_id">{L_REPLACE_IMAGESET}:</label><br /><span>{L_REPLACE_IMAGESET_EXPLAIN}</span></dt>
|
<dt><label for="new_imageset_id">{L_DELETE_IMAGESET}:</label><br /><span>{L_REPLACE_IMAGESET_EXPLAIN}</span></dt>
|
||||||
<dd><select id="new_imageset_id" name="new_imageset_id">{S_REPLACE_IMAGESET_OPTIONS}</select></dd>
|
<dd><select id="new_imageset_id" name="new_imageset_id">{S_REPLACE_IMAGESET_OPTIONS}</select></dd>
|
||||||
</dl>
|
</dl>
|
||||||
<!-- ENDIF -->
|
<!-- ENDIF -->
|
||||||
|
|
|
@ -1587,23 +1587,23 @@ parse_css_file = {PARSE_CSS_FILE}
|
||||||
{
|
{
|
||||||
case 'style':
|
case 'style':
|
||||||
$sql_from = STYLES_TABLE;
|
$sql_from = STYLES_TABLE;
|
||||||
$sql_select = 'style_name, template_id, theme_id, imageset_id';
|
$sql_select = 'style_id, style_name, template_id, theme_id, imageset_id';
|
||||||
$sql_where = 'AND style_active = 1';
|
$sql_where = 'AND style_active = 1';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'template':
|
case 'template':
|
||||||
$sql_from = STYLES_TEMPLATE_TABLE;
|
$sql_from = STYLES_TEMPLATE_TABLE;
|
||||||
$sql_select = 'template_name, template_path, template_storedb';
|
$sql_select = 'template_id, template_name, template_path, template_storedb';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'theme':
|
case 'theme':
|
||||||
$sql_from = STYLES_THEME_TABLE;
|
$sql_from = STYLES_THEME_TABLE;
|
||||||
$sql_select = 'theme_name, theme_path, theme_storedb';
|
$sql_select = 'theme_id, theme_name, theme_path, theme_storedb';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'imageset':
|
case 'imageset':
|
||||||
$sql_from = STYLES_IMAGESET_TABLE;
|
$sql_from = STYLES_IMAGESET_TABLE;
|
||||||
$sql_select = 'imageset_name, imageset_path';
|
$sql_select = 'imageset_id, imageset_name, imageset_path';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1633,37 +1633,14 @@ parse_css_file = {PARSE_CSS_FILE}
|
||||||
trigger_error($user->lang['NO_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING);
|
trigger_error($user->lang['NO_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "SELECT {$mode}_id, {$mode}_name
|
|
||||||
FROM $sql_from
|
|
||||||
WHERE {$mode}_id <> $style_id
|
|
||||||
$sql_where
|
|
||||||
ORDER BY {$mode}_name ASC";
|
|
||||||
$result = $db->sql_query($sql);
|
|
||||||
|
|
||||||
$s_options = '';
|
|
||||||
|
|
||||||
if ($row = $db->sql_fetchrow($result))
|
|
||||||
{
|
|
||||||
do
|
|
||||||
{
|
|
||||||
$s_options .= '<option value="' . $row[$mode . '_id'] . '">' . $row[$mode . '_name'] . '</option>';
|
|
||||||
}
|
|
||||||
while ($row = $db->sql_fetchrow($result));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
trigger_error($user->lang['ONLY_' . $l_prefix] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
||||||
}
|
|
||||||
$db->sql_freeresult($result);
|
|
||||||
|
|
||||||
if ($update)
|
if ($update)
|
||||||
|
{
|
||||||
|
if ($mode == 'style')
|
||||||
{
|
{
|
||||||
$sql = "DELETE FROM $sql_from
|
$sql = "DELETE FROM $sql_from
|
||||||
WHERE {$mode}_id = $style_id";
|
WHERE {$mode}_id = $style_id";
|
||||||
$db->sql_query($sql);
|
$db->sql_query($sql);
|
||||||
|
|
||||||
if ($mode == 'style')
|
|
||||||
{
|
|
||||||
$sql = 'UPDATE ' . USERS_TABLE . "
|
$sql = 'UPDATE ' . USERS_TABLE . "
|
||||||
SET user_style = $new_id
|
SET user_style = $new_id
|
||||||
WHERE user_style = $style_id";
|
WHERE user_style = $style_id";
|
||||||
|
@ -1684,12 +1661,61 @@ parse_css_file = {PARSE_CSS_FILE}
|
||||||
foreach ($components as $component)
|
foreach ($components as $component)
|
||||||
{
|
{
|
||||||
$new_id = request_var('new_' . $component . '_id', 0);
|
$new_id = request_var('new_' . $component . '_id', 0);
|
||||||
$style_id = $style_row[$component . '_id'];
|
$component_id = $style_row[$component . '_id'];
|
||||||
|
$this->remove_component($component, $component_id, $new_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->remove_component($mode, $style_id, $new_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
$cache->destroy('sql', STYLES_TABLE);
|
||||||
|
|
||||||
|
add_log('admin', 'LOG_' . $l_prefix . '_DELETE', $style_row[$mode . '_name']);
|
||||||
|
$message = ($mode != 'style') ? $l_prefix . '_DELETED_FS' : $l_prefix . '_DELETED';
|
||||||
|
trigger_error($user->lang[$message] . adm_back_link($this->u_action));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->display_component_options($mode, $style_row[$mode . '_id'], $style_row);
|
||||||
|
|
||||||
|
$this->page_title = 'DELETE_' . $l_prefix;
|
||||||
|
|
||||||
|
$template->assign_vars(array(
|
||||||
|
'S_DELETE' => true,
|
||||||
|
|
||||||
|
'L_TITLE' => $user->lang[$this->page_title],
|
||||||
|
'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'],
|
||||||
|
'L_NAME' => $user->lang[$l_prefix . '_NAME'],
|
||||||
|
'L_REPLACE' => $user->lang['REPLACE_' . $l_prefix],
|
||||||
|
'L_REPLACE_EXPLAIN' => $user->lang['REPLACE_' . $l_prefix . '_EXPLAIN'],
|
||||||
|
|
||||||
|
'U_ACTION' => $this->u_action . "&action=delete&id=$style_id",
|
||||||
|
'U_BACK' => $this->u_action,
|
||||||
|
|
||||||
|
'NAME' => $style_row[$mode . '_name'],
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($mode == 'style')
|
||||||
|
{
|
||||||
|
$template->assign_vars(array(
|
||||||
|
'S_DELETE_STYLE' => true,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove template/theme/imageset entry from the database
|
||||||
|
*/
|
||||||
|
function remove_component($component, $style_id, $new_id)
|
||||||
|
{
|
||||||
|
global $db;
|
||||||
|
|
||||||
if (($new_id == 0) || ($component === 'template' && ($conflicts = $this->check_inheritance($component, $style_id))))
|
if (($new_id == 0) || ($component === 'template' && ($conflicts = $this->check_inheritance($component, $style_id))))
|
||||||
{
|
{
|
||||||
// We can not delete the template, as the selected one is inheriting from this one.
|
// We can not delete the template, as the selected one is inheriting from this one.
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($component == 'imageset')
|
if ($component == 'imageset')
|
||||||
|
@ -1723,101 +1749,111 @@ parse_css_file = {PARSE_CSS_FILE}
|
||||||
WHERE {$component}_id = $style_id";
|
WHERE {$component}_id = $style_id";
|
||||||
$db->sql_query($sql);
|
$db->sql_query($sql);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
/**
|
||||||
|
* Display the options which can be used to replace a style/template/theme/imageset
|
||||||
|
*/
|
||||||
|
function display_component_options($component, $component_id, $style_row = false, $style_id = false)
|
||||||
{
|
{
|
||||||
if ($mode == 'imageset')
|
global $db, $template, $user;
|
||||||
|
|
||||||
|
$component_in_use = array();
|
||||||
|
if (($component != 'style') && $style_id)
|
||||||
{
|
{
|
||||||
$sql = 'DELETE FROM ' . STYLES_IMAGESET_DATA_TABLE . "
|
$sql = 'SELECT style_id, style_name
|
||||||
WHERE imageset_id = $style_id";
|
FROM ' . STYLES_TABLE . "
|
||||||
$db->sql_query($sql);
|
WHERE {$component}_id = {$component_id}
|
||||||
|
AND style_id <> {$style_id}
|
||||||
|
ORDER BY style_name ASC";
|
||||||
|
$result = $db->sql_query($sql);
|
||||||
|
while ($row = $db->sql_fetchrow($result))
|
||||||
|
{
|
||||||
|
$component_in_use[] = $row['style_name'];
|
||||||
|
}
|
||||||
|
$db->sql_freeresult($result);
|
||||||
|
|
||||||
|
if ($component === 'template' && ($conflicts = $this->check_inheritance($component, $component_id)))
|
||||||
|
{
|
||||||
|
foreach ($conflicts as $temp_id => $conflict_data)
|
||||||
|
{
|
||||||
|
$component_in_use[] = $conflict_data['template_name'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$sql = 'UPDATE ' . STYLES_TABLE . "
|
|
||||||
SET {$mode}_id = $new_id
|
|
||||||
WHERE {$mode}_id = $style_id";
|
|
||||||
$db->sql_query($sql);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$cache->destroy('sql', STYLES_TABLE);
|
|
||||||
|
|
||||||
add_log('admin', 'LOG_' . $l_prefix . '_DELETE', $style_row[$mode . '_name']);
|
|
||||||
$message = ($mode != 'style') ? $l_prefix . '_DELETED_FS' : $l_prefix . '_DELETED';
|
|
||||||
trigger_error($user->lang[$message] . adm_back_link($this->u_action));
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->page_title = 'DELETE_' . $l_prefix;
|
|
||||||
|
|
||||||
$template->assign_vars(array(
|
|
||||||
'S_DELETE' => true,
|
|
||||||
'S_REPLACE_OPTIONS' => $s_options,
|
|
||||||
|
|
||||||
'L_TITLE' => $user->lang[$this->page_title],
|
|
||||||
'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'],
|
|
||||||
'L_NAME' => $user->lang[$l_prefix . '_NAME'],
|
|
||||||
'L_REPLACE' => $user->lang['REPLACE_' . $l_prefix],
|
|
||||||
'L_REPLACE_EXPLAIN' => $user->lang['REPLACE_' . $l_prefix . '_EXPLAIN'],
|
|
||||||
|
|
||||||
'U_ACTION' => $this->u_action . "&action=delete&id=$style_id",
|
|
||||||
'U_BACK' => $this->u_action,
|
|
||||||
|
|
||||||
'NAME' => $style_row[$mode . '_name'],
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($mode == 'style')
|
|
||||||
{
|
|
||||||
$template->assign_vars(array(
|
|
||||||
'S_DELETE_STYLE' => true,
|
|
||||||
));
|
|
||||||
|
|
||||||
$components = array('template', 'theme', 'imageset');
|
|
||||||
foreach ($components as $mode)
|
|
||||||
{
|
|
||||||
$sql_where = '';
|
$sql_where = '';
|
||||||
switch ($mode)
|
switch ($component)
|
||||||
{
|
{
|
||||||
|
case 'style':
|
||||||
|
$sql_from = STYLES_TABLE;
|
||||||
|
$sql_where = 'WHERE style_active = 1';
|
||||||
|
break;
|
||||||
|
|
||||||
case 'template':
|
case 'template':
|
||||||
$sql_from = STYLES_TEMPLATE_TABLE;
|
$sql_from = STYLES_TEMPLATE_TABLE;
|
||||||
$sql_select = 'template_name, template_path, template_storedb';
|
$sql_where = 'WHERE template_inherits_id <> ' . $component_id;
|
||||||
$sql_where = ' AND template_inherits_id <> ' . $style_row[$mode . '_id'];
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'theme':
|
case 'theme':
|
||||||
$sql_from = STYLES_THEME_TABLE;
|
$sql_from = STYLES_THEME_TABLE;
|
||||||
$sql_select = 'theme_name, theme_path, theme_storedb';
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'imageset':
|
case 'imageset':
|
||||||
$sql_from = STYLES_IMAGESET_TABLE;
|
$sql_from = STYLES_IMAGESET_TABLE;
|
||||||
$sql_select = 'imageset_name, imageset_path';
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "SELECT {$mode}_id, {$mode}_name
|
$s_options = '';
|
||||||
|
if (($component != 'style') && empty($component_in_use))
|
||||||
|
{
|
||||||
|
$sql = "SELECT {$component}_id, {$component}_name
|
||||||
FROM $sql_from
|
FROM $sql_from
|
||||||
WHERE {$mode}_id <> {$style_row[$mode . '_id']}
|
WHERE {$component}_id = {$component_id}";
|
||||||
$sql_where
|
|
||||||
ORDER BY {$mode}_name ASC";
|
|
||||||
$result = $db->sql_query($sql);
|
$result = $db->sql_query($sql);
|
||||||
|
$row = $db->sql_fetchrow($result);
|
||||||
|
$db->sql_freeresult($result);
|
||||||
|
|
||||||
$s_options = '<option value="0">' . $user->lang['KEEP_' . strtoupper($mode)] . '</option>';
|
$s_options .= '<option value="-1" selected="selected">' . $user->lang['DELETE_' . strtoupper($component)] . '</option>';
|
||||||
|
$s_options .= '<option value="0">' . sprintf($user->lang['KEEP_' . strtoupper($component)], $row[$component . '_name']) . '</option>';
|
||||||
$set_default = true;
|
|
||||||
while ($row = $db->sql_fetchrow($result))
|
|
||||||
{
|
|
||||||
if ($set_default)
|
|
||||||
{
|
|
||||||
$s_options .= '<option value="' . $row[$mode . '_id'] . '" selected="selected">' . $row[$mode . '_name'] . '</option>';
|
|
||||||
$set_default = false;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$s_options .= '<option value="' . $row[$mode . '_id'] . '">' . $row[$mode . '_name'] . '</option>';
|
$sql = "SELECT {$component}_id, {$component}_name
|
||||||
|
FROM $sql_from
|
||||||
|
$sql_where
|
||||||
|
ORDER BY {$component}_name ASC";
|
||||||
|
$result = $db->sql_query($sql);
|
||||||
|
|
||||||
|
$s_keep_option = $s_options = '';
|
||||||
|
while ($row = $db->sql_fetchrow($result))
|
||||||
|
{
|
||||||
|
if ($row[$component . '_id'] != $component_id)
|
||||||
|
{
|
||||||
|
$s_options .= '<option value="' . $row[$component . '_id'] . '">' . sprintf($user->lang['REPLACE_WITH_OPTION'], $row[$component . '_name']) . '</option>';
|
||||||
|
}
|
||||||
|
else if ($component != 'style')
|
||||||
|
{
|
||||||
|
$s_keep_option = '<option value="0" selected="selected">' . sprintf($user->lang['KEEP_' . strtoupper($component)], $row[$component . '_name']) . '</option>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$db->sql_freeresult($result);
|
$db->sql_freeresult($result);
|
||||||
|
$s_options = $s_keep_option . $s_options;
|
||||||
|
}
|
||||||
|
|
||||||
$template->assign_var('S_REPLACE_' . strtoupper($mode) . '_OPTIONS', $s_options);
|
if (!$style_row)
|
||||||
|
{
|
||||||
|
$template->assign_var('S_REPLACE_' . strtoupper($component) . '_OPTIONS', $s_options);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$template->assign_var('S_REPLACE_OPTIONS', $s_options);
|
||||||
|
if ($component == 'style')
|
||||||
|
{
|
||||||
|
$components = array('template', 'theme', 'imageset');
|
||||||
|
foreach ($components as $component)
|
||||||
|
{
|
||||||
|
$this->display_component_options($component, $style_row[$component . '_id'], false, $component_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -285,9 +285,9 @@ $lang = array_merge($lang, array(
|
||||||
'INSTALLED_TEMPLATE' => 'Installed templates',
|
'INSTALLED_TEMPLATE' => 'Installed templates',
|
||||||
'INSTALLED_THEME' => 'Installed themes',
|
'INSTALLED_THEME' => 'Installed themes',
|
||||||
|
|
||||||
'KEEP_IMAGESET' => 'Keep imageset',
|
'KEEP_IMAGESET' => 'Keep "%s" imageset',
|
||||||
'KEEP_TEMPLATE' => 'Keep template',
|
'KEEP_TEMPLATE' => 'Keep "%s" template',
|
||||||
'KEEP_THEME' => 'Keep theme',
|
'KEEP_THEME' => 'Keep "%s" theme',
|
||||||
|
|
||||||
'LINE_SPACING' => 'Line spacing',
|
'LINE_SPACING' => 'Line spacing',
|
||||||
'LOCALISED_IMAGES' => 'Localised',
|
'LOCALISED_IMAGES' => 'Localised',
|
||||||
|
@ -325,6 +325,7 @@ $lang = array_merge($lang, array(
|
||||||
'REPLACE_TEMPLATE_EXPLAIN' => 'This template set will replace the one you are deleting in any styles that use it.',
|
'REPLACE_TEMPLATE_EXPLAIN' => 'This template set will replace the one you are deleting in any styles that use it.',
|
||||||
'REPLACE_THEME' => 'Replace theme with',
|
'REPLACE_THEME' => 'Replace theme with',
|
||||||
'REPLACE_THEME_EXPLAIN' => 'This theme will replace the one you are deleting in any styles that use it.',
|
'REPLACE_THEME_EXPLAIN' => 'This theme will replace the one you are deleting in any styles that use it.',
|
||||||
|
'REPLACE_WITH_OPTION' => 'Replace with "%s"',
|
||||||
'REQUIRES_IMAGESET' => 'This style requires the %s imageset to be installed.',
|
'REQUIRES_IMAGESET' => 'This style requires the %s imageset to be installed.',
|
||||||
'REQUIRES_TEMPLATE' => 'This style requires the %s template set to be installed.',
|
'REQUIRES_TEMPLATE' => 'This style requires the %s template set to be installed.',
|
||||||
'REQUIRES_THEME' => 'This style requires the %s theme to be installed.',
|
'REQUIRES_THEME' => 'This style requires the %s theme to be installed.',
|
||||||
|
|
Loading…
Add table
Reference in a new issue