RDF Parser

Gesperrt
Andreas
Beiträge: 254
Registriert: So 16. Nov 2003, 14:48
Wohnort: Reichshof
Kontaktdaten:

RDF Parser

Beitrag von Andreas » Mo 21. Feb 2005, 10:26

Hallo zusammen,
ich verwende das Modul RDF Parser (siehe unten). Funktioniert auch, aber:
Wie kann ich hier - neben der Ausgabe der "<title>" auch die "<description>" des RSS-Feed ausgeben lassen?

Modul INPUT

Code: Alles auswählen

echo "<table align=\"left\" cellpadding=\"0\" cellspacing=\"0\" class=\"text_medium\"> 
<tr> 
<td>RDF URL:</td> 
<td colspan=2> <INPUT TYPE=\"text\" NAME=\"CMS_VAR[0]\" VALUE=\"CMS_VALUE[0]\" style=\"width: 300px;\"></td>
<td width=\"20\"> </td>
</tr> 
<tr>
<td>Anzahl News:</td>
<td><INPUT TYPE=\"text\" NAME=\"CMS_VAR[1]\" VALUE=\"CMS_VALUE[1]\" style=\"width: 30px;\"></td>
<td width=\"20\"> </td>
</tr>
</table>";
Modul OUTPUT

Code: Alles auswählen

<?php
include($cfg['path']['contenido'].'external/cafeRSS/cafeRSS.php');
$rssfeedURL = "CMS_VALUE[0]";
$rssItems = "CMS_VALUE[1]";
$rss = new cafeRSS();
$rss->assign('items', $rssItems);
$rss->assign('use_cache', 0);
$rss->assign('cache_dir', $cfg['path']['contenido'].'external/cafeRSS/cache');
$rss->display($rssfeedURL);
?>
Dank im voraus.
Andreas

emergence
Beiträge: 10645
Registriert: Mo 28. Jul 2003, 12:49
Wohnort: Austria
Kontaktdaten:

Beitrag von emergence » Di 22. Feb 2005, 19:11

wo kann man sich die klasse cafeRSS ansehen die du verwendest ?
*** make your own tools (wishlist :: thx)

Andreas
Beiträge: 254
Registriert: So 16. Nov 2003, 14:48
Wohnort: Reichshof
Kontaktdaten:

Beitrag von Andreas » Mi 23. Feb 2005, 17:52

Hallo emergence,
Ist zwar etwas umfangreich aber hier ist die zugehörige cafeRSS.php

Code: Alles auswählen

<?php

