| | 116 | sub 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 | |
| | 145 | sub 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 | |
| | 161 | sub 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 | |
| | 169 | sub 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 | |
| | 176 | sub 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 | |
| | 184 | sub 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 | |
| | 192 | sub 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 | |
| | 200 | sub 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 | |
| | 207 | sub 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> |
| | 220 | EOF |
| | 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 |
| | 227 | sub 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> |
| | 240 | EOF |
| | 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 | |
| | 246 | sub 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 | |
| | 252 | sub 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 | |
| | 257 | 1; |
| | 258 | |
| | 259 | __END__ |
| | 260 | |
| | 261 | # Deprecated |
| | 262 | |
| 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 | } |