PluginProbe
UiCore Elements – Free widgets and templates for Elementor / 1.0.2
UiCore Elements – Free widgets and templates for Elementor v1.0.2
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.0.2, at includes/class-widget-base.php

96 lines 3.1 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 * @return object ['assets-name' => ['condition' => ['key' => 'value'] , 'deps' => ['global-handler-name','other-handler-name'], 'external' => true]]
12 */
13 public abstract function get_styles();
14
15 /**
16 * Get widget categories.
17 *
18 * @return object ['assets-name' => ['condition' => ['key' => 'value'] , 'deps' => ['global-handler-name','other-handler-name'], 'external' => true]]
19 */
20 public abstract function get_scripts();
21
22 public function get_style_depends()
23 {
24 $assets = $this->get_styles();
25 $final_list = $this->parse_asset_list($assets,'style');
26
27 //TODO: combine all the styles into one file and return it
28 return $final_list;
29 }
30
31 public function get_script_depends()
32 {
33 $assets = $this->get_scripts();
34 $final_list = $this->parse_asset_list($assets,'script');
35
36 //TODO: combine all the styles into one file and return it
37 return $final_list;
38 }
39
40
41
42 private function parse_asset_list($list,$type='style'){
43 $final_list = [];
44 foreach ($list as $key => $value) {
45 $deps = (isset($value) && isset($value['deps'])) ? $value['deps'] : [];
46 $external = (isset($value) && isset($value['external'])) ? $value['external'] : false;
47 $name = $this->get_asset_name($key,$value);
48
49 //if name is not empty then we need to add it to the list
50 if($name){
51 $method_name = "register_widget_$type";
52 $final_list[] = Helper::$method_name($name,$deps,$external);
53 }
54 }
55 return $final_list;
56 }
57
58 private function get_asset_name($key,$value){
59 //check the condition/s
60 if (\is_array($value) && !empty($value)) {
61 //check if the condition is true using elementor's function (always return true if we are in edit mode)
62 if($this->is_edit_mode() || $this->is_control_visible($value,$this->get_settings())){
63 return $key;
64 }else{
65 return '';
66 }
67 //this is the same but done manually (eg:remove this if we don;t have problems with it)
68 // foreach ($value as $k => $v) {
69 // if(\is_array($v)){
70 // return $this->get_asset_name($k,$v);
71 // }else{
72 // $this->is_control_visible(['con'])
73 // if($this->get_settings($k) == $v){
74 // return $key;
75 // }else{
76 // return '';
77 // }
78 // }
79 // }
80 }
81 // if list is only declaring the assets without any condition then we need to return the key
82 return $value;
83
84 }
85 protected function is_edit_mode() {
86 $elementor_instance = \Elementor\Plugin::instance();
87 if ( $elementor_instance->preview->is_preview_mode() || $elementor_instance->editor->is_edit_mode() ) {
88 return true;
89 }
90
91 return false;
92 }
93
94
95 }
96