Beautiful Roxen

Published 2 May, 2007 in Roxen - 0 Comments

I’ve been really busy lately at work with various things – developing a blogging system for starters. Most of the stuff you need for a blogging system is already available in Roxen CMS that we use at work. But one thing I needed, that isn’t available, was some commenting functionality. This is something that you could quite easily implement in the templates – Roxen uses XSLT for the templating system, or their own extension of XSLT so that you can write RXML code in the XSL templates.

RXML handles database driven things quite alright but if you develop things in this layer, the presentation layer, it gets harder to maintain or implement on a different server. What you can do then is writing a Roxen Module in Pike. You can create different types of modules – provider modules, RXML tag modules and so on – and you can also combine two or more modules into one. All RXML tags in Roxen is just wrappers for underlying Pike code, so you hide the logic in Pike and provide simple interfaces in RXML. First, let me give an example of how you loop over a database record set in RXML:

5 lines of RoXen Macro Language
  1. <emit source=“sql” host=“myhost” query=“SELECT name, email FROM employees”>
  2. <a href=“mailto:&;”>&;</a>
  3. </emit><else>
  4. No records found
  5. </else>

It doesn’t get more simple than that! Another thing that’s great about the modules is that you can run arbitrary functions when you load the module which means that you can create databases and database tables when you first load the module. Roxen runs on MySQL internally and Roxen provide API:s to the internal MySQL database. What this means is that if you create database driven modules it’s just to install the module and the database and its tables will be created. No fuss!

Roxen, without the CMS, is a standalone open source web server and support the same kind of modules as the CMS does, but there’s more to the CMS!

The CMS modules

I’ve been poking around in the Roxen CMS source code for a while now and I have written some pure RXML tag modules – which is quite simple – but now I saw the opportunity to extend my knowledge and make a real CMS module. Since the CMS provide access control you don’t want emit tags to list stuff that the user don’t have access to. For instance: There’s a emit tag that you can use to list the most recent pages for a given path or pats. For example:

11 lines of RoXen Macro Language
  1. <h2>Latest news</h2>
  2. <ul class=‘newslist’>
  3. <emit source=“site-news” unique-paths=“” maxrows=“20”
  4. path=“/comp-a/news/*/*.xml,/comp-b/news/*/*.xml,/secret/*/*.xml”
  5. >
  6. <li><a href=‘&_.path;’>
  7. <date type=‘iso’ date= iso-time=‘&_.published;’ /> |
  8. <span>&_.title;</span>
  9. </a></li>
  10. </emit>
  11. </ul>

Now, you don’t want unauthorized users to see the items from the emit path do you. This tag in particular won’t show them either and I wanted the same kind of functionality in my set of emit tags. So I poked some more!

Another thing: Each file in Roxen CMS is version controlled through CVS and I needed to get some information about the first published version so I needed to find out how to access the CVS logs. The CVS thing also means that the files in Roxen CMS is saved to a virtual file system with an actual path, i.e emit, and what if there are comments to a page and that page gets moved? Thankfully Roxen CMS provides an API to run your own code when some kind of action takes place on a particular file – if it get moved, edited, deleted, purged and so forth. And I came to understand that I needed to poke around even more ;)

Anyway; the more you dig around at the dark side of Roxen the more impressed you get by how clean the code is, how nice the API:s are and so on. I’m no Roxen beginner by now but up until now I haven’t really used the API:s to the internal workings of Roxen and I must say that after all, it was a bliss.

The comments module

So what will all this babbling lead up to? Well, what my module now does is:

  • Upon load it creates an internal database with the table in which to store the comments. Here you can also make a dump or load a dump of the comments DB. In the settings you can set the default value for how long commenting should be enabled – lets say that after 30 days no further commenting should be allowed. You can also set a default author name if you allow anonymous commenting.
  • It listens to the emit which means that when actions takes place on web pages in the CMS the module will be notified and take actions if necessary. If the page emit has comments to it and the page get moved the paths in the comments table will be updated to the new path so that comments always stick to its page even if the page is moved. Also, if a page gets deleted so will the comments.
  • It provides a set of RXML tags, one for listing comments – either to the page to which they belong or through globs so that you can make lists of “latest comments”, one for listing a particular comment for lets say editing, one tag for adding, one for updating, one for deleting a comment, one emit tag for checking if a user have admin permission to a given comment and one emit tag to check if the commenting form has expired or not and last one tag for counting the comments for a given page.
  • Not the least: I followed through and really documented, through Roxens module documentation functionality, the usage of the RXML tags ;)

So I think that it covers what you’d expect a “commenting system” should be capable of doing. There’s may be some small things to solve as always when you develop stuff but it seems to work quite satisfying.

For anyone curious, here’s the source code:

Comments – Roxen CMS Module 17:31, Sat 17 October 2009 :: 36.3 kB

Here’s some screen dumps

The module status tab:
Status tab

The module settings tab:
Settings tab

The module documentation tab:
Documentation tab

A simple implementation:
Status tab