Update of /cvsroot/php-blog/serendipity/plugins/serendipity_plugin_remoterss
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4943/plugins/serendipity_plugin_remoterss
Modified Files:
serendipity_plugin_remoterss.php
Log Message:
If RSS feeds are encoded differently than UTF-8, we had a problem.
Let users specify the source encoding of an RSS feed, because Onyx RSS doesn't report the used charset.
Fixes import problems and displaying remote RSS feeds.
Index: serendipity_plugin_remoterss.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/plugins/serendipity_plugin_remoterss/serendipity_plugin_remoterss.php,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- serendipity_plugin_remoterss.php 9 Feb 2005 16:26:32 -0000 1.17
+++ serendipity_plugin_remoterss.php 15 Feb 2005 11:25:28 -0000 1.18
@@ -284,13 +284,13 @@
$propbag->add('description', PLUGIN_REMOTERSS_BLAHBLAH);
$propbag->add('stackable', true);
$propbag->add('author', 'Udo Gerhards, Richard Thomas Harrison');
- $propbag->add('version', '1.0');
+ $propbag->add('version', '1.1');
$propbag->add('requirements', array(
'serendipity' => '0.8',
'smarty' => '2.6.7',
'php' => '4.1.0'
));
- $propbag->add('configuration', array('number', 'displaydate', 'dateformat', 'sidebartitle', 'rssuri', 'target', 'cachetime', 'feedtype', 'bulletimg', 'markup'));
+ $propbag->add('configuration', array('number', 'displaydate', 'dateformat', 'sidebartitle', 'rssuri', 'charset', 'target', 'cachetime', 'feedtype', 'bulletimg', 'markup'));
}
function introspect_config_item($name, &$propbag) {
@@ -302,6 +302,25 @@
$propbag->add('default', 'false');
break;
+ case 'charset':
+ $propbag->add('type', 'radio');
+ $propbag->add('name', CHARSET);
+ $propbag->add('description', CHARSET);
+ $propbag->add('default', 'native');
+
+ $charsets = array();
+ if (LANG_CHARSET != 'UTF-8') {
+ $charsets['value'][] = $charsets['desc'][] = 'UTF-8';
+ }
+ if (LANG_CHARSET != 'ISO-8859-1') {
+ $charsets['value'][] = $charsets['desc'][] = 'ISO-8859-1';
+ }
+
+ $charsets['value'][] = 'native';
+ $charsets['desc'][] = LANG_CHARSET;
+ $propbag->add('radio', $charsets);
+ break;
+
case 'feedtype':
$select = array('rss' => 'RSS', 'opml' => 'OPML');
$propbag->add('type', 'select');
@@ -421,11 +440,11 @@
if (empty($item['title'])) {
continue;
}
- $content .= '<a href="' . $this->rss_utf8_decode($item['link']) . '" target="'.$target.'">';
+ $content .= '<a href="' . $this->decode($item['link']) . '" target="'.$target.'">';
if (!empty($bulletimg)) {
$content .= '<img src="' . $bulletimg . '" border="0" alt="*" /> ';
}
- $content .= $this->rss_utf8_decode($item['title']) . "</a><br />\n";
+ $content .= $this->decode($item['title']) . "</a><br />\n";
$item['timestamp'] = @strtotime(isset($item['pubdate']) ? $item['pubdate'] : $item['dc:date']);
if (!($item['timestamp'] == -1) AND ($displaydate == 'true')) {
$content .= '<div class="serendipitySideBarDate">'
@@ -462,23 +481,23 @@
$content = '';
while (($showAll || ($i < $number)) && ($item = $opml->getOPMLOutlineAttr($opmltree, $i))) {
if (!empty($item['url'])) {
- $url = $this->rss_utf8_decode($item['url']);
+ $url = $this->decode($item['url']);
} elseif (!empty($item['htmlUrl'])) {
- $url = $this->rss_utf8_decode($item['htmlUrl']);
+ $url = $this->decode($item['htmlUrl']);
} elseif (!empty($item['xmlUrl'])) {
- $url = $this->rss_utf8_decode($item['xmlUrl']);
+ $url = $this->decode($item['xmlUrl']);
} elseif (!empty($item['urlHTTP'])) {
- $url = $this->rss_utf8_decode($item['urlHTTP']);
+ $url = $this->decode($item['urlHTTP']);
} else {
$url = '';
}
if (!empty($item['text'])) {
- $text = htmlspecialchars($this->rss_utf8_decode($item['text']));
+ $text = htmlspecialchars($this->decode($item['text']));
} elseif (!empty($item['title'])) {
- $text = htmlspecialchars($this->rss_utf8_decode($item['title']));
+ $text = htmlspecialchars($this->decode($item['title']));
} elseif (!empty($item['description'])) {
- $text = htmlspecialchars($this->rss_utf8_decode($item['description']));
+ $text = htmlspecialchars($this->decode($item['description']));
} else {
$text = '';
}
@@ -527,14 +546,26 @@
}
}
- function rss_utf8_decode($string) {
- if (strtolower(LANG_CHARSET) != 'utf-8') {
- return utf8_decode($string);
- } else {
- return $string;
+ function decode($string) {
+ switch($this->get_config('charset', 'native')) {
+ case 'native':
+ return $string;
+
+ case 'ISO-8859-1':
+ if (function_exists('iconv')) {
+ return iconv('ISO-8859-1', LANG_CHARSET, $string);
+ } elseif (function_exists('recode')) {
+ return recode('iso-8859-1..' . LANG_CHARSET, $string);
+ } else {
+ return $string;
+ }
+
+ case 'UTF-8':
+ default:
+ return utf8_decode($string);
}
}
}
/* vim: set sts=4 ts=4 expandtab : */
-?>
+?>
\ No newline at end of file
|