]*>(.*?)<\/div>/i', '', $content );
return $content;
}
add_filter( 'the_content_feed', 'shariff3uu_remove_from_rss', 999 );
/**
* Adds shariff buttons after bbpress forums.
*/
function shariff3uu_bbp_add_shariff_after_forum() {
// Get options.
$shariff3uu = $GLOBALS['shariff3uu'];
if ( isset( $shariff3uu['add_after']['forum'] ) && 1 === $shariff3uu['add_after']['forum'] ) {
// phpcs:ignore
echo shariff3uu_render( array() );
}
}
add_action( 'bbp_template_after_forums_loop', 'shariff3uu_bbp_add_shariff_after_forum' );
/**
* Adds shariff buttons after bbpress topics.
*/
function shariff3uu_bbp_add_shariff_after_topic() {
// Get options.
$shariff3uu = $GLOBALS['shariff3uu'];
if ( isset( $shariff3uu['add_after']['topic'] ) && 1 === $shariff3uu['add_after']['topic'] ) {
// phpcs:ignore
echo shariff3uu_render( array() );
}
}
add_action( 'bbp_template_after_topics_loop', 'shariff3uu_bbp_add_shariff_after_topic' );
/**
* Adds shariff buttons after bbpress replies.
*/
function shariff3uu_bbp_add_shariff_after_reply() {
// Get options.
$shariff3uu = $GLOBALS['shariff3uu'];
if ( isset( $shariff3uu['add_after']['reply'] ) && 1 === $shariff3uu['add_after']['reply'] ) {
// phpcs:ignore
echo shariff3uu_render( array() );
}
}
add_action( 'bbp_theme_after_reply_content', 'shariff3uu_bbp_add_shariff_after_reply' );
/**
* Adds shariff buttons before bbpress forums.
*/
function shariff3uu_bbp_add_shariff_before_forum() {
// Get options.
$shariff3uu = $GLOBALS['shariff3uu'];
if ( isset( $shariff3uu['add_before']['forum'] ) && 1 === $shariff3uu['add_before']['forum'] ) {
// phpcs:ignore
echo shariff3uu_render( array() );
}
}
add_action( 'bbp_template_before_forums_loop', 'shariff3uu_bbp_add_shariff_before_forum' );
/**
* Adds shariff buttons before bbpress topics.
*/
function shariff3uu_bbp_add_shariff_before_topic() {
// Get options.
$shariff3uu = $GLOBALS['shariff3uu'];
if ( isset( $shariff3uu['add_before']['topic'] ) && 1 === $shariff3uu['add_before']['topic'] ) {
// phpcs:ignore
echo shariff3uu_render( array() );
}
}
add_action( 'bbp_template_before_topics_loop', 'shariff3uu_bbp_add_shariff_before_topic' );
/**
* Adds shariff buttons before bbpress replies.
*/
function shariff3uu_bbp_add_shariff_before_reply() {
// Get options.
$shariff3uu = $GLOBALS['shariff3uu'];
if ( isset( $shariff3uu['add_before']['reply'] ) && 1 === $shariff3uu['add_before']['reply'] ) {
// phpcs:ignore
echo shariff3uu_render( array() );
}
}
add_action( 'bbp_theme_before_reply_content', 'shariff3uu_bbp_add_shariff_before_reply' );
/**
* Adds shariff to custom hooks.
*/
function shariff3uu_add_shariff_custom_hooks() {
// Get options.
$shariff3uu = $GLOBALS['shariff3uu'];
if ( isset( $shariff3uu['custom_hooks_shortcode'] ) && ! empty( $shariff3uu['custom_hooks_shortcode'] ) ) {
// Replaces shariff with shariffmeta.
$shariff3uu_custom_hooks_shortcode = str_replace( '[shariff ', '[shariffmeta ', $shariff3uu['custom_hooks_shortcode'] );
// Extracts attributes.
if ( '[shariffmeta]' !== $shariff3uu_custom_hooks_shortcode ) {
do_shortcode( $shariff3uu_custom_hooks_shortcode );
}
if ( isset( $GLOBALS['shariff3uu']['metabox'] ) && ! empty( $GLOBALS['shariff3uu']['metabox'] ) ) {
$shariff3uu_custom_hooks_shortcode = $GLOBALS['shariff3uu']['metabox'];
} else {
$shariff3uu_custom_hooks_shortcode = array();
}
// Clears the metabox global.
$GLOBALS['shariff3uu']['metabox'] = '';
// phpcs:ignore
echo shariff3uu_render( $shariff3uu_custom_hooks_shortcode );
} else {
// phpcs:ignore
echo shariff3uu_render( array() );
}
}
if ( isset( $shariff3uu['custom_hooks'] ) && ! empty( $shariff3uu['custom_hooks'] ) ) {
// Explodes hooks.
$hook_array = explode( '|', $shariff3uu['custom_hooks'] );
// Remove duplicated hooks.
$hook_array = array_unique( $hook_array );
// Loops through all desired hooks.
foreach ( $hook_array as $hook ) {
add_action( esc_html( $hook ), 'shariff3uu_add_shariff_custom_hooks' );
}
}
/**
* Function is called to include the shariff.css in the header of AMP pages.
* Currently only called by the amp_post_template_css hook.
* Supports the AMP plugin by Automatic and the AMP for WP plugin by Ahmed and Mohammed Kaludi.
* We need to strip out all !important in order to pass AMP test.
*/
function shariff3uu_amp_css() {
// Get options.
$shariff3uu = $GLOBALS['shariff3uu'];
// Output CSS.
ob_start();
include dirname( __FILE__ ) . '/css/shariff.min.css';
$shariff_css = ob_get_clean();
if ( false !== $shariff_css ) {
echo esc_html( str_replace( '!important', '', $shariff_css ) );
} else {
include dirname( __FILE__ ) . '/css/shariff.min.css';
}
if ( array_key_exists( 'dynamic_css', $shariff3uu ) && ! empty( $shariff3uu['dynamic_css'] ) ) {
echo esc_html( $shariff3uu['dynamic_css'] );
}
}
add_action( 'amp_post_template_css', 'shariff3uu_amp_css' );
// Registers the shortcode.
add_shortcode( 'shariff', 'shariff3uu_render' );
/**
* Renders the shorttag to the HTML shorttag of Shariff.
*
* @param array $atts (optional) Array of shariff options provided in the shorttag.
*
* @return string|null The rendered HTML shorttag or null if a disable condition is met.
*/
function shariff3uu_render( $atts ) {
// Get options.
$shariff3uu_basic = (array) get_option( 'shariff3uu_basic' );
$shariff3uu_design = (array) get_option( 'shariff3uu_design' );
$shariff3uu_advanced = (array) get_option( 'shariff3uu_advanced' );
$shariff3uu_statistic = (array) get_option( 'shariff3uu_statistic' );
$shariff3uu = array_merge( $shariff3uu_basic, $shariff3uu_design, $shariff3uu_advanced, $shariff3uu_statistic );
if ( array_key_exists( 'dynamic_css', $shariff3uu ) && ! empty( $shariff3uu['dynamic_css'] ) ) {
$dynamic_css = $shariff3uu['dynamic_css'];
} else {
$dynamic_css = '';
}
// Stops all further actions if we are on an admin page.
if ( is_admin() ) {
return null;
}
// Avoids errors if no attributes are given - instead uses the old set of services to make it backward compatible.
if ( empty( $shariff3uu['services'] ) ) {
$shariff3uu['services'] = 'twitter|facebook|linkedin|info';
}
// Uses the backend option for every option that is not set in the shorttag.
$backend_options = $shariff3uu;
if ( isset( $shariff3uu['vertical'] ) && 1 === $shariff3uu['vertical'] ) {
$backend_options['orientation'] = 'vertical';
}
if ( isset( $shariff3uu['backend'] ) && 1 === $shariff3uu['backend'] ) {
$backend_options['backend'] = 'on';
}
if ( isset( $shariff3uu['buttonsize'] ) && 1 === $shariff3uu['buttonsize'] ) {
$backend_options['buttonsize'] = 'small';
}
if ( empty( $atts ) ) {
$atts = $backend_options;
} else {
$atts = array_merge( $backend_options, $atts );
}
// Gets the metabox ignore widget value.
$shariff_metabox_ignore_widget = get_post_meta( get_the_ID(), 'shariff_metabox_ignore_widget', true );
// Adds the meta box settings if it is not a widget or if it is a widget and not being set to be ignored.
if ( ( ! isset( $atts['widget'] ) || ( isset( $atts['widget'] ) && 1 === $atts['widget'] && 1 !== $shariff_metabox_ignore_widget ) ) && 'total' !== $atts['services'] && 'totalnumber' !== $atts['services'] ) {
// Gets the meta box disable value.
$shariff3uu_metabox_disable = get_post_meta( get_the_ID(), 'shariff_metabox_disable', true );
// Stops all further actions if the meta box setting is set to disabled.
if ( '1' === $shariff3uu_metabox_disable ) {
return null;
}
// Gets the meta box shortcode.
$shariff3uu_metabox = get_post_meta( get_the_ID(), 'shariff_metabox', true );
// Replaces shariff with shariffmeta.
$shariff3uu_metabox = str_replace( '[shariff ', '[shariffmeta ', $shariff3uu_metabox );
// Gets the meta box attributes.
if ( '[shariffmeta]' !== $shariff3uu_metabox ) {
do_shortcode( $shariff3uu_metabox );
}
if ( isset( $GLOBALS['shariff3uu']['metabox'] ) && ! empty( $GLOBALS['shariff3uu']['metabox'] ) ) {
$metabox = $GLOBALS['shariff3uu']['metabox'];
} else {
$metabox = array();
}
// Gets the meta box media attribute.
$shariff3uu_metabox_media = get_post_meta( get_the_ID(), 'shariff_metabox_media', true );
if ( ! empty( $shariff3uu_metabox_media ) ) {
$metabox['media'] = $shariff3uu_metabox_media;
}
// Merges the meta box atts array with the atts array (meta box shortcode overrides all others).
if ( ! empty( $metabox ) ) {
$atts = array_merge( $atts, $metabox );
}
// Clears the metabox global.
$GLOBALS['shariff3uu']['metabox'] = '';
} // End meta box if.
// Ov3rfly: Makes the attributes configurable from outside, e.g. for language etc.
$atts = apply_filters( 'shariff3uu_render_atts', $atts );
// Removes empty elements.
$atts = array_filter( $atts );
// Cleans up services (remove leading or trailing |, spaces, etc.).
$atts['services'] = trim( preg_replace( '/[^A-Za-z|]/', '', $atts['services'] ), '|' );
// Cleans up the headline in case it was used in a shorttag.
if ( array_key_exists( 'headline', $atts ) ) {
$atts['headline'] = wp_kses( $atts['headline'], $GLOBALS['allowed_tags'] );
}
// Cleans up the alternative headline in case it was used in a shorttag.
if ( array_key_exists( 'headline_zero', $atts ) ) {
$atts['headline_zero'] = wp_kses( $atts['headline_zero'], $GLOBALS['allowed_tags'] );
}
// Remove previous added inline styles to prevent duplications.
if ( wp_style_is( 'shariffcss', 'enqueued' ) ) {
wp_deregister_style( 'shariffcss' );
}
// Enqueues the stylesheet (loading it here makes sure that it is only loaded on pages that actually contain shariff buttons).
// If SCRIPT_DEBUG is set to true, the non minified version will be loaded.
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG === true ) {
$shariff_css_url = trailingslashit( plugins_url() ) . 'shariff/css/shariff.css';
} else {
$shariff_css_url = trailingslashit( plugins_url() ) . 'shariff/css/shariff.min.css';
}
wp_enqueue_style( 'shariffcss', $shariff_css_url, '', $shariff3uu['version'] );
// Enqueues the share count script (the JS should be loaded at the footer - make sure that wp_footer() is present in your theme!)
// If SCRIPT_DEBUG is set to true, the non minified version will be loaded.
if ( array_key_exists( 'backend', $atts ) && 'on' === $atts['backend'] ) {
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG === true ) {
$shariff_js_url = trailingslashit( plugins_url() ) . 'shariff/js/shariff.js';
} else {
$shariff_js_url = trailingslashit( plugins_url() ) . 'shariff/js/shariff.min.js';
}
wp_enqueue_script( 'shariffjs', $shariff_js_url, '', $shariff3uu['version'], true );
}
// Enqueues the popup script (the JS should be loaded at the footer - make sure that wp_footer() is present in your theme!).
// If SCRIPT_DEBUG is set to true, the non minified version will be loaded.
if ( array_key_exists( 'popup', $atts ) && 1 === $atts['popup'] ) {
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG === true ) {
$shariff_js_popup_url = trailingslashit( plugins_url() ) . 'shariff/js/shariff-popup.js';
} else {
$shariff_js_popup_url = trailingslashit( plugins_url() ) . 'shariff/js/shariff-popup.min.js';
}
wp_enqueue_script( 'shariff_popup', $shariff_js_popup_url, '', $shariff3uu['version'], true );
}
// Sets the share url.
if ( array_key_exists( 'url', $atts ) ) {
$share_url = rawurlencode( $atts['url'] );
} else {
$share_url = rawurlencode( get_permalink() );
}
// Sets the share title.
if ( array_key_exists( 'title', $atts ) ) {
$share_title = rawurlencode( wp_strip_all_tags( $atts['title'] ) );
} else {
$share_title = rawurlencode( wp_strip_all_tags( html_entity_decode( get_the_title(), ENT_COMPAT, 'UTF-8' ) ) );
}
// Sets the transient name.
$post_hash = 'shariff' . hash( 'md5', $share_url );
// Prevents php notices.
$share_counts = array();
$output = '';
// Gets the cached share counts.
if ( array_key_exists( 'backend', $atts ) && 'on' === $atts['backend'] && get_transient( $post_hash ) !== false ) {
$share_counts = get_transient( $post_hash );
}
// Adds ShariffSC container including custom styles if a custom style attribute or class exists.
if ( array_key_exists( 'style', $atts ) || array_key_exists( 'cssclass', $atts ) ) {
$output .= '
'cподеляне',
'cs' => 'sdílet',
'da' => 'del',
'de' => 'teilen',
'en' => 'share',
'es' => 'compartir',
'fi' => 'Jaa',
'fr' => 'partager',
'hr' => 'podijelite',
'hu' => 'megosztás',
'it' => 'condividi',
'ja' => '共有',
'ko' => '공유하기',
'nl' => 'delen',
'no' => 'del',
'pl' => 'udostępnij',
'pt' => 'compartilhar',
'ro' => 'partajează',
'ru' => 'поделиться',
'sk' => 'zdieľať',
'sl' => 'deli',
'sr' => 'podeli',
'sv' => 'dela',
'tr' => 'paylaş',
'zh' => '分享',
);
// Adds the timestamp for the cache.
if ( array_key_exists( 'timestamp', $atts ) ) {
$post_timestamp = $atts['timestamp'];
} else {
$post_timestamp = absint( get_the_modified_date( 'U' ) );
}
// Starts the output of the actual Shariff buttons.
$output .= '
';
// Closes the style attribute, if there was one.
if ( array_key_exists( 'style', $atts ) || array_key_exists( 'cssclass', $atts ) ) {
$output .= '
';
}
// Update the dynamic css db entry if needed.
if ( ( array_key_exists( 'dynamic_css', $shariff3uu ) && $shariff3uu['dynamic_css'] !== $dynamic_css ) || ! array_key_exists( 'dynamic_css', $shariff3uu ) ) {
$shariff3uu_design = array_filter( $GLOBALS['shariff3uu_design'] );
$shariff3uu_design['dynamic_css'] = $dynamic_css;
$GLOBALS['shariff3uu']['dynamic_css'] = $dynamic_css;
update_option( 'shariff3uu_design', $shariff3uu_design );
}
// Displays a warning to admins if patreon is set, but no patreon username was provided.
if ( 1 === $patreon_error && current_user_can( 'manage_options' ) ) {
$output .= '
' . __( 'Username for patreon is missing!', 'shariff' ) . '
';
}
// Displays a warning to admins if paypal is set, but no paypal button id was provided.
if ( 1 === $paypal_error && current_user_can( 'manage_options' ) ) {
$output .= '
' . __( 'Button ID for PayPal is missing!', 'shariff' ) . '
';
}
// Displays a warning to admins if paypalme is set, but no paypalme id was provided.
if ( 1 === $paypalme_error && current_user_can( 'manage_options' ) ) {
$output .= '
' . __( 'PayPal.Me ID is missing!', 'shariff' ) . '
';
}
// Displays a warning to admins if bitcoin is set, but no bitcoin address was provided.
if ( 1 === $bitcoin_error && current_user_can( 'manage_options' ) ) {
$output .= '
' . __( 'Address for Bitcoin is missing!', 'shariff' ) . '
';
}
// If the service totalnumber is set, just output the total share count.
if ( array_key_exists( '0', $service_array ) && 'totalnumber' === $service_array['0'] ) {
$output = '
';
}
return $output;
}
// Registers the helper shortcode.
add_shortcode( 'shariffmeta', 'shariff3uu_meta' );
/**
* Meta box helper function. Creates a global variable with the current meta box attributes.
*
* @param array $atts List of shariff shortcode attributes.
*/
function shariff3uu_meta( $atts ) {
if ( ! empty( $atts ) ) {
$GLOBALS['shariff3uu']['metabox'] = $atts;
} else {
$GLOBALS['shariff3uu']['metabox'] = array();
}
}
/**
* Clears transients and removes cron job upon deactivation.
*/
function shariff3uu_deactivate() {
// Checks for multisite.
if ( is_multisite() && function_exists( 'get_sites' ) && class_exists( 'WP_Site_Query' ) ) {
$sites = get_sites();
foreach ( $sites as $site ) {
switch_to_blog( $site->blog_id );
// Purges transients.
shariff3uu_purge_transients_deactivation();
// Removes the cron job.
wp_clear_scheduled_hook( 'shariff3uu_fill_cache' );
// Switches back to main blog.
restore_current_blog();
}
} else {
// Purges transients.
shariff3uu_purge_transients_deactivation();
// Removes cron job.
wp_clear_scheduled_hook( 'shariff3uu_fill_cache' );
}
}
register_deactivation_hook( __FILE__, 'shariff3uu_deactivate' );
/**
* Purges all the transients associated with our plugin.
*/
function shariff3uu_purge_transients_deactivation() {
// Makes sure the $wpdb class is ready.
if ( ! isset( $wpdb ) ) {
global $wpdb;
}
// Deletes transients.
// phpcs:disable
$wpdb->query( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE "_transient_timeout_shariff%"' );
$wpdb->query( 'DELETE FROM ' . $wpdb->options . ' WHERE option_name LIKE "_transient_shariff%"' );
// phpcs:enable
// Clears the object cache.
wp_cache_flush();
}