News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

RSS Injector available

Started by confusion, December 24, 2005, 04:04:48 PM

Previous topic - Next topic

Xarcell

I've been fiddling with it, and still no luck. IK entered all the info right, uploaded the injector/files to my root directory. I get a blank page (no errors) when I run the news.php file. However nothing shows up in my forum.



/** DATABASE Configuration */
define("DB_HOSTNAME","*myhostname"); //Insert your DB server name here
define("DB_USERNAME","*myusername"); //DB username here
define("DB_PASSWD","******"); // DB password here
define("DB_DATABASE","*mydbname"); //DB name here
$userid = 4; //Set this to the SMF userid you want the messages posted from
$boardid = 35; //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://rss.gamespot.com/misc/rss/gamespot_updates_xbox_360.xml'); //Insert your URL here
//$rss_feed = & new XML_RSS('feed.xml'); //Used this for testing with local file, a bit quicker


Is that all I edit?

balzizras

This script is a really great idea, and I'd like to get it working, but im getting this error:
QuoteTable 'schultz_forum.messages' doesn't exist

Could someone tell me what I need to edit in order to make this work?


Im using the news.php file btw.
A strong body makes the mind strong. As to the species of exercises, I advise the gun. While this gives moderate exercise to the body, it gives boldness, enterprise and independence to the mind. Games played with the ball, and others of that nature, are too violent for the body and stamp no character on the mind. Let your gun therefore be your constant companion of your walks. - Thomas Jefferson, letter to Peter Carr, August 19, 1785

TechnoDragon

@balzizras

you have to manually edit the news.php file.

at each sql call for the table you have to add the prefix for the table.

so example... messages should be smf_messages (or whatever prefix you have in your database)

i am looking at a way to recode the template so there is less editing by using ssi calls, but it is slow going for me as I am new to all of this
Don't tell me to get into shape...I have a shape...It is round!


daveso

i wish i knew what you guys are talking about.
as a new person to all this stuff. it is just too overwhelming.

I'm putting together a forum for our group, at least trying to...all i want is to include news feeds within a couople of topics, but all this editing and stuff of these files i dont even know what you're taling about.

I don;t even know where the files are on my website...or anything...
just a newbie...
can't someone write up a simple step by step from square 1 for new guys?

SMF seems not user friendly anyway compared to the php board I originally tried to run

TechnoDragon

If you run SMF with say Tiny Portal and no mods it is a very user friendly system...the majority of the talk here is for modifying the forum do do more than it was coded to do.

If you are looking for just an rss feed, you can use a package called Tiny Portal (www.tinyportal.net) and it uses an easy system of "blocks" one of which is designed to do rss feeds.

If you are looking to have the feeds entered into your forum as topics and posts that is what this is for and I can help you with the setup if you like.

Also,most of the files that ever need to be modified are usually in one of two places...either the sources directory or the default theme directory.
Don't tell me to get into shape...I have a shape...It is round!


balzizras

Well I got rid of the error i mentioned above, but now I'm getting this one:
QuoteDuplicate entry '0-48' for key 2

Any idea what is wrong?
A strong body makes the mind strong. As to the species of exercises, I advise the gun. While this gives moderate exercise to the body, it gives boldness, enterprise and independence to the mind. Games played with the ball, and others of that nature, are too violent for the body and stamp no character on the mind. Let your gun therefore be your constant companion of your walks. - Thomas Jefferson, letter to Peter Carr, August 19, 1785

TechnoDragon

post a copy of your news.php here and I'll take a look at it
Don't tell me to get into shape...I have a shape...It is round!


Xarcell

You can't have attachments here...

balzizras

Quote<?php
//
// SMF RSS Injector by Jerry Bell - [email protected]
// Based on the Joomla RSS import script by Max Soukhomlinov, [email protected]
//
// 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","localhost"); //Insert your DB server name here
define("DB_USERNAME","schultz_smf1"); //DB username here
define("DB_PASSWD","notpostingmypassherelol"); // DB password here
define("DB_DATABASE","schultz_forum"); //DB name here
$userid = 8; //Set this to the SMF userid you want the messages posted from
$boardid = 48.0;//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://newsrss.bbc.co.uk/rss/newsplayer_world_edition/sci-tech/rss.xml'); //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 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 boards
            SET numPosts = numPosts + 1,
            numTopics = numTopics + 1
            WHERE ID_BOARD = '$boardid'
      ",$obj_db) or die(mysql_error());
