[Einfaches Modul] RSS Feedreader

Gesperrt
cabro0
Beiträge: 2
Registriert: Mi 22. Dez 2004, 20:10
Kontaktdaten:

[Einfaches Modul] RSS Feedreader

Beitrag von cabro0 »

Hallo

Keine Ahnung ob schon irgendwo so ein Modul existiert, auf jeden Fall hab' ich für mich kurz eines erstellt. Vielleicht kann es jemand gebrauchen...

Damit das Modul funktioniert, muss im php.ini der Pfad zu dem PEAR Verzeichnis von PHP konfiguriert und das Package XML_RSS installiert sein (für Windows: go-pear.bat im PHP Verzeichnis ausführen und das Package XML_RSS anschliessend installieren, siehe auch pear.php.net):

INPUT ---------------------------------------

Code: Alles auswählen

?> 

<br>
Anzahl Feeds pro Channel:
<br>
<input type="text" name="CMS_VAR[0]" class="text_medium" value="<?= "CMS_VALUE[0]" ?>">
<br>
<br>
Maximale Textlänge:
<br>
<input type="text" name="CMS_VAR[1]" class="text_medium" value="<?= "CMS_VALUE[1]" ?>">
<br>
<br>
Newsfeeds (Kommata getrennt)
<br>
<textarea style="width:100%;height:80px" class="text_medium" name="CMS_VAR[2]"><?php echo "CMS_VALUE[2]"; echo "</text"."area>"; ?>

<?php
OUTPUT ---------------------------------------

Code: Alles auswählen

<?php

	require_once "XML/RSS.php";

	$rss_feeds = split(",", "CMS_VALUE[2]");
	$count     = "CMS_VALUE[0]";
	$maxLength = "CMS_VALUE[1]" == "" ? 0 : "CMS_VALUE[1]";
	foreach ($rss_feeds as $rss_feed) {
		$rss =& new XML_RSS($rss_feed);
		$rss->parse();
		
		$i = 0;
		foreach ($rss->getItems() as $item) {
			$i++;
			echo "<a href=\"$item[link]\" target=\"_blank\">".utf8_decode($item[title])."</a><br>";
			
			if ($item['description'] != "") {
			 	$description = utf8_decode($item['description']);
				if ($maxLength != 0 && 
				    strlen($description) < $maxLength) {
					$description = substr($description, 0, $maxLength);
				}
			  	echo "$description</tr>";
			}
			
			echo "<hr>";				
			if ($i == $count) {
				break;
			}
		}
	}
?>
emergence
Beiträge: 10653
Registriert: Mo 28. Jul 2003, 12:49
Wohnort: Austria
Kontaktdaten:

Beitrag von emergence »

nettes modul.. ;-)
*** make your own tools (wishlist :: thx)
cabro0
Beiträge: 2
Registriert: Mi 22. Dez 2004, 20:10
Kontaktdaten:

Update

Beitrag von cabro0 »

...ein bisschen Caching wäre doch nicht schlecht:

// INPUT -----------------------------------------------------

Code: Alles auswählen

?> 

	<br>
	Anzahl Feeds pro Channel:
	<br>
	<input type="text" name="CMS_VAR[0]" class="text_medium" value="<?= "CMS_VALUE[0]" ?>">
	<br>
	<br>
	Caching Lifetime:
	<br>
	<input type="text" name="CMS_VAR[1]" class="text_medium" value="<?= "CMS_VALUE[1]" ?>">
	<br>
	<br>
	Maximale Textlänge:
	<br>
	<input type="text" name="CMS_VAR[2]" class="text_medium" value="<?= "CMS_VALUE[2]" ?>">
	<br>
	<br>
	Newsfeeds (Kommata getrennt)
	<br>
	<textarea style="width:100%;height:80px" class="text_medium" name="CMS_VAR[3]"><?php echo "CMS_VALUE[3]"; echo "</text"."area>"; ?>

<?php
// OUTPUT -----------------------------------------------------

Code: Alles auswählen

<?php

	require_once "XML/RSS.php";
	require_once $cfg['path']['pear']."/CACHE/Lite.php";

	$id      = $auth->url() . "rss";
  	$options = array("cacheDir" => "cache/", "lifeTime" => "CMS_VALUE[1]");
  	
	$cache   = new Cache_Lite($options);
	$content = $cache->get($id);
  	
	if ($content) {
  		echo $content;
	} else {
		$rss_feeds = split(",", "CMS_VALUE[3]");
		$count     = "CMS_VALUE[0]";
		$maxLength = "CMS_VALUE[2]" == "" ? 0 : "CMS_VALUE[2]";
		
		foreach ($rss_feeds as $rss_feed) {
			$rss =& new XML_RSS($rss_feed);
			$rss->parse();
			
			$i = 0;
			foreach ($rss->getItems() as $item) {
				$i++;
				$content .= "<a href=\"$item[link]\" target=\"_blank\">".utf8_decode($item[title])."</a><br>";
				
				if ($item['description'] != "") {
					$description = utf8_decode($item['description']);
					if ($maxLength != 0 && 
						strlen($description) < $maxLength) {
						$description = substr($description, 0, $maxLength);
					}
					$content .= $description;
				}
				
				$content .= "<hr>";				
				if ($i == $count) {
					break;
				}
			}
		}
		echo $content;
		$cache->save($content, $id);
	}

?>
mäci
Beiträge: 36
Registriert: Sa 26. Feb 2005, 18:10
Kontaktdaten:

Beitrag von mäci »

ich bekomme nach dem einbinden folgende fehler meldung:

Parse error: parse error, unexpected T_STRING in http://www.netzeitung.de/export/news/rss/titelseite.xml on line 1

ich habe:
require_once "XML/RSS.php";

ersetzt mit
require_once "http://www.netzeitung.de/export/news/rss/titelseite.xml";

was jemand woran dies liegt?
Gesperrt