Changeset 2377

Show
Ignore:
Timestamp:
05/17/08 06:31:00 (6 months ago)
Author:
bchoate
Message:

Fix for setting user context for comment previews. BugId:79757

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/release-38/default_templates/comment_preview.mtml

    r2313 r2377  
    33<html xmlns="http://www.w3.org/1999/xhtml" id="sixapart-standard"> 
    44<head> 
    5     <$mt:include module="<__trans phrase="HTML Head">"$> 
    6     <title><$MTBlogName encode_html="1"$>: <__trans phrase="Previewing your Comment"></title> 
    75    <script type="text/javascript"> 
    86    /* <![CDATA[ */ 
     7    var user = <$MTUserSessionState$>; 
    98    var is_preview = true; 
    109    /* ]]> */ 
    1110    </script> 
     11    <$mt:include module="<__trans phrase="HTML Head">"$> 
     12    <title><$MTBlogName encode_html="1"$>: <__trans phrase="Previewing your Comment"></title> 
    1213</head> 
    1314<body id="<$mt:BlogTemplateSetID$>" class="mt-comment-preview <$MTVar name="page_layout"$>" onload="mtEntryOnLoad()"> 
  • branches/release-38/default_templates/javascript.mtml

    r2375 r2377  
    779779     */ 
    780780    </mt:Ignore> 
    781     if ( is_preview
     781    if ( is_preview && !user
    782782        mtFetchUser(); 
    783783} 
  • branches/release-38/lib/MT/App/Comments.pm

    r2373 r2377  
    8888        $app->mode('generate_captcha'); 
    8989    } 
     90} 
     91 
     92sub load_core_tags { 
     93    return { 
     94        function => { 
     95            UserSessionState => \&_hdlr_user_session_state, 
     96        }, 
     97    }; 
    9098} 
    9199 
     
    14301438} 
    14311439 
    1432 sub session_js { 
    1433     my $app = shift; 
    1434     my $blog_id = int($app->param('blog_id')); 
    1435     my $blog = MT::Blog->load( $blog_id ) if $blog_id; 
    1436     my $jsonp = $app->param('jsonp'); 
    1437     $jsonp = undef if $jsonp !~ m/^\w+$/; 
    1438     return $app->error("Invalid request.") unless $jsonp; 
     1440sub session_state { 
     1441    my $app = shift; 
     1442    my $blog = $app->blog; 
     1443    my $blog_id = $blog->id if $blog; 
    14391444 
    14401445    my $c; 
     
    14791484 
    14801485    unless ($c) { 
    1481         my $can_comment = $blog->allow_anon_comments ? "1" : "0"; 
     1486        my $can_comment = $blog && $blog->allow_anon_comments ? "1" : "0"; 
    14821487        $c = { 
    14831488            is_authenticated => "0", 
     
    14901495    } 
    14911496 
     1497    return $c; 
     1498} 
     1499 
     1500sub session_js { 
     1501    my $app = shift; 
     1502    my $jsonp = $app->param('jsonp'); 
     1503    $jsonp = undef if $jsonp !~ m/^\w+$/; 
     1504    return $app->error("Invalid request.") unless $jsonp; 
     1505 
     1506    my $state = $app->session_state; 
     1507 
    14921508    require JSON; 
    14931509    $app->{no_print_body} = 1; 
    14941510    $app->send_http_header("text/javascript"); 
    1495     my $json = JSON::objToJson($c); 
     1511    my $json = JSON::objToJson($state); 
    14961512    $app->print("$jsonp(" . $json . ");\n"); 
    14971513    return undef; 
     1514} 
     1515 
     1516sub _hdlr_user_session_state { 
     1517    my ($ctx, $args, $cond) = @_; 
     1518    my $state = MT->app->session_state(); 
     1519    require JSON; 
     1520    my $json = JSON::objToJson($state); 
     1521    return $json; 
    14981522} 
    14991523 
     
    18391863        return undef unless $entry; 
    18401864        $app->{_blog} = $entry->blog if $entry; 
     1865    } elsif ( my $blog_id = $app->param('blog_id') ) { 
     1866        $app->{_blog} = MT::Blog->load( int($blog_id) ); 
    18411867    } 
    18421868    return $app->{_blog}; 
  • branches/release-38/lib/MT/Core.pm

    r2245 r2377  
    535535            'upgrade'  => { handler => 'MT::App::Upgrade', }, 
    536536            'wizard'   => { handler => 'MT::App::Wizard', }, 
    537             'comments' => { handler => 'MT::App::Comments', }, 
     537            'comments' => { 
     538                handler => 'MT::App::Comments', 
     539                tags => sub { MT->app->load_core_tags }, 
     540            }, 
    538541            'search'   => { 
    539542                handler => 'MT::App::Search::Legacy',  
  • branches/release-38/lib/MT/Template/ContextHandlers.pm

    r2371 r2377  
    511511            SearchIncludeBlogs => sub { '' }, 
    512512            SearchTemplateID => sub { 0 }, 
     513 
     514            UserSessionState => sub { 'null' }, 
    513515 
    514516            BuildTemplateID => \&_hdlr_build_template_id,