Posts tagged php

A quick and dirty OneBox using PHP

Arguably the most common, if not first, Google Search Appliance (GSA) OneBox module that organizations implement is a module that returns personnel information or listings of some kind. It is one of the most obviously useful OneBox results one can come up with. As we ramped up to implement our version of it, we were surprised to discover that most publicly available examples or models for creation of OneBox modules rely on technologies (ASP and Java being among the most prevalent) that we do not use. We could not find an example of such a OneBox using simple PHP/MySQL.

Our goal was to build an easily replicable OneBox module that does work with PHP, which we do use. A lot. PHP is at the heart of the Pika CMS as well as our public websites built on WordPress.

Here’s an example of what our OneBox special query result looks like, with the first keyword “staff” being the trigger and the second keyword “ukiah”, the name of one of our local office locations. The query returns a OneBox result listing all the active staff in that office:

Clicking on the link for each person’s name triggers a new display with a photo of the person and his or her vitals. This module also works using the same initial trigger with a staff person’s particular name.

Most simply put, this OneBox module works by querying the MySQL database “users” table in the Pika CMS, the application used by all our active employees, across all positions, to record their time and work activity. More specifically, the module breaks down into five basic steps:

  • the OneBox module sends a query to a targeted PHP file
  • the PHP code runs a query against the targeted MySQL database
  • the PHP code then outputs the returned data as XML
  • the GSA reads that XML output
  • the GSA then formats that output for display as a search result

Within the GSA console, one creates a module by selecting OneBox Modules > Create Module Definition, selecting the Trigger (in our case, “staff’), and then identifying the Provider, which in this example is the PHP file we created and attached to the module as an External Provider, by inserting the URL to the PHP file.

You can download as a ZIP file the PHP code and related GSA stylesheet template used in this example.

The PHP file is annotated, but has select information edited or removed (host, passwords, etc.), for obvious reasons. Looking at the PHP code, in sequence the PHP submits the query, connects to the database, joins data from a combination of data tables in our case management system, then takes the results from the MySQL query and outputs it as XML, i.e., the “OneBoxResults” in the code.

Once the GSA outputs the query results as XML, it can then publish the results to a OneBox Stylesheet Template, which one can edit by clicking on the Edit XSL link at the bottom of the console page for the particular module.

Food stamp calculator as a pedagogical tool

To cut to the chase, this post is about a prototype food stamp calculator for use by advocates, built with PHP and JavaScript. (It works fine in Firefox; the design and functions are buggy in IE.)

Here’s the back story:

One of the most successful content projects undertaken by Legal Services of Northern California has been its web-based California Food Stamp Guide (FSG). As part of that project, we had discussions about building a California-specific food stamp calculator, and then further discussions about the purpose and function of such a thing. Should it be client or advocate oriented? In either case, should it be more of an “estimator,” i.e., a screening tool to get a reasonable, in-the-zone estimate of monthly benefits? Or a tool to make more precise food stamp budget calculations, such that one could check and challenge the calculations in individual cases made by a local welfare office? Among the editorial team that worked on the FSG, there was great interest in having a calculator, but no actual consensus emerged about how best to approach it.

One distinctive idea did emerge, however. Rosemary French at the Benchmark Institute promoted the idea of a calculator that would serve as a pedagogical tool. Her notion incorporated these key elements to make it an effective advocate teaching tool: The calculator should make accurate, complete calculations based on all the possible economic and circumstantial elements that make up an actual monthly benefits determination; it should reveal how changes in a relevant dollar amount or in the application of a client’s individual circumstances (e.g., medical expenses, daycare expenses, etc.) affect the outcome; and it should display the calculation as a whole, on a single page, rather than in steps that cannot be viewed in relation to each other.

Rosemary’s idea was the one that inspired us to try something different from the array of other food stamp calculators out there. For various reasons we never quite completed the project, but we do want to share with the larger advocacy community what we did accomplish: a prototype for a California-specific advocate tool for calculating monthly benefits that honors its pedagogical purposes. (Again, it works as intended in Firefox; not so much in IE.)

Hopefully, use by advocates should be self-explanatory. Start entering numbers and selecting options and the budget calculations shall be revealed dynamically, on the right. The calculations are all based on current food stamp program eligibility standards in California, but can only be made accurately for households in which everyone is eligible; the prototype does not make calculations for mixed households in which one or more members are ineligible. There are Ajaxy pop-up help pages that can be used to provide explanations and links to other resources; one can also save a calculation as a bookmark or print out the results; and other touches.

The PHP and Javascript coding, which includes use of jQuery, was done by the esteemed Scott Trudeau. (Ed Lachgar, on the LSNC IT staff, built the PHP print functions. The layout and visual design were done here at the Webdogs 2.0 labs, so don’t blame Scott for what it looks like.) If anyone has questions or interest about the PHP and JavaScript coding, feel free to contact Scott for details, explanations, etc.

Although we have no immediate plans to do more with this project, we are posting all the prototype code for those who may be interested in adapting, modifying or just playing with it. It’s yours for the taking:

