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