diff --git a/.editorconfig b/.editorconfig new file mode 100755 index 0000000..cf8d7fa --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +# editorconfig.org + +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..e69de29 diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100755 index 0000000..01a3840 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,25 @@ +# 1.2.0: September 4th, 2016 +* Remove share counts completely +* Remove JS for window popup +* Refactor CSS and update SVG icons + +# 1.1.0: November 23rd, 2015 +* Remove Twitter share counts as they're [no longer supported by Twitter](https://twittercommunity.com/t/clarification-about-share-counts-for-the-new-tweet-button/52868) + +# 1.0.4: August 12th, 2015 +* Fix issue with loading translated language files + +# 1.0.3: July 2nd, 2015 +* Fix issue with [share] shortcode not using the provided 'title' and 'url' attributes + +# 1.0.2: June 2nd, 2015 +* Don't show 'Pin It' button if post doesn't have a thumbnail +* Make sure post thumbnail URL is absolute +* Use plural name for post type labels + +# 1.0.1: April 7th, 2015 +* Change `&` to `&` +* Add missing `` on SVGs + +# 1.0.0: January 23rd, 2015 +* Initial release diff --git a/README.md b/README.md new file mode 100755 index 0000000..3822463 --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +# Roots Share Buttons + +Add lightweight social sharing buttons. + +## Requirements + +* PHP >= 5.3 + +## Features + +* Supported networks: Facebook, Twitter, Google+, LinkedIn, Pinterest +* Easily set button order +* Lightweight, mobile-first stylesheet +* Automatically include share buttons: + * Before and/or after content on archive templates + * Before and/or after content on single templates + * On specified post types (custom post types are supported) +* Supports custom share button templates +* Includes a `[share]` shortcode for adding the share buttons within post content + +## Customization + +The `[share]` shortcode includes the template from `templates/shortcode-share.php`. If you'd like to use a custom template, copy `shortcode-share.php` into the `templates/` directory in your theme and also implement the following example snippet: + +```php +/** + * Custom [share] shortcode template + */ +function custom_roots_share_buttons_template() { + return get_template_directory() . '/templates/shortcode-share.php'; +} +add_action('roots/share_template', 'custom_roots_share_buttons_template'); +``` + +## Removing plugin CSS + +Roots Share Buttons includes one stylesheet. If you'd prefer to implement these styles within your theme (which is recommended), you can remove the plugin assets with this snippet: + +```php +/** + * Remove Roots Share Buttons assets + */ +function remove_roots_share_buttons_assets() { + wp_dequeue_style('roots-share-buttons'); +} +add_action('wp_enqueue_scripts', 'remove_roots_share_buttons_assets'); +``` diff --git a/assets/scripts/admin.js b/assets/scripts/admin.js new file mode 100755 index 0000000..835e00a --- /dev/null +++ b/assets/scripts/admin.js @@ -0,0 +1,10 @@ +jQuery(document).ready(function() { + + jQuery('#buttons-sort').sortable({ + stop: function(event, ui) { + var buttonOrder = jQuery(this).sortable('toArray').toString().replace(/sort_/g, '').replace('googleplus', 'google_plus'); + jQuery('#roots_share_buttons_button_order').val(buttonOrder); + } + }); + +}); diff --git a/assets/styles/admin.css b/assets/styles/admin.css new file mode 100755 index 0000000..8d470b8 --- /dev/null +++ b/assets/styles/admin.css @@ -0,0 +1,17 @@ +@import url('//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css'); + +.ui-sort { + width: 20em; +} +.ui-sort li { + position: relative; + margin: 0 3px 3px 3px; + padding: 4px 3px 2px 8px; + height: 18px; + cursor: move; +} +.ui-sort li span { + position: absolute; + right: 0; + margin-right: 6px; +} diff --git a/assets/styles/share-buttons.css b/assets/styles/share-buttons.css new file mode 100755 index 0000000..454e72b --- /dev/null +++ b/assets/styles/share-buttons.css @@ -0,0 +1,53 @@ +.entry-share-btns { + margin-left: -.25em; + padding-left: 0; + list-style: none; +} +.entry-share-btns li { + display: inline-block; + margin: .25em; +} +.entry-share-btns a, +.entry-content .entry-share-btns a { + font-size: .75em; + display: block; + padding: .25em .75em; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; + text-decoration: none; + color: #fff; + border: none; + border-radius: 6px; + background: #666; + + background: #27ae60; +} +.entry-share-btns a:hover, +.entry-share-btns a:focus { + text-decoration: none; + color: #fff; + background: #555; +} +.entry-share-btn-icon { + position: relative; + top: 3px; + display: inline-block; + fill: #fff; + stroke: none; +} +.entry-share-btns svg { + width: 1em; + height: 1em; + vertical-align: top; +} +.entry-share-btns span { + display: none; +} +@media (min-width: 600px) { + .entry-share-btns span { + display: inline-block; + padding-left: .4em; + } +} diff --git a/lang/roots_share_buttons.pot b/lang/roots_share_buttons.pot new file mode 100755 index 0000000..8186ad1 --- /dev/null +++ b/lang/roots_share_buttons.pot @@ -0,0 +1,119 @@ +#: lib/admin.php:36 +msgid "General Configuration" +msgstr "" + +#: lib/admin.php:42 +msgid "Enable Buttons" +msgstr "" + +#: lib/admin.php:49 +msgid "Share Count" +msgstr "" + +#: lib/admin.php:56 +msgid "Theme Integration" +msgstr "" + +#: lib/admin.php:62 +msgid "Archive Templates" +msgstr "" + +#: lib/admin.php:69 +msgid "Single Templates" +msgstr "" + +#: lib/admin.php:76 +msgid "Post Types" +msgstr "" + +#: lib/admin.php:210 +msgid "Twitter" +msgstr "" + +#: lib/admin.php:213 +msgid "Facebook" +msgstr "" + +#: lib/admin.php:216 +msgid "Google Plus" +msgstr "" + +#: lib/admin.php:219 +msgid "LinkedIn" +msgstr "" + +#: lib/admin.php:222 +msgid "Pinterest" +msgstr "" + +#: lib/admin.php:231 lib/admin.php:238 +msgid "Before the content" +msgstr "" + +#: lib/admin.php:232 lib/admin.php:239 +msgid "After the content" +msgstr "" + +#: lib/admin.php:245 +msgid "Enabled" +msgstr "" + +#: lib/admin.php:246 +msgid "Disabled" +msgstr "" + +#: templates/shortcode-share.php:30 +msgid "Share on Twitter" +msgstr "" + +#: templates/shortcode-share.php:32 +msgid "Tweet" +msgstr "" + +#: templates/shortcode-share.php:43 +msgid "Share on Facebook" +msgstr "" + +#: templates/shortcode-share.php:45 templates/shortcode-share.php:71 +msgid "Share" +msgstr "" + +#: templates/shortcode-share.php:56 +msgid "Share on Google+" +msgstr "" + +#: templates/shortcode-share.php:58 +msgid "+1" +msgstr "" + +#: templates/shortcode-share.php:69 +msgid "Share on LinkedIn" +msgstr "" + +#: templates/shortcode-share.php:96 +msgid "Share on Pinterest" +msgstr "" + +#: templates/shortcode-share.php:98 +msgid "Pin it" +msgstr "" + +#. Plugin Name of the plugin/theme +msgid "Roots Share Buttons" +msgstr "" + +#. Plugin URI of the plugin/theme +msgid "https://roots.io/plugins/share-buttons/" +msgstr "" + +#. Description of the plugin/theme +msgid "Add lightweight social sharing buttons with optional share counts." +msgstr "" + +#. Author of the plugin/theme +msgid "Ben Word" +msgstr "" + +#. Author URI of the plugin/theme +msgid "https://roots.io/" +msgstr "" diff --git a/lib/activation.php b/lib/activation.php new file mode 100755 index 0000000..8a4a000 --- /dev/null +++ b/lib/activation.php @@ -0,0 +1,7 @@ + +
+
+

