sNews Forum

Previous sNews versions => sNews 1.4 Final => Mods and Addons => Topic started by: Patric Ahlqvist on September 14, 2006, 01:36:00 pm

Title: [ADDON] Grab external feeds
Post by: Patric Ahlqvist on September 14, 2006, 01:36:00 pm
We discussed in another thread that the original grabfeed.php was slow, and the Magpierss didn't work well (and in addition to that it didn't validate, that can't be allowed ;))...

Well I searched the web and found this: http://www.geckotribe.com/rss/carp/

Hehe, yummie. It works fast, and validates. It can be setup to work with MySQL or cache folders, and it's a treat. Just download it and...:

Unzip and upload the content of the Carp folder to a subfolder, preferably called "carp". Upload the carpsetup.php to the root, and load it into your browser. Follow instructions. (I chose cachefolders for some reason.)

Now, if everything worked out and you see feeds in the big gray box, you're done... It's working, eh ? Delete the carpsetup.php located at the root of your site, and carpsetupinc.php located in the carp folder. You can also delete phpftp.php and phptelnet.php in that same folder, they are not used by CaRP.

Now all is well, now we only need to get it up and running on our site, eh ? And we want to display the feeds of our own choice, don't we ? So... Open up your index.php:

In the top part of the index.php add:
Code: [Select]
require_once 'carp/carp.php';that is if you named the folder carp, hehe...

Mine looks like:
Code: [Select]
<? session_start();
include ("snews.php");
include ("audit.php");
ob_start("ob_gzhandler");
require_once 'carp/carp.php';?>
Now you must choose a place for the feeds to show up on your site. When you've done that you paste this:(with courtesy to Avenir, who made the process of coding it a bit faster than me ;))
Code: [Select]
<?php
CarpConf
('cborder','');
CarpConf('maxitems',1);
CarpConf('maxidesc',75);
CarpConf('poweredby','');
CarpConf('cacheinterval',120);
echo 
'<p>'CarpCacheShow('http://www.brauck.nl/rss.xml');echo '</p>';
echo 
'<p>';CarpCacheShow('http://www.free-css-templates.com/rss/');echo '</p>';
echo 
'<p>';CarpCacheShow('http://p-ahlqvist.com/rss.xml');echo '</p>';
echo 
'<p>';CarpCacheShow('http://www.cssplay.co.uk/feed.xml');echo '</p>';
?>
And you're good to go. If you want more feeds from each site, change CarpConf('maxitems',1);, number of characters in descrition, change CarpConf('maxidesc',75); and so on... More feeds ? Just copy a line with a feed in it, and change the URL to whatever you want...

Cherrs Patric.
Title: [ADDON] Grab external feeds
Post by: Patrik on September 14, 2006, 02:09:14 pm
Great Patric, it sure looks great :)

EDIT: And I love your way of writing descriptions! The Patricway...wonderfull :)
Title: [ADDON] Grab external feeds
Post by: elkie on September 14, 2006, 07:39:12 pm
Excellent addon and explanation.  However, I believe there are better choices than carp as the RSS reader.  Although it is free, it is not opensource (they would like you to upgrade to paid version), you need to register to download, it has no real community, somewhat limited as in if you wanted images in your feeds you would need to purchase the upgrade.  I had spent the last month looking at various rss feeds and I tried carp and it worked but I decided not to use it for the reasons as stated.

Simplepie found here www.simplepie.org works as well or I believe better than carp but it is open source, for lack of better term more Web 2 friendly, has strong community who have already created a few plugins for CMS's (textpattern, wordpress)
I used your excellent post on integrating Carp and did the same with Simplepie by downloading the multiple feed http://simplepie.org/blog/2006/08/23/sorting-multiple-feeds-by-time-and-date/ and grabbed 2 from each feed you supplied and had them sorted by date so the latest post is first.  An example is here at www.eelkema.net/sNews/index.php  (sorry I am new to sNews so just installed today and this is just the base install but you get the idea)  If there is interest, I can post later on how I set it up, but basically followed Patric example for Carp and used simplepie instead.

I hope this doesn't come off as impolite, I love sNews so far and believe that simplepie is a better platform to build an addon than Carp.  I look forward to hearing any feedback and look forward to working more in this community once I become more familiar with sNews.

Respectfully,

