Singpolyma

Comment Photos and Highlighting

Posted on

PurpleMoggy has created a set of instructions for using this on Blogger BETA. I have updated my hack to support his new features and fix the bugs he found. There is also now a new ‘no image’ image.

Awhile back I wrote a post detailing my hack for adding profile photos to comments. Unfortunately that post was rather technical in its explanation. This post attempts to deal with adding the hack to your blog in a more user-friendly fashion and also with using the hack to highlight blog-contributor comments.

Step 1 – The first thing you need to do is find the comment section in your blog template. Edit your template and scroll down until you find the <BlogItemComments> tag. The code inside should look something like this:

<div class=”comment-poster” id=”c<$BlogCommentNumber$>”>
<a name=”c<$BlogCommentNumber$>”></a>
<$BlogCommentAuthor$> said…
</div>

<div class=”comment-body”>
<div class=”innerCmntBody”><$BlogCommentBody$></div>
</div>

<div class=”comment-timestamp”>
<a href=”#c<$BlogCommentNumber$>” title=”comment permalink”>4/26/2006 07:49:51 PM</a>
</div>

Step 2 – If you plan to use comment highlighting (so that the comments made by blog authors look different from those of users) this must be wrapped in another tag so that all of the code for each comment is in one tag. Like so:

<div class=”commentelem”>

<div class=”comment-poster” id=”c<$BlogCommentNumber$>”>
<a name=”c<$BlogCommentNumber$>”></a>
<$BlogCommentAuthor$> said…
</div>

<div class=”comment-body”>
<div class=”innerCmntBody”><$BlogCommentBody$></div>
</div>

<div class=”comment-timestamp”>
<a href=”#c<$BlogCommentNumber$>” title=”comment permalink”>4/26/2006 07:49:51 PM</a>
</div>

</div>

Some blog templates will already have a tag around their comments, as will those using the ‘standard’ comment markup. If you have one of those templates just write down the class of the wrapping tag or add one (the underlined section above).

Step 3 – Next we need the class of the element where we can look for the link to the author. In the example code above this would be comment-poster. When in doubt use the class of the overall wrapping tag. Once you have it, write it down. Count the number of <a> tags there are before the <$BlogCommentAuthor$> tag and write this number down (in the above example it is 1).

Step 4 – The only thing left to do in this part of the code is to insert the element where the profile photo will go. Add this code right before the <$BlogCommentBody$> tag: <div class=”commentphoto”></div>

Step 5 – Now go to the <head> section of your blog and add the following code:

<script type=”text/javascript” src=”http://jscripts.ning.com/get.php?xn_auth=no&amp;id=830605;
<script type=”text/javascript”>
//<![CDATA[
function thisblog_showCommentPhotos() {showCommentPhotos(‘commentphoto’,’class of author wrapper‘,# of a tags,’main wrapper class‘,'<$BlogURL$>’,’highlighted text colour‘,’highlighted text background‘;}
addLoadEvent(thisblog_showCommentPhotos);});
//]]>
</script>

Where class of author wrapper is the class you wrote down in step 3, the # of a tags is the number you wrote down in step 3, and the main wrapper class is the class you wrote down in step 2. If you are not going to use comment highlighting the last for parameters can be left off (from main wrapper class to highlighted tex background) otherwise you have to fill in the color you with the text and background of highlighted comments to be in their appropriate spots above.

Step 6 – Save and Republish!

Windows XP Recovery Console

Posted on

Well this is a bit of a different-style post for me, but this discovery struck me as extremely useful and so I thought I’d share it with any of my readers who may not have seen it yet.

On the transition to Windows XP I was horrified to discover that the ’emergency boot disk’ that XP creates cannot read NTFS partitions. It boots to MSDOS7.0 and then if your computer is NTFS you can do nothing. This essentially destroyed any chance of accessing your data if you could not boot to Windows. Many times during computer repair this was a hindrance and either elaborate workarounds had to be devised, or I fell back to the cure-all ‘reformat and reinstall’.

Yesterday I tried to get cheap Excel, but discovered an incredibly useful tool from Microsoft in an incredibly obvious place: the Windows XP install CD. If you boot from the CD and press ‘R’ at the ‘Welcome to Setup’ screen you are taken to the Windows XP Recovery Console. This is exactly what I had been looking for for so long: a reformulation of MSDOS that can access NTFS partitions! I was able to use it to run CHKDSK (scandisk seems to be out) and fix the minor problem the drive had — saving potentially hours of work to fix the problem any other way. There are even some XP-centric commands for dealing with user accounts etc.

What this does not help is users of many preinstalled systems, especially laptops. Most (if not all) of the ‘restore disks’ sent with such systems do not have the Recovery Console. However, techies who have a copy of the install disks can use their copy to run the Recovery Console on another person’s system. No activation procedure 😉 Even XP Professional install disks’ Console will work just fine with XP Home systems 🙂

Google AJAX

Posted on

Google AJAX is an interface for Google search that allows you to get the search results AJAX-style. This can be really handy when doing a series of quick searches. Better yet, however, is the widget that comes with it. Simply cut-and-paste the given code into your blog sidebar and you have inline Google search power — the results are displayed right in your sidebar! You can also (optionally) specify a URL to restrict the search to, thus creating a widget to do an AJAX-style search on your own site using the power of Google right from your sidebar! You can see an example of this in my own sidebar. The script is built using the power of YubNub.

Posting

Posted on

