PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 4.0.1
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v4.0.1
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
1087 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 // 'style' => [
174 // 'plyr',
175 // ],
176 // 'script' => [
177 // 'plyr.polyfilled',
178 // 'initplyr',
179 // 'vimeo-player',
180 // 'embedpress-front',
181 // 'embedpress-ads',
182 // ],
183 'attributes' => array(
184 'clientId' => [
185 'type' => 'string',
186 ],
187 'height' => [
188 'type' => 'string',
189 'default' => '450'
190 ],
191 'width' => [
192 'type' => 'string',
193 'default' => '600'
194 ],
195 'lockContent' => [
196 'type' => 'boolean',
197 'default' => false
198 ],
199 'lockHeading' => [
200 'type' => 'string',
201 'default' => 'Content Locked'
202 ],
203 'lockSubHeading' => [
204 'type' => 'string',
205 'default' => 'Content is locked and requires password to access it.'
206 ],
207 'lockErrorMessage' => [
208 'type' => 'string',
209 'default' => 'Oops, that wasn\'t the right password. Try again.'
210 ],
211 'passwordPlaceholder' => [
212 'type' => 'string',
213 'default' => 'Password'
214 ],
215 'submitButtonText' => [
216 'type' => 'string',
217 'default' => 'Unlock'
218 ],
219 'submitUnlockingText' => [
220 'type' => 'string',
221 'default' => 'Unlocking'
222 ],
223 'enableFooterMessage' => [
224 'type' => 'boolean',
225 'default' => false
226 ],
227 'footerMessage' => [
228 'type' => 'string',
229 'default' => 'In case you don\'t have the password, kindly reach out to content owner or administrator to request access.'
230 ],
231 'contentPassword' => [
232 'type' => 'string',
233 'default' => '',
234 ],
235 'contentShare' => [
236 'type' => 'boolean',
237 'default' => false
238 ],
239 'sharePosition' => [
240 'type' => 'string',
241 'default' => 'right'
242 ],
243 'customTitle' => [
244 'type' => 'string',
245 'default' => ''
246 ],
247 'customDescription' => [
248 'type' => 'string',
249 'default' => ''
250 ],
251 'customThumbnail' => [
252 'type' => 'string',
253 'default' => ''
254 ],
255
256 'videosize' => [
257 'type' => 'string',
258 'default' => 'fixed'
259 ],
260
261 'loadmore' => [
262 'type' => 'boolean',
263 'default' => false
264 ],
265 //Youtube Attributes
266 'starttime' => [
267 'type' => 'string',
268 ],
269 'endtime' => [
270 'type' => 'string',
271 ],
272 'autoplay' => [
273 'type' => 'boolean',
274 'default' => false
275 ],
276 'controls' => [
277 'type' => 'string',
278 ],
279 'progressbarcolor' => [
280 'type' => 'string',
281 ],
282 'videoannotations' => [
283 'type' => 'string',
284 ],
285 'closedcaptions' => [
286 'type' => 'boolean',
287 'default' => true
288 ],
289 'relatedvideos' => [
290 'type' => 'boolean',
291 'default' => true
292 ],
293 'fullscreen' => [
294 'type' => 'boolean',
295 'default' => true
296 ],
297
298 'modestbranding' => [
299 'type' => 'string',
300 ],
301 // custom player attributes
302 'customPlayer' => [
303 'type' => 'boolean',
304 'default' => false
305 ],
306
307 'posterThumbnail' => [
308 'type' => 'string',
309 'default' => ''
310 ],
311
312 'playerPreset' => [
313 'type' => 'string',
314 'default' => ''
315 ],
316
317 'playerColor' => [
318 'type' => 'string',
319 'default' => '#2e2e99'
320 ],
321
322 'playerPip' => [
323 'type' => 'boolean',
324 'default' => false
325 ],
326
327 'playerRestart' => [
328 'type' => 'boolean',
329 'default' => true
330 ],
331
332 'playerRewind' => [
333 'type' => 'boolean',
334 'default' => true
335 ],
336
337 'playerFastForward' => [
338 'type' => 'boolean',
339 'default' => true
340 ],
341 'playerTooltip' => [
342 'type' => 'boolean',
343 'default' => true
344 ],
345 'playerHideControls' => [
346 'type' => 'boolean',
347 'default' => true
348 ],
349 'playerDownload' => [
350 'type' => 'boolean',
351 'default' => true
352 ],
353 //Wistia Attributes
354 'wstarttime' => [
355 'type' => 'string',
356 ],
357 'wautoplay' => [
358 'type' => 'boolean',
359 'default' => true
360 ],
361 'scheme' => [
362 'type' => 'string',
363 ],
364 'captions' => [
365 'type' => 'boolean',
366 'default' => true
367 ],
368 'playbutton' => [
369 'type' => 'boolean',
370 'default' => true
371 ],
372 'smallplaybutton' => [
373 'type' => 'boolean',
374 'default' => true
375 ],
376 'playbar' => [
377 'type' => 'boolean',
378 'default' => true
379 ],
380 'resumable' => [
381 'type' => 'boolean',
382 'default' => true
383 ],
384 'wistiafocus' => [
385 'type' => 'boolean',
386 'default' => true
387 ],
388 'volumecontrol' => [
389 'type' => 'boolean',
390 'default' => true
391 ],
392 'volume' => [
393 'type' => 'number',
394 'default' => 100
395 ],
396 'rewind' => [
397 'type' => 'boolean',
398 'default' => false
399 ],
400 'wfullscreen' => [
401 'type' => 'boolean',
402 'default' => true
403 ],
404
405 // Vimeo attributes
406 'vstarttime' => [
407 'type' => 'string',
408 ],
409 'vautoplay' => [
410 'type' => 'boolean',
411 'default' => false
412 ],
413 'vscheme' => [
414 'type' => 'string',
415 ],
416 'vtitle' => [
417 'type' => 'boolean',
418 'default' => true
419 ],
420 'vauthor' => [
421 'type' => 'boolean',
422 'default' => true
423 ],
424 'vavatar' => [
425 'type' => 'boolean',
426 'default' => true
427 ],
428 'vloop' => [
429 'type' => 'boolean',
430 'default' => false
431 ],
432 'vautopause' => [
433 'type' => 'boolean',
434 'default' => false
435 ],
436 'vdnt' => [
437 'type' => 'boolean',
438 'default' => false
439 ],
440
441 // instaFeed attributes
442 'instaLayout' => [
443 'type' => 'string',
444 'default' => 'insta-grid',
445 ],
446 'instafeedFeedType' => [
447 'type' => 'string',
448 'default' => 'user_account_type',
449 ],
450 'instafeedAccountType' => [
451 'type' => 'string',
452 'default' => 'personal',
453 ],
454 'instafeedProfileImage' => [
455 'type' => 'boolean',
456 'default' => true,
457 ],
458 'instafeedProfileImageUrl' => [
459 'type' => 'string',
460 'default' => '',
461 ],
462 'instafeedFollowBtn' => [
463 'type' => 'boolean',
464 'default' => true,
465 ],
466 'instafeedFollowBtnLabel' => [
467 'type' => 'string',
468 'default' => 'Follow',
469 ],
470 'instafeedPostsCount' => [
471 'type' => 'boolean',
472 'default' => true,
473 ],
474 'instafeedPostsCountText' => [
475 'type' => 'string',
476 'default' => '[count] posts',
477 ],
478 'instafeedFollowersCount' => [
479 'type' => 'boolean',
480 'default' => true,
481 ],
482 'instafeedFollowersCountText' => [
483 'type' => 'string',
484 'default' => '[count] followers',
485 ],
486 'instafeedAccName' => [
487 'type' => 'boolean',
488 'default' => true,
489 ],
490 'instafeedColumns' => [
491 'type' => 'string',
492 'default' => '3',
493 ],
494 'instafeedColumnsGap' => [
495 'type' => 'string',
496 'default' => '5',
497 ],
498 'instafeedPostsPerPage' => [
499 'type' => 'string',
500 'default' => '12',
501 ],
502 'instafeedTab' => [
503 'type' => 'boolean',
504 'default' => true,
505 ],
506 'instafeedLikesCount' => [
507 'type' => 'boolean',
508 'default' => true,
509 ],
510 'instafeedCommentsCount' => [
511 'type' => 'boolean',
512 'default' => true,
513 ],
514 'instafeedPopup' => [
515 'type' => 'boolean',
516 'default' => true,
517 ],
518 'instafeedPopupFollowBtn' => [
519 'type' => 'boolean',
520 'default' => true,
521 ],
522 'instafeedPopupFollowBtnLabel' => [
523 'type' => 'string',
524 'default' => 'Follow',
525 ],
526 'instafeedLoadmore' => [
527 'type' => 'boolean',
528 'default' => true,
529 ],
530 'instafeedLoadmoreLabel' => [
531 'type' => 'string',
532 'default' => 'Load More',
533 ],
534 'slidesShow' => [
535 'type' => 'string',
536 'default' => '4',
537 ],
538 'slidesScroll' => [
539 'type' => 'string',
540 'default' => '4',
541 ],
542 'carouselAutoplay' => [
543 'type' => 'boolean',
544 'default' => false,
545 ],
546 'autoplaySpeed' => [
547 'type' => 'string',
548 'default' => '3000',
549 ],
550 'transitionSpeed' => [
551 'type' => 'string',
552 'default' => '1000',
553 ],
554 'carouselLoop' => [
555 'type' => 'boolean',
556 'default' => true,
557 ],
558 'carouselArrows' => [
559 'type' => 'boolean',
560 'default' => true,
561 ],
562 'carouselSpacing' => [
563 'type' => 'string',
564 'default' => '0',
565 ],
566 'carouselDots' => [
567 'type' => 'boolean',
568 'default' => false,
569 ],
570 // Calendly attributes
571 'cEmbedType' => array(
572 'type' => 'string',
573 'default' => 'inline'
574 ),
575 'calendlyData' => array(
576 'type' => 'boolean',
577 'default' => false
578 ),
579 'hideCookieBanner' => array(
580 'type' => 'boolean',
581 'default' => false
582 ),
583 'hideEventTypeDetails' => array(
584 'type' => 'boolean',
585 'default' => false
586 ),
587 'cBackgroundColor' => array(
588 'type' => 'string',
589 'default' => 'ffffff'
590 ),
591 'cTextColor' => array(
592 'type' => 'string',
593 'default' => '1A1A1A'
594 ),
595 'cButtonLinkColor' => array(
596 'type' => 'string',
597 'default' => '0000FF'
598 ),
599 'cPopupButtonText' => array(
600 'type' => 'string',
601 'default' => 'Schedule time with me'
602 ),
603 'cPopupButtonBGColor' => array(
604 'type' => 'string',
605 'default' => '#0000FF'
606 ),
607 'cPopupButtonTextColor' => array(
608 'type' => 'string',
609 'default' => '#FFFFFF'
610 ),
611 'cPopupLinkText' => array(
612 'type' => 'string',
613 'default' => 'Schedule time with me'
614 ),
615
616 //Ad attributes
617 'adManager' => [
618 'type' => 'boolean',
619 'default' => false
620 ],
621 'adSource' => [
622 'type' => 'string',
623 'default' => 'video'
624 ],
625 'adContent' => [
626 'type' => 'object',
627 ],
628 'adWidth' => array(
629 'type' => 'string',
630 'default' => '300'
631 ),
632 'adHeight' => array(
633 'type' => 'string',
634 'default' => '200'
635 ),
636 'adXPosition' => array(
637 'type' => 'number',
638 'default' => 25
639 ),
640 'adYPosition' => array(
641 'type' => 'number',
642 'default' => 10
643 ),
644 'adUrl' => [
645 'type' => 'string',
646 'default' => ''
647 ],
648 'adStart' => [
649 'type' => 'string',
650 'default' => '10'
651 ],
652 'adSkipButton' => [
653 'type' => 'boolean',
654 'default' => true
655 ],
656 'adSkipButtonAfter' => [
657 'type' => 'string',
658 'default' => '5'
659 ]
660
661 ),
662 ]);
663 } elseif ('embedpress-pdf' === $blocks_to_register) {
664 register_block_type('embedpress/embedpress-pdf', [
665 'attributes' => array(
666 'powered_by' => [
667 'type' => 'boolean',
668 'default' => true
669 ],
670 'lockContent' => [
671 'type' => 'boolean',
672 'default' => false
673 ],
674 'lockHeading' => [
675 'type' => 'string',
676 'default' => 'Content Locked'
677 ],
678 'lockSubHeading' => [
679 'type' => 'string',
680 'default' => 'Content is locked and requires password to access it.'
681 ],
682 'passwordPlaceholder' => [
683 'type' => 'string',
684 'default' => 'Password'
685 ],
686 'submitButtonText' => [
687 'type' => 'string',
688 'default' => 'Unlock'
689 ],
690 'submitUnlockingText' => [
691 'type' => 'string',
692 'default' => 'Unlocking'
693 ],
694 'lockErrorMessage' => [
695 'type' => 'string',
696 'default' => 'Oops, that wasn\'t the right password. Try again.'
697 ],
698 'enableFooterMessage' => [
699 'type' => 'boolean',
700 'default' => false
701 ],
702 'footerMessage' => [
703 'type' => 'string',
704 'default' => 'In case you don\'t have the password, kindly reach out to content owner or administrator to request access.'
705 ],
706 'contentPassword' => [
707 'type' => 'string',
708 'default' => ''
709 ],
710 'contentShare' => [
711 'type' => 'boolean',
712 'default' => false
713 ],
714 'sharePosition' => [
715 'type' => 'string',
716 'default' => 'right'
717 ],
718 'presentation' => [
719 'type' => "boolean",
720 'default' => true,
721 ],
722
723 'position' => [
724 'type' => "string",
725 'default' => 'top',
726 ],
727
728 'print' => [
729 'type' => "boolean",
730 'default' => true,
731 ],
732
733 'download' => [
734 'type' => "boolean",
735 'default' => true,
736 ],
737 'open' => [
738 'type' => "boolean",
739 'default' => true,
740 ],
741 'copy_text' => [
742 'type' => "boolean",
743 'default' => true,
744 ],
745 'add_text' => [
746 'type' => "boolean",
747 'default' => true,
748 ],
749 'draw' => [
750 'type' => "boolean",
751 'default' => true,
752 ],
753 'toolbar' => [
754 'type' => "boolean",
755 'default' => true,
756 ],
757 'doc_details' => [
758 'type' => "boolean",
759 'default' => true,
760 ],
761 'doc_rotation' => [
762 'type' => "boolean",
763 'default' => true,
764 ],
765 'unitoption' => [
766 'type' => "string",
767 'default' => '%',
768 ],
769
770 //Ad attributes
771 'adManager' => [
772 'type' => 'boolean',
773 'default' => false
774 ],
775 'adSource' => [
776 'type' => 'string',
777 'default' => 'video'
778 ],
779 'adContent' => [
780 'type' => 'object',
781 ],
782 'adWidth' => array(
783 'type' => 'string',
784 'default' => '300'
785 ),
786 'adHeight' => array(
787 'type' => 'string',
788 'default' => '200'
789 ),
790 'adXPosition' => array(
791 'type' => 'number',
792 'default' => 25
793 ),
794 'adYPosition' => array(
795 'type' => 'number',
796 'default' => 20
797 ),
798 'adUrl' => [
799 'type' => 'string',
800 'default' => ''
801 ],
802 'adStart' => [
803 'type' => 'string',
804 'default' => '10'
805 ],
806 'adSkipButton' => [
807 'type' => 'boolean',
808 'default' => true
809 ],
810 'adSkipButtonAfter' => [
811 'type' => 'string',
812 'default' => '5'
813 ]
814 ),
815 'render_callback' => 'embedpress_pdf_render_block',
816 ]);
817 } elseif ('embedpress-calendar' === $blocks_to_register) {
818 register_block_type('embedpress/embedpress-calendar', [
819 'render_callback' => 'embedpress_calendar_render_block',
820 ]);
821 } elseif ('document' === $blocks_to_register) {
822 register_block_type('embedpress/' . $blocks_to_register, [
823 // 'render_callback' => 'embedpress_document_render_block',
824 ]);
825 } else {
826 register_block_type('embedpress/' . $blocks_to_register);
827 }
828 } else {
829
830 if (WP_Block_Type_Registry::get_instance()->is_registered('embedpress/' . $blocks_to_register)) {
831 unregister_block_type('embedpress/' . $blocks_to_register);
832 }
833 }
834 }
835
836 endif;
837 }
838
839 add_action('init', 'embedpress_gutenberg_register_all_block');
840
841 function getParamData($attributes)
842 {
843
844 $urlParamData = array(
845 'themeMode' => !empty($attributes['themeMode']) ? $attributes['themeMode'] : 'default',
846 'toolbar' => !empty($attributes['toolbar']) ? 'true' : 'false',
847 'position' => $attributes['position'],
848 'presentation' => !empty($attributes['presentation']) ? 'true' : 'false',
849 'download' => !empty($attributes['download']) ? 'true' : 'false',
850 'copy_text' => !empty($attributes['copy_text']) ? 'true' : 'false',
851 'add_text' => !empty($attributes['add_text']) ? 'true' : 'false',
852 'draw' => !empty($attributes['draw']) ? 'true' : 'false',
853 'doc_rotation' => !empty($attributes['doc_rotation']) ? 'true' : 'false',
854 'doc_details' => !empty($attributes['doc_details']) ? 'true' : 'false',
855 );
856
857 if ($urlParamData['themeMode'] == 'custom') {
858 $urlParamData['customColor'] = !empty($attributes['customColor']) ? $attributes['customColor'] : '#403A81';
859 }
860
861 return "#key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), 'UTF-8'));
862 }
863
864 function embedpress_pdf_block_scripts() {
865
866 $script_handles = [
867 'embedpress-pdfobject',
868 'embedpress-front',
869 'embedpress-ads',
870 ];
871
872 foreach ($script_handles as $handle) {
873 wp_enqueue_script($handle);
874 }
875
876 }
877
878 function embedpress_pdf_render_block($attributes)
879 {
880 embedpress_pdf_block_scripts();
881
882 if (!empty($attributes['href'])) {
883 $renderer = Helper::get_pdf_renderer();
884 $pdf_url = $attributes['href'];
885 $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-pdf-' . rand(100, 10000);
886 $client_id = md5($id);
887
888
889 $unitoption = !empty($attributes['unitoption']) ? $attributes['unitoption'] : 'px';
890 $width = !empty($attributes['width']) ? $attributes['width'] . $unitoption : '600px';
891
892 if ($unitoption == '%') {
893 $width_class = ' ep-percentage-width';
894 } else {
895 $width_class = 'ep-fixed-width';
896 }
897 $content_share_class = '';
898 $share_position_class = '';
899 $share_position = isset($attributes['sharePosition']) ? $attributes['sharePosition'] : 'right';
900
901 if (!empty($attributes['contentShare'])) {
902 $content_share_class = 'ep-content-share-enabled';
903 $share_position_class = 'ep-share-position-' . $share_position;
904 }
905
906 $password_correct = isset($_COOKIE['password_correct_' . $client_id]) ? $_COOKIE['password_correct_' . $client_id] : '';
907 $hash_pass = hash('sha256', wp_salt(32) . md5(isset($attributes['contentPassword']) ? $attributes['contentPassword'] : ''));
908
909
910 $content_protection_class = 'ep-content-protection-enabled';
911 if (empty($attributes['lockContent']) || empty($attributes['contentPassword']) || $hash_pass === $password_correct) {
912 $content_protection_class = 'ep-content-protection-disabled';
913 }
914
915
916
917 $height = !empty($attributes['height']) ? $attributes['height'] . 'px' : '600px';
918 $gen_settings = get_option(EMBEDPRESS_PLG_NAME);
919
920 $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by'];
921 if (isset($attributes['powered_by'])) {
922 $powered_by = $attributes['powered_by'];
923 }
924
925 $src = $renderer . ((strpos($renderer, '?') == false) ? '?' : '&') . 'file=' . urlencode($attributes['href']) . getParamData($attributes);
926
927 $pass_hash_key = isset($attributes['contentPassword']) ? md5($attributes['contentPassword']) : '';
928
929 $aligns = [
930 'left' => 'ep-alignleft',
931 'right' => 'ep-alignright',
932 'center' => 'ep-aligncenter',
933 'wide' => 'ep-alignwide',
934 'full' => 'ep-alignfull'
935 ];
936 $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : '';
937 $dimension = "width:$width;height:$height";
938 ob_start();
939 ?>
940
941
942 <?php
943
944 $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> ';
945
946 if ($powered_by) {
947 $embed_code .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
948 }
949
950 $url = !empty($attributes['href']) ? $attributes['href'] : '';
951
952 $adsAtts = '';
953 if (!empty($attributes['adManager'])) {
954 $ad = base64_encode(json_encode($attributes));
955 $adsAtts = "data-sponsored-id=$client_id data-sponsored-attrs=$ad class=ad-mask";
956 }
957 ?>
958
959 <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); ?> ">
960 <div class="embedpress-inner-iframe <?php if ($unitoption === '%') {
961 echo esc_attr('emebedpress-unit-percent');
962 } ?> ep-doc-<?php echo esc_attr($client_id); ?>" <?php if ($unitoption === '%' && !empty($attributes['width'])) {
963 $style_attr = 'max-width:' . $attributes['width'] . '%';
964 } else {
965 $style_attr = 'max-width:100%';
966 } ?> style="<?php echo esc_attr($style_attr); ?>" id="<?php echo esc_attr($id); ?>">
967 <div <?php echo esc_attr($adsAtts); ?>>
968 <?php
969 do_action('embedpress_pdf_gutenberg_after_embed', $client_id, 'pdf', $attributes, $pdf_url);
970 $embed = $embed_code;
971 if (empty($attributes['lockContent']) || empty($attributes['contentPassword']) || (!empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct))) {
972
973 $custom_thumbnail = isset($attributes['customThumbnail']) ? $attributes['customThumbnail'] : '';
974
975 echo '<div class="ep-embed-content-wraper">';
976 $embed = '<div class="position-' . esc_attr($share_position) . '-wraper gutenberg-pdf-wraper">';
977 $embed .= $embed_code;
978 $embed .= '</div>';
979
980 if (!empty($attributes['contentShare'])) {
981 $content_id = $attributes['id'];
982 $embed .= Helper::embed_content_share($content_id, $attributes);
983 }
984 echo $embed;
985 echo '</div>';
986 } else {
987 if (!empty($attributes['contentShare'])) {
988 $content_id = $attributes['clientId'];
989 $embed = '<div class="position-' . esc_attr($share_position) . '-wraper gutenberg-pdf-wraper">';
990 $embed .= $embed_code;
991 $embed .= '</div>';
992 $embed .= Helper::embed_content_share($content_id, $attributes);
993 }
994 echo '<div class="ep-embed-content-wraper">';
995 Helper::display_password_form($client_id, $embed, $pass_hash_key, $attributes);
996 echo '</div>';
997 }
998 ?>
999
1000 <?php
1001 if(!empty($attributes['adManager'])) {
1002 $embed .= Helper::generateAdTemplate($client_id, $attributes, 'gutenberg');
1003 }
1004 ?>
1005 </div>
1006 </div>
1007 </div>
1008 <?php
1009 return ob_get_clean();
1010 }
1011 }
1012
1013 function isGoogleCalendar($url) {
1014 $pattern = '/^https:\/\/calendar\.google\.com\/calendar\/embed\?.*$/';
1015 return preg_match($pattern, $url);
1016 }
1017
1018 function embedpress_calendar_render_block($attributes)
1019 {
1020
1021 $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-calendar-' . rand(100, 10000);
1022 $url = !empty($attributes['url']) ? $attributes['url'] : '';
1023
1024 if(!isGoogleCalendar($url))
1025 {
1026 return;
1027 }
1028
1029 $is_private = isset($attributes['is_public']);
1030 $client_id = md5($id);
1031 $width = !empty($attributes['width']) ? $attributes['width'] . 'px' : '600px';
1032 $height = !empty($attributes['height']) ? $attributes['height'] . 'px' : '600px';
1033 $gen_settings = get_option(EMBEDPRESS_PLG_NAME);
1034 $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by'];
1035 if (isset($attributes['powered_by'])) {
1036 $powered_by = $attributes['powered_by'];
1037 }
1038
1039 $aligns = [
1040 'left' => 'alignleft',
1041 'right' => 'alignright',
1042 'wide' => 'alignwide',
1043 'full' => 'alignfull'
1044 ];
1045 $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : '';
1046 $dimension = "width:$width;height:$height";
1047 ob_start();
1048 ?>
1049 <div class="embedpress-calendar-gutenberg embedpress-calendar ose-calendar <?php echo esc_attr($alignment) ?>" style="<?php echo esc_attr($dimension); ?>; max-width:100%;">
1050
1051 <?php
1052 if (!empty($url) && !$is_private) {
1053 ?>
1054 <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>
1055 <?php } else {
1056 if (is_embedpress_pro_active()) {
1057 echo Embedpress_Google_Helper::shortcode();
1058 }
1059 } ?>
1060 <?php do_action('embedpress_calendar_gutenberg_after_embed', $client_id, 'calendar', $attributes); ?>
1061
1062 <?php
1063 if ($powered_by) {
1064 printf('<p class="embedpress-el-powered" style="width:' . esc_attr($width) . '" >%s</p>', __('Powered By EmbedPress', 'embedpress'));
1065 } ?>
1066
1067 </div>
1068 <?php
1069 return ob_get_clean();
1070 }
1071
1072
1073
1074 function embedpress_document_block_scripts() {
1075 if (!is_admin() && has_block('embedpress/document')) {
1076 $script_handles = [
1077 'embedpress-front',
1078 'embedpress_documents_viewer_script'
1079 ];
1080
1081 foreach ($script_handles as $handle) {
1082 wp_enqueue_script($handle);
1083 }
1084 }
1085 }
1086 add_action('wp_enqueue_scripts', 'embedpress_document_block_scripts');
1087