PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 4.0.11
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v4.0.11
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 1 year ago dist 1 year ago plugin.php 1 year ago
plugin.php
1184 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_register_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 if(!function_exists('get_options_value')){
41 function get_options_value($key){
42 $g_settings = get_option(EMBEDPRESS_PLG_NAME);
43
44 if(isset($g_settings[$key])){
45 return $g_settings[$key];
46 }
47 return '';
48 }
49 }
50
51
52 /**
53 * Enqueue Gutenberg block assets for backend editor.
54 *
55 * @uses {wp-blocks} for block type registration & related functions.
56 * @uses {wp-element} for WP Element abstraction — structure of blocks.
57 * @uses {wp-i18n} to internationalize the block's text.
58 * @uses {wp-editor} for WP editor styles.
59 * @since 1.0.0
60 */
61
62 function embedpress_blocks_cgb_editor_assets()
63 { // phpcs:ignore
64 // Scripts.
65
66 $elements = (array) get_option(EMBEDPRESS_PLG_NAME . ":elements", []);
67 $g_blocks = isset($elements['gutenberg']) ? (array) $elements['gutenberg'] : [];
68
69 if (!wp_script_is('embedpress-pdfobject')) {
70 wp_enqueue_script(
71 'embedpress-pdfobject',
72 EMBEDPRESS_URL_ASSETS . 'js/pdfobject.min.js',
73 [],
74 EMBEDPRESS_VERSION
75 );
76 }
77
78 wp_enqueue_script(
79 'embedpress_blocks-cgb-block-js', // Handle.
80 EMBEDPRESS_GUTENBERG_DIR_URL . 'dist/blocks.build.js', // Block.build.js: We register the block here. Built with Webpack.
81 array('wp-blocks', 'wp-i18n', 'wp-element', 'wp-api-fetch', 'wp-is-shallow-equal', 'wp-editor', 'wp-components', 'embedpress-pdfobject'), // Dependencies, defined above.
82 filemtime(EMBEDPRESS_GUTENBERG_DIR_PATH . 'dist/blocks.build.js'), // Version: File modification time.
83 true // Enqueue the script in the footer.
84 );
85
86 if (!empty($g_blocks['document'])) {
87 wp_enqueue_script(
88 'embedpress_documents_viewer_script',
89 EMBEDPRESS_PLUGIN_DIR_URL . 'assets/js/documents-viewer-script.js',
90 array('wp-blocks', 'wp-dom-ready', 'wp-edit-post'),
91 EMBEDPRESS_PLUGIN_VERSION,
92 true
93 );
94 }
95
96 $wistia_labels = array(
97 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'),
98 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'),
99 'you_have_watched_it_before' => __('It looks like you\'ve watched<br />part of this video before!', 'embedpress'),
100 );
101 $elements = (array) get_option(EMBEDPRESS_PLG_NAME . ":elements", []);
102 $active_blocks = isset($elements['gutenberg']) ? (array) $elements['gutenberg'] : [];
103
104 $wistia_labels = json_encode($wistia_labels);
105 $wistia_options = null;
106 if (function_exists('embedpress_wisita_pro_get_options')) :
107 $wistia_options = embedpress_wisita_pro_get_options();
108 endif;
109 $pars_url = wp_parse_url(get_site_url());
110 $documents_cta_options = (array) get_option(EMBEDPRESS_PLG_NAME . ':document');
111 wp_localize_script('embedpress_blocks-cgb-block-js', 'embedpressObj', array(
112 'wistia_labels' => $wistia_labels,
113 'wisita_options' => $wistia_options,
114 'embedpress_powered_by' => apply_filters('embedpress_document_block_powered_by', true),
115 'embedpress_pro' => defined('EMBEDPRESS_PRO_PLUGIN_FILE'),
116 'twitch_host' => !empty($pars_url['host']) ? $pars_url['host'] : '',
117 'site_url' => site_url(),
118 'active_blocks' => $active_blocks,
119 'document_cta' => $documents_cta_options,
120 'pdf_renderer' => Helper::get_pdf_renderer(),
121 'is_pro_plugin_active' => defined('EMBEDPRESS_SL_ITEM_SLUG'),
122 'ajaxurl' => admin_url('admin-ajax.php'),
123 'source_nonce' => wp_create_nonce('source_nonce_embedpress'),
124 'can_upload_media' => current_user_can('upload_files'),
125 'EMBEDPRESS_URL_ASSETS' => EMBEDPRESS_URL_ASSETS,
126 'iframe_width' => get_options_value('enableEmbedResizeWidth'),
127 'iframe_height' => get_options_value('enableEmbedResizeHeight'),
128 'pdf_custom_color' => get_options_value('custom_color'),
129
130 ));
131
132 // Styles.
133 wp_enqueue_style(
134 'embedpress_blocks-cgb-block-editor-css', // Handle.
135 EMBEDPRESS_GUTENBERG_DIR_URL . 'dist/blocks.editor.build.css', // Block editor CSS.
136 array('wp-edit-blocks'), // Dependency to include the CSS after it.
137 filemtime(EMBEDPRESS_GUTENBERG_DIR_PATH . 'dist/blocks.editor.build.css') // Version: File modification time.
138 );
139 wp_enqueue_style('embedpress_blocks-cgb-style-css');
140 }
141
142 // Hook: Editor assets.
143 add_action('enqueue_block_editor_assets', 'embedpress_blocks_cgb_editor_assets');
144
145
146 function embedpress_block_category($categories, $post)
147 {
148 return array_merge(
149 $categories,
150 array(
151 array(
152 'slug' => 'embedpress',
153 'title' => 'EmbedPress',
154 'icon' => '',
155 ),
156 )
157 );
158 }
159 $wp_version = get_bloginfo('version', 'display');
160 if (version_compare($wp_version, '5.8', '>=')) {
161 add_filter('block_categories_all', 'embedpress_block_category', 10, 2);
162 } else {
163 add_filter('block_categories', 'embedpress_block_category', 10, 2);
164 }
165
166
167
168
169 foreach (glob(EMBEDPRESS_GUTENBERG_DIR_PATH . 'block-backend/*.php') as $block_logic) {
170 require_once $block_logic;
171 }
172
173 /**
174 * Registers the embedpress gutneberg block on server.
175 */
176
177 function embedpress_gutenberg_register_all_block()
178 {
179 if (function_exists('register_block_type')) :
180
181 $elements = (array) get_option(EMBEDPRESS_PLG_NAME . ":elements", []);
182 $g_blocks = isset($elements['gutenberg']) ? (array) $elements['gutenberg'] : [];
183 $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'];
184
185 foreach ($blocks_to_registers as $blocks_to_register) {
186 if (!empty($g_blocks[$blocks_to_register])) {
187 if ('embedpress' === $blocks_to_register) {
188 register_block_type('embedpress/embedpress', [
189 'render_callback' => 'embedpress_render_block',
190 // 'style' => [
191 // 'plyr',
192 // ],
193 // 'script' => [
194 // 'plyr.polyfilled',
195 // 'initplyr',
196 // 'vimeo-player',
197 // 'embedpress-front',
198 // 'embedpress-ads',
199 // ],
200 'attributes' => array(
201 'clientId' => [
202 'type' => 'string',
203 ],
204 'height' => [
205 'type' => 'string',
206 'default' => get_options_value('enableEmbedResizeHeight')
207 ],
208 'width' => [
209 'type' => 'string',
210 'default' => get_options_value('enableEmbedResizeWidth')
211 ],
212 'lockContent' => [
213 'type' => 'boolean',
214 'default' => false
215 ],
216 'lockHeading' => [
217 'type' => 'string',
218 'default' => 'Content Locked'
219 ],
220 'lockSubHeading' => [
221 'type' => 'string',
222 'default' => 'Content is locked and requires password to access it.'
223 ],
224 'lockErrorMessage' => [
225 'type' => 'string',
226 'default' => 'Oops, that wasn\'t the right password. Try again.'
227 ],
228 'passwordPlaceholder' => [
229 'type' => 'string',
230 'default' => 'Password'
231 ],
232 'submitButtonText' => [
233 'type' => 'string',
234 'default' => 'Unlock'
235 ],
236 'submitUnlockingText' => [
237 'type' => 'string',
238 'default' => 'Unlocking'
239 ],
240 'enableFooterMessage' => [
241 'type' => 'boolean',
242 'default' => false
243 ],
244 'footerMessage' => [
245 'type' => 'string',
246 'default' => 'In case you don\'t have the password, kindly reach out to content owner or administrator to request access.'
247 ],
248 'contentPassword' => [
249 'type' => 'string',
250 'default' => '',
251 ],
252 'contentShare' => [
253 'type' => 'boolean',
254 'default' => false
255 ],
256 'sharePosition' => [
257 'type' => 'string',
258 'default' => 'right'
259 ],
260 'customTitle' => [
261 'type' => 'string',
262 'default' => ''
263 ],
264 'customDescription' => [
265 'type' => 'string',
266 'default' => ''
267 ],
268 'customThumbnail' => [
269 'type' => 'string',
270 'default' => ''
271 ],
272
273 'videosize' => [
274 'type' => 'string',
275 'default' => 'fixed'
276 ],
277
278 'loadmore' => [
279 'type' => 'boolean',
280 'default' => false
281 ],
282 //Youtube Attributes
283 'starttime' => [
284 'type' => 'string',
285 ],
286 'endtime' => [
287 'type' => 'string',
288 ],
289 'autoplay' => [
290 'type' => 'boolean',
291 'default' => false
292 ],
293 'controls' => [
294 'type' => 'string',
295 ],
296 'progressbarcolor' => [
297 'type' => 'string',
298 ],
299 'videoannotations' => [
300 'type' => 'string',
301 ],
302 'closedcaptions' => [
303 'type' => 'boolean',
304 'default' => true
305 ],
306 'relatedvideos' => [
307 'type' => 'boolean',
308 'default' => true
309 ],
310 'fullscreen' => [
311 'type' => 'boolean',
312 'default' => true
313 ],
314
315 'modestbranding' => [
316 'type' => 'string',
317 ],
318 'pagesize' => [
319 'type' => 'number',
320 ],
321 // custom player attributes
322 'customPlayer' => [
323 'type' => 'boolean',
324 'default' => false
325 ],
326
327 'posterThumbnail' => [
328 'type' => 'string',
329 'default' => ''
330 ],
331
332 'playerPreset' => [
333 'type' => 'string',
334 'default' => ''
335 ],
336
337 'playerColor' => [
338 'type' => 'string',
339 'default' => '#2e2e99'
340 ],
341
342 'playerPip' => [
343 'type' => 'boolean',
344 'default' => false
345 ],
346
347 'playerRestart' => [
348 'type' => 'boolean',
349 'default' => true
350 ],
351
352 'playerRewind' => [
353 'type' => 'boolean',
354 'default' => true
355 ],
356
357 'playerFastForward' => [
358 'type' => 'boolean',
359 'default' => true
360 ],
361 'playerTooltip' => [
362 'type' => 'boolean',
363 'default' => true
364 ],
365 'playerHideControls' => [
366 'type' => 'boolean',
367 'default' => true
368 ],
369 'playerDownload' => [
370 'type' => 'boolean',
371 'default' => true
372 ],
373 //Wistia Attributes
374 'wstarttime' => [
375 'type' => 'string',
376 ],
377 'wautoplay' => [
378 'type' => 'boolean',
379 'default' => true
380 ],
381 'scheme' => [
382 'type' => 'string',
383 ],
384 'captions' => [
385 'type' => 'boolean',
386 'default' => true
387 ],
388 'playbutton' => [
389 'type' => 'boolean',
390 'default' => true
391 ],
392 'smallplaybutton' => [
393 'type' => 'boolean',
394 'default' => true
395 ],
396 'playbar' => [
397 'type' => 'boolean',
398 'default' => true
399 ],
400 'resumable' => [
401 'type' => 'boolean',
402 'default' => true
403 ],
404 'wistiafocus' => [
405 'type' => 'boolean',
406 'default' => true
407 ],
408 'volumecontrol' => [
409 'type' => 'boolean',
410 'default' => true
411 ],
412 'volume' => [
413 'type' => 'number',
414 'default' => 100
415 ],
416 'rewind' => [
417 'type' => 'boolean',
418 'default' => false
419 ],
420 'wfullscreen' => [
421 'type' => 'boolean',
422 'default' => true
423 ],
424
425 // Vimeo attributes
426 'vstarttime' => [
427 'type' => 'string',
428 ],
429 'vautoplay' => [
430 'type' => 'boolean',
431 'default' => false
432 ],
433 'vscheme' => [
434 'type' => 'string',
435 ],
436 'vtitle' => [
437 'type' => 'boolean',
438 'default' => true
439 ],
440 'vauthor' => [
441 'type' => 'boolean',
442 'default' => true
443 ],
444 'vavatar' => [
445 'type' => 'boolean',
446 'default' => true
447 ],
448 'vloop' => [
449 'type' => 'boolean',
450 'default' => false
451 ],
452 'vautopause' => [
453 'type' => 'boolean',
454 'default' => false
455 ],
456 'vdnt' => [
457 'type' => 'boolean',
458 'default' => false
459 ],
460
461 // instaFeed attributes
462 'instaLayout' => [
463 'type' => 'string',
464 'default' => 'insta-grid',
465 ],
466 'instafeedFeedType' => [
467 'type' => 'string',
468 'default' => 'user_account_type',
469 ],
470 'instafeedAccountType' => [
471 'type' => 'string',
472 'default' => 'personal',
473 ],
474 'instafeedProfileImage' => [
475 'type' => 'boolean',
476 'default' => true,
477 ],
478 'instafeedProfileImageUrl' => [
479 'type' => 'string',
480 'default' => '',
481 ],
482 'instafeedFollowBtn' => [
483 'type' => 'boolean',
484 'default' => true,
485 ],
486 'instafeedFollowBtnLabel' => [
487 'type' => 'string',
488 'default' => 'Follow',
489 ],
490 'instafeedPostsCount' => [
491 'type' => 'boolean',
492 'default' => true,
493 ],
494 'instafeedPostsCountText' => [
495 'type' => 'string',
496 'default' => '[count] posts',
497 ],
498 'instafeedFollowersCount' => [
499 'type' => 'boolean',
500 'default' => true,
501 ],
502 'instafeedFollowersCountText' => [
503 'type' => 'string',
504 'default' => '[count] followers',
505 ],
506 'instafeedAccName' => [
507 'type' => 'boolean',
508 'default' => true,
509 ],
510 'instafeedColumns' => [
511 'type' => 'string',
512 'default' => '3',
513 ],
514 'instafeedColumnsGap' => [
515 'type' => 'string',
516 'default' => '5',
517 ],
518 'instafeedPostsPerPage' => [
519 'type' => 'string',
520 'default' => '12',
521 ],
522 'instafeedTab' => [
523 'type' => 'boolean',
524 'default' => true,
525 ],
526 'instafeedLikesCount' => [
527 'type' => 'boolean',
528 'default' => true,
529 ],
530 'instafeedCommentsCount' => [
531 'type' => 'boolean',
532 'default' => true,
533 ],
534 'instafeedPopup' => [
535 'type' => 'boolean',
536 'default' => true,
537 ],
538 'instafeedPopupFollowBtn' => [
539 'type' => 'boolean',
540 'default' => true,
541 ],
542 'instafeedPopupFollowBtnLabel' => [
543 'type' => 'string',
544 'default' => 'Follow',
545 ],
546 'instafeedLoadmore' => [
547 'type' => 'boolean',
548 'default' => true,
549 ],
550 'instafeedLoadmoreLabel' => [
551 'type' => 'string',
552 'default' => 'Load More',
553 ],
554 'slidesShow' => [
555 'type' => 'string',
556 'default' => '4',
557 ],
558 'slidesScroll' => [
559 'type' => 'string',
560 'default' => '4',
561 ],
562 'carouselAutoplay' => [
563 'type' => 'boolean',
564 'default' => false,
565 ],
566 'autoplaySpeed' => [
567 'type' => 'string',
568 'default' => '3000',
569 ],
570 'transitionSpeed' => [
571 'type' => 'string',
572 'default' => '1000',
573 ],
574 'carouselLoop' => [
575 'type' => 'boolean',
576 'default' => true,
577 ],
578 'carouselArrows' => [
579 'type' => 'boolean',
580 'default' => true,
581 ],
582 'carouselSpacing' => [
583 'type' => 'string',
584 'default' => '0',
585 ],
586 'carouselDots' => [
587 'type' => 'boolean',
588 'default' => false,
589 ],
590 // Calendly attributes
591 'cEmbedType' => array(
592 'type' => 'string',
593 'default' => 'inline'
594 ),
595 'calendlyData' => array(
596 'type' => 'boolean',
597 'default' => false
598 ),
599 'hideCookieBanner' => array(
600 'type' => 'boolean',
601 'default' => false
602 ),
603 'hideEventTypeDetails' => array(
604 'type' => 'boolean',
605 'default' => false
606 ),
607 'cBackgroundColor' => array(
608 'type' => 'string',
609 'default' => 'ffffff'
610 ),
611 'cTextColor' => array(
612 'type' => 'string',
613 'default' => '1A1A1A'
614 ),
615 'cButtonLinkColor' => array(
616 'type' => 'string',
617 'default' => '0000FF'
618 ),
619 'cPopupButtonText' => array(
620 'type' => 'string',
621 'default' => 'Schedule time with me'
622 ),
623 'cPopupButtonBGColor' => array(
624 'type' => 'string',
625 'default' => '#0000FF'
626 ),
627 'cPopupButtonTextColor' => array(
628 'type' => 'string',
629 'default' => '#FFFFFF'
630 ),
631 'cPopupLinkText' => array(
632 'type' => 'string',
633 'default' => 'Schedule time with me'
634 ),
635
636 //Ad attributes
637 'adManager' => [
638 'type' => 'boolean',
639 'default' => false
640 ],
641 'adSource' => [
642 'type' => 'string',
643 'default' => 'video'
644 ],
645 'adContent' => [
646 'type' => 'object',
647 ],
648 'adWidth' => array(
649 'type' => 'string',
650 'default' => '300'
651 ),
652 'adHeight' => array(
653 'type' => 'string',
654 'default' => '200'
655 ),
656 'adXPosition' => array(
657 'type' => 'number',
658 'default' => 25
659 ),
660 'adYPosition' => array(
661 'type' => 'number',
662 'default' => 10
663 ),
664 'adUrl' => [
665 'type' => 'string',
666 'default' => ''
667 ],
668 'adStart' => [
669 'type' => 'string',
670 'default' => '10'
671 ],
672 'adSkipButton' => [
673 'type' => 'boolean',
674 'default' => true
675 ],
676 'adSkipButtonAfter' => [
677 'type' => 'string',
678 'default' => '5'
679 ]
680
681 ),
682 ]);
683 } elseif ('embedpress-pdf' === $blocks_to_register) {
684 register_block_type('embedpress/embedpress-pdf', [
685 'attributes' => array(
686 'clientId' => [
687 'type' => 'string',
688 ],
689 // 'height' => [
690 // 'type' => 'string',
691 // 'default' => (int) get_options_value('enableEmbedResizeHeight')
692 // ],
693 // 'width' => [
694 // 'type' => 'string',
695 // 'default' => (int) get_options_value('enableEmbedResizeWidth')
696 // ],
697 'customColor' => [
698 'type' => 'string',
699 'default' => get_options_value('custom_color')
700 ],
701 'powered_by' => [
702 'type' => 'boolean',
703 'default' => true
704 ],
705 'lockContent' => [
706 'type' => 'boolean',
707 'default' => false
708 ],
709 'lockHeading' => [
710 'type' => 'string',
711 'default' => 'Content Locked'
712 ],
713 'lockSubHeading' => [
714 'type' => 'string',
715 'default' => 'Content is locked and requires password to access it.'
716 ],
717 'passwordPlaceholder' => [
718 'type' => 'string',
719 'default' => 'Password'
720 ],
721 'submitButtonText' => [
722 'type' => 'string',
723 'default' => 'Unlock'
724 ],
725 'submitUnlockingText' => [
726 'type' => 'string',
727 'default' => 'Unlocking'
728 ],
729 'lockErrorMessage' => [
730 'type' => 'string',
731 'default' => 'Oops, that wasn\'t the right password. Try again.'
732 ],
733 'enableFooterMessage' => [
734 'type' => 'boolean',
735 'default' => false
736 ],
737 'footerMessage' => [
738 'type' => 'string',
739 'default' => 'In case you don\'t have the password, kindly reach out to content owner or administrator to request access.'
740 ],
741 'contentPassword' => [
742 'type' => 'string',
743 'default' => ''
744 ],
745 'contentShare' => [
746 'type' => 'boolean',
747 'default' => false
748 ],
749 'sharePosition' => [
750 'type' => 'string',
751 'default' => 'right'
752 ],
753 'presentation' => [
754 'type' => "boolean",
755 'default' => true,
756 ],
757 'lazyLoad' => [
758 'type' => "boolean",
759 'default' => false,
760 ],
761
762 'position' => [
763 'type' => "string",
764 'default' => 'top',
765 ],
766 'flipbook_toolbar_position' => [
767 'type' => "string",
768 'default' => 'bottom',
769 ],
770
771 'print' => [
772 'type' => "boolean",
773 'default' => true,
774 ],
775
776 'download' => [
777 'type' => "boolean",
778 'default' => true,
779 ],
780 'open' => [
781 'type' => "boolean",
782 'default' => true,
783 ],
784 'copy_text' => [
785 'type' => "boolean",
786 'default' => true,
787 ],
788 'add_text' => [
789 'type' => "boolean",
790 'default' => true,
791 ],
792 'draw' => [
793 'type' => "boolean",
794 'default' => true,
795 ],
796 'toolbar' => [
797 'type' => "boolean",
798 'default' => true,
799 ],
800 'doc_details' => [
801 'type' => "boolean",
802 'default' => true,
803 ],
804 'doc_rotation' => [
805 'type' => "boolean",
806 'default' => true,
807 ],
808 'add_image' => [
809 'type' => "boolean",
810 'default' => true,
811 ],
812 'unitoption' => [
813 'type' => "string",
814 'default' => '%',
815 ],
816 'zoomIn' => [
817 'type' => "boolean",
818 'default' => true,
819 ],
820 'zoomOut' => [
821 'type' => "boolean",
822 'default' => true,
823 ],
824 'fitView' => [
825 'type' => "boolean",
826 'default' => true,
827 ],
828 'bookmark' => [
829 'type' => "boolean",
830 'default' => true,
831 ],
832
833 //Ad attributes
834 'adManager' => [
835 'type' => 'boolean',
836 'default' => false
837 ],
838 'adSource' => [
839 'type' => 'string',
840 'default' => 'video'
841 ],
842 'adContent' => [
843 'type' => 'object',
844 ],
845 'adWidth' => array(
846 'type' => 'string',
847 'default' => '300'
848 ),
849 'adHeight' => array(
850 'type' => 'string',
851 'default' => '200'
852 ),
853 'adXPosition' => array(
854 'type' => 'number',
855 'default' => 25
856 ),
857 'adYPosition' => array(
858 'type' => 'number',
859 'default' => 20
860 ),
861 'adUrl' => [
862 'type' => 'string',
863 'default' => ''
864 ],
865 'adStart' => [
866 'type' => 'string',
867 'default' => '10'
868 ],
869 'adSkipButton' => [
870 'type' => 'boolean',
871 'default' => true
872 ],
873 'adSkipButtonAfter' => [
874 'type' => 'string',
875 'default' => '5'
876 ]
877 ),
878 'render_callback' => 'embedpress_pdf_render_block',
879 ]);
880 } elseif ('embedpress-calendar' === $blocks_to_register) {
881 register_block_type('embedpress/embedpress-calendar', [
882 'render_callback' => 'embedpress_calendar_render_block',
883 ]);
884 } elseif ('document' === $blocks_to_register) {
885 register_block_type('embedpress/' . $blocks_to_register, [
886 // 'render_callback' => 'embedpress_document_render_block',
887 ]);
888 } else {
889 register_block_type('embedpress/' . $blocks_to_register);
890 }
891 } else {
892
893 if (WP_Block_Type_Registry::get_instance()->is_registered('embedpress/' . $blocks_to_register)) {
894 unregister_block_type('embedpress/' . $blocks_to_register);
895 }
896 }
897 }
898
899 endif;
900 }
901
902 add_action('init', 'embedpress_gutenberg_register_all_block');
903
904 function getParamData($attributes)
905 {
906
907 $urlParamData = array(
908 'themeMode' => !empty($attributes['themeMode']) ? $attributes['themeMode'] : 'default',
909 'toolbar' => !empty($attributes['toolbar']) ? 'true' : 'false',
910 'position' => $attributes['position'],
911 'presentation' => !empty($attributes['presentation']) ? 'true' : 'false',
912 'lazyLoad' => !empty($attributes['lazyLoad']) ? 'true' : 'false',
913 'download' => !empty($attributes['download']) ? 'true' : 'false',
914 'copy_text' => !empty($attributes['copy_text']) ? 'true' : 'false',
915 'add_text' => !empty($attributes['add_text']) ? 'true' : 'false',
916 'draw' => !empty($attributes['draw']) ? 'true' : 'false',
917 'doc_rotation' => !empty($attributes['doc_rotation']) ? 'true' : 'false',
918 'add_image' => !empty($attributes['add_image']) ? 'true' : 'false',
919 'doc_details' => !empty($attributes['doc_details']) ? 'true' : 'false',
920 'zoom_in' => !empty($attributes['zoomIn']) ? 'true' : 'false',
921 'zoom_out' => !empty($attributes['zoomOut']) ? 'true' : 'false',
922 'fit_view' => !empty($attributes['fitView']) ? 'true' : 'false',
923 'bookmark' => !empty($attributes['bookmark']) ? 'true' : 'false',
924 'flipbook_toolbar_position' => !empty($attributes['flipbook_toolbar_position']) ? $attributes['flipbook_toolbar_position'] : 'bottom',
925 );
926
927 if ($urlParamData['themeMode'] == 'custom') {
928 $urlParamData['customColor'] = !empty($attributes['customColor']) ? $attributes['customColor'] : '#403A81';
929 }
930
931 if (isset($attributes['viewerStyle']) && $attributes['viewerStyle'] == 'flip-book') {
932 return "&key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), 'UTF-8'));
933 }
934
935 return "#key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), 'UTF-8'));
936 }
937
938 function embedpress_pdf_block_scripts($attributes) {
939
940 $script_handles = [];
941
942 $script_handles[] = 'embedpress-pdfobject';
943 $script_handles[] = 'embedpress-front';
944
945 if(!empty($attributes['adManager'])){
946 $script_handles[] = 'embedpress-ads';
947 }
948
949 foreach ($script_handles as $handle) {
950 wp_enqueue_script($handle);
951 }
952
953 $style_handles = [
954 'embedpress_blocks-cgb-style-css',
955 'embedpress-style'
956 ];
957
958 foreach ($style_handles as $handle) {
959 wp_enqueue_style($handle);
960 }
961
962 }
963
964 function embedpress_pdf_render_block($attributes)
965 {
966 embedpress_pdf_block_scripts($attributes);
967
968 if (!empty($attributes['href'])) {
969 $renderer = Helper::get_pdf_renderer();
970 $pdf_url = $attributes['href'];
971 $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-pdf-' . rand(100, 10000);
972 $client_id = md5($id);
973
974
975 $unitoption = !empty($attributes['unitoption']) ? $attributes['unitoption'] : 'px';
976 $width = !empty($attributes['width']) ? $attributes['width'] . $unitoption : get_options_value('enableEmbedResizeWidth').'px';
977
978 if ($unitoption == '%') {
979 $width_class = ' ep-percentage-width';
980 } else {
981 $width_class = 'ep-fixed-width';
982 }
983 $content_share_class = '';
984 $share_position_class = '';
985 $share_position = isset($attributes['sharePosition']) ? $attributes['sharePosition'] : 'right';
986
987 if (!empty($attributes['contentShare'])) {
988 $content_share_class = 'ep-content-share-enabled';
989 $share_position_class = 'ep-share-position-' . $share_position;
990 }
991
992 $password_correct = isset($_COOKIE['password_correct_' . $client_id]) ? $_COOKIE['password_correct_' . $client_id] : '';
993 $hash_pass = hash('sha256', wp_salt(32) . md5(isset($attributes['contentPassword']) ? $attributes['contentPassword'] : ''));
994
995
996 $content_protection_class = 'ep-content-protection-enabled';
997 if (empty($attributes['lockContent']) || empty($attributes['contentPassword']) || $hash_pass === $password_correct) {
998 $content_protection_class = 'ep-content-protection-disabled';
999 }
1000
1001
1002
1003 $height = !empty($attributes['height']) ? $attributes['height'] . 'px' : get_options_value('enableEmbedResizeHeight').'px';
1004 $gen_settings = get_option(EMBEDPRESS_PLG_NAME);
1005
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 $src = $renderer . ((strpos($renderer, '?') == false) ? '?' : '&') . 'file=' . urlencode($attributes['href']) . getParamData($attributes);
1012
1013 $pass_hash_key = isset($attributes['contentPassword']) ? md5($attributes['contentPassword']) : '';
1014
1015 $aligns = [
1016 'left' => 'ep-alignleft',
1017 'right' => 'ep-alignright',
1018 'center' => 'ep-aligncenter',
1019 'wide' => 'ep-alignwide',
1020 'full' => 'ep-alignfull'
1021 ];
1022 $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : '';
1023 $dimension = "width:$width;height:$height";
1024 ob_start();
1025 ?>
1026
1027
1028 <?php
1029
1030 $url = !empty($attributes['href']) ? $attributes['href'] : '';
1031
1032 $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> ';
1033 if(isset($attributes['viewerStyle']) && $attributes['viewerStyle'] === 'flip-book') {
1034 $src = urlencode($url).getParamData($attributes);
1035 $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(EMBEDPRESS_URL_ASSETS . 'pdf-flip-book/viewer.html?file='.$src).'" frameborder="0" oncontextmenu="return false;"></iframe> ';
1036 }
1037 if ($powered_by) {
1038 $embed_code .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
1039 }
1040
1041 $adsAtts = '';
1042 if (!empty($attributes['adManager'])) {
1043 $ad = base64_encode(json_encode($attributes));
1044 $adsAtts = "data-sponsored-id=$client_id data-sponsored-attrs=$ad class=ad-mask";
1045 }
1046 ?>
1047
1048 <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); ?> ">
1049 <div class="embedpress-inner-iframe <?php if ($unitoption === '%') {
1050 echo esc_attr('emebedpress-unit-percent');
1051 } ?> ep-doc-<?php echo esc_attr($client_id); ?>" <?php if ($unitoption === '%' && !empty($attributes['width'])) {
1052 $style_attr = 'max-width:' . $attributes['width'] . '%';
1053 } else {
1054 $style_attr = 'max-width:100%';
1055 } ?> style="<?php echo esc_attr($style_attr); ?>" id="<?php echo esc_attr($id); ?>">
1056 <div <?php echo esc_attr($adsAtts); ?>>
1057 <?php
1058 do_action('embedpress_pdf_gutenberg_after_embed', $client_id, 'pdf', $attributes, $pdf_url);
1059 $embed = $embed_code;
1060 if (empty($attributes['lockContent']) || empty($attributes['contentPassword']) || (!empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct))) {
1061
1062 $custom_thumbnail = isset($attributes['customThumbnail']) ? $attributes['customThumbnail'] : '';
1063
1064 echo '<div class="ep-embed-content-wraper">';
1065 $embed = '<div class="position-' . esc_attr($share_position) . '-wraper gutenberg-pdf-wraper">';
1066 $embed .= $embed_code;
1067 $embed .= '</div>';
1068
1069 if (!empty($attributes['contentShare'])) {
1070 $content_id = $attributes['id'];
1071 $embed .= Helper::embed_content_share($content_id, $attributes);
1072 }
1073 echo $embed;
1074 echo '</div>';
1075 } else {
1076 if (!empty($attributes['contentShare'])) {
1077 $content_id = $attributes['clientId'];
1078 $embed = '<div class="position-' . esc_attr($share_position) . '-wraper gutenberg-pdf-wraper">';
1079 $embed .= $embed_code;
1080 $embed .= '</div>';
1081 $embed .= Helper::embed_content_share($content_id, $attributes);
1082 }
1083 echo '<div class="ep-embed-content-wraper">';
1084 Helper::display_password_form($client_id, $embed, $pass_hash_key, $attributes);
1085 echo '</div>';
1086 }
1087 ?>
1088
1089 <?php
1090 if(!empty($attributes['adManager'])) {
1091 $embed .= Helper::generateAdTemplate($client_id, $attributes, 'gutenberg');
1092 }
1093 ?>
1094 </div>
1095 </div>
1096 </div>
1097 <?php
1098 return ob_get_clean();
1099 }
1100 }
1101
1102 function isGoogleCalendar($url) {
1103 $pattern = '/^https:\/\/calendar\.google\.com\/calendar\/embed\?.*$/';
1104 return preg_match($pattern, $url);
1105 }
1106
1107 function embedpress_calendar_render_block($attributes)
1108 {
1109
1110 $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-calendar-' . rand(100, 10000);
1111 $url = !empty($attributes['url']) ? $attributes['url'] : '';
1112
1113 if(!isGoogleCalendar($url))
1114 {
1115 return;
1116 }
1117
1118 $is_private = isset($attributes['is_public']);
1119 $client_id = md5($id);
1120 $width = !empty($attributes['width']) ? $attributes['width'] . 'px' : '600px';
1121 $height = !empty($attributes['height']) ? $attributes['height'] . 'px' : '600px';
1122 $gen_settings = get_option(EMBEDPRESS_PLG_NAME);
1123 $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by'];
1124 if (isset($attributes['powered_by'])) {
1125 $powered_by = $attributes['powered_by'];
1126 }
1127
1128 $aligns = [
1129 'left' => 'alignleft',
1130 'right' => 'alignright',
1131 'wide' => 'alignwide',
1132 'full' => 'alignfull'
1133 ];
1134 $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : '';
1135 $dimension = "width:$width;height:$height";
1136 ob_start();
1137 ?>
1138 <div class="embedpress-calendar-gutenberg embedpress-calendar ose-calendar <?php echo esc_attr($alignment) ?>" style="<?php echo esc_attr($dimension); ?>; max-width:100%;">
1139
1140 <?php
1141 if (!empty($url) && !$is_private) {
1142 ?>
1143 <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>
1144 <?php } else {
1145 if (is_embedpress_pro_active()) {
1146 echo Embedpress_Google_Helper::shortcode();
1147 }
1148 } ?>
1149 <?php do_action('embedpress_calendar_gutenberg_after_embed', $client_id, 'calendar', $attributes); ?>
1150
1151 <?php
1152 if ($powered_by) {
1153 printf('<p class="embedpress-el-powered" style="width:' . esc_attr($width) . '" >%s</p>', __('Powered By EmbedPress', 'embedpress'));
1154 } ?>
1155
1156 </div>
1157 <?php
1158 return ob_get_clean();
1159 }
1160
1161 function embedpress_document_block_scripts() {
1162 if (!is_admin() && has_block('embedpress/document')) {
1163 $script_handles = [
1164 'embedpress-pdfobject',
1165 'embedpress-front',
1166 'embedpress_documents_viewer_script'
1167 ];
1168
1169 foreach ($script_handles as $handle) {
1170 wp_enqueue_script($handle);
1171 }
1172
1173 $style_handles = [
1174 'embedpress_blocks-cgb-style-css',
1175 'embedpress-style'
1176 ];
1177
1178 foreach ($style_handles as $handle) {
1179 wp_enqueue_style($handle);
1180 }
1181 }
1182 }
1183 add_action('wp_enqueue_scripts', 'embedpress_document_block_scripts');
1184