Archive for the ‘PHP’ Category

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.

SmartPHP - Yet Another PHP Template Library

Tuesday, March 23rd, 2004

I stumbled on quite a find the other night with the SmartPHP template library. This library supports the normal features for a template library such as:

  • Simple Scalar Substition (strings, variables)
  • Block Iterations (nested Arrays / BEGIN..END)
  • Basic Control Structures (IF..ELSEIF..ELSE)
  • Custom Extension (Output filters, uppercase, sprintf, etc.)
  • Template Compilation (HTML templates are converted to executable PHP Code)
  • Output Caching (Accelerates your applications by reusing page output)

While there’s nothing in this library that hasn’t already been done before, it’s very fast and includes a powerful plugin / extension system. Extensions are easy enough to create and add another dimension to this library.

I’ve used bTemplate in the past because it handles block control structures in a much more intuiative manner then most template libraries. SmartPHP shares a very similiar approach, which coupled with the other enhancements, makes this a very powerful template library.

Installing XSLT for PHP in Windows

Thursday, August 21st, 2003

After searching this for the 10,000 time, here’s my quick how to for install XSLT in Windows.

  • Grab the latest win32 installer of Expat from SourceForge and install it.
  • Locate the expat.dll file the Libs folder of where you installed Expat and copy it into your Windows System32 folder.
  • Download the Windows binary release of Sabotron from the Ginger Alliance website.
  • Extract the zip file and copy the sablot.dll file into your Windows System32 folder.
  • Uncomment the php_xslt.dll extension in the php.ini file (remove the “;”).
  • Run phpinfo(); and double check that the XSLT extension has been loaded.

Back Again

Friday, January 24th, 2003

Overall Class Structure

I have decided to loosely base some of my data access classes on the “Data Access Object Pattern (+ More Widgets)” database model featured on phpPatterns. There is currently three layers to each entity: DAO -> EntityBaseClass -> EntityClass. The DAO layer allows for common code to be shared to every generated entity.

The EntityBaseClass is generated off of the database scheme. The basic insert, update, delete, and select features are implemented along with select by primary keys, etc.

The final layer is the Entity class which inherits the EntityBaseClass. The Entity class is the main class that the user will interact with. This class may changed to add additional functionality.

Database Abstraction Layer

I will also be using the ADODB PHP library for database abstraction.

Template Library

I’m debating whether or not to use patTemplate or bTemplate as my template library of choice. While I like the overall design of patTemplate, bTemplate works exactly how a template library should. Recently, the bTemplate webpage seemed to disappear and it has an account suspended message on it.

I’ve been debating how to structure my admin pages so far. I prefer to work with list, add, edit, and delete pages to each entity in my database. I’m going to play around one template file and one main admin page vs. one template file and four admin pages. Each list section will be assembled into a main menu to allow each section to be accessible.