More Pending Comments

In the last example, I showed you how to list pending comments so that you may easily delete them. This actually works and you should be fine with it. However, there are some other changes that you may want to make so that this feature will be better integrated.

The first step addresses having a lot of comments. With the prior example, you will only see the first 20 comments that are waiting for approval. In many cases, this is fine. But what if you get hit with 100? Normally, you could page through the comments and you’d be able to delete them page by page. Unfortunately, that earlier example didn’t address this – you won’t be able to page through the comments because the necessary information isn’t contained there.

You really have two options. The one I use is to list all outstanding comments awaiting approval. That way I can delete them all in one fell swoop. The other option is to list comments by page, similar to how normal comment listing works. I’ll include both examples here. You should only include one or the other. Doing both may result in some unusual behavior.

First, locate the earlier code you added to CMS.pm. It should look something like this:

  if ($q->param('filter') eq 'pending') {
  $terms{visible} = 0;
  }

Now, add to it one of two options. The first example shows what your code should look like if you want to see all comments. The second should be used if you would like to see “paged” comments. You do not need, and probably should not use, both together:

  if ($q->param('filter') eq 'pending') {
  $terms{visible} = 0;
  $limit = 'none';
  }
  if ($q->param('filter') eq 'pending') {
  $param{filter_args} = "&filter='pending'&filter_val=";
  $terms{visible} = 0;
  }

Another feature you might want is to be able to see what you are filtering. Movable Type does this by showing that you are looking for a particular email address, for example. By adding one more line to this section, you will be able to do the same:

  if ($q->param('filter') eq 'pending') {
  $param{filter} = 'pending';
  $terms{visible} = 0;
  $limit = 'none';
  }

This will simply display that you are showing pending comments. This example lists all comments, as I have it installed on my site. If you used the second example above, then you would have the filter_args line instead of the limit line.

Finally, you may want it to look even nicer. It does look a little strange when you use the information above, since you aren’t required to enter a value for pending. So we can clean it up a bit. First, add another line to the loop we’ve been using above:

  if ($q->param('filter') eq 'pending') {
  $param{filter} = 'pending';
  $param{filter_pending} = 1;
  $terms{visible} = 0;
  $limit = 'none';
  }

This will set another variable that we can use to generate our template. So load list_comment.tmpl and find the line that looks like this:

  <TMPL_IF NAME=FILTER>

Just below it there is a horitonztal rule (<hr />). Just below that, add these lines:

  <TMPL_IF NAME=FILTER_PENDING>
  <MT_TRANS phrase="Currently showing all pending comments.">
  <TMPL_ELSE>

Again, this example is from my installation, and I display all pending comments. If using the “paged” example above, you may want to change the wording to better match your installation.

Finally, move down four lines (just above the input line) and add this:

  </TMPL_IF>

The end result should look like this:

  <TMPL_IF NAME=FILTER>
  <hr />
  <TMPL_IF NAME=FILTER_PENDING>
  <MT_TRANS phrase="Currently showing all pending comments.">
  <TMPL_ELSE>
  <MT_TRANS phrase="Currently showing comments where">
  '<MT_TRANS phrase="<TMPL_VAR NAME=FILTER>">'
  <MT_TRANS phrase="is">
  '<TMPL_VAR NAME=FILTER_VAL ESCAPE=HTML>'.&nbsp;
  </TMPL_IF>
  <input type="button" ... />
  </TMPL_IF>

If the filter_pending value is set, it will show the text we added. If this value is not set – and it won’t be set unless our code is executing – then it will display just as it normally does. Enjoy.

Update: I do offer Movable Type consulting services. If this seems like too much for you, but you’d like to have such a feature, contact me and let’s see if we can work something out.


Posted

in

Comments

One response to “More Pending Comments”

  1. Markiss Avatar

    I know you posted this ages ago but I just wanted to thank you for the tutorial. I have been wanting this for ages now and finally found it on your site. It was very easy to follow and implement on my site too. Many thanks.