<?php
/*
Plugin Name: Short Post URLS
Plugin URI: http://redmine.sproutventure.com
Description: Shortened Post URLs for twitter and the like. Example, http://siteurl.com/s/175. Inspiration from 5thirtyone.com ( http://5thirtyone.com/archives/2075 )
Version: beta
Author: Dan Cameron of Sprout Venture
Author URI: http://dancameron.org
License: GNU General Public License

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	Content Restrictions for WordPress has original works by 
	WP-AddQuicktag: (C) 2005 Roel Meurders - GNU General Public License
	HidePost: (C) 2009 Fu4ny - GNU General Public License

	This Wordpress plugin is released under a GNU General Public License. A complete version of this license
	can be found here: http://www.gnu.org/licenses/gpl.txt

	This Wordpress plugin is released "as is". Without any warranty. The authors cannot
	be held responsible for any damage that this script might cause.
	
*/

class Short_Post_URLS {
	
	
	function Short_Post_URLS() 
		{
			register_activation_hook( __FILE__, array (&$this, 'flush_rewrite_rules' ) );
			add_action( 'generate_rewrite_rules', array (&$this, 'custom_rewrite_rules' ) );
			//add_shortcode ( 'short-url', array (&$this, 'short_open_call' ) ); # thought about this one but cutting for time
		}
		
		// Array of custom URLs with some examples for customization
	function custom_rewrite_rules( $wp_rewrite ) 
		{
			$newRules = array();
		
				// Defualt http://siteurl.com/s/1 ( '1' being the post id )
				$newRules[ 's/([0-9]+)$' ] = 'index.php?p=' . $wp_rewrite->preg_index( 1 );
				// Another example below http://siteurl.com/1
				# $newRules[ '([0-9]+)$' ] = 'index.php?p=' . $wp_rewrite->preg_index( 1 );
		
			$wp_rewrite->rules = $newRules + $wp_rewrite->rules;
			return $wp_rewrite;
		}

		// Flush the current rewrite rules so the above array is added.
	function flush_rewrite_rules() 
		{
			global $wp_rewrite;
			$wp_rewrite->flush_rules();
		}

}

$spurl = new Short_Post_URLS();

?>