PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 4.1.1
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v4.1.1
4.6.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 / Gutenberg / block-backend / block-embedpress.php
embedpress / Gutenberg / block-backend Last commit date
block-embedpress.php 1 year ago block-wistia.php 2 years ago block-youtube.php 2 years ago
block-embedpress.php
525 lines
1 <?php
2
3 use EmbedPress\Includes\Classes\Helper;
4
5 // Exit if accessed directly.
6 if (!defined('ABSPATH')) {
7 exit;
8 }
9 /**
10 * It renders gutenberg block of embedpress on the frontend
11 * @param array $attributes
12 */
13
14 if(!function_exists('lock_content_form_handler')){
15 add_action('wp_ajax_lock_content_form_handler', 'lock_content_form_handler');
16 add_action('wp_ajax_nopriv_lock_content_form_handler', 'lock_content_form_handler');
17
18 function lock_content_form_handler() {
19 // print_r($embedHTML);
20
21 $client_id = isset($_POST['client_id']) ? sanitize_text_field($_POST['client_id']) : '';
22 $password = isset($_POST['password']) ? sanitize_text_field($_POST['password']) : '';
23 $post_id = isset($_POST['post_id']) ? absint($_POST['post_id']) : 0;
24
25 $epbase64 = get_post_meta( $post_id, 'ep_base_' .$client_id, true );
26 $hash_key = get_post_meta( $post_id, 'hash_key_' .$client_id, true );
27
28 // Set the decryption key and initialization vector (IV)
29 $key = Helper::get_hash();
30
31 // Decode the base64 encoded cipher
32 $cipher = base64_decode($epbase64);
33 // Decrypt the cipher using AES-128-CBC encryption
34
35 $wp_pass_key = hash('sha256', wp_salt(32) . md5($password));
36 $iv = substr($wp_pass_key, 0, 16);
37
38 if ($wp_pass_key === $hash_key) {
39 setcookie("password_correct_", $password, time()+3600);
40
41 $embed = openssl_decrypt($cipher, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $iv) . '<script>
42 var now = new Date();
43 var time = now.getTime();
44 var expireTime = time + 1000 * 60 * 60 * 24 * 30;
45 now.setTime(expireTime);
46 document.cookie = "password_correct_'.esc_js($client_id).'='.esc_js($hash_key).'; expires=" + now.toUTCString() + "; path=/";
47 </script>';
48
49 }
50 else{
51 $embed = 0;
52 }
53
54 // Process the form data and return a response
55 $response = array(
56 'success' => true,
57 'password' => $password,
58 'embedHtml' => $embed,
59 'post_id' => $post_id
60 );
61
62 wp_send_json($response);
63
64 }
65 }
66
67 function embedpress_block_scripts($attributes) {
68
69 // print_r($attributes); die;
70
71 $script_handles = [];
72
73 if(!empty($attributes['customPlayer'])){
74 $script_handles[] = 'plyr.polyfilled';
75 $script_handles[] = 'initplyr';
76 $script_handles[] = 'vimeo-player';
77 }
78
79 $script_handles[] = 'embedpress-front';
80
81 if(!empty($attributes['adManager'])){
82 $script_handles[] = 'embedpress-ads';
83 }
84
85 if((!empty($attributes['instaLayout']) && $attributes['instaLayout'] == 'insta-carousel') || (!empty($attributes['ytChannelLayout']) && $attributes['ytChannelLayout'] == 'carousel')){
86 $script_handles[] = 'cg-carousel';
87 }
88
89 foreach ($script_handles as $handle) {
90 wp_enqueue_script($handle);
91 }
92
93 $style_handles = [];
94
95 if(!empty($attributes['customPlayer'])){
96 $style_handles[] = 'plyr';
97 }
98
99 if((!empty($attributes['instaLayout']) && $attributes['instaLayout'] == 'insta-carousel') || (!empty($attributes['ytChannelLayout']) && $attributes['ytChannelLayout'] == 'carousel')){
100 $style_handles[] = 'cg-carousel';
101 }
102
103 $style_handles[] = 'embedpress_blocks-cgb-style-css';
104 $style_handles[] = 'embedpress-style';
105
106 foreach ($style_handles as $handle) {
107 wp_enqueue_style($handle);
108 }
109 }
110
111 function embedpress_render_block($attributes)
112 {
113
114 embedpress_block_scripts($attributes);
115
116
117 $client_id = !empty($attributes['clientId']) ? md5($attributes['clientId']) : '';
118 $block_id = !empty($attributes['clientId']) ? $attributes['clientId'] : '';
119 $custom_player = !empty($attributes['customPlayer']) ? $attributes['customPlayer'] : 0;
120 $instaLayout = !empty($attributes['instaLayout']) ? ' '.$attributes['instaLayout'] : ' insta-grid';
121
122 $_carousel_options = '';
123 $_carousel_id = '';
124 if(!empty($attributes['instaLayout']) && $attributes['instaLayout'] === 'insta-carousel'){
125 $_carousel_id = 'data-carouselid=' . esc_attr($client_id) . '';
126
127 $layout = $attributes['instaLayout'];
128 $slidesShow = !empty($attributes['slidesShow']) ? $attributes['slidesShow'] : 5;
129 $carouselAutoplay = !empty($attributes['carouselAutoplay']) ? $attributes['carouselAutoplay'] : 0;
130 $autoplaySpeed = !empty($attributes['autoplaySpeed']) ? $attributes['autoplaySpeed'] : 3000;
131 $transitionSpeed = !empty($attributes['transitionSpeed']) ? $attributes['transitionSpeed'] : 1000;
132 $carouselLoop = !empty($attributes['carouselLoop']) ? $attributes['carouselLoop'] : 0;
133 $carouselArrows = !empty($attributes['carouselArrows']) ? $attributes['carouselArrows'] : 0;
134 $spacing = !empty($attributes['carouselSpacing']) ? $attributes['carouselSpacing'] : 0;
135
136 // print_r($attributes);
137
138 $carousel_options = [
139 'layout' => $layout,
140 'slideshow' => $slidesShow,
141 'autoplay' => $carouselAutoplay,
142 'autoplayspeed' => $autoplaySpeed,
143 'transitionspeed' => $transitionSpeed,
144 'loop' => $carouselLoop,
145 'arrows' => $carouselArrows,
146 'spacing' => $spacing
147 ];
148
149 $carousel_options_string = json_encode($carousel_options);
150 $_carousel_options = 'data-carousel-options='. htmlentities($carousel_options_string, ENT_QUOTES) .'';
151 }
152
153 $cEmbedType = !empty($attributes['cEmbedType']) ? ' '.$attributes['cEmbedType'] : '';
154
155 $_custom_player = '';
156 $_player_options = '';
157
158 if (!empty($custom_player)) {
159
160 $is_self_hosted = Helper::check_media_format($attributes['url']);
161
162 $_custom_player = 'data-playerid=' . esc_attr($client_id);
163 $player_preset = !empty($attributes['playerPreset']) ? $attributes['playerPreset'] : 'preset-default';
164 $player_color = !empty($attributes['playerColor']) ? $attributes['playerColor'] : '';
165 $poster_thumbnail = !empty($attributes['posterThumbnail']) ? $attributes['posterThumbnail'] : '';
166 $player_pip = !empty($attributes['playerPip']) ? true : false;
167 $player_restart = !empty($attributes['playerRestart']) ? true : false;
168 $player_rewind = !empty($attributes['playerRewind']) ? true : false;
169 $player_fastForward = !empty($attributes['playerFastForward']) ? true : false;
170 $player_tooltip = !empty($attributes['playerTooltip']) ? true : false;
171 $player_hide_controls = !empty($attributes['playerHideControls']) ? true : false;
172 $player_download = !empty($attributes['playerDownload']) ? true : false;
173
174 $playerOptions = [
175 'rewind' => $player_rewind,
176 'restart' => $player_restart,
177 'pip' => $player_pip,
178 'poster_thumbnail' => $poster_thumbnail,
179 'player_color' => $player_color,
180 'player_preset' => $player_preset,
181 'fast_forward' => $player_fastForward,
182 'player_tooltip' => $player_tooltip,
183 'hide_controls' => $player_hide_controls,
184 'download' => $player_download,
185 ];
186
187 if(!empty($attributes['fullscreen'])){
188 $playerOptions['fullscreen'] = $attributes['fullscreen'];
189 }
190
191 if(!empty($is_self_hosted['selhosted'])){
192 $playerOptions['self_hosted'] = $is_self_hosted['selhosted'];
193 $playerOptions['hosted_format'] = $is_self_hosted['format'];
194 }
195
196 //Youtube options
197 if(!empty($attributes['starttime'])){
198 $playerOptions['start'] = $attributes['starttime'];
199 }
200 if(!empty($attributes['endtime'])){
201 $playerOptions['end'] = $attributes['endtime'];
202 }
203 if(!empty($attributes['relatedvideos'])){
204 $playerOptions['rel'] = $attributes['relatedvideos'];
205 }
206
207 //vimeo options
208 if(!empty($attributes['vstarttime'])){
209 $playerOptions['t'] = $attributes['vstarttime'];
210 }
211 if(!empty($attributes['vautoplay'])){
212 $playerOptions['vautoplay'] = $attributes['vautoplay'];
213 }
214 if(!empty($attributes['vautopause'])){
215 $playerOptions['autopause'] = $attributes['vautopause'];
216 }
217 if(!empty($attributes['vdnt'])){
218 $playerOptions['dnt'] = $attributes['vdnt'];
219 }
220
221 $playerOptionsString = json_encode($playerOptions);
222 $_player_options = 'data-options='. htmlentities($playerOptionsString, ENT_QUOTES);
223 }
224
225 $pass_hash_key = isset($attributes['contentPassword']) ? md5($attributes['contentPassword']): '';
226
227
228
229 if (!empty($attributes['embedHTML'])) {
230 $embed = apply_filters('embedpress_gutenberg_embed', $attributes['embedHTML'], $attributes);
231
232 $content_share_class = '';
233 $share_position_class = '';
234 $share_position = isset($attributes['sharePosition']) ? $attributes['sharePosition'] : 'right';
235
236 if(!empty($attributes['contentShare'])) {
237 $content_share_class = 'ep-content-share-enabled';
238 $share_position_class = 'ep-share-position-'.$share_position;
239 }
240
241 $password_correct = isset($_COOKIE['password_correct_'.$client_id]) ? $_COOKIE['password_correct_'.$client_id] : '';
242 $hash_pass = hash('sha256', wp_salt(32) . md5(isset($attributes['contentPassword']) ? $attributes['contentPassword'] : ''));
243
244 $content_protection_class = 'ep-content-protection-enabled';
245 if(empty($attributes['lockContent']) || empty($attributes['contentPassword']) || $hash_pass === $password_correct) {
246 $content_protection_class = 'ep-content-protection-disabled';
247 }
248
249 $aligns = [
250 'left' => 'alignleft',
251 'right' => 'alignright',
252 'wide' => 'alignwide',
253 'full' => 'alignfull',
254 'center' => 'aligncenter',
255 ];
256 if (isset($attributes['align'])) {
257 $alignment = isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] . ' clear' : '';
258 } else {
259 $alignment = 'aligncenter'; // default alignment is center in js, so keeping same here
260 }
261 $embed = Helper::customLogo($embed, $attributes);
262 $url = !empty($attributes['href']) ? $attributes['href'] : '';
263
264 $adsAtts = '';
265
266 if(!empty($attributes['adManager'])) {
267 $ad = base64_encode(json_encode($attributes));
268 $adsAtts = "data-sponsored-id=$client_id data-sponsored-attrs=$ad class=sponsored-mask";
269 }
270
271 $hosted_format = '';
272 if (!empty($custom_player)) {
273 $self_hosted = Helper::check_media_format($attributes['url']);
274 $hosted_format = isset($self_hosted['format']) ? $self_hosted['format'] : '';
275 }
276
277 $yt_channel_class = '';
278 if(Helper::is_youtube_channel($attributes['url'])){
279 $yt_channel_class = 'embedded-youtube-channel';
280 }
281
282 $autoPause = '';
283 if(!empty($attributes['autoPause'])){
284 $autoPause = ' enabled-auto-pause';
285 }
286
287 ob_start();
288 ?>
289 <div class="embedpress-gutenberg-wrapper <?php echo esc_attr( $alignment.' '.$content_share_class.' '.$share_position_class.' '.$content_protection_class); echo esc_attr( $cEmbedType ); ?>" id="<?php echo esc_attr($block_id); ?>">
290 <?php
291 $share_position = isset($attributes['sharePosition']) ? $attributes['sharePosition'] : 'right';
292 $custom_thumbnail = isset($attributes['customThumbnail']) ? $attributes['customThumbnail'] : '';
293 ?>
294 <div class="wp-block-embed__wrapper <?php if(!empty($attributes['contentShare'])) echo esc_attr( 'position-'.$share_position.'-wraper'); ?> <?php if($attributes['videosize'] == 'responsive') echo esc_attr( 'ep-video-responsive' ); ?>">
295 <div id="ep-gutenberg-content-<?php echo esc_attr( $client_id )?>" class="ep-gutenberg-content<?php echo esc_attr($autoPause); ?>">
296 <div
297 <?php echo esc_attr( $adsAtts ); ?> >
298 <div class="ep-embed-content-wraper <?php
299 if (!empty($custom_player)) {
300 echo esc_attr($player_preset);
301 }
302 echo esc_attr($instaLayout);
303 ?> <?php echo esc_attr($hosted_format); ?> <?php echo esc_attr($yt_channel_class); ?>"
304 <?php echo esc_attr($_custom_player); ?>
305 <?php echo esc_attr($_player_options); ?>
306 <?php echo esc_attr( $_carousel_id ); ?>
307 <?php echo esc_attr($_carousel_options); ?>
308 >
309 <?php
310 $hash_pass = hash('sha256', wp_salt(32) . md5($attributes['contentPassword']));
311 $password_correct = isset($_COOKIE['password_correct_'.$client_id]) ? $_COOKIE['password_correct_'.$client_id] : '';
312 if(empty($attributes['lockContent']) || empty($attributes['contentPassword']) || (!empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct)) ){
313
314 if(!empty($attributes['contentShare'])) {
315 $content_id = $attributes['clientId'];
316 $embed .= Helper::embed_content_share($content_id, $attributes);
317 }
318 echo $embed;
319 } else {
320 if(!empty($attributes['contentShare'])) {
321 $content_id = $attributes['clientId'];
322 $embed .= Helper::embed_content_share($content_id, $attributes);
323 }
324 do_action('embedpress/display_password_form', $client_id, $embed, $pass_hash_key, $attributes);
325
326 }
327 ?>
328 </div>
329 <?php
330 if(!empty($attributes['adManager'])) {
331 $embed = apply_filters('embedpress/generate_ad_template', $embed, $client_id, $attributes, 'gutenberg');
332
333 }
334 ?>
335 </div>
336 </div>
337 </div>
338 </div>
339 <?php
340
341 echo embedpress_render_block_style($attributes);
342
343
344 return ob_get_clean();
345
346
347 }
348 }
349
350 /**
351 * Make style function for embedpress render block
352 */
353
354 function embedpress_render_block_style($attributes)
355 {
356 $uniqid = !empty($attributes['url']) ? '.ose-uid-' . md5($attributes['url']) : '';
357 $client_id = !empty($attributes['clientId']) ? $attributes['clientId'] : '';
358
359 $custom_player = !empty($attributes['customPlayer']) ? $attributes['customPlayer'] : 0;
360 $player_color = !empty($attributes['playerColor']) ? $attributes['playerColor'] : '';
361 $player_pip = !empty($attributes['playerPip']) ? 'block' : 'none';
362 $logoX = !empty($attributes['logoX']) ? $attributes['logoX'] : 5;
363 $logoY = !empty($attributes['logoY']) ? $attributes['logoY'] : 10;
364 $logoOpacity = !empty($attributes['logoOpacity']) ? $attributes['logoOpacity'] : '1';
365 $player_pip = !empty($attributes['playerPip']) ? 'block' : 'none';
366
367 $playerStyle = '';
368
369 if (!empty($custom_player)) {
370 $playerStyle = '
371 [data-playerid="' . md5($client_id). '"] {
372 --plyr-color-main: ' . ($player_color && strlen($player_color) === 7
373 ? 'rgba(' . hexdec(substr($player_color, 1, 2)) . ', ' . hexdec(substr($player_color, 3, 2)) . ', ' . hexdec(substr($player_color, 5, 2)) . ', .8)!important;'
374 : 'rgba(0, 0, 0, .8)!important;'
375 ) . ';
376 }
377 [data-playerid="' . md5($client_id). '"].custom-player-preset-3, [data-playerid="' . md5($client_id). '"].custom-player-preset-4 {
378 --plyr-color-main: ' . ($player_color && strlen($player_color) === 7
379 ? 'rgb(' . hexdec(substr($player_color, 1, 2)) . ', ' . hexdec(substr($player_color, 3, 2)) . ', ' . hexdec(substr($player_color, 5, 2)) . ')!important;'
380 : 'rgba(0, 0, 0, .8)!important;'
381 ) . ';
382 }
383 [data-playerid="' . md5($client_id). '"] [data-plyr="pip"] {
384 display: '.$player_pip.';
385 }
386
387 [data-playerid="' . md5($client_id). '"] .plyr{
388 width: ' . esc_attr($attributes['width']) . 'px !important;
389 height: ' . esc_attr($attributes['height']) . 'px!important;
390 max-height: ' . esc_attr($attributes['height']) . 'px!important;
391 }
392 ';
393 }
394
395
396 $_iscustomlogo = '';
397
398 $youtubeStyles = '';
399
400 if(!empty($attributes['customlogo'])){
401 $_iscustomlogo = $uniqid.' img.watermark.ep-custom-logo {
402 display: block !important;
403 }
404
405
406 #ep-gutenberg-content-'. md5($client_id).' img.watermark {
407 border: 0;
408 position: absolute;
409 bottom: '.esc_attr($logoY).'%;
410 right: '.esc_attr($logoX).'%;
411 max-width: 150px;
412 max-height: 75px;
413 -o-transition: opacity 0.5s ease-in-out;
414 -moz-transition: opacity 0.5s ease-in-out;
415 -webkit-transition: opacity 0.5s ease-in-out;
416 transition: opacity 0.5s ease-in-out;
417 z-index:1;
418 opacity: '.esc_attr($logoOpacity).';
419 }
420 #ep-gutenberg-content-'. md5($client_id).' img.watermark:hover {
421 opacity: 1;
422 }
423 ';
424 }
425 $youtubeStyles = '<style>
426 .ose-youtube' . esc_attr($uniqid) . ' {
427 width: ' . esc_attr($attributes['width']) . 'px !important;
428 height: ' . esc_attr($attributes['height']) . 'px!important;
429 max-height: ' . esc_attr($attributes['height']) . 'px !important;
430 max-width: 100%;
431 }
432
433 .ose-youtube' . esc_attr($uniqid) . '>iframe {
434 height: ' . esc_attr($attributes['height']) . 'px !important;
435 max-height: ' . esc_attr($attributes['height']) . 'px !important;
436 width: 100%;
437 position: relative !important;
438 }
439
440
441 ' . esc_attr($uniqid) . ' .wistia_embed {
442 max-width: 100%;
443 }
444
445 .alignright .ose-wistia' . esc_attr($uniqid) .'{
446 margin-left: auto;
447 }
448 .alignleft .ose-wistia' . esc_attr($uniqid) .'{
449 margin-right: auto;
450 }
451 .aligncenter .ose-wistia' . esc_attr($uniqid) .'{
452 margin: auto;
453 }
454 '.$uniqid.' img.watermark{
455 display: none;
456 }
457 '.$_iscustomlogo.'
458 '.$playerStyle.'
459
460
461
462 </style>';
463
464 if($attributes['videosize'] == 'responsive') {
465
466 $width = isset($attributes['width']) ? $attributes['width'] : 600;
467 $height = $width * (9/16);
468
469
470 $youtubeStyles = '<style>
471 .ose-youtube' . esc_attr($uniqid) . ' {
472 position: relative;
473 width: ' . esc_attr($attributes['width']) . 'px !important;
474 height: ' . esc_attr($height) . 'px !important;
475 max-width: 100%;
476 }
477
478 .ose-wistia{
479 height: auto !important;
480 padding-top: 0;
481 }
482
483 .ose-youtube' . esc_attr($uniqid) . ' > iframe {
484 width: 100%;
485 height: 100%;
486 max-height:100%;
487 }
488
489 .ep-video-responsive{
490 display: inline-block!important;
491 max-width: 100%;
492 }
493 '.$uniqid.' img.watermark{
494 display: none;
495 }
496 '.$_iscustomlogo.'
497 '.$playerStyle.'
498
499 </style>';
500 }
501
502 $youtubeStyles .= '<style>
503 .ose-matterport' . esc_attr($uniqid) . ' {
504 position: relative;
505 width: ' . esc_attr($attributes['width']) . 'px !important;
506 height: ' . esc_attr($attributes['height']) . 'px !important;
507 max-width: 100%;
508 }
509 .ose-giphy' . esc_attr($uniqid) . ' img{
510 position: relative;
511 width: ' . esc_attr($attributes['width']) . 'px !important;
512 height: ' . esc_attr($attributes['height']) . 'px !important;
513 max-width: 100%;
514 }
515
516
517
518 </style>';
519
520
521
522 return $youtubeStyles;
523 }
524 ?>
525