Advertisement:

Author Topic: RSS Injector available  (Read 189617 times)

Offline Xarcell

  • SMF Hero
  • ******
  • Posts: 1,684
  • Gender: Male
  • SMF-DP Supporter
Re: RSS Injector available
« Reply #40 on: March 16, 2006, 05:37:46 AM »
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.

Code: [Select]

/** 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?

Offline balzizras

  • Semi-Newbie
  • *
  • Posts: 45
  • Gender: Male
    • The Michiganian
Re: RSS Injector available
« Reply #41 on: March 19, 2006, 12:55:25 AM »
This script is a really great idea, and I'd like to get it working, but im getting this error:
Quote
Table '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

Offline TechnoDragon

  • Jr. Member
  • **
  • Posts: 374
  • Gender: Male
  • With great power comes great resposibility...
    • Dragon Talk Forum
Re: RSS Injector available
« Reply #42 on: March 19, 2006, 09:26:07 AM »
@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!


Offline daveso

  • Newbie
  • *
  • Posts: 6
Re: RSS Injector available
« Reply #43 on: March 19, 2006, 10:12:25 AM »
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

Offline TechnoDragon

  • Jr. Member
  • **
  • Posts: 374
  • Gender: Male
  • With great power comes great resposibility...
    • Dragon Talk Forum
Re: RSS Injector available
« Reply #44 on: March 19, 2006, 01:22:22 PM »
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!


Offline balzizras

  • Semi-Newbie
  • *
  • Posts: 45
  • Gender: Male
    • The Michiganian
Re: RSS Injector available
« Reply #45 on: March 19, 2006, 02:15:27 PM »
Well I got rid of the error i mentioned above, but now I'm getting this one:
Quote
Duplicate 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

Offline TechnoDragon

  • Jr. Member
  • **
  • Posts: 374
  • Gender: Male
  • With great power comes great resposibility...
    • Dragon Talk Forum
Re: RSS Injector available
« Reply #46 on: March 19, 2006, 02:29:02 PM »
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!


Offline Xarcell

  • SMF Hero
  • ******
  • Posts: 1,684
  • Gender: Male
  • SMF-DP Supporter
Re: RSS Injector available
« Reply #47 on: March 19, 2006, 02:42:34 PM »
You can't have attachments here...

Offline balzizras

  • Semi-Newbie
  • *
  • Posts: 45
  • Gender: Male
    • The Michiganian
Re: RSS Injector available
« Reply #48 on: March 19, 2006, 02:45:22 PM »
Quote
<?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","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

Offline TechnoDragon

  • Jr. Member
  • **
  • Posts: 374
  • Gender: Male
  • With great power comes great resposibility...
    • Dragon Talk Forum
Re: RSS Injector available
« Reply #49 on: March 19, 2006, 03:32:27 PM »
Code: [Select]
<?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&#39; terms of use.  

/** the PEAR XML_RSS object/class is required */
require &#39;RSS.php&#39;;

/** 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(&#39;http://newsrss.bbc.co.uk/rss/newsplayer_world_edition/sci-tech/rss.xml&#39;); //Insert your URL here
//$rss_feed = & new XML_RSS(&#39;&#39;); //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 = &#39;"
str_stop(addslashes($item[&#39;title&#39;]),100) ."&#39;
        
",$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[&#39;link_match&#39;] == 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[&#39;title&#39;]),100);
// This adds an html link at to the original article at the very bottom of the post.
$maintext = addslashes($item[&#39;description&#39;]) . "<p><a href=\"" $item[&#39;link&#39;] . "\">" . $item[&#39;link&#39;] . "</a>";
    
@mysql_query("
INSERT INTO smf_topics(
ID_BOARD,
ID_MEMBER_STARTED,
ID_MEMBER_UPDATED
) VALUES (
&#39;
$boardid&#39;,
&#39;
$userid&#39;,
&#39;
$userid&#39;
)
"
,$obj_db) or die(mysql_error());
$topic mysql_insert_id();
$postertime date(&#39;U&#39;);
//Insert the actual message
    
@mysql_query("
INSERT INTO smf_messages(
subject,
body,
  ID_MEMBER,
ID_BOARD,
ID_TOPIC,
posterTime
) VALUES (
&#39;"
$titletext ."&#39;,
&#39;"
$maintext ."&#39;,
&#39;
$userid&#39;,
&#39;
$boardid&#39;,
&#39;
$topic&#39;,
&#39;
$postertime&#39;
)
"
,$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 = &#39;
$messageid&#39;, 
ID_LAST_MSG = &#39;
$messageid&#39;
WHERE ID_TOPIC = &#39;
$topic&#39;
"
,$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 = &#39;
$boardid&#39;
"
,$obj_db) or die(mysql_error());
//Increment Total Messages
    
@mysql_query("
UPDATE smf_settings
SET value = value + 1
WHERE variable = &#39;totalMessages&#39;
"
,$obj_db) or die(mysql_error());
//Increment Total Topics
    
@mysql_query("
UPDATE smf_settings
SET value = value + 1
WHERE variable = &#39;totalTopics&#39;
"
,$obj_db) or die(mysql_error());
// Increment post count for user record
    
@mysql_query("
                        UPDATE smf_members
                        SET posts = posts + 1
                                WHERE ID_MEMBER = &#39;
$userid&#39;
                "
,$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!


Offline Xarcell

  • SMF Hero
  • ******
  • Posts: 1,684
  • Gender: Male
  • SMF-DP Supporter
Re: RSS Injector available
« Reply #50 on: March 19, 2006, 03:47:34 PM »
Code: [Select]
<?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&#39; terms of use.  

/** the PEAR XML_RSS object/class is required */
require &#39;RSS.php&#39;;

