Recent Topics

1 Sep 03, 2008 03:35    

My b2evolution Version: Not Entered

First, I love the B2 interface. It has been an amazing tool for what I am doing and support on the forum has been OUTSTANDING! Thank you.

I am trying to generate basically a post from another website (using data I have in another database). I am able to send over:

PostTitle
PostBody
B2BlogID

With this I am able to find the correct existing category or create a new category and then save the new post into the evo_items__item and evo_items__prerendering databases, but the post never shows up on the site or on the admin control panel for the site.

Perhaps I am missing something simple?!

Here is the code:


<?

# I connect to the database here

$B2BlogID = $_POST["B2BlogID"];
$PostTitle = $_POST["PostTitle"];
$PostBody = $_POST["PostBody"];
$USDealID = $_POST["USDealID"];


# Some error checking...
if($B2BlogID == "")
	{
	print"<p>You did not pass in the B2BlogID.</p>\n";
	exit;
	}

# Get Site Data
if($GetSite = mysql_query("SELECT * FROM evo_blogs WHERE blog_ID=\"$B2BlogID\" LIMIT 1"))
	{
	if($SiteData = mysql_fetch_object($GetSite))
		{
		print"<p>We are publishing to $SiteData->blog_siteurl... (blog_id = $SiteData->blog_ID for <b>$SiteData->blog_shortname</b>)</p>\n";
		}
	}

$CatName = "$SiteData->blog_shortname Lessons";
$CatURLName = strtolower($CatName);
$CatURLName = eregi_replace(" ", "-", $CatURLName);


# Check to see if Category Exists and get Category ID
# If not, then make new Category and get Category ID

if($GetCategory = mysql_query("SELECT * FROM evo_categories WHERE cat_blog_ID=\"$SiteData->blog_ID\" AND cat_urlname=\"$CatURLName\" LIMIT 1"))
	{
	if(mysql_num_rows($GetCategory) == 0)
		{
		print"<p>There are no matching categories for <b>$CatURLName</b> ($CatName)</p>\n";
		if($Insert = mysql_query("INSERT INTO evo_categories SET cat_name=\"$CatName\", cat_urlname=\"$CatURLName\", cat_blog_ID=\"$SiteData->blog_ID\""))
			{
			$CategoryID = mysql_insert_id();
			print"<p>Add Successful. Category ID = $CategoryID</p>\n";
			}
		}
	else
		{
		if($CategoryData = mysql_fetch_object($GetCategory))
			{
			$CategoryID = $CategoryData->cat_ID;
			}
		print"<p>We found a match for category named <b>$CatURLName</b> ($CatName)</p>\n";
		print"<p>Category ID = $CategoryID</p>\n";
		}
	}
else
	{
	print"<p>Error: Could not query categories...</p>\n";
	exit;
	}


# Add post to the system and return to the USDeals.php
$PostURLTitle = eregi_replace(" ", "-", $PostTitle);
$PostURLTitle = strtolower($PostTitle);


if($CategoryID != "")
	{
	if($AddPost = mysql_query("INSERT INTO evo_items__item SET post_creator_user_ID=\"1\",
post_lastedit_user_ID=\"1\",
post_datestart=NOW(),
post_datecreated=NOW(),
post_datemodified=NOW(),
post_status=\"published\",
post_locale=\"en-US\",
post_content=\"$PostBody\",
post_title=\"$PostTitle\",
post_urltitle=\"$PostURLTitle\",
post_main_cat_ID=\"$CategoryID\",
post_ptyp_ID=\"1\",
post_excerpt=\"\",
post_url=\"\",
post_priority=\"3\""))
		{
		print"<p><font color=green>Successfully added post!</font></p>\n";
		$NewPostID = mysql_insert_id();
		if($AddPost = mysql_query("INSERT INTO evo_items__prerendering
SET itpr_itm_ID=\"$NewPostID\",
itpr_format=\"text\",
itpr_renderers=\"\",
itpr_content_prerendered=\"$PostBody\",
itpr_datemodified=NOW()"))
			{
			print"<p><font color=green>Successfully added post!</font></p>\n";
			}
		}
	else
		{
		print"<p><font color=red>Failed adding post!</font></p>\n";
		}
	}

?>

I really appreciate any help you could give on this.

Thanks in advance!

James[/code]

2 Sep 03, 2008 10:46

1) you really need to do some sanitising of your variables ( checking that blog id is actually a number and stuff like that )
2) you don't need to do anything with the pre_rendered table, it'll be auto populated on first view
3) to make the post appear you also need to populate evo_postcats ;)

¥

3 Sep 05, 2008 01:16

Thank you again!

You are awesome.

Sincerely,

James


Form is loading...