From 293906dd1aba444633a8215dcf268eff6ab1f3ae Mon Sep 17 00:00:00 2001 From: pdontthink Date: Mon, 9 Oct 2006 11:35:21 +0000 Subject: [PATCH] templateset_default and templateset_fallback are IDs now, not unpredictable index numbers git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@11872 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- class/template/Template.class.php | 44 ++++++++++-- config/conf.pl | 114 +++++++++++++----------------- config/config_default.php | 22 ++++-- plugins/administrator/defines.php | 2 +- 4 files changed, 105 insertions(+), 77 deletions(-) diff --git a/class/template/Template.class.php b/class/template/Template.class.php index b5c761b1..70705ae2 100644 --- a/class/template/Template.class.php +++ b/class/template/Template.class.php @@ -232,10 +232,26 @@ class Template $aTemplateSet = (!isset($aTemplateSet) || !is_array($aTemplateSet) ? array() : $aTemplateSet); $templateset_fallback = (!isset($templateset_fallback) - ? 0 : $templateset_fallback); + ? $default : $templateset_fallback); - return (!empty($aTemplateSet[$templateset_fallback]['ID']) - ? $aTemplateSet[$templateset_fallback]['ID'] : $default); + // iterate through all template sets, is this a valid skin ID? + // + $found_it = FALSE; + foreach ($aTemplateSet as $aTemplate) { + if ($aTemplate['ID'] == $templateset_fallback) { + $found_it = TRUE; + break; + } + } + + if ($found_it) + return $templateset_fallback; + + // FIXME: note that it is possible for $default to + // point to an invalid (nonexistent) template set + // and that error will not be caught here + // + return $default; } @@ -267,10 +283,26 @@ class Template $aTemplateSet = (!isset($aTemplateSet) || !is_array($aTemplateSet) ? array() : $aTemplateSet); $templateset_default = (!isset($templateset_default) - ? 0 : $templateset_default); + ? $default : $templateset_default); - return (!empty($aTemplateSet[$templateset_default]['ID']) - ? $aTemplateSet[$templateset_default]['ID'] : $default); + // iterate through all template sets, is this a valid skin ID? + // + $found_it = FALSE; + foreach ($aTemplateSet as $aTemplate) { + if ($aTemplate['ID'] == $templateset_default) { + $found_it = TRUE; + break; + } + } + + if ($found_it) + return $templateset_default; + + // FIXME: note that it is possible for $default to + // point to an invalid (nonexistent) template set + // and that error will not be caught here + // + return $default; } diff --git a/config/conf.pl b/config/conf.pl index 2f93f3fe..732c4aae 100755 --- a/config/conf.pl +++ b/config/conf.pl @@ -2929,8 +2929,13 @@ sub command_templates { $count = 0; while ( $count <= $#templateset_name ) { - if ( $count == $templateset_default ) { - print " *"; + if ( $templateset_id[$count] eq $templateset_default ) { + print " d"; + } else { + print " "; + } + if ( $templateset_id[$count] eq $templateset_fallback ) { + print "f "; } else { print " "; } @@ -2948,50 +2953,15 @@ sub command_templates { $count++; } - -# FIXME: what is this stuff? it is commented out, can we just blast it? -# opendir( DIR, "../templates" ); -# @files = readdir(DIR); -# $pos = 0; -# -# while ( $cnt <= $#files ) { -# if ( -d "../templates/" . $files[$i] && $files[$i] !~ /^\./ && $files[$i] ne "CVS" ) { -# $filename = "../templates/" . $files[$cnt]; -# $found = 0; -# for ( $x = 0 ; $x <= $#templateset_id ; $x++ ) { -# if ( $theme_path[$x] eq $filename ) { -# $found = 1; -# } -# } -# } -# $cnt++; -# } -# for ( $i = 0 ; $i <= $#files ; $i++ ) { -# if ( -d "../templates/" . $files[$i] && $files[$i] !~ /^\./ && $files[$i] ne "CVS" ) { -# $match = 0; -# for ( $k = 0 ; $k <= $#aTemplateSets ; $k++ ) { -# if ( $aTemplateSets[$chosen] eq $files[$i] ) { -# $match = 1; -# } -# } -# if ( $match == 0 ) { -# $unused_plugins[$pos] = $files[$i]; -# $pos++; -# } -# } -# } -# -# for ( $i = 0 ; $i <= $#unused_plugins ; $i++ ) { -# $num = $num + 1; -# print " $num. $unused_plugins[$i]\n"; -# } -# closedir DIR; + print "\n d = default template set\n" + . " f = fallback template set\n\n"; $menu_text = ".-------------------------------------.\n" . "| t (detect template set) |\n" . "| + (add template set) |\n" . "| - N (remove template set) |\n" . "| m N (mark default template set) |\n" + . "| f N (set fallback template set) |\n" . "| l (list template sets) |\n" . "| d (done) |\n" . "|-------------------------------------|\n" @@ -3010,8 +2980,13 @@ sub command_templates { if ( $input =~ /^\s*l\s*/i ) { $count = 0; while ( $count <= $#templateset_name ) { - if ( $count == $templateset_default ) { - print " *"; + if ( $templateset_id[$count] eq $templateset_default ) { + print " d"; + } else { + print " "; + } + if ( $templateset_id[$count] eq $templateset_fallback ) { + print "f "; } else { print " "; } @@ -3029,18 +3004,31 @@ sub command_templates { $count++; } + print "\n d = default template set\n" + . " f = fallback template set\n\n"; # mark default template set # } elsif ( $input =~ /^\s*m\s*[0-9]+/i ) { $old_def = $templateset_default; - $templateset_default = $input; - $templateset_default =~ s/^\s*m\s*//; - if ( ( $templateset_default > $#templateset_name ) || ( $templateset_default < 0 ) ) { - print "Cannot set default template set to $templateset_default. That template set does not exist.\n"; + $input =~ s/^\s*m\s*//; + $templateset_default = $templateset_id[$input]; + if ( $templateset_default =~ /^\s*$/ ) { + print "Cannot set default template set to $input. That template set does not exist.\n"; $templateset_default = $old_def; } + # set fallback template set + # + } elsif ( $input =~ /^\s*f\s*[0-9]+/i ) { + $old_def = $templateset_fallback; + $input =~ s/^\s*f\s*//; + $templateset_fallback = $templateset_id[$input]; + if ( $templateset_fallback =~ /^\s*$/ ) { + print "Cannot set fallback template set to $input. That template set does not exist.\n"; + $templateset_fallback = $old_def; + } + # add template set # } elsif ( $input =~ /^\s*\+/ ) { @@ -3081,9 +3069,6 @@ sub command_templates { $nm =~ s/[\n\r]//g; $templateset_id[ $#templateset_id + 1 ] = $filename; $templateset_name[ $#templateset_name + 1 ] = $nm; -# FIXME: why are these two lines here? -# $aTemplateSet[ $#templateset_name + 1 ] = $nm; -# $aTemplateSet[ $#templateset_id + 1 ] = $filename; } } $cnt++; @@ -3093,8 +3078,8 @@ sub command_templates { $filename = $templateset_id[$cnt]; if ( !(-d change_to_rel_path('SM_PATH . \'templates/' . $filename)) ) { print " Removing \"$filename\" (template set directory not found)\n"; - if ( $templateset_default gt $cnt ) { $templateset_default--; } - elsif ( $templateset_default eq $cnt ) { $templateset_default = 0; } + if ( $templateset_default eq $filename ) { $templateset_default = 'default'; } + if ( $templateset_fallback eq $filename ) { $templateset_fallback = 'default'; } $offset = 0; @new_templateset_name = (); @new_templateset_id = (); @@ -3130,8 +3115,10 @@ sub command_templates { } else { $rem_num = $#templateset_name; } - if ( $rem_num == $templateset_default ) { + if ( $templateset_id[$rem_num] eq $templateset_default ) { print "You cannot remove the default template set!\n"; + } elsif ( $templateset_id[$rem_num] eq $templateset_fallback ) { + print "You cannot remove the fallback template set!\n"; } else { $count = 0; @new_templateset_name = (); @@ -3145,16 +3132,19 @@ sub command_templates { } @templateset_name = @new_templateset_name; @templateset_id = @new_templateset_id; - if ( $templateset_default > $rem_num ) { - $templateset_default--; - } } # help # } elsif ( $input =~ /^\s*\?\s*/ ) { print $menu_text; + + # command not understood + # + } else { + print "Command not understood\n"; } + print "[template set] command (?=help) > "; $input = ; $input =~ s/[\r\n]//g; @@ -4381,15 +4371,11 @@ sub save_data { } print CF "\n"; - if ( $templateset_default eq '' ) { $templateset_default = '0'; } - print CF "\$templateset_default = $templateset_default;\n"; -# FIXME: need to make this a setting the user can change herein -# This REALLY needs to be done, since the index of the "default" -# set cannot always be predicted! -# Heck, why are default and fallback indexes? If we make them -# into the ID strings, then it would not cause such issues -$templateset_fallback = 0; - print CF "\$templateset_fallback = $templateset_fallback;\n"; + if ( $templateset_default eq '' ) { $templateset_default = 'default'; } + print CF "\$templateset_default = '$templateset_default';\n"; + + if ( $templateset_fallback eq '' ) { $templateset_fallback = 'default'; } + print CF "\$templateset_fallback = '$templateset_fallback';\n"; for ( $count = 0 ; $count <= $#templateset_name ; $count++ ) { print CF "\$aTemplateSet[$count]['ID'] = '" . $templateset_id[$count] . "';\n"; diff --git a/config/config_default.php b/config/config_default.php index afd45d3c..56d73f49 100644 --- a/config/config_default.php +++ b/config/config_default.php @@ -733,8 +733,8 @@ $icon_themes[3]['NAME'] = 'XP Style Icons'; /** * Templates - * You can define your own template and put it in a new directory - * under SM_PATH/templates. The ID must match the name of + * You can define your own template set (skin) and put it in a new + * directory under SM_PATH/templates. The ID must match the name of * the template directory as the example below. You can name the * template whatever you want. For an example of a template, see * the ones included in the SM_PATH/templates directory. @@ -742,12 +742,22 @@ $icon_themes[3]['NAME'] = 'XP Style Icons'; * To add a new template to the options that users can choose from, just * add a new number to the array at the bottom, and follow the pattern. * - * $templateset_default sets theme that will be used by default. + * $templateset_default sets the skin that will be used by default + * when a user doesn't have a skin selection + * in their preferences. (Must be the "ID" of + * the desired template set) * - * @global integer $templateset_default + * $templateset_fallback tells SquirrelMail which template set (skin) + * to use when looking for a file that is not + * contained within whatever skin is currently + * being used. (Must be the "ID" of the desired + * template set) + * + * @global string $templateset_default + * @global string $templateset_fallback */ -$templateset_default = 0; -$templateset_fallback = 0; +$templateset_default = 'default'; +$templateset_fallback = 'default'; $aTemplateSet[0]['ID'] = 'default'; $aTemplateSet[0]['NAME'] = 'Default'; diff --git a/plugins/administrator/defines.php b/plugins/administrator/defines.php index 067cbb9e..420bb516 100644 --- a/plugins/administrator/defines.php +++ b/plugins/administrator/defines.php @@ -39,7 +39,7 @@ function adm_template_options() { global $aTemplateSet; $ret = array(); foreach ($aTemplateSet as $iTemplateID => $aTemplate) { - $ret[$iTemplateID] = $aTemplate['NAME']; + $ret[$aTemplate['ID']] = $aTemplate['NAME']; } return $ret; } -- 2.25.1