News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

RSS Injector available

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

Previous topic - Next topic

Ben_S

Nicely done, herrin.

One thing I'd suggest as an enhancment though would be to use SMF's createPost function to actually post the message rather than direcly putting it into the database.
Liverpool FC Forum with 14 million+ posts.

L.G.S

Yes that's what I forgot to say, it would be nice if the posts were actually added to the overall post count / topic count.
FREE and LIVE World Cup + Premier League football streams:

www.gamesandgoals.com


herrin

Quote from: L.G.S on August 31, 2006, 01:48:48 PM
Thanks for the help,

but, I meant the post itself, not the title. The content of the post stretches the page and makes sigs unreadable.

What exactly does creating the cache directory do?

Ahhhh, you could apply the same function to the get description on this line to chop it.

$maintext = "<p>" . $item->get_date('j M Y') . "</p><p>" . addslashes($item->get_description()) . "</p><p><a href=\"" . $item->get_permalink() . "\">" . $item->get_permalink() . "</a></p>";

The simplepie caching mechanism is to make sure you aren't overloading the feed.  Like if you pull from a feed everytime a page is viewed, this will cache it and expire it so you aren't hitting the feed everytime.  For this though I don't think that's a desired feature as I assume you want to see new items everytime you run your script.

herrin

Quote from: Ben_S on August 31, 2006, 02:25:15 PM
Nicely done, herrin.

One thing I'd suggest as an enhancment though would be to use SMF's createPost function to actually post the message rather than direcly putting it into the database.

I didn't do anything I just stood on the shoulders of whoever wrote it first. :)

If you have a link to some documentation or explanation of the createPost function I would love to use that instead as there are some inconsistencies doing it with the method it's currently using.

Ben_S

#224
Not sure of any documentation but the function itself is pretty simple to use, have a look in Subs-Post.php for createPost.

Basically if you just include SSI.php in your injector file you should be able to call createPost with the required variables. Having included SSI.php, SMF should deal with connecting to the database etc.

I should add that the createPost function is 1.1x feature.

Also see http://www.simplemachines.org/community/index.php?topic=48529.msg348548#msg348548
Liverpool FC Forum with 14 million+ posts.

herrin

Quote from: Ben_S on August 31, 2006, 02:56:38 PM
Not sure of any documentation but the function itself is pretty simple to use, have a look in Subs-Post.php for createPost.

Basically if you just include SSI.php in your injector file you should be able to call createPost with the required variables. Having included SSI.php, SMF should deal with connecting to the database etc.

I should add that the createPost function is 1.1x feature.

Also see http://www.simplemachines.org/community/index.php?topic=48529.msg348548#msg348548

You the bomb in phantoms yo.  I'm 10 minutes from having it working.  I'll post it shortly, by the way, using that function works MUCH better!

TLM

#226
http://www.mindlesstux.com/rss_injector.phps
http://www.mindlesstux.com/rss_injector.sql

For those that like what I have done with mine.  You will need to get MagpieRSS and extract it to a MagpieRSS directory in your forum dir.  Then simply load the sql into the same table with your forum, and edit the feeds, I think the fields are self explanitory.  I am not going to make this into a mod, someone can if they like, but I dont have time to make a admin panel like I had before the hd crash.

Quote from: Ben_S on August 31, 2006, 02:56:38 PM
Basically if you just include SSI.php in your injector file you should be able to call createPost with the required variables. Having included SSI.php, SMF should deal with connecting to the database etc.
I think you have to include Subs-Post.php as well for it to work.  Or at least for me I did.

L.G.S

Hey herrin, your script is seriously screwin my pages up lol.

Check here:

http://www.ruthlessintent.com/board/index.php?topic=8930.0

Login with: JTCM
Password: helper
FREE and LIVE World Cup + Premier League football streams:

www.gamesandgoals.com


herrin

New version using a safer native SMF function. createPost()

Apparently this only works in SMF 1.1.

USE AT YOUR OWN RISK.  IT COULD SCREW UP YOUR FORUM.  IT WORKS FINE FOR ME, BUT THAT MEANS NOTHING. I CAN'T HELP YOU IF IT SCREWS UP YOUR FORUM.

