News:

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

Main Menu

RSS Feed Poster help...

Started by L.G.S, January 28, 2007, 11:49:54 AM

Previous topic - Next topic

L.G.S

Tried asking for help in the mod thread but the creator has no idea why his mod is making this error, so I'm asking here.

I get this error every time a page is accessed..

Notice: Undefined offset: 9 in /home/tscar/public_html/board/Sources/Subs-RSS.php on line 234

Clogs up my error log around 25,000 pages a day and it's starting to become annoying.

What's causing it and how can I fix it?
FREE and LIVE World Cup + Premier League football streams:

www.gamesandgoals.com


KGIII

Can you attach a copy of the Subs-RSS.php? I haven't used that particular mod yet, I did mine manually, but if you attach the code someone might be able to figure it out.

My PC Support Forum
Please ask in-thread before PMing
                   SMF Help
                   Visit My Blog

How can we improve the support process?:
http://www.simplemachines.org/community/index.php?topic=163533.0

SMF vs. Godzilla? Who do you think will win?

L.G.S

Ok... I looked myself and the line is blank but it wouldn't be happening if there wasn't a problem....
FREE and LIVE World Cup + Premier League football streams:

www.gamesandgoals.com


samyot

Hi,

I am getting the same errors in my logs except the line is 235 which has:

$itemhash = md5($context['feeditems'][$i]['title'] . $context['feeditems'][$i]['description']);

I suspect perhaps there are some blank entries being feed which is causing the Undefined offset

For testing purposes, I replaced the line with $itemhash = md5("testing"); and the error goes away but since the itemhash value is always the same, feeds are not imported.

Looking at the smf_feedbot_log table, which is where this value is inserted, I can see that all the md5 hash entries are unique.

Is there a way to change this line to hash different values without using:
$context['feeditems'][$i]['title'] . $context['feeditems'][$i]['description']

KGIII

Hmm... All that says is "hacking attempt." I don't really have an answer then but I do potentially have a work-around.

It is a little more complicated but not so hard really. I have had good luck with this one:

RSS Injector available:
http://www.simplemachines.org/community/index.php?topic=62121.0;topicseen

Basically you just make a folder called includes in the root forum directory, put the simplepie file in there, and add the rss files and call them via CRON job. It takes only a couple of minutes.

(I didn't do the one with the whole MySQL addition. I did see your posts where that one had messed up your site though.)

?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/username/public_html/forum/SSI.php');
require_once('/home/username/public_html/forum/Sources/Subs-Post.php');

/** DATABASE Configuration */
define("DB_HOSTNAME","localhost"); //Insert your DB server name here
define("DB_USERNAME","db_user"); //DB username here
define("DB_PASSWD","db_pass"); // DB password here
define("DB_DATABASE","db_name"); //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 = 1; // Set this to the SMF userid you want the messages posted from
$iBoardId = 3.0; // Set this to the id of the board you want to post the messages in
$sRealName = "Sec Watch"; // **Not quite sure - I believe this allows you to override the realname of the $iUserId specified
$sEmailAddr = "[email protected]"; // **Not quite sure - I believe this allows you to override the email address of the $iUserId specified
$iMarkAsRead = FALSE; // 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://backend.secwatch.org/be-advisories.rss"; // This is the feed to fetch.
$iMaxItemsToRetrieve = 10; // 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);
}
?>


I edited the obvious out. I then created CRON jobs, let's say that one was named securitywatch.php (I left in some sample addresses and paths) and those look like:


php -q -f /home/username/public_html/forum/securitywatch.php


And set the schedule. Most web hosting control panels have a nice handy interface for making it pretty easy. The file will need to be CHMODed to 755. If not then it isn't too difficult to find the information online.

Now what this does is it schedules the PHP file to run. This file runs, grabs the RSS feed, passes it through the simplepie.inc file, inserts it into your database, and the post appears just as a normal post - meaning that there aren't any ways that it /should/ be able to mess up your forum. (I put the PHP files that are called by the CRON job right in the root directory.)

The copy of simplepie.inc that I am using is located here:
http://kgiii.info/ignore/simplepie.zip

If you click the link in my signature you will see the news section of the board - the one with all sorts of posts - and that is in working. No MySQL changes, no messing up anything, etc. That is it in use, I don't actually go out and make those posts. (The output depends on what the feed gives you, some of mine just give links though. There is at least one stickied one though - it was pulled in from my own WordPress blog - and it came through with images and everything already intact and linked properly. I was impressed and decided that, when the mod came out, I wasn't going to bother changing it.)

Anyhow, I figured that if I couldn't answer your question directly I would answer it in a way that hopefully explained how it worked and gave you another option. Here's a good example post:

http://forum.kgiii.info/index.php?topic=685.msg2412#msg2412

This is a pretty basic post result:
http://forum.kgiii.info/index.php?topic=971.0

I am sorry that I am unable to directly answer your question with the information at hand but, hopefully, I presented a way to have an alternative. You can set up multiple files, multiple CRON jobs, and varied schedules. It is really light on server resources as it is opening just a couple of files and takes just a couple of seconds to complete.

My PC Support Forum
Please ask in-thread before PMing
                   SMF Help
                   Visit My Blog

How can we improve the support process?:
http://www.simplemachines.org/community/index.php?topic=163533.0

SMF vs. Godzilla? Who do you think will win?

samyot

Hi KGIII,

I have switched to using the RSS Injector from http://www.veign.com/vrc_codeview.asp?type=web&id=47 because it allows multiple feeds to be inserted into different forums.

Thanks for the help!

KGIII

Thanks for letting us know what works for you - in my case I just made multiple files and can insert them into multiple places. I regret that I don't have an answer as to what might make the one that is a sanctioned modification work properly.

My PC Support Forum
Please ask in-thread before PMing
                   SMF Help
                   Visit My Blog

How can we improve the support process?:
http://www.simplemachines.org/community/index.php?topic=163533.0

SMF vs. Godzilla? Who do you think will win?

SleePy

Try This and see if the error stops.

Find:
// Check feed Log
// Generate the hash for the log
$itemhash = md5($context['feeditems'][$i]['title'] . $context['feeditems'][$i]['description']);


Add before:

if(!isset($context['feeditems'][$i]['title']) || !isset($context['feeditems'][$i]['description']) || !isset($context['feeditems'][$i]['link']))
continue;


See if that will stop the errors and what occurs.
Jeremy D ~ Site Team / SMF Developer ~ GitHub Profile ~ Join us on IRC @ Libera.chat/#smf ~ Support the SMF Support team!

L.G.S

FREE and LIVE World Cup + Premier League football streams:

www.gamesandgoals.com


KGIII

Quote from: L.G.S on January 29, 2007, 04:57:44 PM
Excellent Sleepy, no errors!!

(When in doubt sneak into chat and poke him. He's skilled. *chuckles* He's got more PHP skills in his pinky than I have in a collection of books.)

My PC Support Forum
Please ask in-thread before PMing
                   SMF Help
                   Visit My Blog

How can we improve the support process?:
http://www.simplemachines.org/community/index.php?topic=163533.0

SMF vs. Godzilla? Who do you think will win?

samyot

Hi SleePy,

Thanks for the fix! I went back to this MOD and all is working fine!

Cheers

Advertisement: