Internal RSS plugin hacks

Discussion corner for Developers of Serendipity.
Post Reply
sapphirecat
Regular
Posts: 7
Joined: Thu May 03, 2007 2:19 am

Internal RSS plugin hacks

Post by sapphirecat »

I've hacked a couple of behaviors into the default RSS plugin:

First, I wanted to have a PNG icon for the feeds instead of xml.gif, so I added a configuration option to set a URL for it.

Then, in the current version of my blog, I put a 'border-bottom' style on links, only to discover that the RSS icons became underlined as well. So I added class="rssimg" to the link surrounding the icons, to be able to reach it with CSS.

You can see all this in action at my blog. Before I post the patch, I have one question: should I change the "rssimg" class name to something else first? Or would it be fine the way it is?
sapphirecat
Regular
Posts: 7
Joined: Thu May 03, 2007 2:19 am

Post by sapphirecat »

Argh! It seems that last night I unpacked a 1.1.2 tarball thinking it was 1.2-beta1, and didn't notice because it always unpacks as 'serendipity' with no version.

So I see that the links now have class="serendipity_xml_icon" set. I'll try and roll a fresh patch against 1.2-beta1 for the configurable icon feature and post it here later today or tomorrow.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Thanks for getting involved!

How does your configuration option differ from the "Image for the RSS feed" option that is already implemented into the plugin?

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
sapphirecat
Regular
Posts: 7
Joined: Thu May 03, 2007 2:19 am

Post by sapphirecat »

