function installStyle($styleName)
{
global $config, $db, $user, $auth, $template, $cache;
global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
if (preg_match('/([^a-z0-9_]+)/iS',$styleName))
throw new Exception('Style name is not valid',1001);
$res = $db->sql_query(
"SELECT * FROM
{$table_prefix}styles WHERE style_name = '{$styleName}'"
);
$styles = new acp_styles();
if ($db->sql_affectedrows()) {
$row = $db->sql_fetchrow();
$db->sql_query(
"UPDATE {$table_prefix}styles SET style_active = 0"
);
$db->sql_query(
"UPDATE
{$table_prefix}styles
SET
style_name = '{$styleName}',
style_active = 1
WHERE
style_id = {$row['style_id']}"
);
$db->sql_query(
"UPDATE {$table_prefix}users SET user_style = " . $row['style_id']
);
set_config('default_style', $row['style_id']);
} else {
// getting instalation config
$installcfg =
parse_cfg_file(
$phpbb_root_path
. 'styles'
. DIRECTORY_SEPARATOR . $styleName
. DIRECTORY_SEPARATOR . 'style.cfg'
);
// prepare data to install
$error = array();
$action = 'install';
$root_path = $phpbb_root_path . 'styles/' . $styleName . '/';
$id = 0;
$name = $styleName;
$path = $styleName;
$copyright = $installcfg['copyright'];
$active = 1;
$default = 1;
$style_row = array();
if (!is_dir($root_path))
throw new Exception('Directory not found',1002);
$element_ary = array(
'template' => STYLES_TEMPLATE_TABLE,
'theme' => STYLES_THEME_TABLE,
'imageset' => STYLES_IMAGESET_TABLE
);
$style_row = array(
'style_id' => 0,
'style_name' => $installcfg['name'],
'style_copyright' => $installcfg['copyright']
);
$reqd_template =
(isset($installcfg['required_template']))
? $installcfg['required_template']
: false;
$reqd_theme =
(isset($installcfg['required_theme']))
? $installcfg['required_theme']
: false;
$reqd_imageset =
(isset($installcfg['required_imageset']))
? $installcfg['required_imageset']
: false;
// Getting related info
foreach ($element_ary as $element => $table)
{
$style_row =
array_merge(
$style_row,
array(
$element . '_id' => 0,
$element . '_name' => '',
$element . '_copyright' => ''
)
);
$styles->test_installed(
$element,
$error,
(${'reqd_' . $element})
? $phpbb_root_path . 'styles/' . $reqd_template .'/'
: $root_path, ${'reqd_' . $element},
$style_row[$element . '_id'],
$style_row[$element . '_name'],
$style_row[$element . '_copyright']
);
if (!$style_row[$element . '_name'])
$style_row[$element . '_name'] = $reqd_template;
}
// Install
$styles->install_style(
$error,
$action,
$root_path,
$id,
$name,
$path,
$copyright,
$active,
$default,
$style_row
);
}
}