On the first day of Kirby Week, Four Island gave to me: A tutorial on coding a blogging engine.

Welcome to Kirby Week 2008. As I told you yesterday, I'm going to spend this week teaching you how to write your own blogging engine. As we go along, we'll be adding many enhancements and such, but for now, we'll be starting with the basics. The blog you will be building will be loosely based on the SimpleBlog engine.

To do this tutorial, you, of course, need:

  • A Web Server
  • PHP
  • MySQL

We'll start with creating the base directory structure. In your webroot, create a folder called kirbyweek08. Create a css folder inside that folder.

Next, we need to set up the database. Create a new database called "kirbyweek08" and use this schema to create the tables:

CREATE TABLE `posts` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(255) NOT NULL,
  `text` text NOT NULL,
  `slug` varchar(255) NOT NULL,
  `pubDate` timestamp NOT NULL default CURRENT_TIMESTAMP,
  `tags` varchar(255) NOT NULL,
  PRIMARY KEY  (`id`)
);

We need to let your site connect to the database. So, create a db.php in the kirbyweek08 folder, and put this in it:

<?php

$dbwebhost = 'localhost';
$dbwebuser = 'root';
$dbwebpasswd = '';
$dbwebname = 'kirbyweek08';

mysql_connect($dbwebhost, $dbwebuser, $dbwebpasswd);
mysql_select_db($dbwebname);

?>

$dbwebhost and $dbwebname are probably correct for you, but swap in the correct values for $dbwebuser and $dbwebpasswd (a.k.a. username and password of someone with permission to access and modify the kirbyweek08 database). Now that that's done, we can start making the blog.

Create an index.php file in your kirbyweek08 folder, and put this in it:

<?php

require_once('db.php');
require_once('functions.php');
include('header.php');

$getposts = "SELECT * FROM posts LIMIT 0,4";
$getposts2 = mysql_query($getposts);
$i=0;
while ($getposts3[$i] = mysql_fetch_array($getposts2))
{
    displayPost($getposts3[$i],true);

    $i++;
}

include('footer.php');

?>

A little explanation is required here. First, this file connects to the database by loading the db.php file we created before. Second, it loads a file called functions.php that we haven't created yet, and a file called header.php that we also haven't created yet. These files will contain useful functions reused often in your code, and a header to display above every file, respectively.

Next, the file downloads the latest four posts from your database and uses a function called displayPost() to display it. Finally, it loads a non-existent file called footer.php which will contain a footer.

The most important part is the displayPost() function. It will lie in the functions.php file. Instead of posting the code, I'm just going to link to it because it's rather long and it goes off of the side of the post.

Wow! That was a lot. Don't worry, that's the longest code snippet in this application. Whew. I think it's time for testing. However, if we test it now, there'll be nothing to see. First, add a record to the posts database.

The fields are simple. Ignore id and pubDate, they're automatically generated by MySQL. title and text should be self-explanatory. tags is a comma-deliminated list of tags for the post. Now we can test it.

You should see your post, surrounded by tons of errors. Oops. We forgot to make the header and footer! Also, you'll notice that it's saying your post is by "Anonymous". Want to fix that? Notice at the top of functions.php, a variable named $author. Set that to your username and you're set.

Let's create that header. Basically, you can put whatever you like in it. Just remember that it is pasted above the contents of every file, so make sure that a <BODY> tag has been opened by the time the file ends. Use this as an opportunity to theme this new blog with the rest of your site! Follow suit with footer.php as well, it's just a footer.

Nearly done! Now, all we have to do is create the other two files linked to by the displayPost() function. Here's read.php:

<?php

require_once('db.php');
require_once('functions.php');
include('header.php');

$getpost = "SELECT * FROM posts WHERE id = " . $_GET['id'];
$getpost2 = mysql_query($getpost);
$getpost3 = mysql_fetch_array($getpost2);

displayPost($getpost3, false);

include('footer.php');

?>

And tag.php:

<?php

require_once('db.php');
require_once('functions.php');
include('header.php');

$getposts = "SELECT * FROM posts WHERE tags LIKE \"%" . $_GET['tag'] . "%\" LIMIT 0,4";
$getposts2 = mysql_query($getposts);
$i=0;
while ($getposts3[$i] = mysql_fetch_array($getposts2))
{
    displayPost($getposts3[$i],true);

    $i++;
}

include('footer.php');

?>

We'll, we're pretty much done! I know, I know, it's mediocre. Don't worry, during this week we'll really spruce it up. Thank you for surviving that long tutorial, the rest is more fun.

