diff --git a/phpBB/adm/admin_styles.php b/phpBB/adm/admin_styles.php index c18540edc4..e7f707a5fc 100644 --- a/phpBB/adm/admin_styles.php +++ b/phpBB/adm/admin_styles.php @@ -77,21 +77,335 @@ switch ($mode) break; case 'export': + if ($style_id) + { + $sql = 'SELECT s.style_id, s.style_name, s.style_copyright, t.template_id, t.template_name, t.template_path, t.template_copyright, c.theme_id, c.theme_name, c.theme_path, c.theme_copyright, c.css_storedb, c.css_data, i.* + FROM ' . STYLES_TABLE . ' s, ' . STYLES_TPL_TABLE . ' t, ' . STYLES_CSS_TABLE . ' c, ' . STYLES_IMAGE_TABLE . " i + WHERE s.style_id = $style_id + AND t.template_id = s.template_id + AND c.theme_id = s.theme_id + AND i.imageset_id = s.imageset_id"; + $result = $db->sql_query($sql); + + if (!($row = ($db->sql_fetchrow($result)))) + { + trigger_error($user->lang['NO_STYLE']); + } + $db->sql_freeresult($result); + + $var_ary = array('style_id', 'style_name', 'style_copyright', 'template_id', 'template_name', 'template_path', 'template_copyright', 'theme_id', 'theme_name', 'theme_path', 'theme_copyright', 'css_storedb', 'css_data', 'imageset_id', 'imageset_name', 'imageset_path', 'imageset_copyright'); + foreach ($var_ary as $var) + { + $$var = (!empty($row[$var])) ? $row[$var] : ''; + unset($row[$var]); + } + + $style_cfg = addslashes($style_name) . "\n"; + $style_cfg .= addslashes($style_copyright) . "\n"; + $style_cfg .= addslashes($config['version']) . "\n"; + + $template_cfg = addslashes($template_name) . "\n"; + $template_cfg .= addslashes($template_copyright) . "\n"; + $template_cfg .= addslashes($config['version']) . "\n"; + + $theme_cfg = addslashes($theme_name) . "\n"; + $theme_cfg .= addslashes($theme_copyright) . "\n"; + $theme_cfg .= addslashes($config['version']) . "\n"; + + $imageset_cfg = addslashes($imageset_name) . "\n"; + $imageset_cfg .= addslashes($imageset_copyright) . "\n"; + $imageset_cfg .= addslashes($config['version']) . "\n"; + + foreach (array_keys($row) as $key) + { + $imageset_cfg.= $key . '||' . str_replace("styles/$imageset_path/imageset/", '{PATH}', $row[$key]) . "\n"; + unset($row[$key]); + } + + $files = array( + array( + 'src' => "styles/$template_path/template/", + 'prefix-' => "styles/$template_path/", + 'prefix+' => false, + 'exclude' => 'template.cfg'), + array( + 'src' => "styles/$theme_path/theme/", + 'prefix-' => "styles/$theme_path/", + 'prefix+' => false, + 'exclude' => ($css_storedb) ? 'stylesheet.cfg,theme.cfg' : 'theme.cfg' + ), + array( + 'src' => "styles/$imageset_path/imageset/", + 'prefix-' => "styles/$imageset_path/", + 'prefix+' => false, + 'exclude' => 'imageset.cfg' + ), + ); + + $data = array( + array( + 'src' => trim($style_cfg), + 'prefix' => 'style.cfg' + ), + array( + 'src' => trim($theme_cfg), + 'prefix' => 'theme/theme.cfg' + ), + array( + 'src' => trim($template_cfg), + 'prefix' => 'template/template.cfg' + ), + array( + 'src' => trim($imageset_cfg), + 'prefix' => 'imageset/imageset.cfg' + ), + ); + + if ($css_storedb) + { + $data += array( + array( + 'src' => $css_data, + 'prefix' => 'theme/stylesheet.css' + ), + ); + } + + unset($css_data); + unset($style_cfg); + unset($theme_cfg); + unset($template_cfg); + unset($imageset_cfg); + + export('style', $style_id, $style_name, str_replace(' ', '_', $style_name), $files, $data); + } break; case 'add': case 'edit': + case 'install': if (isset($_POST['update'])) { - $style_name = (isset($_POST['style_name'])) ? stripslashes(htmlspecialchars($_POST['style_name'])) : ''; - $style_copyright = (isset($_POST['style_copyright'])) ? stripslashes(htmlspecialchars($_POST['style_copyright'])) : ''; + if ($action == 'install') + { + $style_path = htmlspecialchars($_POST['style_path']); + if (!($cfg = file("{$phpbb_root_path}styles/$style_path/style.cfg"))) + { + trigger_error($user->lang['NO_STYLE']); + } + + $style_name = trim($cfg[0]); + $style_copyright = trim($cfg[1]); + + // Imageset + if (!($cfg = file("{$phpbb_root_path}styles/$style_path/imageset/imageset.cfg"))) + { + trigger_error($user->lang['NO_IMAGESET']); + } + $imageset_name = trim($cfg[0]); + $imageset_copyright = trim($cfg[1]); + + $sql = 'SELECT imageset_id, imageset_name + FROM ' . STYLES_IMAGE_TABLE . " + WHERE imageset_name = '" . $db->sql_escape($imageset_name) . "'"; + $result = $db->sql_query($sql); + + // If an entry already exists we need not install this one + if (!($row = $db->sql_fetchrow($result))) + { + if (empty($imageset_name)) + { + $error[] = $user->lang['IMAGESET_ERR_STYLE_NAME']; + } + + if (strlen($imageset_name) > 30) + { + $error[] = $user->lang['IMAGESET_ERR_NAME_LONG']; + } + + if (!preg_match('#^[a-z0-9_\-\+\. ]+$#i', $imageset_name)) + { + $error[] = $user->lang['IMAGESET_ERR_NAME_CHARS']; + } + + if (strlen($imageset_copyright) > 60) + { + $error[] = $user->lang['IMAGESET_ERR_COPY_LONG']; + } + + if (!sizeof($error)) + { + $sql_img_ary = array(); + + for ($i = 3; $i < sizeof($cfg); $i++) + { + $tmp = explode('||', $cfg[$i]); + $sql_img_ary[$tmp[0]] = str_replace('{PATH}', "styles/$style_path/imageset/", trim($tmp[1])); + } + + $sql_ary = array( + 'imageset_name' => $imageset_name, + 'imageset_copyright' => $imageset_copyright, + 'imageset_path' => str_replace(' ', '_', $style_path), + ); + $sql_ary += $sql_img_ary; + + $sql = 'INSERT INTO ' . STYLES_IMAGE_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + $imageset_id = $db->sql_nextid(); + + add_log('admin', 'LOG_ADD_IMAGESET', $imageset_name); + } + } + else + { + $imageset_id = $row['imageset_id']; + } + $db->sql_freeresult($result); + unset($cfg); + + // Theme + if (!($cfg = file("{$phpbb_root_path}styles/$style_path/theme/theme.cfg"))) + { + trigger_error($user->lang['NO_THEME']); + } + $theme_name = trim($cfg[0]); + $theme_copyright = trim($cfg[1]); + + $sql = 'SELECT theme_id, theme_name + FROM ' . STYLES_CSS_TABLE . " + WHERE theme_name = '" . $db->sql_escape($theme_name) . "'"; + $result = $db->sql_query($sql); + + // If an entry already exists we need not install this one + if (!($row = $db->sql_fetchrow($result))) + { + if (empty($theme_name)) + { + $error[] = $user->lang['THEME_ERR_STYLE_NAME']; + } + + if (strlen($theme_name) > 30) + { + $error[] = $user->lang['THEME_ERR_NAME_LONG']; + } + + if (!preg_match('#^[a-z0-9_\-\+\. ]+$#i', $theme_name)) + { + $error[] = $user->lang['THEME_ERR_NAME_CHARS']; + } + + if (strlen($theme_copyright) > 60) + { + $error[] = $user->lang['THEME_ERR_COPY_LONG']; + } + + if (!sizeof($error)) + { + $css_storedb = 0; + $css_data = ''; + if (!is_writeable("{$phpbb_root_path}styles/$style_path/theme/stylesheet.css")) + { + $css_data = implode('', file("{$phpbb_root_path}styles/$style_path/theme/stylesheet.css")); + $css_storedb = 1; + } + + $sql_ary = array( + 'theme_name' => $theme_name, + 'theme_copyright' => $theme_copyright, + 'theme_path' => str_replace(' ', '_', $style_path), + 'css_storedb' => $css_storedb, + 'css_data' => $css_data, + ); + + $sql = 'INSERT INTO ' . STYLES_CSS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + $theme_id = $db->sql_nextid(); + + $log = ($css_storedb) ? 'LOG_ADD_THEME_DB' : 'LOG_ADD_THEME_FS'; + add_log('admin', $log, $theme_name); + } + } + else + { + $theme_id = $row['theme_id']; + } + $db->sql_freeresult($result); + unset($cfg); + + + // Template + if (!($cfg = file("{$phpbb_root_path}styles/$style_path/template/template.cfg"))) + { + trigger_error($user->lang['NO_TEMPLATE']); + } + $template_name = trim($cfg[0]); + $template_copyright = trim($cfg[1]); + + $sql = 'SELECT template_id, template_name + FROM ' . STYLES_TPL_TABLE . " + WHERE template_name = '" . $db->sql_escape($template_name) . "'"; + $result = $db->sql_query($sql); + + // If an entry already exists we need not install this one + if (!($row = $db->sql_fetchrow($result))) + { + if (empty($template_name)) + { + $error[] = $user->lang['TPL_ERR_STYLE_NAME']; + } + + if (strlen($template_name) > 30) + { + $error[] = $user->lang['TPL_ERR_NAME_LONG']; + } + + if (!preg_match('#^[a-z0-9_\-\+\. ]+$#i', $template_name)) + { + $error[] = $user->lang['TPL_ERR_NAME_CHARS']; + } + + if (strlen($template_copyright) > 60) + { + $error[] = $user->lang['TPL_ERR_COPY_LONG']; + } + + if (!sizeof($error)) + { + $sql_ary = array( + 'template_name' => $template_name, + 'template_copyright' => $template_copyright, + 'template_path' => str_replace(' ', '_', $style_path), + ); + + $sql = 'INSERT INTO ' . STYLES_TPL_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + $template_id = $db->sql_nextid(); + + $log = 'LOG_ADD_TPL_FS'; + add_log('admin', $log, $template_name); + } + } + else + { + $template_id = $row['template_id']; + } + $db->sql_freeresult($result); + unset($cfg); + } + else + { + $style_name = (isset($_POST['style_name'])) ? stripslashes(htmlspecialchars($_POST['style_name'])) : ''; + $style_copyright = (isset($_POST['style_copyright'])) ? stripslashes(htmlspecialchars($_POST['style_copyright'])) : ''; + + $template_id = (!empty($_POST['template_id'])) ? intval($_POST['template_id']) : 0; + $theme_id = (!empty($_POST['theme_id'])) ? intval($_POST['theme_id']) : 0; + $imageset_id = (!empty($_POST['imageset_id'])) ? intval($_POST['imageset_id']) : 0; + } $style_active = (!empty($_POST['style_active'])) ? 1 : 0; - - $template_id = (!empty($_POST['template_id'])) ? intval($_POST['template_id']) : 0; - $theme_id = (!empty($_POST['theme_id'])) ? intval($_POST['theme_id']) : 0; - $imageset_id = (!empty($_POST['imageset_id'])) ? intval($_POST['imageset_id']) : 0; + $style_default = (!empty($_POST['default_style'])) ? 1 : 0; if (empty($style_name)) { @@ -118,7 +432,7 @@ switch ($mode) $error[] = $user->lang['STYLE_ERR_NO_IDS']; } - $sql_where = ($action == 'add') ? "WHERE style_name = '" . $db->sql_escape($style_name) . "'" : "WHERE style_id <> $style_id AND style_name = '" . $db->sql_escape($style_name) . "'"; + $sql_where = ($action == 'add' || $action == 'install') ? "WHERE style_name = '" . $db->sql_escape($style_name) . "'" : "WHERE style_id <> $style_id AND style_name = '" . $db->sql_escape($style_name) . "'"; $sql = 'SELECT style_name FROM ' . STYLES_TABLE . " $sql_where"; @@ -140,13 +454,23 @@ switch ($mode) 'imageset_id' => $imageset_id, ); - $sql = ($action == 'add') ? 'INSERT INTO ' . STYLES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary) : 'UPDATE ' . STYLES_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE style_id = $style_id"; + $sql = ($action == 'add' || $action == 'install') ? 'INSERT INTO ' . STYLES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary) : 'UPDATE ' . STYLES_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE style_id = $style_id"; $db->sql_query($sql); - $log = ($action == 'add') ? 'LOG_ADD_STYLE' : 'LOG_EDIT_STYLE'; - add_log('admin', $log, addslashes($style_name)); + if ($action == 'add' || $action == 'install') + { + $style_id = $db->sql_nextid(); + } - $message = ($action == 'add') ? 'STYLED_ADDED' : 'STYLE_EDITED'; + if ($style_default) + { + set_config('default_style', $style_id); + } + + $log = ($action == 'add' || $action == 'install') ? 'LOG_ADD_STYLE' : 'LOG_EDIT_STYLE'; + add_log('admin', $log, $style_name); + + $message = ($action == 'add' || $action == 'install') ? 'STYLED_ADDED' : 'STYLE_EDITED'; trigger_error($user->lang[$message]); } } @@ -162,41 +486,96 @@ switch ($mode) if (!extract($db->sql_fetchrow($result))) { - die("ERROR"); + trigger_error($user->lang['NO_STYLE']); } $db->sql_freeresult($result); + + $style_default = ($config['default_style'] == $style_id) ? 1 : 0; } else { - $style_name = (isset($_POST['style_name'])) ? stripslashes(htmlspecialchars($_POST['style_name'])) : ''; - $style_copyright = ''; - $style_active = 1; - $template_id = $theme_id = $imageset_id = 0; + if ($action == 'install' && !empty($_GET['name'])) + { + $style_path = htmlspecialchars($_GET['name']); + if (!file_exists("{$phpbb_root_path}styles/$style_path/style.cfg")) + { + trigger_error($user->lang['NO_STYLE']); + } + + if (!($cfg = file("{$phpbb_root_path}styles/$style_path/style.cfg"))) + { + trigger_error($user->lang['NO_STYLE']); + } + + $style_version = preg_replace('#^2\.([0-9]+?)\.([0-9]+?).*?$#', '\1.\2', trim($cfg[2])); + $phpbbversion = preg_replace('#^2\.([0-9]+?)\.([0-9]+?).*?$#', '\1.\2', $config['version']); + + if ($style_version != $phpbbversion) + { + $error[] = $user->lang['STYLE_VERSION_DIFF']; + } + + $style_name = trim($cfg[0]); + $style_copyright = trim($cfg[1]); + + if (!($cfg = file("{$phpbb_root_path}styles/$style_path/imageset/imageset.cfg"))) + { + trigger_error($user->lang['NO_IMAGESET']); + } + $imageset_name = trim($cfg[0]); + unset($cfg); + + if (!($cfg = file("{$phpbb_root_path}styles/$style_path/theme/theme.cfg"))) + { + trigger_error($user->lang['NO_THEME']); + } + $theme_name = trim($cfg[0]); + unset($cfg); + + if (!($cfg = file("{$phpbb_root_path}styles/$style_path/template/template.cfg"))) + { + trigger_error($user->lang['NO_TEMPLATE']); + } + $template_name = trim($cfg[0]); + unset($cfg); + + $style_active = 1; + $s_hidden_fields = ''; + } + else + { + $style_name = (isset($_POST['style_name'])) ? stripslashes(htmlspecialchars($_POST['style_name'])) : ''; + $style_copyright = ''; + $style_active = 1; + $template_id = $theme_id = $imageset_id = $style_default = 0; + } } } - $style_options = array(); - $field_ary = array(STYLES_CSS_TABLE => 'theme', STYLES_TPL_TABLE => 'template', STYLES_IMAGE_TABLE => 'imageset'); - foreach ($field_ary as $table => $field) + if ($action != 'install') { - $sql = "SELECT {$field}_id, {$field}_name - FROM $table - ORDER BY {$field}_id"; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) + $style_options = array(); + $field_ary = array(STYLES_CSS_TABLE => 'theme', STYLES_TPL_TABLE => 'template', STYLES_IMAGE_TABLE => 'imageset'); + foreach ($field_ary as $table => $field) { - $selected = ($row[$field . '_id'] == ${$field . '_id'}) ? ' selected="selected"' : ''; - ${$field . '_options'} .= ''; - } - $db->sql_freeresult($result); - } + $sql = "SELECT {$field}_id, {$field}_name + FROM $table + ORDER BY {$field}_id"; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $selected = ($row[$field . '_id'] == ${$field . '_id'}) ? ' selected="selected"' : ''; + ${$field . '_options'} .= ''; + } + $db->sql_freeresult($result); + } + } $active_yes = ($style_active) ? ' checked="checked"' : ''; $active_no = (!$style_active) ? ' checked="checked"' : ''; - $default_style_yes = ($style_id == $config['default_style']) ? ' checked="checked"' : ''; - $default_style_no = ($style_id != $config['default_style']) ? ' checked="checked"' : ''; + $style_default_yes = ($style_default) ? ' checked="checked"' : ''; + $style_default_no = (!$style_default) ? ' checked="checked"' : ''; // Output the page @@ -234,32 +613,55 @@ switch ($mode)
lang['MANAGE_IMAGESET_EXPLAIN']; ?>
- - - "styles/templates/$template_path/", 'prefix' => "styles/templates/$template_path/", 'exclude' => 'tpl.cfg')); - $data = array(array('src' => trim($cfg), 'prefix' => 'tpl.cfg')); + $files = array(array('src' => "styles/$template_path/template/", 'prefix-' => "styles/$template_path/", 'prefix+' => false, 'exclude' => 'template.cfg')); + $data = array(array('src' => trim($cfg), 'prefix' => 'template/template.cfg')); } export('template', $template_id, $template_name, $template_path, $files, $data); @@ -992,7 +1346,6 @@ switch ($mode) break; case 'cache': - $sql = 'SELECT * FROM ' . STYLES_TPL_TABLE . " WHERE template_id = $template_id"; @@ -1004,16 +1357,14 @@ switch ($mode) } $db->sql_freeresult($result); - $cache_prefix = 'tpl_' . $template_path; - // User wants to delete one or more files ... if ($_POST['update'] && !empty($_POST['delete'])) { foreach ($_POST['delete'] as $file) { - $file = $phpbb_root_path . 'cache/' . $cache_prefix . '_' . $file . '.html.' . $phpEx; + $file = "{$phpbb_root_path}cache/{$cache_prefix}_$file.html.$phpEx"; if (file_exists($file) && is_file($file)) { @unlink($file); @@ -1168,7 +1519,7 @@ function viewsource(url)lang['MANAGE_TEMPLATE_EXPLAIN']; ?>
- - - - $class_ary) { - $class_options .= ''; + $class_options .= ''; foreach ($class_ary as $class_name) { $selected = ($class_name == $class) ? ' selected="selected"' : ''; - $class_options .= ''; + $class_options .= ''; } } @@ -2305,141 +2596,23 @@ function csspreview() if ($css_storedb) { - $files = array(array('src' => "styles/themes/$theme_path/", 'prefix' => "styles/themes/$theme_path/", 'exclude' => "$theme_path.css,theme.cfg")); - $data = array(array('src' => $css_data, 'prefix' => "$theme_path.css"), array('src' => trim($cfg), 'prefix' => "theme.cfg")); + $files = array(array('src' => "styles/$theme_path/theme/", 'prefix-' => "styles/$theme_path/", 'prefix+' => false, 'exclude' => "$theme_path.css,theme.cfg")); + $data = array(array('src' => $css_data, 'prefix' => "theme/$theme_path.css"), array('src' => trim($cfg), 'prefix' => "theme/theme.cfg")); } else { - $files = array(array('src' => "styles/themes/$theme_path/", 'prefix' => "styles/themes/$theme_path/", 'exclude' => "theme.cfg")); - $data = array(array('src' => trim($cfg), 'prefix' => "theme.cfg")); + $files = array(array('src' => "styles/$theme_path/theme/", 'prefix-' => "styles/$theme_path/", 'prefix+' => false, 'exclude' => "theme.cfg")); + $data = array(array('src' => trim($cfg), 'prefix' => "theme/theme.cfg")); } unset($css_data); export('theme', $theme_id, $theme_name, $theme_path, $files, $data); } - break; } - - // Output list of themes - adm_page_header($user->lang['THEMES']); - -?> -lang['THEMES_EXPLAIN']; ?>
- - - -lang[$l_prefix . 'S']); + +?> +lang[$l_prefix . 'S_EXPLAIN']; ?>
+ + + +" . $sql = "DELETE FROM $table + $sql = "DELETE FROM $table WHERE {$type}_id = $id"; -// $db->sql_query($sql); + $db->sql_query($sql); - echo "