Have an account? Sign in
Login  Register  Facebook
Rss source link does not work
Hello to everyone!

I have a php ajax rss reader for my site but i have a problem with it. The link of the item that comes from rss does not work, I mean, when a user clicks on the link of the rss item, didn't open the page of that item but just reloads the page where the user is (# effect). The second problem that i have is that i don't know how to get descriptions of the rss item. The thir problem is a generall one, when i include this page on my home page and in this one (getrss.php) are non-latin lettersm those are not appearing correctly (ë or ç).

getrss.php


<?php
	//Disable Error Reporting
	error_reporting(0);

	//Check if someone attempting to connect from another site (Saves your Bandwith!)
	if ($_SERVER['HTTP_REFERER'] &&
 $_SERVER['HTTP_HOST'] &&
 !strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'])) return 'For local use only!';

	//Get Feeds options
	$feed_url = $_GET['url'];
	$feed_show_num = $_GET['num'];
	$feed_sep = $_GET['sep'];
	$feed_image = $_GET['image'];	
	
	//Get Feed
	$feed = file_get_contents($feed_url);
	
	//Load DOM Document
	$doc = new DOMDocument;
	$doc->loadXML($feed);
	
	//Get items
	$items = $doc->getElementsByTagName('item');
	if ($items->length == 0) $items = $doc->getElementsByTagName('entry');
	if ($items->length == 0) return;
	
	$count = 0;
	//Get Data for each item
	foreach( $items as $item ) {
		if ($count == $feed_show_num) break;
		
		if ($item->getElementsByTagName('title')->length != 0)
			$title = $item->getElementsByTagName('title')->item(0)->nodeValue;
		else
			$title = "Titulli";
		
		if ($item->getElementsByTagName('pubDate')->length != 0)
			$pubdate = $item->getElementsByTagName('pubDate')->item(0)->nodeValue;
		else if ($item->getElementsByTagName('published')->length != 0)
			$pubdate = $item->getElementsByTagName('published')->item(0)->nodeValue;
		else
			$pubdate = date("D, d M Y H:i:s T");
		
		if ($item->getElementsByTagName('guid')->length != 0)
			$link = $item->getElementsByTagName('guid')->item(0)->nodeValue;
		else if ($item->getElementsByTagName('link')->length != 0)
			$link = $item->getElementsByTagName('link')->item(0)->getAttribute('href');
		else
			$link = "#";
			
		//Calc Time
		$timestamp = strtotime($pubdate);
		$now = strtotime('now');
		$fdate = abs($now - $timestamp);
		$date = formatDate($fdate);
		
		//Show Data
		echo '<div class="item" time="'.$timestamp.'">';
		echo '<img src="'.$feed_image.'" /> ';
		echo '<span class="desc"><a href="'.$link.'" rel="nofollow">'.$title.'</a>'.$feed_sep.'
<span class="date">'.$date.' me pare</span></span>';
		echo '</div>';
		$count++;
	}
	
	function formatDate($date){
		$years = intval($date / (3600 * 24 * 30 * 12));
		$months = intval($date / (3600 * 24 * 30));
		$days = intval($date / (60 * 60 * 24));
		$hours = intval($date / (60 * 60));
		$minutes = intval($date / 60);
		$seconds = $date;
		
		if ($years!=0) return $years.' vite';
		if ($months!=0) return $months.' muaj';
		if ($days!=0) return $days.' dite';
		if ($hours!=0) return $hours.' ore';
		if ($minutes!=0) return $minutes.' minuta';
		if ($seconds!=0) return $seconds.' sekonda';
	}
?>


Thank you!
Started: September 19, 2011 Latest Activity: September 19, 2011 rss feed reader ajax
1 Answer
the Solution of the href problem as follow
at line 48 replace with
$link = $item->getElementsByTagName(\'link\')->item(0)->nodeValue;
and to get the description use:
echo $item->getElementsByTagName(\'description\')->item(0)->nodeValue;

Posted: MacOS
In: September 19, 2011

Thank you. It's working now. And i got the idea of how it works ;) U R the best ;)
September 19, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer