Programmatic Themes

December 12th 2009

For some time now I've been thinking about programmatic themes. That is, themes that are produced entirely in PHP and as a result can be modified entirely by code.

The concept of using objects within code which are directly representative of HTML elements is not a new one, ASP.Net uses this extensively as does Habari for form handling; however, I have yet to see a full theme handling framework produced for WordPress and the idea intrigues me a lot.

Before I go on to consider the advantages and disadvantages of this let me explain a little bit about what I mean.

WordPress themes are really just normal PHP files. Everything WordPress loads in the background is aimed at preparing the data that will be needed when the webpages that make up the theme are loaded. Once this point is reached WordPress chooses which file should be used and it runs with very little intervention, as if it had been called directly.

Some other systems use a more involved process whereby the HTML and some special codes are included within template files. The content system loads this template into a variable and replaces the special codes with content before echoing to the browser. These can be quite complex with markup for insertion, formatting and even repeating regions. Despite this complexity and control these template files are still essentially hand crafted html which is off limits to the code.

What I am interested in is a process without any template files at all. Instead of template files the theme contains a library of PHP objects that represent HTML structures. For example, you might have a menu object into which you add details of the items you want to include. When called the PHP object will output a div tag that contains an unordered list which in turn contains all of the menu items you created within your PHP script.

The concept might be difficult to imagine so let me provide a slightly more involved example using some code.

In WordPress, the functions.php file contains:

  1. //create the page object
  2. //this handles all the doctype, header, etc.
  3. $page = new page();
  4. $page->title = the_title();
  5. //create a header object
  6. $header = new htmlcontainer();
  7. $header->width = '100%';
  8. $header->height = '200px';
  9. //create the content for the main body
  10. //use a container object which is a DIV or series of DIVs
  11. $contentContainer = new container();
  12. $contentContainer->width = '100%';
  13. //we went this container to have 2 columns, main and sidebar
  14. $contentContainer->columns = 2;
  15. $contentContainer->columns[1]->width = '70%';
  16. $contentContainer->columns[2]->width = '30%';
  17. //we want the first column to contain the post content only
  18. //so create a generic container for the content
  19. $content = new genericHTML();
  20. $content->content = the_content();
  21. //add the generic content object into the first column
  22. $contentContainer->columns[1]->add( $content );
  23. //add the content into the page
  24. $page->add( $header );
  25. $page->add( $content );

There is only one other template file, the index.php file. This file contains one line:

  1. $page->display();

This triggers every item that has been added to the page to output its HTML in order. This creates the page.

So Why is this an interesting concept?

There are a few reasons why this concept interests me. Firstly it puts almost every aspect of the layout into the control of the coders, so you can not only create the layout with code, but easily modify it as well.

Taking the above example, converting this from a two column layout to a three column layout is a matter of modifying a couple of lines of code, or using a plugin to alter it before it is output. Similarly, if you need an extra class, or an extra DIV inserted somewhere you can modify the output of the object so that it is produced.

This concept also makes it possible to create a user interface to modify most parts of the layout instead of selecting from one of several pre-designed layouts. While it is true that a small selection of layouts is generally suitable for most users greater control is an attractive concept.

Finally, the object library can be extended to include objects that do not directly mirror HTML structures, for example, an object that outputs microformat based elements or mapping.

It isn't all good, of course.

Firstly, the additional control comes only where there is additional development to provide interfaces for it so by default this leaves, potentially, quite complex code which new users may find difficult to get a handle on.

Secondly, plugin authors are unlikely to specialise on themes that use this concept when everything else is produced in the usual style. This style is also likely to put much of the layout CSS inline, or at the top of the page, which might make it difficult for plugins that aren't written for this style to override it.

Third, all this object processing creates significant overheards. These can be managed with appropriate use of caching but this will never be as efficient as simply including a text file, which is effectively what normal templates do.

This is entirely theoretical, the amount of work involved in putting something like toghether is significant and not something I would do on a whim, but I am interested to know what people think of the idea, or if they know of somewhere that this is already a reality.

1 Comment


Privacy for Web Apps

December 12th 2009

A post currently going on (and on and on...) in the WPTavern forums illustrates the way that some people don't really get the whole privacy thing. That isn't a criticism, they just don't see what the fuss is about. This post is to explain my general position.

I think a big part of people's failure to understand privacy concerns is the point where they start their logic; their default position.

My default is this: Information that relates to me, in any way, is mine.

The only exceptions to this statement involve an abuse of my rights. It is a common occurance and given the abusers I have little choice but to accept it. Nonetheless, they are in the wrong.

If I use a piece of software that you have produced, if you want to know something about me then you must ask. Whatever it is. Even if that data is in the public domain. Even if that data is printed on my website.

Note the difference here between ask for and notify about taking.

The issue being discussed about WordPress is trivial and not one I really care about, but the arguments being made do matter, a lot. You see, a lot of those arguments are of the sort that ask those concerned with privacy why they want to restrict the data. They ask what harm could come from them having that data, what evil could possibly be done with information that is already in the public domain in most cases anyway? These are entirely the wrong questions and really miss the point that any privacy advocate is trying to get across.

