Hi there..
I’m Using
getFeed 1.0.0-rc1 over
2.0.4-pl2 to get feeds from
EPN Products.
[[!getFeed?
&url=`http://www.epn-online.com/rss/index/type_art/Top+product`
&tpl=`epnFeedTpl`
&limit=`3`
]]
.
epnFeedTpl Chunk (Formmating Items grabed from "EPN Online - Top products" feed for getFeed.)
<div>
<p><img src="[[!EPN_IMG_PULL? &URL=[[+link]]]]" />
<br /><a href="[[+link]]">[[+title]]</a>
<br />[[+description:ellipsis=`250`]]
<br />[[+pubdate:fuzzydate]]</p>
</div>
[[!EPN_IMG_PULL? &URL=[[+link]]]]
As you can see The Structure of the feed contains Title, Link, Description & Date, but doesn’t have the appropriate Image from the original Item.
Therefore I’ve Scribbled a Snippet that used-with/gets Item’s URL from the getFeed PlaceHolder inside the tpl chunk
and grabs the content, striping and pulling the picture of item’s URL ,when it possible (if the page has one).
Custom Snippet:
//PULL EPN's PRODUCT IMAGE ACCORDING TO GIVEN URL.
//OUTPUT: DIRECT-IMAGE-URL
<?php
// Default Image InCase Object isn't found.
$default = 'http://www.epn-online.com/images/logo.png';
// Fetch content from given address.
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
curl_close($c);
// Strip to get the name of the image.
if ($contents) {
$root = 'http://www.epn-online.com/lib/image.php?uri=/content/users/';
$start = '/lib/image.php?uri=/content/users/';
$end = '" class="article_details_data_image';
$ini = strpos($contents,$start);
if ($ini === false)
return $default;
$ini += strlen($start);
$len = strpos($contents,$end,$ini) - $ini;
return ($root.substr($contents,$ini,$len));
}
else return $default;
?>
(
example of a single item page from the feed that i trying to pull from)
It’s all works fine right to the purpose but it’s very un-efficient and slow.
Which is not surprising because of all the snippet calls ,HTTP Requests, pulling-striping-manipulating process (aside with the work MODx itself does processing),
and thank god i didn’t need to use Regex in this specific case.
And Now To The Big Questions..
As far as i know
getFeed is based on
magpieRSS which has default cache settings that isn’t much of configurable from getFeed.
I don’t really know so well how the MODx’s cache system works to figure out how to do it in the best-efficient way.
so,
how can it be done in the best way?
Maybe it’s better to use spiefeed which is based on SimplePie and has some cache options?
- Or maybe somehow use getCache to cache & speed things up?
umm..
more advanced idea i got in mind:
- Is it possible to produce Resource from the feed and archive it?
Many Thanks for reading this topic through getting this far ,haha..