/** 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(&#39;http://newsrss.bbc.co.uk/rss/newsplayer_world_edition/sci-tech/rss.xml&#39;); //Insert your URL here
//$rss_feed = & new XML_RSS(&#39;&#39;); //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 = &#39;"
str_stop(addslashes($item[&#39;title&#39;]),100) ."&#39;
        
",$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[&#39;link_match&#39;] == 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[&#39;title&#39;]),100);
// This adds an html link at to the original article at the very bottom of the post.
$maintext = addslashes($item[&#39;description&#39;]) . "<p><a href=\"" $item[&#39;link&#39;] . "\">" . $item[&#39;link&#39;] . "</a>";
    
@mysql_query("
INSERT INTO smf_topics(
ID_BOARD,
ID_MEMBER_STARTED,
ID_MEMBER_UPDATED
) VALUES (
&#39;
$boardid&#39;,
&#39;
$userid&#39;,
&#39;
$userid&#39;
)
"
,$obj_db) or die(mysql_error());
$topic mysql_insert_id();
$postertime date(&#39;U&#39;);
//Insert the actual message
    
@mysql_query("
INSERT INTO smf_messages(
subject,
body,
  ID_MEMBER,
ID_BOARD,
ID_TOPIC,
posterTime
) VALUES (
&#39;"
$titletext ."&#39;,
&#39;"
$maintext ."&#39;,
&#39;
$userid&#39;,
&#39;
$boardid&#39;,
&#39;
$topic&#39;,
&#39;
$postertime&#39;
)
"
,$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 = &#39;
$messageid&#39;, 
ID_LAST_MSG = &#39;
$messageid&#39;
WHERE ID_TOPIC = &#39;
$topic&#39;
"
,$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 = &#39;
$boardid&#39;
"
,$obj_db) or die(mysql_error());
//Increment Total Messages
    
@mysql_query("
UPDATE smf_settings
SET value = value + 1
WHERE variable = &#39;totalMessages&#39;
"
,$obj_db) or die(mysql_error());
//Increment Total Topics
    
@mysql_query("
UPDATE smf_settings
SET value = value + 1
WHERE variable = &#39;totalTopics&#39;
"
,$obj_db) or die(mysql_error());
// Increment post count for user record
    
@mysql_query("
                        UPDATE smf_members
                        SET posts = posts + 1
                                WHERE ID_MEMBER = &#39;
$userid&#39;
                "
,$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.

Offline TechnoDragon

  • Jr. Member
  • **
  • Posts: 374
  • Gender: Male
  • With great power comes great resposibility...
    • Dragon Talk Forum
Re: RSS Injector available
« Reply #51 on: March 19, 2006, 03:54:29 PM »
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!


Offline Xarcell

  • SMF Hero
  • ******
  • Posts: 1,684
  • Gender: Male
  • SMF-DP Supporter
Re: RSS Injector available
« Reply #52 on: March 19, 2006, 04:07:40 PM »
@technodragon73

What version of SMF do you have it installed on?

Offline balzizras

  • Semi-Newbie
  • *
  • Posts: 45
  • Gender: Male
    • The Michiganian
Re: RSS Injector available
« Reply #53 on: March 19, 2006, 04:51:31 PM »
I'm getting this error now :
Quote
Access 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..

Code: [Select]
<?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&#39; terms of use.  

/** the PEAR XML_RSS object/class is required */
require &#39;RSS.php&#39;;

