PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 4.3.0
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v4.3.0
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 10 months ago plugin.php 10 months ago
plugin.php
1498 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 'sound' => [
975 'type' => "boolean",
976 'default' => true,
977 ],
978 //Spreaker
979 'theme' => array(
980 'type' => 'string',
981 'default' => 'light',
982 ),
983 'color' => array(
984 'type' => 'string',
985 'default' => '',
986 ),
987 'coverImageUrl' => array(
988 'type' => 'string',
989 'default' => '',
990 ),
991 'playlist' => array(
992 'type' => 'boolean',
993 'default' => false,
994 ),
995 'playlistContinuous' => array(
996 'type' => 'boolean',
997 'default' => false,
998 ),
999 'playlistLoop' => array(
1000 'type' => 'boolean',
1001 'default' => false,
1002 ),
1003 'playlistAutoupdate' => array(
1004 'type' => 'boolean',
1005 'default' => true,
1006 ),
1007 'chaptersImage' => array(
1008 'type' => 'boolean',
1009 'default' => true,
1010 ),
1011 'episodeImagePosition' => array(
1012 'type' => 'string',
1013 'default' => 'right',
1014 ),
1015 'hideLikes' => array(
1016 'type' => 'boolean',
1017 'default' => false,
1018 ),
1019 'hideComments' => array(
1020 'type' => 'boolean',
1021 'default' => false,
1022 ),
1023 'hideSharing' => array(
1024 'type' => 'boolean',
1025 'default' => false,
1026 ),
1027 'hideLogo' => array(
1028 'type' => 'boolean',
1029 'default' => false,
1030 ),
1031 'hideEpisodeDescription' => array(
1032 'type' => 'boolean',
1033 'default' => false,
1034 ),
1035 'hidePlaylistDescriptions' => array(
1036 'type' => 'boolean',
1037 'default' => false,
1038 ),
1039 'hidePlaylistImages' => array(
1040 'type' => 'boolean',
1041 'default' => false,
1042 ),
1043 'hideDownload' => array(
1044 'type' => 'boolean',
1045 'default' => false,
1046 ),
1047 'mode' => array(
1048 'type' => 'string',
1049 'default' => 'carousel'
1050 ),
1051 'imageWidth' => array(
1052 'type' => 'number',
1053 'default' => 800
1054 ),
1055 'imageHeight' => array(
1056 'type' => 'number',
1057 'default' => 600
1058 ),
1059 'playerAutoplay' => array(
1060 'type' => 'boolean',
1061 'default' => false
1062 ),
1063 'delay' => array(
1064 'type' => 'number',
1065 'default' => 5
1066 ),
1067 'repeat' => array(
1068 'type' => 'boolean',
1069 'default' => true
1070 ),
1071 'mediaitemsAspectRatio' => array(
1072 'type' => 'boolean',
1073 'default' => true
1074 ),
1075 'mediaitemsEnlarge' => array(
1076 'type' => 'boolean',
1077 'default' => false
1078 ),
1079 'mediaitemsStretch' => array(
1080 'type' => 'boolean',
1081 'default' => false
1082 ),
1083 'mediaitemsCover' => array(
1084 'type' => 'boolean',
1085 'default' => false
1086 ),
1087 'backgroundColor' => array(
1088 'type' => 'string',
1089 'default' => ''
1090 ),
1091 'expiration' => array(
1092 'type' => 'number',
1093 'default' => 60
1094 ),
1095 //Ad attributes
1096 'adManager' => [
1097 'type' => 'boolean',
1098 'default' => false
1099 ],
1100 'adSource' => [
1101 'type' => 'string',
1102 'default' => 'video'
1103 ],
1104 'adContent' => [
1105 'type' => 'object',
1106 ],
1107 'adWidth' => array(
1108 'type' => 'string',
1109 'default' => '300'
1110 ),
1111 'adHeight' => array(
1112 'type' => 'string',
1113 'default' => '200'
1114 ),
1115 'adXPosition' => array(
1116 'type' => 'number',
1117 'default' => 25
1118 ),
1119 'adYPosition' => array(
1120 'type' => 'number',
1121 'default' => 20
1122 ),
1123 'adUrl' => [
1124 'type' => 'string',
1125 'default' => ''
1126 ],
1127 'adStart' => [
1128 'type' => 'string',
1129 'default' => '10'
1130 ],
1131 'adSkipButton' => [
1132 'type' => 'boolean',
1133 'default' => true
1134 ],
1135 'adSkipButtonAfter' => [
1136 'type' => 'string',
1137 'default' => '5'
1138 ]
1139 ),
1140 'render_callback' => 'embedpress_pdf_render_block',
1141 ]);
1142 } elseif ('embedpress-calendar' === $blocks_to_register) {
1143 register_block_type('embedpress/embedpress-calendar', [
1144 'render_callback' => 'embedpress_calendar_render_block',
1145 ]);
1146 } elseif ('document' === $blocks_to_register) {
1147 register_block_type('embedpress/' . $blocks_to_register, [
1148 // 'render_callback' => 'embedpress_document_render_block',
1149 ]);
1150 } else {
1151 register_block_type('embedpress/' . $blocks_to_register);
1152 }
1153 } else {
1154
1155 if (WP_Block_Type_Registry::get_instance()->is_registered('embedpress/' . $blocks_to_register)) {
1156 unregister_block_type('embedpress/' . $blocks_to_register);
1157 }
1158 }
1159 }
1160
1161 endif;
1162 }
1163
1164 add_action('init', 'embedpress_gutenberg_register_all_block');
1165
1166 function getParamData($attributes)
1167 {
1168
1169 $urlParamData = array(
1170 'themeMode' => !empty($attributes['themeMode']) ? $attributes['themeMode'] : 'default',
1171 'toolbar' => !empty($attributes['toolbar']) ? 'true' : 'false',
1172 'position' => $attributes['position'] ?? 'top',
1173 'presentation' => !empty($attributes['presentation']) ? 'true' : 'false',
1174 'lazyLoad' => !empty($attributes['lazyLoad']) ? 'true' : 'false',
1175 'download' => !empty($attributes['download']) ? 'true' : 'false',
1176 'copy_text' => !empty($attributes['copy_text']) ? 'true' : 'false',
1177 'add_text' => !empty($attributes['add_text']) ? 'true' : 'false',
1178 'draw' => !empty($attributes['draw']) ? 'true' : 'false',
1179 'doc_rotation' => !empty($attributes['doc_rotation']) ? 'true' : 'false',
1180 'add_image' => !empty($attributes['add_image']) ? 'true' : 'false',
1181 'doc_details' => !empty($attributes['doc_details']) ? 'true' : 'false',
1182 'zoom_in' => !empty($attributes['zoomIn']) ? 'true' : 'false',
1183 'zoom_out' => !empty($attributes['zoomOut']) ? 'true' : 'false',
1184 'fit_view' => !empty($attributes['fitView']) ? 'true' : 'false',
1185 'bookmark' => !empty($attributes['bookmark']) ? 'true' : 'false',
1186 'sound' => !empty($attributes['sound']) ? 'true' : 'false',
1187 'flipbook_toolbar_position' => !empty($attributes['flipbook_toolbar_position']) ? $attributes['flipbook_toolbar_position'] : 'bottom',
1188 'selection_tool' => isset($attributes['selection_tool']) ? esc_attr($attributes['selection_tool']) : '0',
1189 'scrolling' => isset($attributes['scrolling']) ? esc_attr($attributes['scrolling']) : '-1',
1190 'spreads' => isset($attributes['spreads']) ? esc_attr($attributes['spreads']) : '-1',
1191 );
1192
1193 if ($urlParamData['themeMode'] == 'custom') {
1194 $urlParamData['customColor'] = !empty($attributes['customColor']) ? $attributes['customColor'] : '#403A81';
1195 }
1196
1197 if (isset($attributes['viewerStyle']) && $attributes['viewerStyle'] == 'flip-book') {
1198 return "&key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), 'UTF-8'));
1199 }
1200
1201 return "#key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), 'UTF-8'));
1202 }
1203
1204 function embedpress_pdf_block_scripts($attributes)
1205 {
1206
1207 $script_handles = [];
1208
1209 $script_handles[] = 'embedpress-pdfobject';
1210 $script_handles[] = 'embedpress-remove-round-button';
1211 $script_handles[] = 'embedpress-front';
1212
1213 if (!empty($attributes['adManager'])) {
1214 $script_handles[] = 'embedpress-ads';
1215 }
1216
1217 foreach ($script_handles as $handle) {
1218 wp_enqueue_script($handle);
1219 }
1220
1221 $style_handles = [
1222 'embedpress_blocks-cgb-style-css',
1223 'embedpress-style'
1224 ];
1225
1226 foreach ($style_handles as $handle) {
1227 wp_enqueue_style($handle, false, [], EMBEDPRESS_PLUGIN_VERSION);
1228 }
1229 }
1230
1231 if (!function_exists('has_content_allowed_roles')) {
1232 function has_content_allowed_roles($allowed_roles = [])
1233 {
1234
1235 if ((count($allowed_roles) === 1 && empty($allowed_roles[0]))) {
1236 return true;
1237 }
1238
1239 $current_user = wp_get_current_user();
1240 $user_roles = $current_user->roles;
1241
1242 return !empty(array_intersect($user_roles, $allowed_roles));
1243 }
1244 }
1245
1246
1247
1248 function embedpress_pdf_render_block($attributes)
1249 {
1250 embedpress_pdf_block_scripts($attributes);
1251
1252 if (!empty($attributes['href'])) {
1253 $renderer = Helper::get_pdf_renderer();
1254 $pdf_url = $attributes['href'];
1255 $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-pdf-' . rand(100, 10000);
1256 $client_id = md5($id);
1257
1258
1259 $unitoption = !empty($attributes['unitoption']) ? $attributes['unitoption'] : 'px';
1260 $width = !empty($attributes['width']) ? $attributes['width'] . $unitoption : (get_options_value('enableEmbedResizeWidth') ?: 600) . 'px';
1261
1262
1263 if ($unitoption == '%') {
1264 $width_class = ' ep-percentage-width';
1265 } else {
1266 $width_class = 'ep-fixed-width';
1267 }
1268 $content_share_class = '';
1269 $share_position_class = '';
1270 $share_position = isset($attributes['sharePosition']) ? $attributes['sharePosition'] : 'right';
1271
1272 if (!empty($attributes['contentShare'])) {
1273 $content_share_class = 'ep-content-share-enabled';
1274 $share_position_class = 'ep-share-position-' . $share_position;
1275 }
1276
1277 $password_correct = isset($_COOKIE['password_correct_' . $client_id]) ? $_COOKIE['password_correct_' . $client_id] : '';
1278 $hash_pass = hash('sha256', wp_salt(32) . md5(isset($attributes['contentPassword']) ? $attributes['contentPassword'] : ''));
1279
1280
1281 $content_protection_class = 'ep-content-protection-enabled';
1282 if (empty($attributes['lockContent']) || empty($attributes['contentPassword']) || $hash_pass === $password_correct) {
1283 $content_protection_class = 'ep-content-protection-disabled';
1284 }
1285
1286
1287 $height = !empty($attributes['height'])
1288 ? $attributes['height'] . 'px'
1289 : (get_options_value('enableEmbedResizeHeight') ?: 600) . 'px';
1290
1291 $gen_settings = get_option(EMBEDPRESS_PLG_NAME);
1292
1293 $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by'];
1294 if (isset($attributes['powered_by'])) {
1295 $powered_by = $attributes['powered_by'];
1296 }
1297
1298 $src = $renderer . ((strpos($renderer, '?') == false) ? '?' : '&') . 'file=' . urlencode($attributes['href']) . getParamData($attributes);
1299
1300 $pass_hash_key = isset($attributes['contentPassword']) ? md5($attributes['contentPassword']) : '';
1301
1302 $aligns = [
1303 'left' => 'ep-alignleft',
1304 'right' => 'ep-alignright',
1305 'center' => 'ep-aligncenter',
1306 'wide' => 'ep-alignwide',
1307 'full' => 'ep-alignfull'
1308 ];
1309 $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : '';
1310 $dimension = "width:$width;height:$height";
1311 ob_start();
1312 ?>
1313
1314
1315 <?php
1316
1317 $url = !empty($attributes['href']) ? $attributes['href'] : '';
1318
1319 $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> ';
1320
1321 if (isset($attributes['viewerStyle']) && $attributes['viewerStyle'] === 'flip-book') {
1322 $src = urlencode($url) . getParamData($attributes);
1323 $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> ';
1324 }
1325 if ($powered_by) {
1326 $embed_code .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
1327 }
1328
1329 $adsAtts = '';
1330 if (!empty($attributes['adManager'])) {
1331 $ad = base64_encode(json_encode($attributes));
1332 $adsAtts = "data-sponsored-id=$client_id data-sponsored-attrs=$ad class=sponsored-mask";
1333 }
1334 ?>
1335
1336 <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); ?> ">
1337 <div class="embedpress-inner-iframe <?php if ($unitoption === '%') {
1338 echo esc_attr('emebedpress-unit-percent');
1339 } ?> ep-doc-<?php echo esc_attr($client_id); ?>" <?php if ($unitoption === '%' && !empty($attributes['width'])) {
1340 $style_attr = 'max-width:' . $attributes['width'] . '%';
1341 } else {
1342 $style_attr = 'max-width:100%';
1343 } ?> style="<?php echo esc_attr($style_attr); ?>" id="<?php echo esc_attr($id); ?>">
1344 <div <?php echo esc_attr($adsAtts); ?>>
1345 <?php
1346 do_action('embedpress_pdf_gutenberg_after_embed', $client_id, 'pdf', $attributes, $pdf_url);
1347 $embed = $embed_code;
1348
1349 if (
1350 !apply_filters('embedpress/is_allow_rander', false) ||
1351 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']))
1352 ) {
1353
1354 $custom_thumbnail = isset($attributes['customThumbnail']) ? $attributes['customThumbnail'] : '';
1355
1356 echo '<div class="ep-embed-content-wraper">';
1357 $embed = '<div class="position-' . esc_attr($share_position) . '-wraper gutenberg-pdf-wraper">';
1358 $embed .= $embed_code;
1359 $embed .= '</div>';
1360
1361 if (!empty($attributes['contentShare'])) {
1362 $content_id = $attributes['id'];
1363 $embed .= Helper::embed_content_share($content_id, $attributes);
1364 }
1365 echo $embed;
1366 echo '</div>';
1367 } else {
1368 if (!empty($attributes['contentShare'])) {
1369 $content_id = $attributes['clientId'];
1370 $embed = '<div class="position-' . esc_attr($share_position) . '-wraper gutenberg-pdf-wraper">';
1371 $embed .= $embed_code;
1372 $embed .= '</div>';
1373 $embed .= Helper::embed_content_share($content_id, $attributes);
1374 }
1375 echo '<div class="ep-embed-content-wraper">';
1376 if ($attributes['protectionType'] == 'password') {
1377 do_action('embedpress/display_password_form', $client_id, $embed, $pass_hash_key, $attributes);
1378 } else {
1379 do_action('embedpress/content_protection_content', $client_id, $attributes['protectionMessage'], $attributes['userRole']);
1380 }
1381 echo '</div>';
1382 }
1383
1384 ?>
1385
1386 <?php
1387 if (!empty($attributes['adManager'])) {
1388 $embed = apply_filters('embedpress/generate_ad_template', $embed, $client_id, $attributes, 'gutenberg');
1389 }
1390 ?>
1391 </div>
1392 </div>
1393 </div>
1394 <?php
1395 return ob_get_clean();
1396 }
1397 }
1398
1399 function isGoogleCalendar($url)
1400 {
1401 $pattern = '/^https:\/\/calendar\.google\.com\/calendar\/embed\?.*$/';
1402 return preg_match($pattern, $url);
1403 }
1404
1405 function embedpress_calendar_render_block($attributes)
1406 {
1407
1408 $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-calendar-' . rand(100, 10000);
1409 $url = !empty($attributes['url']) ? $attributes['url'] : '';
1410
1411 if (!isGoogleCalendar($url)) {
1412 return;
1413 }
1414
1415 $is_private = isset($attributes['is_public']);
1416 $client_id = md5($id);
1417 $width = !empty($attributes['width']) ? $attributes['width'] . 'px' : '600px';
1418 $height = !empty($attributes['height']) ? $attributes['height'] . 'px' : '600px';
1419 $gen_settings = get_option(EMBEDPRESS_PLG_NAME);
1420 $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by'];
1421 if (isset($attributes['powered_by'])) {
1422 $powered_by = $attributes['powered_by'];
1423 }
1424
1425 $aligns = [
1426 'left' => 'alignleft',
1427 'right' => 'alignright',
1428 'wide' => 'alignwide',
1429 'full' => 'alignfull'
1430 ];
1431 $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : '';
1432 $dimension = "width:$width;height:$height";
1433 ob_start();
1434 ?>
1435 <div class="embedpress-calendar-gutenberg embedpress-calendar ose-calendar <?php echo esc_attr($alignment) ?>" style="<?php echo esc_attr($dimension); ?>; max-width:100%;">
1436
1437 <?php
1438 if (!empty($url) && !$is_private) {
1439 ?>
1440 <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>
1441 <?php } else {
1442 do_action('embedpress_google_helper_shortcode', 10);
1443 } ?>
1444 <?php do_action('embedpress_calendar_gutenberg_after_embed', $client_id, 'calendar', $attributes); ?>
1445
1446 <?php
1447 if ($powered_by) {
1448 printf('<p class="embedpress-el-powered" style="width:' . esc_attr($width) . '" >%s</p>', __('Powered By EmbedPress', 'embedpress'));
1449 } ?>
1450
1451 </div>
1452 <?php
1453 return ob_get_clean();
1454 }
1455
1456 function embedpress_document_block_scripts()
1457 {
1458 // Exit if this is the admin panel
1459 if (is_admin()) {
1460 return;
1461 }
1462
1463 global $post;
1464
1465 // Check for the presence of the 'embedpress/document' block
1466 $block_exists = false;
1467
1468 if (function_exists('has_block')) {
1469 $block_exists = has_block('embedpress/document');
1470 } elseif (isset($post->post_content)) {
1471 // Fallback for older WordPress versions
1472 $block_exists = strpos($post->post_content, '<!-- wp:embedpress/document') !== false;
1473 }
1474
1475 // If the block exists, enqueue the scripts and styles
1476 if ($block_exists) {
1477 $script_handles = [
1478 'embedpress-pdfobject',
1479 'embedpress-front',
1480 'embedpress_documents_viewer_script'
1481 ];
1482
1483 foreach ($script_handles as $handle) {
1484 wp_enqueue_script($handle);
1485 }
1486
1487 $style_handles = [
1488 'embedpress_blocks-cgb-style-css',
1489 'embedpress-style'
1490 ];
1491
1492 foreach ($style_handles as $handle) {
1493 wp_enqueue_style($handle, false, [], EMBEDPRESS_PLUGIN_VERSION);
1494 }
1495 }
1496 }
1497 add_action('wp_enqueue_scripts', 'embedpress_document_block_scripts');
1498