Singpolyma

Technical Blog

Archive for the "Tech" Category

New Inline Comments Form

Posted on

See this page for a similar hack for the new version of Blogger.

This hack does not work with Blogger BETA.

After considerable use and some feedback from both users and implementors I have redone my inline comments form hack. The new hack should be simpler, cleaner, and XHTML-valid. Previous implementors will have to remove the old hack before continuing.

You might also wish to check out the asynchronous version of this hack 🙂

This hack is now coComment-compatible.

  1. Word verification for comments must be turned off (to do this go to the ‘comments’ tab in your blog settings, scroll to ‘Show word verification for comments?’ and select ‘No’)
  2. Turn comment posting by anonymous users on (to do this go to the ‘comments’ tab in your blog settings, scroll to ‘Who Can Comment?’ and select ‘Anyone’)
  3. Insert the following code into the <head> section of your blog template :
    <script type=”text/javascript”>
    //<![CDATA[

    function toggleitem(postid,linkid,newtxt,displaytype) {
    if(!displaytype) {displaytype = ‘block’;}
    var whichpost = document.getElementById(postid);
    if (whichpost.style.display != “none”) {
    whichpost.style.display = “none”;
    } else {
    whichpost.style.display = displaytype;
    }
    if(linkid) {
    var lnk = document.getElementById(linkid);
    lnk.href = “javascript:toggleitem(‘”+postid+”‘,'”+linkid+”‘,'”+lnk.innerHTML+”‘);”;
    lnk.innerHTML = newtxt;
    }
    }

    //]]>
    </script>

  4. Replace the <$BlogItemCreate$> tag with the following code:
    <!– COMMENT FORM –>
    <ItemPage>
    <script type=”text/javascript”>

    var blogTool = “Blogger”;
    var blogURL = “<$BlogURL$>/”;
    var blogTitle = “<$BlogTitle$>”;
    var postURL = “<$BlogItemPermalinkUrl$>”;
    var postTitle = “<BlogItemTitle><$BlogItemTitle$></BlogItemTitle>”;
    var commentAuthorFieldName = “anonName”;
    var commentAuthorLoggedIn = “false”;
    var commentFormID = “cformtag<$BlogItemNumber$>”;
    var commentTextFieldName = “postBody”;
    var commentButtonName = “post”;
    var cocomment_force = false;

    </script>

    <script type=”text/javascript” src=”http://www.cocomment.com/js/cocomment.js </script>
    </ItemPage>
    <ItemPage><a href=”javascript:toggleitem(‘cform’);”>Post a Comment</a>
    <div style=”display:block;” id=”cform”></ItemPage>
    <MainOrArchivePage><a href=”javascript:toggleitem(‘cform<$BlogItemNumber$>’);”>Post a Comment</a>
    <div style=”display:none;” id=”cform<$BlogItemNumber$>”></MainOrArchivePage>
    <form action=”http://www.blogger.com/login-comment.do onsubmit=”isSubmit=true;” method=”post”><div>
    <input type=”hidden” name=”blogID” value=”<$BlogID$>” />
    <input type=”hidden” name=”postID” value=”<$BlogItemNumber$>” />
    <div>
    <h2 class=”sidebar-title form-title”><label class=”cbody”>Leave your comment </label></h2>
    <h2 class=”sidebar-title”> You can use some HTML tags, such as <b> &lt;b&gt;, &lt;i&gt;, &lt;a&gt; </b> </h2>
    <textarea name=”postBody” class=”comment” rows=”8″ cols=”40″></textarea>
    <h2 class=”sidebar-title identity”> Choose an identity </h2>
    <div>
    <div>
    <input type=”radio” name=”iden” value=”Blogger” checked=”checked” onchange=”toggleitem(‘cfo<$BlogItemNumber$>’);” />
    <label> Your Blogger display name </label>
    </div>
    <div>
    <input type=”radio” name=”iden” value=”Other” onchange=”toggleitem(‘cfo<$BlogItemNumber$>’);” />
    <label>Other</label>
    <div style=”display:none;” id=”cfo<$BlogItemNumber$>”>
    <table style=”margin-left: 4em;” cellpadding=”0″ cellspacing=”0″>
    <tr> <td colspan=”2″ style=”padding-top:.4em;position:relative;left:-4em;” align=”left”> These fields are optional, but I would appreciate it if you filled them out. </td></tr>
    <tr> <td> <label> Name </label> </td>
    <td> <div class=”errorbox-good”> <input type=”text” name=”anonName” value=”” maxlength=”100″ class=”text” /> </div> </td> </tr>
    <tr> <td> <label> Your web page </label> </td>
    <td> <div class=”errorbox-good”> <input type=”text” name=”anonURL” value=”” maxlength=”100″ class=”text” /> </div> </td> </tr>
    </table>
    </div>
    </div>
    <div class=”diff-user”> Or you can sign in <a href=”http://www.blogger.com/login.g?r=http%3A%2F%2Fwww.blogger.com%2Fcomment.g%3FblogID%3D;$BlogID$>%26postID%3D<$BlogItemNumber$>”> as a different user</a>.</div>
    </div>
    </div>
    <div class=”errorbox-good”> </div>
    <p class=”buttons”>
    <input style=”margin-right:.3em” name=”post” value=”Publish Your Comment” class=”publish” onclick=”isSubmit=true;” type=”submit” tabindex=”2″ />
    <input value=”Preview” type=”submit” name=”preview” onclick=”isSubmit=true;” tabindex=”3″ />
    </p>
    </div></form>
    </div>
    <!– END COMMENT FORM –>

  5. Save your template and republish your blog

