PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 4.0.3
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v4.0.3
4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / Gutenberg / plugin.php
embedpress / Gutenberg Last commit date
block-backend 2 years ago dist 2 years ago plugin.php 2 years ago
plugin.php
1170 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 'unitoption' => [
802 'type' => "string",
803 'default' => '%',
804 ],
805 'zoomIn' => [
806 'type' => "boolean",
807 'default' => true,
808 ],
809 'zoomOut' => [
810 'type' => "boolean",
811 'default' => true,
812 ],
813 'fitView' => [
814 'type' => "boolean",
815 'default' => true,
816 ],
817 'bookmark' => [
818 'type' => "boolean",
819 'default' => true,
820 ],
821
822 //Ad attributes
823 'adManager' => [
824 'type' => 'boolean',
825 'default' => false
826 ],
827 'adSource' => [
828 'type' => 'string',
829 'default' => 'video'
830 ],
831 'adContent' => [
832 'type' => 'object',
833 ],
834 'adWidth' => array(
835 'type' => 'string',
836 'default' => '300'
837 ),
838 'adHeight' => array(
839 'type' => 'string',
840 'default' => '200'
841 ),
842 'adXPosition' => array(
843 'type' => 'number',
844 'default' => 25
845 ),
846 'adYPosition' => array(
847 'type' => 'number',
848 'default' => 20
849 ),
850 'adUrl' => [
851 'type' => 'string',
852 'default' => ''
853 ],
854 'adStart' => [
855 'type' => 'string',
856 'default' => '10'
857 ],
858 'adSkipButton' => [
859 'type' => 'boolean',
860 'default' => true
861 ],
862 'adSkipButtonAfter' => [
863 'type' => 'string',
864 'default' => '5'
865 ]
866 ),
867 'render_callback' => 'embedpress_pdf_render_block',
868 ]);
869 } elseif ('embedpress-calendar' === $blocks_to_register) {
870 register_block_type('embedpress/embedpress-calendar', [
871 'render_callback' => 'embedpress_calendar_render_block',
872 ]);
873 } elseif ('document' === $blocks_to_register) {
874 register_block_type('embedpress/' . $blocks_to_register, [
875 // 'render_callback' => 'embedpress_document_render_block',
876 ]);
877 } else {
878 register_block_type('embedpress/' . $blocks_to_register);
879 }
880 } else {
881
882 if (WP_Block_Type_Registry::get_instance()->is_registered('embedpress/' . $blocks_to_register)) {
883 unregister_block_type('embedpress/' . $blocks_to_register);
884 }
885 }
886 }
887
888 endif;
889 }
890
891 add_action('init', 'embedpress_gutenberg_register_all_block');
892
893 function getParamData($attributes)
894 {
895
896 $urlParamData = array(
897 'themeMode' => !empty($attributes['themeMode']) ? $attributes['themeMode'] : 'default',
898 'toolbar' => !empty($attributes['toolbar']) ? 'true' : 'false',
899 'position' => $attributes['position'],
900 'presentation' => !empty($attributes['presentation']) ? 'true' : 'false',
901 'download' => !empty($attributes['download']) ? 'true' : 'false',
902 'copy_text' => !empty($attributes['copy_text']) ? 'true' : 'false',
903 'add_text' => !empty($attributes['add_text']) ? 'true' : 'false',
904 'draw' => !empty($attributes['draw']) ? 'true' : 'false',
905 'doc_rotation' => !empty($attributes['doc_rotation']) ? 'true' : 'false',
906 'doc_details' => !empty($attributes['doc_details']) ? 'true' : 'false',
907 'zoom_in' => !empty($attributes['zoomIn']) ? 'true' : 'false',
908 'zoom_out' => !empty($attributes['zoomOut']) ? 'true' : 'false',
909 'fit_view' => !empty($attributes['fitView']) ? 'true' : 'false',
910 'bookmark' => !empty($attributes['bookmark']) ? 'true' : 'false',
911 'flipbook_toolbar_position' => !empty($attributes['flipbook_toolbar_position']) ? $attributes['flipbook_toolbar_position'] : 'bottom',
912 );
913
914 if ($urlParamData['themeMode'] == 'custom') {
915 $urlParamData['customColor'] = !empty($attributes['customColor']) ? $attributes['customColor'] : '#403A81';
916 }
917
918 if (isset($attributes['viewerStyle']) && $attributes['viewerStyle'] == 'flip-book') {
919 return "&key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), 'UTF-8'));
920 }
921
922 return "#key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), 'UTF-8'));
923 }
924
925 function embedpress_pdf_block_scripts($attributes) {
926
927 $script_handles = [];
928
929 $script_handles[] = 'embedpress-pdfobject';
930 $script_handles[] = 'embedpress-front';
931
932 if(!empty($attributes['adManager'])){
933 $script_handles[] = 'embedpress-ads';
934 }
935
936 foreach ($script_handles as $handle) {
937 wp_enqueue_script($handle);
938 }
939
940 $style_handles = [
941 'embedpress_blocks-cgb-style-css',
942 'embedpress-style'
943 ];
944
945 foreach ($style_handles as $handle) {
946 wp_enqueue_style($handle);
947 }
948
949 }
950
951 function embedpress_pdf_render_block($attributes)
952 {
953 embedpress_pdf_block_scripts($attributes);
954
955 if (!empty($attributes['href'])) {
956 $renderer = Helper::get_pdf_renderer();
957 $pdf_url = $attributes['href'];
958 $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-pdf-' . rand(100, 10000);
959 $client_id = md5($id);
960
961
962 $unitoption = !empty($attributes['unitoption']) ? $attributes['unitoption'] : 'px';
963 $width = !empty($attributes['width']) ? $attributes['width'] . $unitoption : get_options_value('enableEmbedResizeWidth').'px';
964
965 if ($unitoption == '%') {
966 $width_class = ' ep-percentage-width';
967 } else {
968 $width_class = 'ep-fixed-width';
969 }
970 $content_share_class = '';
971 $share_position_class = '';
972 $share_position = isset($attributes['sharePosition']) ? $attributes['sharePosition'] : 'right';
973
974 if (!empty($attributes['contentShare'])) {
975 $content_share_class = 'ep-content-share-enabled';
976 $share_position_class = 'ep-share-position-' . $share_position;
977 }
978
979 $password_correct = isset($_COOKIE['password_correct_' . $client_id]) ? $_COOKIE['password_correct_' . $client_id] : '';
980 $hash_pass = hash('sha256', wp_salt(32) . md5(isset($attributes['contentPassword']) ? $attributes['contentPassword'] : ''));
981
982
983 $content_protection_class = 'ep-content-protection-enabled';
984 if (empty($attributes['lockContent']) || empty($attributes['contentPassword']) || $hash_pass === $password_correct) {
985 $content_protection_class = 'ep-content-protection-disabled';
986 }
987
988
989
990 $height = !empty($attributes['height']) ? $attributes['height'] . 'px' : get_options_value('enableEmbedResizeHeight').'px';
991 $gen_settings = get_option(EMBEDPRESS_PLG_NAME);
992
993 $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by'];
994 if (isset($attributes['powered_by'])) {
995 $powered_by = $attributes['powered_by'];
996 }
997
998 $src = $renderer . ((strpos($renderer, '?') == false) ? '?' : '&') . 'file=' . urlencode($attributes['href']) . getParamData($attributes);
999
1000 $pass_hash_key = isset($attributes['contentPassword']) ? md5($attributes['contentPassword']) : '';
1001
1002 $aligns = [
1003 'left' => 'ep-alignleft',
1004 'right' => 'ep-alignright',
1005 'center' => 'ep-aligncenter',
1006 'wide' => 'ep-alignwide',
1007 'full' => 'ep-alignfull'
1008 ];
1009 $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : '';
1010 $dimension = "width:$width;height:$height";
1011 ob_start();
1012 ?>
1013
1014
1015 <?php
1016
1017 $url = !empty($attributes['href']) ? $attributes['href'] : '';
1018
1019 $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> ';
1020 if(isset($attributes['viewerStyle']) && $attributes['viewerStyle'] === 'flip-book') {
1021 $src = urlencode($url).getParamData($attributes);
1022 $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> ';
1023 }
1024 if ($powered_by) {
1025 $embed_code .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
1026 }
1027
1028 $adsAtts = '';
1029 if (!empty($attributes['adManager'])) {
1030 $ad = base64_encode(json_encode($attributes));
1031 $adsAtts = "data-sponsored-id=$client_id data-sponsored-attrs=$ad class=ad-mask";
1032 }
1033 ?>
1034
1035 <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); ?> ">
1036 <div class="embedpress-inner-iframe <?php if ($unitoption === '%') {
1037 echo esc_attr('emebedpress-unit-percent');
1038 } ?> ep-doc-<?php echo esc_attr($client_id); ?>" <?php if ($unitoption === '%' && !empty($attributes['width'])) {
1039 $style_attr = 'max-width:' . $attributes['width'] . '%';
1040 } else {
1041 $style_attr = 'max-width:100%';
1042 } ?> style="<?php echo esc_attr($style_attr); ?>" id="<?php echo esc_attr($id); ?>">
1043 <div <?php echo esc_attr($adsAtts); ?>>
1044 <?php
1045 do_action('embedpress_pdf_gutenberg_after_embed', $client_id, 'pdf', $attributes, $pdf_url);
1046 $embed = $embed_code;
1047 if (empty($attributes['lockContent']) || empty($attributes['contentPassword']) || (!empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct))) {
1048
1049 $custom_thumbnail = isset($attributes['customThumbnail']) ? $attributes['customThumbnail'] : '';
1050
1051 echo '<div class="ep-embed-content-wraper">';
1052 $embed = '<div class="position-' . esc_attr($share_position) . '-wraper gutenberg-pdf-wraper">';
1053 $embed .= $embed_code;
1054 $embed .= '</div>';
1055
1056 if (!empty($attributes['contentShare'])) {
1057 $content_id = $attributes['id'];
1058 $embed .= Helper::embed_content_share($content_id, $attributes);
1059 }
1060 echo $embed;
1061 echo '</div>';
1062 } else {
1063 if (!empty($attributes['contentShare'])) {
1064 $content_id = $attributes['clientId'];
1065 $embed = '<div class="position-' . esc_attr($share_position) . '-wraper gutenberg-pdf-wraper">';
1066 $embed .= $embed_code;
1067 $embed .= '</div>';
1068 $embed .= Helper::embed_content_share($content_id, $attributes);
1069 }
1070 echo '<div class="ep-embed-content-wraper">';
1071 Helper::display_password_form($client_id, $embed, $pass_hash_key, $attributes);
1072 echo '</div>';
1073 }
1074 ?>
1075
1076 <?php
1077 if(!empty($attributes['adManager'])) {
1078 $embed .= Helper::generateAdTemplate($client_id, $attributes, 'gutenberg');
1079 }
1080 ?>
1081 </div>
1082 </div>
1083 </div>
1084 <?php
1085 return ob_get_clean();
1086 }
1087 }
1088
1089 function isGoogleCalendar($url) {
1090 $pattern = '/^https:\/\/calendar\.google\.com\/calendar\/embed\?.*$/';
1091 return preg_match($pattern, $url);
1092 }
1093
1094 function embedpress_calendar_render_block($attributes)
1095 {
1096
1097 $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-calendar-' . rand(100, 10000);
1098 $url = !empty($attributes['url']) ? $attributes['url'] : '';
1099
1100 if(!isGoogleCalendar($url))
1101 {
1102 return;
1103 }
1104
1105 $is_private = isset($attributes['is_public']);
1106 $client_id = md5($id);
1107 $width = !empty($attributes['width']) ? $attributes['width'] . 'px' : '600px';
1108 $height = !empty($attributes['height']) ? $attributes['height'] . 'px' : '600px';
1109 $gen_settings = get_option(EMBEDPRESS_PLG_NAME);
1110 $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by'];
1111 if (isset($attributes['powered_by'])) {
1112 $powered_by = $attributes['powered_by'];
1113 }
1114
1115 $aligns = [
1116 'left' => 'alignleft',
1117 'right' => 'alignright',
1118 'wide' => 'alignwide',
1119 'full' => 'alignfull'
1120 ];
1121 $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : '';
1122 $dimension = "width:$width;height:$height";
1123 ob_start();
1124 ?>
1125 <div class="embedpress-calendar-gutenberg embedpress-calendar ose-calendar <?php echo esc_attr($alignment) ?>" style="<?php echo esc_attr($dimension); ?>; max-width:100%;">
1126
1127 <?php
1128 if (!empty($url) && !$is_private) {
1129 ?>
1130 <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>
1131 <?php } else {
1132 if (is_embedpress_pro_active()) {
1133 echo Embedpress_Google_Helper::shortcode();
1134 }
1135 } ?>
1136 <?php do_action('embedpress_calendar_gutenberg_after_embed', $client_id, 'calendar', $attributes); ?>
1137
1138 <?php
1139 if ($powered_by) {
1140 printf('<p class="embedpress-el-powered" style="width:' . esc_attr($width) . '" >%s</p>', __('Powered By EmbedPress', 'embedpress'));
1141 } ?>
1142
1143 </div>
1144 <?php
1145 return ob_get_clean();
1146 }
1147
1148 function embedpress_document_block_scripts() {
1149 if (!is_admin() && has_block('embedpress/document')) {
1150 $script_handles = [
1151 'embedpress-front',
1152 'embedpress_documents_viewer_script'
1153 ];
1154
1155 foreach ($script_handles as $handle) {
1156 wp_enqueue_script($handle);
1157 }
1158
1159 $style_handles = [
1160 'embedpress_blocks-cgb-style-css',
1161 'embedpress-style'
1162 ];
1163
1164 foreach ($style_handles as $handle) {
1165 wp_enqueue_style($handle);
1166 }
1167 }
1168 }
1169 add_action('wp_enqueue_scripts', 'embedpress_document_block_scripts');
1170