summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJorge Manuel B. S. Vicetto (jmbsvicetto) <jmbsvicetto@gentoo.org>2015-05-01 00:40:49 +0000
committerJorge Manuel B. S. Vicetto (jmbsvicetto) <jmbsvicetto@gentoo.org>2015-05-01 00:40:49 +0000
commitc64ce3ae8de09092f9570ab88a68fe920b0fd970 (patch)
treea9959002055a8bdff0ee46bf82ca6a2a39bf00cd /plugins/jetpack/modules/sharedaddy/sharing-service.php
parentAdd easy-table plugin, requested by hwoarang (diff)
downloadblogs-gentoo-c64ce3ae8de09092f9570ab88a68fe920b0fd970.tar.gz
blogs-gentoo-c64ce3ae8de09092f9570ab88a68fe920b0fd970.tar.bz2
blogs-gentoo-c64ce3ae8de09092f9570ab88a68fe920b0fd970.zip
Update plugins and themes to the latest versions.
Signed-off-by: Jorge Manuel B. S. Vicetto (jmbsvicetto) <jmbsvicetto@gentoo.org>
Diffstat (limited to 'plugins/jetpack/modules/sharedaddy/sharing-service.php')
-rw-r--r--plugins/jetpack/modules/sharedaddy/sharing-service.php183
1 files changed, 159 insertions, 24 deletions
diff --git a/plugins/jetpack/modules/sharedaddy/sharing-service.php b/plugins/jetpack/modules/sharedaddy/sharing-service.php
index 80f4d8de..2f992d72 100644
--- a/plugins/jetpack/modules/sharedaddy/sharing-service.php
+++ b/plugins/jetpack/modules/sharedaddy/sharing-service.php
@@ -39,12 +39,13 @@ class Sharing_Service {
/**
* Gets a list of all available service names and classes
*/
- private function get_all_services() {
+ public function get_all_services( $include_custom = true ) {
// Default services
+ // if you update this list, please update the REST API tests
+ // in bin/tests/api/suites/SharingTest.php
$services = array(
'email' => 'Share_Email',
'print' => 'Share_Print',
- 'digg' => 'Share_Digg',
'facebook' => 'Share_Facebook',
'linkedin' => 'Share_LinkedIn',
'reddit' => 'Share_Reddit',
@@ -57,12 +58,21 @@ class Sharing_Service {
'pocket' => 'Share_Pocket',
);
- // Add any custom services in
- $options = $this->get_global_options();
- foreach ( (array)$options['custom'] AS $custom_id ) {
- $services[$custom_id] = 'Share_Custom';
+ if ( $include_custom ) {
+ // Add any custom services in
+ $options = $this->get_global_options();
+ foreach ( (array) $options['custom'] AS $custom_id ) {
+ $services[$custom_id] = 'Share_Custom';
+ }
}
+ /**
+ * Filters the list of available Sharing Services.
+ *
+ * @since 1.1.0
+ *
+ * @param array $services Array of all available Sharing Services.
+ */
return apply_filters( 'sharing_services', $services );
}
@@ -81,6 +91,9 @@ class Sharing_Service {
// Add a new custom service
$options['global']['custom'][] = $service_id;
+ if ( false !== $this->global ) {
+ $this->global['custom'][] = $service_id;
+ }
update_option( 'sharing-options', $options );
@@ -120,6 +133,21 @@ class Sharing_Service {
// Ensure we don't have the same ones in hidden and visible
$hidden = array_diff( $hidden, $visible );
+ /**
+ * Control the state of the list of sharing services.
+ *
+ * @since 1.1.0
+ *
+ * @param array $args {
+ * Array of options describing the state of the sharing services.
+ *
+ * @type array $services List of all available service names and classes.
+ * @type array $available Validated list of all available service names and classes.
+ * @type array $hidden List of services hidden behind a "More" button.
+ * @type array $visible List of visible services.
+ * @type array $this->get_blog_services() Array of Sharing Services currently enabled.
+ * }
+ */
do_action( 'sharing_get_services_state', array(
'services' => $services,
'available' => $available,
@@ -142,12 +170,19 @@ class Sharing_Service {
$global = $options['global'];
// Default services
- if ( !is_array( $enabled ) ) {
+ if ( ! is_array( $enabled ) ) {
$enabled = array(
'visible' => array(),
'hidden' => array()
);
+ /**
+ * Filters the list of default Sharing Services.
+ *
+ * @since 1.1.0
+ *
+ * @param array $enabled Array of default Sharing Services.
+ */
$enabled = apply_filters( 'sharing_default_services', $enabled );
}
@@ -166,6 +201,13 @@ class Sharing_Service {
}
}
+ /**
+ * Filters the list of enabled Sharing Services.
+ *
+ * @since 1.1.0
+ *
+ * @param array $blog Array of enabled Sharing Services.
+ */
$blog = apply_filters( 'sharing_services_enabled', $blog );
// Add CSS for NASCAR
@@ -198,13 +240,20 @@ class Sharing_Service {
// Defaults
$options['global'] = array(
- 'button_style' => 'icon-text',
+ 'button_style' => 'icon',
'sharing_label' => $this->default_sharing_label,
'open_links' => 'same',
- 'show' => array( 'post', 'page' ),
+ 'show' => array(),
'custom' => isset( $options['global']['custom'] ) ? $options['global']['custom'] : array()
);
+ /**
+ * Filters global sharing settings.
+ *
+ * @since 1.1.0
+ *
+ * @param array $options['global'] Array of global sharing settings.
+ */
$options['global'] = apply_filters( 'sharing_default_global', $options['global'] );
// Validate options and set from our data
@@ -242,8 +291,6 @@ class Sharing_Service {
if ( $data['show'] = array_intersect( $data['show'], $shows ) ) {
$options['global']['show'] = $data['show'];
}
- } else {
- $options['global']['show'] = array();
}
update_option( 'sharing-options', $options );
@@ -288,9 +335,23 @@ class Sharing_Service {
$options = get_option( 'sharing-options' );
// No options yet
- if ( !is_array( $options ) )
+ if ( ! is_array( $options ) ) {
$options = array();
+ }
+ /**
+ * Get the state of a sharing button.
+ *
+ * @since 1.1.0
+ *
+ * @param array $args {
+ * State of a sharing button.
+ *
+ * @type string $id Service ID.
+ * @type array $options Array of all sharing options.
+ * @type array $service Details about a service.
+ * }
+ */
do_action( 'sharing_get_button_state', array( 'id' => $id, 'options' => $options, 'service' => $service ) );
$options[$id] = $service->get_options();
@@ -400,26 +461,66 @@ function sharing_register_post_for_share_counts( $post_id ) {
$jetpack_sharing_counts[ (int) $post_id ] = get_permalink( $post_id );
}
+function sharing_maybe_enqueue_scripts() {
+ $sharer = new Sharing_Service();
+ $global_options = $sharer->get_global_options();
+
+ $enqueue = false;
+ if ( is_singular() && in_array( get_post_type(), $global_options['show'] ) ) {
+ $enqueue = true;
+ } elseif ( in_array( 'index', $global_options['show'] ) && ( is_home() || is_front_page() || is_archive() || is_search() || in_array( get_post_type(), $global_options['show'] ) ) ) {
+ $enqueue = true;
+ }
+
+ /**
+ * Filter to decide when sharing scripts should be enqueued.
+ *
+ * @since 3.2.0
+ *
+ * @param bool $enqueue Decide if the sharing scripts should be enqueued.
+ */
+ return (bool) apply_filters( 'sharing_enqueue_scripts', $enqueue );
+}
+
function sharing_add_footer() {
global $jetpack_sharing_counts;
- if ( apply_filters( 'sharing_js', true ) ) {
-
- if ( is_array( $jetpack_sharing_counts ) && count( $jetpack_sharing_counts ) ) :
+ /**
+ * Filter all Javascript output by the sharing module.
+ *
+ * @since 1.1.0
+ *
+ * @param bool true Control whether the sharing module should add any Javascript to the site. Default to true.
+ */
+ if ( apply_filters( 'sharing_js', true ) && sharing_maybe_enqueue_scripts() ) {
+
+ /**
+ * Filter the display of sharing counts next to the sharing buttons.
+ *
+ * @since 3.2.0
+ *
+ * @param bool true Control the display of counters next to the sharing buttons. Default to true.
+ */
+ if ( apply_filters( 'jetpack_sharing_counts', true ) && is_array( $jetpack_sharing_counts ) && count( $jetpack_sharing_counts ) ) :
$sharing_post_urls = array_filter( $jetpack_sharing_counts );
if ( $sharing_post_urls ) :
?>
<script type="text/javascript">
- WPCOM_sharing_counts = <?php echo json_encode( array_flip( $sharing_post_urls ) ); ?>
+ window.WPCOM_sharing_counts = <?php echo json_encode( array_flip( $sharing_post_urls ) ); ?>;
+ window.WPCOM_site_ID = <?php echo defined( 'IS_WPCOM' ) && IS_WPCOM ? get_current_blog_id() : Jetpack_Options::get_option( 'id', 0 ); ?>;
</script>
<?php
endif;
endif;
wp_enqueue_script( 'sharing-js' );
- $recaptcha__options = array( 'lang' => get_base_recaptcha_lang_code() );
- wp_localize_script('sharing-js', 'recaptcha_options', $recaptcha__options);
+ $sharing_js_options = array(
+ 'lang' => get_base_recaptcha_lang_code(),
+ /** This filter is documented in modules/sharedaddy/sharing-service.php */
+ 'counts' => apply_filters( 'jetpack_sharing_counts', true )
+ );
+ wp_localize_script( 'sharing-js', 'sharing_js_options', $sharing_js_options);
}
$sharer = new Sharing_Service();
@@ -437,8 +538,16 @@ function sharing_add_header() {
$service->display_header();
}
- if ( count( $enabled['all'] ) > 0 )
- wp_enqueue_style( 'sharedaddy', plugin_dir_url( __FILE__ ) .'sharing.css', array(), JETPACK__VERSION );
+ if ( count( $enabled['all'] ) > 0 && sharing_maybe_enqueue_scripts() ) {
+ // @todo: Remove this opt-out filter in the future
+ if ( ( ! defined( 'IS_WPCOM' ) ) || ( ! IS_WPCOM ) || apply_filters( 'wpl_sharing_2014_1', true ) ) {
+ wp_enqueue_style( 'sharedaddy', plugin_dir_url( __FILE__ ) .'sharing.css', array(), JETPACK__VERSION );
+ wp_enqueue_style( 'genericons' );
+ } else {
+ wp_enqueue_style( 'sharedaddy', plugin_dir_url( __FILE__ ) .'sharing-legacy.css', array(), JETPACK__VERSION );
+ }
+ }
+
}
add_action( 'wp_head', 'sharing_add_header', 1 );
@@ -463,7 +572,7 @@ function sharing_display( $text = '', $echo = false ) {
if ( empty( $post ) )
return $text;
- if ( is_preview() ) {
+ if ( is_preview() || is_admin() ) {
return $text;
}
@@ -503,12 +612,19 @@ function sharing_display( $text = '', $echo = false ) {
if ( !is_feed() ) {
if ( is_singular() && in_array( get_post_type(), $global['show'] ) ) {
$show = true;
- } elseif ( in_array( 'index', $global['show'] ) && ( is_home() || is_archive() || is_search() ) ) {
+ } elseif ( in_array( 'index', $global['show'] ) && ( is_home() || is_archive() || is_search() || in_array( get_post_type(), $global['show'] ) ) ) {
$show = true;
}
}
- // Pass through a filter for final say so
+ /**
+ * Filter to decide if sharing buttons should be displayed.
+ *
+ * @since 1.1.0
+ *
+ * @param
+ * @param WP_Post $post The post to share.
+ */
$show = apply_filters( 'sharing_show', $show, $post );
// Disabled for this post?
@@ -517,6 +633,13 @@ function sharing_display( $text = '', $echo = false ) {
if ( !empty( $switched_status ) )
$show = false;
+ // Private post?
+ $post_status = get_post_status( $post->ID );
+
+ if ( $post_status == 'private' ) {
+ $show = false;
+ }
+
// Allow to be used on P2 ajax requests for latest posts.
if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['action'] ) && 'get_latest_posts' == $_REQUEST['action'] )
$show = true;
@@ -524,6 +647,13 @@ function sharing_display( $text = '', $echo = false ) {
$sharing_content = '';
if ( $show ) {
+ /**
+ * Filters the list of enabled Sharing Services.
+ *
+ * @since 2.2.3
+ *
+ * @param array $sharer->get_blog_services() Array of Sharing Services currently enabled.
+ */
$enabled = apply_filters( 'sharing_enabled', $sharer->get_blog_services() );
if ( count( $enabled['all'] ) > 0 ) {
@@ -593,7 +723,12 @@ function sharing_display( $text = '', $echo = false ) {
$sharing_content .= '</div></div></div>';
// Register our JS
- wp_register_script( 'sharing-js', plugin_dir_url( __FILE__ ).'sharing.js', array( 'jquery' ), '20121205' );
+ if ( defined( 'JETPACK__VERSION' ) ) {
+ $ver = JETPACK__VERSION;
+ } else {
+ $ver = '20141212';
+ }
+ wp_register_script( 'sharing-js', plugin_dir_url( __FILE__ ).'sharing.js', array( 'jquery' ), $ver );
add_action( 'wp_footer', 'sharing_add_footer' );
}
}