Flattr plugin with text buttons

Creating and modifying plugins.
Post Reply
nomeata
Posts: 2
Joined: Mon Jul 04, 2011 2:00 pm

Flattr plugin with text buttons

Post by nomeata »

Hi,

I started using the flattr plugin, but I really dislike the buttons (too intrusive, not welcome on all planets), even the static one. Now someone pointed out to me that it is possible to auto-create things in flattr even with static links, see http://flattrchattr.com/2011/06/20/flat ... press-com/. I thus patched the flattr plugin to support this feature.

Code: Select all

Index: lang_de.inc.php
===================================================================
RCS file: /cvsroot/php-blog/additional_plugins/serendipity_event_flattr/lang_de.inc.php,v
retrieving revision 1.2
diff -u -r1.2 lang_de.inc.php
--- lang_de.inc.php	18 May 2010 12:03:04 -0000	1.2
+++ lang_de.inc.php	4 Jul 2011 12:02:31 -0000
@@ -9,10 +9,10 @@
 @define('PLUGIN_FLATTR_PLACEMENT_SMARTY', 'Als Smarty-Variable {$entry.flattr}, f�r entries.tpl');
 @define('PLUGIN_FLATTR_PLACEMENT', 'Wo soll der flattr-Button erscheinen');
 
-@define('PLUGIN_FLATTR_BUTTON', 'Flattr Button-Typ ("default" oder "compact")');
+@define('PLUGIN_FLATTR_BUTTON', 'Flattr Button-Typ ("default", "compact" or "text")');
 @define('PLUGIN_FLATTR_CATS', 'Flattr-Kategorie');
 @define('PLUGIN_FLATTR_LANG', 'Flattr-Sprache');
 @define('PLUGIN_FLATTR_DSC', 'Flattr-Beschreibung (standardm��ig Artikeltext)');
 @define('PLUGIN_FLATTR_TAG', 'Flattr-Schlagw�rter (standardm��ig vom Artikel-Tags-Plugin, falls verwendet)');
 
-@define('PLUGIN_FLATTR_ACTIVE', 'Flattr aktivieren');
\ No newline at end of file
+@define('PLUGIN_FLATTR_ACTIVE', 'Flattr aktivieren');
Index: lang_en.inc.php
===================================================================
RCS file: /cvsroot/php-blog/additional_plugins/serendipity_event_flattr/lang_en.inc.php,v
retrieving revision 1.2
diff -u -r1.2 lang_en.inc.php
--- lang_en.inc.php	18 May 2010 12:03:04 -0000	1.2
+++ lang_en.inc.php	4 Jul 2011 12:02:31 -0000
@@ -9,10 +9,10 @@
 @define('PLUGIN_FLATTR_PLACEMENT_SMARTY', 'Smarty-Variable {$entry.flattr}, for entries.tpl');
 @define('PLUGIN_FLATTR_PLACEMENT', 'Where to place flattr-Badge');
 
-@define('PLUGIN_FLATTR_BUTTON', 'Flattr Badge-Style ("default" or "compact")');
+@define('PLUGIN_FLATTR_BUTTON', 'Flattr Badge-Style ("default", "compact" or "text")');
 @define('PLUGIN_FLATTR_CATS', 'Flattr posting category');
 @define('PLUGIN_FLATTR_LANG', 'Flattr posting language');
 @define('PLUGIN_FLATTR_DSC', 'Flattr posting description (defaults to entry body)');
 @define('PLUGIN_FLATTR_TAG', 'Flattr posting tags (defaults to freetag plugin, if used)');
 
-@define('PLUGIN_FLATTR_ACTIVE', 'Enable flattr');
\ No newline at end of file
+@define('PLUGIN_FLATTR_ACTIVE', 'Enable flattr');
Index: serendipity_event_flattr.php
===================================================================
RCS file: /cvsroot/php-blog/additional_plugins/serendipity_event_flattr/serendipity_event_flattr.php,v
retrieving revision 1.14
diff -u -r1.14 serendipity_event_flattr.php
--- serendipity_event_flattr.php	10 Jun 2011 12:08:22 -0000	1.14
+++ serendipity_event_flattr.php	4 Jul 2011 12:02:31 -0000
@@ -46,8 +46,8 @@
             'flattr_lng'
         ));
 
