PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.2.4
UiCore Elements – Free widgets and templates for Elementor v1.2.4
1.3.17 1.3.16 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 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.2.0 1.2.1 1.2.2 1.2.3 1.2.4 All 41 releases
uicore-elements / includes / class-widget-base.php

class-widget-base.php in UiCore Elements – Free widgets and templates for Elementor 1.2.4, at includes/class-widget-base.php

135 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace UiCoreElements;
3 use Elementor\Widget_Base;
4 use UiCoreElements\Helper;
5
6 abstract class UiCoreWidget extends Widget_Base {
7
8 /**
9 * Get widget categories.
10 *
11 * custom_condition need to always return true if $this->is_edit_mode() is true
12 * @return object ['assets-name' => ['condition' => ['key' => 'value'] , 'deps' => ['global-handler-name','other-handler-name'], 'external' => true]]
13 */
14 public abstract function get_styles();
15
16 /**
17 * Get widget categories.
18 *
19 * custom_condition need to always return true if $this->is_edit_mode() is true
20 * @return object ['assets-name' => ['condition' => ['key' => 'value'] ,'custom_condition' => true , 'deps' => ['global-handler-name','other-handler-name'], 'external' => true]]
21 */
22 public abstract function get_scripts();
23
24 public function get_style_depends()
25 {
26 $assets = $this->get_styles();
27 $final_list = $this->parse_asset_list($assets,'style');
28
29 //TODO: combine all the styles into one file and return it
30 return $final_list;
31 }
32
33 public function get_script_depends()
34 {
35 $assets = $this->get_scripts();
36 $final_list = $this->parse_asset_list($assets,'script');
37
38 //TODO: combine all the styles into one file and return it
39 return $final_list;
40 }
41
42
43
44 private function parse_asset_list($list,$type='style'){
45 $final_list = [];
46 foreach ($list as $key => $value) {
47 $deps = (isset($value) && isset($value['deps'])) ? $value['deps'] : [];
48 $external = (isset($value) && isset($value['external'])) ? $value['external'] : false;
49 $name = $this->get_asset_name($key,$value);
50
51 //if name is not empty then we need to add it to the list
52 if($name){
53 $method_name = "register_widget_$type";
54 $final_list[] = Helper::$method_name($name,$deps,$external);
55 }
56 }
57 return $final_list;
58 }
59
60 private function get_asset_name($key,$value){
61 //check the condition/s
62 if (\is_array($value) && !empty($value)) {
63
64 //custom condition
65 if(isset($value['custom_condition'])){
66 if($value['custom_condition']){
67 return $key;
68 }else{
69 return '';
70 }
71 }
72
73 //check if the condition is true using elementor's function (always return true if we are in edit mode)
74 if($this->is_edit_mode() || $this->is_control_visible($value,$this->get_settings())){
75 return $key;
76 }else{
77 return '';
78 }
79 }
80 // if list is only declaring the assets without any condition then we need to return the key
81 return $value;
82
83 }
84 protected function is_edit_mode() {
85 $elementor_instance = \Elementor\Plugin::instance();
86 if ( $elementor_instance->preview->is_preview_mode() || $elementor_instance->editor->is_edit_mode() ) {
87 return true;
88 }
89
90 return false;
91 }
92
93 /**
94 * Verify if the control exists and if matches the given value.
95 * Usefull for controls that may not be returned, in the settings stack, under certain conditions.
96 *
97 * @param string $control The control slug.
98 * @param string|null $value Optional. The value to check against.
99 * @param string $operator Optional. The operator to use for comparing `control` and `value`. Default is '==='.
100 *
101 * @return bool
102 * @since 1.2.4
103 */
104 protected function is_option( string $control, $value = null, $operator = '==='): bool
105 {
106 $option = $this->get_settings_for_display($control);
107
108 if( isset($option) ){
109
110 if( !isset($value) ){
111 return true;
112 }
113
114 switch($operator){
115 case '===':
116 return $option === $value;
117 case '!==':
118 return $option !== $value;
119 case '<':
120 return $option < $value;
121 case '<=':
122 return $option <= $value;
123 case '>':
124 return $option > $value;
125 case '>=':
126 return $option >= $value;
127 default:
128 return false;
129 }
130 }
131
132 return false;
133 }
134 }
135