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

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

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

if ( !is_numeric($topicid) || ( empty($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',
	allow_bbcode=1,
	allow_html=1,
	allow_smileys=1,
	type='$type'";

if ( !empty($categoryid) && is_numeric($categoryid) ) {
	$sql .= ",topicid='$categoryid'";
	} elseif ( !empty($topicid) ) {
		$sql .= ",topicid='$topicid'";
		} else {
			$sql .= ",topicid='1'";
		}

$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();
?>
