plugin.php
685 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 | )); |
| 102 | |
| 103 | // Styles. |
| 104 | wp_enqueue_style( |
| 105 | 'embedpress_blocks-cgb-block-editor-css', // Handle. |
| 106 | EMBEDPRESS_GUTENBERG_DIR_URL . 'dist/blocks.editor.build.css', // Block editor CSS. |
| 107 | array('wp-edit-blocks'), // Dependency to include the CSS after it. |
| 108 | filemtime(EMBEDPRESS_GUTENBERG_DIR_PATH . 'dist/blocks.editor.build.css') // Version: File modification time. |
| 109 | ); |
| 110 | } |
| 111 | |
| 112 | // Hook: Editor assets. |
| 113 | add_action('enqueue_block_editor_assets', 'embedpress_blocks_cgb_editor_assets'); |
| 114 | |
| 115 | |
| 116 | function embedpress_block_category($categories, $post) |
| 117 | { |
| 118 | return array_merge( |
| 119 | $categories, |
| 120 | array( |
| 121 | array( |
| 122 | 'slug' => 'embedpress', |
| 123 | 'title' => 'EmbedPress', |
| 124 | 'icon' => '', |
| 125 | ), |
| 126 | ) |
| 127 | ); |
| 128 | } |
| 129 | $wp_version = get_bloginfo('version', 'display'); |
| 130 | if (version_compare($wp_version, '5.8', '>=')) { |
| 131 | add_filter('block_categories_all', 'embedpress_block_category', 10, 2); |
| 132 | } else { |
| 133 | add_filter('block_categories', 'embedpress_block_category', 10, 2); |
| 134 | } |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | foreach (glob(EMBEDPRESS_GUTENBERG_DIR_PATH . 'block-backend/*.php') as $block_logic) { |
| 140 | require_once $block_logic; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Registers the embedpress gutneberg block on server. |
| 145 | */ |
| 146 | |
| 147 | function embedpress_gutenberg_register_all_block() |
| 148 | { |
| 149 | if (function_exists('register_block_type')) : |
| 150 | |
| 151 | $elements = (array) get_option(EMBEDPRESS_PLG_NAME . ":elements", []); |
| 152 | $g_blocks = isset($elements['gutenberg']) ? (array) $elements['gutenberg'] : []; |
| 153 | $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']; |
| 154 | |
| 155 | foreach ($blocks_to_registers as $blocks_to_register) { |
| 156 | if (!empty($g_blocks[$blocks_to_register])) { |
| 157 | if ('embedpress' === $blocks_to_register) { |
| 158 | register_block_type('embedpress/embedpress', [ |
| 159 | 'render_callback' => 'embedpress_render_block', |
| 160 | 'attributes' => array( |
| 161 | 'clientId' => [ |
| 162 | 'type' => 'string', |
| 163 | ], |
| 164 | 'height' => [ |
| 165 | 'type' => 'string', |
| 166 | 'default' => '450' |
| 167 | ], |
| 168 | 'width' => [ |
| 169 | 'type' => 'string', |
| 170 | 'default' => '600' |
| 171 | ], |
| 172 | 'lockContent' => [ |
| 173 | 'type' => 'boolean', |
| 174 | 'default' => false |
| 175 | ], |
| 176 | 'lockHeading' => [ |
| 177 | 'type' => 'string', |
| 178 | 'default' => 'Content Locked' |
| 179 | ], |
| 180 | 'lockSubHeading' => [ |
| 181 | 'type' => 'string', |
| 182 | 'default' => 'Content is locked and requires password to access it.' |
| 183 | ], |
| 184 | 'lockErrorMessage' => [ |
| 185 | 'type' => 'string', |
| 186 | 'default' => 'Oops, that wasn\'t the right password. Try again.' |
| 187 | ], |
| 188 | 'passwordPlaceholder' => [ |
| 189 | 'type' => 'string', |
| 190 | 'default' => 'Password' |
| 191 | ], |
| 192 | 'submitButtonText' => [ |
| 193 | 'type' => 'string', |
| 194 | 'default' => 'Unlock' |
| 195 | ], |
| 196 | 'submitUnlockingText' => [ |
| 197 | 'type' => 'string', |
| 198 | 'default' => 'Unlocking' |
| 199 | ], |
| 200 | 'enableFooterMessage' => [ |
| 201 | 'type' => 'boolean', |
| 202 | 'default' => false |
| 203 | ], |
| 204 | 'footerMessage' => [ |
| 205 | 'type' => 'string', |
| 206 | 'default' => 'In case you don\'t have the password, kindly reach out to content owner or administrator to request access.' |
| 207 | ], |
| 208 | 'contentPassword' => [ |
| 209 | 'type' => 'string', |
| 210 | 'default' => '', |
| 211 | ], |
| 212 | 'contentShare' => [ |
| 213 | 'type' => 'boolean', |
| 214 | 'default' => false |
| 215 | ], |
| 216 | 'sharePosition' => [ |
| 217 | 'type' => 'string', |
| 218 | 'default' => 'right' |
| 219 | ], |
| 220 | 'customTitle' => [ |
| 221 | 'type' => 'string', |
| 222 | 'default' => '' |
| 223 | ], |
| 224 | 'customDescription' => [ |
| 225 | 'type' => 'string', |
| 226 | 'default' => '' |
| 227 | ], |
| 228 | 'customThumbnail' => [ |
| 229 | 'type' => 'string', |
| 230 | 'default' => '' |
| 231 | ], |
| 232 | |
| 233 | 'videosize' => [ |
| 234 | 'type' => 'string', |
| 235 | 'default' => 'fixed' |
| 236 | ], |
| 237 | |
| 238 | 'loadmore' => [ |
| 239 | 'type' => 'boolean', |
| 240 | 'default' => false |
| 241 | ], |
| 242 | //Youtube Attributes |
| 243 | 'starttime' => [ |
| 244 | 'type' => 'string', |
| 245 | ], |
| 246 | 'endtime' => [ |
| 247 | 'type' => 'string', |
| 248 | ], |
| 249 | 'autoplay' => [ |
| 250 | 'type' => 'boolean', |
| 251 | 'default' => false |
| 252 | ], |
| 253 | 'controls' => [ |
| 254 | 'type' => 'string', |
| 255 | ], |
| 256 | 'progressbarcolor' => [ |
| 257 | 'type' => 'string', |
| 258 | ], |
| 259 | 'videoannotations' => [ |
| 260 | 'type' => 'string', |
| 261 | ], |
| 262 | 'closedcaptions' => [ |
| 263 | 'type' => 'boolean', |
| 264 | 'default' => true |
| 265 | ], |
| 266 | 'relatedvideos' => [ |
| 267 | 'type' => 'boolean', |
| 268 | 'default' => true |
| 269 | ], |
| 270 | 'fullscreen' => [ |
| 271 | 'type' => 'boolean', |
| 272 | 'default' => true |
| 273 | ], |
| 274 | |
| 275 | 'modestbranding' => [ |
| 276 | 'type' => 'string', |
| 277 | ], |
| 278 | //Wistia Attributes |
| 279 | 'wstarttime' => [ |
| 280 | 'type' => 'string', |
| 281 | ], |
| 282 | 'wautoplay' => [ |
| 283 | 'type' => 'boolean', |
| 284 | 'default' => true |
| 285 | ], |
| 286 | 'scheme' => [ |
| 287 | 'type' => 'string', |
| 288 | ], |
| 289 | 'captions' => [ |
| 290 | 'type' => 'boolean', |
| 291 | 'default' => true |
| 292 | ], |
| 293 | 'playbutton' => [ |
| 294 | 'type' => 'boolean', |
| 295 | 'default' => true |
| 296 | ], |
| 297 | 'smallplaybutton' => [ |
| 298 | 'type' => 'boolean', |
| 299 | 'default' => true |
| 300 | ], |
| 301 | 'playbar' => [ |
| 302 | 'type' => 'boolean', |
| 303 | 'default' => true |
| 304 | ], |
| 305 | 'resumable' => [ |
| 306 | 'type' => 'boolean', |
| 307 | 'default' => true |
| 308 | ], |
| 309 | 'wistiafocus' => [ |
| 310 | 'type' => 'boolean', |
| 311 | 'default' => true |
| 312 | ], |
| 313 | 'volumecontrol' => [ |
| 314 | 'type' => 'boolean', |
| 315 | 'default' => true |
| 316 | ], |
| 317 | 'volume' => [ |
| 318 | 'type' => 'number', |
| 319 | 'default' => 100 |
| 320 | ], |
| 321 | 'rewind' => [ |
| 322 | 'type' => 'boolean', |
| 323 | 'default' => false |
| 324 | ], |
| 325 | 'wfullscreen' => [ |
| 326 | 'type' => 'boolean', |
| 327 | 'default' => true |
| 328 | ], |
| 329 | |
| 330 | // Vimeo attributes |
| 331 | 'vstarttime' => [ |
| 332 | 'type' => 'string', |
| 333 | ], |
| 334 | 'vautoplay' => [ |
| 335 | 'type' => 'boolean', |
| 336 | 'default' => false |
| 337 | ], |
| 338 | 'vscheme' => [ |
| 339 | 'type' => 'string', |
| 340 | ], |
| 341 | 'vtitle' => [ |
| 342 | 'type' => 'boolean', |
| 343 | 'default' => true |
| 344 | ], |
| 345 | 'vauthor' => [ |
| 346 | 'type' => 'boolean', |
| 347 | 'default' => true |
| 348 | ], |
| 349 | 'vavatar' => [ |
| 350 | 'type' => 'boolean', |
| 351 | 'default' => true |
| 352 | ], |
| 353 | 'vloop' => [ |
| 354 | 'type' => 'boolean', |
| 355 | 'default' => false |
| 356 | ], |
| 357 | 'vautopause' => [ |
| 358 | 'type' => 'boolean', |
| 359 | 'default' => false |
| 360 | ], |
| 361 | 'vdnt' => [ |
| 362 | 'type' => 'boolean', |
| 363 | 'default' => false |
| 364 | ], |
| 365 | |
| 366 | ), |
| 367 | ]); |
| 368 | } elseif ('embedpress-pdf' === $blocks_to_register) { |
| 369 | register_block_type('embedpress/embedpress-pdf', [ |
| 370 | 'attributes' => array( |
| 371 | 'powered_by' => [ |
| 372 | 'type' => 'boolean', |
| 373 | 'default' => true |
| 374 | ], |
| 375 | 'lockContent' => [ |
| 376 | 'type' => 'boolean', |
| 377 | 'default' => false |
| 378 | ], |
| 379 | 'lockHeading' => [ |
| 380 | 'type' => 'string', |
| 381 | 'default' => 'Content Locked' |
| 382 | ], |
| 383 | 'lockSubHeading' => [ |
| 384 | 'type' => 'string', |
| 385 | 'default' => 'Content is locked and requires password to access it.' |
| 386 | ], |
| 387 | 'passwordPlaceholder' => [ |
| 388 | 'type' => 'string', |
| 389 | 'default' => 'Password' |
| 390 | ], |
| 391 | 'submitButtonText' => [ |
| 392 | 'type' => 'string', |
| 393 | 'default' => 'Unlock' |
| 394 | ], |
| 395 | 'submitUnlockingText' => [ |
| 396 | 'type' => 'string', |
| 397 | 'default' => 'Unlocking' |
| 398 | ], |
| 399 | 'lockErrorMessage' => [ |
| 400 | 'type' => 'string', |
| 401 | 'default' => 'Oops, that wasn\'t the right password. Try again.' |
| 402 | ], |
| 403 | 'enableFooterMessage' => [ |
| 404 | 'type' => 'boolean', |
| 405 | 'default' => false |
| 406 | ], |
| 407 | 'footerMessage' => [ |
| 408 | 'type' => 'string', |
| 409 | 'default' => 'In case you don\'t have the password, kindly reach out to content owner or administrator to request access.' |
| 410 | ], |
| 411 | 'contentPassword' => [ |
| 412 | 'type' => 'string', |
| 413 | 'default' => '' |
| 414 | ], |
| 415 | 'contentShare' => [ |
| 416 | 'type' => 'boolean', |
| 417 | 'default' => false |
| 418 | ], |
| 419 | 'sharePosition' => [ |
| 420 | 'type' => 'string', |
| 421 | 'default' => 'right' |
| 422 | ], |
| 423 | 'presentation' => [ |
| 424 | 'type' => "boolean", |
| 425 | 'default' => true, |
| 426 | ], |
| 427 | |
| 428 | 'position' => [ |
| 429 | 'type' => "string", |
| 430 | 'default' => 'top', |
| 431 | ], |
| 432 | |
| 433 | 'print' => [ |
| 434 | 'type' => "boolean", |
| 435 | 'default' => true, |
| 436 | ], |
| 437 | |
| 438 | 'download' => [ |
| 439 | 'type' => "boolean", |
| 440 | 'default' => true, |
| 441 | ], |
| 442 | 'open' => [ |
| 443 | 'type' => "boolean", |
| 444 | 'default' => true, |
| 445 | ], |
| 446 | 'copy_text' => [ |
| 447 | 'type' => "boolean", |
| 448 | 'default' => true, |
| 449 | ], |
| 450 | 'add_text' => [ |
| 451 | 'type' => "boolean", |
| 452 | 'default' => true, |
| 453 | ], |
| 454 | 'draw' => [ |
| 455 | 'type' => "boolean", |
| 456 | 'default' => true, |
| 457 | ], |
| 458 | 'toolbar' => [ |
| 459 | 'type' => "boolean", |
| 460 | 'default' => true, |
| 461 | ], |
| 462 | 'doc_details' => [ |
| 463 | 'type' => "boolean", |
| 464 | 'default' => true, |
| 465 | ], |
| 466 | 'doc_rotation' => [ |
| 467 | 'type' => "boolean", |
| 468 | 'default' => true, |
| 469 | ], |
| 470 | 'unitoption' => [ |
| 471 | 'type' => "string", |
| 472 | 'default' => 'px', |
| 473 | ], |
| 474 | ), |
| 475 | 'render_callback' => 'embedpress_pdf_render_block', |
| 476 | ]); |
| 477 | } elseif ('embedpress-calendar' === $blocks_to_register) { |
| 478 | register_block_type('embedpress/embedpress-calendar', [ |
| 479 | 'render_callback' => 'embedpress_calendar_render_block', |
| 480 | ]); |
| 481 | } else { |
| 482 | register_block_type('embedpress/' . $blocks_to_register); |
| 483 | } |
| 484 | } else { |
| 485 | |
| 486 | if (WP_Block_Type_Registry::get_instance()->is_registered('embedpress/' . $blocks_to_register)) { |
| 487 | unregister_block_type('embedpress/' . $blocks_to_register); |
| 488 | } |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | endif; |
| 493 | } |
| 494 | |
| 495 | add_action('init', 'embedpress_gutenberg_register_all_block'); |
| 496 | |
| 497 | function getParamData($attributes) |
| 498 | { |
| 499 | |
| 500 | $urlParamData = array( |
| 501 | 'themeMode' => !empty($attributes['themeMode']) ? $attributes['themeMode'] : 'default', |
| 502 | 'toolbar' => !empty($attributes['toolbar']) ? 'true' : 'false', |
| 503 | 'position' => $attributes['position'], |
| 504 | 'presentation' => !empty($attributes['presentation']) ? 'true' : 'false', |
| 505 | 'download' => !empty($attributes['download']) ? 'true' : 'false', |
| 506 | 'copy_text' => !empty($attributes['copy_text']) ? 'true' : 'false', |
| 507 | 'add_text' => !empty($attributes['add_text']) ? 'true' : 'false', |
| 508 | 'draw' => !empty($attributes['draw']) ? 'true' : 'false', |
| 509 | 'doc_rotation' => !empty($attributes['doc_rotation']) ? 'true' : 'false', |
| 510 | 'doc_details' => !empty($attributes['doc_details']) ? 'true' : 'false', |
| 511 | ); |
| 512 | |
| 513 | if($urlParamData['themeMode'] == 'custom') { |
| 514 | $urlParamData['customColor'] = !empty($attributes['customColor']) ? $attributes['customColor'] : '#403A81'; |
| 515 | } |
| 516 | |
| 517 | return "#" . http_build_query($urlParamData); |
| 518 | } |
| 519 | |
| 520 | function embedpress_pdf_render_block($attributes) |
| 521 | { |
| 522 | |
| 523 | |
| 524 | if (!empty($attributes['href'])) { |
| 525 | $renderer = Helper::get_pdf_renderer(); |
| 526 | $pdf_url = $attributes['href']; |
| 527 | $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-pdf-' . rand(100, 10000); |
| 528 | $client_id = md5($id); |
| 529 | |
| 530 | $hash_pass = hash('sha256', wp_salt(32) . md5(isset($attributes['contentPassword']) ? $attributes['contentPassword'] : '')); |
| 531 | |
| 532 | $unitoption = !empty($attributes['unitoption']) ? $attributes['unitoption'] : 'px'; |
| 533 | $width = !empty($attributes['width']) ? $attributes['width'] . $unitoption : '600px'; |
| 534 | |
| 535 | if($unitoption == '%'){ |
| 536 | $width_class = ' ep-percentage-width'; |
| 537 | } |
| 538 | else{ |
| 539 | $width_class = 'ep-fixed-width'; |
| 540 | } |
| 541 | $content_share_class = ''; |
| 542 | $share_position_class = ''; |
| 543 | $share_position = isset($attributes['sharePosition']) ? $attributes['sharePosition'] : 'right'; |
| 544 | |
| 545 | if(!empty($attributes['contentShare'])) { |
| 546 | $content_share_class = 'ep-content-share-enabled'; |
| 547 | $share_position_class = 'ep-share-position-'.$share_position; |
| 548 | } |
| 549 | |
| 550 | $password_correct = isset($_COOKIE['password_correct_'.$client_id]) ? $_COOKIE['password_correct_'.$client_id] : ''; |
| 551 | |
| 552 | $content_protection_class = 'ep-content-protection-enabled'; |
| 553 | if(empty($attributes['lockContent']) || empty($attributes['contentPassword']) || $hash_pass === $password_correct) { |
| 554 | $content_protection_class = 'ep-content-protection-disabled'; |
| 555 | } |
| 556 | |
| 557 | |
| 558 | |
| 559 | $height = !empty($attributes['height']) ? $attributes['height'] . 'px' : '600px'; |
| 560 | $gen_settings = get_option(EMBEDPRESS_PLG_NAME); |
| 561 | |
| 562 | $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by']; |
| 563 | if (isset($attributes['powered_by'])) { |
| 564 | $powered_by = $attributes['powered_by']; |
| 565 | } |
| 566 | |
| 567 | $src = $renderer . ((strpos($renderer, '?') == false) ? '?' : '&') . 'file=' . urlencode($attributes['href']) . getParamData($attributes); |
| 568 | |
| 569 | $pass_hash_key = isset($attributes['contentPassword']) ? md5($attributes['contentPassword']): ''; |
| 570 | |
| 571 | $aligns = [ |
| 572 | 'left' => 'ep-alignleft', |
| 573 | 'right' => 'ep-alignright', |
| 574 | 'center' => 'ep-aligncenter', |
| 575 | 'wide' => 'ep-alignwide', |
| 576 | 'full' => 'ep-alignfull' |
| 577 | ]; |
| 578 | $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : ''; |
| 579 | $dimension = "width:$width;height:$height"; |
| 580 | ob_start(); |
| 581 | ?> |
| 582 | |
| 583 | |
| 584 | <?php |
| 585 | |
| 586 | $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_attr($src) . '" frameborder="0" oncontextmenu="return false;"></iframe> '; |
| 587 | |
| 588 | |
| 589 | if ($powered_by) { |
| 590 | $embed_code .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress')); |
| 591 | } |
| 592 | |
| 593 | |
| 594 | $url = !empty($attributes['href']) ? $attributes['href'] : ''; |
| 595 | ?> |
| 596 | |
| 597 | <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); ?> "> |
| 598 | <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); ?>"> |
| 599 | |
| 600 | <?php |
| 601 | do_action('embedpress_pdf_gutenberg_after_embed', $client_id, 'pdf', $attributes, $pdf_url); |
| 602 | $embed = $embed_code; |
| 603 | if(empty($attributes['lockContent']) || empty($attributes['contentPassword']) || (!empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct)) ){ |
| 604 | |
| 605 | $custom_thumbnail = isset($attributes['customThumbnail']) ? $attributes['customThumbnail'] : ''; |
| 606 | |
| 607 | echo '<div class="ep-embed-content-wraper">'; |
| 608 | $embed = '<div class="position-'.esc_attr( $share_position ).'-wraper gutenberg-pdf-wraper">'; |
| 609 | $embed .= $embed_code; |
| 610 | $embed.= '</div>'; |
| 611 | |
| 612 | if(!empty($attributes['contentShare'])) { |
| 613 | $content_id = $attributes['id']; |
| 614 | $embed .= Helper::embed_content_share($content_id, $attributes); |
| 615 | } |
| 616 | echo $embed; |
| 617 | echo '</div>'; |
| 618 | } else { |
| 619 | if(!empty($attributes['contentShare'])) { |
| 620 | $content_id = $attributes['clientId']; |
| 621 | $embed = '<div class="position-'.esc_attr( $share_position ).'-wraper gutenberg-pdf-wraper">'; |
| 622 | $embed .= $embed_code; |
| 623 | $embed.= '</div>'; |
| 624 | $embed .= Helper::embed_content_share($content_id, $attributes); |
| 625 | } |
| 626 | echo '<div class="ep-embed-content-wraper">'; |
| 627 | Helper::display_password_form($client_id, $embed, $pass_hash_key, $attributes); |
| 628 | echo '</div>'; |
| 629 | } |
| 630 | ?> |
| 631 | |
| 632 | </div> |
| 633 | </div> |
| 634 | <?php |
| 635 | return ob_get_clean(); |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | function embedpress_calendar_render_block($attributes) |
| 640 | { |
| 641 | |
| 642 | $id = !empty($attributes['id']) ? $attributes['id'] : 'embedpress-calendar-' . rand(100, 10000); |
| 643 | $url = !empty($attributes['url']) ? $attributes['url'] : ''; |
| 644 | $is_private = isset($attributes['is_public']); |
| 645 | $client_id = md5($id); |
| 646 | $width = !empty($attributes['width']) ? $attributes['width'] . 'px' : '600px'; |
| 647 | $height = !empty($attributes['height']) ? $attributes['height'] . 'px' : '600px'; |
| 648 | $gen_settings = get_option(EMBEDPRESS_PLG_NAME); |
| 649 | $powered_by = isset($gen_settings['embedpress_document_powered_by']) && 'yes' === $gen_settings['embedpress_document_powered_by']; |
| 650 | if (isset($attributes['powered_by'])) { |
| 651 | $powered_by = $attributes['powered_by']; |
| 652 | } |
| 653 | |
| 654 | $aligns = [ |
| 655 | 'left' => 'alignleft', |
| 656 | 'right' => 'alignright', |
| 657 | 'wide' => 'alignwide', |
| 658 | 'full' => 'alignfull' |
| 659 | ]; |
| 660 | $alignment = isset($attributes['align']) && isset($aligns[$attributes['align']]) ? $aligns[$attributes['align']] : ''; |
| 661 | $dimension = "width:$width;height:$height"; |
| 662 | ob_start(); |
| 663 | ?> |
| 664 | <div class="embedpress-calendar-gutenberg embedpress-calendar ose-calendar <?php echo esc_attr($alignment) ?>" style="<?php echo esc_attr($dimension); ?>; max-width:100%;"> |
| 665 | |
| 666 | <?php |
| 667 | if (!empty($url) && !$is_private) { |
| 668 | ?> |
| 669 | <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_attr($url); ?>"></iframe> |
| 670 | <?php } else { |
| 671 | if (is_embedpress_pro_active()) { |
| 672 | echo Embedpress_Google_Helper::shortcode(); |
| 673 | } |
| 674 | } ?> |
| 675 | <?php do_action('embedpress_calendar_gutenberg_after_embed', $client_id, 'calendar', $attributes); ?> |
| 676 | |
| 677 | <?php |
| 678 | if ($powered_by) { |
| 679 | printf('<p class="embedpress-el-powered" style="width:' . esc_attr($width) . '" >%s</p>', __('Powered By EmbedPress', 'embedpress')); |
| 680 | } ?> |
| 681 | |
| 682 | </div> |
| 683 | <?php |
| 684 | return ob_get_clean(); |
| 685 | } |