PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 3.7.3
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v3.7.3
4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / EmbedPress / Includes / Classes / Feature_Enhancer.php
embedpress / EmbedPress / Includes / Classes Last commit date
Elementor_Enhancer.php 3 years ago EmbedPress_Core_Installer.php 6 years ago EmbedPress_Notice.php 4 years ago EmbedPress_Plugin_Usage_Tracker.php 3 years ago Extend_Elementor_Controls.php 3 years ago Feature_Enhancer.php 3 years ago Helper.php 3 years ago
Feature_Enhancer.php
1577 lines
1 <?php
2
3 namespace EmbedPress\Includes\Classes;
4
5 use \EmbedPress\Providers\Youtube;
6 use EmbedPress\Shortcode;
7 use EmbedPress\Includes\Classes\Helper;
8 use \Elementor\Controls_Manager;
9
10 class Feature_Enhancer
11 {
12 public static $attributes_data;
13
14 public function __construct()
15 {
16 add_filter('embedpress:onAfterEmbed', [$this, 'enhance_youtube'], 90);
17 add_filter('embedpress:onAfterEmbed', [$this, 'enhance_vimeo'], 90);
18 add_filter('embedpress:onAfterEmbed', [$this, 'enhance_wistia'], 90);
19 add_filter('embedpress:onAfterEmbed', [$this, 'enhance_twitch'], 90);
20 add_filter('embedpress:onAfterEmbed', [$this, 'enhance_dailymotion'], 90);
21 add_filter('embedpress:onAfterEmbed', [$this, 'enhance_soundcloud'], 90);
22 add_filter('embedpress:onAfterEmbed', [$this, 'enhance_missing_title'], 90);
23
24 add_filter(
25 'embedpress_gutenberg_youtube_params',
26 [$this, 'embedpress_gutenberg_register_block_youtube']
27 );
28
29 add_action('init', array($this, 'embedpress_gutenberg_register_block_vimeo'));
30 add_action('embedpress_gutenberg_wistia_block_after_embed', array($this, 'embedpress_wistia_block_after_embed'));
31 add_action('elementor/widget/embedpres_elementor/skins_init', [$this, 'elementor_setting_init']);
32 add_action('wp_ajax_youtube_rest_api', [$this, 'youtube_rest_api']);
33 add_action('wp_ajax_nopriv_youtube_rest_api', [$this, 'youtube_rest_api']);
34 add_action('embedpress_gutenberg_embed', [$this, 'gutenberg_embed'], 10, 2);
35 add_action( 'wp_ajax_save_source_data', [$this, 'save_source_data'] );
36 add_action( 'wp_ajax_nopriv_save_source_data', [$this, 'save_source_data'] );
37 add_action( 'save_post', [$this, 'save_source_data_on_post_update'], 10, 3 );
38 add_action( 'wp_ajax_delete_source_data', [$this, 'delete_source_data'] );
39 add_action( 'wp_ajax_nopriv_delete_source_data', [$this, 'delete_source_data'] );
40 add_action( 'load-post.php', [$this, 'delete_source_temp_data_on_reload'] );
41 add_action('embedpress:isEmbra', [$this, 'isEmbra'], 10, 3);
42 add_action( 'elementor/editor/after_save', [$this, 'save_el_source_data_on_post_update'] );
43
44 add_action('wp_head', [$this, 'embedpress_generate_social_share_meta']);
45 }
46
47 public function save_source_data(){
48
49 $source_url = $_POST['source_url'];
50 $blockid = $_POST['block_id'];
51
52 Helper::get_source_data($blockid, $source_url, 'gutenberg_source_data', 'gutenberg_temp_source_data');
53 }
54
55 function save_el_source_data_on_post_update( $post_id ) {
56 Helper::get_save_source_data_on_post_update('elementor_source_data', 'elementor_temp_source_data');
57 }
58
59 function save_source_data_on_post_update( $post_id, $post, $update ) {
60 if (!empty(strpos($post->post_content, 'wp:embedpress'))) {
61 Helper::get_save_source_data_on_post_update('gutenberg_source_data', 'gutenberg_temp_source_data');
62 }
63 }
64
65 public function delete_source_data() {
66 $blockid = $_POST['block_id'];
67 Helper::get_delete_source_data($blockid, 'gutenberg_source_data', 'gutenberg_temp_source_data');
68 }
69
70 public function delete_source_temp_data_on_reload() {
71 Helper::get_delete_source_temp_data_on_reload('gutenberg_temp_source_data');
72
73 }
74
75
76
77 public function isEmbra($isEmbra, $url, $atts)
78 {
79 if (strpos($url, 'youtube.com') !== false) {
80 $youtube = new Youtube($url, $atts);
81 if ($youtube->validateUrl($youtube->getUrl(false))) {
82 return true;
83 }
84 }
85 return $isEmbra;
86 }
87
88 public function youtube_rest_api()
89 {
90 $result = Youtube::get_gallery_page([
91 'playlistId' => isset($_POST['playlistid']) ? sanitize_text_field($_POST['playlistid']) : null,
92 'pageToken' => isset($_POST['pagetoken']) ? sanitize_text_field($_POST['pagetoken']) : null,
93 'pagesize' => isset($_POST['pagesize']) ? sanitize_text_field($_POST['pagesize']) : null,
94 'currentpage' => isset($_POST['currentpage']) ? sanitize_text_field($_POST['currentpage']) : null,
95 'columns' => isset($_POST['epcolumns']) ? sanitize_text_field($_POST['epcolumns']) : null,
96 'showTitle' => isset($_POST['showtitle']) ? sanitize_text_field($_POST['showtitle']) : null,
97 'showPaging' => isset($_POST['showpaging']) ? sanitize_text_field($_POST['showpaging']) : null,
98 'autonext' => isset($_POST['autonext']) ? sanitize_text_field($_POST['autonext']) : null,
99 'thumbplay' => isset($_POST['thumbplay']) ? sanitize_text_field($_POST['thumbplay']) : null,
100 'thumbnail_quality' => isset($_POST['thumbnail_quality']) ? sanitize_text_field($_POST['thumbnail_quality']) : null,
101 ]);
102
103 wp_send_json($result);
104 }
105
106
107 //Check is YouTube single video
108 public function ytValidateUrl($url)
109 {
110 return (bool) (preg_match('~v=(?:[a-z0-9_\-]+)~i', (string) $url));
111 }
112
113 //Check is YouTube live video
114 public function ytValidateLiveUrl($url)
115 {
116 return (bool) (preg_match('/^https?:\/\/(?:www\.)?youtube\.com\/(?:channel\/[\w-]+|@[\w-]+)\/live$/', (string) $url));
117 }
118
119
120 //Check is Wistia validate url
121 public function wistiaValidateUrl($url)
122 {
123 return (bool) (preg_match('#\/medias\\\?\/([a-z0-9]+)\.?#i', (string) $url ));
124 }
125
126 //Check is Wistia validate url
127 public function vimeoValidateUrl($url)
128 {
129 return (bool)preg_match('/https?:\/\/(www\.)?vimeo\.com\/\d+/', (string) $url);
130 }
131
132
133
134 // Get wistia block attributes
135 public function get_wistia_block_attributes($attributes) {
136
137 // Embed Options
138 $embedOptions = new \stdClass;
139 $embedOptions->videoFoam = false;
140 $embedOptions->fullscreenButton = (isset($attributes['wfullscreen']) && (bool) $attributes['wfullscreen'] === true);
141 $embedOptions->playbar = (isset($attributes['playbar']) && (bool) $attributes['playbar'] === true);
142
143 $embedOptions->playButton = (isset($attributes['playbutton']) && (bool) $attributes['playbutton'] === true);
144 $embedOptions->smallPlayButton = (isset($attributes['smallplaybutton']) && (bool) $attributes['smallplaybutton'] === true);
145
146 $embedOptions->autoPlay = (isset($attributes['wautoplay']) && (bool) $attributes['wautoplay'] === true);
147 $embedOptions->resumable = (isset($attributes['resumable']) && (bool) $attributes['resumable'] === true);
148
149 if(!empty($attributes['wstarttime'])){
150 $embedOptions->time = isset($attributes['wstarttime']) ? $attributes['wstarttime'] : '';
151 }
152
153 if ( is_embedpress_pro_active() ) {
154 $embedOptions->volumeControl = (isset($attributes['volumecontrol']) && (bool) $attributes['volumecontrol'] === true);
155
156 $volume = isset($attributes['volume']) ? (float) $attributes['volume'] : 0;
157
158 if ( $volume > 1 ) {
159 $volume = $volume / 100;
160 }
161 $embedOptions->volume = $volume;
162 }
163
164 $pluginList = [];
165
166 if (isset($attributes['scheme'])) {
167 $color = $attributes['scheme'];
168 if (null !== $color) {
169 $embedOptions->playerColor = $color;
170 }
171 }
172
173 // Closed Captions plugin
174 if ( $attributes['captions'] === true ) {
175 $isCaptionsEnabled = ( $attributes['captions'] === true );
176 $isCaptionsEnabledByDefault = ( $attributes['captions'] === true );
177 if ( $isCaptionsEnabled ) {
178 $pluginList['captions-v1'] = [
179 'onByDefault' => $isCaptionsEnabledByDefault,
180 ];
181 }
182 $embedOptions->captions = $isCaptionsEnabled;
183 $embedOptions->captionsDefault = $isCaptionsEnabledByDefault;
184 }
185
186 $embedOptions->plugin = $pluginList;
187
188
189
190 return json_encode($embedOptions);
191 }
192
193 public function gutenberg_embed($embedHTML, $attributes)
194 {
195 if (!empty($attributes['url'])) {
196 $youtube = new Youtube($attributes['url']);
197
198 $is_youtube = $youtube->validateUrl($youtube->getUrl(false));
199 if ($is_youtube && empty($this->ytValidateLiveUrl($attributes['url']))) {
200 $atts = [
201 'width' => intval($attributes['width']),
202 'height' => intval($attributes['height']),
203 'pagesize' => isset($attributes['pagesize']) ? intval($attributes['pagesize']) : 6,
204 'columns' => isset($attributes['columns']) ? intval($attributes['columns']) : 3,
205 'ispagination' => isset($attributes['ispagination']) ? $attributes['ispagination'] : 0,
206 'gapbetweenvideos' => isset($attributes['gapbetweenvideos']) ? $attributes['gapbetweenvideos'] : 30,
207 ];
208
209 $urlInfo = Shortcode::parseContent($attributes['url'], true, $atts);
210
211 if (!empty($urlInfo->embed)) {
212 $embedHTML = $urlInfo->embed;
213 }
214 }
215
216 if(!empty($attributes['url']) && ($this->ytValidateUrl($attributes['url']) || $this->ytValidateLiveUrl($attributes['url']))){
217
218 $atts = [
219 'url' => $attributes['url'],
220 'starttime' => !empty($attributes['starttime']) ? $attributes['starttime'] : '',
221 'endtime' => !empty($attributes['endtime']) ? $attributes['endtime'] : '',
222 'autoplay' => !empty($attributes['autoplay']) ? 1 : 0,
223 'controls' => isset($attributes['controls']) ? $attributes['controls'] : '1',
224 'fullscreen' => !empty($attributes['fullscreen']) ? 1 : 0,
225 'videoannotations' => !empty($attributes['videoannotations']) ? 1 : 0,
226 'progressbarcolor' => !empty($attributes['progressbarcolor']) ? $attributes['progressbarcolor'] : 'red',
227 'closedcaptions' => !empty($attributes['closedcaptions']) ? 1 : 0,
228 'modestbranding' => !empty($attributes['modestbranding']) ? $attributes['modestbranding'] : '',
229 'relatedvideos' => !empty($attributes['relatedvideos']) ? 1 : 0,
230 'customlogo' => !empty($attributes['customlogo']) ? $attributes['customlogo'] : '',
231 'logoX' => !empty($attributes['logoX']) ? $attributes['logoX'] : 5,
232 'logoY' => !empty($attributes['logoY']) ? $attributes['logoY'] : 10,
233 'customlogoUrl' => !empty($attributes['customlogoUrl']) ? $attributes['customlogoUrl'] : '',
234 'logoOpacity' => !empty($attributes['logoOpacity']) ? $attributes['logoOpacity'] : 0.6,
235 ];
236
237 $urlInfo = Shortcode::parseContent($attributes['url'], true, $atts);
238
239 if (!empty($urlInfo->embed)) {
240 $embedHTML = $urlInfo->embed;
241 }
242
243 if(isset( $urlInfo->embed ) && preg_match( '/src=\"(.+?)\"/', $urlInfo->embed, $match )){
244 $url_full = $match[1];
245 $query = parse_url( $url_full, PHP_URL_QUERY );
246 parse_str( $query, $params );
247
248 $params['controls'] = isset($attributes['controls']) ? $attributes['controls']: '1';
249 $params['iv_load_policy'] = !empty($attributes['videoannotations']) ? 1 : 0;
250 $params['fs'] = !empty($attributes['fullscreen']) ? 1 : 0;
251 $params['rel'] = !empty($attributes['relatedvideos']) ? 1 : 0;
252 $params['end'] = !empty($attributes['endtime']) ? $attributes['endtime'] : '';
253 $params['autoplay'] = !empty($attributes['autoplay']) ? 1 : 0;
254 $params['start'] = !empty($attributes['starttime']) ? $attributes['starttime'] : '';
255 $params['color'] = !empty($attributes['progressbarcolor']) ? $attributes['progressbarcolor'] : 'red';
256 $params['modestbranding'] = empty($attributes['modestbranding']) ? 0 : 1; // Reverse the condition value for modestbranding. 0 = display, 1 = do not display
257 $params['cc_load_policy'] = !empty($attributes['closedcaptions']) ? 0 : 1;
258
259 preg_match( '/(.+)?\?/', $url_full, $url );
260
261 if ( empty( $url) ) {
262 return $embedHTML;
263 }
264
265 $url = $url[1];
266
267 // Reassemble the url with the new variables.
268 $url_modified = $url . '?';
269
270 foreach ( $params as $paramName => $paramValue ) {
271
272 $and = '&';
273 if(array_key_last($params) === $paramName){
274 $and = '';
275 }
276
277 if(isset($paramValue) && $paramValue !== ''){
278 $url_modified .= $paramName . '=' . $paramValue . $and;
279 }
280 }
281
282 // Replaces the old url with the new one.
283 $embedHTML = str_replace( $url_full, rtrim( $url_modified, '&' ), $urlInfo->embed );
284
285 }
286
287 }
288
289 }
290
291 if (!empty($attributes['url']) && $this->wistiaValidateUrl($attributes['url'])) {
292
293
294 $embedOptions = $this->get_wistia_block_attributes($attributes);
295
296 // Get the video ID
297 $videoId = $this->getVideoIDFromURL($attributes['url']);
298 $shortVideoId = substr($videoId, 0, 3);
299
300 // Responsive?
301
302 $class = array(
303 'wistia_embed',
304 'wistia_async_' . $videoId
305 );
306
307 $attribs = array(
308 sprintf('id="wistia_%s"', $videoId),
309 sprintf('class="%s"', join(' ', $class)),
310 sprintf('style="width:%spx; height:%spx;"', $attributes['width'], $attributes['height'])
311 );
312
313 $labels = array(
314 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'),
315 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'),
316 'you_have_watched_it_before' => __(
317 'It looks like you\'ve watched<br />part of this video before!',
318 'embedpress'
319 ),
320 );
321 $labels = json_encode($labels);
322
323 preg_match('/ose-uid-([a-z0-9]*)/', $attributes['embedHTML'], $matches);
324 $uid = $matches[1];
325
326 $html = "<div class=\"embedpress-wrapper ose-wistia ose-uid-{$uid} responsive\">";
327 $html .= '<script src="https://fast.wistia.com/assets/external/E-v1.js" async></script>';
328 $html .= "<script>window.pp_embed_wistia_labels = {$labels};</script>\n";
329 $html .= "<script>window._wq = window._wq || []; _wq.push({\"{$shortVideoId}\": {$embedOptions}});</script>\n";
330 $html .= '<div ' . join(' ', $attribs) . "></div>\n";
331 $html .= '</div>';
332 $embedHTML = $html;
333 }
334
335 if(!empty($attributes['url']) && $this->vimeoValidateUrl($attributes['url'])){
336 $atts = [
337 'url' => $attributes['url'],
338 'vstarttime' => !empty($attributes['vstarttime']) ? $attributes['vstarttime'] : '',
339 'vscheme' => !empty($attributes['vscheme']) ? $attributes['vscheme'] : 'red',
340 'vautoplay' => !empty($attributes['vautoplay']) ? 1 : 0,
341 'vtitle' => !empty($attributes['vtitle']) ? 1 : 0,
342 'vauthor' => !empty($attributes['vauthor']) ? 1 : 0,
343 'vavatar' => !empty($attributes['vavatar']) ? 1 : 0,
344 'vautopause' => !empty($attributes['vautopause']) ? 1 : 0,
345 'vdnt' => !empty($attributes['vdnt']) ? 1 : 0,
346 'customlogo' => !empty($attributes['customlogo']) ? $attributes['customlogo'] : '',
347 'logoX' => !empty($attributes['logoX']) ? $attributes['logoX'] : 5,
348 'logoY' => !empty($attributes['logoY']) ? $attributes['logoY'] : 10,
349 'customlogoUrl' => !empty($attributes['customlogoUrl']) ? $attributes['customlogoUrl'] : '',
350 'logoOpacity' => !empty($attributes['logoOpacity']) ? $attributes['logoOpacity'] : 0.6,
351 ];
352
353 $urlInfo = Shortcode::parseContent($attributes['url'], true, $atts);
354
355 if (!empty($urlInfo->embed)) {
356 $embedHTML = $urlInfo->embed;
357 }
358
359 if(isset( $urlInfo->embed ) && preg_match( '/src=\"(.+?)\"/', $urlInfo->embed, $match )){
360 $url_full = $match[1];
361 $query = parse_url( $url_full, PHP_URL_QUERY );
362 parse_str( $query, $params );
363
364
365 unset($params['amp;dnt']);
366
367 $params['title'] = !empty($attributes['vtitle']) ? 1 : 0;
368 $params['byline'] = !empty($attributes['vauthor']) ? 1 : 0;
369 $params['portrait'] = !empty($attributes['vavatar']) ? 1 : 0;
370 $params['autoplay'] = !empty($attributes['vautoplay']) ? 1 : 0;
371 $params['loop'] = !empty($attributes['vloop']) ? 1 : 0;
372 $params['autopause'] = !empty($attributes['vautopause']) ? 1 : 0;
373 if(empty($attributes['vautopause'])) :
374 $params['dnt'] = !empty($attributes['vdnt']) ? 1 : 0;
375 endif;
376 $params['color'] = !empty($attributes['vscheme']) ? str_replace("#", "", $attributes['vscheme']) : '00ADEF';
377
378 if(!empty($attributes['vstarttime'])) :
379 $params['t'] = !empty($attributes['vstarttime']) ? $attributes['vstarttime'] : '';
380 endif;
381
382 preg_match( '/(.+)?\?/', $url_full, $url );
383
384 if ( empty( $url) ) {
385 return $embedHTML;
386 }
387
388 $url = $url[1];
389
390 // Reassemble the url with the new variables.
391 $url_modified = $url . '?';
392
393 // print_r($url_modified);
394
395
396 foreach ($params as $param => $value) {
397 $url_modified = add_query_arg($param, $value, $url_modified);
398 }
399
400 $url_modified = str_replace("&t=", "#t=", $url_modified);
401
402 // Replaces the old url with the new one.
403 $embedHTML = str_replace( $url_full, rtrim( $url_modified, '&' ), $urlInfo->embed );
404
405 }
406 }
407
408 return $embedHTML ;
409 }
410
411
412 public function elementor_setting_init()
413 {
414 $this->remove_classic_filters();
415 add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'youtube'], 10, 2);
416 add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'wistia'], 10, 2);
417 add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'twitch'], 10, 2);
418 add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'soundcloud'], 10, 2);
419 add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'dailymotion'], 10, 2);
420 add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'spotify'], 10, 2);
421 add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'vimeo'], 10, 2);
422 }
423 public function remove_classic_filters()
424 {
425 remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_youtube'], 90);
426 remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_vimeo'], 90);
427 remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_wistia'], 90);
428 remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_twitch'], 90);
429 remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_dailymotion'], 90);
430 remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_soundcloud'], 90);
431 }
432 public function getOptions($provider = '', $schema = [])
433 {
434 $options = (array) get_option(EMBEDPRESS_PLG_NAME . ':' . $provider, []);
435 if (empty($options) || (count($options) === 1 && empty($options[0]))) {
436 $options = [];
437
438 foreach ($schema as $fieldSlug => $field) {
439 $value = isset($field['default']) ? $field['default'] : "";
440
441 settype($value, isset($field['type']) && in_array(
442 strtolower($field['type']),
443 ['bool', 'boolean', 'int', 'integer', 'float', 'string']
444 ) ? $field['type'] : 'string');
445
446 if ($fieldSlug === "license_key") {
447 $options['license'] = [
448 'key' => true,
449 'status' => "missing",
450 ];
451 } else {
452 $options[$fieldSlug] = $value;
453 }
454 }
455 }
456
457 $options['license'] = [
458 'key' => true,
459 'status' => "missing",
460 ];
461 return apply_filters('emebedpress_get_options', $options);
462 }
463
464 public function get_youtube_params($options)
465 {
466 $params = [];
467
468 // Handle `autoplay` option.
469 if (isset($options['autoplay']) && (bool) $options['autoplay'] === true) {
470 $params['autoplay'] = 1;
471 } else {
472 unset($params['autoplay']);
473 }
474
475 // Handle `controls` option.
476 if (isset($options['controls']) && in_array((int) $options['controls'], [0, 1, 2])) {
477 $params['controls'] = (int) $options['controls'];
478 } else {
479 unset($params['controls']);
480 }
481
482 // Handle `fs` option.
483 if (isset($options['fs']) && in_array((int) $options['fs'], [0, 1])) {
484 $params['fs'] = (int) $options['fs'];
485 } else {
486 unset($params['fs']);
487 }
488
489 // Handle `iv_load_policy` option.
490 if (isset($options['iv_load_policy']) && in_array((int) $options['iv_load_policy'], [1, 3])) {
491 $params['iv_load_policy'] = (int) $options['iv_load_policy'];
492 } else {
493 unset($params['iv_load_policy']);
494 }
495
496 return apply_filters('embedpress_youtube_params', $params);
497 }
498
499 public function get_vimeo_params($options)
500 {
501 $params = [];
502
503 // Handle `display_title` option.
504 if (isset($options['display_title']) && (bool) $options['display_title'] === true) {
505 $params['title'] = 1;
506 } else {
507 $params['title'] = 0;
508 }
509
510 // Handle `autoplay` option.
511 if (!empty($options['autoplay'])) {
512 $params['autoplay'] = 1;
513 } else {
514 unset($params['autoplay']);
515 }
516
517 // Handle `color` option.
518 if (!empty($options['color'])) {
519 $params['color'] = str_replace('#', '', $options['color']);
520 } else {
521 unset($params['color']);
522 }
523 return apply_filters('embedpress_vimeo_params', $params);
524 }
525
526 //--- For CLASSIC AND BLOCK EDITOR
527 public function enhance_youtube($embed)
528 {
529
530
531 $isYoutube = (isset($embed->provider_name) && strtoupper($embed->provider_name) === 'YOUTUBE') || (isset($embed->url) && isset($embed->{$embed->url}) && isset($embed->{$embed->url}['provider_name']) && strtoupper($embed->{$embed->url}['provider_name']) === 'YOUTUBE');
532
533 if (
534 $isYoutube && isset($embed->embed)
535 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
536 ) {
537
538 // for compatibility only, @TODO; remove later after deep testing.
539 $options = $this->getOptions('youtube', $this->get_youtube_settings_schema());
540
541 // Parse the url to retrieve all its info like variables etc.
542 $url_full = $match[1];
543 $query = parse_url($url_full, PHP_URL_QUERY);
544 parse_str($query, $params);
545 // Handle `color` option.
546 if (!empty($options['color'])) {
547 $params['color'] = $options['color'];
548 } else {
549 unset($params['color']);
550 }
551 // Handle `rel` option.
552 if (isset($options['rel']) && in_array((int) $options['rel'], [0, 1])) {
553 $params['rel'] = (int) $options['rel'];
554 } else {
555 unset($params['rel']);
556 }
557
558 // Handle `autoplay` option.
559 if (isset($options['autoplay']) && (bool) $options['autoplay'] === true) {
560 $params['autoplay'] = 1;
561 } else {
562 unset($params['autoplay']);
563 }
564
565 // Handle `controls` option.
566 if (isset($options['controls']) && in_array((int) $options['controls'], [0, 1, 2])) {
567 $params['controls'] = (int) $options['controls'];
568 } else {
569 unset($params['controls']);
570 }
571 if (isset($options['start_time'])) {
572 $params['start'] = $options['start_time'];
573 } else {
574 unset($params['start']);
575 }
576 if (isset($options['end_time'])) {
577 $params['end'] = $options['end_time'];
578 } else {
579 unset($params['end']);
580 }
581
582 // Handle `fs` option.
583 if (isset($options['fs']) && in_array((int) $options['fs'], [0, 1])) {
584 $params['fs'] = (int) $options['fs'];
585 } else {
586 unset($params['fs']);
587 }
588
589 // Handle `iv_load_policy` option.
590 if (isset($options['iv_load_policy']) && in_array((int) $options['iv_load_policy'], [1, 3])) {
591 $params['iv_load_policy'] = (int) $options['iv_load_policy'];
592 } else {
593 unset($params['iv_load_policy']);
594 }
595
596 // pro controls will be handled by the pro so remove it from the free.
597 $pro_controls = ['cc_load_policy', 'modestbranding'];
598 foreach ($pro_controls as $pro_control) {
599 if (isset($params[$pro_control])) {
600 unset($params[$pro_control]);
601 }
602 }
603
604 preg_match('/(.+)?\?/', $url_full, $url);
605 $url = $url[1];
606
607 if(is_object($embed->attributes) && !empty($embed->attributes)){
608 $attributes = (array) $embed->attributes;
609
610 $params['controls'] = isset($attributes['data-controls']) ? $attributes['data-controls'] : '1';
611 $params['iv_load_policy'] = !empty($attributes['data-videoannotations']) && ($attributes['data-videoannotations'] == 'true') ? 1 : 0;
612 $params['fs'] = !empty($attributes['data-fullscreen']) && ($attributes['data-fullscreen'] == 'true') ? 1 : 0;
613 $params['rel'] = !empty($attributes['data-relatedvideos']) && ($attributes['data-relatedvideos'] == 'true') ? 1 : 0;
614 $params['end'] = !empty($attributes['data-endtime']) ? $attributes['data-endtime'] : '';
615 $params['autoplay'] = !empty($attributes['data-autoplay']) && ($attributes['data-autoplay'] == 'true') ? 1 : 0;
616 $params['start'] = !empty($attributes['data-starttime']) ? $attributes['data-starttime'] : '';
617 $params['color'] = !empty($attributes['data-progressbarcolor']) ? $attributes['data-progressbarcolor'] : 'red';
618 $params['modestbranding'] = empty($attributes['data-modestbranding']) ? 0 : 1; // Reverse the condition value for modestbranding. 0 = display, 1 = do not display
619 $params['cc_load_policy'] = !empty($attributes['data-closedcaptions']) && ($attributes['data-closedcaptions'] == 'true') ? 0 : 1;
620 }
621
622 // Reassemble the url with the new variables.
623 $url_modified = $url . '?';
624 foreach ($params as $paramName => $paramValue) {
625 $url_modified .= $paramName . '=' . $paramValue . '&';
626 }
627
628 // Replaces the old url with the new one.
629 $embed->embed = str_replace($url_full, rtrim($url_modified, '&'), $embed->embed);
630 }
631
632 return $embed;
633 }
634
635 public function enhance_vimeo($embed)
636 {
637
638
639 if (
640 isset($embed->provider_name)
641 && strtoupper($embed->provider_name) === 'VIMEO'
642 && isset($embed->embed)
643 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
644 ) {
645 // old schema is for backward compatibility only @todo; remove it in the next version after deep test
646 $options = $this->getOptions('vimeo', $this->get_vimeo_settings_schema());
647
648 $url_full = $match[1];
649 $params = [];
650
651 // Handle `display_title` option.
652 if (isset($options['display_title']) && (bool) $options['display_title'] === true) {
653 $params['title'] = 1;
654 } else {
655 $params['title'] = 0;
656 }
657
658 // Handle `autoplay` option.
659 if (isset($options['autoplay']) && (bool) $options['autoplay'] === true) {
660 $params['autoplay'] = 1;
661 } else {
662 unset($params['autoplay']);
663 }
664
665 // Handle `color` option.
666 if (!empty($options['color'])) {
667 $params['color'] = str_replace('#', '', $options['color']);
668 } else {
669 unset($params['color']);
670 }
671 // Handle `display_author` option.
672 if (isset($options['display_author']) && (bool) $options['display_author'] === true) {
673 $params['byline'] = 1;
674 } else {
675 $params['byline'] = 0;
676 }
677
678 // Handle `display_avatar` option.
679 if (isset($options['display_avatar']) && (bool) $options['display_avatar'] === true) {
680 $params['portrait'] = 1;
681 } else {
682 $params['portrait'] = 0;
683 }
684
685 // NOTE: 'vimeo_dnt' is actually only 'dnt' in the params, so unset 'dnt' only
686 //@todo; maybe extract unsetting pro vars to a function later
687 $pro_controls = ['loop', 'autopause', 'dnt',];
688 foreach ($pro_controls as $pro_control) {
689 if (isset($params[$pro_control])) {
690 unset($params[$pro_control]);
691 }
692 }
693
694 if(!empty($params['autopause'])){
695 unset($params['dnt']);
696 unset($params['amp;dnt']);
697 }
698
699 // Reassemble the url with the new variables.
700 $url_modified = str_replace("&amp;dnt=1", "", $url_full);
701
702 if(is_object($embed->attributes) && !empty($embed->attributes)){
703 $attributes = (array) $embed->attributes;
704 $attributes = stringToBoolean($attributes);
705
706 $params['title'] = !empty($attributes['data-vtitle']) ? 1 : 0;
707 $params['byline'] = !empty($attributes['data-vauthor']) ? 1 : 0;
708 $params['portrait'] = !empty($attributes['data-vavatar']) ? 1 : 0;
709 $params['autoplay'] = !empty($attributes['data-vautoplay']) ? 1 : 0;
710 $params['loop'] = !empty($attributes['data-vloop']) ? 1 : 0;
711 $params['autopause'] = !empty($attributes['data-vautopause']) ? 1 : 0;
712 if(empty($attributes['data-vautopause'])) :
713 $params['dnt'] = !empty($attributes['data-vdnt']) ? 1 : 0;
714 endif;
715 $params['color'] = !empty($attributes['data-vscheme']) ? str_replace("#", "", $attributes['data-vscheme']) : '00ADEF';
716
717 if(!empty($attributes['data-vstarttime'])) :
718 $params['t'] = !empty($attributes['data-vstarttime']) ? $attributes['data-vstarttime'] : '';
719 endif;
720
721 foreach ($params as $param => $value) {
722 $url_modified = add_query_arg($param, $value, $url_modified);
723 }
724
725 $url_modified = str_replace("&t=", "#t=", $url_modified);
726
727 }
728 else{
729 foreach ($params as $param => $value) {
730 $url_modified = add_query_arg($param, $value, $url_modified);
731 }
732
733 if (empty($attributes['data-vstarttime']) && isset($options['start_time'])) {
734 $url_modified .= '#t=' . $options['start_time'];
735 }
736 }
737
738 do_action('embedpress_after_modified_url', $url_modified, $url_full, $params);
739
740 // Replaces the old url with the new one.
741 $embed->embed = str_replace($url_full, $url_modified, $embed->embed);
742
743 }
744
745 return $embed;
746 }
747
748 public function enhance_wistia($embed)
749 {
750
751 if (
752 isset($embed->provider_name)
753 && strtoupper($embed->provider_name) === 'WISTIA, INC.'
754 && isset($embed->embed)
755 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
756 ) {
757 $options = $this->getOptions('wistia', $this->get_wistia_settings_schema());
758
759 $url_full = $match[1];
760
761 // Parse the url to retrieve all its info like variables etc.
762 $query = parse_url($embed->url, PHP_URL_QUERY);
763 $url = str_replace('?' . $query, '', $url_full);
764
765 parse_str($query, $params);
766
767 // Set the class in the attributes
768 $embed->attributes->class = str_replace('{provider_alias}', 'wistia', $embed->attributes->class);
769 $embed->embed = str_replace('ose-wistia, inc.', 'ose-wistia', $embed->embed);
770
771
772 // Embed Options
773 $embedOptions = new \stdClass;
774 $embedOptions->videoFoam = false;
775 $embedOptions->fullscreenButton = (isset($options['display_fullscreen_button']) && (bool) $options['display_fullscreen_button'] === true);
776 $embedOptions->playbar = (isset($options['display_playbar']) && (bool) $options['display_playbar'] === true);
777
778 $embedOptions->smallPlayButton = (isset($options['small_play_button']) && (bool) $options['small_play_button'] === true);
779
780 $embedOptions->autoPlay = (isset($options['autoplay']) && (bool) $options['autoplay'] === true);
781
782 if(!empty($options['start_time'])){
783 $embedOptions->time = isset($options['start_time']) ? $options['start_time'] : 0;
784 }
785
786 if (isset($options['player_color'])) {
787 $color = $options['player_color'];
788 if (null !== $color) {
789 $embedOptions->playerColor = $color;
790 }
791 }
792
793 // Plugins
794 $pluginsBaseURL = plugins_url('assets/js/wistia/min', dirname(__DIR__) . '/embedpress-Wistia.php');
795
796 $pluginList = array();
797
798 // Resumable
799 if (isset($options['plugin_resumable'])) {
800 $isResumableEnabled = $options['plugin_resumable'];
801 if ($isResumableEnabled) {
802 // Add the resumable plugin
803 $pluginList['resumable'] = array(
804 'src' => $pluginsBaseURL . '/resumable.min.js',
805 'async' => false
806 );
807 }
808 }
809
810 // Add a fix for the autoplay and resumable work better together
811 if (isset($options->autoPlay)) {
812 if ($isResumableEnabled) {
813 $pluginList['fixautoplayresumable'] = array(
814 'src' => $pluginsBaseURL . '/fixautoplayresumable.min.js'
815 );
816 }
817 }
818
819 // Focus plugin
820 if (isset($options['plugin_focus'])) {
821 $isFocusEnabled = $options['plugin_focus'];
822 $pluginList['dimthelights'] = array(
823 'src' => $pluginsBaseURL . '/dimthelights.min.js',
824 'autoDim' => $isFocusEnabled
825 );
826 $embedOptions->focus = $isFocusEnabled;
827 }
828
829 // Rewind plugin
830 if (isset($options['plugin_rewind'])) {
831 if ($options['plugin_rewind']) {
832 $embedOptions->rewindTime = isset($options['plugin_rewind_time']) ? (int) $options['plugin_rewind_time'] : 10;
833
834 $pluginList['rewind'] = array(
835 'src' => $pluginsBaseURL . '/rewind.min.js'
836 );
837 }
838 }
839 $embedOptions->plugin = $pluginList;
840
841 $embedOptions = json_encode($embedOptions);
842
843 // Get the video ID
844 $videoId = $this->getVideoIDFromURL($embed->url);
845 $shortVideoId = substr($videoId, 0, 3);
846
847 // Responsive?
848
849 $class = array(
850 'wistia_embed',
851 'wistia_async_' . $videoId
852 );
853
854 $attribs = array(
855 sprintf('id="wistia_%s"', $videoId),
856 sprintf('class="%s"', join(' ', $class)),
857 sprintf('style="width:%spx; height:%spx;"', $embed->width, $embed->height)
858 );
859
860 $labels = array(
861 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'),
862 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'),
863 'you_have_watched_it_before' => __(
864 'It looks like you\'ve watched<br />part of this video before!',
865 'embedpress'
866 ),
867 );
868 $labels = json_encode($labels);
869
870 preg_match('/ose-uid-([a-z0-9]*)/', $embed->embed, $matches);
871 $uid = $matches[1];
872
873 $html = "<div class=\"embedpress-wrapper ose-wistia ose-uid-{$uid} responsive\">";
874 $html .= '<script src="https://fast.wistia.com/assets/external/E-v1.js" async></script>';
875 $html .= "<script>window.pp_embed_wistia_labels = {$labels};</script>\n";
876 $html .= "<script>window._wq = window._wq || []; _wq.push({\"{$shortVideoId}\": {$embedOptions}});</script>\n";
877 $html .= '<div ' . join(' ', $attribs) . "></div>\n";
878 $html .= '</div>';
879 $embed->embed = $html;
880 }
881
882 return $embed;
883 }
884
885 public function enhance_twitch($embed_content)
886 {
887 $e = isset($embed_content->url) && isset($embed_content->{$embed_content->url}) ? $embed_content->{$embed_content->url} : [];
888 if (isset($e['provider_name']) && strtoupper($e['provider_name']) === 'TWITCH' && isset($embed_content->embed)) {
889 $settings = $this->getOptions('twitch', $this->get_twitch_settings_schema());
890
891 $atts = isset($embed_content->attributes) ? $embed_content->attributes : [];
892 $time = '0h0m0s';
893 $type = $e['type'];
894 $content_id = $e['content_id'];
895 $channel = 'channel' === $type ? $content_id : '';
896 $video = 'video' === $type ? $content_id : '';
897 $muted = isset($settings['embedpress_pro_twitch_mute']) && ('yes' === $settings['embedpress_pro_twitch_mute']) ? 'true' : 'false';
898 $full_screen = isset($settings['embedpress_pro_fs']) && ('yes' === $settings['embedpress_pro_fs']) ? 'true' : 'false';
899 $autoplay = isset($settings['embedpress_pro_twitch_autoplay']) && ('yes' === $settings['embedpress_pro_twitch_autoplay']) ? 'true' : 'false';
900 $theme = !empty($settings['embedpress_pro_twitch_theme']) ? $settings['embedpress_pro_twitch_theme'] : 'dark';
901
902 $layout = 'video';
903 $width = !empty($atts->{'data-width'}) ? (int) $atts->{'data-width'} : 800;
904 $height = !empty($atts->{'data-height'}) ? (int) $atts->{'data-height'} : 450;
905 if (!empty($settings['start_time'])) {
906 $ta = explode(':', gmdate("G:i:s", $settings['start_time']));
907 $h = $ta[0] . 'h';
908 $m = ($ta[1] * 1) . 'm';
909 $s = ($ta[2] * 1) . 's';
910 $time = $h . $m . $s;
911 }
912 $url = "https://embed.twitch.tv?autoplay={$autoplay}&channel={$channel}&height={$height}&layout={$layout}&migration=true&muted={$muted}&theme={$theme}&time={$time}&video={$video}&width={$width}&allowfullscreen={$full_screen}";
913 $pars_url = wp_parse_url(get_site_url());
914 $url = !empty($pars_url['host']) ? $url . '&parent=' . $pars_url['host'] : $url;
915 ob_start();
916 ?>
917 <div class="embedpress_wrapper" data-url="<?php echo esc_attr(esc_url($embed_content->url)); ?>">
918 <iframe src="<?php echo esc_url($url); ?>" allowfullscreen="" scrolling="no" frameborder="0" allow="autoplay; fullscreen" title="Twitch" sandbox="allow-modals allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox" width="<?php echo esc_attr($width); ?>" height="<?php echo esc_attr($height); ?>" style="max-width: <?php echo esc_attr($width); ?>px; max-height:<?php echo esc_attr($height); ?>px;"></iframe>
919 </div>
920 <?php
921 $c = ob_get_clean();
922 $embed_content->embed = $c;
923 }
924
925 return $embed_content;
926 }
927 public function enhance_dailymotion($embed)
928 {
929 $options = $this->getOptions('dailymotion', $this->get_dailymotion_settings_schema());
930 $isDailymotion = (isset($embed->provider_name) && strtoupper($embed->provider_name) === 'DAILYMOTION') || (isset($embed->url) && isset($embed->{$embed->url}) && isset($embed->{$embed->url}['provider_name']) && strtoupper($embed->{$embed->url}['provider_name']) === 'DAILYMOTION');
931
932 if (
933 $isDailymotion && isset($embed->embed)
934 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
935 ) {
936 // Parse the url to retrieve all its info like variables etc.
937 $url_full = $match[1];
938 $params = [
939 'ui-highlight' => str_replace('#', '', isset($options['color']) ? $options['color'] : null),
940 'mute' => (int) isset($options['mute']) ? $options['mute'] : null,
941 'autoplay' => (int) isset($options['autoplay']) ? $options['autoplay'] : null,
942 'controls' => (int) isset($options['controls']) ? $options['controls'] : null,
943 'ui-start-screen-info' => (int) isset($options['video_info']) ? $options['video_info'] : null,
944 'endscreen-enable' => 0,
945 ];
946
947 if (isset($options['play_on_mobile']) && $options['play_on_mobile'] == '1') {
948 $params['playsinline'] = 1;
949 }
950 $params['start'] = (int) isset($options['start_time']) ? $options['start_time'] : null;
951 if (is_embedpress_pro_active()) {
952 $params['ui-logo'] = (int) isset($options['show_logo']) ? $options['show_logo'] : null;
953 }
954
955 $url_modified = $url_full;
956 foreach ($params as $param => $value) {
957 $url_modified = add_query_arg($param, $value, $url_modified);
958 }
959 $embed->embed = str_replace($url_full, $url_modified, $embed->embed);
960 }
961
962 return $embed;
963 }
964 public function enhance_soundcloud($embed)
965 {
966
967 $isSoundcloud = (isset($embed->provider_name) && strtoupper($embed->provider_name) === 'SOUNDCLOUD') || (isset($embed->url) && isset($embed->{$embed->url}) && isset($embed->{$embed->url}['provider_name']) && strtoupper($embed->{$embed->url}['provider_name']) === 'SOUNDCLOUD');
968
969 if (
970 $isSoundcloud && isset($embed->embed)
971 && preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
972 ) {
973 $options = $this->getOptions('soundcloud', $this->get_soundcloud_settings_schema());
974 // Parse the url to retrieve all its info like variables etc.
975 $url_full = $match[1];
976 $params = [
977 'color' => str_replace('#', '', $options['color']),
978 'visual' => isset($options['visual']) && $options['visual'] == '1' ? 'true' : 'false',
979 'auto_play' => isset($options['autoplay']) && $options['autoplay'] == '1' ? 'true' : 'false',
980 'sharing' => isset($options['share_button']) && $options['share_button'] == '1' ? 'true' : 'false',
981 'show_comments' => isset($options['comments']) && $options['comments'] == '1' ? 'true' : 'false',
982 'buying' => 'false',
983 'download' => 'false',
984 'show_artwork' => isset($options['artwork']) && $options['artwork'] == '1' ? 'true' : 'false',
985 'show_playcount' => isset($options['play_count']) && $options['play_count'] == '1' ? 'true' : 'false',
986 'show_user' => isset($options['username']) && $options['username'] == '1' ? 'true' : 'false',
987 ];
988
989 if (is_embedpress_pro_active()) {
990 $params['buying'] = isset($options['buy_button']) && $options['buy_button'] == '1' ? 'true' : 'false';
991 $params['download'] = isset($options['download_button']) && $options['download_button'] == '1' ? 'true' : 'false';
992 }
993
994 $url_modified = $url_full;
995 foreach ($params as $param => $value) {
996 $url_modified = add_query_arg($param, $value, $url_modified);
997 }
998
999 // Replaces the old url with the new one.
1000 $embed->embed = str_replace($url_full, $url_modified, $embed->embed);
1001 if ('false' === $params['visual']) {
1002 $embed->embed = str_replace('height="400"', 'height="200 !important"', $embed->embed);
1003 }
1004 }
1005
1006 return $embed;
1007 }
1008 public function embedpress_gutenberg_register_block_youtube($youtube_params)
1009 {
1010 $youtube_options = $this->getOptions('youtube', $this->get_youtube_settings_schema());
1011 return $this->get_youtube_params($youtube_options);
1012 }
1013 public function embedpress_gutenberg_register_block_vimeo()
1014 {
1015 if (function_exists('register_block_type')) :
1016 register_block_type('embedpress/vimeo-block', array(
1017 'attributes' => array(
1018 'url' => array(
1019 'type' => 'string',
1020 'default' => ''
1021 ),
1022 'iframeSrc' => array(
1023 'type' => 'string',
1024 'default' => ''
1025 ),
1026 ),
1027 'render_callback' => [$this, 'embedpress_gutenberg_render_block_vimeo']
1028 ));
1029 endif;
1030 }
1031 public function embedpress_gutenberg_render_block_vimeo($attributes)
1032 {
1033 ob_start();
1034 if (!empty($attributes) && !empty($attributes['iframeSrc'])) :
1035 $vimeo_options = $this->getOptions('vimeo', $this->get_vimeo_settings_schema());
1036 $vimeo_params = $this->get_vimeo_params($vimeo_options);
1037 $iframeUrl = $attributes['iframeSrc'];
1038 $align = 'align' . (isset($attributes['align']) ? $attributes['align'] : 'center');
1039 foreach ($vimeo_params as $param => $value) {
1040 $iframeUrl = add_query_arg($param, $value, $iframeUrl);
1041 }
1042 //@TODO; test responsive without static height width, keeping for now backward compatibility
1043 ?>
1044 <div class="ose-vimeo wp-block-embed-vimeo <?php echo $align; ?>">
1045 <iframe src="<?php echo $iframeUrl; ?>" allowtransparency="true" frameborder="0" width="640" height="360">
1046 </iframe>
1047 </div>
1048 <?php
1049 endif;
1050
1051 return apply_filters('embedpress_gutenberg_block_markup', ob_get_clean());
1052 }
1053 public function get_youtube_settings_schema()
1054 {
1055 return [
1056 'autoplay' => [
1057 'type' => 'bool',
1058 'default' => false
1059 ],
1060 'color' => [
1061 'type' => 'string',
1062 'default' => 'red'
1063 ],
1064 'cc_load_policy' => [
1065 'type' => 'bool',
1066 'default' => false
1067 ],
1068 'controls' => [
1069 'type' => 'string',
1070 'default' => '1'
1071 ],
1072 'fs' => [
1073 'type' => 'bool',
1074 'default' => true
1075 ],
1076 'iv_load_policy' => [
1077 'type' => 'radio',
1078 'default' => '1'
1079 ],
1080 'rel' => [
1081 'type' => 'bool',
1082 'default' => true
1083 ],
1084 'modestbranding' => [
1085 'type' => 'string',
1086 'default' => '0'
1087 ],
1088 'logo_url' => [
1089 'type' => 'url',
1090 ],
1091 'logo_xpos' => [
1092 'type' => 'number',
1093 'default' => 10
1094 ],
1095 'logo_ypos' => [
1096 'type' => 'number',
1097 'default' => 10
1098 ],
1099 'cta_url' => [
1100 'type' => 'url',
1101 ],
1102 'start_time' => [
1103 'type' => 'number',
1104 'default' => 10
1105 ],
1106 'end_time' => [
1107 'type' => 'number',
1108 'default' => 10
1109 ],
1110 ];
1111 }
1112 public function get_vimeo_settings_schema()
1113 {
1114 return array(
1115 'start_time' => [
1116 'type' => 'number',
1117 'default' => 10
1118 ],
1119 'autoplay' => array(
1120 'type' => 'bool',
1121 'default' => false
1122 ),
1123 'loop' => array(
1124 'type' => 'bool',
1125 'default' => false
1126 ),
1127 'autopause' => array(
1128 'type' => 'bool',
1129 'default' => false
1130 ),
1131 'vimeo_dnt' => array(
1132 'type' => 'bool',
1133 'default' => true,
1134 ),
1135 'color' => array(
1136 'type' => 'text',
1137 'default' => '#00adef',
1138 'classes' => 'color-field'
1139 ),
1140 'display_title' => array(
1141 'type' => 'bool',
1142 'default' => true
1143 ),
1144 'display_author' => array(
1145 'type' => 'bool',
1146 'default' => true
1147 ),
1148 'display_avatar' => array(
1149 'type' => 'bool',
1150 'default' => true
1151 )
1152 );
1153 }
1154 public function get_wistia_settings_schema()
1155 {
1156 return array(
1157 'start_time' => [
1158 'type' => 'number',
1159 'default' => 0
1160 ],
1161 'display_fullscreen_button' => array(
1162 'type' => 'bool',
1163 'default' => true
1164 ),
1165 'display_playbar' => array(
1166 'type' => 'bool',
1167 'default' => true
1168 ),
1169 'small_play_button' => array(
1170 'type' => 'bool',
1171 'default' => true
1172 ),
1173 'display_volume_control' => array(
1174 'type' => 'bool',
1175 'default' => true
1176 ),
1177 'autoplay' => array(
1178 'type' => 'bool',
1179 'default' => false
1180 ),
1181 'volume' => array(
1182 'type' => 'text',
1183 'default' => '100'
1184 ),
1185 'player_color' => array(
1186 'type' => 'text',
1187 'default' => '#00adef',
1188 ),
1189 'plugin_resumable' => array(
1190 'type' => 'bool',
1191 'default' => false
1192 ),
1193 'plugin_captions' => array(
1194 'type' => 'bool',
1195 'default' => false
1196 ),
1197 'plugin_captions_default' => array(
1198 'type' => 'bool',
1199 'default' => false
1200 ),
1201 'plugin_focus' => array(
1202 'type' => 'bool',
1203 'default' => false
1204 ),
1205 'plugin_rewind' => array(
1206 'type' => 'bool',
1207 'default' => false
1208 ),
1209 'plugin_rewind_time' => array(
1210 'type' => 'text',
1211 'default' => '10'
1212 ),
1213 );
1214 }
1215
1216
1217 public function getVideoIDFromURL($url)
1218 {
1219 // https://fast.wistia.com/embed/medias/xf1edjzn92.jsonp
1220 // https://ostraining-1.wistia.com/medias/xf1edjzn92
1221 preg_match('#\/medias\\\?\/([a-z0-9]+)\.?#i', $url, $matches);
1222
1223 $id = false;
1224 if (isset($matches[1])) {
1225 $id = $matches[1];
1226 }
1227
1228 return $id;
1229 }
1230 public function embedpress_wistia_block_after_embed($attributes)
1231 {
1232 $embedOptions = $this->embedpress_wistia_pro_get_options();
1233 // Get the video ID
1234 $videoId = $this->getVideoIDFromURL($attributes['url']);
1235 $shortVideoId = $videoId;
1236
1237 $labels = array(
1238 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'),
1239 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'),
1240 'you_have_watched_it_before' => __('It looks like you\'ve watched<br />part of this video before!', 'embedpress'),
1241 );
1242 $labels = json_encode($labels);
1243
1244
1245 $html = '<script src="https://fast.wistia.com/assets/external/E-v1.js"></script>';
1246 $html .= "<script>window.pp_embed_wistia_labels = {$labels};</script>\n";
1247 $html .= "<script>wistiaEmbed = Wistia.embed( \"{$shortVideoId}\", {$embedOptions} );</script>\n";
1248
1249
1250
1251 echo $html;
1252 }
1253 public function embedpress_wistia_pro_get_options()
1254 {
1255 $options = $this->getOptions('wistia', $this->get_wistia_settings_schema());
1256 // Embed Options
1257 $embedOptions = new \stdClass;
1258 // $embedOptions->videoFoam = true;
1259 $embedOptions->fullscreenButton = (isset($options['display_fullscreen_button']) && (bool) $options['display_fullscreen_button'] === true);
1260 $embedOptions->smallPlayButton = (isset($options['small_play_button']) && (bool) $options['small_play_button'] === true);
1261 $embedOptions->autoPlay = (isset($options['autoplay']) && (bool) $options['autoplay'] === true);
1262
1263 if (isset($options['player_color'])) {
1264 $color = $options['player_color'];
1265 if (null !== $color) {
1266 $embedOptions->playerColor = $color;
1267 }
1268 }
1269
1270 // Plugins
1271 $pluginsBaseURL = plugins_url('assets/js/wistia/min', dirname(__DIR__) . '/embedpress-Wistia.php');
1272
1273 $pluginList = array();
1274
1275 // Resumable
1276 if (isset($options['plugin_resumable'])) {
1277 $isResumableEnabled = $options['plugin_resumable'];
1278 if ($isResumableEnabled) {
1279 // Add the resumable plugin
1280 $pluginList['resumable'] = array(
1281 'src' => '//fast.wistia.com/labs/resumable/plugin.js',
1282 'async' => false
1283 );
1284 }
1285 }
1286 // Add a fix for the autoplay and resumable work better together
1287 //@TODO; check baseurl deeply, not looking good
1288 if ($options['autoplay']) {
1289 if ($isResumableEnabled) {
1290 $pluginList['fixautoplayresumable'] = array(
1291 'src' => $pluginsBaseURL . '/fixautoplayresumable.min.js'
1292 );
1293 }
1294 }
1295
1296
1297 // Focus plugin
1298 if (isset($options['plugin_focus'])) {
1299 $isFocusEnabled = $options['plugin_focus'];
1300 $pluginList['dimthelights'] = array(
1301 'src' => '//fast.wistia.com/labs/dim-the-lights/plugin.js',
1302 'autoDim' => $isFocusEnabled
1303 );
1304 $embedOptions->focus = $isFocusEnabled;
1305 }
1306
1307 $embedOptions->plugin = $pluginList;
1308 $embedOptions = apply_filters('embedpress_wistia_params', $embedOptions);
1309 $embedOptions = json_encode($embedOptions);
1310 return apply_filters('embedpress_wistia_params_after_encode', $embedOptions);
1311 }
1312
1313
1314 public function get_twitch_settings_schema()
1315 {
1316 return [
1317 'start_time' => [
1318 'type' => 'number',
1319 'default' => 0,
1320 ],
1321 'embedpress_pro_twitch_autoplay' => [
1322 'type' => 'string',
1323 'default' => 'no',
1324 ],
1325 'embedpress_pro_twitch_chat' => [
1326 'type' => 'string',
1327 'default' => 'no',
1328 ],
1329
1330 'embedpress_pro_twitch_theme' => [
1331 'type' => 'string',
1332 'default' => 'dark',
1333 ],
1334 'embedpress_pro_fs' => [
1335 'type' => 'string',
1336 'default' => 'yes',
1337 ],
1338 'embedpress_pro_twitch_mute' => [
1339 'type' => 'string',
1340 'default' => 'yes',
1341 ],
1342
1343 ];
1344 }
1345 public function get_dailymotion_settings_schema()
1346 {
1347 return [
1348 'autoplay' => [
1349 'type' => 'string',
1350 'default' => ''
1351 ],
1352 'play_on_mobile' => [
1353 'type' => 'string',
1354 'default' => ''
1355 ],
1356 'color' => [
1357 'type' => 'string',
1358 'default' => '#dd3333'
1359 ],
1360 'mute' => [
1361 'type' => 'string',
1362 'default' => ''
1363 ],
1364 'controls' => [
1365 'type' => 'string',
1366 'default' => '1'
1367 ],
1368 'video_info' => [
1369 'type' => 'string',
1370 'default' => '1'
1371 ],
1372 'show_logo' => [
1373 'type' => 'string',
1374 'default' => '1'
1375 ],
1376 'start_time' => [
1377 'type' => 'string',
1378 'default' => '0'
1379 ],
1380 ];
1381 }
1382 public function get_soundcloud_settings_schema()
1383 {
1384 return [
1385 'visual' => [
1386 'type' => 'string',
1387 'default' => ''
1388 ],
1389 'autoplay' => [
1390 'type' => 'string',
1391 'default' => ''
1392 ],
1393 'play_on_mobile' => [
1394 'type' => 'string',
1395 'default' => ''
1396 ],
1397 'color' => [
1398 'type' => 'string',
1399 'default' => '#dd3333'
1400 ],
1401
1402 'share_button' => [
1403 'type' => 'string',
1404 'default' => ''
1405 ],
1406 'comments' => [
1407 'type' => 'string',
1408 'default' => '1'
1409 ],
1410 'artwork' => [
1411 'type' => 'string',
1412 'default' => ''
1413 ],
1414 'play_count' => [
1415 'type' => 'string',
1416 'default' => '1'
1417 ],
1418 'username' => [
1419 'type' => 'string',
1420 'default' => '1'
1421 ],
1422 'download_button' => [
1423 'type' => 'string',
1424 'default' => '1'
1425 ],
1426 'buy_button' => [
1427 'type' => 'string',
1428 'default' => '1'
1429 ],
1430 ];
1431 }
1432
1433 public function enhance_missing_title($embed){
1434
1435
1436 $embed_arr = get_object_vars($embed);
1437
1438 $url = $embed->url;
1439
1440 if (strpos($url, 'gettyimages') !== false) {
1441 $title = $embed_arr[$url]['title'];
1442 } else {
1443 $title = '';
1444 }
1445
1446
1447 $embed->embed = $embed->embed . "
1448 <script>
1449 if (typeof gie === 'function') {
1450 gie(function(){
1451 var iframe = document.querySelector('.ose-embedpress-responsive iframe');
1452 if(iframe && !iframe.getAttribute('title')){
1453 iframe.setAttribute('title', '$title')
1454 }
1455 });
1456 }
1457 </script>
1458 ";
1459 return $embed;
1460 }
1461
1462
1463 public function embedpress_generate_social_share_meta()
1464 {
1465 $post_id = get_the_ID();
1466 $post = get_post($post_id);
1467 $tags = '';
1468
1469 $thumbnail_url = get_the_post_thumbnail_url($post_id);
1470
1471 if (!empty($_GET['hash'])) {
1472
1473 $id_value = $_GET['hash'];
1474 $url = get_the_permalink( $post_id );
1475
1476 if (class_exists('Elementor\Plugin') && \Elementor\Plugin::$instance->db->is_built_with_elementor(get_the_ID())) {
1477 $page_settings = get_post_meta( $post_id, '_elementor_data', true );
1478
1479 $ep_settings = Helper::ep_get_elementor_widget_settings($page_settings, $id_value, 'embedpres_elementor');
1480 $pdf_settings = Helper::ep_get_elementor_widget_settings($page_settings, $id_value, 'embedpress_pdf');
1481 $doc_settings = Helper::ep_get_elementor_widget_settings($page_settings, $id_value, 'embedpres_document');
1482
1483
1484
1485 if (is_array($ep_settings) && !empty($ep_settings)) {
1486 $title = !empty($ep_settings['settings']['embedpress_content_title']) ? $ep_settings['settings']['embedpress_content_title'] : '';
1487
1488 $description = !empty($ep_settings['settings']['embedpress_content_descripiton']) ? $ep_settings['settings']['embedpress_content_descripiton'] : '';
1489
1490 $image_url = !empty($ep_settings['settings']['embedpress_content_share_custom_thumbnail']['url']) ? $ep_settings['settings']['embedpress_content_share_custom_thumbnail']['url'] : '';
1491 }
1492 else if (is_array($pdf_settings) && !empty($pdf_settings)) {
1493 $title = !empty($pdf_settings['settings']['embedpress_pdf_content_title']) ? $pdf_settings['settings']['embedpress_pdf_content_title'] : '';
1494
1495 $description = !empty($pdf_settings['settings']['embedpress_pdf_content_descripiton']) ? $pdf_settings['settings']['embedpress_pdf_content_descripiton'] : '';
1496
1497 $image_url = !empty($pdf_settings['settings']['embedpress_pdf_content_share_custom_thumbnail']['url']) ? $pdf_settings['settings']['embedpress_pdf_content_share_custom_thumbnail']['url'] : '';
1498 }
1499 else if (is_array($doc_settings) && !empty($doc_settings)) {
1500 $title = !empty($doc_settings['settings']['embedpress_doc_content_title']) ? $doc_settings['settings']['embedpress_doc_content_title'] : '';
1501
1502 $description = !empty($doc_settings['settings']['embedpress_doc_content_descripiton']) ? $doc_settings['settings']['embedpress_doc_content_descripiton'] : '';
1503
1504 $image_url = !empty($doc_settings['settings']['embedpress_doc_content_share_custom_thumbnail']['url']) ? $doc_settings['settings']['embedpress_doc_content_share_custom_thumbnail']['url'] : '';
1505 }
1506
1507 // Search for the regex pattern in the string and extract the href value
1508 if (!empty($image_url)) {
1509 $tags .= "<meta name='twitter:image' content='$image_url'/>\n";
1510 $tags .= "<meta property='og:image' content='$image_url'/>\n";
1511 $tags .= "<meta property='og:url' content='$url?hash=$id_value'/>\n";
1512 }
1513 else if(!empty($thumbnail_ur)){
1514 $tags .= "<meta name='twitter:image' content='$image_url'/>\n";
1515 $tags .= "<meta property='og:image' content='$image_url'/>\n";
1516 }
1517
1518 if (!empty($title)) {
1519 $title = json_decode('"' . $title . '"', JSON_UNESCAPED_UNICODE);
1520 $tags .= "<meta property='og:title' content='$title'/>\n";
1521 $tags .= "<meta name='title' property='og:title' content='$title'>\n";
1522 $tags .= "<meta name='twitter:title' content='$title'/>\n";
1523 }
1524 if (!empty($description)) {
1525 $description = json_decode('"' . $description . '"', JSON_UNESCAPED_UNICODE);
1526 $tags .= "<meta property='og:description' content='$description'/>\n";
1527 $tags .= "<meta name='twitter:description' content='$description'/>\n";
1528 }
1529
1530 } else {
1531
1532 $block_content = $post->post_content;
1533
1534 // Regular expression to match the id and href keys and their values
1535 $thumb = '/(?:"id":"' . $id_value . '"|"clientId":"' . $id_value . '").*?"customThumbnail":"(.*?)"/';
1536 $title = '/(?:"id":"' . $id_value . '"|"clientId":"' . $id_value . '").*?"customTitle":"(.*?)"/';
1537 $description = '/(?:"id":"' . $id_value . '"|"clientId":"' . $id_value . '").*?"customDescription":"(.*?)"/';
1538
1539 // Search for the regex pattern in the string and extract the href value
1540 if (preg_match($thumb, $block_content, $matches1)) {
1541 $image_url = $matches1[1];
1542 $tags .= "\n<meta name='twitter:image' content='$image_url'/>\n";
1543 $tags .= "<meta property='og:image' content='$image_url'/>\n";
1544 $tags .= "<meta property='og:url' content='$url?hash=$id_value'/>\n";
1545 }
1546 else if(!empty($thumbnail_url)){
1547 $tags .= "\n<meta name='twitter:image' content='$thumbnail_url'/>\n";
1548 $tags .= "<meta property='og:image' content='$thumbnail_url'/>\n";
1549 }
1550
1551 if (preg_match($title, $block_content, $matches2)) {
1552 $title = json_decode('"' . $matches2[1] . '"', JSON_UNESCAPED_UNICODE);
1553 $tags .= "<meta property='og:title' content='$title'/>\n";
1554 $tags .= "<meta name='title' property='og:title' content='$title'>\n";
1555 $tags .= "<meta name='twitter:title' content='$title'/>\n";
1556 }
1557
1558 if (preg_match($description, $block_content, $matches3)) {
1559 $description = json_decode('"' . $matches3[1] . '"', JSON_UNESCAPED_UNICODE);
1560 $tags .= "<meta property='og:description' content='$description'/>\n";
1561 $tags .= "<meta name='twitter:description' content='$description'/>\n";
1562 }
1563 }
1564
1565 $tags .= "<meta name='twitter:card' content='summary_large_image'/>\n";
1566
1567 remove_action('wp_head', 'rel_canonical');
1568
1569 echo $tags;
1570
1571 }
1572 }
1573
1574
1575
1576 }
1577