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