App-ZofCMS

 view release on metacpan or  search on metacpan

lib/App/ZofCMS/Plugin/StartPage.pm  view on Meta::CPAN

                is_selected => $is_redirect_page,
            };
        }
    }

    $conf->{pages}       = \@proper_pages;
    $conf->{valid_pages} = \%valid_pages;
}

sub make_form {
    my $self = shift;
    my $conf = $self->{CONF};

    my $template = HTML::Template->new_scalar_ref(
        \ form_html_template(),
        die_on_bad_params => 0,
    );

    $template->param(
        ( $conf->{save_settings_ok} ? ( save_success => 1 ) : () ),
        page          => $self->{Q_PAGE},
        pages         => $conf->{pages},
        submit_button => $conf->{submit_button},
        label_text    => $conf->{label_text},
    );

    return $template->output;
}


sub dbh {
    my $self = shift;

    return $self->{DBH}
        if $self->{DBH};

    $self->{DBH} = DBI->connect_cached(
        @{ $self->{CONF} }{ qw/dsn user pass opt/ },
    );

    return $self->{DBH};
}

sub has_value {
    my $v = shift;

    return 1
        if defined $v and length $v;

    return 0;
}

sub form_html_template {
    return <<'END_HTML';
<tmpl_if name='save_success'>
    <p class="success-message">Successfully saved</p>
</tmpl_if>
<form action="" method="POST" id="plug_start_page_form">
<div>
    <input type="hidden" name="page"
        value="<tmpl_var escape='html' name='page'>">
    <input type="hidden" name="plugsp_save_settings" value="1">

    <label for="plugsp_page"><tmpl_var escape='html'
        name='label_text'></label
    ><select id="plugsp_page" name="plugsp_page"
    ><tmpl_loop name='pages'>
        <option value="<tmpl_var escape='html' name='page'>"
            <tmpl_if name='is_selected'>selected</tmpl_if>
        ><tmpl_var escape='html' name='name'></option>
    </tmpl_loop>

    <tmpl_var name="submit_button">
</div>
</form>
END_HTML
}

1;
__END__

=encoding utf8

=head1 NAME

App::ZofCMS::Plugin::StartPage - ZofCMS plugin that redirects the user to a page choosen by the user

=head1 SYNOPSIS

In L<HTML::Template> template:

    <tmpl_var name='plug_start_page_form'>

In ZofCMS Template:

    plugins => [ qw/StartPage/ ],

    plug_start_page => {
        pages => [
            'http://google.ca/'             => 'Google',
            'http://zoffix.com/'            => 'Zoffix Znet Portal',
            'http://mind-power-book.com/'   => 'Mind Power Book',
        ],

        # everthing below is optional; default values are shown
        dsn           => "DBI:mysql:database=test;host=localhost",
        user          => '',
        pass          => undef,
        opts          => { RaiseError => 1, AutoCommit => 1 },
        no_redirect   => undef,
        table         => 'users',
        login_col     => 'login',
        page_col      => 'start_page',
        login         => sub { $_[0]->{d}{user}{login} },
        label_text    => 'Start page:',
        default_page  => undef,
        submit_button => q|<input type="submit" class="input_submit"|
                            . q| value="Save">|,
    },

=head1 DESCRIPTION

The module is a plugin for L<App::ZofCMS> that provides means to present
a user a form where they can select one of several pages to which to
redirect (selection is stored in a SQL database). The module was
designed to provide means to let the users select their landing pages
upon logon, which is how the name of the module originated.

This documentation assumes you've read L<App::ZofCMS>,
L<App::ZofCMS::Config> and L<App::ZofCMS::Template>.



( run in 0.591 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )