| 1 |
<?php |
| 2 |
|
| 3 |
namespace MasterAddons\Addons; |
| 4 |
|
| 5 |
/** |
| 6 |
* Author Name: Liton Arefin |
| 7 |
* Author URL: https://jeweltheme.com |
| 8 |
* Date: 6/26/19 |
| 9 |
*/ |
| 10 |
|
| 11 |
use MasterAddons\Inc\Classes\Base\Master_Widget; |
| 12 |
use \Elementor\Controls_Manager; |
| 13 |
use \Elementor\Repeater; |
| 14 |
use \Elementor\Group_Control_Typography; |
| 15 |
|
| 16 |
use MasterAddons\Inc\Admin\Config; |
| 17 |
|
| 18 |
if (!defined('ABSPATH')) exit; // If this file is called directly, abort. |
| 19 |
|
| 20 |
class Progress_Bars extends Master_Widget |
| 21 |
{ |
| 22 |
use \MasterAddons\Inc\Traits\Widget_Notice; |
| 23 |
use \MasterAddons\Inc\Traits\Widget_Assets_Trait; |
| 24 |
|
| 25 |
public function get_name() |
| 26 |
{ |
| 27 |
return 'ma-progressbars'; |
| 28 |
} |
| 29 |
|
| 30 |
public function get_title() |
| 31 |
{ |
| 32 |
return esc_html__('Progressbars', 'master-addons' ); |
| 33 |
} |
| 34 |
|
| 35 |
public function get_icon() |
| 36 |
{ |
| 37 |
return 'jltma-icon ' . Config::get_addon_icon($this->get_name()); |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
protected function register_controls() |
| 42 |
{ |
| 43 |
|
| 44 |
$this->start_controls_section( |
| 45 |
'section_stats_bars', |
| 46 |
[ |
| 47 |
'label' => __('Stats Bars', 'master-addons' ), |
| 48 |
] |
| 49 |
); |
| 50 |
|
| 51 |
$repeater = new Repeater(); |
| 52 |
|
| 53 |
$repeater->add_control( |
| 54 |
'stats_title', |
| 55 |
[ |
| 56 |
'label' => __('Stats Title', 'master-addons' ), |
| 57 |
'type' => Controls_Manager::TEXT, |
| 58 |
'description' => __('The title for the stats bar', 'master-addons' ), |
| 59 |
'default' => __('My stats title', 'master-addons' ), |
| 60 |
'dynamic' => [ |
| 61 |
'active' => true, |
| 62 |
], |
| 63 |
] |
| 64 |
); |
| 65 |
|
| 66 |
$repeater->add_control( |
| 67 |
'percentage_value', |
| 68 |
[ |
| 69 |
'label' => __('Percentage Value', 'master-addons' ), |
| 70 |
'type' => Controls_Manager::NUMBER, |
| 71 |
'min' => 1, |
| 72 |
'max' => 100, |
| 73 |
'step' => 1, |
| 74 |
'default' => 30, |
| 75 |
'description' => __('The percentage value for the stats.', 'master-addons' ), |
| 76 |
] |
| 77 |
); |
| 78 |
|
| 79 |
$repeater->add_control( |
| 80 |
'bar_color', |
| 81 |
[ |
| 82 |
'label' => __('Bar Color', 'master-addons' ), |
| 83 |
'type' => Controls_Manager::COLOR, |
| 84 |
'default' => '', |
| 85 |
'selectors' => [ |
| 86 |
'{{WRAPPER}} .jltma-stats-bars {{CURRENT_ITEM}}.jltma-stats-bar .jltma-stats-bar-content' => 'background: {{VALUE}}' |
| 87 |
] |
| 88 |
] |
| 89 |
); |
| 90 |
|
| 91 |
$this->add_control( |
| 92 |
'stats_bars', |
| 93 |
[ |
| 94 |
'type' => Controls_Manager::REPEATER, |
| 95 |
'default' => [ |
| 96 |
[ |
| 97 |
'stats_title' => __('Web Design', 'master-addons' ), |
| 98 |
'percentage_value' => 87, |
| 99 |
], |
| 100 |
|
| 101 |
[ |
| 102 |
'stats_title' => __('SEO Services', 'master-addons' ), |
| 103 |
'percentage_value' => 76, |
| 104 |
], |
| 105 |
|
| 106 |
[ |
| 107 |
'stats_title' => __('Brand Marketing', 'master-addons' ), |
| 108 |
'percentage_value' => 40, |
| 109 |
], |
| 110 |
], |
| 111 |
'fields' => $repeater->get_controls(), |
| 112 |
'title_field' => '{{{ stats_title }}}', |
| 113 |
] |
| 114 |
); |
| 115 |
|
| 116 |
$this->end_controls_section(); |
| 117 |
|
| 118 |
// Help Docs section (links from config.php) |
| 119 |
$this->jltma_help_docs(); |
| 120 |
|
| 121 |
$this->upgrade_to_pro_message(); |
| 122 |
|
| 123 |
$this->start_controls_section( |
| 124 |
'section_stats_bar_styling', |
| 125 |
[ |
| 126 |
'label' => esc_html__('Stats Bar', 'master-addons' ), |
| 127 |
'tab' => Controls_Manager::TAB_STYLE, |
| 128 |
] |
| 129 |
); |
| 130 |
|
| 131 |
$this->add_control( |
| 132 |
'stats_bar_bg_color', |
| 133 |
[ |
| 134 |
'label' => esc_html__('Bar BG Color', 'master-addons' ), |
| 135 |
'type' => Controls_Manager::COLOR, |
| 136 |
'selectors' => [ |
| 137 |
'{{WRAPPER}} .jltma-stats-bars .jltma-stats-bar .jltma-stats-bar-bg' => 'background-color: {{VALUE}};', |
| 138 |
], |
| 139 |
] |
| 140 |
); |
| 141 |
|
| 142 |
$this->add_control( |
| 143 |
'stats_bar_active_bar_bg_color', |
| 144 |
[ |
| 145 |
'label' => esc_html__('Active Bar Color', 'master-addons' ), |
| 146 |
'type' => Controls_Manager::COLOR, |
| 147 |
'default' => '#704aff', |
| 148 |
'selectors' => [ |
| 149 |
'{{WRAPPER}} .jltma-stats-bars .jltma-stats-bar .jltma-stats-bar-content' => 'background: {{VALUE}};', |
| 150 |
], |
| 151 |
] |
| 152 |
); |
| 153 |
|
| 154 |
$this->add_control( |
| 155 |
'stats_bar_spacing', |
| 156 |
[ |
| 157 |
'label' => esc_html__('Vertical Spacing', 'master-addons' ), |
| 158 |
'type' => Controls_Manager::SLIDER, |
| 159 |
'size_units' => ['px'], |
| 160 |
'default' => [ |
| 161 |
'size' => 18, |
| 162 |
], |
| 163 |
'range' => [ |
| 164 |
'px' => [ |
| 165 |
'min' => 5, |
| 166 |
'max' => 128, |
| 167 |
], |
| 168 |
], |
| 169 |
'selectors' => [ |
| 170 |
'{{WRAPPER}} .jltma-stats-bars .jltma-stats-bar' => 'margin-bottom: {{SIZE}}{{UNIT}};', |
| 171 |
], |
| 172 |
] |
| 173 |
); |
| 174 |
|
| 175 |
$this->add_control( |
| 176 |
'stats_bar_height', |
| 177 |
[ |
| 178 |
'label' => __('Bar Height', 'master-addons' ), |
| 179 |
'type' => Controls_Manager::SLIDER, |
| 180 |
'size_units' => ['px'], |
| 181 |
'default' => [ |
| 182 |
'size' => 10, |
| 183 |
], |
| 184 |
'range' => [ |
| 185 |
'px' => [ |
| 186 |
'min' => 1, |
| 187 |
'max' => 96, |
| 188 |
], |
| 189 |
], |
| 190 |
'selectors' => [ |
| 191 |
'{{WRAPPER}} .jltma-stats-bars .jltma-stats-bar .jltma-stats-bar-bg, {{WRAPPER}} .jltma-stats-bars .jltma-stats-bar .jltma-stats-bar-content' => 'height: {{SIZE}}{{UNIT}};', |
| 192 |
'{{WRAPPER}} .jltma-stats-bars .jltma-stats-bar .jltma-stats-bar-bg' => 'margin-top: -{{SIZE}}{{UNIT}};', |
| 193 |
], |
| 194 |
] |
| 195 |
); |
| 196 |
|
| 197 |
$this->add_control( |
| 198 |
'stats_bar_border_radius', |
| 199 |
[ |
| 200 |
'label' => __('Stats Bar Border Radius', 'master-addons' ), |
| 201 |
'type' => Controls_Manager::DIMENSIONS, |
| 202 |
'size_units' => ['px', '%'], |
| 203 |
'selectors' => [ |
| 204 |
'{{WRAPPER}} .jltma-stats-bars .jltma-stats-bar .jltma-stats-bar-bg, {{WRAPPER}} .jltma-stats-bars .jltma-stats-bar .jltma-stats-bar-content' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 205 |
], |
| 206 |
] |
| 207 |
); |
| 208 |
|
| 209 |
$this->end_controls_section(); |
| 210 |
|
| 211 |
$this->start_controls_section( |
| 212 |
'section_stats_title', |
| 213 |
[ |
| 214 |
'label' => __('Stats Title', 'master-addons' ), |
| 215 |
'tab' => Controls_Manager::TAB_STYLE, |
| 216 |
] |
| 217 |
); |
| 218 |
|
| 219 |
$this->add_control( |
| 220 |
'stats_title_align', |
| 221 |
[ |
| 222 |
'label' => __('Alignment', 'master-addons' ), |
| 223 |
'type' => Controls_Manager::CHOOSE, |
| 224 |
'label_block' => false, |
| 225 |
'options' => [ |
| 226 |
'left' => [ |
| 227 |
'title' => __('Left', 'master-addons' ), |
| 228 |
'icon' => 'eicon-h-align-left', |
| 229 |
], |
| 230 |
'center' => [ |
| 231 |
'title' => __('Default', 'master-addons' ), |
| 232 |
'icon' => 'eicon-h-align-center', |
| 233 |
], |
| 234 |
'right' => [ |
| 235 |
'title' => __('Right', 'master-addons' ), |
| 236 |
'icon' => 'eicon-h-align-right', |
| 237 |
], |
| 238 |
], |
| 239 |
'default' => 'left', |
| 240 |
'style_transfer' => true, |
| 241 |
'selectors' => [ |
| 242 |
'{{WRAPPER}} .jltma-stats-bars .jltma-stats-bar .jltma-stats-title' => 'text-align: {{VALUE}};' |
| 243 |
] |
| 244 |
] |
| 245 |
); |
| 246 |
|
| 247 |
$this->add_control( |
| 248 |
'stats_title_color', |
| 249 |
[ |
| 250 |
'label' => __('Color', 'master-addons' ), |
| 251 |
'type' => Controls_Manager::COLOR, |
| 252 |
'selectors' => [ |
| 253 |
'{{WRAPPER}} .jltma-stats-bars .jltma-stats-bar .jltma-stats-title' => 'color: {{VALUE}};', |
| 254 |
], |
| 255 |
] |
| 256 |
); |
| 257 |
|
| 258 |
$this->add_group_control( |
| 259 |
Group_Control_Typography::get_type(), |
| 260 |
[ |
| 261 |
'name' => 'stats_title_typography', |
| 262 |
'selector' => '{{WRAPPER}} .jltma-stats-bars .jltma-stats-bar .jltma-stats-title', |
| 263 |
] |
| 264 |
); |
| 265 |
|
| 266 |
$this->end_controls_section(); |
| 267 |
|
| 268 |
// Stats Percentage |
| 269 |
$this->start_controls_section( |
| 270 |
'section_stats_percentage', |
| 271 |
[ |
| 272 |
'label' => __('Stats Percentage', 'master-addons' ), |
| 273 |
'tab' => Controls_Manager::TAB_STYLE, |
| 274 |
] |
| 275 |
); |
| 276 |
|
| 277 |
$this->add_control( |
| 278 |
'stats_percentage_color', |
| 279 |
[ |
| 280 |
'label' => __('Color', 'master-addons' ), |
| 281 |
'type' => Controls_Manager::COLOR, |
| 282 |
'selectors' => [ |
| 283 |
'{{WRAPPER}} .jltma-stats-bars .jltma-stats-bar span.jltma-stats-percentage' => 'color: {{VALUE}};' |
| 284 |
], |
| 285 |
] |
| 286 |
); |
| 287 |
|
| 288 |
$this->add_group_control( |
| 289 |
Group_Control_Typography::get_type(), |
| 290 |
[ |
| 291 |
'name' => 'stats_percentage_typography', |
| 292 |
'selector' => '{{WRAPPER}} .jltma-stats-bars .jltma-stats-bar span.jltma-stats-percentage', |
| 293 |
] |
| 294 |
); |
| 295 |
|
| 296 |
$this->end_controls_section(); |
| 297 |
} |
| 298 |
|
| 299 |
protected function render() |
| 300 |
{ |
| 301 |
|
| 302 |
$settings = $this->get_settings_for_display(); |
| 303 |
|
| 304 |
$settings = apply_filters('ma_el_stats_bars_' . esc_attr( $this->get_id() ) . '_settings', $settings); |
| 305 |
|
| 306 |
$output = '<div class="jltma-stats-bars">'; |
| 307 |
|
| 308 |
foreach ($settings['stats_bars'] as $stats_bar) : |
| 309 |
|
| 310 |
$color_style = ''; |
| 311 |
$color = ''; |
| 312 |
$bar_color = !empty($stats_bar['bar_color']) ? $stats_bar['bar_color'] : ''; |
| 313 |
$stats_bar_active_bar_bg_color = !empty($stats_bar['stats_bar_active_bar_bg_color']) ? $stats_bar['stats_bar_active_bar_bg_color'] : ''; |
| 314 |
|
| 315 |
if(!empty($bar_color)){ |
| 316 |
$color = $bar_color; |
| 317 |
}else{ |
| 318 |
$color = $stats_bar_active_bar_bg_color; |
| 319 |
} |
| 320 |
|
| 321 |
if ($color){ |
| 322 |
$color_style = ' style="background:' . esc_attr($color) . ';"'; |
| 323 |
} |
| 324 |
|
| 325 |
$child_output = '<div class="jltma-stats-bar elementor-repeater-item-' . esc_attr( $stats_bar['_id'] ) .'">'; |
| 326 |
|
| 327 |
$child_output .= '<div class="jltma-stats-title">'; |
| 328 |
|
| 329 |
$child_output .= $this->parse_text_editor($stats_bar['stats_title']); |
| 330 |
|
| 331 |
$child_output .= '</div>'; |
| 332 |
|
| 333 |
$child_output .= '<div class="jltma-stats-bar-wrap">'; |
| 334 |
|
| 335 |
$child_output .= '<div ' . esc_attr($color_style) . ' class="jltma-stats-bar-content" data-perc="' . esc_attr($stats_bar['percentage_value']) . '">'; |
| 336 |
$child_output .= '<span class="jltma-stats-percentage">' . esc_attr($stats_bar['percentage_value']) . '%</span>'; |
| 337 |
$child_output .= '</div>'; |
| 338 |
|
| 339 |
$child_output .= '<div class="jltma-stats-bar-bg"></div>'; |
| 340 |
|
| 341 |
$child_output .= '</div>'; |
| 342 |
|
| 343 |
$child_output .= '</div><!-- .jltma-stats-bar -->'; |
| 344 |
|
| 345 |
$output .= apply_filters('ma_el_stats_bar_output', $child_output, $stats_bar, $settings); |
| 346 |
|
| 347 |
endforeach; |
| 348 |
|
| 349 |
$output .= '</div><!-- .jltma-stats-bars -->'; |
| 350 |
|
| 351 |
echo apply_filters('ma_el_stats_bars_output', $output, $settings); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $output is plugin-constructed HTML built with escaped values; filter follows WP convention for HTML output filters |
| 352 |
} |
| 353 |
|
| 354 |
protected function content_template() |
| 355 |
{ |
| 356 |
} |
| 357 |
} |
| 358 |
|