New theme chooser (with better preview using iframes)

It's a bit rough but it works.
This commit is contained in:
moodler 2005-01-30 19:27:46 +00:00
parent 626138c9b6
commit 8ba55c01ae
2 changed files with 74 additions and 28 deletions

View File

@ -2,7 +2,6 @@
require_once("../config.php");
$preview = optional_param("preview",'',PARAM_FILE); // which theme to show
$choose = optional_param("choose",'',PARAM_FILE); // set this theme as default
if (! $site = get_site()) {
@ -15,35 +14,26 @@
error("You must be an administrator to change themes.");
}
if ($choose) {
if (!is_dir($choose)) {
error("This theme is not installed!");
}
$preview = $choose;
}
if ($preview and confirm_sesskey()) {
$CFG->theme = $preview;
$CFG->stylesheet = "$CFG->wwwroot/theme/$CFG->theme/styles.php?themename=$preview";
$CFG->header = "$CFG->dirroot/theme/$CFG->theme/header.html";
$CFG->footer = "$CFG->dirroot/theme/$CFG->theme/footer.html";
include ("$CFG->theme/config.php");
}
unset($SESSION->theme);
$stradministration = get_string("administration");
$strconfiguration = get_string("configuration");
$strthemes = get_string("themes");
$strpreview = get_string("preview");
$strsavechanges = get_string("savechanges");
$strchoose = get_string("choose");
$strinfo = get_string("info");
$strtheme = get_string("theme");
$strthemesaved = get_string("themesaved");
print_header("$site->shortname: $strthemes", $site->fullname,
"<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> -> ".
"<a href=\"$CFG->wwwroot/$CFG->admin/configure.php\">$strconfiguration</a> -> $strthemes");
if ($choose and confirm_sesskey()) {
if (!is_dir($choose)) {
error("This theme is not installed!");
}
if (set_config("theme", $choose)) {
print_header("$site->shortname: $strthemes", $site->fullname,
"<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> -> ".
"<a href=\"$CFG->wwwroot/$CFG->admin/configure.php\">$strconfiguration</a> -> $strthemes");
print_heading(get_string("themesaved"));
print_continue("$CFG->wwwroot/");
@ -65,30 +55,44 @@
}
}
print_heading(get_string("previeworchoose"));
print_header("$site->shortname: $strthemes", $site->fullname,
"<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> -> ".
"<a href=\"$CFG->wwwroot/$CFG->admin/configure.php\">$strconfiguration</a> -> $strthemes");
print_heading($strthemes);
$themes = get_list_of_plugins("theme");
$sesskey = !empty($USER->id) ? $USER->sesskey : '';
echo "<table align=\"center\" cellpadding=\"7\" cellspacing=\"5\">";
echo "<tr><th class=\"generaltableheader\">$strtheme<th class=\"generaltableheader\">&nbsp;</tr>";
echo "<tr class=\"generaltableheader\"><th>$strtheme</th><th>$strinfo</th></tr>";
foreach ($themes as $theme) {
if (!file_exists("$CFG->dirroot/theme/$theme/config.php")) { // bad folder
continue;
}
include ("$CFG->dirroot/theme/$theme/config.php");
echo "<tr>";
echo "<td align=\"center\"><iframe name=\"$theme\" src=\"preview.php?preview=$theme\" height=\"150\" width=\"500\"></iframe></td>";
if ($CFG->theme == $theme) {
echo "<td align=\"center\" bgcolor=\"$THEME->body\">$theme</td>";
echo "<td align=\"center\"><a href=\"index.php?choose=$theme&amp;sesskey=$sesskey\">$strsavechanges</a></td>";
echo '<td valign="top" style="border-style:solid; border-width:2px; border-color=#000000">';
} else {
echo "<td align=\"center\" bgcolor=\"$THEME->body\">";
echo "<a title=\"$strpreview\" href=\"index.php?preview=$theme&amp;sesskey=$sesskey\">$theme</a>";
echo "</td>";
echo "<td>&nbsp;</td>";
echo '<td valign="top">';
}
echo "<h4>$theme</h4>";
echo "<p><a target=\"$theme\" href=\"preview.php?preview=$theme\">$strpreview</a></p>";
if (file_exists("$theme/README.html")) {
link_to_popup_window('/theme/'.$theme.'/README.html', $theme, $strinfo);
} else if (file_exists("$theme/README.txt")) {
link_to_popup_window('/theme/'.$theme.'/README.txt', $theme, $strinfo);
}
if ($CFG->theme != $theme) {
echo "<p><a href=\"index.php?choose=$theme&amp;sesskey=$sesskey\">$strchoose</a></p>";
}
echo '</td>';
echo "</tr>";
}
echo "</table>";

42
theme/preview.php Normal file
View File

@ -0,0 +1,42 @@
<?php // $Id$
require_once("../config.php");
$preview = optional_param('preview','standard',PARAM_FILE); // which theme to show
if (!file_exists($preview)) {
$preview = 'standard';
}
if (! $site = get_site()) {
error("Site doesn't exist!");
}
require_login();
if (!isadmin()) {
error("You must be an administrator to change themes.");
}
$CFG->theme = $preview;
$CFG->header = "$CFG->dirroot/theme/$CFG->theme/header.html";
$CFG->footer = "$CFG->dirroot/theme/$CFG->theme/footer.html";
print_header();
$stradministration = get_string("administration");
$strconfiguration = get_string("configuration");
$strthemes = get_string("themes");
$strpreview = get_string("preview");
$strsavechanges = get_string("savechanges");
$strtheme = get_string("theme");
$strthemesaved = get_string("themesaved");
print_header("$site->shortname: $strpreview", $site->fullname, "$strthemes -> $strpreview");
print_simple_box_start('center', '80%');
print_heading($preview);
print_simple_box_end();
print_footer();
?>