<?php
// $Id: editPost.php,v 1.1 2004/07/11 10:28:47 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: metaWeblog.editPost

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

$storyid = (int)$params[0];
$publish = (bool)$params[4];

$title       = (string)$params[3]['title'];
$content     = (string)$params[3]['description'];
$categoryid  = (int)$params[3]['categories'][0]['categoryId'];

$home = extractFromTag("hometext", $content);
$more = extractFromTag("moretext", $content);

if ( !isset($home) && !isset($more) && !empty($content) ) {
	$home = $content;
}

if ( !isset($title) || !isset($home) ) {
	trigger_error(_phpRPC_BlogBeSure, E_USER_ERROR);
}

($publish == 1) ? ($published = time()) : ($published = 0);

// Comment out the following line, to let user edited posts
// reappear directly instead of having to be revalidated.
if ( !defined("isAdmin") ) { $published = 0; }

$title = addslashes(unhtmlentities($title));
$home  = addslashes(unhtmlentities($home));
$more  = addslashes(unhtmlentities($more));
$host  = $HTTP_SERVER_VARS['REMOTE_ADDR'];

$sql = "UPDATE ".$db->prefix("stories")." SET
	uid='$uid',
	title='$title',
	published='$published',
	hostname='$host',
	hometext='$home',
	bodytext='$more'";

if ( !empty($categoryid) && is_numeric($categoryid) ) {
	$sql .= ",topicid='$categoryid'";
}
$sql .= " WHERE storyid='$storyid'";

$query = $db->query($sql);

// Return a result
if (!$query) {
	trigger_error(_phpRPC_DBerreur, E_USER_ERROR);
	} elseif (isAdmin == 1) {
		load_function("newsRSS");
		build_rss();
	}

$rpc_encoder->add_value("boolean", 1);
$rpc_encoder->return_call();
?>
