[%#
ts_conf - REQUIRED
ts_texts
tweakmodule
tweakcfg
conf
nocontainers
changed_settings (optional for tweaksettings only right now)
-%]
[% USE ServerRoles -%]
[% USE JSON -%]
[% USE Whostmgr -%]
[% USE CPHash -%]
[% USE CPScalar -%]
[% USE CPSort -%]
[% USE Encoder -%]
[%# could not get scrolling tabs to behave in IE6 -%]
[% SET this_is_ie6 = CPANEL.ua_is_ie().match('^6'); -%]
[% bootstrap = bootstrap; %]
[% UNLESS nocontainers -%]
[% END -%]
[%
SET extrascript = '';
IF tweakcfg.extra_settings;
FOR settings_key = tweakcfg.extra_settings.keys;
ts_conf.$settings_key = tweakcfg.extra_settings.$settings_key;
END;
END;
SET TS_display = ts_display || ts_texts.TS_display;
SET make_tabs = TS_display.size > 1;
SET hide_group = {};
FOR group_item = TS_display;
SET group_shown = 0;
FOR setting_name = group_item.1;
SET cur_settings = ts_conf.$setting_name;
# Sometimes ts_conf is pre-filtered to have removed
# role-restricted settings. This handles those cases.
IF !cur_settings;
NEXT;
END;
# Check if this setting should be shown (not skipped)
SET setting_should_be_shown = 1;
# Skip if skipif condition evaluates to true
IF cur_settings.exists( 'skipif' )
&& ref( \cur_settings.skipif ) == 'CODE'
&& cur_settings.skipif( conf );
SET setting_should_be_shown = 0;
END;
# Skip if role restrictions aren't met
IF setting_should_be_shown
&& cur_settings.needs_role
&& !ServerRoles.are_roles_enabled(cur_settings.needs_role);
SET setting_should_be_shown = 0;
END;
# If at least one setting in the group should be shown, show the group
IF setting_should_be_shown;
group_shown = 1;
LAST;
END;
END;
IF !group_shown;
hide_group.${group_item.0} = 1;
END;
END;
IF make_tabs;
UNLESS this_is_ie6;
'
<
';
'
>
';
'
';
'
';
END;
'
';
FOR group_item = TS_display;
SET group = group_item.0;
IF !hide_group.$group;
SET groupkey = group.replace('[^A-Za-z0-9]','');
SET class_html = loop.last ? ' class="last"' : '';
"\t
' _ "\n\n";
FOR group_item = TS_display;
SET group = group_item.0;
IF hide_group.$group;
NEXT;
END;
SET groupkey = group.replace('[^A-Za-z0-9]','');
SET header_text = ts_headers
? ts_headers.$group
? ts_headers.$group.txt
: ''
: ''
;
'
';
WRAPPER '_brick.tmpl'
bootstrap = bootstrap
norow=1
bricktitle = group _ ( header_text ? " $header_text" : '' )
brickid = "group_" _ groupkey
brickclass = "settingsgroup"
;
#do this because we do NEXT IF to some of the rows, which would give
#two rows with the same color using loop.index
SET row_index = 0;
SET sorted_keys = group_item.1;
IF tweakcfg.extra_texts && tweakcfg.extra_texts.$group;
SET extra_keys = tweakcfg.extra_texts.$group.keys.sort();
SET sorted_keys = sorted_keys.merge( extra_keys );
FOR extra_key = extra_keys;
SET ts_texts.$extra_key = tweakcfg.extra_texts.$group.$extra_key;
END;
END;
FOR key = sorted_keys;
"\n\n";
SET cur_settings = ts_conf.$key;
# Sometimes ts_conf is pre-filtered to have removed
# role-restricted settings. This handles those cases.
IF !cur_settings;
NEXT;
END;
SET cur_texts = ts_texts.$key;
SET cur_label = cur_texts.label || cur_settings.label;
NEXT IF cur_settings.exists( 'skipif' )
&& ref( \cur_settings.skipif ) == 'CODE'
&& cur_settings.skipif( conf )
;
SET row_index = row_index + 1;
SET tclass = row_index % 2 ? 'tdshade1_noborder' : 'tdshade2_noborder';
'';
IF ! conf.$key.defined;
'';
END;
IF cur_settings.needs_role && !ServerRoles.are_roles_enabled(cur_settings.needs_role);
NEXT;
END;
SET this_is_a_button = cur_settings && cur_settings.type == 'button';
IF this_is_a_button;
IF cur_settings && cur_settings.popup;
SET button_html = "${cur_texts.button}";
ELSE;
SET button_html = "${cur_texts.button}";
END;
#if no label, put the button on the left and then go to the next setting
IF !cur_texts.label;
"
";
button_html;
'
';
NEXT;
END;
END;
SET newoption_title = '';
IF changed_settings && changed_settings.exists(key);
SET newoption = !this_is_a_button;
IF newoption;
SET newoption_title = locale.maketext('The setting, [_1], has changed since the last time you saved this page.',key);
END;
ELSE;
SET newoption = !this_is_a_button && !conf.exists( key ) && (!cur_settings.save_location || cur_settings.save_location == 'cpanel.config');
IF newoption;
SET newoption_title = locale.maketext('The setting, [_1], was not set in the configuration file, so the default has been used.',key);
IF cur_settings.exists('default');
SET conf.$key = cur_settings.default;
END;
END;
END;
IF cur_settings.requires_test;
extrascript = extrascript _ "register_requires_test( '$key', '"
_ cur_settings.requires_test.join("','")
_ "')\n"
;
END;
IF cur_settings.excludes;
SET excludes = ref ( cur_settings.excludes ) == 'ARRAY'
? cur_settings.excludes
: cur_settings.excludes.split(',')
;
FOR exclusion = excludes;
IF exclusion != key; #cannot exclude self
extrascript = extrascript _ "register_exclude('$key','$exclusion');\n";
END;
END;
END;
IF cur_settings.requires;
SET requirements = ref ( cur_settings.requires ) == 'ARRAY'
? cur_settings.requires
: cur_settings.requires.split(',')
;
FOR requirement = requirements;
IF requirements != key; #cannot require self
extrascript = extrascript _ "register_requires('$key','$requirement');\n";
END;
END;
END;
IF cur_settings.depends;
FOR dep = cur_settings.depends;
extrascript = extrascript _ "register_depends('$key','$dep');\n";
END;
END;
IF cur_settings.exists('value');
#ignore the value in the config file and use the value supplied
conf.$key = cur_settings.value(conf);
END;
SET unformatted_value = conf.$key;
SET formatted_value = cur_settings.exists( 'format' ) && ref( \cur_settings.format ) == 'CODE'
? cur_settings.format( unformatted_value )
: unformatted_value
;
SET formatted_value_enc = formatted_value.cpanel_safe_html_encode_str();
IF newoption || this_is_a_button || cur_settings.type == 'multiselect';
SET is_invalid = 0;
ELSE;
#undef values are "special"
IF cur_settings.type == 'number' && !formatted_value.length;
SET formatted_value = UNDEF;
SET is_invalid = 0;
END;
IF formatted_value.defined();
TRY;
SET is_invalid = cur_settings.exists( 'checkval' )
&& ref( \cur_settings.checkval ) == 'CODE'
&& ! cur_settings.only_validate_on_change
&& ! cur_settings.checkval( formatted_value ).defined();
CATCH;
SET is_invalid = 1;
END;
ELSE;
#if undef but setting can't disable, then that's invalid
SET is_invalid = !cur_settings.can_undef;
END;
END;
IF is_invalid;
SET tclass = tclass _ ' invalid';
END;
SET range_html = [];
IF cur_settings.exists('minimum');
SET minimum = cur_settings.minimum;
# If a special formatter is being applied to the displayed value, the same
# needs to be done to the displayed minimum, if any.
IF cur_settings.exists( 'format' ) && ref( \cur_settings.format ) == 'CODE';
minimum = cur_settings.format( minimum );
END;
range_html.push( locale.maketext('Minimum: [numf,_1]',minimum) );
END;
IF cur_settings.exists('maximum');
SET maximum = cur_settings.maximum;
IF cur_settings.exists( 'format' ) && ref( \cur_settings.format ) == 'CODE';
maximum = cur_settings.format( maximum );
END;
range_html.push( locale.maketext('Maximum: [numf,_1]',maximum) );
END;
SET range_html = ( range_html.size > 0 )
? ' (' _ range_html.join('; ') _ ')'
: UNDEF
;
SET newoption_html = '';
IF newoption;
SET newoption_html = ' ';
END;
SET cur_help = cur_texts.help || cur_settings.help;
IF tweakcfg.display_label;
IF !cur_help;
SET display_html = "
${newoption_html}${cur_label}${range_html}
";
ELSIF tweakcfg.always_show_help;
SET display_html = "
'
;
END;
ELSE;
# Adding an alert warning to inform users that their website stats are not available because of
# the 'common' setting as LOGSTYLE.
IF key == "LOGSTYLE" && formatted_value == "common";
SET common_setting_warning =
"
"
_ locale.maketext("Your “[_1]” uses the “[_2]” setting. Your website’s stats may not function.", "LOGSTYLE", "COMMON")
_ "
";
SET display_html = common_setting_warning _ cur_help;
ELSE;
SET display_html = cur_help _ range_html;
END;
END;
"
';
FOR opt = cur_settings.options;
SET checked_html = conf.$key.$opt ? 'checked="checked"' : '';
# NB: If every option is hidden then the user will see
# no controls, which is awkward. If that’s ever a
# possibility, we’ll need to make this smarter.
IF cur_settings.hidden.grep("$opt").size();
IF checked_html;
"";
END;
NEXT;
ELSE;
SET label = cur_texts.optionlabels.$opt || cur_settings.optionlabels.$opt || opt;
IF cur_settings.default.$opt;
label = label _ " default";
END;
IF cur_settings.pci.$opt;
label = label _ " PCI Recommended";
END;
" ";
END;
END;
'
';
CASE [ 'select', 'locale' ];
IF cur_settings.sorter;
SET select_options = cur_settings.sorter( cur_settings.options );
ELSE;
SET select_options = cur_settings.options.sort();
END;
SET cur_option_in_options = 0;
SET select_html = "';
select_html = select_html _ '
';
IF cur_settings.exists('default');
IF cur_settings.type == 'locale';
SET cur_default = locale.get_locale_name(cur_settings.default);
ELSE;
SET cur_default = cur_settings.default;
END;
select_html = select_html _ ' ' _ locale.maketext('System Default: [_1]',cur_default);
END;
IF cur_settings.exists('pci');
select_html = select_html _ ' ' _ locale.maketext('PCI Recommendation: [_1]',cur_settings.pci);
END;
select_html = select_html _ '
';
SET use_radio_buttons = cur_settings.allow_other;
IF use_radio_buttons;
"";
'
'; #weird hack to achieve centering...
"
";
"
"
_ "'
_ select_html
_ '
'
;
IF cur_settings.exists('maxlength') && cur_settings.maxlength;
SET input_size = " size='${cur_settings.maxlength}'";
ELSIF cur_settings.exists('width') && cur_settings.width;
SET input_size = " size='${cur_settings.width}'";
ELSE;
SET input_size = '';
END;
"