/** 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(&#39;http://rss.news.yahoo.com/rss/topstories&#39;); //Insert your URL here
//$rss_feed = & new XML_RSS(&#39;&#39;); //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 = &#39;"
str_stop(addslashes($item[&#39;title&#39;]),100) ."&#39;
        
",$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[&#39;link_match&#39;] == 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[&#39;title&#39;]),100);
// This adds an html link at to the original article at the very bottom of the post.
$maintext = addslashes($item[&#39;description&#39;]) . "<p><a href=\"" $item[&#39;link&#39;] . "\">" . $item[&#39;link&#39;] . "</a>";
    
@mysql_query("
INSERT INTO smf_topics(
ID_BOARD,
ID_MEMBER_STARTED,
ID_MEMBER_UPDATED
) VALUES (
&#39;
$boardid&#39;,
&#39;
$userid&#39;,
&#39;
$userid&#39;
)
"
,$obj_db) or die(mysql_error());
$topic mysql_insert_id();
$postertime date(&#39;U&#39;);
//Insert the actual message
    
@mysql_query("
INSERT INTO smf_messages(
subject,
body,
 ID_MEMBER,
ID_BOARD,
ID_TOPIC,
posterTime
) VALUES (
&#39;"
$titletext ."&#39;,
&#39;"
$maintext ."&#39;,
&#39;
$userid&#39;,
&#39;
$boardid&#39;,
&#39;
$topic&#39;,
&#39;
$postertime&#39;
)
"
,$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 = &#39;
$messageid&#39;, 
ID_LAST_MSG = &#39;
$messageid&#39;
WHERE ID_TOPIC = &#39;
$topic&#39;
"
,$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 = &#39;
$boardid&#39;
"
,$obj_db) or die(mysql_error());
//Increment Total Messages
    
@mysql_query("
UPDATE smf_settings
SET value = value + 1
WHERE variable = &#39;totalMessages&#39;
"
,$obj_db) or die(mysql_error());
//Increment Total Topics
    
@mysql_query("
UPDATE smf_settings
SET value = value + 1
WHERE variable = &#39;totalTopics&#39;
"
,$obj_db) or die(mysql_error());
// Increment post count for user record
    
@mysql_query("
                        UPDATE smf_members
                        SET posts = posts + 1
                                WHERE ID_MEMBER = &#39;
$userid&#39;
                "
,$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

Offline Xarcell

  • SMF Hero
  • ******
  • Posts: 1,684
  • Gender: Male
  • SMF-DP Supporter
Re: RSS Injector available
« Reply #54 on: March 19, 2006, 05:01:12 PM »
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...


Offline Xarcell

  • SMF Hero
  • ******
  • Posts: 1,684
  • Gender: Male
  • SMF-DP Supporter
Re: RSS Injector available
« Reply #55 on: March 19, 2006, 05:03:58 PM »
Cut and paste this code and write in your DB password in the configuration.

Code: [Select]

<?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&#39; terms of use.  

/** the PEAR XML_RSS object/class is required */
require &#39;RSS.php&#39;;