<?php
/*
SMF FEED / RSS INJECTOR by Shawn Herrin - [email protected]

This script will grab a feed or even autodetect feeds and inject them into the
SMF forum of your choice.

This script is based on the great work done by:
- SMF RSS Injector by Jerry Bell - [email protected]

** I don't know whether this is secure or unsafe or what.  I don't support it 
it's a quick hack to get a feature I need.  It could hose your SMF db.  Who knows.
Use with caution and at your own risk.
*/

error_reporting(E_ALL);

require(
"./includes/simplepie/simplepie.inc");
// these need the full path to your SMF files
require_once('/home/user/public_html/forum/SSI.php');
require_once(
'/home/user/public_html/forum/Sources/Subs-Post.php');

/** DATABASE Configuration */
define("DB_HOSTNAME","localhost"); //Insert your DB server name here
define("DB_USERNAME",""); //DB username here
define("DB_PASSWD","*"); // DB password here
define("DB_DATABASE",""); //DB name here

// initialize variables ** Don't touch these.
$sSql  "";
$aryMsgOptions = Array();
$aryTopicOptions = Array();
$aryPosterOptions = Array();

// set variables ** Modify these to match your board
$iUserId  0 // Set this to the SMF userid you want the messages posted from
$iBoardId  0; // Set this to the id of the board you want to post the messages in
$sRealName  ""; // **Not quite sure - I believe this allows you to override the realname of the $iUserId specified
$sEmailAddr  ""; // **Not quite sure - I believe this allows you to override the email address of the $iUserId specified
$iMarkAsRead TRUE// Set this either true or false This defines whether the injected posts are marked as read.
$iUpdatePostCount TRUE;// Set this to either true or false.  This defines whether to include the injected items in your post counts.
$sFeedUrl  "http://yourfeed.com/rss"// This is the feed to fetch.
$iMaxItemsToRetrieve 5// This is the max number of feed items to retreive.
// Instantiate SimplePie object
$feed = new SimplePie();

$feed->feed_url($sFeedUrl);

$feed->enable_caching(false);

$feed->init();

$feed->handle_content_type();

$obj_db mysql_connect(DB_HOSTNAME,DB_USERNAME,DB_PASSWD) or die (mysql_error());
mysql_select_db(DB_DATABASE,$obj_db) or die (mysql_error());

