XUL is Mozilla’s eXtensible User interface Language, an outstanding Open Source technology that makes building complete GUI‘s much like building web pages with DHTML.
Just to give a feel for what it’s capable of, phpPatterns now has an “XUL Viewer” - essentially a gimmick to make it “easier” to browse the site.
What is XUL?
XUL is an XML format designed for building “rich clients”; complete windowed applications using. To quote the Mozilla team;
In the beginning, there were 3 front ends (FE’s): mac, windows, unix. Each took a suite of developers to maintain. Adding a new feature (even just a button) required 3 engineers to waste at least a day (more often a week) slaving away until the feature was complete. This had to change. What if we could be in a world where we could just write the code once? Where non-programmers could design the look and feel of a product using W3C standards instead of C++? Where platform differences could be expressed in stylesheets, not hardcoded with #ifdefs? Do you like that world? So do we.
The Third Way
If you believe what you’re told, you have a choice when it comes to building GUIs;
- choose Java and fight your way through a maze of standards and competiting vendors to build your GUIs in a language which will become your lifes work.
- choose .NET and become dependent on the tools that make it “so easy” to develop apps in a language which may as well be Java.
Either way, unless you’ve got money and time to burn, building GUI‘s will probably remain out of reach ( unless you want to try PHP GTK but that’s another story ).
But there is a third way - the way of XUL. What you probably won’t hear about in the mainstream IT press is the revolution that’s happened with the Mozilla project; they’ve turned the Gecko engine into a runtime for executing applications just like Java and .NET have runtimes.
What’s more where Java (Swing / AWT) is slow and .NET is Windows only, XUL is both fast and cross platform. Oh and it can be run both as a local desktop app or launched directly from a website.
It's so easy
If you know HTML, picking up XUL will be a breeze. The tag naming ( see here ) is both logical and intuitive.
What’s more, XUL is paired with other technologies which, if you’ve played with any DHTML, you’ll already know, namely JavaScript, CSS, RDF and others.
In terms of what XUL can acheive, essentially anything that the Mozilla browser has (in terms of a GUI) can be done with XUL (all the GUI “widgets” are already there plus access to the filesystem, text editing and so on...).
Behind the scenes, the Mozilla team have implemented a library called XPCom (cross platform COM) which comes with support for SOAP and XML-RPC among others. The library is also relatively easy to build upon (in MS-speak - making your own “code behind”) given Python, Perl and Ruby (where’s the PHP!) implementations. IBM have a tutorial here explaining XPCom in detail and how to extend it with Python: Part 1, Part 2 and Part 3.
Browser Wars
There is a catch. To execute XUL applications you need to have something on your client running (a recent) version of the Gecko engine.
In practice that means Mozilla, Netscape 7, the up and coming Phoenix (if you think Mozilla is too slow, Phoenix keeps pace with Opera...) or one of the browsers listed here. There’s also a chance that people will begin embedding the Gecko engine in things like handheld devices...
XUL and PHP
As XUL is simply an XML markup, rendering XUL from a web site with PHP is essentially the exact same “problem” as rendering HTML.
Simply begin with sending the correct MIME header;
<?php header( "Content-type: application/vnd.mozilla.xul+xml" ); ?>
Then render your XUL.
To date, most of the projects built with XUL are intended to be locally installed under Mozilla. There’s been less work in making XUL apps which can be launched directly from a web site and, as with Java Applets, there are limitations on what can and can’t be done (e.g. no filesystem access) as discussed here.
Having said that, all those (often irritating) DHTML gimmicks people like to add to their site can be easily reproduced with XUL, which is exactly what I’ve done here (you’ll need a browser packing Gecko to view that).
The source XUL document is here;
http://xul.phppatterns.com/index.php
The CSS document which defines it’s look and feel is here;
http://xul.phppatterns.com/style.css
The JavaScript which responds to “events” fired off by the XUL app is here
http://xul.phppatterns.com/phppatterns.js
Here’s how it looks with Mozilla;
In other words, it’s incredibly easy to knock up an XUL application. I’m not saying the “phpPatterns XUL Viewer” is anything amazing but it demonstrates the point and perhaps makes it easier to navigate the site - the “Articles” and “Links” menus are generated on the fly by PHP.
XUL Needs You!
[RANT ON] What’s particularily wierd about XUL is how little attention it’s getting while (IMO) it’s a truly outstanding technology. That probably has alot to do with who’s paying the IT press to talk about their products (Open Source relies on developers to spread the word) as well as Mozilla being perceived to have “lost” the browser wars.
Given PHP‘s pervasiveness on the web, if the PHP Community as a whole began to “push” XUL, that situation could change radically.
What’s more, XUL has alot of offer to PHP developers, particularily in the area of Content Management. How many DHTML based have there been to construct online HTML editors? With XUL it’s a breeze for example Composite - this could be extended to an editor could be build that updates a site via SOAP or XML-RPC... Mozblog (a locally installed APP) demonstrates the point nicely, using XML-RPC.
Right now there’s little out there both in the way of sites providing XUL tutorials or RAD tools for building XUL applications ( couple I’ve found are Theodore which seems to use it’s own version of XUL and is geared to “thinlets” and XUL Maker which is a half finished application for designing and constructing XUL apps, written in XUL). Certainly if you’re looking for an opportunity to put up a “resource” site, XUL makes great subject material...
As far as PHP is concerned, there’s basically next to zero projects out there doing anything with XUL (certainly a library for building XUL widgets along the lines of HAWHAW would be worthwhile...). [/RANT OFF]
Anyway, if any of this has grabbed your interest, check out the resources below and give XUL a test drive.
[UPDATE: 07.05.2003] The Incentive Check out the Mozilla Amazon Browser - this is an outstanding example project, demonstrating, among other things, the parsing remote XML and how to make data persist within an application session. O’Reilly cover it as a case study here
Oh and XUL to PHP
Resources
XUL Planet - small but plenty of useful tutorials as well as the XUL element reference and XPCom API reference (which could do with many more examples).
Mozilla Site Navigation Tutorial - pretty much explains what I’ve done with phpPatterns.
Creating Applications with Mozilla - online version of O’Reillys book (this is perhaps the best resource for an in depth look at XUL)
OReillynet Mozdev Center - a few handy tutorials here such as how to use the XPCom SOAP API.o use the XPCom SOAP API.
