Warning

This document hasn't been checked for compatibility with current versions of Plone. Use at your own risk.

Publish Plone search queries on other web sites using syndication

by bjelkeman — last modified Dec 06, 2009 09:27 PM
Shows how to publish the Plone Recent items on another web site and have it look like the Recent items portlet. With some changes you could publish virtually any query in Plone as an RSS feed onto another web site.

I wanted to have the Plone "Recent items" portlet from our document library which is held in Plone, automatically updated and visible on another web site which is not managed by Plone. To do this I used Plone's syndication feature. To see what the end result looks like check out the OTECnews web site which is a flat file web site. It has both a News and Recent items feed from Plone on a different server.

I started by reading the How To Syndicate News Items and learning how to publish the News items from my Plone installation to my other web site. Here are the main steps in doing this.

  1. Enable syndication
  2. Check that the syndication works for News
  3. Select RSS parsing and republishing software
  4. Set up FeedDigest to import the RSS from the Plone News
  5. Set up the web page that will receive the RSS feed from Plone via FeedDigest
  6. And then finally: Create a query which will work like the Recent Items portlet

Here is a more detailed description of how I did that:

Enable syndication

Go to the Zope Management Interface of the site, go to portal_syndication, then go to the Properties tab and there, enable syndication.

Check that the syndication works for News

To try if the syndication worked for my News items on my Plone site I entered the following URL into a browser http://library.greenocean.org/search_rss?portal_type=News+Item&review_state=published

If you receive an XML file (in Firefox) that begin something like this then you have managed to get it to work:

        <rdf:RDF>
                <channel rdf:about="http://library.greenocean.org">
                        <title>The GreenOcean Project / OTECnews</title>
                        <link>http://library.greenocean.org</link>
                        <description>Online library </description>
                        <image rdf:resource="http://library.greenocean.org/logo.jpg"/>
                                <items>
                                        <rdf:Seq>
                                                <rdf:li rdf:resource="http://blah blah blah
                                                <rdf:li rdf:resource="http://blah blah blah
                                                etc. etc.

Select RSS parsing and republishing software

To be able to parse and import the syndication RSS file from my Plone site and publish it on my web site I needed to choose some software to do this. You can either host the software to do this yourself or you can use an online service to do it. One open source solution which you can host yourself is Magpie RSS . A free service (which I am using at the moment) is FeedDigest , and this example will show how to use FeedDigest to achieve the desired result.

Set up FeedDigest to import the RSS from the Plone News

The FeedDigest service will allow us to get the RSS data from our Plone site and structure it so that it is suitable to republish it on our web site. It also automatically generates Javascript or PHP code for us to use on the web site.

  1. Create an account at FeedDigest
  2. In the Control Panel, Create a new digest by entering the URL above in the Feed Address field
  3. Set relevant options: Digest name, order Items by, max items to show, click here for dupe filtering
  4. Set up the Digest layout / template. Here I edited the HTML manually so that I could create something that looked like the Plone portlet on my web site.

The following is the main code.

Per item template

HTML code which I entered:

        <div class=portletBody">
        <div class=portletContent even">
        <div class=portlettext>
        <b><a href="%URL%">%TITLE,50%</a></b><ifdescription><br />
                %DESCRIPTIONPLAIN,85%</ifdescription></div>
        <div class="portletDetails">
        %YEAR%-%MONTH2%-%DAY2%</div></div>

Header template

HTML code which I entered:

        <table cellpadding="2" cellspacing="1" border="0">      

Footer template

HTML code which I entered:

        </table>

Then after a saved the digest. I tried it by clicking the Outputs HTML link. It looked like I expected the feed to look like at this point. More control of the style and layout comes next.

Set up the web page that will receive the RSS feed from Plone via FeedDigest

One the web page which we publish the RSS feed on we need to enter the relevant style sheet information to make the above CSS code work properly. I added the following to the top of the web pages.

