Skip to content

Commit

Permalink
Fix to drop the ui_element API, which has never been used for real
Browse files Browse the repository at this point in the history
  • Loading branch information
iliajie committed Jul 20, 2024
1 parent e95087c commit 0a08256
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 128 deletions.
117 changes: 0 additions & 117 deletions authentic-funcs.pl
Original file line number Diff line number Diff line change
Expand Up @@ -53,123 +53,6 @@ sub ui_button_group_local
return $rv;
}

sub ui_element
{
my ($e, $c) = @_;

# Allowed elements to use 'type' attr
if ($e =~ /^(a|button|embed|input|link|menu|object|script|source|style)$/) {

# Set default `type` for common elements
if ($e eq 'input') {
$c->{'type'} = "text" if (!$c->{'type'});
} elsif ($e eq 'button') {
$c->{'type'} = "button" if (!$c->{'type'});
}
$c->{'type'} = " type=\"@{[quote_escape($c->{'type'})]}\"" if ($c->{'type'});
} else {
delete $c->{'type'};
}

# Allowed elements to use 'name' attr
if ($e =~ /^(button|fieldset|form|iframe|input|map|meta|object|output|param|select|textarea)$/) {
$c->{'name'} = " name=\"@{[quote_escape($c->{'name'})]}\"" if ($c->{'name'});
} else {
delete $c->{'name'};
}

# Allowed elements to use 'value' attr
if ($e =~ /^(button|input|meter|li|option|progress|param)$/) {
$c->{'value'} = " value=\"@{[quote_escape($c->{'value'})]}\"" if ($c->{'value'});
} else {
delete $c->{'value'};
}

# Trigger `autofocus` or remove it
if ($e =~ /^(button|input|select|textarea)$/) {
if ($c->{'autofocus'} =~ /^(false|0)$/) {
delete $c->{'autofocus'};
}

# If element is empty trigger autofocus
elsif ($e =~ /input|textarea/ && !$c->{'value'}) {
$c->{'autofocus'} = " autofocus";
}
}

# Set default `class` for common elements
if (!$c->{'class'}) {
my $c_;
if ($e eq 'input') {
$c_ = "form-control";
if ($c->{'type'} =~ /password/) {
$c_ .= " ui_password";
} else {
$c_ .= " ui_textbox";
}
} elsif ($e eq 'textarea') {
$c_ = "form-control ui_textarea";
}
$c->{'class'} = " class=\"$c_\"";
} else {
$c->{'class'} = " class=\"@{[quote_escape($c->{'class'})]}\"";
}

# Collect all other independent attributes
my $attrs;
foreach my $attr (keys %{$c}) {
if ($attr ne "class" &&
$attr ne "value" &&
$attr ne "name" &&
$attr ne "type")
{

# Parse and add data attributes passed as reference
if ($attr eq "data") {
if (ref($c->{$attr})) {
foreach my $dattr (keys %{ $c->{$attr} }) {
$attrs .= " data-$dattr=\"@{[quote_escape($c->{$attr}->{$dattr})]}\"";
}
}

# Add all other attributes to the tag
} else {
$attrs .= " $attr=\"@{[quote_escape($c->{$attr})]}\"";
}
}
}

# Check if a tag must be closed
my $e_c;
if ($e !~ /^(area|base|br|hr|input|link|meta|param|source|circle|track|wbr)$/) {
$e_c = "</$e>";
}
return "<$e$c->{'type'}$c->{'name'}$c->{'value'}$c->{'class'}$attrs>@{[html_escape($c->{'_'})]}$e_c\n";
}

sub ui_input
{
my ($c, $v, $s, $d, $m, $t) = @_;

# If old type input used, support it as well
if (!ref($c)) {
$c = { 'name' => $c,
'value' => $v,
'size' => $s };
$c->{'disabled'} = "true" if ($d);
$c->{'maxlength'} = $m if ($m);
if ($t) {
my @t = split(/\s+/, $t);
foreach my $t (@t) {
my ($t, $v) = ($t =~ /(.*?)=(.*)/);
$v =~ s/^("|')|("|')$//g;
$c->{$t} = "@{[quote_escape($v)]}";
}
}
}
return ui_element('input', $c);
}

sub ui_span_local
{
my ($data, $extra_class) = @_;
Expand Down
8 changes: 5 additions & 3 deletions authentic.pl
Original file line number Diff line number Diff line change
Expand Up @@ -674,14 +674,16 @@ sub theme_ui_form_end

sub theme_ui_textbox
{
my ($name, $value, $size, $dis, $max, $tags) = @_;
my ($name, $value, $size, $dis, $max, $tags, $class, $nostyle) = @_;
my $rv;

my $ids;
$ids = "_i_$main::ui_textbox_tcalled" if ($main::ui_textbox_tcalled++);

$class = $class ? " $class" : "";
my $style = ' style="display: inline; width: auto; max-width: 100%; height: 28px; padding-top: 0; padding-bottom: 2px; vertical-align: middle"';
$style = '' if ($nostyle);
$rv .=
'<input style="display: inline; width: auto; max-width: 100%; height: 28px; padding-top: 0; padding-bottom: 2px; vertical-align: middle" class="form-control ui_textbox" type="text" ';
"<input$style class=\"form-control ui_textbox$class\" type=\"text\" ";
$rv .= 'id="' . &quote_escape($name . $ids) . '" ';
$rv .= 'name="' . &quote_escape($name) . '" ';
$rv .= 'value="' . &quote_escape($value) . '" ';
Expand Down
12 changes: 4 additions & 8 deletions session_login.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,10 @@ if ($in{'twofactor_msg'} && $miniserv{'twofactor_provider'}) {
} else {
print '<p class="form-signin-paragraph">' . &theme_text('login_message') . '<strong> ' . $host . '</strong></p>' . "\n";
print '<div class="input-group form-group">' . "\n";
print ui_input(
{ 'name' => 'user',
'value' => $in{"failed"},
'class' => 'form-control session_login',
"autocomplete" => $gconfig{'noremember'} ? "off" : "username",
"autocorrect" => "off",
"autocapitalize" => "none",
"placeholder" => $theme_text{'theme_xhred_login_user'} });
my $autocomplete = $gconfig{'noremember'} ? "off" : "username";
print &ui_textbox("user", $in{'failed'}, 20, 0, undef,
"autocomplete='$autocomplete' autocorrect='off' autocapitalize='none' ".
"placeholder='$theme_text{'theme_xhred_login_user'}'", 'session_login', 1);

print '<span class="input-group-addon"><i class="fa fa-fw fa-user"></i></span>' . "\n";
print '</div>' . "\n";
Expand Down

0 comments on commit 0a08256

Please sign in to comment.