Path

ez.no / ezpublish / documentation / incoming / setting up rss import


Setting up RSS Import

These documentation pages are no longer maintained. Please visit the new documentation site.

This document will show, how to set up an RSS import for importing an RSS newsfeed into ezPublish. RSS import is available since ezPublish 3.3, which -at the time of writing- is only available as a beta release, which should not be used for production sites.

For this example, I set up a 3.3 beta 1 site using the "news" package. We will get an RSS newsfeed from N24.de, which is a german news site. If you already have your RSS URL, you can use yours in the last step ;)

Please note, that I use a german ezPublish setup and back-translate some GUI elements, like button names. So, i hope, the names are correct. If not, someone please fix that here.

Overview

In order to import an RSS newsfeed, you will need to follow these steps

  1. Create an appropriate class, where the data from the newsfeed shall be imported to and create a full-view template for this class
  2. Edit your roles, so that users will see the new class
  3. Create a place (folder), where you want your imported news items to be displayed
  4. Define the RSS newsfeed to be imported
  5. Import the newsfeed by running a cronjob

Steps 1 and 2 are required only once. You can skip these completly and import the data to some existing class (ie "article"), if you want to.

Steps 3 and 4 are required once for every news feed import, that you want to define (assuming, that you want to import each feed into a seperate folder)

Step 5 should be run automatically by your cronjob. The frequency depends, on how you want to update you news. You should set up the cronjob to run at least once every day (every 24 hours). Setting up a cronjob is not described here.

Note: Your server will need a HTTP connection to the location of the RSS feed. If your server is behind some firewall, which prevents HTTP communication, RSS import will probably not work, as it does not (yet) support HTTP proxies.

Detailled Description

Setting up a class

Each newsfeed consists of distinct "news items". Usually, an RSS feed contains 10-15 items. "RSS import" looks at the RSS feed (which is an XML structure), take some data from each news items and publishes one ezPublish object per news item.

You could use the "article" class for this, but let's define our own class, that will hold the news items from the RSS feed, because the article class is a bit too complex for this.

So log in to your admin siteaccess, go to "Setup" tab, choose "Classes" and define a new class in the "Content" group.

For this document, we will use this class:

  1. Class name: "Link" (identifier: "link")
  2. First Attribute: "Titel" (Textline, identyfier "titel")
  3. Second Attribute: "Intro" (Textfield, identyfier "intro")
  4. Third Attribute: "URL" (URL, identyfier "url")

After you have set up the class, you will need some template for that class, so you can really use it at you site.

Go to "Template" (still in the "Setup" tab), click on "node/view/full.tpl", choose your user-siteaccess from the dropdown list and press "set". You should now see some template for folders, articles etc. Click "Create new", name the template "link.tpl", choose your class (Link) from the first dropdown list and select "View (without children)". Press "Create". This will create a template and bring you back to the template list.

Edit your newly created template. You should see something like this:

<h1>{$node.name}</h1>

 

<h2>Titel</h2>

{attribute_view_gui attribute=$node.object.data_map.titel}

 

<h2>Intro</h2>

{attribute_view_gui attribute=$node.object.data_map.intro}

 

<h2>URL</h2>

{attribute_view_gui attribute=$node.object.data_map.url}

This is almost nice, but will not show you the URL later, because "attribute_view_gui" uses the "text" of a URL to display the link. But when we import the news later, we will have no URL text, so we would see no link.

Because of that, we change the template to look like this:

<h1>{$node.name}</h1>

 

{attribute_view_gui attribute=$node.object.data_map.intro}

 

<p>mehr: <a href="{$node.object.data_map.url.content}">{$node.object.data_map.url.content}</a></p>

That should give us a more or less nice "full view" of the imported news item. Save the template. We are done with the class definition. Note, that I did not change the "line" template here. Maybe it's better to define a nice "line" template with title, intro and URL, instead of the "full-view"-template, because an RSS news item NEVER has a body. Per definition, the body of the news item always is on the news site itself and so, it might be a good idea to just define a "line" template, which will link to the (external) news item full view immendiatly. But.. i will leave this to you as an exercise ;)

Adapt your role policies

Note, that you could go ahead now and define and import RSS data now, but the user would not see it at the user site. Why? Because the "anonymous" role is not yet allowed to read our new class!

So, go to the "Users" tab, choose "roles" and edit the "Anonymous" role. There, edit the "content read" policy and add your new class (Link) in the first drop-down-list (Control-Click). Confirm with "Update" and then don't forget to press "Store" ! From now on, "Anonymous" users should be able to see the news items... but we don't have any yet.

Define a place for your news items

Remember, that the import will create new objects (one for each news item). You should create a nice place for these items.

In the "content" tab, create a new folder at root level and name it "RSS" (just for this example). In that, create another folder called "N24", which is the name of the news site, where we will get our RSS news from in some minutes. The folder "N24" should be sorted by date, backwards, so the item, that was imported latest, will be at the top.

You should now have a folder with this path "News / RSS / N24", which is empty.

Define the RSS feed to be imported

Now, after all that prerequisites, we will finally define our news feed. Go to "setup" tab, click on "RSS". You should see two lists: "RSS Exports" and "RSS imports". Both are empty, so let's create a new import. Press the "New Import" button.

There, fill in these information:

  • Title: N24 Home (will not be visible to the user, it's just to give the import a name)
  • URL: http://n24.de/rss/?rubrik=home (The URL of the RSS feed).
  • Destination path: Press "Browse" and browse to your target folder (/News/RSS/N24). After you press "Select", the path of the target folder will appear in the text field.
  • Imported Objects owner: Leave it to "Administrator user". This will be the owner of the news items.
  • Class: Select "Link" from the dropdown list and press the "Update" button to update the attributes in the next lists to reflect the attributes of the "Link" class
  • Title: Select "Title" from the drop-down-list
  • URL: Select "URL" from the drop-down-list
  • Description: Select "Intro" from the drop-down-list
  • Active: Leave enabled

Press the "Store" button to save the import definition. This defines the RSS import, but does not import anything yet. Importing is done during a cronjob run.

Importing data with a cronjob

In 3.3, the cronjob script "runcronjobs.php" includes a PHP script, which imports news items for all (enabled) RSS imports.

Refer to http://ez.no/developer/ez_publish_3/documentation/configuration/configuration/cron_jobs for more information on setting up a cron-job.

The cronjob will import and publish the distinct news items for the defined RSS imports. It will use the "URL" field to determine, if a news item already exists and skip it, if this is the case.

Note that this will create lots of objects in just a few days, so make sure, that you manage this somehow to prevent "information overflow".

Comments