Add function to validate style, s2id, and format args and then pass
them back in a ready to use URL form.
Patch by afuna.
diffs (31 lines):
diff -r 8d0176156a61 -r 19b03e6b9ecd cgi-bin/weblib.pl
--- a/cgi-bin/weblib.pl Mon Oct 26 02:57:10 2009 +0000
+++ b/cgi-bin/weblib.pl Mon Oct 26 03:02:28 2009 +0000
@@ -993,6 +993,27 @@ sub set_lastcomment
sub deemp {
"<span class='de'>$_[0]</span>";
+}
+
+=head2 C<< LJ::viewing_style_args( %arguments ) >>
+Takes a list of viewing styles arguments from a list, makes sure they are
valid values,
+and returns them as a string that can be appended to the URL. Looks for
"s2id", "format", "style"
+=cut
+sub viewing_style_args {
+ my ( %args ) = @_;
+ my $valid_style_args = {
+ format => { light => 1 },
+ style => { light => 1, style => 1, site => 1, mine => 1 },
+ };
+
+ my @valid_args;
+ # only accept purely numerical s2ids
+ push @valid_args, "s2id=$args{s2id}" if $args{s2id} && $args{s2id} =~
/^\d+$/;
+
+ foreach my $key ( qw( format style ) ) {
+ push @valid_args, "style=$args{$key}" if
$valid_style_args->{$key}->{$args{$key}};
+ }
+ return join "&", @valid_args;
}
# <LJFUNC>
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog