scriptygoddess

12 Jun, 2003

Author's RSS Feed field in comments

Posted by: Jennifer In: MT hacks

A while back Chris had asked about getting an extra field in the comments form. At the time all I could do was figure out a way to get the field emailed to you. But thanks to a few lessons I learned in the last script/MT-hack I wrote – I've figured out how to do it all. So this is part MT-hack and part plugin.

Here's a summary of what this does:

You add a field in your comments form to collect RSS feed's from your commenters and then you can display it back in your comments on your site – just like you do with their blog-URL.

What's involved:

You'll be editing any template you use that displays comments or the comment form, and install a plugin (which is as simple as uploading a file to your site) As well, You'll need to edit two MT files and the mt-database. If you're not comfortable doing this – I suggest you set up a test MT install and play with this first.

Here is the download for the plugin. The tags associated with the plugin will not work on their own – you'll need to follow all of the instructions (below).

Some credit notes: A MASSIVELY HUGE THANK YOU to "Milbertus" (A.) of milbertus.com for writing the plugin for the MTCommentFeed tag (MTCommentPreviewFeed tags still in development at this time) (I wrote the plugin for the MTCommentIfRSS tag. w00t!)

Part One: Edit your comments form

In your comments form, add this:

Your RSS Feed: <input type="text" name="rssfeed" />

If you have the "remember me" cookies working on this page, and you'd like this field to also be remembered, look for your "remember me" and "forget me" functions (towards the top of your page), and just add the line that I have in red/bold text:

