Embedpress_Elementor.php
237 lines
| 1 | <?php |
| 2 | |
| 3 | namespace EmbedPress\Elementor\Widgets; |
| 4 | |
| 5 | |
| 6 | use \Elementor\Controls_Manager as Controls_Manager; |
| 7 | use Elementor\Group_Control_Background; |
| 8 | use \Elementor\Group_Control_Css_Filter; |
| 9 | use \Elementor\Widget_Base as Widget_Base; |
| 10 | use \EmbedPress\Shortcode; |
| 11 | |
| 12 | (defined( 'ABSPATH' )) or die( "No direct script access allowed." ); |
| 13 | |
| 14 | class Embedpress_Elementor extends Widget_Base { |
| 15 | |
| 16 | public function get_name() { |
| 17 | return 'embedpres_elementor'; |
| 18 | } |
| 19 | |
| 20 | public function get_title() { |
| 21 | return esc_html__( 'EmbedPress', 'embedoress' ); |
| 22 | } |
| 23 | |
| 24 | public function get_categories() { |
| 25 | return [ 'embedpress' ]; |
| 26 | } |
| 27 | |
| 28 | public function get_custom_help_url() { |
| 29 | return 'https://embedpress.com/documentation'; |
| 30 | } |
| 31 | |
| 32 | public function get_icon() { |
| 33 | return 'icon-embedpress'; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Get widget keywords. |
| 38 | * |
| 39 | * Retrieve the list of keywords the widget belongs to. |
| 40 | * |
| 41 | * @return array Widget keywords. |
| 42 | * @since 2.4.1 |
| 43 | * @access public |
| 44 | * |
| 45 | */ |
| 46 | public function get_keywords() { |
| 47 | return [ |
| 48 | 'embedpress', |
| 49 | 'audio', |
| 50 | 'video', |
| 51 | 'map', |
| 52 | 'youtube', |
| 53 | 'vimeo', |
| 54 | 'wistia', |
| 55 | 'twitch', |
| 56 | 'soundcloud', |
| 57 | 'giphy gifs', |
| 58 | 'spotify', |
| 59 | 'smugmug', |
| 60 | 'meetup', |
| 61 | 'dailymotion', |
| 62 | 'instagram', |
| 63 | 'slideshare', |
| 64 | 'flickr', |
| 65 | 'ted', |
| 66 | 'google docs', |
| 67 | 'google slides', |
| 68 | 'google drawings' |
| 69 | ]; |
| 70 | } |
| 71 | |
| 72 | protected function _register_controls() { |
| 73 | |
| 74 | /** |
| 75 | * EmbedPress Content Settings |
| 76 | */ |
| 77 | $this->start_controls_section( |
| 78 | 'embedpress_elementor_content_settings', |
| 79 | [ |
| 80 | 'label' => esc_html__( 'Content Settings', 'embedpress' ), |
| 81 | ] |
| 82 | ); |
| 83 | |
| 84 | do_action( 'embedpress/embeded/extend', $this ); |
| 85 | |
| 86 | $this->add_control( |
| 87 | 'embedpress_embeded_link', |
| 88 | [ |
| 89 | |
| 90 | 'label' => __( 'Embeded Link', 'embedpress' ), |
| 91 | 'type' => Controls_Manager::TEXT, |
| 92 | 'dynamic' => [ |
| 93 | 'active' => true, |
| 94 | ], |
| 95 | 'placeholder' => __( 'Enter your Link', 'embedpress' ), |
| 96 | 'label_block' => true |
| 97 | |
| 98 | ] |
| 99 | ); |
| 100 | |
| 101 | do_action( 'embedpress/control/extend', $this ); |
| 102 | |
| 103 | $this->end_controls_section(); |
| 104 | |
| 105 | $this->start_controls_section( |
| 106 | 'embedpress_style_section', |
| 107 | [ |
| 108 | 'label' => __( 'Style', 'elementor' ), |
| 109 | 'tab' => Controls_Manager::TAB_STYLE, |
| 110 | ] |
| 111 | ); |
| 112 | |
| 113 | |
| 114 | $this->add_control( |
| 115 | 'embedpress_elementor_aspect_ratio', |
| 116 | [ |
| 117 | 'label' => __( 'Aspect Ratio', 'embedpress' ), |
| 118 | 'description' => __( 'Good for any video. You may turn it off for other embed type.', 'embedpress' ), |
| 119 | 'type' => Controls_Manager::SELECT, |
| 120 | 'options' => [ |
| 121 | 0 => __('None'), |
| 122 | '169' => '16:9', |
| 123 | '219' => '21:9', |
| 124 | '43' => '4:3', |
| 125 | '32' => '3:2', |
| 126 | '11' => '1:1', |
| 127 | '916' => '9:16', |
| 128 | ], |
| 129 | 'default' => 0, |
| 130 | 'prefix_class' => 'embedpress-aspect-ratio-', |
| 131 | 'frontend_available' => true, |
| 132 | ] |
| 133 | ); |
| 134 | |
| 135 | $this->add_control( |
| 136 | 'width', |
| 137 | [ |
| 138 | 'label' => __( 'Width', 'embedpress' ), |
| 139 | 'type' => Controls_Manager::SLIDER, |
| 140 | 'size_units' => [ 'px' ], |
| 141 | 'range' => [ |
| 142 | 'px' => [ |
| 143 | 'min' => 0, |
| 144 | 'max' => 1500, |
| 145 | 'step' => 5, |
| 146 | ], |
| 147 | ], |
| 148 | 'default' => [ |
| 149 | 'unit' => 'px', |
| 150 | 'size' => 600, |
| 151 | ] |
| 152 | ] |
| 153 | ); |
| 154 | $this->add_control( |
| 155 | 'height', |
| 156 | [ |
| 157 | 'label' => __( 'Height', 'embedpress' ), |
| 158 | 'type' => Controls_Manager::SLIDER, |
| 159 | 'size_units' => [ 'px' ], |
| 160 | 'range' => [ |
| 161 | 'px' => [ |
| 162 | 'min' => 0, |
| 163 | 'max' => 1500, |
| 164 | 'step' => 5, |
| 165 | ], |
| 166 | ], |
| 167 | 'default' => [ |
| 168 | 'unit' => 'px', |
| 169 | 'size' => 400, |
| 170 | ] |
| 171 | ] |
| 172 | ); |
| 173 | |
| 174 | $this->add_responsive_control( |
| 175 | 'margin', |
| 176 | [ |
| 177 | 'label' => __( 'Margin', 'embedpress' ), |
| 178 | 'type' => Controls_Manager::DIMENSIONS, |
| 179 | 'size_units' => [ 'px', '%', 'em' ], |
| 180 | 'selectors' => [ |
| 181 | '{{WRAPPER}} .embedpress-elements-wrapper .embedpress-wrapper' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 182 | ], |
| 183 | ] |
| 184 | ); |
| 185 | $this->add_responsive_control( |
| 186 | 'padding', |
| 187 | [ |
| 188 | 'label' => __( 'Padding', 'embedpress' ), |
| 189 | 'type' => Controls_Manager::DIMENSIONS, |
| 190 | 'size_units' => [ 'px', '%', 'em' ], |
| 191 | 'selectors' => [ |
| 192 | '{{WRAPPER}} .embedpress-elements-wrapper .embedpress-wrapper' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 193 | ], |
| 194 | ] |
| 195 | ); |
| 196 | $this->add_group_control( |
| 197 | Group_Control_Background::get_type(), |
| 198 | [ |
| 199 | 'name' => 'background', |
| 200 | 'label' => __( 'Background', 'embedpress' ), |
| 201 | 'types' => [ 'classic', 'gradient' ], |
| 202 | 'selector' => '{{WRAPPER}} .embedpress-elements-wrapper .embedpress-wrapper, {{WRAPPER}} .embedpress-fit-aspect-ratio .embedpress-wrapper iframe', |
| 203 | ] |
| 204 | ); |
| 205 | $this->add_group_control( |
| 206 | Group_Control_Css_Filter::get_type(), |
| 207 | [ |
| 208 | 'name' => 'embedpress_elementor_css_filters', |
| 209 | 'selector' => '{{WRAPPER}} .embedpress-elements-wrapper .embedpress-wrapper', |
| 210 | ] |
| 211 | ); |
| 212 | $this->end_controls_section(); |
| 213 | |
| 214 | |
| 215 | } |
| 216 | |
| 217 | protected function render() { |
| 218 | $settings = $this->get_settings_for_display(); |
| 219 | $height = (!empty( $settings['height']) && !empty( $settings['height']['size'] )) |
| 220 | ? $settings['height']['size'] : null; |
| 221 | $width = (!empty( $settings['width']) && !empty( $settings['width']['size'] )) |
| 222 | ? $settings['width']['size'] : null; |
| 223 | |
| 224 | $embed_content = Shortcode::parseContent( $settings['embedpress_embeded_link'], true, [ 'height'=> $height, 'width'=>$width ] ); |
| 225 | $embed = apply_filters( 'embedpress_elementor_embed', $embed_content, $settings ); |
| 226 | $content = is_object( $embed ) ? $embed->embed : $embed; |
| 227 | |
| 228 | ?> |
| 229 | <div class="embedpress-elements-wrapper <?php echo !empty( $settings['embedpress_elementor_aspect_ratio']) ? 'embedpress-fit-aspect-ratio': ''; ?>"> |
| 230 | <?php echo $content; ?> |
| 231 | </div> |
| 232 | <?php |
| 233 | } |
| 234 | |
| 235 | |
| 236 | } |
| 237 |