• Welcome to Simple Machines Community Forum. Please login or sign up.
December 04, 2021, 05:19:20 PM

News:

SMF 2.1 RC4 has been released! Try it out and help us test! :) Read more.


RSS Feed Poster

Started by SMFHacks.com Team, January 11, 2007, 07:46:04 PM

Previous topic - Next topic

genix

November 29, 2008, 07:21:04 AM #1140 Last Edit: November 29, 2008, 07:26:13 AM by genix
Fuf, guys, I've read all this topis and didn't found any solution for problem with XML error. And I decided to solve it by myself. So, here is my story:

First off all, the problem is in XML-reading, so it is in file Subs-RSS.php. We need the function with name 'UpdateRSSFeedBots()'.

Find there xml_set_element_handler($xml_parser, "startElement1", "endElement1");
and add BEFORE this:
$feeddata = iconv('RSS-CHARSET', 'UTF-8', $feeddata);
$feeddata = str_replace('´',' ',$feeddata);

but RSS-CHARSET replace with charset of your RSS-feed (for me it was cp1251, I'm Russian).

And one more:
Find // Error reading xml data
And add AFTER
echo "<br>XML Error: ";
        echo xml_error_string(xml_get_error_code($xml_parser));
        echo " at line ".xml_get_current_line_number($xml_parser)."<br>";
echo "<br>Data:<br>".$feeddata."<br><br>";


Now I will explain why I did so. I converted data from RSS to UTF-8 because xml-parser doesn't work good with my charset. So, when I converted it, it was better.
But second line I wrote, because XML-parser again said me about an error and it was some character '&acute;'. I really don't know what is it, that's why I replaced it with a space.

And what about second block - it's only addition to make file cronrss.php speak a little bit about xml-errors =).

Oh, one more thing - you should also use this code modification to get back your charset:
// Create the Post
$msg_title_ = $func['htmlspecialchars'](($feed['html'] ? $context['feeditems'][$i]['title'] : strip_tags($context['feeditems'][$i]['title'])), ENT_QUOTES);
$msg_title = iconv("UTF-8", "YOUR-CHARSET", $msg_title_);  //// NEW added Code

                     
$msg_body =  $func['htmlspecialchars'](($feed['html'] ? $context['feeditems'][$i]['description'] . "\n\n" . $context['feeditems'][$i]['link']  : strip_tags($context['feeditems'][$i]['description'] .  "\n\n" . $context['feeditems'][$i]['link'])), ENT_QUOTES);
$msg_body = iconv("UTF-8", "YOUR-CHARSET", $msg_body);  //// NEW added Code 

Where YOUR-CHARSET is your forum charset =)

Sorry if my post is not so beatiful, ask me if you have any troubles with that ;)
- All that don't kill me can only make me stronger - F.Nicshe, Karandash, Kanye West

Sabre™

November 29, 2008, 03:37:54 PM #1141 Last Edit: November 29, 2008, 03:41:41 PM by Sabre™
Hi mate,
your explanation was very good, and Im in the process of attempting/testing this, but I am not literate in many things.
So my question is what is a  charset ?
I initially thought it was the amount of characters added or something, but Im guessing Im wrong.
How would I know what my charset is?
Is it   feed.poster.english  So the language template is the charset??


Thank You in advance for sharing your knowledge :)
Do NOT give admin and/or ftp details to just anybody, see if they are trust worthy first!!  Do your homework ;)


genix

Charset is a collection of different symbols wich can be printed on your screen. It is something like coding different letters... Maybe you understand if I tell some names of charsets:
UTF-8 (Unicode)
cp1251 (Cyrillic)
ISO-8859-1 (WestEuropean)

You could know what charset you have from HTML code of the page:
...
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
...


As you see, there is UTF-8 charset in this forum page, but your RSS-feed can be another. Look at the HTML-code of it to know that =)
- All that don't kill me can only make me stronger - F.Nicshe, Karandash, Kanye West

Sabre™

