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

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

$topicid = (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);
}

if ( !is_numeric($topicid) || empty($topicid) ) {
	trigger_error(_phpRPC_Topic, E_USER_ERROR);
}

($publish == 1) ? ($published = time()) : ($published = 0);
if ( !defined("isAdmin") ) {
	$published = 0;
	$html      = 0;
	$type      = 'user';
	} else {
		$html = 1;
		$type = 'admin';
	}

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

$sql = "INSERT INTO " .$db->prefix("stories"). " SET
	uid='$uid',
	title='$title',
	created='$created',
	published='$published',
	hostname='$host',
	hometext='$home',
	bodytext='$more',
	topicid='$topicid',
	allow_bbcode=1,
	allow_html=$html,
	allow_smileys=1,
	type='$type'";

$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("integer", $db->insert_id());
$rpc_encoder->return_call();
?>
