PluginProbe ʕ •ᴥ•ʔ
Presto Player / 2.2.3-beta1
Presto Player v2.2.3-beta1
4.4.1 4.4.0 4.3.3 4.3.2 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 2 years ago ReusableVideoWidget.php 3 years ago VideoWidget.php 5 years ago
ReusableVideoWidget.php
218 lines
1 <?php
2
3 namespace PrestoPlayer\Integrations\Elementor;
4
5 use Elementor\Widget_Base;
6 use Elementor\Controls_Manager;
7 use PrestoPlayer\WPackio\Enqueue;
8 use PrestoPlayer\Models\ReusableVideo;
9 use Elementor\Modules\DynamicTags\Module as TagsModule;
10
11 if (!defined('ABSPATH')) {
12 exit; // Exit if accessed directly.
13 }
14
15 /**
16 * presto-player video widget.
17 *
18 * presto-player widget that displays a video player.
19 *
20 * @since 1.0.0
21 */
22 class ReusableVideoWidget extends Widget_Base
23 {
24 /**
25 * Get widget name.
26 *
27 * Retrieve video widget name.
28 *
29 * @since 1.0.0
30 * @access public
31 *
32 * @return string Widget name.
33 */
34 public function get_name()
35 {
36 return 'presto_video';
37 }
38
39 /**
40 * Get widget title.
41 *
42 * Retrieve video widget title.
43 *
44 * @since 1.0.0
45 * @access public
46 *
47 * @return string Widget title.
48 */
49 public function get_title()
50 {
51 return __('Presto Player Media', 'presto-player');
52 }
53
54 /**
55 * Get widget icon.
56 *
57 * Retrieve video widget icon.
58 *
59 * @since 1.0.0
60 * @access public
61 *
62 * @return string Widget icon.
63 */
64 public function get_icon()
65 {
66 return 'eicon-youtube';
67 }
68
69 /**
70 * Get widget categories.
71 *
72 * Retrieve the list of categories the video widget belongs to.
73 *
74 * Used to determine where to display the widget in the editor.
75 *
76 * @since 2.0.0
77 * @access public
78 *
79 * @return array Widget categories.
80 */
81 public function get_categories()
82 {
83 return ['basic'];
84 }
85
86 /**
87 * Get widget keywords.
88 *
89 * Retrieve the list of keywords the widget belongs to.
90 *
91 * @since 2.1.0
92 * @access public
93 *
94 * @return array Widget keywords.
95 */
96 public function get_keywords()
97 {
98 return ['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 {
111 $this->start_controls_section(
112 'section_video',
113 [
114 'label' => __('Media', 'presto-player'),
115 ]
116 );
117
118
119 $options = $this->get_videos_options();
120 $this->add_control(
121 'video_block',
122 [
123 'label' => __('Media Hub Item', 'presto-player'),
124 'type' => \Elementor\Controls_Manager::SELECT2,
125 'options' => $options,
126 'default' => '-1'
127 ]
128 );
129
130 $this->add_control(
131 'edit_video',
132 [
133 'label' => __('Edit Media', 'plugin-name'),
134 'type' => \Elementor\Controls_Manager::BUTTON,
135 'text' => __('Edit', 'plugin-domain'),
136 'event' => 'presto:video:edit',
137 'condition' => array(
138 'video_block!' => '-1',
139 ),
140 ]
141 );
142
143 $this->add_control(
144 'create_video',
145 [
146 'label' => __('Create Media', 'plugin-name'),
147 'separator' => 'before',
148 'classes' => 'testclass',
149 'type' => \Elementor\Controls_Manager::BUTTON,
150 'text' => __('Create', 'plugin-domain'),
151 'event' => 'presto:video:create',
152 ]
153 );
154
155
156 $this->add_control(
157 'url_override',
158 [
159 'label' => __('Dynamic URL Override', 'presto-player'),
160 'separator' => 'before',
161 'type' => Controls_Manager::TEXT,
162 'dynamic' => [
163 'active' => true,
164 'categories' => [
165 TagsModule::POST_META_CATEGORY,
166 TagsModule::URL_CATEGORY,
167 ],
168 ],
169 'placeholder' => __('Enter a url override', 'presto-player'),
170 'default' => '',
171 'label_block' => true,
172 ]
173 );
174
175 $this->end_controls_section();
176 }
177
178 public function get_videos_options()
179 {
180 $videos = (new ReusableVideo())->fetch();
181 $options = [];
182 foreach ($videos as $video) {
183 $options[$video->ID] = sanitize_text_field($video->post_title);
184 }
185 return $options;
186 }
187
188 /**
189 * Render video widget output on the frontend.
190 *
191 * Written in PHP and used to generate the final HTML.
192 *
193 * @since 1.0.0
194 * @access protected
195 */
196 protected function render()
197 {
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 = [];
205 if ($settings['url_override']) {
206 $overrides['src'] = $settings['url_override'];
207 }
208 $render = $video->renderBlock($overrides);
209 if ($render) {
210 echo $render;
211 return;
212 }
213
214 $video = (new ReusableVideo())->first();
215 echo $video ? $video->renderBlock($overrides) : '';
216 }
217 }
218