PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 3.9.16
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v3.9.16
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 / plugin.php
embedpress / Gutenberg Last commit date
block-backend 2 years ago dist 2 years ago plugin.php 2 years ago
plugin.php
914 lines
1 <?php
2
3 /**
4 * Blocks Initializer
5 *
6 * Enqueue CSS/JS of all the blocks.
7 *
8 * @since 1.0.0
9 * @package CGB
10 */
11
12 // Exit if accessed directly.
13 use EmbedPress\Includes\Classes\Helper;
14
15 if (!defined('ABSPATH')) {
16 exit;
17 }
18
19
20 /**
21 * Enqueue Gutenberg block assets for both frontend + backend.
22 *
23 * @uses {wp-editor} for WP editor styles.
24 * @since 1.0.0
25 */
26 function embedpress_blocks_cgb_block_assets()
27 { // phpcs:ignore
28 // Styles.
29 wp_enqueue_style(
30 'embedpress_blocks-cgb-style-css', // Handle.
31 EMBEDPRESS_GUTENBERG_DIR_URL . 'dist/blocks.style.build.css', // Block style CSS.
32 is_admin() ? array('wp-editor') : null, // Dependency to include the CSS after it.
33 filemtime(EMBEDPRESS_GUTENBERG_DIR_PATH . 'dist/blocks.style.build.css') // Version: File modification time.
34 );
35 }
36
37 // Hook: Frontend assets.
38 add_action('enqueue_block_assets', 'embedpress_blocks_cgb_block_assets');
39
40 /**
41 * Enqueue Gutenberg block assets for backend editor.
42 *
43 * @uses {wp-blocks} for block type registration & related functions.
44 * @uses {wp-element} for WP Element abstraction — structure of blocks.
45 * @uses {wp-i18n} to internationalize the block's text.
46 * @uses {wp-editor} for WP editor styles.
47 * @since 1.0.0
48 */
49
50 function embedpress_blocks_cgb_editor_assets()
51 { // phpcs:ignore
52 // Scripts.
53
54 $elements = (array) get_option(EMBEDPRESS_PLG_NAME . ":elements", []);
55 $g_blocks = isset($elements['gutenberg']) ? (array) $elements['gutenberg'] : [];
56
57 if (!wp_script_is('embedpress-pdfobject')) {
58 wp_enqueue_script(
59 'embedpress-pdfobject',
60 EMBEDPRESS_URL_ASSETS . 'js/pdfobject.min.js',
61 [],
62 EMBEDPRESS_VERSION
63 );
64 }
65
66 wp_enqueue_script(
67 'embedpress_blocks-cgb-block-js', // Handle.
68 EMBEDPRESS_GUTENBERG_DIR_URL . 'dist/blocks.build.js', // Block.build.js: We register the block here. Built with Webpack.
69 array('wp-blocks', 'wp-i18n', 'wp-element', 'wp-api-fetch', 'wp-is-shallow-equal', 'wp-editor', 'wp-components', 'embedpress-pdfobject'), // Dependencies, defined above.
70 filemtime(EMBEDPRESS_GUTENBERG_DIR_PATH . 'dist/blocks.build.js'), // Version: File modification time.
71 true // Enqueue the script in the footer.
72 );
73
74 if (!empty($g_blocks['document'])) {
75 wp_enqueue_script(
76 'embedpress_documents_viewer_script',
77 EMBEDPRESS_PLUGIN_DIR_URL . 'assets/js/documents-viewer-script.js',
78 array('wp-blocks', 'wp-dom-ready', 'wp-edit-post'),
79 EMBEDPRESS_PLUGIN_VERSION,
80 true
81 );
82 }
83
84 $wistia_labels = array(
85 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'),
86 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'),
87 'you_have_watched_it_before' => __('It looks like you\'ve watched<br />part of this video before!', 'embedpress'),
88 );
89 $elements = (array) get_option(EMBEDPRESS_PLG_NAME . ":elements", []);
90 $active_blocks = isset($elements['gutenberg']) ? (array) $elements['gutenberg'] : [];
91
92 $wistia_labels = json_encode($wistia_labels);
93 $wistia_options = null;
94 if (function_exists('embedpress_wisita_pro_get_options')) :
95 $wistia_options = embedpress_wisita_pro_get_options();
96 endif;
97 $pars_url = wp_parse_url(get_site_url());
98 $documents_cta_options = (array) get_option(EMBEDPRESS_PLG_NAME . ':document');
99 wp_localize_script('embedpress_blocks-cgb-block-js', 'embedpressObj', array(
100 'wistia_labels' => $wistia_labels,
101 'wisita_options' => $wistia_options,
102 'embedpress_powered_by' => apply_filters('embedpress_document_block_powered_by', true),
103 'embedpress_pro' => defined('EMBEDPRESS_PRO_PLUGIN_FILE'),
104 'twitch_host' => !empty($pars_url['host']) ? $pars_url['host'] : '',
105 'site_url' => site_url(),
106 'active_blocks' => $active_blocks,
107 'document_cta' => $documents_cta_options,
108 'pdf_renderer' => Helper::get_pdf_renderer(),
109 'is_pro_plugin_active' => defined('EMBEDPRESS_SL_ITEM_SLUG'),
110 'ajaxurl' => admin_url('admin-ajax.php'),
111 'source_nonce' => wp_create_nonce('source_nonce_embedpress'),
112 'can_upload_media' => current_user_can('upload_files')
113
114 ));
115
116 // Styles.
117 wp_enqueue_style(
118 'embedpress_blocks-cgb-block-editor-css', // Handle.
119 EMBEDPRESS_GUTENBERG_DIR_URL . 'dist/blocks.editor.build.css', // Block editor CSS.
120 array('wp-edit-blocks'), // Dependency to include the CSS after it.
121 filemtime(EMBEDPRESS_GUTENBERG_DIR_PATH . 'dist/blocks.editor.build.css') // Version: File modification time.
122 );
123 }
124
125 // Hook: Editor assets.
126 add_action('enqueue_block_editor_assets', 'embedpress_blocks_cgb_editor_assets');
127
128
129 function embedpress_block_category($categories, $post)
130 {
131 return array_merge(
132 $categories,
133 array(
134 array(
135 'slug' => 'embedpress',
136 'title' => 'EmbedPress',
137 'icon' => '',
138 ),
139 )
140 );
141 }
142 $wp_version = get_bloginfo('version', 'display');
143 if (version_compare($wp_version, '5.8', '>=')) {
144 add_filter('block_categories_all', 'embedpress_block_category', 10, 2);
145 } else {
146 add_filter('block_categories', 'embedpress_block_category', 10, 2);
147 }
148
149
150
151
152 foreach (glob(EMBEDPRESS_GUTENBERG_DIR_PATH . 'block-backend/*.php') as $block_logic) {
153 require_once $block_logic;
154 }
155
156 /**
157 * Registers the embedpress gutneberg block on server.
158 */
159
160 function embedpress_gutenberg_register_all_block()
161 {
162 if (function_exists('register_block_type')) :
163
164 $elements = (array) get_option(EMBEDPRESS_PLG_NAME . ":elements", []);
165 $g_blocks = isset($elements['gutenberg']) ? (array) $elements['gutenberg'] : [];
166 $blocks_to_registers = ['twitch-block', 'google-slides-block', 'google-sheets-block', 'google-maps-block', 'google-forms-block', 'google-drawings-block', 'google-docs-block', 'embedpress', 'embedpress-pdf', 'embedpress-calendar', 'document'];
167
168 foreach ($blocks_to_registers as $blocks_to_register) {
169 if (!empty($g_blocks[$blocks_to_register])) {
170 if ('embedpress' === $blocks_to_register) {
171 register_block_type('embedpress/embedpress', [
172 'render_callback' => 'embedpress_render_block',
173 'attributes' => array(
174 'clientId' => [
175 'type' => 'string',
176 ],
177 'height' => [
178 'type' => 'string',
179 'default' => '450'
180 ],
181 'width' => [
182 'type' => 'string',
183 'default' => '600'
184 ],
185 'lockContent' => [
186 'type' => 'boolean',
187 'default' => false
188 ],
189 'lockHeading' => [
190 'type' => 'string',
191 'default' => 'Content Locked'
192 ],
193 'lockSubHeading' => [
194 'type' => 'string',
195 'default' => 'Content is locked and requires password to access it.'
196 ],
197 'lockErrorMessage' => [
198 'type' => 'string',
199 'default' => 'Oops, that wasn\'t the right password. Try again.'
200 ],
201 'passwordPlaceholder' => [
202 'type' => 'string',
203 'default' => 'Password'
204 ],
205 'submitButtonText' => [
206 'type' => 'string',
207 'default' => 'Unlock'
208 ],
209 'submitUnlockingText' => [
210 'type' => 'string',
211 'default' => 'Unlocking'
212 ],
213 'enableFooterMessage' => [
214 'type' => 'boolean',
215 'default' => false
216 ],
217 'footerMessage' => [
218 'type' => 'string',
219 'default' => 'In case you don\'t have the password, kindly reach out to content owner or administrator to request access.'
220 ],
221 'contentPassword' => [
222 'type' => 'string',
223 'default' => '',
224 ],
225 'contentShare' => [
226 'type' => 'boolean',
227 'default' => false
228 ],
229 'sharePosition' => [
230 'type' => 'string',
231 'default' => 'right'
232 ],
233 'customTitle' => [
234 'type' => 'string',
235 'default' => ''
236 ],
237 'customDescription' => [
238 'type' => 'string',
239 'default' => ''
240 ],
241 'customThumbnail' => [
242 'type' => 'string',
243 'default' => ''
244 ],
245
246 'videosize' => [
247 'type' => 'string',
248 'default' => 'fixed'
249 ],
250
251 'loadmore' => [
252 'type' => 'boolean',
253 'default' => false
254 ],
255 //Youtube Attributes
256 'starttime' => [
257 'type' => 'string',
258 ],
259 'endtime' => [
260 'type' => 'string',
261 ],
262 'autoplay' => [
263 'type' => 'boolean',
264 'default' => false
265 ],
266 'controls' => [
267 'type' => 'string',
268 ],
269 'progressbarcolor' => [
270 'type' => 'string',
271 ],
272 'videoannotations' => [
273 'type' => 'string',
274 ],
275 'closedcaptions' => [
276 'type' => 'boolean',
277 'default' => true
278 ],
279 'relatedvideos' => [
280 'type' => 'boolean',
281 'default' => true
282 ],
283 'fullscreen' => [
284 'type' => 'boolean',
285 'default' => true
286 ],
287
288 'modestbranding' => [
289 'type' => 'string',
290 ],
291 // custom player attributes
292 'customPlayer' => [
293 'type' => 'boolean',
294 'default' => false
295 ],
296
297 'posterThumbnail' => [
298 'type' => 'string',
299 'default' => ''
300 ],
301
302 'playerPreset' => [
303 'type' => 'string',
304 'default' => ''
305 ],
306
307 'playerColor' => [
308 'type' => 'string',
309 'default' => '#2e2e99'
310 ],
311
312 'playerPip' => [
313 'type' => 'boolean',
314 'default' => false
315 ],
316
317 'playerRestart' => [
318 'type' => 'boolean',
319 'default' => true
320 ],
321
322 'playerRewind' => [
323 'type' => 'boolean',
324 'default' => true
325 ],
326
327 'playerFastForward' => [
328 'type' => 'boolean',
329 'default' => true
330 ],
331 'playerTooltip' => [
332 'type' => 'boolean',
333 'default' => true
334 ],
335 'playerHideControls' => [
336 'type' => 'boolean',
337 'default' => true
338 ],
339 'playerDownload' => [
340 'type' => 'boolean',
341 'default' => true
342 ],
343 //Wistia Attributes
344 'wstarttime' => [
345 'type' => 'string',
346 ],
347 'wautoplay' => [
348 'type' => 'boolean',
349 'default' => true
350 ],
351 'scheme' => [
352 'type' => 'string',
353 ],
354 'captions' => [
355 'type' => 'boolean',
356 'default' => true
357 ],
358 'playbutton' => [
359 'type' => 'boolean',
360 'default' => true
361 ],
362 'smallplaybutton' => [
363 'type' => 'boolean',
364 'default' => true
365 ],
366 'playbar' => [
367 'type' => 'boolean',
368 'default' => true
369 ],
370 'resumable' => [
371 'type' => 'boolean',
372 'default' => true
373 ],
374 'wistiafocus' => [
375 'type' => 'boolean',
376 'default' => true
377 ],
378 'volumecontrol' => [
379 'type' => 'boolean',
380 'default' => true
381 ],
382 'volume' => [
383 'type' => 'number',
384 'default' => 100
385 ],
386 'rewind' => [
387 'type' => 'boolean',
388 'default' => false
389 ],
390 'wfullscreen' => [
391 'type' => 'boolean',
392 'default' => true
393 ],
394
395 // Vimeo attributes
396 'vstarttime' => [
397 'type' => 'string',
398 ],
399 'vautoplay' => [
400 'type' => 'boolean',
401 'default' => false
402 ],
403 'vscheme' => [
404 'type' => 'string',
405 ],
406 'vtitle' => [
407 'type' => 'boolean',
408 'default' => true
409 ],
410 'vauthor' => [
411 'type' => 'boolean',
412 'default' => true
413 ],
414 'vavatar' => [
415 'type' => 'boolean',
416 'default' => true
417 ],
418 'vloop' => [
419 'type' => 'boolean',
420 'default' => false
421 ],
422 'vautopause' => [
423 'type' => 'boolean',
424 'default' => false
425 ],
426 'vdnt' => [
427 'type' => 'boolean',
428 'default' => false
429 ],
430
431 // Calendly attributes
432 'cEmbedType' => array(
433 'type' => 'string',
434 'default' => 'inline'
435 ),
436 'calendlyData' => array(
437 'type' => 'boolean',
438 'default' => false
439 ),
440 'hideCookieBanner' => array(
441 'type' => 'boolean',
442 'default' => false
443 ),
444 'hideEventTypeDetails' => array(
445 'type' => 'boolean',
446 'default' => false
447 ),
448 'cBackgroundColor' => array(
449 'type' => 'string',
450 'default' => 'ffffff'
451 ),
452 'cTextColor' => array(
453 'type' => 'string',
454 'default' => '1A1A1A'
455 ),
456 'cButtonLinkColor' => array(
457 'type' => 'string',
458 'default' => '0000FF'
459 ),
460 'cPopupButtonText' => array(
461 'type' => 'string',
462 'default' => 'Schedule time with me'
463 ),
464 'cPopupButtonBGColor' => array(
465 'type' => 'string',
466 'default' => '#0000FF'
467 ),
468 'cPopupButtonTextColor' => array(
469 'type' => 'string',
470 'default' => '#FFFFFF'
471 ),
472 'cPopupLinkText' => array(
473 'type' => 'string',
474 'default' => 'Schedule time with me'
475 ),
476
477 //Ad attributes
478 'adManager' => [
479 'type' => 'boolean',
480 'default' => false
481 ],
482 'adSource' => [
483 'type' => 'string',
484 'default' => 'video'
485 ],
486 'adContent' => [
487 'type' => 'object',
488 ],
489 'adWidth' => array(
490 'type' => 'string',
491 'default' => '300'
492 ),
493 'adHeight' => array(
494 'type' => 'string',
495 'default' => '200'
496 ),
497 'adXPosition' => array(
498 'type' => 'number',
499 'default' => 25
500 ),
501 'adYPosition' => array(
502 'type' => 'number',
503 'default' => 10
504 ),
505 'adUrl' => [
506 'type' => 'string',
507 'default' => ''
508 ],
509 'adStart' => [
510 'type' => 'string',
511 'default' => '10'
512 ],
513 'adSkipButton' => [
514 'type' => 'boolean',
515 'default' => true
516 ],
517 'adSkipButtonAfter' => [
518 'type' => 'string',
519 'default' => '5'
520 ]
521
522 ),
523 ]);
524 } elseif ('embedpress-pdf' === $blocks_to_register) {
525 register_block_type('embedpress/embedpress-pdf', [
526 'attributes' => array(
527 'powered_by' => [
528 'type' => 'boolean',
529 'default' => true
530 ],
531 'lockContent' => [
532 'type' => 'boolean',
533 'default' => false
534 ],
535 'lockHeading' => [
536 'type' => 'string',
537 'default' => 'Content Locked'
538 ],
539 'lockSubHeading' => [
540 'type' => 'string',
541 'default' => 'Content is locked and requires password to access it.'
542 ],
543 'passwordPlaceholder' => [
544 'type' => 'string',
545 'default' => 'Password'
546 ],
547 'submitButtonText' => [
548 'type' => 'string',
549 'default' => 'Unlock'
550 ],
551 'submitUnlockingText' => [
552 'type' => 'string',
553 'default' => 'Unlocking'
554 ],
555 'lockErrorMessage' => [
556 'type' => 'string',
557 'default' => 'Oops, that wasn\'t the right password. Try again.'
558 ],
559 'enableFooterMessage' => [
560 'type' => 'boolean',
561 'default' => false
562 ],
563 'footerMessage' => [
564 'type' => 'string',
565 'default' => 'In case you don\'t have the password, kindly reach out to content owner or administrator to request access.'
566 ],
567 'contentPassword' => [
568 'type' => 'string',
569 'default' => ''
570 ],
571 'contentShare' => [
572 'type' => 'boolean',
573 'default' => false
574 ],
575 'sharePosition' => [
576 'type' => 'string',
577 'default' => 'right'
578 ],
579 'presentation' => [
580 'type' => "boolean",
581 'default' => true,
582 ],
583
584 'position' => [
585 'type' => "string",
586 'default' => 'top',
587 ],
588
589 'print' => [
590 'type' => "boolean",
591 'default' => true,
592 ],
593
594 'download' => [
595 'type' => "boolean",
596 'default' => true,
597 ],
598 'open' => [
599 'type' => "boolean",
600 'default' => true,
601 ],
602 'copy_text' => [
603 'type' => "boolean",
604 'default' => true,
605 ],
606 'add_text' => [
607 'type' => "boolean",
608 'default' => true,
609 ],
610 'draw' => [
611 'type' => "boolean",
612 'default' => true,
613 ],
614 'toolbar' => [
615 'type' => "boolean",
616 'default' => true,
617 ],
618 'doc_details' => [
619 'type' => "boolean",
620 'default' => true,
621 ],
622 'doc_rotation' => [
623 'type' => "boolean",
624 'default' => true,
625 ],
626 'unitoption' => [
627 'type' => "string",
628 'default' => '%',
629 ],
630
631 //Ad attributes
632 'adManager' => [
633 'type' => 'boolean',
634 'default' => false
635 ],
636 'adSource' => [
637 'type' => 'string',
638 'default' => 'video'
639 ],
640 'adContent' => [
641 'type' => 'object',
642 ],
643 'adWidth' => array(
644 'type' => 'string',
645 'default' => '300'
646 ),
647 'adHeight' => array(
648 'type' => 'string',
649 'default' => '200'
650 ),
651 'adXPosition' => array(
652 'type' => 'number',
653 'default' => 25
654 ),
655 'adYPosition' => array(
656 'type' => 'number',
657 'default' => 20
658 ),
659 'adUrl' => [
660 'type' => 'string',
661 'default' => ''
662 ],
663 'adStart' => [
664 'type' => 'string',
665 'default' => '10'
666 ],
667 'adSkipButton' => [
668 'type' => 'boolean',
669 'default' => true
670 ],
671 'adSkipButtonAfter' => [
672 'type' => 'string',
673 'default' => '5'
674 ]
675 ),
676 'render_callback' => 'embedpress_pdf_render_block',
677 ]);
678 } elseif ('embedpress-calendar' === $blocks_to_register) {
679 register_block_type('embedpress/embedpress-calendar', [
680 'render_callback' => 'embedpress_calendar_render_block',
681 ]);
682 } else {
683 register_block_type('embedpress/' . $blocks_to_register);
684 }
685 } else {
686
687 if (WP_Block_Type_Registry::get_instance()->is_registered('embedpress/' . $blocks_to_register)) {
688 unregister_block_type('embedpress/' . $blocks_to_register);
689 }
690 }
691 }
692
693 endif;
694 }
695
696 add_action('init', 'embedpress_gutenberg_register_all_block');
697
698 function getParamData($attributes)
699 {
700
701 $urlParamData = array(
702 'themeMode' => !empty($attributes['themeMode']) ? $attributes['themeMode'] : 'default',
703 'toolbar' => !empty($attributes['toolbar']) ? 'true' : 'false',
704 'position' => $attributes['position'],
705 'presentation' => !empty($attributes['presentation']) ? 'true' : 'false',
706 'download' => !empty($attributes['download']) ? 'true' : 'false',
707 'copy_text' => !empty($attributes['copy_text']) ? 'true' : 'false',
708 'add_text' => !empty($attributes['add_text']) ? 'true' : 'false',
709 'draw' => !empty($attributes['draw']) ? 'true' : 'false',
710 'doc_rotation' => !empty($attributes['doc_rotation']) ? 'true' : 'false',
711 'doc_details' => !empty($attributes['doc_details']) ? 'true' : 'false',
712 );
713
714 if ($urlParamData['themeMode'] == 'custom') {
715 $urlParamData['customColor'] = !empty($attributes['customColor']) ? $attributes['customColor'] : '#403A81';
716 }
717
718 return "#key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), 'UTF-8'));
719 }
720
721 function embedpress_pdf_render_block($attributes)
722 {
723
724
725 if (!empty($attributes['href'])) {
726 $renderer = Helper::get_pdf_renderer();
727 $pdf_url = $attributes['href'];
728 $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-pdf-' . rand(100, 10000);
729 $client_id = md5($id);
730
731
732 $unitoption = !empty($attributes['unitoption']) ? $attributes['unitoption'] : 'px';
733 $width = !empty($attributes['width']) ? $attributes['width'] . $unitoption : '600px';
734
735 if ($unitoption == '%') {
736 $width_class = ' ep-percentage-width';
737 } else {
738 $width_class = 'ep-fixed-width';
739 }
740 $content_share_class = '';
741 $share_position_class = '';
742 $share_position = isset($attributes['sharePosition']) ? $attributes['sharePosition'] : 'right';
743
744 if (!empty($attributes['contentShare'])) {
745 $content_share_class = 'ep-content-share-enabled';
746 $share_position_class = 'ep-share-position-' . $share_position;
747 }
748
749 $password_correct = isset($_COOKIE['password_correct_' . $client_id]) ? $_COOKIE['password_correct_' . $client_id] : '';
750 $hash_pass = hash('sha256', wp_salt(32) . md5(isset($attributes['contentPassword']) ? $attributes['contentPassword'] : ''));
751
752
753 $content_protection_class = 'ep-content-protection-enabled';
754 if (empty($attributes['lockContent']) || empty($attributes['contentPassword']) || $hash_pass === $password_correct) {
755 $content_protection_class = 'ep-content-protection-disabled';
756 }
757
758
759
760 $height = !empty($attributes['height']) ? $attributes['height'] . 'px' : '600px';
761 $gen_settings = get_option(EMBEDPRESS_PLG_NAME);
762
763 $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by'];
764 if (isset($attributes['powered_by'])) {
765 $powered_by = $attributes['powered_by'];
766 }
767
768 $src = $renderer . ((strpos($renderer, '?') == false) ? '?' : '&') . 'file=' . urlencode($attributes['href']) . getParamData($attributes);
769
770 $pass_hash_key = isset($attributes['contentPassword']) ? md5($attributes['contentPassword']) : '';
771
772 $aligns = [
773 'left' => 'ep-alignleft',
774 'right' => 'ep-alignright',
775 'center' => 'ep-aligncenter',
776 'wide' => 'ep-alignwide',
777 'full' => 'ep-alignfull'
778 ];
779 $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : '';
780 $dimension = "width:$width;height:$height";
781 ob_start();
782 ?>
783
784
785 <?php
786
787 $embed_code = '<iframe title="' . esc_attr(Helper::get_file_title($attributes['href'])) . '" class="embedpress-embed-document-pdf ' . esc_attr($id) . '" style="' . esc_attr($dimension) . '; max-width:100%; display: inline-block" src="' . esc_url($src) . '" frameborder="0" oncontextmenu="return false;"></iframe> ';
788
789 if ($powered_by) {
790 $embed_code .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
791 }
792
793 $url = !empty($attributes['href']) ? $attributes['href'] : '';
794
795 $adsAtts = '';
796 if (!empty($attributes['adManager'])) {
797 $ad = base64_encode(json_encode($attributes));
798 $adsAtts = "data-ad-id=$client_id data-ad-attrs=$ad class=ad-mask";
799 }
800 ?>
801
802 <div id="ep-gutenberg-content-<?php echo esc_attr($client_id) ?>" class="ep-gutenberg-content <?php echo esc_attr($alignment . ' ' . $width_class . ' ' . $content_share_class . ' ' . $share_position_class . ' ' . $content_protection_class); ?> ">
803 <div class="embedpress-inner-iframe <?php if ($unitoption === '%') {
804 echo esc_attr('emebedpress-unit-percent');
805 } ?> ep-doc-<?php echo esc_attr($client_id); ?>" <?php if ($unitoption === '%' && !empty($attributes['width'])) {
806 $style_attr = 'max-width:' . $attributes['width'] . '%';
807 } else {
808 $style_attr = 'max-width:100%';
809 } ?> style="<?php echo esc_attr($style_attr); ?>" id="<?php echo esc_attr($id); ?>">
810 <div <?php echo esc_attr($adsAtts); ?>>
811 <?php
812 do_action('embedpress_pdf_gutenberg_after_embed', $client_id, 'pdf', $attributes, $pdf_url);
813 $embed = $embed_code;
814 if (empty($attributes['lockContent']) || empty($attributes['contentPassword']) || (!empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct))) {
815
816 $custom_thumbnail = isset($attributes['customThumbnail']) ? $attributes['customThumbnail'] : '';
817
818 echo '<div class="ep-embed-content-wraper">';
819 $embed = '<div class="position-' . esc_attr($share_position) . '-wraper gutenberg-pdf-wraper">';
820 $embed .= $embed_code;
821 $embed .= '</div>';
822
823 if (!empty($attributes['contentShare'])) {
824 $content_id = $attributes['id'];
825 $embed .= Helper::embed_content_share($content_id, $attributes);
826 }
827 echo $embed;
828 echo '</div>';
829 } else {
830 if (!empty($attributes['contentShare'])) {
831 $content_id = $attributes['clientId'];
832 $embed = '<div class="position-' . esc_attr($share_position) . '-wraper gutenberg-pdf-wraper">';
833 $embed .= $embed_code;
834 $embed .= '</div>';
835 $embed .= Helper::embed_content_share($content_id, $attributes);
836 }
837 echo '<div class="ep-embed-content-wraper">';
838 Helper::display_password_form($client_id, $embed, $pass_hash_key, $attributes);
839 echo '</div>';
840 }
841 ?>
842
843 <?php
844 if(!empty($attributes['adManager'])) {
845 $embed .= Helper::generateAdTemplate($client_id, $attributes, 'gutenberg');
846 }
847 ?>
848 </div>
849 </div>
850 </div>
851 <?php
852 return ob_get_clean();
853 }
854 }
855
856 function isGoogleCalendar($url) {
857 $pattern = '/^https:\/\/calendar\.google\.com\/calendar\/embed\?.*$/';
858 return preg_match($pattern, $url);
859 }
860
861 function embedpress_calendar_render_block($attributes)
862 {
863
864 $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-calendar-' . rand(100, 10000);
865 $url = !empty($attributes['url']) ? $attributes['url'] : '';
866
867 if(!isGoogleCalendar($url))
868 {
869 return;
870 }
871
872 $is_private = isset($attributes['is_public']);
873 $client_id = md5($id);
874 $width = !empty($attributes['width']) ? $attributes['width'] . 'px' : '600px';
875 $height = !empty($attributes['height']) ? $attributes['height'] . 'px' : '600px';
876 $gen_settings = get_option(EMBEDPRESS_PLG_NAME);
877 $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by'];
878 if (isset($attributes['powered_by'])) {
879 $powered_by = $attributes['powered_by'];
880 }
881
882 $aligns = [
883 'left' => 'alignleft',
884 'right' => 'alignright',
885 'wide' => 'alignwide',
886 'full' => 'alignfull'
887 ];
888 $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : '';
889 $dimension = "width:$width;height:$height";
890 ob_start();
891 ?>
892 <div class="embedpress-calendar-gutenberg embedpress-calendar ose-calendar <?php echo esc_attr($alignment) ?>" style="<?php echo esc_attr($dimension); ?>; max-width:100%;">
893
894 <?php
895 if (!empty($url) && !$is_private) {
896 ?>
897 <iframe title="<?php echo esc_attr(Helper::get_file_title($url)); ?>" style="<?php echo esc_attr($dimension); ?>; max-width:100%; display: inline-block" src="<?php echo esc_url($url); ?>"></iframe>
898 <?php } else {
899 if (is_embedpress_pro_active()) {
900 echo Embedpress_Google_Helper::shortcode();
901 }
902 } ?>
903 <?php do_action('embedpress_calendar_gutenberg_after_embed', $client_id, 'calendar', $attributes); ?>
904
905 <?php
906 if ($powered_by) {
907 printf('<p class="embedpress-el-powered" style="width:' . esc_attr($width) . '" >%s</p>', __('Powered By EmbedPress', 'embedpress'));
908 } ?>
909
910 </div>
911 <?php
912 return ob_get_clean();
913 }
914