Page 1 of 1

[Solved] RSS Simple Pie - Edit Feed Content

Posted: Wed Apr 22, 2015 5:50 pm
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>

Re: RSS Simple Pie - Edit Feed Content

Posted: Wed Apr 22, 2015 10:17 pm
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.

Re: RSS Simple Pie - Edit Feed Content

Posted: Thu Apr 23, 2015 6:02 pm
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?

Re: RSS Simple Pie - Edit Feed Content

Posted: Fri Apr 24, 2015 8:00 am
by velden
try:

Code: Select all

|regex_replace:'/<br>\s*(.*)<br><br>/':"$1<br>"

Re: RSS Simple Pie - Edit Feed Content

Posted: Sun Apr 26, 2015 3:47 pm
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>"