From 0244aaa5d0c492fbd8fa396fe732cad91cefb5de Mon Sep 17 00:00:00 2001
From: "Paul S. Owen"
Date: Fri, 18 Jul 2003 18:20:58 +0000
Subject: [PATCH] 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 | 737 ++++++++++++++++++-------------
phpBB/language/en/lang_admin.php | 16 +-
2 files changed, 454 insertions(+), 299 deletions(-)
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,25 +1207,49 @@ function viewsource(url)
lang['EDIT_THEME_EXPLAIN']; ?>
-
+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)
+ {
-You may upload additional themes using the form below. Once uploaded the theme will immediately be available for use, editing, etc.
+?>
+
+
+ ">Install
+
+">
@@ -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 ';
+
+?>
+
+
+
+
+
+
+
+
+
+
+
+ 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" ;
+
+
+
+
+
+
+
+
+
+ 'Deleted forum, its messages and subforums » %s',
'LOG_FORUM_DEL_MOVE_POSTS_MOVE_FORUMS' => 'Deleted forum, moved posts to %s and subforums to %s » %s',
- 'LOG_EDIT_THEME' => 'Edited theme » %s',
+ 'LOG_EDIT_THEME' => 'Edited theme » %s',
+ 'LOG_EDIT_THEME_DETAILS'=> 'Edited theme details » %s',
+ 'LOG_ADD_THEME_FS' => 'Add new theme on filesystem » %s',
+ 'LOG_ADD_THEME_DB' => 'Added new theme to database » %s',
+
'LOG_ADD_STYLE' => 'Added new style » %s',
'LOG_EDIT_STYLE' => 'Edited style » %s',
+
'LOG_CLEAR_TPLCACHE'=> 'Cleared template cache » %s',
@@ -1009,7 +1014,16 @@ $lang = array_merge($lang, array(
'STYLE_ANCHOR_VISITED' => 'Visited',
'STYLE_ANCHOR_HOVER' => 'Hover',
+ 'THEME_ERR_STYLE_NAME' => 'You must supply a name for this theme',
+ 'THEME_ERR_NAME_LONG' => 'The theme name can be no longer than 30 characters',
+ 'THEME_ERR_NAME_EXIST' => 'A theme with that name already exists',
+ 'THEME_ERR_COPY_LONG' => 'The copyright can be no longer than 60 characters',
+
'THEME_UPDATED' => 'Theme updated successfully',
+ 'THEME_DB_ADDED' => 'New theme added to database',
+ 'THEME_FS_ADDED' => 'New theme added on filesystem',
+ 'THEME_DETAILS_UPDATE' => 'Theme details updated',
+
'MANAGE_IMAGESET_EXPLAIN'=> 'Imagesets comprise all the button, forum, folder, etc. and other non-style specific images used by the board. Here you can edit, export or delete existing imagesets and import or activate new sets.',
'EDIT_IMAGESET' => 'Edit Imageset',