| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; // Exit if accessed directly. |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* FV Player Elementor video widget. |
| 9 |
* |
| 10 |
* Elementor widget that displays FV Player. |
| 11 |
* |
| 12 |
* @since 1.0.0 |
| 13 |
* @disregard P1009 Undefined type |
| 14 |
*/ |
| 15 |
class FV_Player_Elementor_Widget extends Elementor\Widget_Base { |
| 16 |
|
| 17 |
/** |
| 18 |
* Get widget name. |
| 19 |
* |
| 20 |
* Retrieve video widget name. |
| 21 |
* |
| 22 |
* @since 1.0.0 |
| 23 |
* @access public |
| 24 |
* |
| 25 |
* @return string Widget name. |
| 26 |
*/ |
| 27 |
public function get_name() { |
| 28 |
return 'fv_player'; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Get widget title. |
| 33 |
* |
| 34 |
* Retrieve video widget title. |
| 35 |
* |
| 36 |
* @since 1.0.0 |
| 37 |
* @access public |
| 38 |
* |
| 39 |
* @return string Widget title. |
| 40 |
*/ |
| 41 |
public function get_title() { |
| 42 |
return esc_html__( 'FV Player', 'elementor' ); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Get widget icon. |
| 47 |
* |
| 48 |
* Retrieve video widget icon. |
| 49 |
* |
| 50 |
* @since 1.0.0 |
| 51 |
* @access public |
| 52 |
* |
| 53 |
* @return string Widget icon. |
| 54 |
*/ |
| 55 |
public function get_icon() { |
| 56 |
return 'eicon-youtube'; |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Get widget categories. |
| 61 |
* |
| 62 |
* Retrieve the list of categories the video widget belongs to. |
| 63 |
* |
| 64 |
* Used to determine where to display the widget in the editor. |
| 65 |
* |
| 66 |
* @since 2.0.0 |
| 67 |
* @access public |
| 68 |
* |
| 69 |
* @return array Widget categories. |
| 70 |
*/ |
| 71 |
public function get_categories() { |
| 72 |
return [ 'basic' ]; |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Get widget keywords. |
| 77 |
* |
| 78 |
* Retrieve the list of keywords the widget belongs to. |
| 79 |
* |
| 80 |
* @since 2.1.0 |
| 81 |
* @access public |
| 82 |
* |
| 83 |
* @return array Widget keywords. |
| 84 |
*/ |
| 85 |
public function get_keywords() { |
| 86 |
return [ 'fv', 'video', 'player', 'embed', 'youtube', 'vimeo' ]; |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Special Elementor feature to reduce the amount of HTML elements. |
| 91 |
* Docs: https://developers.elementor.com/docs/widgets/widget-inner-wrapper/ |
| 92 |
*/ |
| 93 |
public function has_widget_inner_wrapper(): bool { |
| 94 |
/** @disregard P1009 Undefined type */ |
| 95 |
/** @disregard P1014 Undefined property */ |
| 96 |
return ! Elementor\Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' ); |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Register video widget controls. |
| 101 |
* |
| 102 |
* Note that the follwoing fields are not saved in the Elementor DB but in the FV Player DB: |
| 103 |
* - source_url |
| 104 |
* - splash_url |
| 105 |
* - title |
| 106 |
* - timeline_previews |
| 107 |
* - hls_hlskey |
| 108 |
* |
| 109 |
* The field values are populated using JavaScript with Ajax with action=fv_player_guttenberg_attributes_load |
| 110 |
* The field values are removed from Elementor data using PHP in fv_player_editor_elementor_widget_remove_settings(). |
| 111 |
* |
| 112 |
* @access protected |
| 113 |
*/ |
| 114 |
protected function register_controls() { |
| 115 |
/** @disregard P1013 Undefined method */ |
| 116 |
$this->start_controls_section( |
| 117 |
'section_video', |
| 118 |
[ |
| 119 |
'label' => esc_html__( 'Video', 'elementor' ), |
| 120 |
] |
| 121 |
); |
| 122 |
|
| 123 |
// Note: This field is populated in JS and removed from Elementor data, see function comment. |
| 124 |
/** @disregard P1013 Undefined method */ |
| 125 |
/** @disregard P1009 Undefined type */ |
| 126 |
$this->add_control( |
| 127 |
'source_url', |
| 128 |
array( |
| 129 |
'label' => esc_html__( 'Source URL', 'fv-player' ), |
| 130 |
'type' => Elementor\Controls_Manager::URL, |
| 131 |
'options' => false, |
| 132 |
'ai' => array( |
| 133 |
'active' => false, |
| 134 |
), |
| 135 |
) |
| 136 |
); |
| 137 |
|
| 138 |
/** @disregard P1013 Undefined method */ |
| 139 |
/** @disregard P1009 Undefined type */ |
| 140 |
$this->add_control( |
| 141 |
'_media_library_source_url', |
| 142 |
array( |
| 143 |
'type' => Elementor\Controls_Manager::BUTTON, |
| 144 |
'text' => esc_html__( 'Select Media', 'fv-player' ), |
| 145 |
'event' => 'fv-player-elementor-pick-source_url', |
| 146 |
'button_type' => 'default', |
| 147 |
'show_label' => false, |
| 148 |
) |
| 149 |
); |
| 150 |
|
| 151 |
// Note: This field is populated in JS and removed from Elementor data, see function comment. |
| 152 |
/** @disregard P1013 Undefined method */ |
| 153 |
/** @disregard P1009 Undefined type */ |
| 154 |
$this->add_control( |
| 155 |
'splash_url', |
| 156 |
array( |
| 157 |
'label' => esc_html__( 'Splash URL', 'fv-player' ), |
| 158 |
'type' => Elementor\Controls_Manager::URL, |
| 159 |
'options' => false, |
| 160 |
'ai' => array( |
| 161 |
'active' => false, |
| 162 |
), |
| 163 |
) |
| 164 |
); |
| 165 |
|
| 166 |
// Note: This field is populated in JS and removed from Elementor data, see function comment. |
| 167 |
/** @disregard P1013 Undefined method */ |
| 168 |
/** @disregard P1009 Undefined type */ |
| 169 |
$this->add_control( |
| 170 |
'splash_attachment_id', |
| 171 |
array( |
| 172 |
'type' => Elementor\Controls_Manager::HIDDEN, |
| 173 |
'default' => '', |
| 174 |
) |
| 175 |
); |
| 176 |
|
| 177 |
/** @disregard P1013 Undefined method */ |
| 178 |
/** @disregard P1009 Undefined type */ |
| 179 |
$this->add_control( |
| 180 |
'_media_library_splash_url', |
| 181 |
array( |
| 182 |
'type' => Elementor\Controls_Manager::BUTTON, |
| 183 |
'text' => esc_html__( 'Select Media', 'fv-player' ), |
| 184 |
'event' => 'fv-player-elementor-pick-splash_url', |
| 185 |
'button_type' => 'default', |
| 186 |
'show_label' => false, |
| 187 |
) |
| 188 |
); |
| 189 |
|
| 190 |
// Note: This field is populated in JS and removed from Elementor data, see function comment. |
| 191 |
/** @disregard P1013 Undefined method */ |
| 192 |
/** @disregard P1009 Undefined type */ |
| 193 |
$this->add_control( |
| 194 |
'title', |
| 195 |
array( |
| 196 |
'label' => esc_html__( 'Video Title', 'fv-player' ), |
| 197 |
'label_block' => true, |
| 198 |
'type' => Elementor\Controls_Manager::TEXT, |
| 199 |
'ai' => array( |
| 200 |
'active' => false, |
| 201 |
), |
| 202 |
) |
| 203 |
); |
| 204 |
|
| 205 |
// Deal with "Timeline Previews" field visibility. |
| 206 |
// Note: This field is populated in JS and removed from Elementor data, see function comment. |
| 207 |
/** @disregard P1013 Undefined method */ |
| 208 |
/** @disregard P1009 Undefined type */ |
| 209 |
$this->add_control( |
| 210 |
'_show_timeline_previews', |
| 211 |
array( |
| 212 |
'type' => Elementor\Controls_Manager::HIDDEN, |
| 213 |
'default' => '', |
| 214 |
) |
| 215 |
); |
| 216 |
|
| 217 |
// Note: This field is populated in JS and removed from Elementor data, see function comment. |
| 218 |
/** @disregard P1013 Undefined method */ |
| 219 |
/** @disregard P1009 Undefined type */ |
| 220 |
$this->add_control( |
| 221 |
'timeline_previews', |
| 222 |
array( |
| 223 |
'label' => esc_html__( 'Timeline Previews', 'fv-player' ), |
| 224 |
'type' => Elementor\Controls_Manager::URL, |
| 225 |
'options' => false, |
| 226 |
'ai' => array( |
| 227 |
'active' => false, |
| 228 |
), |
| 229 |
'condition' => array( |
| 230 |
'_show_timeline_previews' => 'yes', |
| 231 |
), |
| 232 |
) |
| 233 |
); |
| 234 |
|
| 235 |
// Deal with "HLS Key" field visibility. |
| 236 |
// Note: This field is populated in JS and removed from Elementor data, see function comment. |
| 237 |
/** @disregard P1013 Undefined method */ |
| 238 |
/** @disregard P1009 Undefined type */ |
| 239 |
$this->add_control( |
| 240 |
'_show_hls_key', |
| 241 |
array( |
| 242 |
'type' => Elementor\Controls_Manager::HIDDEN, |
| 243 |
'default' => '', |
| 244 |
) |
| 245 |
); |
| 246 |
|
| 247 |
// Note: This field is populated in JS and removed from Elementor data, see function comment. |
| 248 |
/** @disregard P1013 Undefined method */ |
| 249 |
/** @disregard P1009 Undefined type */ |
| 250 |
$this->add_control( |
| 251 |
'hls_key', |
| 252 |
array( |
| 253 |
'label' => esc_html__( 'HLS Key', 'fv-player' ), |
| 254 |
'label_block' => true, |
| 255 |
'type' => Elementor\Controls_Manager::TEXT, |
| 256 |
'ai' => array( |
| 257 |
'active' => false, |
| 258 |
), |
| 259 |
'condition' => array( |
| 260 |
'_show_hls_key' => 'yes', |
| 261 |
), |
| 262 |
) |
| 263 |
); |
| 264 |
|
| 265 |
/** @disregard P1013 Undefined method */ |
| 266 |
/** @disregard P1009 Undefined type */ |
| 267 |
$this->add_control( |
| 268 |
'shortcode', |
| 269 |
array( |
| 270 |
'type' => Elementor\Controls_Manager::HIDDEN, |
| 271 |
'default' => '', |
| 272 |
) |
| 273 |
); |
| 274 |
|
| 275 |
/** @disregard P1013 Undefined method */ |
| 276 |
/** @disregard P1009 Undefined type */ |
| 277 |
$this->add_control( |
| 278 |
'fvplayer_subtitles_settings_note', |
| 279 |
array( |
| 280 |
'type' => Elementor\Controls_Manager::RAW_HTML, |
| 281 |
'raw' => esc_html__( 'Looking for subtitles or player settings?', 'fv-player' ), |
| 282 |
'content_classes' => 'elementor-panel-alert elementor-panel-alert-info', |
| 283 |
) |
| 284 |
); |
| 285 |
|
| 286 |
/** @disregard P1013 Undefined method */ |
| 287 |
/** @disregard P1009 Undefined type */ |
| 288 |
$this->add_control( |
| 289 |
'fvplayer_editor_button', |
| 290 |
array( |
| 291 |
'type' => Elementor\Controls_Manager::BUTTON, |
| 292 |
'text' => esc_html__( 'Configure Player', 'fv-player' ), |
| 293 |
'event' => 'fv-player-elementor-editor-open', |
| 294 |
'button_type' => 'default', |
| 295 |
'show_label' => false, |
| 296 |
) |
| 297 |
); |
| 298 |
|
| 299 |
// TODO: Add these controls back in. |
| 300 |
/** @disregard P1013 Undefined method */ |
| 301 |
/** @disregard P1009 Undefined type */ |
| 302 |
// $this->add_control( |
| 303 |
// 'autoplay', |
| 304 |
// array( |
| 305 |
// 'label' => esc_html__( 'Autoplay', 'elementor' ), |
| 306 |
// 'description' => sprintf( |
| 307 |
// /* translators: 1: `<a>` opening tag, 2: `</a>` closing tag. */ |
| 308 |
// esc_html__( 'Note: Autoplay is affected by %1$s Google’s Autoplay policy %2$s on Chrome browsers.', 'elementor' ), |
| 309 |
// '<a href="https://developers.google.com/web/updates/2017/09/autoplay-policy-changes" target="_blank">', |
| 310 |
// '</a>' |
| 311 |
// ), |
| 312 |
// 'type' => Elementor\Controls_Manager::SWITCHER, |
| 313 |
// 'frontend_available' => true, |
| 314 |
// ) |
| 315 |
// ); |
| 316 |
|
| 317 |
// TODO: Add these controls back in. |
| 318 |
// /** @disregard P1013 Undefined method */ |
| 319 |
// /** @disregard P1009 Undefined type */ |
| 320 |
// $this->add_control( |
| 321 |
// 'loop', |
| 322 |
// array( |
| 323 |
// 'label' => esc_html__( 'Loop', 'elementor' ), |
| 324 |
// 'type' => Elementor\Controls_Manager::SWITCHER, |
| 325 |
// 'frontend_available' => true, |
| 326 |
// ) |
| 327 |
// ); |
| 328 |
|
| 329 |
// TODO: Add these controls back in. |
| 330 |
// /** @disregard P1013 Undefined method */ |
| 331 |
// /** @disregard P1009 Undefined type */ |
| 332 |
// $this->add_control( |
| 333 |
// 'controls', |
| 334 |
// array( |
| 335 |
// 'label' => esc_html__( 'Player Controls', 'elementor' ), |
| 336 |
// 'type' => Elementor\Controls_Manager::SWITCHER, |
| 337 |
// 'label_off' => esc_html__( 'Hide', 'elementor' ), |
| 338 |
// 'label_on' => esc_html__( 'Show', 'elementor' ), |
| 339 |
// 'default' => 'yes', |
| 340 |
// 'frontend_available' => true, |
| 341 |
// ) |
| 342 |
// ); |
| 343 |
|
| 344 |
// TODO: Add these controls back in. |
| 345 |
// /** @disregard P1013 Undefined method */ |
| 346 |
// /** @disregard P1009 Undefined type */ |
| 347 |
// $this->add_control( |
| 348 |
// 'lightbox', |
| 349 |
// array( |
| 350 |
// 'label' => esc_html__( 'Lightbox', 'elementor' ), |
| 351 |
// 'type' => Elementor\Controls_Manager::SWITCHER, |
| 352 |
// 'frontend_available' => true, |
| 353 |
// 'label_off' => esc_html__( 'Off', 'elementor' ), |
| 354 |
// 'label_on' => esc_html__( 'On', 'elementor' ), |
| 355 |
// 'separator' => 'before', |
| 356 |
// ) |
| 357 |
// ); |
| 358 |
|
| 359 |
/** @disregard P1013 Undefined method */ |
| 360 |
$this->end_controls_section(); |
| 361 |
|
| 362 |
/** @disregard P1013 Undefined method */ |
| 363 |
/** @disregard P1009 Undefined type */ |
| 364 |
$this->start_controls_section( |
| 365 |
'section_video_style', |
| 366 |
array( |
| 367 |
'label' => esc_html__( 'Video', 'elementor' ), |
| 368 |
'tab' => Elementor\Controls_Manager::TAB_STYLE, |
| 369 |
) |
| 370 |
); |
| 371 |
|
| 372 |
// TODO: This does not work. |
| 373 |
/** @disregard P1013 Undefined method */ |
| 374 |
/** @disregard P1009 Undefined type */ |
| 375 |
$this->add_control( |
| 376 |
'aspect_ratio', |
| 377 |
array( |
| 378 |
'label' => esc_html__( 'Aspect Ratio', 'elementor' ), |
| 379 |
'type' => Elementor\Controls_Manager::SELECT, |
| 380 |
'options' => array( |
| 381 |
'169' => '16:9', |
| 382 |
'219' => '21:9', |
| 383 |
'43' => '4:3', |
| 384 |
'32' => '3:2', |
| 385 |
'11' => '1:1', |
| 386 |
'916' => '9:16', |
| 387 |
), |
| 388 |
'selectors_dictionary' => array( |
| 389 |
'169' => '1.77777', // 16 / 9 |
| 390 |
'219' => '2.33333', // 21 / 9 |
| 391 |
'43' => '1.33333', // 4 / 3 |
| 392 |
'32' => '1.5', // 3 / 2 |
| 393 |
'11' => '1', // 1 / 1 |
| 394 |
'916' => '0.5625', // 9 / 16 |
| 395 |
), |
| 396 |
'default' => '169', |
| 397 |
'selectors' => array( |
| 398 |
'{{WRAPPER}} .elementor-wrapper' => '--video-aspect-ratio: {{VALUE}}', |
| 399 |
), |
| 400 |
) |
| 401 |
); |
| 402 |
|
| 403 |
/** @disregard P1013 Undefined method */ |
| 404 |
/** @disregard P1009 Undefined type */ |
| 405 |
$this->add_group_control( |
| 406 |
Elementor\Group_Control_Css_Filter::get_type(), |
| 407 |
array( |
| 408 |
'name' => 'css_filters', |
| 409 |
'selector' => '{{WRAPPER}} .elementor-wrapper', |
| 410 |
) |
| 411 |
); |
| 412 |
|
| 413 |
/** @disregard P1013 Undefined method */ |
| 414 |
/** @disregard P1009 Undefined type */ |
| 415 |
$this->end_controls_section(); |
| 416 |
} |
| 417 |
|
| 418 |
public function print_a11y_text( $image_overlay ) { |
| 419 |
if ( empty( $image_overlay['alt'] ) ) { |
| 420 |
echo esc_html__( 'Play Video', 'elementor' ); |
| 421 |
} else { |
| 422 |
echo esc_html__( 'Play Video about', 'elementor' ) . ' ' . esc_attr( $image_overlay['alt'] ); |
| 423 |
} |
| 424 |
} |
| 425 |
|
| 426 |
/** |
| 427 |
* Render video widget output on the frontend. |
| 428 |
* |
| 429 |
* Written in PHP and used to generate the final HTML. |
| 430 |
* |
| 431 |
* @since 1.0.0 |
| 432 |
* @access protected |
| 433 |
*/ |
| 434 |
protected function render() { |
| 435 |
/** @disregard P1013 Undefined method */ |
| 436 |
$settings = $this->get_settings_for_display(); |
| 437 |
|
| 438 |
$video_html = do_shortcode( $settings['shortcode'] ); |
| 439 |
|
| 440 |
if ( empty( $video_html ) ) { |
| 441 |
return; |
| 442 |
} |
| 443 |
|
| 444 |
/** @disregard P1013 Undefined method */ |
| 445 |
$this->add_render_attribute( 'video-wrapper', 'class', 'elementor-wrapper' ); |
| 446 |
|
| 447 |
/** @disregard P1013 Undefined method */ |
| 448 |
$this->add_render_attribute( 'video-wrapper', 'class', 'elementor-open-inline' ); |
| 449 |
?> |
| 450 |
<div <?php /** @disregard P1013 Undefined method */ $this->print_render_attribute_string( 'video-wrapper' ); ?>> |
| 451 |
<?php |
| 452 |
/** @disregard P1009 Undefined type */ |
| 453 |
Elementor\Utils::print_unescaped_internal_string( $video_html ); // XSS ok. |
| 454 |
?> |
| 455 |
</div> |
| 456 |
<?php |
| 457 |
} |
| 458 |
|
| 459 |
/** |
| 460 |
* Set script dependencies for the widget editing. |
| 461 |
* |
| 462 |
* @since 1.0.0 |
| 463 |
* @access public |
| 464 |
* |
| 465 |
* @return array Widget script dependencies. |
| 466 |
*/ |
| 467 |
public function get_script_depends() { |
| 468 |
/** @disregard P1009 Undefined type */ |
| 469 |
/** @disregard P1014 Undefined property */ |
| 470 |
return Elementor\Plugin::$instance->preview->is_preview_mode() ? array( 'elementor-fv-player-widget' ) : array(); |
| 471 |
} |
| 472 |
} |
| 473 |
|