XOXO Blog and Template

Posted on

I have started the XOXO Blog for the promotion of the XOXO microformat. (For those wondering what XOXO is, see my post What is XOXO?) The blog’s template is fully XOXO-paresable and I am working on changeing over my Blogger Comment Syndication service to parse XOXO formated compatible with this new concept, which is only slightly different from my original XOXO code, but is more compatible with other uses. All users of my service will have to switch to this new (hopefully better) code snippet, but I think it will ultimately be worth it. Blogs based off of an XOXO template (I’ll be publishing one and the specs soon. As you can see by looking at the XOXO Blog itself, I’m not much of a designer, but I’m proving the concept first. I’ll get other people to help me with looks later.) will be able to use the service directly with no added code.

Other benefits to the XOXO-template could include :

  • The ability to produce better post feeds by parseing the blog main page
  • The ability to parse the whole blog for backup/transfer to another service if needed

The XOXO blog itself will soon be populated with different tools, not only to go with XOXO templates, but to work with other uses for XOXO as well.

Tags:

Backlinks on Main Page

Posted on

This hack has been superceded by this better one.

Getting Blogger baclinks to display on your main page is no picnic – wheather for peek-a-boo or permanent display. The way the script works direct from Blogger it assumes that it is running on a post page. So, after mor than a little fussing, I have come up with a hack that works for fixing this. The following will install peek-a-boo backlinks on your Blogger blog (template hackers will be pleased to know that the backlink template-tag section is still intact for your hacking pleasure) :

  1. Enable backlinks on your blog — an obvious, but necessary, step
  2. a – Put manual metadata in your template. Feedburner users have already done this. If you already have your metadata in your template manually for this or another reason, change this line:
    <script type="text/javascript" src="http://www.blogger.com/js/backlink.js"></script>

    To this:

    <script type="text/javascript" src="http://www.awriterz.org/etcetc/backlink.js"></script>

    Otherwise go on to 2b.

    b – Find this : ‘<$BlogMetaData$>‘, it should be somewhere near the top of your blog template. Replace it with this:

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="MSSmartTagsPreventParsing" content="true" />
    <meta name="generator" content="Blogger" />
    <link rel="alternate" type="application/xml" title="<$BlogTitle$>" href="<$BlogSiteFeedUrl$>" />
    <link rel="service.post" type="application/atom+xml" title="<$BlogTitle$>" href="https://www.blogger.com/atom;$BlogID$>" />
    <link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://www.blogger.com/rsd.g?blogID;$BlogID$>" />
    <style type="text/css">
     @import url("http://www.blogger.com/css/blog_controls.css");
     @import url("http://www.blogger.com/dyn-css/authorization.css?blogID;$BlogID$>");
    </style>
    <script type="text/javascript" src="http://www.awriterz.org/etcetc/backlink.js"></script>
    <script type="text/javascript" src="http://www.blogger.com/js/backlink_control.js"></script>
    <script type="text/javascript">var BL_backlinkURL='http://www.blogger.com/dyn-js/backlink_count.js', BL_blogId='<$BlogID$>';</script>
    
  3. Put this code directly after that which you just inserted:
    <script type="text/javascript">
    //<![CDATA[
    function toggleitem (postid,linkid,newtxt) {
    var whichpost = document.getElementById(postid);
    if (whichpost.style.display != "none") {
       whichpost.style.display = "none";
    } else {
       whichpost.style.display = "block";
    }
    if(linkid) {
       var lnk = document.getElementById(linkid);
       lnk.href = "javascript:toggleitem('"+postid+"','"+linkid+"','"+lnk.innerHTML+"');";
    lnk.innerHTML = newtxt;
    }
    }
    //]]>
    </script>
    
  4. Find the section in your template that starts with ‘<BlogItemBacklinksEnabled>‘ and ends with ‘</BlogItemBacklinksEnabled>‘ and replace the entire thing (these tags included) with this code:
    <ItemPage><div style="display:block;" id="backlinks<$BlogItemNumber$>"></ItemPage>
    <MainOrArchivePage><div style="display:none;" id="bl<$BlogItemNumber$>"></MainOrArchivePage>
    <BlogItemBacklinksEnabled>
     <a name="links"></a><h4>Backlinks:</h4>
     <dl id="comments-block">
    <script type="text/javascript">backlink = new Array();BL_Backlinks = new Array();</script>
    <script type="text/javascript" src="http://www.blogger.com/dyn-js/backlink.js?blogID;$BlogID$>&amp;postID=<$BlogItemNumber$>" defer="true"></script>
    <div id="blogger-dcom-block<$BlogItemNumber<div id="blogger-dcom-block<$BlogItemNumber<div id="blogger-dcom-block<$BlogItemNumber<div id="blogger-dcom-block<$BlogItemNumber<div id="blogger-dcom-block<$BlogItemNumber<div id="blogger-dcom-block<$BlogItemNumber<div id="blogger-dcom-block<$BlogItemNumber<div id="blogger-dcom-block<$BlogItemNumber$>" style="display:none">
    amp;gt;" style="display:none">
    amp;gt;" style="display:none">
    amp;gt;" style="display:none">
         <dt class="comment-title">
         <span class="comment-toggler"> </span>
         <a href="<$BlogBacklinkURL$>"><$BlogBacklinkTitle$></a>
         </dt>
         <dd class="comment-body"><$BlogBacklinkSnippet$>
         <br />
         <span class="comment-poster">
         <em>posted by <$BlogBacklinkAuthor$> @ <$BlogBacklinkDateTime$></em>
         </span>
         </dd>
     </div>
    <script type="text/javascript">BL_writeBacklinks('<$BlogItemNumber$>');</script>
     </dl>
     <p class="comment-timestamp"><$BlogItemBacklinkCreate$></p>
     </BlogItemBacklinksEnabled>
    </div>
    
  5. Find the code for the ‘links to this post’ link in your post footer template code and replace it with ‘<a href=”javascript:toggleitem(‘backlinks<$BlogItemNumber$>’);”>links to this post</a>
  6. Save your template and republish your blog!

