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