PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 4.0.5
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v4.0.5
4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / EmbedPress / Elementor / Widgets / Embedpress_Pdf.php
embedpress / EmbedPress / Elementor / Widgets Last commit date
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_Pdf.php
961 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 public function get_style_depends()
48 {
49 return [
50 'embedpress-elementor-css',
51 'embedpress-style',
52 ];
53 }
54
55 public function get_script_depends()
56 {
57
58 $handler_keys = get_option('enabled_elementor_scripts', []);
59
60 $handles = [];
61
62 $handles[] = 'embedpress-pdfobject';
63 $handles[] = 'embedpress-front';
64
65 if (isset($handler_keys['enabled_ads']) && $handler_keys['enabled_ads'] === 'yes') {
66 $handles[] = 'embedpress-ads';
67 }
68
69 return $handles;
70 }
71
72 /**
73 * Get widget keywords.
74 *
75 * Retrieve the list of keywords the widget belongs to.
76 *
77 * @return array Widget keywords.
78 * @since 2.5.5
79 * @access public
80 *
81 */
82 public function get_keywords()
83 {
84 return ['embedpress', 'pdf', 'doc', 'embedpress-document'];
85 }
86
87 protected function register_controls()
88 {
89 $this->pro_class = is_embedpress_pro_active() ? '' : 'embedpress-pro-control not-active';
90 $this->pro_text = is_embedpress_pro_active() ? '' : '<sup class="embedpress-pro-label" style="color:red">' . __('Pro', 'embedpress') . '</sup>';
91 /**
92 * EmbedPress Content Settings
93 */
94 $this->start_controls_section(
95 'embedpress_content_settings',
96 [
97 'label' => esc_html__('General', 'embedpress'),
98 ]
99 );
100
101 $this->add_control(
102 'embedpress_pdf_type',
103 [
104 'label' => __('Document Type', 'embedpress'),
105 'type' => Controls_Manager::SELECT,
106 'default' => 'file',
107 'options' => [
108 'file' => __('File', 'embedpress'),
109 'url' => __('URL', 'embedpress')
110 ],
111 ]
112 );
113
114 $this->add_control(
115 'embedpress_pdf_file_link_from',
116 [
117 'label' => __( 'URL From', 'embedpress' ),
118 'type' => Controls_Manager::SELECT,
119 'default' => 'external',
120 'options' => [
121 'self' => __( 'Self', 'embedpress' ),
122 'external' => __( 'External', 'embedpress' )
123 ],
124 'condition' => [
125 'embedpress_pdf_type' => 'url'
126 ]
127 ]
128 );
129
130 $this->add_control(
131 'embedpress_pdf_Uploader',
132 [
133 'label' => __('Upload File', 'embedpress'),
134 'type' => Controls_Manager::MEDIA,
135 'dynamic' => [
136 'active' => true,
137 'categories' => [
138 TagsModule::MEDIA_CATEGORY,
139 ],
140 ],
141 'media_type' => [
142 'application/pdf',
143 ],
144 'description' => __(
145 'Upload a file or pick one from your media library for embed. Supported File Type: PDF',
146 'embedpress'
147 ),
148 'condition' => [
149 'embedpress_pdf_type' => 'file'
150 ],
151 ]
152 );
153
154 $this->add_control(
155 'embedpress_pdf_file_link',
156 [
157 'label' => __('URL', 'embedpress'),
158 'type' => Controls_Manager::URL,
159 'placeholder' => __('https://your-link.com/file.pdf', 'embedpress'),
160 'dynamic' => [
161 'active' => true,
162 ],
163 'show_external' => false,
164 'dynamic' => [
165 'active' => true,
166 ],
167 'default' => [
168 'url' => ''
169 ],
170 'condition' => [
171 'embedpress_pdf_type' => 'url'
172 ],
173 ]
174 );
175
176
177 $this->add_control(
178 'embedpress_pdf_viewer_style',
179 [
180 'label' => __('Viewer Style', 'embedpress'),
181 'type' => Controls_Manager::SELECT,
182 'default' => 'modern',
183 'options' => [
184 'modern' => __('Modern', 'embedpress'),
185 'flip-book' => __('Flip Book', 'embedpress'),
186 ],
187 'conditions' => [
188 'relation' => 'or',
189 'terms' => [
190 ['name' => 'embedpress_pdf_type', 'operator' => '===', 'value' => 'file'],
191 ['name' => 'embedpress_pdf_file_link_from', 'operator' => '===', 'value' => 'self'],
192 ],
193 ],
194 ]
195 );
196
197 $this->add_control(
198 'embedpress_pdf_zoom',
199 [
200 'label' => __('Zoom', 'embedpress'),
201 'type' => Controls_Manager::SELECT,
202 'default' => 'auto',
203 'options' => [
204 'auto' => __('Automatic Zoom', 'embedpress'),
205 'page-actual' => __('Actual Size', 'embedpress'),
206 'page-fit' => __('Page Fit', 'embedpress'),
207 'page-width' => __('Page Width', 'embedpress'),
208 'custom' => __('Custom', 'embedpress'),
209 '50' => __('50%', 'embedpress'),
210 '75' => __('75%', 'embedpress'),
211 '100' => __('100%', 'embedpress'),
212 '125' => __('125%', 'embedpress'),
213 '150' => __('150%', 'embedpress'),
214 '200' => __('200%', 'embedpress'),
215 '300' => __('300%', 'embedpress'),
216 '400' => __('400%', 'embedpress'),
217 ],
218 'condition' => [
219 'embedpress_pdf_viewer_style' => 'modern'
220 ]
221 ]
222 );
223 $this->add_control(
224 'embedpress_pdf_zoom_custom',
225 [
226 'label' => __('Custom Zoom', 'embedpress'),
227 'type' => Controls_Manager::NUMBER,
228 'condition' => [
229 'embedpress_pdf_zoom' => 'custom'
230 ],
231 ]
232 );
233 $this->add_responsive_control(
234 'embedpress_elementor_document_width',
235 [
236 'type' => \Elementor\Controls_Manager::SLIDER,
237 'label' => esc_html__( 'Width', 'embedpress' ),
238 'size_units' => [ 'px', '%' ],
239 'range' => [
240 'px' => [
241 'min' => 1,
242 'max' => 1500,
243 ],
244 ],
245 'devices' => [ 'desktop', 'tablet', 'mobile' ],
246 'default' => [
247 'unit' => '%',
248 'size' => 100,
249 ],
250 'desktop_default' => [
251 'unit' => 'px',
252 'size' => 600,
253 ],
254 'tablet_default' => [
255 'size' => 400,
256 'unit' => 'px',
257 ],
258 'mobile_default' => [
259 'size' => 300,
260 'unit' => 'px',
261 ],
262 'selectors' => [
263 '{{WRAPPER}} .embedpress-document-embed iframe, , {{WRAPPER}} .ep-share-position-bottom .ep-embed-content-wraper' => 'width: {{SIZE}}{{UNIT}}!important; max-width: {{SIZE}}{{UNIT}}!important',
264 // '{{WRAPPER}} .embedpress-document-embed' => 'width: {{SIZE}}{{UNIT}}; max-width: 100%',
265 // '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%',
266 ],
267 'render_type' => 'template',
268 ]
269 );
270 $this->add_responsive_control(
271 'embedpress_elementor_document_height',
272 [
273 'type' => \Elementor\Controls_Manager::SLIDER,
274 'label' => esc_html__( 'Height', 'embedpress' ),
275 'range' => [
276 'px' => [
277 'min' => 1,
278 'max' => 1000,
279 ],
280 ],
281 'devices' => [ 'desktop', 'tablet', 'mobile' ],
282 'default' => [
283 'unit' => 'px',
284 'size' => Helper::get_options_value('enableEmbedResizeHeight'),
285 ],
286 'desktop_default' => [
287 'unit' => 'px',
288 'size' => 600,
289 ],
290 'tablet_default' => [
291 'size' => 400,
292 'unit' => 'px',
293 ],
294 'mobile_default' => [
295 'size' => 300,
296 'unit' => 'px',
297 ],
298 'selectors' => [
299 '{{WRAPPER}} .embedpress-document-embed iframe' => 'height: {{SIZE}}{{UNIT}}!important;',
300 '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'height: {{SIZE}}{{UNIT}}!important;',
301 ],
302 'render_type' => 'template',
303 ]
304 );
305
306 $this->add_responsive_control(
307 'embedpress_elementor_document_align',
308 [
309 'label' => __('Alignment', 'embedpress'),
310 'type' => Controls_Manager::CHOOSE,
311 'options' => [
312 'left' => [
313 'title' => __('Left', 'embedpress'),
314 'icon' => 'eicon-text-align-left',
315 ],
316 'center' => [
317 'title' => __('Center', 'embedpress'),
318 'icon' => 'eicon-text-align-center',
319 ],
320 'right' => [
321 'title' => __('Right', 'embedpress'),
322 'icon' => 'eicon-text-align-right',
323 ]
324 ],
325 'prefix_class' => 'elementor%s-align-',
326 'default' => '',
327 ]
328 );
329
330 $this->add_control(
331 'embedpress_pdf_powered_by',
332 [
333 'label' => __('Powered By', 'embedpress'),
334 'type' => Controls_Manager::SWITCHER,
335 'label_on' => __('Show', 'embedpress'),
336 'label_off' => __('Hide', 'embedpress'),
337 'return_value' => 'yes',
338 'default' => apply_filters('embedpress_document_powered_by_control', 'yes'),
339 ]
340 );
341
342 $this->init_branding_controls('document');
343
344 $this->end_controls_section();
345
346
347 /**
348 * EmbedPress PDF Control Settings
349 */
350
351 $this->start_controls_section(
352 'embedpress_pdf_content_settings',
353 [
354 'label' => esc_html__('Controls', 'embedpress'),
355 'conditions' => [
356 'relation' => 'or',
357 'terms' => [
358 ['name' => 'embedpress_pdf_type', 'operator' => '===', 'value' => 'file'],
359 ['name' => 'embedpress_pdf_file_link_from', 'operator' => '===', 'value' => 'self'],
360 ],
361 ],
362 ]
363 );
364
365
366 $this->add_control(
367 'embedpress_theme_mode',
368 [
369 'label' => __('Theme', 'embedpress'),
370 'type' => Controls_Manager::SELECT,
371 'default' => 'default',
372 'options' => [
373 'default' => __('System Default', 'embedpress'),
374 'dark' => __('Dark', 'embedpress'),
375 'light' => __('Light', 'embedpress'),
376 'custom' => __('Custom', 'embedpress')
377 ],
378 ]
379 );
380
381 $this->add_control(
382 'embedpress_pdf_custom_color',
383 [
384 'label' => esc_html__( 'Color', 'embedpress' ),
385 'type' => \Elementor\Controls_Manager::COLOR,
386 'default' => Helper::get_options_value('custom_color'),
387 'condition' => [
388 'embedpress_theme_mode' => 'custom',
389 ],
390 ]
391 );
392
393 $this->add_control(
394 'pdf_toolbar',
395 [
396 'label' => sprintf(__('Toolbar %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 ]
404 );
405
406
407 $this->add_control(
408 'pdf_toolbar_position',
409 [
410 'label' => esc_html__('Toolbar Position', 'embedpress'),
411 'type' => \Elementor\Controls_Manager::CHOOSE,
412 'options' => [
413 'top' => [
414 'title' => esc_html__('Top', 'embedpress'),
415 'icon' => 'eicon-arrow-up',
416 ],
417 'bottom' => [
418 'title' => esc_html__('Bottom', 'embedpress'),
419 'icon' => 'eicon-arrow-down',
420 ],
421 ],
422 'default' => 'top',
423 'toggle' => true,
424 'condition' => [
425 'pdf_toolbar' => 'yes',
426 'embedpress_pdf_viewer_style' => 'modern',
427 ],
428 ]
429 );
430 $this->add_control(
431 'flipbook_toolbar_position',
432 [
433 'label' => esc_html__('Toolbar Position', 'embedpress'),
434 'type' => \Elementor\Controls_Manager::CHOOSE,
435 'options' => [
436 'top' => [
437 'title' => esc_html__('Top', 'embedpress'),
438 'icon' => 'eicon-arrow-up',
439 ],
440 'bottom' => [
441 'title' => esc_html__('Bottom', 'embedpress'),
442 'icon' => 'eicon-arrow-down',
443 ],
444 ],
445 'default' => 'bottom',
446 'toggle' => true,
447 'condition' => [
448 'pdf_toolbar' => 'yes',
449 'embedpress_pdf_viewer_style' => 'flip-book',
450 ],
451 ]
452 );
453
454
455 $this->add_control(
456 'pdf_print_download',
457 [
458 'label' => sprintf(__('Print/Download %s', 'embedpress'), $this->pro_text),
459 'type' => Controls_Manager::SWITCHER,
460 'label_on' => __('Show', 'embedpress'),
461 'label_off' => __('Hide', 'embedpress'),
462 'return_value' => 'yes',
463 'default' => 'yes',
464 'classes' => $this->pro_class,
465 'condition' => [
466 'pdf_toolbar' => 'yes',
467 ],
468 ]
469 );
470
471
472
473 $this->add_control(
474 'pdf_zoom_in',
475 [
476 'label' => __('Zoom In', 'embedpress'),
477 'type' => Controls_Manager::SWITCHER,
478 'label_on' => __('Show', 'embedpress'),
479 'label_off' => __('Hide', 'embedpress'),
480 'return_value' => 'yes',
481 'default' => 'yes',
482 'condition' => [
483 'pdf_toolbar' => 'yes',
484 'embedpress_pdf_viewer_style' => 'flip-book',
485 ],
486 ]
487 );
488 $this->add_control(
489 'pdf_zoom_out',
490 [
491 'label' => __('Zoom Out', 'embedpress'),
492 'type' => Controls_Manager::SWITCHER,
493 'label_on' => __('Show', 'embedpress'),
494 'label_off' => __('Hide', 'embedpress'),
495 'return_value' => 'yes',
496 'default' => 'yes',
497 'condition' => [
498 'pdf_toolbar' => 'yes',
499 'embedpress_pdf_viewer_style' => 'flip-book',
500 ],
501 ]
502 );
503 $this->add_control(
504 'pdf_fit_view',
505 [
506 'label' => __('Fit View', 'embedpress'),
507 'type' => Controls_Manager::SWITCHER,
508 'label_on' => __('Show', 'embedpress'),
509 'label_off' => __('Hide', 'embedpress'),
510 'return_value' => 'yes',
511 'default' => 'yes',
512 'condition' => [
513 'pdf_toolbar' => 'yes',
514 'embedpress_pdf_viewer_style' => 'flip-book',
515 ],
516 ]
517 );
518 $this->add_control(
519 'pdf_bookmark',
520 [
521 'label' => __('Bookmark', 'embedpress'),
522 'type' => Controls_Manager::SWITCHER,
523 'label_on' => __('Show', 'embedpress'),
524 'label_off' => __('Hide', 'embedpress'),
525 'return_value' => 'yes',
526 'default' => 'yes',
527 'condition' => [
528 'pdf_toolbar' => 'yes',
529 'embedpress_pdf_viewer_style' => 'flip-book',
530 ],
531 ]
532 );
533
534
535 $this->add_control(
536 'pdf_presentation_mode',
537 [
538 'label' => __('PDF Presentation Mode', 'embedpress'),
539 'type' => Controls_Manager::SWITCHER,
540 'label_on' => __('Show', 'embedpress'),
541 'label_off' => __('Hide', 'embedpress'),
542 'return_value' => 'yes',
543 'default' => 'yes',
544 'condition' => [
545 'pdf_toolbar' => 'yes',
546 ],
547 ]
548 );
549
550 $this->add_control(
551 'pdf_text_copy',
552 [
553 'label' => sprintf(__('Copy Text %s', 'embedpress'), $this->pro_text),
554 'type' => Controls_Manager::SWITCHER,
555 'label_on' => __('Show', 'embedpress'),
556 'label_off' => __('Hide', 'embedpress'),
557 'return_value' => 'yes',
558 'default' => 'yes',
559 'classes' => $this->pro_class,
560 'condition' => [
561 'pdf_toolbar' => 'yes',
562 'embedpress_pdf_viewer_style' => 'modern',
563 ],
564 ]
565 );
566
567 $this->add_control(
568 'add_text',
569 [
570 'label' => sprintf(__('Add Text', 'embedpress')),
571 'type' => Controls_Manager::SWITCHER,
572 'label_on' => __('Show', 'embedpress'),
573 'label_off' => __('Hide', 'embedpress'),
574 'return_value' => 'yes',
575 'default' => 'yes',
576 'condition' => [
577 'pdf_toolbar' => 'yes',
578 'embedpress_pdf_viewer_style' => 'modern',
579 ],
580 ]
581 );
582 $this->add_control(
583 'draw',
584 [
585 'label' => sprintf(__('Draw %s', 'embedpress'), $this->pro_text),
586 'type' => Controls_Manager::SWITCHER,
587 'label_on' => __('Show', 'embedpress'),
588 'label_off' => __('Hide', 'embedpress'),
589 'return_value' => 'yes',
590 'default' => 'yes',
591 'classes' => $this->pro_class,
592 'condition' => [
593 'pdf_toolbar' => 'yes',
594 'embedpress_pdf_viewer_style' => 'modern',
595 ],
596 ]
597 );
598
599 $this->add_control(
600 'add_image',
601 [
602 'label' => __('Add Image', 'embedpress'),
603 'type' => Controls_Manager::SWITCHER,
604 'label_on' => __('Show', 'embedpress'),
605 'label_off' => __('Hide', 'embedpress'),
606 'return_value' => 'yes',
607 'default' => 'yes',
608 'condition' => [
609 'pdf_toolbar' => 'yes',
610 'embedpress_pdf_viewer_style' => 'modern',
611 ],
612 ]
613 );
614 $this->add_control(
615 'pdf_rotate_access',
616 [
617 'label' => __('Rotation', 'embedpress'),
618 'type' => Controls_Manager::SWITCHER,
619 'label_on' => __('Show', 'embedpress'),
620 'label_off' => __('Hide', 'embedpress'),
621 'return_value' => 'yes',
622 'default' => 'yes',
623 'condition' => [
624 'pdf_toolbar' => 'yes',
625 'embedpress_pdf_viewer_style' => 'modern',
626 ],
627 ]
628 );
629
630 $this->add_control(
631 'pdf_details',
632 [
633 'label' => __('Properties', 'embedpress'),
634 'type' => Controls_Manager::SWITCHER,
635 'label_on' => __('Show', 'embedpress'),
636 'label_off' => __('Hide', 'embedpress'),
637 'return_value' => 'yes',
638 'default' => 'yes',
639 'condition' => [
640 'pdf_toolbar' => 'yes',
641 'embedpress_pdf_viewer_style' => 'modern',
642 ],
643 ]
644 );
645
646 $this->end_controls_section();
647
648 do_action( 'extend_elementor_controls', $this, '_pdf_', $this->pro_text, $this->pro_class);
649
650 if (!is_embedpress_pro_active()) {
651 $this->start_controls_section(
652 'embedpress_pro_section',
653 [
654 'label' => __('Go Premium for More Features', 'embedpress'),
655 ]
656 );
657
658 $this->add_control(
659 'embedpress_pro_cta',
660 [
661 'label' => __('Unlock more possibilities', 'embedpress'),
662 'type' => Controls_Manager::CHOOSE,
663 'options' => [
664 '1' => [
665 'title' => '',
666 'icon' => 'eicon-lock',
667 ],
668 ],
669 'default' => '1',
670 '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>',
671 ]
672 );
673
674 $this->end_controls_section();
675 }
676 }
677
678 private function is_pdf($url)
679 {
680 $arr = explode('.', $url);
681 return end($arr) === 'pdf';
682 }
683
684 public function render()
685 {
686 $settings = $this->get_settings();
687
688 Helper::get_enable_settings_data_for_scripts($settings);
689
690 $url = $this->get_file_url();
691
692 if($settings['embedpress_pdf_type'] === 'url') {
693
694 if(!empty($settings['__dynamic__']) && !empty($settings['__dynamic__']['embedpress_pdf_file_link'])){
695 $decode_url = urldecode(($settings['__dynamic__']['embedpress_pdf_file_link']));
696
697 preg_match('/name="([^"]+)"/', $decode_url, $name_matches);
698
699 if (!empty($name_matches[1])) {
700 $name_key = $name_matches[1];
701 if ($name_key === 'acf-url' && class_exists('ACF') && function_exists('get_field')) {
702 $pattern = '/"key":"([^"]+):([^"]+)"/';
703 preg_match($pattern, $decode_url, $matches);
704 } elseif ($name_key === 'toolset-url' && class_exists('Types_Helper_Output_Meta_Box')) {
705 $pattern = '/"key":"[^"]+:(.*?)"/';
706 preg_match($pattern, $decode_url, $matches);
707 }
708
709 if (!empty($matches[1])) {
710 $get_acf_key = $matches[1];
711 if ($name_key === 'acf-url') {
712 $url = get_field($get_acf_key);
713 } elseif ($name_key === 'toolset-url') {
714 $url = get_post_meta(get_the_ID(), 'wpcf-' . $get_acf_key, true);
715 }
716
717 if (empty($url)) {
718 preg_match('/"fallback":"([^"]+)"/', $decode_url, $fallback_matches);
719 if (!empty($fallback_matches[1])) {
720 $url = $fallback_matches[1];
721 }
722 }
723 }
724 }
725 }
726 }
727
728 $client_id = $this->get_id();
729
730 $this->_render($url, $settings, $client_id);
731 Helper::get_source_data(md5($this->get_id()).'_eb_elementor', $url, 'elementor_source_data', 'elementor_temp_source_data');
732 }
733
734 public function getParamData($settings){
735 $urlParamData = array(
736 'themeMode' => $settings['embedpress_theme_mode'],
737 'toolbar' => !empty($settings['pdf_toolbar']) ? 'true' : 'false',
738 'position' => $settings['pdf_toolbar_position'],
739 'presentation' => !empty($settings['pdf_presentation_mode']) ? 'true' : 'false',
740 'download' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['pdf_print_download'] : 'true',
741 'copy_text' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['pdf_text_copy'] : 'true',
742 'add_text' => !empty($settings['add_text']) ? 'true' : 'false',
743 'draw' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['draw'] : 'true',
744 'add_image' => !empty($settings['add_image']) ? 'true' : 'false',
745 'pdf_rotation' => !empty($settings['pdf_rotate_access']) ? 'true' : 'false',
746 'pdf_details' => !empty($settings['pdf_details']) ? 'true' : 'false',
747 'zoom_in' => !empty($settings['pdf_zoom_in']) ? 'true' : 'false',
748 'zoom_out' => !empty($settings['pdf_zoom_out']) ? 'true' : 'false',
749 'fit_view' => !empty($settings['pdf_fit_view']) ? 'true' : 'false',
750 'bookmark' => !empty($settings['pdf_bookmark']) ? 'true' : 'false',
751 'flipbook_toolbar_position' => !empty($settings['flipbook_toolbar_position']) ? $settings['flipbook_toolbar_position'] : 'bottom',
752 );
753
754 if($settings['embedpress_theme_mode'] == 'custom') {
755 $urlParamData['customColor'] = $settings['embedpress_pdf_custom_color'];
756 }
757
758 if($settings['embedpress_pdf_viewer_style'] == 'flip-book'){
759 return "&key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), "UTF-8"));
760 }
761
762 return "#key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), "UTF-8"));
763
764 }
765
766 public function _render($url, $settings, $id)
767 {
768 $unitoption = 'emebedpress-unit-px';
769 if($settings['embedpress_elementor_document_width']['unit'] === '%'){
770 $unitoption = 'emebedpress-unit-percent';
771 }
772 $client_id = $id;
773 $id = 'embedpress-pdf-' . $id;
774 $hash_pass = hash('sha256', wp_salt(32) . md5($settings['embedpress_pdf_lock_content_password']));
775
776 $dimension = '';
777
778 $password_correct = isset($_COOKIE['password_correct_' . $client_id]) ? sanitize_text_field($_COOKIE['password_correct_' . $client_id]) : '';
779
780 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))){
781 $dimension = "width: {$settings['embedpress_elementor_document_width']['size']}{$settings['embedpress_elementor_document_width']['unit']}!important;height: {$settings['embedpress_elementor_document_height']['size']}px;";
782 }
783
784 $content_protection_class = 'ep-content-protection-enabled';
785 $content_locked_class = 'ep-content-locked';
786 if(empty($settings['embedpress_pdf_lock_content']) || empty($settings['embedpress_pdf_lock_content_password']) || $hash_pass === $password_correct) {
787 $content_locked_class = '';
788 $content_protection_class = 'ep-content-protection-disabled';
789 }
790
791 $pass_hash_key = md5($settings['embedpress_pdf_lock_content_password']);
792 $this->add_render_attribute('embedpres-pdf-render', [
793 'class' => ['embedpress-embed-document-pdf', esc_attr($id)],
794 'data-emid' => esc_attr($id)
795 ]);
796 $this->add_render_attribute('embedpress-document', [
797 'class' => ['embedpress-document-embed', 'ep-doc-' . md5($id), 'ose-document', $unitoption, $content_locked_class ],
798 'data-thememode' => isset($settings['embedpress_theme_mode']) ? esc_attr($settings['embedpress_theme_mode']) : '',
799 'data-customcolor' => isset($settings['embedpress_pdf_custom_color']) ? esc_attr($settings['embedpress_pdf_custom_color']) : '',
800 'data-toolbar' => isset($settings['pdf_toolbar']) ? esc_attr($settings['pdf_toolbar']) : '',
801 'data-toolbar-position' => isset($settings['pdf_toolbar_position']) ? esc_attr($settings['pdf_toolbar_position']) : 'top',
802 'data-open' => 'no', // Assuming 'no' is a static value, no need to sanitize
803 'data-presentation-mode' => isset($settings['pdf_presentation_mode']) ? esc_attr($settings['pdf_presentation_mode']) : '',
804 'data-download' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION') ? esc_attr($settings['pdf_print_download']) : 'yes', // Assuming 'yes' is a safe fallback
805 'data-copy' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION') ? esc_attr($settings['pdf_text_copy']) : 'yes', // Assuming 'yes' is a safe fallback
806 'data-add-image' => isset($settings['add_image']) ? esc_attr($settings['add_image']) : '',
807 'data-rotate' => isset($settings['pdf_rotate_access']) ? esc_attr($settings['pdf_rotate_access']) : '',
808 'data-details' => isset($settings['pdf_details']) ? esc_attr($settings['pdf_details']) : '',
809 'data-id' => $id // Assuming $id is safe, no need to sanitize
810 ]);
811
812 $embed_settings = [];
813 $embed_settings['customThumbnail'] = !empty($settings['embedpress_pdf_content_share_custom_thumbnail']['url']) ? esc_url($settings['embedpress_pdf_content_share_custom_thumbnail']['url']) : '';
814
815 $embed_settings['customTitle'] = !empty($settings['embedpress_pdf_content_title']) ? sanitize_text_field($settings['embedpress_pdf_content_title']) : Helper::get_file_title($url);
816
817 $embed_settings['customDescription'] = !empty($settings['embedpress_pdf_content_descripiton']) ? sanitize_text_field($settings['embedpress_pdf_content_descripiton']) : Helper::get_file_title($url);
818
819 $embed_settings['sharePosition'] = !empty($settings['embedpress_pdf_content_share_position']) ? sanitize_text_field($settings['embedpress_pdf_content_share_position']) : 'right';
820
821 $embed_settings['lockHeading'] = !empty($settings['embedpress_pdf_lock_content_heading']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_heading']) : '';
822
823 $embed_settings['lockSubHeading'] = !empty($settings['embedpress_pdf_lock_content_sub_heading']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_sub_heading']) : '';
824
825 $embed_settings['lockErrorMessage'] = !empty($settings['embedpress_pdf_lock_content_error_message']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_error_message']) : '';
826
827 $embed_settings['passwordPlaceholder'] = !empty($settings['embedpress_pdf_password_placeholder']) ? sanitize_text_field($settings['embedpress_pdf_password_placeholder']) : '';
828
829 $embed_settings['submitButtonText'] = !empty($settings['embedpress_pdf_submit_button_text']) ? sanitize_text_field($settings['embedpress_pdf_submit_button_text']) : '';
830
831 $embed_settings['submitUnlockingText'] = !empty($settings['embedpress_pdf_submit_Unlocking_text']) ? sanitize_text_field($settings['embedpress_pdf_submit_Unlocking_text']) : '';
832
833 $embed_settings['enableFooterMessage'] = !empty($settings['embedpress_pdf_enable_footer_message']) ? sanitize_text_field($settings['embedpress_pdf_enable_footer_message']) : '';
834
835 $embed_settings['footerMessage'] = !empty($settings['embedpress_pdf_lock_content_footer_message']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_footer_message']) : '';
836
837
838 if($settings['embedpress_elementor_document_width']['unit'] === '%'){
839 $width_class = ' ep-percentage-width';
840 }
841 else{
842 $width_class = 'ep-fixed-width';
843 }
844 $content_share_class = '';
845 $share_position_class = '';
846 $share_position = isset($settings['embedpress_pdf_content_share_position']) ? $settings['embedpress_pdf_content_share_position'] : 'right';
847
848 if(!empty($settings['embedpress_pdf_content_share'])) {
849 $content_share_class = 'ep-content-share-enabled';
850 $share_position_class = 'ep-share-position-'.$share_position;
851 }
852
853 $adsAtts = '';
854
855 if (!empty($settings['adManager'])) {
856 $ad = base64_encode(json_encode($settings)); // Using WordPress JSON encoding function
857 $adsAtts = 'data-sponsored-id="' . esc_attr($client_id) . '" data-sponsored-attrs="' . esc_attr($ad) . '" class="ad-mask"';
858 }
859
860 ?>
861 <div <?php echo $this->get_render_attribute_string('embedpress-document'); ?> style=" max-width:100%; display: inline-block">
862
863 <?php
864 do_action('embedpress_pdf_after_embed', $settings, $url, $id, $this);
865
866 if ($url != '') {
867 $url = esc_url($url);
868
869 if ($this->is_pdf($url) && !$this->is_external_url($url)) {
870 $renderer = Helper::get_pdf_renderer();
871 $src = $renderer . ((strpos($renderer, '?') == false) ? '?' : '&') . 'file=' . urlencode($url).$this->getParamData($settings);
872 if (!empty($settings['embedpress_pdf_zoom'])) {
873 $zoom = $settings['embedpress_pdf_zoom'];
874 if ($zoom == 'custom') {
875 if (!empty($settings['embedpress_pdf_zoom_custom'])) {
876 $zoom = $settings['embedpress_pdf_zoom_custom'];
877 } else {
878 $zoom = null;
879 }
880 }
881 if ($zoom) {
882 $src = $src . "&zoom=$zoom";
883 }
884 }
885 if(isset($settings['embedpress_pdf_viewer_style']) && $settings['embedpress_pdf_viewer_style'] === 'modern') {
886 $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_url($src).'"';
887 }
888 else{
889 $src = urlencode($url).$this->getParamData($settings);
890 $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_url(EMBEDPRESS_URL_ASSETS . 'pdf-flip-book/viewer.html?file='.$src).'"';
891 }
892
893
894 $embed_content .= ' '.$this->get_render_attribute_string('embedpres-pdf-render').' frameborder="0"></iframe>';
895 if ($settings['embedpress_pdf_powered_by'] === 'yes') {
896 $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
897 }
898
899 } else {
900 $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).'"';
901 $embed_content .= ' '.$this->get_render_attribute_string('embedpres-pdf-render').'></iframe>';
902
903 if ($settings['embedpress_pdf_powered_by'] === 'yes') {
904 $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
905 }
906 }
907
908 ?>
909
910 <div <?php echo $adsAtts; ?>>
911
912 <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); ?>">
913 <div id="<?php echo esc_attr( $this->get_id() ); ?>" class="ep-embed-content-wraper">
914 <?php
915 $embed = '<div>'.$embed_content.'</div>';
916
917 $content_id = $client_id;
918 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)) ){
919 if(!empty($settings['embedpress_pdf_content_share'])){
920 $embed .= Helper::embed_content_share($content_id, $embed_settings);
921 }
922 echo $embed ;
923
924 } else {
925 if(!empty($settings['embedpress_pdf_content_share'])){
926 $embed .= Helper::embed_content_share($content_id, $embed_settings);
927 }
928 Helper::display_password_form($client_id, $embed, $pass_hash_key, $embed_settings);
929 }
930 ?>
931 </div>
932
933 </div>
934 <?php
935 if(!empty($settings['adManager'])) {
936 $embed_content .= Helper::generateAdTemplate($client_id, $settings, 'elementor');
937 }
938 ?>
939 </div>
940 <?php
941
942 }
943 ?>
944
945 </div>
946
947 <?php
948 }
949
950 private function get_file_url()
951 {
952 $settings = $this->get_settings();
953 return $settings['embedpress_pdf_type'] === 'url' ? $settings['embedpress_pdf_file_link']['url'] : $settings['embedpress_pdf_Uploader']['url'];
954 }
955
956 protected function is_external_url($url)
957 {
958 return strpos($url, get_site_url()) === false;
959 }
960 }
961