PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 3.8.1
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v3.8.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 3 years ago block-wistia.php 5 years ago block-youtube.php 3 years ago
block-embedpress.php
368 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']) ? $_POST['client_id'] : '';
22 $password = isset($_POST['password']) ? $_POST['password'] : '';
23 $epbase64 = isset($_POST['epbase']) ? $_POST['epbase'] : '';
24 $hash_key = isset($_POST['hash_key']) ? $_POST['hash_key'] : '';
25
26 // echo $client_id;
27
28
29 // Set the decryption key and initialization vector (IV)
30 $key = Helper::get_hash();
31
32 // Decode the base64 encoded cipher
33 $cipher = base64_decode($epbase64);
34 // Decrypt the cipher using AES-128-CBC encryption
35
36 $wp_pass_key = hash('sha256', wp_salt(32) . md5($password));
37 $iv = substr($wp_pass_key, 0, 16);
38
39 if ($wp_pass_key === $hash_key) {
40 setcookie("password_correct_", $password, time()+3600);
41
42 $embed = openssl_decrypt($cipher, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $iv) . '<script>
43 var now = new Date();
44 var time = now.getTime();
45 var expireTime = time + 1000 * 60 * 60 * 24 * 30;
46 now.setTime(expireTime);
47 document.cookie = "password_correct_'.$client_id.'='.$hash_key.'; expires=" + now.toUTCString() + "; path=/";
48 </script>';
49
50 }
51 else{
52 $embed = 0;
53 }
54
55 // Process the form data and return a response
56 $response = array(
57 'success' => true,
58 'password' => $password,
59 'embedHtml' => $embed
60 );
61
62 echo json_encode($response);
63
64 wp_die();
65 }
66 }
67
68
69 function embedpress_render_block($attributes)
70 {
71
72 $client_id = !empty($attributes['clientId']) ? md5($attributes['clientId']) : '';
73 $block_id = !empty($attributes['clientId']) ? $attributes['clientId'] : '';
74 $custom_player = !empty($attributes['customPlayer']) ? $attributes['customPlayer'] : 0;
75
76
77 $_custom_player = '';
78 $_player_options = '';
79
80 if (!empty($custom_player)) {
81
82 $is_self_hosted = Helper::check_media_format($attributes['url']);
83
84
85 $_custom_player = 'data-playerid="' . esc_attr($client_id) . '"';
86 $player_preset = !empty($attributes['playerPreset']) ? $attributes['playerPreset'] : 'preset-default';
87 $player_color = !empty($attributes['playerColor']) ? $attributes['playerColor'] : '';
88 $poster_thumbnail = !empty($attributes['posterThumbnail']) ? $attributes['posterThumbnail'] : '';
89 $player_pip = !empty($attributes['playerPip']) ? true : false;
90 $player_restart = !empty($attributes['playerRestart']) ? true : false;
91 $player_rewind = !empty($attributes['playerRewind']) ? true : false;
92 $player_fastForward = !empty($attributes['playerFastForward']) ? true : false;
93 $player_tooltip = !empty($attributes['playerTooltip']) ? true : false;
94 $player_hide_controls = !empty($attributes['playerHideControls']) ? true : false;
95 $player_download = !empty($attributes['playerDownload']) ? true : false;
96
97 $playerOptions = [
98 'rewind' => $player_rewind,
99 'restart' => $player_restart,
100 'pip' => $player_pip,
101 'poster_thumbnail' => $poster_thumbnail,
102 'player_color' => $player_color,
103 'player_preset' => $player_preset,
104 'fast_forward' => $player_fastForward,
105 'player_tooltip' => $player_tooltip,
106 'hide_controls' => $player_hide_controls,
107 'download' => $player_download,
108 ];
109
110 if(!empty($attributes['fullscreen'])){
111 $playerOptions['fullscreen'] = $attributes['fullscreen'];
112 }
113
114 if(!empty($is_self_hosted['selhosted'])){
115 $playerOptions['self_hosted'] = $is_self_hosted['selhosted'];
116 $playerOptions['hosted_format'] = $is_self_hosted['format'];
117 }
118
119 //Youtube options
120 if(!empty($attributes['starttime'])){
121 $playerOptions['start'] = $attributes['starttime'];
122 }
123 if(!empty($attributes['endtime'])){
124 $playerOptions['end'] = $attributes['endtime'];
125 }
126 if(!empty($attributes['relatedvideos'])){
127 $playerOptions['rel'] = $attributes['relatedvideos'];
128 }
129
130 //vimeo options
131 if(!empty($attributes['vstarttime'])){
132 $playerOptions['t'] = $attributes['vstarttime'];
133 }
134 if(!empty($attributes['vautoplay'])){
135 $playerOptions['vautoplay'] = $attributes['vautoplay'];
136 }
137 if(!empty($attributes['vautopause'])){
138 $playerOptions['autopause'] = $attributes['vautopause'];
139 }
140 if(!empty($attributes['vdnt'])){
141 $playerOptions['dnt'] = $attributes['vdnt'];
142 }
143
144 $playerOptionsString = json_encode($playerOptions);
145 $_player_options = 'data-options=\'' . htmlentities($playerOptionsString, ENT_QUOTES) . '\'';
146 }
147
148 $pass_hash_key = isset($attributes['contentPassword']) ? md5($attributes['contentPassword']): '';
149
150 if (!empty($attributes['embedHTML'])) {
151 $embed = apply_filters('embedpress_gutenberg_embed', $attributes['embedHTML'], $attributes);
152
153 $content_share_class = '';
154 $share_position_class = '';
155 $share_position = isset($attributes['sharePosition']) ? $attributes['sharePosition'] : 'right';
156
157 if(!empty($attributes['contentShare'])) {
158 $content_share_class = 'ep-content-share-enabled';
159 $share_position_class = 'ep-share-position-'.$share_position;
160 }
161 $content_protection_class = '';
162 if(!empty($attributes['lockContent']) && !empty($attributes['contentPassword'])) {
163 $content_protection_class = 'ep-content-protection-enabled';
164 }
165
166 $aligns = [
167 'left' => 'alignleft',
168 'right' => 'alignright',
169 'wide' => 'alignwide',
170 'full' => 'alignfull',
171 'center' => 'aligncenter',
172 ];
173 if (isset($attributes['align'])) {
174 $alignment = isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] . ' clear' : '';
175 } else {
176 $alignment = 'aligncenter'; // default alignment is center in js, so keeping same here
177 }
178 $embed = Helper::customLogo($embed, $attributes);
179 $url = !empty($attributes['href']) ? $attributes['href'] : '';
180
181 ob_start();
182 ?>
183 <div class="embedpress-gutenberg-wrapper <?php echo esc_attr( $alignment.' '.$content_share_class.' '.$share_position_class.' '.$content_protection_class); ?>" id="<?php echo esc_attr($block_id); ?>">
184 <?php
185 $share_position = isset($attributes['sharePosition']) ? $attributes['sharePosition'] : 'right';
186 $custom_thumbnail = isset($attributes['customThumbnail']) ? $attributes['customThumbnail'] : '';
187 ?>
188 <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' ); ?>">
189 <div id="ep-gutenberg-content-<?php echo esc_attr( $client_id )?>" class="ep-gutenberg-content">
190 <div class="ep-embed-content-wraper <?php !empty($custom_player) ? esc_attr_e($player_preset) : ''; ?>" <?php echo $_custom_player; ?> <?php echo $_player_options; ?>>
191 <?php
192 $hash_pass = hash('sha256', wp_salt(32) . md5($attributes['contentPassword']));
193 $password_correct = isset($_COOKIE['password_correct_'.$client_id]) ? $_COOKIE['password_correct_'.$client_id] : '';
194 if(empty($attributes['lockContent']) || empty($attributes['contentPassword']) || (!empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct)) ){
195
196 if(!empty($attributes['contentShare'])) {
197 $content_id = $attributes['clientId'];
198 $embed .= Helper::embed_content_share($content_id, $attributes);
199 }
200 echo $embed;
201 } else {
202 if(!empty($attributes['contentShare'])) {
203 $content_id = $attributes['clientId'];
204 $embed .= Helper::embed_content_share($content_id, $attributes);
205 }
206 Helper::display_password_form($client_id, $embed, $pass_hash_key, $attributes);
207 }
208 ?>
209 </div>
210 </div>
211 </div>
212 </div>
213 <?php
214
215 echo embedpress_render_block_style($attributes);
216
217
218 return ob_get_clean();
219
220
221 }
222 }
223
224 /**
225 * Make style function for embedpress render block
226 */
227
228 function embedpress_render_block_style($attributes)
229 {
230
231 $uniqid = !empty($attributes['url']) ? '.ose-uid-' . md5($attributes['url']) : '';
232 $client_id = !empty($attributes['clientId']) ? $attributes['clientId'] : '';
233
234 $custom_player = !empty($attributes['customPlayer']) ? $attributes['customPlayer'] : 0;
235 $player_color = !empty($attributes['playerColor']) ? $attributes['playerColor'] : '';
236 $player_pip = !empty($attributes['playerPip']) ? 'block' : 'none';
237 $logoX = !empty($attributes['logoX']) ? $attributes['logoX'] : 5;
238 $logoY = !empty($attributes['logoY']) ? $attributes['logoX'] : 10;
239 $player_pip = !empty($attributes['playerPip']) ? 'block' : 'none';
240
241 $playerStyle = '';
242
243 if (!empty($custom_player)) {
244 $playerStyle = '
245 [data-playerid="' . md5($client_id). '"] {
246 --plyr-color-main: ' . ($player_color && strlen($player_color) === 7
247 ? 'rgba(' . hexdec(substr($player_color, 1, 2)) . ', ' . hexdec(substr($player_color, 3, 2)) . ', ' . hexdec(substr($player_color, 5, 2)) . ', .8)!important;'
248 : 'rgba(0, 0, 0, .8)!important;'
249 ) . ';
250 }
251 [data-playerid="' . md5($client_id). '"].custom-player-preset-3, [data-playerid="' . md5($client_id). '"].custom-player-preset-4 {
252 --plyr-color-main: ' . ($player_color && strlen($player_color) === 7
253 ? 'rgb(' . hexdec(substr($player_color, 1, 2)) . ', ' . hexdec(substr($player_color, 3, 2)) . ', ' . hexdec(substr($player_color, 5, 2)) . ')!important;'
254 : 'rgba(0, 0, 0, .8)!important;'
255 ) . ';
256 }
257 [data-playerid="' . md5($client_id). '"] [data-plyr="pip"] {
258 display: '.$player_pip.';
259 }
260
261 [data-playerid="' . md5($client_id). '"] .plyr{
262 width: ' . esc_attr($attributes['width']) . 'px !important;
263 height: ' . esc_attr($attributes['height']) . 'px!important;
264 max-height: ' . esc_attr($attributes['height']) . 'px!important;
265 }
266
267 [data-playerid="' . md5($client_id). '"] img.watermark {
268 border: 0;
269 position: absolute;
270 bottom: '.$logoY.'%;
271 right: '.$logoX.'%;
272 max-width: 150px;
273 max-height: 75px;
274 opacity: 1;
275 -o-transition: opacity 0.5s ease-in-out;
276 -moz-transition: opacity 0.5s ease-in-out;
277 -webkit-transition: opacity 0.5s ease-in-out;
278 transition: opacity 0.5s ease-in-out;
279 z-index:1;
280 }
281
282 ';
283 }
284
285
286 $_iscustomlogo = '';
287
288 if(!empty($attributes['customlogo'])){
289 $_iscustomlogo = $uniqid.' img.watermark.ep-custom-logo {
290 display: block !important;
291 }';
292 }
293 $youtubeStyles = '<style>
294 ' . esc_attr($uniqid) . ' {
295 width: ' . esc_attr($attributes['width']) . 'px !important;
296 height: ' . esc_attr($attributes['height']) . 'px;
297 max-width: 100%;
298 }
299
300 ' . esc_attr($uniqid) . '>iframe {
301 height: ' . esc_attr($attributes['height']) . 'px !important;
302 max-height: ' . esc_attr($attributes['height']) . 'px !important;
303 width: 100%;
304 }
305
306 ' . esc_attr($uniqid) . ' .wistia_embed {
307 max-width: 100%;
308 }
309
310 .alignright .ose-wistia' . esc_attr($uniqid) .'{
311 margin-left: auto;
312 }
313 .alignleft .ose-wistia' . esc_attr($uniqid) .'{
314 margin-right: auto;
315 }
316 .aligncenter .ose-wistia' . esc_attr($uniqid) .'{
317 margin: auto;
318 }
319 '.$uniqid.' img.watermark{
320 display: none;
321 }
322 '.$_iscustomlogo.'
323 '.$playerStyle.'
324
325 </style>';
326
327 if($attributes['videosize'] == 'responsive') {
328
329 $width = isset($attributes['width']) ? $attributes['width'] : 600;
330 $height = $width * (9/16);
331
332
333 $youtubeStyles = '<style>
334 ' . esc_attr($uniqid) . ' {
335 position: relative;
336 width: ' . esc_attr($attributes['width']) . 'px !important;
337 height: ' . esc_attr($height) . 'px !important;
338 max-width: 100%;
339 }
340
341 .ose-wistia{
342 height: auto !important;
343 padding-top: 0;
344 }
345
346 ' . esc_attr($uniqid) . ' > iframe {
347 width: 100%;
348 height: 100%;
349 max-height:100%;
350 }
351
352 .ep-video-responsive{
353 display: inline-block!important;
354 max-width: 100%;
355 }
356 '.$uniqid.' img.watermark{
357 display: none;
358 }
359 '.$_iscustomlogo.'
360 '.$playerStyle.'
361
362 </style>';
363 }
364
365 return $youtubeStyles;
366 }
367 ?>
368