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,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 );