/*

CaféRSS 1.1

Copyright (C) 2002 Michel Valdrighi
Copyright (C) 2004 BarkerJr <http://barkerjr.net>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/

class cafeRSS {

	var $url;
	var $debugtimer;

	/* defaut values */
	var $items = 'all';
	var $template_string = '<div id="rsslist">{rss_items}<li><a href="{$rss_item_link}" target="_blank">{$rss_item_title}</a></li>{/rss_items}</div>'; 
	var $template_file = '';
	var $use_cache = 0;
	var $cache_dir = 'cafeRSS_cache'; # if you want to cache, chmod a directory 777 and put its name here
	var $refresh_time = 900; # in seconds - has no effect if $use_cache = 0;
	var $echo = 1;
	var $debug = 0;


	/* usage: $this->assign('var','value'); */

	function assign($var, $value) {
		$this->$var = $value;
	}


	/* usage: $this->display('url' [, those optional parameters below ]); */

	function display($rss_file = 'blah', $rss_items = 'blah', $rss_template_string = 'blah', $rss_template_file = 'blah', $rss_use_cache= 'blah', $rss_cache_dir = 'blah', $rss_refresh_time = 'blah', $rss_echo = 'blah', $rss_debug = 'blah') {

		if ($rss_file == 'blah') { $rss_file = $this->url; }
		if ($rss_items == 'blah') { $rss_items = $this->items; }
		if ($rss_template_string == 'blah') { $rss_template_string = $this->template_string; }
		if ($rss_template_file == 'blah') { $rss_template_file = $this->template_file; }
		if ($rss_use_cache == 'blah') { $rss_use_cache = $this->use_cache; }
		if ($rss_cache_dir == 'blah') { $rss_cache_dir = $this->cache_dir; }
		if ($rss_refresh_time == 'blah') { $rss_refresh_time = $this->refresh_time; }
		if ($rss_echo == 'blah') { $rss_echo = $this->echo; }
		if ($rss_debug == 'blah') { $rss_debug = $this->debug; }

		$rss_cache_file = $rss_cache_dir.'/'.preg_replace('/[^a-zA-Z0-9_\.-]/', '_', $rss_file).'.cache';


		if (preg_match('/</', $rss_file)) {
			$content = $rss_file;
		} else {


			/* the secret cache ops, part I */

			$isCached = false;
			if (($rss_cache_dir != '') && ($rss_use_cache)) {
				clearstatcache();
				$get_rss = 1;
				$cache_rss = 1;
				if (file_exists($rss_cache_file)) {
					if ((time() - filemtime($rss_cache_file)) < $rss_refresh_time) {
						$this->timer_start();
						$f = fopen($rss_cache_file, 'r');
						$content = fread($f, filesize($rss_cache_file));
						fclose($f);
						$debugfopencachetime = $this->timer_stop(0);
						$get_rss = 0;
						$isCached = true;
					}
				}
			} else {
				$get_rss = 1;
				$cache_rss = 0;
			}


			/* opens the RSS file */

			$this->timer_start();
			if ($get_rss) {
				$f = fopen($rss_file,'r') or $nocon = true;
				if ($nocon)
				{
					echo '<p><i>(error displaying RSS feed)</i></p>';
					return;
				}
				while (!feof($f)) {
					$content .= fgets($f, 4096);
				}
				fclose($f);
			}
			$debugfopentime = $this->timer_stop(0);


			/* the secret cache ops, part II */

			if (($cache_rss) && ($rss_use_cache) && (!$isCached)) {
				$this->timer_start();
				$f = fopen($rss_cache_file, 'w+');
				fwrite($f, $content);
				fclose($f);
				$debugcachetime = $this->timer_stop(0);
			} else {
				$debugcachetime = 0;
			}

		}


		/* gets RSS channel info and RSS items info */

		$this->timer_start();
		preg_match_all("'<channel>(.+?)<title>(.*?)</title>(.+?)</channel>'si",$content,$rss_title);
		preg_match_all("'<channel>(.+?)<link>(.*?)</link>(.+?)</channel>'si",$content,$rss_link);
		preg_match_all("'<channel>(.+?)<description>(.*?)</description>(.+?)</channel>'si",$content,$rss_description);
		preg_match_all("'<channel>(.+?)<lastBuildDate>(.*?)</lastBuildDate>(.+?)</channel>'si",$content,$rss_lastBuildDate);
		preg_match_all("'<channel>(.+?)<docs>(.*?)</docs>(.+?)</channel>'si",$content,$rss_docs);
		preg_match_all("'<channel>(.+?)<managingEditor>(.*?)</managingEditor>(.+?)</channel>'si",$content,$rss_managingEditor);
		preg_match_all("'<channel>(.+?)<webMaster>(.*?)</webMaster>(.+?)</channel>'si",$content,$rss_webMaster);
		preg_match_all("'<channel>(.+?)<language>(.*?)</language>(.+?)</channel>'si",$content,$rss_language);
		preg_match_all("'<image>(.+?)<title>(.*?)</title>(.+?)</image>'si",$content,$rss_image_title);
		preg_match_all("'<image>(.+?)<url>(.*?)</url>(.+?)</image>'si",$content,$rss_image_url);
		preg_match_all("'<image>(.+?)<link>(.*?)</link>(.+?)</image>'si",$content,$rss_image_link);
		preg_match_all("'<item>(.+?)<title>(.*?)</title>(.+?)</item>'si",$content,$rss_item_titles);
		preg_match_all("'<item>(.+?)<link>(.*?)</link>(.+?)</item>'si",$content,$rss_item_links);
		preg_match_all("'<item>(.+?)<description>(.*?)</description>(.+?)</item>'si",$content,$rss_item_descriptions);
		$rss_title = $rss_title[2][0];
		$rss_link = $rss_link[2][0];
		$rss_description = $rss_description[2][0];
		$rss_lastBuildDate = $rss_lastBuildDate[2][0];
		$rss_docs = $rss_docs[2][0];
		$rss_managingEditor = $rss_managingEditor[2][0];
		$rss_webMaster = $rss_webMaster[2][0];
		$rss_language = $rss_language[2][0];
		$rss_image_title = $rss_image_title[2][0];
		$rss_image_url = $rss_image_url[2][0];
		$rss_image_link = $rss_image_link[2][0];
		$debugparsersstime = $this->timer_stop(0);



		/* gets the template */

		$this->timer_start();
		if (empty($rss_template_string)) {
			$f = fopen($rss_template_file,'r');
			$rss_template = fread($f, filesize($rss_template_file));
			fclose($f);
		} else {
			$rss_template = $rss_template_string;
		}
		$debugfopentemplatetime = $this->timer_stop(0);
		preg_match_all("'{rss_items}(.+?){/rss_items}'si",$rss_template,$rss_template_loop);
		$rss_template_loop = $rss_template_loop[1][0];

		$rss_template = str_replace('{rss_items}','',$rss_template);
		$rss_template = str_replace('{/rss_items}','',$rss_template);



		/* processes the template - rss channel info */

		$this->timer_start();
		$rss_template = str_replace('{$rss_title}',$rss_title, $rss_template);
		$rss_template = str_replace('{$rss_link}',$rss_link, $rss_template);
		$rss_template = str_replace('{$rss_description}',$rss_description, $rss_template);
		$rss_template = str_replace('{$rss_lastBuildDate}',$rss_lastBuildDate, $rss_template);
		$rss_template = str_replace('{$rss_docs}',$rss_docs, $rss_template);
		$rss_template = str_replace('{$rss_managingEditor}',$rss_managingEditor, $rss_template);
		$rss_template = str_replace('{$rss_webMaster}',$rss_webMaster, $rss_template);
		$rss_template = str_replace('{$rss_language}',$rss_language, $rss_template);



		/* processes the template - rss image info */

		if ($rss_image_url != '') {
			$rss_template = str_replace('{rss_image}','',$rss_template);
			$rss_template = str_replace('{/rss_image}','',$rss_template);
			$rss_template = str_replace('{$rss_image_title}',$rss_image_title, $rss_template);
			$rss_template = str_replace('{$rss_image_link}',$rss_image_link, $rss_template);
			$rss_template = str_replace('{$rss_image_url}',$rss_image_url, $rss_template);
		} else {
			$rand = md5(rand(1,5)); /* now there's an ugly hack that I'll have to fix */
			$rss_template = preg_replace('/(\015\012)|(\015)|(\012)/', $rand, $rss_template);
			$rss_template = preg_replace('/{rss_image}(.*?){\/rss_image}/', '', $rss_template);
			$rss_template = preg_replace("/$rand/", "\n", $rss_template);
		}



		/* processes the template - rss items info */

		$rss_template_loop_processed = '';
		$k = count($rss_item_titles[2]);
		$j = (($rss_items == 'all') || ($rss_items > $k)) ? $k : intval($rss_items);
		for ($i = 0; $i<$j; $i++) {
			$tmp_template = $rss_template_loop;
			$tmp_title = $rss_item_titles[2][$i];
			$tmp_link = $rss_item_links[2][$i];
			$tmp_description = $rss_item_descriptions[2][$i];
			if ($tmp_description == '') {
				$tmp_description = '-';
			}
			if ($tmp_title == '') {
				$tmp_title = substr($tmp_description,0,20);
				if (strlen($tmp_description) > 20) {
					$tmp_title .= '...';
				}
			}
			$tmp_template = str_replace('{$rss_item_title}',$tmp_title, $tmp_template);
			$tmp_template = str_replace('{$rss_item_link}',$tmp_link, $tmp_template);
			$tmp_template = str_replace('{$rss_item_description}',$tmp_description, $tmp_template);
			$rss_template_loop_processed .= $tmp_template;
		}
		$rss_template = str_replace($rss_template_loop, $rss_template_loop_processed, $rss_template);
		$debugprocesstemplatetime = $this->timer_stop(0);

		clearstatcache();
		
		
		/* echoes or returns the processed template :) */

		if ($rss_echo) {
			echo $rss_template;
			if ($rss_debug) {
				echo '<p>';
				echo $debugfopentime.' seconds to load the remote RSS file.<br />';
				echo $debugparsersstime.' seconds to parse the RSS.<br />';
				echo $debugfopentemplatetime.' seconds to load the template file.<br />';
				echo $debugprocesstemplatetime.' seconds to process the template.<br />';
				if ($cache_rss) {
					echo $debugcachetime.' seconds to cache the parsing+processing.<br />';
				}
				echo '<br />';
				$debugtotaltime = ($debugfopentime+$debugparsersstime+$debugfopentemplatetime+$debugfopentemplatetime+$debugprocesstemplatetime+$debugcachetime);
				echo 'Total: '.$debugtotaltime.' seconds.';
				echo '</p>';
			}
		} else {
			return $rss_template;
		}

	}

	function timer_start() {
		$mtime = microtime();
		$mtime = explode(" ",$mtime);
		$mtime = $mtime[1] + $mtime[0];
		$this->debugtimer = $mtime;
		return true;
	}

	function timer_stop($display=0,$precision=3) {
		$mtime = microtime();
		$mtime = explode(" ",$mtime);
		$mtime = $mtime[1] + $mtime[0];
		$this->debugtimer = $mtime - $this->debugtimer;
		if ($display)
			echo number_format($this->debugtimer,$precision);
		return($this->debugtimer);
	}

}

