blog changes

Not that anyone’s going to be that interested in this, but I made a couple of changes to the sidebar on this blog today. First, I removed the Technorati and Spurl widgets. I guess I never really figured out what the point of Technorati was, and the little widget I had on the side didn’t seem to serve much of a purpose.

Spurl, on the other hand, is a great web-based bookmark manager. Unfortunately, it appears to be a zombie site at this point; it’s still up and running, but at reduced functionality, and, looking at their user forums, it doesn’t appear that anyone’s minding the shop — there’s nothing but link spam in the forums right now. I’m still using Spurl, but I’m thinking about dropping it, since it’s probably going to disappear at some point. (I have a mental image of Spurl running on a server in a closet somewhere that everyone’s just forgotten about. At some point, the hard drive will die, or someone will find it and unplug it, and that’ll be the end of that.)

I’ve replaced the Spurl widget with a del.icio.us linkroll. I think that’s a little more representative of what I’m bookmarking lately.

And I reformatted the tag list. It used to be a bulleted list. Now it’s just the keywords separated by slashes. I just wanted to make it more compact, so you could see it all together easily.

Blogger label cloud

I just found a PHP script by this guy that does pretty much the same thing that my script does, except in the form of a cloud instead of a list. Nice. He also uses a cache file so he doesn’t have to read the directory on every call. Both of those were things that I had thought about adding to my PHP program. Now I can probably just borrow this guy’s code.

more fun with Blogger tags and PHP

I wanted to enhance my tag list PHP program to do a couple more things. Basically, I wanted it to be aware of when we are on a label page, so that we could make the list item for the current page plain text (instead of a link), and so that I could put a link back to the main page on any label page.
Normally, I have a link back to the main page in the header of any page other than the main one. I do this through the Blogger template, using the “ItemPage” and “ArchivePage” Blogger template tags to figure out when we’re not on the main page. Unfortunately, there’s no “LabelPage” template tag, as far as I can tell.
Making one of the list items text rather than a link broke the sorting, since I was just sorting on the text of the list item, including the “a href…” stuff. To get around this, I switched to using an associative array, where the key value is the tag.
Here’s the code:

<?php
$dirname = ".";                        # current directory
$uri = $_SERVER["REQUEST_URI"];        # the page we're on
$bOnLabelPage = false;                # are we on a label page?
$dir = opendir($dirname);
$file_list = array();
$i = 0;

while (false != ($file = readdir($dir)))
    {
    if (ereg(".html$", $file))
        {
        $tag = substr($file, 0, strlen($file)-5);
        $key = strtoupper($tag);
        if (ereg("$file$", $uri))
            {
            $file_list[$key] = "<li>$tag";
            $bOnLabelPage = true;
            }
        else
            $file_list[$key] = "<li><a href='/labels/$file'>$tag</a>";
        $i++;
        }
    }
closedir($dir);
#natcasesort($file_list);
ksort($file_list);
?>
<h1>My Tags</h1>
<?php
if ($bOnLabelPage) echo ("<a href='/'>[Back to main page]</a>");
?>
<ul>
<?php foreach ($file_list as $file) echo($file); ?>
</ul>

A little more complex than what I started with, but still not too bad.
As a side note, I am using TextWrangler to edit PHP files on my Mac, and it’s working pretty well. It’s got syntax-highlighting for PHP and HTML. I’m also now using Fugu to copy files up to my server. It integrates well with TextWrangler, so that I can just keep a file open in TextWrangler and have it copied back to the server every time I save. Nice.
On Windows, I’m mostly using Multi-Edit and WinSCP. That combo works pretty well too, though I’m using an older version of Multi-Edit that doesn’t have PHP syntax highlighting.

sorted list of tags

OK, this time I’ve revised my PHP code to show a sorted list of labels:

<?php
$dirname = ".";         # current directory
$dir = opendir($dirname);
$file_list = array();
$i = 0;

while (false != ($file = readdir($dir)))
        {
        if (ereg(".html$", $file))
                {
                $tag = substr($file, 0, strlen($file)-5);
                $file_list[$i] = "<li><a href='/labels/$file'>$tag</a>";
                $i++;
                }
        }
closedir($dir);
natcasesort($file_list);
?>
<h1>My Tags</h1>
<ul>
<?php foreach ($file_list as $file) echo($file); ?>
</ul>

Not a big deal, but it does show a (probably) typical use of arrays in PHP. As a side note, the “foreach” construct in PHP is a bit different from the usual foreach in other languages. It’s usually something like “foreach (item in list)”, while in PHP it’s reversed: “foreach (list as item)”. I should also mention that I first tried the regular sort() function, but switched to natcasesort(), since a case-insensitive sort makes more sense here.

Blogger Tags

Well, I wrote a quick PHP script to create a list of tag links that I could display on this page. It should be over to the left. The code is pretty simple:

<?php
$dirname = ".";         # current directory
$dir = opendir($dirname);

while (false != ($file = readdir($dir)))
        {
        if (ereg(".html$", $file))
                {
                $tag = substr($file, 0, strlen($file)-5);
                $file_list .= "<li><a href='/labels/$file'>$tag</a>";
                }
        }
closedir($dir);
?>
<h1>My Tags</h1>
<ul>
<?php echo($file_list); ?>
</ul>

I don’t have the tags showing in any particular order yet, but they’re all there. I just saved this code to a file in the labels directory on my server, then included it in my template with a server-side include.
Also, I should mention that I used this page to format the source code above so it would look OK in a blog post. (Hopefully, it does look ok…)

more Blogger weirdness

I think I just discovered that the post archive settings went slightly wrong at some point, either because of the change over to the new beta, or at some point in the past. Either way, I just fixed it by putting an explicit archive URL in the settings. I think. If the archive links don’t go where they’re supposed to, then maybe not.

Blogger Beta

I just switched this blog over to the new Blogger beta. I like having labels (aka tags) built into Blogger — that was overdue. I don’t like the fact that the BlogThis! bookmarklet doesn’t work anymore. And it looks like I can’t put a list of labels on this page for as long as I’m still using the classic template style. I’d have to switch to the new layout scheme.

Alternative Style Sheets

My dad has trouble reading this page since I switched to the fancy CSS layout. Apparently, all the fancy positioning and sizing screws things up when you’ve got your computer set up to use large fonts, a high-contrast color scheme, and so on. I’ve been meaning to implement an alternate style sheet for him, and I’ve finally gotten around to it, with the help of this article. If you look over at the link bar, you’ll now see buttons to switch between the “normal” style sheet, and a “basic” style sheet, which simply turns off most of the fancy stuff and basically switches back to a one-column design, with the left bar at the bottom of the page instead. The JavaScript code behind the buttons should set a cookie, so the style sheet choice will be persistent. Let me know how it works!

browsers

I tried the new design out in a few different browsers on my Mac. It looks fine in Safari, IE, and an old version of Mozilla. Just for yuks, I tried it out in a really old version of Netscape running under OS 9 mode. The CSS didn’t get handled at all, which was to be expected, but the page did show up in a readable form.