Tag Archives: PHP

sqlLayer, pushing foomatic data into the database

The second portion of my project is to write a perl lib to push foomatic’s data into a relational database. This would allow the use of SQLite instead of the xml database for foomatic-db-engine. This isn’t going to affect CUPS users (the vast majority of people) since last year’s project (vitor’s) created pyppd which can side-step foomatic-db-engine entierly for end users. What it does though is provide considerable performance increases for users of legacy spoolers.

Like with xmlParse I am not treading new ground, openprinting already has a script to import the data set. This script was written as part of another GSoC project two years ago as part of the openprinting website re-design. A few months before this year’s GSoC Till gave me a copy of the script along with a database dump. I was able to convert this database dump into a sqlite database. With those I’ve been able to make considerable progress. Currently I’m adding support for about one table a day.

Thinking about the project as a whole I am rather proud of the phonebooks, by extending them to document the database schema I’ve been able to operate at a fairly high abstraction level. Whereas the C programs and the PHP import script had 100s of lines of simple ‘if def assign’ the phonebooks let a single* loop handle all the simple renaming and processing for xmlParse. For complex types the raw data is handed to special case code to process.

Sample special case code for option’s complex data:
#The specific groups
} elsif ($group == 11) { #constraints
	setConstraint($node, \$perlData{$destinationKey});

} elsif ($group == 12) { #enum_values
	foreach my $subnode ($node->findnodes("./enum_val")) {
		my %enumValue;

		foreach my $subsubnode ($subnode->findnodes('./@id[1]')) {
			$enumValue{"idx"} = $subsubnode->to_literal;

		foreach my $longnames ($subnode->findnodes('./ev_longname')) {
			$this->setHumanReadableText(\%enumValue,\"comment", $longnames);

If I were to redo my work I would make the phonebooks document the structures of the complex data. This would allow an even further generalisation and do away with the special case code for the complex types.

That isn’t going to happen though, the current code has been tested and is working. And while the special cases could have been done better I do realise that a more general approach would have had a much harder time conforming to the behaviour of the C programs.


*Not necessarily a single instance of the loop. I’m a bit ashamed to admit but there are actually three copies of the same loop, one for each xml type. It is this way because when I created the phonebooks I made groups above 10 be namespace specific groups. Thus group 11 for an option xml is different from printer’s group 11. In xmlParse this is implemented by the fact that the option loop is separate from the printer’s loop. The groups that all loops share are in a separate function, so really only the loop structure is copy pasted. In sqlLayer I’ve kept the loop singular and simply added support for namespaces, support which will be made cleaner if I can think of a way.

WP Markerboard Widget

I’ve seen this ‘toy’ elsewhere and after debugging Overview generation for foomatic I felt a quick break was in order so this morning I created WP Markerboard. It is a WordPress plugin that provides a “marker board” widget for visitors to play with. I built it using html5’s canvas element and jQuery.

An example can be seen below, try moving your mouse over the outlined box.

Being an html5 toy your browser must of course support the canvas element. For visitors without modern browsers the javascript fails gracefully.

The widget has four options, line color, line width, box width, and box height. Unfortunately canvas requires explicit dimensions, the default dimensions for Markerboard are 150px by 150px.

To install unzip the zip and ftp the resulting folder into your wp-contet/plugins/ directory. The plugin will then show up in WordPress’s list of plugins, active it, you may now add this widget to your sidebars.
Or simply install from wordpress’s add new plugin page as wp markerboard is hosted on wordpress.org’s plugin repository.
See WP Markerbaord on wordpress.org

WordPress XML-RPC documentation links

Unfortunately the documentation for WordPress’ XML-RPC API only covers the WordPress specific extensions. As such if you want to do anything useful you’ll have to seek help else where. Perhaps the most important thing to note is that WordPress supports Metaweblog a proper open standard.

During my google’ing I came accross several helpful links:

Attaching an image to a post:

One thing that was absolutely un-documented was a method to attach an image to a post. After some digging I found attach_uploads() which is a function that wordpress calls every time a post is created or edited over xml-rpc. What it does is search through the list of un-attached media objects and see if the new/edited post contains a link to them. Since I was trying to attach images so that the theme’s gallery would use them I didn’t necessarily want to link to the images within the post, nor did I want to edit wordpress. So what I ended up doing was including the image url within an html comment.


Loging the #openprinting irc channel

The IRC channel is nice in theory for team wide casual communication. Unfortunately you need critical mass for it to do this task well. Often #openprinting will only have me and Till in it. Occasionally others will be present and only very occasionally will conversation occur. Since I’m new to the project I want to intercept as much inter-team communication as possible. Thus I’ve setup my home server with the irc client Irssi which logs all communication, then a perl script to clean the log and FTP it to my site. Finally one line of php to print it out on it’s own page.

Truthfully I wrote it up on a whime, but I do look forward to not missing out on chats.