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