diff --git a/phpBB/adm/admin_styles.php b/phpBB/adm/admin_styles.php index a7ec9fe265..a3955b7192 100644 --- a/phpBB/adm/admin_styles.php +++ b/phpBB/adm/admin_styles.php @@ -13,9 +13,8 @@ // TODO // BBCode support -> M-3 +// Previews of templates, imagesets, themes ... unified -> M-3 // Add custom theme classes -// Allow import/upload/install of styles with partial style elements -// Previews of templates, imagesets, themes ... unified // Security review if (!empty($setmodules)) @@ -69,12 +68,12 @@ else } // Set some basic vars -$error = array(); +$error = $cfg = $stylecfg = array(); +$archive_types = $archive_preg = $tmp_path = ''; $safe_mode = (@ini_get('safe_mode') && @strtolower(ini_get('safe_mode')) == 'on') ? true : false; // Generate list of archive types inc. regexp | match -$archive_types = $archive_preg = ''; foreach (array('zip' => 'zlib', 'tar' => '', 'tar.gz' => 'zlib', 'tar.bz2' => 'bz2') as $type => $module) { if ($module && !@extension_loaded($module)) @@ -115,6 +114,82 @@ switch ($mode) break; case 'delete': + if ($style_id) + { + $new_style_id = (!empty($_POST['newid'])) ? intval($_POST['newid']) : false; + + $sql = 'SELECT style_name + FROM ' . STYLES_TABLE . " + WHERE style_id = $style_id"; + $result = $db->sql_query($sql); + + if (!extract($db->sql_fetchrow($result))) + { + trigger_error($user->lang['NO_STYLE']); + } + + // Get list of other styles + $sql = 'SELECT style_id, style_name + FROM ' . STYLES_TABLE . " + WHERE style_id <> $style_id + ORDER BY style_id"; + $result = $db->sql_query($sql); + + $options = ''; + if (!($row = $db->sql_fetchrow($result))) + { + trigger_error($user->lang['ONLY_STYLE']); + } + + do + { + $options .= ''; + } + while ($row = $db->sql_fetchrow($result)); + + if ($update && $new_style_id) + { + $sql = 'DELETE FROM ' . STYLES_TABLE . " + WHERE style_id = $style_id"; + $db->sql_query($sql); + + $sql = 'UPDATE ' . STYLES_TABLE . " + SET style_id = $new_style_id + WHERE style_id = $style_id"; + $db->sql_query($sql); + + add_log('admin', 'LOG_DELETE_STYLE', $style_name); + trigger_error($user->lang['STYLE_DELETED']); + } + + // Output list of themes + adm_page_header($user->lang['DELETE_STYLE']); + +?> +
lang['DELETE_STYLE_EXPLAIN']; ?>
+ + +sql_freeresult($result); - $var_ary = array('style_id', 'style_name', 'style_copyright', 'template_id', 'template_name', 'template_path', 'template_copyright', 'template_storedb', 'bbcode_bitfield', 'theme_id', 'theme_name', 'theme_path', 'theme_copyright', 'theme_storedb', 'theme_data', 'imageset_id', 'imageset_name', 'imageset_path', 'imageset_copyright'); + $var_ary = array('style_id', 'style_name', 'style_copyright', 'template_id', 'template_name', 'template_path', 'template_copyright', 'template_storedb', 'bbcode_bitfield', 'theme_id', 'theme_name', 'theme_path', 'theme_copyright', 'theme_storedb', 'theme_mtime', 'theme_data', 'imageset_id', 'imageset_name', 'imageset_path', 'imageset_copyright'); foreach ($var_ary as $var) { $$var = (!empty($style_row[$var])) ? $style_row[$var] : ''; @@ -170,6 +245,7 @@ switch ($mode) ); unset($style_cfg); + // Export template core code if ($inc_template) { $template_cfg = addslashes($template_name) . "\n"; @@ -210,6 +286,8 @@ switch ($mode) } unset($template_cfg); } + + // Export theme core code if ($inc_theme) { $theme_cfg = addslashes($theme_name) . "\n"; @@ -238,6 +316,8 @@ switch ($mode) unset($theme_data); unset($theme_cfg); } + + // Export imageset core code if ($inc_imageset) { $imageset_cfg = addslashes($imageset_name) . "\n"; @@ -364,27 +444,89 @@ switch ($mode) case 'add': case 'edit': case 'install': - $style_path = (!empty($_REQUEST['name'])) ? htmlspecialchars($_REQUEST['name']) : ''; + $style_path = (!empty($_REQUEST['path'])) ? htmlspecialchars($_REQUEST['path']) : ''; + $root_path = ''; $element_ary = array('template' => STYLES_TPL_TABLE, 'theme' => STYLES_CSS_TABLE, 'imageset' => STYLES_IMAGE_TABLE); + $phpbbversion = preg_replace('#^2\.([0-9]+?)\.([0-9]+?).*?$#', '\1.\2', $config['version']); - // Process parameters ... if we're installing and a style path is set - // we'll grab the relevant data from the cfg file - if ($action == 'install' && $style_path) + + // Importing/uploading then check data and extract archive + if (!empty($_FILES['upload_file']['name']) || !empty($_POST['import_file'])) { - if (!($cfg = @file("{$phpbb_root_path}styles/$style_path/style.cfg"))) + if (!empty($_FILES['upload_file']['name'])) { - trigger_error($user->lang['NO_STYLE']); + $realname = htmlspecialchars($_FILES['upload_file']['name']); + $filename = htmlspecialchars($_FILES['upload_file']['tmp_name']); + + if (!is_uploaded_file($filename)) + { + trigger_error("$filename was not uploaded"); + } + } + else + { + $realname = htmlspecialchars($_POST['import_file']); + $filename = "{$phpbb_root_path}store/$realname"; } - $style_name = trim($cfg[0]); - $style_copyright = trim($cfg[1]); - $style_version = preg_replace('#^2\.([0-9]+?)\.([0-9]+?).*?$#', '\1.\2', trim($cfg[2])); - $reqd_template = trim($cfg[3]); - $reqd_theme = trim($cfg[4]); - $reqd_imageset = trim($cfg[5]); + if (!preg_match('#(' . $archive_preg . ')$#i', $realname, $match)) + { + $error[] = sprintf($user->lang['UPLOAD_WRONG_TYPE'], $archive_types); + } + $path = preg_replace('#^(.*?)' . preg_quote($match[0]) . '$#', '\1', $realname); - $phpbbversion = preg_replace('#^2\.([0-9]+?)\.([0-9]+?).*?$#', '\1.\2', $config['version']); + // Attempt to extract the files to a temporary directory in store + $tmp_path = $phpbb_root_path . 'store/tmp_' . substr(uniqid(''), 0, 10) . '/'; + if (!@mkdir($tmp_path)) + { + trigger_error("Cannot create $tmp_path", E_USER_ERROR); + } + + include($phpbb_root_path . 'includes/functions_compress.'.$phpEx); + + switch ($match[0]) + { + case '.zip': + $zip = new compress_zip('r', $filename); + break; + default: + $zip = new compress_tar('r', $filename, $match[0]); + } + $zip->extract($tmp_path); + $zip->close(); + + unset($cfg); + } + + + // Installing, importing/uploading then obtain the style cfg information + if (($action == 'install' && $style_path) || (!empty($_FILES['upload_file']['name']) || !empty($_POST['import_file']))) + { + $root_path = ($action == 'install') ? "{$phpbb_root_path}styles/$style_path/" : "$tmp_path"; + + if (!($fp = @fopen("{$root_path}style.cfg", 'rb'))) + { + $error[] = $user->lang['STYLE_ERR_NOT_STYLE']; + } + else + { + $stylecfg = explode("\n", fread($fp, filesize("{$root_path}style.cfg"))); + } + fclose($fp); + } + + + // Installing, importing/uploading then grab the element info else grab the + // submitted params + if (sizeof($stylecfg)) + { + $style_name = trim($stylecfg[0]); + $style_copyright = trim($stylecfg[1]); + $style_version = preg_replace('#^2\.([0-9]+?)\.([0-9]+?).*?$#', '\1.\2', trim($stylecfg[2])); + $reqd_template = trim($stylecfg[3]); + $reqd_theme = trim($stylecfg[4]); + $reqd_imageset = trim($stylecfg[5]); foreach ($element_ary as $element => $table) { @@ -396,7 +538,7 @@ switch ($mode) } else { - if (!($cfg = @file("{$phpbb_root_path}styles/$style_path/$element/$element.cfg"))) + if (!($cfg = @file("$root_path$element/$element.cfg"))) { $error[] = sprintf($user->lang['REQUIRES_' . $l_element], ${'reqd_' . $element}); } @@ -426,29 +568,46 @@ switch ($mode) } } - $s_hidden_fields = ''; + $s_hidden_fields = ''; } else { // NOTE: Data here is stripslashed! Ensure it's escaped when entering the DB - $style_name = (!empty($_POST['style_name'])) ? stripslashes(htmlspecialchars($_POST['style_name'])) : ''; - $style_copyright = (!empty($_POST['style_copyright'])) ? stripslashes(htmlspecialchars($_POST['style_copyright'])) : ''; + $style_name = (!empty($_POST['name'])) ? stripslashes(htmlspecialchars($_POST['name'])) : ''; + $style_copyright = (!empty($_POST['copyright'])) ? stripslashes(htmlspecialchars($_POST['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; - $basis = (!empty($_POST['basis'])) ? intval($_POST['basis']) : false; + if (!empty($_POST['basis'])) + { + $basis = intval($_POST['basis']); + + $sql = 'SELECT template_id, theme_id, imageset_id + FROM ' . STYLES_TABLE . " + WHERE style_id = $basis"; + $result = $db->sql_query($sql); + + if (!extract($db->sql_fetchrow($result))) + { + $error[] = $user->lang['NO_STYLE']; + } + $db->sql_freeresult($result); + } } - $style_active = (!empty($_POST['style_active'])) ? ((!$_POST['style_active']) ? 0 : 1) : 1; - $style_default = (!empty($_POST['style_default'])) ? ((!$_POST['style_default']) ? 0 : 1) : 0; + + // Common params + $style_active = (isset($_POST['style_active'])) ? ((!empty($_POST['style_active'])) ? 1 : 0) : 1; + $style_default = (isset($_POST['style_default'])) ? ((!empty($_POST['style_active'])) ? 1 : 0) : (($config['default_style'] == $style_id) ? 1 : 0); - // User has submitted form ... so let's process it + // User has submitted form and no errors have occured if ($update && !sizeof($error)) { - if ($action == 'install') + // We're installing/uploading/importing + if (sizeof($stylecfg)) { foreach ($element_ary as $element => $table) { @@ -482,12 +641,21 @@ switch ($mode) switch ($element) { case 'template': - $template_storedb = (!is_writeable("{$phpbb_root_path}styles/$style_path/template")) ? 1 : 0; + $template_path = str_replace(' ', '_', $template_name); + + if ($action != 'install') + { + @mkdir("{$phpbb_root_path}styles/$template_path", 0777); + @chmod("{$phpbb_root_path}styles/$template_path", 0777); + copy_files($root_path, filelist("{$root_path}template", '', '*'), "$template_path/template"); + } + + $template_storedb = (!is_writeable("{$phpbb_root_path}styles/$template_path/template")) ? 1 : 0; $sql_ary = array( 'template_name' => $template_name, 'template_copyright' => $template_copyright, - 'template_path' => $style_path, + 'template_path' => $template_path, 'template_storedb' => $template_storedb ); @@ -501,7 +669,7 @@ switch ($mode) if ($template_storedb) { - $filelist = filelist("{$phpbb_root_path}styles/$style_path/template", '', 'html'); + $filelist = filelist("{$root_path}template", '', 'html'); store_templates('insert', $template_id, $style_path, $filelist); } @@ -512,21 +680,30 @@ switch ($mode) break; case 'theme': - $theme_storedb = 0; + $theme_path = str_replace(' ', '_', $theme_name); - if (!is_writeable("{$phpbb_root_path}styles/$style_path/theme/stylesheet.css")) + if ($action != 'install') { - $theme_data = implode('', file("{$phpbb_root_path}styles/$style_path/theme/stylesheet.css")); + + @mkdir("{$phpbb_root_path}styles/$theme_path", 0777); + @chmod("{$phpbb_root_path}styles/$theme_path", 0777); + copy_files($root_path, filelist("{$root_path}theme", '', '*'), "$theme_path/theme"); + } + + $theme_storedb = 0; + if (!is_writeable("{$phpbb_root_path}styles/$theme_path/theme/stylesheet.css")) + { + $theme_data = str_replace('./', "styles/$theme_path/theme/", implode('', file("$root_path/theme/stylesheet.css"))); $theme_storedb = 1; } $sql_ary = array( 'theme_name' => $theme_name, 'theme_copyright' => $theme_copyright, - 'theme_path' => $style_path, + 'theme_path' => $theme_path, 'theme_storedb' => $theme_storedb, - 'theme_data' => ($theme_storedb) ? $theme_data : '', - 'theme_mtime' => ($theme_storedb) ? filemtime("{$phpbb_root_path}styles/$style_path/theme/stylesheet.css") : 0 + 'theme_data' => ($theme_storedb) ? $theme_data : '', + 'theme_mtime' => ($theme_storedb) ? filemtime("{$phpbb_root_path}styles/$theme_path/theme/stylesheet.css") : 0 ); $sql = 'INSERT INTO ' . STYLES_CSS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); @@ -539,20 +716,29 @@ switch ($mode) break; case 'imageset': + $imageset_path = str_replace(' ', '_', $imageset_name); + + if ($action != 'install') + { + + @mkdir("{$phpbb_root_path}styles/$imageset_path", 0777); + @chmod("{$phpbb_root_path}styles/$imageset_path", 0777); + copy_files("{$root_path}imageset", filelist("{$root_path}imageset", '', '*'), "$imageset_path/imageset"); + } + + $cfg = file("{$phpbb_root_path}styles/$imageset_path/imageset/imageset.cfg"); + $sql_img_ary = array(); - - $cfg = file("{$phpbb_root_path}styles/$style_path/imageset/imageset.cfg"); - 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_img_ary[$tmp[0]] = str_replace('{PATH}', "styles/$imageset_path/imageset/", trim($tmp[1])); } $sql_ary = array( 'imageset_name' => $imageset_name, 'imageset_copyright' => $imageset_copyright, - 'imageset_path' => $style_path, + 'imageset_path' => $imageset_path, ); $sql_ary += $sql_img_ary; @@ -567,79 +753,100 @@ switch ($mode) } } } + } + + if (!sizeof($error)) + { + if ($action != 'edit' && empty($style_name)) + { + $error[] = $user->lang['STYLE_ERR_STYLE_NAME']; + } + + if ($action != 'edit' && strlen($style_name) > 30) + { + $error[] = $user->lang['STYLE_ERR_NAME_LONG']; + } + + if ($action != 'edit' && !preg_match('#^[a-z0-9_\-\+\. ]+$#i', $style_name)) + { + $error[] = $user->lang['STYLE_ERR_NAME_CHARS']; + } + + if ($action != 'edit' && strlen($style_copyright) > 60) + { + $error[] = $user->lang['STYLE_ERR_COPY_LONG']; + } + + if (!$template_id || !$theme_id || !$imageset_id) + { + $error[] = $user->lang['STYLE_ERR_NO_IDS']; + } + + $sql_where = ($action != 'edit') ? "style_name = '" . $db->sql_escape($style_name) . "'" : "style_id = $style_id"; + $sql = 'SELECT style_name + FROM ' . STYLES_TABLE . " + WHERE $sql_where"; + $result = $db->sql_query($sql); + + if (extract($db->sql_fetchrow($result)) && $action != 'edit') + { + $error[] = $user->lang['STYLE_ERR_NAME_EXIST']; + } + $db->sql_freeresult($result); + if (!sizeof($error)) { - if (empty($style_name)) + $sql_ary = array( + 'template_id' => $template_id, + 'theme_id' => $theme_id, + 'imageset_id' => $imageset_id, + 'style_active' => $style_active, + ); + if ($action != 'edit') { - $error[] = $user->lang['STYLE_ERR_STYLE_NAME']; - } - - if (strlen($style_name) > 30) - { - $error[] = $user->lang['STYLE_ERR_NAME_LONG']; - } - - if (!preg_match('#^[a-z0-9_\-\+\. ]+$#i', $style_name)) - { - $error[] = $user->lang['STYLE_ERR_NAME_CHARS']; - } - - if (strlen($style_copyright) > 60) - { - $error[] = $user->lang['STYLE_ERR_COPY_LONG']; - } - - if (!$template_id || !$theme_id || !$imageset_id) - { - $error[] = $user->lang['STYLE_ERR_NO_IDS']; - } - - $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"; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - $error[] = $user->lang['STYLE_ERR_NAME_EXIST']; - } - $db->sql_freeresult($result); - - if (!sizeof($error)) - { - $sql_ary = array( + $sql_ary += array( 'style_name' => $style_name, 'style_copyright' => $style_copyright, - 'template_id' => $template_id, - 'theme_id' => $theme_id, - 'imageset_id' => $imageset_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); - - if ($action == 'add' || $action == 'install') - { - $style_id = $db->sql_nextid(); - } - - 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]); } + + $sql = ($action != 'edit') ? '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); + + if ($action != 'edit') + { + $style_id = $db->sql_nextid(); + } + + if ($style_default) + { + set_config('default_style', $style_id); + } + + if ($tmp_path) + { + cleanup_folder($tmp_path); + } + + $log = ($action != 'edit') ? 'LOG_ADD_STYLE' : 'LOG_EDIT_STYLE'; + add_log('admin', $log, $style_name); + + $message = ($action != 'edit') ? 'STYLE_ADDED' : 'STYLE_EDITED'; + trigger_error($user->lang[$message]); } } } + // Something went wrong ... so we'll clean up any decompressed + // uploaded/imported archives. It means the user will have to + // reupload but hum ho it's better than leaving old files + // laying around + if ($tmp_path) + { + cleanup_folder($tmp_path); + } + // Either an error occured or the user has just entered the form if (!sizeof($error) && !$update && $style_id) { @@ -692,7 +899,7 @@ switch ($mode)lang[$l_prefix . '_STYLE_EXPLAIN']; ?>
-