PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 4.0.0
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v4.0.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 / plugin.php
embedpress / Gutenberg Last commit date
block-backend 2 years ago dist 2 years ago plugin.php 2 years ago
plugin.php
1043 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 // instaFeed attributes
432 'instaLayout' => [
433 'type' => 'string',
434 'default' => 'insta-grid',
435 ],
436 'instafeedFeedType' => [
437 'type' => 'string',
438 'default' => 'user_account_type',
439 ],
440 'instafeedAccountType' => [
441 'type' => 'string',
442 'default' => 'personal',
443 ],
444 'instafeedProfileImage' => [
445 'type' => 'boolean',
446 'default' => true,
447 ],
448 'instafeedProfileImageUrl' => [
449 'type' => 'string',
450 'default' => '',
451 ],
452 'instafeedFollowBtn' => [
453 'type' => 'boolean',
454 'default' => true,
455 ],
456 'instafeedFollowBtnLabel' => [
457 'type' => 'string',
458 'default' => 'Follow',
459 ],
460 'instafeedPostsCount' => [
461 'type' => 'boolean',
462 'default' => true,
463 ],
464 'instafeedPostsCountText' => [
465 'type' => 'string',
466 'default' => '[count] posts',
467 ],
468 'instafeedFollowersCount' => [
469 'type' => 'boolean',
470 'default' => true,
471 ],
472 'instafeedFollowersCountText' => [
473 'type' => 'string',
474 'default' => '[count] followers',
475 ],
476 'instafeedAccName' => [
477 'type' => 'boolean',
478 'default' => true,
479 ],
480 'instafeedColumns' => [
481 'type' => 'string',
482 'default' => '3',
483 ],
484 'instafeedColumnsGap' => [
485 'type' => 'string',
486 'default' => '5',
487 ],
488 'instafeedPostsPerPage' => [
489 'type' => 'string',
490 'default' => '12',
491 ],
492 'instafeedTab' => [
493 'type' => 'boolean',
494 'default' => true,
495 ],
496 'instafeedLikesCount' => [
497 'type' => 'boolean',
498 'default' => true,
499 ],
500 'instafeedCommentsCount' => [
501 'type' => 'boolean',
502 'default' => true,
503 ],
504 'instafeedPopup' => [
505 'type' => 'boolean',
506 'default' => true,
507 ],
508 'instafeedPopupFollowBtn' => [
509 'type' => 'boolean',
510 'default' => true,
511 ],
512 'instafeedPopupFollowBtnLabel' => [
513 'type' => 'string',
514 'default' => 'Follow',
515 ],
516 'instafeedLoadmore' => [
517 'type' => 'boolean',
518 'default' => true,
519 ],
520 'instafeedLoadmoreLabel' => [
521 'type' => 'string',
522 'default' => 'Load More',
523 ],
524 'slidesShow' => [
525 'type' => 'string',
526 'default' => '4',
527 ],
528 'slidesScroll' => [
529 'type' => 'string',
530 'default' => '4',
531 ],
532 'carouselAutoplay' => [
533 'type' => 'boolean',
534 'default' => false,
535 ],
536 'autoplaySpeed' => [
537 'type' => 'string',
538 'default' => '3000',
539 ],
540 'transitionSpeed' => [
541 'type' => 'string',
542 'default' => '1000',
543 ],
544 'carouselLoop' => [
545 'type' => 'boolean',
546 'default' => true,
547 ],
548 'carouselArrows' => [
549 'type' => 'boolean',
550 'default' => true,
551 ],
552 'carouselSpacing' => [
553 'type' => 'string',
554 'default' => '0',
555 ],
556 'carouselDots' => [
557 'type' => 'boolean',
558 'default' => false,
559 ],
560 // Calendly attributes
561 'cEmbedType' => array(
562 'type' => 'string',
563 'default' => 'inline'
564 ),
565 'calendlyData' => array(
566 'type' => 'boolean',
567 'default' => false
568 ),
569 'hideCookieBanner' => array(
570 'type' => 'boolean',
571 'default' => false
572 ),
573 'hideEventTypeDetails' => array(
574 'type' => 'boolean',
575 'default' => false
576 ),
577 'cBackgroundColor' => array(
578 'type' => 'string',
579 'default' => 'ffffff'
580 ),
581 'cTextColor' => array(
582 'type' => 'string',
583 'default' => '1A1A1A'
584 ),
585 'cButtonLinkColor' => array(
586 'type' => 'string',
587 'default' => '0000FF'
588 ),
589 'cPopupButtonText' => array(
590 'type' => 'string',
591 'default' => 'Schedule time with me'
592 ),
593 'cPopupButtonBGColor' => array(
594 'type' => 'string',
595 'default' => '#0000FF'
596 ),
597 'cPopupButtonTextColor' => array(
598 'type' => 'string',
599 'default' => '#FFFFFF'
600 ),
601 'cPopupLinkText' => array(
602 'type' => 'string',
603 'default' => 'Schedule time with me'
604 ),
605
606 //Ad attributes
607 'adManager' => [
608 'type' => 'boolean',
609 'default' => false
610 ],
611 'adSource' => [
612 'type' => 'string',
613 'default' => 'video'
614 ],
615 'adContent' => [
616 'type' => 'object',
617 ],
618 'adWidth' => array(
619 'type' => 'string',
620 'default' => '300'
621 ),
622 'adHeight' => array(
623 'type' => 'string',
624 'default' => '200'
625 ),
626 'adXPosition' => array(
627 'type' => 'number',
628 'default' => 25
629 ),
630 'adYPosition' => array(
631 'type' => 'number',
632 'default' => 10
633 ),
634 'adUrl' => [
635 'type' => 'string',
636 'default' => ''
637 ],
638 'adStart' => [
639 'type' => 'string',
640 'default' => '10'
641 ],
642 'adSkipButton' => [
643 'type' => 'boolean',
644 'default' => true
645 ],
646 'adSkipButtonAfter' => [
647 'type' => 'string',
648 'default' => '5'
649 ]
650
651 ),
652 ]);
653 } elseif ('embedpress-pdf' === $blocks_to_register) {
654 register_block_type('embedpress/embedpress-pdf', [
655 'attributes' => array(
656 'powered_by' => [
657 'type' => 'boolean',
658 'default' => true
659 ],
660 'lockContent' => [
661 'type' => 'boolean',
662 'default' => false
663 ],
664 'lockHeading' => [
665 'type' => 'string',
666 'default' => 'Content Locked'
667 ],
668 'lockSubHeading' => [
669 'type' => 'string',
670 'default' => 'Content is locked and requires password to access it.'
671 ],
672 'passwordPlaceholder' => [
673 'type' => 'string',
674 'default' => 'Password'
675 ],
676 'submitButtonText' => [
677 'type' => 'string',
678 'default' => 'Unlock'
679 ],
680 'submitUnlockingText' => [
681 'type' => 'string',
682 'default' => 'Unlocking'
683 ],
684 'lockErrorMessage' => [
685 'type' => 'string',
686 'default' => 'Oops, that wasn\'t the right password. Try again.'
687 ],
688 'enableFooterMessage' => [
689 'type' => 'boolean',
690 'default' => false
691 ],
692 'footerMessage' => [
693 'type' => 'string',
694 'default' => 'In case you don\'t have the password, kindly reach out to content owner or administrator to request access.'
695 ],
696 'contentPassword' => [
697 'type' => 'string',
698 'default' => ''
699 ],
700 'contentShare' => [
701 'type' => 'boolean',
702 'default' => false
703 ],
704 'sharePosition' => [
705 'type' => 'string',
706 'default' => 'right'
707 ],
708 'presentation' => [
709 'type' => "boolean",
710 'default' => true,
711 ],
712
713 'position' => [
714 'type' => "string",
715 'default' => 'top',
716 ],
717
718 'print' => [
719 'type' => "boolean",
720 'default' => true,
721 ],
722
723 'download' => [
724 'type' => "boolean",
725 'default' => true,
726 ],
727 'open' => [
728 'type' => "boolean",
729 'default' => true,
730 ],
731 'copy_text' => [
732 'type' => "boolean",
733 'default' => true,
734 ],
735 'add_text' => [
736 'type' => "boolean",
737 'default' => true,
738 ],
739 'draw' => [
740 'type' => "boolean",
741 'default' => true,
742 ],
743 'toolbar' => [
744 'type' => "boolean",
745 'default' => true,
746 ],
747 'doc_details' => [
748 'type' => "boolean",
749 'default' => true,
750 ],
751 'doc_rotation' => [
752 'type' => "boolean",
753 'default' => true,
754 ],
755 'unitoption' => [
756 'type' => "string",
757 'default' => '%',
758 ],
759
760 //Ad attributes
761 'adManager' => [
762 'type' => 'boolean',
763 'default' => false
764 ],
765 'adSource' => [
766 'type' => 'string',
767 'default' => 'video'
768 ],
769 'adContent' => [
770 'type' => 'object',
771 ],
772 'adWidth' => array(
773 'type' => 'string',
774 'default' => '300'
775 ),
776 'adHeight' => array(
777 'type' => 'string',
778 'default' => '200'
779 ),
780 'adXPosition' => array(
781 'type' => 'number',
782 'default' => 25
783 ),
784 'adYPosition' => array(
785 'type' => 'number',
786 'default' => 20
787 ),
788 'adUrl' => [
789 'type' => 'string',
790 'default' => ''
791 ],
792 'adStart' => [
793 'type' => 'string',
794 'default' => '10'
795 ],
796 'adSkipButton' => [
797 'type' => 'boolean',
798 'default' => true
799 ],
800 'adSkipButtonAfter' => [
801 'type' => 'string',
802 'default' => '5'
803 ]
804 ),
805 'render_callback' => 'embedpress_pdf_render_block',
806 ]);
807 } elseif ('embedpress-calendar' === $blocks_to_register) {
808 register_block_type('embedpress/embedpress-calendar', [
809 'render_callback' => 'embedpress_calendar_render_block',
810 ]);
811 } else {
812 register_block_type('embedpress/' . $blocks_to_register);
813 }
814 } else {
815
816 if (WP_Block_Type_Registry::get_instance()->is_registered('embedpress/' . $blocks_to_register)) {
817 unregister_block_type('embedpress/' . $blocks_to_register);
818 }
819 }
820 }
821
822 endif;
823 }
824
825 add_action('init', 'embedpress_gutenberg_register_all_block');
826
827 function getParamData($attributes)
828 {
829
830 $urlParamData = array(
831 'themeMode' => !empty($attributes['themeMode']) ? $attributes['themeMode'] : 'default',
832 'toolbar' => !empty($attributes['toolbar']) ? 'true' : 'false',
833 'position' => $attributes['position'],
834 'presentation' => !empty($attributes['presentation']) ? 'true' : 'false',
835 'download' => !empty($attributes['download']) ? 'true' : 'false',
836 'copy_text' => !empty($attributes['copy_text']) ? 'true' : 'false',
837 'add_text' => !empty($attributes['add_text']) ? 'true' : 'false',
838 'draw' => !empty($attributes['draw']) ? 'true' : 'false',
839 'doc_rotation' => !empty($attributes['doc_rotation']) ? 'true' : 'false',
840 'doc_details' => !empty($attributes['doc_details']) ? 'true' : 'false',
841 );
842
843 if ($urlParamData['themeMode'] == 'custom') {
844 $urlParamData['customColor'] = !empty($attributes['customColor']) ? $attributes['customColor'] : '#403A81';
845 }
846
847 return "#key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), 'UTF-8'));
848 }
849
850 function embedpress_pdf_render_block($attributes)
851 {
852
853
854 if (!empty($attributes['href'])) {
855 $renderer = Helper::get_pdf_renderer();
856 $pdf_url = $attributes['href'];
857 $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-pdf-' . rand(100, 10000);
858 $client_id = md5($id);
859
860
861 $unitoption = !empty($attributes['unitoption']) ? $attributes['unitoption'] : 'px';
862 $width = !empty($attributes['width']) ? $attributes['width'] . $unitoption : '600px';
863
864 if ($unitoption == '%') {
865 $width_class = ' ep-percentage-width';
866 } else {
867 $width_class = 'ep-fixed-width';
868 }
869 $content_share_class = '';
870 $share_position_class = '';
871 $share_position = isset($attributes['sharePosition']) ? $attributes['sharePosition'] : 'right';
872
873 if (!empty($attributes['contentShare'])) {
874 $content_share_class = 'ep-content-share-enabled';
875 $share_position_class = 'ep-share-position-' . $share_position;
876 }
877
878 $password_correct = isset($_COOKIE['password_correct_' . $client_id]) ? $_COOKIE['password_correct_' . $client_id] : '';
879 $hash_pass = hash('sha256', wp_salt(32) . md5(isset($attributes['contentPassword']) ? $attributes['contentPassword'] : ''));
880
881
882 $content_protection_class = 'ep-content-protection-enabled';
883 if (empty($attributes['lockContent']) || empty($attributes['contentPassword']) || $hash_pass === $password_correct) {
884 $content_protection_class = 'ep-content-protection-disabled';
885 }
886
887
888
889 $height = !empty($attributes['height']) ? $attributes['height'] . 'px' : '600px';
890 $gen_settings = get_option(EMBEDPRESS_PLG_NAME);
891
892 $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by'];
893 if (isset($attributes['powered_by'])) {
894 $powered_by = $attributes['powered_by'];
895 }
896
897 $src = $renderer . ((strpos($renderer, '?') == false) ? '?' : '&') . 'file=' . urlencode($attributes['href']) . getParamData($attributes);
898
899 $pass_hash_key = isset($attributes['contentPassword']) ? md5($attributes['contentPassword']) : '';
900
901 $aligns = [
902 'left' => 'ep-alignleft',
903 'right' => 'ep-alignright',
904 'center' => 'ep-aligncenter',
905 'wide' => 'ep-alignwide',
906 'full' => 'ep-alignfull'
907 ];
908 $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : '';
909 $dimension = "width:$width;height:$height";
910 ob_start();
911 ?>
912
913
914 <?php
915
916 $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> ';
917
918 if ($powered_by) {
919 $embed_code .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
920 }
921
922 $url = !empty($attributes['href']) ? $attributes['href'] : '';
923
924 $adsAtts = '';
925 if (!empty($attributes['adManager'])) {
926 $ad = base64_encode(json_encode($attributes));
927 $adsAtts = "data-sponsored-id=$client_id data-sponsored-attrs=$ad class=ad-mask";
928 }
929 ?>
930
931 <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); ?> ">
932 <div class="embedpress-inner-iframe <?php if ($unitoption === '%') {
933 echo esc_attr('emebedpress-unit-percent');
934 } ?> ep-doc-<?php echo esc_attr($client_id); ?>" <?php if ($unitoption === '%' && !empty($attributes['width'])) {
935 $style_attr = 'max-width:' . $attributes['width'] . '%';
936 } else {
937 $style_attr = 'max-width:100%';
938 } ?> style="<?php echo esc_attr($style_attr); ?>" id="<?php echo esc_attr($id); ?>">
939 <div <?php echo esc_attr($adsAtts); ?>>
940 <?php
941 do_action('embedpress_pdf_gutenberg_after_embed', $client_id, 'pdf', $attributes, $pdf_url);
942 $embed = $embed_code;
943 if (empty($attributes['lockContent']) || empty($attributes['contentPassword']) || (!empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct))) {
944
945 $custom_thumbnail = isset($attributes['customThumbnail']) ? $attributes['customThumbnail'] : '';
946
947 echo '<div class="ep-embed-content-wraper">';
948 $embed = '<div class="position-' . esc_attr($share_position) . '-wraper gutenberg-pdf-wraper">';
949 $embed .= $embed_code;
950 $embed .= '</div>';
951
952 if (!empty($attributes['contentShare'])) {
953 $content_id = $attributes['id'];
954 $embed .= Helper::embed_content_share($content_id, $attributes);
955 }
956 echo $embed;
957 echo '</div>';
958 } else {
959 if (!empty($attributes['contentShare'])) {
960 $content_id = $attributes['clientId'];
961 $embed = '<div class="position-' . esc_attr($share_position) . '-wraper gutenberg-pdf-wraper">';
962 $embed .= $embed_code;
963 $embed .= '</div>';
964 $embed .= Helper::embed_content_share($content_id, $attributes);
965 }
966 echo '<div class="ep-embed-content-wraper">';
967 Helper::display_password_form($client_id, $embed, $pass_hash_key, $attributes);
968 echo '</div>';
969 }
970 ?>
971
972 <?php
973 if(!empty($attributes['adManager'])) {
974 $embed .= Helper::generateAdTemplate($client_id, $attributes, 'gutenberg');
975 }
976 ?>
977 </div>
978 </div>
979 </div>
980 <?php
981 return ob_get_clean();
982 }
983 }
984
985 function isGoogleCalendar($url) {
986 $pattern = '/^https:\/\/calendar\.google\.com\/calendar\/embed\?.*$/';
987 return preg_match($pattern, $url);
988 }
989
990 function embedpress_calendar_render_block($attributes)
991 {
992
993 $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-calendar-' . rand(100, 10000);
994 $url = !empty($attributes['url']) ? $attributes['url'] : '';
995
996 if(!isGoogleCalendar($url))
997 {
998 return;
999 }
1000
1001 $is_private = isset($attributes['is_public']);
1002 $client_id = md5($id);
1003 $width = !empty($attributes['width']) ? $attributes['width'] . 'px' : '600px';
1004 $height = !empty($attributes['height']) ? $attributes['height'] . 'px' : '600px';
1005 $gen_settings = get_option(EMBEDPRESS_PLG_NAME);
1006 $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by'];
1007 if (isset($attributes['powered_by'])) {
1008 $powered_by = $attributes['powered_by'];
1009 }
1010
1011 $aligns = [
1012 'left' => 'alignleft',
1013 'right' => 'alignright',
1014 'wide' => 'alignwide',
1015 'full' => 'alignfull'
1016 ];
1017 $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : '';
1018 $dimension = "width:$width;height:$height";
1019 ob_start();
1020 ?>
1021 <div class="embedpress-calendar-gutenberg embedpress-calendar ose-calendar <?php echo esc_attr($alignment) ?>" style="<?php echo esc_attr($dimension); ?>; max-width:100%;">
1022
1023 <?php
1024 if (!empty($url) && !$is_private) {
1025 ?>
1026 <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>
1027 <?php } else {
1028 if (is_embedpress_pro_active()) {
1029 echo Embedpress_Google_Helper::shortcode();
1030 }
1031 } ?>
1032 <?php do_action('embedpress_calendar_gutenberg_after_embed', $client_id, 'calendar', $attributes); ?>
1033
1034 <?php
1035 if ($powered_by) {
1036 printf('<p class="embedpress-el-powered" style="width:' . esc_attr($width) . '" >%s</p>', __('Powered By EmbedPress', 'embedpress'));
1037 } ?>
1038
1039 </div>
1040 <?php
1041 return ob_get_clean();
1042 }
1043