plugin.php
888 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_enqueue_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 | /** |
| 41 | * Enqueue Gutenberg block assets for backend editor. |
| 42 | * |
| 43 | * @uses {wp-blocks} for block type registration & related functions. |
| 44 | * @uses {wp-element} for WP Element abstraction — structure of blocks. |
| 45 | * @uses {wp-i18n} to internationalize the block's text. |
| 46 | * @uses {wp-editor} for WP editor styles. |
| 47 | * @since 1.0.0 |
| 48 | */ |
| 49 | |
| 50 | function embedpress_blocks_cgb_editor_assets() |
| 51 | { // phpcs:ignore |
| 52 | // Scripts. |
| 53 | if (!wp_script_is('embedpress-pdfobject')) { |
| 54 | wp_enqueue_script( |
| 55 | 'embedpress-pdfobject', |
| 56 | EMBEDPRESS_URL_ASSETS . 'js/pdfobject.min.js', |
| 57 | [], |
| 58 | EMBEDPRESS_VERSION |
| 59 | ); |
| 60 | } |
| 61 | |
| 62 | wp_enqueue_script( |
| 63 | 'embedpress_blocks-cgb-block-js', // Handle. |
| 64 | EMBEDPRESS_GUTENBERG_DIR_URL . 'dist/blocks.build.js', // Block.build.js: We register the block here. Built with Webpack. |
| 65 | array('wp-blocks', 'wp-i18n', 'wp-element', 'wp-api-fetch', 'wp-is-shallow-equal', 'wp-editor', 'wp-components', 'embedpress-pdfobject'), // Dependencies, defined above. |
| 66 | filemtime(EMBEDPRESS_GUTENBERG_DIR_PATH . 'dist/blocks.build.js'), // Version: File modification time. |
| 67 | true // Enqueue the script in the footer. |
| 68 | ); |
| 69 | |
| 70 | wp_enqueue_script( |
| 71 | 'embedpress_documents_viewer_script', EMBEDPRESS_PLUGIN_DIR_URL . 'assets/js/documents-viewer-script.js', array( 'wp-blocks', 'wp-dom-ready', 'wp-edit-post' ), EMBEDPRESS_PLUGIN_VERSION, true |
| 72 | ); |
| 73 | |
| 74 | $wistia_labels = array( |
| 75 | 'watch_from_beginning' => __('Watch from the beginning', 'embedpress'), |
| 76 | 'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'), |
| 77 | 'you_have_watched_it_before' => __('It looks like you\'ve watched<br />part of this video before!', 'embedpress'), |
| 78 | ); |
| 79 | $elements = (array) get_option(EMBEDPRESS_PLG_NAME . ":elements", []); |
| 80 | $active_blocks = isset($elements['gutenberg']) ? (array) $elements['gutenberg'] : []; |
| 81 | |
| 82 | $wistia_labels = json_encode($wistia_labels); |
| 83 | $wistia_options = null; |
| 84 | if (function_exists('embedpress_wisita_pro_get_options')) : |
| 85 | $wistia_options = embedpress_wisita_pro_get_options(); |
| 86 | endif; |
| 87 | $pars_url = wp_parse_url(get_site_url()); |
| 88 | $documents_cta_options = (array) get_option(EMBEDPRESS_PLG_NAME . ':document'); |
| 89 | wp_localize_script('embedpress_blocks-cgb-block-js', 'embedpressObj', array( |
| 90 | 'wistia_labels' => $wistia_labels, |
| 91 | 'wisita_options' => $wistia_options, |
| 92 | 'embedpress_powered_by' => apply_filters('embedpress_document_block_powered_by', true), |
| 93 | 'embedpress_pro' => defined('EMBEDPRESS_PRO_PLUGIN_FILE'), |
| 94 | 'twitch_host' => !empty($pars_url['host']) ? $pars_url['host'] : '', |
| 95 | 'site_url' => site_url(), |
| 96 | 'active_blocks' => $active_blocks, |
| 97 | 'document_cta' => $documents_cta_options, |
| 98 | 'pdf_renderer' => Helper::get_pdf_renderer(), |
| 99 | 'is_pro_plugin_active' => defined('EMBEDPRESS_SL_ITEM_SLUG'), |
| 100 | 'ajaxurl' => admin_url('admin-ajax.php'), |
| 101 | 'source_nonce' => wp_create_nonce('source_nonce_embedpress'), |
| 102 | 'can_upload_media' => current_user_can( 'upload_files' ) |
| 103 | |
| 104 | )); |
| 105 | |
| 106 | // Styles. |
| 107 | wp_enqueue_style( |
| 108 | 'embedpress_blocks-cgb-block-editor-css', // Handle. |
| 109 | EMBEDPRESS_GUTENBERG_DIR_URL . 'dist/blocks.editor.build.css', // Block editor CSS. |
| 110 | array('wp-edit-blocks'), // Dependency to include the CSS after it. |
| 111 | filemtime(EMBEDPRESS_GUTENBERG_DIR_PATH . 'dist/blocks.editor.build.css') // Version: File modification time. |
| 112 | ); |
| 113 | } |
| 114 | |
| 115 | // Hook: Editor assets. |
| 116 | add_action('enqueue_block_editor_assets', 'embedpress_blocks_cgb_editor_assets'); |
| 117 | |
| 118 | |
| 119 | function embedpress_block_category($categories, $post) |
| 120 | { |
| 121 | return array_merge( |
| 122 | $categories, |
| 123 | array( |
| 124 | array( |
| 125 | 'slug' => 'embedpress', |
| 126 | 'title' => 'EmbedPress', |
| 127 | 'icon' => '', |
| 128 | ), |
| 129 | ) |
| 130 | ); |
| 131 | } |
| 132 | $wp_version = get_bloginfo('version', 'display'); |
| 133 | if (version_compare($wp_version, '5.8', '>=')) { |
| 134 | add_filter('block_categories_all', 'embedpress_block_category', 10, 2); |
| 135 | } else { |
| 136 | add_filter('block_categories', 'embedpress_block_category', 10, 2); |
| 137 | } |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | foreach (glob(EMBEDPRESS_GUTENBERG_DIR_PATH . 'block-backend/*.php') as $block_logic) { |
| 143 | require_once $block_logic; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Registers the embedpress gutneberg block on server. |
| 148 | */ |
| 149 | |
| 150 | function embedpress_gutenberg_register_all_block() |
| 151 | { |
| 152 | if (function_exists('register_block_type')) : |
| 153 | |
| 154 | $elements = (array) get_option(EMBEDPRESS_PLG_NAME . ":elements", []); |
| 155 | $g_blocks = isset($elements['gutenberg']) ? (array) $elements['gutenberg'] : []; |
| 156 | $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']; |
| 157 | |
| 158 | foreach ($blocks_to_registers as $blocks_to_register) { |
| 159 | if (!empty($g_blocks[$blocks_to_register])) { |
| 160 | if ('embedpress' === $blocks_to_register) { |
| 161 | register_block_type('embedpress/embedpress', [ |
| 162 | 'render_callback' => 'embedpress_render_block', |
| 163 | 'attributes' => array( |
| 164 | 'clientId' => [ |
| 165 | 'type' => 'string', |
| 166 | ], |
| 167 | 'height' => [ |
| 168 | 'type' => 'string', |
| 169 | 'default' => '450' |
| 170 | ], |
| 171 | 'width' => [ |
| 172 | 'type' => 'string', |
| 173 | 'default' => '600' |
| 174 | ], |
| 175 | 'lockContent' => [ |
| 176 | 'type' => 'boolean', |
| 177 | 'default' => false |
| 178 | ], |
| 179 | 'lockHeading' => [ |
| 180 | 'type' => 'string', |
| 181 | 'default' => 'Content Locked' |
| 182 | ], |
| 183 | 'lockSubHeading' => [ |
| 184 | 'type' => 'string', |
| 185 | 'default' => 'Content is locked and requires password to access it.' |
| 186 | ], |
| 187 | 'lockErrorMessage' => [ |
| 188 | 'type' => 'string', |
| 189 | 'default' => 'Oops, that wasn\'t the right password. Try again.' |
| 190 | ], |
| 191 | 'passwordPlaceholder' => [ |
| 192 | 'type' => 'string', |
| 193 | 'default' => 'Password' |
| 194 | ], |
| 195 | 'submitButtonText' => [ |
| 196 | 'type' => 'string', |
| 197 | 'default' => 'Unlock' |
| 198 | ], |
| 199 | 'submitUnlockingText' => [ |
| 200 | 'type' => 'string', |
| 201 | 'default' => 'Unlocking' |
| 202 | ], |
| 203 | 'enableFooterMessage' => [ |
| 204 | 'type' => 'boolean', |
| 205 | 'default' => false |
| 206 | ], |
| 207 | 'footerMessage' => [ |
| 208 | 'type' => 'string', |
| 209 | 'default' => 'In case you don\'t have the password, kindly reach out to content owner or administrator to request access.' |
| 210 | ], |
| 211 | 'contentPassword' => [ |
| 212 | 'type' => 'string', |
| 213 | 'default' => '', |
| 214 | ], |
| 215 | 'contentShare' => [ |
| 216 | 'type' => 'boolean', |
| 217 | 'default' => false |
| 218 | ], |
| 219 | 'sharePosition' => [ |
| 220 | 'type' => 'string', |
| 221 | 'default' => 'right' |
| 222 | ], |
| 223 | 'customTitle' => [ |
| 224 | 'type' => 'string', |
| 225 | 'default' => '' |
| 226 | ], |
| 227 | 'customDescription' => [ |
| 228 | 'type' => 'string', |
| 229 | 'default' => '' |
| 230 | ], |
| 231 | 'customThumbnail' => [ |
| 232 | 'type' => 'string', |
| 233 | 'default' => '' |
| 234 | ], |
| 235 | |
| 236 | 'videosize' => [ |
| 237 | 'type' => 'string', |
| 238 | 'default' => 'fixed' |
| 239 | ], |
| 240 | |
| 241 | 'loadmore' => [ |
| 242 | 'type' => 'boolean', |
| 243 | 'default' => false |
| 244 | ], |
| 245 | //Youtube Attributes |
| 246 | 'starttime' => [ |
| 247 | 'type' => 'string', |
| 248 | ], |
| 249 | 'endtime' => [ |
| 250 | 'type' => 'string', |
| 251 | ], |
| 252 | 'autoplay' => [ |
| 253 | 'type' => 'boolean', |
| 254 | 'default' => false |
| 255 | ], |
| 256 | 'controls' => [ |
| 257 | 'type' => 'string', |
| 258 | ], |
| 259 | 'progressbarcolor' => [ |
| 260 | 'type' => 'string', |
| 261 | ], |
| 262 | 'videoannotations' => [ |
| 263 | 'type' => 'string', |
| 264 | ], |
| 265 | 'closedcaptions' => [ |
| 266 | 'type' => 'boolean', |
| 267 | 'default' => true |
| 268 | ], |
| 269 | 'relatedvideos' => [ |
| 270 | 'type' => 'boolean', |
| 271 | 'default' => true |
| 272 | ], |
| 273 | 'fullscreen' => [ |
| 274 | 'type' => 'boolean', |
| 275 | 'default' => true |
| 276 | ], |
| 277 | |
| 278 | 'modestbranding' => [ |
| 279 | 'type' => 'string', |
| 280 | ], |
| 281 | // custom player attributes |
| 282 | 'customPlayer' => [ |
| 283 | 'type' => 'boolean', |
| 284 | 'default' => false |
| 285 | ], |
| 286 | |
| 287 | 'posterThumbnail' => [ |
| 288 | 'type' => 'string', |
| 289 | 'default' => '' |
| 290 | ], |
| 291 | |
| 292 | 'playerPreset' => [ |
| 293 | 'type' => 'string', |
| 294 | 'default' => '' |
| 295 | ], |
| 296 | |
| 297 | 'playerColor' => [ |
| 298 | 'type' => 'string', |
| 299 | 'default' => '#2e2e99' |
| 300 | ], |
| 301 | |
| 302 | 'playerPip' => [ |
| 303 | 'type' => 'boolean', |
| 304 | 'default' => false |
| 305 | ], |
| 306 | |
| 307 | 'playerRestart' => [ |
| 308 | 'type' => 'boolean', |
| 309 | 'default' => true |
| 310 | ], |
| 311 | |
| 312 | 'playerRewind' => [ |
| 313 | 'type' => 'boolean', |
| 314 | 'default' => true |
| 315 | ], |
| 316 | |
| 317 | 'playerFastForward' => [ |
| 318 | 'type' => 'boolean', |
| 319 | 'default' => true |
| 320 | ], |
| 321 | 'playerTooltip' => [ |
| 322 | 'type' => 'boolean', |
| 323 | 'default' => true |
| 324 | ], |
| 325 | 'playerHideControls' => [ |
| 326 | 'type' => 'boolean', |
| 327 | 'default' => true |
| 328 | ], |
| 329 | 'playerDownload' => [ |
| 330 | 'type' => 'boolean', |
| 331 | 'default' => true |
| 332 | ], |
| 333 | //Wistia Attributes |
| 334 | 'wstarttime' => [ |
| 335 | 'type' => 'string', |
| 336 | ], |
| 337 | 'wautoplay' => [ |
| 338 | 'type' => 'boolean', |
| 339 | 'default' => true |
| 340 | ], |
| 341 | 'scheme' => [ |
| 342 | 'type' => 'string', |
| 343 | ], |
| 344 | 'captions' => [ |
| 345 | 'type' => 'boolean', |
| 346 | 'default' => true |
| 347 | ], |
| 348 | 'playbutton' => [ |
| 349 | 'type' => 'boolean', |
| 350 | 'default' => true |
| 351 | ], |
| 352 | 'smallplaybutton' => [ |
| 353 | 'type' => 'boolean', |
| 354 | 'default' => true |
| 355 | ], |
| 356 | 'playbar' => [ |
| 357 | 'type' => 'boolean', |
| 358 | 'default' => true |
| 359 | ], |
| 360 | 'resumable' => [ |
| 361 | 'type' => 'boolean', |
| 362 | 'default' => true |
| 363 | ], |
| 364 | 'wistiafocus' => [ |
| 365 | 'type' => 'boolean', |
| 366 | 'default' => true |
| 367 | ], |
| 368 | 'volumecontrol' => [ |
| 369 | 'type' => 'boolean', |
| 370 | 'default' => true |
| 371 | ], |
| 372 | 'volume' => [ |
| 373 | 'type' => 'number', |
| 374 | 'default' => 100 |
| 375 | ], |
| 376 | 'rewind' => [ |
| 377 | 'type' => 'boolean', |
| 378 | 'default' => false |
| 379 | ], |
| 380 | 'wfullscreen' => [ |
| 381 | 'type' => 'boolean', |
| 382 | 'default' => true |
| 383 | ], |
| 384 | |
| 385 | // Vimeo attributes |
| 386 | 'vstarttime' => [ |
| 387 | 'type' => 'string', |
| 388 | ], |
| 389 | 'vautoplay' => [ |
| 390 | 'type' => 'boolean', |
| 391 | 'default' => false |
| 392 | ], |
| 393 | 'vscheme' => [ |
| 394 | 'type' => 'string', |
| 395 | ], |
| 396 | 'vtitle' => [ |
| 397 | 'type' => 'boolean', |
| 398 | 'default' => true |
| 399 | ], |
| 400 | 'vauthor' => [ |
| 401 | 'type' => 'boolean', |
| 402 | 'default' => true |
| 403 | ], |
| 404 | 'vavatar' => [ |
| 405 | 'type' => 'boolean', |
| 406 | 'default' => true |
| 407 | ], |
| 408 | 'vloop' => [ |
| 409 | 'type' => 'boolean', |
| 410 | 'default' => false |
| 411 | ], |
| 412 | 'vautopause' => [ |
| 413 | 'type' => 'boolean', |
| 414 | 'default' => false |
| 415 | ], |
| 416 | 'vdnt' => [ |
| 417 | 'type' => 'boolean', |
| 418 | 'default' => false |
| 419 | ], |
| 420 | |
| 421 | // Calendly attributes |
| 422 | 'cEmbedType' => array( |
| 423 | 'type' => 'string', |
| 424 | 'default' => 'inline' |
| 425 | ), |
| 426 | 'calendlyData' => array( |
| 427 | 'type' => 'boolean', |
| 428 | 'default' => false |
| 429 | ), |
| 430 | 'hideCookieBanner' => array( |
| 431 | 'type' => 'boolean', |
| 432 | 'default' => false |
| 433 | ), |
| 434 | 'hideEventTypeDetails' => array( |
| 435 | 'type' => 'boolean', |
| 436 | 'default' => false |
| 437 | ), |
| 438 | 'cBackgroundColor' => array( |
| 439 | 'type' => 'string', |
| 440 | 'default' => 'ffffff' |
| 441 | ), |
| 442 | 'cTextColor' => array( |
| 443 | 'type' => 'string', |
| 444 | 'default' => '1A1A1A' |
| 445 | ), |
| 446 | 'cButtonLinkColor' => array( |
| 447 | 'type' => 'string', |
| 448 | 'default' => '0000FF' |
| 449 | ), |
| 450 | 'cPopupButtonText' => array( |
| 451 | 'type' => 'string', |
| 452 | 'default' => 'Schedule time with me' |
| 453 | ), |
| 454 | 'cPopupButtonBGColor' => array( |
| 455 | 'type' => 'string', |
| 456 | 'default' => '#0000FF' |
| 457 | ), |
| 458 | 'cPopupButtonTextColor' => array( |
| 459 | 'type' => 'string', |
| 460 | 'default' => '#FFFFFF' |
| 461 | ), |
| 462 | 'cPopupLinkText' => array( |
| 463 | 'type' => 'string', |
| 464 | 'default' => 'Schedule time with me' |
| 465 | ), |
| 466 | |
| 467 | //Ad attributes |
| 468 | 'adManager' => [ |
| 469 | 'type' => 'boolean', |
| 470 | 'default' => false |
| 471 | ], |
| 472 | 'adSource' => [ |
| 473 | 'type' => 'string', |
| 474 | 'default' => 'video' |
| 475 | ], |
| 476 | 'adContent' => [ |
| 477 | 'type' => 'object', |
| 478 | ], |
| 479 | 'adWidth' => array( |
| 480 | 'type' => 'string', |
| 481 | 'default' => '300' |
| 482 | ), |
| 483 | 'adHeight' => array( |
| 484 | 'type' => 'string', |
| 485 | 'default' => '200' |
| 486 | ), |
| 487 | 'adXPosition' => array( |
| 488 | 'type' => 'number', |
| 489 | 'default' => 25 |
| 490 | ), |
| 491 | 'adYPosition' => array( |
| 492 | 'type' => 'number', |
| 493 | 'default' => 10 |
| 494 | ), |
| 495 | 'adUrl' => [ |
| 496 | 'type' => 'string', |
| 497 | 'default' => '' |
| 498 | ], |
| 499 | 'adStart' => [ |
| 500 | 'type' => 'string', |
| 501 | 'default' => '10' |
| 502 | ], |
| 503 | 'adSkipButton' => [ |
| 504 | 'type' => 'boolean', |
| 505 | 'default' => true |
| 506 | ], |
| 507 | 'adSkipButtonAfter' => [ |
| 508 | 'type' => 'string', |
| 509 | 'default' => '5' |
| 510 | ] |
| 511 | |
| 512 | ), |
| 513 | ]); |
| 514 | } elseif ('embedpress-pdf' === $blocks_to_register) { |
| 515 | register_block_type('embedpress/embedpress-pdf', [ |
| 516 | 'attributes' => array( |
| 517 | 'powered_by' => [ |
| 518 | 'type' => 'boolean', |
| 519 | 'default' => true |
| 520 | ], |
| 521 | 'lockContent' => [ |
| 522 | 'type' => 'boolean', |
| 523 | 'default' => false |
| 524 | ], |
| 525 | 'lockHeading' => [ |
| 526 | 'type' => 'string', |
| 527 | 'default' => 'Content Locked' |
| 528 | ], |
| 529 | 'lockSubHeading' => [ |
| 530 | 'type' => 'string', |
| 531 | 'default' => 'Content is locked and requires password to access it.' |
| 532 | ], |
| 533 | 'passwordPlaceholder' => [ |
| 534 | 'type' => 'string', |
| 535 | 'default' => 'Password' |
| 536 | ], |
| 537 | 'submitButtonText' => [ |
| 538 | 'type' => 'string', |
| 539 | 'default' => 'Unlock' |
| 540 | ], |
| 541 | 'submitUnlockingText' => [ |
| 542 | 'type' => 'string', |
| 543 | 'default' => 'Unlocking' |
| 544 | ], |
| 545 | 'lockErrorMessage' => [ |
| 546 | 'type' => 'string', |
| 547 | 'default' => 'Oops, that wasn\'t the right password. Try again.' |
| 548 | ], |
| 549 | 'enableFooterMessage' => [ |
| 550 | 'type' => 'boolean', |
| 551 | 'default' => false |
| 552 | ], |
| 553 | 'footerMessage' => [ |
| 554 | 'type' => 'string', |
| 555 | 'default' => 'In case you don\'t have the password, kindly reach out to content owner or administrator to request access.' |
| 556 | ], |
| 557 | 'contentPassword' => [ |
| 558 | 'type' => 'string', |
| 559 | 'default' => '' |
| 560 | ], |
| 561 | 'contentShare' => [ |
| 562 | 'type' => 'boolean', |
| 563 | 'default' => false |
| 564 | ], |
| 565 | 'sharePosition' => [ |
| 566 | 'type' => 'string', |
| 567 | 'default' => 'right' |
| 568 | ], |
| 569 | 'presentation' => [ |
| 570 | 'type' => "boolean", |
| 571 | 'default' => true, |
| 572 | ], |
| 573 | |
| 574 | 'position' => [ |
| 575 | 'type' => "string", |
| 576 | 'default' => 'top', |
| 577 | ], |
| 578 | |
| 579 | 'print' => [ |
| 580 | 'type' => "boolean", |
| 581 | 'default' => true, |
| 582 | ], |
| 583 | |
| 584 | 'download' => [ |
| 585 | 'type' => "boolean", |
| 586 | 'default' => true, |
| 587 | ], |
| 588 | 'open' => [ |
| 589 | 'type' => "boolean", |
| 590 | 'default' => true, |
| 591 | ], |
| 592 | 'copy_text' => [ |
| 593 | 'type' => "boolean", |
| 594 | 'default' => true, |
| 595 | ], |
| 596 | 'add_text' => [ |
| 597 | 'type' => "boolean", |
| 598 | 'default' => true, |
| 599 | ], |
| 600 | 'draw' => [ |
| 601 | 'type' => "boolean", |
| 602 | 'default' => true, |
| 603 | ], |
| 604 | 'toolbar' => [ |
| 605 | 'type' => "boolean", |
| 606 | 'default' => true, |
| 607 | ], |
| 608 | 'doc_details' => [ |
| 609 | 'type' => "boolean", |
| 610 | 'default' => true, |
| 611 | ], |
| 612 | 'doc_rotation' => [ |
| 613 | 'type' => "boolean", |
| 614 | 'default' => true, |
| 615 | ], |
| 616 | 'unitoption' => [ |
| 617 | 'type' => "string", |
| 618 | 'default' => 'px', |
| 619 | ], |
| 620 | |
| 621 | //Ad attributes |
| 622 | 'adManager' => [ |
| 623 | 'type' => 'boolean', |
| 624 | 'default' => false |
| 625 | ], |
| 626 | 'adSource' => [ |
| 627 | 'type' => 'string', |
| 628 | 'default' => 'video' |
| 629 | ], |
| 630 | 'adContent' => [ |
| 631 | 'type' => 'object', |
| 632 | ], |
| 633 | 'adWidth' => array( |
| 634 | 'type' => 'string', |
| 635 | 'default' => '300' |
| 636 | ), |
| 637 | 'adHeight' => array( |
| 638 | 'type' => 'string', |
| 639 | 'default' => '200' |
| 640 | ), |
| 641 | 'adXPosition' => array( |
| 642 | 'type' => 'number', |
| 643 | 'default' => 25 |
| 644 | ), |
| 645 | 'adYPosition' => array( |
| 646 | 'type' => 'number', |
| 647 | 'default' => 20 |
| 648 | ), |
| 649 | 'adUrl' => [ |
| 650 | 'type' => 'string', |
| 651 | 'default' => '' |
| 652 | ], |
| 653 | 'adStart' => [ |
| 654 | 'type' => 'string', |
| 655 | 'default' => '10' |
| 656 | ], |
| 657 | 'adSkipButton' => [ |
| 658 | 'type' => 'boolean', |
| 659 | 'default' => true |
| 660 | ], |
| 661 | 'adSkipButtonAfter' => [ |
| 662 | 'type' => 'string', |
| 663 | 'default' => '5' |
| 664 | ] |
| 665 | ), |
| 666 | 'render_callback' => 'embedpress_pdf_render_block', |
| 667 | ]); |
| 668 | } elseif ('embedpress-calendar' === $blocks_to_register) { |
| 669 | register_block_type('embedpress/embedpress-calendar', [ |
| 670 | 'render_callback' => 'embedpress_calendar_render_block', |
| 671 | ]); |
| 672 | } else { |
| 673 | register_block_type('embedpress/' . $blocks_to_register); |
| 674 | } |
| 675 | } else { |
| 676 | |
| 677 | if (WP_Block_Type_Registry::get_instance()->is_registered('embedpress/' . $blocks_to_register)) { |
| 678 | unregister_block_type('embedpress/' . $blocks_to_register); |
| 679 | } |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | endif; |
| 684 | } |
| 685 | |
| 686 | add_action('init', 'embedpress_gutenberg_register_all_block'); |
| 687 | |
| 688 | function getParamData($attributes) |
| 689 | { |
| 690 | |
| 691 | $urlParamData = array( |
| 692 | 'themeMode' => !empty($attributes['themeMode']) ? $attributes['themeMode'] : 'default', |
| 693 | 'toolbar' => !empty($attributes['toolbar']) ? 'true' : 'false', |
| 694 | 'position' => $attributes['position'], |
| 695 | 'presentation' => !empty($attributes['presentation']) ? 'true' : 'false', |
| 696 | 'download' => !empty($attributes['download']) ? 'true' : 'false', |
| 697 | 'copy_text' => !empty($attributes['copy_text']) ? 'true' : 'false', |
| 698 | 'add_text' => !empty($attributes['add_text']) ? 'true' : 'false', |
| 699 | 'draw' => !empty($attributes['draw']) ? 'true' : 'false', |
| 700 | 'doc_rotation' => !empty($attributes['doc_rotation']) ? 'true' : 'false', |
| 701 | 'doc_details' => !empty($attributes['doc_details']) ? 'true' : 'false', |
| 702 | ); |
| 703 | |
| 704 | if($urlParamData['themeMode'] == 'custom') { |
| 705 | $urlParamData['customColor'] = !empty($attributes['customColor']) ? $attributes['customColor'] : '#403A81'; |
| 706 | } |
| 707 | |
| 708 | return "#key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), 'UTF-8')); |
| 709 | |
| 710 | } |
| 711 | |
| 712 | function embedpress_pdf_render_block($attributes) |
| 713 | { |
| 714 | |
| 715 | |
| 716 | if (!empty($attributes['href'])) { |
| 717 | $renderer = Helper::get_pdf_renderer(); |
| 718 | $pdf_url = $attributes['href']; |
| 719 | $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-pdf-' . rand(100, 10000); |
| 720 | $client_id = md5($id); |
| 721 | |
| 722 | |
| 723 | $unitoption = !empty($attributes['unitoption']) ? $attributes['unitoption'] : 'px'; |
| 724 | $width = !empty($attributes['width']) ? $attributes['width'] . $unitoption : '600px'; |
| 725 | |
| 726 | if($unitoption == '%'){ |
| 727 | $width_class = ' ep-percentage-width'; |
| 728 | } |
| 729 | else{ |
| 730 | $width_class = 'ep-fixed-width'; |
| 731 | } |
| 732 | $content_share_class = ''; |
| 733 | $share_position_class = ''; |
| 734 | $share_position = isset($attributes['sharePosition']) ? $attributes['sharePosition'] : 'right'; |
| 735 | |
| 736 | if(!empty($attributes['contentShare'])) { |
| 737 | $content_share_class = 'ep-content-share-enabled'; |
| 738 | $share_position_class = 'ep-share-position-'.$share_position; |
| 739 | } |
| 740 | |
| 741 | $password_correct = isset($_COOKIE['password_correct_'.$client_id]) ? $_COOKIE['password_correct_'.$client_id] : ''; |
| 742 | $hash_pass = hash('sha256', wp_salt(32) . md5(isset($attributes['contentPassword']) ? $attributes['contentPassword'] : '')); |
| 743 | |
| 744 | |
| 745 | $content_protection_class = 'ep-content-protection-enabled'; |
| 746 | if(empty($attributes['lockContent']) || empty($attributes['contentPassword']) || $hash_pass === $password_correct) { |
| 747 | $content_protection_class = 'ep-content-protection-disabled'; |
| 748 | } |
| 749 | |
| 750 | |
| 751 | |
| 752 | $height = !empty($attributes['height']) ? $attributes['height'] . 'px' : '600px'; |
| 753 | $gen_settings = get_option(EMBEDPRESS_PLG_NAME); |
| 754 | |
| 755 | $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by']; |
| 756 | if (isset($attributes['powered_by'])) { |
| 757 | $powered_by = $attributes['powered_by']; |
| 758 | } |
| 759 | |
| 760 | $src = $renderer . ((strpos($renderer, '?') == false) ? '?' : '&') . 'file=' . urlencode($attributes['href']) . getParamData($attributes); |
| 761 | |
| 762 | $pass_hash_key = isset($attributes['contentPassword']) ? md5($attributes['contentPassword']): ''; |
| 763 | |
| 764 | $aligns = [ |
| 765 | 'left' => 'ep-alignleft', |
| 766 | 'right' => 'ep-alignright', |
| 767 | 'center' => 'ep-aligncenter', |
| 768 | 'wide' => 'ep-alignwide', |
| 769 | 'full' => 'ep-alignfull' |
| 770 | ]; |
| 771 | $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : ''; |
| 772 | $dimension = "width:$width;height:$height"; |
| 773 | ob_start(); |
| 774 | ?> |
| 775 | |
| 776 | |
| 777 | <?php |
| 778 | |
| 779 | $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> '; |
| 780 | |
| 781 | if ($powered_by) { |
| 782 | $embed_code .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress')); |
| 783 | } |
| 784 | |
| 785 | $url = !empty($attributes['href']) ? $attributes['href'] : ''; |
| 786 | |
| 787 | $adsAtts = ''; |
| 788 | if(!empty($attributes['adManager'])) { |
| 789 | $ad = base64_encode(json_encode($attributes)); |
| 790 | $adsAtts = "data-ad-id=$client_id data-ad-attrs=$ad class=ad-mask"; |
| 791 | } |
| 792 | ?> |
| 793 | |
| 794 | <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); ?> "> |
| 795 | <div class="embedpress-inner-iframe <?php if ($unitoption === '%') { echo esc_attr('emebedpress-unit-percent'); } ?> ep-doc-<?php echo esc_attr($client_id); ?>"<?php if ($unitoption === '%' && !empty($attributes['width'])) { $style_attr = 'max-width:' . $attributes['width'] . '%'; } else { $style_attr = 'max-width:100%'; } ?> style="<?php echo esc_attr($style_attr); ?>" id="<?php echo esc_attr($id); ?>"> |
| 796 | <div <?php echo esc_attr( $adsAtts ); ?> > |
| 797 | <?php |
| 798 | do_action('embedpress_pdf_gutenberg_after_embed', $client_id, 'pdf', $attributes, $pdf_url); |
| 799 | $embed = $embed_code; |
| 800 | if(empty($attributes['lockContent']) || empty($attributes['contentPassword']) || (!empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct)) ){ |
| 801 | |
| 802 | $custom_thumbnail = isset($attributes['customThumbnail']) ? $attributes['customThumbnail'] : ''; |
| 803 | |
| 804 | echo '<div class="ep-embed-content-wraper">'; |
| 805 | $embed = '<div class="position-'.esc_attr( $share_position ).'-wraper gutenberg-pdf-wraper">'; |
| 806 | $embed .= $embed_code; |
| 807 | $embed.= '</div>'; |
| 808 | |
| 809 | if(!empty($attributes['contentShare'])) { |
| 810 | $content_id = $attributes['id']; |
| 811 | $embed .= Helper::embed_content_share($content_id, $attributes); |
| 812 | } |
| 813 | echo $embed; |
| 814 | echo '</div>'; |
| 815 | } else { |
| 816 | if(!empty($attributes['contentShare'])) { |
| 817 | $content_id = $attributes['clientId']; |
| 818 | $embed = '<div class="position-'.esc_attr( $share_position ).'-wraper gutenberg-pdf-wraper">'; |
| 819 | $embed .= $embed_code; |
| 820 | $embed.= '</div>'; |
| 821 | $embed .= Helper::embed_content_share($content_id, $attributes); |
| 822 | } |
| 823 | echo '<div class="ep-embed-content-wraper">'; |
| 824 | Helper::display_password_form($client_id, $embed, $pass_hash_key, $attributes); |
| 825 | echo '</div>'; |
| 826 | } |
| 827 | ?> |
| 828 | |
| 829 | <?php |
| 830 | if(!empty($attributes['adManager'])) { |
| 831 | $embed .= Helper::generateAdTemplate($client_id, $attributes, 'gutenberg'); |
| 832 | } |
| 833 | ?> |
| 834 | </div> |
| 835 | </div> |
| 836 | </div> |
| 837 | <?php |
| 838 | return ob_get_clean(); |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | function embedpress_calendar_render_block($attributes) |
| 843 | { |
| 844 | |
| 845 | $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-calendar-' . rand(100, 10000); |
| 846 | $url = !empty($attributes['url']) ? $attributes['url'] : ''; |
| 847 | $is_private = isset($attributes['is_public']); |
| 848 | $client_id = md5($id); |
| 849 | $width = !empty($attributes['width']) ? $attributes['width'] . 'px' : '600px'; |
| 850 | $height = !empty($attributes['height']) ? $attributes['height'] . 'px' : '600px'; |
| 851 | $gen_settings = get_option(EMBEDPRESS_PLG_NAME); |
| 852 | $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by']; |
| 853 | if (isset($attributes['powered_by'])) { |
| 854 | $powered_by = $attributes['powered_by']; |
| 855 | } |
| 856 | |
| 857 | $aligns = [ |
| 858 | 'left' => 'alignleft', |
| 859 | 'right' => 'alignright', |
| 860 | 'wide' => 'alignwide', |
| 861 | 'full' => 'alignfull' |
| 862 | ]; |
| 863 | $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : ''; |
| 864 | $dimension = "width:$width;height:$height"; |
| 865 | ob_start(); |
| 866 | ?> |
| 867 | <div class="embedpress-calendar-gutenberg embedpress-calendar ose-calendar <?php echo esc_attr($alignment) ?>" style="<?php echo esc_attr($dimension); ?>; max-width:100%;"> |
| 868 | |
| 869 | <?php |
| 870 | if (!empty($url) && !$is_private) { |
| 871 | ?> |
| 872 | <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> |
| 873 | <?php } else { |
| 874 | if (is_embedpress_pro_active()) { |
| 875 | echo Embedpress_Google_Helper::shortcode(); |
| 876 | } |
| 877 | } ?> |
| 878 | <?php do_action('embedpress_calendar_gutenberg_after_embed', $client_id, 'calendar', $attributes); ?> |
| 879 | |
| 880 | <?php |
| 881 | if ($powered_by) { |
| 882 | printf('<p class="embedpress-el-powered" style="width:' . esc_attr($width) . '" >%s</p>', __('Powered By EmbedPress', 'embedpress')); |
| 883 | } ?> |
| 884 | |
| 885 | </div> |
| 886 | <?php |
| 887 | return ob_get_clean(); |
| 888 | } |