Ahhh  thanks for that mate!
Thats why I enjoy coming here, there hasn't been a day when I haven't learnt something new.

Thanks once again genix :)

So where your code has every instant of UTF8, since nothing on my site is UTF8, should I remove that?
So the code would go from
$feeddata = iconv('ISO-8859-1', 'UTF-8', $feeddata);

TO
$feeddata = iconv('ISO-8859-1', $feeddata);

??
Do NOT give admin and/or ftp details to just anybody, see if they are trust worthy first!!  Do your homework ;)


Smoky "Rider" Blue

for text languages, here is something for you to "cut your teeth on" Sabre:

http://www.blooberry.com/indexdot/html/tagpages/text.htm

interesting reading.. and yes thanks genix ;)
**Take the time to remember friendships and family.. Sometimes it's all we have, and missed very much**

genix

This function "iconv" takes only three arguments, so if you remove something it will not work =). And you maybe don't understand the reason of using that function - it is to convert text from one charset to another (to UTF-8), because text in your charset couldn't be parsed.

So, for you (if your charset is ISO-8859-1) this line will be just
$feeddata = iconv('ISO-8859-1', 'UTF-8', $feeddata);

And in the another code-block you should the same replace only "YOUR-CHARSET" with "ISO-8859-1" and not delete anything else =)
- All that don't kill me can only make me stronger - F.Nicshe, Karandash, Kanye West

Sabre™

November 30, 2008, 03:48:39 AM #1146 Last Edit: November 30, 2008, 04:03:21 AM by Sabre™
Awesome!!

Thank You mate.

I tried both ways of doing it, and you are right, once I deleted the UTF8, it nolonger worked.

I will post back later to update you on the functionality of your code.

Looking into this code also made me see what I had to do to get the  <html>  function to work.
*slaps his own head at the simple solution
lol ;)

For those that may have missed it, in your Subs-RSS.php  in your sources folder, you will see this code
/* if ($feed['html'])
{
$msg_body = '[html]' . $msg_body . '[/html]';
preparsecode($msg_body);
} */


remove the  /*  and   */   so now the code is read, and looks like this
if ($feed['html'])
{
$msg_body = '[html]' . $msg_body . '[/html]';
preparsecode($msg_body);
}

All images etc are showing perfect!!    All html code is functioning as it should
Do NOT give admin and/or ftp details to just anybody, see if they are trust worthy first!!  Do your homework ;)


vbgamer45

Quote from: Sabre™ on November 30, 2008, 03:48:39 AM
Awesome!!

Thank You mate.

I tried both ways of doing it, and you are right, once I deleted the UTF8, it nolonger worked.

I will post back later to update you on the functionality of your code.

Looking into this code also made me see what I had to do to get the  <html>  function to work.
*slaps his own head at the simple solution
lol ;)

For those that may have missed it, in your Subs-RSS.php  in your sources folder, you will see this code
/* if ($feed['html'])
{
$msg_body = '[html]' . $msg_body . '[/html]';
preparsecode($msg_body);
} */


remove the  /*  and   */   so now the code is read, and looks like this
if ($feed['html'])
{
$msg_body = '[html]' . $msg_body . '[/html]';
preparsecode($msg_body);
}

All images etc are showing perfect!!    All html code is functioning as it should
I could swear I tried that and it did not work for me thats why I commented it out. Maybe I forgot another reason.
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

Garou

VB nice to see you posting here again. :)

Sabre™

Quote from: vbgamer45 on November 30, 2008, 03:47:33 PM
I could swear I tried that and it did not work for me thats why I commented it out. Maybe I forgot another reason.

Yeah mate.
I only uncommented that area after doing genix edits, and was in shock when I saw it actually now adds the  [html ]  tags lol

Maybe look over his edits bud.

I know you havent been far, just busy like everyone else ;)
Congrats on the new/latest release of your portal also.
Do NOT give admin and/or ftp details to just anybody, see if they are trust worthy first!!  Do your homework ;)


Smoky "Rider" Blue

yeah im glad he is taking to posting on this thread as well..

