I had a hard time getting this to work with PHP5 php 5.0.4
This makes a difference, I think. I have php4 compatibility mode turned ON in my php.ini:
zend.ze1_compatibility_mode = On
Three problems I've had:
1) Just didn't work out of the box. The way php5 handles/decides reference when passing objects to functions is different with php5. Did a little reading on the PHP documentation and came up with this fix:
in "mods/netclectic/find_input/includes/functions_news.php"
- $rss_parser = new rssParser();
+ $rss_parser = & new rssParser();
and in mods/netclectic/find_input/includes/rss_parser.php
- xml_set_object($this->_xml_parser,&$this);
+ xml_set_object($this->_xml_parser,$this);
... phew, now we're php5 compatible!
2) Second problem was with receiving RSS feeds with non-standard characters (out of the 20-127 range). The XML parser would choke. Since this doesn't occur very often, and I don't care if we lose a character or two, I changed the way we read in the XML:
First, the old way:
(inside mods/netclectic/find_input/includes/rss_parser.php)
Code: Select all
// retrieve the data from the given url
if ($this->_fp = @fopen($RSS_URL,'r'))
{
// read the file into our data in 4k chunks
while ($data = fread($this->_fp, 4096))
{
// parse our xml data until we find the end of our file
xml_parse($this->_xml_parser, $data, feof($this->_fp))
or die(sprintf('XML error: %s at line %d',
xml_error_string(xml_get_error_code($this->_xml_parser)),
xml_get_current_line_number($this->_xml_parser)));
$result = true;
}
}
CHANGED TO:
Code: Select all
if ($this->_fp = @fopen($RSS_URL,'r'))
{
while ( $line = fread($this->_fp, 4096))
$data .= $line;
# Fixes a bug with xml parsing non-standard ascii characters:
$data = preg_replace("/[^ -~\n]/", "", $data);
// parse our xml data until we find the end of our file
xml_parse($this->_xml_parser, $data, true)
or die(sprintf('XML error: %s at line %d',
xml_error_string(xml_get_error_code($this->_xml_parser)),
xml_get_current_line_number($this->_xml_parser)));
$result = true;
}
What changed is: instead of reading the RSS XML stream directly into the XML parser, I fetch the entire contents of the XML first, then I can preg_replace the bad characters out, then feed the resulting text to the parser.
3) My third problem was that each time I would fetch the RSS feed, it would create a new post, regardless of whether there was already a post there or not. Is there really nothing in this mod to prevent multiple posts?
I took care of this problem by adding this (in just the right spot) to mods/netclectic/includes/functions_insert_post.php:
Code: Select all
#PREVENT DUPLICATE POSTS:
$sql = "SELECT post_id FROM ". POSTS_TEXT_TABLE . " WHERE post_subject LIKE '$subject'";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
if ( $row['post_id'] )
return false;
I have the patch of all my changes available here:
http://www.modphp.org/src/find_input_1_ ... dups.patch
You can see my bulletin board with this mod applied, in action, here:
http://www.modphp.org/