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