Download the source code.

Using IE conditional comments with Pika 3.06

This is a repost of an item I added this morning to the PikaDocs wiki. And it has to do with a very unexpected problem we encountered with the recent Pika 3.06 iteration, which implements code changes that unintentionally strip out IE conditional comments from the Pika default.html template. Needless to say, IE conditional comments are a widely adopted, all-but-standardized way to apply IE-only CSS code to control the design or display of web pages. And LSNC has long relied on custom IE-specific CSS code for its Pika redesign. What were CSS hacks like us to do about this dilemma?

Well, sure enough, those PHP-code ninjas over at Pika Software (Matt, to be specific) had the answer:

Open the pl.php file located in the your Pika subdirectory at /app/lib/pl.php. Carefully comment out lines 2055 and 2056 by preceding them with double-forward slashes so that it looks like this:

// $str = str_replace("<!--[", $tpl_prefix, $str);
// $str = str_replace("]-->", $tpl_suffix, $str);

Save the changes and upload the pl.php file to replace it. Now your IE conditional comments code will play nice with Pika 3.06.

WAMP me up, Scotty!

I got the heads up about Uniform Server, an open-source WAMP-based web development test bed server from The World’s Easiest PHP/MySQL Testing Server, a brief but informative article by Rob Williams at Community MX. What caught my eye in the article was this paragraph pregnant with the promise of total ease of use:

You do NOT have to install it, configure it, or in fact make any change at all to the downloaded files in order to have a fully functioning test server up and running! One of the goals of Uniform is to create a standalone server that does not alter or affect the local machine in any way at all. Once you’ve downloaded the package, all you need to do is extract them to a folder and double-click the “start server” batch file; a full-fledged Apache 2 server with the latest version of PHP, MySQL and Perl already installed and pre-configured will then start up. When you’re done with your testing, simply double-click the “stop server” batch file and the entire server shuts down, packs itself up and disappears from existence again leaving no remnants in memory or registry files!

There is not one word of exaggeration in that description. Download it, extract it, click the server_start.bat file in the “Uniform Server” folder to crank it up … and from your local Windows desktop you have a fully functioning and customizable web server test bed with all the files automatically placed in the default locations you would expect in a typical Linux server. Click the stop.bat and it all unloads from memory. And this wonderfully self-contained web server test bed is fully portable to a flash drive, whatever. Take your test bed with you, people. Sweet, to the max.

Uniform Server is a total freebie you can download from SourceForge. It works.

Pika 3.06 ~ CSS Matrix: Once more, with feeling

With a few more tweaks and a 100+ more entries, I have compiled a final version of the Pika 3.06 ~ CSS Matrix, with 238 entries sortable by HTML or PHP file name, markup tag; or id or class attribute.

And the point is…?

The first point was the original point, namely, to play with creating a sortable table. To coin a phrase, “mission accomplished.”

The second point was to go through the exercise of deconstructing what was done with Pika 3.06 to remove embedded styles from the application. It was fairly easy to do. With the Pika HTML templates, all it took was setting up a few basic search queries for character patterns that would lock in on id and class attributes in the structural markup. All I did was go through each of the HTML template files, do the queries, and plopped the results in the CSS Matrix table. In each instance, it only took a few minutes. Culling this same information from the PHP files was a little more demanding because my initial queries revealed how deeply and widely the Pika PHP files have so may pockets of code with embedded tags and attributes that are legacy or commented out or whatever, with no real connection to the current default Pika CSS files. So I took a different tack: I worked backward from the CSS files, searching the PHP files for any attribute referenced in the style sheets. This simplified the search to tags embedded in the PHP files with attributes with a connection to reality, i.e., ones affected by the CSS code in the danio.css and other style sheets. For purposes of the CSS Matrix, any other attributes were irrelevant. The 238 entries listed are all the ones I could find.

The third point is where I am going with this as part of LSNC’s various Pika test beds. We currently have four Pika installation:

  • The real Pika install used by all LSNC staff.
  • The Pika test install which duplicates the real install exactly, where we can test modifications and risk things blowing up before we fold changes into the real install.
  • A virgin copy of Pika 3.06, essentially a reference copy of the current iteration so we can readily access an untouched copy of the current code and see it function as Aaron intended.
  • And the Pika makeover edition, where we can experiment with our ideas for our next internal build of Pika.

One of the first sets of tests we will be doing with Pika 3.06 is to test out its new custom template functionality so that we understand how it works and can get comfortable with it. As part of that we will be using the CSS Matrix as one of the tools to mess with the Pika styles. It will be fun to see how hard we can push the boundaries of the presentational characteristics of Pika out of the box, only using the Pika style sheets. That’s where the CSS Matrix comes into play.

We’ll get back to you about that in a few weeks, provided the patient survives our tinkering.

You code girl!

I have no idea whether CodeGrrl.com is a good PHP/MySQL resource or not. I just wanted to run the headline.