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