Commit 9540593a authored by root's avatar root Committed by lechuck
Browse files

Import flattr 0.9.22.2

parent c05fff99
<?php
if ( isset ($_REQUEST['oauth_token']) && isset ($_REQUEST['oauth_verifier'])) {
if (session_id() == '') { session_start(); }
include_once "oAuth/flattr_rest.php";
$api_key = get_option('flattrss_api_key');
$api_secret = get_option('flattrss_api_secret');
$flattr = new Flattr_Rest($api_key, $api_secret, $_SESSION['flattrss_current_token']['oauth_token'], $_SESSION['flattrss_current_token']['oauth_token_secret']);
$access_token = $flattr->getAccessToken($_REQUEST['oauth_verifier']);
if ($flattr->http_code == 200) {
add_option('flattrss_api_oauth_token', $access_token['oauth_token']);
update_option('flattrss_api_oauth_token', $access_token['oauth_token']);
add_option('flattrss_api_oauth_token_secret', $access_token['oauth_token_secret']);
update_option('flattrss_api_oauth_token_secret', $access_token['oauth_token_secret']);
} else {
wp_die("<h1>Callback Error.</h1><p>Please clear browser cach and cookies, then try again. Sorry for the inconvenience.</p><p align='right'>Michael Henke</p>");
}
header("Status: 307");
header("Location: ". get_bloginfo('wpurl') .'/wp-admin/admin.php?page=flattr/settings.php');
exit(307);
}
\ No newline at end of file
<?php
/**
* @package Flattr
* @author Michael Henke
* @version 0.9.22.2
*/
/*
Plugin Name: Flattr
Plugin URI: http://wordpress.org/extend/plugins/flattr/
Description: Give your readers the opportunity to Flattr your effort
Version: 0.9.19
Author: Flattr.com
Author URI: http://flattr.com/
Version: 0.9.22.2
Author: Michael Henke
Author URI: http://allesblog.de/
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. :)
*/
Comment: The author of this plugin is not affiliated with the flattr company in whatever meaning.
*/
if (version_compare(PHP_VERSION, '5.0.0', '<'))
{
......
<?php
if (session_id() == '') { session_start(); }
class Flattr
{
const VERSION = '0.9.19';
const VERSION = '0.9.22';
const WP_MIN_VER = '2.9';
const API_SCRIPT = 'api.flattr.com/js/0.6/load.js?mode=auto';
......@@ -30,11 +32,12 @@ class Flattr
$this->init();
}
if ( get_option('flattr_aut_page', 'off') == 'on' || get_option('flattr_aut', 'off') == 'on' )
if (( get_option('flattr_aut_page', 'off') == 'on' || get_option('flattr_aut', 'off') == 'on' ) && !in_array( 'live-blogging/live-blogging.php' , get_option('active_plugins') ))
{
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);
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'));
}
......@@ -200,13 +203,13 @@ class Flattr
public static function filterGetExcerpt($content)
{
$excerpt_length = apply_filters('excerpt_length', 55);
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
$excerpt_length = apply_filters('excerpt_length', 55);
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
return self::getExcerpt($excerpt_length) . $excerpt_more;
return self::getExcerpt($excerpt_length, $excerpt_more);
}
public static function getExcerpt($excerpt_max_length = 1024)
public static function getExcerpt($excerpt_max_length = 55, $excerpt_more = ' [...]')
{
global $post;
......@@ -223,11 +226,20 @@ class Flattr
// Hacks for various plugins
$excerpt = preg_replace('/httpvh:\/\/[^ ]+/', '', $excerpt); // hack for smartyoutube plugin
$excerpt = preg_replace('%httpv%', 'http', $excerpt); // hack for youtube lyte plugin
$excerpt = explode(' ', $excerpt, $excerpt_max_length);
if ( count($excerpt) >= $excerpt_max_length) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).' ...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
// Try to shorten without breaking words
if ( strlen($excerpt) > $excerpt_max_length )
if ( strlen($excerpt) > 1024 )
{
$pos = strpos($excerpt, ' ', $excerpt_max_length);
$pos = strpos($excerpt, ' ', 1024);
if ($pos !== false)
{
$excerpt = substr($excerpt, 0, $pos);
......@@ -235,9 +247,9 @@ class Flattr
}
// If excerpt still too long
if (strlen($excerpt) > $excerpt_max_length)
if (strlen($excerpt) > 1024)
{
$excerpt = substr($excerpt, 0, $excerpt_max_length);
$excerpt = substr($excerpt, 0, 1024);
}
return $excerpt;
......@@ -297,6 +309,9 @@ class Flattr
public function injectIntoTheContent($content)
{
global $post;
if (in_array(get_post_type(), get_option('flattr_post_types'))) {
$button = $this->getButton();
$button = '<p class="wp-flattr-button">' . apply_filters('flattr_button', $button) . '</p>';
......@@ -311,7 +326,9 @@ class Flattr
{
return $result;
}
return $content;
}
return $content;
}
}
......@@ -334,3 +351,228 @@ function the_flattr_permalink()
{
echo(get_the_flattr_permalink());
}
if (file_exists(WP_PLUGIN_DIR . '/' . plugin_basename( dirname(__FILE__) ) . '/flattrwidget.php')) {
include WP_PLUGIN_DIR . '/' . plugin_basename( dirname(__FILE__) ) . '/flattrwidget.php';
}
add_action('admin_init', 'tabber_stylesheet');
/*
* Enqueue style-file, if it exists.
*/
function tabber_stylesheet() {
$myStyleUrl = WP_PLUGIN_URL . '/flattr/tabber.css';
$myStyleFile = WP_PLUGIN_DIR . '/flattr/tabber.css';
if ( file_exists($myStyleFile) ) {
wp_register_style('myStyleSheets', $myStyleUrl);
wp_enqueue_style( 'myStyleSheets');
}
}
if(!defined('FLATTRSS_PLUGIN_PATH')) { define(FLATTRSS_PLUGIN_PATH, get_bloginfo('wpurl') . '/wp-content/plugins/flattr'); }
add_option('flattrss_api_key', "");
add_option('flattrss_autodonate', false);
add_option('flattrss_api_secret', "");
add_option('flattrss_api_oauth_token',"");
add_option('flattrss_api_oauth_token_secret',"");
add_option('flattrss_custom_image_url', FLATTRSS_PLUGIN_PATH .'/img/flattr-badge-large.png');
add_option('flattrss_clicktrack_since_date', date("r"));
add_option('flattrss_clickthrough_n', 0);
add_option('flattrss_clicktrack_enabled', true);
add_option('flattrss_error_reporting', true);
add_option('flattrss_autosubmit', true);
add_option('flattr_post_types', array('post','page'));
function flattr_post2rss($content) {
global $post;
$flattr = "";
$flattr_post_types = get_option('flattr_post_types');
if (is_feed() && in_array(get_post_type(), $flattr_post_types)) {
$id = $post->ID;
$md5 = md5($post->post_title);
$permalink = urlencode(get_permalink( $id ));
$flattr.= ' <p><a href="'. get_bloginfo('wpurl') .'/?flattrss_redirect&amp;id='.$id.'&amp;md5='.$md5.'" title="Flattr" target="_blank"><img src="'. FLATTRSS_PLUGIN_PATH .'/img/flattr-badge-large.png" alt="flattr this!"/></a></p>';
}
return ($content.$flattr);
}
if(function_exists('curl_init')) {
add_filter('the_content_feed', 'flattr_post2rss',999999);
}
function new_flattrss_autosubmit_action () {
global $call_n;
$post = $_POST;
if (((get_option('flattr_hide') == false) && $post['post_status'] == "publish") && ($post['original_post_status'] != "publish" && (strtotime($post['post_date_gmt']) - strtotime(gmdate("Y-m-d H:i:s")) <= 0)) && ($call_n == 1)) {
$e = error_reporting();
error_reporting(E_ERROR);
$url = get_permalink($post['ID']);
$tagsA = get_the_tags($post['ID']);
$tags = "";
if ($tagsA) {
foreach ($tagsA as $tag) {
if (strlen($tags)!=0){
$tags .=",";
}
$tags .= $tag->name;
}
}
if (trim($tags) == "") {
$tags .= "blog";
}
$category = "text";
if (get_option('flattr_cat')!= "") {
$category = get_option('flattr_cat');
}
$language = "en_EN";
if (get_option('flattr_lng')!="") {
$language = get_option('flattr_lng');
}
if (!function_exists('getExcerpt')) {
function getExcerpt($post, $excerpt_max_length = 1024) {
$excerpt = $post['post_excerpt'];
if (trim($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;
}
}
$content = preg_replace(array('/\<br\s*\/?\>/i',"/\n/","/\r/", "/ +/"), " ", getExcerpt($post));
$content = strip_tags($content);
if (strlen(trim($content)) == 0) {
$content = "(no content provided...)";
}
$title = strip_tags($post['post_title']);
$title = str_replace(array("\"","\'"), "", $title);
$api_key = get_option('flattrss_api_key');
$api_secret = get_option('flattrss_api_secret');
$oauth_token = get_option('flattrss_api_oauth_token');
$oauth_token_secret = get_option('flattrss_api_oauth_token_secret');
if (!class_exists('Flattr_Rest')) {
include 'oAuth/flattr_rest.php';
}
$flattr_user = new Flattr_Rest($api_key, $api_secret, $oauth_token, $oauth_token_secret);
if ($flattr_user->error()) {
return;
}
if(!function_exists("encode")) {
function encode($string) {
if (function_exists("mb_detect_encoding")) {
$string = (mb_detect_encoding($string, "UTF-8") == "UTF-8" )? $string : utf8_encode($string);
} else {
$string = utf8_encode($string);
}
return $string;
}
}
#print_r(array($url, encode($title), $category, encode($content), $tags, $language));
$flattr_user->submitThing($url, encode($title), $category, encode($content), $tags, $language, get_option('flattr_hide'));
/*
if (get_option('flattrss_autodonate') && !isset($_SESSION['flattrss_autodonate_click'])) {
$flattr_user->clickThing("ead246fc95fc401ce69d15f3981da971");
$_SESSION['flattrss_autodonate_click'] = true;
}*/
error_reporting($e);
}
$call_n = 1;
}
if (get_option('flattrss_autosubmit') && function_exists('curl_init')) {
add_action('save_post','new_flattrss_autosubmit_action',9999);
}
add_action('init', 'new_flattrss_redirect');
add_action('init', 'new_flattrss_callback');
function new_flattrss_redirect() {
include_once 'redirect.php';
}
function new_flattrss_callback() {
include_once 'callback.php';
}
if(is_admin()) {
$admin_notice = "";
$oauth_token = get_option('flattrss_api_oauth_token');
$oauth_token_secret = get_option('flattrss_api_oauth_token_secret');
$active_plugins = get_option('active_plugins');
if ( in_array( 'live-blogging/live-blogging.php' , $active_plugins ) && ( get_option('flattr_aut_page', 'off') == 'on' || get_option('flattr_aut', 'off') == 'on' ) ) {
$admin_notice .= 'echo \'<div id="message" class="updated"><p><strong>Warning:</strong> There is an <a href="http://wordpress.org/support/topic/plugin-live-blogging-how-to-avoid-the_content-of-live_blog_entries" target="_blank">incompatibility</a> with [Liveblog] plugin and automatic Flattr button injection! Automatic injection is disabled as long as [Liveblog] plugin is enabled. You need to use the manual method to add Flattr buttons to your posts.</p></div>\';';
}
if (defined('LIBXML_VERSION')) {
define('LIBXML_TARGET',20616);
if (version_compare(LIBXML_VERSION, LIBXML_TARGET, '<')) {
$admin_notice .= 'echo \'<div id="message" class="updated"><p><strong>Warning:</strong> There might be an <a href="http://forum.flattr.net/showthread.php?tid=681" target="_blank">incompatibility</a> with your web server running libxml '.LIBXML_VERSION.'. Flattr Plugin requieres at least '.LIBXML_TARGET.'. You can help improve the Flattr experience for everybody, <a href="mailto:flattr@allesblog.de?subject='.rawurlencode("My webserver is running LIBXML Version ".LIBXML_VERSION).'">please contact me</a> :). See Feedback-tab for details.</p></div>\';';
}
} else {
$admin_notice .= 'echo \'<div id="message" class="error"><p><strong>Error:</strong> Your PHP installation must support <strong>libxml</strong> for Flattr plugin to work!</p></div>\';';
}
if (in_array( 'flattrss/flattrss.php' , $active_plugins)) {
$admin_notice .= 'echo \'<div id="message" class="error"><p><strong>Error:</strong> It is mandatory for <strong>FlattRSS</strong> plugin to be at least deactivated. Functionality and Settings are merged into the Flattr plugin.</p></div>\';';
}
if (in_array( 'flattrwidget/flattrwidget.php' , $active_plugins)) {
$admin_notice .= 'echo \'<div id="message" class="error"><p><strong>Error:</strong> It is mandatory for <strong>Flattr Widget</strong> plugin to be at least deactivated. Functionality and Settings are merged into the Flattr plugin.</p></div>\';';
}
if ($admin_notice != "") {
add_action( 'admin_notices',
create_function('', $admin_notice)
);
}
}
\ No newline at end of file
<?php
if (!function_exists('flattrwidget_control')) {
function new_flattrwidget_control() {
$options = get_option("flattrwidget");
if (!is_array( $options )) {
$options = array(
'title' => 'Flattr',
'text' => '',
'above' => true,
'compact' => false,
'html' => false
);
}
if ($_POST['flattrwidget-submit']) {
$options['title'] = htmlspecialchars($_POST['flattrwidget-title']);
if($options['html']) {
$options['text'] = $_POST['flattrwidget-text'];
} else {
$options['text'] = htmlspecialchars($_POST['flattrwidget-text']);
};
$options['above'] = $_POST['flattrwidget-above'];
$options['compact'] = $_POST['flattrwidget-compact'];
$options['html'] = $_POST['flattrwidget-html'];
update_option("flattrwidget", $options);
}
?>
<p>
<label for="flattrwidget-title">Title: </label><br />
<input class="widefat" type="text" id="flattrwidget-title" name="flattrwidget-title" value="<?php echo $options['title'];?>" />
<label for="flattrwidget-text">Text: </label><br />
<textarea class="widefat" rows="16" cols="10" type="text" id="flattrwidget-text" name="flattrwidget-text"><?php echo stripslashes($options['text']);?></textarea>
<input type="checkbox" id="flattrwidget-above" name="flattrwidget-above"<?php if ($options['above']) { echo " checked"; } ?> />
<label for="flattrwidget-above">Check to display the text above the Flattr button. (leave unchecked to display below)</label><br />
<input type="checkbox" id="flattrwidget-html" name="flattrwidget-html"<?php if ($options['html']) { echo " checked"; } ?> />
<label for="flattrwidget-html">Check to allow HTML in text.</label><br />
<input type="checkbox" id="flattrwidget-compact" name="flattrwidget-compact"<?php if ($options['compact']) { echo " checked"; } ?> />
<label for="flattrwidget-compact">Check to use compact style Flattr button.</label><br />
<input type="hidden" id="flattrwidget-submit" name="flattrwidget-submit" value="1" />
<?php
if (!get_option('flattr_uid')) {
$url = get_bloginfo('wpurl') .'/wp-admin/plugin-install.php?tab=plugin-information&plugin=flattr&TB_iframe=true&width=640&height=840';
echo "<p>You need the <a href=\"$url\">official Flattr plugin</a> installed, activated and configured for the widget to work!</p>";
echo "<p>Nothing will be displayed in your sidebar right now.</p>";
}
}
function new_flattrwidget_widget($args) {
if (!get_option('flattr_uid')) { return; }
extract($args);
$options = get_option("flattrwidget");
echo $before_widget;
echo $before_title;
echo $options['title'];
echo $after_title;
if ($options['above']) { echo "<p>". stripslashes($options['text']) ."</p>"; }
echo "<p align=\"center\">";
$uid = get_option('flattr_uid');
$cat = get_option('flattr_cat');
$lang = get_option('flattr_lng');
$category = $cat;
$title = get_bloginfo('name');
$description = get_bloginfo('description');
$tags = 'blog,wordpress,widget';
$url = get_bloginfo('url');
$language = $lang;
$userID = $uid;
$compact = compact;
if (!$options['compact']) { $compact = 'large'; }
$cleaner = create_function('$expression', "return trim(preg_replace('~\r\n|\r|\n~', ' ', addslashes(\$expression)));");
# button: compact | default
/*
* <a class="FlattrButton" style="display:none;"
title="Detta är min post titel"
data-flattr-uid="kjell"
data-flattr-tags="tag1, tag2"
data-flattr-category="text"
href="http://wp.local/?p=444">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Lorem ipsum dolor sit amet, consectetur adipiscing
Maecenas aliquet aliquam leo quis fringilla.
</a>
*/
$output = "<a class='FlattrButton' style='display:none;'".
' href="'.$cleaner($url).'"'.
' title="'.$cleaner($title).'"'.
' data-flattr-uid="'.$cleaner($userID).'"'.
' data-flattr-tags="'.$tags.'"'.
' data-flattr-button="'.$compact.'"'.
' data-flattr-category="'.$cleaner($category).'">'.
$cleaner($description).
'</a>';
/*
$output = "<script type=\"text/javascript\">\n";
if ( defined('Flattr::VERSION')) {
$output .= "var flattr_wp_ver = '" . Flattr::VERSION . "';\n";
}
$output .= "var flattr_uid = '" . $cleaner($userID) . "';\n";
$output .= "var flattr_url = '" . $cleaner($url) . "';\n";
$output .= "var flattr_lng = '" . $cleaner($language) . "';\n";
$output .= "var flattr_cat = '" . $cleaner($category) . "';\n";
if($tags) { $output .= "var flattr_tag = '". $cleaner($tags) ."';\n"; }
if ($options['compact']) { $output .= "var flattr_btn = 'compact';\n"; } else {
$output .= "var flattr_btn = 'large';\n";
}
$output .= "var flattr_tle = '". $cleaner($title) ."';\n";
$output .= "var flattr_dsc = '". $cleaner($description) ."';\n";
$output .= "</script>\n";
if ( defined('Flattr::API_SCRIPT')) {
$output .= '<script src="' . Flattr::API_SCRIPT . '" type="text/javascript"></script>';
}
*
*/
echo $output;
echo "</p>";
if (!$options['above']) { echo "<p>". stripslashes($options['text']) ."</p>"; }
echo $after_widget;
}
register_sidebar_widget ( "Flattr Widget", new_flattrwidget_widget );
register_widget_control ( "Flattr Widget", new_flattrwidget_control );
} else {
}
?>
<?php
require_once('oauth.php');
require_once( 'flattr_xml.php' );
class Flattr_Rest
{
public $http_header;
public $url;
public $http_code;
public $http_info;
public $signature_method;
public $consumer;
public $token;
private $apiVersion = '0.5';
private $error;
private $baseUrl = 'http://api.flattr.com';
public function __construct($consumer_key, $consumer_secret, $oauth_token = null, $oauth_token_secret = null)
{
if ( defined('LOCAL_DEV_ENV') )
{
$this->baseUrl = 'http://api.flattr.com';
}
$this->signature_method = new OAuthSignatureMethod_HMAC_SHA1();
$this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);
if ( !empty($oauth_token) && ! empty($oauth_token_secret) )
{
$this->token = new OAuthConsumer($oauth_token, $oauth_token_secret);
}
else
{
$this->token = null;
}
}
// Flattr API methods
public function browse($params)
{
$url = $this->actionUrl('/thing/browse');
if ( isset($params['query']) && $params['query'] != '' )
{
$url .= '/query/' . $params['query'];
}
if ( isset($params['tag']) && $params['tag'] != '' )
{
if ( ! is_array($params['tag']) )
{
$params['tag'] = array($params['tag']);
}
$url .=