Show
Ignore:
Timestamp:
05/30/08 02:23:26 (18 months ago)
Author:
bchoate
Message:

Updates to optimize recently_commented_on, category and tag attributes for Entries tag - BugId:79914. Search app can now supply user state - BugId:79906. Fix for 2-digit year bug - BugId:79924

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/release-39/lib/MT/App/Comments.pm

    r2425 r2463  
    2424    $app->SUPER::init(@_) or return; 
    2525    $app->add_methods( 
    26         login            => \&login, 
     26        login            => \&login_form, 
    2727        login_external   => \&login_external, 
    2828        do_login         => \&do_login, 
     
    9191 
    9292sub load_core_tags { 
    93     return { 
    94         function => { 
    95             UserSessionState => \&_hdlr_user_session_state, 
    96         }, 
    97     }; 
     93    return {}; 
    9894} 
    9995 
     
    109105sub _get_commenter_session { 
    110106    my $app = shift; 
    111     my $q   = $app->param; 
    112  
    113     my $session_key; 
    114  
    115     my $blog = $app->blog; 
    116     if ($blog) { 
    117         my $auths = $blog->commenter_authenticators || ''; 
    118         if ( $auths =~ /MovableType/ ) { 
    119             # First, check for a real MT user login. If one exists, 
    120             # return that as the commenter identity 
    121             my ($user, $first_time) = $app->SUPER::login(); 
    122             if ( $user ) { 
    123                 my $sess = $app->session; 
    124                 return ( $sess, $user ); 
    125             } 
    126         } 
    127     } 
    128  
    129     my %cookies = $app->cookies(); 
    130     my $cookie_name = $app->commenter_cookie; 
    131     if ( !$cookies{$cookie_name} ) { 
    132         return ( undef, undef ); 
    133     } 
    134     $session_key = $cookies{$cookie_name}->value() || ""; 
    135     $session_key =~ y/+/ /; 
    136     my $cfg = $app->config; 
    137     require MT::Session; 
    138     my $sess_obj = MT::Session->load( { id => $session_key, kind => 'SI' } ); 
    139     my $timeout = $cfg->CommentSessionTimeout; 
    140     my $user_id = $sess_obj->get('author_id') if $sess_obj; 
    141     my $user = MT::Author->load( $user_id ) if $user_id; 
    142  
    143     if (   !$sess_obj 
    144         || ( $sess_obj->start() + $timeout < time ) 
    145         || ( !$user_id ) 
    146         || ( !$user ) 
    147       ) 
    148     { 
    149         $app->_invalidate_commenter_session( \%cookies ); 
    150         return ( undef, undef ); 
    151     } 
    152  
    153     # session is valid! 
    154     return ( $sess_obj, $user ); 
    155 } 
    156  
    157 sub login { 
     107    return $app->get_commenter_session(); 
     108} 
     109 
     110sub login_form { 
    158111    my $app   = shift; 
    159112    my %param = @_; 
     
    14221375    my $static = $q->param('static') || $q->param('return_url') || ''; 
    14231376 
    1424     if ( ($static eq '') || ($static eq 1) ) { 
     1377    if ( ($static eq '') || ($static eq '1') ) { 
    14251378        require MT::Entry; 
    14261379        my $entry = MT::Entry->load( $q->param('entry_id') || 0 ) 
    14271380            or return $app->error($app->translate('Can\'t load entry #[_1].', $q->param('entry_id'))); 
    14281381        $target = $entry->archive_url; 
    1429         my $blog = MT::Blog->load( $entry->blog_id ); 
    1430         $target = MT::Util::strip_index( $target, $blog ); 
    14311382    } 
    14321383    elsif ($static ne '') { 
     
    14471398} 
    14481399 
    1449 sub session_state { 
    1450     my $app = shift; 
    1451     my $blog = $app->blog; 
    1452     my $blog_id = $blog->id if $blog; 
    1453  
    1454     my $c; 
    1455     if ( $blog_id && $blog ) { 
    1456         my ( $sessobj, $commenter ) = $app->_get_commenter_session(); 
    1457         if ( $sessobj && $commenter ) { 
    1458             my $blog_perms = $commenter->blog_perm($blog_id); 
    1459             my $banned = $commenter->is_banned($blog_id) ? "1" : "0"; 
    1460             $banned = 0 if $blog_perms && $blog_perms->can_administer; 
    1461             $banned ||= 1 if $commenter->status == MT::Author::BANNED(); 
    1462  
    1463             if ($banned) { 
    1464                 $sessobj->remove; 
    1465             } else { 
    1466                 $sessobj->start( time + 
    1467                     $app->config->CommentSessionTimeout); # extend by timeout 
    1468                 $sessobj->save(); 
    1469             } 
    1470  
    1471             # FIXME: These may not be accurate in 'SingleCommunity' mode... 
    1472             my $can_comment = $banned ? 0 : 1; 
    1473             $can_comment = 0 unless $blog->allow_unreg_comments || $blog->allow_reg_comments; 
    1474             my $can_post = ($blog_perms && $blog_perms->can_create_post) ? "1" : "0"; 
    1475             $c = { 
    1476                 sid => $sessobj->id, 
    1477                 name => $commenter->nickname, 
    1478                 url => $commenter->url, 
    1479                 email => $commenter->email, 
    1480                 userpic => scalar $commenter->userpic_url, 
    1481                 profile => "", # profile link url 
    1482                 is_authenticated => "1", 
    1483                 is_trusted => ($commenter->is_trusted($blog_id) ? "1" : "0"), 
    1484                 is_author => ($commenter->type == MT::Author::AUTHOR() ? "1" : "0"), 
    1485                 is_anonymous => "0", 
    1486                 is_banned => $banned, 
    1487                 can_comment => $can_comment, 
    1488                 can_post => $can_post, 
    1489             }; 
    1490         } 
    1491     } 
    1492  
    1493     unless ($c) { 
    1494         my $can_comment = $blog && $blog->allow_anon_comments ? "1" : "0"; 
    1495         $c = { 
    1496             is_authenticated => "0", 
    1497             is_trusted => "0", 
    1498             is_anonymous => "1", 
    1499             can_post => "0", # no anonymous posts 
    1500             can_comment => $can_comment, 
    1501             is_banned => "0", 
    1502         }; 
    1503     } 
    1504  
    1505     return $c; 
    1506 } 
    1507  
    15081400sub session_js { 
    15091401    my $app = shift; 
     
    15201412    $app->print("$jsonp(" . $json . ");\n"); 
    15211413    return undef; 
    1522 } 
    1523  
    1524 sub _hdlr_user_session_state { 
    1525     my ($ctx, $args, $cond) = @_; 
    1526     my $state = MT->app->session_state(); 
    1527     require JSON; 
    1528     my $json = JSON::objToJson($state); 
    1529     return $json; 
    15301414} 
    15311415