Brian Eelkema
Title: [ADDON] Grab external feeds
Post by: Keyrocks on September 14, 2006, 08:41:14 pm
Hi Brian... and Welcome to our sNews Community. About being impolite... that's OK... you were granted 3 Free Impolite Coupons when you signed up so you still have 2 more and, after they are used up... well... no more OK? (just kidding, hehe)

Seriously, you are not being impolite at all. In fact, bringing your mod to the Forum is a good thing. We welcome a diversity of opinion and approach as long as it comes with respect for all fellow sNoozers here on the Forums. We enjoy a little fun but we do believe in showing consideration and respect.

Please... do share your mod in this Topic. Again... it is most welcome! :)
Title: [ADDON] Grab external feeds
Post by: Patric Ahlqvist on September 14, 2006, 08:43:12 pm
Hey, Brian. Not impolite at all, aux contraire mon ami, hehe... Excellent post, and please, Brian, do post how you set it up. I'm a basic PHP imbecille and need an hour per your five minutes to understand and setup things like this ;)... So please post an explanation, and do it in laymens terms ;)...

I did find this and thought it was ok, I'm a bit ignorant that way, not to knowledgable, but more of a glad chum when things get to work...So you might be, probably are, correct in your assumption that  Simplepie is better.
Title: [ADDON] Grab external feeds
Post by: Fred K on September 14, 2006, 08:55:30 pm
Well, SimplePie fits my needs perfectly. And I also think that the documentation could serve as a beacon/guiding light/inspiration... :D
Title: [ADDON] Grab external feeds
Post by: elkie on September 14, 2006, 10:30:59 pm
Thanks for the feedback.  I will find some time in the next day or 2 to post the howto.  Looking forward really getting to know sNews and its community.  I had just spent a month working with different rss parsers so this area I had some knowledge but in other areas I will seek many of your cumulative wisdoms.

Brian
Title: [ADDON] Grab external feeds
Post by: mosh on September 21, 2006, 07:59:20 pm
very good addon thank you :)

how can i show feeds on the articles or pages i creat with in snews ?
Title: [ADDON] Grab external feeds
Post by: Patric Ahlqvist on September 22, 2006, 09:08:32 am
Mhm, if I understand your questiong properly, you just should have to put that last code snippet inside the article or page you want it to appear in...
Title: [ADDON] Grab external feeds
Post by: mosh on September 22, 2006, 12:20:55 pm
what code should i use to includ with in the articles ?

i have try :
<?php CarpCacheShow('http://www.geckotribe.com/press/rss/pr.rss'); ?>

and i have try :
<?php
CarpConf('cborder','');
CarpConf('maxitems',1);
CarpConf('maxidesc',75);
CarpConf('poweredby','');
CarpConf('cacheinterval',120);
echo '<p>'; CarpCacheShow('http://www.brauck.nl/rss.xml');echo '</p>';
echo '<p>';CarpCacheShow('http://www.free-css-templates.com/rss/');echo '</p>';
echo '<p>';CarpCacheShow('http://p-ahlqvist.com/rss.xml');echo '</p>';
echo '<p>';CarpCacheShow('http://www.cssplay.co.uk/feed.xml');echo '</p>';
?>

but nothing.

it works only when i set it in the index.php page layout .... hmm :)
Title: [ADDON] Grab external feeds
Post by: Patric Ahlqvist on September 22, 2006, 12:44:48 pm
well you could create an txt or php file that contains the script  and then in the article you type:

Code: [Select]
[include]path/to/script.txt[/include]I think that this should work... ? I have my google adsense included that way.

My solution for the feed grabber is to hardcode it into the index.php (ver 1.4) as I want it to be visible on the FP at all times...
Title: [ADDON] Grab external feeds
Post by: mosh on September 22, 2006, 01:23:48 pm
OMG :) it's working like magic ..... THANK YOU PATRIC :)
Title: [ADDON] Grab external feeds
Post by: Patric Ahlqvist on September 22, 2006, 01:26:51 pm
Ahhhh, great to be able to be of assistance ;). Glad you got it running...
Title: [ADDON] Grab external feeds
Post by: mosh on September 22, 2006, 01:44:48 pm
awesome ...... now i can really do some work hehehehe soooo cool man thanks again :)
Title: [ADDON] Grab external feeds
Post by: philmoz on September 26, 2006, 01:24:16 pm
for those in this thread using simplepie, have you managed to get it to read the rss of this site??
Title: [ADDON] Grab external feeds
Post by: mosh on September 26, 2006, 10:28:43 pm
yes, no problem :)

http://www.solucija.com/rss/   <---- // you will not get feeds

http://www.solucija.com/rss.xml     <---- // that will work


hope that help :)
Title: [ADDON] Grab external feeds
Post by: philmoz on September 26, 2006, 11:38:45 pm
Quote from: mo
yes, no problem :)

http://www.solucija.com/rss/   <---- // you will not get feeds

http://www.solucija.com/rss.xml     <---- // that will work


hope that help :)
Nope, didn't work....  

Now I am wondering whether my simplepie isn't set up right.
(I can read feeds that have a physical file, so I is working.)

Need some ideas to track down problem.
Title: [ADDON] Grab external feeds
Post by: elkie on September 27, 2006, 04:13:57 am
I think it is an issue with dates.  When I use the feed http://www.solucija.com/rss.xml     all the dates equal Dec.31, 1969.  Simplepie is not parsing the feed correctly either due to error in simplepie or the RSS feed itself.  I think it is the feed as other RSS sites done with sNews don't seem to have the same issue.

Brian
Title: [ADDON] Grab external feeds
Post by: Fred K on September 27, 2006, 08:45:22 am
It says in simplepie's docs that it won't parse feeds with no dates (or incorrect dates). I also think --but I could be wrong of course-- that solucija still uses the original 1.4 RSS feed incorporation method, which didn't work properly. I can't get it into simplepies feed system either, and Safari's feed reader still won't parse it either, so...
Title: [ADDON] Grab external feeds
Post by: philmoz on November 07, 2006, 09:12:49 am
Code: [Select]
http://www.solucija.com/rss//rss.xmlthe above works.
Title: Re: [ADDON] Grab external feeds
Post by: Patric Ahlqvist on May 13, 2008, 03:26:30 pm
I got a simplepie up and running, but I have no possibility to style it, edit it, or whatever, hehe... But the news is there,
Title: Re: [ADDON] Grab external feeds
Post by: Sven on February 19, 2009, 09:49:53 am
Almost a year later... ;D
Can someone give a hand to the famous php idiot of the forum?
I just installed this piece of cake called Simple Pie,
and the demo in the package is working fine.

But but but... how can I make it work in an sNews page of mine?
I just put this piece of code:
Quote
   <div class="header">
      <h1><a href="<?php echo $feed->get_permalink(); ?>"><?php echo $feed->get_title(); ?></a></h1>
      <p><?php echo $feed->get_description(); ?></p>
   </div>
 
   <?php
   /*
   Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop.
   */
   foreach ($feed->get_items() as $item):
   ?>
 
      <div class="item">
         <h2><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h2>
         <p><?php echo $item->get_description(); ?></p>
         <p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
      </div>
 
   <?php endforeach; ?>
and html output code result is:
Quote
      <h1><a href="<?php echo $feed->get_permalink(); ?>"><?php echo $feed->get_title(); ?></a></h1>
      <p><?php echo $feed->get_description(); ?></p>
   </div>
 
   <?php
   /*
   Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop.
   */
   foreach ($feed->get_items() as $item):
   ?>
 
      <div class="item">
         <h2><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h2>
         <p><?php echo $item->get_description(); ?></p>

         <p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
      </div>
 
   <?php endforeach; ?
As always need your 3 minutes (?) help to make it work.  :-[
Title: Re: [ADDON] Grab external feeds
Post by: bikoz on February 19, 2009, 11:57:32 am
Just my guess:

Try to put the whole code (HTML and PHP) in an external text file, say "script.php", and insert the file with [include]path/to/script.php[/include] on the actual sNews page.

And of course, tell us if this works. :-)
Title: Re: [ADDON] Grab external feeds
Post by: Sven on February 19, 2009, 02:59:27 pm
Hello Mr Vincent,
et merci pour ton message et ta réponse.

I made what you said and nope, still not workin out.
But now it says:
Quote
Fatal error: Call to a member function get_permalink() on a non-object in D:\xampp\htdocs\richard\script.php on line 2

I've followed those instructions: http://simplepie.org/wiki/setup/setup
and for the php code followed this instructions in this page: http://simplepie.org/wiki/setup/sample_page

I thought those recipes were enough to make my pie, but you know I'm a dumb PHP cook. ;D


Title: Re: [ADDON] Grab external feeds
Post by: lann on February 19, 2009, 04:03:34 pm
for example in your Snews index.php (or index of your theme ) u have to add <?php require 'php/simplepie.inc'; ?>  that works on my site
Title: Re: [ADDON] Grab external feeds
Post by: lann on February 19, 2009, 04:19:06 pm
Step 1 add <?php require 'php/simplepie.inc'; ?> in index.php

Step 2 your code ...
Quote
<div class="header">
      <h1><a href="<?php echo $feed->get_permalink(); ?>"><?php echo $feed->get_title(); ?></a></h1>
      <p><?php echo $feed->get_description(); ?></p>
   </div>
   ...

Step 3
 then you can put it (php code) in an external text/ php file and insert the file with [include] on your page
Title: Re: [ADDON] Grab external feeds
Post by: bikoz on February 19, 2009, 04:47:25 pm
I made what you said and nope, still not workin out.
But now it says:
Quote
Fatal error: Call to a member function get_permalink() on a non-object in D:\xampp\htdocs\richard\script.php on line 2

I guess the [include]...[/include] does not take care of libraries/classes dependencies.

You should add the necessary "include" statements at the top of index.php as Iann mentioned.

Let us know.
Title: Re: [ADDON] Grab external feeds
Post by: Sven on February 19, 2009, 05:40:44 pm
Well, it's already in the file:
Quote
<?php
// Make sure SimplePie is included. You may need to change this to match the location of simplepie.inc.
require_once('php/simplepie.inc');
 
// We'll process this feed with all of the default options.
$feed = new SimplePie('http://simplepie.org/blog/feed/');
 
// This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it).
$feed->handle_content_type();
?>
- simplepie.inc, is in the PHP folder,
- cache directory is present too,
- and engine (create.php) at the root.

 ???
Title: Re: [ADDON] Grab external feeds
Post by: bikoz on February 19, 2009, 05:53:36 pm
Just to be sure:

- The require_once('php/simplepie.inc'); statement goes at the top of your (sNews) index.php file.

- Both $feed = new SimplePie('http://simplepie.org/blog/feed/'); and $feed->handle_content_type(); are in the custom script (text file) that you include from [include]script.php[/include] in your snews page.

This is how I see it... but I may be totally wrong.


Title: Re: [ADDON] Grab external feeds
Post by: lann on February 19, 2009, 05:58:22 pm
Did you try :

AT THE BEGINNING AND WITHOUT SPACE before <?
********************************************************************************your index page *********************
<?php require 'php/simplepie.inc'; ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ........ bla bla
Title: Re: [ADDON] Grab external feeds
Post by: lann on February 19, 2009, 06:16:31 pm
in external file - dont forget to add

<?php 

 $feed = new SimplePie('http://www...........com/search/rss.html?s=xxxxxx&l=xxxx&lid=xxxxxx');

?>

<?php foreach ($feed->get_items() as $item): ?>           


attention aux guillemets, si la page est en php il faut utiliser '   et non "
Title: Re: [ADDON] Grab external feeds
Post by: Sven on February 19, 2009, 06:29:20 pm
Salut les gars... c'est vraiment sympa de me donner un coup de main : c'est pour un pote que je cherche à mettre ça en place.

But for for all snoozers let's go on in english now.

Whatever I try I still get the same error:
Quote
Fatal error: Call to a member function get_permalink() on a non-object in D:\xampp\htdocs\richard\script.php on line 2

Im my index file I got:
Quote
<?php require 'php/simplepie.inc'; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
bla bla bla
In the script:
Quote
<div class="header">
      <h1><a href="<?php echo $feed->get_permalink(); ?>"><?php echo $feed->get_title(); ?></a></h1>
      <p><?php echo $feed->get_description(); ?></p>
   </div>
 <?php
// We'll process this feed with all of the default options.
$feed = new SimplePie('http://simplepie.org/blog/feed/');
?>
   <?php
   /*
   Here, we'll loop through all of the items in the feed, and $item represents the current item in the loop.
   */
   foreach ($feed->get_items() as $item):
   ?>
 
      <div class="item">
         <h2><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h2>
         <p><?php echo $item->get_description(); ?></p>
         <p><small>Posted on <?php echo $item->get_date('j F Y | g:i a'); ?></small></p>
      </div>
 
