PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 4.2.8
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v4.2.8
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
1075 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
546 $this->add_control(
547 'pdf_presentation_mode',
548 [
549 'label' => __('PDF Presentation Mode', 'embedpress'),
550 'type' => Controls_Manager::SWITCHER,
551 'label_on' => __('Show', 'embedpress'),
552 'label_off' => __('Hide', 'embedpress'),
553 'return_value' => 'yes',
554 'default' => 'yes',
555 'condition' => [
556 'pdf_toolbar' => 'yes',
557 ],
558 ]
559 );
560 $this->add_control(
561 'pdf_lazyload',
562 [
563 'label' => __('Lazy Load', 'embedpress'),
564 'type' => Controls_Manager::SWITCHER,
565 'label_on' => __('Yes', 'embedpress'),
566 'label_off' => __('No', 'embedpress'),
567 'return_value' => 'yes',
568 'default' => '',
569 'condition' => [
570 'pdf_toolbar' => 'yes',
571 ],
572 ]
573 );
574
575 $this->add_control(
576 'pdf_text_copy',
577 [
578 'label' => sprintf(__('Copy Text %s', 'embedpress'), $this->pro_text),
579 'type' => Controls_Manager::SWITCHER,
580 'label_on' => __('Show', 'embedpress'),
581 'label_off' => __('Hide', 'embedpress'),
582 'return_value' => 'yes',
583 'default' => 'yes',
584 'classes' => $this->pro_class,
585 'condition' => [
586 'pdf_toolbar' => 'yes',
587 'embedpress_pdf_viewer_style' => 'modern',
588 ],
589 ]
590 );
591
592 $this->add_control(
593 'add_text',
594 [
595 'label' => sprintf(__('Add Text', 'embedpress')),
596 'type' => Controls_Manager::SWITCHER,
597 'label_on' => __('Show', 'embedpress'),
598 'label_off' => __('Hide', 'embedpress'),
599 'return_value' => 'yes',
600 'default' => 'yes',
601 'condition' => [
602 'pdf_toolbar' => 'yes',
603 'embedpress_pdf_viewer_style' => 'modern',
604 ],
605 ]
606 );
607 $this->add_control(
608 'draw',
609 [
610 'label' => sprintf(__('Draw %s', 'embedpress'), $this->pro_text),
611 'type' => Controls_Manager::SWITCHER,
612 'label_on' => __('Show', 'embedpress'),
613 'label_off' => __('Hide', 'embedpress'),
614 'return_value' => 'yes',
615 'default' => 'yes',
616 'classes' => $this->pro_class,
617 'condition' => [
618 'pdf_toolbar' => 'yes',
619 'embedpress_pdf_viewer_style' => 'modern',
620 ],
621 ]
622 );
623
624 $this->add_control(
625 'add_image',
626 [
627 'label' => __('Add Image', 'embedpress'),
628 'type' => Controls_Manager::SWITCHER,
629 'label_on' => __('Show', 'embedpress'),
630 'label_off' => __('Hide', 'embedpress'),
631 'return_value' => 'yes',
632 'default' => 'yes',
633 'condition' => [
634 'pdf_toolbar' => 'yes',
635 'embedpress_pdf_viewer_style' => 'modern',
636 ],
637 ]
638 );
639 $this->add_control(
640 'pdf_rotate_access',
641 [
642 'label' => __('Rotation', '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
655 $this->add_control(
656 'pdf_details',
657 [
658 'label' => __('Properties', 'embedpress'),
659 'type' => Controls_Manager::SWITCHER,
660 'label_on' => __('Show', 'embedpress'),
661 'label_off' => __('Hide', 'embedpress'),
662 'return_value' => 'yes',
663 'default' => 'yes',
664 'condition' => [
665 'pdf_toolbar' => 'yes',
666 'embedpress_pdf_viewer_style' => 'modern',
667 ],
668 ]
669 );
670
671 $this->add_control(
672 'selection_tool',
673 [
674 'label' => sprintf(__('Default Selection Tool %s', 'embedpress'), $this->pro_text),
675 'type' => \Elementor\Controls_Manager::SELECT,
676 'options' => [
677 '0' => esc_html__('Text Tool', 'embedpress'),
678 '1' => esc_html__('Hand Tool', 'embedpress'),
679 ],
680 'default' => '0',
681 'classes' => $this->pro_class,
682
683 ]
684 );
685
686 $this->add_control(
687 'scrolling',
688 [
689 'label' => sprintf(__('Default Scrolling %s', 'embedpress'), $this->pro_text),
690 'type' => \Elementor\Controls_Manager::SELECT,
691 'options' => [
692 '-1' => esc_html__('Page Scrolling', 'embedpress'),
693 '0' => esc_html__('Vertical Scrolling', 'embedpress'),
694 '1' => esc_html__('Horizontal Scrolling', 'embedpress'),
695 '2' => esc_html__('Wrapped Scrolling', 'embedpress'),
696 ],
697 'default' => '0',
698 'classes' => $this->pro_class,
699 ]
700 );
701
702 $this->add_control(
703 'spreads',
704 [
705 'label' => esc_html__('Default Spreads', 'embedpress'),
706 'type' => \Elementor\Controls_Manager::SELECT,
707 'options' => [
708 '0' => esc_html__('No Spreads', 'embedpress'),
709 '1' => esc_html__('Odd Spreads', 'embedpress'),
710 '2' => esc_html__('Even Spreads', 'embedpress'),
711 ],
712 'default' => '-1',
713 'condition' => [
714 'scrolling!' => '1',
715 ],
716 ]
717 );
718
719 $this->end_controls_section();
720
721 do_action( 'extend_elementor_controls', $this, '_pdf_', $this->pro_text, $this->pro_class);
722
723 }
724
725 private function is_pdf($url)
726 {
727 $arr = explode('.', $url);
728 return end($arr) === 'pdf';
729 }
730
731 public function render()
732 {
733 $settings = $this->get_settings();
734
735 Helper::get_enable_settings_data_for_scripts($settings);
736
737 $url = $this->get_file_url();
738
739 if ($settings['embedpress_pdf_type'] === 'url') {
740 if (!empty($settings['__dynamic__']['embedpress_pdf_file_link'])) {
741 $decode_url = urldecode($settings['__dynamic__']['embedpress_pdf_file_link']);
742 preg_match('/name="([^"]+)"/', $decode_url, $name_matches);
743
744 if (!empty($name_matches[1])) {
745 $name_key = $name_matches[1];
746 $pattern = '';
747
748 if ($name_key === 'acf-url' && class_exists('ACF') && function_exists('get_field')) {
749 $pattern = '/"key":"[^"]+:(.*?)"/';
750 } elseif ($name_key === 'toolset-url' && class_exists('Types_Helper_Output_Meta_Box')) {
751 $pattern = '/"key":"[^"]+:(.*?)"/';
752 } elseif ($name_key === 'jet-post-custom-field' && class_exists('Jet_Engine')) {
753 $pattern = '/"meta_field":"([^"]+)"/';
754 }
755
756 if ($pattern) {
757 preg_match($pattern, $decode_url, $matches);
758
759 if (!empty($matches[1])) {
760 $get_field_key = sanitize_key($matches[1]);
761
762 $url = '';
763
764 if ($name_key === 'acf-url') {
765 $url = get_field($get_field_key);
766 } elseif ($name_key === 'toolset-url') {
767 $url = get_post_meta(get_the_ID(), 'wpcf-' . $get_field_key, true);
768 } elseif ($name_key === 'jet-post-custom-field') {
769 $url = get_post_meta(get_the_ID(), $get_field_key, true);
770 }
771
772 $url = apply_filters('embedpress/custom_meta_field_value', $url, $get_field_key);
773
774 // Fallback if empty
775 if (empty($url)) {
776 preg_match('/"fallback":"([^"]+)"/', $decode_url, $fallback_matches);
777 if (!empty($fallback_matches[1])) {
778 $url = $fallback_matches[1];
779 }
780 }
781
782 // Final sanitization
783 $url = esc_url_raw($url);
784 }
785 }
786 }
787 }
788 }
789
790 $client_id = $this->get_id();
791
792 $this->_render($url, $settings, $client_id);
793 Helper::get_source_data(md5($this->get_id()).'_eb_elementor', $url, 'elementor_source_data', 'elementor_temp_source_data');
794 }
795
796
797 public function getParamData($settings){
798 $urlParamData = array(
799 'themeMode' => $settings['embedpress_theme_mode'],
800 'toolbar' => !empty($settings['pdf_toolbar']) ? 'true' : 'false',
801 'position' => $settings['pdf_toolbar_position'],
802 'presentation' => !empty($settings['pdf_presentation_mode']) ? 'true' : 'false',
803 'lazyLoad' => !empty($settings['pdf_lazyload']) ? 'true' : 'false',
804 'download' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['pdf_print_download'] : 'true',
805 'copy_text' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['pdf_text_copy'] : 'true',
806 'add_text' => !empty($settings['add_text']) ? 'true' : 'false',
807 'draw' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['draw'] : 'true',
808 'add_image' => !empty($settings['add_image']) ? 'true' : 'false',
809 'pdf_rotation' => !empty($settings['pdf_rotate_access']) ? 'true' : 'false',
810 'pdf_details' => !empty($settings['pdf_details']) ? 'true' : 'false',
811 'zoom_in' => !empty($settings['pdf_zoom_in']) ? 'true' : 'false',
812 'zoom_out' => !empty($settings['pdf_zoom_out']) ? 'true' : 'false',
813 'fit_view' => !empty($settings['pdf_fit_view']) ? 'true' : 'false',
814 'bookmark' => !empty($settings['pdf_bookmark']) ? 'true' : 'false',
815 'flipbook_toolbar_position' => !empty($settings['flipbook_toolbar_position']) ? $settings['flipbook_toolbar_position'] : 'bottom',
816 'selection_tool' => isset($settings['selection_tool']) ? esc_attr($settings['selection_tool']) : '0',
817 'scrolling' => isset($settings['scrolling']) ? esc_attr($settings['scrolling']) : '-1',
818 'spreads' => isset($settings['spreads']) ? esc_attr($settings['spreads']) : '-1',
819 'is_pro_active' => apply_filters('embedpress/is_allow_rander', false)
820
821 );
822
823 $custom_color = Helper::get_elementor_global_color($settings, 'embedpress_pdf_custom_color');
824
825 if($settings['embedpress_theme_mode'] == 'custom') {
826 $urlParamData['customColor'] = $custom_color;
827 }
828
829 if($settings['embedpress_pdf_viewer_style'] == 'flip-book'){
830 return "&key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), "UTF-8"));
831 }
832
833 return "#key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), "UTF-8"));
834
835 }
836
837 public function _render($url, $settings, $id)
838 {
839
840 $custom_color = Helper::get_elementor_global_color($settings, 'embedpress_pdf_custom_color');
841
842 $unitoption = 'emebedpress-unit-px';
843 if($settings['embedpress_elementor_document_width']['unit'] === '%'){
844 $unitoption = 'emebedpress-unit-percent';
845 }
846 $client_id = $id;
847 $id = 'embedpress-pdf-' . $id;
848 $hash_pass = hash('sha256', wp_salt(32) . md5($settings['embedpress_pdf_lock_content_password']));
849
850 $dimension = '';
851
852 $password_correct = isset($_COOKIE['password_correct_' . $client_id]) ? sanitize_text_field($_COOKIE['password_correct_' . $client_id]) : '';
853
854 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))){
855 $dimension = "width: {$settings['embedpress_elementor_document_width']['size']}{$settings['embedpress_elementor_document_width']['unit']}!important;height: {$settings['embedpress_elementor_document_height']['size']}px;";
856 }
857
858 $content_protection_class = 'ep-content-protection-enabled';
859 $content_locked_class = 'ep-content-locked';
860 if(empty($settings['embedpress_pdf_lock_content']) || empty($settings['embedpress_pdf_lock_content_password']) || $hash_pass === $password_correct) {
861 $content_locked_class = '';
862 $content_protection_class = 'ep-content-protection-disabled';
863 }
864
865 $pass_hash_key = md5($settings['embedpress_pdf_lock_content_password']);
866 $this->add_render_attribute('embedpres-pdf-render', [
867 'class' => ['embedpress-embed-document-pdf', esc_attr($id)],
868 'data-emid' => esc_attr($id)
869 ]);
870 $this->add_render_attribute('embedpress-document', [
871 'class' => ['embedpress-document-embed', 'ep-doc-' . md5($id), 'ose-document', $unitoption, $content_locked_class ],
872 'data-thememode' => isset($settings['embedpress_theme_mode']) ? esc_attr($settings['embedpress_theme_mode']) : '',
873 'data-customcolor' => isset($custom_color) ? esc_attr($custom_color) : '',
874 'data-toolbar' => isset($settings['pdf_toolbar']) ? esc_attr($settings['pdf_toolbar']) : '',
875 'data-toolbar-position' => isset($settings['pdf_toolbar_position']) ? esc_attr($settings['pdf_toolbar_position']) : 'top',
876 'data-open' => 'no', // Assuming 'no' is a static value, no need to sanitize
877 'data-presentation-mode' => isset($settings['pdf_presentation_mode']) ? esc_attr($settings['pdf_presentation_mode']) : '',
878 'data-download' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION') ? esc_attr($settings['pdf_print_download']) : 'yes', // Assuming 'yes' is a safe fallback
879 'data-copy' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION') ? esc_attr($settings['pdf_text_copy']) : 'yes', // Assuming 'yes' is a safe fallback
880 'data-add-image' => isset($settings['add_image']) ? esc_attr($settings['add_image']) : '',
881 'data-rotate' => isset($settings['pdf_rotate_access']) ? esc_attr($settings['pdf_rotate_access']) : '',
882 'data-details' => isset($settings['pdf_details']) ? esc_attr($settings['pdf_details']) : '',
883 'data-id' => $id, // Assuming $id is safe, no need to sanitize
884 'data-selection-tool' => isset($settings['selection_tool']) ? esc_attr($settings['selection_tool']) : '0',
885 'data-scrolling' => isset($settings['scrolling']) ? esc_attr($settings['scrolling']) : '-1',
886 'data-spreads' => isset($settings['spreads']) ? esc_attr($settings['spreads']) : '-1',
887 ]);
888
889 $embed_settings = [];
890 $embed_settings['customThumbnail'] = !empty($settings['embedpress_pdf_content_share_custom_thumbnail']['url']) ? esc_url($settings['embedpress_pdf_content_share_custom_thumbnail']['url']) : '';
891
892 $embed_settings['customTitle'] = !empty($settings['embedpress_pdf_content_title']) ? sanitize_text_field($settings['embedpress_pdf_content_title']) : Helper::get_file_title($url);
893
894 $embed_settings['customDescription'] = !empty($settings['embedpress_pdf_content_descripiton']) ? sanitize_text_field($settings['embedpress_pdf_content_descripiton']) : Helper::get_file_title($url);
895
896 $embed_settings['sharePosition'] = !empty($settings['embedpress_pdf_content_share_position']) ? sanitize_text_field($settings['embedpress_pdf_content_share_position']) : 'right';
897
898 // Add social share platform settings
899 $embed_settings['shareFacebook'] = !empty($settings['embedpress_pdf_share_facebook']) ? true : false;
900 $embed_settings['shareTwitter'] = !empty($settings['embedpress_pdf_share_twitter']) ? true : false;
901 $embed_settings['sharePinterest'] = !empty($settings['embedpress_pdf_share_pinterest']) ? true : false;
902 $embed_settings['shareLinkedin'] = !empty($settings['embedpress_pdf_share_linkedin']) ? true : false;
903
904 $embed_settings['lockHeading'] = !empty($settings['embedpress_pdf_lock_content_heading']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_heading']) : '';
905
906 $embed_settings['lockSubHeading'] = !empty($settings['embedpress_pdf_lock_content_sub_heading']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_sub_heading']) : '';
907
908 $embed_settings['lockErrorMessage'] = !empty($settings['embedpress_pdf_lock_content_error_message']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_error_message']) : '';
909
910 $embed_settings['passwordPlaceholder'] = !empty($settings['embedpress_pdf_password_placeholder']) ? sanitize_text_field($settings['embedpress_pdf_password_placeholder']) : '';
911
912 $embed_settings['submitButtonText'] = !empty($settings['embedpress_pdf_submit_button_text']) ? sanitize_text_field($settings['embedpress_pdf_submit_button_text']) : '';
913
914 $embed_settings['submitUnlockingText'] = !empty($settings['embedpress_pdf_submit_Unlocking_text']) ? sanitize_text_field($settings['embedpress_pdf_submit_Unlocking_text']) : '';
915
916 $embed_settings['enableFooterMessage'] = !empty($settings['embedpress_pdf_enable_footer_message']) ? sanitize_text_field($settings['embedpress_pdf_enable_footer_message']) : '';
917
918 $embed_settings['footerMessage'] = !empty($settings['embedpress_pdf_lock_content_footer_message']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_footer_message']) : '';
919
920 $embed_settings['userRole'] = !empty($settings['embedpress_pdf_select_roles']) ? $settings['embedpress_pdf_select_roles'] : [];
921
922 $embed_settings['protectionMessage'] = !empty($settings['embedpress_pdf_protection_message']) ? $settings['embedpress_pdf_protection_message'] : '';
923
924
925 if($settings['embedpress_elementor_document_width']['unit'] === '%'){
926 $width_class = ' ep-percentage-width';
927 }
928 else{
929 $width_class = 'ep-fixed-width';
930 }
931 $content_share_class = '';
932 $share_position_class = '';
933 $share_position = isset($settings['embedpress_pdf_content_share_position']) ? $settings['embedpress_pdf_content_share_position'] : 'right';
934
935 if(!empty($settings['embedpress_pdf_content_share'])) {
936 $content_share_class = 'ep-content-share-enabled';
937 $share_position_class = 'ep-share-position-'.$share_position;
938 }
939
940 $adsAtts = '';
941
942 if (!empty($settings['adManager'])) {
943 $ad = base64_encode(json_encode($settings)); // Using WordPress JSON encoding function
944 $adsAtts = 'data-sponsored-id="' . esc_attr($client_id) . '" data-sponsored-attrs="' . esc_attr($ad) . '" class="sponsored-mask"';
945 }
946
947 ?>
948 <div <?php echo $this->get_render_attribute_string('embedpress-document'); ?> style=" max-width:100%; display: inline-block">
949
950 <?php
951 do_action('embedpress_pdf_after_embed', $settings, $url, $id, $this);
952
953 if ($url != '') {
954 $url = esc_url($url);
955
956 if ($this->is_pdf($url) && !$this->is_external_url($url)) {
957 $renderer = Helper::get_pdf_renderer();
958 $src = $renderer . ((strpos($renderer, '?') === false) ? '?' : '&')
959 . 'file=' . urlencode($url)
960 . '&scrolling=' . $settings['scrolling']
961 . '&selection_tool=' . $settings['selection_tool']
962 . '&spreads=' . $settings['spreads']
963 . $this->getParamData($settings);
964
965
966 if (!empty($settings['embedpress_pdf_zoom'])) {
967 $zoom = $settings['embedpress_pdf_zoom'];
968 if ($zoom == 'custom') {
969 if (!empty($settings['embedpress_pdf_zoom_custom'])) {
970 $zoom = $settings['embedpress_pdf_zoom_custom'];
971 } else {
972 $zoom = null;
973 }
974 }
975 if ($zoom) {
976 $src = $src . "&zoom=$zoom";
977 }
978 }
979
980 if(isset($settings['embedpress_pdf_viewer_style']) && $settings['embedpress_pdf_viewer_style'] === 'modern') {
981 $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).'"';
982 }
983 else{
984 $src = urlencode($url).$this->getParamData($settings);
985 $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).'"';
986 }
987
988
989 $embed_content .= ' '.$this->get_render_attribute_string('embedpres-pdf-render').' frameborder="0"></iframe>';
990 if ($settings['embedpress_pdf_powered_by'] === 'yes') {
991 $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
992 }
993
994 } else {
995 $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).'"';
996 $embed_content .= ' '.$this->get_render_attribute_string('embedpres-pdf-render').'></iframe>';
997
998 if ($settings['embedpress_pdf_powered_by'] === 'yes') {
999 $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
1000 }
1001 }
1002
1003 ?>
1004
1005 <div <?php echo $adsAtts; ?>>
1006
1007 <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); ?>">
1008 <div id="<?php echo esc_attr( $this->get_id() ); ?>" class="ep-embed-content-wraper">
1009 <?php
1010 $embed = '<div>'.$embed_content.'</div>';
1011
1012 $content_id = $client_id;
1013 if(
1014
1015 (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') ||
1016 ($settings['embedpress_pdf_protection_type'] == 'password' && !empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct) ) ||
1017 !apply_filters('embedpress/is_allow_rander', false) ||
1018 ($settings['embedpress_pdf_protection_type'] == 'user-role' && Helper::has_allowed_roles($embed_settings['userRole']))
1019
1020 ){
1021 if(!empty($settings['embedpress_pdf_content_share'])){
1022 $embed .= Helper::embed_content_share($content_id, $embed_settings);
1023 }
1024 echo $embed ;
1025
1026 } else {
1027 if(!empty($settings['embedpress_pdf_content_share'])){
1028 $embed .= Helper::embed_content_share($content_id, $embed_settings);
1029 }
1030
1031 if ($settings['embedpress_pdf_protection_type'] == 'password') {
1032 do_action('embedpress/display_password_form', $client_id, $embed, $pass_hash_key, $embed_settings);
1033 } else {
1034 do_action('embedpress/content_protection_content', $client_id, $embed_settings['protectionMessage'], $embed_settings['userRole']);
1035 }
1036 }
1037 ?>
1038 </div>
1039
1040 </div>
1041
1042
1043 <?php
1044 $isAdEnabled = !empty($settings['adManager']);
1045 $isContentUnlocked = empty($settings['embedpress_pdf_lock_content']);
1046 $isPasswordCorrect = Helper::is_password_correct($client_id) && ($hash_pass === $password_correct);
1047
1048 if ($isAdEnabled && ($isContentUnlocked || $isPasswordCorrect)) {
1049 $embed_content = apply_filters('embedpress/generate_ad_template', $embed_content, $client_id, $settings, 'elementor');
1050 }
1051 ?>
1052
1053 </div>
1054 <?php
1055
1056 }
1057 ?>
1058
1059 </div>
1060
1061 <?php
1062 }
1063
1064 private function get_file_url()
1065 {
1066 $settings = $this->get_settings();
1067 return $settings['embedpress_pdf_type'] === 'url' ? $settings['embedpress_pdf_file_link']['url'] : $settings['embedpress_pdf_Uploader']['url'];
1068 }
1069
1070 protected function is_external_url($url)
1071 {
1072 return strpos($url, get_site_url()) === false;
1073 }
1074 }
1075