You'll have noticed that there's no way you can post to this blog short of manually editing the database. Tomorrow we'll be looking at creating an admin panel for you to use for your bloggy funness. Enjoy!

Hatkirby on
👍 7 👎

I'm glad to see many "I LOVE ITs" for TGS, because it's such a great project. For you who don't know what it is, see this: The Greatest Story.

I LOVE IT. - 9 vote(s)! It's an interesting idea. - 0 vote(s)! What the negative is it? - 2 vote(s)! **** - 0 vote(s)!

I'm sure you all know, Kirby Week 2008 starts today! For those who don't know, Kirby Week is the third week of advent, when the candle is pink. Yes, I know, that wasn't funny. :)

I started the strange idea of Kirby Week in December 2006, a year before Four Island even existed. Since then, each Kirby Week has been a week of fun, joy and excitement at the holiday to come. Starting this year, I'd also like to do something for Four Island during Kirby Week.

I've decided that during Kirby Week, I shall post a weekly special (like VisitorGrid Week) on a set topic. Sound like fun? I hope it does!

This year's topic is how to code your own blog. TimTam has been nagging me to do this anyway, so I might as well use it for Kirby Week!

And also, I've decided to do use last year's Kirby Week poll for this year as well. So, all in all, I hope you all enjoy Kirby Week 2008!

Hatkirby on
👍 0 👎

This sort of goes hand-in-hand with yesterday's post of drastic changes. I often get the urge to switch to Wordpress for my blogging engine, instead of the homebrew one I currently use.

I mean, I have pride in my own work, my own, extremely customizable, hand-typed code, but sometimes, Wordpress just really looks attractive with all of it's power and the more dedicated work put into it by a team of people.

I just started reading Lorelle again, and the first post I saw was about the new release of Wordpress that came out yesterday, 2.7. I was a little interested, but what really caught my attention was the new admin panel. It looks soooooo good! How can I resist?

It's hard, resisting a wonderful looking package (that, by the way, Color Pencils and Dream Weaver use) for my own work, but it's worth it. While I don't get the same degree of power and looks, I get the power that I want that Wordpress can't provide as easily: complete freedom.

If there's something my blog isn't doing correctly, I can just go into the source code and fix it. If there's something in Wordpress, if I was using it, that I was unhappy with, I'd have to go hack it or try to write a good plugin.

For instance, at one point, when I was developing the 7th layout that will not exist, I was using Wordpress on the development machine. However, the first, instantly noticeable problem was, "How am I going to have a pending queue?" The thing that I find most useful with my blog is that I can just write posts to it and they're posted on a daily basis, without any required intervention from me.

Wordpress can't provide that the way I want. It does have a scheduled posting feature, but with that, you have to provide the exact date and time you want each post to be posted. That wouldn't work for me, because sometimes there's an emergency post I have to post instantly, and let the pending queue delay for one day. With Wordpress, I'd have to manually edit each post and change the post date.

This would also happen if I decided to make a simple change in the order of the posts in the pending queue. With Four Island, I click on the "Move Up" or "Move Down" button next to the necessary post. With Wordpress, I'd have to manually edit both posts in question. And what if I wanted to move a post more than one space? shivers

So, in conclusion, and without a reason to care, I don't want to use Wordpress, no matter how.... tempting it may be. And I'll try to stand by that. And if that means forcing my readers to yell at me and not read my site anymore if I switch to Wordpress, so be it. :)

Hatkirby on
👍 7 👎

Yes, this is a reference to TimTam's I Was Sleepy. It made me think. How may of us blog people like to make random, drastic changes to their websites without thinking of the consequences and hating it later? Or is it just me?

Speaking of randomly induced drastic changes, I almost decided to release a layout #7 for Four Island, so soon after the 6th layout was released, but in the end, I decided to use the theme for the TGS webs----oops! Wasn't supposed to say that yet. Oh well, I'm going to be posting about it soon enough anyway. :)

So, how many of you out there do this? Random drastic changes? Not even just your blog! I once changed my username on the Fourm to "Starla", quickly realized that it went against my statement of anonymity (though everyone knows my name anyway) and changed it back to "hatkirby". (I actually also then changed it to "StarlaXY". It was meant to be "StarlaXYZ", but I seemed to have missed the "Z" and was too lazy to fix it)

Omigosh, I just realized, I just made another stupid question post. Oh, don't groan! I love it when people contribute! COMMENTS! GIVE ME COMMENTS! AND PINGBACKS! :)

So, anyways, here's the link to the last question post: Say What?

Hatkirby on
👍 -2 👎

Say What?

