ID ) ), ENT_QUOTES, 'UTF-8' );
} else {
$linkname = '';
}
}
$linkname_enc = rawurlencode( $linkname );
// Set linkurl if needed, and not a Follow kit.
if ( ! $linkurl && empty( $args['is_follow'] ) ) {
if ( $use_current_page ) {
$linkurl = esc_url_raw( home_url( $_SERVER['REQUEST_URI'] ) );
} elseif ( isset( $post ) ) {
$linkurl = get_permalink( $post->ID );
} else {
$linkurl = '';
}
}
$linkurl_enc = rawurlencode( $linkurl );
// Set linkmedia (only applies to services that explicitly accept media; Pinterest does, most do not).
$linkmedia_enc = ! empty( $args['linkmedia'] ) ? rawurlencode( $args['linkmedia'] ) : '';
return compact( 'linkname', 'linkname_enc', 'linkurl', 'linkurl_enc', 'linkmedia', 'linkmedia_enc', 'use_current_page' );
}
// Combine ADDTOANY_SHARE_SAVE_ICONS and ADDTOANY_SHARE_SAVE_BUTTON.
function ADDTOANY_SHARE_SAVE_KIT( $args = array() ) {
$options = get_option( 'addtoany_options', array() );
$args = array_merge( $args, A2A_SHARE_SAVE_link_vars( $args ) ); // linkname_enc, etc.
$defaults = array(
'output_later' => false,
'icon_size' => isset( $options['icon_size'] ) ? $options['icon_size'] : '32',
'is_follow' => false,
);
$args = wp_parse_args( $args, $defaults );
// If universal button disabled, and not manually disabled through args.
if ( isset( $options['button'] ) && $options['button'] == 'NONE' && ! isset( $args['no_universal_button'] ) ) {
// Pass this setting on to ADDTOANY_SHARE_SAVE_BUTTON,
// and only via this ADDTOANY_SHARE_SAVE_KIT function because it is used for automatic placement.
$args['no_universal_button'] = true;
}
// Custom icons enabled?
$custom_icons = ( isset( $options['custom_icons'] ) && $options['custom_icons'] == 'url' && isset( $options['custom_icons_url'] ) ) ? true : false;
$kit_additional_classes = '';
$kit_data_media = empty( $args['linkmedia'] ) ? '' : ' data-a2a-media="' . esc_attr( $args['linkmedia'] ) . '"';
$kit_data_title = empty( $args['linkname'] ) || $args['use_current_page'] ? '' : ' data-a2a-title="' . esc_attr( $args['linkname'] ) . '"';
$kit_data_url = empty( $args['linkurl'] ) || $args['use_current_page'] ? '' : ' data-a2a-url="' . esc_attr( $args['linkurl'] ) . '"';
$kit_data_scroll_show = empty( $args['scroll_show'] ) ? '' : ' data-a2a-scroll-show="' . esc_attr( $args['scroll_show'] ) . '"';
$kit_style = '';
// Add additional classNames to .a2a_kit.
if ( ! empty( $args['kit_additional_classes'] ) ) {
// Append space and className(s).
$kit_additional_classes .= ' ' . $args['kit_additional_classes'];
}
// Set a2a_kit_size_## class name.
if ( $custom_icons ) {
// If vertical style (.a2a_vertical_style)
if ( strpos( $kit_additional_classes, 'a2a_vertical_style' ) !== false ) {
// Use width (if specified) for .a2a_kit_size_## class name to size default service counters.
$icon_size_classname = isset( $options['custom_icons_width'] ) ? ' a2a_kit_size_' . $options['custom_icons_width'] : '';
} else {
// Use height (if specified) for .a2a_kit_size_## class name to size default service counters.
$icon_size_classname = isset( $options['custom_icons_height'] ) ? ' a2a_kit_size_' . $options['custom_icons_height'] : '';
}
// Set a2a_kit_size_## icon size.
} else {
$icon_size_classname = ' a2a_kit_size_' . $args['icon_size'];
}
// Add addtoany_list className unless disabled (for floating buttons).
if ( ! isset( $args['no_addtoany_list_classname'] ) ) {
$kit_additional_classes .= ' addtoany_list';
}
// Add style attribute if set.
if ( ! empty( $args['kit_style'] ) ) {
$kit_style = ' style="' . esc_attr( $args['kit_style'] ) . '"';
}
if ( ! isset( $args['html_container_open'] ) ) {
$args['html_container_open'] = '
';
$args['is_kit'] = true;
}
if ( ! isset( $args['html_container_close'] ) )
$args['html_container_close'] = "
";
// Close container element in ADDTOANY_SHARE_SAVE_BUTTON, not prematurely in ADDTOANY_SHARE_SAVE_ICONS.
// Cache for _BUTTON.
$html_container_close = $args['html_container_close'];
// Avoid passing to ADDTOANY_SHARE_SAVE_ICONS since set in _BUTTON.
unset( $args['html_container_close'] );
if ( ! isset( $args['html_wrap_open'] ) )
$args['html_wrap_open'] = "";
if ( ! isset( $args['html_wrap_close'] ) )
$args['html_wrap_close'] = "";
$kit_html = ADDTOANY_SHARE_SAVE_ICONS( $args );
// Set again because it was unset above for _ICONS.
$args['html_container_close'] = $html_container_close;
// Avoid passing to ADDTOANY_SHARE_SAVE_BUTTON since set in _ICONS.
unset( $args['html_container_open'] );
$kit_html .= ADDTOANY_SHARE_SAVE_BUTTON( $args );
if ( true == $args['output_later'] )
return $kit_html;
else
echo wp_kses_post( $kit_html );
}
function ADDTOANY_SHARE_SAVE_ICONS( $args = array() ) {
// $args array: output_later, html_container_open, html_container_close, html_wrap_open, html_wrap_close, linkname, linkurl
global $A2A_SHARE_SAVE_services,
$A2A_FOLLOW_services;
$options = get_option( 'addtoany_options', array() );
$args = array_merge( $args, A2A_SHARE_SAVE_link_vars( $args ) ); // linkname_enc, etc.
$defaults = array(
'linkname' => '',
'linkurl' => '',
'linkmedia' => '',
'linkname_enc' => '',
'linkurl_enc' => '',
'linkmedia_enc' => '',
'output_later' => false,
'html_container_open' => '',
'html_container_close' => '',
'html_wrap_open' => '',
'html_wrap_close' => '',
'icon_size' => isset( $options['icon_size'] ) ? $options['icon_size'] : '32',
'is_follow' => false,
'no_universal_button' => false,
'basic_html' => false,
'buttons' => array(),
);
$args = wp_parse_args( $args, $defaults );
$is_amp = function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ? true : false;
// Use large icons except for AMP.
$large_icons = $is_amp ? false : true;
// Make the color of the icons extensible, primariliy for AMP use cases.
$icon_bg_color_filtered = apply_filters( 'addtoany_icons_bg_color', '' );
// Directory of either custom icons or the packaged icons
if ( isset( $options['custom_icons'] ) && $options['custom_icons'] == 'url' && isset( $options['custom_icons_url'] ) ) {
// Custom icons expected at a specified URL, i.e. //example.com/blog/uploads/addtoany/icons/custom/
$icons_dir = $options['custom_icons_url'];
$icons_type = ( isset( $options['custom_icons_type'] ) ) ? $options['custom_icons_type'] : 'png';
$icons_width = ( isset( $options['custom_icons_width'] ) ) ? $options['custom_icons_width'] : '';
$icons_height = ( isset( $options['custom_icons_height'] ) ) ? $options['custom_icons_height'] : '';
$custom_icons = true;
} else {
// Default to local SVGs.
$icons_dir = plugins_url('/icons/', __FILE__ );
$icons_type = 'svg';
}
// If Follow kit
if ( $args['is_follow'] ) {
// Make available services extensible via plugins, themes (functions.php), etc.
$services = apply_filters( 'A2A_FOLLOW_services', $A2A_FOLLOW_services );
$service_codes = ( is_array( $services ) ) ? array_keys( $services ) : array();
// Services set by "buttons" arg
$active_services = empty( $args['buttons'] ) ? array() : array_keys( $args['buttons'] );
// Else Share kit
} else {
// Make available services extensible via plugins, themes (functions.php), etc.
$services = apply_filters( 'A2A_SHARE_SAVE_services', $A2A_SHARE_SAVE_services );
$service_codes = ( is_array( $services ) ) ? array_keys( $services ) : array();
// Include Facebook Like and Twitter Tweet etc. unless no_special_services arg is true.
if ( ! isset( $args['no_special_services'] ) || false == $args['no_special_services'] ) {
array_unshift( $service_codes, 'facebook_like', 'twitter_tweet', 'pinterest_pin' );
}
// Use default services if services have not been selected yet.
$active_services = isset( $options['active_services'] ) ? $options['active_services'] : array( 'facebook', 'mastodon', 'email' );
// Services set by "buttons" arg? Then use "buttons" arg instead.
$active_services = empty( $args['buttons'] ) ? $active_services : $args['buttons'];
}
$ind_html = "" . $args['html_container_open'];
foreach( $active_services as $active_service ) {
$custom_service = false;
if ( ! in_array( $active_service, $service_codes ) )
continue;
if ( $active_service == 'facebook_like' || $active_service == 'twitter_tweet' || $active_service == 'pinterest_pin' ) {
$special_args = $args;
$special_args['output_later'] = true;
$link = ADDTOANY_SHARE_SAVE_SPECIAL( $active_service, $special_args );
} else {
$service = $services[ $active_service ];
$code_name = $active_service;
$name = $service['name'];
// If Follow kit and HREF specified
if ( $args['is_follow'] && isset( $service['href'] ) ) {
$follow_id = $args['buttons'][ $active_service ]['id'];
$is_url = in_array( parse_url( $follow_id, PHP_URL_SCHEME ), array( 'http', 'https' ) );
// If it's a URL instead of a service ID
if ( $is_url ) {
// Just use the given URL instead of the URL template.
$href = $follow_id;
} else {
// Replace the ID placeholder in the URL template.
$href = str_replace( '${id}', $follow_id, $service['href'] );
}
$href = ( 'feed' == $code_name ) ? $follow_id : $href;
// If icon_url is set, presume custom service.
if ( isset( $service['icon_url'] ) ) {
$custom_service = true;
}
// Else if Share Kit and HREF specified, presume custom service.
} elseif ( isset( $service['href'] ) ) {
$custom_service = true;
$href = $service['href'];
if ( isset( $service['href_js_esc'] ) ) {
$href_linkurl = str_replace( "'", "\'", $args['linkurl'] );
$href_linkname = str_replace( "'", "\'", $args['linkname'] );
} else {
$href_linkurl = $args['linkurl_enc'];
$href_linkname = $args['linkname_enc'];
}
$href = str_replace( "A2A_LINKURL", $href_linkurl, $href );
$href = str_replace( "A2A_LINKNAME", $href_linkname, $href );
$href = str_replace( " ", "%20", $href );
}
// AddToAny counter enabled?
$counter_enabled = ( ! $args['is_follow'] // Disable counters on Follow Kits
&& in_array( $active_service, array( 'pinterest', 'reddit', 'tumblr' ) )
&& isset( $options['special_' . $active_service . '_options'] )
&& isset( $options['special_' . $active_service . '_options']['show_count'] )
&& $options['special_' . $active_service . '_options']['show_count'] == '1'
) ? true : false;
$icon = isset( $service['icon'] ) ? $service['icon'] : 'default'; // Just the icon filename
$icon_url = isset( $service['icon_url'] ) ? $service['icon_url'] : false;
$icon_url = $is_amp && ! $icon_url ? 'https://static.addtoany.com/buttons/' . $icon . '.svg' : $icon_url;
$width_attr = isset( $service['icon_width'] ) ? ' width="' . esc_attr( $service['icon_width'] ) . '"' : ' width="16"';
$width_attr = $is_amp && ! empty( $args['icon_size'] ) ? ' width="' . esc_attr( $args['icon_size'] ) . '"' : $width_attr;
$height_attr = isset( $service['icon_height'] ) ? ' height="' . esc_attr( $service['icon_height'] ) . '"' : ' height="16"';
$height_attr = $is_amp && ! empty( $args['icon_size'] ) ? ' height="' . esc_attr( $args['icon_size'] ) . '"' : $height_attr;
$img_style_attr_bg_color = ! empty( $service['color'] ) ? '#' . $service['color'] : '';
$img_style_attr_bg_color = ! empty( $icon_bg_color_filtered ) ? $icon_bg_color_filtered : $img_style_attr_bg_color;
$img_style_attr = $is_amp && ! empty( $img_style_attr_bg_color ) ? ' style="background-color:' . esc_attr( $img_style_attr_bg_color ) . ';"' : '';
$url = isset( $href ) ? $href : 'https://www.addtoany.com/add_to/' . $code_name . '?linkurl=' . $args['linkurl_enc'] .'&linkname=' . $args['linkname_enc'];
$src = $icon_url ? $icon_url : $icons_dir . $icon . '.' . $icons_type;
$counter = $counter_enabled ? ' a2a_counter' : '';
$class_attr = $custom_service ? '' : ' class="a2a_button_' . esc_attr( $code_name ) . $counter . '"';
$href_attr = $args['basic_html'] && ! isset( $href ) ? '' : ' href="' . esc_attr( $url ) . '"';
$title_attr = $args['basic_html'] ? '' : ' title="' . esc_attr( $name ) . '"';
if ( isset( $service['target'] ) ) {
$target_attr = empty( $service['target'] ) ? '' : ' target="' . esc_attr( $service['target'] ) . '"';
} elseif ( ! $args['basic_html'] ) {
$target_attr = ' target="_blank"';
} else {
$target_attr = '';
}
// Use rel="noopener" for links that open in a new tab/window.
$rel_noopener = $custom_service || ! $target_attr ? '' : ' noopener';
$rel_noopener_only = $rel_noopener || $target_attr ? ' rel="noopener"' : '';
$rel_attr = $args['is_follow'] ? $rel_noopener_only : ' rel="nofollow' . $rel_noopener . '"'; // ($args['is_follow'] indicates a Follow Kit. 'nofollow' is for search crawlers. Different things)
$rel_attr = $args['basic_html'] ? '' : $rel_attr;
// Use AMP's "print" action.
if ( $is_amp && 'print' === $code_name ) {
$amp_on_attr = ' on="tap:AMP.print()"';
$href_attr = ' href="#print"';
$target_attr = '';
} else {
$amp_on_attr = '';
}
// Set dimension attributes if using custom icons and dimension is specified.
if ( isset( $custom_icons ) && ! $is_amp ) {
$width_attr = ! empty( $icons_width ) ? ' width="' . $icons_width . '"' : '';
$height_attr = ! empty( $icons_height ) ? ' height="' . $icons_height . '"' : '';
}
$link = $args['html_wrap_open'] . "";
$link .= ( $large_icons && ! isset( $custom_icons ) && ! $custom_service ) ? '' : '
';
$link .= "" . $args['html_wrap_close'];
}
$ind_html .= $link;
}
$ind_html .= $args['html_container_close'];
if ( true == $args['output_later'] )
return $ind_html;
else
echo wp_kses_post( $ind_html );
}
function ADDTOANY_SHARE_SAVE_BUTTON( $args = array() ) {
// $args array = output_later, html_container_open, html_container_close, html_wrap_open, html_wrap_close, linkname, linkurl, no_universal_button
$options = get_option( 'addtoany_options', array() );
$args = array_merge( $args, A2A_SHARE_SAVE_link_vars( $args ) ); // linkname_enc, etc.
$defaults = array(
'linkname' => '',
'linkurl' => '',
'linkmedia' => '',
'linkname_enc' => '',
'linkurl_enc' => '',
'linkmedia_enc' => '',
'use_current_page' => false,
'output_later' => false,
'is_kit' => false,
'html_container_open' => '',
'html_container_close' => '',
'html_wrap_open' => '',
'html_wrap_close' => '',
'html_content' => '',
'button_additional_classes' => '',
'icon_size' => isset( $options['icon_size'] ) ? $options['icon_size'] : '32',
'no_universal_button' => false,
);
$args = wp_parse_args( $args, $defaults );
$is_feed = is_feed();
$is_amp = function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ? true : false;
// Make the color of the icons extensible, primariliy for AMP use cases.
$icon_bg_color_filtered = apply_filters( 'addtoany_icons_bg_color', '#0166ff' );
$button_class = '';
$button_data_media = $args['is_kit'] || empty( $args['linkmedia'] ) ? '' : ' data-a2a-media="' . esc_attr( $args['linkmedia'] ) . '"';
$button_data_title = $args['is_kit'] || empty( $args['linkname'] ) ? '' : ' data-a2a-title="' . esc_attr( $args['linkname'] ) . '"';
$button_data_url = $args['is_kit'] || empty( $args['linkurl'] ) ? '' : ' data-a2a-url="' . esc_attr( $args['linkurl'] ) . '"';
$button_target = $is_amp ? ' target="_blank"' : '';
$button_href_querystring = ($is_feed || $is_amp) ? '#url=' . $args['linkurl_enc'] . '&title=' . $args['linkname_enc'] : '';
// If universal button is enabled
if ( ! $args['no_universal_button'] ) {
if ( isset( $options['button'] ) && 'CUSTOM' == $options['button'] ) {
// Custom button.
$button_src = $options['button_custom'];
$button_width = '';
$button_height = '';
$button_style = '';
} else if ( isset( $options['button'] ) && 'TEXT' == $options['button'] ) {
// Text-only button.
$button_text = stripslashes( $options[ 'button_text'] );
// Do not display universal icon.
$button_class .= ' addtoany_no_icon';
} else {
// Default AddToAny button.
if ( $is_amp ) {
// AMP (Accelerated Mobile Page).
$button_src = 'https://static.addtoany.com/buttons/a2a.svg';
$button_width = ! empty( $args['icon_size'] ) ? ' width="' . $args['icon_size'] .'"' : ' width="32"';
$button_height = ! empty( $args['icon_size'] ) ? ' height="' . $args['icon_size'] .'"' : ' height="32"';
$button_style = ! empty( $icon_bg_color_filtered ) ? ' style="background-color:' . esc_attr( $icon_bg_color_filtered ) . '"' : '';
}
}
if ( ! empty( $html_content ) ) {
$button = $html_content;
} elseif ( ! empty( $button_text ) ) {
$button = $button_text;
} elseif ( ! empty( $button_src ) ) {
$button = '
';
} else {
$button = '';
}
// Add additional classNames to .a2a_dd.
$button_additional_classes = ! empty( $args['button_additional_classes'] ) ? ' ' . $args['button_additional_classes'] : '';
if ( isset( $options['button_show_count'] ) && $options['button_show_count'] == '1' ) {
$button_class .= ' a2a_counter';
}
$button_html = $args['html_container_open'] . $args['html_wrap_open'] . '' . $button . '';
} else {
// Universal button disabled.
$button_html = '';
}
// Closing tags come after