Changeset 1497 for trunk/ForumUtils

Show
Ignore:
Timestamp:
03/11/09 19:53:38 (9 months ago)
Author:
breese
Message:

added support for featured entries

Location:
trunk/ForumUtils
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/ForumUtils

    • Property svn:ignore set to
      MANIFEST
      Makefile
      MANIFEST.bak
      ForumUtils-*
  • trunk/ForumUtils/MANIFEST.SKIP

    r782 r1497  
    99^blib/ 
    1010~$ 
     11^ForumUtils 
    1112 
    1213# packages 
  • trunk/ForumUtils/Makefile.PL

    r783 r1497  
    33WriteMakefile( 
    44    NAME            => 'Forum Utilities', 
    5     VERSION         => '0.91', 
     5    VERSION         => '0.92', 
    66    DISTNAME        => 'ForumUtils', 
    77); 
  • trunk/ForumUtils/mt-static/plugins/ForumUtils/css/app.css

    r768 r1497  
     1#entry-listing-table tr.selected td.featured.yes img, 
    12#comment-listing-table tr.selected td.featured.yes img {  
    23   background-image: url(../images/star-listing-on.gif);  
    34} 
     5#entry-listing-table td.featured.yes img, 
    46#comment-listing-table td.featured.yes img {  
    57   background-image: url(../images/star-listing.gif);  
    68} 
     9.featured-link span {  
     10   padding-left:20px; 
     11   background-position:4px 2px; 
     12   background-repeat:no-repeat; 
     13   background-image:url('../images/star-listing.gif'); 
     14} 
  • trunk/ForumUtils/plugins/ForumUtils/config.yaml

    r783 r1497  
    55author_name: Byrne Reese 
    66description: This plugin provides a number of utilities for forum administrators, including: a) promoting a comment to an entry, b) closing comments from the entry listing screen, and c) the ability to feature comments. 
    7 version: 0.91 
     7version: 0.92 
    88plugin_link: http://www.majordojo.com/projects/forum-utils.php 
    9 schema_version: 3 
     9schema_version: 4 
    1010 
    1111object_types: 
    1212    entry: 
    13         promoted_from_comment_id: integer 
     13        is_featured: smallint 
     14        promoted_from_comment_id: integer meta 
    1415    comment: 
    1516        is_featured: smallint 
    16         promoted_to_entry_id: integer 
     17        promoted_to_entry_id: integer meta 
    1718 
    1819tags: 
     
    2324        CommentIsPromoted?: $ForumUtils::ForumUtils::Plugin::tag_is_comment_promoted 
    2425        CommentIsFeatured?: $ForumUtils::ForumUtils::Plugin::tag_is_comment_featured 
     26        EntryIsFeatured?: $ForumUtils::ForumUtils::Plugin::tag_is_entry_featured 
    2527        EntryWasPromoted?: $ForumUtils::ForumUtils::Plugin::tag_was_entry_promoted 
    2628 
    2729callbacks: 
    2830    MT::App::CMS::template_source.comment_table: $ForumUtils::ForumUtils::Plugin::xfrm_featured_comments 
     31    MT::App::CMS::template_source.entry_table: $ForumUtils::ForumUtils::Plugin::xfrm_featured_entries 
    2932    MT::App::CMS::template_source.header: $ForumUtils::ForumUtils::Plugin::xfrm_header 
    30  
     33    MT::App::CMS::template_source.edit_entry: $ForumUtils::ForumUtils::Plugin::xfrm_edit_entry 
    3134 
    3235list_actions: 
     
    4245            label: Toggle Featured 
    4346            order: 100 
    44             code:  $ForumUtils::ForumUtils::Plugin::itemset_feature_comment 
     47            code:  $ForumUtils::ForumUtils::Plugin::itemset_feature 
    4548            permission: edit_all_posts 
    4649    entry: 
     
    4952            order: 200 
    5053            code:  $ForumUtils::ForumUtils::Plugin::itemset_close_comments 
     54            permission: edit_all_posts 
     55        feature: 
     56            label: Toggle Featured 
     57            order: 100 
     58            code:  $ForumUtils::ForumUtils::Plugin::itemset_feature 
    5159            permission: edit_all_posts 
    5260 
     
    6169            label: Toggle Featured 
    6270            order: 100 
    63             code:  $ForumUtils::ForumUtils::Plugin::itemset_feature_comment 
     71            code:  $ForumUtils::ForumUtils::Plugin::itemset_feature 
     72    entry: 
     73        toggle_featured: 
     74            label: Toggle Featured 
     75            order: 100 
     76            code:  $ForumUtils::ForumUtils::Plugin::itemset_feature 
  • trunk/ForumUtils/plugins/ForumUtils/lib/ForumUtils/Plugin.pm

    r768 r1497  
    114114} 
    115115 
     116sub itemset_feature { 
     117    my ($app) = @_; 
     118    $app->validate_magic or return; 
     119 
     120    my $type = $app->{query}->param('_type'); 
     121    my $class = MT->model($type) if $type; 
     122    # TODO error if class is null 
     123 
     124    my @objs = $app->param('id'); 
     125    for my $obj_id (@objs) { 
     126        my $obj = $class->load($obj_id) or next; 
     127        if ($obj->is_featured) { 
     128            $obj->is_featured(0); 
     129        } else { 
     130            $obj->is_featured(1); 
     131        } 
     132        $obj->save; 
     133        if ($type eq 'entry') { 
     134# TODO rebuild indexes? 
     135#           MT->instance->rebuild( Entry => $obj->entry_id ); 
     136        } elsif ($type eq 'comment') { 
     137            MT->instance->rebuild( Entry => $obj->entry_id ); 
     138        } 
     139    } 
     140 
     141    $app->add_return_arg( featured => 1 ); 
     142    $app->call_return; 
     143} 
     144 
     145sub itemset_close_comments { 
     146    my ($app) = @_; 
     147    $app->validate_magic or return; 
     148 
     149    require MT::Entry; 
     150    my @entries = $app->param('id'); 
     151    for my $entry_id (@entries) { 
     152        my $entry = MT::Entry->load($entry_id) or next; 
     153        $entry->allow_comments(0); 
     154        $entry->save or die $entry->errstr; 
     155        MT->instance->rebuild( Entry => $entry_id ); 
     156    } 
     157    $app->add_return_arg( comments_closed => 1 ); 
     158    $app->call_return; 
     159} 
     160 
     161sub tag_is_comment_promoted { 
     162    my ($ctx, $args, $cond) = @_; 
     163    my $c = $ctx->stash('comment') 
     164        or return $ctx->_no_comment_error($ctx->stash('tag')); 
     165    return ($c->promoted_to_entry_id > 0); 
     166 
     167} 
     168 
     169sub tag_promoted_to_entry_id { 
     170    my ($ctx, $args, $cond) = @_; 
     171    my $c = $ctx->stash('comment') 
     172        or return $ctx->_no_comment_error($ctx->stash('tag')); 
     173    return $c->promoted_to_entry_id; 
     174} 
     175 
     176sub tag_was_entry_promoted { 
     177    my ($ctx, $args, $cond) = @_; 
     178    my $e = $ctx->stash('entry') 
     179        or return $ctx->_no_entry_error($ctx->stash('tag')); 
     180    return ($e->promoted_from_comment_id > 0); 
     181 
     182} 
     183 
     184sub tag_is_comment_featured { 
     185    my ($ctx, $args, $cond) = @_; 
     186    my $obj = $ctx->stash('comment') 
     187        or return $ctx->_no_comment_error($ctx->stash('tag')); 
     188    return $obj->is_featured; 
     189 
     190} 
     191 
     192sub tag_is_entry_featured { 
     193    my ($ctx, $args, $cond) = @_; 
     194    my $obj = $ctx->stash('entry') 
     195        or return $ctx->_no_entry_error($ctx->stash('tag')); 
     196    return $obj->is_featured; 
     197 
     198} 
     199 
     200sub tag_promoted_from_comment_id { 
     201    my ($ctx, $args, $cond) = @_; 
     202    my $obj = $ctx->stash('entry') 
     203        or return $ctx->_no_entry_error($ctx->stash('tag')); 
     204    return $obj->promoted_from_comment_id; 
     205} 
     206 
     207sub xfrm_featured_comments { 
     208    my ($cb, $app, $html_ref) = @_; 
     209     
     210    $$html_ref =~ s{(<th class="comment")}{<th class="featured"><img src="<mt:var name="static_uri">plugins/ForumUtils/images/star-listing.gif" alt="<__trans phrase="Featured">" width="9" height="9" /></th>$1}msg; 
     211 
     212    my $html = <<"EOF"; 
     213                    <td class="featured <mt:if name="is_featured">yes</mt:if>"> 
     214                <mt:if name="is_featured">  
     215                        <img src="<mt:var name="static_uri">images/spacer.gif" alt="<__trans phrase="Not Featured">" width="9" height="9" /> 
     216               <mt:else> 
     217                        <img src="<mt:var name="static_uri">images/spacer.gif" alt="<__trans phrase="Not Featured">" width="9" height="9" /> 
     218                </mt:if> 
     219                    </td> 
     220EOF 
     221 
     222    $$html_ref =~ s{(<td class="comment")}{$html$1}msg; 
     223    $$html_ref =~ s{<td>(.*<mt:if name="has_edit_access">)}{<td colspan="2">$1}msg; 
     224} 
     225 
     226# TODO use template param callback 
     227sub xfrm_featured_entries { 
     228    my ($cb, $app, $html_ref) = @_; 
     229     
     230    $$html_ref =~ s{(<th class="title")}{<th class="featured"><img src="<mt:var name="static_uri">plugins/ForumUtils/images/star-listing.gif" alt="<__trans phrase="Featured">" width="9" height="9" /></th>$1}msg; 
     231 
     232    my $html = <<"EOF"; 
     233                    <td class="featured <mt:if name="is_featured">yes</mt:if>"> 
     234                <mt:if name="is_featured">  
     235                        <img src="<mt:var name="static_uri">images/spacer.gif" alt="<__trans phrase="Not Featured">" width="9" height="9" /> 
     236               <mt:else> 
     237                        <img src="<mt:var name="static_uri">images/spacer.gif" alt="<__trans phrase="Not Featured">" width="9" height="9" /> 
     238                </mt:if> 
     239                    </td> 
     240EOF 
     241 
     242    $$html_ref =~ s{(<td class="title")}{$html$1}msg; 
     243    $$html_ref =~ s{<td>(.*<mt:if name="has_edit_access">)}{<td colspan="2">$1}msg; 
     244} 
     245 
     246sub xfrm_header { 
     247    my ($cb, $app, $html_ref) = @_; 
     248    $$html_ref =~ s{</head>}{<link rel="stylesheet" href="<mt:var name="static_uri">plugins/ForumUtils/css/app.css" type="text/css" /></head>}m; 
     249#       if $app->mode eq 'list_comments'; 
     250} 
     251 
     252sub xfrm_edit_entry { 
     253    my ($cb, $app, $html_ref) = @_; 
     254    $$html_ref =~ s{(<li class="pings-link">.*</li>)}{$1<mt:if name="is_featured"><li class="featured-link"><span>This is a featured entry</span></li></mt:if>}m; 
     255} 
     256 
     2571; 
     258 
     259__END__ 
     260 
     261# Deprecated 
     262 
    116263sub itemset_feature_comment { 
    117264    my ($app) = @_; 
     
    132279    } 
    133280 
    134     $app->add_return_arg( promoted => 1 ); 
    135     $app->call_return; 
    136 } 
    137  
    138 sub itemset_close_comments { 
    139     my ($app) = @_; 
    140     $app->validate_magic or return; 
    141  
    142     require MT::Entry; 
    143     my @entries = $app->param('id'); 
    144     for my $entry_id (@entries) { 
    145         my $entry = MT::Entry->load($entry_id) or next; 
    146         $entry->allow_comments(0); 
    147         $entry->save or die $entry->errstr; 
    148         MT->instance->rebuild( Entry => $entry_id ); 
    149     } 
    150     $app->add_return_arg( comments_closed => 1 ); 
    151     $app->call_return; 
    152 } 
    153  
    154 sub tag_is_comment_promoted { 
    155     my ($ctx, $args, $cond) = @_; 
    156     my $c = $ctx->stash('comment') 
    157         or return $ctx->_no_comment_error($ctx->stash('tag')); 
    158     return ($c->promoted_to_entry_id > 0); 
    159  
    160 } 
    161  
    162 sub tag_promoted_to_entry_id { 
    163     my ($ctx, $args, $cond) = @_; 
    164     my $c = $ctx->stash('comment') 
    165         or return $ctx->_no_comment_error($ctx->stash('tag')); 
    166     return $c->promoted_to_entry_id; 
    167 } 
    168  
    169 sub tag_was_entry_promoted { 
    170     my ($ctx, $args, $cond) = @_; 
    171     my $e = $ctx->stash('entry') 
    172         or return $ctx->_no_entry_error($ctx->stash('tag')); 
    173     return ($e->promoted_from_comment_id > 0); 
    174  
    175 } 
    176  
    177 sub tag_is_comment_featured { 
    178     my ($ctx, $args, $cond) = @_; 
    179     my $c = $ctx->stash('comment') 
    180         or return $ctx->_no_comment_error($ctx->stash('tag')); 
    181     return $c->is_featured; 
    182  
    183 } 
    184  
    185 sub tag_promoted_from_comment_id { 
    186     my ($ctx, $args, $cond) = @_; 
    187     my $e = $ctx->stash('entry') 
    188         or return $ctx->_no_entry_error($ctx->stash('tag')); 
    189     return $e->promoted_from_comment_id; 
    190 } 
    191  
    192 sub xfrm_featured_comments { 
    193     my ($cb, $app, $html_ref) = @_; 
    194      
    195     $$html_ref =~ s{(<th class="comment")}{<th class="featured"><img src="<mt:var name="static_uri">plugins/ForumUtils/images/star-listing.gif" alt="<__trans phrase="Featured">" width="9" height="9" /></th>$1}msg; 
    196  
    197     my $html = <<"EOF"; 
    198                     <td class="featured <mt:if name="is_featured">yes</mt:if>"> 
    199                 <mt:if name="is_featured">  
    200                         <img src="<mt:var name="static_uri">images/spacer.gif" alt="<__trans phrase="Not Featured">" width="9" height="9" /> 
    201                <mt:else> 
    202                         <img src="<mt:var name="static_uri">images/spacer.gif" alt="<__trans phrase="Not Featured">" width="9" height="9" /> 
    203                 </mt:if> 
    204                     </td> 
    205 EOF 
    206  
    207     $$html_ref =~ s{(<td class="comment")}{$html$1}msg; 
    208     $$html_ref =~ s{<td>(.*<mt:if name="has_edit_access">)}{<td colspan="2">$1}msg; 
    209 } 
    210  
    211 sub xfrm_header { 
    212     my ($cb, $app, $html_ref) = @_; 
    213     $$html_ref =~ s{</head>}{<link rel="stylesheet" href="<mt:var name="static_uri">plugins/ForumUtils/css/app.css" type="text/css" /></head>}m; 
    214 #       if $app->mode eq 'list_comments'; 
    215 } 
    216 1; 
    217  
     281    $app->add_return_arg( featured => 1 ); 
     282    $app->call_return; 
     283}