Embedpress_Calendar.php
2 years ago
Embedpress_Document.php
2 years ago
Embedpress_Elementor.php
2 years ago
Embedpress_Pdf.php
2 years ago
Embedpress_Document.php
783 lines
| 1 | <?php |
| 2 | |
| 3 | namespace EmbedPress\Elementor\Widgets; |
| 4 | |
| 5 | |
| 6 | use \Elementor\Controls_Manager as Controls_Manager; |
| 7 | use \Elementor\Modules\DynamicTags\Module as TagsModule; |
| 8 | use \Elementor\Widget_Base as Widget_Base; |
| 9 | use \Elementor\Plugin; |
| 10 | use EmbedPress\Includes\Traits\Branding; |
| 11 | use EmbedPress\Includes\Classes\Helper; |
| 12 | |
| 13 | ( defined( 'ABSPATH' ) ) or die( "No direct script access allowed." ); |
| 14 | |
| 15 | class Embedpress_Document extends Widget_Base |
| 16 | { |
| 17 | use Branding; |
| 18 | protected $pro_class = ''; |
| 19 | protected $pro_text = ''; |
| 20 | public function get_name() |
| 21 | { |
| 22 | return 'embedpres_document'; |
| 23 | } |
| 24 | |
| 25 | public function get_title() |
| 26 | { |
| 27 | return esc_html__( 'EmbedPress Document', 'embedpress' ); |
| 28 | } |
| 29 | |
| 30 | public function get_categories() |
| 31 | { |
| 32 | return ['embedpress']; |
| 33 | } |
| 34 | |
| 35 | public function get_custom_help_url() |
| 36 | { |
| 37 | return 'https://embedpress.com/documentation'; |
| 38 | } |
| 39 | |
| 40 | public function get_icon() |
| 41 | { |
| 42 | return 'icon-document'; |
| 43 | } |
| 44 | |
| 45 | public function get_style_depends() |
| 46 | { |
| 47 | return [ |
| 48 | 'embedpress-elementor-css', |
| 49 | 'embedpress-style' |
| 50 | ]; |
| 51 | } |
| 52 | |
| 53 | public function get_script_depends() |
| 54 | { |
| 55 | |
| 56 | $handler_keys = get_option('enabled_elementor_scripts', []); |
| 57 | |
| 58 | $handles = []; |
| 59 | |
| 60 | $handles[] = 'embedpress-pdfobject'; |
| 61 | $handles[] = 'embedpress-front'; |
| 62 | |
| 63 | if (isset($handler_keys['enabled_ads']) && $handler_keys['enabled_ads'] === 'yes') { |
| 64 | $handles[] = 'embedpress-ads'; |
| 65 | } |
| 66 | if (isset($handler_keys['enabled_docs_custom_viewer']) && $handler_keys['enabled_docs_custom_viewer'] === 'yes') { |
| 67 | $handles[] = 'embedpress_documents_viewer_script'; |
| 68 | } |
| 69 | |
| 70 | return $handles; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Get widget keywords. |
| 75 | * |
| 76 | * Retrieve the list of keywords the widget belongs to. |
| 77 | * |
| 78 | * @return array Widget keywords. |
| 79 | * @since 2.5.5 |
| 80 | * @access public |
| 81 | * |
| 82 | */ |
| 83 | public function get_keywords() |
| 84 | { |
| 85 | return ['embedpress', 'pdf', 'doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'embedpress-document']; |
| 86 | } |
| 87 | |
| 88 | protected function register_controls() |
| 89 | { |
| 90 | $this->pro_class = is_embedpress_pro_active() ? '': 'embedpress-pro-control not-active'; |
| 91 | $this->pro_text = is_embedpress_pro_active() ? '': '<sup class="embedpress-pro-label" style="color:red">'.__('Pro', 'embedpress').'</sup>'; |
| 92 | /** |
| 93 | * EmbedPress Content Settings |
| 94 | */ |
| 95 | $this->start_controls_section( |
| 96 | 'embedpress_document_content_settings', |
| 97 | [ |
| 98 | 'label' => esc_html__( 'General', 'embedpress' ), |
| 99 | ] |
| 100 | ); |
| 101 | |
| 102 | $this->add_control( |
| 103 | 'embedpress_document_type', |
| 104 | [ |
| 105 | 'label' => __( 'Document Type', 'embedpress' ), |
| 106 | 'type' => Controls_Manager::SELECT, |
| 107 | 'default' => 'file', |
| 108 | 'options' => [ |
| 109 | 'file' => __( 'File', 'embedpress' ), |
| 110 | 'url' => __( 'URL', 'embedpress' ) |
| 111 | ], |
| 112 | ] |
| 113 | ); |
| 114 | $this->add_control( |
| 115 | 'embedpress_document_Uploader', |
| 116 | [ |
| 117 | |
| 118 | 'label' => __( 'Upload File', 'embedpress' ), |
| 119 | 'type' => Controls_Manager::MEDIA, |
| 120 | 'dynamic' => [ |
| 121 | 'active' => true, |
| 122 | 'categories' => [ |
| 123 | TagsModule::MEDIA_CATEGORY, |
| 124 | ], |
| 125 | ], |
| 126 | 'media_type' => [ |
| 127 | 'application/pdf', |
| 128 | 'application/msword', |
| 129 | 'application/vnd.ms-powerpoint', |
| 130 | 'application/vnd.ms-excel', |
| 131 | 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
| 132 | 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', |
| 133 | 'application/vnd.openxmlformats-officedocument.presentationml.presentation', |
| 134 | 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' // Added PPSX MIME type |
| 135 | |
| 136 | ], |
| 137 | 'description' => __( 'Upload a file or pick one from your media library for embed. Supported File Type: PDF, DOC/DOCX, PPT/PPTX, XLS/XLSX etc.', |
| 138 | 'embedpress' ), |
| 139 | 'condition' => [ |
| 140 | 'embedpress_document_type' => 'file' |
| 141 | ], |
| 142 | ] |
| 143 | ); |
| 144 | |
| 145 | $this->add_control( |
| 146 | 'embedpress_document_file_link', |
| 147 | [ |
| 148 | 'label' => __( 'URL', 'embedpress' ), |
| 149 | 'type' => Controls_Manager::URL, |
| 150 | 'placeholder' => __( 'https://your-link.com/file.pdf', 'embedpress' ), |
| 151 | 'show_external' => false, |
| 152 | 'dynamic' => [ |
| 153 | 'active' => true, |
| 154 | ], |
| 155 | 'default' => [ |
| 156 | 'url' => '' |
| 157 | ], |
| 158 | 'condition' => [ |
| 159 | 'embedpress_document_type' => 'url' |
| 160 | ], |
| 161 | ] |
| 162 | ); |
| 163 | |
| 164 | $this->add_responsive_control( |
| 165 | 'embedpress_elementor_document_width', |
| 166 | [ |
| 167 | 'type' => \Elementor\Controls_Manager::SLIDER, |
| 168 | 'label' => esc_html__( 'Width', 'embedpress' ), |
| 169 | 'range' => [ |
| 170 | 'px' => [ |
| 171 | 'min' => 1, |
| 172 | 'max' => 1000, |
| 173 | ], |
| 174 | ], |
| 175 | 'devices' => [ 'desktop', 'tablet', 'mobile' ], |
| 176 | 'default' => [ |
| 177 | 'unit' => 'px', |
| 178 | 'size' => Helper::get_options_value('enableEmbedResizeWidth'), |
| 179 | ], |
| 180 | 'desktop_default' => [ |
| 181 | 'unit' => 'px', |
| 182 | 'size' => 600, |
| 183 | ], |
| 184 | 'tablet_default' => [ |
| 185 | 'size' => 400, |
| 186 | 'unit' => 'px', |
| 187 | ], |
| 188 | 'mobile_default' => [ |
| 189 | 'size' => 300, |
| 190 | 'unit' => 'px', |
| 191 | ], |
| 192 | 'selectors' => [ |
| 193 | '{{WRAPPER}} .embedpress-document-embed iframe' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%', |
| 194 | '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%', |
| 195 | '{{WRAPPER}} .embedpress-document-embed' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%', |
| 196 | ], |
| 197 | ] |
| 198 | ); |
| 199 | $this->add_responsive_control( |
| 200 | 'embedpress_elementor_document_height', |
| 201 | [ |
| 202 | 'type' => \Elementor\Controls_Manager::SLIDER, |
| 203 | 'label' => esc_html__( 'Height', 'embedpress' ), |
| 204 | 'range' => [ |
| 205 | 'px' => [ |
| 206 | 'min' => 1, |
| 207 | 'max' => 1500, |
| 208 | ], |
| 209 | ], |
| 210 | 'devices' => [ 'desktop', 'tablet', 'mobile' ], |
| 211 | 'default' => [ |
| 212 | 'unit' => 'px', |
| 213 | 'size' => Helper::get_options_value('enableEmbedResizeHeight'), |
| 214 | ], |
| 215 | 'desktop_default' => [ |
| 216 | 'unit' => 'px', |
| 217 | 'size' => 600, |
| 218 | ], |
| 219 | 'tablet_default' => [ |
| 220 | 'size' => 400, |
| 221 | 'unit' => 'px', |
| 222 | ], |
| 223 | 'mobile_default' => [ |
| 224 | 'size' => 300, |
| 225 | 'unit' => 'px', |
| 226 | ], |
| 227 | 'selectors' => [ |
| 228 | '{{WRAPPER}} .embedpress-document-embed iframe' => 'height: {{SIZE}}{{UNIT}}!important;', |
| 229 | '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'height: {{SIZE}}{{UNIT}};', |
| 230 | '{{WRAPPER}} .embedpress-document-embed ' => 'max-height: {{SIZE}}{{UNIT}};', |
| 231 | ], |
| 232 | ] |
| 233 | ); |
| 234 | |
| 235 | $this->add_responsive_control( |
| 236 | 'embedpress_elementor_document_align', |
| 237 | [ |
| 238 | 'label' => __( 'Alignment', 'embedpress' ), |
| 239 | 'type' => Controls_Manager::CHOOSE, |
| 240 | 'options' => [ |
| 241 | 'left' => [ |
| 242 | 'title' => __( 'Left', 'embedpress' ), |
| 243 | 'icon' => 'eicon-text-align-left', |
| 244 | ], |
| 245 | 'center' => [ |
| 246 | 'title' => __( 'Center', 'embedpress' ), |
| 247 | 'icon' => 'eicon-text-align-center', |
| 248 | ], |
| 249 | 'right' => [ |
| 250 | 'title' => __( 'Right', 'embedpress' ), |
| 251 | 'icon' => 'eicon-text-align-right', |
| 252 | ] |
| 253 | ], |
| 254 | 'prefix_class' => 'elementor%s-align-', |
| 255 | 'default' => '', |
| 256 | ] |
| 257 | ); |
| 258 | |
| 259 | $this->add_control( |
| 260 | 'embedpress_document_powered_by', |
| 261 | [ |
| 262 | 'label' => __( 'Powered By', 'embedpress' ), |
| 263 | 'type' => Controls_Manager::SWITCHER, |
| 264 | 'label_on' => __( 'Show', 'embedpress' ), |
| 265 | 'label_off' => __( 'Hide', 'embedpress' ), |
| 266 | 'return_value' => 'yes', |
| 267 | 'default' => apply_filters( 'embedpress_document_powered_by_control', 'yes' ), |
| 268 | ] |
| 269 | ); |
| 270 | |
| 271 | $this->init_branding_controls( 'document'); |
| 272 | |
| 273 | $this->end_controls_section(); |
| 274 | |
| 275 | /** |
| 276 | * EmbedPress Document control settings |
| 277 | */ |
| 278 | |
| 279 | $this->start_controls_section( |
| 280 | 'embedpress_doc_content_settings', |
| 281 | [ |
| 282 | 'label' => esc_html__('Controls', 'embedpress'), |
| 283 | ] |
| 284 | ); |
| 285 | |
| 286 | $this->add_control( |
| 287 | 'important_note', |
| 288 | [ |
| 289 | 'type' => \Elementor\Controls_Manager::RAW_HTML, |
| 290 | 'raw' => esc_html__( 'Download feature is available when link has the document extension at the end.', 'embedpress' ), |
| 291 | 'content_classes' => 'elementor-panel-alert elementor-panel-alert-info', |
| 292 | 'condition' => [ |
| 293 | 'embedpress_document_type' => 'url', |
| 294 | ], |
| 295 | ] |
| 296 | ); |
| 297 | |
| 298 | $this->add_control( |
| 299 | 'important_note_2', |
| 300 | [ |
| 301 | 'type' => \Elementor\Controls_Manager::RAW_HTML, |
| 302 | 'raw' => esc_html__( 'Toolbar and additional feature options become accessible upon selecting the Custom Viewer mode.', 'embedpress' ), |
| 303 | 'content_classes' => 'elementor-panel-alert elementor-panel-alert-info', |
| 304 | 'condition' => [ |
| 305 | 'embedpress_document_type' => 'file', |
| 306 | 'embedpress_document_viewer' => 'office', |
| 307 | ], |
| 308 | ] |
| 309 | ); |
| 310 | |
| 311 | |
| 312 | $this->add_control( |
| 313 | 'embedpress_document_viewer', |
| 314 | [ |
| 315 | 'label' => __('Viewer', 'embedpress'), |
| 316 | 'type' => Controls_Manager::SELECT, |
| 317 | 'default' => 'custom', |
| 318 | 'options' => [ |
| 319 | 'custom' => __('Custom', 'embedpress'), |
| 320 | 'office' => __('MS Office', 'embedpress'), |
| 321 | 'google' => __('Google', 'embedpress'), |
| 322 | ], |
| 323 | ] |
| 324 | ); |
| 325 | |
| 326 | $this->add_control( |
| 327 | 'embedpress_theme_mode', |
| 328 | [ |
| 329 | 'label' => __('Theme', 'embedpress'), |
| 330 | 'type' => Controls_Manager::SELECT, |
| 331 | 'default' => 'default', |
| 332 | 'options' => [ |
| 333 | 'default' => __('System Default', 'embedpress'), |
| 334 | 'dark' => __('Dark', 'embedpress'), |
| 335 | 'light' => __('Light', 'embedpress'), |
| 336 | 'custom' => __('Custom', 'embedpress') |
| 337 | ], |
| 338 | 'condition' => [ |
| 339 | 'embedpress_document_viewer' => 'custom', |
| 340 | ], |
| 341 | |
| 342 | ] |
| 343 | ); |
| 344 | |
| 345 | $this->add_control( |
| 346 | 'embedpress_doc_custom_color', |
| 347 | [ |
| 348 | 'label' => esc_html__( 'Color', 'embedpress' ), |
| 349 | 'type' => \Elementor\Controls_Manager::COLOR, |
| 350 | 'condition' => [ |
| 351 | 'embedpress_theme_mode' => 'custom', |
| 352 | 'embedpress_document_viewer' => 'custom', |
| 353 | ], |
| 354 | ] |
| 355 | ); |
| 356 | |
| 357 | $this->add_control( |
| 358 | 'doc_toolbar', |
| 359 | [ |
| 360 | 'label' => sprintf(__('Toolbar %s', 'embedpress'), $this->pro_text), |
| 361 | 'type' => Controls_Manager::SWITCHER, |
| 362 | 'label_on' => __('Show', 'embedpress'), |
| 363 | 'label_off' => __('Hide', 'embedpress'), |
| 364 | 'return_value' => 'yes', |
| 365 | 'default' => 'yes', |
| 366 | 'classes' => $this->pro_class, |
| 367 | 'condition' => [ |
| 368 | 'embedpress_document_viewer' => 'custom', |
| 369 | ], |
| 370 | ] |
| 371 | ); |
| 372 | |
| 373 | |
| 374 | $this->add_control( |
| 375 | 'doc_fullscreen_mode', |
| 376 | [ |
| 377 | 'label' => __('Fullscreen', 'embedpress'), |
| 378 | 'type' => Controls_Manager::SWITCHER, |
| 379 | 'label_on' => __('Show', 'embedpress'), |
| 380 | 'label_off' => __('Hide', 'embedpress'), |
| 381 | 'return_value' => 'yes', |
| 382 | 'default' => 'yes', |
| 383 | 'condition' => [ |
| 384 | 'doc_toolbar' => 'yes', |
| 385 | 'embedpress_document_viewer' => 'custom', |
| 386 | ], |
| 387 | ] |
| 388 | ); |
| 389 | |
| 390 | $this->add_control( |
| 391 | 'doc_print_download', |
| 392 | [ |
| 393 | 'label' => sprintf(__('Print/Download %s', 'embedpress'), $this->pro_text), |
| 394 | 'type' => Controls_Manager::SWITCHER, |
| 395 | 'label_on' => __('Show', 'embedpress'), |
| 396 | 'label_off' => __('Hide', 'embedpress'), |
| 397 | 'return_value' => 'yes', |
| 398 | 'default' => 'yes', |
| 399 | 'classes' => $this->pro_class, |
| 400 | 'condition' => [ |
| 401 | 'doc_toolbar' => 'yes', |
| 402 | 'embedpress_document_viewer' => 'custom', |
| 403 | ], |
| 404 | ] |
| 405 | ); |
| 406 | |
| 407 | |
| 408 | $this->add_control( |
| 409 | 'doc_draw', |
| 410 | [ |
| 411 | 'label' => __('Draw', 'embedpress'), |
| 412 | 'type' => Controls_Manager::SWITCHER, |
| 413 | 'label_on' => __('Show', 'embedpress'), |
| 414 | 'label_off' => __('Hide', 'embedpress'), |
| 415 | 'return_value' => 'yes', |
| 416 | 'default' => 'yes', |
| 417 | 'condition' => [ |
| 418 | 'doc_toolbar' => 'yes', |
| 419 | 'embedpress_document_viewer' => 'custom', |
| 420 | ], |
| 421 | ] |
| 422 | ); |
| 423 | |
| 424 | |
| 425 | $this->end_controls_section(); |
| 426 | |
| 427 | do_action( 'extend_elementor_controls', $this, '_doc_', $this->pro_text, $this->pro_class); |
| 428 | |
| 429 | if (! is_embedpress_pro_active()) { |
| 430 | $this->start_controls_section( |
| 431 | 'embedpress_pro_section', |
| 432 | [ |
| 433 | 'label' => __('Go Premium for More Features', 'embedpress'), |
| 434 | ] |
| 435 | ); |
| 436 | |
| 437 | $this->add_control( |
| 438 | 'embedpress_pro_cta', |
| 439 | [ |
| 440 | 'label' => __('Unlock more possibilities', 'embedpress'), |
| 441 | 'type' => Controls_Manager::CHOOSE, |
| 442 | 'options' => [ |
| 443 | '1' => [ |
| 444 | 'title' => '', |
| 445 | 'icon' => 'eicon-lock', |
| 446 | ], |
| 447 | ], |
| 448 | 'default' => '1', |
| 449 | 'description' => '<span class="pro-feature"> Get the <a href="https://wpdeveloper.com/in/upgrade-embedpress" target="_blank">Pro version</a> for more provider support and customization options.</span>', |
| 450 | ] |
| 451 | ); |
| 452 | |
| 453 | $this->end_controls_section(); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | private function is_pdf( $url ) |
| 458 | { |
| 459 | $arr = explode( '.', $url ); |
| 460 | return end( $arr ) === 'pdf'; |
| 461 | } |
| 462 | |
| 463 | protected function render() |
| 464 | { |
| 465 | $settings = $this->get_settings(); |
| 466 | |
| 467 | Helper::get_enable_settings_data_for_scripts($settings); |
| 468 | |
| 469 | $client_id = esc_attr($this->get_id()); |
| 470 | $pass_hash_key = md5($settings['embedpress_doc_lock_content_password']); |
| 471 | $url = esc_url($this->get_file_url()); |
| 472 | $id = 'embedpress-pdf-' . esc_attr($this->get_id()); |
| 473 | |
| 474 | if ($settings['embedpress_document_type'] === 'url') { |
| 475 | if (class_exists('ACF') && function_exists('get_field')) { |
| 476 | if (!empty($settings['__dynamic__']) && !empty($settings['__dynamic__']['embedpress_document_file_link'])) { |
| 477 | $decode_url = urldecode(($settings['__dynamic__']['embedpress_document_file_link'])); |
| 478 | preg_match('/"key":"([^"]+):([^"]+)"/', $decode_url, $matches); |
| 479 | if (isset($matches[0])) { |
| 480 | if (isset($matches[1])) { |
| 481 | $get_acf_key = $matches[1]; |
| 482 | $url = esc_url(get_field($get_acf_key)); |
| 483 | |
| 484 | if (empty($url)) { |
| 485 | $pattern = '/"fallback":"([^"]+)"/'; |
| 486 | preg_match($pattern, $decode_url, $matches); |
| 487 | |
| 488 | if (isset($matches[1])) { |
| 489 | $url = esc_url($matches[1]); |
| 490 | } |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | } |
| 496 | } |
| 497 | $hash_pass = hash('sha256', wp_salt(32) . md5($settings['embedpress_doc_lock_content_password'])); |
| 498 | |
| 499 | $dimension = ''; |
| 500 | if (empty($settings['embedpress_doc_lock_content']) && empty($settings['embedpress_doc_lock_content_password'])) { |
| 501 | $dimension = "width: " . esc_attr($settings['embedpress_elementor_document_width']['size']) . "px; height: " . esc_attr($settings['embedpress_elementor_document_height']['size']) . "px"; |
| 502 | } |
| 503 | |
| 504 | $content_locked_class = ''; |
| 505 | if (!empty($settings['embedpress_doc_lock_content']) && !empty($settings['embedpress_doc_lock_content_password'])) { |
| 506 | $content_locked_class = 'ep-content-locked'; |
| 507 | } |
| 508 | |
| 509 | $this->add_render_attribute('embedpres-pdf-render', [ |
| 510 | 'class' => ['embedpress-embed-document-pdf', $id], |
| 511 | 'data-emid' => esc_attr($id) |
| 512 | ]); |
| 513 | |
| 514 | Helper::get_source_data(md5($this->get_id()) . '_eb_elementor', $url, 'elementor_source_data', 'elementor_temp_source_data'); |
| 515 | |
| 516 | $this->add_render_attribute('embedpress-document', [ |
| 517 | 'class' => ['embedpress-document-embed', 'ep-doc-' . md5($id), 'ose-document', $content_locked_class] |
| 518 | ]); |
| 519 | |
| 520 | $embed_settings = []; |
| 521 | $embed_settings['customThumbnail'] = !empty($settings['embedpress_doc_content_share_custom_thumbnail']['url']) ? esc_url($settings['embedpress_doc_content_share_custom_thumbnail']['url']) : ''; |
| 522 | |
| 523 | $embed_settings['customTitle'] = !empty($settings['embedpress_doc_content_title']) ? sanitize_text_field($settings['embedpress_doc_content_title']) : sanitize_text_field(Helper::get_file_title($url)); |
| 524 | |
| 525 | $embed_settings['customDescription'] = !empty($settings['embedpress_doc_content_descripiton']) ? sanitize_text_field($settings['embedpress_doc_content_descripiton']) : sanitize_text_field(Helper::get_file_title($url)); |
| 526 | |
| 527 | $embed_settings['sharePosition'] = !empty($settings['embedpress_doc_content_share_position']) ? esc_attr($settings['embedpress_doc_content_share_position']) : 'right'; |
| 528 | |
| 529 | $embed_settings['lockHeading'] = !empty($settings['embedpress_doc_lock_content_heading']) ? sanitize_text_field($settings['embedpress_doc_lock_content_heading']) : ''; |
| 530 | |
| 531 | $embed_settings['lockSubHeading'] = !empty($settings['embedpress_doc_lock_content_sub_heading']) ? sanitize_text_field($settings['embedpress_doc_lock_content_sub_heading']) : ''; |
| 532 | |
| 533 | $embed_settings['lockErrorMessage'] = !empty($settings['embedpress_doc_lock_content_error_message']) ? sanitize_text_field($settings['embedpress_doc_lock_content_error_message']) : ''; |
| 534 | |
| 535 | $embed_settings['passwordPlaceholder'] = !empty($settings['embedpress_doc_password_placeholder']) ? esc_attr($settings['embedpress_doc_password_placeholder']) : ''; |
| 536 | |
| 537 | $embed_settings['submitButtonText'] = !empty($settings['embedpress_doc_submit_button_text']) ? sanitize_text_field($settings['embedpress_doc_submit_button_text']) : ''; |
| 538 | |
| 539 | $embed_settings['submitUnlockingText'] = !empty($settings['embedpress_doc_submit_Unlocking_text']) ? sanitize_text_field($settings['embedpress_doc_submit_Unlocking_text']) : ''; |
| 540 | |
| 541 | $embed_settings['enableFooterMessage'] = !empty($settings['embedpress_doc_enable_footer_message']) ? esc_attr($settings['embedpress_doc_enable_footer_message']) : ''; |
| 542 | |
| 543 | $embed_settings['footerMessage'] = !empty($settings['embedpress_doc_lock_content_footer_message']) ? sanitize_text_field($settings['embedpress_doc_lock_content_footer_message']) : ''; |
| 544 | |
| 545 | |
| 546 | $content_share_class = ''; |
| 547 | $share_position_class = ''; |
| 548 | $share_position = isset($settings['embedpress_doc_content_share_position']) ? esc_attr($settings['embedpress_doc_content_share_position']) : 'right'; |
| 549 | |
| 550 | if (!empty($settings['embedpress_doc_content_share'])) { |
| 551 | $content_share_class = 'ep-content-share-enabled'; |
| 552 | $share_position_class = 'ep-share-position-' . $share_position; |
| 553 | } |
| 554 | |
| 555 | $password_correct = isset($_COOKIE['password_correct_' . $client_id]) ? sanitize_text_field($_COOKIE['password_correct_' . $client_id]) : ''; |
| 556 | |
| 557 | $content_protection_class = 'ep-content-protection-enabled'; |
| 558 | if (empty($settings['embedpress_doc_lock_content']) || empty($settings['embedpress_doc_lock_content_password']) || $hash_pass === $password_correct) { |
| 559 | $content_protection_class = 'ep-content-protection-disabled'; |
| 560 | } |
| 561 | |
| 562 | $adsAtts = ''; |
| 563 | |
| 564 | if (!empty($settings['adManager'])) { |
| 565 | $ad = base64_encode(json_encode($settings)); // Using WordPress JSON encoding function |
| 566 | $adsAtts = 'data-sponsored-id="' . esc_attr($client_id) . '" data-sponsored-attrs="' . esc_attr($ad) . '" class="ad-mask"'; |
| 567 | } |
| 568 | |
| 569 | ?> |
| 570 | |
| 571 | <div <?php echo $this->get_render_attribute_string('embedpress-document'); ?> style="<?php echo esc_attr($dimension); ?>; max-width:100%; display: inline-block"> |
| 572 | |
| 573 | <?php |
| 574 | do_action('embedpress_document_after_embed', $settings, $url, $id, $this); |
| 575 | |
| 576 | if ($url != '') { |
| 577 | $url = esc_url($url); |
| 578 | |
| 579 | if ($this->is_pdf($url)) { |
| 580 | $this->add_render_attribute('embedpres-pdf-render', 'data-emsrc', esc_url($url)); |
| 581 | $embed_content = '<div ' . $this->get_render_attribute_string('embedpres-pdf-render') . '>'; |
| 582 | |
| 583 | $embed_content .= '<iframe title="' . esc_attr(Helper::get_file_title($url)) . '" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" style="' . esc_attr($dimension) . '; max-width:100%;" src="' . esc_url($url) . '"></iframe>'; |
| 584 | |
| 585 | if ($settings['embedpress_document_powered_by'] === 'yes') { |
| 586 | $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', esc_html__('Powered By EmbedPress', 'embedpress')); |
| 587 | } |
| 588 | $embed_content .= '</div>'; |
| 589 | |
| 590 | if (Plugin::$instance->editor->is_edit_mode()) { |
| 591 | $embed_content .= $this->render_editor_script($id, $url); |
| 592 | } |
| 593 | } else { |
| 594 | if (Helper::is_file_url($url)) { |
| 595 | $view_link = '//view.officeapps.live.com/op/embed.aspx?src=' . urlencode($url) . '&embedded=true'; |
| 596 | } else { |
| 597 | $view_link = 'https://drive.google.com/viewerng/viewer?url=' . urlencode($url) . '&embedded=true&chrome=false'; |
| 598 | } |
| 599 | |
| 600 | |
| 601 | if($settings['embedpress_document_viewer'] === 'custom') |
| 602 | { |
| 603 | if (Helper::is_file_url($url)) { |
| 604 | $view_link = '//view.officeapps.live.com/op/embed.aspx?src=' . urlencode($url) . '&embedded=true'; |
| 605 | } else { |
| 606 | $view_link = 'https://drive.google.com/viewerng/viewer?url=' . urlencode($url) . '&embedded=true&chrome=false'; |
| 607 | } |
| 608 | } |
| 609 | elseif($settings['embedpress_document_viewer'] === 'office') |
| 610 | { |
| 611 | $view_link = '//view.officeapps.live.com/op/embed.aspx?src=' . urlencode($url) . '&embedded=true'; |
| 612 | } |
| 613 | elseif($settings['embedpress_document_viewer'] === 'google') |
| 614 | { |
| 615 | $view_link = '//docs.google.com/gview?embedded=true&url=' . urlencode($url); |
| 616 | } |
| 617 | |
| 618 | $hostname = parse_url($url, PHP_URL_HOST); |
| 619 | $domain = implode(".", array_slice(explode(".", $hostname), -2)); |
| 620 | |
| 621 | if ($domain == "google.com") { |
| 622 | $view_link = $url . '?embedded=true'; |
| 623 | if (strpos($view_link, '/presentation/')) { |
| 624 | $view_link = Helper::get_google_presentation_url($url); |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | $embed_content = '<div ' . $this->get_render_attribute_string('embedpres-pdf-render') . '>'; |
| 629 | |
| 630 | $is_powered_by = ''; |
| 631 | if ($settings['embedpress_document_powered_by'] === 'yes') { |
| 632 | $is_powered_by = 'ep-powered-by-enabled'; |
| 633 | } |
| 634 | |
| 635 | $is_download_enabled = ' enabled-file-download'; |
| 636 | if ($settings['doc_print_download'] !== 'yes') { |
| 637 | $is_download_enabled = ''; |
| 638 | } |
| 639 | |
| 640 | $file_extenstion = 'link'; |
| 641 | if (!empty(Helper::is_file_url($url))) { |
| 642 | $file_extenstion = Helper::get_extension_from_file_url($url); |
| 643 | } |
| 644 | |
| 645 | $is_masked = ''; |
| 646 | |
| 647 | if($settings['embedpress_document_viewer'] === 'custom') |
| 648 | { |
| 649 | $is_masked = 'ep-file-download-option-masked '; |
| 650 | } |
| 651 | |
| 652 | $is_custom_theme = ''; |
| 653 | |
| 654 | if ($settings['embedpress_theme_mode'] == 'custom') { |
| 655 | $custom_color = sanitize_text_field($settings['embedpress_doc_custom_color']); |
| 656 | |
| 657 | $is_custom_theme = 'data-custom-color="'.esc_attr($custom_color).'"'; |
| 658 | } |
| 659 | |
| 660 | $embed_content .= '<div class="'.esc_attr( $is_masked ).'ep-file-' . esc_attr($file_extenstion) . ' ' . $is_powered_by . '' . $is_download_enabled . '" data-theme-mode="' . esc_attr($settings['embedpress_theme_mode']) . '"' . $is_custom_theme . ' data-id="' . esc_attr($this->get_id()) . '">'; |
| 661 | |
| 662 | $sandbox = ''; |
| 663 | if ($settings['doc_print_download'] === 'yes') { |
| 664 | $sandbox = 'sandbox="allow-forms allow-modals allow-orientation-lock allow-pointer-lock allow-presentation allow-same-origin allow-scripts allow-top-navigation allow-top-navigation-by-user-activation"'; |
| 665 | } |
| 666 | |
| 667 | $embed_content .= '<iframe title="' . esc_attr(Helper::get_file_title($url)) . '" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" style="' . esc_attr($dimension) . '; max-width:100%;" src="' . esc_url($view_link) . '" ' . $sandbox . '> |
| 668 | </iframe>'; |
| 669 | |
| 670 | if ($settings['embedpress_document_viewer'] === 'custom' && $settings['doc_print_download'] === 'yes' && (Helper::get_extension_from_file_url($url) === 'pptx' || Helper::get_extension_from_file_url($url) === 'ppt' || Helper::get_extension_from_file_url($url) === 'xls' || Helper::get_extension_from_file_url($url) === 'xlsx')) { |
| 671 | $embed_content .= '<div class="embed-download-disabled"></div>'; |
| 672 | } |
| 673 | |
| 674 | if ($settings['doc_draw'] === 'yes') { |
| 675 | $embed_content .= '<canvas class="ep-doc-canvas" width="' . esc_attr($settings['embedpress_elementor_document_width']['size']) . '" height="' . esc_attr($settings['embedpress_elementor_document_height']['size']) . '" ></canvas>'; |
| 676 | } |
| 677 | |
| 678 | if ($settings['doc_print_download'] === 'yes' && Helper::get_extension_from_file_url($url) !== 'pptx') { |
| 679 | $embed_content .= '<div style="width: 40px; height: 40px; position: absolute; opacity: 0; right: 12px; top: 12px;"></div>'; |
| 680 | } |
| 681 | |
| 682 | if (!empty($settings['doc_toolbar']) && $settings['embedpress_document_viewer'] === 'custom') { |
| 683 | $embed_content .= '<div class="ep-external-doc-icons">'; |
| 684 | |
| 685 | if (empty(Helper::is_file_url($url))) { |
| 686 | $embed_content .= Helper::ep_get_popup_icon(); |
| 687 | } |
| 688 | |
| 689 | if (!empty(Helper::is_file_url($url))) { |
| 690 | if (!empty($settings['doc_print_download'])) { |
| 691 | $embed_content .= Helper::ep_get_print_icon(); |
| 692 | $embed_content .= Helper::ep_get_download_icon(); |
| 693 | } |
| 694 | } |
| 695 | if (!empty($settings['doc_draw'])) { |
| 696 | $embed_content .= Helper::ep_get_draw_icon(); |
| 697 | } |
| 698 | if (!empty($settings['doc_fullscreen_mode'])) { |
| 699 | $embed_content .= Helper::ep_get_fullscreen_icon(); |
| 700 | $embed_content .= Helper::ep_get_minimize_icon(); |
| 701 | } |
| 702 | |
| 703 | $embed_content .= '</div>'; |
| 704 | } |
| 705 | $embed_content .= '</div>'; |
| 706 | |
| 707 | if ($settings['embedpress_document_powered_by'] === 'yes') { |
| 708 | $embed_content .= '<div>'; |
| 709 | $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', esc_html__('Powered By EmbedPress', 'embedpress')); |
| 710 | $embed_content .= '</div>'; |
| 711 | } |
| 712 | |
| 713 | $embed_content .= '</div>'; |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | |
| 718 | ?> |
| 719 | <div <?php echo $adsAtts; ?>> |
| 720 | |
| 721 | <div id="ep-elementor-content-<?php echo esc_attr($client_id) ?>" class="ep-elementor-content <?php if (!empty($settings['embedpress_doc_content_share'])) : echo esc_attr('position-' . $settings['embedpress_doc_content_share_position'] . '-wraper'); endif; ?> <?php echo esc_attr($content_share_class . ' ' . $share_position_class . ' ' . $content_protection_class); ?>"> |
| 722 | <div id="<?php echo esc_attr($this->get_id()); ?>" class="ep-embed-content-wraper"> |
| 723 | <?php |
| 724 | |
| 725 | $content_id = $client_id; |
| 726 | if ((empty($settings['embedpress_doc_lock_content']) || $settings['embedpress_doc_lock_content'] == 'no' || empty($settings['embedpress_doc_lock_content_password'])) || (!empty(Helper::is_password_correct($client_id)) && ($hash_pass === $_COOKIE['password_correct_' . $client_id]))) { |
| 727 | |
| 728 | if (!empty($settings['embedpress_doc_content_share'])) { |
| 729 | $embed_content .= Helper::embed_content_share($content_id, $embed_settings); |
| 730 | } |
| 731 | if (!empty($embed_content)) { |
| 732 | echo $embed_content; |
| 733 | } |
| 734 | } else { |
| 735 | if (!empty($settings['embedpress_doc_content_share'])) { |
| 736 | $embed_content .= Helper::embed_content_share($content_id, $embed_settings); |
| 737 | } |
| 738 | Helper::display_password_form($client_id, $embed_content, $pass_hash_key, $embed_settings); |
| 739 | } |
| 740 | ?> |
| 741 | </div> |
| 742 | </div> |
| 743 | <?php |
| 744 | if (!empty($settings['adManager'])) { |
| 745 | $embed_content .= Helper::generateAdTemplate($client_id, $settings, 'elementor'); |
| 746 | } |
| 747 | ?> |
| 748 | </div> |
| 749 | </div> |
| 750 | |
| 751 | <?php |
| 752 | } |
| 753 | |
| 754 | |
| 755 | private function get_file_url() |
| 756 | { |
| 757 | $settings = $this->get_settings(); |
| 758 | $file_url = $settings['embedpress_document_type'] === 'url' ? esc_url($settings['embedpress_document_file_link']['url']) : esc_url($settings['embedpress_document_Uploader']['url']); |
| 759 | return $file_url; |
| 760 | } |
| 761 | |
| 762 | |
| 763 | protected function render_editor_script( $id, $url ) |
| 764 | { |
| 765 | ?> |
| 766 | <script> |
| 767 | (function ($) { |
| 768 | 'use strict'; |
| 769 | $(document).ready(function () { |
| 770 | var selector = $('.embedpress-embed-document-pdf'); |
| 771 | let option = { |
| 772 | forceObject: false, |
| 773 | }; |
| 774 | if (selector.length) { |
| 775 | PDFObject.embed("<?php echo $url; ?>", "<?php echo '.' . $id; ?>", option); |
| 776 | } |
| 777 | }); |
| 778 | })(jQuery); |
| 779 | </script> |
| 780 | <?php |
| 781 | } |
| 782 | } |
| 783 |