if (
$feed->data
{    
$max $feed->get_item_quantity($iMaxItemsToRetrieve);
for ($x 0$x $max$x++) 
    {
    
$item $feed->get_item($x);
        
// This is a simple check to make sure that the item doesn't already exist in your SMF.
    
$sSql "SELECT
                COUNT(ID_MSG) AS ENTRY_EXISTS
             FROM smf_messages 
             WHERE subject = '"
addslashes($item->get_title()) ."'";
        
    
$obj_query mysql_query($sSql$obj_db) or die(mysql_error());

        
$int_count mysql_fetch_assoc($obj_query) or die(mysql_error());

        
mysql_free_result($obj_query);
        
        
// If it's a new item, insert it!
        
if ($int_count['ENTRY_EXISTS'] == 0
        { 
$sItemTitle addslashes($item->get_title());
//$sItemTitle = smart_trim(addslashes($item->get_title()), 50, false, "...");

$sItemBody "<p>" $item->get_date('j M Y') . "</p><p>" addslashes($item->get_description()) . "</p><p><a href=\"" $item->get_permalink() . "\">" $item->get_permalink() . "</a></p>";
 
        
// Setup the variables for creatPost()
$aryTopicOptions = array
(
        'id' => 0,
        'board' => $iBoardId,
        'mark_as_read' => $iMarkAsRead,
);

$aryPosterOptions = array
(
        'id' => $iUserId,
        'name' => $sRealName,
        'email' => $sEmailAddr,
        'ip' => '127.0.0.1',
        'update_post_count' => $iUpdatePostCount,
);

$aryMsgOptions = array
(
        'id' => 0,
        'subject' => $sItemTitle,
        'body' => $sItemBody,
);  
      
        
echo("*******************************************************************<br />\r\n");
echo("title: " $sItemTitle "<br />\r\n");
        
echo("*******************************************************************<br />\r\n");
        

        
createPost($aryMsgOptions$aryTopicOptions$aryPosterOptions);
        }
        else 
        {
        
echo("There is already a match<br />\r\n");
        } 
    }
}

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



L.G.S

Do I need any rss.php extra files?

edit: nevermind I got it thanks
FREE and LIVE World Cup + Premier League football streams:

www.gamesandgoals.com


herrin

Quote from: L.G.S on August 31, 2006, 03:57:15 PM
Hey herrin, your script is seriously screwin my pages up lol.

Check here:

hxxp:www.ruthlessintent.com/board/index.php?topic=8930.0 [nonactive]

Login with: JTCM
Password: helper

That sucks, try the new one, otherwise, not sure what's causing it.  My guess is the formatting from the feed.  Don't know, mine works fine so far.

herrin

Now that TLM is back, I won't be updating mine anymore.  I wasn't trying to step on you, just hadn't seen any working versions and wanted to post for anyone who needed one.

haktanir2

TLM could you give more information about the editing parts?

So I've sent the Magpie folder, but do I need any other files? It talks of SSI.php and some other stuff.

And where do I enter the username, password, feed URL, etc?

L.G.S

Quote from: herrin on August 31, 2006, 04:04:02 PM
Quote from: L.G.S on August 31, 2006, 03:57:15 PM
Hey herrin, your script is seriously screwin my pages up lol.

Check here:

http://www.ruthlessintent.com/board/index.php?topic=8930.0

Login with: JTCM
Password: helper

That sucks, try the new one, otherwise, not sure what's causing it.  My guess is the formatting from the feed.  Don't know, mine works fine so far.

Yeah same with the new one, it causes the bg colours to mess up and everything
FREE and LIVE World Cup + Premier League football streams:

www.gamesandgoals.com


vbgamer45

The RSS mod is one of the ones I am really looking forward to. Just to use to make the forum look more active and to give topics for people to comment on.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

TLM

#235
Quote from: herrin on August 31, 2006, 04:05:50 PM
Now that TLM is back, I won't be updating mine anymore.  I wasn't trying to step on you, just hadn't seen any working versions and wanted to post for anyone who needed one.
No big deal, I wanted to make a whole mod on this one, I have several ideas but its looking like I wont have time.  I figured I better release what I got, seeing how it seems to be the better so far, for supporting multiple feeds/posters/boards.

Quote from: haktanir2 on August 31, 2006, 04:10:52 PM
TLM could you give more information about the editing parts?

So I've sent the Magpie folder, but do I need any other files? It talks of SSI.php and some other stuff.

And where do I enter the username, password, feed URL, etc?

(assuming your forum is at /forum)
1. copy the .phps code into a text file, save as a .php and place in /forum
2. dload magpierss, and place everything in it at /forum/MagpieRSS
3. dload the sql file, and use something like phpmyadmin to load the table into the forum database
4. go back to the table you just now imported and the feilds are rather descriptive in themselves.  Just add rows with the desired information.
5. Make a cronjob or what ever to run the script, eg in linux,
0 */4 * * * php /homedirectory/forums/rss_injector.php
would run the script every 4 hours.  Note you will have to alter your path to the script as needed.
6. Enjoy hopefully.

If I ever have time that are not involved with life, priorities are to finsh the google maps mod then finsh this one.  Although I would not mind if someone made this into a mod using my code, as long as they credited me for what is due.

Ben_S

Looks good TLM, I'll probably make use of yours in a couple of weeks when I'm back from holiday.
Liverpool FC Forum with 14 million+ posts.

TLM

Quote from: Ben_S on August 31, 2006, 04:26:04 PM
Looks good TLM, I'll probably make use of yours in a couple of weeks when I'm back from holiday.
Hehe, no prob there, have a beer for me too. (The holiday is bday for me, and I dont plan on celerbrating it, but rather reading about 60 pages of small print books for one class)

o_1281

I thin I have TLM mods implemented, how can I check to see if its working correctly?

TLM

Load the rss_injector.php and if you get nothing back, should have.  Then go check the forum.  Or wait till the server hits one of the 4th hour points (if thats what you set it up as).

Advertisement: