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