From e3c310db51bd00bed0bdfe00a2e4e2cb6f0d4fa7 Mon Sep 17 00:00:00 2001 From: "Paul S. Owen" Date: Thu, 7 Aug 2003 16:52:36 +0000 Subject: [PATCH] Style related updates git-svn-id: file:///svn/phpbb/trunk@4351 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/adm/admin_styles.php | 368 ++++++++++++++++++++++--------- phpBB/language/en/lang_admin.php | 29 +++ 2 files changed, 289 insertions(+), 108 deletions(-) diff --git a/phpBB/adm/admin_styles.php b/phpBB/adm/admin_styles.php index 005ea788fe..c54c093865 100644 --- a/phpBB/adm/admin_styles.php +++ b/phpBB/adm/admin_styles.php @@ -1,4 +1,30 @@ 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)) { @@ -29,8 +55,9 @@ if (!$auth->acl_get('a_styles')) } -// Get and set some vars +// Get some vars $mode = (isset($_REQUEST['mode'])) ? htmlspecialchars($_REQUEST['mode']) : ''; +$update = ($update) ? true : false; if (isset($_REQUEST['action'])) { @@ -49,6 +76,7 @@ else } } +// Set some basic vars $error = array(); $safe_mode = (@ini_get('safe_mode') && @strtolower(ini_get('safe_mode')) == 'on') ? true : false; @@ -57,7 +85,7 @@ $safe_mode = (@ini_get('safe_mode') && @strtolower(ini_get('safe_mode')) == 'on' $archive_types = $archive_preg = ''; foreach (array('zip' => 'zlib', 'tar' => '', 'tar.gz' => 'zlib', 'tar.bz2' => 'bz2') as $type => $module) { - if ($module && !extension_loaded($module)) + if ($module && !@extension_loaded($module)) { break; } @@ -66,7 +94,6 @@ foreach (array('zip' => 'zlib', 'tar' => '', 'tar.gz' => 'zlib', 'tar.bz2' => 'b } - // What shall we do today then? switch ($mode) { @@ -79,125 +106,250 @@ switch ($mode) { case 'activate': case 'deactivate': - // TODO ... reset user_styles if their style is deactivated + if ($style_id == $config['default_style']) + { + trigger_error($user->lang['DEACTIVATE_DEFAULT']); + } + $sql = 'UPDATE ' . STYLES_TABLE . ' SET style_active = ' . (($action == 'activate') ? 1 : 0) . ' WHERE style_id = ' . $style_id; $db->sql_query($sql); + + // Set style to default for any member using deactivated style + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_style = ' . $config['default_style'] . " + WHERE user_style = $style_id"; + $db->sql_query($sql); break; case 'delete': break; case 'export': + $inc_template = (!empty($_POST['inc_template'])) ? true : false; + $inc_theme = (!empty($_POST['inc_theme'])) ? true : false; + $inc_imageset = (!empty($_POST['inc_imageset'])) ? true : false; + 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)))) + // Lets do a merry dance ... either that or generate the archive + if ($update) { - trigger_error($user->lang['NO_STYLE']); - } - $db->sql_freeresult($result); + $sql_select = 's.style_id, s.style_name, s.style_copyright'; + $sql_from = STYLES_TABLE . ' s'; + $sql_where = "s.style_id = $style_id"; - $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]); - } + if ($inc_template) + { + $sql_select .= ', t.*'; + $sql_from .= ', ' . STYLES_TPL_TABLE . ' t'; + $sql_where .= ' AND t.template_id = s.template_id'; + } + if ($inc_theme) + { + $sql_select .= ', c.*'; + $sql_from .= ', ' . STYLES_CSS_TABLE . ' c'; + $sql_where .= ' AND c.theme_id = s.theme_id'; + } + if ($inc_imageset) + { + $sql_select .= ', i.*'; + $sql_from .= ', ' . STYLES_IMAGE_TABLE . ' i'; + $sql_where .= ' AND i.imageset_id = s.imageset_id'; + } - $style_cfg = addslashes($style_name) . "\n"; - $style_cfg .= addslashes($style_copyright) . "\n"; - $style_cfg .= addslashes($config['version']) . "\n"; + $sql = "SELECT $sql_select + FROM $sql_from + WHERE $sql_where"; + $result = $db->sql_query($sql); - $template_cfg = addslashes($template_name) . "\n"; - $template_cfg .= addslashes($template_copyright) . "\n"; - $template_cfg .= addslashes($config['version']) . "\n"; + if (!($row = ($db->sql_fetchrow($result)))) + { + trigger_error($user->lang['NO_STYLE']); + } + $db->sql_freeresult($result); - $theme_cfg = addslashes($theme_name) . "\n"; - $theme_cfg .= addslashes($theme_copyright) . "\n"; - $theme_cfg .= addslashes($config['version']) . "\n"; + $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'); + foreach ($var_ary as $var) + { + $$var = (!empty($row[$var])) ? $row[$var] : ''; + unset($row[$var]); + } - $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]); - } + $style_cfg = addslashes($style_name) . "\n"; + $style_cfg .= addslashes($style_copyright) . "\n"; + $style_cfg .= addslashes($config['version']) . "\n"; - $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' - ), - ); + $template_cfg = addslashes($template_name) . "\n"; + $template_cfg .= addslashes($template_copyright) . "\n"; + $template_cfg .= addslashes($config['version']) . "\n"; + $template_cfg .= addslashes($bbcode_bitfield) . "\n"; - $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' - ), - ); + $theme_cfg = addslashes($theme_name) . "\n"; + $theme_cfg .= addslashes($theme_copyright) . "\n"; + $theme_cfg .= addslashes($config['version']) . "\n"; - if ($css_storedb) - { - $data += array( + $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' => $css_data, - 'prefix' => 'theme/stylesheet.css' + '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' => ($theme_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($theme_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); + } + else + { + $sql = 'SELECT style_id, 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']); + } + $db->sql_freeresult($result); } - unset($css_data); - unset($style_cfg); - unset($theme_cfg); - unset($template_cfg); - unset($imageset_cfg); + // Output list of themes + adm_page_header($user->lang['STYLE_EXPORT']); - export('style', $style_id, $style_name, str_replace(' ', '_', $style_name), $files, $data); - } +?> +

