PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 4.2.4
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v4.2.4
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
1049 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
741 if(!empty($settings['__dynamic__']) && !empty($settings['__dynamic__']['embedpress_pdf_file_link'])){
742 $decode_url = urldecode(($settings['__dynamic__']['embedpress_pdf_file_link']));
743
744 preg_match('/name="([^"]+)"/', $decode_url, $name_matches);
745
746 if (!empty($name_matches[1])) {
747 $name_key = $name_matches[1];
748 if ($name_key === 'acf-url' && class_exists('ACF') && function_exists('get_field')) {
749 $pattern = '/"key":"([^"]+):([^"]+)"/';
750 preg_match($pattern, $decode_url, $matches);
751 } elseif ($name_key === 'toolset-url' && class_exists('Types_Helper_Output_Meta_Box')) {
752 $pattern = '/"key":"[^"]+:(.*?)"/';
753 preg_match($pattern, $decode_url, $matches);
754 }
755
756 if (!empty($matches[1])) {
757 $get_acf_key = $matches[1];
758 if ($name_key === 'acf-url') {
759 $url = get_field($get_acf_key);
760 } elseif ($name_key === 'toolset-url') {
761 $url = get_post_meta(get_the_ID(), 'wpcf-' . $get_acf_key, true);
762 }
763
764 if (empty($url)) {
765 preg_match('/"fallback":"([^"]+)"/', $decode_url, $fallback_matches);
766 if (!empty($fallback_matches[1])) {
767 $url = $fallback_matches[1];
768 }
769 }
770 }
771 }
772 }
773 }
774
775 $client_id = $this->get_id();
776
777 $this->_render($url, $settings, $client_id);
778 Helper::get_source_data(md5($this->get_id()).'_eb_elementor', $url, 'elementor_source_data', 'elementor_temp_source_data');
779 }
780
781
782 public function getParamData($settings){
783 $urlParamData = array(
784 'themeMode' => $settings['embedpress_theme_mode'],
785 'toolbar' => !empty($settings['pdf_toolbar']) ? 'true' : 'false',
786 'position' => $settings['pdf_toolbar_position'],
787 'presentation' => !empty($settings['pdf_presentation_mode']) ? 'true' : 'false',
788 'lazyLoad' => !empty($settings['pdf_lazyload']) ? 'true' : 'false',
789 'download' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['pdf_print_download'] : 'true',
790 'copy_text' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['pdf_text_copy'] : 'true',
791 'add_text' => !empty($settings['add_text']) ? 'true' : 'false',
792 'draw' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['draw'] : 'true',
793 'add_image' => !empty($settings['add_image']) ? 'true' : 'false',
794 'pdf_rotation' => !empty($settings['pdf_rotate_access']) ? 'true' : 'false',
795 'pdf_details' => !empty($settings['pdf_details']) ? 'true' : 'false',
796 'zoom_in' => !empty($settings['pdf_zoom_in']) ? 'true' : 'false',
797 'zoom_out' => !empty($settings['pdf_zoom_out']) ? 'true' : 'false',
798 'fit_view' => !empty($settings['pdf_fit_view']) ? 'true' : 'false',
799 'bookmark' => !empty($settings['pdf_bookmark']) ? 'true' : 'false',
800 'flipbook_toolbar_position' => !empty($settings['flipbook_toolbar_position']) ? $settings['flipbook_toolbar_position'] : 'bottom',
801 'selection_tool' => isset($settings['selection_tool']) ? esc_attr($settings['selection_tool']) : '0',
802 'scrolling' => isset($settings['scrolling']) ? esc_attr($settings['scrolling']) : '-1',
803 'spreads' => isset($settings['spreads']) ? esc_attr($settings['spreads']) : '-1',
804 'is_pro_active' => apply_filters('embedpress/is_allow_rander', false)
805
806 );
807
808 $custom_color = Helper::get_elementor_global_color($settings, 'embedpress_pdf_custom_color');
809
810 if($settings['embedpress_theme_mode'] == 'custom') {
811 $urlParamData['customColor'] = $custom_color;
812 }
813
814 if($settings['embedpress_pdf_viewer_style'] == 'flip-book'){
815 return "&key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), "UTF-8"));
816 }
817
818 return "#key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), "UTF-8"));
819
820 }
821
822 public function _render($url, $settings, $id)
823 {
824
825 $custom_color = Helper::get_elementor_global_color($settings, 'embedpress_pdf_custom_color');
826
827 $unitoption = 'emebedpress-unit-px';
828 if($settings['embedpress_elementor_document_width']['unit'] === '%'){
829 $unitoption = 'emebedpress-unit-percent';
830 }
831 $client_id = $id;
832 $id = 'embedpress-pdf-' . $id;
833 $hash_pass = hash('sha256', wp_salt(32) . md5($settings['embedpress_pdf_lock_content_password']));
834
835 $dimension = '';
836
837 $password_correct = isset($_COOKIE['password_correct_' . $client_id]) ? sanitize_text_field($_COOKIE['password_correct_' . $client_id]) : '';
838
839 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))){
840 $dimension = "width: {$settings['embedpress_elementor_document_width']['size']}{$settings['embedpress_elementor_document_width']['unit']}!important;height: {$settings['embedpress_elementor_document_height']['size']}px;";
841 }
842
843 $content_protection_class = 'ep-content-protection-enabled';
844 $content_locked_class = 'ep-content-locked';
845 if(empty($settings['embedpress_pdf_lock_content']) || empty($settings['embedpress_pdf_lock_content_password']) || $hash_pass === $password_correct) {
846 $content_locked_class = '';
847 $content_protection_class = 'ep-content-protection-disabled';
848 }
849
850 $pass_hash_key = md5($settings['embedpress_pdf_lock_content_password']);
851 $this->add_render_attribute('embedpres-pdf-render', [
852 'class' => ['embedpress-embed-document-pdf', esc_attr($id)],
853 'data-emid' => esc_attr($id)
854 ]);
855 $this->add_render_attribute('embedpress-document', [
856 'class' => ['embedpress-document-embed', 'ep-doc-' . md5($id), 'ose-document', $unitoption, $content_locked_class ],
857 'data-thememode' => isset($settings['embedpress_theme_mode']) ? esc_attr($settings['embedpress_theme_mode']) : '',
858 'data-customcolor' => isset($custom_color) ? esc_attr($custom_color) : '',
859 'data-toolbar' => isset($settings['pdf_toolbar']) ? esc_attr($settings['pdf_toolbar']) : '',
860 'data-toolbar-position' => isset($settings['pdf_toolbar_position']) ? esc_attr($settings['pdf_toolbar_position']) : 'top',
861 'data-open' => 'no', // Assuming 'no' is a static value, no need to sanitize
862 'data-presentation-mode' => isset($settings['pdf_presentation_mode']) ? esc_attr($settings['pdf_presentation_mode']) : '',
863 'data-download' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION') ? esc_attr($settings['pdf_print_download']) : 'yes', // Assuming 'yes' is a safe fallback
864 'data-copy' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION') ? esc_attr($settings['pdf_text_copy']) : 'yes', // Assuming 'yes' is a safe fallback
865 'data-add-image' => isset($settings['add_image']) ? esc_attr($settings['add_image']) : '',
866 'data-rotate' => isset($settings['pdf_rotate_access']) ? esc_attr($settings['pdf_rotate_access']) : '',
867 'data-details' => isset($settings['pdf_details']) ? esc_attr($settings['pdf_details']) : '',
868 'data-id' => $id, // Assuming $id is safe, no need to sanitize
869 'data-selection-tool' => isset($settings['selection_tool']) ? esc_attr($settings['selection_tool']) : '0',
870 'data-scrolling' => isset($settings['scrolling']) ? esc_attr($settings['scrolling']) : '-1',
871 'data-spreads' => isset($settings['spreads']) ? esc_attr($settings['spreads']) : '-1',
872 ]);
873
874 $embed_settings = [];
875 $embed_settings['customThumbnail'] = !empty($settings['embedpress_pdf_content_share_custom_thumbnail']['url']) ? esc_url($settings['embedpress_pdf_content_share_custom_thumbnail']['url']) : '';
876
877 $embed_settings['customTitle'] = !empty($settings['embedpress_pdf_content_title']) ? sanitize_text_field($settings['embedpress_pdf_content_title']) : Helper::get_file_title($url);
878
879 $embed_settings['customDescription'] = !empty($settings['embedpress_pdf_content_descripiton']) ? sanitize_text_field($settings['embedpress_pdf_content_descripiton']) : Helper::get_file_title($url);
880
881 $embed_settings['sharePosition'] = !empty($settings['embedpress_pdf_content_share_position']) ? sanitize_text_field($settings['embedpress_pdf_content_share_position']) : 'right';
882
883 $embed_settings['lockHeading'] = !empty($settings['embedpress_pdf_lock_content_heading']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_heading']) : '';
884
885 $embed_settings['lockSubHeading'] = !empty($settings['embedpress_pdf_lock_content_sub_heading']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_sub_heading']) : '';
886
887 $embed_settings['lockErrorMessage'] = !empty($settings['embedpress_pdf_lock_content_error_message']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_error_message']) : '';
888
889 $embed_settings['passwordPlaceholder'] = !empty($settings['embedpress_pdf_password_placeholder']) ? sanitize_text_field($settings['embedpress_pdf_password_placeholder']) : '';
890
891 $embed_settings['submitButtonText'] = !empty($settings['embedpress_pdf_submit_button_text']) ? sanitize_text_field($settings['embedpress_pdf_submit_button_text']) : '';
892
893 $embed_settings['submitUnlockingText'] = !empty($settings['embedpress_pdf_submit_Unlocking_text']) ? sanitize_text_field($settings['embedpress_pdf_submit_Unlocking_text']) : '';
894
895 $embed_settings['enableFooterMessage'] = !empty($settings['embedpress_pdf_enable_footer_message']) ? sanitize_text_field($settings['embedpress_pdf_enable_footer_message']) : '';
896
897 $embed_settings['footerMessage'] = !empty($settings['embedpress_pdf_lock_content_footer_message']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_footer_message']) : '';
898
899 $embed_settings['userRole'] = !empty($settings['embedpress_pdf_select_roles']) ? $settings['embedpress_pdf_select_roles'] : [];
900
901 $embed_settings['protectionMessage'] = !empty($settings['embedpress_pdf_protection_message']) ? $settings['embedpress_pdf_protection_message'] : '';
902
903
904 if($settings['embedpress_elementor_document_width']['unit'] === '%'){
905 $width_class = ' ep-percentage-width';
906 }
907 else{
908 $width_class = 'ep-fixed-width';
909 }
910 $content_share_class = '';
911 $share_position_class = '';
912 $share_position = isset($settings['embedpress_pdf_content_share_position']) ? $settings['embedpress_pdf_content_share_position'] : 'right';
913
914 if(!empty($settings['embedpress_pdf_content_share'])) {
915 $content_share_class = 'ep-content-share-enabled';
916 $share_position_class = 'ep-share-position-'.$share_position;
917 }
918
919 $adsAtts = '';
920
921 if (!empty($settings['adManager'])) {
922 $ad = base64_encode(json_encode($settings)); // Using WordPress JSON encoding function
923 $adsAtts = 'data-sponsored-id="' . esc_attr($client_id) . '" data-sponsored-attrs="' . esc_attr($ad) . '" class="sponsored-mask"';
924 }
925
926 ?>
927 <div <?php echo $this->get_render_attribute_string('embedpress-document'); ?> style=" max-width:100%; display: inline-block">
928
929 <?php
930 do_action('embedpress_pdf_after_embed', $settings, $url, $id, $this);
931
932 if ($url != '') {
933 $url = esc_url($url);
934
935 if ($this->is_pdf($url) && !$this->is_external_url($url)) {
936 $renderer = Helper::get_pdf_renderer();
937 $src = $renderer . ((strpos($renderer, '?') === false) ? '?' : '&')
938 . 'file=' . urlencode($url)
939 . '&scrolling=' . $settings['scrolling']
940 . '&selection_tool=' . $settings['selection_tool']
941 . '&spreads=' . $settings['spreads']
942 . $this->getParamData($settings);
943
944
945 if (!empty($settings['embedpress_pdf_zoom'])) {
946 $zoom = $settings['embedpress_pdf_zoom'];
947 if ($zoom == 'custom') {
948 if (!empty($settings['embedpress_pdf_zoom_custom'])) {
949 $zoom = $settings['embedpress_pdf_zoom_custom'];
950 } else {
951 $zoom = null;
952 }
953 }
954 if ($zoom) {
955 $src = $src . "&zoom=$zoom";
956 }
957 }
958
959 if(isset($settings['embedpress_pdf_viewer_style']) && $settings['embedpress_pdf_viewer_style'] === 'modern') {
960 $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).'"';
961 }
962 else{
963 $src = urlencode($url).$this->getParamData($settings);
964 $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).'"';
965 }
966
967
968 $embed_content .= ' '.$this->get_render_attribute_string('embedpres-pdf-render').' frameborder="0"></iframe>';
969 if ($settings['embedpress_pdf_powered_by'] === 'yes') {
970 $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
971 }
972
973 } else {
974 $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).'"';
975 $embed_content .= ' '.$this->get_render_attribute_string('embedpres-pdf-render').'></iframe>';
976
977 if ($settings['embedpress_pdf_powered_by'] === 'yes') {
978 $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
979 }
980 }
981
982 ?>
983
984 <div <?php echo $adsAtts; ?>>
985
986 <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); ?>">
987 <div id="<?php echo esc_attr( $this->get_id() ); ?>" class="ep-embed-content-wraper">
988 <?php
989 $embed = '<div>'.$embed_content.'</div>';
990
991 $content_id = $client_id;
992 if(
993
994 (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') ||
995 ($settings['embedpress_pdf_protection_type'] == 'password' && !empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct) ) ||
996 !apply_filters('embedpress/is_allow_rander', false) ||
997 ($settings['embedpress_pdf_protection_type'] == 'user-role' && Helper::has_allowed_roles($embed_settings['userRole']))
998
999 ){
1000 if(!empty($settings['embedpress_pdf_content_share'])){
1001 $embed .= Helper::embed_content_share($content_id, $embed_settings);
1002 }
1003 echo $embed ;
1004
1005 } else {
1006 if(!empty($settings['embedpress_pdf_content_share'])){
1007 $embed .= Helper::embed_content_share($content_id, $embed_settings);
1008 }
1009
1010 if ($settings['embedpress_pdf_protection_type'] == 'password') {
1011 do_action('embedpress/display_password_form', $client_id, $embed, $pass_hash_key, $embed_settings);
1012 } else {
1013 do_action('embedpress/content_protection_content', $client_id, $embed_settings['protectionMessage'], $embed_settings['userRole']);
1014 }
1015 }
1016 ?>
1017 </div>
1018
1019 </div>
1020
1021
1022 <?php
1023 if (!empty($settings['adManager']) && (!empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct) )){
1024 $embed_content = apply_filters('embedpress/generate_ad_template', $embed_content, $client_id, $settings, 'elementor');
1025 }
1026 ?>
1027 </div>
1028 <?php
1029
1030 }
1031 ?>
1032
1033 </div>
1034
1035 <?php
1036 }
1037
1038 private function get_file_url()
1039 {
1040 $settings = $this->get_settings();
1041 return $settings['embedpress_pdf_type'] === 'url' ? $settings['embedpress_pdf_file_link']['url'] : $settings['embedpress_pdf_Uploader']['url'];
1042 }
1043
1044 protected function is_external_url($url)
1045 {
1046 return strpos($url, get_site_url()) === false;
1047 }
1048 }
1049