/** 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(&#39;http://rss.news.yahoo.com/rss/topstories&#39;); //Insert your URL here
//$rss_feed = & new XML_RSS(&#39;&#39;); //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 = &#39;"
str_stop(addslashes($item[&#39;title&#39;]),100) ."&#39;
        
",$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[&#39;link_match&#39;] == 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[&#39;title&#39;]),100);
// This adds an html link at to the original article at the very bottom of the post.
$maintext = addslashes($item[&#39;description&#39;]) . "<p><a href=\"" $item[&#39;link&#39;] . "\">" . $item[&#39;link&#39;] . "</a>";
    
@mysql_query("
INSERT INTO smf_topics(
ID_BOARD,
ID_MEMBER_STARTED,
ID_MEMBER_UPDATED
) VALUES (
&#39;
$boardid&#39;,
&#39;
$userid&#39;,
&#39;
$userid&#39;
)
"
,$obj_db) or die(mysql_error());
$topic mysql_insert_id();
$postertime date(&#39;U&#39;);
//Insert the actual message
    
@mysql_query("
INSERT INTO smf_messages(
subject,
body,
  ID_MEMBER,
ID_BOARD,
ID_TOPIC,
posterTime
) VALUES (
&#39;"
$titletext ."&#39;,
&#39;"
$maintext ."&#39;,
&#39;
$userid&#39;,
&#39;
$boardid&#39;,
&#39;
$topic&#39;,
&#39;
$postertime&#39;
)
"
,$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 = &#39;
$messageid&#39;, 
ID_LAST_MSG = &#39;
$messageid&#39;
WHERE ID_TOPIC = &#39;
$topic&#39;
"
,$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 = &#39;
$boardid&#39;
"
,$obj_db) or die(mysql_error());
//Increment Total Messages
    
@mysql_query("
UPDATE smf_settings
SET value = value + 1
WHERE variable = &#39;totalMessages&#39;
"
,$obj_db) or die(mysql_error());
//Increment Total Topics
    
@mysql_query("
UPDATE smf_settings
SET value = value + 1
WHERE variable = &#39;totalTopics&#39;
"
,$obj_db) or die(mysql_error());
// Increment post count for user record
    
@mysql_query("
                        UPDATE smf_members
                        SET posts = posts + 1
                                WHERE ID_MEMBER = &#39;
$userid&#39;
                "
,$obj_db) or die(mysql_error());
        } 
    }

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

« Last Edit: March 19, 2006, 05:06:18 PM by Xarcell »

Offline TechnoDragon

  • Jr. Member
  • **
  • Posts: 374
  • Gender: Male
  • With great power comes great resposibility...
    • Dragon Talk Forum
Re: RSS Injector available
« Reply #56 on: March 19, 2006, 05:09:11 PM »
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!


Offline balzizras

  • Semi-Newbie
  • *
  • Posts: 45
  • Gender: Male
    • The Michiganian
Re: RSS Injector available
« Reply #57 on: March 19, 2006, 05:34:30 PM »
Cut and paste this code and write in your DB password in the configuration.

Code: [Select]

<?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&#39; terms of use.  

/** the PEAR XML_RSS object/class is required */
require &#39;RSS.php&#39;;

/** 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(&#39;http://rss.news.yahoo.com/rss/topstories&#39;); //Insert your URL here
//$rss_feed = & new XML_RSS(&#39;&#39;); //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 = &#39;"
str_stop(addslashes($item[&#39;title&#39;]),100) ."&#39;
        ",$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[&#39;link_match&#39;] == 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[&#39;title&#39;]),100);
// This adds an html link at to the original article at the very bottom of the post.
$maintext = addslashes($item[&#39;description&#39;]) . "<p><a href=\"" $item[&#39;link&#39;] . "\">" . $item[&#39;link&#39;] . "</a>";
    @mysql_query("
INSERT INTO smf_topics(
ID_BOARD,
ID_MEMBER_STARTED,
ID_MEMBER_UPDATED
) VALUES (
&#39;
$boardid&#39;,
&#39;
$userid&#39;,
&#39;
$userid&#39;
)
"
,$obj_db) or die(mysql_error());
$topic mysql_insert_id();
$postertime date(&#39;U&#39;);
//Insert the actual message
    @mysql_query("
INSERT INTO smf_messages(
subject,
body,
  ID_MEMBER,
ID_BOARD,
ID_TOPIC,
posterTime
) VALUES (
&#39;"
$titletext ."&#39;,
&#39;"
$maintext ."&#39;,
&#39;
$userid&#39;,
&#39;
$boardid&#39;,
&#39;
$topic&#39;,
&#39;
$postertime&#39;
)
"
,$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 = &#39;
$messageid&#39;, 
ID_LAST_MSG = &#39;
$messageid&#39;
WHERE ID_TOPIC = &#39;
$topic&#39;
"
,$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 = &#39;
$boardid&#39;
"
,$obj_db) or die(mysql_error());
//Increment Total Messages
    @mysql_query("
UPDATE smf_settings
SET value = value + 1
WHERE variable = &#39;totalMessages&#39;
"
,$obj_db) or die(mysql_error());
//Increment Total Topics
    @mysql_query("
UPDATE smf_settings
SET value = value + 1
WHERE variable = &#39;totalTopics&#39;
"
,$obj_db) or die(mysql_error());
// Increment post count for user record
    @mysql_query("
                        UPDATE smf_members
                        SET posts = posts + 1
                                WHERE ID_MEMBER = &#39;
$userid&#39;
                "
,$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

Offline TechnoDragon

  • Jr. Member
  • **
  • Posts: 374
  • Gender: Male
  • With great power comes great resposibility...
    • Dragon Talk Forum
Re: RSS Injector available
« Reply #58 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
Don't tell me to get into shape...I have a shape...It is round!


Offline balzizras

  • Semi-Newbie
  • *
  • Posts: 45
  • Gender: Male
    • The Michiganian
Re: RSS Injector available
« Reply #59 on: March 19, 2006, 10:43:19 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:
Code: [Select]
$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?
« Last Edit: March 20, 2006, 12:30:44 AM by balzizras »
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