From 808d0f1455041b8ce051e23992ca43354eea9475 Mon Sep 17 00:00:00 2001 From: "Paul S. Owen" Date: Wed, 13 Aug 2003 14:35:50 +0000 Subject: Some tidying up of theme editing, highlight used classes, enable custom class addition, allow tabs, newlines, etc. within class strings ... though standard format is very much prefered git-svn-id: file:///svn/phpbb/trunk@4397 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/adm/admin_styles.php | 81 ++++++++++++++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 27 deletions(-) (limited to 'phpBB/adm/admin_styles.php') diff --git a/phpBB/adm/admin_styles.php b/phpBB/adm/admin_styles.php index ba0c722116..25179daf49 100644 --- a/phpBB/adm/admin_styles.php +++ b/phpBB/adm/admin_styles.php @@ -672,6 +672,7 @@ function viewsource(url) case 'edit': // General parameters $class = (isset($_POST['classname'])) ? htmlspecialchars($_POST['classname']) : ''; + $customclass = (!empty($_POST['customclass'])) ? htmlspecialchars($_POST['customclass']) : ''; $txtcols = (isset($_POST['txtcols'])) ? max(20, intval($_POST['txtcols'])) : 76; $txtrows = (isset($_POST['txtrows'])) ? max(5, intval($_POST['txtrows'])) : 10; @@ -686,10 +687,10 @@ function viewsource(url) 'table', 'th', '.cat', '.catdiv', 'td', '.row1', '.row2', '.row3', '.spacer', 'hr', ), 'forms' => array( - 'form', 'input', 'select', '.textarea', '.post', '.btnlite', '.btnmain', '.btnbbcode', + 'form', 'input', 'select', 'textarea', '.post', '.btnlite', '.btnmain', '.btnbbcode', ), 'bbcode' => array( - '.b', '.u', '.i', '.color', '.size', '.code', '.quote', 'flash', '.syntaxbg', '.syntaxcomment', '.syntaxdefault', '.syntaxhtml', '.syntaxkeyword', '.syntaxstring', + '.b', '.u', '.i', '.color', '.size', '.code', '.quote', '.flash', '.syntaxbg', '.syntaxcomment', '.syntaxdefault', '.syntaxhtml', '.syntaxkeyword', '.syntaxstring', ), 'custom' => array(), ); @@ -747,20 +748,23 @@ function viewsource(url) } // Pull out list of "custom" tags - if (preg_match_all('#([a-z\.:]+?) {.*?}#si', $stylesheet, $matches)) + $class_used = $test_ary = array(); + if (preg_match_all('/^([a-z0-9\.:#>]+?)[ \t]*?\{.*?\}/msi', $stylesheet, $matches)) { - $test_ary = array(); foreach ($base_classes as $category => $class_ary) { - $test_ary += $class_ary; + $test_ary = array_merge($test_ary, $class_ary); } - $matches = preg_replace('#^\.#', '', $matches[1]); - foreach ($matches as $value) + foreach ($matches[1] as $value) { if (!in_array($value, $test_ary)) { -// $base_classes['custom'][] = $value; + $base_classes['custom'][] = $value; + } + else + { + $class_used[] = $value; } } unset($matches); @@ -778,14 +782,14 @@ function viewsource(url) $css_element = array(); if (!empty($_POST['rawcss']) && (!empty($_POST['hidecss']) || !empty($_POST['preview']) || $update)) { - $css_element = preg_replace("#;[\r\n]*#s", "\n", stripslashes($_POST['rawcss'])); + $css_element = trim(stripslashes(htmlspecialchars(preg_replace("#;[\r\n]*#s", "\n", $_POST['rawcss'])))); $css_element = explode("\n", $css_element); } else if (($showcss && !empty($_POST['showcss'])) || !empty($_POST['preview']) || $update) { if (!empty($_POST['cssother'])) { - $css_element = explode('; ', stripslashes($_POST['cssother'])); + $css_element = explode(';', stripslashes(htmlspecialchars(trim($_POST['cssother'])))); } foreach ($match_elements as $type => $match_ary) @@ -800,18 +804,38 @@ function viewsource(url) } } } - else if (preg_match('#^' . $class . ' {(.*?)}#m', $stylesheet, $matches)) + else if (preg_match('#^' . $class . '[ \t]*?\{(.*?)\}#ms', $stylesheet, $matches)) { - $css_element = explode('; ', ltrim(substr($matches[1], 0, -2))); + $css_element = explode(';', substr(trim($matches[1]), 0, -1)); } + $css_element = preg_replace('#^\s*(.*?)\s*$#', '\1', $css_element); + // User wants to submit data ... - if ($update) - { - $updated_element = implode('; ', $css_element) . ';'; - if (preg_match('#^' . $class . ' {(.*?)}#m', $stylesheet)) + if ($update || $customclass) + { + if ($update) { - $stylesheet = preg_replace('#^(' . $class . ' {).*?(})#m', '\1 ' . $updated_element . ' \2', $stylesheet); + $updated_element = trim(implode('; ', $css_element)) . ';'; + if (preg_match('#^' . $class . '[ \t]*?\{(.*?)\}#ms', $stylesheet)) + { + $stylesheet = preg_replace('#^(' . $class . '[ \t]*?\{).*?(\})#m', '\1 ' . $updated_element . ' \2', $stylesheet); + } + $error[] = $user->lang['THEME_UPDATED']; + } + else + { + // Check custom class name is valid + if (!preg_match('/^[a-z0-9#:\.]+$/i', $customclass)) + { + $error[] = $user->lang['THEME_ERR_CLASS_CHARS']; + } + else + { + $stylesheet .= "\n$customclass { }"; + $base_classes['custom'][] = $customclass; + $error[] = $user->lang['THEME_CLASS_ADDED']; + } } // Where is the CSS stored? @@ -839,8 +863,6 @@ function viewsource(url) } $cache->destroy('sql', STYLES_CSS_TABLE); - - $error[] = $user->lang['THEME_UPDATED']; add_log('admin', 'LOG_EDIT_THEME', $theme_name); } @@ -871,7 +893,7 @@ function viewsource(url) { foreach ($css_element as $key => $element) { - if (preg_match('#^' . preg_quote($match, '#') . ': (.*?)$#', $element, $matches)) + if (preg_match('#^' . preg_quote($match, '#') . ':[ \t]*?(.*?)$#', $element, $matches)) { switch ($type) { @@ -921,10 +943,12 @@ function viewsource(url) $class_options .= ''; foreach ($class_ary as $class_name) { + $used = (in_array($class_name, $class_used) || $category == 'custom') ? ' style="color:red"' : ''; $selected = ($class_name == $class) ? ' selected="selected"' : ''; - $class_options .= ''; + $class_options .= '' . (($category == 'custom') ? $class_name : $user->lang['CSS_' . str_replace('.', '', strtoupper($class_name))]) . ''; } } + unset($class_used); // Grab list of potential images for class backgrounds $imglist = filelist("{$phpbb_root_path}styles/$theme_path/theme"); @@ -980,6 +1004,7 @@ function csspreview()

lang['EDIT_THEME_EXPLAIN']; ?>

+

lang['SELECTED_THEME']; ?>:

' . implode('
', $error) . '
'; + echo '' . implode('
', $error) . '
'; } ?> @@ -1036,9 +1061,9 @@ function csspreview() ' . implode('
', $error) . '
'; + echo '' . implode('
', $error) . '
'; } ?> @@ -2579,12 +2604,14 @@ function install($type, $action, $id) $imageset_id = (!empty($_POST['imageset_id'])) ? intval($_POST['imageset_id']) : 0; $basis = (isset($_POST['basis'])) ? intval($_POST['basis']) : 0; - if ($basis || $update) + // If we have a basis or we're editing we want some additional info ... else + // we need nothing + if ($basis || ($update && $action != 'add')) { switch ($type) { case 'style': - $sql_select = ($action != 'details') ? 'style_name, template_id, theme_id, imageset_id' : 'style_name'; + $sql_select = ($action != 'edit') ? 'style_name, template_id, theme_id, imageset_id' : 'style_name'; break; case 'template': $sql_select = 'template_id, template_name, template_path, template_storedb'; -- cgit v1.2.1