first commit

This commit is contained in:
CHIEFSOFT\ameye
2023-11-30 13:20:54 -05:00
commit e9e5c0546c
5833 changed files with 1801865 additions and 0 deletions
@@ -0,0 +1,643 @@
<?php
/**
* The admin-specific functionality of the module.
*
* @link https://codesupply.co
* @since 1.0.0
*
* @package Powerkit
* @subpackage Modules/Admin
*/
/**
* The admin-specific functionality of the module.
*/
class Powerkit_Share_Buttons_Admin extends Powerkit_Module_Admin {
/**
* Initialize
*/
public function initialize() {
add_action( 'init', array( $this, 'register_options_default' ) );
add_action( 'admin_menu', array( $this, 'register_options_page' ) );
add_filter( 'powerkit_ajax_reset_cache', array( $this, 'register_reset_cache' ) );
}
/**
* Register Reset Cache
*
* @since 1.0.0
* @param array $list Change list reset cache.
* @access private
*/
public function register_reset_cache( $list ) {
$slug = powerkit_get_page_slug( $this->slug );
$list[ $slug ] = array(
'powerkit_share_buttons_transient',
);
return $list;
}
/**
* Register options default
*
* @since 1.0.0
*/
public function register_options_default() {
// Save options default [locations].
$locations = apply_filters( 'powerkit_share_buttons_locations', array() );
if ( $locations ) {
foreach ( $locations as $key => $item ) {
$location = $item['location'];
add_filter(
"default_option_powerkit_share_buttons_{$location}_display", function ( $default ) use ( $item ) {
return isset( $item['display'] ) ? $item['display'] : $default;
}
);
add_filter(
"default_option_powerkit_share_buttons_{$location}_multiple_list", function ( $default ) use ( $item ) {
return isset( $item['shares'] ) ? (array) $item['shares'] : $default;
}
);
add_filter(
"default_option_powerkit_share_buttons_{$location}_order_multiple_list", function ( $default ) use ( $item ) {
return isset( $item['shares'] ) ? (array) $item['shares'] : $default;
}
);
add_filter(
"default_option_powerkit_share_buttons_{$location}_display_labels", function ( $default ) use ( $item ) {
return isset( $item['meta']['labels'] ) ? $item['meta']['labels'] : true;
}
);
add_filter(
"default_option_powerkit_share_buttons_{$location}_display_total_share_count", function ( $default ) use ( $item ) {
return isset( $item['display_total'] ) ? $item['display_total'] : true;
}
);
add_filter(
"default_option_powerkit_share_buttons_{$location}_display_count", function ( $default ) use ( $item ) {
return isset( $item['display_count'] ) ? $item['display_count'] : true;
}
);
add_filter(
"default_option_powerkit_share_buttons_{$location}_title_location", function ( $default ) use ( $item ) {
return isset( $item['title_location'] ) ? $item['title_location'] : $default;
}
);
add_filter(
"default_option_powerkit_share_buttons_{$location}_label_location", function ( $default ) use ( $item ) {
return isset( $item['label_location'] ) ? $item['label_location'] : $default;
}
);
add_filter(
"default_option_powerkit_share_buttons_{$location}_count_location", function ( $default ) use ( $item ) {
return isset( $item['count_location'] ) ? $item['count_location'] : $default;
}
);
add_filter(
"default_option_powerkit_share_buttons_{$location}_layout", function ( $default ) use ( $item ) {
return isset( $item['layout'] ) ? $item['layout'] : $default;
}
);
add_filter(
"default_option_powerkit_share_buttons_{$location}_scheme", function ( $default ) use ( $item ) {
return isset( $item['scheme'] ) ? $item['scheme'] : $default;
}
);
}
}
}
/**
* Register admin page
*
* @since 1.0.0
*/
public function register_options_page() {
add_options_page( esc_html__( 'Share Buttons', 'powerkit' ), esc_html__( 'Share Buttons', 'powerkit' ), 'manage_options', powerkit_get_page_slug( $this->slug ), array( $this, 'build_options_page' ) );
}
/**
* Build admin page
*
* @since 1.0.0
*/
public function build_options_page() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You do not have sufficient rights to view this page.', 'powerkit' ) );
}
$this->save_options_page();
?>
<div class="wrap pk-share-buttons-wrap">
<h1><?php esc_html_e( 'Share Buttons', 'powerkit' ); ?></h1>
<div class="pk-share-buttons-settings">
<?php $locations = apply_filters( 'powerkit_share_buttons_locations', array() ); ?>
<?php if ( $locations ) : ?>
<form class="pk-share-buttons-basic" method="post">
<div class="pk-share-buttons-tabs">
<?php
$locations = array_values( $locations );
$tab = sanitize_title( isset( $_GET['tab'] ) ? $_GET['tab'] : $locations[0]['location'] ); // Input var ok; sanitization ok.
?>
<nav class="nav-tab-wrapper woo-nav-tab-wrapper">
<?php
foreach ( $locations as $item ) {
$class = ( $item['location'] === $tab ) ? 'nav-tab-active' : ''; // Input var ok.
printf(
'<a class="nav-tab %4$s" href="%1$s&tab=%2$s">%3$s</a>',
esc_url( powerkit_get_page_url( $this->slug ) ), esc_attr( $item['location'] ), esc_html( $item['name'] ), esc_attr( $class )
);
}
?>
<a class="nav-tab nav-tab-advanced <?php echo esc_attr( 'advanced-settings' === $tab ? 'nav-tab-active' : '' ); ?>"
href="<?php echo esc_url( powerkit_get_page_url( $this->slug ) ); ?>&tab=<?php echo esc_attr( 'advanced-settings' ); ?>">
<?php esc_html_e( 'Advanced Settings', 'powerkit' ); ?>
</a>
</nav>
<?php
foreach ( $locations as $item ) {
if ( $item['location'] === $tab ) { // Input var ok.
$location = $item['location'];
?>
<div id="tab-<?php echo esc_attr( $location ); ?>" class="tab-wrap">
<table class="form-table">
<tbody>
<!-- Display Share Buttons -->
<tr class="visible">
<th scope="row"><label for="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display"><?php esc_html_e( 'Display Share Buttons', 'powerkit' ); ?></label></th>
<td><input class="powerkit_share_buttons_display" id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display" type="checkbox" value="true" <?php checked( (bool) get_option( "powerkit_share_buttons_{$location}_display", false ) ); ?>></td>
</tr>
<!-- Share Buttons -->
<tr>
<th scope="row"><?php esc_html_e( 'Share Buttons', 'powerkit' ); ?></label></th>
<td>
<div class="pk-share-buttons-source">
<?php
$accounts = powerkit_share_buttons_get_accounts();
if ( $accounts ) {
foreach ( $accounts as $key => $account ) {
// Check support accounts for extra locations.
if ( 'highlight-text' === $location || 'blockquote' === $location ) {
$list = powerkit_share_buttons_support_text_accounts();
if ( ! in_array( $key, $list, true ) ) {
continue;
}
}
$powerkit_share_buttons_multiple_list = get_option( "powerkit_share_buttons_{$location}_multiple_list", array() );
$checked = in_array( $key, $powerkit_share_buttons_multiple_list, true ) ? 'checked' : '';
?>
<p class="share-item">
<label for="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_multiple_list_<?php echo esc_attr( $key ); ?>"><input class="powerkit_share_buttons_multiple_list" data-item="<?php echo esc_attr( $key ); ?>" id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_multiple_list_<?php echo esc_attr( $key ); ?>" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_multiple_list[]" type="checkbox" value="<?php echo esc_attr( $key ); ?>" <?php echo esc_attr( $checked ); ?>> <?php echo esc_attr( $account['name'] ); ?></label>
<?php if ( in_array( $key, array( 'whatsapp', 'fb-messenger' ), true ) ) : ?>
<code class="description"><?php esc_html_e( '[mobile only]', 'powerkit' ); ?></code>
<?php endif; ?>
</p>
<?php
}
}
?>
</div>
</td>
</tr>
<!-- Order -->
<tr>
<th scope="row"><label for="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_order_multiple_list"><?php esc_html_e( 'Order', 'powerkit' ); ?></label></th>
<td>
<ul class="social-sortable">
<?php
$accounts_save = get_option( "powerkit_share_buttons_{$location}_order_multiple_list", array() );
$accounts = powerkit_share_buttons_get_accounts();
// Sort.
if ( $accounts_save && $accounts ) {
$accounts_save = array_flip( $accounts_save );
$accounts = array_merge( $accounts_save, $accounts );
}
// Output.
if ( $accounts ) {
foreach ( $accounts as $key => $account ) {
// Check support accounts for extra locations.
if ( 'highlight-text' === $location || 'blockquote' === $location ) {
$list = powerkit_share_buttons_support_text_accounts();
if ( ! in_array( $key, $list, true ) ) {
continue;
}
}
?>
<li class="ui-state-default <?php echo esc_attr( $key ); ?>">
<span class="dashicons dashicons-leftright"></span>
<input type="text" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_order_multiple_list[]" value="<?php echo esc_attr( $key ); ?>"><?php echo esc_attr( $account['name'] ); ?>
</li>
<?php
}
}
?>
</ul>
</td>
</tr>
<!-- Display Labels -->
<?php if ( isset( $item['meta']['labels'] ) ? $item['meta']['labels'] : true ) : ?>
<tr>
<th scope="row"><label for="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display_labels"><?php esc_html_e( 'Display Labels', 'powerkit' ); ?></label></th>
<td><input id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display_labels" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display_labels" type="checkbox" value="true" <?php checked( (bool) get_option( "powerkit_share_buttons_{$location}_display_labels", true ) ); ?>></td>
</tr>
<?php endif; ?>
<!-- Display Total Share Count -->
<?php if ( isset( $item['fields']['display_total'] ) && $item['fields']['display_total'] ) : ?>
<tr>
<th scope="row"><label for="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display_total_share_count"><?php esc_html_e( 'Display Total Share Count', 'powerkit' ); ?></label></th>
<td><input id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display_total_share_count" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display_total_share_count" type="checkbox" value="true" <?php checked( (bool) get_option( "powerkit_share_buttons_{$location}_display_total_share_count", false ) ); ?>></td>
</tr>
<?php endif; ?>
<!-- Display Counts -->
<?php if ( isset( $item['fields']['display_count'] ) && $item['fields']['display_count'] ) : ?>
<tr>
<th scope="row"><label for="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display_count"><?php esc_html_e( 'Display Counts', 'powerkit' ); ?></label></th>
<td><input id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display_count" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_display_count" type="checkbox" value="true" <?php checked( (bool) get_option( "powerkit_share_buttons_{$location}_display_count", false ) ); ?>></td>
</tr>
<?php endif; ?>
<!-- Title Location -->
<?php
if ( isset( $item['meta']['titles'] ) ? $item['meta']['titles'] : false ) {
$title_location = isset( $item['fields']['title_locations'] ) ? (array) $item['fields']['title_locations'] : array( 'inside', 'outside' );
if ( in_array( 'inside', $title_location, true ) && in_array( 'outside', $title_location, true ) ) {
?>
<tr>
<th scope="row"><?php esc_html_e( 'Title Location', 'powerkit' ); ?></th>
<td>
<label>
<input type="radio" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_title_location" id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_title_location" value="inside" <?php checked( get_option( "powerkit_share_buttons_{$location}_title_location", 'inside' ), 'inside' ); ?>>
<?php esc_html_e( 'Inside', 'powerkit' ); ?>&nbsp;
</label>
<label>
<input type="radio" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_title_location" id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_title_location" value="outside" <?php checked( get_option( "powerkit_share_buttons_{$location}_title_location", 'inside' ), 'outside' ); ?>>
<?php esc_html_e( 'Outside', 'powerkit' ); ?>&nbsp;
</label>
</td>
</tr>
<?php
}
}
?>
<!-- Label Location -->
<?php
if ( isset( $item['meta']['labels'] ) ? $item['meta']['labels'] : true ) {
$label_location = isset( $item['fields']['label_locations'] ) ? (array) $item['fields']['label_locations'] : array( 'inside', 'outside' );
if ( in_array( 'inside', $label_location, true ) && in_array( 'outside', $label_location, true ) ) {
?>
<tr>
<th scope="row"><?php esc_html_e( 'Label Location', 'powerkit' ); ?></th>
<td>
<label>
<input type="radio" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_label_location" id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_label_location" value="inside" <?php checked( get_option( "powerkit_share_buttons_{$location}_label_location", 'inside' ), 'inside' ); ?>>
<?php esc_html_e( 'Inside', 'powerkit' ); ?>&nbsp;
</label>
<label>
<input type="radio" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_label_location" id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_label_location" value="outside" <?php checked( get_option( "powerkit_share_buttons_{$location}_label_location", 'inside' ), 'outside' ); ?>>
<?php esc_html_e( 'Outside', 'powerkit' ); ?>&nbsp;
</label>
</td>
</tr>
<?php
}
}
?>
<!-- Count Location -->
<?php
$count_location = isset( $item['fields']['count_locations'] ) ? (array) $item['fields']['count_locations'] : array( 'inside', 'outside' );
if ( in_array( 'inside', $count_location, true ) && in_array( 'outside', $count_location, true ) ) {
?>
<tr>
<th scope="row"><?php esc_html_e( 'Count Location', 'powerkit' ); ?></th>
<td>
<label>
<input type="radio" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_count_location" id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_count_location" value="inside" <?php checked( get_option( "powerkit_share_buttons_{$location}_count_location", 'inside' ), 'inside' ); ?>>
<?php esc_html_e( 'Inside', 'powerkit' ); ?>&nbsp;
</label>
<label>
<input type="radio" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_count_location" id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_count_location" value="outside" <?php checked( get_option( "powerkit_share_buttons_{$location}_count_location", 'inside' ), 'outside' ); ?>>
<?php esc_html_e( 'Outside', 'powerkit' ); ?>&nbsp;
</label>
</td>
</tr>
<?php } ?>
<!-- Layout -->
<?php
$layouts = powerkit_share_buttons_format_layouts( $item, $location );
if ( count( (array) $layouts ) > 1 ) {
?>
<tr>
<th scope="row"><label for="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_layout"><?php esc_html_e( 'Layout', 'powerkit' ); ?></label></th>
<td>
<select class="regular-text" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_layout" id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_layout">
<?php
if ( $layouts ) {
foreach ( $layouts as $key => $i ) {
?>
<option value="<?php echo esc_attr( $key ); ?>" <?php selected( get_option( "powerkit_share_buttons_{$location}_layout" ), $key ); ?>><?php echo esc_attr( $i['name'] ); ?></option>
<?php
}
}
?>
</select>
</td>
</tr>
<?php } ?>
<!-- Color Scheme -->
<?php
$schemes = powerkit_share_buttons_format_color_schemes( $item );
if ( count( (array) $schemes ) > 1 ) {
?>
<tr>
<th scope="row"><label for="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_scheme"><?php esc_html_e( 'Color Scheme', 'powerkit' ); ?></label></th>
<td>
<select class="regular-text" name="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_scheme" id="powerkit_share_buttons_<?php echo esc_attr( $location ); ?>_scheme">
<?php
if ( $schemes ) {
foreach ( $schemes as $key => $i ) {
?>
<option value="<?php echo esc_attr( $key ); ?>" <?php selected( get_option( "powerkit_share_buttons_{$location}_scheme" ), $key ); ?>><?php echo esc_attr( $i['name'] ); ?></option>
<?php
}
}
?>
</select>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<input type="hidden" name="<?php echo esc_attr( "powerkit_share_buttons_action_{$location}" ); ?>" value="true">
</div>
<?php
}
}
?>
<?php if ( 'advanced-settings' === $tab ) { ?>
<div id="tab-advanced-settings" class="tab-wrap">
<input type="hidden" name="advanced_settings" value="1">
<!-- Share Labels -->
<h3><?php esc_html_e( 'Share Labels', 'powerkit' ); ?></h3>
<table class="form-table">
<tbody>
<?php
$accounts = apply_filters( 'powerkit_share_buttons_accounts', array(), null, null );
foreach ( $accounts as $key => $account ) {
?>
<tr class="visible simple">
<th scope="row">
<label for="powerkit_share_buttons_label_<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $account['name'] ); ?></label>
</th>
<td>
<input class="regular-text" id="powerkit_share_buttons_label_<?php echo esc_attr( $key ); ?>" name="powerkit_share_buttons_label_<?php echo esc_attr( $key ); ?>" type="text" value="<?php echo esc_attr( get_option( "powerkit_share_buttons_label_{$key}", $account['label'] ) ); ?>">
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<hr>
<!-- Recover social counts -->
<h3><?php esc_html_e( 'Recover social counts', 'powerkit' ); ?></h3>
<p class="description"><?php esc_html_e( 'If enabled, the total share count will be displayed for both http and https versions of a page', 'powerkit' ); ?></p>
<table class="form-table">
<tbody>
<tr class="visible">
<th scope="row">
<label for="powerkit_share_buttons_recover"><?php esc_html_e( 'Enable recover counts', 'powerkit' ); ?></label>
</th>
<td><input class="powerkit_share_buttons_recover" id="powerkit_share_buttons_recover" name="powerkit_share_buttons_recover" type="checkbox" value="true" <?php checked( (bool) get_option( 'powerkit_share_buttons_recover', false ) ); ?>></td>
</tr>
</tbody>
</table>
<hr>
<!-- Bitly Link Shortening -->
<h3><?php esc_html_e( 'Bitly Link Shortening', 'powerkit' ); ?></h3>
<p class="description"><?php esc_html_e( 'If you like to have all of your links automatically shortened, enter your Access Token from bitly.com', 'powerkit' ); ?></p>
<div class="form-field">
<h4><?php esc_html_e( 'Instructions', 'powerkit' ); ?></h4>
<ol>
<li><?php esc_html_e( 'Log in to your', 'powerkit' ); ?> <?php echo sprintf( '<a href="%1$s" target="_blank">%2$s</a>', esc_url( 'https://bitly.com/' ), esc_html__( 'Bitly account', 'powerkit' ) ); ?></li>
<li><?php esc_html_e( 'Go to Settings → Advanced Settings → FOR DEVELOPERS OAuth → Generic Access Token', 'powerkit' ); ?></li>
<li><?php esc_html_e( 'Generate your Token', 'powerkit' ); ?></li>
<li><?php esc_html_e( 'Copy your "Token"', 'powerkit' ); ?></li>
</ol>
</div>
<table class="form-table">
<tbody>
<tr class="visible">
<th scope="row">
<label for="powerkit_share_buttons_bitly_api_token"><?php esc_html_e( 'Bitly API Token', 'powerkit' ); ?></label>
</th>
<td><input id="powerkit_share_buttons_bitly_api_token" class="regular-text" name="powerkit_share_buttons_bitly_api_token" type="text" value="<?php echo esc_attr( get_option( 'powerkit_share_buttons_bitly_api_token' ) ); ?>"></td>
</tr>
</tbody>
</table>
</div>
<?php } ?>
</div>
<?php wp_nonce_field(); ?>
<p class="submit">
<input class="button button-primary" name="save_settings" type="submit" value="<?php esc_html_e( 'Save changes', 'powerkit' ); ?>" />
</p>
</form>
<?php else : ?>
<p class="submit">
<?php esc_html_e( 'No available locations found.', 'powerkit' ); ?>
</p>
<?php endif; ?>
</div>
</div>
<?php
}
/**
* Settings save
*
* @since 1.0.0
*/
protected function save_options_page() {
if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'] ) ) { // Input var ok; sanitization ok.
return;
}
if ( isset( $_POST['save_settings'] ) ) { // Input var ok.
// Save social buttons [locations].
$locations = apply_filters( 'powerkit_share_buttons_locations', array() );
if ( $locations ) {
foreach ( $locations as $key => $item ) {
$location = $item['location'];
if ( ! isset( $_POST[ "powerkit_share_buttons_action_{$location}" ] ) ) { // Input var ok.
continue;
}
if ( isset( $_POST[ "powerkit_share_buttons_{$location}_display" ] ) ) { // Input var ok.
update_option( "powerkit_share_buttons_{$location}_display", true );
} else {
update_option( "powerkit_share_buttons_{$location}_display", false );
}
if ( isset( $_POST[ "powerkit_share_buttons_{$location}_multiple_list" ] ) ) { // Input var ok.
update_option( "powerkit_share_buttons_{$location}_multiple_list", array_map( 'sanitize_key', (array) $_POST[ "powerkit_share_buttons_{$location}_multiple_list" ] ) ); // Input var ok; sanitization ok.
} else {
update_option( "powerkit_share_buttons_{$location}_multiple_list", array() );
}
if ( isset( $_POST[ "powerkit_share_buttons_{$location}_order_multiple_list" ] ) ) { // Input var ok.
update_option( "powerkit_share_buttons_{$location}_order_multiple_list", array_map( 'sanitize_key', (array) $_POST[ "powerkit_share_buttons_{$location}_order_multiple_list" ] ) ); // Input var ok; sanitization ok.
} else {
update_option( "powerkit_share_buttons_{$location}_order_multiple_list", array() );
}
if ( isset( $_POST[ "powerkit_share_buttons_{$location}_title_location" ] ) ) { // Input var ok.
update_option( "powerkit_share_buttons_{$location}_title_location", sanitize_text_field( wp_unslash( $_POST[ "powerkit_share_buttons_{$location}_title_location" ] ) ) ); // Input var ok.
}
if ( isset( $_POST[ "powerkit_share_buttons_{$location}_label_location" ] ) ) { // Input var ok.
update_option( "powerkit_share_buttons_{$location}_label_location", sanitize_text_field( wp_unslash( $_POST[ "powerkit_share_buttons_{$location}_label_location" ] ) ) ); // Input var ok.
}
if ( isset( $_POST[ "powerkit_share_buttons_{$location}_count_location" ] ) ) { // Input var ok.
update_option( "powerkit_share_buttons_{$location}_count_location", sanitize_text_field( wp_unslash( $_POST[ "powerkit_share_buttons_{$location}_count_location" ] ) ) ); // Input var ok.
}
if ( isset( $_POST[ "powerkit_share_buttons_{$location}_layout" ] ) ) { // Input var ok.
update_option( "powerkit_share_buttons_{$location}_layout", sanitize_text_field( wp_unslash( $_POST[ "powerkit_share_buttons_{$location}_layout" ] ) ) ); // Input var ok.
}
if ( isset( $_POST[ "powerkit_share_buttons_{$location}_scheme" ] ) ) { // Input var ok.
update_option( "powerkit_share_buttons_{$location}_scheme", sanitize_text_field( wp_unslash( $_POST[ "powerkit_share_buttons_{$location}_scheme" ] ) ) ); // Input var ok.
}
if ( isset( $item['meta']['labels'] ) ? $item['meta']['labels'] : true ) {
if ( isset( $_POST[ "powerkit_share_buttons_{$location}_display_labels" ] ) ) { // Input var ok.
update_option( "powerkit_share_buttons_{$location}_display_labels", true );
} else {
update_option( "powerkit_share_buttons_{$location}_display_labels", false );
}
}
if ( isset( $item['fields']['display_total'] ) && $item['fields']['display_total'] ) {
if ( isset( $_POST[ "powerkit_share_buttons_{$location}_display_total_share_count" ] ) ) { // Input var ok.
update_option( "powerkit_share_buttons_{$location}_display_total_share_count", true );
} else {
update_option( "powerkit_share_buttons_{$location}_display_total_share_count", false );
}
}
if ( isset( $item['fields']['display_count'] ) && $item['fields']['display_count'] ) {
if ( isset( $_POST[ "powerkit_share_buttons_{$location}_display_count" ] ) ) { // Input var ok.
update_option( "powerkit_share_buttons_{$location}_display_count", true );
} else {
update_option( "powerkit_share_buttons_{$location}_display_count", false );
}
}
}
}
// Advanced Settings.
if ( isset( $_POST['advanced_settings'] ) ) { // Input var ok.
$accounts = apply_filters( 'powerkit_share_buttons_accounts', array(), null, null );
foreach ( $accounts as $key => $account ) {
if ( isset( $_POST[ "powerkit_share_buttons_label_{$key}" ] ) ) { // Input var ok.
update_option( "powerkit_share_buttons_label_{$key}", sanitize_text_field( wp_unslash( $_POST[ "powerkit_share_buttons_label_{$key}" ] ) ) ); // Input var ok.
}
}
if ( isset( $_POST['powerkit_share_buttons_recover'] ) ) { // Input var ok.
update_option( 'powerkit_share_buttons_recover', true );
} else {
update_option( 'powerkit_share_buttons_recover', false );
}
if ( isset( $_POST['powerkit_share_buttons_bitly_api_token'] ) ) { // Input var ok.
update_option( 'powerkit_share_buttons_bitly_api_token', sanitize_text_field( wp_unslash( $_POST['powerkit_share_buttons_bitly_api_token'] ) ) ); // Input var ok.
}
}
// Reset cache.
Powerkit_Connect::reset_cache(
array(
'powerkit_share_buttons_count',
'powerkit_share_buttons_transient',
)
);
printf( '<div id="message" class="updated fade"><p><strong>%s</strong></p></div>', esc_html__( 'Settings saved.', 'powerkit' ) );
}
}
/**
* Register the stylesheets and JavaScript for the admin area.
*
* @param string $page Current page.
*/
public function admin_enqueue_scripts( $page ) {
if ( 'settings_page_' . powerkit_get_page_slug( $this->slug ) === $page ) {
wp_enqueue_script( 'jquery-ui-sortable' );
// Styles.
wp_enqueue_style( 'powerkit-share-buttons', powerkit_style( plugin_dir_url( __FILE__ ) . 'css/admin-powerkit-share-buttons.css' ), array(), powerkit_get_setting( 'version' ), 'all' );
// Scripts.
wp_enqueue_script( 'powerkit-share-buttons', plugin_dir_url( __FILE__ ) . 'js/admin-powerkit-share-buttons.js', array( 'jquery' ), powerkit_get_setting( 'version' ), false );
}
}
}
@@ -0,0 +1,87 @@
.nav-tab-advanced {
float: left;
}
.nav-tab-advanced:not(.nav-tab-active) {
background: #FFFFFF;
}
.pk-share-buttons-wrap .form-table + hr {
margin: 2rem 0;
}
.pk-share-buttons-wrap .form-table tr {
display: none;
}
.pk-share-buttons-wrap .form-table tr.visible {
display: table-row;
}
.pk-share-buttons-wrap .form-table tr.simple th, .pk-share-buttons-wrap .form-table tr.simple td {
padding: 10px 0 0;
}
.pk-share-buttons-wrap .social-sortable {
display: flex;
flex-wrap: wrap;
list-style-type: none;
margin: 0;
padding: 0;
width: 100%;
}
.pk-share-buttons-wrap .social-sortable li {
position: relative;
border: 1px solid #CCCCCC;
background: #E5E5E5;
display: none;
border: none;
margin: 0 3px 5px 3px;
padding: 8px 18px;
font-size: 14px;
line-height: 1.2em;
min-width: 200px;
height: 18px;
cursor: pointer;
}
.pk-share-buttons-wrap .social-sortable li.ui-state-highlight {
display: block;
border: 1px dashed #CCCCCC;
background: #E5E5E5;
padding: 8px 18px;
line-height: 1.2em;
height: 18px;
}
.pk-share-buttons-wrap .social-sortable li span {
position: absolute;
top: 10px;
left: 15px;
font-size: 14px;
}
.pk-share-buttons-wrap .social-sortable li input {
display: none;
}
.pk-share-buttons-wrap .social-sortable li:hover {
opacity: 0.6;
}
.pk-share-buttons-source {
width: 100%;
}
.pk-share-buttons-source .share-item {
display: inline-block;
width: 100%;
max-width: 300px;
}
.pk-share-buttons-source:after {
display: table;
clear: both;
content: '';
}
@@ -0,0 +1,87 @@
.nav-tab-advanced {
float: right;
}
.nav-tab-advanced:not(.nav-tab-active) {
background: #FFFFFF;
}
.pk-share-buttons-wrap .form-table + hr {
margin: 2rem 0;
}
.pk-share-buttons-wrap .form-table tr {
display: none;
}
.pk-share-buttons-wrap .form-table tr.visible {
display: table-row;
}
.pk-share-buttons-wrap .form-table tr.simple th, .pk-share-buttons-wrap .form-table tr.simple td {
padding: 10px 0 0;
}
.pk-share-buttons-wrap .social-sortable {
display: flex;
flex-wrap: wrap;
list-style-type: none;
margin: 0;
padding: 0;
width: 100%;
}
.pk-share-buttons-wrap .social-sortable li {
position: relative;
border: 1px solid #CCCCCC;
background: #E5E5E5;
display: none;
border: none;
margin: 0 3px 5px 3px;
padding: 8px 18px;
font-size: 14px;
line-height: 1.2em;
min-width: 200px;
height: 18px;
cursor: pointer;
}
.pk-share-buttons-wrap .social-sortable li.ui-state-highlight {
display: block;
border: 1px dashed #CCCCCC;
background: #E5E5E5;
padding: 8px 18px;
line-height: 1.2em;
height: 18px;
}
.pk-share-buttons-wrap .social-sortable li span {
position: absolute;
top: 10px;
right: 15px;
font-size: 14px;
}
.pk-share-buttons-wrap .social-sortable li input {
display: none;
}
.pk-share-buttons-wrap .social-sortable li:hover {
opacity: 0.6;
}
.pk-share-buttons-source {
width: 100%;
}
.pk-share-buttons-source .share-item {
display: inline-block;
width: 100%;
max-width: 300px;
}
.pk-share-buttons-source:after {
display: table;
clear: both;
content: '';
}
@@ -0,0 +1,63 @@
"use strict";
( function( $ ) {
/*
* Share Buttons
*/
$( function() {
/*
* jQuery Sortable UI
*/
$( '.pk-share-buttons-wrap .social-sortable' ).sortable( {
placeholder: 'ui-state-highlight',
} );
$( '.pk-share-buttons-wrap .social-sortable' ).disableSelection();
/*
* Check display fields
*/
function powerkitButtonsCheckDisplayFields() {
$( '.pk-share-buttons-wrap .powerkit_share_buttons_display' ).each( function( index, el ) {
if ( $( el ).prop( 'checked' ) ) {
$( el ).parents( '.form-table' ).find( 'tr' ).show();
} else {
$( el ).parents( '.form-table' ).find( 'tr' ).not( $( el ).parents( 'tr' ) ).hide();
}
} );
$( '.pk-share-buttons-wrap .powerkit_share_buttons_multiple_list' ).each( function( index, el ) {
var item = $( el ).attr( 'data-item' );
if ( !$( el ).prop( 'checked' ) ) {
$( '.pk-share-buttons-wrap .social-sortable .ui-state-default.' + item ).hide();
} else {
$( '.pk-share-buttons-wrap .social-sortable .ui-state-default.' + item ).show();
}
} );
}
/*
* Cick display buttons
*/
$( '.pk-share-buttons-wrap .powerkit_share_buttons_display' ).on( 'click', function( event ) {
powerkitButtonsCheckDisplayFields();
} );
/*
* Cick display social
*/
$( '.pk-share-buttons-wrap .powerkit_share_buttons_multiple_list' ).on( 'click', function( event ) {
powerkitButtonsCheckDisplayFields();
} );
/*
* INIT
*/
powerkitButtonsCheckDisplayFields();
} );
} )( jQuery );
@@ -0,0 +1,73 @@
<?php
/**
* Share Buttons
*
* @package Powerkit
* @subpackage Modules
*/
if ( class_exists( 'Powerkit_Module' ) ) {
/**
* Init module
*/
class Powerkit_Share_Buttons extends Powerkit_Module {
/**
* Register module
*/
public function register() {
$this->name = esc_html__( 'Share Buttons', 'powerkit' );
$this->desc = esc_html__( 'Display share buttons in theme-predefined or standard locations. Select from various social networks and add per-button and the total share counts with just a few clicks.', 'powerkit' );
$this->slug = 'share_buttons';
$this->type = 'default';
$this->category = 'social';
$this->priority = 10;
$this->public = true;
$this->enabled = true;
$this->links = array(
array(
'name' => esc_html__( 'Go to settings', 'powerkit' ),
'url' => powerkit_get_page_url( $this->slug ),
),
array(
'name' => esc_html__( 'Clear cache', 'powerkit' ),
'url' => powerkit_get_page_url( $this->slug . '&action=powerkit_reset_cache' ),
),
array(
'name' => esc_html__( 'View documentation', 'powerkit' ),
'url' => powerkit_get_setting( 'documentation' ) . '/social-integrations/share-buttons/',
'target' => '_blank',
),
);
}
/**
* Initialize module
*/
public function initialize() {
/* Load the required dependencies for this module */
// Helpers Functions for the module.
require_once dirname( __FILE__ ) . '/helpers/helper-powerkit-buttons.php';
require_once dirname( __FILE__ ) . '/helpers/helper-powerkit-buttons-list.php';
require_once dirname( __FILE__ ) . '/helpers/helper-powerkit-buttons-api.php';
// The classes responsible for defining all actions.
require_once dirname( __FILE__ ) . '/public/class-powerkit-share-buttons-shortcode.php';
if ( function_exists( 'register_block_type' ) ) {
require_once dirname( __FILE__ ) . '/public/class-powerkit-share-buttons-block.php';
}
// Admin and public area.
require_once dirname( __FILE__ ) . '/admin/class-powerkit-share-buttons-admin.php';
require_once dirname( __FILE__ ) . '/public/class-powerkit-share-buttons-public.php';
new Powerkit_Share_Buttons_Admin( $this->slug );
new Powerkit_Share_Buttons_Public( $this->slug );
}
}
new Powerkit_Share_Buttons();
}
@@ -0,0 +1,273 @@
<?php
/**
* Get Share Buttons Counter
*
* @package Powerkit
* @subpackage Modules/Helper
*/
/**
* Add Facebook Counter.
*
* @param array $account Account name.
* @param int|string $post_id Post ID.
* @param string $url Custom URL.
* @param bool $suffix Unique suffix.
*/
function powerkit_share_buttons_facebook_counter( $account, $post_id, $url = null, $suffix = false ) {
// Get Post ID.
$post_id = $post_id ? $post_id : powerkit_share_buttons_get_current_post_id( $url );
// Get Chache.
$count = powerkit_share_buttons_get_cached_account( $account, $post_id, $url, false, $suffix );
if ( false !== $count ) {
return intval( $count );
}
$remote_url = add_query_arg( array(
'access_token' => powerkit_connect( 'facebook_share_access_token' ),
'id' => $url,
'fields' => 'engagement',
), 'https://graph.facebook.com/' );
// Get Counter.
$response = wp_remote_get( esc_url( $remote_url, null, '' ), array(
'timeout' => 3,
) );
$response = wp_remote_retrieve_body( $response );
// Create Counter.
$response_result = json_decode( $response, true );
if ( isset( $response_result['engagement']['share_count'] ) ) {
$count = $response_result['engagement']['share_count'];
} else {
$count = powerkit_share_buttons_get_cached_account( $account, $post_id, $url, true, $suffix );
}
// Set Cache.
powerkit_share_buttons_set_cache_account( $account, $post_id, intval( $count ), $url, $suffix );
// Return Result.
return $count;
}
/**
* Add Xing Counter.
*
* @param array $account Account name.
* @param int|string $post_id Post ID.
* @param string $url Custom URL.
* @param bool $suffix Unique suffix.
*/
function powerkit_share_buttons_xing_counter( $account, $post_id, $url = null, $suffix = false ) {
// Get Post ID.
$post_id = $post_id ? $post_id : powerkit_share_buttons_get_current_post_id( $url );
// Get Chache.
$count = powerkit_share_buttons_get_cached_account( $account, $post_id, $url, false, $suffix );
if ( false !== $count ) {
return intval( $count );
}
// Get Count.
$endpoint = esc_url( 'https://www.xing-share.com/app/share?op=get_share_button;counter=top;url=' . $url, null, '' );
$response = wp_remote_get( $endpoint, array(
'timeout' => 3,
) );
$response = wp_remote_retrieve_body( $response );
// Set Count.
preg_match( '/<span class="xing-count[^"]*?">(\d+)<\/span>/si', $response, $response_result );
if ( isset( $response_result[1] ) ) {
$count = $response_result[1];
} else {
$count = powerkit_share_buttons_get_cached_account( $account, $post_id, $url, true, $suffix );
}
// Set Cache.
powerkit_share_buttons_set_cache_account( $account, $post_id, intval( $count ), $url, $suffix );
// Return Result.
return $count;
}
/**
* Add LinkedIn Counter.
*
* @param array $account Account name.
* @param int|string $post_id Post ID.
* @param string $url Custom URL.
* @param bool $suffix Unique suffix.
*/
function powerkit_share_buttons_linkedin_counter( $account, $post_id, $url = null, $suffix = false ) {
// Get Post ID.
$post_id = $post_id ? $post_id : powerkit_share_buttons_get_current_post_id( $url );
// Get Chache.
$count = powerkit_share_buttons_get_cached_account( $account, $post_id, $url, false, $suffix );
if ( false !== $count ) {
return intval( $count );
}
// Get Count.
$endpoint = esc_url( 'https://www.linkedin.com/countserv/count/share?format=json&url=' . $url, null, '' );
$response = wp_remote_get( $endpoint, array(
'timeout' => 3,
) );
$response = wp_remote_retrieve_body( $response );
// Set Count.
$response_result = json_decode( $response, true );
if ( isset( $response_result['count'] ) ) {
$count = $response_result['count'];
} else {
$count = powerkit_share_buttons_get_cached_account( $account, $post_id, $url, true, $suffix );
}
// Set Cache.
powerkit_share_buttons_set_cache_account( $account, $post_id, intval( $count ), $url, $suffix );
// Return Result.
return $count;
}
/**
* Add Pinterest Counter.
*
* @param array $account Account name.
* @param int|string $post_id Post ID.
* @param string $url Custom URL.
* @param bool $suffix Unique suffix.
*/
function powerkit_share_buttons_pinterest_counter( $account, $post_id, $url = null, $suffix = false ) {
// Get Post ID.
$post_id = $post_id ? $post_id : powerkit_share_buttons_get_current_post_id( $url );
// Get Chache.
$count = powerkit_share_buttons_get_cached_account( $account, $post_id, $url, false, $suffix );
if ( false !== $count ) {
return intval( $count );
}
// Get Count.
$endpoint = esc_url( 'https://widgets.pinterest.com/v1/urls/count.json?callback=jsonp&url=' . $url, null, '' );
$response = wp_remote_get( $endpoint, array(
'timeout' => 3,
) );
$response = wp_remote_retrieve_body( $response );
// Set Count.
$response_body = str_replace( array( 'jsonp(', ')' ), '', $response );
$response_result = json_decode( $response_body, true );
if ( isset( $response_result['count'] ) ) {
$count = $response_result['count'];
} else {
$count = powerkit_share_buttons_get_cached_account( $account, $post_id, $url, true, $suffix );
}
// Set Cache.
powerkit_share_buttons_set_cache_account( $account, $post_id, intval( $count ), $url, $suffix );
// Return Result.
return $count;
}
/**
* Add Odnoklassniki Counter.
*
* @param array $account Account name.
* @param int|string $post_id Post ID.
* @param string $url Custom URL.
* @param bool $suffix Unique suffix.
*/
function powerkit_share_buttons_ok_counter( $account, $post_id, $url = null, $suffix = false ) {
// Get Post ID.
$post_id = $post_id ? $post_id : powerkit_share_buttons_get_current_post_id( $url );
// Get Chache.
$count = powerkit_share_buttons_get_cached_account( $account, $post_id, $url, false, $suffix );
if ( false !== $count ) {
return intval( $count );
}
// Get Count.
$endpoint = esc_url( 'https://connect.ok.ru/dk?st.cmd=extLike&ref=' . $url, null, '' );
$response = wp_remote_get( $endpoint, array(
'timeout' => 3,
) );
$response = wp_remote_retrieve_body( $response );
// Set Count.
preg_match( "/'null','(\d*?)'/s", $response, $result );
if ( isset( $result[1] ) ) {
$count = $result[1];
} else {
$count = powerkit_share_buttons_get_cached_account( $account, $post_id, $url, true, $suffix );
}
// Set Cache.
powerkit_share_buttons_set_cache_account( $account, $post_id, intval( $count ), $url, $suffix );
// Return Result.
return $count;
}
/**
* Add Vkontakte Counter.
*
* @param array $account Account name.
* @param int|string $post_id Post ID.
* @param string $url Custom URL.
* @param bool $suffix Unique suffix.
*/
function powerkit_share_buttons_vkontakte_counter( $account, $post_id, $url = null, $suffix = false ) {
// Get Post ID.
$post_id = $post_id ? $post_id : powerkit_share_buttons_get_current_post_id( $url );
// Get Chache.
$count = powerkit_share_buttons_get_cached_account( $account, $post_id, $url, false, $suffix );
if ( false !== $count ) {
return intval( $count );
}
// Get Count.
$endpoint = esc_url( 'https://vk.com/share.php?act=count&index=1&url=' . $url, null, '' );
$response = wp_remote_get( $endpoint, array(
'timeout' => 3,
) );
$response = wp_remote_retrieve_body( $response );
// Set Count.
preg_match( '/^VK.Share.count\(1, (\d+)\);$/i', $response, $response_result );
if ( isset( $response_result[1] ) ) {
$count = $response_result[1];
} else {
$count = powerkit_share_buttons_get_cached_account( $account, $post_id, $url, true, $suffix );
}
// Set Cache.
powerkit_share_buttons_set_cache_account( $account, $post_id, intval( $count ), $url, $suffix );
// Return Result.
return $count;
}
@@ -0,0 +1,559 @@
<?php
/**
* Share Buttons Accounts List
*
* @package Powerkit
* @subpackage Modules/Helper
*/
/**
* Add Facebook provider.
*
* @param array $accounts Social Accounts List.
* @param string $share_url Url for Share.
* @param int|string $post_id Post Id or options.
*/
function powerkit_share_buttons_add_facebook( $accounts, $share_url, $post_id ) {
/* Share text url */
$share_text_url = esc_url( 'https://www.facebook.com/sharer.php?t=--SHARETEXT--&u=' . $share_url, null, '' );
/* Share url */
$share_url = esc_url( 'https://www.facebook.com/sharer.php?u=' . $share_url, null, '' );
/* Add account */
$accounts['facebook'] = array(
'share_text_url' => $share_text_url,
'share_url' => $share_url,
'name' => esc_html__( 'Facebook', 'powerkit' ),
'label' => esc_html__( 'Share', 'powerkit' ),
'count_walker' => 'powerkit_share_buttons_facebook_counter',
);
return $accounts;
}
add_filter( 'powerkit_share_buttons_accounts', 'powerkit_share_buttons_add_facebook', 10, 3 );
/**
* Add Twitter provider.
*
* @param array $accounts Social Accounts List.
* @param string $share_url Url for Share.
* @param int|string $post_id Post Id or options.
*/
function powerkit_share_buttons_add_twitter( $accounts, $share_url, $post_id ) {
$twitter_text = null;
$via = null;
/* Twitter Text */
if ( intval( $post_id ) > 0 ) {
$title = html_entity_decode( get_the_title( $post_id ) );
$twitter_text = '&text=' . rawurlencode( $title );
}
/* Twitter Via */
$username = get_option( 'powerkit_social_links_twitter_user' );
if ( $username ) {
$via = '&via=' . $username;
}
/* Share text url */
$share_text_url = esc_url( 'https://twitter.com/share?text=--SHARETEXT--&url=' . $share_url, null, '' );
/* Share url */
$share_url = esc_url( 'https://twitter.com/share?' . $twitter_text . $via . '&url=' . $share_url, null, '' );
/* Add account */
$accounts['twitter'] = array(
'share_text_url' => $share_text_url,
'share_url' => $share_url,
'name' => esc_html__( 'Twitter', 'powerkit' ),
'label' => esc_html__( 'Tweet', 'powerkit' ),
);
return $accounts;
}
add_filter( 'powerkit_share_buttons_accounts', 'powerkit_share_buttons_add_twitter', 10, 3 );
/**
* Add Pinterest provider.
*
* @param array $accounts Social Accounts List.
* @param string $share_url Url for Share.
* @param int|string $post_id Post Id or options.
*/
function powerkit_share_buttons_add_pinterest( $accounts, $share_url, $post_id ) {
/* Media */
$media = __return_empty_string();
if ( intval( $post_id ) > 0 ) {
$thumb_url = false;
// Parse all images.
$post_content = get_post_field( 'post_content', intval( $post_id ) );
if ( $post_content ) {
preg_match_all( '/<a[^>]+powerkit-pinterest-cover[^>]+>.*?<\/a>/i', $post_content, $links );
// Add support Gutenberg <a>.
if ( ! empty( array_filter( $links ) ) ) {
$post_content = __return_empty_string();
foreach ( $links as $link ) {
$post_content .= $link[0];
}
}
preg_match_all( '/<figure[^>]+powerkit-pinterest-cover[^>]+>.*?<\/figure>/i', $post_content, $figures );
// Add support Gutenberg <figure>.
if ( ! empty( array_filter( $figures ) ) ) {
$post_content = __return_empty_string();
foreach ( $figures as $figure ) {
$post_content .= $figure[0];
}
}
// Parse all images.
preg_match_all( '/<img[^>]+>/i', $post_content, $result );
if ( is_array( $result ) ) {
$images = array();
// Parse attributes from finded images.
foreach ( $result[0] as $img_tag ) {
preg_match_all( '/(class|src)=("[^"]*")/i', $img_tag, $images[ $img_tag ] );
}
if ( is_array( $images ) ) {
// Post Content images loop.
foreach ( $images as $image_key => $image ) {
$temp_src = false;
$pin_exist = false;
// Each attributes per image.
foreach ( $image[1] as $index => $attr ) {
if ( 'src' === $attr ) {
$temp_src = $image[2][ $index ];
}
if ( ! empty( array_filter( $links ) ) || ! empty( array_filter( $figures ) ) ) {
if ( 'class' === $attr ) {
$pin_exist = true;
}
} else {
if ( 'class' === $attr && strpos( $image[2][ $index ], 'powerkit-pinterest-cover' ) !== false ) {
$pin_exist = true;
}
}
}
// Finded! Break loop and return image url.
if ( $pin_exist ) {
$thumb_url = $temp_src;
break;
}
}
}
}
}
// Show post thumnail, if post content doesn't have pinterest class in images.
if ( ! $thumb_url ) {
$thumb_url = get_the_post_thumbnail_url( intval( $post_id ), 'large' );
}
if ( $thumb_url ) {
$media = '&media=' . $thumb_url;
}
}
/* Share text url */
$share_text_url = esc_url( 'https://pinterest.com/pin/create/bookmarklet/?description=--SHARETEXT--&url=' . $share_url . $media, null, '' );
/* Share url */
$share_url = esc_url( 'https://pinterest.com/pin/create/bookmarklet/?url=' . $share_url . $media, null, '' );
/* Add account */
$accounts['pinterest'] = array(
'share_text_url' => $share_text_url,
'share_url' => $share_url,
'name' => esc_html__( 'Pinterest', 'powerkit' ),
'label' => esc_html__( 'Pin it', 'powerkit' ),
'count_walker' => 'powerkit_share_buttons_pinterest_counter',
);
return $accounts;
}
add_filter( 'powerkit_share_buttons_accounts', 'powerkit_share_buttons_add_pinterest', 10, 3 );
/**
* Add Mail provider.
*
* @param array $accounts Social Accounts List.
* @param string $share_url Url for Share.
* @param int|string $post_id Post Id or options.
*/
function powerkit_share_buttons_add_mail( $accounts, $share_url, $post_id ) {
$mail_text = esc_html__( 'Share Link', 'powerkit' );
/* Title */
if ( intval( $post_id ) > 0 ) {
$title = html_entity_decode( get_the_title( $post_id ) );
$mail_text = rawurlencode( $title );
}
/* Share text url */
$share_text_url = esc_url( 'mailto:?subject=' . $mail_text . '&body=--SHARETEXT--%20' . $share_url, null, '' );
/* Share url */
$share_url = esc_url( 'mailto:?subject=' . $mail_text . '&body=' . $mail_text . '%20' . $share_url, null, '' );
/* Add account */
$accounts['mail'] = array(
'share_text_url' => $share_text_url,
'share_url' => $share_url,
'name' => esc_html__( 'Mail', 'powerkit' ),
'label' => esc_html__( 'Share', 'powerkit' ),
);
return $accounts;
}
add_filter( 'powerkit_share_buttons_accounts', 'powerkit_share_buttons_add_mail', 10, 3 );
/**
* Add Xing provider.
*
* @param array $accounts Social Accounts List.
* @param string $share_url Url for Share.
* @param int|string $post_id Post Id or options.
*/
function powerkit_share_buttons_add_xing( $accounts, $share_url, $post_id ) {
/* Share url */
$share_url = esc_url( 'https://www.xing.com/spi/shares/new?url=' . $share_url, null, '' );
/* Add account */
$accounts['xing'] = array(
'share_url' => $share_url,
'name' => esc_html__( 'Xing', 'powerkit' ),
'label' => esc_html__( 'Share', 'powerkit' ),
'count_walker' => 'powerkit_share_buttons_xing_counter',
);
return $accounts;
}
add_filter( 'powerkit_share_buttons_accounts', 'powerkit_share_buttons_add_xing', 10, 3 );
/**
* Add LinkedIn provider.
*
* @param array $accounts Social Accounts List.
* @param string $share_url Url for Share.
* @param int|string $post_id Post Id or options.
*/
function powerkit_share_buttons_add_linkedin( $accounts, $share_url, $post_id ) {
/* Share url */
$share_url = esc_url( 'https://www.linkedin.com/shareArticle?mini=true&url=' . $share_url, null, '' );
/* Add account */
$accounts['linkedin'] = array(
'share_url' => $share_url,
'name' => esc_html__( 'LinkedIn', 'powerkit' ),
'label' => esc_html__( 'Share', 'powerkit' ),
'count_walker' => 'powerkit_share_buttons_linkedin_counter',
);
return $accounts;
}
add_filter( 'powerkit_share_buttons_accounts', 'powerkit_share_buttons_add_linkedin', 10, 3 );
/**
* Add StumbleUpon provider.
*
* @param array $accounts Social Accounts List.
* @param string $share_url Url for Share.
* @param int|string $post_id Post Id or options.
*/
function powerkit_share_buttons_add_stumbleupon( $accounts, $share_url, $post_id ) {
/* Share url */
$share_url = esc_url( 'http://www.stumbleupon.com/submit?url=' . $share_url, null, '' );
/* Add account */
$accounts['stumbleupon'] = array(
'share_url' => $share_url,
'name' => esc_html__( 'StumbleUpon', 'powerkit' ),
'label' => esc_html__( 'Share', 'powerkit' ),
);
return $accounts;
}
add_filter( 'powerkit_share_buttons_accounts', 'powerkit_share_buttons_add_stumbleupon', 10, 3 );
/**
* Add Pocket provider.
*
* @param array $accounts Social Accounts List.
* @param string $share_url Url for Share.
* @param int|string $post_id Post Id or options.
*/
function powerkit_share_buttons_add_pocket( $accounts, $share_url, $post_id ) {
/* Share url */
$share_url = esc_url( 'https://getpocket.com/save?url=' . $share_url, null, '' );
/* Add account */
$accounts['pocket'] = array(
'share_url' => $share_url,
'name' => esc_html__( 'Pocket', 'powerkit' ),
'label' => esc_html__( 'Share', 'powerkit' ),
);
return $accounts;
}
add_filter( 'powerkit_share_buttons_accounts', 'powerkit_share_buttons_add_pocket', 10, 3 );
/**
* Add WhatsApp provider.
*
* @param array $accounts Social Accounts List.
* @param string $share_url Url for Share.
* @param int|string $post_id Post Id or options.
*/
function powerkit_share_buttons_add_whatsapp( $accounts, $share_url, $post_id ) {
/* Share url */
$share_url = esc_url( 'whatsapp://send?text=' . $share_url, null, '' );
/* Add account */
$accounts['whatsapp'] = array(
'share_url' => $share_url,
'name' => esc_html__( 'WhatsApp', 'powerkit' ),
'label' => esc_html__( 'Share', 'powerkit' ),
);
return $accounts;
}
add_filter( 'powerkit_share_buttons_accounts', 'powerkit_share_buttons_add_whatsapp', 10, 3 );
/**
* Add Facebook Messenger provider.
*
* @param array $accounts Social Accounts List.
* @param string $share_url Url for Share.
* @param int|string $post_id Post Id or options.
*/
function powerkit_share_buttons_add_fb_messenger( $accounts, $share_url, $post_id ) {
/* Share url */
$share_url = esc_url( 'fb-messenger://share/?link=' . $share_url, null, '' );
/* Add account */
$accounts['fb-messenger'] = array(
'share_url' => $share_url,
'name' => esc_html__( 'Facebook Messenger', 'powerkit' ),
'label' => esc_html__( 'Share', 'powerkit' ),
);
return $accounts;
}
add_filter( 'powerkit_share_buttons_accounts', 'powerkit_share_buttons_add_fb_messenger', 10, 3 );
/**
* Add Viber provider.
*
* @param array $accounts Social Accounts List.
* @param string $share_url Url for Share.
* @param int|string $post_id Post Id or options.
*/
function powerkit_share_buttons_add_viber( $accounts, $share_url, $post_id ) {
/* Share url */
$share_url = esc_url( 'viber://forward?text=' . $share_url, null, '' );
/* Add account */
$accounts['viber'] = array(
'share_url' => $share_url,
'name' => esc_html__( 'Viber', 'powerkit' ),
'label' => esc_html__( 'Share', 'powerkit' ),
);
return $accounts;
}
add_filter( 'powerkit_share_buttons_accounts', 'powerkit_share_buttons_add_viber', 10, 3 );
/**
* Add Odnoklassniki provider.
*
* @param array $accounts Social Accounts List.
* @param string $share_url Url for Share.
* @param int|string $post_id Post Id or options.
*/
function powerkit_share_buttons_add_ok( $accounts, $share_url, $post_id ) {
/* Share url */
$share_url = esc_url( 'https://connect.ok.ru/offer?url=' . $share_url, null, '' );
/* Add account */
$accounts['ok'] = array(
'share_url' => $share_url,
'name' => esc_html__( 'Odnoklassniki', 'powerkit' ),
'label' => esc_html__( 'Like', 'powerkit' ),
'count_walker' => 'powerkit_share_buttons_ok_counter',
);
return $accounts;
}
add_filter( 'powerkit_share_buttons_accounts', 'powerkit_share_buttons_add_ok', 10, 3 );
/**
* Add Vkontakte provider.
*
* @param array $accounts Social Accounts List.
* @param string $share_url Url for Share.
* @param int|string $post_id Post Id or options.
*/
function powerkit_share_buttons_add_vk( $accounts, $share_url, $post_id ) {
/* Share url */
$share_url = esc_url( 'https://vk.com/share.php?url=' . $share_url, null, '' );
/* Add account */
$accounts['vkontakte'] = array(
'share_url' => $share_url,
'name' => esc_html__( 'VK', 'powerkit' ),
'label' => esc_html__( 'Like', 'powerkit' ),
'count_walker' => 'powerkit_share_buttons_vkontakte_counter',
);
return $accounts;
}
add_filter( 'powerkit_share_buttons_accounts', 'powerkit_share_buttons_add_vk', 10, 3 );
/**
* Add Telegram provider.
*
* @param array $accounts Social Accounts List.
* @param string $share_url Url for Share.
* @param int|string $post_id Post Id or options.
*/
function powerkit_share_buttons_add_telegram( $accounts, $share_url, $post_id ) {
/* Text */
$telegram_text = null;
if ( intval( $post_id ) > 0 ) {
$title = html_entity_decode( get_the_title( $post_id ) );
$telegram_text = '&text=' . rawurlencode( $title );
}
/* Share url */
$share_url = esc_url( 'https://t.me/share/url?' . $telegram_text . '&url=' . $share_url, null, '' );
/* Add account */
$accounts['telegram'] = array(
'share_url' => $share_url,
'name' => esc_html__( 'Telegram', 'powerkit' ),
'label' => esc_html__( 'Share', 'powerkit' ),
);
return $accounts;
}
add_filter( 'powerkit_share_buttons_accounts', 'powerkit_share_buttons_add_telegram', 10, 3 );
/**
* Add LINE provider.
*
* @param array $accounts Social Accounts List.
* @param string $share_url Url for Share.
* @param int|string $post_id Post Id or options.
*/
function powerkit_share_buttons_add_line( $accounts, $share_url, $post_id ) {
/* Share url */
$share_url = esc_url( 'http://line.me/R/msg/text/?' . $share_url, null, '' );
/* Add account */
$accounts['line'] = array(
'share_url' => $share_url,
'name' => esc_html__( 'Line', 'powerkit' ),
'label' => esc_html__( 'Share', 'powerkit' ),
);
return $accounts;
}
add_filter( 'powerkit_share_buttons_accounts', 'powerkit_share_buttons_add_line', 10, 3 );
/**
* Add Reddit provider.
*
* @param array $accounts Social Accounts List.
* @param string $share_url Url for Share.
* @param int|string $post_id Post Id or options.
*/
function powerkit_share_buttons_add_reddit( $accounts, $share_url, $post_id ) {
/* Share url */
$share_url = esc_url( 'http://www.reddit.com/submit?url=' . $share_url, null, '' );
/* Add account */
$accounts['reddit'] = array(
'share_url' => $share_url,
'name' => esc_html__( 'Reddit', 'powerkit' ),
'label' => esc_html__( 'Share', 'powerkit' ),
);
return $accounts;
}
add_filter( 'powerkit_share_buttons_accounts', 'powerkit_share_buttons_add_reddit', 10, 3 );
/**
* Add Mix.com provider.
*
* @param array $accounts Social Accounts List.
* @param string $share_url Url for Share.
* @param int|string $post_id Post Id or options.
*/
function powerkit_share_buttons_add_mix( $accounts, $share_url, $post_id ) {
/* Share url */
$share_url = esc_url( 'https://mix.com/add?url=' . $share_url, null, '' );
/* Add account */
$accounts['mix'] = array(
'share_url' => $share_url,
'name' => esc_html__( 'Mix.com', 'powerkit' ),
'label' => esc_html__( 'Share', 'powerkit' ),
);
return $accounts;
}
add_filter( 'powerkit_share_buttons_accounts', 'powerkit_share_buttons_add_mix', 10, 3 );
@@ -0,0 +1,35 @@
<?php
/**
* Share Buttons block template
*
* @var $attributes - block attributes
* @var $options - layout options
*
* @link https://codesupply.co
* @since 1.0.0
*
* @package PowerKit
* @subpackage PowerKit/templates
*/
$params = array(
'title' => esc_html__( 'Share Buttons', 'powerkit' ),
'accounts' => $attributes['accounts'] ? : array(),
'total' => $attributes['showTotal'],
'icons' => $attributes['showIcons'],
'labels' => $attributes['showLabels'],
'counts' => $attributes['showCounts'],
'titles' => $attributes['showTitles'],
'title_location' => 'inside',
'label_location' => 'inside',
'count_location' => 'inside',
'mode' => apply_filters( 'powerkit_share_buttons_block_counter_mode', 'mixed' ),
'layout' => $attributes['layout'] ? : 'default',
'scheme' => 'gutenberg-block',
);
echo '<div class="' . esc_attr( $attributes['className'] ) . '" ' . ( isset( $attributes['anchor'] ) ? ' id="' . esc_attr( $attributes['anchor'] ) . '"' : '' ) . '>';
powerkit_share_buttons( $params['accounts'], $params['total'], $params['icons'], $params['titles'], $params['labels'], $params['counts'], $params['title_location'], $params['label_location'], $params['count_location'], $params['mode'], $params['layout'], $params['scheme'], '' );
echo '</div>';
@@ -0,0 +1,176 @@
<?php
/**
* The Gutenberg Block.
*
* @link https://codesupply.co
* @since 1.0.0
*
* @package Powerkit
* @subpackage Modules/public
*/
/**
* The initialize block.
*/
class Powerkit_Share_Buttons_Block {
/**
* Initialize
*/
public function __construct() {
add_action( 'init', array( $this, 'block' ) );
add_filter( 'canvas_register_block_type', array( $this, 'register_block_type' ) );
}
/**
* Enqueue the block's assets for the editor.
*/
public function block() {
// Styles.
wp_register_style(
'powerkit-share-buttons-block-editor-style',
plugins_url( 'css/public-powerkit-share-buttons.css', __FILE__ ),
array( 'wp-edit-blocks' ),
filemtime( plugin_dir_path( __FILE__ ) . 'css/public-powerkit-share-buttons.css' )
);
wp_style_add_data( 'powerkit-share-buttons-block-editor-style', 'rtl', 'replace' );
}
/**
* Register block
*
* @param array $blocks all registered blocks.
* @return array
*/
public function register_block_type( $blocks ) {
$additional_fields = array();
$styles = array();
$colors = apply_filters( 'powerkit_share_buttons_color_schemes', array() );
$layouts = apply_filters( 'powerkit_share_buttons_color_layouts', array() );
// Colors.
if ( count( (array) $colors ) > 1 ) {
foreach ( $colors as $name => $scheme ) {
$styles[] = array(
'name' => 'pk-share-buttons-' . $name,
'label' => $scheme['name'],
);
}
}
// Layouts.
if ( count( (array) $layouts ) > 1 ) {
$layouts_array = array();
foreach ( $layouts as $name => $layout ) {
$layouts_array[ $name ] = $layout['name'];
}
$additional_fields[] = array(
'key' => 'layout',
'label' => esc_html__( 'Layout', 'powerkit' ),
'section' => 'general',
'type' => 'select',
'default' => 'default',
'choices' => $layouts_array,
);
}
$accounts = apply_filters( 'powerkit_share_buttons_accounts', array(), null, null );
$accounts_choices = array();
foreach ( $accounts as $key => $account ) {
$accounts_choices[ $key ] = esc_html( $account['name'] );
}
$blocks[] = array(
'name' => 'canvas/share-buttons',
'title' => esc_html__( 'Share Buttons', 'powerkit' ),
'category' => 'canvas',
'keywords' => array(),
'icon' => '<svg width="22" height="24" xmlns="http://www.w3.org/2000/svg"><g fill="none" fill-rule="evenodd"><path fill="none" d="M-1 0h24v24H-1z"/><path d="M17.667 16.4c1.84 0 3.333 1.477 3.333 3.3 0 1.823-1.492 3.3-3.333 3.3-1.841 0-3.334-1.477-3.334-3.3 0-1.823 1.493-3.3 3.334-3.3zM4.333 8.7c1.841 0 3.334 1.477 3.334 3.3 0 1.823-1.493 3.3-3.334 3.3C2.493 15.3 1 13.823 1 12c0-1.823 1.492-3.3 3.333-3.3zM17.667 1C19.507 1 21 2.477 21 4.3c0 1.823-1.492 3.3-3.333 3.3-1.841 0-3.334-1.477-3.334-3.3 0-1.823 1.493-3.3 3.334-3.3zM7.21 13.661l7.589 4.378m-.011-12.078L7.21 10.339" stroke="#2D2D2D" stroke-width="1.5"/></g></svg>',
'supports' => array(
'className' => true,
'anchor' => true,
'html' => false,
'canvasSpacings' => true,
'canvasBorder' => true,
'canvasResponsive' => true,
),
'styles' => $styles,
'location' => array(),
'sections' => array(
'general' => array(
'title' => esc_html__( 'Block Settings', 'powerkit' ),
'priority' => 5,
'open' => true,
),
),
'layouts' => array(),
'fields' => array_merge(
$additional_fields, array(
array(
'key' => 'accounts',
'label' => esc_html__( 'Accounts', 'powerkit' ),
'section' => 'general',
'type' => 'react-select',
'multiple' => true,
'choices' => $accounts_choices,
'default' => array(
'facebook',
'twitter',
'pinterest',
),
'items' => array(
'type' => 'string',
),
),
array(
'key' => 'showTotal',
'label' => esc_html__( 'Display Total Shares', 'powerkit' ),
'section' => 'general',
'type' => 'toggle',
'default' => false,
),
array(
'key' => 'showIcons',
'label' => esc_html__( 'Display Icons', 'powerkit' ),
'section' => 'general',
'type' => 'toggle',
'default' => true,
),
array(
'key' => 'showLabels',
'label' => esc_html__( 'Display Labels', 'powerkit' ),
'section' => 'general',
'type' => 'toggle',
'default' => true,
),
array(
'key' => 'showTitles',
'label' => esc_html__( 'Display Titles', 'powerkit' ),
'section' => 'general',
'type' => 'toggle',
'default' => true,
),
array(
'key' => 'showCounts',
'label' => esc_html__( 'Display Counts', 'powerkit' ),
'section' => 'general',
'type' => 'toggle',
'default' => true,
),
)
),
'template' => dirname( __FILE__ ) . '/block/render.php',
// enqueue registered scripts/styles.
'editor_style' => 'powerkit-share-buttons-block-editor-style',
);
return $blocks;
}
}
new Powerkit_Share_Buttons_Block();
@@ -0,0 +1,349 @@
<?php
/**
* The public-facing functionality of the module.
*
* @link https://codesupply.co
* @since 1.0.0
*
* @package Powerkit
* @subpackage Modules/public
*/
/**
* The public-facing functionality of the module.
*/
class Powerkit_Share_Buttons_Public extends Powerkit_Module_Public {
/**
* Initialize
*/
public function initialize() {
add_action( 'wp_footer', array( $this, 'wp_footer' ) );
add_filter( 'the_content', array( $this, 'the_post_content' ) );
add_filter( 'kses_allowed_protocols', array( $this, 'allow_protocols' ) );
add_filter( 'powerkit_share_buttons_locations', array( $this, 'locations_default' ), 10 );
add_filter( 'powerkit_share_buttons_locations', array( $this, 'locations_extra' ), 100 );
add_filter( 'powerkit_share_buttons_color_layouts', array( $this, 'layouts_default' ), 10, 2 );
add_filter( 'powerkit_share_buttons_color_schemes', array( $this, 'schemes_default' ) );
add_filter( 'powerkit_share_buttons_total_label', array( $this, 'mobile_share_buttons_total_label' ), 10, 3 );
}
/**
* Allow protocols for esc_url.
*
* @param array $protocols Array of allowed protocols.
*/
public function allow_protocols( $protocols ) {
array_push( $protocols, 'fb-messenger', 'whatsapp', 'viber', 'tg' );
return $protocols;
}
/**
* Output mobile share buttons.
*/
public function wp_footer() {
// Check AMP endpoint.
if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
return;
}
if ( is_singular( 'post' ) && is_single( get_the_ID() ) ) {
?>
<div class="pk-mobile-share-overlay">
<?php
powerkit_share_buttons_location( 'mobile-share' );
?>
</div>
<?php
}
}
/**
* Filter output buttons in post content.
*
* @param string $content The content of post.
*/
public function the_post_content( $content ) {
// Check AMP endpoint.
if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
return $content;
}
if ( is_singular( 'post' ) && is_single( get_the_ID() ) ) {
ob_start();
powerkit_share_buttons_location( 'before-content' );
$before_shares = ob_get_clean();
ob_start();
powerkit_share_buttons_location( 'after-content' );
$after_shares = ob_get_clean();
ob_start();
powerkit_share_buttons_location( 'highlight-text' );
$highlight_shares = ob_get_clean();
$content .= $highlight_shares;
ob_start();
powerkit_share_buttons_location( 'blockquote' );
$blockquote = ob_get_clean();
$content .= $blockquote;
// Clearfix.
if ( $after_shares ) {
$after_shares = '<div class="pk-clearfix"></div>' . $after_shares;
}
// Concatenation.
$content = $before_shares . $content . $after_shares;
}
return $content;
}
/**
* Filter Register Locations
*
* @since 1.0.0
* @access private
*
* @param array $locations List of Locations.
*/
public function locations_default( $locations = array() ) {
$locations = array(
'after-content' => array(
'shares' => array( 'facebook', 'twitter', 'pinterest', 'mail' ),
'name' => 'After Post Content',
'location' => 'after-content',
'mode' => 'mixed',
'before' => '',
'after' => '',
'display' => true,
'fields' => array(
'display_total' => true,
'display_count' => true,
),
),
'before-content' => array(
'shares' => array( 'facebook', 'twitter', 'pinterest', 'mail' ),
'name' => 'Before Post Content',
'location' => 'before-content',
'mode' => 'mixed',
'before' => '',
'after' => '',
'fields' => array(
'display_total' => true,
'display_count' => true,
),
),
);
return $locations;
}
/**
* Filter Register Extra Locations
*
* @since 1.0.0
* @access private
*
* @param array $locations List of Locations.
*/
public function locations_extra( $locations = array() ) {
$locations['highlight-text'] = array(
'shares' => array( 'facebook', 'twitter', 'pinterest', 'mail' ),
'name' => '⚡ Highlight Text',
'location' => 'highlight-text',
'mode' => 'none',
'before' => '',
'after' => '',
'meta' => array(
'icons' => true,
'titles' => false,
'labels' => false,
),
'fields' => array(
'display_total' => false,
'display_count' => false,
'title_locations' => array(),
'count_locations' => array(),
'label_locations' => array(),
'layouts' => array( 'simple' ),
),
'display_total' => false,
'layout' => 'simple',
);
$locations['blockquote'] = array(
'shares' => array( 'facebook', 'twitter' ),
'name' => '⭐ Blockquote',
'location' => 'blockquote',
'mode' => 'none',
'before' => '',
'after' => '',
'meta' => array(
'icons' => true,
'titles' => false,
'labels' => true,
),
'fields' => array(
'display_total' => false,
'display_count' => false,
'title_locations' => array(),
'count_locations' => array(),
'label_locations' => array(),
'layouts' => array( 'simple' ),
),
'display_total' => false,
'layout' => 'simple',
);
$locations['mobile-share'] = array(
'shares' => array( 'facebook', 'pinterest', 'twitter', 'mail' ),
'name' => '📱 Mobile Share',
'location' => 'mobile-share',
'mode' => 'none',
'before' => '',
'after' => '',
'meta' => array(
'icons' => true,
'titles' => false,
'labels' => false,
),
'fields' => array(
'display_total' => false,
'display_count' => true,
'title_locations' => array(),
'count_locations' => array(),
'label_locations' => array(),
'schemes' => array( 'default', 'simple-dark-back', 'bold-bg', 'bold' ),
'layouts' => array( 'horizontal', 'left-side', 'right-side', 'popup' ),
),
'layout' => 'horizontal',
);
return $locations;
}
/**
* Filter Register Layouts
*
* @param array $layouts List of Layouts.
* @param string $location Name of Location.
*/
public function layouts_default( $layouts = array(), $location = null ) {
$layouts['default'] = array(
'name' => 'First Two Large Buttons',
);
$layouts['equal'] = array(
'name' => 'Equal Width Buttons',
);
$layouts['simple'] = array(
'name' => 'Simple Buttons',
);
if ( 'mobile-share' === $location ) {
$layouts['horizontal'] = array(
'name' => 'Horizontal',
);
$layouts['left-side'] = array(
'name' => 'Left side',
);
$layouts['right-side'] = array(
'name' => 'Right side',
);
$layouts['popup'] = array(
'name' => 'Popup',
);
}
return $layouts;
}
/**
* Filter Register Schemes
*
* @param array $schemes List of Schemes.
*/
public function schemes_default( $schemes = array() ) {
$schemes['default'] = array( // simple-light-back.
'name' => 'Simple & Light Background',
);
$schemes['simple-dark-back'] = array(
'name' => 'Simple & Dark Background',
);
$schemes['bold-bg'] = array( // simple-bold-back.
'name' => 'Simple & Bold Background',
);
$schemes['simple-light'] = array(
'name' => 'Simple',
);
$schemes['bold'] = array( // bold-light-back.
'name' => 'Bold & Light Background',
);
$schemes['bold-light'] = array(
'name' => 'Bold',
);
$schemes['inverse-light'] = array(
'name' => 'Inverse',
);
return $schemes;
}
/**
* Change Total Output of Share Buttons
*
* @param bool $output The output.
* @param string $class The class.
* @param int $count The count.
*/
public function mobile_share_buttons_total_label( $output, $class, $count ) {
if ( false !== strpos( $class, 'pk-share-buttons-mobile-share' ) ) {
$output = esc_html__( 'Share', 'powerkit' );
}
return $output;
}
/**
* Register the stylesheets for the public-facing side of the site.
*/
public function wp_enqueue_scripts() {
wp_enqueue_style( 'powerkit-share-buttons', powerkit_style( plugin_dir_url( __FILE__ ) . 'css/public-powerkit-share-buttons.css' ), array(), powerkit_get_setting( 'version' ), 'all' );
// Add RTL support.
wp_style_add_data( 'powerkit-share-buttons', 'rtl', 'replace' );
// Scripts.
wp_enqueue_script( 'powerkit-share-buttons', plugin_dir_url( __FILE__ ) . 'js/public-powerkit-share-buttons.js', array( 'jquery' ), powerkit_get_setting( 'version' ), true );
}
/**
* Add styles in Gutenberg editor.
* Used in Featured Posts block.
*/
public function enqueue_block_editor_assets() {
wp_enqueue_style( 'powerkit-share-buttons', powerkit_style( plugin_dir_url( __FILE__ ) . 'css/public-powerkit-share-buttons.css' ), array(), powerkit_get_setting( 'version' ), 'all' );
// Add RTL support.
wp_style_add_data( 'powerkit-share-buttons', 'rtl', 'replace' );
}
}
@@ -0,0 +1,58 @@
<?php
/**
* Shortcode Share Buttons
*
* @link https://codesupply.co
* @since 1.0.0
*
* @package PowerKit
* @subpackage PowerKit/shortcodes
*/
/**
* Share Buttons Shortcode
*
* @param array $atts User defined attributes in shortcode tag.
* @param string $content Shorcode tag content.
* @return string Shortcode result HTML.
*/
function powerkit_share_buttons_shortcode( $atts, $content = '' ) {
$params = powerkit_shortcode_atts( shortcode_atts( array(
'accounts' => '',
'total' => true,
'icons' => true,
'labels' => true,
'counts' => true,
'titles' => false,
'title_location' => 'inside',
'label_location' => 'inside',
'count_location' => 'inside',
'mode' => 'mixed',
'layout' => 'default',
'scheme' => 'default',
), $atts ) );
$params['total'] = filter_var( $params['total'], FILTER_VALIDATE_BOOLEAN );
$params['labels'] = filter_var( $params['labels'], FILTER_VALIDATE_BOOLEAN );
$params['counts'] = filter_var( $params['counts'], FILTER_VALIDATE_BOOLEAN );
ob_start();
// Accounts.
if ( $params['accounts'] ) {
$params['accounts'] = explode( ',', $params['accounts'] );
if ( $params['accounts'] ) {
foreach ( $params['accounts'] as $key => $val ) {
$params['accounts'][ $key ] = trim( $val );
}
}
}
// Get Shares.
powerkit_share_buttons( $params['accounts'], $params['total'], $params['icons'], $params['titles'], $params['labels'], $params['counts'], $params['title_location'], $params['label_location'], $params['count_location'], $params['mode'], $params['layout'], $params['scheme'], '' );
return ob_get_clean();
}
add_shortcode( 'powerkit_share_buttons', 'powerkit_share_buttons_shortcode' );
@@ -0,0 +1,124 @@
/**
* Share buttons.
*/
( function( $ ) {
$( document ).ready( function() {
// Blockquote
let blockquoteLength = $( '.pk-share-buttons-blockquote' ).length;
if ( blockquoteLength ) {
$( '.entry-content' ).find( 'blockquote' ).each( function( index, item ) {
if ( $( item ).closest( '.wp-block-embed' ).length ) {
return;
}
if ( $( item ).closest( '.twitter-tweet' ).length ) {
return;
}
var text = $( this ).find( 'p' ).text();
if ( ! text ) {
text = $( this ).text();
}
let container = $( '.pk-share-buttons-blockquote' ).not( '.pk-share-buttons-blockquote-clone' ).clone().appendTo( item );
container.addClass( 'pk-share-buttons-blockquote-clone' );
container.find( '.pk-share-buttons-link' ).each( function( index, item ) {
let url = $( this ).attr( 'href' ).replace( '--SHARETEXT--', encodeURIComponent( text ) );
$( this ).attr( 'href', url );
} );
} );
}
// Highlight and Share
let highlightLength = $( '.pk-share-buttons-highlight-text' ).length;
if ( highlightLength ) {
/*
* Events
*/
$( 'body' ).on( 'mouseup', function( e ) {
if ( ! $( e.target ).closest( '.entry-content' ).length &&
! $( e.target ).closest( '.pk-share-buttons-wrap' ).length ) {
highlightRemove();
}
} );
$( 'body' ).on( 'mouseup', '.entry-content', function( e ) {
e.preventDefault();
highlightRemove();
let selection = window.getSelection();
let text = selection.toString();
// Current title.
this.title = '';
// Check exists text.
if ( '' != text ) {
highlightDisplay( text, e );;
}
} );
/*
* Remove highlight container
*/
var highlightRemove = function() {
$( '.pk-share-buttons-highlight-clone' ).remove();
};
/*
* Show highlight container
*/
var highlightDisplay = function( text, e ) {
highlightRemove();
let container = $( '.pk-share-buttons-highlight-text' ).not( '.pk-share-buttons-highlight-clone' ).clone().appendTo( 'body' );
let wrapper_x = e.pageX + 10;
let wrapper_y = e.pageY + 10;
container.addClass( 'pk-share-buttons-highlight-clone' );
container.css( { left: wrapper_x, top: wrapper_y } );
container.find( '.pk-share-buttons-link' ).each( function( index, item ) {
let url = $( this ).attr( 'href' ).replace( '--SHARETEXT--', encodeURIComponent( text ) );
$( this ).attr( 'href', url );
} );
}
}
// Mobile Share
let mobileShare = $( '.pk-share-buttons-layout-right-side, .pk-share-buttons-layout-left-side, .pk-share-buttons-layout-popup' );
$( mobileShare ).each( function(index, elem) {
$( elem ).find( '.pk-share-buttons-total, .pk-share-buttons-link' ).on( 'click', function(e){
$( 'body' ).toggleClass( 'pk-mobile-share-active' );
});
} );
// Close outside.
$( document ).on( 'click', function(e) {
if ( ! $( e.target ) .closest( '.pk-share-buttons-total' ).length ) {
$( 'body' ).removeClass( 'pk-mobile-share-active' );
}
});
} );
} )( jQuery );