Blogger Comment Syndication Service

Posted on

I have completed the a Blogger comments syndication service, which grew from a hack I proposed on Some Assembly Required. Dubbed Blogger Recent Comments, this service takes the URL to a compatible Blogger blog and generates an RSS, JSON, JavaScript, or XHTML feed of the recent comments to that blog. It can also generate feeds for recent comments to individual post pages. For blogs that are set up per the instructions, comments are archived by the service as they come in, the service being notified of new comments via email, thus enabling the service to include new comments to old posts in the feed (unlike the Farrago Recent Comments Hack, which only shows new comments to posts on the main page). Setting up your blog to be compatible (per these instructions) is relatively painless, and afterwards you should never have to worry about it again, but you gain the benefits of comments feeds and optional sidebar elements.

Tags: Blogger Comments Hack

Commentosphere – Name, URL, Some Other Thoughts

Posted on

I have decided that, at this early stage at least, the name for Commentosphere is rather immaterial. The URL comment.ning.com, is sufficiently abstract, I think, to be maintained no matter what the service ends up being called. Even though the scope of the service may well prove to be outside that of blog comments, the URL works well enough for (as they may be termed) comments on forums and other things as well. Should a move be in order it will be dealt with when the time comes, but I think that, for now at least, the current URL will suffice.

I have been talking some with Yoz Grahame (from Ning) about Commentosphere. Most of this discussion has centred around the methods of getting data into the service. A summation of the results follows, and I will be quick to point out that most of this idea is his with only minor additions of my own.

Write a JavaScript piece that is hosted on Commentosphere and can be included by blog owners in their pages. Then, on the occurance of a comment posting form in the page, a function defined in this JavaScript can be called with a reference to the comment form itself, and to the names of the necessary fields (comment content, poster name) and other data (page title, page url, these cannot be pulled by the JavaScript itself because the script may be running on the blog’s main page). The script then alters the form to include a checkbox (defaultly checked) that turns on/off the automatic posting of any comments entered into that form to Commentosphere. Optionally, fields for tagging the comment and specifying parent(s) may be added by the script. Additionally, a small piece stating wheather or not the user is currently logged in on Ning will be inserted.

If the user is logged in, then when they post the comment to the blog it will automatically also be added to their account on Commentosphere by the method described below. If the user is not logged in, and chooses not to sign in (or has, indeed, no account) the comment will still be added, but to an anonymous account and merely have the user’s name (as specified in the appropriate place on the form) stored for display purposes.

For Blogger blogs that use the Blogger comments form, a simple Greasemonkey script will suffice to inject a script tag into the page calling this same script from Commentosphere with the appropriate data being supplied by the Greasemonkey script instead of the blog template.

The posting method runs as follows : An onsubmit handler is added to the comment posting form. When it is run it creates a new Image object and loads into in an image which is really the result of a PHP script running at Commentosphere. Data is pulled from the form and passed to this script via GET (so the URL to the ‘image’ would be something like http://comment.ning.com/addExternal.php?content The function loops until Image.complete is TRUE, and then returns TRUE, thus waiting until the request to Commentosphere has completed before submitting. If the user is logged in this cookie will be passed with the image request and the script will detect it and add the comment to the correct account. No popup windows.

I can find only one potential problem with this method, and that is that the comment’s permalink URL is not set until it has been posted into the blog system, so how could that be passed to the server beforehand? It warrants some thought, however, because if this worked it would make Commentosphere an almost seamless service.

Tags: