Topic: [Snippet] NewsParserX (version 0.9)  (Read 16849 times)

Pages: [1] 2  All   Go Down

#1: 15-Jan-2006, 01:32 PM

Foundation

OpenGeek
MODx Co-Founder
Posts: 6,985

damn accurate caricatures...

WWW
Here's an old NewsParser snippet variation I created back at Etomite that does work with multiple instances per page.

Extract this into the directory /assets/snippets/newsparserx/ and then copy and paste the newslisting.snippet.txt contents into a new snippet that you can call from your pages.

Sample Call
Code:
$snippetOutput .= $modx->runSnippet('NewsParserX',array('url'=>'http://domain.tld/feed_url'));

[UPDATE: version 0.9 posted 2006-04-02 to address html entities in complex feed URLs, e.g. those will query string parameters]

* newsparserx.0.9.zip (5.75 KB - downloaded 645 times.)
« Last Edit: 2-Apr-2006, 01:03 PM by OpenGeek »
Jason Coward
MODx Co-Founder
xPDO Founder
CTO @ Collabpad
work productively.
work intelligently.
work together.
Light is just a vibration of a note too. Everything is. You've got to keep that in mind.
  Frank Zappa

#2: 15-Jan-2006, 04:53 PM

Marketing & Design Team

davidm
MODx evangelist
Posts: 7,073

The best way to predict the future is to invent it

WWW
Waow Jason, just when we were discussing this !

That was fast !!!
Thanks Smiley
.: nodeo.net : Pour un web libre, moderne et ouvert ! :: david-molliere.net : Suivez en "live" mes expérimentations et billets sur les CMS et autres applications web :.

*** Forums modxcms.fr Participez à l'élaboration du site MODx francophone ! ***

! Nouveau !  En live, ne manquez pas les news de modxcms.fr sur Twitter   ! Nouveau !

MODx est l'outil idéal pour les developpeurs et webdesigners qui cherchent un framework de gestion de contenu hautement flexible et performant, tout en étant simple d'accès pour les utilisateurs finaux.

Config : Apache 2.2.8 - MySQL 5.0.67 - PHP 5.2.8 | Debian 4.0 (Etch)

Réalisations sous MODx : | pargade-notaires.fr | soleil.info | gican.asso.fr | michelez-notaires.com | amadom.gerondicap.com | jocelyne-violet.net

#3: 31-Jan-2006, 09:23 AM

Coding Team

sottwell
Posts: 10,556

WWW
I've never worked with newsfeeds before.  How would I get the rss feed from here?

Code:
http://modxcms.com/forums/index.php?sa=recent;type=rss2;action=.xml&limit=20

Is this the url I use? Do I need to make another snippet to call the NewsParserX snippet, or can I call the NewsParserX snippet directly in my template?

sottwell.com has moved to a lovely Solaris 10 server!
Log in username guest, password guestuser.
Templates are now becoming available at http://sottwell.com/templates.html

#4: 31-Jan-2006, 09:48 AM

Coding Team

sottwell
Posts: 10,556

WWW
To answer my own questions: Yes, and yes.

I created a second snippet named ParseNews, with just this code:

Code:
return $modx->runSnippet('NewsParserX',array('url'=>'http://modxcms.com/forums/index.php?sa=recent;type=rss2;action=.xml&limit=6'));

Called ParseNews in my template.

And the results:
http://www.sottwell.com
sottwell.com has moved to a lovely Solaris 10 server!
Log in username guest, password guestuser.
Templates are now becoming available at http://sottwell.com/templates.html

#5: 31-Jan-2006, 10:15 AM

Coding Team

sottwell
Posts: 10,556

WWW
I have a question.  The links open in the same browser window, taking the user out of my site.  How would I go about having the links open in a new window?

I hacked the newsparserx.inc.php file adding

Code:
target="_blank"

to all the links. Is there a better way?
« Last Edit: 31-Jan-2006, 10:25 AM by sottwell »
sottwell.com has moved to a lovely Solaris 10 server!
Log in username guest, password guestuser.
Templates are now becoming available at http://sottwell.com/templates.html

#6: 31-Jan-2006, 10:38 AM

Marketing & Design Team

davidm
MODx evangelist
Posts: 7,073

The best way to predict the future is to invent it

WWW
Thanks Susan for sharing all this, pretty useful !

And, by the way, nice port of YAML theme : nice clean looking template Smiley
.: nodeo.net : Pour un web libre, moderne et ouvert ! :: david-molliere.net : Suivez en "live" mes expérimentations et billets sur les CMS et autres applications web :.

*** Forums modxcms.fr Participez à l'élaboration du site MODx francophone ! ***

! Nouveau !  En live, ne manquez pas les news de modxcms.fr sur Twitter   ! Nouveau !

MODx est l'outil idéal pour les developpeurs et webdesigners qui cherchent un framework de gestion de contenu hautement flexible et performant, tout en étant simple d'accès pour les utilisateurs finaux.

