PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 4.1.8
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v4.1.8
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 css 1 year ago dist 1 year ago plugin.php 1 year ago
plugin.php
1357 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 {
43 $g_settings = get_option(EMBEDPRESS_PLG_NAME);
44
45 if (isset($g_settings[$key])) {
46 return $g_settings[$key];
47 }
48 return '';
49 }
50 }
51 if (!function_exists('get_branding_value')) {
52 function get_branding_value($key, $provider)
53 {
54 $settings = get_option(EMBEDPRESS_PLG_NAME . ':' . $provider, []);
55
56 if (isset($settings['branding']) && $settings['branding'] === 'yes' && isset($settings[$key])) {
57 return $settings[$key];
58 }
59 return '';
60 }
61 }
62
63
64 /**
65 * Enqueue Gutenberg block assets for backend editor.
66 *
67 * @uses {wp-blocks} for block type registration & related functions.
68 * @uses {wp-element} for WP Element abstraction — structure of blocks.
69 * @uses {wp-i18n} to internationalize the block's text.
70 * @uses {wp-editor} for WP editor styles.
71 * @since 1.0.0
72 */
73
74 function embedpress_blocks_cgb_editor_assets()
75 { // phpcs:ignore
76 // Scripts.
77
78 $elements = (array) get_option(EMBEDPRESS_PLG_NAME . ":elements", []);
79 $g_blocks = isset($elements['gutenberg']) ? (array) $elements['gutenberg'] : [];
80
81 if (!wp_script_is('embedpress-pdfobject')) {
82 wp_enqueue_script(
83 'embedpress-pdfobject',
84 EMBEDPRESS_URL_ASSETS . 'js/pdfobject.js',
85 [],
86 EMBEDPRESS_VERSION
87 );
88 }
89
90 wp_enqueue_script(
91 'embedpress_blocks-cgb-block-js', // Handle.
92 EMBEDPRESS_GUTENBERG_DIR_URL . 'dist/blocks.build.js', // Block.build.js: We register the block here. Built with Webpack.
93 array('wp-blocks', 'wp-i18n', 'wp-element', 'wp-api-fetch', 'wp-is-shallow-equal', 'wp-editor', 'wp-components', 'embedpress-pdfobject'), // Dependencies, defined above.
94 filemtime(EMBEDPRESS_GUTENBERG_DIR_PATH . 'dist/blocks.build.js'), // Version: File modification time.
95 true // Enqueue the script in the footer.
96 );
97
98 if (!empty($g_blocks['document'])) {
99 wp_enqueue_script(
100 'embedpress_documents_viewer_script',
101 EMBEDPRESS_PLUGIN_DIR_URL . 'assets/js/documents-viewer-script.js',
102 array('wp-blocks', 'wp-dom-ready', 'wp-edit-post'),
103 EMBEDPRESS_PLUGIN_VERSION,
104 true
105 );
106 }
107
108 $wistia_labels = array(
109 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'),
110 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'),
111 'you_have_watched_it_before' => __('It looks like you\'ve watched<br />part of this video before!', 'embedpress'),
112 );
113 $elements = (array) get_option(EMBEDPRESS_PLG_NAME . ":elements", []);
114 $active_blocks = isset($elements['gutenberg']) ? (array) $elements['gutenberg'] : [];
115
116 $wistia_labels = json_encode($wistia_labels);
117 $wistia_options = null;
118 if (function_exists('embedpress_wisita_pro_get_options')) :
119 $wistia_options = embedpress_wisita_pro_get_options();
120 endif;
121 $pars_url = wp_parse_url(get_site_url());
122 $documents_cta_options = (array) get_option(EMBEDPRESS_PLG_NAME . ':document');
123 wp_localize_script('embedpress_blocks-cgb-block-js', 'embedpressObj', array(
124 'wistia_labels' => $wistia_labels,
125 'wisita_options' => $wistia_options,
126 'embedpress_powered_by' => apply_filters('embedpress_document_block_powered_by', true),
127 'embedpress_pro' => defined('EMBEDPRESS_PRO_PLUGIN_FILE'),
128 'twitch_host' => !empty($pars_url['host']) ? $pars_url['host'] : '',
129 'site_url' => site_url(),
130 'active_blocks' => $active_blocks,
131 'document_cta' => $documents_cta_options,
132 'pdf_renderer' => Helper::get_pdf_renderer(),
133 'is_pro_plugin_active' => defined('EMBEDPRESS_SL_ITEM_SLUG'),
134 'ajaxurl' => admin_url('admin-ajax.php'),
135 'source_nonce' => wp_create_nonce('source_nonce_embedpress'),
136 'can_upload_media' => current_user_can('upload_files'),
137 'EMBEDPRESS_URL_ASSETS' => EMBEDPRESS_URL_ASSETS,
138 'iframe_width' => get_options_value('enableEmbedResizeWidth'),
139 'iframe_height' => get_options_value('enableEmbedResizeHeight'),
140 'pdf_custom_color' => get_options_value('custom_color'),
141 'pdf_custom_color' => get_options_value('custom_color'),
142 'youtube_brand_logo_url' => get_branding_value('logo_url', 'youtube'),
143 'vimeo_brand_logo_url' => get_branding_value('logo_url', 'vimeo'),
144 'wistia_brand_logo_url' => get_branding_value('logo_url', 'wistia'),
145 'twitch_brand_logo_url' => get_branding_value('logo_url', 'twitch'),
146 'dailymotion_brand_logo_url' => get_branding_value('logo_url', 'dailymotion'),
147
148 ));
149
150 // Styles.
151 wp_enqueue_style(
152 'embedpress_blocks-cgb-block-editor-css', // Handle.
153 EMBEDPRESS_GUTENBERG_DIR_URL . 'dist/blocks.editor.build.css', // Block editor CSS.
154 array('wp-edit-blocks'), // Dependency to include the CSS after it.
155 filemtime(EMBEDPRESS_GUTENBERG_DIR_PATH . 'dist/blocks.editor.build.css') // Version: File modification time.
156 );
157 wp_enqueue_style('embedpress_blocks-cgb-style-css');
158 }
159
160 // Hook: Editor assets.
161 add_action('enqueue_block_editor_assets', 'embedpress_blocks_cgb_editor_assets');
162
163
164 function embedpress_block_category($categories, $post)
165 {
166 return array_merge(
167 $categories,
168 array(
169 array(
170 'slug' => 'embedpress',
171 'title' => 'EmbedPress',
172 'icon' => '',
173 ),
174 )
175 );
176 }
177 $wp_version = get_bloginfo('version', 'display');
178 if (version_compare($wp_version, '5.8', '>=')) {
179 add_filter('block_categories_all', 'embedpress_block_category', 10, 2);
180 } else {
181 add_filter('block_categories', 'embedpress_block_category', 10, 2);
182 }
183
184
185
186
187 foreach (glob(EMBEDPRESS_GUTENBERG_DIR_PATH . 'block-backend/*.php') as $block_logic) {
188 require_once $block_logic;
189 }
190
191 /**
192 * Registers the embedpress gutneberg block on server.
193 */
194
195 function embedpress_gutenberg_register_all_block()
196 {
197 if (function_exists('register_block_type')) :
198
199 $elements = (array) get_option(EMBEDPRESS_PLG_NAME . ":elements", []);
200 $g_blocks = isset($elements['gutenberg']) ? (array) $elements['gutenberg'] : [];
201 $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'];
202
203 foreach ($blocks_to_registers as $blocks_to_register) {
204 if (!empty($g_blocks[$blocks_to_register])) {
205 if ('embedpress' === $blocks_to_register) {
206 register_block_type('embedpress/embedpress', [
207 'render_callback' => 'embedpress_render_block',
208 // 'style' => [
209 // 'plyr',
210 // ],
211 // 'script' => [
212 // 'plyr.polyfilled',
213 // 'initplyr',
214 // 'vimeo-player',
215 // 'embedpress-front',
216 // 'embedpress-ads',
217 // ],
218 'attributes' => array(
219 'clientId' => [
220 'type' => 'string',
221 ],
222 'height' => [
223 'type' => 'string',
224 'default' => get_options_value('enableEmbedResizeHeight')
225 ],
226 'width' => [
227 'type' => 'string',
228 'default' => get_options_value('enableEmbedResizeWidth')
229 ],
230 'lockContent' => [
231 'type' => 'boolean',
232 'default' => false
233 ],
234 'lockHeading' => [
235 'type' => 'string',
236 'default' => 'Content Locked'
237 ],
238 'lockSubHeading' => [
239 'type' => 'string',
240 'default' => 'Content is locked and requires password to access it.'
241 ],
242 'lockErrorMessage' => [
243 'type' => 'string',
244 'default' => 'Oops, that wasn\'t the right password. Try again.'
245 ],
246 'passwordPlaceholder' => [
247 'type' => 'string',
248 'default' => 'Password'
249 ],
250 'submitButtonText' => [
251 'type' => 'string',
252 'default' => 'Unlock'
253 ],
254 'submitUnlockingText' => [
255 'type' => 'string',
256 'default' => 'Unlocking'
257 ],
258 'enableFooterMessage' => [
259 'type' => 'boolean',
260 'default' => false
261 ],
262 'footerMessage' => [
263 'type' => 'string',
264 'default' => 'In case you don\'t have the password, kindly reach out to content owner or administrator to request access.'
265 ],
266 'contentPassword' => [
267 'type' => 'string',
268 'default' => '',
269 ],
270 'contentShare' => [
271 'type' => 'boolean',
272 'default' => false
273 ],
274 'sharePosition' => [
275 'type' => 'string',
276 'default' => 'right'
277 ],
278 'customTitle' => [
279 'type' => 'string',
280 'default' => ''
281 ],
282 'customDescription' => [
283 'type' => 'string',
284 'default' => ''
285 ],
286 'customThumbnail' => [
287 'type' => 'string',
288 'default' => ''
289 ],
290
291 'videosize' => [
292 'type' => 'string',
293 'default' => 'fixed'
294 ],
295
296 'loadmore' => [
297 'type' => 'boolean',
298 'default' => false
299 ],
300 //Youtube Attributes
301 'starttime' => [
302 'type' => 'string',
303 ],
304 'endtime' => [
305 'type' => 'string',
306 ],
307 'autoplay' => [
308 'type' => 'boolean',
309 'default' => false
310 ],
311 'controls' => [
312 'type' => 'string',
313 ],
314 'progressbarcolor' => [
315 'type' => 'string',
316 ],
317 'videoannotations' => [
318 'type' => 'string',
319 ],
320 'closedcaptions' => [
321 'type' => 'boolean',
322 'default' => true
323 ],
324 'relatedvideos' => [
325 'type' => 'boolean',
326 'default' => true
327 ],
328 'fullscreen' => [
329 'type' => 'boolean',
330 'default' => true
331 ],
332
333 'modestbranding' => [
334 'type' => 'string',
335 ],
336 'pagesize' => [
337 'type' => 'number',
338 ],
339 // custom player attributes
340 'autoPause' => [
341 'type' => 'boolean',
342 'default' => false
343 ],
344 'customPlayer' => [
345 'type' => 'boolean',
346 'default' => false
347 ],
348
349 'posterThumbnail' => [
350 'type' => 'string',
351 'default' => ''
352 ],
353
354 'playerPreset' => [
355 'type' => 'string',
356 'default' => ''
357 ],
358
359 'playerColor' => [
360 'type' => 'string',
361 'default' => '#2e2e99'
362 ],
363
364 'playerPip' => [
365 'type' => 'boolean',
366 'default' => false
367 ],
368
369 'playerRestart' => [
370 'type' => 'boolean',
371 'default' => true
372 ],
373
374 'playerRewind' => [
375 'type' => 'boolean',
376 'default' => true
377 ],
378
379 'playerFastForward' => [
380 'type' => 'boolean',
381 'default' => true
382 ],
383 'playerTooltip' => [
384 'type' => 'boolean',
385 'default' => true
386 ],
387 'playerHideControls' => [
388 'type' => 'boolean',
389 'default' => true
390 ],
391 'playerDownload' => [
392 'type' => 'boolean',
393 'default' => true
394 ],
395 //Wistia Attributes
396 'wstarttime' => [
397 'type' => 'string',
398 ],
399 'wautoplay' => [
400 'type' => 'boolean',
401 'default' => true
402 ],
403 'scheme' => [
404 'type' => 'string',
405 ],
406 'captions' => [
407 'type' => 'boolean',
408 'default' => true
409 ],
410 'playbutton' => [
411 'type' => 'boolean',
412 'default' => true
413 ],
414 'smallplaybutton' => [
415 'type' => 'boolean',
416 'default' => true
417 ],
418 'playbar' => [
419 'type' => 'boolean',
420 'default' => true
421 ],
422 'resumable' => [
423 'type' => 'boolean',
424 'default' => true
425 ],
426 'wistiafocus' => [
427 'type' => 'boolean',
428 'default' => true
429 ],
430 'volumecontrol' => [
431 'type' => 'boolean',
432 'default' => true
433 ],
434 'volume' => [
435 'type' => 'number',
436 'default' => 100
437 ],
438 'rewind' => [
439 'type' => 'boolean',
440 'default' => false
441 ],
442 'wfullscreen' => [
443 'type' => 'boolean',
444 'default' => true
445 ],
446
447 // Vimeo attributes
448 'vstarttime' => [
449 'type' => 'string',
450 ],
451 'vautoplay' => [
452 'type' => 'boolean',
453 'default' => false
454 ],
455 'vscheme' => [
456 'type' => 'string',
457 ],
458 'vtitle' => [
459 'type' => 'boolean',
460 'default' => true
461 ],
462 'vauthor' => [
463 'type' => 'boolean',
464 'default' => true
465 ],
466 'vavatar' => [
467 'type' => 'boolean',
468 'default' => true
469 ],
470 'vloop' => [
471 'type' => 'boolean',
472 'default' => false
473 ],
474 'vautopause' => [
475 'type' => 'boolean',
476 'default' => false
477 ],
478 'vdnt' => [
479 'type' => 'boolean',
480 'default' => false
481 ],
482
483 // instaFeed attributes
484 'instaLayout' => [
485 'type' => 'string',
486 'default' => 'insta-grid',
487 ],
488 'instafeedFeedType' => [
489 'type' => 'string',
490 'default' => 'user_account_type',
491 ],
492 'instafeedAccountType' => [
493 'type' => 'string',
494 'default' => 'personal',
495 ],
496 'instafeedProfileImage' => [
497 'type' => 'boolean',
498 'default' => true,
499 ],
500 'instafeedProfileImageUrl' => [
501 'type' => 'string',
502 'default' => '',
503 ],
504 'instafeedFollowBtn' => [
505 'type' => 'boolean',
506 'default' => true,
507 ],
508 'instafeedFollowBtnLabel' => [
509 'type' => 'string',
510 'default' => 'Follow',
511 ],
512 'instafeedPostsCount' => [
513 'type' => 'boolean',
514 'default' => true,
515 ],
516 'instafeedPostsCountText' => [
517 'type' => 'string',
518 'default' => '[count] posts',
519 ],
520 'instafeedFollowersCount' => [
521 'type' => 'boolean',
522 'default' => true,
523 ],
524 'instafeedFollowersCountText' => [
525 'type' => 'string',
526 'default' => '[count] followers',
527 ],
528 'instafeedAccName' => [
529 'type' => 'boolean',
530 'default' => true,
531 ],
532 'instafeedColumns' => [
533 'type' => 'string',
534 'default' => '3',
535 ],
536 'instafeedColumnsGap' => [
537 'type' => 'string',
538 'default' => '5',
539 ],
540 'instafeedPostsPerPage' => [
541 'type' => 'string',
542 'default' => '12',
543 ],
544 'instafeedTab' => [
545 'type' => 'boolean',
546 'default' => true,
547 ],
548 'instafeedLikesCount' => [
549 'type' => 'boolean',
550 'default' => true,
551 ],
552 'instafeedCommentsCount' => [
553 'type' => 'boolean',
554 'default' => true,
555 ],
556 'instafeedPopup' => [
557 'type' => 'boolean',
558 'default' => true,
559 ],
560 'instafeedPopupFollowBtn' => [
561 'type' => 'boolean',
562 'default' => true,
563 ],
564 'instafeedPopupFollowBtnLabel' => [
565 'type' => 'string',
566 'default' => 'Follow',
567 ],
568 'instafeedLoadmore' => [
569 'type' => 'boolean',
570 'default' => true,
571 ],
572 'instafeedLoadmoreLabel' => [
573 'type' => 'string',
574 'default' => 'Load More',
575 ],
576 'slidesShow' => [
577 'type' => 'string',
578 'default' => '4',
579 ],
580 'slidesScroll' => [
581 'type' => 'string',
582 'default' => '4',
583 ],
584 'carouselAutoplay' => [
585 'type' => 'boolean',
586 'default' => false,
587 ],
588 'autoplaySpeed' => [
589 'type' => 'string',
590 'default' => '3000',
591 ],
592 'transitionSpeed' => [
593 'type' => 'string',
594 'default' => '1000',
595 ],
596 'carouselLoop' => [
597 'type' => 'boolean',
598 'default' => true,
599 ],
600 'carouselArrows' => [
601 'type' => 'boolean',
602 'default' => true,
603 ],
604 'carouselSpacing' => [
605 'type' => 'string',
606 'default' => '0',
607 ],
608 'carouselDots' => [
609 'type' => 'boolean',
610 'default' => false,
611 ],
612 // Calendly attributes
613 'cEmbedType' => array(
614 'type' => 'string',
615 'default' => 'inline'
616 ),
617 'calendlyData' => array(
618 'type' => 'boolean',
619 'default' => false
620 ),
621 'hideCookieBanner' => array(
622 'type' => 'boolean',
623 'default' => false
624 ),
625 'hideEventTypeDetails' => array(
626 'type' => 'boolean',
627 'default' => false
628 ),
629 'cBackgroundColor' => array(
630 'type' => 'string',
631 'default' => 'ffffff'
632 ),
633 'cTextColor' => array(
634 'type' => 'string',
635 'default' => '1A1A1A'
636 ),
637 'cButtonLinkColor' => array(
638 'type' => 'string',
639 'default' => '0000FF'
640 ),
641 'cPopupButtonText' => array(
642 'type' => 'string',
643 'default' => 'Schedule time with me'
644 ),
645 'cPopupButtonBGColor' => array(
646 'type' => 'string',
647 'default' => '#0000FF'
648 ),
649 'cPopupButtonTextColor' => array(
650 'type' => 'string',
651 'default' => '#FFFFFF'
652 ),
653 'cPopupLinkText' => array(
654 'type' => 'string',
655 'default' => 'Schedule time with me'
656 ),
657
658 //Ad attributes
659 'adManager' => [
660 'type' => 'boolean',
661 'default' => false
662 ],
663 'adSource' => [
664 'type' => 'string',
665 'default' => 'video'
666 ],
667 'adContent' => [
668 'type' => 'object',
669 ],
670 'adWidth' => array(
671 'type' => 'string',
672 'default' => '300'
673 ),
674 'adHeight' => array(
675 'type' => 'string',
676 'default' => '200'
677 ),
678 'adXPosition' => array(
679 'type' => 'number',
680 'default' => 25
681 ),
682 'adYPosition' => array(
683 'type' => 'number',
684 'default' => 10
685 ),
686 'adUrl' => [
687 'type' => 'string',
688 'default' => ''
689 ],
690 'adStart' => [
691 'type' => 'string',
692 'default' => '10'
693 ],
694 'adSkipButton' => [
695 'type' => 'boolean',
696 'default' => true
697 ],
698 'adSkipButtonAfter' => [
699 'type' => 'string',
700 'default' => '5'
701 ]
702
703 ),
704 ]);
705 } elseif ('embedpress-pdf' === $blocks_to_register) {
706 register_block_type('embedpress/embedpress-pdf', [
707 'attributes' => array(
708 'clientId' => [
709 'type' => 'string',
710 ],
711 // 'height' => [
712 // 'type' => 'string',
713 // 'default' => (int) get_options_value('enableEmbedResizeHeight')
714 // ],
715 // 'width' => [
716 // 'type' => 'string',
717 // 'default' => (int) get_options_value('enableEmbedResizeWidth')
718 // ],
719 'customColor' => [
720 'type' => 'string',
721 'default' => get_options_value('custom_color')
722 ],
723 'powered_by' => [
724 'type' => 'boolean',
725 'default' => true
726 ],
727 'lockContent' => [
728 'type' => 'boolean',
729 'default' => false
730 ],
731 'lockHeading' => [
732 'type' => 'string',
733 'default' => 'Content Locked'
734 ],
735 'lockSubHeading' => [
736 'type' => 'string',
737 'default' => 'Content is locked and requires password to access it.'
738 ],
739 'passwordPlaceholder' => [
740 'type' => 'string',
741 'default' => 'Password'
742 ],
743 'submitButtonText' => [
744 'type' => 'string',
745 'default' => 'Unlock'
746 ],
747 'submitUnlockingText' => [
748 'type' => 'string',
749 'default' => 'Unlocking'
750 ],
751 'lockErrorMessage' => [
752 'type' => 'string',
753 'default' => 'Oops, that wasn\'t the right password. Try again.'
754 ],
755 'enableFooterMessage' => [
756 'type' => 'boolean',
757 'default' => false
758 ],
759 'footerMessage' => [
760 'type' => 'string',
761 'default' => 'In case you don\'t have the password, kindly reach out to content owner or administrator to request access.'
762 ],
763 'contentPassword' => [
764 'type' => 'string',
765 'default' => ''
766 ],
767 'contentShare' => [
768 'type' => 'boolean',
769 'default' => false
770 ],
771 'sharePosition' => [
772 'type' => 'string',
773 'default' => 'right'
774 ],
775 'presentation' => [
776 'type' => "boolean",
777 'default' => true,
778 ],
779 'lazyLoad' => [
780 'type' => "boolean",
781 'default' => false,
782 ],
783
784 'position' => [
785 'type' => "string",
786 'default' => 'top',
787 ],
788 'flipbook_toolbar_position' => [
789 'type' => "string",
790 'default' => 'bottom',
791 ],
792
793 'print' => [
794 'type' => "boolean",
795 'default' => true,
796 ],
797
798 'download' => [
799 'type' => "boolean",
800 'default' => true,
801 ],
802 'open' => [
803 'type' => "boolean",
804 'default' => true,
805 ],
806 'selection_tool' => [
807 'type' => "string",
808 'default' => '0',
809 ],
810 'scrolling' => [
811 'type' => "string",
812 'default' => '-1',
813 ],
814 'spreads' => [
815 'type' => "string",
816 'default' => '-1',
817 ],
818 'copy_text' => [
819 'type' => "boolean",
820 'default' => true,
821 ],
822 'add_text' => [
823 'type' => "boolean",
824 'default' => true,
825 ],
826 'draw' => [
827 'type' => "boolean",
828 'default' => true,
829 ],
830 'toolbar' => [
831 'type' => "boolean",
832 'default' => true,
833 ],
834 'doc_details' => [
835 'type' => "boolean",
836 'default' => true,
837 ],
838 'doc_rotation' => [
839 'type' => "boolean",
840 'default' => true,
841 ],
842 'add_image' => [
843 'type' => "boolean",
844 'default' => true,
845 ],
846 'unitoption' => [
847 'type' => "string",
848 'default' => '%',
849 ],
850 'zoomIn' => [
851 'type' => "boolean",
852 'default' => true,
853 ],
854 'zoomOut' => [
855 'type' => "boolean",
856 'default' => true,
857 ],
858 'fitView' => [
859 'type' => "boolean",
860 'default' => true,
861 ],
862 'bookmark' => [
863 'type' => "boolean",
864 'default' => true,
865 ],
866 //Spreaker
867 'theme' => array(
868 'type' => 'string',
869 'default' => 'light',
870 ),
871 'color' => array(
872 'type' => 'string',
873 'default' => '',
874 ),
875 'coverImageUrl' => array(
876 'type' => 'string',
877 'default' => '',
878 ),
879 'playlist' => array(
880 'type' => 'boolean',
881 'default' => false,
882 ),
883 'playlistContinuous' => array(
884 'type' => 'boolean',
885 'default' => false,
886 ),
887 'playlistLoop' => array(
888 'type' => 'boolean',
889 'default' => false,
890 ),
891 'playlistAutoupdate' => array(
892 'type' => 'boolean',
893 'default' => true,
894 ),
895 'chaptersImage' => array(
896 'type' => 'boolean',
897 'default' => true,
898 ),
899 'episodeImagePosition' => array(
900 'type' => 'string',
901 'default' => 'right',
902 ),
903 'hideLikes' => array(
904 'type' => 'boolean',
905 'default' => false,
906 ),
907 'hideComments' => array(
908 'type' => 'boolean',
909 'default' => false,
910 ),
911 'hideSharing' => array(
912 'type' => 'boolean',
913 'default' => false,
914 ),
915 'hideLogo' => array(
916 'type' => 'boolean',
917 'default' => false,
918 ),
919 'hideEpisodeDescription' => array(
920 'type' => 'boolean',
921 'default' => false,
922 ),
923 'hidePlaylistDescriptions' => array(
924 'type' => 'boolean',
925 'default' => false,
926 ),
927 'hidePlaylistImages' => array(
928 'type' => 'boolean',
929 'default' => false,
930 ),
931 'hideDownload' => array(
932 'type' => 'boolean',
933 'default' => false,
934 ),
935 'mode' => array(
936 'type' => 'string',
937 'default' => 'carousel'
938 ),
939 'imageWidth' => array(
940 'type' => 'number',
941 'default' => 800
942 ),
943 'imageHeight' => array(
944 'type' => 'number',
945 'default' => 600
946 ),
947 'playerAutoplay' => array(
948 'type' => 'boolean',
949 'default' => false
950 ),
951 'delay' => array(
952 'type' => 'number',
953 'default' => 5
954 ),
955 'repeat' => array(
956 'type' => 'boolean',
957 'default' => true
958 ),
959 'mediaitemsAspectRatio' => array(
960 'type' => 'boolean',
961 'default' => true
962 ),
963 'mediaitemsEnlarge' => array(
964 'type' => 'boolean',
965 'default' => false
966 ),
967 'mediaitemsStretch' => array(
968 'type' => 'boolean',
969 'default' => false
970 ),
971 'mediaitemsCover' => array(
972 'type' => 'boolean',
973 'default' => false
974 ),
975 'backgroundColor' => array(
976 'type' => 'string',
977 'default' => ''
978 ),
979 'expiration' => array(
980 'type' => 'number',
981 'default' => 60
982 ),
983 //Ad attributes
984 'adManager' => [
985 'type' => 'boolean',
986 'default' => false
987 ],
988 'adSource' => [
989 'type' => 'string',
990 'default' => 'video'
991 ],
992 'adContent' => [
993 'type' => 'object',
994 ],
995 'adWidth' => array(
996 'type' => 'string',
997 'default' => '300'
998 ),
999 'adHeight' => array(
1000 'type' => 'string',
1001 'default' => '200'
1002 ),
1003 'adXPosition' => array(
1004 'type' => 'number',
1005 'default' => 25
1006 ),
1007 'adYPosition' => array(
1008 'type' => 'number',
1009 'default' => 20
1010 ),
1011 'adUrl' => [
1012 'type' => 'string',
1013 'default' => ''
1014 ],
1015 'adStart' => [
1016 'type' => 'string',
1017 'default' => '10'
1018 ],
1019 'adSkipButton' => [
1020 'type' => 'boolean',
1021 'default' => true
1022 ],
1023 'adSkipButtonAfter' => [
1024 'type' => 'string',
1025 'default' => '5'
1026 ]
1027 ),
1028 'render_callback' => 'embedpress_pdf_render_block',
1029 ]);
1030 } elseif ('embedpress-calendar' === $blocks_to_register) {
1031 register_block_type('embedpress/embedpress-calendar', [
1032 'render_callback' => 'embedpress_calendar_render_block',
1033 ]);
1034 } elseif ('document' === $blocks_to_register) {
1035 register_block_type('embedpress/' . $blocks_to_register, [
1036 // 'render_callback' => 'embedpress_document_render_block',
1037 ]);
1038 } else {
1039 register_block_type('embedpress/' . $blocks_to_register);
1040 }
1041 } else {
1042
1043 if (WP_Block_Type_Registry::get_instance()->is_registered('embedpress/' . $blocks_to_register)) {
1044 unregister_block_type('embedpress/' . $blocks_to_register);
1045 }
1046 }
1047 }
1048
1049 endif;
1050 }
1051
1052 add_action('init', 'embedpress_gutenberg_register_all_block');
1053
1054 function getParamData($attributes)
1055 {
1056
1057 $urlParamData = array(
1058 'themeMode' => !empty($attributes['themeMode']) ? $attributes['themeMode'] : 'default',
1059 'toolbar' => !empty($attributes['toolbar']) ? 'true' : 'false',
1060 'position' => $attributes['position'],
1061 'presentation' => !empty($attributes['presentation']) ? 'true' : 'false',
1062 'lazyLoad' => !empty($attributes['lazyLoad']) ? 'true' : 'false',
1063 'download' => !empty($attributes['download']) ? 'true' : 'false',
1064 'copy_text' => !empty($attributes['copy_text']) ? 'true' : 'false',
1065 'add_text' => !empty($attributes['add_text']) ? 'true' : 'false',
1066 'draw' => !empty($attributes['draw']) ? 'true' : 'false',
1067 'doc_rotation' => !empty($attributes['doc_rotation']) ? 'true' : 'false',
1068 'add_image' => !empty($attributes['add_image']) ? 'true' : 'false',
1069 'doc_details' => !empty($attributes['doc_details']) ? 'true' : 'false',
1070 'zoom_in' => !empty($attributes['zoomIn']) ? 'true' : 'false',
1071 'zoom_out' => !empty($attributes['zoomOut']) ? 'true' : 'false',
1072 'fit_view' => !empty($attributes['fitView']) ? 'true' : 'false',
1073 'bookmark' => !empty($attributes['bookmark']) ? 'true' : 'false',
1074 'flipbook_toolbar_position' => !empty($attributes['flipbook_toolbar_position']) ? $attributes['flipbook_toolbar_position'] : 'bottom',
1075 'selection_tool' => isset($attributes['selection_tool']) ? esc_attr($attributes['selection_tool']) : '0',
1076 'scrolling' => isset($attributes['scrolling']) ? esc_attr($attributes['scrolling']) : '-1',
1077 'spreads' => isset($attributes['spreads']) ? esc_attr($attributes['spreads']) : '-1',
1078 );
1079
1080 if ($urlParamData['themeMode'] == 'custom') {
1081 $urlParamData['customColor'] = !empty($attributes['customColor']) ? $attributes['customColor'] : '#403A81';
1082 }
1083
1084 if (isset($attributes['viewerStyle']) && $attributes['viewerStyle'] == 'flip-book') {
1085 return "&key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), 'UTF-8'));
1086 }
1087
1088 return "#key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), 'UTF-8'));
1089 }
1090
1091 function embedpress_pdf_block_scripts($attributes)
1092 {
1093
1094 $script_handles = [];
1095
1096 $script_handles[] = 'embedpress-pdfobject';
1097 $script_handles[] = 'embedpress-front';
1098
1099 if (!empty($attributes['adManager'])) {
1100 $script_handles[] = 'embedpress-ads';
1101 }
1102
1103 foreach ($script_handles as $handle) {
1104 wp_enqueue_script($handle);
1105 }
1106
1107 $style_handles = [
1108 'embedpress_blocks-cgb-style-css',
1109 'embedpress-style'
1110 ];
1111
1112 foreach ($style_handles as $handle) {
1113 wp_enqueue_style($handle);
1114 }
1115 }
1116
1117 function embedpress_pdf_render_block($attributes)
1118 {
1119 embedpress_pdf_block_scripts($attributes);
1120
1121 if (!empty($attributes['href'])) {
1122 $renderer = Helper::get_pdf_renderer();
1123 $pdf_url = $attributes['href'];
1124 $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-pdf-' . rand(100, 10000);
1125 $client_id = md5($id);
1126
1127
1128 $unitoption = !empty($attributes['unitoption']) ? $attributes['unitoption'] : 'px';
1129 $width = !empty($attributes['width']) ? $attributes['width'] . $unitoption : (get_options_value('enableEmbedResizeWidth') ?: 600) . 'px';
1130
1131
1132 if ($unitoption == '%') {
1133 $width_class = ' ep-percentage-width';
1134 } else {
1135 $width_class = 'ep-fixed-width';
1136 }
1137 $content_share_class = '';
1138 $share_position_class = '';
1139 $share_position = isset($attributes['sharePosition']) ? $attributes['sharePosition'] : 'right';
1140
1141 if (!empty($attributes['contentShare'])) {
1142 $content_share_class = 'ep-content-share-enabled';
1143 $share_position_class = 'ep-share-position-' . $share_position;
1144 }
1145
1146 $password_correct = isset($_COOKIE['password_correct_' . $client_id]) ? $_COOKIE['password_correct_' . $client_id] : '';
1147 $hash_pass = hash('sha256', wp_salt(32) . md5(isset($attributes['contentPassword']) ? $attributes['contentPassword'] : ''));
1148
1149
1150 $content_protection_class = 'ep-content-protection-enabled';
1151 if (empty($attributes['lockContent']) || empty($attributes['contentPassword']) || $hash_pass === $password_correct) {
1152 $content_protection_class = 'ep-content-protection-disabled';
1153 }
1154
1155
1156 $height = !empty($attributes['height'])
1157 ? $attributes['height'] . 'px'
1158 : (get_options_value('enableEmbedResizeHeight') ?: 600) . 'px';
1159
1160 $gen_settings = get_option(EMBEDPRESS_PLG_NAME);
1161
1162 $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by'];
1163 if (isset($attributes['powered_by'])) {
1164 $powered_by = $attributes['powered_by'];
1165 }
1166
1167 $src = $renderer . ((strpos($renderer, '?') == false) ? '?' : '&') . 'file=' . urlencode($attributes['href']) . getParamData($attributes);
1168
1169 $pass_hash_key = isset($attributes['contentPassword']) ? md5($attributes['contentPassword']) : '';
1170
1171 $aligns = [
1172 'left' => 'ep-alignleft',
1173 'right' => 'ep-alignright',
1174 'center' => 'ep-aligncenter',
1175 'wide' => 'ep-alignwide',
1176 'full' => 'ep-alignfull'
1177 ];
1178 $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : '';
1179 $dimension = "width:$width;height:$height";
1180 ob_start();
1181 ?>
1182
1183
1184 <?php
1185
1186 $url = !empty($attributes['href']) ? $attributes['href'] : '';
1187
1188 $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> ';
1189 if (isset($attributes['viewerStyle']) && $attributes['viewerStyle'] === 'flip-book') {
1190 $src = urlencode($url) . getParamData($attributes);
1191 $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> ';
1192 }
1193 if ($powered_by) {
1194 $embed_code .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
1195 }
1196
1197 $adsAtts = '';
1198 if (!empty($attributes['adManager'])) {
1199 $ad = base64_encode(json_encode($attributes));
1200 $adsAtts = "data-sponsored-id=$client_id data-sponsored-attrs=$ad class=sponsored-mask";
1201 }
1202 ?>
1203
1204 <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); ?> ">
1205 <div class="embedpress-inner-iframe <?php if ($unitoption === '%') {
1206 echo esc_attr('emebedpress-unit-percent');
1207 } ?> ep-doc-<?php echo esc_attr($client_id); ?>" <?php if ($unitoption === '%' && !empty($attributes['width'])) {
1208 $style_attr = 'max-width:' . $attributes['width'] . '%';
1209 } else {
1210 $style_attr = 'max-width:100%';
1211 } ?> style="<?php echo esc_attr($style_attr); ?>" id="<?php echo esc_attr($id); ?>">
1212 <div <?php echo esc_attr($adsAtts); ?>>
1213 <?php
1214 do_action('embedpress_pdf_gutenberg_after_embed', $client_id, 'pdf', $attributes, $pdf_url);
1215 $embed = $embed_code;
1216 if (empty($attributes['lockContent']) || empty($attributes['contentPassword']) || (!empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct))) {
1217
1218 $custom_thumbnail = isset($attributes['customThumbnail']) ? $attributes['customThumbnail'] : '';
1219
1220 echo '<div class="ep-embed-content-wraper">';
1221 $embed = '<div class="position-' . esc_attr($share_position) . '-wraper gutenberg-pdf-wraper">';
1222 $embed .= $embed_code;
1223 $embed .= '</div>';
1224
1225 if (!empty($attributes['contentShare'])) {
1226 $content_id = $attributes['id'];
1227 $embed .= Helper::embed_content_share($content_id, $attributes);
1228 }
1229 echo $embed;
1230 echo '</div>';
1231 } else {
1232 if (!empty($attributes['contentShare'])) {
1233 $content_id = $attributes['clientId'];
1234 $embed = '<div class="position-' . esc_attr($share_position) . '-wraper gutenberg-pdf-wraper">';
1235 $embed .= $embed_code;
1236 $embed .= '</div>';
1237 $embed .= Helper::embed_content_share($content_id, $attributes);
1238 }
1239 echo '<div class="ep-embed-content-wraper">';
1240 do_action('embedpress/display_password_form', $client_id, $embed, $pass_hash_key, $attributes);
1241 echo '</div>';
1242 }
1243 ?>
1244
1245 <?php
1246 if (!empty($attributes['adManager'])) {
1247 $embed = apply_filters('embedpress/generate_ad_template', $embed, $client_id, $attributes, 'gutenberg');
1248 }
1249 ?>
1250 </div>
1251 </div>
1252 </div>
1253 <?php
1254 return ob_get_clean();
1255 }
1256 }
1257
1258 function isGoogleCalendar($url)
1259 {
1260 $pattern = '/^https:\/\/calendar\.google\.com\/calendar\/embed\?.*$/';
1261 return preg_match($pattern, $url);
1262 }
1263
1264 function embedpress_calendar_render_block($attributes)
1265 {
1266
1267 $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-calendar-' . rand(100, 10000);
1268 $url = !empty($attributes['url']) ? $attributes['url'] : '';
1269
1270 if (!isGoogleCalendar($url)) {
1271 return;
1272 }
1273
1274 $is_private = isset($attributes['is_public']);
1275 $client_id = md5($id);
1276 $width = !empty($attributes['width']) ? $attributes['width'] . 'px' : '600px';
1277 $height = !empty($attributes['height']) ? $attributes['height'] . 'px' : '600px';
1278 $gen_settings = get_option(EMBEDPRESS_PLG_NAME);
1279 $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by'];
1280 if (isset($attributes['powered_by'])) {
1281 $powered_by = $attributes['powered_by'];
1282 }
1283
1284 $aligns = [
1285 'left' => 'alignleft',
1286 'right' => 'alignright',
1287 'wide' => 'alignwide',
1288 'full' => 'alignfull'
1289 ];
1290 $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : '';
1291 $dimension = "width:$width;height:$height";
1292 ob_start();
1293 ?>
1294 <div class="embedpress-calendar-gutenberg embedpress-calendar ose-calendar <?php echo esc_attr($alignment) ?>" style="<?php echo esc_attr($dimension); ?>; max-width:100%;">
1295
1296 <?php
1297 if (!empty($url) && !$is_private) {
1298 ?>
1299 <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>
1300 <?php } else {
1301 do_action('embedpress_google_helper_shortcode', 10);
1302 } ?>
1303 <?php do_action('embedpress_calendar_gutenberg_after_embed', $client_id, 'calendar', $attributes); ?>
1304
1305 <?php
1306 if ($powered_by) {
1307 printf('<p class="embedpress-el-powered" style="width:' . esc_attr($width) . '" >%s</p>', __('Powered By EmbedPress', 'embedpress'));
1308 } ?>
1309
1310 </div>
1311 <?php
1312 return ob_get_clean();
1313 }
1314
1315 function embedpress_document_block_scripts()
1316 {
1317 // Exit if this is the admin panel
1318 if (is_admin()) {
1319 return;
1320 }
1321
1322 global $post;
1323
1324 // Check for the presence of the 'embedpress/document' block
1325 $block_exists = false;
1326
1327 if (function_exists('has_block')) {
1328 $block_exists = has_block('embedpress/document');
1329 } elseif (isset($post->post_content)) {
1330 // Fallback for older WordPress versions
1331 $block_exists = strpos($post->post_content, '<!-- wp:embedpress/document') !== false;
1332 }
1333
1334 // If the block exists, enqueue the scripts and styles
1335 if ($block_exists) {
1336 $script_handles = [
1337 'embedpress-pdfobject',
1338 'embedpress-front',
1339 'embedpress_documents_viewer_script'
1340 ];
1341
1342 foreach ($script_handles as $handle) {
1343 wp_enqueue_script($handle);
1344 }
1345
1346 $style_handles = [
1347 'embedpress_blocks-cgb-style-css',
1348 'embedpress-style'
1349 ];
1350
1351 foreach ($style_handles as $handle) {
1352 wp_enqueue_style($handle);
1353 }
1354 }
1355 }
1356 add_action('wp_enqueue_scripts', 'embedpress_document_block_scripts');
1357