templates
4 months ago
Accordion.php
9 months ago
Alerts_Box.php
9 months ago
Blog_Grid.php
6 months ago
Cheat_Sheet.php
6 months ago
Counter.php
6 months ago
Dynamic_Faq.php
1 month ago
Icon_Box.php
6 months ago
Integrations.php
6 months ago
List_Item.php
9 months ago
Tabs.php
6 months ago
Team_Carousel.php
6 months ago
Testimonial.php
6 months ago
Timeline.php
9 months ago
Video_Playlist.php
6 months ago
Video_Popup.php
6 months ago
Counter.php
451 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Use namespace to avoid conflict |
| 4 | */ |
| 5 | |
| 6 | namespace SPEL\Widgets; |
| 7 | |
| 8 | use Elementor\Group_Control_Typography; |
| 9 | use Elementor\Widget_Base; |
| 10 | use Elementor\Controls_Manager; |
| 11 | |
| 12 | // Exit if accessed directly |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit; |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Class Team |
| 19 | * |
| 20 | * @package spider\Widgets |
| 21 | * @since 1.0.0 |
| 22 | */ |
| 23 | class Counter extends Widget_Base { |
| 24 | |
| 25 | public function get_name(): string { |
| 26 | return 'spe_counter'; // ID of the widget (Don't change this name) |
| 27 | } |
| 28 | |
| 29 | public function get_title(): string { |
| 30 | return esc_html__( 'Counter', 'spider-elements' ); |
| 31 | } |
| 32 | |
| 33 | public function get_icon(): string { |
| 34 | return 'eicon-counter spel-icon'; |
| 35 | } |
| 36 | |
| 37 | public function get_keywords(): array { |
| 38 | return [ 'spider', 'Counter', 'Progress bar', ]; |
| 39 | } |
| 40 | |
| 41 | public function get_categories(): array { |
| 42 | return [ 'spider-elements' ]; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Name: get_style_depends() |
| 47 | * Desc: Register the required CSS dependencies for the frontend. |
| 48 | */ |
| 49 | public function get_style_depends(): array { |
| 50 | return [ 'spel-main' ]; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Name: get_script_depends() |
| 55 | * Desc: Register the required JS dependencies for the frontend. |
| 56 | */ |
| 57 | public function get_script_depends(): array { |
| 58 | return [ 'spel-el-widgets', 'counterup', 'waypoint' ]; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Name: register_controls() |
| 63 | * Desc: Register controls for these widgets |
| 64 | * Params: no params |
| 65 | * Return: @void |
| 66 | * Since: @1.0.0 |
| 67 | * Package: @spider-elements |
| 68 | * Author: spider-themes |
| 69 | */ |
| 70 | protected function register_controls(): void { |
| 71 | $this->elementor_content_control(); |
| 72 | $this->counter_style_control(); |
| 73 | } |
| 74 | |
| 75 | |
| 76 | /** |
| 77 | * Name: elementor_content_control() |
| 78 | * Desc: Register the Content Tab output on the Elementor editor. |
| 79 | * Params: no params |
| 80 | * Return: @void |
| 81 | * Since: @1.0.0 |
| 82 | * Package: @spider-elements |
| 83 | * Author: spider-themes |
| 84 | */ |
| 85 | |
| 86 | private function counter_layout_option(): array { |
| 87 | |
| 88 | if ( spel_is_premium() ) { |
| 89 | $options = [ |
| 90 | '1' => [ |
| 91 | 'icon' => 'counter1', |
| 92 | 'title' => esc_html__( '01 : Counter', 'spider-elements' ) |
| 93 | ], |
| 94 | '2' => [ |
| 95 | 'icon' => 'counter2', |
| 96 | 'title' => esc_html__( '02 : Counter', 'spider-elements' ) |
| 97 | ], |
| 98 | ]; |
| 99 | } else { |
| 100 | $options = [ |
| 101 | '1' => [ |
| 102 | 'icon' => 'counter1', |
| 103 | 'title' => esc_html__( '01 : Counter', 'spider-elements' ) |
| 104 | ], |
| 105 | '2' => [ |
| 106 | 'icon' => 'counter2 spel-pro-label', |
| 107 | 'title' => esc_html__( 'spel-pro-label', 'spider-elements' ) |
| 108 | ], |
| 109 | ]; |
| 110 | } |
| 111 | |
| 112 | return $options; |
| 113 | } |
| 114 | |
| 115 | |
| 116 | public function elementor_content_control(): void { |
| 117 | |
| 118 | |
| 119 | //==================== Select Preset Skin ====================// |
| 120 | $this->start_controls_section( |
| 121 | 'counter_preset', [ |
| 122 | 'label' => esc_html__( 'Preset Skin', 'spider-elements' ), |
| 123 | ] |
| 124 | ); |
| 125 | |
| 126 | |
| 127 | $this->add_control( |
| 128 | 'style', |
| 129 | [ |
| 130 | 'label' => esc_html__( 'Counter Style', 'spider-elements' ), |
| 131 | 'type' => Controls_Manager::CHOOSE, |
| 132 | 'options' => $this->counter_layout_option(), |
| 133 | 'default' => '1', |
| 134 | ] |
| 135 | ); |
| 136 | |
| 137 | $this->end_controls_section(); // End Preset Skin |
| 138 | |
| 139 | |
| 140 | //=================== Counter ===================// |
| 141 | $this->start_controls_section( |
| 142 | 'sec_counter', [ |
| 143 | 'label' => esc_html__( 'Counter', 'spider-elements' ), |
| 144 | ] |
| 145 | ); |
| 146 | |
| 147 | $this->add_control( |
| 148 | 'counter_value', [ |
| 149 | 'label' => esc_html__( 'Value', 'spider-elements' ), |
| 150 | 'type' => Controls_Manager::NUMBER, |
| 151 | 'default' => 85, |
| 152 | 'min' => 0, |
| 153 | 'max' => 100, |
| 154 | ] |
| 155 | ); |
| 156 | |
| 157 | // Control for Number Prefix & Suffix |
| 158 | $this->add_control( |
| 159 | 'counter_prefix', [ |
| 160 | 'label' => esc_html__( 'Number Prefix', 'spider-elements' ), |
| 161 | 'type' => \Elementor\Controls_Manager::TEXT, |
| 162 | ] |
| 163 | ); |
| 164 | |
| 165 | $this->add_control( |
| 166 | 'counter_suffix', [ |
| 167 | 'label' => esc_html__( 'Number Suffix', 'spider-elements' ), |
| 168 | 'type' => \Elementor\Controls_Manager::TEXT, |
| 169 | 'default' => '%', |
| 170 | ] |
| 171 | ); |
| 172 | |
| 173 | $this->add_control( |
| 174 | 'counter_text', [ |
| 175 | 'label' => esc_html__( 'Title', 'spider-elements' ), |
| 176 | 'type' => Controls_Manager::TEXT, |
| 177 | 'default' => esc_html__( 'User research', 'spider-elements' ), |
| 178 | ] |
| 179 | ); |
| 180 | |
| 181 | $this->end_controls_section(); //End Counter |
| 182 | |
| 183 | } |
| 184 | |
| 185 | |
| 186 | /** |
| 187 | * Name: counter_style_control() |
| 188 | * Desc: Register the Style Tab output on the Elementor editor. |
| 189 | * Params: no params |
| 190 | * Return: @void |
| 191 | * Since: @1.0.0 |
| 192 | * Package: @spider-elements |
| 193 | * Author: spider-themes |
| 194 | */ |
| 195 | public function counter_style_control(): void { |
| 196 | |
| 197 | //===================== Counter Style ============================// |
| 198 | $this->start_controls_section( |
| 199 | 'style_counter', [ |
| 200 | 'label' => esc_html__( 'Counter', 'spider-elements' ), |
| 201 | 'tab' => Controls_Manager::TAB_STYLE, |
| 202 | ] |
| 203 | ); |
| 204 | |
| 205 | $this->add_group_control( |
| 206 | \Elementor\Group_Control_Background::get_type(), |
| 207 | [ |
| 208 | 'name' => 'style_bg', |
| 209 | 'types' => [ 'classic', 'gradient' ], |
| 210 | 'exclude' => [ 'image' ], |
| 211 | 'selector' => '{{WRAPPER}} .skill_item_two .radial-progress', |
| 212 | 'condition' => [ |
| 213 | 'style' => [ '2' ] |
| 214 | ] |
| 215 | ] |
| 216 | ); |
| 217 | |
| 218 | $this->add_control( |
| 219 | 'style_radius', |
| 220 | [ |
| 221 | 'label' => esc_html__( 'Border Radius', 'spider-elements' ), |
| 222 | 'type' => Controls_Manager::DIMENSIONS, |
| 223 | 'size_units' => [ 'px' ], |
| 224 | 'selectors' => [ |
| 225 | '{{WRAPPER}} .skill_item_two .radial-progress' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 226 | ], |
| 227 | 'condition' => [ |
| 228 | 'style' => [ '2' ] |
| 229 | ] |
| 230 | ] |
| 231 | ); |
| 232 | |
| 233 | $this->add_responsive_control( |
| 234 | 'counter_circle_size', |
| 235 | [ |
| 236 | 'label' => esc_html__( 'Size', 'spider-elements' ), |
| 237 | 'type' => Controls_Manager::SLIDER, |
| 238 | 'size_units' => [ 'px' ], |
| 239 | 'range' => [ |
| 240 | 'px' => [ |
| 241 | 'min' => 50, |
| 242 | 'max' => 500, |
| 243 | 'step' => 1, |
| 244 | ], |
| 245 | ], |
| 246 | 'default' => [ |
| 247 | 'unit' => 'px', |
| 248 | 'size' => 100, |
| 249 | ], |
| 250 | 'selectors' => [ |
| 251 | '{{WRAPPER}} .skill_item svg.radial-progress' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};' |
| 252 | ], |
| 253 | 'separator' => 'after', |
| 254 | ] |
| 255 | ); |
| 256 | |
| 257 | $this->add_control( |
| 258 | 'fill_color', |
| 259 | [ |
| 260 | 'label' => esc_html__( 'Fill Color', 'spider-elements' ), |
| 261 | 'type' => Controls_Manager::COLOR, |
| 262 | 'selectors' => [ |
| 263 | '{{WRAPPER}} svg.radial-progress circle.incomplete' => 'stroke: {{VALUE}};', |
| 264 | ], |
| 265 | ] |
| 266 | ); |
| 267 | |
| 268 | $this->add_control( |
| 269 | 'stroke_color', |
| 270 | [ |
| 271 | 'label' => esc_html__( 'Stroke Color', 'spider-elements' ), |
| 272 | 'type' => Controls_Manager::COLOR, |
| 273 | 'selectors' => [ |
| 274 | '{{WRAPPER}} .radial-progress .complete' => 'stroke: {{VALUE}};', |
| 275 | ], |
| 276 | ] |
| 277 | ); |
| 278 | |
| 279 | $this->add_responsive_control( |
| 280 | 'counter_circle_stroke_width', [ |
| 281 | 'label' => esc_html__( 'Stroke Width', 'spider-elements' ), |
| 282 | 'type' => Controls_Manager::SLIDER, |
| 283 | 'size_units' => [ 'px' ], |
| 284 | 'range' => [ |
| 285 | 'px' => [ |
| 286 | 'min' => 0, |
| 287 | 'max' => 100, |
| 288 | 'step' => 1, |
| 289 | ], |
| 290 | ], |
| 291 | 'default' => [ |
| 292 | 'unit' => 'px', |
| 293 | 'size' => 6, |
| 294 | ], |
| 295 | 'selectors' => [ |
| 296 | '{{WRAPPER}} svg.radial-progress circle' => 'stroke-width: {{SIZE}}{{UNIT}}', |
| 297 | ], |
| 298 | 'separator' => 'before', |
| 299 | ] |
| 300 | ); |
| 301 | |
| 302 | $this->end_controls_section(); |
| 303 | |
| 304 | |
| 305 | // Control for percent color |
| 306 | $this->start_controls_section( |
| 307 | 'number_style', [ |
| 308 | 'label' => esc_html__( 'Number', 'spider-elements' ), |
| 309 | 'tab' => Controls_Manager::TAB_STYLE, |
| 310 | ] |
| 311 | ); |
| 312 | |
| 313 | $this->add_group_control( |
| 314 | Group_Control_Typography::get_type(), [ |
| 315 | 'name' => 'number_typo', |
| 316 | 'selector' => '{{WRAPPER}} .counters-container .skill_item .counter-wrap, |
| 317 | {{WRAPPER}} .skill_item_two .skill_pr .counter2-wrap', |
| 318 | ] |
| 319 | |
| 320 | ); |
| 321 | |
| 322 | $this->add_control( |
| 323 | 'number_color', |
| 324 | [ |
| 325 | 'label' => esc_html__( 'Color', 'spider-elements' ), |
| 326 | 'type' => Controls_Manager::COLOR, |
| 327 | 'selectors' => [ |
| 328 | '{{WRAPPER}} .counters-container .skill_item .counter-wrap' => 'color: {{VALUE}};', |
| 329 | '{{WRAPPER}} .skill_item_two .skill_pr .counter2-wrap' => 'color: {{VALUE}};', |
| 330 | ], |
| 331 | ] |
| 332 | ); |
| 333 | |
| 334 | $this->add_responsive_control( |
| 335 | 'prefix_suffix_size', |
| 336 | [ |
| 337 | 'label' => esc_html__( 'Number Gap', 'spider-elements' ), |
| 338 | 'type' => Controls_Manager::SLIDER, |
| 339 | 'size_units' => [ 'px', 'em', 'rem', '%' ], |
| 340 | 'range' => [ |
| 341 | 'px' => [ |
| 342 | 'min' => 0, |
| 343 | 'max' => 500, |
| 344 | 'step' => 1, |
| 345 | ], |
| 346 | 'em' => [ |
| 347 | 'min' => 0, |
| 348 | 'max' => 50, |
| 349 | 'step' => 0.1, |
| 350 | ], |
| 351 | 'rem' => [ |
| 352 | 'min' => 0, |
| 353 | 'max' => 50, |
| 354 | 'step' => 0.1, |
| 355 | ], |
| 356 | '%' => [ |
| 357 | 'min' => 0, |
| 358 | 'max' => 100, |
| 359 | 'step' => 1, |
| 360 | ], |
| 361 | ], |
| 362 | 'selectors' => [ |
| 363 | '{{WRAPPER}} .counter-wrap' => 'gap: {{SIZE}}{{UNIT}};', |
| 364 | '{{WRAPPER}} .counter2-wrap' => 'gap: {{SIZE}}{{UNIT}};' |
| 365 | ], |
| 366 | 'separator' => 'before', |
| 367 | ] |
| 368 | ); |
| 369 | |
| 370 | $this->end_controls_section(); |
| 371 | |
| 372 | // Control for text color |
| 373 | $this->start_controls_section( |
| 374 | 'counter_title', [ |
| 375 | 'label' => esc_html__( 'Title', 'spider-elements' ), |
| 376 | 'tab' => Controls_Manager::TAB_STYLE, |
| 377 | ] |
| 378 | ); |
| 379 | |
| 380 | $this->add_group_control( |
| 381 | Group_Control_Typography::get_type(), [ |
| 382 | 'name' => 'counter_text_typo', |
| 383 | 'selector' => '{{WRAPPER}} .counters-container .spel_counter_title, |
| 384 | {{WRAPPER}} .skill_item .spel_counter_title' |
| 385 | ] |
| 386 | ); |
| 387 | |
| 388 | $this->add_control( |
| 389 | 'counter_text_color', |
| 390 | [ |
| 391 | 'label' => esc_html__( 'Color', 'spider-elements' ), |
| 392 | 'type' => Controls_Manager::COLOR, |
| 393 | 'selectors' => [ |
| 394 | '{{WRAPPER}} .skill_item .spel_counter_title' => 'color: {{VALUE}};', |
| 395 | '{{WRAPPER}} .counters-container .spel_counter_title' => 'color: {{VALUE}};', |
| 396 | ], |
| 397 | ] |
| 398 | ); |
| 399 | |
| 400 | $this->add_responsive_control( |
| 401 | 'counter_text_margin', |
| 402 | [ |
| 403 | 'label' => esc_html__( 'Margin Top', 'spider-elements' ), |
| 404 | 'type' => Controls_Manager::SLIDER, |
| 405 | 'size_units' => [ 'px', '%' ], |
| 406 | 'range' => [ |
| 407 | 'px' => [ |
| 408 | 'min' => 0, |
| 409 | 'max' => 100, |
| 410 | 'step' => 1, |
| 411 | ], |
| 412 | ], |
| 413 | 'default' => [ |
| 414 | 'size' => 6, |
| 415 | ], |
| 416 | 'selectors' => [ |
| 417 | '{{WRAPPER}} .skill_item .spel_counter_title' => 'margin-top: {{SIZE}}{{UNIT}}', |
| 418 | '{{WRAPPER}} .counters-container .spel_counter_title' => 'margin-top: {{SIZE}}{{UNIT}}', |
| 419 | |
| 420 | ], |
| 421 | ] |
| 422 | ); |
| 423 | $this->end_controls_section(); |
| 424 | |
| 425 | } |
| 426 | |
| 427 | /** |
| 428 | * Name: elementor_render() |
| 429 | * Desc: Render the widget output on the frontend. |
| 430 | * Params: no params |
| 431 | * Return: @void |
| 432 | * Since: @1.0.0 |
| 433 | * Package: @spider-elements |
| 434 | * Author: spider-themes |
| 435 | */ |
| 436 | protected function render(): void { |
| 437 | $settings = $this->get_settings_for_display(); |
| 438 | extract( $settings ); //extract all settings array to variables converted to name of key |
| 439 | |
| 440 | //================= Template Parts =================// |
| 441 | // Whitelist valid style values to prevent Local File Inclusion |
| 442 | $allowed_styles = array( '1', '2' ); |
| 443 | $style = isset( $settings['style'] ) && in_array( $settings['style'], $allowed_styles, true ) ? $settings['style'] : '1'; |
| 444 | if ( spel_is_premium() ) { |
| 445 | include __DIR__ . "/templates/counter/counter-{$style}.php"; |
| 446 | } else { |
| 447 | include __DIR__ . "/templates/counter/counter-1.php"; |
| 448 | } |
| 449 | |
| 450 | } |
| 451 | } |