1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-06 23:55:26 +02:00

A little over half done the styles admin

Can do: Add new themes from cfg file, export theme data to cfg file, remove themes
Cannot do: Created or edit themes


git-svn-id: file:///svn/phpbb/trunk@1244 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
James Atkinson 2001-10-25 08:53:18 +00:00
parent a719de20ea
commit fb8511df75
6 changed files with 434 additions and 6 deletions

View File

@ -24,8 +24,9 @@ if($setmodules == 1)
{
$file = basename(__FILE__);
$module['Styles']['Add_new'] = "$file?mode=addnew";
$module['Styles']['Create_new'] = "$file?mode=addnew";
$module['Styles']['Create_new'] = "$file?mode=create";
$module['Styles']['Manage'] = "$file";
$module['Styles']['Export'] = "$file?mode=export";
return;
}
@ -33,9 +34,24 @@ if($setmodules == 1)
// Load default header
//
$phpbb_root_dir = "./../";
require('pagestart.inc');
if( isset($HTTP_GET_VARS['mode']) || isset($HTTP_POST_VARS['mode']) )
//
// Check if the user has cancled a confirmation message.
//
$confirm = ( $HTTP_POST_VARS['confirm'] ) ? TRUE : FALSE;
$cancel = ( $HTTP_POST_VARS['cancel'] ) ? TRUE : FALSE;
if($cancel)
{
header("Location: $PHP_SELF");
}
if(!$HTTP_POST_VARS['send_file'])
{
require('pagestart.inc');
}
if(isset($HTTP_GET_VARS['mode']) || isset($HTTP_POST_VARS['mode']) )
{
$mode = ($HTTP_GET_VARS['mode']) ? $HTTP_GET_VARS['mode'] : $HTTP_POST_VARS['mode'];
}
@ -44,6 +60,352 @@ else
$mode = "";
}
include('page_footer_admin.'.$phpEx);
switch($mode)
{
case "addnew":
$install_to = ($HTTP_GET_VARS['install_to']) ? urldecode($HTTP_GET_VARS['install_to']) : $HTTP_POST_VARS['install_to'];
$style_name = ($HTTP_GET_VARS['style']) ? urldecode($HTTP_GET_VARS['style']) : $HTTP_POST_VARS['style'];
if(isset($install_to))
{
include($phpbb_root_dir . "templates/" . $install_to . "/theme_info.cfg");
$template_name = $$install_to;
$found = FALSE;
for($i = 0; $i < count($template_name) && !$found; $i++)
{
if($template_name[$i]['style_name'] == $style_name)
{
while(list($key, $val) = each($template_name[$i]))
{
$db_fields[] = $key;
$db_values[] = $val;
}
}
}
$sql = "INSERT INTO " . THEMES_TABLE . " (";
for($i = 0; $i < count($db_fields); $i++)
{
$sql .= $db_fields[$i];
if($i != (count($db_fields) - 1))
{
$sql .= ", ";
}
}
$sql .= ") VALUES (";
for($i = 0; $i < count($db_values); $i++)
{
$sql .= "'" . $db_values[$i] . "'";
if($i != (count($db_values) - 1))
{
$sql .= ", ";
}
}
$sql .= ")";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, "Could not insert theme data!", "Error", __LINE__, __FILE__, $sql);
}
message_die(GENERAL_MESSAGE, $lang['Theme_installed'], $lang['Success']);
}
else
{
$installable_themes = array();
if($dir = opendir($phpbb_root_dir . "templates/"))
{
while($sub_dir = readdir($dir))
{
if($sub_dir != "." && $sub_dir != ".." && $sub_dir != "CVS")
{
if(file_exists($phpbb_root_dir . "templates/" . $sub_dir . "/theme_info.cfg"))
{
include($phpbb_root_dir . "templates/" . $sub_dir . "/theme_info.cfg");
for($i = 0; $i < count($$sub_dir); $i++)
{
$working_data = $$sub_dir;
$style_name = $working_data[$i]['style_name'];
$sql = "SELECT themes_id FROM " . THEMES_TABLE . " WHERE style_name = '$style_name'";
if(!$result = $db->sql_query($sql))
{
message_die(GENREAL_ERROR, "Could not query themes table!", "Error", __LINE__, __FILE__, $sql);
}
if(!$db->sql_numrows($result))
{
$installable_themes[] = $working_data[$i];
}
}
}
}
}
$template->set_filenames(array(
"body" => "admin/styles_addnew_body.tpl")
);
$template->assign_vars(array(
"L_STYLES_TITLE" => $lang['Styles_admin'],
"L_STYLES_ADD_TEXT" => $lang['Styles_addnew_explain'],
"L_STYLE" => $lang['Style'],
"L_TEMPLATE" => $lang['Template'],
"L_INSTALL" => $lang['Install'],
"L_ACTION" => $lang['Action'])
);
for($i = 0; $i < count($installable_themes); $i++)
{
$row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
$template->assign_block_vars("styles", array(
"STYLE_NAME" => $installable_themes[$i]['style_name'],
"TEMPLATE_NAME" => $installable_themes[$i]['template_name'],
"ROW_CLASS" => $row_class,
"ROW_COLOR" => $row_color,
"U_STYLES_INSTALL" => append_sid("admin_styles.$phpEx?mode=addnew&style=" . urlencode($installable_themes[$i]['style_name']) . "&install_to=" . urlencode($installable_themes[$i]['template_name'])))
);
}
$template->pparse("body");
}
closedir($dir);
}
break;
case "create":
case "edit":
break;
case "export";
if($HTTP_POST_VARS['export_template'])
{
$template_name = $HTTP_POST_VARS['export_template'];
$sql = "SELECT * FROM " . THEMES_TABLE . " WHERE template_name = '$template_name'";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, "Could not get theme data for selected template", "Error", __LINE__, __FILE__, $sql);
}
$theme_rowset = $db->sql_fetchrowset($result);
if(count($theme_rowset) == 0)
{
message_die(GENERAL_MESSAGE, $lang['No_themes'], $lang['Export_themes']);
}
$theme_data = '<?php'."\n\n";
$theme_data .= "//\n// phpBB 2.x auto-generated theme config file for $template_name\n// Do not change anything in this file!\n//\n\n";
for($i = 0; $i < count($theme_rowset); $i++)
{
while(list($key, $val) = each($theme_rowset[$i]))
{
if(!intval($key) && $key != "0")
{
$theme_data .= '$' . $template_name . "[$i][$key] = \"$val\";\n";
}
}
$theme_data .= "\n";
}
$theme_data .= '?' . '>'; // Done this to prevent highlighting editors getting confused!
@umask(0111);
$fp = @fopen($phpbb_root_path . 'templates/' . $template_name . '/theme_info.cfg', 'w');
if( !$fp )
{
//
// Unable to open the file writeable do something here as an attempt
// to get around that...
//
$s_hidden_fields = '<input type="hidden" name="theme_info" value="' . htmlspecialchars($theme_data) . '" />';
$s_hidden_fields .= '<input type="hidden" name="send_file" value="1" /><input type="hidden" name="mode" value="export" />';
$download_form = '<form action="'. append_sid("admin_styles.$phpEx") .'" method="POST"><input type="submit" name="submit" value="' . $lang['Download'] . '" />' . $s_hidden_fields;
$template->set_filenames(array(
"body" => "message_body.tpl")
);
$template->assign_vars(array(
"MESSAGE_TITLE" => $lang['Export_themes'],
"MESSAGE_TEXT" => $lang['Download_theme_cfg'] . "<br />" . $download_form)
);
$template->pparse('body');
exit();
}
$result = @fputs($fp, $theme_data, strlen($theme_data));
fclose($fp);
message_die(GENERAL_MESSAGE, $lang['Theme_info_saved'], $lang['Success']);
}
else if($HTTP_POST_VARS['send_file'])
{
header("Content-Type: text/x-delimtext; name=\"theme_info.cfg\"");
header("Content-disposition: attachment; filename=theme_info.cfg");
if( get_magic_quotes_gpc() )
{
$HTTP_POST_VARS['theme_info'] = stripslashes($HTTP_POST_VARS['theme_info']);
}
echo $HTTP_POST_VARS['theme_info'];
}
else
{
$template->set_filenames(array(
"body" => "admin/styles_exporter.tpl")
);
if($dir = opendir($phpbb_root_path . 'templates/'))
{
$s_template_select = '<select name="export_template">';
while($file = readdir($dir))
{
if($file != "." && $file != ".." && $file != "CVS")
{
$s_template_select .= '<option value="' . $file . '">' . $file . "</option>\n";
}
}
}
else
{
message_die(GENERAL_ERROR, $lang['No_template_dir'], $lang['Error'], __LINE__, __FILE__);
}
$template->assign_vars(array(
"L_STYLE_EXPORTER" => $lang['Export_themes'],
"L_EXPORTER_EXPLAIN" => $lang['Export_explain'],
"S_EXPORTER_ACTION" => append_sid("$PHP_SELF?mode=export"),
"L_TEMPLATE_SELECT" => $lang['Select_template'],
"S_TEMPLATE_SELECT" => $s_template_select,
"L_SUBMIT" => $lang['Submit'])
);
$template->pparse("body");
}
break;
case "delete":
$style_id = ($HTTP_GET_VARS['style_id']) ? intval($HTTP_GET_VARS['style_id']) : intval($HTTP_POST_VARS['style_id']);
if(!$confirm)
{
$hidden_fields = '<input type="hidden" name="mode" value="'.$mode.'" /><input type="hidden" name="style_id" value="'.$style_id.'" />';
//
// Set template files
//
$template->set_filenames(array(
"confirm" => "confirm_body.tpl")
);
$template->assign_vars(array(
"MESSAGE_TITLE" => $lang['Confirm'],
"MESSAGE_TEXT" => $lang['Confirm_delete_style'],
"L_YES" => $lang['Yes'],
"L_NO" => $lang['No'],
"S_CONFIRM_ACTION" => append_sid("admin_styles.$phpEx"),
"S_HIDDEN_FIELDS" => $hidden_fields)
);
$template->pparse("confirm");
}
else
{
//
// The user has confirmed the delete. Remove the style, the style element names and update any users
// who might be using this style
//
$sql = "DELETE FROM " . THEMES_TABLE . " WHERE themes_id = $style_id";
if(!$result = $db->sql_query($sql, BEGIN_TRANSACTION))
{
message_die(GENERAL_ERROR, "Could not remove style data!", "Error", __LINE__, __FILE__, $sql);
}
$sql = "DELETE FROM " . THEMES_NAME_TABLE . " WHERE themes_id = $style_id";
// There may not be any theme name data so don't throw an error if the SQL dosan't work
$db->sql_query($sql);
$sql = "UPDATE " . USERS_TABLE . " SET user_style = " . $board_config['default_style'] . " WHERE user_style = $style_id";
if(!$result = $db->sql_query($sql, END_TRANSACTION))
{
message_die(GENERAL_ERROR, "Could not update user style information", "Error", __LINE__, __FILE__, $sql);
}
message_die(GENERAL_MESSAGE, $lang['Style_removed'], $lang['Success']);
}
break;
default:
$sql = "SELECT themes_id, template_name, style_name FROM phpbb_themes ORDER BY template_name";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, "Could not get style information!", "Error", __LINE__, __FILE__, $sql);
}
$style_rowset = $db->sql_fetchrowset($result);
$template->set_filenames(array(
"body" => "admin/styles_list_body.tpl")
);
$template->assign_vars(array("L_STYLES_TITLE" => $lang['Styles_admin'],
"L_STYLES_TEXT" => $lang['Styles_explain'],
"L_STYLE" => $lang['Style'],
"L_TEMPLATE" => $lang['Template'],
"L_EDIT" => $lang['Edit'],
"L_DELETE" => $lang['Delete']));
for($i = 0; $i < count($style_rowset); $i++)
{
$row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
$template->assign_block_vars("styles", array("ROW_CLASS" => $row_class,
"ROW_COLOR" => $row_color,
"STYLE_NAME" => $style_rowset[$i]['style_name'],
"TEMPLATE_NAME" => $style_rowset[$i]['template_name'],
"U_STYLES_EDIT" => append_sid("$PHP_SELF?mode=edit&style_id=" . $style_rowset[$i]['themes_id']),
"U_STYLES_DELETE" => append_sid("$PHP_SELF?mode=delete&style_id=" . $style_rowset[$i]['themes_id'])));
}
$template->pparse("body");
break;
}
if(!$HTTP_POST_VARS['send_file'])
{
include('page_footer_admin.'.$phpEx);
}
?>

