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