Loading...
 
Skip to main content

Plugin allowing to integrate Flattr

Status
Open
Subject
Plugin allowing to integrate Flattr
Version
6.x
Category
  • Feature request
Feature
Wiki Plugin (extends basic syntax)
Submitted by
costamojan
Lastmod by
costamojan
Rating
(0)
Description

Here's a little plugin that allows to easily integrate Flattr with the wiki. Since this is my first attempt to write a plugin it would be great to review the code (especially since I'm no expert for php).
One thing that would be nice to solve would be the inclusion of the javascript part which should be added into the head-element when the rendered page contains a flattr plugin. I just did that while using a simple switch. Really ugly but it works for me.

Bye

Solution
wikiplugin_flattr
Copy to clipboard
<?php // Wiki plugin for the integration of Flattr // By Daniel Kasmeroglu, Copyright (C) 2011. All rights reserved. // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE (LGPL). function wikiplugin_flattr_help() { return tra("Create a Flattr link").":<br /> {flattr(url=*, button=large|compact|static)}".tra("text")."{flattr} "; } function wikiplugin_flattr_info() { return array( 'name' => tra('Flattr'), 'description' => tra('Create a Flattr link in the wiki page.'), 'validate' => 'all', 'params' => array( 'url' => array( 'required' => true, 'name' => tra('The location of the resource for the contribution'), 'description' => tra('The URL is used to identify the resource (project) which will be used for the contribution.'), ), 'button' => array( 'required' => false, 'name' => tra('Type of the Flattr button to be displayed.'), 'description' => tra('Just select the button type. Default is *large*. Allowed: large, compact, static.'), ), ), ); } $wikiplugin_flattr_gotscript = 0; function wikiplugin_flattr($data, $params) { // Always include this line to read the data and parameters. extract ($params,EXTR_SKIP); $quote =''; // Check for color if (!isset($url)) { $msg = 'Please specify a valid URL.'; return $msg; } else { $u = $url; } // Check for the button type if (!isset($button)) { $b = "large"; } else { if ((strcmp("large", $button) == 0) || (strcmp("compact", $button) == 0) || (strcmp("static", $button) == 0)) { $b = $button; } else { $msg = 'The button type is only allowed to have one of the following values: large, compact, static.'; return $msg; } } // @todo [24-Mar-2011:KASI] Check how to alter the head-element of a page, so the script part could go there. if ($wikiplugin_flattr_gotscript == 0) { $quote .= "<script type='text/javascript'>"; $quote .= "/* <![CDATA[ */"; $quote .= " (function() {"; $quote .= " var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];"; $quote .= " s.type = 'text/javascript';"; $quote .= " s.async = true;"; $quote .= " s.src = 'http://api.flattr.com/js/0.6/load.js?mode=auto';"; $quote .= " t.parentNode.insertBefore(s, t);"; $quote .= " })();"; $quote .= "/* ]]> */"; $quote .= "</script>"; $wikiplugin_flattr_gotscript = 1; } // Build the output if (strcmp("large", $b) == 0) { $quote .= "<a class='FlattrButton' style='display:none;' href='".$u."'></a>"; } else if (strcmp("compact", $b) == 0) { $quote .= "<a class='FlattrButton' style='display:none;' href='".$u."' rev='flattr;button:compact;'></a>"; } else /* if (strcmp("static", $b) == 0) */ { $quote .= "<a href='".$u."' target='_blank'>"; $quote .= "<img src='http://api.flattr.com/button/flattr-badge-large.png' alt='Flattr this' title='Flattr this' border='0'/></a>"; } return $quote; } ?>
Importance
1 low
Priority
5
Demonstrate Bug on Tiki 19+
Demonstrate Bug (older Tiki versions)
Ticket ID
3833
Created
Wednesday 23 March, 2011 23:45:25 UTC
by costamojan
LastModif
Wednesday 23 March, 2011 23:48:53 UTC


Show PHP error messages