Changeset 1250

Show
Ignore:
Timestamp:
11/15/08 18:09:47 (16 months ago)
Author:
bsmith
Message:

Adding two new scoring options:
1. FavTog - A toggle for favoriting
2. Follow - A toggle for Following another user

Location:
trunk/Score
Files:
4 added
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/Score/mt-static/plugins/Score/score_base.js

    r1221 r1250  
    1919    if (!xh) return false; 
    2020    DOM.addClassName( el, pending ); 
    21     var url = commentScript + '?__mode=' + ns + '_score&static=1&entry_id=' + obj_id + '&score=' + score; 
     21    var url = blogSettings.commentScript + '?__mode=' + ns + '_score&static=1&entry_id=' + obj_id + '&score=' + score; 
    2222    xh.open('POST', url, true); 
    2323    xh.onreadystatechange = function() { 
  • trunk/Score/plugins/Score/config.yaml

    r1221 r1250  
    11id: score 
    22name: Score 
    3 version: 0.1 
     3version: 0.2 
    44description: Scoring framework for  
    55author_name: Beau Smith; Fumiaki Yoshimatsu 
     
    1212            fivestar_score: $Score::Score::App::score_fivestar 
    1313            favorite_score: $Score::Score::App::score_favorite 
     14            favtog_score: $Score::Score::App::score_favtog 
    1415 
    1516tags: 
     
    1920        FiveStarScore: $Score::Score::Tag::_hdlr_five_star_score 
    2021        FavoriteScore: $Score::Score::Tag::_hdlr_favorite_score 
     22        FavTogCount: $Score::Score::Tag::_hdlr_favtog_count 
     23        FavTogScore: $Score::Score::Tag::_hdlr_favtog_score 
    2124 
    2225# TODO 
  • trunk/Score/plugins/Score/lib/Score/App.pm

    r1221 r1250  
    2727    require JSON; 
    2828    $app->print("dugScoreResponse($entry_id,$count);"); 
     29    return undef; 
     30} 
     31 
     32sub score_favtog { 
     33    my $app = shift; 
     34    my $q = $app->param; 
     35    my ( $sess_obj, $commenter ) = $app->get_commenter_session(); 
     36    # return $app->redirect_to_target unless $commenter && ( 'MT::Author' eq ref($commenter) ); 
     37 
     38    my $entry_id = $q->param('entry_id') 
     39      or return $app->handle_error( 
     40        $app->translate( 'Entry ID is missing.' ) ); 
     41    my $entry = $app->model('entry')->load($entry_id) 
     42      or return $app->handle_error( 
     43        $app->translate( 'Entry is missing.' ) ); 
     44    my $score = defined $q->param('score') 
     45      ? $q->param('score') 
     46      : 1; 
     47 
     48    $entry->set_score( 'favtog', $commenter, $score, 1 ); 
     49    my $sum = $entry->score_for( 'favtog' ); 
     50 
     51    $app->rebuild_entry( Entry => $entry_id, PreferredArchiveOnly => 1, BuildIndexes => 1 ) 
     52      or return $app->handle_error( 
     53        $app->translate( "Publish failed: [_1]", $app->errstr ) ); 
     54 
     55    $app->send_http_header("text/javascript+json"); 
     56    $app->{no_print_body} = 1; 
     57    require JSON; 
     58    $app->print("$sum"); 
    2959    return undef; 
    3060} 
  • trunk/Score/plugins/Score/lib/Score/Tag.pm

    r1221 r1250  
    1919    my $html = <<HTML; 
    2020<a href="javascript:void(0)" id="dug$id" onclick="dugScore('$id');">$score</a> 
     21HTML 
     22    return $html; 
     23} 
     24 
     25 
     26sub _hdlr_favtog_count { 
     27    my ( $ctx, $args ) = @_; 
     28    my $entry = $ctx->stash('entry') 
     29        or return $ctx->_no_entry_error(); 
     30    my $count = $entry->votes_for( 'FavTogScore' ); 
     31    return $ctx->count_format($count, $args); 
     32} 
     33 
     34sub _hdlr_favtog_score { 
     35    my ( $ctx, $args ) = @_; 
     36    my $tag = $args->{tag} || 'span'; 
     37    my $class = $args->{class} || ''; 
     38    $class = ' ' . $class if $class; 
     39    my $entry = $ctx->stash('entry') 
     40        or return $ctx->_no_entry_error(); 
     41    # my $score = $entry->votes_for( 'FavTogScore' ); 
     42    my $id = $entry->id; 
     43    my $html = <<HTML; 
     44<$tag id="favtog$id" class="favtog$class">favorite</$tag> 
    2145HTML 
    2246    return $html; 
  • trunk/Score/tutorial.markdown

    r1221 r1250  
    6666                    Scoring 
    6767 
    68 2. Update the header template with the JavaScript code to set a few variables and link to the base scoring functions. 
     682. Set a few variables and link to the base scoring functions. If these variables my already exist in the blog's javascript file, you only need to link to the scripts in the header. 
    6969 
    7070        <script type="text/javascript"> 
    71             var staticWebPath = "<$mt:StaticWebPath$>"; 
    72             var commentScript = "<$mt:CGIPath$><$mt:CommentScript$>"; 
     71            var blogSettings = { 
     72                commentScript: '<$mt:CGIPath$><$mt:CommentScript$>', 
     73                staticWebPath: <$mt:StaticWebPath$>" 
     74            }; 
    7375        </script> 
    7476        <script type="text/javascript" src="<$mt:StaticWebPath$>plugins/Score/score_base.js"></script>