elementor
3 years ago
admin-create-shortcode.php
7 years ago
admin-create-user.php
3 years ago
admin-custom-function.php
3 years ago
admin-rest-api.php
4 years ago
admin-settings.php
3 years ago
admin-social-button.php
3 years ago
admin-social-enque-script.php
5 years ago
counter-widget.php
3 years ago
counter.php
3 years ago
custom-function.php
4 years ago
login-widget.php
3 years ago
login.php
5 years ago
share-widget.php
3 years ago
share.php
3 years ago
counter-widget.php
180 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WP_Social\Inc; |
| 4 | |
| 5 | use WP_Social\App\Providers; |
| 6 | |
| 7 | defined('ABSPATH') || exit; |
| 8 | |
| 9 | |
| 10 | /** |
| 11 | * Class Name : Counter_Widget; |
| 12 | * Class Details : Create Widget for XS Social Login Plugin |
| 13 | * |
| 14 | * @params : void |
| 15 | * @return : void |
| 16 | * |
| 17 | * @since : 1.0 |
| 18 | */ |
| 19 | class Counter_Widget extends \WP_Widget { |
| 20 | |
| 21 | public $styleArr = []; |
| 22 | public $providers = []; |
| 23 | private $hover_effect = []; |
| 24 | |
| 25 | public function __construct() { |
| 26 | |
| 27 | $widget_ops = array( |
| 28 | 'classname' => 'xs_counter-widget', |
| 29 | 'description' => __('Wp Social Login System for Facebook, Twitter, Linkedin, Dribble, Pinterest, Post, Comments counter.', 'wp-social') |
| 30 | ); |
| 31 | |
| 32 | parent::__construct('Counter_Widget', __('WSLU Social Counter', 'wp-social'), $widget_ops, []); |
| 33 | |
| 34 | $this->styleArr = \WP_Social\Inc\Admin_Settings::counter_styles(); |
| 35 | } |
| 36 | |
| 37 | public static function register() { |
| 38 | |
| 39 | register_widget('WP_Social\Inc\Counter_Widget'); |
| 40 | } |
| 41 | |
| 42 | |
| 43 | /** |
| 44 | * |
| 45 | * @param $args |
| 46 | * @param $instance |
| 47 | */ |
| 48 | public function widget($args, $instance) { |
| 49 | |
| 50 | extract($args); |
| 51 | |
| 52 | $title = isset($instance['title']) ? $instance['title'] : ''; |
| 53 | $layout = isset($instance['layout']) ? $instance['layout'] : ''; |
| 54 | $hover = isset($instance['hover_effect']) ? $instance['hover_effect'] : ''; |
| 55 | $providers = isset($instance['providers']) ? $instance['providers'] : ''; |
| 56 | $cusClass = isset($instance['customclass']) ? $instance['customclass'] : ''; |
| 57 | $box_only = isset($instance['box_only']) ? $instance['box_only'] : false; |
| 58 | |
| 59 | |
| 60 | $counter = New \WP_Social\Inc\Counter(false); |
| 61 | |
| 62 | $config = []; |
| 63 | $config['class'] = $cusClass; |
| 64 | $config['style'] = $layout; |
| 65 | $config['hover'] = $hover; |
| 66 | $providers = (is_array($providers) && !empty($providers) && !empty($providers[0])) ? $providers : 'all'; |
| 67 | |
| 68 | echo wp_kses(($before_widget . $before_title . $title . $after_title), \WP_Social\Helper\Helper::get_kses_array()); |
| 69 | |
| 70 | echo wp_kses(($counter->get_counter_data($providers, $config)), \WP_Social\Helper\Helper::get_kses_array()); |
| 71 | |
| 72 | echo wp_kses(($after_widget), \WP_Social\Helper\Helper::get_kses_array()); |
| 73 | } |
| 74 | |
| 75 | |
| 76 | /** |
| 77 | * |
| 78 | * @param $instance |
| 79 | */ |
| 80 | public function form($instance) { |
| 81 | |
| 82 | $defaults = array('title' => __('Follow us', 'wp-social'), 'layout' => 'block', 'columns' => 'xs-3-column', 'box_only' => false, 'providers' => '', 'customclass' => ''); |
| 83 | $instance = wp_parse_args((array)$instance, $defaults); |
| 84 | $select_provider = is_array($instance['providers']) && !empty($instance['providers']) && !empty($instance['providers'][0]) ? $instance['providers'] : []; |
| 85 | |
| 86 | $core_providers = Providers::get_core_providers_count(); |
| 87 | |
| 88 | ?> |
| 89 | <p> |
| 90 | <label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('Counter Title :', 'wp-social') ?> </label> |
| 91 | <input id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" |
| 92 | value="<?php echo esc_attr($instance['title']); ?>" class="widefat" type="text"/> |
| 93 | </p> |
| 94 | |
| 95 | <p> |
| 96 | <label for="<?php echo esc_attr($this->get_field_id('providers')); ?>"><?php esc_html_e('Providers :', 'wp-social') ?></label> |
| 97 | <select class="widefat" |
| 98 | id="<?php echo esc_attr($this->get_field_id('providers')); ?>" |
| 99 | name="<?php echo esc_attr($this->get_field_name('providers')); ?>[]" multiple> |
| 100 | <option value="" <?php echo empty($select_provider) ? 'selected' : '' ?>>All</option> |
| 101 | <?php |
| 102 | foreach($core_providers as $k => $v): |
| 103 | ?> |
| 104 | <option value="<?php echo esc_attr($k); ?>" <?php echo esc_attr((in_array($k, $select_provider)) ? 'selected' : ''); ?>> |
| 105 | <?php echo esc_html($v['label']) ?> |
| 106 | </option> <?php |
| 107 | endforeach; ?> |
| 108 | </select> |
| 109 | </p> |
| 110 | |
| 111 | <p> |
| 112 | <label for="<?php echo esc_attr($this->get_field_id('layout')); ?>"><?php esc_html_e('Style :', 'wp-social') ?></label> |
| 113 | <select class="widefat" id="<?php echo esc_attr($this->get_field_id('layout')); ?>" |
| 114 | name="<?php echo esc_attr($this->get_field_name('layout')); ?>"> |
| 115 | <?php |
| 116 | foreach($this->styleArr as $k => $v): |
| 117 | ?> |
| 118 | <option value="<?php echo esc_attr((!did_action('wslu_social_pro/plugin_loaded')) && ($v['package'] == 'pro') ? 'wslu-pro-only' : $k); ?>" <?php echo esc_attr(($instance['layout'] == $k) ? 'selected' : ''); ?>> |
| 119 | <?php |
| 120 | echo esc_html($v['name']); |
| 121 | esc_html_e((!did_action('wslu_social_pro/plugin_loaded')) && ($v['package'] == 'pro') ? '(Pro Only)' : '', 'wp-social'); |
| 122 | ?> |
| 123 | </option> |
| 124 | <?php endforeach; ?> |
| 125 | </select> |
| 126 | </p> |
| 127 | |
| 128 | <?php |
| 129 | |
| 130 | if(did_action('wslu_social_pro/plugin_loaded')): |
| 131 | |
| 132 | if( method_exists( \WP_Social_Pro\Inc\Admin_Settings::class, 'counter_hover_effects' ) ){ |
| 133 | |
| 134 | $this->hover_effect = \WP_Social_Pro\Inc\Admin_Settings::counter_hover_effects(); |
| 135 | |
| 136 | }else{ |
| 137 | |
| 138 | $this->hover_effect = \WP_Social_Pro\Inc\Admin_Settings::$counter_hover_effects; |
| 139 | |
| 140 | } |
| 141 | ?> |
| 142 | <p> |
| 143 | <label for="<?php echo esc_attr($this->get_field_id('hover_effect')); ?>"><?php esc_html_e('Hover effect :', 'wp-social') ?></label> |
| 144 | <select class="widefat" id="<?php echo esc_attr($this->get_field_id('hover_effect')); ?>" |
| 145 | name="<?php echo esc_attr($this->get_field_name('hover_effect')); ?>"> |
| 146 | <?php |
| 147 | foreach($this->hover_effect as $k => $v): |
| 148 | ?> |
| 149 | <option value="<?php echo esc_attr($k); ?>" <?php echo esc_attr((isset($instance['hover_effect']) && $instance['hover_effect'] == $k) ? 'selected' : ''); ?>> <?php esc_html_e($v['name'], 'wp-social'); ?> </option> |
| 150 | <?php endforeach; ?> |
| 151 | </select> |
| 152 | </p> |
| 153 | |
| 154 | <?php |
| 155 | |
| 156 | endif; ?> |
| 157 | |
| 158 | <p> |
| 159 | <label for="<?php echo esc_attr($this->get_field_id('customclass')); ?>"><?php esc_html_e('Custom Class :', 'wp-social') ?> </label> |
| 160 | <input id="<?php echo esc_attr($this->get_field_id('customclass')); ?>" |
| 161 | name="<?php echo esc_attr($this->get_field_name('customclass')); ?>" |
| 162 | value="<?php echo esc_attr($instance['customclass']); ?>" class="widefat" type="text"/> |
| 163 | </p> |
| 164 | <?php |
| 165 | } |
| 166 | |
| 167 | public function update($new_instance, $old_instance) { |
| 168 | |
| 169 | $instance = $old_instance; |
| 170 | $instance['providers'] = $new_instance['providers'] ; |
| 171 | $instance['layout'] = $new_instance['layout'] ; |
| 172 | $instance['hover_effect'] = isset($new_instance['hover_effect']) ? $new_instance['hover_effect'] : '' ; |
| 173 | $instance['title'] = $new_instance['title'] ; |
| 174 | $instance['box_only'] = isset($new_instance['box_only']) ? $new_instance['box_only'] : false ; |
| 175 | $instance['customclass'] = $new_instance['customclass'] ; |
| 176 | |
| 177 | return $instance; |
| 178 | } |
| 179 | } |
| 180 |