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