<?
	/*
	 * void
	 * blog_createpostlink
	 *
	 * returns a link to a blog post given the post's id
	 *
	 * ex: post.php?id=<? print($id); ?>
	 */
	function blog_createpostlink($id, $additionalQueryString = "")
	{
		return "viewpost.php?id=" . $id . $additionalQueryString;
	}
	
	
	/*
	 * string 
	 * blog_formatdate($format, $date)
	 * 
	 * returns a date string formatted using the given format parameter
	 */
	function blog_formatdate($format, $date)
	{
		return date($format, strtotime($date));
	}
	
    /*
	* void
	* blog_redirect($destination)
	* 
	* redirects user to specified destination
	*/
    function blog_redirect($destination)
    {
		/* Redirect to a different page in the current directory that was requested */
		$host  = $_SERVER['HTTP_HOST'];
		$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
		header("Location: http://$host$uri/$destination");
		exit;
    }
	
	/*
	* boolean
	* blog_isAuthenticated()
	*
	* returns true if the user has already authenticated, false otherwise
	*/
	function blog_isAuthenticated()
	{
		return (isset($_SESSION[BLOG_USER]));
	}
	
	/*
	* blog_showpost()
	* configurably displays a single post
	*/
	function blog_displaypost($post, $post_ShowTitleAsLink = TRUE, $post_ShowComments = FALSE, $feedback = null)
	{
		require("templates/post.php");
	}

	/*
	* blog_showpost()
	* displays feedback
	*/
	function blog_displayfeedback($feedback, $type)
	{
		require("templates/feedback.php");
	}
	
	/*
	* boolean
	* blog_open_db_connection()
	*
	* returns db connection if created successfully, otherwise exits with error message
	*/
	function blog_open_db_connection()
	{
		// connect to the database
		if(($connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD)) === FALSE)
		{
			exit( "Could not connect to database" );
		}
		
		// select the active database
		if(mysql_select_db(DATABASE_NAME, $connection) === FALSE)
		{
			exit( "Could not select database: " . mysql_error($connection) );	
		}
		
		return $connection;
	}
?>