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