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