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

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

$storyid = (int)$params[1];
$content = (string)$params[4];
$publish = (bool)$params[5];

$title   = extractFromTag("title",    $content);
$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'
	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();
?>