function rememberMe (f) {
var now = new Date();
fixDate(now);
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
setCookie('mtcmtauth', f.author.value, now, ", HOST, ");
setCookie('mtcmtmail', f.email.value, now, ", HOST, ");
setCookie('mtcmthome', f.url.value, now, ", HOST, ");
setCookie('mtcmtrssfeed', f.rssfeed.value, now, ", HOST, ");
}
function forgetMe (f) {
deleteCookie('mtcmtmail', ", HOST);
deleteCookie('mtcmthome', ", HOST);
deleteCookie('mtcmtauth', ", HOST);
deleteCookie('mtcmtrssfeed', ", HOST);
f.email.value = ";
f.author.value = ";
f.url.value = ";
f.rssfeed.value =";
}

Now look towards the bottom for the page for the code below and add what I have in red/bold

<script type="text/javascript" language="javascript">
<!–
document.comments.email.value = getCookie("mtcmtmail");
document.comments.author.value = getCookie("mtcmtauth");
document.comments.url.value = getCookie("mtcmthome");
document.comments.rssfeed.value = getCookie("mtcmtrssfeed");
//–>
</script>

Part Two: Getting the field into the MT database.

You will need to run this SQL query. I suggest going into phpMyAdmin (if your
host provider has this). Click on the SQL tab, and paste the line below in the
field, and then click go.

ALTER TABLE mt_comment ADD comment_author_rss VARCHAR( 255 ) ;

Part Three: Edit Comments.pm

This is the part that has to be re-done each time you upgrade (or replace your comments.pm file). Your Comments.pm file should be located in this path: yourMTfolder/lib/MT/App/Comments.pm
Look for this line (probably around line 82):

$comment->author(remove_html(scalar $q->param('author')));

and add these lines below it:

my $rssfeed = $q->param('rssfeed') || ";
if ($rssfeed) {
require MT::Util;
if (my $fixed2 = MT::Util::is_valid_url($rssfeed)) {
$rssfeed = $fixed2;
} else {
return $app->handle_error($app->translate(
"Invalid URL '[_1]'", $rssfeed));
}
}
$comment->author_rss(remove_html($rssfeed));

Look for this line (probably around line 150):

$app->translate('URL:') . ' ' . $comment->url . "\n\n" .

and add this line below it:

$app->translate('RSS Feed:') . ' ' . $comment->rssfeed. "\n\n" .

Part Four: Edit Comment.pm

This will also need to be re-done each time you upgrade (or replace your Comment.pm file). Your Comment.pm file should be located in this path: YourMTFolder/lib/MT/Comment.pm
Look for this line

'id', 'blog_id', 'entry_id', 'author', 'email', 'url', 'text', 'ip'

CHANGE it to (you're just adding the 'author_rss', in there:

'id', 'blog_id', 'entry_id', 'author', 'email', 'url', 'author_rss',
'text', 'ip'

Part Five: Using the Plugin:

Here's an example of how the tags will work. This site uses this plugin and mt-hack, so you can see how it is displayed.

<MTCommentIfRSS>
<a href="<$MTCommentFeed$>">My RSS Feed</a>
</MTCommentIfRSS>

(MTCommentPreviewFeed example coming…)

Part Six/Addendum: Comment Subscribe modification

If you use "subscribe to comments" script, you'll also need to edit the processing.tmpl file that came with the script. Add this to the form on that page:

<input type="hidden" name="rssfeed" value="<?
echo $rssfeed ?>">

15 Responses to "Author's RSS Feed field in comments"

1 | Jennifer

June 12th, 2003 at 11:31 pm

Avatar

Just showing an example of how this works.. :)

2 | Jennifer

June 12th, 2003 at 11:34 pm

Avatar

Ok – so that was an example with no feed link.. here's an example of one WITH a feed link

3 | Al-Muhajabah

June 13th, 2003 at 2:05 pm

Avatar

Jennifer, this is not directly related to your hack, but I want to thank you for explaining everything in this post. I had been trying to implement a hack and plugin that created threaded comments, but it wouldn't remember the new fields. The reason is that I forgot about the "subscribe to comments" script. I didn't add the new fields to processing.tmpl and that's why they were getting lost before they could be put in the database. When I read your instructions here, I began banging my head on my computer monitor. Then I quit that and when to add the info to processing.tmpl

Now my threaded comments hack works perfectly! Woohoo!!!!!!

4 | Al-Muhajabah

June 13th, 2003 at 2:19 pm

Avatar

Jennifer, this isn't specifically about your new plugin-hack, but I want to thank you for giving such detailed instructions. I had been trying to implement a plugin-hack to create threaded comments and a new comment subject field. But for some reason, it wouldn't work!

It turns out that I had forgotten about the subscribe to comments script. Since I didn't put the new fields in the processing.tmpl page, they got lost before they were entered in the database.

After I read your instructions here (and after I stopped banging my head on my computer monitor!) I went and added the new fields to processing.tmpl. Now it works like a charm!

5 | julie

June 13th, 2003 at 4:57 pm

Avatar

awesome! you rawk jenn. thanks! : )

6 | Al-Muhajabah

June 14th, 2003 at 8:10 pm

Avatar

Sorry about the double post. Forgot you had the comment queue hack set up here.

It seems like the same basic methodology could be used to add any extra comment field, not just the comment author's RSS feed.

7 | Jennifer

June 14th, 2003 at 8:34 pm

Avatar

Yes – sort of. The hack can be used to add any type of extra field – with the exception that what I add to comments.pm – is some code to check to make sure it's a valid URL. If you wanted it to add the field directly to the database…then instead of this part:

my $rssfeed = $q->param('rssfeed') || ";
if ($rssfeed) {
require MT::Util;
if (my $fixed2 = MT::Util::is_valid_url($rssfeed)) {
$rssfeed = $fixed2;
} else {
return $app->handle_error($app->translate(
"Invalid URL '[_1]'", $rssfeed));
}
}
$comment->author_rss(remove_html($rssfeed));

Just add this:

$comment->author_rss($q->param('rssfeed'));

8 | JLT

June 15th, 2003 at 5:40 pm

Avatar

Thanks for the great help as always! Keep up the great work, I really appreciate it.

9 | Jennifer

August 12th, 2003 at 9:09 pm

Avatar

FYI – if you'd like to display a long list of XML feeds from anyone that's ever commented on your site and filled out that field, use this code:

<?
mysql_connect ("localhost", "DBUSERNAME", "DBPASSWORD") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("MTDATABASE");
$query = "SELECT DISTINCT comment_author_rss, comment_author FROM mt_comment
WHERE comment_author_rss <> " order by comment_author";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
for ($i=0; $i < $numrows; $i++) {
$row = mysql_fetch_array($result);
if (stristr($row['comment_author_rss'], ".rdf") || stristr($row['comment_author_rss'], ".xml")) {
echo $row['comment_author'];
echo "<br>";
echo "<a href=\"".$row['comment_author_rss']."\">";
echo $row['comment_author_rss'];
echo "</a>";
echo "<br>";
echo "<br>";
}
}
?>

10 | Jennifer

August 12th, 2003 at 9:10 pm

Avatar

(I meant .RDF or .XML feeds)

11 | Big Pink Cookie

June 18th, 2003 at 12:56 pm

Avatar

I See You…
I see all these people floating through my personal blogosphere, but no one is stopping to say hi. Come on…

12 | Live in the Delirious Cool

August 17th, 2003 at 11:59 am

Avatar

Commenting, it's where the fun is.
Can you believe in all this time I've never once hacked or altered my MT files? This might be worth it. Also, a nice, easy fix to the "remember me" problem seen in MT commenting.

13 | Bloggie Broad

December 13th, 2003 at 7:59 pm

Avatar

Bloggie Scripty Reverb
I like to keep an up-to-date listing of all the…

14 | Bloggie Broad

December 14th, 2003 at 5:38 pm

Avatar

Breaking from the breaking news….
to announce that you can post your RSS feed in…

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements