[Solved] RSS Simple Pie - Edit Feed Content

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
apollo9
Forum Members
Forum Members
Posts: 22
Joined: Sat Nov 09, 2013 3:10 pm

[Solved] RSS Simple Pie - Edit Feed Content

Post by apollo9 »

I would like to use this feed https://www.tidetimes.org.uk/stoke-gabr ... -times.rss to display the tide times on our website.

I've reduced the RSS Simple Pie template down to this.

Code: Select all

<div class="feeds">{foreach from=$feeds item=onefeed}
    <div class="feed-content"> 
        {$onefeed->get_content()}
    </div>
{/foreach}</div>
However, the "feed content" contains information I would like to omit.
From this template I get the following output:

Tide Times & Heights for
Stoke Gabriel (Duncannon) on 22nd April 2015

03:19 - Low Tide (0.10m)
09:46 - High Tide (4.50m)
15:36 - Low Tide (0.30m)
21:57 - High Tide (4.50m)

It would be useful to keep the <pubDate> date. Otherwise, it's only the tidal information I wish to display and not the description.

RSS raw data is as follows:

Code: Select all

<item>
  <title>Stoke Gabriel (Duncannon) Tide Times for 22nd April 2015</title>
  <link>http://www.tidetimes.org.uk/stoke-gabriel-duncannon-tide-times</link>
  <guid>http://www.tidetimes.org.uk/stoke-gabriel-duncannon-tide-times</guid>
  <pubDate>Wed, 22 Apr 2015 00:00:00 GMT</pubDate>
  <description><a href="http://www.tidetimes.org.uk" title="Tide Times">Tide Times</a> & Heights for<br/><a href="http://www.tidetimes.org.uk/stoke-gabriel-duncannon-tide-times" title="Stoke Gabriel (Duncannon) tide times">Stoke Gabriel (Duncannon)</a> on 22nd April 2015<br/><br/>03:19 - Low Tide &#x28;0.10m&#x29;<br/>09:46 - High Tide &#x28;4.50m&#x29;<br/>15:36 - Low Tide &#x28;0.30m&#x29;<br/>21:57 - High Tide &#x28;4.50m&#x29;<br/></description>
 </item>
Last edited by apollo9 on Fri May 08, 2015 5:29 pm, edited 1 time in total.
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Contact:

Re: RSS Simple Pie - Edit Feed Content

Post by paulbaker »

It looks like the bit you don't want stays the same each time. So one way of doing this would be to use Smarty replace:
http://www.smarty.net/docs/en/language. ... eplace.tpl

So you will want something like this:

Code: Select all

{$onefeed->get_content()|replace:'All the text you do not want to show':''}
So you are replacing the text you don't want with '' (empty string).

Of course, if the RSS text is later changed your replace won't work because it won't match and so you will need to keep an eye on it.
To copy System Information to the forum:
https://docs.cmsmadesimple.org/troubles ... nformation

CMS Made Simple Geekmoots attended:
Nottingham, UK 2012 | Ghent, Belgium 2015 | Leicester, UK 2016
apollo9
Forum Members
Forum Members
Posts: 22
Joined: Sat Nov 09, 2013 3:10 pm

Re: RSS Simple Pie - Edit Feed Content

Post by apollo9 »

I've replaced the first part (including links) like this:

Code: Select all

{$onefeed->get_content()|regex_replace:"/(<a>|<a [^>]*>|<\\/a>)/":""|replace:'Tide Times':''|replace:"&":""|replace:'Heights for':''|replace:'Stoke Gabriel (Duncannon)':''|replace:'on':''}
Which leaves :
23rd April 2015

03:53 - Low Tide (0.40m)
10:24 - High Tide (4.20m)
16:10 - Low Tide (0.70m)
22:31 - High Tide (4.20m)
The line space between the date and tide times is problem. It would be better with a smaller space.
The code on the page now begins like this:

Code: Select all

<br>  23rd April 2015<br><br>03:53 - Low Tide
Is there a way to replace those first two <br> with something I could modify with CSS to get the desired space?

The alternative is to just remove the date. But how - because it changes every day?
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: RSS Simple Pie - Edit Feed Content

Post by velden »

try:

Code: Select all

|regex_replace:'/<br>\s*(.*)<br><br>/':"$1<br>"
apollo9
Forum Members
Forum Members
Posts: 22
Joined: Sat Nov 09, 2013 3:10 pm

Re: RSS Simple Pie - Edit Feed Content

Post by apollo9 »

Thank you!
I managed to tweak your suggestion so that the date is in a <div> in order to add some padding.

Code: Select all

|regex_replace:'/<br>\s*(.*)<br><br>/':"<div class=\"feeds-tides-date\">$1</div>"
Post Reply

Return to “Modules/Add-Ons”