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