~ubuntu-branches/debian/squeeze/movabletype-opensource/squeeze

« back to all changes in this revision

Viewing changes to lib/MT/App/Comments.pm

  • Committer: Bazaar Package Importer
  • Author(s): Dominic Hargreaves
  • Date: 2009-10-06 22:09:27 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20091006220927-qusoqt9vtm3fgtgr
Tags: 4.3.2-1
New upstream release (closes: #544206)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
# This program is distributed under the terms of the
3
3
# GNU General Public License, version 2.
4
4
#
5
 
# $Id: Comments.pm 3742 2009-05-26 15:13:38Z jmarcotte $
 
5
# $Id: Comments.pm 4075 2009-07-23 15:22:27Z plim $
6
6
 
7
7
package MT::App::Comments;
8
8
use strict;
44
44
        recover          => \&recover,
45
45
        new_pw           => \&new_pw,
46
46
 
 
47
        comment_listing    => \&comment_listing,
 
48
 
47
49
        # deprecated
48
50
        cmtr_name_js   => \&commenter_name_js,
49
51
        cmtr_status_js => \&commenter_status_js,
889
891
        $app->translate( "An error occurred: [_1]", $app->errstr() ) )
890
892
        unless $comment;
891
893
 
892
 
    $app->run_callbacks( 'api_post_save.comment', $app, $comment, $commenter );
893
 
    
894
894
    my $remember = $q->param('bakecookie') || 0;
895
895
    $remember = 0 if $remember eq 'Forget Info';    # another value for '0'
896
896
    if ( $commenter && $remember ) {
974
974
        }
975
975
        );
976
976
    if ( $comment->id && !$comment->is_junk ) {
 
977
        
 
978
        $app->run_callbacks( 'api_post_save.comment', $app, $comment, $commenter );
 
979
        
977
980
        $app->log(
978
981
            {   message => $app->translate(
979
982
                    'Comment on "[_1]" by [_2].', $entry->title,
1473
1476
    return undef;
1474
1477
}
1475
1478
 
 
1479
sub comment_listing {
 
1480
    my ($app) = shift;
 
1481
    $app->{no_print_body} = 1;
 
1482
    $app->response_code(200);
 
1483
    $app->response_message('OK');
 
1484
    $app->send_http_header('text/javascript');
 
1485
 
 
1486
    require MT::Entry;
 
1487
    require MT::Comment;
 
1488
    require MT::Template;
 
1489
    require MT::Template::Context;
 
1490
 
 
1491
    my $entry_id = $app->param('entry_id');
 
1492
    return '1;' if ( !$entry_id );
 
1493
    my $entry = MT::Entry->load($entry_id);
 
1494
    return '1;' if ( !$entry );
 
1495
    my $offset = $app->param('offset');
 
1496
    $offset ||= 0;
 
1497
 
 
1498
    if ( $offset !~ /^\d+$/ ) {
 
1499
        $offset = 0;
 
1500
    }
 
1501
    my $limit = $app->param('limit');
 
1502
    $limit ||= 100;
 
1503
    if ( $limit !~ /^\d+$/ ) {
 
1504
        $limit = 100;
 
1505
    }
 
1506
    my $direction = 'ascend';
 
1507
    if ( $app->param('direction') eq 'descend' ) {
 
1508
        $direction = 'descend';
 
1509
    }
 
1510
    my $method = $app->param('method');
 
1511
    $method ||= 'displayComments';
 
1512
    my $tmpl = MT::Template->load(
 
1513
        {   name    => 'Comment Listing',
 
1514
            blog_id => $entry->blog_id
 
1515
        }
 
1516
    );
 
1517
    return '1;' if ( !$tmpl );
 
1518
    my $total = MT::Comment->count( { entry_id => $entry_id, visible => 1 } );
 
1519
    my @comments = MT::Comment->load( { entry_id => $entry_id, visible => 1 },
 
1520
        { limit => $limit, offset => $offset, direction => $direction } );
 
1521
    my $ctx = MT::Template::Context->new;
 
1522
    $ctx->stash( 'entry',    $entry );
 
1523
    $ctx->stash( 'entry_id', $entry->id );
 
1524
    $ctx->stash( 'comments', \@comments );
 
1525
    $ctx->var( 'commentTotal',     $total );
 
1526
    $ctx->var( 'commentLimit',     $limit );
 
1527
    $ctx->var( 'commentOffset',    $offset );
 
1528
    $ctx->var( 'commentDirection', $direction );
 
1529
    $app->print( $tmpl->build($ctx) );
 
1530
    return 1;
 
1531
}
 
1532
 
 
1533
 
1476
1534
# deprecated
1477
1535
sub _commenter_status {
1478
1536
    my $app              = shift;