So here is the key point of this whole thing. The basic concept that you need to understand. By default the data is mine. I don't have to have a good reason to deny you access, you need to have a good reason for me to provide you with access. The burden of justification is always on you, the person that wants the data, in all circumstances, so you need to convince me that I should give it to you.

It doesn't matter what the data is, it matters that it is mine.

2 Comments


The Proposed Cookie Law

November 9th 2009

I've been reading a fair few posts recently about the EUs planned changes to the law relating to storing cookies on user's computers. Most of these posts suggest that the rule is moronic, prohibitive, and illustrates a complete lack of understanding on the part of the law makers. I'm not so sure though.

Now, I'm neither a lawyer, nor an expert in this field, so I can tell you only what it appears to mean to me (I have quoted the relevent part of the proposed amendment below).

As I understand it you will not be alowed to store information, or access information that has been stored, on a user's computer without their explicit consent, with the exception of cases where access to that information is strictly necessary for the provision of services that the user has explicitly requested.

So what are the instances where a web-site owner will want or need to store cookies?

Firstly there are cookies to used to identify the user during their session. If they have registered and logged on, or are using a service such as a shopping cart then I think you could argue that these are needed to perform the service they have requested.

Secondly, there are cookies used to track the user for analytics purposes. I think these are debateable. You could argue that analytical data is needed for the operation of the site that, by visiting, they have requested access to, but I don't think this holds much water really. It may be that the analytics software would have to do what it can using referrer data and IP address information instead.

Finally, you have cookies used to track which advertising a user has previously seen across one, or multiple sites. I don't think it is possible to argue that this is a service that has been requested, so consent would be required.

Are there any I've missed?

It could be that I am missing something here but, actually, I like the idea that I have to consent to being complicit in creating information about my habits and movements for the benefit of third parties. It is, perhaps, a tad hyprocritical of the EU given that the trend among government's is to try and make ISPs track our activities for their own uses, but anything that reduces the flow of information about us is a good thing isn't it? It is the reason why so many virus checkers consider advertising based cookies to be bad and so remove them isn't it?

I will be looking out for more information to find out why this is such a bad idea, but in the meantime I remain unconvinced that it is as incompetent, or ignorantly produced, as some suggest.

There is of course an irony in this post in that I am tracking your movements right now, and using cookies to do it.

The following has been quoted from: Out-Law.com: Proposed changes to cookie laws

Article 5(3) shall be replaced by the following:

Member States shall ensure that the storing of information, or the gaining of access to information already stored, in the terminal equipment of a subscriber or user is only allowed on condition that the subscriber or user concerned has given his or her consent, having been provided with clear and comprehensive information, in accordance with Directive 95/46/EC, inter alia about the purposes of the processing. This shall not prevent any technical storage or access for the sole purpose of carrying out the transmission of a communication over an electronic communications network, or as strictly necessary in order for the provider of an information society service explicitly requested by the subscriber or user to provide the service.

The Proposed Recital

(66)Third parties may wish to store information on the equipment of a user, or gain access to information already stored, for a number of purposes, ranging from the legitimate (such as certain types of cookies) to those involving unwarranted intrusion into the private sphere (such as spyware or viruses). It is therefore of paramount importance that users be provided with clear and comprehensive information when engaging in any activity which could result in such storage or gaining of access. The methods of providing information and offering the right to refuse should be as user-friendly as possible. Exceptions to the obligation to provide information and offer the right to refuse should be limited to those situations where the technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user. Where it is technically possible and effective, in accordance with the relevant provisions of Directive 95/46/EC, the user's consent to processing may be expressed by using the appropriate settings of a browser or other application. The enforcement of these requirements should be made more effective by way of enhanced powers granted to the relevant national authorities.

1 Comment


Recording readers' reactions

October 27th 2009

I've just come across this widget on the NBC New York website that I though was a particularly interesting.

This widget allows readers to state their general feelings about the news story without the need to write a comment about it.

I like this a lot as so often it is only those who write a comment who get noticed and so it can be hard to judge what the general reaction is. You only get the reaction from people who think they need to offer an opinion, correction, or just weigh in on the other misguided chumps who are commenting.

What I like most is that it doesn't just focus on whether they like it or not, it asks how they feel. Thrilled, sad, bored, furious intrigued, or laughing. I'm sure there are other feelings but to get a quite reaction poll I think this could be quite useful.

Unfortunately not too many people are using it. I went back over quite a few other stories and when I added votes discovered that in some cases I was the third person to vote. That seems pretty low for a city with the population of New York.

Perhaps it needs a more intuitive and prominent way of voting. Some big buttons perhaps instead of a drop down box and it could also be positioned within the story itself. Currently it appears as an extra column and is likely to be ignored as it looks like an advert.

0 Comments


Feeds

Categories

Topics