More on redirecting from Textpattern to Wordpress

I hacked up the Textpattern top level index.php so that it tries to redirect to Wordpress. Of course I found a bug in the import script: it silently fails on articles that have single quotes in their title.

Anyway, my code tries to be fail-safe — in this case it falls thru to the defalt TXP logic.

Below the things in bold need to be replaced with appropriate values for your environment. Sorry but the indentation didn’t come thru on the cute and paste so it’s not as pretty as it could be — but it should work w/o too much effort if you’ve used PHP and MySQL before.

<?php

$atom = $_GET[ “atom”];
if ( $atom == 1)
{
header( “Location: WP_BASE_URL/feed/atom”);
exit( 0);
}
$rss = $_GET[ “rss”];
if ( $rss == 1)
{
header( “Location: WP_BASE_URL/feed/rss”);
exit( 0);
}

include ‘textpattern/config.php’;

$conn = mysql_pconnect( “HOST“, “USER“, “PASSWORD“) || die( “ouch”);
mysql_select_db( “TXP_DB_NAME“) || die( “ouch 2″);
$id = $_GET[ “id”];
if ( isset( $id))
{
$data = mysql_fetch_row( mysql_query( “SELECT Title FROM textpattern WHERE ID = $id”));
$title = $data[ 0];
mysql_select_db( “WORDPRESS_DB_NAME“) || die( “ouch 3″);
$data = mysql_fetch_row( mysql_query( $sql = “SELECT
CONCAT( ‘WP_BASE_URL‘, DATE_FORMAT( post_date, ‘/%Y/%m/%d/’), post_name, ‘/’) FROM wp_posts WHERE post_title = ‘” . mysql_escape_string( $title) . “‘”));
$url = $data[ 0];
if ( $url)
{
header( “Location: $url”);
exit( 0);
}
else
{

# bug in importer: doesn’t import docs w/ single quotes in title
# fall thru

}
}
else
{
header( “Location: WP_BASE_URL/”);
exit( 0);
}

# fall thru to default txp logic
include $txpcfg[’txpath’].’/publish.php’;
textpattern();
?>

Leave a Reply »»