| 1 |
<?php |
| 2 |
|
| 3 |
class WdkGetElementSettings { |
| 4 |
|
| 5 |
|
| 6 |
public function __construct( $postid, $widget_id, $widget_type ) { |
| 7 |
|
| 8 |
|
| 9 |
$this->postid = $postid; |
| 10 |
$this->widget_id = $widget_id; |
| 11 |
$this->widget_type = $widget_type; |
| 12 |
$this->widget = null; |
| 13 |
|
| 14 |
$this->parse(); |
| 15 |
|
| 16 |
} |
| 17 |
|
| 18 |
public function elementor(){ |
| 19 |
|
| 20 |
return \Elementor\Plugin::$instance; |
| 21 |
|
| 22 |
} |
| 23 |
|
| 24 |
public function get_settings () { |
| 25 |
if(!$this->widget) return false; |
| 26 |
return $this->widget; |
| 27 |
} |
| 28 |
|
| 29 |
private function parse() { |
| 30 |
$data = $this->read_data(); |
| 31 |
$this->parse_options($data); |
| 32 |
} |
| 33 |
|
| 34 |
private function read_data () { |
| 35 |
|
| 36 |
return $this->elementor()->documents->get( $this->postid )->get_elements_data(); |
| 37 |
|
| 38 |
} |
| 39 |
|
| 40 |
private function parse_options($data) { |
| 41 |
|
| 42 |
if(!is_array($data) || empty($data)){ |
| 43 |
return; |
| 44 |
} |
| 45 |
|
| 46 |
foreach ( $data as $item ) { |
| 47 |
|
| 48 |
if(empty($item)){ |
| 49 |
continue; |
| 50 |
} |
| 51 |
|
| 52 |
if ( 'section' === $item['elType'] || 'column' === $item['elType'] || 'container' === $item['elType']) { |
| 53 |
|
| 54 |
$this->parse_options($item['elements']); |
| 55 |
|
| 56 |
} else { |
| 57 |
|
| 58 |
$this->parse_options_simple($item); |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
private function parse_options_simple($item) { |
| 64 |
|
| 65 |
if ( |
| 66 |
|
| 67 |
$item['id'] === $this->widget_id && |
| 68 |
$item['widgetType'] === $this->widget_type |
| 69 |
|
| 70 |
) { |
| 71 |
$this->widget = $item; |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
public function generate_icon($icon, $attributes = [], $tag = 'i' ){ |
| 76 |
if ( empty( $icon['library'] ) ) { |
| 77 |
return false; |
| 78 |
} |
| 79 |
$output = ''; |
| 80 |
|
| 81 |
// handler SVG Icon |
| 82 |
if ( 'svg' === $icon['library'] ) { |
| 83 |
$output = \Elementor\Icons_Manager::render_uploaded_svg_icon( $icon['value'] ); |
| 84 |
} else { |
| 85 |
$output = $this->render_icon_html( $icon, $attributes, $tag ); |
| 86 |
} |
| 87 |
|
| 88 |
return $output; |
| 89 |
} |
| 90 |
|
| 91 |
public function render_icon_html( $icon, $attributes = [], $tag = 'i' ) { |
| 92 |
$icon_types = \Elementor\Icons_Manager::get_icon_manager_tabs(); |
| 93 |
if ( isset( $icon_types[ $icon['library'] ]['render_callback'] ) && is_callable( $icon_types[ $icon['library'] ]['render_callback'] ) ) { |
| 94 |
return call_user_func_array( $icon_types[ $icon['library'] ]['render_callback'], [ $icon, $attributes, $tag ] ); |
| 95 |
} |
| 96 |
|
| 97 |
if ( empty( $attributes['class'] ) ) { |
| 98 |
$attributes['class'] = $icon['value']; |
| 99 |
} else { |
| 100 |
if ( is_array( $attributes['class'] ) ) { |
| 101 |
$attributes['class'][] = $icon['value']; |
| 102 |
} else { |
| 103 |
$attributes['class'] .= ' ' . $icon['value']; |
| 104 |
} |
| 105 |
} |
| 106 |
return '<' . $tag . ' ' . Utils::render_html_attributes( $attributes ) . '></' . $tag . '>'; |
| 107 |
} |
| 108 |
} |