| Mirage Source http://miragesource.net/forums/ |
|
| Adding an RSS Feed reader to your application. http://miragesource.net/forums/viewtopic.php?f=210&t=3473 |
Page 1 of 2 |
| Author: | Asrrin29 [ Tue Mar 11, 2008 12:55 am ] | ||
| Post subject: | Adding an RSS Feed reader to your application. | ||
RSS Feed Reader (*Special thanks to Fox for giving me the idea to do this.) ********************************************************** Difficulty (3/5 involves a lot of things outside of just copying and pasting code) An RSS Feed reader allows players to look at the news that gets updated on your website without having to open up the browser, and can be pointed at any feed you wish. A lot of games, such as Guild Wars and World of Warcraft, have implemented a feed reader into the main menu of the clients while waiting for things to load. Be warned though, this Feature requires that you have a few things set up. first you need a website, and then you need some sort of feed generator on your website. Most CRM's (such as Joomla, Mambo, phpnuke, wordpress, etc.) have built in feed readers or can have a reader installed via a module or component. Any custom designed html site likewise can use a php, java, or ajax script to create an rss feed, though I know a little less about these. Once you have an RSS feed you obviously need the news posts to generate content for the feed. Once you have all that, the feed will create an RSS friendly xml page that can be read by a feed reader. This xml page is the reason you can't just put a web control on your game and point it to the RSS feed. It will come back very strange looking, as a web rendering engine doesn't normally handle xml. so you need some code that will parse the xml into an html readable page. With that said this tutorial will have you create a couple files along with the code. first you need an rss.htm, a default.css (this is a cascading stylesheet to make it easier to format your feed to make it fit your game), and an rss.xsl. I will provide the code and a download of the files to make it easier for everyone. The rss.htm is created dynamically every time the code launches, so just make a blank file and that will be good. Code for default.css Code: body { font-family: Arial,sans-serif,verdana; margin:10px 0 10px 0; background-color: #FFFFFF; } h1{font-size:14px;} .tubuh{margin:5px;} p,span,.deskripsi,.properti{font-weight:normal,} p,span,.deskripsi,div{font-size:12px;text-align:justify;} .properti{font-size:10px;color:#ffffff;} Code for rss.xsl Code: <?xml version="1.0" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:atom="http://purl.org/atom/ns#" exclude-result-prefixes="atom" > <xsl:output indent="yes" method="xml" encoding="UTF-8" /> <xsl:template match="//atom:feed"> <rss version="2.0"> <channel> <title><xsl:value-of select="atom:title"/></title> <link><xsl:value-of select="atom:link[@rel='alternate']/@href"/></link> <description><xsl:value-of select="atom:tagline"/></description> <generator><xsl:value-of select="atom:generator"/> <xsl:value-of select="atom:generator/@version" /></generator> </channel> <xsl:call-template name="items"/> </rss> </xsl:template> <xsl:template name="items"> <xsl:for-each select="atom:entry"> <item> <title><xsl:value-of select="atom:title"/></title> <link><xsl:value-of select="atom:link"/><xsl:value-of select="atom:link[@rel='alternate']/@href"/></link> <description><xsl:value-of select="atom:description"/><xsl:value-of select="atom:summary" /><xsl:value-of select="atom:content"/></description> <pubDate><xsl:value-of select="atom:pubDate"/><xsl:value-of select="atom:issued"/></pubDate> </item> </xsl:for-each> </xsl:template> <xsl:template match="/rss/channel"> <rss version="2.0"> <channel> <title><xsl:value-of select="title"/></title> <link><xsl:value-of select="link"/></link> <description><xsl:value-of select="description"/></description> <generator><xsl:value-of select="generator"/></generator> </channel> <xsl:call-template name="itemsc"/> </rss> </xsl:template> <xsl:template name="itemsc"> <xsl:for-each select="item"> <item> <title><xsl:value-of select="title"/></title> <link><xsl:value-of select="link"/></link> <description><xsl:value-of select="description"/></description> <pubDate><xsl:value-of select="pubDate"/></pubDate> </item> </xsl:for-each> </xsl:template> </xsl:stylesheet> Once you have these three files you can open up your code and open up the form where you wish to place the RSS feed. I opted to place it in frmMainMenu, but you can put it anywhere. Now you need to add a component for the web browser. For this you have a few choices. If you choose to use IE7 you need to browse to the C:\WINDOWS\system32\ folder and find shdocvw.dll which will replace ieframe.dll for Microsoft Internet Controls. If you use IE6 you just use ieframe.dll. If you wish to use the gecko rendering engine (what Firefox uses) then head over to http://www.iol.ie/~locka/mozilla/mozilla.htm and download the latest activeX object. it will function exactly as MIC will, only with a different rendering engine. A note on the Mozilla control however, I saw that it caused VB6 to error out when attempting to click a link from the feed, so I ended up using MIC. if anyone can find the problem, let me know. Create a web browser box using the control you just enabled and name it wb. Disable any toolbars you don't want showing up. Once you have that all done go to Private Sub Form_Load() and paste the following: Code: Dim strurl As String, NamaFile As String, DataRss As String, strChannelTitle As String Dim strChannelDescription As String, strChannelLink As String, strChannelImageTitle As String Dim strChannelImageUrl As String, strChannelImageLink As String, strChannelImageWidth As String Dim strChannelImageHeight As String, strItemTitle As String, strItemLink As String Dim strItemDescription As String, strItemcontent As String, strItempubDate As String Dim arrItemTitle() As String, arrItemLink() As String, arrItemDescription() As String Dim A As Integer Dim Title As String strurl = "http://yourgame.com" Dim objXML, objXSL, objOutputXMLDoc, channelNodes, entry, images, itemNodes, Item NamaFile = App.Path & "\rss.htm" Open NamaFile For Output As #1 Print #1, "<html>" Print #1, "<head>" Print #1, "<title>Extreme RSS</title>" Print #1, "<link rel=""stylesheet"" href=""default.css"" type=""Text/css"" />" Print #1, "</style></head>" Print #1, "<body>" Print #1, "<div class=""tubuh"">" If strurl <> "" Then If Left(strurl, 7) = "http://" Then strurl = Right(strurl, Len(strurl) - 7) strurl = "http://" & strurl Set objXML = CreateObject("MSXML2.DOMDocument") Set objXSL = CreateObject("MSXML2.DOMDocument") objXML.async = False objXSL.async = False objXML.SetProperty "ServerHTTPRequest", True If objXML.Load(strurl) Then objXSL.Load App.Path & ("\rss.xsl") DataRss = objXML.transformNode(objXSL) Else Print #1, " Error: " & objXML.parseError.reason & "<br />" End If Set objXML = Nothing Set objXSL = Nothing Set objOutputXMLDoc = CreateObject("MSXML2.DOMDocument") objOutputXMLDoc.loadXML DataRss If (objOutputXMLDoc.parseError.errorCode <> 0) Then Print #1, " XML error: " & objOutputXMLDoc.parseError.reason Else Set channelNodes = objOutputXMLDoc.selectNodes("//channel/*") For Each entry In channelNodes If entry.tagName = "title" Then strChannelTitle = entry.Text ElseIf entry.tagName = "description" Then strChannelDescription = entry.Text ElseIf entry.tagName = "link" Then strChannelLink = entry.Text End If Next Set channelNodes = objOutputXMLDoc.selectNodes("//image/*") For Each images In channelNodes If images.tagName = "title" Then strChannelImageTitle = images.Text ElseIf images.tagName = "url" Then strChannelImageUrl = images.Text ElseIf images.tagName = "link" Then strChannelImageLink = images.Text ElseIf images.tagName = "width" Then strChannelImageWidth = images.Text ElseIf images.tagName = "height" Then strChannelImageHeight = images.Text End If Next Print #1, "<h1>" & strChannelTitle & "</h1>" If strChannelImageUrl <> "" Then Print #1, "<img align=""left"" vspace=""10"" hspace=""10"" title="" & strChannelImageTitle & "" src="" & strChannelImageUrl & "" width="" & strChannelImageWidth & "" height="" & strChannelImageHeigh & "" alt="" & strChannelImageTitlee & "" />" End If Print #1, "<span>" & strChannelDescription; 7; "</span><br />" Print #1, "<span class=""properti""><a href="" & strChannelLink & "">" & strChannelTitle & "</a></span>" Print #1, "<hr>" Set itemNodes = objOutputXMLDoc.selectNodes("//item/*") For Each Item In itemNodes If Item.tagName = "title" Then strItemTitle = strItemTitle & Item.Text & "#%#" ElseIf Item.tagName = "link" Then strItemLink = strItemLink & Item.Text & "#%#" ElseIf Item.tagName = "description" Then strItemDescription = strItemDescription & Item.Text & "#%#" ElseIf Item.tagName = "content" Then strItemcontent = strItemcontent & Item.Text & "#%#" ElseIf Item.tagName = "pubDate" Then strItempubDate = strItempubDate & Item.Text & "#%#" End If Next arrItemTitle = Split(strItemTitle, "#%#") arrItemLink = Split(strItemLink, "#%#") arrItemDescription = Split(strItemDescription, "#%#") If UBound(arrItemTitle) = UBound(arrItemLink) And UBound(arrItemLink) = UBound(arrItemDescription) Then For A = 0 To UBound(arrItemTitle) - 1 strItemLink = arrItemLink(A) strItemTitle = arrItemTitle(A) strItemDescription = arrItemDescription(A) If strItemLink <> "" Then Title = "<a target=""_blank"" title= """ & strItemTitle & """ href=""" & strItemLink & """ >" & strItemTitle & "</a><br>" & vbCrLf Else Title = strItemTitle & "<br>" & vbCrLf End If Print #1, "<h1>" & Title & "</h1>" Print #1, "<div class=""deskripsi"">" & strItemDescription & "</div><br />" Print #1, "<span class=""properti"">" & Left(Replace(strItemLink, "http://", "", 1, -1, 1), 25) & "</span><br />" Next End If End If Else Print #1, "<h1>Your game name here</h1>" End If Print #1, "</div>" Print #1, "</body>" Print #1, "</html>" Close #1 wb.Navigate NamaFile This is the code that will parse the xml into the rss.htm and then point the browser control at it. Be sure to replace the contents of strurl with your own for your rss feed. This will give you a basic white background black lettering RSS feed, and you can change this very simply by changing the default.css file. Now the only thing you have to do is learn a little CSS P.S. I downloaded the xml parsing code from Bowo Ekowidodo at pscode.com. It was in pretty rough shape, he didn't use Option Explicit so I had to change a whole crap ton of it to get it to work in standard VB6 language. But I thought I should include my sources.
|
|||
| Author: | Coke [ Tue Mar 11, 2008 1:53 am ] |
| Post subject: | Re: Adding an RSS Feed reader to your application. |
This is way different to mine xD Mine just parses an uber simple .rss document and recognises a few html commands into an RTB ^_^ Looks complicated ;O |
|
| Author: | Rezeyu [ Tue Mar 11, 2008 1:54 am ] |
| Post subject: | Re: Adding an RSS Feed reader to your application. |
..whats wrong with just reading from a news.txt off the domain.. ? |
|
| Author: | Coke [ Tue Mar 11, 2008 1:57 am ] |
| Post subject: | Re: Adding an RSS Feed reader to your application. |
Doesn't parse html, and RSS feeds are the industry standard. Also, you can do cool things like the news list on my main menu thingie with RSS :] |
|
| Author: | Lea [ Tue Mar 11, 2008 1:58 am ] |
| Post subject: | Re: Adding an RSS Feed reader to your application. |
this is much cooler, and allows formatted text |
|
| Author: | Rezeyu [ Tue Mar 11, 2008 1:59 am ] |
| Post subject: | Re: Adding an RSS Feed reader to your application. |
..so does text. I have it set up to parse everything, and apply selbold/selitalic/etc. |
|
| Author: | Coke [ Tue Mar 11, 2008 2:07 am ] |
| Post subject: | Re: Adding an RSS Feed reader to your application. |
Fox wrote: Doesn't parse html, and RSS feeds are the industry standard. Also, you can do cool things like the news list on my main menu thingie with RSS :] You can feed straight from say a WordPress Blog, a phpbb forum topic RSS monitor, joomla, anything - it just allows you to interface with 99% of the interwebs news feeds with no hassle. |
|
| Author: | Asrrin29 [ Tue Mar 11, 2008 3:36 am ] |
| Post subject: | Re: Adding an RSS Feed reader to your application. |
Fox wrote: This is way different to mine xD Mine just parses an uber simple .rss document and recognises a few html commands into an RTB ^_^ Looks complicated ;O What this code does is basically parses out the rss xml into a temporary html page that is then loaded onto a web browser control. The html is dynamically created using the xml parser code plus the rss.xsl file, and then the html in turn is formated by a cascading stylesheet that can be set to change anything on the website from backgrounds to text without having to recode anything. Rezeyu wrote: ..whats wrong with just reading from a news.txt off the domain.. ? RSS is technology that is already freely available to pretty much any web space currently on the internet. any .asp, .php, or coldfusion or ajax based website has the ability to seamlessly integrate an rss feed into the code with minimal hassle. with a news.txt file, you have to custom code how to generate that txt file, where with rss, the code is already there, and a web standard at that. With this you could put this into an engine and everyone will be able to use this feature, rather then just those that make a special file. |
|
| Author: | James [ Tue Mar 11, 2008 5:22 am ] |
| Post subject: | Re: Adding an RSS Feed reader to your application. |
According to what you just said, wouldn't it be simpler for me to simply stick in a web control and load ANY web page in ANY language? I don't see the advantage of this method. |
|
| Author: | Asrrin29 [ Tue Mar 11, 2008 11:31 am ] |
| Post subject: | Re: Adding an RSS Feed reader to your application. |
James wrote: According to what you just said, wouldn't it be simpler for me to simply stick in a web control and load ANY web page in ANY language? I don't see the advantage of this method. RSS gets automatically generated every time a new article or post is created on the targeted website. there is no need to manually synchronize everything. If you've ever used Live Bookmarks on firefox that is an example of RSS. This feature is easier then alot of people are making it out to be. You download the rss files I provided, add a web control to your game, and copy past the code into your sub FormLoad(). The complicated thing comes when you want to change the color of the text, the background of the feed, or whatever. then all you do is edit the default.css with some CSS formating and you are good to go. |
|
| Author: | grimsk8ter11 [ Sat Apr 19, 2008 2:53 am ] |
| Post subject: | Re: Adding an RSS Feed reader to your application. |
If i find it, i actually have the complete code to fox's RSS, since he uses what we used in cryshall. We had an uber simple way to do HTMl, but i need to find the tutorial i made |
|
| Author: | Coke [ Sat Apr 19, 2008 12:58 pm ] |
| Post subject: | Re: Adding an RSS Feed reader to your application. |
Noooo Grim, the secrets, you keeps them!! :O |
|
| Author: | Lea [ Sat Apr 19, 2008 1:01 pm ] |
| Post subject: | Re: Adding an RSS Feed reader to your application. |
Mirage isn't about secrets ;-; It's about sharing what you can do with others so others can do something and share what they do... But it usually doesn't turn out that way |
|
| Author: | grimsk8ter11 [ Sat Apr 19, 2008 3:47 pm ] |
| Post subject: | Re: Adding an RSS Feed reader to your application. |
haha if you use the HTML part, i wont release it, but i was just sayyying, its there lol. |
|
| Author: | Coke [ Sat Apr 19, 2008 11:38 pm ] |
| Post subject: | Re: Adding an RSS Feed reader to your application. |
KEEEPS THEMS!!!!! ;O;O;O xD |
|
| Author: | grimsk8ter11 [ Sun Apr 20, 2008 4:24 am ] |
| Post subject: | Re: Adding an RSS Feed reader to your application. |
I demand a purple name and 4 cookies and maybe for you to use MSN once every few years? |
|
| Author: | Coke [ Sun Apr 20, 2008 1:49 pm ] |
| Post subject: | Re: Adding an RSS Feed reader to your application. |
I'm always on msn >_>; |
|
| Page 1 of 2 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|