PluginProbe ʕ •ᴥ•ʔ
Presto Player / 4.3.1
Presto Player v4.3.1
4.3.1 4.3.0 4.2.4 4.2.3 4.2.2 4.2.0 4.2.1 trunk 1.10.0 1.10.1 1.10.2 1.11.0 1.12.0 1.13.0 1.14.0 1.14.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 1.6.13 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 2.2.3-beta1 2.3.0 2.3.1 2.3.2 2.3.3 3.0.0 3.0.0-beta1 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.1.0 3.1.1 3.1.2 3.1.3 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4
presto-player / inc / Integrations / Elementor / ReusableVideoWidget.php
presto-player / inc / Integrations / Elementor Last commit date
Elementor.php 1 year ago ReusableVideoWidget.php 3 weeks ago VideoWidget.php 3 weeks ago
ReusableVideoWidget.php
218 lines
1 <?php
2 /**
3 * Elementor Presto Player reusable video widget.
4 *
5 * @package PrestoPlayer
6 */
7
8 namespace PrestoPlayer\Integrations\Elementor;
9
10 use Elementor\Widget_Base;
11 use Elementor\Controls_Manager;
12 use PrestoPlayer\WPackio\Enqueue;
13 use PrestoPlayer\Models\ReusableVideo;
14 use Elementor\Modules\DynamicTags\Module as TagsModule;
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit; // Exit if accessed directly.
18 }
19
20 /**
21 * Presto Player reusable video widget.
22 *
23 * Presto Player widget that displays a reusable video player.
24 *
25 * @since 1.0.0
26 */
27 class ReusableVideoWidget extends Widget_Base {
28
29 /**
30 * Get widget name.
31 *
32 * Retrieve video widget name.
33 *
34 * @since 1.0.0
35 * @access public
36 *
37 * @return string Widget name.
38 */
39 public function get_name() {
40 return 'presto_video';
41 }
42
43 /**
44 * Get widget title.
45 *
46 * Retrieve video widget title.
47 *
48 * @since 1.0.0
49 * @access public
50 *
51 * @return string Widget title.
52 */
53 public function get_title() {
54 return __( 'Presto Player Media', 'presto-player' );
55 }
56
57 /**
58 * Get widget icon.
59 *
60 * Retrieve video widget icon.
61 *
62 * @since 1.0.0
63 * @access public
64 *
65 * @return string Widget icon.
66 */
67 public function get_icon() {
68 return 'eicon-youtube';
69 }
70
71 /**
72 * Get widget categories.
73 *
74 * Retrieve the list of categories the video widget belongs to.
75 *
76 * Used to determine where to display the widget in the editor.
77 *
78 * @since 2.0.0
79 * @access public
80 *
81 * @return array Widget categories.
82 */
83 public function get_categories() {
84 return array( 'basic' );
85 }
86
87 /**
88 * Get widget keywords.
89 *
90 * Retrieve the list of keywords the widget belongs to.
91 *
92 * @since 2.1.0
93 * @access public
94 *
95 * @return array Widget keywords.
96 */
97 public function get_keywords() {
98 return array( 'video', 'audio', 'embed', 'youtube', 'vimeo' );
99 }
100
101 /**
102 * Register video widget controls.
103 *
104 * Adds different input fields to allow the user to change and customize the widget settings.
105 *
106 * @since 1.0.0
107 * @access protected
108 */
109 protected function _register_controls() {
110 $this->start_controls_section(
111 'section_video',
112 array(
113 'label' => __( 'Media', 'presto-player' ),
114 )
115 );
116
117 $options = $this->get_videos_options();
118 $this->add_control(
119 'video_block',
120 array(
121 'label' => __( 'Media Hub Item', 'presto-player' ),
122 'type' => \Elementor\Controls_Manager::SELECT2,
123 'options' => $options,
124 'default' => '-1',
125 )
126 );
127
128 $this->add_control(
129 'edit_video',
130 array(
131 'label' => __( 'Edit Media', 'presto-player' ),
132 'type' => \Elementor\Controls_Manager::BUTTON,
133 'text' => __( 'Edit', 'presto-player' ),
134 'event' => 'presto:video:edit',
135 'condition' => array(
136 'video_block!' => '-1',
137 ),
138 )
139 );
140
141 $this->add_control(
142 'create_video',
143 array(
144 'label' => __( 'Create Media', 'presto-player' ),
145 'separator' => 'before',
146 'classes' => 'testclass',
147 'type' => \Elementor\Controls_Manager::BUTTON,
148 'text' => __( 'Create', 'presto-player' ),
149 'event' => 'presto:video:create',
150 )
151 );
152
153 $this->add_control(
154 'url_override',
155 array(
156 'label' => __( 'Dynamic URL Override', 'presto-player' ),
157 'separator' => 'before',
158 'type' => Controls_Manager::TEXT,
159 'dynamic' => array(
160 'active' => true,
161 'categories' => array(
162 TagsModule::POST_META_CATEGORY,
163 TagsModule::URL_CATEGORY,
164 ),
165 ),
166 'placeholder' => __( 'Enter a url override', 'presto-player' ),
167 'default' => '',
168 'label_block' => true,
169 )
170 );
171
172 $this->end_controls_section();
173 }
174
175 /**
176 * Get the available reusable video options for the select control.
177 *
178 * @return array Map of reusable video post ID to post title.
179 */
180 public function get_videos_options() {
181 $videos = ( new ReusableVideo() )->fetch();
182 $options = array();
183 foreach ( $videos as $video ) {
184 $options[ $video->ID ] = sanitize_text_field( $video->post_title );
185 }
186 return $options;
187 }
188
189 /**
190 * Render video widget output on the frontend.
191 *
192 * Written in PHP and used to generate the final HTML.
193 *
194 * @since 1.0.0
195 * @access protected
196 */
197 protected function render() {
198 global $load_presto_js;
199 $load_presto_js = true;
200 $settings = $this->get_settings_for_display();
201 // For backward compatibility.
202 $video_url = ( '-1' !== $settings['video_block'] ) ? $settings['video_block'] : '0';
203 $video = new ReusableVideo( $video_url );
204 $overrides = array();
205 if ( $settings['url_override'] ) {
206 $overrides['src'] = $settings['url_override'];
207 }
208 $render = $video->renderBlock( $overrides );
209 if ( $render ) {
210 echo $render; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- renderBlock() returns player markup escaped within the block renderer.
211 return;
212 }
213
214 $video = ( new ReusableVideo() )->first();
215 echo $video ? $video->renderBlock( $overrides ) : ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- renderBlock() returns player markup escaped within the block renderer.
216 }
217 }
218