App-ZofCMS

 view release on metacpan or  search on metacpan

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

    for ( $name, $email, $comment ) {
        $_ = 'N/A'
            unless length;
    }

    $html_template->param( success => 1 );

    @$query{ @form_fields } = ( $name, $email, $comment );

    return 1;
}

sub _prepare_html_template {
    my ( $self, $comments_page, $page, $query ) = @_;
    my $html_template = HTML::Template->new_scalar_ref(
        \ $self->_form_template
    );

    $html_template->param(
        name          => $query->{zofcms_comments_name},
        email         => $query->{zofcms_comments_email},
        comment       => $query->{zofcms_comments_comment},
        page          => $page,
        comments_page => $comments_page,
        back_to_comments_page => $query->{zofcms_comments_page},
    );

    return $html_template;
}

sub _fill_defaults {
    my ( $self, $plug_conf ) = @_;
    $plug_conf = {
        'sort'          => 0,
        table           => 'comments',
        mod_table       => 'mod_comments',
        page            => '/comments',
        must_name       => 0,
        must_email      => 0,
        must_comment    => 1,
        name_max        => 100,
        email_max       => 200,
        comment_max     => 10000,
        moderate        => 1,
        send_entered    => 1,
        subject         => 'ZofCMS Comments',
        flood_num       => 2,
        flood_time      => 180,
        mod_out_time    => 1209600,
        opts            => { RaiseError => 1, AutoCommit => 1 },

        %$plug_conf,
    };
}

sub _comments_template {
    return <<'END_TEMPLATE';
<ul class="zofcms_comments">
<tmpl_loop name="comments">
    <li id="zofcms_comment_<tmpl_var name="comment_number">">
        <p class="zofcms_comments_name"><a href="#zofcms_comment_<tmpl_var name="comment_number">"><tmpl_var escape="html" name="name"></a></p>
        <p class="zofcms_comments_date"><tmpl_var escape="html" name="date"></p>
        <p class="zofcms_comments_comment"><tmpl_var name="comment"></p>
    </li>
</tmpl_loop>
</ul>
END_TEMPLATE
}

sub _form_template {
    return <<'END_TEMPLATE';
<tmpl_if name="success"><p class="success">Your comment was successfuly added.</p>
<p>Feel free to go back to the <a href="/index.pl?page=<tmpl_var name="back_to_comments_page" escape="html">">original page</a>.</p>
<tmpl_else>
<tmpl_if name="error"><p class="error"><tmpl_var name="error"></p></tmpl_if>
<form class="zofcms_comments" action="" method="POST">
<fieldset>
    <legend>Create new comment</legend>
    <input type="hidden" name="zofcms_comments_page" value="<tmpl_var name="comments_page" escape="html">">
    <input type="hidden" name="zofcms_comments_username" value="your user name">
    <input type="hidden" name="page" value="<tmpl_var escape="html"name="page">">
    <ul>
        <li>
            <label for="zofcms_comments_name">Name: </label
            ><input type="text" name="zofcms_comments_name"
            id="zofcms_comments_name" value="<tmpl_var escape="html" name="name">">
        </li>
        <li>
            <label for="zofcms_comments_email">E-mail: </label
            ><input type="text" name="zofcms_comments_email"
            id="zofcms_comments_email" value="<tmpl_var escape="html" name="email">">
        </li>
        <li>
            <label for="zofcms_comments_comment">Comment: </label
            ><textarea name="zofcms_comments_comment"
            id="zofcms_comments_comment" cols="40" rows="10"><tmpl_var name="comment" escape="html"></textarea>
        </li>
    </ul>
    <input id="zofcms_comments_submit" type="submit" value="Post">
</fieldset>
</form>
</tmpl_if>
END_TEMPLATE
}

sub _get_mail_template {
    return <<'END_MAIL_TEMPLATE';
<tmpl_if name="mod">
Approve: <tmpl_var name="approve">

Deny: <tmpl_var name="deny">

</tmpl_if>
Comment on page: <tmpl_var name="page">
From: <tmpl_var name="name"> [ <tmpl_var name="host"> ]
Time: <tmpl_var name="time">
E-mail: <tmpl_var name="email">
Comment:
<tmpl_var name="comment">
END_MAIL_TEMPLATE
}

1;
__END__

=encoding utf8

=head1 NAME

App::ZofCMS::Plugin::Comments - drop-in visitor comments support.

=head1 SYNOPSIS

In your "main config" file:

    comments_plugin => {
        dsn         => "DBI:mysql:database=test;host=localhost",
        user        => 'test',
        pass        => 'test',
        email_to    => [ 'admin@example.com', 'admin2@example.com' ],
    },

In your ZofCMS template:

    plugins => [ qw/Comments/ ],

In your "comments" page L<HTML::Template> template, which we set to be C</comments> by default:

    <tmpl_var name="zofcms_comments_form">

In any page on which you wish to have comments:

    <tmpl_var name="zofcms_comments_form">
    <tmpl_var name="zofcms_comments">

=head1 DESCRIPTION



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