LJSUP-17669: Login.bml form refactoring
[livejournal.git] / cgi-bin / LJ / Setting / SafeSearch.pm
blob0bef53633eef8bae36fad903723506b5ee2f3f7d
1 package LJ::Setting::SafeSearch;
2 use base 'LJ::Setting';
3 use strict;
4 use warnings;
6 sub should_render {
7 my ($class, $u) = @_;
9 return !LJ::is_enabled("content_flag") || !LJ::is_enabled("safe_search") || !$u || $u->is_community ? 0 : 1;
12 sub helpurl {
13 my ($class, $u) = @_;
15 return "adult_content_full";
18 sub label {
19 my $class = shift;
21 return $class->ml('setting.safesearch.label');
24 sub option {
25 my ($class, $u, $errs, $args) = @_;
26 my $key = $class->pkgkey;
28 my $safesearch = $class->get_arg($args, "safesearch") || $u->safe_search;
30 my $ret;
32 if ( LJ::is_enabled('remove_adult_concepts') ) {
34 $ret = LJ::html_check({
35 name => "${key}safesearch",
36 id => "${key}safesearch",
37 value => '20',
38 selected => $safesearch eq '20' ? 1 : 0,
39 });
41 $ret .= "<label for='${key}safesearch'>" . $class->ml('setting.safesearch.option') . "</label> ";
43 } else {
45 my @options = (
46 none => $class->ml('setting.safesearch.option.select.none'),
47 10 => $class->ml('setting.safesearch.option.select.explicit'),
48 20 => $class->ml('setting.safesearch.option.select.concepts'),
51 $ret = LJ::html_select({
52 name => "${key}safesearch",
53 selected => $safesearch,
54 }, @options);
56 my $errdiv = $class->errdiv($errs, "safesearch");
57 $ret .= "<br />$errdiv" if $errdiv;
60 return $ret;
63 sub error_check {
64 my ($class, $u, $args) = @_;
65 my $val = $class->get_arg($args, "safesearch");
67 $class->errors( safesearch => $class->ml('setting.safesearch.error.invalid') )
68 unless $val eq "none" || $val =~ /^\d+$/;
70 return 1;
73 sub save {
74 my ($class, $u, $args) = @_;
76 my $val;
78 if ( LJ::is_enabled('remove_adult_concepts') ) {
80 $val = $class->get_arg($args, "safesearch") ? '20' : 'none';
82 } else {
83 $class->error_check($u, $args);
85 $val = $class->get_arg($args, "safesearch");
88 $u->set_prop( safe_search => $val );
90 return 1;