perhaps now, he would like to support his mod here, if im not mistaken''

no, im not "mad" over this, i have something in the works as well, but i have just had a death in my family, and the funeral is tomorrow. so hopefully if there is anything else, he can provide the support needed for his mod.

i would have taken it, but he didnt ever say yes.. its not nice to assume control over a mod that the mod author hasnt relinquished.  ;)
**Take the time to remember friendships and family.. Sometimes it's all we have, and missed very much**

sshagent

nice to see you about vbgamer.

any chance you can offer some advice or point me in the right direction at least.  I'm getting ( and others i believe ) double  or sometimes triple posts. 

presumably somewhere in the code either my server isn't noticing the feeds are duplicates, or some bug type issue.  Anyway any assistnace would be massively appreciated. 

thanks in advance.

smoky, i'll keep an eye out for your work :D

genix

December 01, 2008, 01:46:04 PM #1152 Last Edit: December 01, 2008, 01:52:19 PM by genix
Hey guys, maybe you'll find interesting what I did with this mod.

I use this mod to copy news about my town from another news-site. There are many news about different events, but I need news only about my town. So, I wrote a small filter to stop publishing themes which I'm not interested in.
And also most RSS-feeds offer you only small news-text and if you want more you should follow the link to their site. But it is not comfortable for me to make a link-garbage from my forum. So, I wrote small addition that copies all the news-text from the link and posts to my forum. But to use that you need to know tags-brackets inside those is the text you need. Always it is something like .......<span class="news-text">TEXT_WHAT_YOU_NEED</span>.......
So, here is my added code:
Find

$msgOptions = array(
'id' => 0,
'subject' => $feed['topicprefix'] . $msg_title,
'body' => '[b]' . $msg_title . "[/b]\n\n" . $msg_body,
'icon' => 'xx',
'smileys_enabled' => 1,
'attachments' => array(),
);
$topicOptions = array(
'id' => 0,
'board' => $feed['ID_BOARD'],
'poll' => null,
'lock_mode' => $feed['locked'],
'sticky_mode' => null,
'mark_as_read' => true,
);
$posterOptions = array(
'id' => $feed['ID_MEMBER'],
'name' => $feed['postername'],
'email' => '',
'update_post_count' => (($feed['ID_MEMBER'] == 0) ? 0 : 1),
);

createPost($msgOptions, $topicOptions, $posterOptions);

And REPLACE with this if you want =)

// Add news only if words exist inside
if(strpos($msg_body,'SOMETHING_HERE')||strpos($msg_body, 'OR_SMTH_HERE'))
{
echo "<br>Link: ".$context['feeditems'][$i]['link']."<br>";
$curl = curl_init($context['feeditems'][$i]['link']);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, true);
$contents = '';
$contents = curl_exec ($curl);
curl_close($curl);

if ($contents!='')
{
echo "File opened<br>";
}
else echo "not opened<br>";

$fullbody = explode('<span class="news-text">', $contents);
$fullbody2 = explode('</span>',$fullbody[1]);
$msg_body = $fullbody2[0];
echo "<hr>".$msg_body."<hr>";


$msgOptions = array(
'id' => 0,
'subject' => $feed['topicprefix'] . $msg_title,
'body' => '[b]' . $msg_title . "[/b]\n\n" . $msg_body,
'icon' => 'xx',
'smileys_enabled' => 1,
'attachments' => array(),
);
$topicOptions = array(
'id' => 0,
'board' => $feed['ID_BOARD'],
'poll' => null,
'lock_mode' => $feed['locked'],
'sticky_mode' => null,
'mark_as_read' => true,
);
$posterOptions = array(
'id' => $feed['ID_MEMBER'],
'name' => $feed['postername'],
'email' => '',
'update_post_count' => (($feed['ID_MEMBER'] == 0) ? 0 : 1),
);

createPost($msgOptions, $topicOptions, $posterOptions);
}


So, now I need only to delete what I don't need and so on =)
- All that don't kill me can only make me stronger - F.Nicshe, Karandash, Kanye West

