<?php

/*
Plugin Name: RevvedUp special page handler
Plugin URI: http://rudd-o.com/
Description: Handle the RevvedUp theme special pages
Version: 0.1.0
Author: Manuel Amador (Rudd-O)
Author URI: http://rudd-o.com/
*/


function revvedup_sendstatus($code,$string) {
        header("Status: $code $string");
        header("HTTP/1.x $code $string");
}


function revvedup_special_pages_redirect() {

if (!isset($_GET["showpage"]) && is_404()) {
	$redir_url = $_SERVER["REDIRECT_URL"];
	if ($redir_url == "/archives") {
		header("Location: /archives/"); die;
	}
	if ($redir_url == "/archives/") {
		$_GET["showpage"] = "archives";
	}
}

if (isset($_GET["showpage"])) {
	global $wp_query;
	if ($_GET["showpage"] == 'archives') {
		unset($_GET["error"]);
		$wp_query->is_404 = false;
		revvedup_sendstatus(200,"OK");
		require(TEMPLATEPATH . "/archives.php");
		die;
	}
	elseif ($_GET["showpage"] == 'directoryindex') {
		unset($_GET["error"]);
		$wp_query->is_404 = false;
		revvedup_sendstatus(200,"OK");
		require(TEMPLATEPATH . "/directoryindex.php");
		die;
	}
	elseif ($_GET["showpage"] == 'error') {
		require(TEMPLATEPATH . "/404.php");
		die;
	}
	else { /* the user tried a bad request */
		$_GET["error"] = "404"; /* simulate an HTTP error */
		$wp_query->is_404 = true;
		$_GET["httperror"] = "400"; /* simulate an HTTP error */
		require(TEMPLATEPATH . "/404.php");
		die;
	}
}
}

add_action("template_redirect","revvedup_special_pages_redirect");
?>
