PDA

View Full Version : Author in gAjax RSS Feeds Displayer?



ShieldofChaos
01-27-2012, 10:03 AM
1) Script Title:
gAjax RSS Feeds Displayer
2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex18/gajaxrssdisplayer.htm
3) Describe problem:

Hey everyone!

I have recently used gAjax RSS Feeds Displayer from Dynamic Drive (using the third example). Everything works perfectly, it successfully grabbed my RSS feeds.

Right now, I would like to put in an author to be display inside so people will know who is the one that posted the feeds but I just can't seem to get it at all.

Please help!

Extra note: The RSS feeds is from a forum.

jscheuer1
01-27-2012, 02:55 PM
You cannot get the author from the feed item unless it has one. I made up a demo with a modified gfeedfetcher.js that looks for:

item author
item copyright
feed author
feed copyright

in that order, returning:

unavailable

if none of those are found.

Of the three example feeds on the demo page only a few items in the second feed (the socialfeed) returned an author. In those three cases it was the item author.

That said, you can try the modified script:

4290

It allows you to put in the on page code, for example:


<script type="text/javascript">

var socialfeed=new gfeedfetcher("example2", "example2class", "_new")
socialfeed.addFeed("Slashdot", "http://rss.slashdot.org/Slashdot/slashdot") //Specify "label" plus URL to RSS feed
socialfeed.addFeed("Digg", "http://digg.com/rss/index.xml") //Specify "label" plus URL to RSS feed
socialfeed.displayoptions("label datetime snippet author") //show the specified additional fields
socialfeed.setentrycontainer("div") //Display each entry as a DIV
socialfeed.filterfeed(6, "label") //Show 6 entries, sort by label
socialfeed.init() //Always call this last

</script>

And it will try to find the author as described above. It will add this HTML at the end of the item's HTML:


<br/><span class="authorfield">Author: something, perhaps unavailable</span>

ShieldofChaos
01-27-2012, 03:55 PM
Thanks a bunch, trying it now. Will edit the post after trying.

Reason for this is because when I use Feed2JS and Feedburner, both of them returned the Author name who created the feeds. However I do not like both of them (weird huh haha!).

ShieldofChaos
01-27-2012, 04:06 PM
Oh my gosh! The author has displayed itself! Thanks! But can I be a bit more greedy and ask for a little more request? :p

Right now the feeds are displaying as this,


10th test haha Friday, January 27, 2012 6:45:16 PM
hi
Author: Admin

No modification is done to the js at all. However, since I am only good at HTML, I can't do this part on my own.

What I would like is for the feeds to display in this manner,


10th test haha
Friday, January 27, 2012 6:45:16 PM by Admin
hi


How will it be possible? :o Do we have to go to the js to accomplish this?

======

Edit: Alright, after looking through the JS and doing many trials and errors, I finally get it. To get the output I want, I simply just look at the RSSOUTPUT line!

This is my final code that fulfill the criteria of what I want,


gfeedfetcher.prototype._displayresult=function(feeds){
var rssoutput=(this.itemcontainer=="<li>")? "<ul>\n" : ""
gfeedfetcher._sortarray(feeds, this.sortstring)
for (var i=0; i<feeds.length; i++){
var itemtitle="<a href=\"" + feeds[i].link + "\" target=\"" + this.linktarget + "\" class=\"titlefield\">" + feeds[i].title + "</a>" + "<br />"
var itemlabel=/label/i.test(this.showoptions)? '<span class="labelfield">['+this.feeds[i].ddlabel+']</span>' : " "
var itemdate=gfeedfetcher._formatdate(feeds[i].publishedDate, this.showoptions)
var itemdescription=/description/i.test(this.showoptions)? "<br />"+feeds[i].content : /snippet/i.test(this.showoptions)? "<br />"+feeds[i].contentSnippet : ""
var itemauthor = /author/i.test(this.showoptions)? "<span class='authorfield'> by "+(feeds[i].author || feeds[i].copyright || feeds.author || feeds.copyright || 'unavailable')+ "</span>": '';
rssoutput+=this.itemcontainer + itemtitle + " " + itemlabel + " " + itemdate + "" + itemauthor + "\n" + itemdescription + this.itemcontainer.replace("<", "</") + "\n\n"
}
rssoutput+=(this.itemcontainer=="<li>")? "</ul>" : ""
this.feedcontainer.innerHTML=rssoutput
}

It will be good if you inspect those in red and see if there are any problems with it. I tested it and it worked perfectly.

Additionally, I have a suggestion is to put this "Author" id somewhere inside the gAjax RSS Feeds Displayer page since I believe there are people out there like me who would love to display the author of the RSS feeds.

Thanks alot! :cool:

jscheuer1
01-27-2012, 05:32 PM
Looks good, and since it works - Great!