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_Pdf.php
740 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 EmbedPress\Includes\Classes\Helper; |
| 10 | use EmbedPress\Includes\Traits\Branding; |
| 11 | |
| 12 | |
| 13 | |
| 14 | (defined('ABSPATH')) or die("No direct script access allowed."); |
| 15 | |
| 16 | class Embedpress_Pdf extends Widget_Base |
| 17 | { |
| 18 | |
| 19 | use Branding; |
| 20 | protected $pro_class = ''; |
| 21 | protected $pro_text = ''; |
| 22 | public function get_name() |
| 23 | { |
| 24 | return 'embedpress_pdf'; |
| 25 | } |
| 26 | |
| 27 | public function get_title() |
| 28 | { |
| 29 | return esc_html__('EmbedPress PDF', 'embedpress'); |
| 30 | } |
| 31 | |
| 32 | public function get_categories() |
| 33 | { |
| 34 | return ['embedpress']; |
| 35 | } |
| 36 | |
| 37 | public function get_custom_help_url() |
| 38 | { |
| 39 | return 'https://embedpress.com/documentation'; |
| 40 | } |
| 41 | |
| 42 | public function get_icon() |
| 43 | { |
| 44 | return 'icon-pdf'; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Get widget keywords. |
| 49 | * |
| 50 | * Retrieve the list of keywords the widget belongs to. |
| 51 | * |
| 52 | * @return array Widget keywords. |
| 53 | * @since 2.5.5 |
| 54 | * @access public |
| 55 | * |
| 56 | */ |
| 57 | public function get_keywords() |
| 58 | { |
| 59 | return ['embedpress', 'pdf', 'doc', 'embedpress-document']; |
| 60 | } |
| 61 | |
| 62 | protected function register_controls() |
| 63 | { |
| 64 | $this->pro_class = is_embedpress_pro_active() ? '' : 'embedpress-pro-control not-active'; |
| 65 | $this->pro_text = is_embedpress_pro_active() ? '' : '<sup class="embedpress-pro-label" style="color:red">' . __('Pro', 'embedpress') . '</sup>'; |
| 66 | /** |
| 67 | * EmbedPress Content Settings |
| 68 | */ |
| 69 | $this->start_controls_section( |
| 70 | 'embedpress_content_settings', |
| 71 | [ |
| 72 | 'label' => esc_html__('General', 'embedpress'), |
| 73 | ] |
| 74 | ); |
| 75 | |
| 76 | $this->add_control( |
| 77 | 'embedpress_pdf_type', |
| 78 | [ |
| 79 | 'label' => __('Document Type', 'embedpress'), |
| 80 | 'type' => Controls_Manager::SELECT, |
| 81 | 'default' => 'file', |
| 82 | 'options' => [ |
| 83 | 'file' => __('File', 'embedpress'), |
| 84 | 'url' => __('URL', 'embedpress') |
| 85 | ], |
| 86 | ] |
| 87 | ); |
| 88 | |
| 89 | $this->add_control( |
| 90 | 'embedpress_pdf_Uploader', |
| 91 | [ |
| 92 | 'label' => __('Upload File', 'embedpress'), |
| 93 | 'type' => Controls_Manager::MEDIA, |
| 94 | 'dynamic' => [ |
| 95 | 'active' => true, |
| 96 | 'categories' => [ |
| 97 | TagsModule::MEDIA_CATEGORY, |
| 98 | ], |
| 99 | ], |
| 100 | 'media_type' => [ |
| 101 | 'application/pdf', |
| 102 | ], |
| 103 | 'description' => __( |
| 104 | 'Upload a file or pick one from your media library for embed. Supported File Type: PDF', |
| 105 | 'embedpress' |
| 106 | ), |
| 107 | 'condition' => [ |
| 108 | 'embedpress_pdf_type' => 'file' |
| 109 | ], |
| 110 | ] |
| 111 | ); |
| 112 | |
| 113 | $this->add_control( |
| 114 | 'embedpress_pdf_file_link', |
| 115 | [ |
| 116 | 'label' => __('URL', 'embedpress'), |
| 117 | 'type' => Controls_Manager::URL, |
| 118 | 'placeholder' => __('https://your-link.com/file.pdf', 'embedpress'), |
| 119 | 'dynamic' => [ |
| 120 | 'active' => true, |
| 121 | ], |
| 122 | 'show_external' => false, |
| 123 | 'dynamic' => [ |
| 124 | 'active' => true, |
| 125 | ], |
| 126 | 'default' => [ |
| 127 | 'url' => '' |
| 128 | ], |
| 129 | 'condition' => [ |
| 130 | 'embedpress_pdf_type' => 'url' |
| 131 | ], |
| 132 | ] |
| 133 | ); |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | $this->add_control( |
| 139 | 'embedpress_pdf_zoom', |
| 140 | [ |
| 141 | 'label' => __('Zoom', 'embedpress'), |
| 142 | 'type' => Controls_Manager::SELECT, |
| 143 | 'default' => 'auto', |
| 144 | 'options' => [ |
| 145 | 'auto' => __('Automatic Zoom', 'embedpress'), |
| 146 | 'page-actual' => __('Actual Size', 'embedpress'), |
| 147 | 'page-fit' => __('Page Fit', 'embedpress'), |
| 148 | 'page-width' => __('Page Width', 'embedpress'), |
| 149 | 'custom' => __('Custom', 'embedpress'), |
| 150 | '50' => __('50%', 'embedpress'), |
| 151 | '75' => __('75%', 'embedpress'), |
| 152 | '100' => __('100%', 'embedpress'), |
| 153 | '125' => __('125%', 'embedpress'), |
| 154 | '150' => __('150%', 'embedpress'), |
| 155 | '200' => __('200%', 'embedpress'), |
| 156 | '300' => __('300%', 'embedpress'), |
| 157 | '400' => __('400%', 'embedpress'), |
| 158 | ], |
| 159 | ] |
| 160 | ); |
| 161 | $this->add_control( |
| 162 | 'embedpress_pdf_zoom_custom', |
| 163 | [ |
| 164 | 'label' => __('Custom Zoom', 'embedpress'), |
| 165 | 'type' => Controls_Manager::NUMBER, |
| 166 | 'condition' => [ |
| 167 | 'embedpress_pdf_zoom' => 'custom' |
| 168 | ], |
| 169 | ] |
| 170 | ); |
| 171 | $this->add_responsive_control( |
| 172 | 'embedpress_elementor_document_width', |
| 173 | [ |
| 174 | 'type' => \Elementor\Controls_Manager::SLIDER, |
| 175 | 'label' => esc_html__( 'Width', 'embedpress' ), |
| 176 | 'size_units' => [ 'px', '%' ], |
| 177 | 'range' => [ |
| 178 | 'px' => [ |
| 179 | 'min' => 1, |
| 180 | 'max' => 1000, |
| 181 | ], |
| 182 | ], |
| 183 | 'devices' => [ 'desktop', 'tablet', 'mobile' ], |
| 184 | 'default' => [ |
| 185 | 'unit' => 'px', |
| 186 | 'size' => 600, |
| 187 | ], |
| 188 | 'desktop_default' => [ |
| 189 | 'unit' => 'px', |
| 190 | 'size' => 600, |
| 191 | ], |
| 192 | 'tablet_default' => [ |
| 193 | 'size' => 400, |
| 194 | 'unit' => 'px', |
| 195 | ], |
| 196 | 'mobile_default' => [ |
| 197 | 'size' => 300, |
| 198 | 'unit' => 'px', |
| 199 | ], |
| 200 | 'selectors' => [ |
| 201 | '{{WRAPPER}} .embedpress-document-embed iframe' => 'width: {{SIZE}}{{UNIT}}!important; max-width: {{SIZE}}{{UNIT}}!important', |
| 202 | // '{{WRAPPER}} .embedpress-document-embed' => 'width: {{SIZE}}{{UNIT}}; max-width: 100%', |
| 203 | // '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%', |
| 204 | ], |
| 205 | 'render_type' => 'template', |
| 206 | ] |
| 207 | ); |
| 208 | $this->add_responsive_control( |
| 209 | 'embedpress_elementor_document_height', |
| 210 | [ |
| 211 | 'type' => \Elementor\Controls_Manager::SLIDER, |
| 212 | 'label' => esc_html__( 'Height', 'embedpress' ), |
| 213 | 'range' => [ |
| 214 | 'px' => [ |
| 215 | 'min' => 1, |
| 216 | 'max' => 1000, |
| 217 | ], |
| 218 | ], |
| 219 | 'devices' => [ 'desktop', 'tablet', 'mobile' ], |
| 220 | 'default' => [ |
| 221 | 'unit' => 'px', |
| 222 | 'size' => 600, |
| 223 | ], |
| 224 | 'desktop_default' => [ |
| 225 | 'unit' => 'px', |
| 226 | 'size' => 600, |
| 227 | ], |
| 228 | 'tablet_default' => [ |
| 229 | 'size' => 400, |
| 230 | 'unit' => 'px', |
| 231 | ], |
| 232 | 'mobile_default' => [ |
| 233 | 'size' => 300, |
| 234 | 'unit' => 'px', |
| 235 | ], |
| 236 | 'selectors' => [ |
| 237 | '{{WRAPPER}} .embedpress-document-embed iframe' => 'height: {{SIZE}}{{UNIT}}!important;', |
| 238 | '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'height: {{SIZE}}{{UNIT}}!important;', |
| 239 | ], |
| 240 | 'render_type' => 'template', |
| 241 | ] |
| 242 | ); |
| 243 | |
| 244 | $this->add_responsive_control( |
| 245 | 'embedpress_elementor_document_align', |
| 246 | [ |
| 247 | 'label' => __('Alignment', 'embedpress'), |
| 248 | 'type' => Controls_Manager::CHOOSE, |
| 249 | 'options' => [ |
| 250 | 'left' => [ |
| 251 | 'title' => __('Left', 'embedpress'), |
| 252 | 'icon' => 'eicon-text-align-left', |
| 253 | ], |
| 254 | 'center' => [ |
| 255 | 'title' => __('Center', 'embedpress'), |
| 256 | 'icon' => 'eicon-text-align-center', |
| 257 | ], |
| 258 | 'right' => [ |
| 259 | 'title' => __('Right', 'embedpress'), |
| 260 | 'icon' => 'eicon-text-align-right', |
| 261 | ] |
| 262 | ], |
| 263 | 'prefix_class' => 'elementor%s-align-', |
| 264 | 'default' => '', |
| 265 | ] |
| 266 | ); |
| 267 | |
| 268 | $this->add_control( |
| 269 | 'embedpress_pdf_powered_by', |
| 270 | [ |
| 271 | 'label' => __('Powered By', 'embedpress'), |
| 272 | 'type' => Controls_Manager::SWITCHER, |
| 273 | 'label_on' => __('Show', 'embedpress'), |
| 274 | 'label_off' => __('Hide', 'embedpress'), |
| 275 | 'return_value' => 'yes', |
| 276 | 'default' => apply_filters('embedpress_document_powered_by_control', 'yes'), |
| 277 | ] |
| 278 | ); |
| 279 | |
| 280 | $this->init_branding_controls('document'); |
| 281 | |
| 282 | $this->end_controls_section(); |
| 283 | |
| 284 | |
| 285 | /** |
| 286 | * EmbedPress PDF Control Settings |
| 287 | */ |
| 288 | |
| 289 | $this->start_controls_section( |
| 290 | 'embedpress_pdf_content_settings', |
| 291 | [ |
| 292 | 'label' => esc_html__('Controls', 'embedpress'), |
| 293 | 'condition' => [ |
| 294 | 'embedpress_pdf_type' => 'file' |
| 295 | ], |
| 296 | ] |
| 297 | ); |
| 298 | |
| 299 | $this->add_control( |
| 300 | 'embedpress_theme_mode', |
| 301 | [ |
| 302 | 'label' => __('Theme', 'embedpress'), |
| 303 | 'type' => Controls_Manager::SELECT, |
| 304 | 'default' => 'default', |
| 305 | 'options' => [ |
| 306 | 'default' => __('System Default', 'embedpress'), |
| 307 | 'dark' => __('Dark', 'embedpress'), |
| 308 | 'light' => __('Light', 'embedpress'), |
| 309 | 'custom' => __('Custom', 'embedpress') |
| 310 | ], |
| 311 | ] |
| 312 | ); |
| 313 | |
| 314 | $this->add_control( |
| 315 | 'embedpress_pdf_custom_color', |
| 316 | [ |
| 317 | 'label' => esc_html__( 'Color', 'embedpress' ), |
| 318 | 'type' => \Elementor\Controls_Manager::COLOR, |
| 319 | 'condition' => [ |
| 320 | 'embedpress_theme_mode' => 'custom', |
| 321 | ], |
| 322 | ] |
| 323 | ); |
| 324 | |
| 325 | $this->add_control( |
| 326 | 'pdf_toolbar', |
| 327 | [ |
| 328 | 'label' => sprintf(__('Toolbar %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 | ] |
| 336 | ); |
| 337 | |
| 338 | |
| 339 | $this->add_control( |
| 340 | 'pdf_toolbar_position', |
| 341 | [ |
| 342 | 'label' => esc_html__('Toolbar Position', 'embedpress'), |
| 343 | 'type' => \Elementor\Controls_Manager::CHOOSE, |
| 344 | 'options' => [ |
| 345 | 'top' => [ |
| 346 | 'title' => esc_html__('Top', 'embedpress'), |
| 347 | 'icon' => 'eicon-arrow-up', |
| 348 | ], |
| 349 | 'bottom' => [ |
| 350 | 'title' => esc_html__('Bottom', 'embedpress'), |
| 351 | 'icon' => 'eicon-arrow-down', |
| 352 | ], |
| 353 | ], |
| 354 | 'default' => 'top', |
| 355 | 'toggle' => true, |
| 356 | 'condition' => [ |
| 357 | 'pdf_toolbar' => 'yes', |
| 358 | ], |
| 359 | ] |
| 360 | ); |
| 361 | |
| 362 | |
| 363 | $this->add_control( |
| 364 | 'pdf_presentation_mode', |
| 365 | [ |
| 366 | 'label' => __('PDF Presentation Mode', 'embedpress'), |
| 367 | 'type' => Controls_Manager::SWITCHER, |
| 368 | 'label_on' => __('Show', 'embedpress'), |
| 369 | 'label_off' => __('Hide', 'embedpress'), |
| 370 | 'return_value' => 'yes', |
| 371 | 'default' => 'yes', |
| 372 | 'condition' => [ |
| 373 | 'pdf_toolbar' => 'yes', |
| 374 | ], |
| 375 | ] |
| 376 | ); |
| 377 | |
| 378 | $this->add_control( |
| 379 | 'pdf_print_download', |
| 380 | [ |
| 381 | 'label' => sprintf(__('Print/Download %s', 'embedpress'), $this->pro_text), |
| 382 | 'type' => Controls_Manager::SWITCHER, |
| 383 | 'label_on' => __('Show', 'embedpress'), |
| 384 | 'label_off' => __('Hide', 'embedpress'), |
| 385 | 'return_value' => 'yes', |
| 386 | 'default' => 'yes', |
| 387 | 'classes' => $this->pro_class, |
| 388 | 'condition' => [ |
| 389 | 'pdf_toolbar' => 'yes', |
| 390 | ], |
| 391 | ] |
| 392 | ); |
| 393 | $this->add_control( |
| 394 | 'pdf_text_copy', |
| 395 | [ |
| 396 | 'label' => sprintf(__('Copy Text %s', 'embedpress'), $this->pro_text), |
| 397 | 'type' => Controls_Manager::SWITCHER, |
| 398 | 'label_on' => __('Show', 'embedpress'), |
| 399 | 'label_off' => __('Hide', 'embedpress'), |
| 400 | 'return_value' => 'yes', |
| 401 | 'default' => 'yes', |
| 402 | 'classes' => $this->pro_class, |
| 403 | 'condition' => [ |
| 404 | 'pdf_toolbar' => 'yes', |
| 405 | ], |
| 406 | ] |
| 407 | ); |
| 408 | |
| 409 | $this->add_control( |
| 410 | 'add_text', |
| 411 | [ |
| 412 | 'label' => sprintf(__('Add Text', 'embedpress')), |
| 413 | 'type' => Controls_Manager::SWITCHER, |
| 414 | 'label_on' => __('Show', 'embedpress'), |
| 415 | 'label_off' => __('Hide', 'embedpress'), |
| 416 | 'return_value' => 'yes', |
| 417 | 'default' => 'yes', |
| 418 | 'condition' => [ |
| 419 | 'pdf_toolbar' => 'yes', |
| 420 | ], |
| 421 | ] |
| 422 | ); |
| 423 | $this->add_control( |
| 424 | 'draw', |
| 425 | [ |
| 426 | 'label' => sprintf(__('Draw %s', 'embedpress'), $this->pro_text), |
| 427 | 'type' => Controls_Manager::SWITCHER, |
| 428 | 'label_on' => __('Show', 'embedpress'), |
| 429 | 'label_off' => __('Hide', 'embedpress'), |
| 430 | 'return_value' => 'yes', |
| 431 | 'default' => 'yes', |
| 432 | 'classes' => $this->pro_class, |
| 433 | 'condition' => [ |
| 434 | 'pdf_toolbar' => 'yes', |
| 435 | ], |
| 436 | ] |
| 437 | ); |
| 438 | |
| 439 | $this->add_control( |
| 440 | 'pdf_rotate_access', |
| 441 | [ |
| 442 | 'label' => __('Rotation', 'embedpress'), |
| 443 | 'type' => Controls_Manager::SWITCHER, |
| 444 | 'label_on' => __('Show', 'embedpress'), |
| 445 | 'label_off' => __('Hide', 'embedpress'), |
| 446 | 'return_value' => 'yes', |
| 447 | 'default' => 'yes', |
| 448 | 'condition' => [ |
| 449 | 'pdf_toolbar' => 'yes', |
| 450 | ], |
| 451 | ] |
| 452 | ); |
| 453 | |
| 454 | $this->add_control( |
| 455 | 'pdf_details', |
| 456 | [ |
| 457 | 'label' => __('Properties', 'embedpress'), |
| 458 | 'type' => Controls_Manager::SWITCHER, |
| 459 | 'label_on' => __('Show', 'embedpress'), |
| 460 | 'label_off' => __('Hide', 'embedpress'), |
| 461 | 'return_value' => 'yes', |
| 462 | 'default' => 'yes', |
| 463 | 'condition' => [ |
| 464 | 'pdf_toolbar' => 'yes', |
| 465 | ], |
| 466 | ] |
| 467 | ); |
| 468 | |
| 469 | $this->end_controls_section(); |
| 470 | |
| 471 | do_action( 'extend_elementor_controls', $this, '_pdf_', $this->pro_text, $this->pro_class); |
| 472 | |
| 473 | if (!is_embedpress_pro_active()) { |
| 474 | $this->start_controls_section( |
| 475 | 'embedpress_pro_section', |
| 476 | [ |
| 477 | 'label' => __('Go Premium for More Features', 'embedpress'), |
| 478 | ] |
| 479 | ); |
| 480 | |
| 481 | $this->add_control( |
| 482 | 'embedpress_pro_cta', |
| 483 | [ |
| 484 | 'label' => __('Unlock more possibilities', 'embedpress'), |
| 485 | 'type' => Controls_Manager::CHOOSE, |
| 486 | 'options' => [ |
| 487 | '1' => [ |
| 488 | 'title' => '', |
| 489 | 'icon' => 'eicon-lock', |
| 490 | ], |
| 491 | ], |
| 492 | 'default' => '1', |
| 493 | '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>', |
| 494 | ] |
| 495 | ); |
| 496 | |
| 497 | $this->end_controls_section(); |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | private function is_pdf($url) |
| 502 | { |
| 503 | $arr = explode('.', $url); |
| 504 | return end($arr) === 'pdf'; |
| 505 | } |
| 506 | |
| 507 | public function render() |
| 508 | { |
| 509 | $settings = $this->get_settings(); |
| 510 | |
| 511 | $url = $this->get_file_url(); |
| 512 | |
| 513 | if($settings['embedpress_pdf_type'] === 'url') { |
| 514 | if(class_exists( 'ACF' ) && function_exists('get_field')){ |
| 515 | if(!empty($settings['__dynamic__']) && !empty($settings['__dynamic__']['embedpress_pdf_file_link'])){ |
| 516 | $decode_url = urldecode(($settings['__dynamic__']['embedpress_pdf_file_link'])); |
| 517 | |
| 518 | preg_match('/"key":"([^"]+):([^"]+)"/', $decode_url, $matches); |
| 519 | if (isset($matches[0])) { |
| 520 | if (isset($matches[1])) { |
| 521 | $get_acf_key = $matches[1]; |
| 522 | $url = get_field($get_acf_key); |
| 523 | |
| 524 | if(empty($url)){ |
| 525 | $pattern = '/"fallback":"([^"]+)"/'; |
| 526 | preg_match($pattern, $decode_url, $matches); |
| 527 | |
| 528 | if (isset($matches[1])) { |
| 529 | $url = $matches[1]; |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | } |
| 534 | } |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | $client_id = $this->get_id(); |
| 539 | |
| 540 | $this->_render($url, $settings, $client_id); |
| 541 | Helper::get_source_data(md5($this->get_id()).'_eb_elementor', $url, 'elementor_source_data', 'elementor_temp_source_data'); |
| 542 | } |
| 543 | |
| 544 | public function getParamData($settings){ |
| 545 | $urlParamData = array( |
| 546 | 'themeMode' => $settings['embedpress_theme_mode'], |
| 547 | 'toolbar' => !empty($settings['pdf_toolbar']) ? 'true' : 'false', |
| 548 | 'position' => $settings['pdf_toolbar_position'], |
| 549 | 'presentation' => !empty($settings['pdf_presentation_mode']) ? 'true' : 'false', |
| 550 | 'download' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['pdf_print_download'] : 'true', |
| 551 | 'copy_text' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['pdf_text_copy'] : 'true', |
| 552 | 'add_text' => !empty($settings['add_text']) ? 'true' : 'false', |
| 553 | 'draw' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['draw'] : 'true', |
| 554 | 'pdf_rotation' => !empty($settings['pdf_rotate_access']) ? 'true' : 'false', |
| 555 | 'pdf_details' => !empty($settings['pdf_details']) ? 'true' : 'false', |
| 556 | ); |
| 557 | |
| 558 | if($settings['embedpress_theme_mode'] == 'custom') { |
| 559 | $urlParamData['customColor'] = $settings['embedpress_pdf_custom_color']; |
| 560 | } |
| 561 | |
| 562 | if($settings['embedpress_pdf_type'] == 'file'){ |
| 563 | return "#key=" . base64_encode(utf8_encode(http_build_query($urlParamData))); |
| 564 | } |
| 565 | return ''; |
| 566 | |
| 567 | } |
| 568 | |
| 569 | public function _render($url, $settings, $id) |
| 570 | { |
| 571 | $unitoption = 'emebedpress-unit-px'; |
| 572 | if($settings['embedpress_elementor_document_width']['unit'] === '%'){ |
| 573 | $unitoption = 'emebedpress-unit-percent'; |
| 574 | } |
| 575 | $client_id = $id; |
| 576 | $id = 'embedpress-pdf-' . $id; |
| 577 | $hash_pass = hash('sha256', wp_salt(32) . md5($settings['embedpress_pdf_lock_content_password'])); |
| 578 | |
| 579 | $dimension = ''; |
| 580 | |
| 581 | $password_correct = isset($_COOKIE['password_correct_'.$client_id]) ? $_COOKIE['password_correct_'.$client_id] : ''; |
| 582 | |
| 583 | if(empty($settings['embedpress_pdf_lock_content']) || empty($settings['embedpress_pdf_lock_content_password']) || (!empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct))){ |
| 584 | $dimension = "width: {$settings['embedpress_elementor_document_width']['size']}{$settings['embedpress_elementor_document_width']['unit']}!important;height: {$settings['embedpress_elementor_document_height']['size']}px;"; |
| 585 | } |
| 586 | |
| 587 | $content_protection_class = 'ep-content-protection-enabled'; |
| 588 | $content_locked_class = 'ep-content-locked'; |
| 589 | if(empty($settings['embedpress_pdf_lock_content']) || empty($settings['embedpress_pdf_lock_content_password']) || $hash_pass === $password_correct) { |
| 590 | $content_locked_class = ''; |
| 591 | $content_protection_class = 'ep-content-protection-disabled'; |
| 592 | } |
| 593 | |
| 594 | $pass_hash_key = md5($settings['embedpress_pdf_lock_content_password']); |
| 595 | $this->add_render_attribute('embedpres-pdf-render', [ |
| 596 | 'class' => ['embedpress-embed-document-pdf', $id], |
| 597 | 'data-emid' => $id |
| 598 | ]); |
| 599 | $this->add_render_attribute('embedpress-document', [ |
| 600 | 'class' => ['embedpress-document-embed', 'ep-doc-' . md5($id), 'ose-document', $unitoption, $content_locked_class ], |
| 601 | 'data-thememode' => $settings['embedpress_theme_mode'], |
| 602 | 'data-customcolor' => $settings['embedpress_pdf_custom_color'], |
| 603 | 'data-toolbar' => $settings['pdf_toolbar'], |
| 604 | 'data-toolbar-position' => $settings['pdf_toolbar_position'], |
| 605 | 'data-open' => 'no', |
| 606 | 'data-presentation-mode' => $settings['pdf_presentation_mode'], |
| 607 | 'data-download' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['pdf_print_download'] : 'yes', |
| 608 | 'data-copy' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['pdf_text_copy'] : 'yes', |
| 609 | 'data-rotate' => $settings['pdf_rotate_access'], |
| 610 | 'data-details' => $settings['pdf_details'], |
| 611 | 'data-id' => $id |
| 612 | ]); |
| 613 | |
| 614 | $embed_settings = []; |
| 615 | $embed_settings['customThumbnail'] = !empty($settings['embedpress_pdf_content_share_custom_thumbnail']['url']) ? $settings['embedpress_pdf_content_share_custom_thumbnail']['url'] : ''; |
| 616 | |
| 617 | $embed_settings['customTitle'] = !empty($settings['embedpress_pdf_content_title']) ? $settings['embedpress_pdf_content_title'] : Helper::get_file_title($url); |
| 618 | |
| 619 | $embed_settings['customDescription'] = !empty($settings['embedpress_pdf_content_descripiton']) ? $settings['embedpress_pdf_content_descripiton'] : Helper::get_file_title($url); |
| 620 | |
| 621 | $embed_settings['sharePosition'] = !empty($settings['embedpress_pdf_content_share_position']) ? $settings['embedpress_pdf_content_share_position'] : 'right'; |
| 622 | |
| 623 | $embed_settings['lockHeading'] = !empty($settings['embedpress_pdf_lock_content_heading']) ? $settings['embedpress_pdf_lock_content_heading'] : ''; |
| 624 | |
| 625 | $embed_settings['lockSubHeading'] = !empty($settings['embedpress_pdf_lock_content_sub_heading']) ? $settings['embedpress_pdf_lock_content_sub_heading'] : ''; |
| 626 | |
| 627 | $embed_settings['lockErrorMessage'] = !empty($settings['embedpress_pdf_lock_content_error_message']) ? $settings['embedpress_pdf_lock_content_error_message'] : ''; |
| 628 | |
| 629 | $embed_settings['passwordPlaceholder'] = !empty($settings['embedpress_pdf_password_placeholder']) ? $settings['embedpress_pdf_password_placeholder'] : ''; |
| 630 | |
| 631 | $embed_settings['submitButtonText'] = !empty($settings['embedpress_pdf_submit_button_text']) ? $settings['embedpress_pdf_submit_button_text'] : ''; |
| 632 | |
| 633 | $embed_settings['submitUnlockingText'] = !empty($settings['embedpress_pdf_submit_Unlocking_text']) ? $settings['embedpress_pdf_submit_Unlocking_text'] : ''; |
| 634 | |
| 635 | $embed_settings['enableFooterMessage'] = !empty($settings['embedpress_pdf_enable_footer_message']) ? $settings['embedpress_pdf_enable_footer_message'] : ''; |
| 636 | |
| 637 | $embed_settings['footerMessage'] = !empty($settings['embedpress_pdf_lock_content_footer_message']) ? $settings['embedpress_pdf_lock_content_footer_message'] : ''; |
| 638 | |
| 639 | |
| 640 | if($settings['embedpress_elementor_document_width']['unit'] === '%'){ |
| 641 | $width_class = ' ep-percentage-width'; |
| 642 | } |
| 643 | else{ |
| 644 | $width_class = 'ep-fixed-width'; |
| 645 | } |
| 646 | $content_share_class = ''; |
| 647 | $share_position_class = ''; |
| 648 | $share_position = isset($settings['embedpress_pdf_content_share_position']) ? $settings['embedpress_pdf_content_share_position'] : 'right'; |
| 649 | |
| 650 | if(!empty($settings['embedpress_pdf_content_share'])) { |
| 651 | $content_share_class = 'ep-content-share-enabled'; |
| 652 | $share_position_class = 'ep-share-position-'.$share_position; |
| 653 | } |
| 654 | |
| 655 | ?> |
| 656 | <div <?php echo $this->get_render_attribute_string('embedpress-document'); ?> style=" max-width:100%; display: inline-block"> |
| 657 | |
| 658 | <?php |
| 659 | do_action('embedpress_pdf_after_embed', $settings, $url, $id, $this); |
| 660 | |
| 661 | if ($url != '') { |
| 662 | if ($this->is_pdf($url) && !$this->is_external_url($url)) { |
| 663 | $this->add_render_attribute('embedpres-pdf-render', $url); |
| 664 | $renderer = Helper::get_pdf_renderer(); |
| 665 | $src = $renderer . ((strpos($renderer, '?') == false) ? '?' : '&') . 'file=' . urlencode($url).$this->getParamData($settings); |
| 666 | if (!empty($settings['embedpress_pdf_zoom'])) { |
| 667 | $zoom = $settings['embedpress_pdf_zoom']; |
| 668 | if ($zoom == 'custom') { |
| 669 | if (!empty($settings['embedpress_pdf_zoom_custom'])) { |
| 670 | $zoom = $settings['embedpress_pdf_zoom_custom']; |
| 671 | } else { |
| 672 | $zoom = null; |
| 673 | } |
| 674 | } |
| 675 | if ($zoom) { |
| 676 | $src = $src . "&zoom=$zoom"; |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | $embed_content = '<iframe title="'.esc_attr(Helper::get_file_title($url)).'" class="embedpress-embed-document-pdf '.esc_attr($id).'" style="'.esc_attr($dimension).'; max-width:100%; display: inline-block" src="'.esc_attr($src).'"'; |
| 681 | $embed_content .= ' '.$this->get_render_attribute_string('embedpres-pdf-render').' frameborder="0"></iframe>'; |
| 682 | if ($settings['embedpress_pdf_powered_by'] === 'yes') { |
| 683 | $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress')); |
| 684 | } |
| 685 | |
| 686 | } else { |
| 687 | $embed_content = '<iframe title="'.esc_attr(Helper::get_file_title($url)).'" class="embedpress-embed-document-pdf '.esc_attr($id).'" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" style="'.esc_attr($dimension).'; max-width:100%;" src="'.esc_url($url).'"'; |
| 688 | $embed_content .= ' '.$this->get_render_attribute_string('embedpres-pdf-render').'></iframe>'; |
| 689 | |
| 690 | if ($settings['embedpress_pdf_powered_by'] === 'yes') { |
| 691 | $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress')); |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | ?> |
| 696 | |
| 697 | |
| 698 | <div id="ep-elementor-content-<?php echo esc_attr( $client_id )?>" class="ep-elementor-content <?php if(!empty($settings['embedpress_pdf_content_share'])) : echo esc_attr( 'position-'.$settings['embedpress_pdf_content_share_position'].'-wraper' ); endif; ?> <?php echo esc_attr($width_class.' '.$content_share_class.' '.$share_position_class.' '.$content_protection_class); ?>"> |
| 699 | <div id="<?php echo esc_attr( $this->get_id() ); ?>" class="ep-embed-content-wraper"> |
| 700 | <?php |
| 701 | $embed = '<div>'.$embed_content.'</div>'; |
| 702 | |
| 703 | $content_id = $client_id; |
| 704 | if((empty($settings['embedpress_pdf_lock_content']) || empty($settings['embedpress_pdf_lock_content_password']) || $settings['embedpress_pdf_lock_content'] == 'no') || (!empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct)) ){ |
| 705 | if(!empty($settings['embedpress_pdf_content_share'])){ |
| 706 | $embed .= Helper::embed_content_share($content_id, $embed_settings); |
| 707 | } |
| 708 | echo $embed ; |
| 709 | |
| 710 | } else { |
| 711 | if(!empty($settings['embedpress_pdf_content_share'])){ |
| 712 | $embed .= Helper::embed_content_share($content_id, $embed_settings); |
| 713 | } |
| 714 | Helper::display_password_form($client_id, $embed, $pass_hash_key, $embed_settings); |
| 715 | } |
| 716 | ?> |
| 717 | </div> |
| 718 | </div> |
| 719 | <?php |
| 720 | |
| 721 | } |
| 722 | ?> |
| 723 | |
| 724 | </div> |
| 725 | |
| 726 | <?php |
| 727 | } |
| 728 | |
| 729 | private function get_file_url() |
| 730 | { |
| 731 | $settings = $this->get_settings(); |
| 732 | return $settings['embedpress_pdf_type'] === 'url' ? $settings['embedpress_pdf_file_link']['url'] : $settings['embedpress_pdf_Uploader']['url']; |
| 733 | } |
| 734 | |
| 735 | protected function is_external_url($url) |
| 736 | { |
| 737 | return strpos($url, get_site_url()) === false; |
| 738 | } |
| 739 | } |
| 740 |