Buying Convert RSS feed to live Ajax feed

Discussion in 'Programming' started by IamNed, Nov 23, 2009.

  1. #1
    I would like to hire someone to create/modify a script that parses an arbitrary number of RSS feeds, allows me to control how many items from each feed should be be displayed, and arrange the results by time. Then make it update live via AJAX.

    I started some of the work myself but I cant get it to work for multiple URLs . It seems I can only specify one 'url' but I want many.

    var scriptUrl = http://iamned.com/ajax/z3.php :

    <?php
    
    // turn off browser caching (required to make ajax work)
    header("Cache-Control: no-cache, must-revalidate");
    header('Pragma: no-cache');
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    
    
    // retrieve POST parameters
    $url = strip_tags($_POST['url']);
    $cacheDuration = strip_tags($_POST['cacheduration']);
    
    require 'simplepie.inc';
    $feed = new SimplePie();
    $feed->set_feed_url($url);
    $feed->set_cache_duration($cacheDuration);
    $feed->init();
    
    
    if($feed->error())
    {
    	echo '<p>'.$feed->error().'</p>';
    }
    else
    {
    	foreach($feed->get_items(0,3) as $item)
    	{
    		echo '<a href="' . $item->get_link() . '">' . $item->get_title() . '</a>';
    		echo '<br>';
    		echo '<small>'.$item->get_date().'</small>';
    		echo '<br>';
    		echo '<br>';
    	}
    }
    ?>
    PHP:
    and javascript portion:

    /**
     *
     * Update RSS/ATOM feed and display it using SimplePie and Ajax
     *
     *
     * LICENSE: This source file is subject to the BSD license
     * that is available through the world-wide-web at the following URI:
     * http://www.opensource.org/licenses/bsd-license.php.
     *
     * @author     Michael P. Shipley <michael@michaelpshipley.com>
     * @copyright  2008 Michael P. Shipley
     * @license    http://www.opensource.org/licenses/bsd-license.php BSD
     * @version    1.0
     * @link       http://www.michaelpshipley.com Michael Shipley
     */
    
    /*
    	Global variables
    */
    
    // Set ajax update interval
    var minutesBetweenUpdates = 1;
    
    // Set feed url
    var feedUrl = 'http://finance.yahoo.com/rss/economy';
    
    // Set url of PHP script that will fetch and return a feed or feeds using SimplePie
    var scriptUrl = 'http://iamned.com/ajax/z3.php';
    
    // Set SimplePie cache duration (seconds)
    var cacheDuration = 0;  // normally 3600
    
    // Set div id where feed output will go
    var divId = 'feedDiv'; 
    
    /*
    	Initialize feed display
    */
    updateFeed(feedUrl,scriptUrl,cacheDuration,divId); 
    
    /*
    	Start feed update timer
    */
    
    // Calc milliseconds
    var seconds = minutesBetweenUpdates * 60;
    var milliseconds = seconds * 1000;
    
    // Setup function that feed update timer will call
    var command = 'updateFeed(feedUrl,scriptUrl,cacheDuration,divId)';
    
    // Start feed update timer
    var updateFeedTimer = setInterval(command,milliseconds);
    
    /**
    	Use ajax to call  SimplePie to get feed data
    	@param: feedUrl  string  feed link
    	@param: scriptUrl string php script url
    	@param: cacheDuration integer SimplePie cache duration in seconds
    	@param: divId string id of div to output html to
    */
    function updateFeed(feedUrl,scriptUrl,cacheDuration,divId)
    {
    	// Display the "updating" message
    	var div = document.getElementById(divId);
    	div.innerHTML = div.innerHTML + '<p>Updating...</p>';
    
    	// Get the http requester
    	if (window.XMLHttpRequest)
    	{
    		var http = new XMLHttpRequest();
    	}
    	else if (window.ActiveXObject)
    	{
    		var http = new ActiveXObject('Microsoft.XMLHTTP')
    	}
    	else
    	{
    		alert('browser doesn\'t support javascript http connections');
    		return true;
    	}
    
    	// Process response
    	http.onreadystatechange = function()
    	{
    		if(http.readyState == 4)
    		{
    			if(http.status != 200)
    			{
    				alert(http.responseText);
    			}
    			else
    			{
    				div.innerHTML = http.responseText;
    			}
    			return true;
    		}
    	}
    
    	// Send http request via post
    	params = 'url=' + feedUrl + '&cacheduration=' + cacheDuration;
    	http.open("POST", scriptUrl, true);
    	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    	http.setRequestHeader("Content-length", params.length);
    	http.send(params);
    	return true;
    }
    
    /*
    	Start countdown timer (optional)
    */
    var countDownTimerDivId = 'countDownTimer';
    var date = new Date();
    var timeOut = date.getTime() + milliseconds;
    var timerId = document.getElementById(countDownTimerDivId);
    var timer = setInterval(countDownTimer,100);
    function countDownTimer()
    {
    	var date = new Date();
    	var timeLeft = timeOut - date.getTime();
    	if(timeLeft <= 0)
    	{
    		timeLeft = 0;
    		timeOut = date.getTime() + milliseconds;
    	}
    	timerId.innerHTML = 'Seconds to next update: ' + parseInt(timeLeft/1000);
    }
    
    
    
    Code (markup):

    Finally, i must be able to specify the quantity of output items. Example: 20 items from 20 feeds, and one item from each feed.

    thanks
     
    IamNed, Nov 23, 2009 IP