View File

@ -167,6 +167,7 @@ define('SEARCH_TABLE', $table_prefix.'search_results');
define('SESSIONS_TABLE', $table_prefix.'sessions');
define('SMILIES_TABLE', $table_prefix.'smilies');
define('THEMES_TABLE', $table_prefix.'themes');
define('THEMES_NAME_TALBE', $table_prefix.'themes_name');
define('TOPICS_TABLE', $table_prefix.'topics');
define('TOPICS_WATCH_TABLE', $table_prefix.'topics_watch');
define('USER_GROUP_TABLE', $table_prefix.'user_group');

View File

@ -1123,10 +1123,21 @@ $lang['no_disallowed'] = "No Disallowed Usernames";
//
$lang['Styles_admin'] = "Styles Administration";
$lang['Styles_explain'] = "In this panel you can edit or remove styles from your forum. To import a new styles click on 'Add New' in the left hand panel, to create a new styles click on 'Create New'";
$lang['Styles_addnew_explain'] = "The following list contains all the themes that are available for the templates you currently have. The items on this list HAVE NOT yet been installed into the phpBB database. To install a theme simply click the 'install' link beside a selected entry";
$lang['Style'] = "Style";
$lang['Template'] = "Template";
$lang['Install'] = "Install";
$lang['Confirm_delete_style'] = "Are you sure you want to delete this style?";
$lang['Style_removed'] = "The selected style has been removed from the database. To fully remove this style from your system you must delete the appropriate directory from your templates directory.";
$lang['Theme_installed'] = "The selected theme has been installed successfully";
$lang['Export_themes'] = "Export Themes";
$lang['Download_theme_cfg'] = "The exporter could not write the theme information file. Click the button below to download this file with your browser. Once you have downloaded it you can transer it to your templates dir and package your template for distribution if you choose.";
$lang['No_themes'] = "The template you selected has no themes attached to it. Click on the 'Create New' link to the left to create one.";
$lang['Download'] = "Download";
$lang['No_template_dir'] = "Could not open template dir, it may be unreadable by the webserver or may not exist";
$lang['Export_explain'] = "In this panel you will be able to export the theme data for a selected template. Select the template from the list below and the script will create the theme configuration file and attempt to save it to the selected template directory. If it cannot save the file itself it will give you the option to download it. In order for the script to save the file you must give write access to the webserver for the selected template dir. For more information on this see the phpBB users guide.";
$lang['Select_template'] = "Select a Template";
$lang['Theme_info_saved'] = "The theme information for the selected template has been saved. You should now return the permissions on the theme_info.cfg and/or selected template directory to READ ONLY.";
//
// That's all Folks!
// -------------------------------------------------

