I’ve made a few tweaks to my theme, inspired by some of the entries at Alex King’s WordPress 1.5 Theme Competition. Most notably, the page menu is now at the top of the page.
Programming
Header Graphic
I’ve added a simple hack to the default Kubrick theme which displays a random header graphic. Here’s how it works. I added the following function to the top of header.php:
NOTE: this must come AFTER the doctype & html lines.
<?php
function header_graphic() {
echo "/images/";
$num=rand(0,8);
echo "kubrickheader".$num.".jpg";
};
?>
Next, I changed the style element for header as follows:
#header { background: url("< ?php bloginfo('stylesheet_directory'); header_graphic(); ?>") no-repeat bottom center; }
Finally, I saved several header graphics in my image directory named kubrickheader0.jpg through kubrickheader7.jpg.
If you’d like to see the different graphics, here they are:
kubrickheader0.jpg
kubrickheader1.jpg
kubrickheader2.jpg
kubrickheader3.jpg
kubrickheader4.jpg
kubrickheader5.jpg
kubrickheader6.jpg
kubrickheader7.jpg
kubrickheader8.jpg
kubrickheader9.jpg
UPDATE: I should have specified that the code needs to come after the first two lines in header.php. I also added links for the two new pictures I added after I posted the article.
Fixed!
I finally fixed a communication problem I’ve been working on for a few weeks caused by a timing issue. It’s lots of fun trying to debug something in which you can’t use a debugger. Since it’s timing dependent, the only way to debug is by putting in lots of debugging messages and watching the log carefully. It was really starting to wear on me, and finally fixing it is a huge relief.
Coding
For the past few weeks I’ve been buried in some pretty gnarly code, but it’s finally starting to fall into place. I’m converting some old code which used Open Transport to cross-platform BSD sockets.
Burn it!
Since more than half of the visitors to MacMegasite read the RSS feed, I’ve decided to take advantage of it by putting ads in the feed, using FeedBurner. Since FeedBurner doesn’t modify the original feed but creates a new modified feed, I needed a way to get ads in my existing feed. One way to do it is by adding a redirect for the RSS file.
Since Drupal uses a dynamically generated feed, that isn’t so easy. I figured out a simple work-around with a small patch to node.php. My patch creates a private feed URL and redirects /node/feed to the FeedBurner feed. Here’s how to do it:
Find the function node_page() in modules/node.module and look for the switch statement which dispatches the command. You’ll see the following lines:
case 'feed':
node_feed();
return;
Change it to
case 'something_random_here':
node_feed();
return;
case 'feed':
header("Location: http://feeds.feedburner.com/macmegasite");
return;
Use some random value for the command which will invoke node_feed() and use that only as feedburner’s source. Now your private URL is used to access the actual RSS feed and /node/feed will be redirected to feedburner’s modified feed.
File downloads in Drupal 4.5
When I upgraded MacMegasite to Drupal 4.5 I got rid of the old filestore module I was using for downloads. Instead, I’m now taking advantage of the new capability to attach files directly to a story. I created a download page which lists the 20 most recent attached files. I found that the best way to add a new feature to the site is by putting the PHP code in a file and then creating a PHP page which simply includes it and add a URL alias to that page. That’s how I created the store & feedback pages. It’s a lot easier than writing a Drupal module.
Weird XCode problem
I’m having a very weird problem with an XCode project. It’s a converted PowerPlant project. I’m able to build it on both of my machines, both interactively from inside XCode and using the xcodebuild command line tool.
When one of the other programmers tries to build it on his machine, he can build it from inside XCode but when he uses xcodebuild he gets lots of files not found (all of the PowerPlant headers included from the prefix header). We’ve verified that he’s set up the CodeWarrior source tree in XCode and all of the paths are correct in the project. In the logs from his computer, I see it’s failing on the ‘ProcessPCH++’ step, which isn’t even being run on my machine. Yet he’s able to build successfully from within XCode.
Any ideas?
Automated SQL injection
Via Lockergnome Bytes:
Automated SQL injection: What your enterprise needs to know: “SQL injection exploits may soon be as common as those targeting Windows and Unix flaws, experts say. An estimated 60% of Web applications that use dynamic content are likely vulnerable, with devastating consequences for an enterprise. A presentation of an automated attack targeting SQL injection flaws is planned for Black Hat Briefings this week in Las Vegas. This two-part interview with SPI Dynamics CTO Caleb Sima will tell you what you should fear, why and…”
This is why PHP-Nuke should be avoided. It doesn’t attempt to be secure, with user-provided values passed directly to SQL queries without any error checking or quoting. Drupal, on the other hand, never passes any user-provided values directly to any query.
ADHOC Blogging
I’m now at the ADHOC conference and David Pogue is giving the keynote. My first impression is that it’s a lot smaller than the usual MacHack and has a very low-budget feel. There are only about 100 people rather than the usual 200-300. A lot of people who were here previous years weren’t here. I think this was the first MacHack that Leonard Rosenthal didn’t attend. Even Miro isn’t here.
We only have half of the main hall where the keynote & hack show was held. Internet access was a bit different. There’s no DHCP server; we have to obtain a static IP address.
At first there were no power strips in the atrium. We had to beg for them in the machine room. The keynote is as much fun as always, so maybe things will pick up for the rest of the conference.
ADHOC Conference
I leave tomorrow morning for ADHOC Conference (formerly MacHack). Posting will probably be light the next few days.