AJAX – Build a RSS reader module with javascript and ASP/PHP

WARNING: THE CODE OF PROXY.PHP BELOW IS VULNERABLE. A HACKER CAN VIEW YOUR LOCALHOST FILES AND MORE (I AM ON RESEARCHING).PLEASE DO NOT USE IT UNTIL I FIX IT.
Today I read an interesting post about creating a RSS reader module with Javascript and ASP at following link http://dev.meotom.net/2010/3/5/Tao-box-doc-tin-RSS-don-gian-voi-Javascript-32C.htm . I test myself this module and its source code to see if it works. And below is my copy-and-paste product. The module works perfectly and is pretty beautiful.

However this code runs only on Windows host with ASP because it uses visual basic script to fetch content of RSS link from other site.

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
   If Not Request.QueryString("Url") = "" Then
       Session.CodePage = 65001
       Dim objXmlHttp
       Dim strHTML
       Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
       objXmlHttp.open "GET", Request.QueryString("Url"), False
       objXmlHttp.send
       strHTML = objXmlHttp.responseText
       Set objXmlHttp = Nothing
%>
       <base href="<%=Request.QueryString("Url")%>" />
<%= strHTML %>
<%
   End If
%>

I would like to use this module on Linux system with PHP, for example in this blog. Therefore I would like to convert that script above into PHP as following

<?php
header('Content-type: application/xml');
// Website url to open
$daurl = $_GET['url'];
echo file_get_contents($daurl);
?>

The code above will fetch content cross domain so that I can pass its content to AjaxRequest provided by http://www.ajaxtoolbox.com/ .

var RSS = {
    init: function(vUrl, vItem, SiteName, SiteUrl, divId) {
        AjaxRequest.get(
    	{
    	    "url": "/Web/Source/RSS%20Reader/proxy.php?url=" + vUrl
    	    , 'onLoading': function() {
				gmobj(divId).innerHTML = "<div class=\"mtAd_____loadingDiv\">Loading ...</div>";
				}
    		, 'onSuccess': function(req) {
    		    var strOut = "";
    		    var TotalItem = 0;
    		    strContent = req.responseXML;
    		    TotalItem = req.responseXML.getElementsByTagName('item').length;
    		    //alert(TotalItem);
    		    if (vItem > TotalItem) {
    		        vItem = TotalItem;
    		    }
    		    if (vItem <= 0) {
    		        vItem = 5
    		    }

    		    strOut += "<div class=\"mtAd_____otherBox\">";
    		    strOut += " <div class=\"mtAd_____headerBox\"><a href=\"" + SiteUrl + "\" target=\"blank\">RSS from " + SiteName + "</a></div>";
    		    strOut += " <div class=\"mtAd_____contentBox\" id=\"mtAd_____mtRSS\">";
    		    strOut += "     <table cellpadding=\"4\" cellspacing=\"6\" border=\"0\" width=\"100%\" class=\"mtAd_____tblDashboard\">";
    		    for (i = 0; i <= vItem-1; i++) {
    		        title = getNodeValue(strContent.getElementsByTagName('item').item(i).getElementsByTagName('title'));
    		        link = getNodeValue(strContent.getElementsByTagName('item').item(i).getElementsByTagName('link'));
    		        postdate = getNodeValue(strContent.getElementsByTagName('item').item(i).getElementsByTagName('pubDate'));

    		        strOut += "     <tr>";
    		        strOut += "         <td><a target=\"blank\" href=\"".concat(link).concat("\" title=\"").concat(title).concat("\">").concat(title).concat("</a><span class=\"mtAd_____lblPostDate\"> - ").concat(dateFormat(postdate, "isoDate")).concat("</span></td>");
    		        strOut += "     </tr>";
    		    }
    		    strOut += "     </table>";
    		    strOut += " </div>";
    		    strOut += "</div>";
    		    gmobj(divId).innerHTML = strOut;
    		}
    		, 'onError': function(req) {
    		    gmobj(vDivId).innerHTML = req.statusText;
    		}
    	});
    }
}

The function RSS.init() I will call where I would like to put my RSS module. vUrl is URL of RSS source, vItem is number of items should be displayed, SiteUrl is information of site which I want to put over the module, divId is name of div-class where I want to put module into.

<div style="width:192px;">
        <div id="divAd"></div>
        <link href="adStyle.css" media="all" type="text/css" rel="Stylesheet" />
        <script language="javascript" type="text/javascript" src="LibAd.js"></script>
        <script language="javascript" type="text/javascript">
            window.onload = RSS.init("http://hintdesk.com/feed/", 6, "Rongchaua.Net", "http://hintdesk.com", "divAd");
        </script>
    </div>

There are also a lot of help-functions which I do not write here. You can view the source code on links below
– In PHP: http://hintdesk.com/Web/Source/RSS%20Reader/RssReader.htm
– In ASP http://rongchaua.brinkster.net/RssReader.htm

Leave a Reply

Your email address will not be published. Required fields are marked *