Ok. I'm going to admit it without caring about the abuse I will get from various people for not admitting it earlier (I'm looking at you, TimTam). I like Firefox more than Internet Explorer. There, I said it.

I don't really know why I didn't say it before, I guess it's just part of the "pride" package that comes with not using Wordpress for your blog. :)

The reason I'm bringing this up is because IE is being SO ANNOYING. Any viewers out there use IE? Yes? You're lying. If you were, you couldn't read this post. For some reason, IE is hiding the text of all of my posts, horribly disfiguring The Fourm and generally being mean to Four Island.

Does anyone know why this could be? It's not just IE 6, 7 is doing it too. I've tried using the IE 7 script (the one that makes IE into a standards-compliant browser) but it doesn't work for me. So, if anyone has any ideas, I'm open! I guess this is a question post, then.

The standard seems to be to link to the last question post in all question posts, so I'll try to do that here. I think the last one was Tag Clash, but I may be wrong. :)

And yes, this post's title is a clear indication that I've been watching too much Hannah Montana. :)

Hatkirby on
👍 -2 👎

Bzipped Tar

This always seems strange to me. Why do most people on the internet that provide software packages, such as Linux packages that do not have standard distribution formats, or PHP sites like Wordpress, always distribute their software using gzipped tars? As in .tar.gz

I mean, really. Bzipped tars (.tar.bz2) are a much better way to compress things. Bzip2 is a much more effective compression algorithm than Gzip. I always use bzipped tars to archive my data.

Or wait. Is there some kind of deficiency with the algorithm that I don't know about? Am I going to wake up one day and find all of my backups useless? Oh dear, now I'm scared. :)

So, what is with bzip2? Is it just that people can't be bothered to switch to it, or is there some huge bug that'll eat Four Island?

Hatkirby on
👍 1 👎

Ok. So, I found about Automattic's new commenting system thing, IntenseDebate from CSS-Tricks. The features list made it sound really good, so I tried installing it, and I also got Drifty and Timbo94 to install it on their blogs too.

Well.... it's interesting. I mean, it does have it's good features, which are great, like reputation and threading and generally looking nice. But there is a problem.

It's so slooooooow! I mean, it loads quickly enough, but when I sit down to type in a comment, I'm way ahead of it and the letters are appearing the box one.... by.... one.... very.... slowly and I'm just sitting there, waiting for everything to appear so I can figure out what spelling mistakes I made.

So.... I guess IntenseDebate is pretty good. However, I'd like to argue about it with someone, so we can do that here. :) I've uninstalled IntenseDebate for the time being because I can't really have it perfectly yet until I hack the Wordpress plugin, so we're back to Four Island comments for now!

Or, even better, we can deblatog about it!

Hatkirby on
👍 -2 👎

Well.... I can see now that Layout 6 has to go. Oh well. I have to stop trying to change. :)

YES!1!1!1!1 - 2 vote(s)! It's, like, ok - 6 vote(s)! No - 10 vote(s)! Indifferent - 0 vote(s)!

So yes, I guess we are once again back at Layout 4. There have been two unsuccessful attempts to move to a new layout. It seems Layout 4 is quite popular. I'll try to resist the urge to change again, kay?

So, you people will start coming back to Four Island now that Layout 6 is gone, right? Right? :)

EDIT: Oh dear, it seems like I'm just being paranoid. People actually do like Layout 6. So, we're back to it. However, Layout 6 still clashes with IE. GAH, have to fix that.

Hatkirby on
👍 2 👎

Ok. Recently, I (OMG, I didn't mean to!) attempted to help an acquatience activate their copy of Windows XP, which was expiring in a day. Their computer was really old, and it had a copy of Xubuntu Gutsy on it, but they preferred Windows XP for some strange reason.

So, I though, this'll take five seconds. Oh, but I forgot to mention, their computer didn't have internet access. Oh well. At least there's an automated phone service used to handle Windows activations (toll-free!).

So I called the number for my region and waited. It asked me a few questions like "Are you activating Windows XP?", but it wanted me to say yes or no. Confused, I answered, but the next part was the GAH.

The computer at the other end told me to recite the Windows XP activation code to her. This is a some 32 digit long number and I have to TELL her it instead of just typing in the numbers on the phone.

Warning: If you're ever trying to do this, get someone to do it who has no emotions. I giggled after the first block of numbers and the computer said: "I did not understand that. Good bye."

Oh, and by the way, it turned out that they had an expired version of Windows XP anyway, so the time I spent was futile. Oh well, at least it was funny. :)

Hatkirby on
👍 1 👎