PluginProbe
Sight – Professional Image Gallery and Portfolio / 1.0.6
Sight – Professional Image Gallery and Portfolio v1.0.6
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8
sight / elementor / widget-portfolio.php

widget-portfolio.php in Sight – Professional Image Gallery and Portfolio 1.0.6, at elementor/widget-portfolio.php

1,094 lines 24.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Widget Portfolio.
4 *
5 * @package Sight
6 */
7
8 namespace Sight_Elementor\Widgets;
9
10 use Elementor\Widget_Base;
11 use Elementor\Controls_Manager;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Elementor Widget
19 *
20 * @since 1.0.0
21 */
22 class Sight_Widget_Portfolio extends Widget_Base {
23
24 /**
25 * Retrieve the widget name.
26 *
27 * @since 1.0.0
28 *
29 * @access public
30 *
31 * @return string Widget name.
32 */
33 public function get_name() {
34 return 'sight-portfolio-widget';
35 }
36
37 /**
38 * Retrieve the widget title.
39 *
40 * @since 1.0.0
41 *
42 * @access public
43 *
44 * @return string Widget title.
45 */
46 public function get_title() {
47 return esc_html__( 'Portfolio', 'sight' );
48 }
49
50 /**
51 * Retrieve the widget icon.
52 *
53 * @since 1.0.0
54 *
55 * @access public
56 *
57 * @return string Widget icon.
58 */
59 public function get_icon() {
60 return 'eicon-call-to-action';
61 }
62
63 /**
64 * Retrieve the list of categories the widget belongs to.
65 *
66 * Used to determine where to display the widget in the editor.
67 *
68 * Note that currently Elementor supports only one category.
69 * When multiple categories passed, Elementor uses the first one.
70 *
71 * @since 1.0.0
72 *
73 * @access public
74 *
75 * @return array Widget categories.
76 */
77 public function get_categories() {
78 return array( 'basic' );
79 }
80
81 /**
82 * Registers layouts of block.
83 */
84 public function widget_layouts() {
85 $layouts = array(
86 'standard' => array(
87 'name' => esc_html__( 'Standard', 'sight' ),
88 'template' => SIGHT_PATH . 'render/handler/post-area-init.php',
89 ),
90 );
91
92 // Return.
93 return apply_filters( 'sight_widget_portfolio_layouts', $layouts );
94 }
95
96 /**
97 * Get layouts (format: array)
98 *
99 * @access protected
100 */
101 protected function get_array_layouts() {
102 $widget_layouts = $this->widget_layouts();
103
104 $layouts = array();
105
106 foreach ( $widget_layouts as $key => $attrs ) {
107 $layouts[ $key ] = $attrs['name'];
108 }
109
110 return $layouts;
111 }
112
113 /**
114 * Register the widget controls.
115 *
116 * Adds different input fields to allow the user to change and customize the widget settings.
117 *
118 * @since 1.0.0
119 *
120 * @access protected
121 */
122 protected function _register_controls() {
123
124 $this->start_controls_section(
125 'layout_section',
126 array(
127 'label' => esc_html__( 'Layout', 'sight' ),
128 )
129 );
130
131 do_action( 'sight/widget/fields/before', $this );
132
133 $this->add_control(
134 'layout',
135 array(
136 'label' => esc_html__( 'Layout', 'sight' ),
137 'type' => Controls_Manager::SELECT,
138 'default' => 'standard',
139 'options' => $this->get_array_layouts(),
140 )
141 );
142
143 $this->end_controls_section();
144
145 $this->start_controls_section(
146 'general',
147 array(
148 'label' => esc_html__( 'General Settings', 'sight' ),
149 )
150 );
151
152 do_action( 'sight/widget/fields/general/before', $this );
153
154 $this->add_control(
155 'source',
156 array(
157 'label' => esc_html__( 'Source', 'sight' ),
158 'type' => Controls_Manager::SELECT,
159 'default' => 'projects',
160 'options' => array(
161 'projects' => esc_html__( 'Projects', 'sight' ),
162 'custom' => esc_html__( 'Images', 'sight' ),
163 'categories' => esc_html__( 'Categories', 'sight' ),
164 'post' => esc_html__( 'Post Attachments', 'sight' ),
165 ),
166 )
167 );
168
169 /* Type Projects */
170
171 $this->add_control(
172 'video',
173 array(
174 'label' => esc_html__( 'Video Background', 'sight' ),
175 'type' => Controls_Manager::SELECT,
176 'default' => 'always',
177 'options' => array(
178 'none' => esc_html__( 'None', 'sight' ),
179 'always' => esc_html__( 'Always', 'sight' ),
180 'hover' => esc_html__( 'On Hover', 'sight' ),
181 ),
182 'conditions' => array(
183 'relation' => 'and',
184 'terms' => array(
185 array(
186 'name' => 'source',
187 'operator' => '==',
188 'value' => 'projects',
189 ),
190 ),
191 ),
192 )
193 );
194
195 $this->add_control(
196 'video_controls',
197 array(
198 'label' => esc_html__( 'Enable video controls', 'sight' ),
199 'type' => Controls_Manager::SWITCHER,
200 'return_value' => 'true',
201 'default' => 'true',
202 'conditions' => array(
203 'relation' => 'and',
204 'terms' => array(
205 array(
206 'name' => 'source',
207 'operator' => '==',
208 'value' => 'projects',
209 ),
210 array(
211 'name' => 'video',
212 'operator' => '!=',
213 'value' => 'none',
214 ),
215 ),
216 ),
217 )
218 );
219
220 /* Post */
221
222 $this->add_control(
223 'custom_post',
224 array(
225 'label' => esc_html__( 'Post', 'sight' ),
226 'type' => 'custom_post',
227 'conditions' => array(
228 'relation' => 'and',
229 'terms' => array(
230 array(
231 'name' => 'source',
232 'operator' => '==',
233 'value' => 'post',
234 ),
235 ),
236 ),
237 )
238 );
239
240 /* Type Custom */
241
242 $this->add_control(
243 'custom_images',
244 array(
245 'label' => esc_html__( 'Images', 'sight' ),
246 'type' => Controls_Manager::GALLERY,
247 'conditions' => array(
248 'relation' => 'and',
249 'terms' => array(
250 array(
251 'name' => 'source',
252 'operator' => '==',
253 'value' => 'custom',
254 ),
255 ),
256 ),
257 )
258 );
259
260 /* Common end */
261
262 $this->add_control(
263 'number_items',
264 array(
265 'label' => esc_html__( 'Number of Items', 'sight' ),
266 'type' => Controls_Manager::NUMBER,
267 'min' => 1,
268 'max' => 100,
269 'step' => 1,
270 'default' => 10,
271 )
272 );
273
274 do_action( 'sight/widget/fields/general/after', $this );
275
276 $this->end_controls_section();
277
278 $this->start_controls_section(
279 'meta',
280 array(
281 'label' => esc_html__( 'Meta Settings', 'sight' ),
282 )
283 );
284
285 do_action( 'sight/widget/fields/meta/after', $this );
286
287 $this->add_control(
288 'meta_title',
289 array(
290 'label' => esc_html__( 'Display item title', 'sight' ),
291 'type' => Controls_Manager::SWITCHER,
292 'return_value' => 'true',
293 'default' => 'true',
294 'conditions' => array(
295 'relation' => 'and',
296 'terms' => array(
297 array(
298 'name' => 'source',
299 'operator' => '!=',
300 'value' => 'post',
301 ),
302 array(
303 'name' => 'source',
304 'operator' => '!=',
305 'value' => 'custom',
306 ),
307 ),
308 ),
309 )
310 );
311
312 $this->add_control(
313 'meta_caption',
314 array(
315 'label' => esc_html__( 'Display item caption', 'sight' ),
316 'type' => Controls_Manager::SWITCHER,
317 'return_value' => 'true',
318 'default' => 'true',
319 )
320 );
321
322 $this->add_control(
323 'meta_caption_length',
324 array(
325 'label' => esc_html__( 'Caption length', 'sight' ),
326 'type' => Controls_Manager::NUMBER,
327 'min' => 1,
328 'max' => 1000,
329 'step' => 1,
330 'default' => 100,
331 'conditions' => array(
332 'relation' => 'and',
333 'terms' => array(
334 array(
335 'name' => 'meta_caption',
336 'operator' => '==',
337 'value' => 'true',
338 ),
339 ),
340 ),
341 )
342 );
343
344 $this->add_control(
345 'meta_category',
346 array(
347 'label' => esc_html__( 'Display meta category', 'sight' ),
348 'type' => Controls_Manager::SWITCHER,
349 'return_value' => 'true',
350 'conditions' => array(
351 'relation' => 'and',
352 'terms' => array(
353 array(
354 'name' => 'source',
355 'operator' => '==',
356 'value' => 'projects',
357 ),
358 array(
359 'name' => 'projects_filter_post_type',
360 'operator' => '==',
361 'value' => 'sight-projects',
362 ),
363 ),
364 ),
365 )
366 );
367
368 $this->add_control(
369 'meta_date',
370 array(
371 'label' => esc_html__( 'Display meta date', 'sight' ),
372 'type' => Controls_Manager::SWITCHER,
373 'return_value' => 'true',
374 'conditions' => array(
375 'relation' => 'and',
376 'terms' => array(
377 array(
378 'name' => 'source',
379 'operator' => '!=',
380 'value' => 'categories',
381 ),
382 ),
383 ),
384 )
385 );
386
387 do_action( 'sight/widget/fields/meta/after', $this );
388
389 $this->end_controls_section();
390
391 $this->start_controls_section(
392 'media',
393 array(
394 'label' => esc_html__( 'Media Settings', 'sight' ),
395 )
396 );
397
398 do_action( 'sight/widget/fields/media/before', $this );
399
400 $this->add_control(
401 'attachment_lightbox',
402 array(
403 'label' => esc_html__( 'Enable lightbox', 'sight' ),
404 'type' => Controls_Manager::SWITCHER,
405 'return_value' => 'true',
406 )
407 );
408
409 $this->add_control(
410 'attachment_lightbox_icon',
411 array(
412 'label' => esc_html__( 'Display lightbox zoom icon', 'sight' ),
413 'type' => Controls_Manager::SWITCHER,
414 'return_value' => 'true',
415 'default' => 'true',
416 'conditions' => array(
417 'relation' => 'and',
418 'terms' => array(
419 array(
420 'name' => 'attachment_lightbox',
421 'operator' => '==',
422 'value' => 'true',
423 ),
424 ),
425 ),
426 )
427 );
428
429 $this->add_control(
430 'attachment_link_to',
431 array(
432 'label' => esc_html__( 'Link To', 'sight' ),
433 'description' => sight_is_archive() ? null : esc_html__( 'If the source is "Categories" then the "Page" value will be ignored.', 'sight' ),
434 'type' => Controls_Manager::SELECT,
435 'default' => 'page',
436 'options' => array(
437 'none' => esc_html__( 'None', 'sight' ),
438 'media' => esc_html__( 'Media File', 'sight' ),
439 'page' => esc_html__( 'Page', 'sight' ),
440 ),
441 'conditions' => array(
442 'relation' => 'and',
443 'terms' => array(
444 array(
445 'name' => 'attachment_lightbox',
446 'operator' => '!=',
447 'value' => 'true',
448 ),
449 ),
450 ),
451 )
452 );
453
454 $this->add_control(
455 'attachment_view_more',
456 array(
457 'label' => esc_html__( 'Enable view more', 'sight' ),
458 'type' => Controls_Manager::SWITCHER,
459 'return_value' => 'true',
460 'conditions' => array(
461 'relation' => 'and',
462 'terms' => array(
463 array(
464 'name' => 'attachment_lightbox',
465 'operator' => '!=',
466 'value' => 'true',
467 ),
468 array(
469 'name' => 'attachment_link_to',
470 'operator' => '!=',
471 'value' => 'none',
472 ),
473 ),
474 ),
475 )
476 );
477
478 $this->add_control(
479 'attachment_size',
480 array(
481 'label' => esc_html__( 'Size', 'sight' ),
482 'type' => Controls_Manager::SELECT,
483 'default' => 'large',
484 'options' => sight_get_list_available_image_sizes(),
485 )
486 );
487
488 $this->add_control(
489 'attachment_orientation',
490 array(
491 'label' => esc_html__( 'Orientation', 'sight' ),
492 'type' => Controls_Manager::SELECT,
493 'default' => 'landscape-16-9',
494 'options' => array(
495 'original' => esc_html__( 'Original', 'sight' ),
496 'landscape-4-3' => esc_html__( 'Landscape 4:3', 'sight' ),
497 'landscape-3-2' => esc_html__( 'Landscape 3:2', 'sight' ),
498 'landscape-16-9' => esc_html__( 'Landscape 16:9', 'sight' ),
499 'portrait-3-4' => esc_html__( 'Portrait 3:4', 'sight' ),
500 'portrait-2-3' => esc_html__( 'Portrait 2:3', 'sight' ),
501 'square' => esc_html__( 'Square', 'sight' ),
502 ),
503 )
504 );
505
506 do_action( 'sight/widget/fields/media/after', $this );
507
508 $this->end_controls_section();
509
510 $this->start_controls_section(
511 'typography',
512 array(
513 'label' => esc_html__( 'Typography Settings', 'sight' ),
514 )
515 );
516
517 do_action( 'sight/widget/fields/typography/before', $this );
518
519 $this->add_control(
520 'typography_heading',
521 array(
522 'label' => esc_html__( 'Heading Font Size', 'sight' ),
523 'type' => Controls_Manager::TEXT,
524 'default' => '',
525 'conditions' => array(
526 'relation' => 'and',
527 'terms' => array(
528 array(
529 'name' => 'source',
530 'operator' => '!=',
531 'value' => 'post',
532 ),
533 array(
534 'name' => 'source',
535 'operator' => '!=',
536 'value' => 'custom',
537 ),
538 array(
539 'name' => 'meta_title',
540 'operator' => '==',
541 'value' => 'true',
542 ),
543 ),
544 ),
545 )
546 );
547
548 $this->add_control(
549 'typography_heading_tag',
550 array(
551 'label' => esc_html__( 'Heading Tag', 'sight' ),
552 'type' => Controls_Manager::SELECT,
553 'default' => 'h3',
554 'options' => array(
555 'h1' => esc_html__( 'H1', 'sight' ),
556 'h2' => esc_html__( 'H2', 'sight' ),
557 'h3' => esc_html__( 'H3', 'sight' ),
558 'h4' => esc_html__( 'H4', 'sight' ),
559 'h5' => esc_html__( 'H5', 'sight' ),
560 'h6' => esc_html__( 'H6', 'sight' ),
561 'p' => esc_html__( 'P', 'sight' ),
562 'div' => esc_html__( 'DIV', 'sight' ),
563 ),
564 'conditions' => array(
565 'relation' => 'and',
566 'terms' => array(
567 array(
568 'name' => 'source',
569 'operator' => '!=',
570 'value' => 'post',
571 ),
572 array(
573 'name' => 'source',
574 'operator' => '!=',
575 'value' => 'custom',
576 ),
577 array(
578 'name' => 'meta_title',
579 'operator' => '==',
580 'value' => 'true',
581 ),
582 ),
583 ),
584 )
585 );
586
587 $this->add_control(
588 'typography_caption',
589 array(
590 'label' => esc_html__( 'Caption Font Size', 'sight' ),
591 'type' => Controls_Manager::TEXT,
592 'default' => '',
593 'conditions' => array(
594 'relation' => 'and',
595 'terms' => array(
596 array(
597 'name' => 'meta_caption',
598 'operator' => '==',
599 'value' => 'true',
600 ),
601 ),
602 ),
603 )
604 );
605
606 do_action( 'sight/widget/fields/typography/after', $this );
607
608 $this->end_controls_section();
609
610 $this->start_controls_section(
611 'query',
612 array(
613 'label' => esc_html__( 'Query Settings', 'sight' ),
614 'conditions' => array(
615 'relation' => 'or',
616 'terms' => array(
617 array(
618 'name' => 'source',
619 'operator' => '==',
620 'value' => 'projects',
621 ),
622 array(
623 'name' => 'source',
624 'operator' => '==',
625 'value' => 'categories',
626 ),
627 ),
628 ),
629 )
630 );
631
632 do_action( 'sight/widget/fields/query/before', $this );
633
634 $this->add_control(
635 'projects_filter_post_type',
636 array(
637 'label' => esc_html__( 'Filter by Post Type', 'sight' ),
638 'type' => Controls_Manager::SELECT,
639 'default' => 'sight-projects',
640 'options' => sight_get_post_types_stack(),
641 'conditions' => array(
642 'relation' => 'and',
643 'terms' => array(
644 array(
645 'name' => 'source',
646 'operator' => '==',
647 'value' => 'projects',
648 ),
649 ),
650 ),
651 )
652 );
653
654 $this->add_control(
655 'projects_filter_categories',
656 array(
657 'label' => esc_html__( 'Filter by Categories', 'sight' ),
658 'type' => Controls_Manager::SELECT2,
659 'multiple' => true,
660 'options' => sight_get_categories_stack(),
661 'conditions' => array(
662 'relation' => 'and',
663 'terms' => array(
664 array(
665 'name' => 'source',
666 'operator' => '==',
667 'value' => 'projects',
668 ),
669 array(
670 'name' => 'projects_filter_post_type',
671 'operator' => '==',
672 'value' => 'sight-projects',
673 ),
674 ),
675 ),
676 )
677 );
678
679 $this->add_control(
680 'projects_filter_offset',
681 array(
682 'label' => esc_html__( 'Offset', 'sight' ),
683 'type' => Controls_Manager::TEXT,
684 'conditions' => array(
685 'relation' => 'and',
686 'terms' => array(
687 array(
688 'name' => 'source',
689 'operator' => '==',
690 'value' => 'projects',
691 ),
692 ),
693 ),
694 )
695 );
696
697 $this->add_control(
698 'projects_orderby',
699 array(
700 'label' => esc_html__( 'Order By', 'sight' ),
701 'type' => Controls_Manager::SELECT,
702 'default' => 'date',
703 'options' => array(
704 'date' => esc_html__( 'Published Date', 'sight' ),
705 'modified' => esc_html__( 'Modified Date', 'sight' ),
706 'title' => esc_html__( 'Title', 'sight' ),
707 'rand' => esc_html__( 'Random', 'sight' ),
708 'views' => esc_html__( 'Views', 'sight' ),
709 'comment_count' => esc_html__( 'Comment Count', 'sight' ),
710 'ID' => esc_html__( 'ID', 'sight' ),
711 ),
712 'conditions' => array(
713 'relation' => 'and',
714 'terms' => array(
715 array(
716 'name' => 'source',
717 'operator' => '==',
718 'value' => 'projects',
719 ),
720 ),
721 ),
722 )
723 );
724
725 $this->add_control(
726 'projects_order',
727 array(
728 'label' => esc_html__( 'Order', 'sight' ),
729 'type' => Controls_Manager::SELECT,
730 'default' => 'DESC',
731 'options' => array(
732 'DESC' => esc_html__( 'Descending', 'sight' ),
733 'ASC' => esc_html__( 'Ascending', 'sight' ),
734 ),
735 'conditions' => array(
736 'relation' => 'and',
737 'terms' => array(
738 array(
739 'name' => 'source',
740 'operator' => '==',
741 'value' => 'projects',
742 ),
743 ),
744 ),
745 )
746 );
747
748 $this->add_control(
749 'categories_filter_ids',
750 array(
751 'label' => esc_html__( 'Filter by Categories', 'sight' ),
752 'type' => Controls_Manager::SELECT,
753 'options' => sight_get_categories_stack(),
754 'conditions' => array(
755 'relation' => 'and',
756 'terms' => array(
757 array(
758 'name' => 'source',
759 'operator' => '==',
760 'value' => 'categories',
761 ),
762 ),
763 ),
764 )
765 );
766
767 $this->add_control(
768 'categories_orderby',
769 array(
770 'label' => esc_html__( 'Order By', 'sight' ),
771 'type' => Controls_Manager::SELECT,
772 'default' => 'name',
773 'options' => array(
774 'name' => esc_html__( 'Name', 'sight' ),
775 'count' => esc_html__( 'Posts count', 'sight' ),
776 'include' => esc_html__( 'Filter include', 'sight' ),
777 'ID' => esc_html__( 'ID', 'sight' ),
778 ),
779 'conditions' => array(
780 'relation' => 'and',
781 'terms' => array(
782 array(
783 'name' => 'source',
784 'operator' => '==',
785 'value' => 'categories',
786 ),
787 ),
788 ),
789 )
790 );
791
792 $this->add_control(
793 'categories_order',
794 array(
795 'label' => esc_html__( 'Order', 'sight' ),
796 'type' => Controls_Manager::SELECT,
797 'default' => 'ASC',
798 'options' => array(
799 'DESC' => esc_html__( 'Descending', 'sight' ),
800 'ASC' => esc_html__( 'Ascending', 'sight' ),
801 ),
802 'conditions' => array(
803 'relation' => 'and',
804 'terms' => array(
805 array(
806 'name' => 'source',
807 'operator' => '==',
808 'value' => 'categories',
809 ),
810 ),
811 ),
812 )
813 );
814
815 do_action( 'sight/widget/fields/query/after', $this );
816
817 $this->end_controls_section();
818
819 $this->start_controls_section(
820 'color',
821 array(
822 'label' => esc_html__( 'Color Settings', 'sight' ),
823 )
824 );
825
826 do_action( 'sight/widget/fields/color/before', $this );
827
828 $this->add_control(
829 'color_heading',
830 array(
831 'label' => esc_html__( 'Heading Color', 'sight' ),
832 'type' => Controls_Manager::COLOR,
833 'conditions' => array(
834 'relation' => 'and',
835 'terms' => array(
836 array(
837 'name' => 'source',
838 'operator' => '!=',
839 'value' => 'post',
840 ),
841 array(
842 'name' => 'source',
843 'operator' => '!=',
844 'value' => 'custom',
845 ),
846 array(
847 'name' => 'meta_title',
848 'operator' => '==',
849 'value' => 'true',
850 ),
851 ),
852 ),
853 )
854 );
855
856 $this->add_control(
857 'color_heading_hover',
858 array(
859 'label' => esc_html__( 'Heading Hover Color', 'sight' ),
860 'type' => Controls_Manager::COLOR,
861 'conditions' => array(
862 'relation' => 'and',
863 'terms' => array(
864 array(
865 'name' => 'source',
866 'operator' => '!=',
867 'value' => 'post',
868 ),
869 array(
870 'name' => 'source',
871 'operator' => '!=',
872 'value' => 'custom',
873 ),
874 array(
875 'name' => 'meta_title',
876 'operator' => '==',
877 'value' => 'true',
878 ),
879 ),
880 ),
881 )
882 );
883
884 $this->add_control(
885 'color_caption',
886 array(
887 'label' => esc_html__( 'Caption Color', 'sight' ),
888 'type' => Controls_Manager::COLOR,
889 'conditions' => array(
890 'relation' => 'and',
891 'terms' => array(
892 array(
893 'name' => 'meta_caption',
894 'operator' => '==',
895 'value' => 'true',
896 ),
897 ),
898 ),
899 )
900 );
901
902 do_action( 'sight/widget/fields/color/after', $this );
903
904 $this->end_controls_section();
905
906 do_action( 'sight/widget/fields/after', $this );
907 }
908
909 /**
910 * Render attributes from widget.
911 *
912 * @param array $attributes The attributes.
913 * @param string $layout The layout.
914 */
915 public function render_attributes( $attributes, $layout ) {
916
917 // Change type for bool attributes.
918 foreach ( $attributes as $key => $value ) {
919 if ( 'true' === $attributes[ $key ] ) {
920 $attributes[ $key ] = true;
921 } elseif ( 'false' === $attributes[ $key ] ) {
922 $attributes[ $key ] = false;
923 }
924 }
925
926 // Set attribute for field 'Images'.
927 if ( $attributes['custom_images'] ) {
928 $attributes['custom_images'] = wp_list_pluck( $attributes['custom_images'], 'id' );
929 }
930
931 return $attributes;
932 }
933
934 /**
935 * Render options from widget.
936 *
937 * @param array $attributes The attributes.
938 * @param string $layout The layout.
939 */
940 public function render_options( $attributes, $layout ) {
941 $options = array();
942
943 // Get layouts.
944 $layouts = $this->widget_layouts();
945
946 // Render stack.
947 foreach ( $attributes as $key => $settings ) {
948
949 $clear_key = str_replace( $layout . '_', '', $key );
950
951 $search = $layout . '_' . $clear_key;
952
953 if ( array_key_exists( $search, $attributes ) ) {
954 $options[ $clear_key ] = $attributes[ $search ];
955 }
956 }
957
958 return $options;
959 }
960
961 /**
962 * Render the widget output on the frontend.
963 *
964 * Written in PHP and used to generate the final HTML.
965 *
966 * @since 1.0.0
967 *
968 * @access protected
969 */
970 protected function render() {
971 $attributes = $this->get_settings_for_display();
972
973 $layouts = $this->widget_layouts();
974
975 // Set id.
976 $id = $this->get_id();
977
978 // Set layout.
979 $layout = $attributes['layout'];
980
981 // Render attributes.
982 $attributes = $this->render_attributes( $attributes, $layout );
983
984 // Render options.
985 $options = $this->render_options( $attributes, $layout );
986
987 // Set classes.
988 $classes = " sight-block-portfolio-id-{$id}";
989 $classes .= " sight-block-portfolio-layout-{$layout}";
990
991 // Output.
992 ?>
993 <div class="sight-block-portfolio <?php echo esc_attr( $classes ); ?>">
994 <?php
995 if ( isset( $layouts[ $layout ]['template'] ) && file_exists( $layouts[ $layout ]['template'] ) ) {
996
997 // Require custom template.
998 require $layouts[ $layout ]['template'];
999 } else {
1000
1001 // Default template.
1002 require SIGHT_PATH . 'render/handler/post-area-init.php';
1003 }
1004 ?>
1005 </div>
1006
1007 <?php sight_portfolio_render_style( $attributes, $options, $id ); ?>
1008 <?php
1009 }
1010 }
1011
1012 /**
1013 * Elementor Widget Layouts
1014 *
1015 * @since 1.0.0
1016 */
1017 class Sight_Widget_Portfolio_Layouts {
1018
1019 /**
1020 * Initialize
1021 */
1022 public function __construct() {
1023 add_action( 'sight/widget/fields/general/after', array( $this, 'widget_portfolio_standard_fields' ), 5, 1 );
1024 }
1025
1026 /**
1027 * Add controls for standard layout.
1028 *
1029 * @param object $object The object.
1030 */
1031 public function widget_portfolio_standard_fields( $object ) {
1032 $object->add_control(
1033 'standard_filter_items',
1034 array(
1035 'label' => esc_html__( 'Display category filter', 'sight' ),
1036 'type' => Controls_Manager::SWITCHER,
1037 'return_value' => 'true',
1038 'default' => 'true',
1039 'conditions' => array(
1040 'relation' => 'and',
1041 'terms' => array(
1042 array(
1043 'name' => 'layout',
1044 'operator' => '==',
1045 'value' => 'standard',
1046 ),
1047 array(
1048 'name' => 'source',
1049 'operator' => '==',
1050 'value' => 'projects',
1051 ),
1052 array(
1053 'name' => 'projects_filter_post_type',
1054 'operator' => '==',
1055 'value' => 'sight-projects',
1056 ),
1057 ),
1058 ),
1059 )
1060 );
1061
1062 $object->add_control(
1063 'standard_pagination_type',
1064 array(
1065 'label' => esc_html__( 'Pagination type', 'sight' ),
1066 'type' => Controls_Manager::SELECT,
1067 'default' => 'ajax',
1068 'options' => array(
1069 'none' => esc_html__( 'None', 'sight' ),
1070 'ajax' => esc_html__( 'Load More', 'sight' ),
1071 'infinite' => esc_html__( 'Infinite Load', 'sight' ),
1072 ),
1073 'conditions' => array(
1074 'relation' => 'and',
1075 'terms' => array(
1076 array(
1077 'name' => 'layout',
1078 'operator' => '==',
1079 'value' => 'standard',
1080 ),
1081 array(
1082 'name' => 'source',
1083 'operator' => '==',
1084 'value' => 'projects',
1085 ),
1086 ),
1087 ),
1088 )
1089 );
1090 }
1091 }
1092
1093 new Sight_Widget_Portfolio_Layouts();
1094