[ticket/10752] Removing globals acp_styles

Removing global variables from functions in acp_styles

PHPBB3-10752
This commit is contained in:
Vjacheslav Trushkin 2012-04-03 00:14:30 +03:00
parent 8363d32765
commit 7c99525b98

View file

@ -26,25 +26,46 @@ class acp_styles
var $mode; var $mode;
var $styles_path; var $styles_path;
var $styles_path_absolute = 'styles'; var $styles_path_absolute = 'styles';
var $default_style = 0;
private $db = false;
private $user = false;
private $template = false;
private $request = false;
private $cache = false;
private $auth = false;
private $phpbb_root_path = false;
private $phpEx = false;
function main($id, $mode) function main($id, $mode)
{ {
global $user, $phpbb_admin_path, $phpbb_root_path, $phpEx, $template, $request; global $db, $user, $phpbb_admin_path, $phpbb_root_path, $phpEx, $template, $request, $cache, $auth, $config;
$this->styles_path = $phpbb_root_path . $this->styles_path_absolute . '/'; $this->db = $db;
$this->user = $user;
$this->template = $template;
$this->request = $request;
$this->cache = $cache;
$this->auth = $auth;
$this->config = $config;
$this->phpbb_root_path = $phpbb_root_path;
$this->phpEx = $phpEx;
$this->default_style = $config['default_style'];
$this->styles_path = $this->phpbb_root_path . $this->styles_path_absolute . '/';
$this->u_base_action = append_sid("{$phpbb_admin_path}index.$phpEx", "i={$id}"); $this->u_base_action = append_sid("{$phpbb_admin_path}index.$phpEx", "i={$id}");
$this->s_hidden_fields = array( $this->s_hidden_fields = array(
'mode' => $mode, 'mode' => $mode,
); );
$user->add_lang('acp/styles'); $this->user->add_lang('acp/styles');
$this->tpl_name = 'acp_styles'; $this->tpl_name = 'acp_styles';
$this->page_title = 'ACP_CAT_STYLES'; $this->page_title = 'ACP_CAT_STYLES';
$this->mode = $mode; $this->mode = $mode;
$action = $request->variable('action', ''); $action = $this->request->variable('action', '');
$post_actions = array('install', 'activate', 'deactivate', 'uninstall'); $post_actions = array('install', 'activate', 'deactivate', 'uninstall');
foreach ($post_actions as $key) foreach ($post_actions as $key)
{ {
@ -58,7 +79,7 @@ class acp_styles
$this->s_hidden_fields['action'] = $action; $this->s_hidden_fields['action'] = $action;
} }
$template->assign_vars(array( $this->template->assign_vars(array(
'U_ACTION' => $this->u_base_action, 'U_ACTION' => $this->u_base_action,
'S_HIDDEN_FIELDS' => build_hidden_fields($this->s_hidden_fields) 'S_HIDDEN_FIELDS' => build_hidden_fields($this->s_hidden_fields)
) )
@ -107,8 +128,7 @@ class acp_styles
$this->action_cache(); $this->action_cache();
return; return;
} }
global $user; trigger_error($this->user->lang['NO_MODE'] . adm_back_link($this->u_action), E_USER_WARNING);
trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action), E_USER_WARNING);
} }
/** /**
@ -116,17 +136,15 @@ class acp_styles
*/ */
function action_cache() function action_cache()
{ {
global $cache, $auth, $user; $this->cache->purge();
$cache->purge();
// Clear permissions // Clear permissions
$auth->acl_clear_prefetch(); $this->auth->acl_clear_prefetch();
cache_moderators(); cache_moderators();
add_log('admin', 'LOG_PURGE_CACHE'); add_log('admin', 'LOG_PURGE_CACHE');
trigger_error($user->lang['PURGED_CACHE'] . adm_back_link($this->u_base_action), E_USER_NOTICE); trigger_error($this->user->lang['PURGED_CACHE'] . adm_back_link($this->u_base_action), E_USER_NOTICE);
} }
/** /**
@ -134,8 +152,6 @@ class acp_styles
*/ */
function action_install() function action_install()
{ {
global $user;
// Get list of styles to install // Get list of styles to install
$dirs = $this->request_vars('dir', '', true); $dirs = $this->request_vars('dir', '', true);
@ -166,23 +182,23 @@ class acp_styles
$last_installed = $style['style_id']; $last_installed = $style['style_id'];
$installed_names[] = $style['style_name']; $installed_names[] = $style['style_name'];
$installed_dirs[] = $style['style_path']; $installed_dirs[] = $style['style_path'];
$messages[] = sprintf($user->lang['STYLE_INSTALLED'], htmlspecialchars($style['style_name'])); $messages[] = sprintf($this->user->lang['STYLE_INSTALLED'], htmlspecialchars($style['style_name']));
} }
} }
if (!$found) if (!$found)
{ {
$messages[] = sprintf($user->lang['STYLE_NOT_INSTALLED'], htmlspecialchars($dir)); $messages[] = sprintf($this->user->lang['STYLE_NOT_INSTALLED'], htmlspecialchars($dir));
} }
} }
// Show message // Show message
if (!count($messages)) if (!count($messages))
{ {
trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING);
} }
$message = implode('<br />', $messages); $message = implode('<br />', $messages);
$message .= '<br /><br />' . sprintf($user->lang['STYLE_INSTALLED_RETURN_STYLES'], $this->u_base_action . '&amp;mode=style'); $message .= '<br /><br />' . sprintf($this->user->lang['STYLE_INSTALLED_RETURN_STYLES'], $this->u_base_action . '&amp;mode=style');
$message .= '<br /><br />' . sprintf($user->lang['STYLE_INSTALLED_RETURN_UNINSTALLED'], $this->u_base_action . '&amp;mode=install'); $message .= '<br /><br />' . sprintf($this->user->lang['STYLE_INSTALLED_RETURN_UNINSTALLED'], $this->u_base_action . '&amp;mode=install');
trigger_error($message, E_USER_NOTICE); trigger_error($message, E_USER_NOTICE);
} }
@ -191,8 +207,6 @@ class acp_styles
*/ */
function action_uninstall() function action_uninstall()
{ {
global $user, $config, $template, $request;
// Get list of styles to uninstall // Get list of styles to uninstall
$ids = $this->request_vars('id', 0, true); $ids = $this->request_vars('id', 0, true);
@ -200,7 +214,7 @@ class acp_styles
if (confirm_box(true)) if (confirm_box(true))
{ {
// Uninstall // Uninstall
$this->action_uninstall_confirmed($ids, $request->variable('confirm_delete_files', false)); $this->action_uninstall_confirmed($ids, $this->request->variable('confirm_delete_files', false));
return; return;
} }
@ -209,8 +223,8 @@ class acp_styles
'action' => 'uninstall', 'action' => 'uninstall',
'ids' => $ids 'ids' => $ids
)); ));
$template->assign_var('S_CONFIRM_DELETE', true); $this->template->assign_var('S_CONFIRM_DELETE', true);
confirm_box(false, $user->lang['CONFIRM_UNINSTALL_STYLES'], $s_hidden, 'acp_styles.html'); confirm_box(false, $this->user->lang['CONFIRM_UNINSTALL_STYLES'], $s_hidden, 'acp_styles.html');
// Canceled - show styles list // Canceled - show styles list
$this->frontend(); $this->frontend();
@ -224,9 +238,7 @@ class acp_styles
*/ */
function action_uninstall_confirmed($ids, $delete_files) function action_uninstall_confirmed($ids, $delete_files)
{ {
global $db, $user, $cache, $config; $default = $this->default_style;
$default = $config['default_style'];
$uninstalled = array(); $uninstalled = array();
$messages = array(); $messages = array();
@ -235,11 +247,11 @@ class acp_styles
{ {
if (!$id) if (!$id)
{ {
trigger_error($user->lang['INVALID_STYLE_ID'] . adm_back_link($this->u_action), E_USER_WARNING); trigger_error($this->user->lang['INVALID_STYLE_ID'] . adm_back_link($this->u_action), E_USER_WARNING);
} }
if ($id == $default) if ($id == $default)
{ {
trigger_error($user->lang['UNINSTALL_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING); trigger_error($this->user->lang['UNINSTALL_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING);
} }
$uninstalled[$id] = false; $uninstalled[$id] = false;
} }
@ -250,10 +262,10 @@ class acp_styles
FROM ' . STYLES_TABLE . ' FROM ' . STYLES_TABLE . '
WHERE style_id IN (' . implode(', ', $ids) . ') WHERE style_id IN (' . implode(', ', $ids) . ')
ORDER BY style_id DESC'; ORDER BY style_id DESC';
$result = $db->sql_query($sql); $result = $this->db->sql_query($sql);
$rows = $db->sql_fetchrowset($result); $rows = $this->db->sql_fetchrowset($result);
$db->sql_freeresult($result); $this->db->sql_freeresult($result);
// Uinstall each style // Uinstall each style
$uninstalled = array(); $uninstalled = array();
@ -266,20 +278,20 @@ class acp_styles
$messages[] = $result; $messages[] = $result;
continue; continue;
} }
$messages[] = sprintf($user->lang['STYLE_UNINSTALLED'], $style['style_name']); $messages[] = sprintf($this->user->lang['STYLE_UNINSTALLED'], $style['style_name']);
$uninstalled[] = $style['style_name']; $uninstalled[] = $style['style_name'];
// Attempt to delete files // Attempt to delete files
if ($delete_files) if ($delete_files)
{ {
$messages[] = sprintf($user->lang[$this->delete_style_files($style['style_path']) ? 'DELETE_STYLE_FILES_SUCCESS' : 'DELETE_STYLE_FILES_FAILED'], $style['style_name']); $messages[] = sprintf($this->user->lang[$this->delete_style_files($style['style_path']) ? 'DELETE_STYLE_FILES_SUCCESS' : 'DELETE_STYLE_FILES_FAILED'], $style['style_name']);
} }
} }
if (empty($messages)) if (empty($messages))
{ {
// Nothing to uninstall? // Nothing to uninstall?
trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING);
} }
// Log action // Log action
@ -289,7 +301,7 @@ class acp_styles
} }
// Clear cache // Clear cache
$cache->purge(); $this->cache->purge();
// Show message // Show message
trigger_error(implode('<br />', $messages) . adm_back_link($this->u_action), E_USER_NOTICE); trigger_error(implode('<br />', $messages) . adm_back_link($this->u_action), E_USER_NOTICE);
@ -300,8 +312,6 @@ class acp_styles
*/ */
function action_activate() function action_activate()
{ {
global $user, $config, $cache, $db;
// Get list of styles to activate // Get list of styles to activate
$ids = $this->request_vars('id', 0, true); $ids = $this->request_vars('id', 0, true);
@ -309,10 +319,10 @@ class acp_styles
$sql = 'UPDATE ' . STYLES_TABLE . ' $sql = 'UPDATE ' . STYLES_TABLE . '
SET style_active = 1 SET style_active = 1
WHERE style_id IN (' . implode(', ', $ids) . ')'; WHERE style_id IN (' . implode(', ', $ids) . ')';
$db->sql_query($sql); $this->db->sql_query($sql);
// Purge cache // Purge cache
$cache->destroy('sql', STYLES_TABLE); $this->cache->destroy('sql', STYLES_TABLE);
// Show styles list // Show styles list
$this->frontend(); $this->frontend();
@ -323,17 +333,15 @@ class acp_styles
*/ */
function action_deactivate() function action_deactivate()
{ {
global $user, $config, $cache, $db;
// Get list of styles to deactivate // Get list of styles to deactivate
$ids = $this->request_vars('id', 0, true); $ids = $this->request_vars('id', 0, true);
// Check for default style // Check for default style
foreach ($ids as $id) foreach ($ids as $id)
{ {
if ($id == $config['default_style']) if ($id == $this->default_style)
{ {
trigger_error($user->lang['DEACTIVATE_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING); trigger_error($this->user->lang['DEACTIVATE_DEFAULT'] . adm_back_link($this->u_action), E_USER_WARNING);
} }
} }
@ -341,16 +349,16 @@ class acp_styles
$sql = 'UPDATE ' . USERS_TABLE . ' $sql = 'UPDATE ' . USERS_TABLE . '
SET user_style = 0 SET user_style = 0
WHERE user_style IN (' . implode(', ', $ids) . ')'; WHERE user_style IN (' . implode(', ', $ids) . ')';
$db->sql_query($sql); $this->db->sql_query($sql);
// Deactivate styles // Deactivate styles
$sql = 'UPDATE ' . STYLES_TABLE . ' $sql = 'UPDATE ' . STYLES_TABLE . '
SET style_active = 0 SET style_active = 0
WHERE style_id IN (' . implode(', ', $ids) . ')'; WHERE style_id IN (' . implode(', ', $ids) . ')';
$db->sql_query($sql); $this->db->sql_query($sql);
// Purge cache // Purge cache
$cache->destroy('sql', STYLES_TABLE); $this->cache->destroy('sql', STYLES_TABLE);
// Show styles list // Show styles list
$this->frontend(); $this->frontend();
@ -361,12 +369,10 @@ class acp_styles
*/ */
function action_details() function action_details()
{ {
global $user, $config, $db, $request, $template, $cache; $id = $this->request->variable('id', 0);
$id = $request->variable('id', 0);
if (!$id) if (!$id)
{ {
trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING);
} }
// Get all styles // Get all styles
@ -386,19 +392,19 @@ class acp_styles
if ($style === false) if ($style === false)
{ {
trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING);
} }
// Find all available parent styles // Find all available parent styles
$list = $this->find_possible_parents($styles, $id); $list = $this->find_possible_parents($styles, $id);
// Change data // Change data
if ($request->variable('update', false)) if ($this->request->variable('update', false))
{ {
$update = array( $update = array(
'style_name' => trim($request->variable('style_name', $style['style_name'])), 'style_name' => trim($this->request->variable('style_name', $style['style_name'])),
'style_parent_id' => $request->variable('style_parent', (int) $style['style_parent_id']), 'style_parent_id' => $this->request->variable('style_parent', (int) $style['style_parent_id']),
'style_active' => $request->variable('style_active', (int) $style['style_active']), 'style_active' => $this->request->variable('style_active', (int) $style['style_active']),
); );
$update_action = $this->u_action . '&amp;action=details&amp;id=' . $id; $update_action = $this->u_action . '&amp;action=details&amp;id=' . $id;
@ -407,13 +413,13 @@ class acp_styles
{ {
if (!strlen($update['style_name'])) if (!strlen($update['style_name']))
{ {
trigger_error($user->lang['STYLE_ERR_STYLE_NAME'] . adm_back_link($update_action), E_USER_WARNING); trigger_error($this->user->lang['STYLE_ERR_STYLE_NAME'] . adm_back_link($update_action), E_USER_WARNING);
} }
foreach ($styles as $row) foreach ($styles as $row)
{ {
if ($row['style_name'] == $update['style_name']) if ($row['style_name'] == $update['style_name'])
{ {
trigger_error($user->lang['STYLE_ERR_NAME_EXIST'] . adm_back_link($update_action), E_USER_WARNING); trigger_error($this->user->lang['STYLE_ERR_NAME_EXIST'] . adm_back_link($update_action), E_USER_WARNING);
} }
} }
} }
@ -439,7 +445,7 @@ class acp_styles
} }
if (!$found) if (!$found)
{ {
trigger_error($user->lang['STYLE_ERR_INVALID_PARENT'] . adm_back_link($update_action), E_USER_WARNING); trigger_error($this->user->lang['STYLE_ERR_INVALID_PARENT'] . adm_back_link($update_action), E_USER_WARNING);
} }
} }
else else
@ -455,9 +461,9 @@ class acp_styles
// Check style_active // Check style_active
if ($update['style_active'] != $style['style_active']) if ($update['style_active'] != $style['style_active'])
{ {
if (!$update['style_active'] && $config['default_style'] == $style['style_id']) if (!$update['style_active'] && $this->default_style == $style['style_id'])
{ {
trigger_error($user->lang['DEACTIVATE_DEFAULT'] . adm_back_link($update_action), E_USER_WARNING); trigger_error($this->user->lang['DEACTIVATE_DEFAULT'] . adm_back_link($update_action), E_USER_WARNING);
} }
} }
else else
@ -469,9 +475,9 @@ class acp_styles
if (count($update)) if (count($update))
{ {
$sql = 'UPDATE ' . STYLES_TABLE . ' $sql = 'UPDATE ' . STYLES_TABLE . '
SET ' . $db->sql_build_array('UPDATE', $update) . " SET ' . $this->db->sql_build_array('UPDATE', $update) . "
WHERE style_id = $id"; WHERE style_id = $id";
$db->sql_query($sql); $this->db->sql_query($sql);
$style = array_merge($style, $update); $style = array_merge($style, $update);
@ -482,22 +488,22 @@ class acp_styles
if ($this->update_styles_tree(&$styles, $style)) if ($this->update_styles_tree(&$styles, $style))
{ {
// Something was changed in styles tree, purge all cache // Something was changed in styles tree, purge all cache
$cache->purge(); $this->cache->purge();
} }
} }
add_log('admin', 'LOG_STYLE_EDIT_DETAILS', $style['style_name']); add_log('admin', 'LOG_STYLE_EDIT_DETAILS', $style['style_name']);
} }
// Update default style // Update default style
$default = $request->variable('style_default', 0); $default = $this->request->variable('style_default', 0);
if ($default) if ($default)
{ {
if (!$style['style_active']) if (!$style['style_active'])
{ {
trigger_error($user->lang['STYLE_DEFAULT_CHANGE_INACTIVE'] . adm_back_link($update_action), E_USER_WARNING); trigger_error($this->user->lang['STYLE_DEFAULT_CHANGE_INACTIVE'] . adm_back_link($update_action), E_USER_WARNING);
} }
set_config('default_style', $id); set_config('default_style', $id);
$cache->purge(); $this->cache->purge();
} }
// Show styles list // Show styles list
@ -508,7 +514,7 @@ class acp_styles
// Show parent styles // Show parent styles
foreach ($list as $row) foreach ($list as $row)
{ {
$template->assign_block_vars('parent_styles', array( $this->template->assign_block_vars('parent_styles', array(
'STYLE_ID' => $row['style_id'], 'STYLE_ID' => $row['style_id'],
'STYLE_NAME' => htmlspecialchars($row['style_name']), 'STYLE_NAME' => htmlspecialchars($row['style_name']),
'LEVEL' => $row['level'], 'LEVEL' => $row['level'],
@ -518,7 +524,7 @@ class acp_styles
} }
// Show style details // Show style details
$template->assign_vars(array( $this->template->assign_vars(array(
'S_STYLE_DETAILS' => true, 'S_STYLE_DETAILS' => true,
'STYLE_ID' => $style['style_id'], 'STYLE_ID' => $style['style_id'],
'STYLE_NAME' => htmlspecialchars($style['style_name']), 'STYLE_NAME' => htmlspecialchars($style['style_name']),
@ -526,7 +532,7 @@ class acp_styles
'STYLE_COPYRIGHT' => strip_tags($style['style_copyright']), 'STYLE_COPYRIGHT' => strip_tags($style['style_copyright']),
'STYLE_PARENT' => $style['style_parent_id'], 'STYLE_PARENT' => $style['style_parent_id'],
'S_STYLE_ACTIVE' => $style['style_active'], 'S_STYLE_ACTIVE' => $style['style_active'],
'S_STYLE_DEFAULT' => ($style['style_id'] == $config['default_style']) 'S_STYLE_DEFAULT' => ($style['style_id'] == $this->default_style)
) )
); );
} }
@ -536,14 +542,12 @@ class acp_styles
*/ */
function show_installed() function show_installed()
{ {
global $user, $template;
// Get all installed styles // Get all installed styles
$styles = $this->get_styles(); $styles = $this->get_styles();
if (!count($styles)) if (!count($styles))
{ {
trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING);
} }
usort($styles, 'acp_styles::sort_styles'); usort($styles, 'acp_styles::sort_styles');
@ -560,7 +564,7 @@ class acp_styles
// Set up styles list variables // Set up styles list variables
// Addons should increase this number and update template variable // Addons should increase this number and update template variable
$this->styles_list_cols = 4; $this->styles_list_cols = 4;
$template->assign_var('STYLES_LIST_COLS', $this->styles_list_cols); $this->template->assign_var('STYLES_LIST_COLS', $this->styles_list_cols);
// Show styles list // Show styles list
$this->show_styles_list(&$styles, 0, 0); $this->show_styles_list(&$styles, 0, 0);
@ -570,29 +574,29 @@ class acp_styles
{ {
if (empty($style['_shown'])) if (empty($style['_shown']))
{ {
$style['_note'] = sprintf($user->lang['REQUIRES_STYLE'], htmlspecialchars($style['style_parent_tree'])); $style['_note'] = sprintf($this->user->lang['REQUIRES_STYLE'], htmlspecialchars($style['style_parent_tree']));
$this->list_style($style, 0); $this->list_style($style, 0);
} }
} }
// Add buttons // Add buttons
$template->assign_block_vars('extra_actions', array( $this->template->assign_block_vars('extra_actions', array(
'ACTION_NAME' => 'activate', 'ACTION_NAME' => 'activate',
'L_ACTION' => $user->lang['STYLE_ACTIVATE'], 'L_ACTION' => $this->user->lang['STYLE_ACTIVATE'],
) )
); );
$template->assign_block_vars('extra_actions', array( $this->template->assign_block_vars('extra_actions', array(
'ACTION_NAME' => 'deactivate', 'ACTION_NAME' => 'deactivate',
'L_ACTION' => $user->lang['STYLE_DEACTIVATE'], 'L_ACTION' => $this->user->lang['STYLE_DEACTIVATE'],
) )
); );
if (isset($this->style_counters) && $this->style_counters['total'] > 1) if (isset($this->style_counters) && $this->style_counters['total'] > 1)
{ {
$template->assign_block_vars('extra_actions', array( $this->template->assign_block_vars('extra_actions', array(
'ACTION_NAME' => 'uninstall', 'ACTION_NAME' => 'uninstall',
'L_ACTION' => $user->lang['STYLE_UNINSTALL'], 'L_ACTION' => $this->user->lang['STYLE_UNINSTALL'],
) )
); );
} }
@ -603,21 +607,19 @@ class acp_styles
*/ */
function show_available() function show_available()
{ {
global $user, $template;
// Get list of styles // Get list of styles
$styles = $this->find_available(true); $styles = $this->find_available(true);
// Show styles // Show styles
if (empty($styles)) if (empty($styles))
{ {
trigger_error($user->lang['NO_UNINSTALLED_STYLE'] . adm_back_link($this->u_base_action), E_USER_NOTICE); trigger_error($this->user->lang['NO_UNINSTALLED_STYLE'] . adm_back_link($this->u_base_action), E_USER_NOTICE);
} }
usort($styles, 'acp_styles::sort_styles'); usort($styles, 'acp_styles::sort_styles');
$this->styles_list_cols = 3; $this->styles_list_cols = 3;
$template->assign_vars(array( $this->template->assign_vars(array(
'STYLES_LIST_COLS' => $this->styles_list_cols, 'STYLES_LIST_COLS' => $this->styles_list_cols,
'STYLES_LIST_HIDE_COUNT' => true 'STYLES_LIST_HIDE_COUNT' => true
) )
@ -658,9 +660,9 @@ class acp_styles
// Add button // Add button
if (isset($this->style_counters) && $this->style_counters['caninstall'] > 0) if (isset($this->style_counters) && $this->style_counters['caninstall'] > 0)
{ {
$template->assign_block_vars('extra_actions', array( $this->template->assign_block_vars('extra_actions', array(
'ACTION_NAME' => 'install', 'ACTION_NAME' => 'install',
'L_ACTION' => $user->lang['INSTALL_STYLES'], 'L_ACTION' => $this->user->lang['INSTALL_STYLES'],
) )
); );
} }
@ -674,8 +676,6 @@ class acp_styles
*/ */
function find_available($all) function find_available($all)
{ {
global $user;
// Get list of installed styles // Get list of installed styles
$installed = $this->get_styles(); $installed = $this->get_styles();
@ -743,7 +743,7 @@ class acp_styles
{ {
// Parent style is not installed yet // Parent style is not installed yet
$style['_available'] = false; $style['_available'] = false;
$style['_note'] = sprintf($user->lang['REQUIRES_STYLE'], htmlspecialchars($parent)); $style['_note'] = sprintf($this->user->lang['REQUIRES_STYLE'], htmlspecialchars($parent));
} }
} }
@ -821,11 +821,10 @@ class acp_styles
} }
if ($update) if ($update)
{ {
global $db;
$sql = 'UPDATE ' . STYLES_TABLE . " $sql = 'UPDATE ' . STYLES_TABLE . "
SET style_parent_tree = '" . $db->sql_escape($parent_tree) . "' SET style_parent_tree = '" . $this->db->sql_escape($parent_tree) . "'
WHERE style_parent_id = {$parent_id}"; WHERE style_parent_id = {$parent_id}";
$db->sql_query($sql); $this->db->sql_query($sql);
$updated = true; $updated = true;
} }
return $updated; return $updated;
@ -869,8 +868,6 @@ class acp_styles
*/ */
function list_style($style, $level) function list_style($style, $level)
{ {
global $template, $config, $db, $user, $phpbb_root_path, $phpEx;
// Mark row as shown // Mark row as shown
if (!empty($style['_shown'])) return; if (!empty($style['_shown'])) return;
$style['_shown'] = true; $style['_shown'] = true;
@ -886,7 +883,7 @@ class acp_styles
'STYLE_ACTIVE' => $style['style_active'], 'STYLE_ACTIVE' => $style['style_active'],
// Additional data // Additional data
'DEFAULT' => ($style['style_id'] && $style['style_id'] == $config['default_style']), 'DEFAULT' => ($style['style_id'] && $style['style_id'] == $this->default_style),
'USERS' => (isset($style['_users'])) ? $style['_users'] : '', 'USERS' => (isset($style['_users'])) ? $style['_users'] : '',
'LEVEL' => $level, 'LEVEL' => $level,
'PADDING' => (4 + 16 * $level), 'PADDING' => (4 + 16 * $level),
@ -909,31 +906,31 @@ class acp_styles
// Details // Details
$actions[] = array( $actions[] = array(
'U_ACTION' => $this->u_action . '&amp;action=details&amp;id=' . $style['style_id'], 'U_ACTION' => $this->u_action . '&amp;action=details&amp;id=' . $style['style_id'],
'L_ACTION' => $user->lang['DETAILS'] 'L_ACTION' => $this->user->lang['DETAILS']
); );
// Activate // Activate
$actions[] = array( $actions[] = array(
'U_ACTION' => $this->u_action . '&amp;action=' . ($style['style_active'] ? 'de' : '') . 'activate&amp;id=' . $style['style_id'], 'U_ACTION' => $this->u_action . '&amp;action=' . ($style['style_active'] ? 'de' : '') . 'activate&amp;id=' . $style['style_id'],
'L_ACTION' => $user->lang['STYLE_' . ($style['style_active'] ? 'DE' : '') . 'ACTIVATE'] 'L_ACTION' => $this->user->lang['STYLE_' . ($style['style_active'] ? 'DE' : '') . 'ACTIVATE']
); );
/* // Export /* // Export
$actions[] = array( $actions[] = array(
'U_ACTION' => $this->u_action . '&amp;action=export&amp;id=' . $style['style_id'], 'U_ACTION' => $this->u_action . '&amp;action=export&amp;id=' . $style['style_id'],
'L_ACTION' => $user->lang['EXPORT'] 'L_ACTION' => $this->user->lang['EXPORT']
); */ ); */
// Uninstall // Uninstall
$actions[] = array( $actions[] = array(
'U_ACTION' => $this->u_action . '&amp;action=uninstall&amp;id=' . $style['style_id'], 'U_ACTION' => $this->u_action . '&amp;action=uninstall&amp;id=' . $style['style_id'],
'L_ACTION' => $user->lang['STYLE_UNINSTALL'] 'L_ACTION' => $this->user->lang['STYLE_UNINSTALL']
); );
// Preview // Preview
$actions[] = array( $actions[] = array(
'U_ACTION' => append_sid("{$phpbb_root_path}index.$phpEx", 'style=' . $style['style_id']), 'U_ACTION' => append_sid($this->phpbb_root_path . 'index.' . $this->phpEx, 'style=' . $style['style_id']),
'L_ACTION' => $user->lang['PREVIEW'] 'L_ACTION' => $this->user->lang['PREVIEW']
); );
} }
else else
@ -942,14 +939,14 @@ class acp_styles
if (empty($style['_available'])) if (empty($style['_available']))
{ {
$actions[] = array( $actions[] = array(
'HTML' => $user->lang['CANNOT_BE_INSTALLED'] 'HTML' => $this->user->lang['CANNOT_BE_INSTALLED']
); );
} }
else else
{ {
$actions[] = array( $actions[] = array(
'U_ACTION' => $this->u_action . '&amp;action=install&amp;dir=' . urlencode($style['style_path']), 'U_ACTION' => $this->u_action . '&amp;action=install&amp;dir=' . urlencode($style['style_path']),
'L_ACTION' => $user->lang['INSTALL_STYLE'] 'L_ACTION' => $this->user->lang['INSTALL_STYLE']
); );
} }
} }
@ -957,10 +954,10 @@ class acp_styles
// todo: add hook // todo: add hook
// Assign template variables // Assign template variables
$template->assign_block_vars('styles_list', $row); $this->template->assign_block_vars('styles_list', $row);
foreach($actions as $action) foreach($actions as $action)
{ {
$template->assign_block_vars('styles_list.actions', $action); $this->template->assign_block_vars('styles_list.actions', $action);
} }
// Increase counters // Increase counters
@ -987,10 +984,9 @@ class acp_styles
*/ */
function welcome_message($title, $description) function welcome_message($title, $description)
{ {
global $user, $template; $this->template->assign_vars(array(
$template->assign_vars(array( 'L_TITLE' => (isset($this->user->lang[$title])) ? $this->user->lang[$title] : $title,
'L_TITLE' => (isset($user->lang[$title])) ? $user->lang[$title] : $title, 'L_EXPLAIN' => (isset($this->user->lang[$description])) ? $this->user->lang[$description] : $description
'L_EXPLAIN' => (isset($user->lang[$description])) ? $user->lang[$description] : $description
) )
); );
} }
@ -1084,8 +1080,6 @@ class acp_styles
*/ */
function install_style($style) function install_style($style)
{ {
global $db;
// Generate row // Generate row
$sql_ary = array(); $sql_ary = array();
foreach ($style as $key => $value) foreach ($style as $key => $value)
@ -1097,15 +1091,15 @@ class acp_styles
} }
// Add to database // Add to database
$db->sql_transaction('begin'); $this->db->sql_transaction('begin');
$sql = 'INSERT INTO ' . STYLES_TABLE . ' $sql = 'INSERT INTO ' . STYLES_TABLE . '
' . $db->sql_build_array('INSERT', $sql_ary); ' . $this->db->sql_build_array('INSERT', $sql_ary);
$db->sql_query($sql); $this->db->sql_query($sql);
$id = $db->sql_nextid(); $id = $this->db->sql_nextid();
$db->sql_transaction('commit'); $this->db->sql_transaction('commit');
add_log('admin', 'LOG_STYLE_ADD', $sql_ary['style_name']); add_log('admin', 'LOG_STYLE_ADD', $sql_ary['style_name']);
@ -1119,14 +1113,12 @@ class acp_styles
*/ */
function get_styles() function get_styles()
{ {
global $db;
$sql = 'SELECT * $sql = 'SELECT *
FROM ' . STYLES_TABLE; FROM ' . STYLES_TABLE;
$result = $db->sql_query($sql); $result = $this->db->sql_query($sql);
$rows = $db->sql_fetchrowset($result); $rows = $this->db->sql_fetchrowset($result);
$db->sql_freeresult($result); $this->db->sql_freeresult($result);
return $rows; return $rows;
} }
@ -1138,19 +1130,17 @@ class acp_styles
*/ */
function get_users() function get_users()
{ {
global $db;
$sql = 'SELECT user_style, COUNT(user_style) AS style_count $sql = 'SELECT user_style, COUNT(user_style) AS style_count
FROM ' . USERS_TABLE . ' FROM ' . USERS_TABLE . '
GROUP BY user_style'; GROUP BY user_style';
$result = $db->sql_query($sql); $result = $this->db->sql_query($sql);
$style_count = array(); $style_count = array();
while ($row = $db->sql_fetchrow($result)) while ($row = $this->db->sql_fetchrow($result))
{ {
$style_count[$row['user_style']] = $row['style_count']; $style_count[$row['user_style']] = $row['style_count'];
} }
$db->sql_freeresult($result); $this->db->sql_freeresult($result);
return $style_count; return $style_count;
} }
@ -1163,35 +1153,33 @@ class acp_styles
*/ */
function uninstall_style($style) function uninstall_style($style)
{ {
global $db, $user;
$id = $style['style_id']; $id = $style['style_id'];
$path = $style['style_path']; $path = $style['style_path'];
// Check if style has child styles // Check if style has child styles
$sql = 'SELECT style_id $sql = 'SELECT style_id
FROM ' . STYLES_TABLE . ' FROM ' . STYLES_TABLE . '
WHERE style_parent_id = ' . $id . " OR style_parent_tree = '" . $db->sql_escape($path) . "'"; WHERE style_parent_id = ' . $id . " OR style_parent_tree = '" . $this->db->sql_escape($path) . "'";
$result = $db->sql_query($sql); $result = $this->db->sql_query($sql);
$conflict = $db->sql_fetchrow($result); $conflict = $this->db->sql_fetchrow($result);
$db->sql_freeresult($result); $this->db->sql_freeresult($result);
if ($conflict !== false) if ($conflict !== false)
{ {
return sprintf($user->lang['STYLE_UNINSTALL_DEPENDENT'], $style['style_name']); return sprintf($this->user->lang['STYLE_UNINSTALL_DEPENDENT'], $style['style_name']);
} }
// Change default style for users // Change default style for users
$sql = 'UPDATE ' . USERS_TABLE . ' $sql = 'UPDATE ' . USERS_TABLE . '
SET user_style = 0 SET user_style = 0
WHERE user_style = ' . $id; WHERE user_style = ' . $id;
$db->sql_query($sql); $this->db->sql_query($sql);
// Uninstall style // Uninstall style
$sql = 'DELETE FROM ' . STYLES_TABLE . ' $sql = 'DELETE FROM ' . STYLES_TABLE . '
WHERE style_id = ' . $id; WHERE style_id = ' . $id;
$db->sql_query($sql); $this->db->sql_query($sql);
return true; return true;
} }
@ -1253,10 +1241,8 @@ class acp_styles
*/ */
function request_vars($name, $default, $error = false) function request_vars($name, $default, $error = false)
{ {
global $request, $user; $item = $this->request->variable($name, $default);
$items = $this->request->variable($name . 's', array($default));
$item = $request->variable($name, $default);
$items = $request->variable($name . 's', array($default));
if (count($items) == 1 && $items[0] == $default) if (count($items) == 1 && $items[0] == $default)
{ {
@ -1270,7 +1256,7 @@ class acp_styles
if ($error && !count($items)) if ($error && !count($items))
{ {
trigger_error($user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); trigger_error($this->user->lang['NO_MATCHING_STYLES_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING);
} }
return $items; return $items;