//Increment Total Messages
    @mysql_query("
         UPDATE settings
            SET value = value + 1
            WHERE variable = 'totalMessages'
      ",$obj_db) or die(mysql_error());
//Increment Total Topics
    @mysql_query("
         UPDATE settings
            SET value = value + 1
            WHERE variable = 'totalTopics'
      ",$obj_db) or die(mysql_error());
// Increment post count for user record
    @mysql_query("
                        UPDATE members
                        SET posts = posts + 1
                                WHERE ID_MEMBER = '$userid'
                ",$obj_db) or die(mysql_error());
        }
    }

if ($obj_db) {
    @mysql_close($obj_db);
}
?>

There ya go thanks.
A strong body makes the mind strong. As to the species of exercises, I advise the gun. While this gives moderate exercise to the body, it gives boldness, enterprise and independence to the mind. Games played with the ball, and others of that nature, are too violent for the body and stamp no character on the mind. Let your gun therefore be your constant companion of your walks. - Thomas Jefferson, letter to Peter Carr, August 19, 1785

TechnoDragon

<?php
//
// SMF RSS Injector by Jerry Bell - [email protected]
// Based on the Joomla RSS import script by Max Soukhomlinov, [email protected]
// 
// 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",""); //Insert your DB server name here
define("DB_USERNAME",""); //DB username here
define("DB_PASSWD",""); // DB password here
define("DB_DATABASE",""); //DB name here
$userid 8//Set this to the SMF userid you want the messages posted from
$boardid 48;//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://newsrss.bbc.co.uk/rss/newsplayer_world_edition/sci-tech/rss.xml'); //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($string0$max_length);
       
$pos strrpos($string" ");
       if(
$pos === false) {return substr($string0$max_length)."...";}
       return 
substr($string0$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);
}
?>


There...you missed some of the database calls.
Don't tell me to get into shape...I have a shape...It is round!


Xarcell

Quote from: technodragon73 on March 19, 2006, 03:32:27 PM
<?php
//
// SMF RSS Injector by Jerry Bell - [email protected]
// Based on the Joomla RSS import script by Max Soukhomlinov, [email protected]
// 
// 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",""); //Insert your DB server name here
define("DB_USERNAME",""); //DB username here
define("DB_PASSWD",""); // DB password here
define("DB_DATABASE",""); //DB name here
$userid 8//Set this to the SMF userid you want the messages posted from
$boardid 48;//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://newsrss.bbc.co.uk/rss/newsplayer_world_edition/sci-tech/rss.xml'); //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($string0$max_length);
       
$pos strrpos($string" ");
       if(
$pos === false) {return substr($string0$max_length)."...";}
       return 
substr($string0$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);
}
?>


There...you missed some of the database calls.

I'm completely lost.

TechnoDragon

There were minor ommissions in there.  I found them as I had exactly the same problem with it when I tried to use it.
Don't tell me to get into shape...I have a shape...It is round!


Xarcell

@technodragon73

What version of SMF do you have it installed on?

balzizras

I'm getting this error now :
QuoteAccess denied for user: 'schultz@localhost' (Using password: NO)
I only saw two places to put my password, am I blind or stupid? (prolly) what am I doing wrong now?

Btw; sorry to bother you..

<?php
//
// SMF RSS Injector by Jerry Bell - [email protected]
// Based on the Joomla RSS import script by Max Soukhomlinov, [email protected]
// 
// 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("localhost",""); //Insert your DB server name here
define("schultz_smf1",""); //DB username here
define("mypass",""); // DB password here
define("schultz_forum",""); //DB name here
$userid 8//Set this to the SMF userid you want the messages posted from
$boardid 48;//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://rss.news.yahoo.com/rss/topstories'); //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($string0$max_length);
       
$pos strrpos($string" ");
       if(
$pos === false) {return substr($string0$max_length)."...";}
       return 
substr($string0$pos)."...";
   }else{return 
$string;}
}
/** create the database connection object */
$obj_db = @mysql_connect(localhost,schultz_smf1,mypass) or die (mysql_error());

