Block Comments after X days

Eugenia (who used to write for BeOS sites, back in the day) wanted to know how to stop comments from being posted on posts that are over 10 days. I’ll generalize this to X days, just for completeness. You need to get the date of the post, and the current date. I’ll get the post date, and put it into a variable: {capture name=pdate}{the_time d=“U”}{/capture} {$smarty.now} Now, you need to subtract the two of these: {$smarty.now - $smarty.capture.pdate} Note that it will be somewhat incorrect, as {$smarty.now} is server time, whilst {the_time} is WordPress time. Now, this gives us a value in seconds, so we want to work out how long X days is in seconds. This, again is simple: X days = 60*60*24 seconds X days = 86400 seconds {capture name=diff}{$smarty.now-$smarty.capture.pdate}{/capture} Now, the actual code to display the error message is: {if $smarty.capture.diff/86400 > 10}     I'm sorry, Comments are now closed. {/if} But, we want this to appear instead of a comment form, so you’ll need to find the line that looks a bit like: {if 'open' == $post->comment_status} And replace it with: {if $smarty.capture.diff/86400 > 10}     I'm sorry, Comments are now closed. {elseif 'open' == $post->comment_status} Naturally, replace 10 with however many days of comments you wish to allow.

Electrocution (Hydro Mix)Decoder RingSomersault ★★½

Stickies No Longer Editable

I use MacOS X Stickies as desktop reminders, and by an large they are very cool. Just recently, however, they got a whole lot less useful for me. Something has gone wrong, and I can no longer edit the text in any sticky note. I can select it, and I can paste into it, but I can’t type into it. And, before you ask, I’ve trashed the prefs, and deleted my ~/Library/StickiesDatabase file, all to no avail. And google can’t tell me anything about it either.

Back to Dialup

If you’ve been following the saga with Veridas, you may have noticed that whilst the network was up briefly, it went down again. I’ve now connected with another ISP, and have a complimentary dialup account to use until my churn completes. And man, dialup sucks…

Veridas back on the air?

It seems like Veridas, the wholesale ISP that my ISP goes through, is back providing internet access, at least to some degree. It’s billing system is back up online, but the home page, and the pages of my ISP are not. I’m still at work, so I can’t see if my ADSL is back, but I hope it is.

ISP Issues

Well, I can’t get onto my less-than-one-month-old ADSL connection, since Veridas, the upstream ISP for Opti has apparently gone belly-up. The bad thing about this is that it also affects some files I was hosting there (and, worse, the files Jaq had set up for her web site). I can’t even set up a replacement web site, as the files are only on my home computer, and I have no access from home. Not even dialup.

Getting Child Categories

I’ve been racking my brain thinking about how to get child categories of a specific category. And I think I’ve just figured it out. Examine all of the other categories in a complete list, and grab all of them that have the current page’s URL at the start. The next word will be the sub-category . Of course, knowing how to split stuff in Smarty is a bit difficult. I was thinking in JavaScript…

It Don’t HurtSheryl CrowThe Globe Sessions ★★½

Talk Like a Pirate Day.

My pirate name is:

Calico James Flint

Often indecisive, you can’t even choose a favorite color. You’re apt to follow wherever the wind blows you, just like Calico Jack Rackham, your namesake. Like the rock flint, you’re hard and sharp. But, also like flint, you’re easily chipped, and sparky. Arr!

Get your own pirate name from piratequiz.com.
part of the fidius.org network

Cross-browser AJAX

I need a simple wrapper for a Mozilla/Safari and IE compatible XMLHttpRequest(). Perhaps something like (courtesy of Apple):

    function loadXMLDoc(url,method,readyFunc) {
        req = false;
        if (method) method = "GET";
        // branch for native XMLHttpRequest object
        if(window.XMLHttpRequest) {
            try {
                req = new XMLHttpRequest();
            } catch(e) {
                req = false;
            }
        // branch for IE/Windows ActiveX version
        } else if(window.ActiveXObject) {
            try {
                req = new ActiveXObject("Msxml2.XMLHTTP");
            } catch(e) {
                try {
                    req = new ActiveXObject("Microsoft.XMLHTTP");
                } catch(e) {
                    req = false;
                }
            }
        }
        if(req) {
            req.onreadystatechange = readyFunc;
            req.open(method, url, true);
            req.send("");
        }
        return req;
    }

document.documentURI vs. location

Apparently, document.documentURI and document.location are not identical. Basically, document.location is not a string, so to treat it like one, you need to do: (document.location+"").split("/") Instead of: document.documentURI.split("/") Stupid IE.

Inline Search

I’ve implemented a new feature on my blog, which I think is pretty cool. Over the the right is a new box labelled: Beta: Inline Search. Try typing something into it, and pressing return, or clicking the button. Wait a few seconds (depending on connection speed) and search results for this blog should appear underneath. It’s still fairly rudimentary - I plan to make a “working” indicator, plus the ability to search for more results. But I guess you want to see the code…

    function SearchBlog(){
        window.searchreq = new XMLHttpRequest();
        var s=document.getElementById("s").value.replace(/ /g,"+");
        searchreq.open("POST","/category/&s="+s);
        searchreq.onload = UpdateSearchResults
        searchreq.send("")
    }
    
    function UpdateSearchResults(){
        if (searchreq){
            if (searchreq.status==200) {
                data = searchreq.responseText.split("<body>")[1].split("</body>")[0];
                temp = document.createElement("div");
                temp.innerHTML = data;
                if (temp.getByClass) {
                    results = temp.getByClass("post-title");
                }
                var resList = "Results:<ul>";
                for (var i=0;i < results.length; i++){
                    resList = resList + "<li>"+results[i].innerHTML+"</li>";
                }
                resList = resList + "</ul>";
                document.getElementById("searchresults").innerHTML = resList;
                data = "";
                temp = "";
                resList = "";
            }
        }
    }

You will need to have a getByClass() function installed - if you don’t, it’s:

    /* 
        Thanks to Dustin Diaz for this one:
        http://www.dustindiaz.com/getelementsbyclass/
        */
    document.getByClass = function(searchClass,tag){
            var classElements = new Array();
            if (tag==undefined){tag="*";}
            var els = this.getElementsByTagName(tag); // use "*" for all elements
            var elsLen = els.length;
            var pattern = new RegExp("(^|\s)"+searchClass+"(\s|$)");
            for (i = 0,j = 0; i < elsLen; i++) {
                if ( pattern.test(els[i].className) ) {
                    classElements[j] = els[i];
                    j++;
                }
            }
            return classElements;
        }

BarbarellaFerrante & TeicherUltra-Lounge, Vol. 16: Mondo Hollywood ★½