PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 4.1.3
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v4.1.3
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
1288 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 'selection_tool' => [
807 'type' => "string",
808 'default' => '0',
809 ],
810 'scrolling' => [
811 'type' => "string",
812 'default' => '-1',
813 ],
814 'spreads' => [
815 'type' => "string",
816 'default' => '-1',
817 ],
818 'copy_text' => [
819 'type' => "boolean",
820 'default' => true,
821 ],
822 'add_text' => [
823 'type' => "boolean",
824 'default' => true,
825 ],
826 'draw' => [
827 'type' => "boolean",
828 'default' => true,
829 ],
830 'toolbar' => [
831 'type' => "boolean",
832 'default' => true,
833 ],
834 'doc_details' => [
835 'type' => "boolean",
836 'default' => true,
837 ],
838 'doc_rotation' => [
839 'type' => "boolean",
840 'default' => true,
841 ],
842 'add_image' => [
843 'type' => "boolean",
844 'default' => true,
845 ],
846 'unitoption' => [
847 'type' => "string",
848 'default' => '%',
849 ],
850 'zoomIn' => [
851 'type' => "boolean",
852 'default' => true,
853 ],
854 'zoomOut' => [
855 'type' => "boolean",
856 'default' => true,
857 ],
858 'fitView' => [
859 'type' => "boolean",
860 'default' => true,
861 ],
862 'bookmark' => [
863 'type' => "boolean",
864 'default' => true,
865 ],
866 //Spreaker
867 'theme' => array(
868 'type' => 'string',
869 'default' => 'light',
870 ),
871 'color' => array(
872 'type' => 'string',
873 'default' => '',
874 ),
875 'coverImageUrl' => array(
876 'type' => 'string',
877 'default' => '',
878 ),
879 'playlist' => array(
880 'type' => 'boolean',
881 'default' => false,
882 ),
883 'playlistContinuous' => array(
884 'type' => 'boolean',
885 'default' => false,
886 ),
887 'playlistLoop' => array(
888 'type' => 'boolean',
889 'default' => false,
890 ),
891 'playlistAutoupdate' => array(
892 'type' => 'boolean',
893 'default' => true,
894 ),
895 'chaptersImage' => array(
896 'type' => 'boolean',
897 'default' => true,
898 ),
899 'episodeImagePosition' => array(
900 'type' => 'string',
901 'default' => 'right',
902 ),
903 'hideLikes' => array(
904 'type' => 'boolean',
905 'default' => false,
906 ),
907 'hideComments' => array(
908 'type' => 'boolean',
909 'default' => false,
910 ),
911 'hideSharing' => array(
912 'type' => 'boolean',
913 'default' => false,
914 ),
915 'hideLogo' => array(
916 'type' => 'boolean',
917 'default' => false,
918 ),
919 'hideEpisodeDescription' => array(
920 'type' => 'boolean',
921 'default' => false,
922 ),
923 'hidePlaylistDescriptions' => array(
924 'type' => 'boolean',
925 'default' => false,
926 ),
927 'hidePlaylistImages' => array(
928 'type' => 'boolean',
929 'default' => false,
930 ),
931 'hideDownload' => array(
932 'type' => 'boolean',
933 'default' => false,
934 ),
935 //Ad attributes
936 'adManager' => [
937 'type' => 'boolean',
938 'default' => false
939 ],
940 'adSource' => [
941 'type' => 'string',
942 'default' => 'video'
943 ],
944 'adContent' => [
945 'type' => 'object',
946 ],
947 'adWidth' => array(
948 'type' => 'string',
949 'default' => '300'
950 ),
951 'adHeight' => array(
952 'type' => 'string',
953 'default' => '200'
954 ),
955 'adXPosition' => array(
956 'type' => 'number',
957 'default' => 25
958 ),
959 'adYPosition' => array(
960 'type' => 'number',
961 'default' => 20
962 ),
963 'adUrl' => [
964 'type' => 'string',
965 'default' => ''
966 ],
967 'adStart' => [
968 'type' => 'string',
969 'default' => '10'
970 ],
971 'adSkipButton' => [
972 'type' => 'boolean',
973 'default' => true
974 ],
975 'adSkipButtonAfter' => [
976 'type' => 'string',
977 'default' => '5'
978 ]
979 ),
980 'render_callback' => 'embedpress_pdf_render_block',
981 ]);
982 } elseif ('embedpress-calendar' === $blocks_to_register) {
983 register_block_type('embedpress/embedpress-calendar', [
984 'render_callback' => 'embedpress_calendar_render_block',
985 ]);
986 } elseif ('document' === $blocks_to_register) {
987 register_block_type('embedpress/' . $blocks_to_register, [
988 // 'render_callback' => 'embedpress_document_render_block',
989 ]);
990 } else {
991 register_block_type('embedpress/' . $blocks_to_register);
992 }
993 } else {
994
995 if (WP_Block_Type_Registry::get_instance()->is_registered('embedpress/' . $blocks_to_register)) {
996 unregister_block_type('embedpress/' . $blocks_to_register);
997 }
998 }
999 }
1000
1001 endif;
1002 }
1003
1004 add_action('init', 'embedpress_gutenberg_register_all_block');
1005
1006 function getParamData($attributes)
1007 {
1008
1009 $urlParamData = array(
1010 'themeMode' => !empty($attributes['themeMode']) ? $attributes['themeMode'] : 'default',
1011 'toolbar' => !empty($attributes['toolbar']) ? 'true' : 'false',
1012 'position' => $attributes['position'],
1013 'presentation' => !empty($attributes['presentation']) ? 'true' : 'false',
1014 'lazyLoad' => !empty($attributes['lazyLoad']) ? 'true' : 'false',
1015 'download' => !empty($attributes['download']) ? 'true' : 'false',
1016 'copy_text' => !empty($attributes['copy_text']) ? 'true' : 'false',
1017 'add_text' => !empty($attributes['add_text']) ? 'true' : 'false',
1018 'draw' => !empty($attributes['draw']) ? 'true' : 'false',
1019 'doc_rotation' => !empty($attributes['doc_rotation']) ? 'true' : 'false',
1020 'add_image' => !empty($attributes['add_image']) ? 'true' : 'false',
1021 'doc_details' => !empty($attributes['doc_details']) ? 'true' : 'false',
1022 'zoom_in' => !empty($attributes['zoomIn']) ? 'true' : 'false',
1023 'zoom_out' => !empty($attributes['zoomOut']) ? 'true' : 'false',
1024 'fit_view' => !empty($attributes['fitView']) ? 'true' : 'false',
1025 'bookmark' => !empty($attributes['bookmark']) ? 'true' : 'false',
1026 'flipbook_toolbar_position' => !empty($attributes['flipbook_toolbar_position']) ? $attributes['flipbook_toolbar_position'] : 'bottom',
1027 'selection_tool' => isset($attributes['selection_tool']) ? esc_attr($attributes['selection_tool']) : '0',
1028 'scrolling' => isset($attributes['scrolling']) ? esc_attr($attributes['scrolling']) : '-1',
1029 'spreads' => isset($attributes['spreads']) ? esc_attr($attributes['spreads']) : '-1',
1030 );
1031
1032 if ($urlParamData['themeMode'] == 'custom') {
1033 $urlParamData['customColor'] = !empty($attributes['customColor']) ? $attributes['customColor'] : '#403A81';
1034 }
1035
1036 if (isset($attributes['viewerStyle']) && $attributes['viewerStyle'] == 'flip-book') {
1037 return "&key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), 'UTF-8'));
1038 }
1039
1040 return "#key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), 'UTF-8'));
1041 }
1042
1043 function embedpress_pdf_block_scripts($attributes)
1044 {
1045
1046 $script_handles = [];
1047
1048 $script_handles[] = 'embedpress-pdfobject';
1049 $script_handles[] = 'embedpress-front';
1050
1051 if (!empty($attributes['adManager'])) {
1052 $script_handles[] = 'embedpress-ads';
1053 }
1054
1055 foreach ($script_handles as $handle) {
1056 wp_enqueue_script($handle);
1057 }
1058
1059 $style_handles = [
1060 'embedpress_blocks-cgb-style-css',
1061 'embedpress-style'
1062 ];
1063
1064 foreach ($style_handles as $handle) {
1065 wp_enqueue_style($handle);
1066 }
1067 }
1068
1069 function embedpress_pdf_render_block($attributes)
1070 {
1071 embedpress_pdf_block_scripts($attributes);
1072
1073 if (!empty($attributes['href'])) {
1074 $renderer = Helper::get_pdf_renderer();
1075 $pdf_url = $attributes['href'];
1076 $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-pdf-' . rand(100, 10000);
1077 $client_id = md5($id);
1078
1079
1080 $unitoption = !empty($attributes['unitoption']) ? $attributes['unitoption'] : 'px';
1081 $width = !empty($attributes['width']) ? $attributes['width'] . $unitoption : get_options_value('enableEmbedResizeWidth') . 'px';
1082
1083 if ($unitoption == '%') {
1084 $width_class = ' ep-percentage-width';
1085 } else {
1086 $width_class = 'ep-fixed-width';
1087 }
1088 $content_share_class = '';
1089 $share_position_class = '';
1090 $share_position = isset($attributes['sharePosition']) ? $attributes['sharePosition'] : 'right';
1091
1092 if (!empty($attributes['contentShare'])) {
1093 $content_share_class = 'ep-content-share-enabled';
1094 $share_position_class = 'ep-share-position-' . $share_position;
1095 }
1096
1097 $password_correct = isset($_COOKIE['password_correct_' . $client_id]) ? $_COOKIE['password_correct_' . $client_id] : '';
1098 $hash_pass = hash('sha256', wp_salt(32) . md5(isset($attributes['contentPassword']) ? $attributes['contentPassword'] : ''));
1099
1100
1101 $content_protection_class = 'ep-content-protection-enabled';
1102 if (empty($attributes['lockContent']) || empty($attributes['contentPassword']) || $hash_pass === $password_correct) {
1103 $content_protection_class = 'ep-content-protection-disabled';
1104 }
1105
1106
1107
1108 $height = !empty($attributes['height']) ? $attributes['height'] . 'px' : get_options_value('enableEmbedResizeHeight') . 'px';
1109 $gen_settings = get_option(EMBEDPRESS_PLG_NAME);
1110
1111 $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by'];
1112 if (isset($attributes['powered_by'])) {
1113 $powered_by = $attributes['powered_by'];
1114 }
1115
1116 $src = $renderer . ((strpos($renderer, '?') == false) ? '?' : '&') . 'file=' . urlencode($attributes['href']) . getParamData($attributes);
1117
1118 $pass_hash_key = isset($attributes['contentPassword']) ? md5($attributes['contentPassword']) : '';
1119
1120 $aligns = [
1121 'left' => 'ep-alignleft',
1122 'right' => 'ep-alignright',
1123 'center' => 'ep-aligncenter',
1124 'wide' => 'ep-alignwide',
1125 'full' => 'ep-alignfull'
1126 ];
1127 $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : '';
1128 $dimension = "width:$width;height:$height";
1129 ob_start();
1130 ?>
1131
1132
1133 <?php
1134
1135 $url = !empty($attributes['href']) ? $attributes['href'] : '';
1136
1137 $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> ';
1138 if (isset($attributes['viewerStyle']) && $attributes['viewerStyle'] === 'flip-book') {
1139 $src = urlencode($url) . getParamData($attributes);
1140 $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> ';
1141 }
1142 if ($powered_by) {
1143 $embed_code .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
1144 }
1145
1146 $adsAtts = '';
1147 if (!empty($attributes['adManager'])) {
1148 $ad = base64_encode(json_encode($attributes));
1149 $adsAtts = "data-sponsored-id=$client_id data-sponsored-attrs=$ad class=sponsored-mask";
1150 }
1151 ?>
1152
1153 <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); ?> ">
1154 <div class="embedpress-inner-iframe <?php if ($unitoption === '%') {
1155 echo esc_attr('emebedpress-unit-percent');
1156 } ?> ep-doc-<?php echo esc_attr($client_id); ?>" <?php if ($unitoption === '%' && !empty($attributes['width'])) {
1157 $style_attr = 'max-width:' . $attributes['width'] . '%';
1158 } else {
1159 $style_attr = 'max-width:100%';
1160 } ?> style="<?php echo esc_attr($style_attr); ?>" id="<?php echo esc_attr($id); ?>">
1161 <div <?php echo esc_attr($adsAtts); ?>>
1162 <?php
1163 do_action('embedpress_pdf_gutenberg_after_embed', $client_id, 'pdf', $attributes, $pdf_url);
1164 $embed = $embed_code;
1165 if (empty($attributes['lockContent']) || empty($attributes['contentPassword']) || (!empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct))) {
1166
1167 $custom_thumbnail = isset($attributes['customThumbnail']) ? $attributes['customThumbnail'] : '';
1168
1169 echo '<div class="ep-embed-content-wraper">';
1170 $embed = '<div class="position-' . esc_attr($share_position) . '-wraper gutenberg-pdf-wraper">';
1171 $embed .= $embed_code;
1172 $embed .= '</div>';
1173
1174 if (!empty($attributes['contentShare'])) {
1175 $content_id = $attributes['id'];
1176 $embed .= Helper::embed_content_share($content_id, $attributes);
1177 }
1178 echo $embed;
1179 echo '</div>';
1180 } else {
1181 if (!empty($attributes['contentShare'])) {
1182 $content_id = $attributes['clientId'];
1183 $embed = '<div class="position-' . esc_attr($share_position) . '-wraper gutenberg-pdf-wraper">';
1184 $embed .= $embed_code;
1185 $embed .= '</div>';
1186 $embed .= Helper::embed_content_share($content_id, $attributes);
1187 }
1188 echo '<div class="ep-embed-content-wraper">';
1189 do_action('embedpress/display_password_form', $client_id, $embed, $pass_hash_key, $attributes);
1190 echo '</div>';
1191 }
1192 ?>
1193
1194 <?php
1195 if (!empty($attributes['adManager'])) {
1196 $embed = apply_filters('embedpress/generate_ad_template', $embed, $client_id, $attributes, 'gutenberg');
1197 }
1198 ?>
1199 </div>
1200 </div>
1201 </div>
1202 <?php
1203 return ob_get_clean();
1204 }
1205 }
1206
1207 function isGoogleCalendar($url)
1208 {
1209 $pattern = '/^https:\/\/calendar\.google\.com\/calendar\/embed\?.*$/';
1210 return preg_match($pattern, $url);
1211 }
1212
1213 function embedpress_calendar_render_block($attributes)
1214 {
1215
1216 $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-calendar-' . rand(100, 10000);
1217 $url = !empty($attributes['url']) ? $attributes['url'] : '';
1218
1219 if (!isGoogleCalendar($url)) {
1220 return;
1221 }
1222
1223 $is_private = isset($attributes['is_public']);
1224 $client_id = md5($id);
1225 $width = !empty($attributes['width']) ? $attributes['width'] . 'px' : '600px';
1226 $height = !empty($attributes['height']) ? $attributes['height'] . 'px' : '600px';
1227 $gen_settings = get_option(EMBEDPRESS_PLG_NAME);
1228 $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by'];
1229 if (isset($attributes['powered_by'])) {
1230 $powered_by = $attributes['powered_by'];
1231 }
1232
1233 $aligns = [
1234 'left' => 'alignleft',
1235 'right' => 'alignright',
1236 'wide' => 'alignwide',
1237 'full' => 'alignfull'
1238 ];
1239 $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : '';
1240 $dimension = "width:$width;height:$height";
1241 ob_start();
1242 ?>
1243 <div class="embedpress-calendar-gutenberg embedpress-calendar ose-calendar <?php echo esc_attr($alignment) ?>" style="<?php echo esc_attr($dimension); ?>; max-width:100%;">
1244
1245 <?php
1246 if (!empty($url) && !$is_private) {
1247 ?>
1248 <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>
1249 <?php } else {
1250 do_action('embedpress_google_helper_shortcode', 10);
1251 } ?>
1252 <?php do_action('embedpress_calendar_gutenberg_after_embed', $client_id, 'calendar', $attributes); ?>
1253
1254 <?php
1255 if ($powered_by) {
1256 printf('<p class="embedpress-el-powered" style="width:' . esc_attr($width) . '" >%s</p>', __('Powered By EmbedPress', 'embedpress'));
1257 } ?>
1258
1259 </div>
1260 <?php
1261 return ob_get_clean();
1262 }
1263
1264 function embedpress_document_block_scripts()
1265 {
1266 if (!is_admin() && has_block('embedpress/document')) {
1267 $script_handles = [
1268 'embedpress-pdfobject',
1269 'embedpress-front',
1270 'embedpress_documents_viewer_script'
1271 ];
1272
1273 foreach ($script_handles as $handle) {
1274 wp_enqueue_script($handle);
1275 }
1276
1277 $style_handles = [
1278 'embedpress_blocks-cgb-style-css',
1279 'embedpress-style'
1280 ];
1281
1282 foreach ($style_handles as $handle) {
1283 wp_enqueue_style($handle);
1284 }
1285 }
1286 }
1287 add_action('wp_enqueue_scripts', 'embedpress_document_block_scripts');
1288