TheDisturbedOne

Do I need to run a cron for this?
I haven't seen anything in the few pages of this topic that I looked in.

Sabre™

genix

You sir are a breath of fresh air, and Im happy you share your edits :)
Your ideas are that of which I have had similar thought.

With the above code, does it follow the link to the full story, and print the whole thing?

Where your code has
if(strpos($msg_body,'SOMETHING_HERE')

would mine would be ?
if(strpos($msg_body,'martial_art')

For multiple words, do we separate with   _    ?
eg...
if(strpos($msg_body,'martial_art_kung_fu_aikido')

Cheers
Do NOT give admin and/or ftp details to just anybody, see if they are trust worthy first!!  Do your homework ;)


Garou

Smoky, I'm sorry for your loss. :(
As for the Mod you put a lot of work into this as well as your own. I still hope you release, you put too much effort into it not too. Ill be keeping an eye out for your mods and themes.

TheDisturbedOne, I haven't had a chance to try out the latest version of the mod so I don't know if the fake cron is working or not. VB hasn't mentioned so I plan to test it out sometime this week.

genix that is an awesome idea you have there Ill have to try that out. That and the HTML fix you posted earlier just might help me with some of the feeds I use that don't post correctly.

Smoky "Rider" Blue

thanks Garou, im swamped with family and half i didnt even know of.

as for my mod, it will be released soon after the holidays as its begining to look like this "party" at my house wont end.

i do appreciate everyone's interest and help with this mod and i would like to see it grow.. till then lol keep pluging away and i will try my best to have something decent if not for the beta/rc..  ;)
**Take the time to remember friendships and family.. Sometimes it's all we have, and missed very much**

genix

December 01, 2008, 11:53:10 PM #1157 Last Edit: December 02, 2008, 12:26:34 AM by genix
Smoky, I sympathize you with your loss in family.

Quote from: Sabre™ on December 01, 2008, 06:28:22 PM
With the above code, does it follow the link to the full story, and print the whole thing?
Hmm yep, it will follow the link wich in $context['feeditems'][$i]['link'] and copy all the text from tag <span class="news-text"> to the tag </span>. Look to the HTML code of your full page to know which tags you should put there. If you have trouble with this, give me a link I will explain)

Quote from: Sabre™ on December 01, 2008, 06:28:22 PM
Where your code has
if(strpos($msg_body,'SOMETHING_HERE')

would mine would be ?
if(strpos($msg_body,'martial_art')

For multiple words, do we separate with   _    ?
eg...
if(strpos($msg_body,'martial_art_kung_fu_aikido')
No, the text should be the same as it in the news-text. So, if it is spoken about martial art, I think it will be just 'martial art' separated the same as in the text - with spaces.
But if you wnat to be posted news about kung fu and martial art, you should write smth like
if(strpos($msg_body,'martial art')||strpos($msg_body, 'kung-fu'))
- All that don't kill me can only make me stronger - F.Nicshe, Karandash, Kanye West

TheDisturbedOne

Quote from: Garou on December 01, 2008, 09:51:42 PM
Smoky, I'm sorry for your loss. :(
As for the Mod you put a lot of work into this as well as your own. I still hope you release, you put too much effort into it not too. Ill be keeping an eye out for your mods and themes.

TheDisturbedOne, I haven't had a chance to try out the latest version of the mod so I don't know if the fake cron is working or not. VB hasn't mentioned so I plan to test it out sometime this week.

genix that is an awesome idea you have there Ill have to try that out. That and the HTML fix you posted earlier just might help me with some of the feeds I use that don't post correctly.
How would I set up a real cron though, if the fake cron may not work.

genix

Quote from: TheDisturbedOne on December 02, 2008, 03:26:05 PM
How would I set up a real cron though, if the fake cron may not work.
You can set it up in your cpanel. In this topic were many issues about that, use search , maybe? =)
- All that don't kill me can only make me stronger - F.Nicshe, Karandash, Kanye West

Advertisement: