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