Thanks for taking the time to look at this. The learning curve I am up against is pretty steep.
I should let you know that I did get this script installed and working on another host without any problems. It was a another member that pointed out that DreamHost diabled allow_url_fopen which was problably causing the problem.
The RSS script I am trying to get working comes in three files. It's meant to work with Simple Machine Forums and post news into your forums from RSS feeds.
Thanks for any help with this!
The first file news.php:
<?php
//
// SMF RSS Injector by Jerry Bell - jerry@cyvin.org
// Based on the Joomla RSS import script by Max Soukhomlinov, maxs@intellectit.com.au
//
// This script requires XML_RSS and PHP Pear Libraries
//
//
// This script is quick and dirty. Please remember to abide by the RSS content providers' terms of use.
/** the PEAR XML_RSS object/class is required */
require 'RSS.php';
/** DATABASE Configuration */
define("DB_HOSTNAME","mysql.domain.com"); //Insert your DB server name here
define("DB_USERNAME","mysql_username"); //DB username here
define("DB_PASSWD","mysql_password"); // DB password here
define("DB_DATABASE","mysql_database"); //DB name here
$userid = 1; //Set this to the SMF userid you want the messages posted from
$boardid = 1;//Set this to the id of the board you want to post the messages in
/** pull list of remote RSS feeds, via a remote RSS feed. */
$rss_feed = & new XML_RSS('http://xml.amazon.com/onca/xml3?mode=magazines&bcm=Magazines%3A%20Gay%20%26%20Lesbian&t=webservices-20&dev-t=amznRss&type=lite&page=1&ct=text/xml&sort=+salesrank&f=http://xml.amazon.com/xsl/xml-rss091.xsl&BrowseNodeSearch=602338'); //Insert your URL here
//$rss_feed = & new XML_RSS(''); //Used this for testing with local file, a bit quicker
// Function for shortening articles based on maximum length
function str_stop($string, $max_length){
if (strlen($string) > $max_length){
$string = substr($string, 0, $max_length);
$pos = strrpos($string, " ");
if($pos === false) {return substr($string, 0, $max_length)."...";}
return substr($string, 0, $pos)."...";
}else{return $string;}
}
/** create the database connection object */
$obj_db = @mysql_connect(DB_HOSTNAME,DB_USERNAME,DB_PASSWD) or die (mysql_error());
/** select the intended database */
@mysql_select_db(DB_DATABASE,$obj_db) or die (mysql_error());
$rss_feed->parse();
$num_articles=0; //Variable used to count number of new articles, displayed in an email below
// Here we make sure that feed articles do not already exist in DB
// this uses title names, make sure to use the same title formatting here as you will use further down
// state = 1 not trashed
foreach ($rss_feed->getItems() as $item) {
$obj_query = @mysql_query("
SELECT
COUNT(ID_MSG) AS link_match
FROM
smf_messages
WHERE
subject = '". str_stop(addslashes($item['title']),100) ."'
",$obj_db) or die(mysql_error());
$int_count = @mysql_fetch_assoc($obj_query) or die(mysql_error());
mysql_free_result($obj_query);
if ($int_count['link_match'] == 0) {
$num_articles = $num_articles +1;
/**
* REFORMATTING CODE
**/
// In my experience you have to play with the definitions from different RSS feeds - some rss feeds call fields different things.
$titletext = str_stop(addslashes($item['title']),100);
// This adds an html link at to the original article at the very bottom of the post.
$maintext = addslashes($item['description']) . "<p><a href=\"" . $item['link'] . "\">" . $item['link'] . "</a>";
@mysql_query("
INSERT INTO smf_topics(
ID_BOARD,
ID_MEMBER_STARTED,
ID_MEMBER_UPDATED
) VALUES (
'$boardid',
'$userid',
'$userid'
)
",$obj_db) or die(mysql_error());
$topic = mysql_insert_id();
$postertime = date('U');
//Insert the actual message
@mysql_query("
INSERT INTO smf_messages(
subject,
body,
ID_MEMBER,
ID_BOARD,
ID_TOPIC,
posterTime
) VALUES (
'". $titletext ."',
'". $maintext ."',
'$userid',
'$boardid',
'$topic',
'$postertime'
)
",$obj_db) or die(mysql_error());
$messageid = mysql_insert_id();
//Go back and set ID_FIRST_MSG and ID_LAST_MSG in the topics table
@mysql_query("
UPDATE smf_topics
SET ID_FIRST_MSG = '$messageid',
ID_LAST_MSG = '$messageid'
WHERE ID_TOPIC = '$topic'
",$obj_db) or die(mysql_error());
//Increment total posts for board
@mysql_query("
UPDATE smf_boards
SET numPosts = numPosts + 1,
numTopics = numTopics + 1
WHERE ID_BOARD = '$boardid'
",$obj_db) or die(mysql_error());
//Increment Total Messages
@mysql_query("
UPDATE smf_settings
SET value = value + 1
WHERE variable = 'totalMessages'
",$obj_db) or die(mysql_error());
//Increment Total Topics
@mysql_query("
UPDATE smf_settings
SET value = value + 1
WHERE variable = 'totalTopics'
",$obj_db) or die(mysql_error());
// Increment post count for user record
@mysql_query("
UPDATE smf_members
SET posts = posts + 1
WHERE ID_MEMBER = '$userid'
",$obj_db) or die(mysql_error());
}
}
if ($obj_db) {
@mysql_close($obj_db);
}
?>