Hacking drupal: Add search by node creation date and the author

Some of the users using one of my Drupal sites were asking for search by author and creation date. The site had 3000+ nodes and the user’s request seemed reasonable enough. I first started with googling for a Drupal module or a patch that would add the functionality, but none were found.

So when ahead and hacked the node module. I sucessfully managed to add search by author and node creation date to advanced search block. If you are in searching for a patch like I did you can find it at http://drupal.org/node/233476, I’m keeping my fingers crossed to see whether it would make it to the Drupal trunk :).

Filter module support for Premium module

There was a need to put a log in link with destination get variable set if the user is not authenticated and trying to view a premium node. The obvious place to put such content is the “Premium body text” in /admin/settings/premium, however one problem was that “Premium body text” can only static html, no filters/format.

I couldn’t quite believe why filter module was not being made use of there, so I went ahead an made the necessary changes to make it possible to select the filter/format to be applied to “Premium body text”. The patch will add a Input format section to the settings form, that filter chosen there will be applied when the “Premium body text” is rendered into a node.

You can see the progress of the patch submitted to drupal.org at http://drupal.org/node/231641. I just hope the patch will make it to the premium module head. The development of the premium module is nearly stagnant :(, that conserns me.

Drupal Atom module spits invalid xml

Drupal Atom module is spitting invalid XML in some cases. It is obvious that all user generated text in XML should be either escaped or appear within CDATA section. However it is not the case with title and subtitle sections. If the site title contains “&”, then the atom/feed will guaranteed to be invalid.

I came across this the hard way, in one of the sites I was maintaining someone decided that they need “&” in the title, then the atom/feed was giving a XML parser error. After little bit of head scratching, I was able to triangulate the buggy piece of code.

You can read the progress of the issue at http://drupal.org/node/229392, you can download the patch from the same.

Hope I saved someone from much head scratching and frustrations.

Running Drupal behind a reverse proxy

I was supposed to move one of the Drupal sites I’m maintaining behind a Reverse Proxy. The migration was smooth as it could get, but soon throttiling was an issue. All requests were coming from the Proxy server, and Drupal didn’t seem to automagically detect the client IP based on the X-Forwarded-For header.

So I set about investigating what can be done. As I discovered, automagic client IP detection is only available in Drupal 6 (At the time of writing, under development). I went about porting the changes to Drupal 5.x. Porting was as easy as it can be, but it was not working.

Further investigation lead to one of the site configurations; I had enabled Normal Caching in the Drupal site. It was not acceptable to switch off caching, so I went about debugging this code to make it work with caching enabled. Finally I was able to fix the issue, it was trivial but it was not easy to debug. The fix involved removing cached IP address for every request such that the correct IP will be detected. See my patch in drupal.org at http://drupal.org/node/219825.

Hope this helps someone.