PHP + Elbow Grease…

Although I do use PHP and MySQL (as well as any other tool that fits) in many of my other projects, I have not implemented that style of solution for this website. (although the idea is quite tempting and will most likely happen in the coming months) I have tried some of the ‘canned’ blogging packages that have come out such as Movable Type, and while these packages surely fill a niche, and are very good at what they do, they do not do what this site requires. To know what this site requires, we must examine its purpose. Although ‘Intuition & Elbow Grease’ does serve as my blog and as a repository for a couple of other pieces of information, its primary reason for existence has been that of a proving ground for new code (sometimes for old code) To that end, I have tried to stay away from anyone else’s complete solution. I have surely borrowed bits and pieces along the way in order to aide in my understanding of one nuance or another, but hopefully the resulting concept is unique.

So how does this site really work? The basic building blocks are comprised of the Apache web server, PHP and of course a good smattering of Perl. No database backend has been necessary as of yet, but since I have been having quite a bit of fun designing databases and their associated web-based interfaces, one will probably arrive here soon.

To begin with, let’s look at some of the code that builds this page each time it is loaded:

if (empty($dd)) {
$data_file = "/my_home_dir/index.xml";
$list = file($data_file);

reset($list);
foreach ($list as $key => $val){
if ($key>12 && $key < 23){
$title_start=(strpos($val, "<title>")+7);
$title_end=(strpos($val, "</title>"));
$title=substr($val, $title_start, $title_end);
$link_start=(strpos($val, "<link>")+6);
$link_end=(strpos($val, "</link>"));
$permalink=substr($val, $link_start, 52);
$year=substr($permalink, -8, 4);
$month=substr($permalink, -4, 2);
$day=substr($permalink, -2);
$date=substr($permalink, -8);
$m=$month-1;

if ($title == $date){
$title="$months[$m] $day, $year";
}else{
$title="$title</a> <div id=\"date\">$months[$m] $day, $year</div>";
}

echo "<div id=entry><div id=title>";
echo "<a href=$permalink class=status>$title</a>";
echo "</div><ul>";
require ("/my_home_dir/weblog/$year/$month/$day");
echo "</ul><br>";
$comments= "weblog/" . $year . "/" . $month . "/" . $day . "-comments";
if (file_exists($comments)) {
echo "<p class=\"status\">Comments...";
require ($comments);
}
echo "<a href=\"weblog/comments.php?dn=$day&mo=$month\"";
echo "class=status>add a comment</a><br>";
echo "</div>";
}
}
}

Remember this is just part of the code, not all of it. At the beginning I check to see if the viewer is looking for a specific entry, noted as $dd. If you aren’t then I load an xml file (index.xml) to parse for the current ten entries. From the information in the xml file, I read in each of the specific entry files (and that’s what each entry is, a file in a structured hierachy to represent year, month and day) and format each entry with its permalink, date and any associated comments. When I wrote this code, php did not have any built in support for parsing xml files like it does now, so I hastily wrote the list section with all the ‘title_end’, ‘title_begin’ stuff. (This section is next on the list for a re-write) These variables help to parse the xml file into usable sections for display as this page.

There is a great deal more that goes on in displaying this page that I would like to discuss in greater detail over the next several days. Questions? Comments? Suggested improvements? Please post them below in the comments section or e-mail me directly.

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

WordPress Themes