The existing option changes the URL specified in the /rss/channel/image/url tag (that's an XPath) of the RSS feed. The patch I have changes the image shown in the sidebar's HTML when someone views the blog itself. It basically replaces the hardcoding of 'img/xml.gif' in the call to serendipity_getTemplateFile().

Unfortunately I haven't had time to test it on 1.2-beta1, because Firefox won't take s9y's cookies. (Although Opera and Konqueror do. Official Fx 2.0.0.[34] binaries, all on Linux.)

Anyway, here's the untested patch:

Code: Select all

diff -Nur serendipity-1.1.2-pristine/include/plugin_internal.inc.php pawprints/include/plugin_internal.inc.php
--- serendipity-1.1.2-pristine/include/plugin_internal.inc.php	2007-01-14 09:56:22.000000000 -0500
+++ pawprints/include/plugin_internal.inc.php	2007-06-07 23:39:40.000000000 -0400
@@ -691,6 +691,7 @@
                                         'field_ttl',
                                         'field_pubDate',
                                         'seperator',
+                                        'iconURL',
                                         'bannerURL',
                                         'bannerWidth',
                                         'bannerHeight',
@@ -839,6 +840,13 @@
                 $propbag->add('default',     true);
                 break;
 
+            case 'iconURL':
+                $propbag->add('type',        'string');
+                $propbag->add('name',        SYNDICATION_PLUGIN_ICONURL);
+                $propbag->add('description', SYNDICATION_PLUGIN_ICONURL_DESC);
+                $propbag->add('default',     'img/xml.gif');
+                break;
+
             case 'bannerURL':
                 $propbag->add('type',        'string');
                 $propbag->add('name',        SYNDICATION_PLUGIN_BANNERURL);
@@ -900,11 +908,12 @@
         global $serendipity;
 
         $title = $this->get_config('title');
+        $icon  = serendipity_getTemplateFile($this->get_config('iconURL', 'img/xml.gif'));
 
         if (serendipity_db_bool($this->get_config('show_0.91', true))) {
 ?>
         <div style="padding-bottom: 2px;">
-            <a href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/index.rss', 'serendipityHTTPPath') ?>"><img src="<?php echo serendipity_getTemplateFile('img/xml.gif'); ?>" alt="XML" style="border: 0px" /></a>
+            <a class="rssimg" href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/index.rss', 'serendipityHTTPPath') ?>"><img src="<?php echo $icon; ?>" alt="XML" style="border: 0px" /></a>
             <a href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/index.rss', 'serendipityHTTPPath') ?>">RSS 0.91 feed</a>
         </div>
 <?php
@@ -913,7 +922,7 @@
         if (serendipity_db_bool($this->get_config('show_1.0', true))) {
 ?>
         <div style="padding-bottom: 2px;">
-            <a href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/index.rss1', 'serendipityHTTPPath') ?>"><img src="<?php echo serendipity_getTemplateFile('img/xml.gif'); ?>" alt="XML" style="border: 0px" /></a>
+            <a class="rssimg" href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/index.rss1', 'serendipityHTTPPath') ?>"><img src="<?php echo $icon; ?>" alt="XML" style="border: 0px" /></a>
             <a href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/index.rss1', 'serendipityHTTPPath') ?>">RSS 1.0 feed</a>
         </div>
 <?php
@@ -922,7 +931,7 @@
         if (serendipity_db_bool($this->get_config('show_2.0', true))) {
 ?>
         <div style="padding-bottom: 2px;">
-            <a href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/index.rss2', 'serendipityHTTPPath') ?>"><img src="<?php echo serendipity_getTemplateFile('img/xml.gif'); ?>" alt="XML" style="border: 0px" /></a>
+            <a class="rssimg" href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/index.rss2', 'serendipityHTTPPath') ?>"><img src="<?php echo $icon; ?>" alt="XML" style="border: 0px" /></a>
             <a href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/index.rss2', 'serendipityHTTPPath') ?>">RSS 2.0 feed</a>
         </div>
 <?php
@@ -931,7 +940,7 @@
         if (serendipity_db_bool($this->get_config('show_atom0.3', true))) {
 ?>
         <div style="padding-bottom: 2px;">
-            <a href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/atom03.xml', 'serendipityHTTPPath') ?>"><img src="<?php echo serendipity_getTemplateFile('img/xml.gif'); ?>" alt="ATOM/XML" style="border: 0px" /></a>
+            <a class="rssimg" href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/atom03.xml', 'serendipityHTTPPath') ?>"><img src="<?php echo $icon; ?>" alt="ATOM/XML" style="border: 0px" /></a>
             <a href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/atom03.xml', 'serendipityHTTPPath') ?>">ATOM 0.3 feed</a>
         </div>
 <?php
@@ -940,7 +949,7 @@
         if (serendipity_db_bool($this->get_config('show_atom1.0', true))) {
 ?>
         <div style="padding-bottom: 2px;">
-            <a href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/atom10.xml', 'serendipityHTTPPath') ?>"><img src="<?php echo serendipity_getTemplateFile('img/xml.gif'); ?>" alt="ATOM/XML" style="border: 0px" /></a>
+            <a class="rssimg" href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/atom10.xml', 'serendipityHTTPPath') ?>"><img src="<?php echo $icon; ?>" alt="ATOM/XML" style="border: 0px" /></a>
             <a href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/atom10.xml', 'serendipityHTTPPath') ?>">ATOM 1.0 feed</a>
         </div>
 <?php
@@ -949,7 +958,7 @@
         if (serendipity_db_bool($this->get_config('show_2.0c', true))) {
 ?>
         <div style="padding-bottom: 2px;">
-            <a href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/comments.rss2', 'serendipityHTTPPath') ?>"><img src="<?php echo serendipity_getTemplateFile('img/xml.gif'); ?>" alt="XML" style="border: 0px" /></a>
+            <a class="rssimg" href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/comments.rss2', 'serendipityHTTPPath') ?>"><img src="<?php echo $icon; ?>" alt="XML" style="border: 0px" /></a>
             <a href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/comments.rss2', 'serendipityHTTPPath') ?>"><span style="white-space: nowrap">RSS 2.0 <?php echo COMMENTS; ?></span></a>
         </div>
 <?php
@@ -958,7 +967,7 @@
         if (serendipity_db_bool($this->get_config('show_opml1.0', false))) {
 ?>
         <div style="padding-bottom: 2px;">
-            <a href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/opml.xml', 'serendipityHTTPPath') ?>"><img src="<?php echo serendipity_getTemplateFile('img/xml.gif'); ?>" alt="XML" style="border: 0px" /></a>
+            <a class="rssimg" href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/opml.xml', 'serendipityHTTPPath') ?>"><img src="<?php echo $icon; ?>" alt="XML" style="border: 0px" /></a>
             <a href="<?php echo serendipity_rewriteURL(PATH_FEEDS .'/opml.xml', 'serendipityHTTPPath') ?>">OPML 1.0 feed</a>
         </div>
 <?php
@@ -973,7 +982,7 @@
 			}
 ?>
         <div style="padding-bottom: 2px;">
-			<a href="<?php echo $url; ?>"<?php if (strlen($alt) > 0) echo " title=\"$alt\""; ?>><img src="<?php echo $img; ?>" alt="" style="border:0"/></a>
+			<a class="rssimg" href="<?php echo $url; ?>"<?php if (strlen($alt) > 0) echo " title=\"$alt\""; ?>><img src="<?php echo $img; ?>" alt="" style="border:0"/></a>
             <?php
 			$mytitle = $this->get_config('fb_title');
 			if (strlen($mytitle) > 0) { ?>
diff -Nur serendipity-1.1.2-pristine/lang/serendipity_lang_en.inc.php pawprints/lang/serendipity_lang_en.inc.php
--- serendipity-1.1.2-pristine/lang/serendipity_lang_en.inc.php	2006-11-22 05:30:13.000000000 -0500
+++ pawprints/lang/serendipity_lang_en.inc.php	2007-06-07 23:39:18.000000000 -0400
@@ -227,6 +227,8 @@
 @define('SYNDICATION_PLUGIN_ATOM03', 'ATOM 0.3 feed');
 @define('SYNDICATION_PLUGIN_MANAGINGEDITOR', 'Field "managingEditor"');
 @define('SYNDICATION_PLUGIN_WEBMASTER',  'Field "webMaster"');
+@define('SYNDICATION_PLUGIN_ICONURL', 'Image for the XML icon');
+@define('SYNDICATION_PLUGIN_ICONURL_DESC', 'Image shown in place of the default "XML" sign, relative to your template; e.g. "img/feed-icon-12x12.png"');
 @define('SYNDICATION_PLUGIN_BANNERURL', 'Image for the RSS feed');
 @define('SYNDICATION_PLUGIN_BANNERWIDTH', 'Image width');
 @define('SYNDICATION_PLUGIN_BANNERHEIGHT', 'Image height');
diff -Nur serendipity-1.1.2-pristine/lang/UTF-8/serendipity_lang_en.inc.php pawprints/lang/UTF-8/serendipity_lang_en.inc.php
--- serendipity-1.1.2-pristine/lang/UTF-8/serendipity_lang_en.inc.php	2006-12-04 04:20:14.000000000 -0500
+++ pawprints/lang/UTF-8/serendipity_lang_en.inc.php	2007-06-07 23:39:29.000000000 -0400
@@ -227,6 +227,8 @@
 @define('SYNDICATION_PLUGIN_ATOM03', 'ATOM 0.3 feed');
 @define('SYNDICATION_PLUGIN_MANAGINGEDITOR', 'Field "managingEditor"');
 @define('SYNDICATION_PLUGIN_WEBMASTER',  'Field "webMaster"');
+@define('SYNDICATION_PLUGIN_ICONURL', 'Image for the XML icon');
+@define('SYNDICATION_PLUGIN_ICONURL_DESC', 'Image shown in place of the default "XML" sign, relative to your template; e.g. "img/feed-icon-12x12.png"');
 @define('SYNDICATION_PLUGIN_BANNERURL', 'Image for the RSS feed');
 @define('SYNDICATION_PLUGIN_BANNERWIDTH', 'Image width');
 @define('SYNDICATION_PLUGIN_BANNERHEIGHT', 'Image height');
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Great thing, thanks & committed!
Unfortunately I haven't had time to test it on 1.2-beta1, because Firefox won't take s9y's cookies. (Although Opera and Konqueror do. Official Fx 2.0.0.[34] binaries, all on Linux.)
Are you by chance running it via a http://localhost/ URL? Firefox rejects cookies set on those. You can use a IP hostname instead, or update to the recent snapshot that will be created today, which has a bugfix for that. :)

Regards,
GArvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
sapphirecat
Regular
Posts: 7
Joined: Thu May 03, 2007 2:19 am

Post by sapphirecat »

garvinhicking wrote:Are you by chance running it via a http://localhost/ URL? Firefox rejects cookies set on those.
Yeah, I am, but I hadn't thought it was the problem because the similar 1.1 setup had worked fine. Thanks for the info!
Post Reply