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,85 @@
<?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_Pinterest_Admin extends Powerkit_Module_Admin {
/**
* Initialize
*/
public function initialize() {
add_action( 'admin_init', array( $this, 'register_settings_section' ) );
}
/**
* Register admin page
*
* @since 1.0.0
*/
public function register_settings_section() {
add_settings_section( 'powerkit_pinit_settings', sprintf( '<span id="%s">%s</span>', powerkit_get_page_slug( $this->slug ), esc_html__( 'Pin It Button', 'powerkit' ) ), array( $this, 'powerkit_pinit_settings_callback' ), 'media' );
add_settings_field( 'powerkit_pinit_image_selectors', esc_html__( 'Image selectors', 'powerkit' ), array( $this, 'powerkit_pinit_image_selectors_callback' ), 'media', 'powerkit_pinit_settings' );
add_settings_field( 'powerkit_pinit_exclude_selectors', esc_html__( 'Exclude selectors', 'powerkit' ), array( $this, 'powerkit_pinit_exclude_selectors_callback' ), 'media', 'powerkit_pinit_settings' );
add_settings_field( 'powerkit_pinit_only_hover', esc_html__( 'Display on mouse hover only', 'powerkit' ), array( $this, 'powerkit_pinit_only_hover_callback' ), 'media', 'powerkit_pinit_settings' );
register_setting( 'media', 'powerkit_pinit_image_selectors' );
register_setting( 'media', 'powerkit_pinit_exclude_selectors' );
register_setting( 'media', 'powerkit_pinit_only_hover' );
}
/**
* Section Description.
*
* @since 1.0.0
*/
public function powerkit_pinit_settings_callback() {
return null;
}
/**
* Field | Image selectors.
*
* @since 1.0.0
*/
public function powerkit_pinit_image_selectors_callback() {
?>
<textarea class="regular-text" id="powerkit_pinit_image_selectors" name="powerkit_pinit_image_selectors" rows="8"><?php echo esc_attr( get_option( 'powerkit_pinit_image_selectors', '.entry-content img' ) ); ?></textarea>
<p class="description"><?php esc_html_e( 'Only images with these CSS classes will show the "Pin it" button. The new conditions add a new row.', 'powerkit' ); ?></p>
<?php
}
/**
* Field | Exclude selectors.
*
* @since 1.0.0
*/
public function powerkit_pinit_exclude_selectors_callback() {
?>
<textarea class="regular-text" id="powerkit_pinit_exclude_selectors" name="powerkit_pinit_exclude_selectors" rows="8"><?php echo esc_attr( get_option( 'powerkit_pinit_exclude_selectors', '' ) ); ?></textarea>
<p class="description"><?php esc_html_e( 'Images with these CSS classes won\'t show the "Pin it" button. The new conditions add a new row.', 'powerkit' ); ?></p>
<?php
}
/**
* Field | Display on mouse hover only.
*
* @since 1.0.0
*/
public function powerkit_pinit_only_hover_callback() {
?>
<input class="regular-text" id="powerkit_pinit_only_hover" name="powerkit_pinit_only_hover" type="checkbox" value="true" <?php checked( (bool) get_option( 'powerkit_pinit_only_hover', true ) ); ?>>
<?php
}
}
@@ -0,0 +1,70 @@
<?php
/**
* Pinterest Integration
*
* @package Powerkit
* @subpackage Modules
*/
if ( class_exists( 'Powerkit_Module' ) ) {
/**
* Init module
*/
class Powerkit_Pinterest extends Powerkit_Module {
/**
* Register module
*/
public function register() {
$this->name = esc_html__( 'Pinterest Integration', 'powerkit' );
$this->desc = esc_html__( 'Display your Pinterest Board widget in your sidebar or post content via shortcode. Enable Pin It buttons on single images in post content and all post galleries for the easy pinning of your images to Pinterest boards.', 'powerkit' );
$this->slug = 'pinterest_integration';
$this->type = 'default';
$this->category = 'social';
$this->priority = 40;
$this->public = true;
$this->enabled = true;
$this->links = array(
array(
'name' => esc_html__( 'Go to settings', 'powerkit' ),
'url' => admin_url( sprintf( 'options-media.php#%s', powerkit_get_page_slug( $this->slug ) ) ),
),
array(
'name' => esc_html__( 'View documentation', 'powerkit' ),
'url' => powerkit_get_setting( 'documentation' ) . '/social-integrations/pinterest-integration/',
'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-pinterest.php';
// The classes responsible for defining all actions.
require_once dirname( __FILE__ ) . '/public/class-powerkit-pinterest-shortcode.php';
require_once dirname( __FILE__ ) . '/public/class-powerkit-pinterest-board-widget.php';
require_once dirname( __FILE__ ) . '/public/class-powerkit-pinterest-profile-widget.php';
// Gutenberg blocks.
if ( function_exists( 'register_block_type' ) ) {
require_once dirname( __FILE__ ) . '/public/class-powerkit-pinterest-block.php';
}
// Admin and public area.
require_once dirname( __FILE__ ) . '/admin/class-powerkit-pinterest-admin.php';
require_once dirname( __FILE__ ) . '/public/class-powerkit-pinterest-public.php';
new Powerkit_Pinterest_Admin( $this->slug );
new Powerkit_Pinterest_Public( $this->slug );
}
}
new Powerkit_Pinterest();
}
@@ -0,0 +1,29 @@
<?php
/**
* Helpers Pinterest
*
* @package Powerkit
* @subpackage Modules/Helper
*/
/**
* PinIt process selectors
*
* @param string $selectors List selectors.
*/
function powerkit_pinit_process_selectors( $selectors = array() ) {
if ( ! $selectors ) {
$selectors = array();
}
if ( is_string( $selectors ) ) {
$selectors = str_replace( "\r\n", ',', $selectors );
$selectors = explode( ',', $selectors );
}
$selectors = array_filter( $selectors, 'strlen' );
return $selectors;
}
@@ -0,0 +1,6 @@
!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=3)}([function(e,t,n){var r;
/*!
Copyright (c) 2018 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/!function(){"use strict";var n={}.hasOwnProperty;function o(){for(var e=[],t=0;t<arguments.length;t++){var r=arguments[t];if(r){var i=typeof r;if("string"===i||"number"===i)e.push(r);else if(Array.isArray(r)){if(r.length){var u=o.apply(null,r);u&&e.push(u)}}else if("object"===i)if(r.toString===Object.prototype.toString)for(var a in r)n.call(r,a)&&r[a]&&e.push(a);else e.push(r.toString())}}return e.join(" ")}e.exports?(o.default=o,e.exports=o):void 0===(r=function(){return o}.apply(t,[]))||(e.exports=r)}()},function(e,t,n){!function(e){"use strict";function t(e,t,n,r){var o,i=!1,u=0;function a(){o&&clearTimeout(o)}function c(){for(var c=arguments.length,l=new Array(c),f=0;f<c;f++)l[f]=arguments[f];var p=this,s=Date.now()-u;function b(){u=Date.now(),n.apply(p,l)}function d(){o=void 0}i||(r&&!o&&b(),a(),void 0===r&&s>e?b():!0!==t&&(o=setTimeout(r?d:b,void 0===r?e-s:e)))}return"boolean"!=typeof t&&(r=n,n=t,t=void 0),c.cancel=function(){a(),i=!0},c}e.debounce=function(e,n,r){return void 0===r?t(e,n,!1):t(e,r,!1!==n)},e.throttle=t,Object.defineProperty(e,"__esModule",{value:!0})}(t)},,function(e,t,n){e.exports=n(7)},,,,function(e,t,n){"use strict";n.r(t);var r=n(0),o=n.n(r),i=n(1);function u(e){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function c(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function l(e,t){return(l=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function f(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=b(e);if(t){var o=b(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return p(this,n)}}function p(e,t){return!t||"object"!==u(t)&&"function"!=typeof t?s(e):t}function s(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function b(e){return(b=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var d=wp.i18n.__,y=wp.element,m=y.Component,v=y.Fragment,h=wp.components,w=h.Placeholder,O=h.Disabled,j=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&l(e,t)}(p,e);var t,n,r,u=f(p);function p(){var e;return a(this,p),(e=u.apply(this,arguments)).state={pinApi:!1},e.maybeFindGlobalPinObj=e.maybeFindGlobalPinObj.bind(s(e)),e.maybeInit=Object(i.debounce)(300,e.maybeInit.bind(s(e))),e}return t=p,(n=[{key:"componentDidMount",value:function(){this.maybeInit()}},{key:"componentDidUpdate",value:function(){this.maybeInit()}},{key:"maybeFindGlobalPinObj",value:function(){var e=this;Object.keys(window).forEach((function(t){/^PIN_\d+$/.test(t)&&window[t].f&&window[t].f.build&&e.setState({pinApi:t})}))}},{key:"maybeInit",value:function(){this.state.pinApi?window[this.state.pinApi].f.build():this.maybeFindGlobalPinObj()}},{key:"render",value:function(){var e=this.props.className,t=this.props.attributes,n=t.href,r=t.canvasClassName;return e=o()("pinterest-board-wrapper pk-block-pinterest-board",r,e),wp.element.createElement(v,null,n?wp.element.createElement(O,null,wp.element.createElement("div",{className:e,key:"pin-board-".concat(n)},wp.element.createElement("a",{"data-pin-do":"embedBoard","data-pin-board-width":"100%",href:n}))):wp.element.createElement(w,null,d("Please, enter Pinterest Board URL.")))}}])&&c(t.prototype,n),r&&c(t,r),p}(m);(0,wp.hooks.addFilter)("canvas.customBlock.editRender","canvas/pinterest-board/editRender",(function(e,t){return"canvas/pinterest-board"===t.name?wp.element.createElement(j,t):e}))}]);
@@ -0,0 +1,31 @@
/**
* WordPress dependencies
*/
const {
addFilter,
} = wp.hooks;
/**
* Internal dependencies
*/
import PinterestBoardBlockEdit from './edit.jsx';
/**
* Custom block Edit output for PinterestBoard block.
*
* @param {JSX} edit Original block edit.
* @param {Object} blockProps Block data.
*
* @return {JSX} Block edit.
*/
function editRender( edit, blockProps ) {
if ( 'canvas/pinterest-board' === blockProps.name ) {
return (
<PinterestBoardBlockEdit { ...blockProps } />
);
}
return edit;
}
addFilter( 'canvas.customBlock.editRender', 'canvas/pinterest-board/editRender', editRender );
@@ -0,0 +1,106 @@
/**
* External dependencies
*/
import classnames from 'classnames';
import { debounce } from 'throttle-debounce';
/**
* WordPress dependencies
*/
const { __ } = wp.i18n;
const {
Component,
Fragment,
} = wp.element;
const {
Placeholder,
Disabled,
} = wp.components;
/**
* Component
*/
export default class PinterestBoardBlockEdit extends Component {
constructor() {
super( ...arguments );
this.state = {
pinApi: false,
};
this.maybeFindGlobalPinObj = this.maybeFindGlobalPinObj.bind( this );
this.maybeInit = debounce( 300, this.maybeInit.bind( this ) );
}
componentDidMount() {
this.maybeInit();
}
componentDidUpdate() {
this.maybeInit();
}
/**
* Try to find global Pinterest object.
*/
maybeFindGlobalPinObj() {
Object.keys( window ).forEach( ( k ) => {
if ( /^PIN_\d+$/.test( k ) && window[ k ].f && window[ k ].f.build ) {
this.setState( {
pinApi: k,
} );
}
} );
}
maybeInit() {
if ( ! this.state.pinApi ) {
this.maybeFindGlobalPinObj();
return;
}
window[ this.state.pinApi ].f.build();
}
render() {
let {
className,
} = this.props;
const {
href,
canvasClassName,
} = this.props.attributes;
className = classnames(
'pinterest-board-wrapper pk-block-pinterest-board',
canvasClassName,
className
);
return (
<Fragment>
{ href ? (
<Disabled>
<div
className={ className }
key={ `pin-board-${ href }` }
>
<a
data-pin-do="embedBoard"
data-pin-board-width="100%"
href={ href }
/>
</div>
</Disabled>
) : (
<Placeholder>
{ __( 'Please, enter Pinterest Board URL.' ) }
</Placeholder>
) }
</Fragment>
);
}
}
@@ -0,0 +1,21 @@
<?php
/**
* Pinterest Board block template
*
* @var $attributes - block attributes
* @var $options - layout options
*
* @link https://codesupply.co
* @since 1.0.0
*
* @package PowerKit
* @subpackage PowerKit/templates
*/
$attributes['className'] .= ' pinterest-board-wrapper';
?>
<div class="<?php echo esc_attr( $attributes[ 'className' ] ); ?>" <?php echo ( isset( $attributes[ 'anchor' ] ) ? ' id="' . esc_attr( $attributes[ 'anchor' ] ) . '"' : '' ); ?>>
<a href="<?php echo esc_url( $attributes['href'] ); ?>" data-pin-do="embedBoard" data-pin-board-width="100%"></a>
</div>
@@ -0,0 +1,97 @@
<?php
/**
* Pinterest Board Block.
*
* @link https://codesupply.co
* @since 1.0.0
*
* @package Powerkit
* @subpackage Modules/public
*/
/**
* Initialize Pinterest Board block.
*/
class Powerkit_Block_Pinterest_Board {
/**
* Initialize
*/
public function __construct() {
add_action( 'init', array( $this, 'init' ) );
add_filter( 'canvas_register_block_type', array( $this, 'register_block_type' ) );
}
/**
* Enqueue the block's assets for the editor.
*/
public function init() {
// Editor Scripts.
wp_register_script(
'powerkit-block-pinterest-board-editor-script',
plugins_url( 'block/block.js', __FILE__ ),
array( 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-editor', 'lodash', 'jquery', 'powerkit-pinterest' ),
filemtime( plugin_dir_path( __FILE__ ) . 'block/block.js' ),
true
);
}
/**
* Register block
*
* @param array $blocks all registered blocks.
* @return array
*/
public function register_block_type( $blocks ) {
$blocks[] = array(
'name' => 'canvas/pinterest-board',
'title' => esc_html__( 'Pinterest Board', 'powerkit' ),
'description' => '',
'category' => 'canvas',
'keywords' => array( 'pinterest', 'board' ),
'icon' => '
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<path d="M21 4.92857V19.0714C21 20.1362 20.1362 21 19.0714 21H9.20357C9.59732 20.3411 10.1036 19.3929 10.3045 18.6174C10.425 18.1554 10.9192 16.271 10.9192 16.271C11.2406 16.8857 12.1808 17.404 13.1812 17.404C16.1585 17.404 18.3 14.6679 18.3 11.2688C18.3 8.01027 15.6402 5.57143 12.217 5.57143C7.95804 5.57143 5.7 8.42813 5.7 11.542C5.7 12.9884 6.47143 14.7884 7.70089 15.3629C7.88973 15.4513 7.98616 15.4112 8.03036 15.2304C8.0625 15.0937 8.23125 14.4228 8.30357 14.1134C8.32768 14.0129 8.31563 13.9286 8.23527 13.8321C7.82946 13.3379 7.5 12.4299 7.5 11.5821C7.5 9.40446 9.14732 7.29911 11.9558 7.29911C14.3786 7.29911 16.0781 8.95045 16.0781 11.3129C16.0781 13.9808 14.7321 15.829 12.9763 15.829C12.008 15.829 11.2848 15.0295 11.5138 14.0451C11.7911 12.8719 12.3295 11.6063 12.3295 10.7585C12.3295 8.62902 9.29598 8.92232 9.29598 11.7629C9.29598 12.6348 9.58929 13.2295 9.58929 13.2295C8.32768 18.5652 8.13884 18.6335 8.4 20.9679L8.48839 21H4.92857C3.86384 21 3 20.1362 3 19.0714V4.92857C3 3.86384 3.86384 3 4.92857 3H19.0714C20.1362 3 21 3.86384 21 4.92857Z" />
</svg>
',
'supports' => array(
'className' => true,
'anchor' => true,
'html' => false,
'canvasSpacings' => true,
),
'styles' => array(),
'location' => array(),
'sections' => array(
'general' => array(
'title' => esc_html__( 'Block Settings', 'powerkit' ),
'priority' => 5,
'open' => true,
),
),
'layouts' => array(),
// Set fields just for add block attributes.
// Editor render for this block is custom JSX
// so we don't need to render fields automatically.
'fields' => array(
array(
'key' => 'href',
'label' => esc_html__( 'Pinterest Board URL', 'powerkit' ),
'type' => 'text',
'section' => 'general',
'default' => '',
),
),
'template' => dirname( __FILE__ ) . '/block/render.php',
// enqueue registered scripts/styles.
'editor_script' => 'powerkit-block-pinterest-board-editor-script',
);
return $blocks;
}
}
new Powerkit_Block_Pinterest_Board();
@@ -0,0 +1,113 @@
<?php
/**
* Widget Pinterest Board
*
* @link https://codesupply.co
* @since 1.0.0
*
* @package PowerKit
* @subpackage PowerKit/widgets
*/
/**
* Widget Pinterest Board Class
*/
class Powerkit_Pinterest_Board_Widget extends WP_Widget {
/**
* Sets up a new widget instance.
*/
public function __construct() {
$this->default_settings = apply_filters( 'powerkit_pinterest_board_widget_settings', array(
'title' => esc_html__( 'Pinterest Board', 'powerkit' ),
'href' => '',
) );
$widget_details = array(
'classname' => 'powerkit_pinterest_board_widget',
'description' => esc_html__( 'Add the Pinterest Board widget to your sidebar.', 'powerkit' ),
);
parent::__construct( 'powerkit_pinterest_board_widget', esc_html__( 'Pinterest Board', 'powerkit' ), $widget_details );
}
/**
* Outputs the content for the current widget instance.
*
* @param array $args Display arguments including 'before_title', 'after_title',
* 'before_widget', and 'after_widget'.
* @param array $instance Settings for the current widget instance.
*/
public function widget( $args, $instance ) {
$params = array_merge( $this->default_settings, $instance );
// Before Widget.
echo $args['before_widget']; // XSS OK.
?>
<div class="widget-body">
<?php
// Title.
if ( $params['title'] ) {
echo $args['before_title'] . apply_filters( 'widget_title', wp_kses( $params['title'], 'pk-title' ), $instance, $this->id_base ) . $args['after_title']; // XSS.
}
if ( $params['href'] ) {
?>
<div class="pinterest-board-wrapper">
<a data-pin-do="embedBoard" data-pin-board-width="100%" href="<?php echo esc_attr( $params['href'] ); ?>"></a>
</div>
<?php
} else {
powerkit_alert_warning( esc_html__( 'The "Pinterest Board URL" field is required!', 'powerkit' ) );
}
?>
</div>
<?php
// After Widget.
echo $args['after_widget']; // XSS OK.
}
/**
* Handles updating settings for the current widget instance.
*
* @param array $new_instance New settings for this instance as input by the user via
* WP_Widget::form().
* @param array $old_instance Old settings for this instance.
* @return array Settings to save or bool false to cancel saving.
*/
public function update( $new_instance, $old_instance ) {
$instance = $new_instance;
return $instance;
}
/**
* Outputs the widget settings form.
*
* @param array $instance Current settings.
*/
public function form( $instance ) {
$params = array_merge( $this->default_settings, $instance );
?>
<!-- Title -->
<p><label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'powerkit' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $params['title'] ); ?>" /></p>
<!-- Pinterest Board URL -->
<p><label for="<?php echo esc_attr( $this->get_field_id( 'href' ) ); ?>"><?php esc_html_e( 'Pinterest board URL:', 'powerkit' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'href' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'href' ) ); ?>" type="text" value="<?php echo esc_attr( $params['href'] ); ?>" /></p>
<?php
}
}
/**
* Register Widget
*/
function powerkit_widget_init_pinterest_board() {
register_widget( 'Powerkit_Pinterest_Board_Widget' );
}
add_action( 'widgets_init', 'powerkit_widget_init_pinterest_board' );
@@ -0,0 +1,113 @@
<?php
/**
* Widget Pinterest Profile
*
* @link https://codesupply.co
* @since 1.0.0
*
* @package PowerKit
* @subpackage PowerKit/widgets
*/
/**
* Widget Pinterest Profile Class
*/
class Powerkit_Pinterest_Profile_Widget extends WP_Widget {
/**
* Sets up a new widget instance.
*/
public function __construct() {
$this->default_settings = apply_filters( 'powerkit_pinterest_profile_widget_settings', array(
'title' => esc_html__( 'Pinterest Profile', 'powerkit' ),
'href' => '',
) );
$widget_details = array(
'classname' => 'powerkit_pinterest_profile_widget',
'description' => esc_html__( 'Add the Pinterest Profile widget to your sidebar.', 'powerkit' ),
);
parent::__construct( 'powerkit_pinterest_profile_widget', esc_html__( 'Pinterest Profile', 'powerkit' ), $widget_details );
}
/**
* Outputs the content for the current widget instance.
*
* @param array $args Display arguments including 'before_title', 'after_title',
* 'before_widget', and 'after_widget'.
* @param array $instance Settings for the current widget instance.
*/
public function widget( $args, $instance ) {
$params = array_merge( $this->default_settings, $instance );
// Before Widget.
echo $args['before_widget']; // XSS OK.
?>
<div class="widget-body">
<?php
// Title.
if ( $params['title'] ) {
echo $args['before_title'] . apply_filters( 'widget_title', wp_kses( $params['title'], 'pk-title' ), $instance, $this->id_base ) . $args['after_title']; // XSS.
}
if ( $params['href'] ) {
?>
<div class="pinterest-profile-wrapper">
<a data-pin-do="embedUser" data-pin-board="100%" href="<?php echo esc_attr( $params['href'] ); ?>"></a>
</div>
<?php
} else {
powerkit_alert_warning( esc_html__( 'The "Pinterest Profile URL" field is required!', 'powerkit' ) );
}
?>
</div>
<?php
// After Widget.
echo $args['after_widget']; // XSS OK.
}
/**
* Handles updating settings for the current widget instance.
*
* @param array $new_instance New settings for this instance as input by the user via
* WP_Widget::form().
* @param array $old_instance Old settings for this instance.
* @return array Settings to save or bool false to cancel saving.
*/
public function update( $new_instance, $old_instance ) {
$instance = $new_instance;
return $instance;
}
/**
* Outputs the widget settings form.
*
* @param array $instance Current settings.
*/
public function form( $instance ) {
$params = array_merge( $this->default_settings, $instance );
?>
<!-- Title -->
<p><label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'powerkit' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $params['title'] ); ?>" /></p>
<!-- Pinterest Profile URL -->
<p><label for="<?php echo esc_attr( $this->get_field_id( 'href' ) ); ?>"><?php esc_html_e( 'Pinterest profile URL:', 'powerkit' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'href' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'href' ) ); ?>" type="text" value="<?php echo esc_attr( $params['href'] ); ?>" /></p>
<?php
}
}
/**
* Register Widget
*/
function powerkit_widget_init_pinterest_profile() {
register_widget( 'Powerkit_Pinterest_Profile_Widget' );
}
add_action( 'widgets_init', 'powerkit_widget_init_pinterest_profile' );
@@ -0,0 +1,101 @@
<?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_Pinterest_Public extends Powerkit_Module_Public {
/**
* Initialize
*/
public function initialize() {
add_action( 'init', array( $this, 'init' ) );
add_filter( 'wp_kses_allowed_html', array( $this, 'filter_allowed_html' ), 10, 2 );
add_filter( 'script_loader_tag', array( $this, 'js_attributes' ), 10, 2 );
add_filter( 'powerkit_pinit_exclude_selectors', array( $this, 'pinit_disable' ) );
}
/**
* PinIt disable
*
* @param string $selectors List selectors.
*/
public function pinit_disable( $selectors ) {
$selectors[] = '.wp-block-cover';
return $selectors;
}
/**
* Register pinterest script to use it later.
*/
public function init() {
wp_register_script( 'powerkit-pinterest', '//assets.pinterest.com/js/pinit.js', array(), false, true );
}
/**
* Add custom js attributes.
*
* @since 1.0.0
* @param string $tag The <script> tag for the enqueued script.
* @param string $handle The script's registered handle.
*/
public function js_attributes( $tag, $handle ) {
if ( 'powerkit-pinterest' !== $handle ) {
return $tag;
}
return str_replace( ' src', ' async="async" defer="defer" src', $tag );
}
/**
* Allow pinterest data attributes on our links.
*
* @param array $allowed array The allowed.
* @param string $context string The context.
*/
public function filter_allowed_html( $allowed, $context ) {
if ( 'post' === $context ) {
$allowed['img']['data-pin-description'] = true;
}
return $allowed;
}
/**
* Register the stylesheets for the public-facing side of the site.
*/
public function wp_enqueue_scripts() {
// Styles.
wp_enqueue_style( 'powerkit-pinterest', powerkit_style( plugin_dir_url( __FILE__ ) . 'css/public-powerkit-pinterest.css' ), array(), powerkit_get_setting( 'version' ), 'all' );
// Add RTL support.
wp_style_add_data( 'powerkit-pinterest', 'rtl', 'replace' );
// Scripts.
wp_enqueue_script( 'powerkit-pin-it', plugin_dir_url( __FILE__ ) . 'js/public-powerkit-pin-it.js', array( 'powerkit-pinterest', 'jquery', 'imagesloaded' ), powerkit_get_setting( 'version' ), true );
$image_selectors = get_option( 'powerkit_pinit_image_selectors', array( '.entry-content img' ) );
$exclude_selectors = get_option( 'powerkit_pinit_exclude_selectors', array() );
$image_selectors = powerkit_pinit_process_selectors( $image_selectors );
$exclude_selectors = powerkit_pinit_process_selectors( $exclude_selectors );
$image_selectors = apply_filters( 'powerkit_pinit_image_selectors', $image_selectors );
$exclude_selectors = apply_filters( 'powerkit_pinit_exclude_selectors', $exclude_selectors );
wp_localize_script( 'powerkit-pin-it', 'powerkit_pinit_localize', array(
'image_selectors' => implode( ',', $image_selectors ),
'exclude_selectors' => implode( ',', $exclude_selectors ),
'only_hover' => get_option( 'powerkit_pinit_only_hover', true ),
) );
}
}
@@ -0,0 +1,112 @@
<?php
/**
* Shortcodes Pinterest
*
* @link https://codesupply.co
* @since 1.0.0
*
* @package PowerKit
* @subpackage PowerKit/shortcodes
*/
/**
* Pinterest Board Shortcode
*
* @param array $atts User defined attributes in shortcode tag.
* @param string $content Shorcode tag content.
* @return string Shortcode result HTML.
*/
function powerkit_pinterest_board_shortcode( $atts, $content = '' ) {
$params = powerkit_shortcode_atts( shortcode_atts( array(
'href' => '',
), $atts ) );
ob_start();
if ( $params['href'] ) {
?>
<div class="pinterest-board-wrapper">
<a data-pin-do="embedBoard" data-pin-board-width="100%" href="<?php echo esc_attr( $params['href'] ); ?>"></a>
</div>
<?php
} else {
powerkit_alert_warning( esc_html__( 'The "Pinterest Board URL" field is required!', 'powerkit' ) );
}
return ob_get_clean();
}
add_shortcode( 'powerkit_pinterest_board', 'powerkit_pinterest_board_shortcode' );
/**
* Map Pinterest Board Shortcode into the Basic Shortcodes Plugin
*/
if ( function_exists( 'powerkit_basic_shortcodes_register' ) ) :
powerkit_basic_shortcodes_register( array(
'name' => 'pinterest_board',
'title' => esc_html__( 'Pinterest Board', 'powerkit' ),
'priority' => 150,
'base' => 'powerkit_pinterest_board',
'autoregister' => false,
'fields' => array(
array(
'type' => 'input',
'name' => 'href',
'label' => esc_html__( 'Pinterest board URL', 'powerkit' ),
),
),
) );
endif;
/**
* Pinterest Profile Shortcode
*
* @param array $atts User defined attributes in shortcode tag.
* @param string $content Shorcode tag content.
* @return string Shortcode result HTML.
*/
function powerkit_pinterest_profile_shortcode( $atts, $content = '' ) {
$params = powerkit_shortcode_atts( shortcode_atts( array(
'href' => '',
), $atts ) );
ob_start();
if ( $params['href'] ) {
?>
<div class="pinterest-profile-wrapper">
<a data-pin-do="embedUser" data-pin-board="100%" href="<?php echo esc_attr( $params['href'] ); ?>"></a>
</div>
<?php
} else {
powerkit_alert_warning( esc_html__( 'The "Pinterest Profile URL" field is required!', 'powerkit' ) );
}
return ob_get_clean();
}
add_shortcode( 'powerkit_pinterest_profile', 'powerkit_pinterest_profile_shortcode' );
/**
* Map Pinterest Profile Shortcode into the Basic Shortcodes Plugin
*/
if ( function_exists( 'powerkit_basic_shortcodes_register' ) ) :
powerkit_basic_shortcodes_register( array(
'name' => 'pinterest_profile',
'title' => esc_html__( 'Pinterest Profile', 'powerkit' ),
'priority' => 150,
'base' => 'powerkit_pinterest_profile',
'autoregister' => false,
'fields' => array(
array(
'type' => 'input',
'name' => 'href',
'label' => esc_html__( 'Pinterest profile URL', 'powerkit' ),
),
),
) );
endif;
@@ -0,0 +1,90 @@
/**
* All of the CSS for your public-facing functionality should be
* included in this file.
*/
/**
* Environment for all styles (variables, additions, etc).
*/
/*--------------------------------------------------------------*/
/*--------------------------------------------------------------*/
.pk-pin-it {
--pk-pinterest-pinit-background: rgba(0,0,0,0.25);
--pk-pinterest-pinit-background-hover: rgba(0,0,0,0.5);
--pk-pinterest-pinit-color: #FFFFFF;
--pk-pinterest-pinit-color-hover: #FFFFFF;
--pk-pinterest-pinit-font-size: 16px;
}
/*--------------------------------------------------------------*/
.pk-pin-it-container {
position: relative;
max-width: 100%;
}
@-webkit-keyframes pk_pin_it_show {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@keyframes pk_pin_it_show {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
.pk-pin-it {
position: absolute;
top: 1rem;
right: 1rem;
color: var(--pk-pinterest-pinit-color) !important;
text-decoration: none !important;
border: none !important;
box-shadow: none !important;
background-color: var(--pk-pinterest-pinit-background);
width: 2.5rem;
height: 2.5rem;
line-height: 2.5rem;
font-size: var(--pk-pinterest-pinit-font-size);
text-align: center;
opacity: 1;
transition: background-color 0.25s ease;
z-index: 2;
}
.pk-pin-it:hover {
background-color: var(--pk-pinterest-pinit-background-hover);
color: var(--pk-pinterest-pinit-color-hover);
}
.pk-pin-it span:first-child {
display: none;
}
.pk-pin-it.pk-pin-it-visible {
-webkit-animation: pk_pin_it_show 0.25s ease;
animation: pk_pin_it_show 0.25s ease;
}
.wp-block-gallery .blocks-gallery-image .pk-pin-it,
.wp-block-gallery .blocks-gallery-item
.wp-block-gallery.is-cropped .blocks-gallery-image .pk-pin-it,
.wp-block-gallery.is-cropped .blocks-gallery-item .pk-pin-it {
width: 2.5rem;
height: 2.5rem;
line-height: 2.5rem;
}
.wp-block-gallery figure.wp-block-image a.pk-pin-it {
display: block !important;
width: initial !important;
height: initial !important;
flex: initial !important;
min-width: 32px;
}
@@ -0,0 +1,90 @@
/**
* All of the CSS for your public-facing functionality should be
* included in this file.
*/
/**
* Environment for all styles (variables, additions, etc).
*/
/*--------------------------------------------------------------*/
/*--------------------------------------------------------------*/
.pk-pin-it {
--pk-pinterest-pinit-background: rgba(0,0,0,0.25);
--pk-pinterest-pinit-background-hover: rgba(0,0,0,0.5);
--pk-pinterest-pinit-color: #FFFFFF;
--pk-pinterest-pinit-color-hover: #FFFFFF;
--pk-pinterest-pinit-font-size: 16px;
}
/*--------------------------------------------------------------*/
.pk-pin-it-container {
position: relative;
max-width: 100%;
}
@-webkit-keyframes pk_pin_it_show {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@keyframes pk_pin_it_show {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
.pk-pin-it {
position: absolute;
top: 1rem;
left: 1rem;
color: var(--pk-pinterest-pinit-color) !important;
text-decoration: none !important;
border: none !important;
box-shadow: none !important;
background-color: var(--pk-pinterest-pinit-background);
width: 2.5rem;
height: 2.5rem;
line-height: 2.5rem;
font-size: var(--pk-pinterest-pinit-font-size);
text-align: center;
opacity: 1;
transition: background-color 0.25s ease;
z-index: 2;
}
.pk-pin-it:hover {
background-color: var(--pk-pinterest-pinit-background-hover);
color: var(--pk-pinterest-pinit-color-hover);
}
.pk-pin-it span:first-child {
display: none;
}
.pk-pin-it.pk-pin-it-visible {
-webkit-animation: pk_pin_it_show 0.25s ease;
animation: pk_pin_it_show 0.25s ease;
}
.wp-block-gallery .blocks-gallery-image .pk-pin-it,
.wp-block-gallery .blocks-gallery-item
.wp-block-gallery.is-cropped .blocks-gallery-image .pk-pin-it,
.wp-block-gallery.is-cropped .blocks-gallery-item .pk-pin-it {
width: 2.5rem;
height: 2.5rem;
line-height: 2.5rem;
}
.wp-block-gallery figure.wp-block-image a.pk-pin-it {
display: block !important;
width: initial !important;
height: initial !important;
flex: initial !important;
min-width: 32px;
}
@@ -0,0 +1,174 @@
/**
* Pin It
*/
( function( $ ) {
$.fn.powerkitPinIt = function() {
$( this ).each( function() {
if ( $( this ).hasClass( 'pk-pin-it-ready' ) ) {
return;
}
var width = $( this ).attr( 'width' );
var height = $( this ).attr( 'height' );
if ( typeof width === 'undefined' ) {
width = $( this ).width();
}
if ( typeof height === 'undefined' ) {
height = $( this ).height();
}
if ( !( parseInt( width ) > 120 && parseInt( height ) > 120 ) ) {
$( this ).addClass( 'pk-pin-it-ready' );
return;
}
var container = $( this ).parent(),
postURL = $( location ).attr( 'href' ),
pinURL;
if ( $( container ).is( 'a' ) ) {
var imagehref = $( container ).attr( 'href' );
if ( typeof imagehref !== 'undefined' && imagehref.match( /\.(gif|jpeg|jpg|png|webp)/ ) ) {
pinURL = imagehref;
}
if ( !( $( container ).closest( 'figure' ).length ) ) {
$( container ).wrap( '<figure class="pk-pin-it-container"></figure>' );
}
container = $( container ).parent();
} else {
if ( !( $( container ).is( 'figure' ) || $( container ).closest( 'figure' ).length ) ) {
$( this ).wrap( '<figure class="pk-pin-it-container"></figure>' );
}
container = $( this ).parent();
}
if ( !$( this ).closest( 'figure' ).hasClass( 'pk-pin-it-container' ) ) {
$( this ).closest( 'figure' ).addClass( 'pk-pin-it-container' );
}
if ( ! pinURL ) {
if ( $( this ).is( 'img' ) ) {
pinURL = ( typeof $( this ).data( 'pk-src' ) !== 'undefined' ) ? $( this ).data( 'pk-src' ) : $( this ).attr( 'src' );
} else {
pinURL = ( typeof $( container ).find( 'img' ).data( 'src' ) !== 'undefined' ) ? $( container ).find( 'img' ).data( 'src' ) : $( container ).find( 'img' ).attr( 'src' );
}
}
pinURL = encodeURIComponent( pinURL );
postURL = encodeURIComponent( postURL );
var figure = container;
if ( ! $( container ).is( 'figure' ) ) {
figure = $( container ).closest( 'figure' );
}
// Get caption text.
var imgDescription = $( figure ).find( 'img' ).data( 'pin-description' );
if ( !imgDescription ) {
imgDescription = $( figure ).find( '.wp-caption-text' ).text();
}
if ( !imgDescription ) {
imgDescription = $( figure ).find( 'figcaption' ).text();
}
if ( !imgDescription ) {
imgDescription = $( figure ).find( 'img' ).attr( 'alt' );
}
if ( imgDescription ) {
// Add attribute to share URL.
imgDescription = '&amp;description=' + encodeURIComponent( imgDescription );
}
// Img classes.
var imgClasses = [ 'alignnone', 'aligncenter', 'alignleft', 'alignright' ];
imgClasses.forEach( function( el ) {
if ( $( container ).find( 'img' ).hasClass( el ) ) {
$( container ).find( 'img' ).removeClass( el );
$( container ).find( 'img' ).closest( 'figure' ).addClass( el );
// Add width to figure.
var imgWidth = $( container ).find( 'img' ).attr( 'width' );
if ( parseInt( imgWidth ) !== 'NaN' ) {
$( container ).find( 'img' ).closest( 'figure' ).width( imgWidth );
}
}
} );
// Add func PintIt.
var addPowerkitPintIt = function( container ) {
if ( ! $( container ).find( '.pk-pin-it' ).length ) {
$( '<a class="pk-pin-it" href="http://www.pinterest.com/pin/create/bookmarklet/?url=' + postURL + '&amp;media=' + pinURL + imgDescription + '&is_video=false" target="_blank"><span>Pin</span><span><i class="pk-icon pk-icon-pinterest"></i></span></a>' )
.appendTo( container )
.addClass( 'pk-pin-it-visible' );
}
}
// PintIt Mode.
if ( powerkit_pinit_localize.only_hover ) {
$( container ).mousemove(function(){
addPowerkitPintIt( this );
});
$( container ).mouseleave(function(){
var $this = this;
$( $this ).children( '.pk-pin-it' ).fadeOut( 200, function(){
$( $this ).children( '.pk-pin-it' ).remove();
});
});
} else {
addPowerkitPintIt( container );
}
$( this ).addClass( 'pk-pin-it-ready' );
} );
};
function initPowerkitPinIt() {
// Exclude.
var filterPowerkitPinIt = function() {
var exclude = powerkit_pinit_localize.exclude_selectors;
if ( exclude ) {
if ( $( this ).closest( exclude ).length > 0 ) {
return false;
}
}
return true;
}
// Init.
$( powerkit_pinit_localize.image_selectors ).imagesLoaded( function() {
$( powerkit_pinit_localize.image_selectors ).filter( filterPowerkitPinIt ).powerkitPinIt();
} );
}
$( document ).ready( function() {
initPowerkitPinIt();
$( document.body ).on( 'post-load image-load', function() {
initPowerkitPinIt();
} );
} );
} )( jQuery );