lang['STYLE_EXPORT']; ?>

+ +

lang['STYLE_EXPORT_EXPLAIN']; ?>

+ +
"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
lang['STYLE_EXPORT']; ?> +
', $error); ?>
lang['STYLE_NAME']; ?>:
lang['INCLUDE_TEMPLATE']; ?>: lang['YES']; ?>    lang['NO']; ?>
lang['INCLUDE_THEME']; ?>: lang['YES']; ?>    lang['NO']; ?>
lang['INCLUDE_IMAGESET']; ?>: lang['YES']; ?>    lang['NO']; ?>
lang['DOWNLOAD_STORE']; ?>:
lang['DOWNLOAD_STORE_EXPLAIN']; ?>
lang['EXPORT_STORE']; ?>    lang['EXPORT_DOWNLOAD']; ?>
lang['ARCHIVE_FORMAT']; ?>: 'zlib', 'tar' => '', 'tar.gz' => 'zlib', 'tar.bz2' => 'bz2'); + + foreach ($compress_types as $type => $module) + { + if ($module && !extension_loaded($module)) + { + break; + } + echo ' .' . $type . '  '; + } + +?>
  
+ $theme_name, 'theme_copyright' => $theme_copyright, 'theme_path' => str_replace(' ', '_', $style_path), - 'css_storedb' => $css_storedb, - 'css_data' => $css_data, + 'theme_storedb' => $theme_storedb, + 'theme_data' => $theme_data, ); $sql = 'INSERT INTO ' . STYLES_CSS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); @@ -366,22 +518,22 @@ switch ($mode) { if (empty($template_name)) { - $error[] = $user->lang['TPL_ERR_STYLE_NAME']; + $error[] = $user->lang['TEMPLATE_ERR_STYLE_NAME']; } if (strlen($template_name) > 30) { - $error[] = $user->lang['TPL_ERR_NAME_LONG']; + $error[] = $user->lang['TEMPLATE_ERR_NAME_LONG']; } if (!preg_match('#^[a-z0-9_\-\+\. ]+$#i', $template_name)) { - $error[] = $user->lang['TPL_ERR_NAME_CHARS']; + $error[] = $user->lang['TEMPLATE_ERR_NAME_CHARS']; } if (strlen($template_copyright) > 60) { - $error[] = $user->lang['TPL_ERR_COPY_LONG']; + $error[] = $user->lang['TEMPLATE_ERR_COPY_LONG']; } if (!sizeof($error)) @@ -396,7 +548,7 @@ switch ($mode) $db->sql_query($sql); $template_id = $db->sql_nextid(); - $log = 'LOG_ADD_TPL_FS'; + $log = ($storedb) ? 'LOG_ADD_TEMPLATE_FS' : 'LOG_ADD_TEMPLATE_DB'; add_log('admin', $log, $template_name); } } @@ -1432,7 +1584,7 @@ function viewsource(url) $db->sql_freeresult($result); // User wants to submit data ... - if (!empty($_POST['update'])) + if ($update) { // Where is the template stored? if (!$template_storedb && is_writeable("{$phpbb_root_path}styles/$template_path/template/$tplname")) @@ -1739,12 +1891,12 @@ function viewsource(url) // have just selected a class. We must also cope with switching between // simple and rawcss mode $css_element = array(); - if (!empty($_POST['rawcss']) && (!empty($_POST['hidecss']) || !empty($_POST['preview']) || !empty($_POST['update']))) + if (!empty($_POST['rawcss']) && (!empty($_POST['hidecss']) || !empty($_POST['preview']) || $update)) { $css_element = preg_replace("#;[\r\n]*#s", "\n", stripslashes($_POST['rawcss'])); $css_element = explode("\n", $css_element); } - else if (($showcss && !empty($_POST['showcss'])) || !empty($_POST['preview']) || !empty($_POST['update'])) + else if (($showcss && !empty($_POST['showcss'])) || !empty($_POST['preview']) || $update) { if (!empty($_POST['cssother'])) { @@ -1770,7 +1922,7 @@ function viewsource(url) // User wants to submit data ... - if (!empty($_POST['update'])) + if ($update) { $updated_element = implode('; ', $css_element) . ';'; if (preg_match('#^' . $class . ' {(.*?)}#m', $stylesheet)) @@ -1979,7 +2131,7 @@ function csspreview() ' . implode('
', $error) . '
'; } @@ -2002,7 +2154,7 @@ function csspreview() ' . implode('
', $error) . '
'; } @@ -3343,7 +3495,7 @@ function export($type, $id, $name, $path, &$files, &$data) lang['DOWNLOAD_STORE']; ?>:
lang['DOWNLOAD_STORE_EXPLAIN']; ?> - Store   Download + lang['EXPORT_STORE']; ?>    lang['EXPORT_DOWNLOAD']; ?> lang['ARCHIVE_FORMAT']; ?>: diff --git a/phpBB/language/en/lang_admin.php b/phpBB/language/en/lang_admin.php index cbe6bcacea..099d57ab2c 100644 --- a/phpBB/language/en/lang_admin.php +++ b/phpBB/language/en/lang_admin.php @@ -946,6 +946,7 @@ $lang += array( 'INSTALLED_STYLE' => 'Installed styles', 'UNINSTALLED_STYLE' => 'Uninstalled styles', 'NO_UNINSTALLED_STYLE' => 'No uninstalled styles detected', + 'DEACTIVATE_DEFAULT' => 'You cannot deactivate the default style.', 'EDIT_STYLE' => 'Edit Style', 'EDIT_STYLE_EXPLAIN'=> 'Using the form below you can modify this existing style. You may alter the combination of template, theme and imageset which define the style itself. You may also deactivate the style and alter its name.', @@ -957,6 +958,22 @@ $lang += array( 'STYLE_ADDED' => 'Style added successfully', 'STYLE_EDITED' => 'Style edited successfully', + 'ADD_STYLE' => 'Create Template', + 'ADD_STYLE_EXPLAIN' => 'Here you can add a new template. Depending on your server configuration and file permissions you may have additional options here. For example you may be able to base this template set on an existing one. You may also be able to upload or import (from the store directory) a template archive. If you upload or import an archive the template name can be optionally taken from the archive name (to do this leave the template name blank).', + 'INSTALL_STYLE' => 'Install Template', + 'INSTALL_STYLE_EXPLAIN' => 'Here you can install a new template set. Depending on your server configuration you may have a number of options here.', + 'SELECT_STYLE' => 'Select style', + 'STYLE_EXISTING_BASIS' => 'Use existing style as basis', + 'STYLE_UPLOAD_BASIS' => 'Upload a style', + 'STYLE_IMPORT_BASIS' => 'Import style from store', + + 'STYLE_EXPORT' => 'Export Style', + 'STYLE_EXPORT_EXPLAIN' => 'Here you can export a style in the form of an archive. A style does not need to contain all elements but it must contain at least two. For example if you have created a new theme and imageset for a commonly used template you could simply export the theme and imageset and ommit the template. You may select whether to download the file directly or to place it in your store folder for download later or via FTP.', + 'INCLUDE_TEMPLATE' => 'Include template', + 'INCLUDE_THEME' => 'Include theme', + 'INCLUDE_IMAGESET' => 'Include imageset', + 'STYLE_EXPORTED' => 'Style exported succesfully and stored in %s', + 'STYLE_ERR_STYLE_NAME' => 'You must supply a name for this style', 'STYLE_ERR_NAME_LONG' => 'The style name can be no longer than 30 characters', 'STYLE_ERR_NAME_EXIST' => 'A style with that name already exists', @@ -1196,10 +1213,20 @@ $lang += array( 'IMAGESET_EXPORTED' => 'Imageset exported succesfully and stored in %s', 'DELETE_IMAGESET' => 'Delete Imageset', 'DELETE_IMAGESET_EXPLAIN' => 'Here you can remove the selected imageset from the database. Additionally, if you have permission you can elect to remove the set from the filesystem. Please note that there is no undo capability. When the imageset is deleted it is gone for good. It is recommended that you first export your set for possible future use.', + 'REPLACE_IMAGESET' => 'Replace imageset with', + 'REPLACE_IMAGESET_EXPLAIN' => 'This imageset will replace the one you are deleting in any styles that use it.', 'IMAGESET_DELETED' => 'Imageset set deleted successfully', 'IMAGESET_DELETED_FS' => 'Imageset set removed from database but some files may remain on the filesystem', 'ONLY_IMAGESET' => 'This is the only remaining imageset, you cannot delete it', + 'IMAGESET_ERR_STYLE_NAME' => 'You must supply a name for this imageset', + 'IMAGESET_ERR_NAME_CHARS' => 'The imageset name can only contain alphanumeric characters, -, +, _ and space', + 'IMAGESET_ERR_NAME_LONG' => 'The imageset name can be no longer than 30 characters', + 'IMAGESET_ERR_NAME_EXIST' => 'A imageset with that name already exists', + 'IMAGESET_ERR_COPY_LONG' => 'The copyright can be no longer than 60 characters', + 'IMAGESET_ERR_ARCHIVE' => 'Please select an archive method', + 'IMAGESET_ERR_NOT_IMAGESET' => 'The archive you specified does not contain a valid imageset.', + 'DOWNLOAD_STORE' => 'Download or Store archive', 'DOWNLOAD_STORE_EXPLAIN'=> 'You may directly download the archive or save it in your store/ folder.', @@ -1215,6 +1242,8 @@ $lang += array( 'REFRESH' => 'Refresh', 'STORE_DATABASE' => 'Database', 'STORE_FILESYSTEM' => 'Filesystem', + 'EXPORT_STORE' => 'Store', + 'EXPORT_DOWNLOAD' => 'Download', 'NO_IMAGESET' => 'Cannot find imageset on filesystem', 'NO_THEME' => 'Cannot find theme on filesystem', 'NO_TEMPLATE' => 'Cannot find template on filesystem',