Config : Apache 2.2.8 - MySQL 5.0.67 - PHP 5.2.8 | Debian 4.0 (Etch)

Réalisations sous MODx : | pargade-notaires.fr | soleil.info | gican.asso.fr | michelez-notaires.com | amadom.gerondicap.com | jocelyne-violet.net

#7: 31-Jan-2006, 10:49 AM

Coding Team

sottwell
Posts: 10,556

WWW
The template is clean enough, but the CSS is a major ... something. The main css file calls three or four others, plus he provides css files for a couple of different layouts using the same template. I've been very careful to leave the basic html alone, and to leave the css completely alone.  I just add what I need for the various forms and stuff I've added.
sottwell.com has moved to a lovely Solaris 10 server!
Log in username guest, password guestuser.
Templates are now becoming available at http://sottwell.com/templates.html

#8: 31-Jan-2006, 11:46 AM

Foundation

OpenGeek
MODx Co-Founder
Posts: 6,985

damn accurate caricatures...

WWW
The best way to modify for opening links in a new browser window, if you are interested in keeping it XHTML/CSS compliant, is to use the rel attribute to describe links to be opened in a new window in a standard way.  A common approach is using rel="external" to describe links like this, and then use a script like this to do the work:
Code:
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;

Make sure the script is loaded in the HEAD of your document (either from an external file registered as a startup script or putting the script in the HEAD of your template), and in browsers that support JS and the DOM methods above, you'll get appropriate navigation, and will be ready to support browsers that might not be able to follow the old target="_blank" links (think mobile devices and other specialized browser platforms) with full compliancy.
Jason Coward
MODx Co-Founder
xPDO Founder
CTO @ Collabpad
work productively.
work intelligently.
work together.
Light is just a vibration of a note too. Everything is. You've got to keep that in mind.
  Frank Zappa

#9: 31-Jan-2006, 12:33 PM

Foundation

rthrash
Posts: 11,353

WWW
Jason, I think you need to make a plugin out of that... would be killer!
MODx is a content managmeent framework that allows web professionals to turn over sites to end-users for daily maintenance without worrying. Please help us help you when asking for assistance and read the wiki. Searching the forums from the top level helps, too.
Ryan Thrash
MODx Co-Founder
Principal @ Collabpad
work productively.
work intelligently.
work together.

#10: 20-Feb-2006, 08:32 AM

Coding Team

sottwell
Posts: 10,556

WWW
If it can't connect to the given URL it puts up a nasty MODx error page.  I haven't been able to get it to simply return false on failure to connect.
sottwell.com has moved to a lovely Solaris 10 server!
Log in username guest, password guestuser.
Templates are now becoming available at http://sottwell.com/templates.html

#11: 23-Feb-2006, 03:17 PM

gigli
Posts: 28

WWW
Thank you very much for this useful snippet!!

#12: 22-Mar-2006, 01:05 PM


Trance
Posts: 46

I love MODx!

WWW
I got a bit of trouble to read out a RSS feed from my IPB forums.  This is the URL

http://gamerscollective.com/forums/index.php?act=rssout&id=3

Code:
return $modx->runSnippet('NewsParserX',array('url'=>'http://gamerscollective.com/forums/index.php?act=rssout&id=3'));

This is what I get when I call the snippet: http://stage.server02.com/modx/index.php?id=39 (please look at the link)

It is a valid RSS feed, since my RSS reader picks it up no problem. Only  am concerned about the "?act=" part in the URL.  Any thoughts on how to kill this bird ??

#13: 22-Mar-2006, 02:10 PM

Foundation

OpenGeek
MODx Co-Founder
Posts: 6,985

damn accurate caricatures...

WWW
I got a bit of trouble to read out a RSS feed from my IPB forums.  ...
It is a valid RSS feed, since my RSS reader picks it up no problem. Only  am concerned about the "?act=" part in the URL.  Any thoughts on how to kill this bird ??

Hmmm, same result when I try to load it as well.  I'll have to look into the problem, but I'm a little swamped today.  If you don't hear from me in a couple of days, feel free bump this thread to remind me.  Of course if you figure out the issue in the meantime, I'm sure you'll share that as well...
 Wink
Jason Coward
MODx Co-Founder
xPDO Founder
CTO @ Collabpad
work productively.
work intelligently.
work together.
Light is just a vibration of a note too. Everything is. You've got to keep that in mind.
  Frank Zappa

#14: 28-Mar-2006, 03:30 PM

Duane
Posts: 51

I'm well on my way to proving my complete stupidity...but, I'm getting nowhere being stubborn and trying to figure this out on my own.

I can't seem to wrap my brain around this whole process. I followed the instructions in the original message, and got...nothing.

I then followed Susan Ottwell's followup procedure, and at least got "no entries found" to display.  Undecided

That's where I've been for 2 hours now.

So, here's what I've done:

1.  I put the contents of the zip file into /assets/snippets/newsparserx

2. I created a new snippet called NewsParserX and pasted the newslisting.snippet.txt into it.

Then, I put [[NewsParserX]] into the template.