?>

mhl
Beiträge: 67
Registriert: Mi 18. Aug 2004, 21:59
Wohnort: Salzburg
Kontaktdaten:

Probleme mit Sonderzeichen

Beitrag von mhl » Mi 5. Apr 2006, 23:45

Hallo.

ich habe da leider ein kleines Problem mit der Ausgabe von Sonderzeichen. So stellt er mit statt dem " Anführungszeichen " die HTML Umschreibung idF von " dar. Das ist natürlich unschön. Was kann ich da machen? Ich nehme an das cafeRSS.php muss modifiziert werden, oder?

Danke für die Hinweise!

lux
Beiträge: 33
Registriert: Di 12. Okt 2004, 14:11
Wohnort: .at
Kontaktdaten:

CafeRSS

Beitrag von lux » Do 13. Apr 2006, 11:16

Hallo Leute!

Hab das gleiche Problem mit den Sonderzeichen... Beim Heise News werden aus dem ü ein ü ???

Hab schon die neue Version von CafeRSS 1.6 in Verwendung und hab schon 4 Stunden darum gebastelt - komm aber auf keinen grünen Zweig...

Bitte um Hilfe!

THX

LUX
Das Leben besteht aus Nullen und Einsen!

xmurrix
Beiträge: 3147
Registriert: Do 21. Okt 2004, 11:08
Wohnort: Augsburg
Kontaktdaten:

