Wishful Coding

Didn't you ever wish your
computer understood you?

Updating to Wordpress 3.0

I'm trying to upgrade this blog to WordPress 3.0. While I skipped 2.9.2 because it was only a minor fix, this time there are some cool new features, which I'm not going to tell about, use Google! This theme used the default comment template in WordPress 2.9, but unfortunately this has been removed or broken. To fix this, I had to use the comments.php from the new and shiny twentyten theme. I copied their comments.php over to my theme, but unfortunately this only made matter worse. It uses a few functions defined in functions.php. Rather than trying to copy those specific functions over to my functions.php, I just included theirs:
include(TEMPLATEPATH . "/../twentyten/functions.php");
Can you think of a more ugly solution? I'll fix it later. There might be more bugs to be discovered. Do you see anything out-of-order on this blog? Please leave a comment.

Wordpress RSS widget in a post/page

I'm currently writing a theme for a friend who is going to coach photographers. He wants to have a page that lists RSS feeds from all those photographers. One part of the puzzle is easily solved by using Yahoo! Pipes to combine those feeds, the other part isn't that easy to solve. WordPress comes with a standard RSS widget, but it's only a widget, not a shortcode. There are a bunch of plugins that either offer a RSS widget or turn feeds items into posts. What I did is write my own plugin in only 10 lines of actual code, utilizing the shortcode API and the built-in RSS widget.
  1. Save and upload the snippet below to your plugins folder
  2. Activate it in the WP admin
  3. Add the [rsstag] shortcode to your post or page
  4. Add the feed url like this: [rsstag url="http://pepijn.cqhosting.nl/feed/"]
  5. Save!
You can optionally add one or more of show_summary=1, show_date=1 or show_author=1 to add the respective meta-data to every entry.
php
/*
Plugin Name: Wordpress RSS shortcode
Plugin URI: http://pepijn.cqhosting.nl/2010/06/wordpress-rss-widget-in-a-post-page
Description: This plugin fetches an RSS feed as a shortcode
Author: Pepijn de Vos
Version: 1.0
Author URI: http://pepijn.cqhosting.nl
*/

function rsstag($atts) {
        $atts = shortcode_atts(array(
                'url' => get_bloginfo('rss2_url'),
                'show_author' => 0,
                'show_date' => 0,
                'show_summary' => 0
        ), $atts);
        //var_dump($atts);
        wp_widget_rss_output($atts['url'], $atts);
}
add_shortcode('rsstag', 'rsstag');
?>
I will upload this to WordPress.org soon.

Wordpress MU in Resin with Quercus

While researching Quercus today, I ran into some trouble running the new integrated Multi Site feature of Wordpress 3.0(previously a separate project known as Wordpress MU or WPMU for short) on Resin. Quercus is a PHP implementation written in Java that runs on any Java Servlet Container, including but not limited to Jetty, Tomcat or Resin. I took Resin for it was the easiest to setup and includes Quercus. Normally one would just use Apache and mod_php, but I also want to run Jython and Clojure projects, so I'm looking for a solution to combine these. Wordpress MU allows me to run multiple blogs on a single installation(as seen on wordpress.com), which I want to use for hosting websites for my clients. The problem with WPMU is that to map the different urls to one installation, some tricky mod_rewrite code is required for Apache, but since I'm using Resin here, I'll have to find another solution. There is a post on the Quercus wiki describing the process of setting up a Multi Site Wordpress installation, but this is for an old version of WPMU(before the merge) and an old version of Resin. After a good few hours of trying, I got it working with the latest version of Wordpress 3.0, Quercus 4.0.3 and Resin 4.0.7. Just follow the wiki, except for a few points:
<?xml version="1.0"?>
<web-app xmlns="http://caucho.com/ns/resin" xmlns:resin="urn:java:com.caucho.resin">
	<resin:Forward regexp="^/index\.php$" target="/"/>
	<resin:Dispatch regexp="^">
		<resin:IfFileExists/>
	</resin:Dispatch>
	<resin:Redirect regexp="^(/[_0-9a-zA-Z-]+/)?wp-admin$" target="$1wp-admin/"/>
	<resin:Forward regexp="^(/[_0-9a-zA-Z-]+/)?files/(.+)" target="/wp-includes/ms-files.php?file=$2"/>
	<resin:Forward regexp="^(/[_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*)" target="/$2"/>
	<resin:Forward regexp="^(/[_0-9a-zA-Z-]+/)?(.*\.php)$" target="/$2"/>
	<resin:Forward regexp="/.*" target="/index.php"/>
</web-app>
Note that I did not use the pro version, skipped the DNS stuff by using directory instead of subdomains in WP, I also skipped the chown stuff by removing this block from resin.xml:
<resin:if test="${resin.userName == 'root'}">
        <user-name>pepijndevos</user-name>
        <group-name>staff</group-name>
      </resin:if>