PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 4.2.5
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v4.2.5
4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / Gutenberg / plugin.php
embedpress / Gutenberg Last commit date
block-backend 1 year ago css 1 year ago dist 1 year ago plugin.php 1 year ago
plugin.php
1444 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
339 'videosize' => [
340 'type' => 'string',
341 'default' => 'fixed'
342 ],
343
344 'loadmore' => [
345 'type' => 'boolean',
346 'default' => false
347 ],
348 //Youtube Attributes
349 'starttime' => [
350 'type' => 'string',
351 ],
352 'endtime' => [
353 'type' => 'string',
354 ],
355 'autoplay' => [
356 'type' => 'boolean',
357 'default' => false
358 ],
359 'controls' => [
360 'type' => 'string',
361 ],
362 'progressbarcolor' => [
363 'type' => 'string',
364 ],
365 'videoannotations' => [
366 'type' => 'string',
367 ],
368 'closedcaptions' => [
369 'type' => 'boolean',
370 'default' => true
371 ],
372 'relatedvideos' => [
373 'type' => 'boolean',
374 'default' => true
375 ],
376 'fullscreen' => [
377 'type' => 'boolean',
378 'default' => true
379 ],
380
381 'modestbranding' => [
382 'type' => 'string',
383 ],
384 'pagesize' => [
385 'type' => 'number',
386 ],
387 // custom player attributes
388 'autoPause' => [
389 'type' => 'boolean',
390 'default' => false
391 ],
392 'customPlayer' => [
393 'type' => 'boolean',
394 'default' => false
395 ],
396
397 'posterThumbnail' => [
398 'type' => 'string',
399 'default' => ''
400 ],
401
402 'playerPreset' => [
403 'type' => 'string',
404 'default' => ''
405 ],
406
407 'playerColor' => [
408 'type' => 'string',
409 'default' => '#2e2e99'
410 ],
411
412 'playerPip' => [
413 'type' => 'boolean',
414 'default' => false
415 ],
416
417 'playerRestart' => [
418 'type' => 'boolean',
419 'default' => true
420 ],
421
422 'playerRewind' => [
423 'type' => 'boolean',
424 'default' => true
425 ],
426
427 'playerFastForward' => [
428 'type' => 'boolean',
429 'default' => true
430 ],
431 'playerTooltip' => [
432 'type' => 'boolean',
433 'default' => true
434 ],
435 'playerHideControls' => [
436 'type' => 'boolean',
437 'default' => true
438 ],
439 'playerDownload' => [
440 'type' => 'boolean',
441 'default' => true
442 ],
443 //Wistia Attributes
444 'wstarttime' => [
445 'type' => 'string',
446 ],
447 'wautoplay' => [
448 'type' => 'boolean',
449 'default' => true
450 ],
451 'scheme' => [
452 'type' => 'string',
453 ],
454 'captions' => [
455 'type' => 'boolean',
456 'default' => true
457 ],
458 'playbutton' => [
459 'type' => 'boolean',
460 'default' => true
461 ],
462 'smallplaybutton' => [
463 'type' => 'boolean',
464 'default' => true
465 ],
466 'playbar' => [
467 'type' => 'boolean',
468 'default' => true
469 ],
470 'resumable' => [
471 'type' => 'boolean',
472 'default' => true
473 ],
474 'wistiafocus' => [
475 'type' => 'boolean',
476 'default' => true
477 ],
478 'volumecontrol' => [
479 'type' => 'boolean',
480 'default' => true
481 ],
482 'volume' => [
483 'type' => 'number',
484 'default' => 100
485 ],
486 'rewind' => [
487 'type' => 'boolean',
488 'default' => false
489 ],
490 'wfullscreen' => [
491 'type' => 'boolean',
492 'default' => true
493 ],
494
495 // Vimeo attributes
496 'vstarttime' => [
497 'type' => 'string',
498 ],
499 'vautoplay' => [
500 'type' => 'boolean',
501 'default' => false
502 ],
503 'vscheme' => [
504 'type' => 'string',
505 ],
506 'vtitle' => [
507 'type' => 'boolean',
508 'default' => true
509 ],
510 'vauthor' => [
511 'type' => 'boolean',
512 'default' => true
513 ],
514 'vavatar' => [
515 'type' => 'boolean',
516 'default' => true
517 ],
518 'vloop' => [
519 'type' => 'boolean',
520 'default' => false
521 ],
522 'vautopause' => [
523 'type' => 'boolean',
524 'default' => false
525 ],
526 'vdnt' => [
527 'type' => 'boolean',
528 'default' => false
529 ],
530
531 // instaFeed attributes
532 'instaLayout' => [
533 'type' => 'string',
534 'default' => 'insta-grid',
535 ],
536 'instafeedFeedType' => [
537 'type' => 'string',
538 'default' => 'user_account_type',
539 ],
540 'instafeedAccountType' => [
541 'type' => 'string',
542 'default' => 'personal',
543 ],
544 'instafeedProfileImage' => [
545 'type' => 'boolean',
546 'default' => true,
547 ],
548 'instafeedProfileImageUrl' => [
549 'type' => 'string',
550 'default' => '',
551 ],
552 'instafeedFollowBtn' => [
553 'type' => 'boolean',
554 'default' => true,
555 ],
556 'instafeedFollowBtnLabel' => [
557 'type' => 'string',
558 'default' => 'Follow',
559 ],
560 'instafeedPostsCount' => [
561 'type' => 'boolean',
562 'default' => true,
563 ],
564 'instafeedPostsCountText' => [
565 'type' => 'string',
566 'default' => '[count] posts',
567 ],
568 'instafeedFollowersCount' => [
569 'type' => 'boolean',
570 'default' => true,
571 ],
572 'instafeedFollowersCountText' => [
573 'type' => 'string',
574 'default' => '[count] followers',
575 ],
576 'instafeedAccName' => [
577 'type' => 'boolean',
578 'default' => true,
579 ],
580 'instafeedColumns' => [
581 'type' => 'string',
582 'default' => '3',
583 ],
584 'instafeedColumnsGap' => [
585 'type' => 'string',
586 'default' => '5',
587 ],
588 'instafeedPostsPerPage' => [
589 'type' => 'string',
590 'default' => '12',
591 ],
592 'instafeedTab' => [
593 'type' => 'boolean',
594 'default' => true,
595 ],
596 'instafeedLikesCount' => [
597 'type' => 'boolean',
598 'default' => true,
599 ],
600 'instafeedCommentsCount' => [
601 'type' => 'boolean',
602 'default' => true,
603 ],
604 'instafeedPopup' => [
605 'type' => 'boolean',
606 'default' => true,
607 ],
608 'instafeedPopupFollowBtn' => [
609 'type' => 'boolean',
610 'default' => true,
611 ],
612 'instafeedPopupFollowBtnLabel' => [
613 'type' => 'string',
614 'default' => 'Follow',
615 ],
616 'instafeedLoadmore' => [
617 'type' => 'boolean',
618 'default' => true,
619 ],
620 'instafeedLoadmoreLabel' => [
621 'type' => 'string',
622 'default' => 'Load More',
623 ],
624 'slidesShow' => [
625 'type' => 'string',
626 'default' => '4',
627 ],
628 'slidesScroll' => [
629 'type' => 'string',
630 'default' => '4',
631 ],
632 'carouselAutoplay' => [
633 'type' => 'boolean',
634 'default' => false,
635 ],
636 'autoplaySpeed' => [
637 'type' => 'string',
638 'default' => '3000',
639 ],
640 'transitionSpeed' => [
641 'type' => 'string',
642 'default' => '1000',
643 ],
644 'carouselLoop' => [
645 'type' => 'boolean',
646 'default' => true,
647 ],
648 'carouselArrows' => [
649 'type' => 'boolean',
650 'default' => true,
651 ],
652 'carouselSpacing' => [
653 'type' => 'string',
654 'default' => '0',
655 ],
656 'carouselDots' => [
657 'type' => 'boolean',
658 'default' => false,
659 ],
660 // Calendly attributes
661 'cEmbedType' => array(
662 'type' => 'string',
663 'default' => 'inline'
664 ),
665 'calendlyData' => array(
666 'type' => 'boolean',
667 'default' => false
668 ),
669 'hideCookieBanner' => array(
670 'type' => 'boolean',
671 'default' => false
672 ),
673 'hideEventTypeDetails' => array(
674 'type' => 'boolean',
675 'default' => false
676 ),
677 'cBackgroundColor' => array(
678 'type' => 'string',
679 'default' => 'ffffff'
680 ),
681 'cTextColor' => array(
682 'type' => 'string',
683 'default' => '1A1A1A'
684 ),
685 'cButtonLinkColor' => array(
686 'type' => 'string',
687 'default' => '0000FF'
688 ),
689 'cPopupButtonText' => array(
690 'type' => 'string',
691 'default' => 'Schedule time with me'
692 ),
693 'cPopupButtonBGColor' => array(
694 'type' => 'string',
695 'default' => '#0000FF'
696 ),
697 'cPopupButtonTextColor' => array(
698 'type' => 'string',
699 'default' => '#FFFFFF'
700 ),
701 'cPopupLinkText' => array(
702 'type' => 'string',
703 'default' => 'Schedule time with me'
704 ),
705
706 //Ad attributes
707 'adManager' => [
708 'type' => 'boolean',
709 'default' => false
710 ],
711 'adSource' => [
712 'type' => 'string',
713 'default' => 'video'
714 ],
715 'adContent' => [
716 'type' => 'object',
717 ],
718 'adWidth' => array(
719 'type' => 'string',
720 'default' => '300'
721 ),
722 'adHeight' => array(
723 'type' => 'string',
724 'default' => '200'
725 ),
726 'adXPosition' => array(
727 'type' => 'number',
728 'default' => 25
729 ),
730 'adYPosition' => array(
731 'type' => 'number',
732 'default' => 10
733 ),
734 'adUrl' => [
735 'type' => 'string',
736 'default' => ''
737 ],
738 'adStart' => [
739 'type' => 'string',
740 'default' => '10'
741 ],
742 'adSkipButton' => [
743 'type' => 'boolean',
744 'default' => true
745 ],
746 'adSkipButtonAfter' => [
747 'type' => 'string',
748 'default' => '5'
749 ]
750
751 ),
752 ]);
753 } elseif ('embedpress-pdf' === $blocks_to_register) {
754 register_block_type('embedpress/embedpress-pdf', [
755 'attributes' => array(
756 'clientId' => [
757 'type' => 'string',
758 ],
759 // 'height' => [
760 // 'type' => 'string',
761 // 'default' => (int) get_options_value('enableEmbedResizeHeight')
762 // ],
763 // 'width' => [
764 // 'type' => 'string',
765 // 'default' => (int) get_options_value('enableEmbedResizeWidth')
766 // ],
767 'customColor' => [
768 'type' => 'string',
769 'default' => get_options_value('custom_color')
770 ],
771 'powered_by' => [
772 'type' => 'boolean',
773 'default' => true
774 ],
775 'lockContent' => [
776 'type' => 'boolean',
777 'default' => false
778 ],
779 'protectionType' => [
780 'type' => 'string',
781 'default' => 'password'
782 ],
783 'userRole' => [
784 'type' => 'array',
785 'default' => []
786 ],
787 'protectionMessage' => [
788 'type' => 'string',
789 'default' => 'You do not have access to this content. Only users with the following roles can view it: [user_roles]'
790 ],
791 'lockHeading' => [
792 'type' => 'string',
793 'default' => 'Content Locked'
794 ],
795 'lockSubHeading' => [
796 'type' => 'string',
797 'default' => 'Content is locked and requires password to access it.'
798 ],
799 'passwordPlaceholder' => [
800 'type' => 'string',
801 'default' => 'Password'
802 ],
803 'submitButtonText' => [
804 'type' => 'string',
805 'default' => 'Unlock'
806 ],
807 'submitUnlockingText' => [
808 'type' => 'string',
809 'default' => 'Unlocking'
810 ],
811 'lockErrorMessage' => [
812 'type' => 'string',
813 'default' => 'Oops, that wasn\'t the right password. Try again.'
814 ],
815 'enableFooterMessage' => [
816 'type' => 'boolean',
817 'default' => false
818 ],
819 'footerMessage' => [
820 'type' => 'string',
821 'default' => 'In case you don\'t have the password, kindly reach out to content owner or administrator to request access.'
822 ],
823 'contentPassword' => [
824 'type' => 'string',
825 'default' => ''
826 ],
827 'contentShare' => [
828 'type' => 'boolean',
829 'default' => false
830 ],
831 'sharePosition' => [
832 'type' => 'string',
833 'default' => 'right'
834 ],
835 'presentation' => [
836 'type' => "boolean",
837 'default' => true,
838 ],
839 'lazyLoad' => [
840 'type' => "boolean",
841 'default' => false,
842 ],
843
844 'position' => [
845 'type' => "string",
846 'default' => 'top',
847 ],
848 'flipbook_toolbar_position' => [
849 'type' => "string",
850 'default' => 'bottom',
851 ],
852
853 'print' => [
854 'type' => "boolean",
855 'default' => true,
856 ],
857
858 'download' => [
859 'type' => "boolean",
860 'default' => true,
861 ],
862 'open' => [
863 'type' => "boolean",
864 'default' => true,
865 ],
866 'selection_tool' => [
867 'type' => "string",
868 'default' => '0',
869 ],
870 'scrolling' => [
871 'type' => "string",
872 'default' => '-1',
873 ],
874 'spreads' => [
875 'type' => "string",
876 'default' => '-1',
877 ],
878 'copy_text' => [
879 'type' => "boolean",
880 'default' => true,
881 ],
882 'add_text' => [
883 'type' => "boolean",
884 'default' => true,
885 ],
886 'draw' => [
887 'type' => "boolean",
888 'default' => true,
889 ],
890 'toolbar' => [
891 'type' => "boolean",
892 'default' => true,
893 ],
894 'doc_details' => [
895 'type' => "boolean",
896 'default' => true,
897 ],
898 'doc_rotation' => [
899 'type' => "boolean",
900 'default' => true,
901 ],
902 'add_image' => [
903 'type' => "boolean",
904 'default' => true,
905 ],
906 'unitoption' => [
907 'type' => "string",
908 'default' => '%',
909 ],
910 'zoomIn' => [
911 'type' => "boolean",
912 'default' => true,
913 ],
914 'zoomOut' => [
915 'type' => "boolean",
916 'default' => true,
917 ],
918 'fitView' => [
919 'type' => "boolean",
920 'default' => true,
921 ],
922 'bookmark' => [
923 'type' => "boolean",
924 'default' => true,
925 ],
926 //Spreaker
927 'theme' => array(
928 'type' => 'string',
929 'default' => 'light',
930 ),
931 'color' => array(
932 'type' => 'string',
933 'default' => '',
934 ),
935 'coverImageUrl' => array(
936 'type' => 'string',
937 'default' => '',
938 ),
939 'playlist' => array(
940 'type' => 'boolean',
941 'default' => false,
942 ),
943 'playlistContinuous' => array(
944 'type' => 'boolean',
945 'default' => false,
946 ),
947 'playlistLoop' => array(
948 'type' => 'boolean',
949 'default' => false,
950 ),
951 'playlistAutoupdate' => array(
952 'type' => 'boolean',
953 'default' => true,
954 ),
955 'chaptersImage' => array(
956 'type' => 'boolean',
957 'default' => true,
958 ),
959 'episodeImagePosition' => array(
960 'type' => 'string',
961 'default' => 'right',
962 ),
963 'hideLikes' => array(
964 'type' => 'boolean',
965 'default' => false,
966 ),
967 'hideComments' => array(
968 'type' => 'boolean',
969 'default' => false,
970 ),
971 'hideSharing' => array(
972 'type' => 'boolean',
973 'default' => false,
974 ),
975 'hideLogo' => array(
976 'type' => 'boolean',
977 'default' => false,
978 ),
979 'hideEpisodeDescription' => array(
980 'type' => 'boolean',
981 'default' => false,
982 ),
983 'hidePlaylistDescriptions' => array(
984 'type' => 'boolean',
985 'default' => false,
986 ),
987 'hidePlaylistImages' => array(
988 'type' => 'boolean',
989 'default' => false,
990 ),
991 'hideDownload' => array(
992 'type' => 'boolean',
993 'default' => false,
994 ),
995 'mode' => array(
996 'type' => 'string',
997 'default' => 'carousel'
998 ),
999 'imageWidth' => array(
1000 'type' => 'number',
1001 'default' => 800
1002 ),
1003 'imageHeight' => array(
1004 'type' => 'number',
1005 'default' => 600
1006 ),
1007 'playerAutoplay' => array(
1008 'type' => 'boolean',
1009 'default' => false
1010 ),
1011 'delay' => array(
1012 'type' => 'number',
1013 'default' => 5
1014 ),
1015 'repeat' => array(
1016 'type' => 'boolean',
1017 'default' => true
1018 ),
1019 'mediaitemsAspectRatio' => array(
1020 'type' => 'boolean',
1021 'default' => true
1022 ),
1023 'mediaitemsEnlarge' => array(
1024 'type' => 'boolean',
1025 'default' => false
1026 ),
1027 'mediaitemsStretch' => array(
1028 'type' => 'boolean',
1029 'default' => false
1030 ),
1031 'mediaitemsCover' => array(
1032 'type' => 'boolean',
1033 'default' => false
1034 ),
1035 'backgroundColor' => array(
1036 'type' => 'string',
1037 'default' => ''
1038 ),
1039 'expiration' => array(
1040 'type' => 'number',
1041 'default' => 60
1042 ),
1043 //Ad attributes
1044 'adManager' => [
1045 'type' => 'boolean',
1046 'default' => false
1047 ],
1048 'adSource' => [
1049 'type' => 'string',
1050 'default' => 'video'
1051 ],
1052 'adContent' => [
1053 'type' => 'object',
1054 ],
1055 'adWidth' => array(
1056 'type' => 'string',
1057 'default' => '300'
1058 ),
1059 'adHeight' => array(
1060 'type' => 'string',
1061 'default' => '200'
1062 ),
1063 'adXPosition' => array(
1064 'type' => 'number',
1065 'default' => 25
1066 ),
1067 'adYPosition' => array(
1068 'type' => 'number',
1069 'default' => 20
1070 ),
1071 'adUrl' => [
1072 'type' => 'string',
1073 'default' => ''
1074 ],
1075 'adStart' => [
1076 'type' => 'string',
1077 'default' => '10'
1078 ],
1079 'adSkipButton' => [
1080 'type' => 'boolean',
1081 'default' => true
1082 ],
1083 'adSkipButtonAfter' => [
1084 'type' => 'string',
1085 'default' => '5'
1086 ]
1087 ),
1088 'render_callback' => 'embedpress_pdf_render_block',
1089 ]);
1090 } elseif ('embedpress-calendar' === $blocks_to_register) {
1091 register_block_type('embedpress/embedpress-calendar', [
1092 'render_callback' => 'embedpress_calendar_render_block',
1093 ]);
1094 } elseif ('document' === $blocks_to_register) {
1095 register_block_type('embedpress/' . $blocks_to_register, [
1096 // 'render_callback' => 'embedpress_document_render_block',
1097 ]);
1098 } else {
1099 register_block_type('embedpress/' . $blocks_to_register);
1100 }
1101 } else {
1102
1103 if (WP_Block_Type_Registry::get_instance()->is_registered('embedpress/' . $blocks_to_register)) {
1104 unregister_block_type('embedpress/' . $blocks_to_register);
1105 }
1106 }
1107 }
1108
1109 endif;
1110 }
1111
1112 add_action('init', 'embedpress_gutenberg_register_all_block');
1113
1114 function getParamData($attributes)
1115 {
1116
1117 $urlParamData = array(
1118 'themeMode' => !empty($attributes['themeMode']) ? $attributes['themeMode'] : 'default',
1119 'toolbar' => !empty($attributes['toolbar']) ? 'true' : 'false',
1120 'position' => $attributes['position'] ?? 'top',
1121 'presentation' => !empty($attributes['presentation']) ? 'true' : 'false',
1122 'lazyLoad' => !empty($attributes['lazyLoad']) ? 'true' : 'false',
1123 'download' => !empty($attributes['download']) ? 'true' : 'false',
1124 'copy_text' => !empty($attributes['copy_text']) ? 'true' : 'false',
1125 'add_text' => !empty($attributes['add_text']) ? 'true' : 'false',
1126 'draw' => !empty($attributes['draw']) ? 'true' : 'false',
1127 'doc_rotation' => !empty($attributes['doc_rotation']) ? 'true' : 'false',
1128 'add_image' => !empty($attributes['add_image']) ? 'true' : 'false',
1129 'doc_details' => !empty($attributes['doc_details']) ? 'true' : 'false',
1130 'zoom_in' => !empty($attributes['zoomIn']) ? 'true' : 'false',
1131 'zoom_out' => !empty($attributes['zoomOut']) ? 'true' : 'false',
1132 'fit_view' => !empty($attributes['fitView']) ? 'true' : 'false',
1133 'bookmark' => !empty($attributes['bookmark']) ? 'true' : 'false',
1134 'flipbook_toolbar_position' => !empty($attributes['flipbook_toolbar_position']) ? $attributes['flipbook_toolbar_position'] : 'bottom',
1135 'selection_tool' => isset($attributes['selection_tool']) ? esc_attr($attributes['selection_tool']) : '0',
1136 'scrolling' => isset($attributes['scrolling']) ? esc_attr($attributes['scrolling']) : '-1',
1137 'spreads' => isset($attributes['spreads']) ? esc_attr($attributes['spreads']) : '-1',
1138 );
1139
1140 if ($urlParamData['themeMode'] == 'custom') {
1141 $urlParamData['customColor'] = !empty($attributes['customColor']) ? $attributes['customColor'] : '#403A81';
1142 }
1143
1144 if (isset($attributes['viewerStyle']) && $attributes['viewerStyle'] == 'flip-book') {
1145 return "&key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), 'UTF-8'));
1146 }
1147
1148 return "#key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), 'UTF-8'));
1149 }
1150
1151 function embedpress_pdf_block_scripts($attributes)
1152 {
1153
1154 $script_handles = [];
1155
1156 $script_handles[] = 'embedpress-pdfobject';
1157 $script_handles[] = 'embedpress-front';
1158
1159 if (!empty($attributes['adManager'])) {
1160 $script_handles[] = 'embedpress-ads';
1161 }
1162
1163 foreach ($script_handles as $handle) {
1164 wp_enqueue_script($handle);
1165 }
1166
1167 $style_handles = [
1168 'embedpress_blocks-cgb-style-css',
1169 'embedpress-style'
1170 ];
1171
1172 foreach ($style_handles as $handle) {
1173 wp_enqueue_style($handle, false, [], EMBEDPRESS_PLUGIN_VERSION);
1174 }
1175 }
1176
1177 if (!function_exists('has_content_allowed_roles')) {
1178 function has_content_allowed_roles($allowed_roles = [])
1179 {
1180
1181 if ((count($allowed_roles) === 1 && empty($allowed_roles[0]))) {
1182 return true;
1183 }
1184
1185 $current_user = wp_get_current_user();
1186 $user_roles = $current_user->roles;
1187
1188 return !empty(array_intersect($user_roles, $allowed_roles));
1189 }
1190 }
1191
1192
1193
1194 function embedpress_pdf_render_block($attributes)
1195 {
1196 embedpress_pdf_block_scripts($attributes);
1197
1198 if (!empty($attributes['href'])) {
1199 $renderer = Helper::get_pdf_renderer();
1200 $pdf_url = $attributes['href'];
1201 $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-pdf-' . rand(100, 10000);
1202 $client_id = md5($id);
1203
1204
1205 $unitoption = !empty($attributes['unitoption']) ? $attributes['unitoption'] : 'px';
1206 $width = !empty($attributes['width']) ? $attributes['width'] . $unitoption : (get_options_value('enableEmbedResizeWidth') ?: 600) . 'px';
1207
1208
1209 if ($unitoption == '%') {
1210 $width_class = ' ep-percentage-width';
1211 } else {
1212 $width_class = 'ep-fixed-width';
1213 }
1214 $content_share_class = '';
1215 $share_position_class = '';
1216 $share_position = isset($attributes['sharePosition']) ? $attributes['sharePosition'] : 'right';
1217
1218 if (!empty($attributes['contentShare'])) {
1219 $content_share_class = 'ep-content-share-enabled';
1220 $share_position_class = 'ep-share-position-' . $share_position;
1221 }
1222
1223 $password_correct = isset($_COOKIE['password_correct_' . $client_id]) ? $_COOKIE['password_correct_' . $client_id] : '';
1224 $hash_pass = hash('sha256', wp_salt(32) . md5(isset($attributes['contentPassword']) ? $attributes['contentPassword'] : ''));
1225
1226
1227 $content_protection_class = 'ep-content-protection-enabled';
1228 if (empty($attributes['lockContent']) || empty($attributes['contentPassword']) || $hash_pass === $password_correct) {
1229 $content_protection_class = 'ep-content-protection-disabled';
1230 }
1231
1232
1233 $height = !empty($attributes['height'])
1234 ? $attributes['height'] . 'px'
1235 : (get_options_value('enableEmbedResizeHeight') ?: 600) . 'px';
1236
1237 $gen_settings = get_option(EMBEDPRESS_PLG_NAME);
1238
1239 $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by'];
1240 if (isset($attributes['powered_by'])) {
1241 $powered_by = $attributes['powered_by'];
1242 }
1243
1244 $src = $renderer . ((strpos($renderer, '?') == false) ? '?' : '&') . 'file=' . urlencode($attributes['href']) . getParamData($attributes);
1245
1246 $pass_hash_key = isset($attributes['contentPassword']) ? md5($attributes['contentPassword']) : '';
1247
1248 $aligns = [
1249 'left' => 'ep-alignleft',
1250 'right' => 'ep-alignright',
1251 'center' => 'ep-aligncenter',
1252 'wide' => 'ep-alignwide',
1253 'full' => 'ep-alignfull'
1254 ];
1255 $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : '';
1256 $dimension = "width:$width;height:$height";
1257 ob_start();
1258 ?>
1259
1260
1261 <?php
1262
1263 $url = !empty($attributes['href']) ? $attributes['href'] : '';
1264
1265 $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> ';
1266
1267 if (isset($attributes['viewerStyle']) && $attributes['viewerStyle'] === 'flip-book') {
1268 $src = urlencode($url) . getParamData($attributes);
1269 $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> ';
1270 }
1271 if ($powered_by) {
1272 $embed_code .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
1273 }
1274
1275 $adsAtts = '';
1276 if (!empty($attributes['adManager'])) {
1277 $ad = base64_encode(json_encode($attributes));
1278 $adsAtts = "data-sponsored-id=$client_id data-sponsored-attrs=$ad class=sponsored-mask";
1279 }
1280 ?>
1281
1282 <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); ?> ">
1283 <div class="embedpress-inner-iframe <?php if ($unitoption === '%') {
1284 echo esc_attr('emebedpress-unit-percent');
1285 } ?> ep-doc-<?php echo esc_attr($client_id); ?>" <?php if ($unitoption === '%' && !empty($attributes['width'])) {
1286 $style_attr = 'max-width:' . $attributes['width'] . '%';
1287 } else {
1288 $style_attr = 'max-width:100%';
1289 } ?> style="<?php echo esc_attr($style_attr); ?>" id="<?php echo esc_attr($id); ?>">
1290 <div <?php echo esc_attr($adsAtts); ?>>
1291 <?php
1292 do_action('embedpress_pdf_gutenberg_after_embed', $client_id, 'pdf', $attributes, $pdf_url);
1293 $embed = $embed_code;
1294
1295 if (
1296 !apply_filters('embedpress/is_allow_rander', false) ||
1297 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']))
1298 ) {
1299
1300 $custom_thumbnail = isset($attributes['customThumbnail']) ? $attributes['customThumbnail'] : '';
1301
1302 echo '<div class="ep-embed-content-wraper">';
1303 $embed = '<div class="position-' . esc_attr($share_position) . '-wraper gutenberg-pdf-wraper">';
1304 $embed .= $embed_code;
1305 $embed .= '</div>';
1306
1307 if (!empty($attributes['contentShare'])) {
1308 $content_id = $attributes['id'];
1309 $embed .= Helper::embed_content_share($content_id, $attributes);
1310 }
1311 echo $embed;
1312 echo '</div>';
1313 } else {
1314 if (!empty($attributes['contentShare'])) {
1315 $content_id = $attributes['clientId'];
1316 $embed = '<div class="position-' . esc_attr($share_position) . '-wraper gutenberg-pdf-wraper">';
1317 $embed .= $embed_code;
1318 $embed .= '</div>';
1319 $embed .= Helper::embed_content_share($content_id, $attributes);
1320 }
1321 echo '<div class="ep-embed-content-wraper">';
1322 if ($attributes['protectionType'] == 'password') {
1323 do_action('embedpress/display_password_form', $client_id, $embed, $pass_hash_key, $attributes);
1324 } else {
1325 do_action('embedpress/content_protection_content', $client_id, $attributes['protectionMessage'], $attributes['userRole']);
1326 }
1327 echo '</div>';
1328 }
1329
1330 ?>
1331
1332 <?php
1333 if (!empty($attributes['adManager'])) {
1334 $embed = apply_filters('embedpress/generate_ad_template', $embed, $client_id, $attributes, 'gutenberg');
1335 }
1336 ?>
1337 </div>
1338 </div>
1339 </div>
1340 <?php
1341 return ob_get_clean();
1342 }
1343 }
1344
1345 function isGoogleCalendar($url)
1346 {
1347 $pattern = '/^https:\/\/calendar\.google\.com\/calendar\/embed\?.*$/';
1348 return preg_match($pattern, $url);
1349 }
1350
1351 function embedpress_calendar_render_block($attributes)
1352 {
1353
1354 $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-calendar-' . rand(100, 10000);
1355 $url = !empty($attributes['url']) ? $attributes['url'] : '';
1356
1357 if (!isGoogleCalendar($url)) {
1358 return;
1359 }
1360
1361 $is_private = isset($attributes['is_public']);
1362 $client_id = md5($id);
1363 $width = !empty($attributes['width']) ? $attributes['width'] . 'px' : '600px';
1364 $height = !empty($attributes['height']) ? $attributes['height'] . 'px' : '600px';
1365 $gen_settings = get_option(EMBEDPRESS_PLG_NAME);
1366 $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by'];
1367 if (isset($attributes['powered_by'])) {
1368 $powered_by = $attributes['powered_by'];
1369 }
1370
1371 $aligns = [
1372 'left' => 'alignleft',
1373 'right' => 'alignright',
1374 'wide' => 'alignwide',
1375 'full' => 'alignfull'
1376 ];
1377 $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : '';
1378 $dimension = "width:$width;height:$height";
1379 ob_start();
1380 ?>
1381 <div class="embedpress-calendar-gutenberg embedpress-calendar ose-calendar <?php echo esc_attr($alignment) ?>" style="<?php echo esc_attr($dimension); ?>; max-width:100%;">
1382
1383 <?php
1384 if (!empty($url) && !$is_private) {
1385 ?>
1386 <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>
1387 <?php } else {
1388 do_action('embedpress_google_helper_shortcode', 10);
1389 } ?>
1390 <?php do_action('embedpress_calendar_gutenberg_after_embed', $client_id, 'calendar', $attributes); ?>
1391
1392 <?php
1393 if ($powered_by) {
1394 printf('<p class="embedpress-el-powered" style="width:' . esc_attr($width) . '" >%s</p>', __('Powered By EmbedPress', 'embedpress'));
1395 } ?>
1396
1397 </div>
1398 <?php
1399 return ob_get_clean();
1400 }
1401
1402 function embedpress_document_block_scripts()
1403 {
1404 // Exit if this is the admin panel
1405 if (is_admin()) {
1406 return;
1407 }
1408
1409 global $post;
1410
1411 // Check for the presence of the 'embedpress/document' block
1412 $block_exists = false;
1413
1414 if (function_exists('has_block')) {
1415 $block_exists = has_block('embedpress/document');
1416 } elseif (isset($post->post_content)) {
1417 // Fallback for older WordPress versions
1418 $block_exists = strpos($post->post_content, '<!-- wp:embedpress/document') !== false;
1419 }
1420
1421 // If the block exists, enqueue the scripts and styles
1422 if ($block_exists) {
1423 $script_handles = [
1424 'embedpress-pdfobject',
1425 'embedpress-front',
1426 'embedpress_documents_viewer_script'
1427 ];
1428
1429 foreach ($script_handles as $handle) {
1430 wp_enqueue_script($handle);
1431 }
1432
1433 $style_handles = [
1434 'embedpress_blocks-cgb-style-css',
1435 'embedpress-style'
1436 ];
1437
1438 foreach ($style_handles as $handle) {
1439 wp_enqueue_style($handle, false, [], EMBEDPRESS_PLUGIN_VERSION);
1440 }
1441 }
1442 }
1443 add_action('wp_enqueue_scripts', 'embedpress_document_block_scripts');
1444