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