<?php
// $Id: getRecentPosts.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.getRecentPosts

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

$topicid = (int)$params[1];
$limit   = (int)$params[4];

if ( !empty($topicid) ) {
	$extra = "WHERE topicid=$topicid";
	} else {
		$extra = "WHERE topicid!=$topicid";
	}

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

$query = $db->query("SELECT storyid, uid, title, hometext, bodytext, created FROM " .$db->prefix("stories"). " $extra ORDER BY created DESC", $limit);

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

// Start the response array
$rpc_encoder->start_array();
while (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();
}

// End of response array
$rpc_encoder->end_array();

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