| 1 |
<?php |
| 2 |
|
| 3 |
namespace Borderless\Widgets; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 6 |
|
| 7 |
use \Elementor\Controls_Manager; |
| 8 |
use \Elementor\Group_Control_Background; |
| 9 |
use \Elementor\Group_Control_Box_Shadow; |
| 10 |
use \Elementor\Group_Control_Typography; |
| 11 |
use \Elementor\Core\Kits\Documents\Tabs\Global_Typography; |
| 12 |
use \Elementor\Widget_Base; |
| 13 |
|
| 14 |
class Circular_Progress_Bar extends Widget_Base { |
| 15 |
|
| 16 |
public function get_name() { |
| 17 |
return 'borderless-elementor-circular-progress-bar'; |
| 18 |
} |
| 19 |
|
| 20 |
public function get_title() { |
| 21 |
return esc_html__( 'Circular Progress Bar', 'borderless'); |
| 22 |
} |
| 23 |
|
| 24 |
public function get_icon() { |
| 25 |
return 'borderless-icon-circular-progress-bar'; |
| 26 |
} |
| 27 |
|
| 28 |
public function get_categories() { |
| 29 |
return [ 'borderless' ]; |
| 30 |
} |
| 31 |
|
| 32 |
public function get_keywords() { |
| 33 |
return [ |
| 34 |
'circular progress bar', |
| 35 |
'progress bar', |
| 36 |
'bar', |
| 37 |
'borderless', |
| 38 |
'borderless circular progress bar', |
| 39 |
'borderless progress bar', |
| 40 |
'borderless bar' |
| 41 |
]; |
| 42 |
} |
| 43 |
|
| 44 |
public function get_custom_help_url() { |
| 45 |
return 'https://wpborderless.com/'; |
| 46 |
} |
| 47 |
|
| 48 |
public function get_style_depends() { |
| 49 |
return [ 'borderless-elementor-style' ]; |
| 50 |
} |
| 51 |
|
| 52 |
public function get_script_depends() { |
| 53 |
return [ |
| 54 |
'borderless-elementor-appear-script', |
| 55 |
'borderless-elementor-progressbar-script' |
| 56 |
]; |
| 57 |
} |
| 58 |
|
| 59 |
protected function _register_controls() { |
| 60 |
/*-----------------------------------------------------------------------------------*/ |
| 61 |
/* *. Layout |
| 62 |
/*-----------------------------------------------------------------------------------*/ |
| 63 |
$this->start_controls_section( |
| 64 |
'borderless_section_circular_progress_bar_layout', |
| 65 |
[ |
| 66 |
'label' => esc_html__( 'Layout', 'borderless' ), |
| 67 |
'tab' => Controls_Manager::TAB_CONTENT, |
| 68 |
] |
| 69 |
); |
| 70 |
|
| 71 |
$this->add_control( |
| 72 |
'borderless_circular_progress_bar_title', |
| 73 |
[ |
| 74 |
'label' => esc_html__( 'Title', 'borderless'), |
| 75 |
'type' => Controls_Manager::TEXT, |
| 76 |
'dynamic' => [ 'active' => true ], |
| 77 |
] |
| 78 |
); |
| 79 |
|
| 80 |
$this->add_control( |
| 81 |
'borderless_circular_progress_bar_counter_value', |
| 82 |
[ |
| 83 |
'label' => esc_html__( 'Counter Value', 'borderless'), |
| 84 |
'type' => Controls_Manager::SLIDER, |
| 85 |
'size_units' => ['%'], |
| 86 |
'range' => [ |
| 87 |
'%' => [ |
| 88 |
'min' => 1, |
| 89 |
'max' => 100, |
| 90 |
], |
| 91 |
], |
| 92 |
'default' => [ |
| 93 |
'unit' => '%', |
| 94 |
'size' => 50, |
| 95 |
], |
| 96 |
'separator' => 'before', |
| 97 |
] |
| 98 |
); |
| 99 |
|
| 100 |
$this->add_control( |
| 101 |
'borderless_circular_progress_bar_animation_duration', |
| 102 |
[ |
| 103 |
'label' => __( 'Animation Duration', 'borderless' ), |
| 104 |
'type' => Controls_Manager::SLIDER, |
| 105 |
'size_units' => ['px'], |
| 106 |
'range' => [ |
| 107 |
'px' => [ |
| 108 |
'min' => 1000, |
| 109 |
'max' => 10000, |
| 110 |
'step' => 100, |
| 111 |
], |
| 112 |
], |
| 113 |
'default' => [ |
| 114 |
'unit' => 'px', |
| 115 |
'size' => 1500, |
| 116 |
], |
| 117 |
'separator' => 'before', |
| 118 |
] |
| 119 |
); |
| 120 |
|
| 121 |
$this->end_controls_section(); |
| 122 |
|
| 123 |
|
| 124 |
/*-----------------------------------------------------------------------------------*/ |
| 125 |
/* *. Layout - Style |
| 126 |
/*-----------------------------------------------------------------------------------*/ |
| 127 |
$this->start_controls_section( |
| 128 |
'borderless_section_circular_progress_bar_styles_general', |
| 129 |
[ |
| 130 |
'label' => esc_html__( 'General', 'borderless'), |
| 131 |
'tab' => Controls_Manager::TAB_STYLE |
| 132 |
] |
| 133 |
); |
| 134 |
|
| 135 |
$this->add_control( |
| 136 |
'borderless_circular_progress_bar_alignment', |
| 137 |
[ |
| 138 |
'label' => __( 'Alignment', 'borderless' ), |
| 139 |
'type' => Controls_Manager::CHOOSE, |
| 140 |
'options' => [ |
| 141 |
'borderless-circular-progress-bar-alignment-left' => [ |
| 142 |
'title' => __( 'Left', 'borderless' ), |
| 143 |
'icon' => 'fa fa-align-left', |
| 144 |
], |
| 145 |
'borderless-circular-progress-bar-alignment-center' => [ |
| 146 |
'title' => __( 'Center', 'borderless' ), |
| 147 |
'icon' => 'fa fa-align-center', |
| 148 |
], |
| 149 |
'borderless-circular-progress-bar-alignment-right' => [ |
| 150 |
'title' => __( 'Right', 'borderless' ), |
| 151 |
'icon' => 'fa fa-align-right', |
| 152 |
], |
| 153 |
], |
| 154 |
'default' => 'borderless-circular-progress-bar-alignment-center', |
| 155 |
] |
| 156 |
); |
| 157 |
|
| 158 |
$this->add_control( |
| 159 |
'borderless_circular_progress_bar_size', |
| 160 |
[ |
| 161 |
'label' => __( 'Size', 'borderless' ), |
| 162 |
'type' => Controls_Manager::SLIDER, |
| 163 |
'size_units' => ['px'], |
| 164 |
'range' => [ |
| 165 |
'px' => [ |
| 166 |
'min' => 50, |
| 167 |
'max' => 500, |
| 168 |
'step' => 1, |
| 169 |
], |
| 170 |
], |
| 171 |
'default' => [ |
| 172 |
'unit' => 'px', |
| 173 |
'size' => 200, |
| 174 |
], |
| 175 |
'selectors' => [ |
| 176 |
'{{WRAPPER}} .borderless-elementor-circular-progress-bar' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};', |
| 177 |
], |
| 178 |
'separator' => 'before', |
| 179 |
] |
| 180 |
); |
| 181 |
|
| 182 |
$this->add_control( |
| 183 |
'borderless_circular_progress_bar_stroke_width', |
| 184 |
[ |
| 185 |
'label' => __( 'Stroke Width', 'borderless' ), |
| 186 |
'type' => Controls_Manager::SLIDER, |
| 187 |
'size_units' => ['px'], |
| 188 |
'range' => [ |
| 189 |
'px' => [ |
| 190 |
'min' => 0, |
| 191 |
'max' => 100, |
| 192 |
'step' => 1, |
| 193 |
], |
| 194 |
], |
| 195 |
'default' => [ |
| 196 |
'unit' => 'px', |
| 197 |
'size' => 12, |
| 198 |
], |
| 199 |
'separator' => 'before', |
| 200 |
] |
| 201 |
); |
| 202 |
|
| 203 |
$this->add_control( |
| 204 |
'borderless_circular_progress_bar_stroke_color_style', |
| 205 |
[ |
| 206 |
'label' => __( 'Stroke Color Style', 'borderless' ), |
| 207 |
'type' => Controls_Manager::SELECT, |
| 208 |
'default' => 'borderless-elementor-circular-progress-bar-stroke-solid-color', |
| 209 |
'options' => [ |
| 210 |
'borderless-elementor-circular-progress-bar-stroke-solid-color' => __( 'Solid', 'borderless' ), |
| 211 |
'borderless-elementor-circular-progress-bar-stroke-gradient-color' => __( 'Gradient', 'borderless' ), |
| 212 |
], |
| 213 |
] |
| 214 |
); |
| 215 |
|
| 216 |
$this->add_control( |
| 217 |
'borderless_circular_progress_bar_stroke_color', |
| 218 |
[ |
| 219 |
'label' => __( 'Stroke Color', 'borderless' ), |
| 220 |
'type' => Controls_Manager::COLOR, |
| 221 |
'default' => '#000', |
| 222 |
'condition' => [ |
| 223 |
'borderless_circular_progress_bar_stroke_color_style' => 'borderless-elementor-circular-progress-bar-stroke-solid-color', |
| 224 |
], |
| 225 |
] |
| 226 |
); |
| 227 |
|
| 228 |
$this->add_control( |
| 229 |
'borderless_circular_progress_bar_stroke_color_from', |
| 230 |
[ |
| 231 |
'label' => __( 'Stroke Color From', 'borderless' ), |
| 232 |
'type' => Controls_Manager::COLOR, |
| 233 |
'default' => '#000', |
| 234 |
'condition' => [ |
| 235 |
'borderless_circular_progress_bar_stroke_color_style' => 'borderless-elementor-circular-progress-bar-stroke-gradient-color', |
| 236 |
], |
| 237 |
] |
| 238 |
); |
| 239 |
|
| 240 |
$this->add_control( |
| 241 |
'borderless_circular_progress_bar_stroke_color_to', |
| 242 |
[ |
| 243 |
'label' => __( 'Stroke Color To', 'borderless' ), |
| 244 |
'type' => Controls_Manager::COLOR, |
| 245 |
'default' => '#000', |
| 246 |
'condition' => [ |
| 247 |
'borderless_circular_progress_bar_stroke_color_style' => 'borderless-elementor-circular-progress-bar-stroke-gradient-color', |
| 248 |
], |
| 249 |
] |
| 250 |
); |
| 251 |
|
| 252 |
$this->add_control( |
| 253 |
'borderless_circular_progress_bar_trail_width', |
| 254 |
[ |
| 255 |
'label' => __( 'Trail Width', 'borderless' ), |
| 256 |
'type' => Controls_Manager::SLIDER, |
| 257 |
'size_units' => ['px'], |
| 258 |
'range' => [ |
| 259 |
'px' => [ |
| 260 |
'min' => 0, |
| 261 |
'max' => 100, |
| 262 |
'step' => 1, |
| 263 |
], |
| 264 |
], |
| 265 |
'default' => [ |
| 266 |
'unit' => 'px', |
| 267 |
'size' => 12, |
| 268 |
], |
| 269 |
'separator' => 'before', |
| 270 |
] |
| 271 |
); |
| 272 |
|
| 273 |
$this->add_control( |
| 274 |
'borderless_circular_progress_bar_trail_color', |
| 275 |
[ |
| 276 |
'label' => __( 'Trail Color', 'borderless' ), |
| 277 |
'type' => Controls_Manager::COLOR, |
| 278 |
'default' => '#eee', |
| 279 |
] |
| 280 |
); |
| 281 |
|
| 282 |
$this->add_control( |
| 283 |
'borderless_circular_progress_bar_shape', |
| 284 |
[ |
| 285 |
'label' => __( 'Shape', 'borderless' ), |
| 286 |
'type' => Controls_Manager::SELECT, |
| 287 |
'default' => 'borderless-elementor-circular-progress-bar--round', |
| 288 |
'options' => [ |
| 289 |
'borderless-elementor-circular-progress-bar--square' => __( 'Square', 'borderless' ), |
| 290 |
'borderless-elementor-circular-progress-bar--round' => __( 'Round', 'borderless' ), |
| 291 |
], |
| 292 |
'separator' => 'before', |
| 293 |
] |
| 294 |
); |
| 295 |
|
| 296 |
$this->add_control( |
| 297 |
'borderless_circular_progress_bar_background_color', |
| 298 |
[ |
| 299 |
'label' => __( 'Background Color', 'borderless' ), |
| 300 |
'type' => Controls_Manager::COLOR, |
| 301 |
'default' => '#fff', |
| 302 |
'selectors' => [ |
| 303 |
'{{WRAPPER}} .borderless-elementor-circular-progress-bar' => 'background-color: {{VALUE}}', |
| 304 |
], |
| 305 |
] |
| 306 |
); |
| 307 |
|
| 308 |
$this->add_group_control( |
| 309 |
Group_Control_Box_Shadow::get_type(), |
| 310 |
[ |
| 311 |
'name' => 'borderless_circular_progress_bar_box_shadow', |
| 312 |
'label' => __( 'Box Shadow', 'borderless' ), |
| 313 |
'selector' => '{{WRAPPER}} .borderless-elementor-circular-progress-bar', |
| 314 |
'separator'=> 'before', |
| 315 |
] |
| 316 |
); |
| 317 |
|
| 318 |
$this->end_controls_section(); |
| 319 |
|
| 320 |
/*-----------------------------------------------------------------------------------*/ |
| 321 |
/* *. Typography - Style |
| 322 |
/*-----------------------------------------------------------------------------------*/ |
| 323 |
$this->start_controls_section( |
| 324 |
'borderless_section_circular_progress_bar_typography', |
| 325 |
[ |
| 326 |
'label' => __( 'Typography', 'borderless' ), |
| 327 |
'tab' => Controls_Manager::TAB_STYLE, |
| 328 |
] |
| 329 |
); |
| 330 |
|
| 331 |
$this->add_group_control( |
| 332 |
Group_Control_Typography::get_type(), |
| 333 |
[ |
| 334 |
'name' => 'borderless_circular_progress_bar_title_typography', |
| 335 |
'label' => __( 'Title', 'borderless' ), |
| 336 |
'global' => [ 'default' => Global_Typography::TYPOGRAPHY_PRIMARY ], |
| 337 |
'selector'=> '{{WRAPPER}} .borderless-elementor-circular-progress-bar .progressbar-text .borderless-elementor-circular-progress-bar-title', |
| 338 |
] |
| 339 |
); |
| 340 |
|
| 341 |
$this->add_control( |
| 342 |
'borderless_circular_progress_bar_title_color', |
| 343 |
[ |
| 344 |
'label' => __( 'Title Color', 'borderless' ), |
| 345 |
'type' => Controls_Manager::COLOR, |
| 346 |
'default' => '', |
| 347 |
'selectors' => [ |
| 348 |
'{{WRAPPER}} .borderless-elementor-circular-progress-bar .progressbar-text .borderless-elementor-circular-progress-bar-title' => 'color: {{VALUE}}', |
| 349 |
], |
| 350 |
'separator'=> 'after', |
| 351 |
] |
| 352 |
); |
| 353 |
|
| 354 |
$this->add_group_control( |
| 355 |
Group_Control_Typography::get_type(), |
| 356 |
[ |
| 357 |
'name' => 'borderless_circular_progress_bar_counter_typography', |
| 358 |
'label' => __( 'Counter', 'borderless' ), |
| 359 |
'global' => [ 'default' => Global_Typography::TYPOGRAPHY_PRIMARY ], |
| 360 |
'selector' => '{{WRAPPER}} .borderless-elementor-circular-progress-bar .progressbar-text .borderless-elementor-circular-progress-bar-counter-value', |
| 361 |
] |
| 362 |
); |
| 363 |
|
| 364 |
$this->add_control( |
| 365 |
'borderless_circular_progress_bar_counter_color', |
| 366 |
[ |
| 367 |
'label' => __( 'Counter Color', 'borderless' ), |
| 368 |
'type' => Controls_Manager::COLOR, |
| 369 |
'default' => '', |
| 370 |
'separator'=> 'after', |
| 371 |
] |
| 372 |
); |
| 373 |
|
| 374 |
$this->add_group_control( |
| 375 |
Group_Control_Typography::get_type(), |
| 376 |
[ |
| 377 |
'name' => 'borderless_circular_progress_bar_postfix_typography', |
| 378 |
'label' => __( 'Postfix', 'borderless' ), |
| 379 |
'global' => [ 'default' => Global_Typography::TYPOGRAPHY_PRIMARY ], |
| 380 |
'selector' => '{{WRAPPER}} .borderless-elementor-circular-progress-bar-counter-postfix', |
| 381 |
] |
| 382 |
); |
| 383 |
|
| 384 |
$this->add_control( |
| 385 |
'borderless_circular_progress_bar_postfix_color', |
| 386 |
[ |
| 387 |
'label' => __( 'Postfix Color', 'borderless' ), |
| 388 |
'type' => Controls_Manager::COLOR, |
| 389 |
'default' => '', |
| 390 |
'selectors' => [ |
| 391 |
'{{WRAPPER}} .borderless-elementor-circular-progress-bar-counter-postfix' => 'color: {{VALUE}}', |
| 392 |
], |
| 393 |
] |
| 394 |
); |
| 395 |
|
| 396 |
$this->end_controls_section(); |
| 397 |
} |
| 398 |
|
| 399 |
/*-----------------------------------------------------------------------------------*/ |
| 400 |
/* *. Render |
| 401 |
/*-----------------------------------------------------------------------------------*/ |
| 402 |
|
| 403 |
protected function render() { |
| 404 |
$settings = $this->get_settings_for_display(); |
| 405 |
|
| 406 |
// Sanitize and escape the Title field to prevent stored XSS |
| 407 |
$raw_title = $settings['borderless_circular_progress_bar_title']; |
| 408 |
$clean_title = sanitize_text_field( $raw_title ); |
| 409 |
$safe_title = esc_js( $clean_title ); |
| 410 |
|
| 411 |
if ( 'borderless-elementor-circular-progress-bar-stroke-solid-color' === $settings['borderless_circular_progress_bar_stroke_color_style'] ) { |
| 412 |
$borderless_circular_progress_bar_stroke_color_style = 'stroke_color_mode="solid" stroke_color="' . esc_attr( $settings['borderless_circular_progress_bar_stroke_color'] ) . '"'; |
| 413 |
} else { |
| 414 |
$borderless_circular_progress_bar_stroke_color_style = 'stroke_color_mode="gradient" stroke_color="' . esc_attr( $settings['borderless_circular_progress_bar_stroke_color'] ) . '" stroke_color_from="' . esc_attr( $settings['borderless_circular_progress_bar_stroke_color_from'] ) . '" stroke_color_to="' . esc_attr( $settings['borderless_circular_progress_bar_stroke_color_to'] ) . '"'; |
| 415 |
} |
| 416 |
|
| 417 |
echo '<div class="borderless-elementor-circular-progress-bar-widget ' . esc_attr( $settings['borderless_circular_progress_bar_alignment'] ) . '"> |
| 418 |
<div class="borderless-elementor-circular-progress-bar ' . esc_attr( $settings['borderless_circular_progress_bar_shape'] ) . '" |
| 419 |
title="' . $safe_title . '" |
| 420 |
counter_value="' . esc_attr( $settings['borderless_circular_progress_bar_counter_value']['size'] ) . '" |
| 421 |
' . $borderless_circular_progress_bar_stroke_color_style . ' |
| 422 |
trail_color="' . esc_attr( $settings['borderless_circular_progress_bar_trail_color'] ) . '" |
| 423 |
counter_color="' . esc_attr( $settings['borderless_circular_progress_bar_counter_color'] ) . '" |
| 424 |
stroke_width="' . esc_attr( $settings['borderless_circular_progress_bar_stroke_width']['size'] ) . '" |
| 425 |
trail_width="' . esc_attr( $settings['borderless_circular_progress_bar_trail_width']['size'] ) . '" |
| 426 |
animation_duration="' . esc_attr( $settings['borderless_circular_progress_bar_animation_duration']['size'] ) . '"> |
| 427 |
</div> |
| 428 |
</div>'; |
| 429 |
} |
| 430 |
|
| 431 |
protected function _content_template() {} |
| 432 |
} |
| 433 |
|