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.

too much Christmas music

Okay, it’s two days after Thanksgiving, and I’m already tired of Christmas music. They started piping in music here on Main St. yesterday, and kept it going until a little after 10pm. They’re doing it again today. I’d really like to stay in for the most part this weekend, and get some stuff done, but I may have to go out just to escape having “Feliz Navidad” pounded into my head for the thirteenth time today.

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.

Wii Games

Well, I’ve spent a few minutes playing Cars and Super Monkey Ball: Banana Blitz on the Wii. Cars is kind of disappointing. The only use it really makes of the Wii remote is for steering, and it doesn’t seem to work real well for that. I’ll have to give it some more time and see if I get any better at it. SMB, on the other hand, makes pretty good use of the remote. And any game where you’re controlling a monkey in a plastic bubble has got to be good, right?

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.

Nintendo Wii

I bought a Wii yesterday. I wasn’t really planning to get one, but I was Christmas shopping at the Times Square Toys R Us, and they had a bunch of them, so I just picked one up. I figured that if I didn’t like it, it’d be easy enough to get rid of, either on eBay or to someone at work. I’ve only had a chance to play with it a bit today, but so far, I like it. The controller is pretty easy to use and intuitive under Wii Sports. I haven’t tried any other games yet.
This page at ComputerWorld has a good round-up of opinions on the Wii from around the web.