Import RSS news to the blog

Creating and modifying plugins.
smartcard
Regular
Posts: 14
Joined: Sat Jan 08, 2005 12:47 pm

Import RSS news to the blog

Post by smartcard »

I tried from "Admin -> Import data -> Generic RSS Import" to import news from external RSS news feeds, and it is working fine by creating every news as a new entry (this is what I want).

I need to use this feature regularly. Is there a way I can put this function in the cron job?

The entries make by this function is not putting the original URL of the news in the body, How can I modify the script to insert the original news URL to the body?

Thank you,
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Import RSS news to the blog

Post by garvinhicking »

Hi!

What you seem to want to use is not the Generic RSS import, but the "Aggregator plugin", which can be set by a cronjob. Have a look and download it from spartacus.s9y.org.

That plugin also contains a template patch for using the original URL of a posting.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
smartcard
Regular
Posts: 14
Joined: Sat Jan 08, 2005 12:47 pm

Post by smartcard »

Thanks for that. This is what I exactly want.

Please tell me how can I apply the theme-patch.diff file?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

The .diff file just lists lines that are removed frmo the original template with a "-" prefix, and lines added to that with a "+" prefix. So you could manually apply the changes.

There are alsu GNU Patchutils / Diffutils out there, which you might want to google up.

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
smartcard
Regular
Posts: 14
Joined: Sat Jan 08, 2005 12:47 pm

Post by smartcard »

Sorry, I am not that smart enough to edit these files looking at the theme-patch.diff

Can some of you please show give me your edited .tpl files / codes
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Sure, here is the patched entries.tpl file, using the "templates/default/entries.tpl" as the source:

http://nopaste.php-q.net/214886

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
smartcard
Regular
Posts: 14
Joined: Sat Jan 08, 2005 12:47 pm

Post by smartcard »

Thank you very much for that codes. It works fine for me.

I need the following points to be fixed before I go live with my site:

1) I need to put the Original URL ($entry.properties.ep_aggregator_articleurl) to the post content

2) I want the Aggregated posts to be in the draft mode (not published)

How can I do these?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

1.) Then just move that variable to wherever you need it inside the entries.tpl file. Search for $entry.body and put it next to it?

2.) That is not possible with the current plugin. Why do you want that? Then you would need to approve every single article, you know that?

To patch this you would need to edit the serendipity_event_aggregator.php file and search for :

Code: Select all

                $entry = array('id'             => $ep_id,
                               'title'          => $item['title'],
                               'timestamp'      => $item['date'],
                               'extended'       => '',
                               'isdraft'        => 'false',
                               'allow_comments' => 'false',
                               'categories'     => $feed['categoryids'],
                               'author'         => $feed['feedname'],
                               'authorid'       => $feed_authorid);

Just replace that "false" near "isdraft" with "true":

Code: Select all

                $entry = array('id'             => $ep_id,
                               'title'          => $item['title'],
                               'timestamp'      => $item['date'],
                               'extended'       => '',
                               'isdraft'        => 'true',
                               'allow_comments' => 'false',
                               'categories'     => $feed['categoryids'],
                               'author'         => $feed['feedname'],
                               'authorid'       => $feed_authorid);

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
smartcard
Regular
Posts: 14
Joined: Sat Jan 08, 2005 12:47 pm

Post by smartcard »

Thanks for the help. Both works fine, but the question #1 I want the Original URL in the Administration Edit page, something like I need to see the Original URL inside the Entry Body. I assume for that I need to edit some other files not the entries.tpl file.

Regards,
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Ah. That cannot be done, you need to preview your entry to view the original URL in that case.

Else you'd need to modify the aggregator plugin PHP code to put the original URL into the body.

BTW, if you use categories for putting your aggregated feeds, you can see by the category from which Site an entry comes.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
smartcard
Regular
Posts: 14
Joined: Sat Jan 08, 2005 12:47 pm

Post by smartcard »

Thanks for the reply. May I know how to modify the aggregator plugin PHP code to put the original URL into the body?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

For that, you would need to look at the plugin. Look for where the "ep_*" things are inserted into the database, and instead of doing that, append the variables that are inserted into the entry's body.

You'll definitely learn some PHP along the way, so this is a very good example of learning by doing. The task at hand is not so hard, so I'm sure with some trial and error you'll succeed.

If not, you still have the option of using the category system like I outlined.

The other way is, if you can manage to convince me why anyone (or you specifically) need the feed's URL in the admin section, I might create the patch for you as an official option to the plugin. ;-)

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
smartcard
Regular
Posts: 14
Joined: Sat Jan 08, 2005 12:47 pm

Post by smartcard »

Oophs, that is too difficult for me to edit that file.

Well let me try to convince you.. :)

If you remember that I wanted the aggregated post to be in the draft mode (not to publish immediately) this feature is also related to the same, I want to approve every posts to my Blog, so when the script aggregated the articles it will be in the draft mode so I will go to every article and approve them or delete them, when approving if I need to know more about that particular article I need to go to the original URL to read them, that is the reason I want the original URL to appear in the admin area.

Hope I convinced you? :)
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

Well, for your own purposes (at least for the moment), you could try this:

Open the file serendipity_event_aggregator.php. Find this code:

Code: Select all

                $feed['articleurl'] = $item['link'];
                // Store as property

                $entryid = serendipity_updertEntry($entry);
                $this->insertProperties($entryid, $feed, $md5hash);
                printf(" Save '%s' as %s.\n", $item['title'], $entryid);
Earlier in the code, we got the content and put it into $entry['body']. We'll just add the link at the top, before we go saving it. There's only one line to add, and the result should look like this:

Code: Select all

                $feed['articleurl'] = $item['link'];
                $entry['body'] = 'Original article at <a href="' . $item['link'] . '">' . $item['link'] . '</a>' . "\n";
                // Store as property

                $entryid = serendipity_updertEntry($entry);
                $this->insertProperties($entryid, $feed, $md5hash);
                printf(" Save '%s' as %s.\n", $item['title'], $entryid);
Perhaps not my most elegant code ever, but it should accomplish what you want.
Judebert
---
Website | Wishlist | PayPal
Rik
Posts: 2
Joined: Fri Jun 16, 2006 2:11 am
Contact:

RSS feeds not shown on index. HOW?

Post by Rik »

What do I need to do to automatically not show posts from rss feeds on the index page and only in the category where it is placed ?

What file do I need to edit and more importanly what do I need to add so the posts from the rss aggregator aren't shown on the index page.

Like if you add a new entery and choose the option :
Hide from article overview / frontpage

Can you help me?
Post Reply