<?php
// $Id: getPost.php,v 1.1 2004/07/11 10:28:46 Farsus Exp $
// -------------------------------------------------------------------------//
//			                 RUNCMS                                         //
//                                                                          //
//	 reliable - Unique - Nocost &  Simplicity & ease off use                //
//                       < http://www.runcms.org >                          //
// -------------------------------------------------------------------------//
// Original Author: i-Tech (Half-Dead)
// Author Website : http://www.i-Technology.NET
// License Type   : LGPL: See /manual/LICENSES/LGPL.txt
// ------------------------------------------------------------------------- //

// Function: blogger.getPost

load_function("isAdmin");
$user = (string)$params[2];
$pass = (string)$params[3];
$uid  = login($user, $pass);

$storyid = (int)$params[1];

if ( !defined("isAdmin") ) { $extra = "AND uid=$uid"; }

$query = $db->query("SELECT storyid, uid, title, hometext, bodytext, created FROM " .$db->prefix("stories"). " WHERE storyid='$storyid' $extra");

// Do we have any posts?
if ($db->num_rows($query) < 1) {
	trigger_error(_phpRPC_BlogNoPosts, E_USER_ERROR);
}

list($storyid, $uid, $title, $hometext, $bodytext, $created) = $db->fetch_row($query);

if ( !empty($bodytext) ) {
	$content = "<title>$title</title><hometext>\n$hometext\n</hometext>\n<moretext>\n$bodytext\n</moretext>";
	} else {
		$content = "<title>$title</title>$hometext";
	}

// Each respose has a struct
$rpc_encoder->start_struct();
$rpc_encoder->add_value("integer", $uid    , "userid");
$rpc_encoder->add_value("time"   , $created, "dateCreated");
$rpc_encoder->add_value("string" , $content, "content");
$rpc_encoder->add_value("integer", $storyid, "postid");
$rpc_encoder->end_struct();

// Return the result
$rpc_encoder->return_call();
?>