Re: CafeRSS

Beitrag von xmurrix » Do 13. Apr 2006, 12:51

lux hat geschrieben:Hallo Leute!

Hab das gleiche Problem mit den Sonderzeichen... Beim Heise News werden aus dem ü ein ü ???

Hab schon die neue Version von CafeRSS 1.6 in Verwendung und hab schon 4 Stunden darum gebastelt - komm aber auf keinen grünen Zweig...
hallo,

heisse news und viele andere rss-news werden als utf-8 augeliefert, darum die sonderzeichen in utf-8 zeichenkodierung bei der ausgabe.

um dies zu verhindern brauchst du folgenden code:

Code: Alles auswählen

...
//sorgt dafür, dass die einträge nicht mit echo ausgegeben, sondern zurückgelierfert werden.
$rss->assign('echo', '0'); 

// einträge holen
$items = $rss->display($rssfeedURL);

//den string in einen iso-8859-1 zeichensatz umwandeln
//für andere zeichensätze muss man es selber implementieren :-)
$items = utf8_decode($items);

// ausgabe der einträge
echo $items;
gruß
xmurrix

lux
Beiträge: 33
Registriert: Di 12. Okt 2004, 14:11
Wohnort: .at
Kontaktdaten:

Beitrag von lux » Do 13. Apr 2006, 13:25

Danke für den Tipp mit UTF 8...

Funktioniert wunderbar!

Greets

LUX
Das Leben besteht aus Nullen und Einsen!

Gesperrt