HTML code which I entered:

        <style type="text/css" media="screen">
        http://www.otecnews.org/css/otecnews.css</style>

And in that CSS document I added the following to create the desired result:

        .portlet {
                border: none;
                margin-bottom: 1em;
                padding: 0;
        }

        .portlet h5 { 
                background-color: #dee7ec;
                border: 1px solid #8cacbb;
                padding: 0em 1em 0em 1em;
                text-transform: lowercase;
                display: inline;
                font-size: 1em;
                font-weight: normal;
                white-space: nowrap;
                position: relative;
                top: -1px;
        }

        .portlettext {
                font-family: Verdana, Arial, sans-serif;
                color: black;
                font-size:12px;
                margin:0px;
                margin-top:2px;
        }

        .portletBody {
                position: relative;
                top: -1px;
                background: transparent;
                border: 1px solid #8cacbb;
                margin-right:4px;
        }

        .portletDetails {
                font-family: Verdana, Arial, sans-serif;
                color: black;
                font-size:12px;
                text-align: right;
                margin-top:2px;
        }

        .portletContent {
                padding: 1em;
        }

And then in the web page I added the following HTML to wrap the Javascript which FeedDigest supplied me with (after you have saved the digest in FeedDigest you can click on the link called Get Code, this will produce a Javascript and a PHP script which you can use below):

        <div class="portlet">
        <div class="portlettext"><h5>
        OTEC Library news</h5></div>
        <div class="portletBody">
        <script type="text/javascript" 
        src="http://app.feeddigest.com/digest3/4GBACU7V2L.js">
        <noscript><a href="http://app.feeddigest.com/digest3/4GBACU7V2L.html">
        See the OTEC Library feed digest</a></noscript>
        </script>
        </div>
        </div>

This finally gave me the desired result. Something which looked like a portlet in Plone.

A picture of simulated plone portlet

Create a query which will work like the Recent Items portlet

However, I didn't only want the News items published this way. I wanted the Recent items published too. These are normally not visible on the Plone site unless you are logged in. To get Recent items visible at all times I had to customise the portlet. This was done by editing the portlet Python script.

Plone Recent Items visible for Anonymous users

Go to the Zope Management Interface of the site, go to portal_skins, then go to plone_portlets tab and there, click the customize button to create a custom version of the plone_recent script. When you save it a copy will be saved in /portal_skins/custom.

This is the part of the script before the edit:

    <tal:recentlist tal:define="last_login_time python
        member.getProperty('last_login_time', DateTime());
                results python:request.get('items',
                        here.portal_catalog.searchResults(modified=
                                {'query': last_login_time,'range': 'min'},
                                sort_on='modified',
                               sort_order='reverse',
                                review_state='published')[:5]);">

This is the the customised part of the script after the edit:

    <tal:recentlist tal:define="last_login_time python:DateTime('1/1/1970');
        results python:request.get('items',
                        here.portal_catalog.searchResults(modified=
                                {'query': last_login_time, 'range': 'min'},
                                        sort_on='modified',
                                        sort_order='reverse',
                                        review_state='published')[:5]);">

Set up a FeedDigest entry for recent items

To get the same data published to the RSS feed I need a different query to run. First we set up another FeedDigest digest, this time with a query which will return the same answer as the Recent Items query which the above portlet runs:

         http://library.greenocean.org//search_rss?
                items&sort_order=reverse&review_state=published&sort_on=modified

We also set up the rest of the digest properties (i.e. Digest name, order Items by, max items to show, click here for dupe filtering), like we did for the News digest previously.

Publish the new Recent Items query on the web site

And finally, just like we did above, we now need to put up the HTML on the web site to publish this digest. I put one underneath the other on the OTECnews web site.

Done! Hope this is useful for someone.

Thomas Bjelkeman-Pettersson


Contribute

Something wrong or out of date? Anybody can edit or create a new article in the knowledge base. Simply create an account on this site, log in, and click the Edit button to contribute.