Nothing.

So, I followed the slightly different procedure spelled out by Susan Ottwell, and created a snippet called "parseNews" with the return $modx->runSnippet line as it's only content, and put [[parseNews]] into my template. That gets me the "no entries found" output.

I can't seem to figure out, step by step, what I should be doing. And, the original instructions from Jason seem substantially different from what Susan did. What goes where? And, what should I put in the template?

Thanks. Sorry to be dumb.

Duane

#15: 28-Mar-2006, 03:40 PM

Coding Team

garryn
Posts: 1,391

WWW
Hi Duane,

Are you passing a URL in the snippet call? If [[NewsParserX]] returns 'No Entries Found' then, for all intents and purposes, I think the snippet is working. You just need to tell it where to get the feed  Wink

So, something like this should work:
Code: (Snippet Call)
[[NewsParserX? &url=`http://domain.tld/feed_url`]]

#16: 28-Mar-2006, 03:53 PM

Duane
Posts: 51

Hi Duane,

Are you passing a URL in the snippet call? If [[NewsParserX]] returns 'No Entries Found' then, for all intents and purposes, I think the snippet is working. You just need to tell it where to get the feed  Wink

So, something like this should work:
Code: (Snippet Call)
[[NewsParserX? &url=`http://domain.tld/feed_url`]]

Thanks for the quick reply, Garry.

In order to try and eliminate as many variables in my troubleshooting as possible, I used the exact structure of Susan's snippet call (figuring modx forums were a known source of a feed). So, as she spelled out, I created a snippet called "parseNews" with this content:

Code:
return $modx->runSnippet('NewsParserX',array('url'=>'http://modxcms.com/forums/index.php?sa=recent;type=rss2;action=.xml&limit=6'));

Then, I put [[parseNews]] into my template. This is what yields the "no entries" display.

So, the URL I'm passing is the identical one to Susan's.

Duane

#17: 28-Mar-2006, 04:23 PM

Coding Team

garryn
Posts: 1,391

WWW
Hmm, from the error messages my local install is giving me and just reading some of the previous posts in this thread - I think NewsParserX has an issue with RSS feeds that have a question mark in them (it's actually crashing Apache for me, lol!)

Could you try a URL that doesn't have a question mark, just to see if this is the issue - I know the BBC RSS feeds are okay (www.bbc.co.uk)

Thanks, Garry

#18: 28-Mar-2006, 04:35 PM

Duane
Posts: 51

Hmm, from the error messages my local install is giving me and just reading some of the previous posts in this thread - I think NewsParserX has an issue with RSS feeds that have a question mark in them (it's actually crashing Apache for me, lol!)

Could you try a URL that doesn't have a question mark, just to see if this is the issue - I know the BBC RSS feeds are okay (www.bbc.co.uk)

Thanks, Garry

Here's the content of my snippet now:

Code:
return $modx->runSnippet('NewsParserX',array('url'=>'http://www.bbc.co.uk'));

Sadly, the same result:  "no entries found"

~sigh

#19: 28-Mar-2006, 04:47 PM

Coding Team

garryn
Posts: 1,391

WWW
Sorry Duane, my fault. I meant get an RSS feed off the BBC website:

Try the one below:
Code: (BBC News RSS Feed)
http://www.bbc.co.uk/go/homepage/int/ne/nrss/log/i/-/news/rss/newsonline_uk_edition/front_page/rss.xml

#20: 28-Mar-2006, 10:42 PM

Duane
Posts: 51

Thanks for all the help, Garry. I abandoned NewsParserX and used the old etomite snippet, which worked right off the bat.

Sorry Duane, my fault. I meant get an RSS feed off the BBC website:

Try the one below:
Code: (BBC News RSS Feed)
http://www.bbc.co.uk/go/homepage/int/ne/nrss/log/i/-/news/rss/newsonline_uk_edition/front_page/rss.xml

Same result.

Just to re-orient, here's how things are set up:

1.  In /assets/snippets/newsparserx, I placed the files contained in the zip on the orginal post (a php and a txt file).

2.  I pasted the latest code from the newslisting snippet into the newslisting snippet in the resources tab, and uploaded the snippet txt file to /assets/snippets/newslisting.

3.  I created a snippet called newsParser and pasted this code which came from Susan's post:
Code:
return $modx->runSnippet('NewsParserX',array('url'=>'http://www.bbc.co.uk/go/homepage/int/ne/nrss/log/i/-/news/rss/newsonline_uk_edition/front_page/rss.xml'));

4.  I put [[newsParser]] into my xhtml template code in the div where it's placed in the layout.

What I get is two "no entries found" lines displaying.  If you want to take a look, the URL is:

http://www.ideabankpreview.com/acn (it's at the bottom of the page, center column).

This is still on the staging server, and I'm just beginning to construct the page.

Thanks again,
Duane
« Last Edit: 30-Mar-2006, 08:51 AM by Duane »
Pages: [1] 2  All   Go Up
0 Members and 1 Guest are viewing this topic.