Thursday, January 25, 2018

RSS Reader Using HTML and Javascript

File: rssGet.php

<?php
//get the q parameter from URL
$q=$_GET["q"];

//find out which feed was selected
if($q=="MS") {
 $xml=("https://announce.ssis.edu.vn/?call_custom_simple_rss=1&csrp_posts_per_page=3&csrp_orderby=date&csrp_order=DESC&
csrp_cat=1");
} elseif($q=="HS") {
 $xml=("https://announce.ssis.edu.vn/?call_custom_simple_rss=1&csrp_posts_per_page=3&csrp_orderby=date&csrp_order=DESC&
csrp_cat=4");
}

$xmlDoc = new DOMDocument();
$xmlDoc->load($xml);

//get elements from "<channel>"
$channel=$xmlDoc->getElementsByTagName('channel')->item(0);
$channel_title = $channel->getElementsByTagName('title')
->item(0)->childNodes->item(0)->nodeValue;
$channel_link = $channel->getElementsByTagName('link')
->item(0)->childNodes->item(0)->nodeValue;
$channel_desc = $channel->getElementsByTagName('description')
->item(0)->childNodes->item(0)->nodeValue;

//output elements from "<channel>"
//echo("<p><a href='" . $channel_link
//  . "'>" . $channel_title . "</a>");
//echo("<br>");
//echo($channel_desc . "</p>");

//get and output "<item>" elements
$x=$xmlDoc->getElementsByTagName('item');
for ($i=0; $i<=2; $i++) {
 $item_title=$x->item($i)->getElementsByTagName('title')
 ->item(0)->childNodes->item(0)->nodeValue;
 $item_link=$x->item($i)->getElementsByTagName('link')
 ->item(0)->childNodes->item(0)->nodeValue;
 $item_desc=$x->item($i)->getElementsByTagName('description')
 ->item(0)->childNodes->item(0)->nodeValue;
 echo ("<a href='" . $item_link
 . "'>" . $item_title . "</a>");
 echo ("<br>");
 echo ($item_desc);
}
?>


File: rssShow.php

<html>
<head>
<style>
body {
 font-family: arial;
}
a {
 text-decoration: none;
 text-size: x-small;
 color: #333;
}
td {
 padding: 10px;
}
</style>

</head>
<body>
<table><tr>
 <th><a href="https://announce.ssis.edu.vn/middle-school"><font color="#FF5733">Middle School</font></a></th>
 <th><a href="https://announce.ssis.edu.vn/high-school"><font color="#FFC300">High School</font></a></th>
 </tr><tr>
 <td style="border-right: 3px solid orange;">
   <div id="rssOutputLeft">RSS-feed for MS ...</div>
 </td><td>
   <div id="rssOutputRight">RSS-feed for HS ...</div>
 </td>
</tr></table>

<script>
function showRSS(str,id) {
 if (str.length==0) {
   document.getElementById(id).innerHTML="";
   return;
 }
 if (window.XMLHttpRequest) {
   // code for IE7+, Firefox, Chrome, Opera, Safari
   xmlhttp=new XMLHttpRequest();
 } else {  // code for IE6, IE5
   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
 xmlhttp.onreadystatechange=function() {
   if (this.readyState==4 && this.status==200) {
     document.getElementById(id).innerHTML=this.responseText;
   }
 }
 xmlhttp.open("GET","rssGet.php?q="+str,true);
 xmlhttp.send();
}

showRSS("MS","rssOutputLeft");
showRSS("HS","rssOutputRight");

</script>


</body>
</html>



iFrame option

For those websites that will only take a simple html, provide them with an iframe
<iframe src="https://announce.ssis.edu.vn/rssShow.php" width="100%" height="100%" frameborder="0"></iframe>