From 0244aaa5d0c492fbd8fa396fe732cad91cefb5de Mon Sep 17 00:00:00 2001
From: "Paul S. Owen"
Date: Fri, 18 Jul 2003 18:20:58 +0000
Subject: New theme function, edit theme details ... I'm really beginning to
dislike styles, and safe mode is just well, worse than I remember on 2.0.x :D
git-svn-id: file:///svn/phpbb/trunk@4282 89ea8834-ac86-4346-8a33-228a782c2dd0
---
phpBB/adm/admin_styles.php | 837 ++++++++++++++++++++++++++-------------------
1 file changed, 489 insertions(+), 348 deletions(-)
(limited to 'phpBB/adm/admin_styles.php')
diff --git a/phpBB/adm/admin_styles.php b/phpBB/adm/admin_styles.php
index c51fffea88..0cdf4aa5cb 100644
--- a/phpBB/adm/admin_styles.php
+++ b/phpBB/adm/admin_styles.php
@@ -114,19 +114,17 @@ switch ($mode)
$error[] = $user->lang['STYLE_ERR_NO_IDS'];
}
- if ($action == 'add')
- {
- $sql = 'SELECT style_name
- FROM ' . STYLES_TABLE . "
- WHERE style_name = '" . $db->sql_escape($style_name) . "'";
- $result = $db->sql_query($sql);
+ $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 = '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 ($row = $db->sql_fetchrow($result))
+ {
+ $error[] = $user->lang['STYLE_ERR_NAME_EXIST'];
}
+ $db->sql_freeresult($result);
if (!sizeof($error))
{
@@ -374,11 +372,6 @@ switch ($mode)
{
trigger_error($user->lang['NO_IMAGESET']);
}
-
- do {
- extract($db->sql_fetchrow($result));
- }
- while ($row = $db->sql_fetchrow($result));
$db->sql_freeresult($result);
@@ -611,11 +604,6 @@ switch ($mode)
$db->sql_freeresult($result);
- if (!($dp = @opendir($phpbb_root_path . 'cache')))
- {
- trigger_error($user->lang['ERR_TPLCACHE_READ']);
- }
-
$cache_prefix = 'tpl_' . $template_path;
@@ -624,9 +612,10 @@ switch ($mode)
{
foreach ($_POST['delete'] as $file)
{
- if (file_exists($phpbb_root_path . 'cache/' . $cache_prefix . '_' . $file . '.html.' . $phpEx) && is_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($phpbb_root_path . 'cache/' . $cache_prefix . '_' . $file . '.html.' . $phpEx);
+ @unlink($file);
}
}
@@ -634,8 +623,13 @@ switch ($mode)
trigger_error($user->lang['TEMPLATE_CACHE_CLEARED']);
}
+
+ // Someone wants to see the cached source ... so we'll highlight it,
+ // add line numbers and indent it appropriately. This could be nasty
+ // on larger source files ...
if (!empty($_GET['source']) && file_exists($phpbb_root_path . 'cache/' . $cache_prefix . '_' . $_GET['source'] . '.html.' . $phpEx))
{
+
adm_page_header($user->lang['TEMPLATE_CACHE']);
?>
@@ -644,15 +638,15 @@ switch ($mode)
lang['ERR_TPLCACHE_READ']);
+ }
+
$tplcache_ary = array();
while ($file = readdir($dp))
{
@@ -795,6 +798,7 @@ function viewsource(url)
lang['NO_CACHED_TPL_FILES']; ?>
@@ -819,6 +823,20 @@ function viewsource(url)
case 'add':
case 'details':
+ if ($template_id)
+ {
+ $sql = 'SELECT *
+ FROM ' . STYLES_TPL_TABLE . "
+ WHERE template_id = $template_id";
+ $result = $db->sql_query($sql);
+
+ if (!(extract($db->sql_fetchrow($result))))
+ {
+ trigger_error($user->lang['NO_TEMPLATE']);
+ }
+ $db->sql_freeresult($result);
+ }
+
// Output the page
adm_page_header($user->lang['EDIT_TEMPLATE']);
@@ -997,8 +1015,8 @@ function viewsource(url)
@@ -1045,10 +1062,13 @@ function viewsource(url)
-
-
+ // ------
+ // THEMES
+ // ------
case 'themes':
+ $theme_id = (isset($_REQUEST['id'])) ? intval($_REQUEST['id']) : false;
+
switch ($action)
{
case 'preview':
@@ -1057,6 +1077,127 @@ function viewsource(url)
case 'add':
case 'details':
+ // Do we want to edit an existing theme or are we creating a new theme
+ // or submitting an existing one?
+ if ($theme_id && empty($_POST['update']))
+ {
+ $sql = 'SELECT *
+ FROM ' . STYLES_CSS_TABLE . "
+ WHERE theme_id = $theme_id";
+ $result = $db->sql_query($sql);
+
+ if (!(extract($db->sql_fetchrow($result))))
+ {
+ trigger_error($user->lang['NO_THEME']);
+ }
+ $db->sql_freeresult($result);
+
+ $s_hidden_fields = '';
+ }
+ else
+ {
+ $theme_name = (!empty($_POST['theme_name'])) ? htmlspecialchars(stripslashes($_POST['theme_name'])) : '';
+ $theme_copyright = (!empty($_POST['theme_copyright'])) ? htmlspecialchars(stripslashes($_POST['theme_copyright'])) : '';
+ $s_hidden_fields = (!empty($_POST['theme_basis'])) ? ' ' : '';
+ }
+
+
+ if (isset($_POST['update']))
+ {
+ $sql_where = ($action == 'add') ? "WHERE theme_name = '" . $db->sql_escape($theme_name) . "'" : "WHERE theme_id <> $theme_id AND theme_name = '" . $db->sql_escape($theme_name) . "'";
+ $sql = 'SELECT theme_name
+ FROM ' . STYLES_CSS_TABLE . "
+ $sql_where";
+ $result = $db->sql_query($sql);
+
+ if ($row = $db->sql_fetchrow($result))
+ {
+ $error[] = $user->lang['THEME_ERR_NAME_EXIST'];
+ }
+ $db->sql_freeresult($result);
+
+
+ if (!sizeof($error))
+ {
+ // Replace any chars which may cause us problems with _
+ $bad_chars = array(' ', '/', ':', '*', '?', '"', '<', '>', '|');
+
+ $theme_path = str_replace($bad_chars, '_', $theme_name);
+ if (file_exists($phpbb_root_path . 'styles/themes/' . $theme_path))
+ {
+ for ($i = 1; $i < 100; $i++)
+ {
+ if (!file_exists("$phpbb_root_path/styles/themes/{$theme_path}_{$i}"))
+ {
+ $theme_path .= "_$i";
+ break;
+ }
+ }
+ }
+
+ $css_storedb = 1;
+ if (!@ini_get('safe_mode') && @strtolower(ini_get('safe_mode')) != 'on' && is_writeable($phpbb_root_path . 'styles/themes') && $action == 'add')
+ {
+ umask(0);
+ if (mkdir($phpbb_root_path . 'styles/themes/' . $theme_path, 0777))
+ {
+ $css_storedb = 0;
+ chmod($phpbb_root_path . 'styles/themes/' . $theme_path, 0777);
+ }
+ }
+
+ $css_data = '';
+ if (!empty($_POST['theme_basis']) && $action == 'add')
+ {
+ $sql = 'SELECT theme_name, theme_path, css_storedb, css_data
+ FROM ' . STYLES_CSS_TABLE . '
+ WHERE theme_id = ' . intval($_POST['theme_basis']);
+ $result = $db->sql_query($sql);
+
+ if ($row = $db->sql_fetchrow($result))
+ {
+ $css_data = ($row['css_storedb']) ? $row['css_data'] : implode('', file($phpbb_root_path . 'styles/themes/' . $row['theme_path'] . '/' . $row['theme_path'] . '.css'));
+
+ if (!$css_storedb)
+ {
+ if ($fp = @fopen("{$phpbb_root_path}styles/themes/$theme_path/$theme_path.css", 'wb'))
+ {
+ $css_storedb = (fwrite($fp, $css_data)) ? 0 : 1;
+ }
+ else
+ {
+ $css_storedb = 1;
+ }
+ @fclose($fp);
+ }
+ }
+ $db->sql_freeresult($result);
+ }
+
+ $sql_ary = array(
+ 'theme_name' => $theme_name,
+ 'theme_copyright' => $theme_copyright,
+ );
+ if ($action == 'add')
+ {
+ $sql_ary = array_merge($sql_ary, array(
+ 'css_storedb' => $css_storedb,
+ 'css_data' => ($css_storedb) ? $css_data : '',
+ ));
+ }
+
+ $sql = ($action == 'add') ? 'INSERT INTO ' . STYLES_CSS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary) : 'UPDATE ' . STYLES_CSS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE theme_id = ' . $theme_id;
+ $db->sql_query($sql);
+
+ $message = ($action == 'add') ? (($storedb) ? 'THEME_DB_ADDED' : 'THEME_FS_ADDED') : 'THEME_DETAILS_UPDATE';
+ $log = ($action == 'add') ? (($storedb) ? 'LOG_ADD_THEME_DB' : 'LOG_ADD_THEME_FS') : 'LOG_EDIT_THEME_DETAILS';
+
+ add_log('admin', $log, $theme_name);
+ trigger_error($user->lang[$message]);
+ }
+ }
+
+
// Output the page
adm_page_header($user->lang['EDIT_THEME']);
@@ -1066,40 +1207,59 @@ function viewsource(url)
lang['EDIT_THEME_EXPLAIN']; ?>
-
+sql_freeresult($result);
- // Grab template data
- if (!($fp = fopen("{$phpbb_root_path}styles/themes/$theme_path/$theme_name.css", 'rb')))
+ // Where is the CSS stored?
+ if ($css_storedb)
+ {
+ $stylesheet = &$css_data;
+ }
+ else if (is_writeable("{$phpbb_root_path}styles/themes/$theme_path/$theme_name.css"))
{
- die("ERROR");
+ // Grab template data
+ if (!($fp = fopen("{$phpbb_root_path}styles/themes/$theme_path/$theme_name.css", 'rb')))
+ {
+ trigger_error($user->lang['NO_THEME']);
+ }
+ $stylesheet = fread($fp, filesize("{$phpbb_root_path}styles/themes/$theme_path/$theme_name.css"));
+ fclose($fp);
+ }
+ else
+ {
+ trigger_error($user->lang['ERR_THEME_UNWRITEABLE']);
}
- $stylesheet = fread($fp, filesize("{$phpbb_root_path}styles/themes/$theme_path/$theme_name.css"));
- fclose($fp);
// Pull out list of "custom" tags
@@ -1262,223 +1434,71 @@ function viewsource(url)
// the div/span and some text? This is gonna get nasty :(
if (!empty($_POST['preview']))
{
- $output = '%s ';
-
-?>
-
-
-
-
-
-
-
-
-
-
-
- h1
- h2
- h3
-
-
- mainmenu
-
-
-
-
-
-
-
-
-
-
-
-
- th
-
-
- cattitle / cat
- catdiv
-
-
- topictitle / row1
- topicauthor / row2
- topicdetails / row1
-
-
- row3
-
-
- spacer
-
-
- postauthor / row1
- postdetails / row2
- postbody / row1 posthilit
-
-
-
-
-
-
-
- gen
- genmed
- gensmall
-
-
- copyright phpBB
-
-
-
-
-
-
-
-
-
-
-
- postbody / bold italic underline
-
-
-
-
- A_N_Other wrote: quote
-
-
-
-
-
-
- Code:
-
-
- 10 Print "hello" 20 Goto 10
-
-
-
-
-
-
- PHP:
-
-
- ?> <HTML ><?php echo $this = "HELLO" ;
-
-
-
-
-
-
-
-
-
- $match_ary)
- {
- foreach ($match_ary as $match)
- {
- $var = str_replace('-', '_', $match);
- $$var = '';
-
- if (sizeof($css_element))
- {
- foreach ($css_element as $key => $element)
- {
- if (preg_match('#^' . preg_quote($match, '#') . ': (.*?)$#', $element, $matches))
- {
- switch ($type)
- {
- case 'sizes':
- if (preg_match('#(.*?)(px|%|em|pt)#', $matches[1], $matches))
- {
- ${$var . '_units'} = trim($matches[2]);
- }
- $$var = trim($matches[1]);
- break;
-
- case 'images':
- if (preg_match('#url\(\'(.*?)\'\)#', $matches[1], $matches))
- {
- $$var = trim($matches[1]);
- $$var = str_replace('./', $theme_name . '/', $$var);
- }
- break;
-
- default:
- $$var = trim($matches[1]);
- }
-
- // Remove this element from array
- unset($css_element[$key]);
- break;
- }
- }
- }
- }
- }
-
- // Any remaining elements must be custom data so we save that
- // in a hidden field
- if (sizeof($css_element))
- {
- $s_hidden_fields .= ' ';
- }
- }
- }
- // End of class element variable setting
+ }
+ }
+ // End of class element variable setting
// Generate list of class options
$class_options = '';
@@ -1754,23 +1774,29 @@ function csspreview()
Theme name
Options
+
+ Installed themes
+
sql_query($sql);
+ $installed_themes = array();
+ $basis_options = '';
while ($row = $db->sql_fetchrow($result))
{
+ $installed_themes[] = $row['theme_path'];
+ $basis_options .= '' . $row['theme_name'] . ' ';
+
$row_class = ($row_class != 'row1') ? 'row1' : 'row2';
?>
', $row['theme_name'], '') : $row['theme_name'];
-
- echo sprintf('%s%s%s', "', $row['theme_name'], ' ');
+ echo "' . $row['theme_name'] . ' ';
?>
">Details
@@ -1785,36 +1811,56 @@ function csspreview()
?>
- Create new theme:
+ Uninstalled themes
-
+If you have uploaded a new theme to your themes/ folder it will be listed here. Before it can be used you need to install it using the form below.
+ $new_theme_ary = $themecfg = array();
+ $dp = opendir($phpbb_root_path . 'styles/themes');
+ while ($file = readdir($dp))
+ {
+ if ($file{0} != '.' && file_exists($phpbb_root_path . 'styles/themes/' . $file . '/theme.cfg'))
+ {
+ include($phpbb_root_path . 'styles/themes/' . $file . '/theme.cfg');
+ if (!in_array($themecfg['name'], $installed_themes))
+ {
+ $new_theme_ary[$i]['path'] = $file;
+ $new_theme_ary[$i]['name'] = $themecfg['name'];
+ }
+ }
+ }
+ unset($installed_themes);
+ @closedir($dp);
-">
-
- Install theme
-
-
- No new themes detected
-
+ if (sizeof($new_theme_ary))
+ {
+ foreach ($new_theme_ary as $key => $themecfg)
+ {
+
+?>
-
+
+ ">Install
-
+You may upload additional themes using the form below. Once uploaded the theme will immediately be available for use, editing, etc.
+ }
+ }
+ else
+ {
-">
@@ -1824,75 +1870,170 @@ function csspreview()
break;
+}
-
-}
-
-
// ---------
// FUNCTIONS
//
-class template_admin extends template
+function theme_preview(&$stylesheet, &$class, &$css_element)
{
- function compile_cache_clear($template = false)
+ global $config, $user;
+
+ $output = '%s ';
+
+?>
+
+
+
+
+
+
+
+
- $template_list = array();
+
+
+ h1
+ h2
+ h3
+
+
+ mainmenu
+
+
+
+
+
- if (!$template)
- {
- $dp = opendir($phpbb_root_path . $this->cache_root);
- while ($dir = readdir($dp))
- {
- $template_dir = $phpbb_root_path . $this->cache_root . $dir;
- if (!is_file($template_dir) && !is_link($template_dir) && $dir != '.' && $dir != '..')
- {
- array_push($template_list, $dir);
- }
- }
- closedir($dp);
- }
- else
- {
- array_push($template_list, $template);
- }
+
- foreach ($template_list as $template)
- {
- $dp = opendir($phpbb_root_path . $this->cache_root . $template);
- while ($file = readdir($dp))
- {
- unlink($phpbb_root_path . $this->cache_root . $file);
- }
- closedir($dp);
- }
+
- return;
- }
+
+
+ th
+
+
+ cattitle / cat
+ catdiv
+
+
+ topictitle / row1
+ topicauthor / row2
+ topicdetails / row1
+
+
+ row3
+
+
+ spacer
+
+
+ postauthor / row1
+ postdetails / row2
+ postbody / row1 posthilit
+
+
- function compile_cache_show($template)
- {
- global $phpbb_root_path;
+
- $template_cache = array();
+
+
+ gen
+ genmed
+ gensmall
+
+
+ copyright phpBB
+
+
- $template_dir = $phpbb_root_path . $this->cache_root . $template;
- $dp = opendir($template_dir);
- while ($file = readdir($dp))
- {
- if (preg_match('#\.html$#i', $file) && is_file($template_dir . '/' . $file))
- {
- array_push($template_cache, $file);
- }
- }
- closedir($dp);
+
- return;
- }
+
+
+
+
+
+
+ postbody / bold italic underline
+
+
+
+
+ A_N_Other wrote: quote
+
+
+
+
+
+
+ Code:
+
+
+ 10 Print "hello" 20 Goto 10
+
+
+
+
+
+
+ PHP:
+
+
+ ?> <HTML ><?php echo $this = "HELLO" ;
+
+
+
+
+
+
+
+
+
+