Plugin Directory

source: cowidgets-elementor-addons/trunk/inc/widgets-manager/widgets/content/class-ce-testimonial-carousel.php

Last change on this file was 3099564, checked in by codelessthemes, 11 months ago

fixed security bugs

File size: 18.9 KB
Line 
1<?php
2/**
3 * Elementor Classes.
4 *
5 * @package CoWidgets
6 */
7
8namespace COWIDGETS\WidgetsManager\Widgets;
9
10use Elementor\Controls_Manager;
11use Elementor\Utils;
12use Elementor\Group_Control_Typography;
13use Elementor\Core\Schemes\Typography;
14use Elementor\Core\Schemes\Color;
15use Elementor\Widget_Base;
16use Elementor\Group_Control_Image_Size;
17
18if ( ! defined( 'ABSPATH' ) ) {
19        exit;   // Exit if accessed directly.
20}
21
22/**
23 * Elementor Testimonial Carousel
24 *
25 * Elementor widget for Testimonial Carousel.
26 *
27 * @since 1.0.0
28 */
29class Testimonial_Carousel extends Widget_Base {
30
31        /**
32         * Retrieve the widget name.
33         *
34         * @since 1.0.0
35         *
36         * @access public
37         *
38         * @return string Widget name.
39         */
40        public function get_name() {
41                return 'ce-testimonial-carousel';
42        }
43        /**
44         * Retrieve the widget title.
45         *
46         * @since 1.0.0
47         *
48         * @access public
49         *
50         * @return string Widget title.
51         */
52        public function get_title() {
53                return __( 'Testimonial Carousel', 'cowidgets' );
54        }
55        /**
56         * Retrieve the widget icon.
57         *
58         * @since 1.0.0
59         *
60         * @access public
61         *
62         * @return string Widget icon.
63         */
64        public function get_icon() {
65                return 'ce-icon-testimonial-carousel';
66        }
67        /**
68         * Retrieve the list of categories the widget belongs to.
69         *
70         * Used to determine where to display the widget in the editor.
71         *
72         * Note that currently Elementor supports only one category.
73         * When multiple categories passed, Elementor uses the first one.
74         *
75         * @since 1.0.0
76         *
77         * @access public
78         *
79         * @return array Widget categories.
80         */
81        public function get_categories() {
82                return [ 'ce-content-widgets' ];
83        }
84
85        public function get_script_depends() {
86                return [ 'ce-testimonial-carousel', 'tiny-slider' ];
87    }
88   
89    public function get_style_depends() {               
90        return [ 'tiny-slider' ];
91    }
92
93        /**
94         * Register controls.
95         *
96         * @since 1.0.0
97         * @access protected
98         */
99        protected function register_controls() {
100                $this->register_testimonial_carousel_controls();
101        }
102        /**
103         * Register General Controls.
104         *
105         * @since 1.0.0
106         * @access protected
107         */
108        protected function register_testimonial_carousel_controls() {
109                \COWIDGETS_Helpers::testimonialSelectionSection( $this );
110                $this->start_controls_section(
111                        'section_content_style',
112                        [
113                                'label'     => __( 'Item Layout/Style', 'cowidgets' ),
114                                'tab'       => Controls_Manager::TAB_CONTENT,
115                        ]
116                );
117
118                $this->add_control(
119                        'item_style',
120                        [
121                                'label' => __( 'Style', 'cowidgets' ),
122                                'type' => \Elementor\Controls_Manager::SELECT,
123                                'default' => 'beas',
124                                'options' => apply_filters( 'ce_load_element_styles', [
125                                       
126                                        'beas'  => __( 'Beas', 'cowidgets' ),
127                                        'tista' => __( 'Tista', 'cowidgets' ),
128                                        'talia' => __( 'Talia', 'cowidgets' ),
129                                        'alder' => __( 'Alder', 'cowidgets' ),
130                                        'tapi'  => __( 'Tapi', 'cowidgets' ),
131                                        'modern'        => __( 'Modern', 'cowidgets' ),
132                                ] ),
133                        ]
134        );
135       
136        $this->add_control(
137                        'columns',
138                        [
139                                'label' => __( 'Columns', 'cowidgets' ),
140                                'type' => \Elementor\Controls_Manager::SELECT,
141                                'default' => '2',
142                                'options' => [
143                    1                           => __( '1', 'cowidgets' ),
144                    2                           => __( '2', 'cowidgets' ),
145                    3                           => __( '3', 'cowidgets' ),
146                    4                           => __( '4', 'cowidgets' ),
147                    5                           => __( '5', 'cowidgets' ),
148                    6                           => __( '6', 'cowidgets' ),
149                    7                           => __( '7', 'cowidgets' ),
150                                ],
151                                'render_type' => 'template'
152                        ]
153                );
154               
155                $this->end_controls_section();
156
157                $this->start_controls_section(
158                        'section_content_carousel',
159                        [
160                                'label'     => __( 'Carousel Options', 'cowidgets' ),
161                                'tab'       => Controls_Manager::TAB_CONTENT,
162                        ]
163                );
164       
165        $this->add_control(
166                        'slide_by',
167                        [
168                                'label' => __( 'Slide By', 'cowidgets' ),
169                                'type' => \Elementor\Controls_Manager::SELECT,
170                                'default' => 1,
171                                'options' => [
172                    '1'                         => __( '1', 'cowidgets' ),
173                    'page'                      => __( 'Page', 'cowidgets' ),
174                                ],
175                        ]
176        );
177
178        $this->add_control(
179                        'mode',
180                        [
181                                'label' => __( 'Mode', 'cowidgets' ),
182                                'type' => \Elementor\Controls_Manager::SELECT,
183                                'default' => 'carousel',
184                                'options' => [
185                    'carousel'  => __( 'Carousel', 'cowidgets' ),
186                    'gallery'   => __( 'Gallery', 'cowidgets' ),
187                                ],
188                        ]
189        );
190       
191        $this->add_control(
192                        'autoplay',
193                        [
194                                'label' => __( 'Autoplay', 'cowidgets' ),
195                                'type' => \Elementor\Controls_Manager::SELECT,
196                                'default' => 0,
197                                'options' => [
198                    0   => __( 'No', 'cowidgets' ),
199                    1   => __( 'Yes', 'cowidgets' ),
200                                ],
201                        ]
202        );
203
204        $this->add_control(
205                        'loop',
206                        [
207                                'label' => __( 'Loop', 'cowidgets' ),
208                                'type' => \Elementor\Controls_Manager::SELECT,
209                                'default' => 0,
210                                'options' => [
211                    0   => __( 'No', 'cowidgets' ),
212                    1   => __( 'Yes', 'cowidgets' ),
213                                ],
214                        ]
215        );
216
217       
218
219        $this->add_control(
220                        'center',
221                        [
222                                'label' => __( 'Center', 'cowidgets' ),
223                                'type' => \Elementor\Controls_Manager::SELECT,
224                                'default' => 0,
225                                'options' => [
226                    0   => __( 'No', 'cowidgets' ),
227                    1   => __( 'Yes', 'cowidgets' ),
228                                ],
229                        ]
230        );
231
232        $this->add_control(
233                        'mouse_drag',
234                        [
235                                'label' => __( 'Mouse Drag', 'cowidgets' ),
236                                'type' => \Elementor\Controls_Manager::SELECT,
237                                'default' => 1,
238                                'options' => [
239                    0   => __( 'No', 'cowidgets' ),
240                    1   => __( 'Yes', 'cowidgets' ),
241                                ],
242                        ]
243                );
244               
245                $this->add_control(
246                        'carousel_controls',
247                        [
248                                'label' => __( 'Prev/Next Buttons', 'cowidgets' ),
249                                'type' => \Elementor\Controls_Manager::SELECT,
250                                'default' => 0,
251                                'options' => [
252                    0   => __( 'No', 'cowidgets' ),
253                    1   => __( 'Yes', 'cowidgets' ),
254                                ],
255                        ]
256        );
257
258        $this->add_control(
259                        'vertical_align',
260                        [
261                                'label' => __( 'Items Vertical Align', 'cowidgets' ),
262                                'type' => \Elementor\Controls_Manager::SELECT,
263                                'default' => 'top',
264                                'options' => [
265                    'top'           => __( 'Top', 'cowidgets' ),
266                    'middle'    => __( 'Middle', 'cowidgets' ),
267                    'bottom'    => __( 'Bottom', 'cowidgets' ),
268                ],
269                'selectors' => [
270                    '{{WRAPPER}} .ce-testimonial-carousel .tns-item' => 'vertical-align: {{VALUE}}',
271                ],
272
273                'render_type' => 'template'
274                        ]
275        );
276
277        $this->add_control(
278                        'start_index',
279                        [
280                                'label' => __( 'Start Index', 'cowidgets' ),
281                                'type' => \Elementor\Controls_Manager::TEXT,
282                                'default' => '0',
283                        ]
284        );
285       
286        $this->add_control(
287                        'gutter',
288                        [
289                                'label'       => __( 'Space between items', 'cowidgets' ),
290                                'type'        => Controls_Manager::SLIDER,
291                                'size_units'  => ['px'],
292                                'range'       => [
293                                        'px' => [
294                                                'max' => 500,
295                                                'min' => 0,
296                                        ],
297                                ],
298                                'default'     => [
299                                        'size' => 15,
300                                        'unit' => 'px',
301                                ],
302                                'render_type' => 'template',
303                        ]
304        );
305
306
307       
308        $this->add_control(
309                        'edge_padding',
310                        [
311                                'label'       => __( 'Space on the outside', 'cowidgets' ),
312                                'type'        => Controls_Manager::SLIDER,
313                                'size_units'  => ['px'],
314                                'range'       => [
315                                        'px' => [
316                                                'max' => 500,
317                                                'min' => 0,
318                                        ],
319                                ],
320                                'default'     => [],
321                                'render_type' => 'template',
322                        ]
323                );
324
325                $this->add_control(
326                        'edge_padding_side',
327                        [
328                                'label'       => __( 'Space on the outside only one side', 'cowidgets' ),
329                                'type' => \Elementor\Controls_Manager::SELECT,
330                                'default' => 0,
331                                'options' => [
332                    0   => __( 'No', 'cowidgets' ),
333                    1   => __( 'Yes', 'cowidgets' ),
334                                ],
335                        ]
336                );
337
338                $this->end_controls_section();
339
340                $this->start_controls_section(
341                        'section_style',
342                        [
343                                'label'     => __( 'Global', 'cowidgets' ),
344                                'tab'       => Controls_Manager::TAB_STYLE
345                        ]
346                );
347
348                $this->add_control(
349                        'global_important_note',
350                        [
351                                'type' => \Elementor\Controls_Manager::RAW_HTML,
352                                'raw' => __( 'This section contains global styling options of this element. Some of this options should not work on specific selected styles. Please check the section below for style-specific options.', 'cowidgets' ),
353                                'content_classes' => 'important_note'
354                        ]
355                );
356
357                $this->add_group_control(
358                        \Elementor\Group_Control_Typography::get_type(),
359                        [
360                                'name' => 'text_typography',
361                                'label' => __( 'Item Text Typography', 'plugin-domain' ),
362                                'scheme' => Typography::TYPOGRAPHY_1,
363                                'selector' => '{{WRAPPER}} .ce-testimonial-item .text',
364                        ]
365                );
366
367                $this->add_control(
368                        'item_title_color',
369                        [
370                                'label' => __( 'Item Text Color', 'cowidgets' ),
371                                'type' => \Elementor\Controls_Manager::COLOR,
372                               
373                                'selectors' => [
374                                        '{{WRAPPER}} .ce-testimonial-item .text' => 'color: {{VALUE}}',
375                                ],
376                        ]
377        );
378       
379        $this->add_group_control(
380                        \Elementor\Group_Control_Typography::get_type(),
381                        [
382                                'name' => 'testimon_typography',
383                                'label' => __( 'Item Testimon Name Typography', 'plugin-domain' ),
384                                'scheme' => Typography::TYPOGRAPHY_1,
385                                'selector' => '{{WRAPPER}} .ce-testimonial-item .data .title',
386                        ]
387                );
388
389                $this->add_control(
390                        'testimon_color',
391                        [
392                                'label' => __( 'Item Testimon Name Color', 'cowidgets' ),
393                                'type' => \Elementor\Controls_Manager::COLOR,
394                               
395                                'selectors' => [
396                                        '{{WRAPPER}} .ce-testimonial-item .data .title' => 'color: {{VALUE}}',
397                                ],
398                        ]
399        );
400       
401        $this->add_group_control(
402                        \Elementor\Group_Control_Typography::get_type(),
403                        [
404                                'name' => 'testimon_position_typography',
405                                'label' => __( 'Item Work Position Typography', 'plugin-domain' ),
406                                'scheme' => Typography::TYPOGRAPHY_1,
407                                'selector' => '{{WRAPPER}} .ce-testimonial-item .data .position',
408                        ]
409                );
410
411                $this->add_control(
412                        'testimon_position_color',
413                        [
414                                'label' => __( 'Item Work Position Color', 'cowidgets' ),
415                                'type' => \Elementor\Controls_Manager::COLOR,
416                               
417                                'selectors' => [
418                                        '{{WRAPPER}} .ce-testimonial-item .data .position' => 'color: {{VALUE}}',
419                                ],
420                        ]
421                );
422
423
424                $this->end_controls_section();
425
426                $this->start_controls_section(
427                        'section_specific_style',
428                        [
429                                'label'     => __( 'Style-specific', 'cowidgets' ),
430                                'tab'       => Controls_Manager::TAB_STYLE,
431                        ]
432                );
433
434                $this->add_control(
435                        'specific_important_note',
436                        [
437                                'type' => \Elementor\Controls_Manager::RAW_HTML,
438                                'raw' => __( 'This section contains style-specific options, these options may disappear when you change selected item-style', 'cowidgets' ),
439                                'content_classes' => 'important_note'
440                        ]
441                );
442
443                do_action( 'ce_load_style_specific_options', $this );
444
445                $this->add_control(
446                        'separator_color',
447                        [
448                                'label' => __( 'Separator Color', 'cowidgets' ),
449                                'type' => \Elementor\Controls_Manager::COLOR,
450                               
451                                'selectors' => [
452                                        '{{WRAPPER}} .ce-testimonial-item .data' => 'border-color: {{VALUE}}',
453                                ],
454                                'condition' => [
455                                        'item_style' => 'beas'
456                                ]
457                        ]
458        );
459
460        $this->add_control(
461                        'quote_color',
462                        [
463                                'label' => __( 'Quote SVG Color', 'cowidgets' ),
464                                'type' => \Elementor\Controls_Manager::COLOR,
465                               
466                                'selectors' => [
467                                        '{{WRAPPER}} .ce-testimonial-item svg path' => 'fill: {{VALUE}}',
468                                ],
469                                'condition' => [
470                                        'item_style' => 'beas'
471                                ]
472                        ]
473                );
474       
475        $this->add_control(
476                        'nav_item_color',
477                        [
478                                'label' => __( 'Prev/Next Color', 'cowidgets' ),
479                                'type' => \Elementor\Controls_Manager::COLOR,
480                               
481                                'selectors' => [
482                                        '{{WRAPPER}} .ce-testimonial-item .ce-testimonial-carousel-controls a' => 'color: {{VALUE}}',
483                                ],
484                                'condition' => [
485                                        'item_style' => 'beas'
486                                ]
487                        ]
488                );
489
490
491                $this->end_controls_section();
492       
493        \COWIDGETS_Helpers::animationSection( $this );
494        }
495
496        function set_source_type( $source ){
497                $this->source_type = $source;
498        }
499
500        function get_source_type(){
501                return $this->source_type;
502        }
503
504        /**
505         * Render Copyright output on the frontend.
506         *
507         * Written in PHP and used to generate the final HTML.
508         *
509         * @since 1.0.0
510         * @access protected
511         */
512        protected function render() {
513        $settings = $this->get_settings_for_display();
514
515                $this->set_source_type( $settings['source_type'] );
516
517        $this->add_render_attribute( 'ce-testimonial-carousel', 'class', [ 'ce-testimonial-carousel', 'ce-testimonial-style-' . $settings['item_style'] ] );
518                $this->add_render_attribute( 'ce-testimonial-carousel', 'data-columns', $settings['columns'] );
519        $this->add_render_attribute( 'ce-testimonial-carousel', 'data-autoplay', $settings['autoplay'] );
520        $this->add_render_attribute( 'ce-testimonial-carousel', 'data-slide-by', ( $settings['slide_by'] == 'page' ? $settings['columns'] : $settings['slide_by'] ) );
521        $this->add_render_attribute( 'ce-testimonial-carousel', 'data-loop', $settings['loop'] );
522        $this->add_render_attribute( 'ce-testimonial-carousel', 'data-gutter', $settings['gutter']['size'] );
523        $this->add_render_attribute( 'ce-testimonial-carousel', 'data-center', $settings['center'] );
524        $this->add_render_attribute( 'ce-testimonial-carousel', 'data-mode', $settings['mode'] );
525                $this->add_render_attribute( 'ce-testimonial-carousel', 'data-mouse-drag', $settings['mouse_drag'] );
526                $this->add_render_attribute( 'ce-testimonial-carousel', 'data-edge-padding-side', $settings['edge_padding_side'] );
527                $this->add_render_attribute( 'ce-testimonial-carousel', 'data-carousel-controls', $settings['carousel_controls'] );
528
529        $this->add_render_attribute( 'ce-testimonial-item', 'class', ['ce-testimonial-item'] );
530
531        if( $settings['ce_animation'] != 'none' ){
532            $this->add_render_attribute( 'ce-testimonial-item', 'class', ['ce-animation', 'ce-animation--'.$settings['ce_animation'], 'ce-animation-manual' ] );
533            $this->add_render_attribute( 'ce-testimonial-item', 'data-speed', $settings['ce_animation_speed'] );
534           
535        }
536
537        if( isset( $settings['edge_padding'] ) && !empty( $settings['edge_padding'] ) )
538            $this->add_render_attribute( 'ce-testimonial-carousel', 'data-edge-padding', $settings['edge_padding']['size'] );
539
540        if( isset( $settings['start_index'] ) && !empty( $settings['start_index'] ) )
541            $this->add_render_attribute( 'ce-testimonial-carousel', 'data-start-index', $settings['start_index'] );
542       
543
544                ?>
545               
546                <div <?php echo wp_kses_post( $this->get_render_attribute_string( 'ce-testimonial-carousel' ) ); ?>>
547
548            <?php
549               
550                if( $settings['source_type'] == 'testimonial' ){ 
551                    $new_query = array(
552                        'posts_per_page' => (int) $settings['items_per_page'],
553                        'post_type' => 'testimonial' 
554                    );
555
556                                        if( $settings['items_orderby'] != 'none' ){
557                                                $new_query['orderby'] = $settings['items_orderby'];
558                                                $new_query['order'] = $settings['items_order'];
559                                        }
560
561                    if( is_array( $settings['items_categories'] ) && !empty( $settings['items_categories'] ) ) {
562                   
563                        $new_query['tax_query'] = array(
564                           
565                            array(
566                                'taxonomy' => 'testimonial_entries',
567                                'field' => 'slug',
568                                'terms' => $settings['items_categories'],
569                                'operator' => 'IN' 
570                            ) 
571                        );
572                    }
573
574                    if( !empty( $settings['items_testimonial'] ) ){
575                        $new_query['ignore_sticky_posts'] = 1;
576                        $new_query['post__in'] = $settings['items_testimonial'];
577                        $new_query['ignore_custom_sort'] = true;
578                                        }
579                                       
580                }else if( $settings['source_type'] == 'all_post_types' ) {
581                                        $new_query['post__in'] = $settings['items_posts'];
582                                       
583                }
584
585                $the_query = new \WP_Query( $new_query );
586               
587                if ( is_object( $the_query ) && $the_query->have_posts() ) :
588                                        $counter = 0;
589                    // Start loop
590                    while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
591                                                <?php 
592                                                        $counter += 1;
593                                                        $delay = ( $counter * (int) $settings['ce_animation_delay'] );
594                                                        if( $counter > $settings['columns'] )
595                                                                $delay = 0;
596
597
598                                                        $this->add_render_attribute( 'ce-testimonial-item-'.get_the_ID(), 'data-delay', $delay );
599                                                ?>
600                        <?php
601                                                // Sanitize the item_style parameter
602                                                $sanitized_item_style = sanitize_file_name( $settings['item_style'] );
603
604                                                // Construct the file path
605                                                $file_path = COWIDGETS_DIR . '/inc/widgets-manager/widgets/content/partials/testimonial/' . $sanitized_item_style . '.php';
606
607                                                // Validate the file path to ensure it's within the expected directory
608                                                if ( realpath($file_path) && strpos( realpath($file_path), realpath(COWIDGETS_DIR . '/inc/widgets-manager/widgets/content/partials/testimonial/') ) === 0 ) {
609                                                        // Include the file if it exists and is within the expected directory
610                                                        include( $file_path );
611                                                } else {
612                                                        // Handle the error, e.g., show a default message or log the error
613                                                        echo 'Invalid file path';
614                                                }
615                                                ?>
616
617                    <?php endwhile; ?>
618                <?php wp_reset_postdata(); ?>
619                <?php endif; ?>
620                               
621                </div>
622                <?php if( $settings['carousel_controls'] && $settings['item_style'] == 'modern' ){ ?>
623                        <div class="container">
624                                <div class="ce-carousel-head">
625                        <div class="ce-testimonial-carousel-controls">
626                            <a href="#" class="ce-prev"><i class="feather feather-arrow-left"></i></a>
627                            <a href="#" class="ce-next"><i class="feather feather-arrow-right"></i></a>
628                        </div>
629                        <div class="clearfix"></div>
630                                </div>
631                        </div>                 
632                <?php } ?>
633                <?php
634        }
635
636
637        /**
638         * Render shortcode widget output in the editor.
639         *
640         * Written as a Backbone JavaScript template and used to generate the live preview.
641         *
642         * @since 1.0.0
643         * @access protected
644         */
645        protected function content_template() {}
646
647        /**
648         * Render shortcode output in the editor.
649         *
650         * Written as a Backbone JavaScript template and used to generate the live preview.
651         *
652         * Remove this after Elementor v3.3.0
653         *
654         * @since 1.0.0
655         * @access protected
656         */
657        protected function _content_template() {
658                $this->content_template();
659        }
660}
Note: See TracBrowser for help on using the repository browser.