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
<?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; } ?>
To help developers solve the bug, we kindly request that you demonstrate your bug on a show2.tiki.org instance. To start, simply select a version and click on "Create show2.tiki.org instance". Once the instance is ready (in a minute or two), as indicated in the status window below, you can then access that instance, login (the initial admin username/password is "admin") and configure the Tiki to demonstrate your bug. Priority will be given to bugs that have been demonstrated on show2.tiki.org.
Unable to connect to show.tikiwiki.org. Please let us know of the problem so that we can do something about it. Thanks.
filename | created | hits | comment | version | filetype | ||
---|---|---|---|---|---|---|---|
No attachments for this item |