Multiplay Labs

tech hits and tips from Multiplay

Archive for June, 2010

WordPress v3.0 breaks pagination for sites with category in their permalinks

without comments

Unfortunately WordPress v3.0 breaks post pagination for sites that include category in their permalinks.

The issue is caused by a fix to wp-includes/canonical.php (r13781) that was added to fix bug #14201

The code in question is:

} elseif ( is_single() && strpos($wp_rewrite->permalink_structure, '%category%') !== false ) {
           $category = get_term_by('slug', get_query_var('category_name'), 'category');
           $post_terms = wp_get_object_terms($wp_query->get_queried_object_id(), 'category', array('fields' => 'tt_ids'));
           if ( (!$category || is_wp_error($category)) || ( !is_wp_error($post_terms) && !empty($post_terms) && !in_array($category->term_taxonomy_id, $post_terms) ) )
               $redirect_url = get_permalink($wp_query->get_queried_object_id());

The problem is that get_term_by doesn’t support hierarchies so when passed a second level category e.g. cars/sports it will fail and hence the rewrite is performed loosing the page information.

The following fixes this but I’m not 100% that the intention is to only check the last category in the hierarchy, although with our data anything more would appear to fail. This may indicate that additional fixes are required but anyway:-

$category = get_term_by('slug', end( explode( '/', get_query_var('category_name') ) ), 'category') ;

For more information see WordPress Bug #13471

Written by Dilbert

June 30th, 2010 at 6:53 pm

Posted in Hackery,Wordpress

Vbulletin Error Template issues

without comments

The Standard Error template in Vbulletin ( 3.8.4 Patch Level 2 ) is broken due to a missing global declaration of $spacer_open, $spacer_close.

This shouldn’t break the template with both being missing but during the processing of the template spacer_close gets defined, so the resulting html is broken.

The fix is to add:

global $spacer_open, $spacer_close;

to the head of function standard_error in includes/functions.php

Written by Dilbert

June 22nd, 2010 at 10:04 am

Posted in Hackery

A Great CSS Gradient Generator Tool

without comments

Found this the other day and its a great little tool for generating CSS gradients 🙂

Written by Dilbert

June 21st, 2010 at 9:20 pm

Posted in HTML & CSS

How to fix body background images not displaying correctly in Chrome

without comments

It’s been one of the annoyances which has eluded me for quite a while now. When a page with a background image e.g. background-image: url( myimage.jpg) on the document body loads, sometimes it won’t display, or will partially display in Chrome. If you resize the window or browse full screen then your fine so it seems really random.

Well today I discovered a simple little work around, all you need is following in your css:

html { height: 100% }

Written by Dilbert

June 21st, 2010 at 8:58 pm

Posted in HTML & CSS

Preventing XSL transforms self closing HTML tags

without comments

Every once in a while you will wan’t to do the something like the following an xsl stylesheet:


Unfortunately as XML is well formed and HTML isn’t the resulting HTML will be invalid e.g


The solution to this is quite simple, all you need to do is to tell the transform engine you are generating HTML using the output tag e.g.

<xsl:output method="html" />

Also note that if your target html is actually xhtml then using html as the output method will have some side effect e.g.

<br />

will be incorrectly replaced with


So what do you do if you want xhtml and empty elements which require a closing tag and not short form?

Well I’ve found two methods:-
1. Use a text node with output escaping disabled

<xsl:text disable-output-escaping="yes">&lt;div&gt;&lt;/div&gt;</xsl:text>

2. Use a xsl comment


The first means you need to escape all of you < / >, which is cumbersome the second adds unneeded comments to your output, so its up to you which downside you prefer 😉

Written by Dilbert

June 19th, 2010 at 11:37 pm

Posted in XSL

Tagged with , ,

Fun with Cookie Domains and Rails

without comments

If you are working on a site in rails that supports multiple subdomains and want to share a cookie between them, it makes sense to set your cookie domain in your environment.rb to something like:

	config.action_controller.session = {
		:key => 'my_app_key',
		:secret => 'my_super_secret',
		:domain => '.domain.tld'

However, you may come across a weird problem when developing locally, where the CSRF protection no longer works, always throwing up an invalid authenticity token error.

The answer to this is simple – by setting the cookie domain you’ve essentially cut your local machine (or any machine not in that domain for that matter) out of the loop, as per the usual cookie security policies. The easy way to be able to continue to do local development is set up a local DNS alias with a matching domain scheme. For me, I did this to my /etc/hosts file: local.domain.tld

And now doing local development via http://local.domain.tld works a charm.

Written by Andrew Montgomery-Hurrell

June 16th, 2010 at 8:55 am

Posted in Code,Hackery,Rails

Adding Google Chrome Frame support to nginx hosted sites

without comments

I’m trying to add support for google chrome frame to our nginx config the simple way would be to include a fragment in each server block which looks something like:

    if ( $http_user_agent ~ chromeframe ) {
        add_header X-UA-Compatible "chrome=1";

The problem is for some reason add_header isn’t allowed in server-if blocks on location-if blocks, so this errors with: add_header directive is not allowed here
I can’t see or think of a reason why this shouldn’t be allowed, so I tried adding it and it seems to work without a problem.

The following patch, made against 0.8.40, adds server if block support for both expires and add_header.

--- src/http/modules/ngx_http_headers_filter_module.c.orig  2010-06-14 23:48:58.000000000 +0100
+++ src/http/modules/ngx_http_headers_filter_module.c   2010-06-14 23:49:27.000000000 +0100
@@ -79,7 +79,7 @@
     { ngx_string("expires"),
-                        |NGX_CONF_TAKE12,
+                        |NGX_HTTP_SIF_CONF|NGX_CONF_TAKE12,
@@ -87,7 +87,7 @@
     { ngx_string("add_header"),
-                        |NGX_CONF_TAKE2,
+                        |NGX_HTTP_SIF_CONF|NGX_CONF_TAKE2,

Cross posted to the nginx mailing list here

Written by Dilbert

June 14th, 2010 at 11:06 pm

Posted in Hackery,Nginx

FreeBSD partition edit with sysinstall results in “Invalid partition table”

without comments

After making what should have been a simple change to the partition layout on one of our FreeBSD 7.0 machines, where we split one partition into two. Upon writing changes sysinstall complained about missing directory for the second partition. It seemed it had created both partitions but only the first mount point directory. In addition the second partition label da0s3h wasn’t present so after creating the missing directory we rebooted the machine.

On reboot we where greeted by the error “Invalid partition table”. This was very worrying as the machine contained a large amount of data so was going to take ages to rebuild.

Our first thought was to reboot the machine from the livefs CDROM and attempt a repair but this failed as the CDROM emulation presented by the Supermicro IPMI, that we where using, wouldn’t play nice refusing to load with error = 5 from geom.

After much playing with various combinations we tried 8.1-BETA1 as a last resort, which to our surprise simply just worked 🙂

So now we could attempt a repair. sysinstall still showed all our partitions so it looked like all our data was intact. After a detailed inspection of the partition table using fdisk, it became apparent that for some unknown reason when we commited the changes to split the partition in two, sysinstall had marked all slices as active, which was confusing the boot loader.

To repair all we need to do was a simpple fdisk -a da0, once this was done we had just the one active partition and the machine booted as normal.

Once booted we performed a fsck which refused to acknowledge the fs on the two new partitions. Running newfs and them mounting them fixed this.

So the moral of this story is don’t use sysinstall to split partitions or if you do ensure you correct the active state of the slices before rebooting 😉

Written by Dilbert

June 9th, 2010 at 11:49 am

Posted in FreeBSD