From c361695597725ff2eda86c097edda7b39f90ffad Mon Sep 17 00:00:00 2001 From: root <root@rivolta.investici.org> Date: Wed, 1 Dec 2010 00:41:27 +0000 Subject: [PATCH] Adding plugin flattr --- wp-content/plugins/flattr/flattr.php | 19 + wp-content/plugins/flattr/flattr4.php | 26 ++ wp-content/plugins/flattr/flattr5.php | 333 ++++++++++++++++++ wp-content/plugins/flattr/languages.php | 46 +++ .../plugins/flattr/postmeta-template.php | 41 +++ wp-content/plugins/flattr/postmeta.php | 92 +++++ wp-content/plugins/flattr/readme.txt | 171 +++++++++ .../flattr/settings-confirm-template.php | 45 +++ .../plugins/flattr/settings-template.php | 109 ++++++ wp-content/plugins/flattr/settings.php | 74 ++++ 10 files changed, 956 insertions(+) create mode 100644 wp-content/plugins/flattr/flattr.php create mode 100644 wp-content/plugins/flattr/flattr4.php create mode 100644 wp-content/plugins/flattr/flattr5.php create mode 100644 wp-content/plugins/flattr/languages.php create mode 100644 wp-content/plugins/flattr/postmeta-template.php create mode 100644 wp-content/plugins/flattr/postmeta.php create mode 100644 wp-content/plugins/flattr/readme.txt create mode 100644 wp-content/plugins/flattr/settings-confirm-template.php create mode 100644 wp-content/plugins/flattr/settings-template.php create mode 100644 wp-content/plugins/flattr/settings.php diff --git a/wp-content/plugins/flattr/flattr.php b/wp-content/plugins/flattr/flattr.php new file mode 100644 index 000000000..575d47359 --- /dev/null +++ b/wp-content/plugins/flattr/flattr.php @@ -0,0 +1,19 @@ +<?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'); +} diff --git a/wp-content/plugins/flattr/flattr4.php b/wp-content/plugins/flattr/flattr4.php new file mode 100644 index 000000000..67ab6aa6f --- /dev/null +++ b/wp-content/plugins/flattr/flattr4.php @@ -0,0 +1,26 @@ +<?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() +{ +} diff --git a/wp-content/plugins/flattr/flattr5.php b/wp-content/plugins/flattr/flattr5.php new file mode 100644 index 000000000..15600a10b --- /dev/null +++ b/wp-content/plugins/flattr/flattr5.php @@ -0,0 +1,333 @@ +<?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(']]>', ']]>', $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()); +} diff --git a/wp-content/plugins/flattr/languages.php b/wp-content/plugins/flattr/languages.php new file mode 100644 index 000000000..691bfb1f9 --- /dev/null +++ b/wp-content/plugins/flattr/languages.php @@ -0,0 +1,46 @@ +<?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 diff --git a/wp-content/plugins/flattr/postmeta-template.php b/wp-content/plugins/flattr/postmeta-template.php new file mode 100644 index 000000000..0ffd8fb29 --- /dev/null +++ b/wp-content/plugins/flattr/postmeta-template.php @@ -0,0 +1,41 @@ + <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 /> diff --git a/wp-content/plugins/flattr/postmeta.php b/wp-content/plugins/flattr/postmeta.php new file mode 100644 index 000000000..f27347065 --- /dev/null +++ b/wp-content/plugins/flattr/postmeta.php @@ -0,0 +1,92 @@ +<?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'); + } + +} diff --git a/wp-content/plugins/flattr/readme.txt b/wp-content/plugins/flattr/readme.txt new file mode 100644 index 000000000..1b59ead1e --- /dev/null +++ b/wp-content/plugins/flattr/readme.txt @@ -0,0 +1,171 @@ +=== 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 = +Now applies the 'flattr_button'-filter to the Flattr button to let other plugins modify it. +Used the 'flattr_button'-filter as a quick fix to work better with the ShareThis plugin. + += 0.9.14 = +Made it easier to connect with a Flattr account. +Now possible to put the Flattr button before the content in posts. +User ID is now the username. + += 0.9.13 = +Escaping of quotation marks in tags and title. Tags are now stripped from titles. + += 0.9.12 = +The plugin now uses the ver 0.5 of the JS API. + += 0.9.11 = +Excerpt length fixed +When auto inject into posts or pages are not selected, don't add the filter + += 0.9.10 = +Yet another excerpt fix +Added ability to exclude button from a single post/page +Added flattr settings to pages + += 0.9.9 = +Fixed empty excerpts + += 0.9.8 = +Fixed tags + += 0.9.7 = +* RSS excerpt fix + += 0.9.6 = +* Button didn't show up when using manual calls from templates. + += 0.9.5 = +* Flattr button is no longer added to rss feeds. + += 0.9.4 = +* fixed option to disable button for pages. + += 0.9.3 = +* fixed language bug. Sorry about the frequent updates :) + += 0.9.2 = +* fixed the url to load.js. + += 0.9 = +* Fixed a bug where including files would sometimes break other plugins. +* Will now give error if the plugin isn't compatible with the installed version of WordPress or PHP. +* Added support for hidding things from listings on flattr.com. +* Will warn users that enter their user name instead of their user id. +* Added support for the compact button. + += 0.8 = +* Cleaned up the code +* Added option for disabling the button on a per post basis + += 0.71 = +* Modified plugin to not use short php open tags + += 0.7 = +* Changed category setting to select box instead of input field. +* Added setting for default language. +* Added ability to edit category and language settings per post. + += 0.6 = +* httpvh (Smart YouTube) urls are now stripped when creating excerpt from post content. + += 0.5 = +* Fixed a bug that caused blog posts to display incorrectly when no excerpt was entered. + += 0.4 = +* First public version + +== Upgrade Notice == + += 0.9.9 = +Fixed empty excerpts + += 0.9.8 = +Fixed tags + += 0.9.7 = +Upgrade to get auto excerpts to work for rss feeds. + += 0.9.6 = +Upgrade if using manual the_flattr_permalink() calls. + += 0.9.5 = +Upgrade to get rid of flattr buttons from your rss feeds + += 0.9.4 = +Upgrade to be able to disable button for pages + += 0.9.3 = +Upgrade to fix language problems + += 0.9 = +New goodies available. Fun for the whole family! + += 0.71 = +Short php open tags where used in some places. Upgrade if your host does not support short open tags. + += 0.7 = +Language support. Upgrade required. + += 0.6 = +Previous version didnt work with Smart YouTube when no excerpt was entered. + += 0.5 = +Previous version makes your blog posts display incorrectly if you don't enter an excerpt. + += 0.4 = +Upgrade notices describe the reason a user should upgrade. No more than 300 characters. + + +== Support == + +Direct support: https://flattr.com/support/contact +IRC: #flattr on Freequest +Forum: http://forum.flattr.com/ +Twitter: Twitter to #flattr and the community or a friendly developer might help you. diff --git a/wp-content/plugins/flattr/settings-confirm-template.php b/wp-content/plugins/flattr/settings-confirm-template.php new file mode 100644 index 000000000..f1e5a9d96 --- /dev/null +++ b/wp-content/plugins/flattr/settings-confirm-template.php @@ -0,0 +1,45 @@ + <div class="wrap"> + <h2><?php _e('Flattr Settings'); ?></h2> + + <h3>Confirm new Flattr connection</h3> + <table class="form-table"> + <tr valign="top"> + <th scope="row"><?php _e('Your current Flattr connection'); ?></th> + <td> + <?php if (get_option('flattr_uid')) { ?> + <?php + if (preg_match('[A-Za-z-_.]', get_option('flattr_uid'))) { + ?><a href="<?php echo esc_url( 'https://flattr.com/profile/' . get_option('flattr_uid') ); ?>"><?php + esc_html_e(get_option('flattr_uid')); + ?></a> <?php + } + else { + esc_html_e(get_option('flattr_uid')); + } + ?> + <?php } else { ?> + - + <?php } ?> + </td> + </tr> + <tr valign="top"> + <th scope="row"><?php _e('Your new Flattr connection'); ?></th> + <td> + <a href="<?php echo esc_url( 'https://flattr.com/profile/' . $_GET['FlattrUsername'] ); ?>"><?php esc_html_e($_GET['FlattrUsername']); ?></a> + </td> + </tr> + </table> + <form method="post" action="options.php"> + <p class="submit"> + <?php + // Replicating settings_fields + echo "<input type='hidden' name='option_page' value='flattr-settings-uid-group' />"; + echo '<input type="hidden" name="action" value="update" />'; + wp_nonce_field("flattr-settings-uid-group-options", '_wpnonce', false); + ?> + <input type="hidden" value="<?php esc_attr_e(remove_query_arg(array('FlattrId', 'FlattrUsername'))); ?>" name="_wp_http_referer"> + <input type="hidden" name="flattr_uid" value="<?php esc_attr_e($_GET['FlattrUsername']); ?>" /> + <input type="submit" class="button-primary" value="<?php _e('Accept') ?>" /> + </p> + </form> + </div> diff --git a/wp-content/plugins/flattr/settings-template.php b/wp-content/plugins/flattr/settings-template.php new file mode 100644 index 000000000..a75ec1965 --- /dev/null +++ b/wp-content/plugins/flattr/settings-template.php @@ -0,0 +1,109 @@ + <div class="wrap"> + <h2><?php _e('Flattr Settings'); ?></h2> + + <h3>User account</h3> + <table class="form-table"> + <tr valign="top"> + <th scope="row"><?php _e('Your Flattr account'); ?></th> + <td> + <?php + $connect_callback = rawurlencode( ($_SERVER['HTTPS'] ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); + if (get_option('flattr_uid')) { ?> + Connected as + <?php + if (preg_match('/[A-Za-z-_.]/', get_option('flattr_uid'))) { + ?><a href="<?php echo esc_url( 'https://flattr.com/profile/' . get_option('flattr_uid') ); ?>"><?php + esc_html_e(get_option('flattr_uid')); + ?></a>.<?php + } + else { + ?>user id <?php esc_html_e(get_option('flattr_uid'));?>.<?php + } + ?> + (<a href="https://flattr.com/login?idCallback=<?php echo $connect_callback; ?>">Reconnect</a>) + <?php } else { ?> + None - <a href="https://flattr.com/login?idCallback=<?php echo $connect_callback; ?>">Connect with Flattr</a> + <?php } ?> + </td> + </tr> + </table> + + <h3>Other settings</h3> + <form method="post" action="options.php"> + <?php settings_fields( 'flattr-settings-group' ); ?> + + <table class="form-table"> + + <tr valign="top"> + <th scope="row"><?php _e('Default category for your posts'); ?></th> + <td> + <select name="flattr_cat"> + <?php + foreach (Flattr::getCategories() as $category) + { + printf('<option value="%1$s" %2$s>%1$s</option>', + $category, + ($category == get_option('flattr_cat') ? 'selected' : '') + ); + } + ?> + </select> + </td> + </tr> + + <tr valign="top"> + <th scope="row"><?php _e('Default language for your posts'); ?></th> + <td> + <select name="flattr_lng"> + <?php + foreach (Flattr::getLanguages() as $languageCode => $language) + { + printf('<option value="%s" %s>%s</option>', + $languageCode, + ($languageCode == get_option('flattr_lng') ? 'selected' : ''), + $language + ); + } + ?> + </select> + </td> + </tr> + + <tr valign="top"> + <th scope="row"><?php _e('Insert button before the content'); ?></th> + <td><input <?php if (get_option('flattr_top', 'false') == 'true') { echo(' checked="checked"'); } ?> type="checkbox" name="flattr_top" value="true" /></td> + </tr> + + <tr valign="top"> + <th scope="row"><?php _e('Use the compact button'); ?></th> + <td><input <?php if (get_option('flattr_compact', 'false') == 'true') { echo(' checked="checked"'); } ?> type="checkbox" name="flattr_compact" value="true" /></td> + </tr> + + <tr valign="top"> + <th scope="row"><?php _e('Hide my posts from listings on flattr.com'); ?></th> + <td><input <?php if (get_option('flattr_hide', 'false') == 'true') { echo(' checked="checked"'); } ?> type="checkbox" name="flattr_hide" value="true" /></td> + </tr> + + <tr valign="top"> + <th scope="row"><?php _e('Insert Flattr button into posts automagically'); ?></th> + <td><input <?php if (get_option('flattr_aut', 'off') == 'on') { echo(' checked="checked"'); } ?> type="checkbox" name="flattr_aut" value="on" /><br />(uncheck this if you would rather use <code><?php the_flattr_permalink() ?></code>)</td> + </tr> + + <tr valign="top"> + <th scope="row"><?php _e('Insert Flattr button into pages automagically'); ?></th> + <td><input <?php if (get_option('flattr_aut_page', 'off') == 'on') { echo(' checked="checked"'); } ?> type="checkbox" name="flattr_aut_page" value="on" /><br />(uncheck this if you would rather use <code><?php the_flattr_permalink() ?></code>)</td> + </tr> + + <?php if ( function_exists('st_add_widget') ) { ?> + <tr valign="top"> + <th scope="row"><?php _e('Override ShareThis widget'); ?></th> + <td><input <?php if (get_option('flattr_override_sharethis', 'false') == 'true') { echo(' checked="checked"'); } ?> type="checkbox" name="flattr_override_sharethis" value="true" /><br />(will add the Flattr button after the ShareThis buttons)</td> + </tr> + <?php } ?> + </table> + + <p class="submit"> + <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /> + </p> + </form> + </div> diff --git a/wp-content/plugins/flattr/settings.php b/wp-content/plugins/flattr/settings.php new file mode 100644 index 000000000..247dd457c --- /dev/null +++ b/wp-content/plugins/flattr/settings.php @@ -0,0 +1,74 @@ +<?php + +class Flattr_Settings +{ + public function __construct() + { + add_action('admin_init', array( $this, 'register_settings') ); + add_action('admin_menu', array( $this, 'init_ui') ); + } + + public function init_ui() + { + add_options_page('Flattr Setup', 'Flattr', 'manage_options', __FILE__, array($this, 'render')); + } + + public function register_settings() + { + register_setting('flattr-settings-uid-group', 'flattr_uid', array($this, 'sanitize_userid')); + register_setting('flattr-settings-group', 'flattr_aut', array($this, 'sanitize_auto')); + register_setting('flattr-settings-group', 'flattr_aut_page', array($this, 'sanitize_auto_page')); + register_setting('flattr-settings-group', 'flattr_cat', array($this, 'sanitize_category')); + register_setting('flattr-settings-group', 'flattr_lng', array($this, 'sanitize_language')); + register_setting('flattr-settings-group', 'flattr_compact', array($this, 'sanitize_checkbox')); + register_setting('flattr-settings-group', 'flattr_hide', array($this, 'sanitize_checkbox')); + register_setting('flattr-settings-group', 'flattr_top', array($this, 'sanitize_checkbox')); + register_setting('flattr-settings-group', 'flattr_override_sharethis', array($this, 'sanitize_checkbox')); + } + + public function render() + { + if (array_key_exists('FlattrId', $_GET)) { + include('settings-confirm-template.php'); + } + else { + include('settings-template.php'); + } + } + + public function sanitize_category($category) + { + return $category; + } + + public function sanitize_language($language) + { + return $language; + } + + public function sanitize_checkbox($input) + { + return ($input == 'true' ? 'true' : ''); + } + + public function sanitize_auto($input) + { + return ($input == 'on' ? 'on' : ''); + } + + public function sanitize_auto_page($input) + { + return ($input == 'on' ? 'on' : ''); + } + + public function sanitize_userid($userId) + { + if (preg_match('/[^A-Za-z0-9-_.]/', $userId)) { + $userId = false; + } + else if (is_numeric($userId)) { + $userId = intval($userId); + } + return $userId; + } +} -- GitLab