Archive for April, 2004

Weekends… How quickly they come and go…

Monday, April 19th, 2004

All in all it was a pretty good weekend. I devoted some time on Sunday to playing around with the Google API and I quickly came up with a full google-clone minus paging. After playing with two of PEAR’ classes Pager and Pager_Sliding I was reminded of how hit and miss most of the PEAR libraries are. The PEAR libraries are focused on two slightly different approaches to solving paging with large sets of data. Both classes focuses on loading a larger subset of information but only showing a small subset of information. I was hoping more for something to facilitate loading the count of information found and then I’ll control which records need to be displayed. Needless to say, PEAR goes by the way side, and I’m back to writing my own.

After I had a few queries and some simple information printing on the screen, I decided to start working on adding it to the WordPress theme of my website (similiar to my news aggragator page). While WordPress is an excellent blog tool, the theme support in it has alot left to be desired. Instead I was forced to either grab a static copy of the site (yuck) or try to work with the “PHP” as a templating language approach.

I can safely say, after 5+ years of professional website development, there are those who get templating and layers and those who never will. After seeing this post on SitePoint’s PHP Forums, it reminds me of how tired I’ve grown of the age old debate. To sum it up, if you plan on a project being around for the long haul, a good template library is crucial to the long term maintainabilty and extendability of that project. With that said, I prefer to have a PHP logic page with 10 to 25 lines of code with an html template of 10 to 15 lines of html then I would at having a scattered mess of several hundred lines of mixed html + php code.

(Please forgive the lack of formatting below… WordPress didn’t handle parsing the code + html template as well as I would have liked.)

example.php

< ?php
include( 'bTemplate/bTemplate.php' );
include( 'SOAP_Google.php' );
$google = new SOAP_Google( 'YOUR_GOOGLE_API_KEY_HERE' );
$result = $google->search(
array(
‘query’ => ‘Google Term Here’
)
);
if (false !== $result)
{
foreach( $result->resultElements as $search_result )
{
$search_results[] = array(
‘URL’ => $search_result->URL,
‘cachedSize’ => $search_result->cachedSize,
‘directoryTitle’ => $search_result->directoryTitle,
‘hostName’ => $search_result->hostName,
‘relatedInformationPresent’ => $search_result->relatedInformationPresent,
’snippet’ => $search_result->snippet,
’summary’ => $search_result->summary,
‘title’ => $search_result->title
);
}
}
else
{
echo ‘Query failed.’;
}
$template =& new bTemplate();
$template->set( ’search_results’, $search_results );
echo $template->fetch( ‘templates/search_list.html’ );
?>

And the matching template:



< loop:search_results >
< p>
< a href='< tag:search_results[].URL />‘>< tag:search_results[].title />< /a>< br/>
< tag:search_results[].snippet />< br/>
< tag:search_results[].URL /> -
< tag:search_results[].cachedSize /> -
< a href='< tag:search_results[].URL />‘>Cached< /a> -
< a href='example.php?searchQuery=related:< tag:search_results[].URL />‘>Similar pages< /a>
< /p>
< /loop:search_results>

While bTemplate is hardly the *ideal* Template language to use for all things, it does a really good job of handling arrays and loops in templates. While most Template libraries such as PHPLib force a programmer to focus more on the complexity of handling loops in loops, bTemplate allows you to submit your array to the template and it handles the looping logic. Ah, a template language that makes a complex / harder to maintain piece of code and simplifies it…

Some day I’ll have enough time to give this topic the attention it needs. For now, if WordPress was templated, I’d have a nice and pretty google search within mysite instead of a more simplistic google hack.

Agragated Technology News Feeds Now Public

Monday, April 12th, 2004

About two months ago I started a project to pull news feeds from various sources and to organize them by content. I’ve thrown together a very quick and dirty version that serves mainly as a one stop place to see the latest headlines from various technology and programming related (with emphasis on PHP). The current version of the page will only show the current day’s headlines but I should have a more complete rewrite up by the weekend. For now, visit my news feeds page.

The current system will scan various RSS feeds every 15 minutes and will catalog those changes. When a new feed is added, every reference in that feed shows up as a new article, and that’s why there is a long series of goolge news and slashdot articles instead of an even misture. Some features that I’ve been playing with include interfacing with google and amazon.com to find more content on the subjects and various reference sources.

Once the categories are up, my plan is to build several mini-sites to allow for news / content to be funneled in along with product information to make several on-going informational websites. Sites that keep themselves updated and provide links to new / best selling products that relate to that subject. Until that is ready, I will be looking for good news feeds and good sources for syndicated news feeds (RSS).

Quick Linux Scripts

Wednesday, April 7th, 2004

The need to find Linux files above size-x always seems to come up. I typically nail down the syntax to the find command after referencing the man pages and/or a quick google search. The following will find files in /var:

find /var -size +100000k

I finally had time to play with logrotate. It’s surprising simple and easy to use. Here is an example script that will rotate apache logs when they reach 30M or that are 1 day old (controlled by cron.daily):

/var/log/httpd/httpsd_access_log /var/log/httpd/httpsd_error_log {
missingok
size=30M
sharedscripts
postrotate
/bin/kill -HUP `cat /usr/local/apache/logs/httpd.pid 2>/dev/null` 2> /dev/null || true
endscript
}