Rewrite Rules

When editing RewriteRules, it’s important to remember this: rules which appear first tend to take priority. For instance, I discovered that the rules for http://schinckel.net/200_n_/page/_n_/ style URIs were missing. What was happening was the .htaccess file was finding the closest rule it could. The trick for finding what it’s actually doing under Blogsome is to have this code in your template:

1
2
3
    {foreach from=$smarty.server.argv item=var}
    {$var}
    {/foreach}

This code will print out what the server is receiving. In the case of the URI: http://schinckel.net/2005/page/2/ it’s being sent:

wpblog=schinckel&year=2005&monthnum=&day=&name=page&page=2

The important part here is that the name of the post is being set to ‘page’. Clearly, this is not desired behaviour. The RewriteRule that should apply to this instance looks something like:

1
    RewriteRule ^blogs/([_0-9a-z-]+)/([0-9]{4})/page/([0-9]+)/(.*)/    /wp-inst/index.php?wpblog=$1&year=$2&paged=$3 [L]

I don’t know exactly what the [L] stands for, but it needs to be there to stop Bad Server Errors™. The key thing to know here is that this must be before the greedy rule that was already grabbing the URL, and Rewriting it of its own accord. In my case, that was the line that looked like:

1
    RewriteRule ^blogs/([_0-9a-z-]+)/([0-9]{4})/?([0-9]{1,2})?/?([0-9]{1,2})?/?([_0-9a-z-]+)?/?([0-9]+)?/?$          /wp-inst/index.php?wpblog=$1&year=$2&monthnum=$3&day=$4&name=$5&page=$6 [L]

I made sure my new rule was before this. A good place is where the other rules for subsequent pages of posts are. Of course, this rule only works for yearly archives, you’ll want one for monthly and daily archives (if you are a nutter who posts more times per day than fits onto your front page…):

1
2
    RewriteRule ^blogs/([_0-9a-z-]+)/([0-9]{4})/([0-9]{1,2})/page/(.*)/    /wp-inst/index.php?wpblog=$1&year=$2&month=$3&paged=$4 [L] 
    RewriteRule ^blogs/([_0-9a-z-]+)/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/(.*)/    /wp-inst/index.php?wpblog=$1&year=$2&month=$3&day=$4&paged=$5 [L]

Of course, on Blogsome, you cannot alter this file yourself, but I’m sure these changes will be implemented soon. If the link earlier in the post still gives you “No Posts Made”, then you know it hasn’t…

$smarty.get.*

I don’t know how I never found this before… You can use {$smarty.get.<var>} to get the URL variable you want. For instance, you can use the following ones in WordPress MultiUser:

  • year
  • monthnum
  • day
  • name
  • paged/page
  • category_name
  • wpblog

Unfortunately, these variables don’t seem to be set with Pages, rather than Posts. However, this has given me some tips as to how to fix the .htaccess RewriteRule problems causing Blogsome not to display subsequent pages of monthly archives. Possibly something to do with the fact it uses page, rather than paged, and that for some reason it parses the word page as the name of the post. This looks like not a .htaccess bug at all, now that I think of it.

Moving from Blogsome

Luis Suarez, over at elsua.net wanted to know how to get his posts out of Blogsome. It’s really quite simple - all you need to do is use any XMLRPC offline composer that can get an arbitrary number of posts. ecto is a great example. Then set it to get more posts than you have, and it will grab them all from the server. You may need to learn how to set it all up - I won’t go through that here, but if enough people comment, I will write a tutorial. You can then re-post these entries to another server. IIRC, there isn’t a way to say ‘post all of these entries to another server for me’, so I wrote an AppleScript to do this when I migrated to Blogsome. Basically, it grabbed all of the posts from an Account, and cycled through them, posting each one to Blogsome (after changing the date to match the original, I think - there was an issue where it thought each post was a ’new’ post, rather than using the old date). If you are on a Windows box, there is a version of ecto for Win, but obviously no AppleScript, so you may wish to investigate other solutions. It should be possible to write a simple program that just does this (copies posts from one host to another, via XMLRPC), but I don’t have the need, so I won’t write one ;) As it turns out, Louis asked for, and received a zipped file of all his posts anyway, but incase anyone else needs to do it fast… Oh, and Louis, I didn’t write a Comment because I didn’t want to have to create yet another account somewhere. Maybe you could consider turning on Comments, and using some sort of Spam protection other than requiring logging in. Casual commenters will be quickly turned off this. All of my Comment Spam is gone, just by using a simple JavaScript - now all I get is Trackback Spam.

Post Time Bug

A bug seems to have slipped through my JavaScript of Human Time Posts. The post before this was definitely posted in the wee hours, yet they are being treated as posted around lunchtime. Must fix that. And the fact I’m now running under daylight savings. (Fixed, needed to update the Options).

Category Pages