View File

@ -0,0 +1,19 @@
<h1>{L_STYLES_TITLE}</h1>
<P>{L_STYLES_ADD_TEXT}</p>
<table cellspacing="1" cellpadding="4" border="0" align="center" class="forumline">
<tr>
<th class="thCornerL">{L_STYLE}</th>
<th class="thTop">{L_TEMPLATE}</th>
<th class="thCornerR">{L_ACTION}</th>
</tr>
<!-- BEGIN styles -->
<tr>
<td class="{styles.ROW_CLASS}">{styles.STYLE_NAME}</td>
<td class="{styles.ROW_CLASS}">{styles.TEMPLATE_NAME}</td>
<td class="{styles.ROW_CLASS}"><a href="{styles.U_STYLES_INSTALL}">{L_INSTALL}</a></td>
</tr>
<!-- END styles -->
</table></form>

View File

@ -0,0 +1,14 @@
<h1>{L_STYLE_EXPORTER}</h1>
<p>{L_EXPORTER_EXPLAIN}</p>
<form method="post" action="{S_EXPORTER_ACTION}"><table cellspacing="1" cellpadding="4" border="0" align="center" class="forumline">
<tr>
<th class="thHead" align="center">{L_TEMPLATE_SELECT}</th>
</tr>
<tr>
<td class="row1" align="center">{S_TEMPLATE_SELECT}&nbsp;&nbsp;<input type="submit" name="edit" value="{L_SUBMIT}" class="mainoption" />&nbsp;</td>
</tr>
</table></form>

View File

@ -0,0 +1,21 @@
<h1>{L_STYLES_TITLE}</h1>
<P>{L_STYLES_TEXT}</p>
<table cellspacing="1" cellpadding="4" border="0" align="center" class="forumline">
<tr>
<th class="thCornerL">{L_STYLE}</th>
<th class="thTop">{L_TEMPLATE}</th>
<th class="thTop">{L_EDIT}</th>
<th colspan="2" class="thCornerR">{L_DELETE}</th>
</tr>
<!-- BEGIN styles -->
<tr>
<td class="{styles.ROW_CLASS}">{styles.STYLE_NAME}</td>
<td class="{styles.ROW_CLASS}">{styles.TEMPLATE_NAME}</td>
<td class="{styles.ROW_CLASS}"><a href="{styles.U_STYLES_EDIT}">{L_EDIT}</a></td>
<td class="{styles.ROW_CLASS}"><a href="{styles.U_STYLES_DELETE}">{L_DELETE}</a></td>
</tr>
<!-- END styles -->
</table></form>