Share Buttons Settings

+ +
+
+ array('twitter', 'facebook', 'google_plus', 'linkedin'), + 'button_order' => array('twitter', 'facebook', 'google_plus', 'linkedin', 'pinterest'), + 'post_types' => array('post', 'page'), + 'archive_templates' => array(), + 'single_templates' => array() + ); +} + +function get_settings() { + return wp_parse_args((array) get_option('roots_share_buttons'), get_defaults()); +} + +function get_setting($key) { + $settings = get_settings(); + if (isset($settings[$key])) { + return $settings[$key]; + } + return false; +} + +function settings_sanitize($input) { + $output = array( + 'buttons' => array(), + 'button_order' => array(), + 'post_types' => array(), + 'archive_templates' => array(), + 'single_templates' => array() + ); + + if (isset($input['buttons'])) { + $buttons = get_buttons(); + foreach ((array) $input['buttons'] as $button) { + if (array_key_exists($button, $buttons)) { + $output['buttons'][] = $button; + } + } + } + + if (isset($input['button_order'])) { + if (!is_array($input['button_order'])) { + $input['button_order'] = explode(",", $input['button_order']); + } + + $button_order = array(); + $allowed_items = array( + 'twitter' => true, + 'facebook' => true, + 'google_plus' => true, + 'linkedin' => true, + 'pinterest' => true + ); + + foreach($input['button_order'] as $order_item) { + if (isset($allowed_items[$order_item])) { + $button_order[] = $order_item; + } + } + + $output['button_order'] = $button_order; + } else { + $output['button_order'] = array(); + } + + if (isset($input['archive_templates'])) { + $locations = get_locations_archive(); + foreach ((array) $input['archive_templates'] as $location) { + if (array_key_exists($location, $locations)) { + $output['archive_templates'][] = $location; + } + } + } + + if (isset($input['single_templates'])) { + $locations = get_locations(); + foreach ((array) $input['single_templates'] as $location) { + if (array_key_exists($location, $locations)) { + $output['single_templates'][] = $location; + } + } + } + + if (isset($input['post_types'])) { + $post_types = get_post_types(); + foreach ((array) $input['post_types'] as $post_type) { + if (array_key_exists($post_type, $post_types)) { + $output['post_types'][] = $post_type; + } + } + } + + return $output; +} + +function get_buttons() { + $settings = get_settings(); + $get_buttons_array = array(); + + foreach($settings['button_order'] as $setting) { + switch($setting) { + case 'twitter': + $get_buttons_array['twitter'] = __('Twitter', 'roots_share_buttons'); + break; + case 'facebook': + $get_buttons_array['facebook'] = __('Facebook', 'roots_share_buttons'); + break; + case 'google_plus': + $get_buttons_array['google_plus'] = __('Google Plus', 'roots_share_buttons'); + break; + case 'linkedin': + $get_buttons_array['linkedin'] = __('LinkedIn', 'roots_share_buttons'); + break; + case 'pinterest': + $get_buttons_array['pinterest'] = __('Pinterest', 'roots_share_buttons'); + break; + } + } + return $get_buttons_array; +} + +function get_locations() { + return array( + 'before_content' => __('Before the content', 'roots_share_buttons'), + 'after_content' => __('After the content', 'roots_share_buttons') + ); +} + +function get_locations_archive() { + return array( + 'before_content' => __('Before the content', 'roots_share_buttons'), + 'after_content' => __('After the content', 'roots_share_buttons') + ); +} + +function get_toggles() { + return array( + 'enabled' => __('Enabled', 'roots_share_buttons'), + 'disabled' => __('Disabled', 'roots_share_buttons') + ); +} + +function control_buttons() { + $settings = get_settings(); + $key = 'buttons'; + $buttons = get_buttons(); + $saved = get_setting($key); + + print "\n" . ''; + print "\n" . 'Drag the buttons to determine the order they will be displayed on your blog'; + print "\n" . ''; +} + +function control_archive_templates() { + $key = 'archive_templates'; + $settings = get_settings(); + $saved = get_setting($key); + print "\n" . '
'; + foreach (get_locations_archive() as $location => $label) { + $id = 'roots_share_buttons_' . $key . '_' . $location; + $checked = (in_array($location, $saved)) ? ' checked="checked"' : ''; + print "\n" . '
'; + } + print "\n" . '
'; +} + +function control_single_templates() { + $key = 'single_templates'; + $settings = get_settings(); + $saved = get_setting($key); + print "\n" . '
'; + foreach (get_locations() as $location => $label) { + $id = 'roots_share_buttons_' . $key . '_' . $location; + $checked = (in_array($location, $saved)) ? ' checked="checked"' : ''; + print "\n" . '
'; + } + print "\n" . '
'; +} + +function control_post_types() { + $key = 'post_types'; + $settings = get_settings(); + $saved = get_setting($key); + print "\n" . '
'; + foreach (get_post_types(array('public' => true)) as $post_type => $label) { + $id = 'roots_share_buttons_' . $key . '_' . $post_type; + $checked = (in_array($post_type, $saved)) ? ' checked="checked"' : ''; + $object = get_post_type_object($label); + $label = $object->labels->name; + print "\n" . '
'; + } + print "\n" . '
'; +} diff --git a/lib/buttons.php b/lib/buttons.php new file mode 100755 index 0000000..ca360dc --- /dev/null +++ b/lib/buttons.php @@ -0,0 +1,105 @@ + '', + 'title' => '' + ), $atts)); + + ob_start(); + include(apply_filters('roots/share_template', ROOTS_SHARE_PATH . '/templates/shortcode-share.php')); + return ob_get_clean(); +} +add_shortcode('share', __NAMESPACE__ . '\\shortcode'); diff --git a/share-buttons.php b/share-buttons.php new file mode 100755 index 0000000..f6e2548 --- /dev/null +++ b/share-buttons.php @@ -0,0 +1,32 @@ +ID); + + if (empty($title)) $title = get_the_title(); +?> + +
+ +
diff --git a/uninstall.php b/uninstall.php new file mode 100755 index 0000000..304e316 --- /dev/null +++ b/uninstall.php @@ -0,0 +1,19 @@ +get_results("SELECT blog_id FROM {$wpdb->blogs}", ARRAY_A); + + if (!empty($blogs)) { + foreach($blogs as $blog) { + switch_to_blog($blog['blog_id']); + delete_option('roots_share_buttons'); + } + } +} else { + delete_option('roots_share_buttons'); +} diff --git a/vendor/phpuri.php b/vendor/phpuri.php new file mode 100755 index 0000000..0afb037 --- /dev/null +++ b/vendor/phpuri.php @@ -0,0 +1,208 @@ + + * echo phpUri::parse('https://www.google.com/')->join('foo'); + * //==> https://www.google.com/foo + * + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @author P Guardiario + * @version 1.0 + */ + + /** + * phpUri + */ + class phpUri + { + + /** + * http(s):// + * @var string + */ + public $scheme; + + /** + * www.example.com + * @var string + */ + public $authority; + + /** + * /search + * @var string + */ + public $path; + + /** + * ?q=foo + * @var string + */ + public $query; + + /** + * #bar + * @var string + */ + public $fragment; + + private function __construct( $string ) + { + preg_match_all( '/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/', $string, $m ); + $this->scheme = $m[ 2 ][ 0 ]; + $this->authority = $m[ 4 ][ 0 ]; + + /** + * CHANGE: + * @author Dominik Habichtsberg + * @since 24 Mai 2015 10:02 Uhr + * + * Former code: $this->path = ( empty( $m[ 5 ][ 0 ] ) ) ? '/' : $m[ 5 ][ 0 ]; + * No tests failed, when the path is empty. + * With the former code, the relative urls //g and #s failed + */ + $this->path = $m[ 5 ][ 0 ]; + $this->query = $m[ 7 ][ 0 ]; + $this->fragment = $m[ 9 ][ 0 ]; + } + + private function to_str() + { + $ret = ''; + if ( !empty( $this->scheme ) ) + { + $ret .= "{$this->scheme}:"; + } + + if ( !empty( $this->authority ) ) + { + $ret .= "//{$this->authority}"; + } + + $ret .= $this->normalize_path( $this->path ); + + if ( !empty( $this->query ) ) + { + $ret .= "?{$this->query}"; + } + + if ( !empty( $this->fragment ) ) + { + $ret .= "#{$this->fragment}"; + } + + return $ret; + } + + private function normalize_path( $path ) + { + if ( empty( $path ) ) + { + return ''; + } + + $normalized_path = $path; + $normalized_path = preg_replace( '`//+`', '/', $normalized_path, -1, $c0 ); + $normalized_path = preg_replace( '`^/\\.\\.?/`', '/', $normalized_path, -1, $c1 ); + $normalized_path = preg_replace( '`/\\.(/|$)`', '/', $normalized_path, -1, $c2 ); + + /** + * CHANGE: + * @author Dominik Habichtsberg + * @since 24 Mai 2015 10:05 Uhr + * changed limit form -1 to 1, because climbing up the directory-tree failed + */ + $normalized_path = preg_replace( '`/[^/]*?/\\.\\.(/|$)`', '/', $normalized_path, 1, $c3 ); + $num_matches = $c0 + $c1 + $c2 + $c3; + + return ( $num_matches > 0 ) ? $this->normalize_path( $normalized_path ) : $normalized_path; + } + + /** + * Parse an url string + * + * @param string $url the url to parse + * + * @return phpUri + */ + public static function parse( $url ) + { + $uri = new phpUri( $url ); + + /** + * CHANGE: + * @author Dominik Habichtsberg + * @since 24 Mai 2015 10:25 Uhr + * The base-url should always have a path + */ + if ( empty( $uri->path ) ) + { + $uri->path = '/'; + } + + return $uri; + } + + /** + * Join with a relative url + * + * @param string $relative the relative url to join + * + * @return string + */ + public function join( $relative ) + { + $uri = new phpUri( $relative ); + switch ( TRUE ) + { + case !empty( $uri->scheme ): + break; + + case !empty( $uri->authority ): + break; + + case empty( $uri->path ): + $uri->path = $this->path; + if ( empty( $uri->query ) ) + { + $uri->query = $this->query; + } + break; + + case strpos( $uri->path, '/' ) === 0: + break; + + default: + $base_path = $this->path; + if ( strpos( $base_path, '/' ) === FALSE ) + { + $base_path = ''; + } + else + { + $base_path = preg_replace( '/\/[^\/]+$/', '/', $base_path ); + } + if ( empty( $base_path ) && empty( $this->authority ) ) + { + $base_path = '/'; + } + $uri->path = $base_path . $uri->path; + } + + if ( empty( $uri->scheme ) ) + { + $uri->scheme = $this->scheme; + if ( empty( $uri->authority ) ) + { + $uri->authority = $this->authority; + } + } + + return $uri->to_str(); + } + }