/** select the intended database */
@mysql_select_db(schultz_forum,$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);
}
?>
A strong body makes the mind strong. As to the species of exercises, I advise the gun. While this gives moderate exercise to the body, it gives boldness, enterprise and independence to the mind. Games played with the ball, and others of that nature, are too violent for the body and stamp no character on the mind. Let your gun therefore be your constant companion of your walks. - Thomas Jefferson, letter to Peter Carr, August 19, 1785

Xarcell

There's only one place to put yer password.

I don't think you should have done it the way you have. cut & paste techno's last reply with the news.php code and fill in the info. It should work for your particluar DB...


Xarcell

#55
Cut and paste this code and write in your DB password in the configuration.



<?php
//
// SMF RSS Injector by Jerry Bell - [email protected]
// Based on the Joomla RSS import script by Max Soukhomlinov, [email protected]
// 
// 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","localhost"); //Insert your DB server name here
define("DB_USERNAME","schultz_smf1"); //DB username here
define("DB_PASSWD","yourDBpassword"); // DB password here
define("DB_DATABASE","schultz_forum"); //DB name here
$userid 8//Set this to the SMF userid you want the messages posted from
$boardid 48;//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://rss.news.yahoo.com/rss/topstories'); //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($string0$max_length);
       
$pos strrpos($string" ");
       if(
$pos === false) {return substr($string0$max_length)."...";}
       return 
substr($string0$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);
}
?>


TechnoDragon

Sorry...i figured he would know to put his info in the right spaces...lol
Don't tell me to get into shape...I have a shape...It is round!


balzizras

Quote from: Xarcell on March 19, 2006, 05:03:58 PM
Cut and paste this code and write in your DB password in the configuration.



<?php
//
// SMF RSS Injector by Jerry Bell - [email protected]
// Based on the Joomla RSS import script by Max Soukhomlinov, [email protected]
// 
// 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","localhost"); //Insert your DB server name here
define("DB_USERNAME","schultz_smf1"); //DB username here
define("DB_PASSWD","yourDBpassword"); // DB password here
define("DB_DATABASE","schultz_forum"); //DB name here
$userid 8//Set this to the SMF userid you want the messages posted from
$boardid 48;//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://rss.news.yahoo.com/rss/topstories'); //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($string0$max_length);
       $pos strrpos($string" ");
       if($pos === false) {return substr($string0$max_length)."...";}
       return substr($string0$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);
}
?>



Ok I used the above code, and I finially see what I was doing wrong.. But anyway Im still getting the error I had before: Duplicate entry '0-48' for key 2
A strong body makes the mind strong. As to the species of exercises, I advise the gun. While this gives moderate exercise to the body, it gives boldness, enterprise and independence to the mind. Games played with the ball, and others of that nature, are too violent for the body and stamp no character on the mind. Let your gun therefore be your constant companion of your walks. - Thomas Jefferson, letter to Peter Carr, August 19, 1785

TechnoDragon

first, does that board number actually exist?

Second, if it doesn't you need to create a board with that ID.

If it does, try using another board to make sure that is/is not the problem.

When I had the error I had to first add the database prefix, then I had to change the board
Don't tell me to get into shape...I have a shape...It is round!


balzizras

#59
Quote from: technodragon73 on March 19, 2006, 08:12:01 PM
first, does that board number actually exist?

Second, if it doesn't you need to create a board with that ID.

If it does, try using another board to make sure that is/is not the problem.

When I had the error I had to first add the database prefix, then I had to change the board


First yep that board/board number did exist. Anyway I changed it to another board and it worked.. weird.

So thanks a bunch for helping me out. I know it took me long enough,.. heh.  :)

Anyway one more question, would it be as simple as adding more of this line: $rss_feed = & new XML_RSS(''); to get it to post from multi rss feeds? Or am I just being stupid.. Thanks again.

EDIT: Nevermind i tried it (duh why didn't I think of that) and it does work.

EDIT: It won't insert feeds from this site: http://info.detnews.com/rss/index.cfm
Any idea why?
A strong body makes the mind strong. As to the species of exercises, I advise the gun. While this gives moderate exercise to the body, it gives boldness, enterprise and independence to the mind. Games played with the ball, and others of that nature, are too violent for the body and stamp no character on the mind. Let your gun therefore be your constant companion of your walks. - Thomas Jefferson, letter to Peter Carr, August 19, 1785

Advertisement: