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