PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 4.0.7
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v4.0.7
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 2 years ago
plugin.php
1176 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
755 'position' => [
756 'type' => "string",
757 'default' => 'top',
758 ],
759 'flipbook_toolbar_position' => [
760 'type' => "string",
761 'default' => 'bottom',
762 ],
763
764 'print' => [
765 'type' => "boolean",
766 'default' => true,
767 ],
768
769 'download' => [
770 'type' => "boolean",
771 'default' => true,
772 ],
773 'open' => [
774 'type' => "boolean",
775 'default' => true,
776 ],
777 'copy_text' => [
778 'type' => "boolean",
779 'default' => true,
780 ],
781 'add_text' => [
782 'type' => "boolean",
783 'default' => true,
784 ],
785 'draw' => [
786 'type' => "boolean",
787 'default' => true,
788 ],
789 'toolbar' => [
790 'type' => "boolean",
791 'default' => true,
792 ],
793 'doc_details' => [
794 'type' => "boolean",
795 'default' => true,
796 ],
797 'doc_rotation' => [
798 'type' => "boolean",
799 'default' => true,
800 ],
801 'add_image' => [
802 'type' => "boolean",
803 'default' => true,
804 ],
805 'unitoption' => [
806 'type' => "string",
807 'default' => '%',
808 ],
809 'zoomIn' => [
810 'type' => "boolean",
811 'default' => true,
812 ],
813 'zoomOut' => [
814 'type' => "boolean",
815 'default' => true,
816 ],
817 'fitView' => [
818 'type' => "boolean",
819 'default' => true,
820 ],
821 'bookmark' => [
822 'type' => "boolean",
823 'default' => true,
824 ],
825
826 //Ad attributes
827 'adManager' => [
828 'type' => 'boolean',
829 'default' => false
830 ],
831 'adSource' => [
832 'type' => 'string',
833 'default' => 'video'
834 ],
835 'adContent' => [
836 'type' => 'object',
837 ],
838 'adWidth' => array(
839 'type' => 'string',
840 'default' => '300'
841 ),
842 'adHeight' => array(
843 'type' => 'string',
844 'default' => '200'
845 ),
846 'adXPosition' => array(
847 'type' => 'number',
848 'default' => 25
849 ),
850 'adYPosition' => array(
851 'type' => 'number',
852 'default' => 20
853 ),
854 'adUrl' => [
855 'type' => 'string',
856 'default' => ''
857 ],
858 'adStart' => [
859 'type' => 'string',
860 'default' => '10'
861 ],
862 'adSkipButton' => [
863 'type' => 'boolean',
864 'default' => true
865 ],
866 'adSkipButtonAfter' => [
867 'type' => 'string',
868 'default' => '5'
869 ]
870 ),
871 'render_callback' => 'embedpress_pdf_render_block',
872 ]);
873 } elseif ('embedpress-calendar' === $blocks_to_register) {
874 register_block_type('embedpress/embedpress-calendar', [
875 'render_callback' => 'embedpress_calendar_render_block',
876 ]);
877 } elseif ('document' === $blocks_to_register) {
878 register_block_type('embedpress/' . $blocks_to_register, [
879 // 'render_callback' => 'embedpress_document_render_block',
880 ]);
881 } else {
882 register_block_type('embedpress/' . $blocks_to_register);
883 }
884 } else {
885
886 if (WP_Block_Type_Registry::get_instance()->is_registered('embedpress/' . $blocks_to_register)) {
887 unregister_block_type('embedpress/' . $blocks_to_register);
888 }
889 }
890 }
891
892 endif;
893 }
894
895 add_action('init', 'embedpress_gutenberg_register_all_block');
896
897 function getParamData($attributes)
898 {
899
900 $urlParamData = array(
901 'themeMode' => !empty($attributes['themeMode']) ? $attributes['themeMode'] : 'default',
902 'toolbar' => !empty($attributes['toolbar']) ? 'true' : 'false',
903 'position' => $attributes['position'],
904 'presentation' => !empty($attributes['presentation']) ? 'true' : 'false',
905 'download' => !empty($attributes['download']) ? 'true' : 'false',
906 'copy_text' => !empty($attributes['copy_text']) ? 'true' : 'false',
907 'add_text' => !empty($attributes['add_text']) ? 'true' : 'false',
908 'draw' => !empty($attributes['draw']) ? 'true' : 'false',
909 'doc_rotation' => !empty($attributes['doc_rotation']) ? 'true' : 'false',
910 'add_image' => !empty($attributes['add_image']) ? 'true' : 'false',
911 'doc_details' => !empty($attributes['doc_details']) ? 'true' : 'false',
912 'zoom_in' => !empty($attributes['zoomIn']) ? 'true' : 'false',
913 'zoom_out' => !empty($attributes['zoomOut']) ? 'true' : 'false',
914 'fit_view' => !empty($attributes['fitView']) ? 'true' : 'false',
915 'bookmark' => !empty($attributes['bookmark']) ? 'true' : 'false',
916 'flipbook_toolbar_position' => !empty($attributes['flipbook_toolbar_position']) ? $attributes['flipbook_toolbar_position'] : 'bottom',
917 );
918
919 if ($urlParamData['themeMode'] == 'custom') {
920 $urlParamData['customColor'] = !empty($attributes['customColor']) ? $attributes['customColor'] : '#403A81';
921 }
922
923 if (isset($attributes['viewerStyle']) && $attributes['viewerStyle'] == 'flip-book') {
924 return "&key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), 'UTF-8'));
925 }
926
927 return "#key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), 'UTF-8'));
928 }
929
930 function embedpress_pdf_block_scripts($attributes) {
931
932 $script_handles = [];
933
934 $script_handles[] = 'embedpress-pdfobject';
935 $script_handles[] = 'embedpress-front';
936
937 if(!empty($attributes['adManager'])){
938 $script_handles[] = 'embedpress-ads';
939 }
940
941 foreach ($script_handles as $handle) {
942 wp_enqueue_script($handle);
943 }
944
945 $style_handles = [
946 'embedpress_blocks-cgb-style-css',
947 'embedpress-style'
948 ];
949
950 foreach ($style_handles as $handle) {
951 wp_enqueue_style($handle);
952 }
953
954 }
955
956 function embedpress_pdf_render_block($attributes)
957 {
958 embedpress_pdf_block_scripts($attributes);
959
960 if (!empty($attributes['href'])) {
961 $renderer = Helper::get_pdf_renderer();
962 $pdf_url = $attributes['href'];
963 $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-pdf-' . rand(100, 10000);
964 $client_id = md5($id);
965
966
967 $unitoption = !empty($attributes['unitoption']) ? $attributes['unitoption'] : 'px';
968 $width = !empty($attributes['width']) ? $attributes['width'] . $unitoption : get_options_value('enableEmbedResizeWidth').'px';
969
970 if ($unitoption == '%') {
971 $width_class = ' ep-percentage-width';
972 } else {
973 $width_class = 'ep-fixed-width';
974 }
975 $content_share_class = '';
976 $share_position_class = '';
977 $share_position = isset($attributes['sharePosition']) ? $attributes['sharePosition'] : 'right';
978
979 if (!empty($attributes['contentShare'])) {
980 $content_share_class = 'ep-content-share-enabled';
981 $share_position_class = 'ep-share-position-' . $share_position;
982 }
983
984 $password_correct = isset($_COOKIE['password_correct_' . $client_id]) ? $_COOKIE['password_correct_' . $client_id] : '';
985 $hash_pass = hash('sha256', wp_salt(32) . md5(isset($attributes['contentPassword']) ? $attributes['contentPassword'] : ''));
986
987
988 $content_protection_class = 'ep-content-protection-enabled';
989 if (empty($attributes['lockContent']) || empty($attributes['contentPassword']) || $hash_pass === $password_correct) {
990 $content_protection_class = 'ep-content-protection-disabled';
991 }
992
993
994
995 $height = !empty($attributes['height']) ? $attributes['height'] . 'px' : get_options_value('enableEmbedResizeHeight').'px';
996 $gen_settings = get_option(EMBEDPRESS_PLG_NAME);
997
998 $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by'];
999 if (isset($attributes['powered_by'])) {
1000 $powered_by = $attributes['powered_by'];
1001 }
1002
1003 $src = $renderer . ((strpos($renderer, '?') == false) ? '?' : '&') . 'file=' . urlencode($attributes['href']) . getParamData($attributes);
1004
1005 $pass_hash_key = isset($attributes['contentPassword']) ? md5($attributes['contentPassword']) : '';
1006
1007 $aligns = [
1008 'left' => 'ep-alignleft',
1009 'right' => 'ep-alignright',
1010 'center' => 'ep-aligncenter',
1011 'wide' => 'ep-alignwide',
1012 'full' => 'ep-alignfull'
1013 ];
1014 $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : '';
1015 $dimension = "width:$width;height:$height";
1016 ob_start();
1017 ?>
1018
1019
1020 <?php
1021
1022 $url = !empty($attributes['href']) ? $attributes['href'] : '';
1023
1024 $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> ';
1025 if(isset($attributes['viewerStyle']) && $attributes['viewerStyle'] === 'flip-book') {
1026 $src = urlencode($url).getParamData($attributes);
1027 $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> ';
1028 }
1029 if ($powered_by) {
1030 $embed_code .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
1031 }
1032
1033 $adsAtts = '';
1034 if (!empty($attributes['adManager'])) {
1035 $ad = base64_encode(json_encode($attributes));
1036 $adsAtts = "data-sponsored-id=$client_id data-sponsored-attrs=$ad class=ad-mask";
1037 }
1038 ?>
1039
1040 <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); ?> ">
1041 <div class="embedpress-inner-iframe <?php if ($unitoption === '%') {
1042 echo esc_attr('emebedpress-unit-percent');
1043 } ?> ep-doc-<?php echo esc_attr($client_id); ?>" <?php if ($unitoption === '%' && !empty($attributes['width'])) {
1044 $style_attr = 'max-width:' . $attributes['width'] . '%';
1045 } else {
1046 $style_attr = 'max-width:100%';
1047 } ?> style="<?php echo esc_attr($style_attr); ?>" id="<?php echo esc_attr($id); ?>">
1048 <div <?php echo esc_attr($adsAtts); ?>>
1049 <?php
1050 do_action('embedpress_pdf_gutenberg_after_embed', $client_id, 'pdf', $attributes, $pdf_url);
1051 $embed = $embed_code;
1052 if (empty($attributes['lockContent']) || empty($attributes['contentPassword']) || (!empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct))) {
1053
1054 $custom_thumbnail = isset($attributes['customThumbnail']) ? $attributes['customThumbnail'] : '';
1055
1056 echo '<div class="ep-embed-content-wraper">';
1057 $embed = '<div class="position-' . esc_attr($share_position) . '-wraper gutenberg-pdf-wraper">';
1058 $embed .= $embed_code;
1059 $embed .= '</div>';
1060
1061 if (!empty($attributes['contentShare'])) {
1062 $content_id = $attributes['id'];
1063 $embed .= Helper::embed_content_share($content_id, $attributes);
1064 }
1065 echo $embed;
1066 echo '</div>';
1067 } else {
1068 if (!empty($attributes['contentShare'])) {
1069 $content_id = $attributes['clientId'];
1070 $embed = '<div class="position-' . esc_attr($share_position) . '-wraper gutenberg-pdf-wraper">';
1071 $embed .= $embed_code;
1072 $embed .= '</div>';
1073 $embed .= Helper::embed_content_share($content_id, $attributes);
1074 }
1075 echo '<div class="ep-embed-content-wraper">';
1076 Helper::display_password_form($client_id, $embed, $pass_hash_key, $attributes);
1077 echo '</div>';
1078 }
1079 ?>
1080
1081 <?php
1082 if(!empty($attributes['adManager'])) {
1083 $embed .= Helper::generateAdTemplate($client_id, $attributes, 'gutenberg');
1084 }
1085 ?>
1086 </div>
1087 </div>
1088 </div>
1089 <?php
1090 return ob_get_clean();
1091 }
1092 }
1093
1094 function isGoogleCalendar($url) {
1095 $pattern = '/^https:\/\/calendar\.google\.com\/calendar\/embed\?.*$/';
1096 return preg_match($pattern, $url);
1097 }
1098
1099 function embedpress_calendar_render_block($attributes)
1100 {
1101
1102 $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-calendar-' . rand(100, 10000);
1103 $url = !empty($attributes['url']) ? $attributes['url'] : '';
1104
1105 if(!isGoogleCalendar($url))
1106 {
1107 return;
1108 }
1109
1110 $is_private = isset($attributes['is_public']);
1111 $client_id = md5($id);
1112 $width = !empty($attributes['width']) ? $attributes['width'] . 'px' : '600px';
1113 $height = !empty($attributes['height']) ? $attributes['height'] . 'px' : '600px';
1114 $gen_settings = get_option(EMBEDPRESS_PLG_NAME);
1115 $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by'];
1116 if (isset($attributes['powered_by'])) {
1117 $powered_by = $attributes['powered_by'];
1118 }
1119
1120 $aligns = [
1121 'left' => 'alignleft',
1122 'right' => 'alignright',
1123 'wide' => 'alignwide',
1124 'full' => 'alignfull'
1125 ];
1126 $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : '';
1127 $dimension = "width:$width;height:$height";
1128 ob_start();
1129 ?>
1130 <div class="embedpress-calendar-gutenberg embedpress-calendar ose-calendar <?php echo esc_attr($alignment) ?>" style="<?php echo esc_attr($dimension); ?>; max-width:100%;">
1131
1132 <?php
1133 if (!empty($url) && !$is_private) {
1134 ?>
1135 <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>
1136 <?php } else {
1137 if (is_embedpress_pro_active()) {
1138 echo Embedpress_Google_Helper::shortcode();
1139 }
1140 } ?>
1141 <?php do_action('embedpress_calendar_gutenberg_after_embed', $client_id, 'calendar', $attributes); ?>
1142
1143 <?php
1144 if ($powered_by) {
1145 printf('<p class="embedpress-el-powered" style="width:' . esc_attr($width) . '" >%s</p>', __('Powered By EmbedPress', 'embedpress'));
1146 } ?>
1147
1148 </div>
1149 <?php
1150 return ob_get_clean();
1151 }
1152
1153 function embedpress_document_block_scripts() {
1154 if (!is_admin() && has_block('embedpress/document')) {
1155 $script_handles = [
1156 'embedpress-pdfobject',
1157 'embedpress-front',
1158 'embedpress_documents_viewer_script'
1159 ];
1160
1161 foreach ($script_handles as $handle) {
1162 wp_enqueue_script($handle);
1163 }
1164
1165 $style_handles = [
1166 'embedpress_blocks-cgb-style-css',
1167 'embedpress-style'
1168 ];
1169
1170 foreach ($style_handles as $handle) {
1171 wp_enqueue_style($handle);
1172 }
1173 }
1174 }
1175 add_action('wp_enqueue_scripts', 'embedpress_document_block_scripts');
1176