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,58 @@
<?php
/**
* Contributors
*
* @package Powerkit
* @subpackage Modules
*/
if ( class_exists( 'Powerkit_Module' ) ) {
/**
* Init module
*/
class Powerkit_Contributors extends Powerkit_Module {
/**
* Register module
*/
public function register() {
$this->name = esc_html__( 'Contributors', 'powerkit' );
$this->desc = esc_html__( 'Display a list of your site authors (contributors) in your sidebar, including author name, bio, and avatar in multiple available layouts.', 'powerkit' );
$this->slug = 'contributors';
$this->type = 'default';
$this->category = 'content';
$this->priority = 150;
$this->public = true;
$this->enabled = true;
$this->links = array(
array(
'name' => esc_html__( 'View documentation', 'powerkit' ),
'url' => powerkit_get_setting( 'documentation' ) . '/contributors/',
'target' => '_blank',
),
);
}
/**
* Initialize module
*/
public function initialize() {
// Helpers Functions for the module.
require_once dirname( __FILE__ ) . '/helpers/helper-powerkit-contributors.php';
// The classes responsible for defining all actions.
require_once dirname( __FILE__ ) . '/public/class-powerkit-contributors-widget.php';
if ( function_exists( 'register_block_type' ) ) {
require_once dirname( __FILE__ ) . '/public/class-powerkit-contributors-block.php';
}
// Admin and public area.
require_once dirname( __FILE__ ) . '/public/class-powerkit-contributors-public.php';
new Powerkit_Contributors_Public( $this->slug );
}
}
new Powerkit_Contributors();
}
@@ -0,0 +1,137 @@
<?php
/**
* Helpers Contributors
*
* @package Powerkit
* @subpackage Modules/Helper
*/
/**
* Get html of contributors block
*
* @param array $params Recent options.
* @param string $args Widget args.
*/
function powerkit_contributors_get_html( $params, $args ) {
$params = array_merge(
array(
'title' => '',
'filter_ids' => '',
'avatar' => true,
'social_accounts' => true,
'bio' => true,
'recent_posts' => false,
'recent_posts_count' => 3,
),
$params
);
// Before Widget.
echo $args['before_widget']; // XSS.
// Title.
if ( $params['title'] ) {
echo $args['before_title'] . wp_kses( $params['title'], 'pk-title' ) . $args['after_title']; // XSS.
}
// Content.
?>
<div class="widget-body">
<?php
$authors = powerkit_get_users();
$avatar_size = apply_filters( 'powerkit_widget_coauthors_avatar_size', 80 );
if ( isset( $authors ) && ! empty( $authors ) ) {
?>
<div class="pk-widget-contributors">
<?php
foreach ( $authors as $author ) {
// Filters ids.
if ( $params['filter_ids'] ) {
$filter_ids = explode( ',', str_replace( ' ', '', $params['filter_ids'] ) );
if ( ! in_array( (string) $author->ID, $filter_ids, true ) ) {
continue;
}
}
?>
<div class="pk-author-item">
<?php if ( $params['avatar'] ) { ?>
<div class="pk-author-avatar">
<a href="<?php echo esc_url( get_author_posts_url( $author->ID ) ); ?>" rel="author">
<?php echo get_avatar( $author->ID, $avatar_size ); ?>
</a>
</div>
<?php } ?>
<div class="pk-author-data">
<?php $tag = apply_filters( 'powerkit_widget_contributors_author_name', 'h6' ); ?>
<<?php echo esc_html( $tag ); ?> class="author-name">
<a href="<?php echo esc_url( get_author_posts_url( $author->ID ) ); ?>" rel="author">
<?php echo esc_html( get_the_author_meta( 'display_name', $author->ID ) ); ?>
</a>
</<?php echo esc_html( $tag ); ?>>
<?php
if ( $params['bio'] ) :
$author_description = get_the_author_meta( 'description', $author->ID );
?>
<div class="author-description pk-color-secondary">
<?php echo wp_kses_post( powerkit_str_truncate( $author_description, apply_filters( 'powerkit_widget_contributors_description_length', 100 ) ) ); ?>
</div>
<?php endif; ?>
<?php
if ( $params['social_accounts'] && powerkit_module_enabled( 'social_links' ) ) {
powerkit_author_social_links( $author->ID, 'template-nav' );
}
?>
<?php
if ( $params['recent_posts'] && $params['recent_posts_count'] ) {
$author_posts = get_posts(
array(
'author' => $author->ID,
'posts_per_page' => $params['recent_posts_count'],
)
);
if ( ! empty( $author_posts ) ) {
?>
<div class="pk-author-posts">
<h6><?php echo sprintf( esc_html__( 'Latest from %s:', 'powerkit' ), get_the_author_meta( 'display_name', $author->ID ) ); ?></h6>
<?php
foreach ( $author_posts as $post ) {
?>
<div class="pk-author-posts-single">
<a href="<?php echo esc_url( get_permalink( $post->ID ) ); ?>"><?php echo esc_html( get_the_title( $post->ID ) ); ?></a>
</div>
<?php
}
?>
</div>
<?php
}
}
?>
</div>
</div>
<?php
}
?>
</div>
<?php
}
?>
</div>
<?php
// After Widget.
echo $args['after_widget']; // XSS.
}
@@ -0,0 +1,41 @@
<?php
/**
* Contributors 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' => '',
'filter_ids' => implode( ',', (array) $attributes['contributors'] ),
'avatar' => $attributes['showAvatar'],
'social_accounts' => $attributes['showSocialAccounts'],
'bio' => $attributes['showBio'],
'recent_posts' => $attributes['showRecentPosts'],
'recent_posts_count' => isset( $attributes['countRecentPosts'] ) ? $attributes['countRecentPosts'] : 0,
);
echo '<div class="' . esc_attr( $attributes['className'] ) . '" ' . ( isset( $attributes['anchor'] ) ? ' id="' . esc_attr( $attributes['anchor'] ) . '"' : '' ) . '>';
// Title.
if ( $params['title'] ) {
$params['title'] = '<h5 class="pk-contributors-title">' . $params['title'] . '<h5>';
}
$args = array(
'before_title' => '',
'after_title' => '',
'before_widget' => '',
'after_widget' => '',
);
powerkit_contributors_get_html( $params, $args );
echo '</div>';
@@ -0,0 +1,151 @@
<?php
/**
* The Gutenberg Block.
*
* @link https://codesupply.co
* @since 1.0.0
*
* @package Powerkit
* @subpackage Modules/public
*/
/**
* The initialize block.
*/
class Powerkit_Contributors_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-contributors-block-editor-style',
plugins_url( 'css/public-powerkit-contributors.css', __FILE__ ),
array( 'wp-edit-blocks' ),
filemtime( plugin_dir_path( __FILE__ ) . 'css/public-powerkit-contributors.css' )
);
wp_style_add_data( 'powerkit-contributors-block-editor-style', 'rtl', 'replace' );
}
/**
* Register block
*
* @param array $blocks all registered blocks.
* @return array
*/
public function register_block_type( $blocks ) {
$users = powerkit_get_users();
$users_choices = array();
foreach ( $users as $user ) {
$users_choices[ $user->ID ] = $user->display_name;
}
$blocks[] = array(
'name' => 'canvas/contributors',
'title' => esc_html__( 'Contributors', 'powerkit' ),
'description' => '',
'category' => 'canvas',
'keywords' => array(),
'icon' => '
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<path d="M12.51 9.99C12.51 8.34 11.16 6.99 9.51 6.99C7.86 6.99 6.51 8.34 6.51 9.99C6.51 11.64 7.86 12.99 9.51 12.99C11.16 12.99 12.51 11.64 12.51 9.99ZM9.51 10.99C8.96 10.99 8.51 10.54 8.51 9.99C8.51 9.44 8.96 8.99 9.51 8.99C10.06 8.99 10.51 9.44 10.51 9.99C10.51 10.54 10.06 10.99 9.51 10.99ZM16.01 12.99C17.12 12.99 18.01 12.1 18.01 10.99C18.01 9.88 17.12 8.99 16.01 8.99C14.9 8.99 14 9.88 14.01 10.99C14.01 12.1 14.9 12.99 16.01 12.99ZM12 2C6.48 2 2 6.48 2 12C2 17.52 6.48 22 12 22C17.52 22 22 17.52 22 12C22 6.48 17.52 2 12 2V2ZM5.85 17.11C6.53 16.57 8.12 16 9.51 16C9.58 16 9.66 16.01 9.74 16.01C9.98 15.37 10.41 14.72 11.04 14.15C10.48 14.05 9.95 13.99 9.51 13.99C8.21 13.99 6.12 14.44 4.78 15.42C4.28 14.38 4 13.22 4 11.99C4 7.58 7.59 3.99 12 3.99C16.41 3.99 20 7.58 20 11.99C20 13.19 19.73 14.33 19.25 15.36C18.25 14.77 16.89 14.49 16.01 14.49C14.49 14.49 11.51 15.3 11.51 17.19V19.97C9.24 19.84 7.22 18.76 5.85 17.11V17.11Z" />
</svg>
',
'supports' => array(
'className' => true,
'anchor' => true,
'html' => false,
'canvasSpacings' => true,
'canvasBorder' => true,
'canvasResponsive' => true,
),
'styles' => array(),
'location' => array(),
'sections' => array(
'general' => array(
'title' => esc_html__( 'Block Settings', 'powerkit' ),
'priority' => 5,
'open' => true,
),
),
'layouts' => array(),
'fields' => array(
array(
'key' => 'contributors',
'label' => esc_html__( 'Contributors', 'powerkit' ),
'section' => 'general',
'type' => 'react-select',
'choices' => $users_choices,
'multiple' => true,
'default' => array(),
'items' => array(
'type' => 'integer',
),
),
array(
'key' => 'showAvatar',
'label' => esc_html__( 'Display Avatar', 'powerkit' ),
'section' => 'general',
'type' => 'toggle',
'default' => true,
),
array(
'key' => 'showSocialAccounts',
'label' => esc_html__( 'Display Social Links', 'powerkit' ),
'section' => 'general',
'type' => 'toggle',
'default' => true,
),
array(
'key' => 'showBio',
'label' => esc_html__( 'Display Bio', 'powerkit' ),
'section' => 'general',
'type' => 'toggle',
'default' => true,
),
array(
'key' => 'showRecentPosts',
'label' => esc_html__( 'Display Recent Posts', 'powerkit' ),
'section' => 'general',
'type' => 'toggle',
'default' => false,
),
array(
'key' => 'countRecentPosts',
'label' => esc_html__( 'Number of Recent Posts', 'powerkit' ),
'section' => 'general',
'type' => 'number',
'step' => 1,
'min' => 0,
'max' => 1000,
'default' => 3,
'active_callback' => array(
array(
'field' => 'showRecentPosts',
),
),
),
),
'template' => dirname( __FILE__ ) . '/block/render.php',
// enqueue registered scripts/styles.
'editor_style' => 'powerkit-contributors-block-editor-style',
);
return $blocks;
}
}
new Powerkit_Contributors_Block();
@@ -0,0 +1,26 @@
<?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_Contributors_Public extends Powerkit_Module_Public {
/**
* Register the stylesheets for the public-facing side of the site.
*/
public function wp_enqueue_scripts() {
wp_enqueue_style( 'powerkit-сontributors', powerkit_style( plugin_dir_url( __FILE__ ) . 'css/public-powerkit-contributors.css' ), array(), powerkit_get_setting( 'version' ), 'all' );
// Add RTL support.
wp_style_add_data( 'powerkit-сontributors', 'rtl', 'replace' );
}
}
@@ -0,0 +1,119 @@
<?php
/**
* Widget Contributors
*
* @link https://codesupply.co
* @since 1.0.0
*
* @package Powerkit
* @subpackage Powerkit/widgets
*/
/**
* Contributors
*/
class Powerkit_Contributors_Widget extends WP_Widget {
/**
* Sets up a new widget instance.
*/
public function __construct() {
$this->default_settings = apply_filters( 'powerkit_widget_contributors_settings', array(
'title' => esc_html__( 'Contributors', 'powerkit' ),
'filter_ids' => '',
'avatar' => true,
'social_accounts' => true,
) );
$widget_details = array(
'classname' => 'powerkit_widget_contributors',
'description' => '',
);
parent::__construct( 'powerkit_widget_contributors', esc_html__( 'Contributors', '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 );
// Title.
if ( $params['title'] ) {
$params['title'] = apply_filters( 'widget_title', $params['title'], $instance, $this->id_base );
}
powerkit_contributors_get_html( $params, $args );
}
/**
* 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;
// Display avatar.
if ( ! isset( $instance['avatar'] ) ) {
$instance['avatar'] = false;
}
// Display social accounts.
if ( ! isset( $instance['social_accounts'] ) ) {
$instance['social_accounts'] = false;
}
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>
<!-- Filter by Authors -->
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'filter_ids' ) ); ?>"><?php esc_html_e( 'Filter by authors:', 'powerkit' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'filter_ids' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'filter_ids' ) ); ?>" type="text" value="<?php echo esc_attr( $params['filter_ids'] ); ?>" />
</p>
<p class="help"><?php esc_html_e( 'Add comma-separated list of authors IDs. For example: 1, 2, 3. Leave empty for all authors.' ); ?></p>
<!-- Display avatar -->
<p><input id="<?php echo esc_attr( $this->get_field_id( 'avatar' ) ); ?>" class="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'avatar' ) ); ?>" type="checkbox" <?php checked( (bool) $params['avatar'] ); ?> />
<label for="<?php echo esc_attr( $this->get_field_id( 'avatar' ) ); ?>"><?php esc_html_e( 'Display avatar', 'powerkit' ); ?></label></p>
<?php if ( powerkit_module_enabled( 'social_links' ) ) : ?>
<!-- Display social accounts -->
<p><input id="<?php echo esc_attr( $this->get_field_id( 'social_accounts' ) ); ?>" class="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'social_accounts' ) ); ?>" type="checkbox" <?php checked( (bool) $params['social_accounts'] ); ?> />
<label for="<?php echo esc_attr( $this->get_field_id( 'social_accounts' ) ); ?>"><?php esc_html_e( 'Display social accounts', 'powerkit' ); ?></label></p>
<?php endif; ?>
<?php
}
}
/**
* Register Widget
*/
function powerkit_widget_init_contributors() {
register_widget( 'Powerkit_Contributors_Widget' );
}
add_action( 'widgets_init', 'powerkit_widget_init_contributors' );
@@ -0,0 +1,107 @@
/**
* All of the CSS for your public-facing functionality should be
* included in this file.
*/
/**
* Environment for all styles (variables, additions, etc).
*/
/*--------------------------------------------------------------*/
/*--------------------------------------------------------------*/
.pk-widget-contributors {
--pk-contributors-item-border-color: #eeeeee;
--pk-contributors-post-arrow-color: #ced4da;
--pk-contributors-post-arrow-color-hover: #fff;
--pk-contributors-post-arrow-backgroynd-hover: #6c757d;
--pk-contributors-avatar-border-radius: 100%;
--pk-contributors-post-arrow-border-radius: 100%;
--pk-contributors-description-font-size: 80%;
--pk-contributors-post-link-font-size: 0.875rem;
--pk-contributors-post-link-line-height: 1.25rem;
--pk-contributors-post-arrow-font-size: 14px;
}
/*--------------------------------------------------------------*/
.pk-widget-contributors .pk-author-item {
display: flex;
margin-top: 1rem;
padding-top: 1rem;
border-top: 1px var(--pk-contributors-item-border-color) solid;
}
.pk-widget-contributors .pk-author-item:first-child {
margin-top: 0;
padding-top: 0;
border-top: none;
}
.pk-widget-contributors .pk-author-avatar {
flex: 0 0 80px;
width: 80px;
height: 80px;
margin-left: 1rem;
-o-object-fit: cover;
object-fit: cover;
font-family: 'object-fit: cover;';
}
.pk-widget-contributors .pk-author-avatar img {
border-radius: var(--pk-contributors-avatar-border-radius);
}
.pk-widget-contributors .pk-author-data {
flex-grow: 1;
width: 100%;
}
.pk-widget-contributors .pk-author-data .author-name {
margin-top: 0;
margin-bottom: .5rem;
}
.pk-widget-contributors .pk-author-data .author-description {
font-size: var(--pk-contributors-description-font-size);
margin-bottom: .5rem;
}
.pk-widget-contributors .pk-social-links-wrap {
margin-top: .5rem;
}
.pk-widget-contributors .pk-author-posts {
margin-top: 2rem;
}
.pk-widget-contributors .pk-author-posts > .pk-author-posts-single > a {
display: flex;
padding-top: 0.25rem;
padding-bottom: 0.25rem;
position: relative;
padding-right: 2rem;
font-size: var(--pk-contributors-post-link-font-size);
line-height: var(--pk-contributors-post-link-line-height);
}
.pk-widget-contributors .pk-author-posts > .pk-author-posts-single > a:before {
position: absolute;
right: 0;
top: 4px;
font-family: 'powerkit-icons';
content: "\e940";
color: var(--pk-contributors-post-arrow-color);
font-size: var(--pk-contributors-post-arrow-font-size);
margin-left: 1rem;
display: inline-block;
transition: .2s ease all;
display: flex;
align-items: center;
justify-content: center;
width: 20px;
height: 20px;
border-radius: var(--pk-contributors-post-arrow-border-radius);
}
.pk-widget-contributors .pk-author-posts > .pk-author-posts-single > a:hover:before {
color: var(--pk-contributors-post-arrow-color-hover);
transition: .2s ease all;
background: var(--pk-contributors-post-arrow-backgroynd-hover);
}
@@ -0,0 +1,107 @@
/**
* All of the CSS for your public-facing functionality should be
* included in this file.
*/
/**
* Environment for all styles (variables, additions, etc).
*/
/*--------------------------------------------------------------*/
/*--------------------------------------------------------------*/
.pk-widget-contributors {
--pk-contributors-item-border-color: #eeeeee;
--pk-contributors-post-arrow-color: #ced4da;
--pk-contributors-post-arrow-color-hover: #fff;
--pk-contributors-post-arrow-backgroynd-hover: #6c757d;
--pk-contributors-avatar-border-radius: 100%;
--pk-contributors-post-arrow-border-radius: 100%;
--pk-contributors-description-font-size: 80%;
--pk-contributors-post-link-font-size: 0.875rem;
--pk-contributors-post-link-line-height: 1.25rem;
--pk-contributors-post-arrow-font-size: 14px;
}
/*--------------------------------------------------------------*/
.pk-widget-contributors .pk-author-item {
display: flex;
margin-top: 1rem;
padding-top: 1rem;
border-top: 1px var(--pk-contributors-item-border-color) solid;
}
.pk-widget-contributors .pk-author-item:first-child {
margin-top: 0;
padding-top: 0;
border-top: none;
}
.pk-widget-contributors .pk-author-avatar {
flex: 0 0 80px;
width: 80px;
height: 80px;
margin-right: 1rem;
-o-object-fit: cover;
object-fit: cover;
font-family: 'object-fit: cover;';
}
.pk-widget-contributors .pk-author-avatar img {
border-radius: var(--pk-contributors-avatar-border-radius);
}
.pk-widget-contributors .pk-author-data {
flex-grow: 1;
width: 100%;
}
.pk-widget-contributors .pk-author-data .author-name {
margin-top: 0;
margin-bottom: .5rem;
}
.pk-widget-contributors .pk-author-data .author-description {
font-size: var(--pk-contributors-description-font-size);
margin-bottom: .5rem;
}
.pk-widget-contributors .pk-social-links-wrap {
margin-top: .5rem;
}
.pk-widget-contributors .pk-author-posts {
margin-top: 2rem;
}
.pk-widget-contributors .pk-author-posts > .pk-author-posts-single > a {
display: flex;
padding-top: 0.25rem;
padding-bottom: 0.25rem;
position: relative;
padding-left: 2rem;
font-size: var(--pk-contributors-post-link-font-size);
line-height: var(--pk-contributors-post-link-line-height);
}
.pk-widget-contributors .pk-author-posts > .pk-author-posts-single > a:before {
position: absolute;
left: 0;
top: 4px;
font-family: 'powerkit-icons';
content: "\e940";
color: var(--pk-contributors-post-arrow-color);
font-size: var(--pk-contributors-post-arrow-font-size);
margin-right: 1rem;
display: inline-block;
transition: .2s ease all;
display: flex;
align-items: center;
justify-content: center;
width: 20px;
height: 20px;
border-radius: var(--pk-contributors-post-arrow-border-radius);
}
.pk-widget-contributors .pk-author-posts > .pk-author-posts-single > a:hover:before {
color: var(--pk-contributors-post-arrow-color-hover);
transition: .2s ease all;
background: var(--pk-contributors-post-arrow-backgroynd-hover);
}