So I’m almost done school YAY! didn’t do too well on my final chem exam… hope I pass :S *sigh* but hey, let’s not let that get me down! 😉 nothing I can do about it anyway. In a few short weeks I should be done all my schoolwork… if I don’t procrastinate through it all ;P Been doing a lot of code lately to keep myself busy. Chels has like two months left of grounding (don’t remind me!) but I’m making it ok — one day at a time 😉 uhh *thinks* the pool is open again! 😀 they had closed it to drain+clean+repaint it, but they’re done so we can go again, so that’s cool. Ah, right, the ‘situation’ here, I should mention that. As of right now the official word is that the rebels are licking their wounds in Soudan and the election is tomorrow. Word on the street is that they’ve regrouped and are ‘moving south’ — which means to Sahr and then here. The military in town are prepping just in case. Should be interesting, hehe. Aaaand, nothing much else happening so I’ll end this post for now 😉

‘Standard’ Comment Markup?

Posted on

What would be the benefits of standardising our comment markup? Well, that all depends on who you are. With the advent of comment crawling services a standard markup would really help them do their job. If your blogging platform offers no syndication options a standard comment markup could allow you to generate comment feeds yourself (using Blogger Recent Comments or similar). A standard markup about which we can make certain assuptions would also help the less technically inclined with implementing comment-centric hacks.

So, the natural first place to look is microformats.org. Nada, yet. Falling back to my own work with XOXO I have encapsulated comments as part of the XOXO Blog Format. Testing that with a comment crawler I find that it recognises the data ‘as is’ just fine. If you mix it with hAtom it is recognised by Blogger Recent Comments (more on this in a later post). It also provides many of the things we hackers like in comment hacks — an item surrounding the whole comment and the comment text, and a way of identifying some of the meta-type links.

Thus this proposed ‘standard’ is both based on microformats (XOXO) and fits the three major reasons we would even want any sort of structure to our comment markup. The markup should be on the main page for crawlers et al, but need not be visible. Now to how to add it to your blog. Advanced users can probably figure it out from teh XOXO Blog Format, for others here are simple instructions for both Blogger and WordPress:

Blogger
Go to your blog template and find the section that begins with <BlogItemComments> and ends with </BlogItemComments>. Replace it with this code:

<script type=”text/javascript”>
//<![CDATA[
posturl = “<$BlogItemPermalinkUrl$>”;
//]]>
</script>

<ul class=”xoxo comments”>
<BlogItemComments>
<li id=”c<$BlogCommentNumber$>” class=”commentelem”>Comment at <a href=”#c<$BlogCommentNumber$>” title=”<$BlogCommentNumber$>0″><$BlogCommentDateTime$></a> by
<$BlogCommentAuthor$>
<a name=”<$BlogCommentNumber$>”> </a>
<!– JS HERE –>
<dl>
<dt class=”body”>body</dt>
<dd class=”body”><$BlogCommentBody$></dd>
</dl>
<$BlogCommentDeleteIcon$>
<br />
</li>
</BlogItemComments>
</ul>

If you are going to be visibly displaying comments on your main page it is reccomended you replace the <!– JS HERE –> in the above with:

<script type=”text/javascript”>
//<![CDATA[
commentlink = xget(‘//li[@id=”c<$BlogCommentNumber$>”]//a’);
if(commentlink) {
fragment = commentlink.href.split(‘#’)[1];
commentlink.href = posturl+’#’+fragment;
}//end if commentlink
//]]>
</script>

And add the following to your <head> section:

<script type=”text/javascript”>
//<![CDATA[
function xget(xpathSelector) {
var it = document.evaluate( xpathSelector, document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null );
if(it.snapshotLength)
return it.snapshotItem(0);
return ”;
}//end function xget
//]]>
</script>

Now to style this to look like we are used to having comments look. Skip past WordPress to Styling.

WordPress
To use this code on WordPress blogs, edit your theme and go to the ‘comments.php’ file. Find the section that starts <ol> and ends </ol>. Replace it with:

<ol class=”xoxo comments commentlist”>

<?php foreach ($comments as $comment) : ?>

<li class=”commentelem <?php echo $oddcomment; ?>” id=”comment-<?php comment_ID() ?>”>
<?php if ($comment->comment_approved == ‘0’) : ?>
<em>Your comment is awaiting moderation.</em>
<?php endif; ?>
Comment at <a href=”<?php the_permalink() ?>#comment-<?php comment_ID() ?>” title=”<?php echo strtotime(get_comment_date().’ ‘.get_comment_time()); ?>”><?php comment_date(‘F jS, Y’) ?> <?php comment_time() ?></a>
by <?php comment_author_link() ?>
<br /><?php edit_comment_link(‘e’,”,”); ?>

<dl>
<dt class=”body”>body</dt>
<dd class=”body”><?php comment_text() ?></dd>
</dl>

</li>

<?php /* Changes every other comment to a different class */
if (‘alt’ == $oddcomment) $oddcomment = ”;
else $oddcomment = ‘alt’;
?>

<?php endforeach; /* end for each comment */ ?>

</ol>

This code seems to work with the most common themes. Now to styling so that we get back our old look:

Styling
Add this code to your <head> section:

<style type=”text/css”>
.comments {
list-style-type: none;
margin-left: 0px;
margin-top: 0.5em;
}
.comments li {
display: block;
margin-left: 0px;
margin-bottom: 1em;
}
.comments dl {
display: inline;
}
.comments dd {
margin-left: 0px;
}
.comments dt {
display: none;
}
.comments dd.author {
display: inline;
font-size: 1em;
}
.comments dd.body {
display: block;
margin-top: 0.5em;
}
</style>
http://del.icio.us/singpolyma.techblog/markup