Commit c3616955 authored by root's avatar root Committed by lechuck
Browse files

Adding plugin flattr

parent 742c9191
<?php
/*
Plugin Name: Flattr
Plugin URI: http://wordpress.org/extend/plugins/flattr/
Description: Give your readers the opportunity to Flattr your effort
Version: 0.9.18
Author: Flattr.com
Author URI: http://flattr.com/
License: This code is (un)licensed under the kopimi (copyme) non-license; http://www.kopimi.com. In other words you are free to copy it, taunt it, share it, fork it or whatever. :)
*/
if (version_compare(PHP_VERSION, '5.0.0', '<'))
{
require_once( WP_PLUGIN_DIR . '/' . plugin_basename( dirname(__FILE__) ) . '/flattr4.php');
}
else
{
require_once( WP_PLUGIN_DIR . '/' . plugin_basename( dirname(__FILE__) ) . '/flattr5.php');
}
<?php
add_action( 'admin_notices','flattrAdminNotice' );
function flattrAdminNotice() {
echo '<div id="message" class="error">';
echo '<p><strong>Warning:</strong> The Flattr plugin requires PHP5. You are currently using '. PHP_VERSION .'</p>';
echo '</div>';
}
/**
* returns the Flattr button
* Use this from your template
*/
function get_the_flattr_permalink()
{
return '';
}
/**
* prints the Flattr button
* Use this from your template
*/
function the_flattr_permalink()
{
}
<?php
class Flattr
{
const VERSION = '0.9.18';
const WP_MIN_VER = '2.9';
const API_SCRIPT = 'api.flattr.com/js/0.6/load.js?mode=auto';
/** @var array */
protected static $categories = array('text', 'images', 'audio', 'video', 'software', 'rest');
/** @var array */
protected static $languages;
/** @var Flattr */
protected static $instance;
/** @var Flattr_Settings */
protected $settings;
/** @var String */
protected $basePath;
public function __construct()
{
if (is_admin())
{
if (!$this->compatibilityCheck())
{
return;
}
$this->init();
}
if ( get_option('flattr_aut_page', 'off') == 'on' || get_option('flattr_aut', 'off') == 'on' )
{
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('the_content', array($this, 'injectIntoTheContent'),11);
add_filter('get_the_excerpt', array($this, 'filterGetExcerpt'), 1);
if ( get_option('flattr_override_sharethis', 'false') == 'true' ) {
add_action('plugins_loaded', array($this, 'overrideShareThis'));
}
}
wp_enqueue_script('flattrscript', ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'https://' : 'http://' ) . self::API_SCRIPT, array(), '0.6', true);
}
function overrideShareThis() {
if ( remove_filter('the_content', 'st_add_widget') || remove_filter('the_excerpt', 'st_add_widget') ) {
add_filter('flattr_button', array($this, 'overrideShareThisFilter'));
}
}
protected function addAdminNoticeMessage($msg)
{
if (!isset($this->adminNoticeMessages))
{
$this->adminNoticeMessages = array();
add_action( 'admin_notices', array(&$this, 'adminNotice') );
}
$this->adminNoticeMessages[] = $msg;
}
public function adminNotice()
{
echo '<div id="message" class="error">';
foreach($this->adminNoticeMessages as $msg)
{
echo "<p>{$msg}</p>";
}
echo '</div>';
}
protected function compatibilityCheck()
{
global $wp_version;
if (version_compare($wp_version, self::WP_MIN_VER, '<'))
{
$this->addAdminNoticeMessage('<strong>Warning:</strong> The Flattr plugin requires WordPress '. self::WP_MIN_VER .' or later. You are currently using '. $wp_version);
return false;
}
return true;
}
public function getBasePath()
{
if (!isset($this->basePath))
{
$this->basePath = WP_PLUGIN_DIR . '/' . plugin_basename( dirname(__FILE__) ) . '/';
}
return $this->basePath;
}
public function getButton($skipOptionCheck = false)
{
global $post;
if ( ! $skipOptionCheck && ( ($post->post_type == 'page' && get_option('flattr_aut_page', 'off') != 'on') || ($post->post_type != 'page' && get_option('flattr_aut', 'off') != 'on') || is_feed() ) )
{
return '';
}
if (get_post_meta($post->ID, '_flattr_btn_disabled', true))
{
return '';
}
$flattr_uid = get_option('flattr_uid');
if (!$flattr_uid) {
return '';
}
$selectedLanguage = get_post_meta($post->ID, '_flattr_post_language', true);
if (empty($selectedLanguage))
{
$selectedLanguage = get_option('flattr_lng');
}
$selectedCategory = get_post_meta($post->ID, '_flattr_post_category', true);
if (empty($selectedCategory))
{
$selectedCategory = get_option('flattr_cat');
}
$hidden = get_post_meta($post->ID, '_flattr_post_hidden', true);
if ($hidden == '')
{
$hidden = get_option('flattr_hide', false);
}
$buttonData = array(
'user_id' => $flattr_uid,
'url' => get_permalink(),
'compact' => ( get_option('flattr_compact', false) ? true : false ),
'hide' => $hidden,
'language' => $selectedLanguage,
'category' => $selectedCategory,
'title' => strip_tags(get_the_title()),
'body' => strip_tags(preg_replace('/\<br\s*\/?\>/i', "\n", $this->getExcerpt())),
'tag' => strip_tags(get_the_tag_list('', ',', ''))
);
if (isset($buttonData['user_id'], $buttonData['url'], $buttonData['language'], $buttonData['category']))
{
return $this->getButtonCode($buttonData);
}
}
protected function getButtonCode($params)
{
$rev = sprintf('flattr;uid:%s;language:%s;category:%s;',
$params['user_id'],
$params['language'],
$params['category']
);
if (!empty($params['tag']))
{
$rev .= 'tags:'. addslashes($params['tag']) .';';
}
if ($params['hide'])
{
$rev .= 'hidden:1;';
}
if ($params['compact'])
{
$rev .= 'button:compact;';
}
if (empty($params['body']) && !in_array($params['category'], array('images', 'video', 'audio')))
{
$params['body'] = get_bloginfo('description');
if (empty($params['body']) || strlen($params['body']) < 5)
{
$params['body'] = $params['title'];
}
}
return sprintf('<a class="FlattrButton" style="display:none;" href="%s" title="%s" rev="%s">%s</a>',
$params['url'],
addslashes($params['title']),
$rev,
$params['body']
);
}
public static function getCategories()
{
return self::$categories;
}
public static function filterGetExcerpt($content)
{
$excerpt_length = apply_filters('excerpt_length', 55);
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
return self::getExcerpt($excerpt_length) . $excerpt_more;
}
public static function getExcerpt($excerpt_max_length = 1024)
{
global $post;
$excerpt = $post->post_excerpt;
if (! $excerpt)
{
$excerpt = $post->post_content;
}
$excerpt = strip_shortcodes($excerpt);
$excerpt = strip_tags($excerpt);
$excerpt = str_replace(']]>', ']]&gt;', $excerpt);
// Hacks for various plugins
$excerpt = preg_replace('/httpvh:\/\/[^ ]+/', '', $excerpt); // hack for smartyoutube plugin
$excerpt = preg_replace('%httpv%', 'http', $excerpt); // hack for youtube lyte plugin
// Try to shorten without breaking words
if ( strlen($excerpt) > $excerpt_max_length )
{
$pos = strpos($excerpt, ' ', $excerpt_max_length);
if ($pos !== false)
{
$excerpt = substr($excerpt, 0, $pos);
}
}
// If excerpt still too long
if (strlen($excerpt) > $excerpt_max_length)
{
$excerpt = substr($excerpt, 0, $excerpt_max_length);
}
return $excerpt;
}
public static function getInstance()
{
if (!self::$instance)
{
self::$instance = new self();
}
return self::$instance;
}
public static function getLanguages()
{
if (!isset(self::$languages))
{
include(Flattr::getInstance()->getBasePath() . 'languages.php');
self::$languages = $languages;
}
return self::$languages;
}
protected function init()
{
if (!$this->settings)
{
require_once($this->getBasePath() . 'settings.php');
$this->settings = new Flattr_Settings();
}
if (!$this->postMetaHandler)
{
require_once($this->getBasePath() . 'postmeta.php');
$this->postMetaHandler = new Flattr_PostMeta();
}
}
public function setExcerpt($content)
{
global $post;
return $post->post_content;
}
public function overrideShareThisFilter($button) {
$sharethis_buttons = '';
if ( (is_page() && get_option('st_add_to_page') != 'no') || (!is_page() && get_option('st_add_to_content') != 'no') ) {
if (!is_feed() && function_exists('st_makeEntries')) {
$sharethis_buttons = st_makeEntries();
}
}
return $sharethis_buttons . ' <style>.wp-flattr-button iframe{vertical-align:text-bottom}</style>' . $button;
}
public function injectIntoTheContent($content)
{
$button = $this->getButton();
$button = '<p class="wp-flattr-button">' . apply_filters('flattr_button', $button) . '</p>';
if ( get_option('flattr_top', false) ) {
$result = $button . $content;
}
else {
$result = $content . $button;
}
return $result;
}
}
Flattr::getInstance();
/**
* returns the Flattr button
* Use this from your template
*/
function get_the_flattr_permalink()
{
return Flattr::getInstance()->getButton(true);
}
/**
* prints the Flattr button
* Use this from your template
*/
function the_flattr_permalink()
{
echo(get_the_flattr_permalink());
}
<?php
$languages['sq_AL'] = 'Albanian';
$languages['ar_DZ'] = 'Arabic';
$languages['be_BY'] = 'Belarusian';
$languages['bg_BG'] = 'Bulgarian';
$languages['ca_ES'] = 'Catalan';
$languages['zh_CN'] = 'Chinese';
$languages['hr_HR'] = 'Croatian';
$languages['cs_CZ'] = 'Czech';
$languages['da_DK'] = 'Danish';
$languages['nl_NL'] = 'Dutch';
$languages['en_GB'] = 'English';
$languages['et_EE'] = 'Estonian';
$languages['fi_FI'] = 'Finnish';
$languages['fr_FR'] = 'French';
$languages['de_DE'] = 'German';
$languages['el_GR'] = 'Greek';
$languages['iw_IL'] = 'Hebrew';
$languages['hi_IN'] = 'Hindi';
$languages['hu_HU'] = 'Hungarian';
$languages['is_IS'] = 'Icelandic';
$languages['in_ID'] = 'Indonesian';
$languages['ga_IE'] = 'Irish';
$languages['it_IT'] = 'Italian';
$languages['ja_JP'] = 'Japanese';
$languages['ko_KR'] = 'Korean';
$languages['lv_LV'] = 'Latvian';
$languages['lt_LT'] = 'Lithuanian';
$languages['mk_MK'] = 'Macedonian';
$languages['ms_MY'] = 'Malay';
$languages['mt_MT'] = 'Maltese';
$languages['no_NO'] = 'Norwegian';
$languages['pl_PL'] = 'Polish';
$languages['pt_PT'] = 'Portuguese';
$languages['ro_RO'] = 'Romanian';
$languages['ru_RU'] = 'Russian';
$languages['sr_RS'] = 'Serbian';
$languages['sk_SK'] = 'Slovak';
$languages['sl_SI'] = 'Slovenian';
$languages['es_ES'] = 'Spanish';
$languages['sv_SE'] = 'Swedish';
$languages['th_TH'] = 'Thai';
$languages['tr_TR'] = 'Turkish';
$languages['uk_UA'] = 'Ukrainian';
$languages['vi_VN'] = 'Vietnamese';
\ No newline at end of file
<input type="checkbox" value="1" name="flattr_btn_disabled" <?php if ((bool)$btnDisabled) { echo 'checked="checked"'; } ?>/>
Disable the Flattr button on this post?
<br />
<label for="flattr_post_language"><?php echo __('Language:') ?></label>
<select name="flattr_post_language" id="flattr_post_language">
<?php
foreach (Flattr::getLanguages() as $languageCode => $language)
{
printf('<option value="%s" %s>%s</option>',
$languageCode,
($languageCode == $selectedLanguage ? 'selected' : ''),
$language
);
}
?>
</select>
<br />
<label for="flattr_post_category"><?php echo __('Category:') ?></label>
<select name="flattr_post_category" id="flattr_post_category">
<?php
foreach (Flattr::getCategories() as $category)
{
printf('<option value="%s" %s>%s</option>',
$category,
($category == $selectedCategory ? 'selected' : ''),
ucfirst($category)
);
}
?>
</select>
<br />
<input type="hidden" value="0" name="flattr_post_hidden" />
<input type="checkbox" value="1" name="flattr_post_hidden" <?php if ((bool)$hidden) { echo 'checked="checked"'; } ?>/>
Hide post from listings on flattr.com
<br />
<?php
class Flattr_PostMeta
{
public function __construct()
{
add_action('admin_menu', array($this, 'add_meta_box'));
add_action('save_post', array($this, 'save_post'));
}
public function save_post($id)
{
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
{
return $id;
}
if ( !current_user_can('edit_post', $id) )
{
return $id;
}
add_post_meta($id, '_flattr_post_language', $_POST['flattr_post_language'], true) or update_post_meta($id, '_flattr_post_language', $_POST['flattr_post_language']);
add_post_meta($id, '_flattr_post_category', $_POST['flattr_post_category'], true) or update_post_meta($id, '_flattr_post_category', $_POST['flattr_post_category']);
add_post_meta($id, '_flattr_post_hidden', $_POST['flattr_post_hidden'], true) or update_post_meta($id, '_flattr_post_hidden', $_POST['flattr_post_hidden']);
add_post_meta($id, '_flattr_btn_disabled', $_POST['flattr_btn_disabled'], true) or update_post_meta($id, '_flattr_btn_disabled', $_POST['flattr_btn_disabled']);
return true;
}
public function add_meta_box()
{
if ( function_exists('add_meta_box') )
{
add_meta_box('flattr_post_settings', __('Flattr settings'), array($this, 'inner_meta_box'), 'post', 'advanced');
add_meta_box('flattr_post_settings', __('Flattr settings'), array($this, 'inner_meta_box'), 'page', 'advanced');
}
else
{
add_action('dbx_post_advanced', array($this, 'old_meta_box'));
add_action('dbx_page_advanced', array($this, 'old_meta_box'));
}
}
public function old_meta_box()
{
?>
<div class="dbx-b-ox-wrapper">
<fieldset id="flattr_fieldsetid" class="dbx-box">
<div class="dbx-h-andle-wrapper"><h3 class="dbx-handle">Flattr settings</h3></div>
<div class="dbx-c-ontent-wrapper">
<div class="dbx-content">
<?php $this->inner_meta_box(); ?>
</div>
</div>
</fieldset>
</div>
<?php
}
public function inner_meta_box()
{
global $post;
$selectedLanguage = get_post_meta($post->ID, '_flattr_post_language', true);
if (empty($selectedLanguage))
{
$selectedLanguage = get_option('flattr_lng');
}
$selectedCategory = get_post_meta($post->ID, '_flattr_post_category', true);
if (empty($selectedCategory))
{
$selectedCategory = get_option('flattr_cat');
}
$hidden = get_post_meta($post->ID, '_flattr_post_hidden', true);
if ($hidden == '')
{
$hidden = get_option('flattr_hide', 0);
}
$btnDisabled = get_post_meta($post->ID, '_flattr_btn_disabled', true);
if (empty($btnDisabled))
{
$btnDisabled = get_option('flattr_disable', 0);
}
include('postmeta-template.php');
}
}
=== Flattr ===
Contributors: flattr.com
Tags: flattr, donate, micropayments
Requires at least: 2.9.0
Tested up to: 3.0.1
Stable tag: trunk
This plugin allows you to easily add a Flattr button to your wordpress blog.
== Description ==
Flattr was founded to help people share money, not only content. Before Flattr, the only reasonable way to donate has been to use Paypal or other systems to send money to people. The threshold for this is quite high. People would just ignore sending donations if it wasn't for a really important cause. Sending just a small sum has always been a pain in the ass. Who would ever even login to a payment system just to donate €0.01? And €10 was just too high for just one blog entry we liked...
Flattr solves this issue. When you're registered to flattr, you pay a small monthly fee. You set the amount yourself. In the end of the month, that fee is divided between all the things you flattered. You're always logged in to the account. That means that giving someone some flattr-love is just a button away. And you should! Clicking one more button doesn't add to your fee. It just divides the fee between more people! Flattr tries to encourage people to share. Not only pieces of content, but also some money to support the people who created them. With love!
**Flattr requires an account at flattr.com!**
== Installation ==
Note that we only support PHP 5 and WordPress 2.9 or above.
1. Upload the folder 'flattr' to your server in the folder '/wp-content/plugins/'
2. Go to the WordPress control panel and find the 'Plugins' section
3. Activate the plugin 'Flattr'
4. Go to the 'Options' section and select 'Flattr'
5. Select your default category (which usually would be 'text' if you have a normal blog), select your default language and type in your Flattr user ID (your user ID can be found on your dashboard on http://flattr.com/ )
6. If you want the Flattr button to be automagically included at the end of your posts, leave the checkbox checked
7. If you want to add the Flattr button manually in your theme, uncheck the checkbox and use the following code snippet:
8. When writing or editing a blog post you have the ability to select category and language for this specific blog post.
`<?php the_flattr_permalink(); ?>`
8. Live long and prosper. :)
== Changelog ==
= 0.9.18 =
Will now use version 0.6 of the JS API.
Will load the JS API using https only if the blog itself is using https. This should make the button load a bit faster for most of you.
= 0.9.17 =
Fixed PHP5 detection, will now show a message rather than throwing error on PHP4.
= 0.9.16 =
New release due to changes lost in the last release.
= 0.9.15 =