<?php endforeach; ?>
I thought I could make it fingers in the nose as we say in France, but no way: whatever I try give the same result. :P
Title: Re: [ADDON] Grab external feeds
Post by: lann on February 19, 2009, 06:42:24 pm
I think you have parse error. your script must be simple text file (with html extention) and with 4 lines of code. For example as mine is
******************************************************************
<?php 

 $feed = new SimplePie('http://www.xxxx.com/xxxx/rss.html?s=xxxx&l=xxxxx&lid=1111111');

?>
                     
        <TABLE width="100%">
     
                        <TR>
                <TD><?php foreach ($feed->get_items() as $item):
   ?>           
                 
         <h2><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h2>
         <p><?php echo $item->get_description(); ?></p>
               
                </TD>
            </TR>
            <TR>
                <TD>
                          
    <?php endforeach; ?>
              
                </TD>
            </TR>
       
        </TABLE>
************************************************************
that's all. nothing else. Then in admin area, when creating a new file you make [include] your_text_file.html [/include]
Title: Re: [ADDON] Grab external feeds
Post by: bikoz on February 19, 2009, 06:45:02 pm
If I understand the error message, the error is NORMAL: the $feed object (instance) should be initialized first.

In other words, $feed = new SimplePie('http://simplepie.org/blog/feed/'); should appears BEFORE $feed->get_permalink(); and friends.

Try to rewrite your script and it should work.

If it works, try to move the include back in the script (instead of snews's index.php file).
Title: Re: [ADDON] Grab external feeds
Post by: bikoz on February 19, 2009, 10:00:04 pm
I've just tried this setup on my dev machine with the code from SimplePie's documentation (http://simplepie.org/wiki/setup/sample_page): it works like a charm, I confirm.

No need to modify index.php, the include statement can be in your custom PHP script (the one you call from your actual snews page). You just have to take care of the actual path of simplepie.inc. By the way, you don't have to put it in specific dir (like "php" in the documentation), it can live in the same dir (root) as index.php and snews.php, no worries.

For example I've put it in a "simplepie" dir and I've renamed it to simplepie.inc.php: it still works as expected.

Same thing for the 'cache' dir: by default it has to be in the same dir as your custom script, but this can be changed by editing simplepie.inc, line 490 (the path is relative to your custom script, not simplepie.inc itself because of the include statement).

The ball's in your court!  :-)
Title: Re: [ADDON] Grab external feeds
Post by: Sven on February 20, 2009, 07:40:18 am
Oh boys! You made my day!
(http://www.zvcpibo.be/files/Image/peter_sellers_inspector_clouseau_pi.jpg)
Superb! Brilliant!
Magnifique !

Both of ya desserve a HUGE KARMA.

Garçon, s'il vous plaît : 1 Karma pour chacun de ces messieurs.
 8)
Title: Re: [ADDON] Grab external feeds
Post by: centered on February 22, 2009, 02:28:30 am
Surpisingly SmashingMagazine.com has a recent article with SimplePie

http://www.smashingmagazine.com/2009/02/20/ask-sm-css-smooth-page-scrolling-divs-of-equal-height-dealing-with-ie-6/ (http://www.smashingmagazine.com/2009/02/20/ask-sm-css-smooth-page-scrolling-divs-of-equal-height-dealing-with-ie-6/)

(http://88.198.60.17/images/css-coyier-3/FeedSmusher.png)

Code: [Select]
<?php

    
//get the simplepie library
    
require_once('inc/simplepie.inc');

    
//grab the feed
    
$feed = new SimplePie();

    
$feed->set_feed_url(array(
    
'http://feeds2.feedburner.com/CssTricks',
    
'http://smashingmagazine.com',
    ));

    
//enable caching
    
$feed->enable_cache(true);

    
//provide the caching folder
    
$feed->set_cache_location('cache');

    
//set the amount of seconds you want to cache the feed
    
$feed->set_cache_duration(1800);

    
//init the process
    
$feed->init();

    
//let simplepie handle the content type (atom, RSS...)
    
$feed->handle_content_type();

?>


Code: [Select]

<?php foreach ($feed->get_items() as $item): ?>

<div class="chunk">

<h4 style="background:url(<?php $feed $item->get_feed(); echo $feed->get_favicon(); ?>) no-repeat; text-indent: 25px; margin: 0 0 10px;"><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h4>

<p class="footnote">Source: <a href="<?php $feed $item->get_feed(); echo $feed->get_permalink(); ?>"><?php $feed $item->get_feed(); echo $feed->get_title(); ?></a> | <?php echo $item->get_date('j M Y | g:i a T'); ?></p>

</div>

<?php endforeach; ?>