-        $propbag->add('author',  'Garvin Hicking');
-        $propbag->add('version', '1.7');
+        $propbag->add('author',  'Garvin Hicking, Joachim Breitner');
+        $propbag->add('version', '1.7.nomeata');
         $propbag->add('requirements',  array(
             'serendipity' => '0.7',
             'smarty'      => '2.6.7',
@@ -316,26 +316,40 @@
                 $flattr_url = substr($flattr_url, 0, 2048);
                 $flattr_btn = substr($flattr_btn, 0, 255);
 
-                $flattr = "
-<script type=\"text/javascript\">
-var flattr_uid = '{$flattr_uid}';
-var flattr_tle = '{$flattr_tle}';
-var flattr_dsc = '{$flattr_dsc}';
-var flattr_cat = '{$flattr_cat}';
-var flattr_lng = '{$flattr_lng}';
-var flattr_tag = '{$flattr_tag}';
-var flattr_url = '{$flattr_url}';
-var flattr_btn = '{$flattr_btn}';
-</script>
-<script src=\"http://api.flattr.com/button/load.js\" type=\"text/javascript\"></script>
-";
+		if ($flattr_btn == "text") {
+			$flattr = 
+			"<a href=\"https://flattr.com/submit/auto?".
+			"user_id=".urlencode($flattr_uid)."&".
+			"url=".urlencode($flattr_url)."&".
+			"title=".urlencode($flattr_tle)."&".
+			"description=".urlencode($flattr_dsc)."&".
+			"category=".urlencode($flattr_cat)."&".
+			"language=".urlencode($flattr_lng).
+			"\">Flattr this post</a>";
+
+		} else {
+			$flattr = "
+		<script type=\"text/javascript\">
+		var flattr_uid = '{$flattr_uid}';
+		var flattr_tle = '{$flattr_tle}';
+		var flattr_dsc = '{$flattr_dsc}';
+		var flattr_cat = '{$flattr_cat}';
+		var flattr_lng = '{$flattr_lng}';
+		var flattr_tag = '{$flattr_tag}';
+		var flattr_url = '{$flattr_url}';
+		var flattr_btn = '{$flattr_btn}';
+		</script>
+		<script src=\"http://api.flattr.com/button/load.js\" type=\"text/javascript\"></script>
+		";
+		}
 
                 $field = $this->get_config('placement');
                 
                 if ($addData['from'] == 'functions_entries:updertEntry') {
                 } elseif ($addData['from'] == 'functions_entries:printEntries_rss') {
                     $entryText =& $this->getFieldReference($field, $eventData);
-                    $entryText .= htmlspecialchars($flattr);
+                    # $entryText .= htmlspecialchars($flattr);
+                    $entryText .= $flattr;
                 } else {
                     $entryText =& $this->getFieldReference($field, $eventData);
                     $entryText .= $flattr;
I also patched the RSS generation to include the add_footer data in the RSS feed. Not sure if this is something that can be used generally:

Code: Select all

$ diff functions_rss.inc.php.orig functions_rss.inc.php -u
--- functions_rss.inc.php.orig	2011-07-04 13:45:39.742423598 +0200
+++ functions_rss.inc.php	2011-07-04 13:50:48.088996267 +0200
@@ -81,6 +81,9 @@
             // Do some relative -> absolute URI replacing magic. Replaces all HREF/SRC (<a>, <img>, ...) references to only the serendipitypath with the full baseURL URI
             // garvin: Could impose some problems. Closely watch this one.
             $entry['body'] = preg_replace('@(href|src)=("|\')(' . preg_quote($serendipity['serendipityHTTPPath']) . ')(.*)("|\')(.*)>@imsU', '\1=\2' . $serendipity['baseURL'] . '\4\2\6>', $entry['body']);
+	    if($entry['add_footer']) {
+                $ext .= '<br/>'.$entry['add_footer'];
+	    }
             // jbalcorn: clean up body for XML compliance as best we can.
             $entry['body'] = xhtml_cleanup($entry['body']);

The result can be seen on http://www.joachim-breitner.de/blog/

And here are some feature requests (some probably too special to be generally useful):
  • Disable flattr per default (in case one only wants to enable individual posts)
  • Detect language from category (for users who have per-language categories)
  • Add a "Flattr this Blog" link with a hard-coded thing number for entries that do not have an individual flattr button (cf. the first point)
Thanks,
Joachim
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Flattr plugin with text buttons

Post by garvinhicking »

Hi!

Thanks a lot for sharing! I've committed your change in a slightly different fashion, so users can enter any string they want for the button style, and that is then used for the "Flattr this post" button.

As for the RSS change: Adding the footer there could mean a lot of trouble for many other plugins listening on that event. The add_Footer is not meant for content within the RSS feed, where only the body itself should appear.

The way that it's suggested is to change the flattr plugin to smarty placement, and then edit your feed*.tpl template files and put {$entry.flattr|@escape} there where you want it in the RSS feed. This method then also allows you to put any custom smarty logic in your entries.tpl file, so that you can also place static content there if you like...

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/
nomeata
Posts: 2
Joined: Mon Jul 04, 2011 2:00 pm

Re: Flattr plugin with text buttons

Post by nomeata »

garvinhicking wrote: Thanks a lot for sharing! I've committed your change in a slightly different fashion, so users can enter any string they want for the button style, and that is then used for the "Flattr this post" button.
Sounds good, although maybe a bit confusing – UI-wise it might be easier with a drop-down selection for the type and a custom field for the text. Just in case someone cares about such minor things (I don’t really).
garvinhicking wrote: As for the RSS change: Adding the footer there could mean a lot of trouble for many other plugins listening on that event. The add_Footer is not meant for content within the RSS feed, where only the body itself should appear.

The way that it's suggested is to change the flattr plugin to smarty placement, and then edit your feed*.tpl template files and put {$entry.flattr|@escape} there where you want it in the RSS feed. This method then also allows you to put any custom smarty logic in your entries.tpl file, so that you can also place static content there if you like...
Fair enough. I guess I’ll revert that here and use your code.
Post Reply