I want to add some functionality to my site. I used to just have a few categories, but as I wrote more, I wanted to sub-categorize a bit. So now, I have a handful of parent categories, and under (most of) these I have one or more child categories. In some cases this goes three or four deep. But, so the category list isn’t too long, I only show the parent categories in the sidebar. What I want is that when a category page is shown, at the top is a list of the child categories. I can (relatively) easily find out if I am viewing a category page: {if $smarty.server.REQUEST_URI|truncate:10::1 == '/category/'} I can also quite easily find the name of the category, but not the id. This is what I need for creating the category list. I’ve just had a thought. Checks something. The following displays the info that is sent to the server: {foreach from=$smarty.server.argv item=var} {$var} {/foreach} I was hoping it would give the category id. But it doesn’t, only the name. Back to the drawing board.

JavaScript in Posts

Clearly, this is the first time I’ve tried to do this. No, that’s not quote true. I’ve been working on a post that does it, I just haven’t published it yet. I’ve discovered that JavaScript is really neat for doing lots of cool stuff. However, WordPress has a couple of issues with it. It’s okay to use JavaScript in template files, or include external JavaScripts, and even to use JavaScript in Pages, but if you try to use it in Posts, it fails. It converts " into &quot;, and ’ into &apos;. Or more strictly, into the #8220;-ish version. Which isn’t much good, as then any JavaScript which uses quotes, to define a string, for instance, will not work. You could define a function elsewhere, and then just call it, that should work. But not do anything that requires quotes. There seem to be a couple of WordPress workarounds, but not in WordPress-MU. Or Blogsome, that means. I may have a look at the source, to see if I can figure out a way to make it work nicer. Oh, and that reminds me. I need a decent text editor for Windows. Notepad just ain’t cutting it anymore. Especially if I try to open a Unix file.

Preventing Trackback Spam

Now I’ve (virtually) solved my Comment Spam issue, I’ll look into trackback Spam. Note to self: look at Trackback Validator Plugin over on Trackback Spam Resources. That whole site looks pretty good, too.

Comment Moderation

I need to see why Blogsome isn’t notifying readers when their comments are moderated. Apparently (according to the Codex) this is just a line or two of code. It would be nice to make a system wide change, but I’ll start with just a notification in my blog template.

Catchpa Working?

I think my simple catchpa is working quite well. I’ve only had one comment through that was Spam, and that was actually a trackback, not a comment. Ditto for comments in moderation. However, I haven’t had too many ‘real’ comments in the last few days, either. I hope there aren’t people who are trying to comment but cannot. I don’t think so, since I seem to be able to comment fine, from IE and Firefox. Love to hear from anyone using this method.

XMLRPC Escaped Quotes

For some time, since the XMLRPC file was updated, posting to Blogsome via the XMLRPC interface has been broken. It works, but extraneous slashes are inserted before quotes and apostrophes. I’ve been lucky enough to get my dirty little mitts on the source code, on a test server, and have come up with what may be a fix. The good folks at Blogsome (I think) replaced the dodgy, broken version of XMLRPC.php with one that prevented some problems with a security hole. However, this version of the file came from a more recent WordPress installation. The version of WP-µ that Blogsome uses may not have actually been vulnerable to the problem that the XMLRPC file could have caused, because of this code:

1
2
3
4
5
6
        // Do some escapes for safety
        $post_title = $wpdb->escape($post_title);
        $post_name = sanitize_title($post_title);
        $post_excerpt = $wpdb->escape($post_excerpt);
        $post_content = $wpdb->escape($post_content);
        $post_author = (int) $post_author;

However, the new XMLRPC file also escapes everything. So everything gets escaped twice, causing the quotes to be double-escaped. So, I replaced the above code with the code from the new version:

1
2
3
4
5
6
7
8
9
        // Get the basics.
        $post_content    = apply_filters('content_save_pre',   $post_content);
        $post_excerpt    = apply_filters('excerpt_save_pre',   $post_excerpt);
        $post_title      = apply_filters('title_save_pre',     $post_title);
        $post_category   = apply_filters('category_save_pre',  $post_category);
        $post_status     = apply_filters('status_save_pre',    $post_status);
        $post_name       = apply_filters('name_save_pre',      $post_name);
        $comment_status  = apply_filters('comment_status_pre', $comment_status);
        $ping_status     = apply_filters('ping_status_pre',    $ping_status);

My test blog (which isn’t available to the public, as it’s on another server) seems to be coping well with this, I think I’ll publish a heap of entries to it and see how it holds up. I’m hoping that Ronan will be able to have a look over these changes, and hopefully we’ll see the Quote Escape bug gone, for good, very soon! Update: Apparently I didn’t do enough checking. The filters that are called don’t actually exist, so no escaping is done. That will teach me for going off half cocked. I will try to implement the new filters used by this version of the code, but we’ll see.