Multiple Feed Parsing
Background
The last days i tried to develop a multiple feed parser. For our Project www.livescreaming.eu we need to have an intuitive feed parser which shows User more or less different feeds. More or Less depends on each users interests on reading feeds. If the User klicks on feeds more frequently his Feedoutputbox will get more different Feeds. For instance at the Beginning he sees two different feeds. After klicking 10 times on any link he will see 3 different feeds. Every feed shows up the latest two entries.
Used Tools
Solution
Serverside
I created a server script which fetches all the feeds which are related to the user. The Outputformat is XML to achieve a simple XML Ajax Request from the Clientscript. This is how the serverscript looks like:
dbconnect()) {
$db->dbselectdb($db->dbbase);
$result = Array();
$result = $db->dbquery(”SELECT * FROM livscr_feeds”, 0);
}
//get connected to Database
//creating xml document for ajax request
echo “\n”;
echo “\n”;
foreach($result as $key => $value) {
$url = $value[1];
$title = $value[2];
echo “\t\n”;
echo “\t\t\n”;
echo “\t\t“.$url.” \n”;
echo “\t \n”;
}
echo “ “;
$db->dbclose();
?>
Clientside
In the main-javascriptfile, which is included in the side, there is the following function:
function getUsersRssFeeds(mode){
var feedControl = new google.feeds.FeedControl();
var feedUrls = new Array();
var feedTitles = new Array();
$.ajax({
type: "GET",
url: "php/getRSS.php",
dataType: "txt",
success: function(xml){
$(xml).find('title').each(function(){
feedTitles.push($(this).text());
});
$(xml).find('url').each(function(){
feedUrls.push($(this).text());
});
for (var i = 0; i < feedUrls.length; i++) {
feedControl.addFeed(encodeURI(feedUrls[i]), feedTitles[i]);
}
feedControl.setNumEntries(2);
feedControl.draw(document.getElementById('feedBoxContent'), {
drawMode: google.feeds.FeedControl.DRAW_MODE_TABBED
});
},
error: function(){
alert("There was a Problem by doing Ajax Feed Request");
}
});
}
I used jquery Ajax Libary. I really recommend this libary, its very powerfull and simple to use. With the $.ajax-function i made an ajax request to the described serverscript. On Success i get a XML File which i can parse through by using the find-method. In a loop i add every Feed to the google.feedControl Object which i created before the Ajax Request.
Sorry for the short description. Maybe there is a more efficient way for a solution. In that case you can send me a message or write a comment.