PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 4.4.6
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v4.4.6
4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / EmbedPress / Elementor / Widgets / Embedpress_Pdf.php
embedpress / EmbedPress / Elementor / Widgets Last commit date
Embedpress_Calendar.php 11 months ago Embedpress_Document.php 10 months ago Embedpress_Elementor.php 10 months ago Embedpress_Pdf.php 10 months ago
Embedpress_Pdf.php
1134 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-css',
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 // Get global powered_by setting
339 $g_settings = get_option(EMBEDPRESS_PLG_NAME, []);
340 $powered_by_default = isset($g_settings['embedpress_document_powered_by']) && $g_settings['embedpress_document_powered_by'] === 'yes' ? 'yes' : 'no';
341
342 $this->add_control(
343 'embedpress_pdf_powered_by',
344 [
345 'label' => __('Powered By', 'embedpress'),
346 'type' => Controls_Manager::SWITCHER,
347 'label_on' => __('Show', 'embedpress'),
348 'label_off' => __('Hide', 'embedpress'),
349 'return_value' => 'yes',
350 'default' => apply_filters('embedpress_document_powered_by_control', $powered_by_default),
351 ]
352 );
353
354 $this->init_branding_controls('document');
355
356 $this->end_controls_section();
357
358
359 /**
360 * EmbedPress PDF Control Settings
361 */
362
363 $this->start_controls_section(
364 'embedpress_pdf_content_settings',
365 [
366 'label' => esc_html__('Controls', 'embedpress'),
367 'conditions' => [
368 'relation' => 'or',
369 'terms' => [
370 ['name' => 'embedpress_pdf_type', 'operator' => '===', 'value' => 'file'],
371 ['name' => 'embedpress_pdf_file_link_from', 'operator' => '===', 'value' => 'self'],
372 ],
373 ],
374 ]
375 );
376
377
378 $this->add_control(
379 'embedpress_theme_mode',
380 [
381 'label' => __('Theme', 'embedpress'),
382 'type' => Controls_Manager::SELECT,
383 'default' => 'default',
384 'options' => [
385 'default' => __('System Default', 'embedpress'),
386 'dark' => __('Dark', 'embedpress'),
387 'light' => __('Light', 'embedpress'),
388 'custom' => __('Custom', 'embedpress')
389 ],
390 ]
391 );
392
393 $this->add_control(
394 'embedpress_pdf_custom_color',
395 [
396 'label' => esc_html__( 'Color', 'embedpress' ),
397 'type' => \Elementor\Controls_Manager::COLOR,
398 'default' => Helper::get_options_value('custom_color'),
399 'global' => [
400 'default' => Global_Colors::COLOR_PRIMARY,
401 ],
402 'condition' => [
403 'embedpress_theme_mode' => 'custom',
404 ],
405 ]
406 );
407
408 $this->add_control(
409 'pdf_toolbar',
410 [
411 'label' => sprintf(__('Toolbar %s', 'embedpress'), $this->pro_text),
412 'type' => Controls_Manager::SWITCHER,
413 'label_on' => __('Show', 'embedpress'),
414 'label_off' => __('Hide', 'embedpress'),
415 'return_value' => 'yes',
416 'default' => 'yes',
417 'classes' => $this->pro_class,
418 ]
419 );
420
421
422 $this->add_control(
423 'pdf_toolbar_position',
424 [
425 'label' => esc_html__('Toolbar Position', 'embedpress'),
426 'type' => \Elementor\Controls_Manager::CHOOSE,
427 'options' => [
428 'top' => [
429 'title' => esc_html__('Top', 'embedpress'),
430 'icon' => 'eicon-arrow-up',
431 ],
432 'bottom' => [
433 'title' => esc_html__('Bottom', 'embedpress'),
434 'icon' => 'eicon-arrow-down',
435 ],
436 ],
437 'default' => 'top',
438 'toggle' => true,
439 'condition' => [
440 'pdf_toolbar' => 'yes',
441 'embedpress_pdf_viewer_style' => 'modern',
442 ],
443 ]
444 );
445 $this->add_control(
446 'flipbook_toolbar_position',
447 [
448 'label' => esc_html__('Toolbar Position', 'embedpress'),
449 'type' => \Elementor\Controls_Manager::CHOOSE,
450 'options' => [
451 'top' => [
452 'title' => esc_html__('Top', 'embedpress'),
453 'icon' => 'eicon-arrow-up',
454 ],
455 'bottom' => [
456 'title' => esc_html__('Bottom', 'embedpress'),
457 'icon' => 'eicon-arrow-down',
458 ],
459 ],
460 'default' => 'bottom',
461 'toggle' => true,
462 'condition' => [
463 'pdf_toolbar' => 'yes',
464 'embedpress_pdf_viewer_style' => 'flip-book',
465 ],
466 ]
467 );
468
469
470 $this->add_control(
471 'pdf_print_download',
472 [
473 'label' => sprintf(__('Print/Download %s', 'embedpress'), $this->pro_text),
474 'type' => Controls_Manager::SWITCHER,
475 'label_on' => __('Show', 'embedpress'),
476 'label_off' => __('Hide', 'embedpress'),
477 'return_value' => 'yes',
478 'default' => 'yes',
479 'classes' => $this->pro_class,
480 'condition' => [
481 'pdf_toolbar' => 'yes',
482 ],
483 ]
484 );
485
486
487
488 $this->add_control(
489 'pdf_zoom_in',
490 [
491 'label' => __('Zoom In', 'embedpress'),
492 'type' => Controls_Manager::SWITCHER,
493 'label_on' => __('Show', 'embedpress'),
494 'label_off' => __('Hide', 'embedpress'),
495 'return_value' => 'yes',
496 'default' => 'yes',
497 'condition' => [
498 'pdf_toolbar' => 'yes',
499 'embedpress_pdf_viewer_style' => 'flip-book',
500 ],
501 ]
502 );
503 $this->add_control(
504 'pdf_zoom_out',
505 [
506 'label' => __('Zoom Out', 'embedpress'),
507 'type' => Controls_Manager::SWITCHER,
508 'label_on' => __('Show', 'embedpress'),
509 'label_off' => __('Hide', 'embedpress'),
510 'return_value' => 'yes',
511 'default' => 'yes',
512 'condition' => [
513 'pdf_toolbar' => 'yes',
514 'embedpress_pdf_viewer_style' => 'flip-book',
515 ],
516 ]
517 );
518 $this->add_control(
519 'pdf_fit_view',
520 [
521 'label' => __('Fit View', 'embedpress'),
522 'type' => Controls_Manager::SWITCHER,
523 'label_on' => __('Show', 'embedpress'),
524 'label_off' => __('Hide', 'embedpress'),
525 'return_value' => 'yes',
526 'default' => 'yes',
527 'condition' => [
528 'pdf_toolbar' => 'yes',
529 'embedpress_pdf_viewer_style' => 'flip-book',
530 ],
531 ]
532 );
533 $this->add_control(
534 'pdf_bookmark',
535 [
536 'label' => __('Bookmark', 'embedpress'),
537 'type' => Controls_Manager::SWITCHER,
538 'label_on' => __('Show', 'embedpress'),
539 'label_off' => __('Hide', 'embedpress'),
540 'return_value' => 'yes',
541 'default' => 'yes',
542 'condition' => [
543 'pdf_toolbar' => 'yes',
544 'embedpress_pdf_viewer_style' => 'flip-book',
545 ],
546 ]
547 );
548
549 $this->add_control(
550 'pdf_sound',
551 [
552 'label' => __('Flip Sound', 'embedpress'),
553 'type' => Controls_Manager::SWITCHER,
554 'label_on' => __('On', 'embedpress'),
555 'label_off' => __('Off', 'embedpress'),
556 'return_value' => 'yes',
557 'default' => 'yes',
558 'condition' => [
559 'embedpress_pdf_viewer_style' => 'flip-book',
560 ],
561 ]
562 );
563
564
565 $this->add_control(
566 'pdf_presentation_mode',
567 [
568 'label' => __('PDF Presentation Mode', 'embedpress'),
569 'type' => Controls_Manager::SWITCHER,
570 'label_on' => __('Show', 'embedpress'),
571 'label_off' => __('Hide', 'embedpress'),
572 'return_value' => 'yes',
573 'default' => 'yes',
574 'condition' => [
575 'pdf_toolbar' => 'yes',
576 ],
577 ]
578 );
579 $this->add_control(
580 'pdf_lazyload',
581 [
582 'label' => __('Lazy Load', 'embedpress'),
583 'type' => Controls_Manager::SWITCHER,
584 'label_on' => __('Yes', 'embedpress'),
585 'label_off' => __('No', 'embedpress'),
586 'return_value' => 'yes',
587 'default' => '',
588 'condition' => [
589 'pdf_toolbar' => 'yes',
590 ],
591 ]
592 );
593
594 $this->add_control(
595 'pdf_text_copy',
596 [
597 'label' => sprintf(__('Copy Text %s', 'embedpress'), $this->pro_text),
598 'type' => Controls_Manager::SWITCHER,
599 'label_on' => __('Show', 'embedpress'),
600 'label_off' => __('Hide', 'embedpress'),
601 'return_value' => 'yes',
602 'default' => 'yes',
603 'classes' => $this->pro_class,
604 'condition' => [
605 'pdf_toolbar' => 'yes',
606 'embedpress_pdf_viewer_style' => 'modern',
607 ],
608 ]
609 );
610
611 $this->add_control(
612 'add_text',
613 [
614 'label' => sprintf(__('Add Text', 'embedpress')),
615 'type' => Controls_Manager::SWITCHER,
616 'label_on' => __('Show', 'embedpress'),
617 'label_off' => __('Hide', 'embedpress'),
618 'return_value' => 'yes',
619 'default' => 'yes',
620 'condition' => [
621 'pdf_toolbar' => 'yes',
622 'embedpress_pdf_viewer_style' => 'modern',
623 ],
624 ]
625 );
626 $this->add_control(
627 'draw',
628 [
629 'label' => sprintf(__('Draw %s', 'embedpress'), $this->pro_text),
630 'type' => Controls_Manager::SWITCHER,
631 'label_on' => __('Show', 'embedpress'),
632 'label_off' => __('Hide', 'embedpress'),
633 'return_value' => 'yes',
634 'default' => 'yes',
635 'classes' => $this->pro_class,
636 'condition' => [
637 'pdf_toolbar' => 'yes',
638 'embedpress_pdf_viewer_style' => 'modern',
639 ],
640 ]
641 );
642
643 $this->add_control(
644 'add_image',
645 [
646 'label' => __('Add Image', 'embedpress'),
647 'type' => Controls_Manager::SWITCHER,
648 'label_on' => __('Show', 'embedpress'),
649 'label_off' => __('Hide', 'embedpress'),
650 'return_value' => 'yes',
651 'default' => 'yes',
652 'condition' => [
653 'pdf_toolbar' => 'yes',
654 'embedpress_pdf_viewer_style' => 'modern',
655 ],
656 ]
657 );
658 $this->add_control(
659 'pdf_rotate_access',
660 [
661 'label' => __('Rotation', 'embedpress'),
662 'type' => Controls_Manager::SWITCHER,
663 'label_on' => __('Show', 'embedpress'),
664 'label_off' => __('Hide', 'embedpress'),
665 'return_value' => 'yes',
666 'default' => 'yes',
667 'condition' => [
668 'pdf_toolbar' => 'yes',
669 'embedpress_pdf_viewer_style' => 'modern',
670 ],
671 ]
672 );
673
674 $this->add_control(
675 'pdf_details',
676 [
677 'label' => __('Properties', 'embedpress'),
678 'type' => Controls_Manager::SWITCHER,
679 'label_on' => __('Show', 'embedpress'),
680 'label_off' => __('Hide', 'embedpress'),
681 'return_value' => 'yes',
682 'default' => 'yes',
683 'condition' => [
684 'pdf_toolbar' => 'yes',
685 'embedpress_pdf_viewer_style' => 'modern',
686 ],
687 ]
688 );
689
690 $this->add_control(
691 'selection_tool',
692 [
693 'label' => sprintf(__('Default Selection Tool %s', 'embedpress'), $this->pro_text),
694 'type' => \Elementor\Controls_Manager::SELECT,
695 'options' => [
696 '0' => esc_html__('Text Tool', 'embedpress'),
697 '1' => esc_html__('Hand Tool', 'embedpress'),
698 ],
699 'default' => '0',
700 'classes' => $this->pro_class,
701
702 ]
703 );
704
705 $this->add_control(
706 'scrolling',
707 [
708 'label' => sprintf(__('Default Scrolling %s', 'embedpress'), $this->pro_text),
709 'type' => \Elementor\Controls_Manager::SELECT,
710 'options' => [
711 '-1' => esc_html__('Page Scrolling', 'embedpress'),
712 '0' => esc_html__('Vertical Scrolling', 'embedpress'),
713 '1' => esc_html__('Horizontal Scrolling', 'embedpress'),
714 '2' => esc_html__('Wrapped Scrolling', 'embedpress'),
715 ],
716 'default' => '0',
717 'classes' => $this->pro_class,
718 ]
719 );
720
721 $this->add_control(
722 'spreads',
723 [
724 'label' => esc_html__('Default Spreads', 'embedpress'),
725 'type' => \Elementor\Controls_Manager::SELECT,
726 'options' => [
727 '0' => esc_html__('No Spreads', 'embedpress'),
728 '1' => esc_html__('Odd Spreads', 'embedpress'),
729 '2' => esc_html__('Even Spreads', 'embedpress'),
730 ],
731 'default' => '-1',
732 'condition' => [
733 'scrolling!' => '1',
734 ],
735 ]
736 );
737
738 $this->end_controls_section();
739
740 do_action( 'extend_elementor_controls', $this, '_pdf_', $this->pro_text, $this->pro_class);
741
742 }
743
744 private function is_pdf($url)
745 {
746 $arr = explode('.', $url);
747 return end($arr) === 'pdf';
748 }
749
750 public function render()
751 {
752 $settings = $this->get_settings();
753
754 Helper::get_enable_settings_data_for_scripts($settings);
755
756 $url = $this->get_file_url();
757
758 if ($settings['embedpress_pdf_type'] === 'url') {
759 if (!empty($settings['__dynamic__']['embedpress_pdf_file_link'])) {
760 $decode_url = urldecode($settings['__dynamic__']['embedpress_pdf_file_link']);
761 preg_match('/name="([^"]+)"/', $decode_url, $name_matches);
762
763 if (!empty($name_matches[1])) {
764 $name_key = $name_matches[1];
765 $pattern = '';
766
767 if ($name_key === 'acf-url' && class_exists('ACF') && function_exists('get_field')) {
768 $pattern = '/"key":"[^"]+:(.*?)"/';
769 } elseif ($name_key === 'toolset-url' && class_exists('Types_Helper_Output_Meta_Box')) {
770 $pattern = '/"key":"[^"]+:(.*?)"/';
771 } elseif ($name_key === 'jet-post-custom-field' && class_exists('Jet_Engine')) {
772 $pattern = '/"meta_field":"([^"]+)"/';
773 }
774
775 if ($pattern) {
776 preg_match($pattern, $decode_url, $matches);
777
778 if (!empty($matches[1])) {
779 $get_field_key = sanitize_key($matches[1]);
780
781 $url = '';
782
783 if ($name_key === 'acf-url') {
784 $url = get_field($get_field_key);
785 } elseif ($name_key === 'toolset-url') {
786 $url = get_post_meta(get_the_ID(), 'wpcf-' . $get_field_key, true);
787 } elseif ($name_key === 'jet-post-custom-field') {
788 $url = get_post_meta(get_the_ID(), $get_field_key, true);
789 }
790
791 $url = apply_filters('embedpress/custom_meta_field_value', $url, $get_field_key);
792
793 // Fallback if empty
794 if (empty($url)) {
795 preg_match('/"fallback":"([^"]+)"/', $decode_url, $fallback_matches);
796 if (!empty($fallback_matches[1])) {
797 $url = $fallback_matches[1];
798 }
799 }
800
801 // Final sanitization
802 $url = esc_url_raw($url);
803 }
804 }
805 }
806 }
807 }
808
809 $client_id = $this->get_id();
810
811 $this->_render($url, $settings, $client_id);
812 Helper::get_source_data(md5($this->get_id()).'_eb_elementor', $url, 'elementor_source_data', 'elementor_temp_source_data');
813 }
814
815
816 public function getParamData($settings){
817 $urlParamData = array(
818 'themeMode' => $settings['embedpress_theme_mode'],
819 'toolbar' => !empty($settings['pdf_toolbar']) ? 'true' : 'false',
820 'position' => $settings['pdf_toolbar_position'],
821 'presentation' => !empty($settings['pdf_presentation_mode']) ? 'true' : 'false',
822 'lazyLoad' => !empty($settings['pdf_lazyload']) ? 'true' : 'false',
823 'download' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['pdf_print_download'] : 'true',
824 'copy_text' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['pdf_text_copy'] : 'true',
825 'add_text' => !empty($settings['add_text']) ? 'true' : 'false',
826 'draw' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['draw'] : 'true',
827 'add_image' => !empty($settings['add_image']) ? 'true' : 'false',
828 'pdf_rotation' => !empty($settings['pdf_rotate_access']) ? 'true' : 'false',
829 'pdf_details' => !empty($settings['pdf_details']) ? 'true' : 'false',
830 'zoom_in' => !empty($settings['pdf_zoom_in']) ? 'true' : 'false',
831 'zoom_out' => !empty($settings['pdf_zoom_out']) ? 'true' : 'false',
832 'fit_view' => !empty($settings['pdf_fit_view']) ? 'true' : 'false',
833 'bookmark' => !empty($settings['pdf_bookmark']) ? 'true' : 'false',
834 'sound' => !empty($settings['pdf_sound']) ? 'true' : 'false',
835 'flipbook_toolbar_position' => !empty($settings['flipbook_toolbar_position']) ? $settings['flipbook_toolbar_position'] : 'bottom',
836 'selection_tool' => isset($settings['selection_tool']) ? esc_attr($settings['selection_tool']) : '0',
837 'scrolling' => isset($settings['scrolling']) ? esc_attr($settings['scrolling']) : '-1',
838 'spreads' => isset($settings['spreads']) ? esc_attr($settings['spreads']) : '-1',
839 'is_pro_active' => apply_filters('embedpress/is_allow_rander', false)
840
841 );
842
843 $custom_color = Helper::get_elementor_global_color($settings, 'embedpress_pdf_custom_color');
844
845 if($settings['embedpress_theme_mode'] == 'custom') {
846 $urlParamData['customColor'] = $custom_color;
847 }
848
849 if($settings['embedpress_pdf_viewer_style'] == 'flip-book'){
850 return "&key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), "UTF-8"));
851 }
852
853 return "#key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), "UTF-8"));
854
855 }
856
857 public function _render($url, $settings, $id)
858 {
859
860 $custom_color = Helper::get_elementor_global_color($settings, 'embedpress_pdf_custom_color');
861
862 $unitoption = 'emebedpress-unit-px';
863 if($settings['embedpress_elementor_document_width']['unit'] === '%'){
864 $unitoption = 'emebedpress-unit-percent';
865 }
866 $client_id = $id;
867 $id = 'embedpress-pdf-' . $id;
868 $hash_pass = hash('sha256', wp_salt(32) . md5($settings['embedpress_pdf_lock_content_password']));
869
870 $dimension = '';
871
872 $password_correct = isset($_COOKIE['password_correct_' . $client_id]) ? sanitize_text_field($_COOKIE['password_correct_' . $client_id]) : '';
873
874 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))){
875 $dimension = "width: {$settings['embedpress_elementor_document_width']['size']}{$settings['embedpress_elementor_document_width']['unit']}!important;height: {$settings['embedpress_elementor_document_height']['size']}px;";
876 }
877
878 $content_protection_class = 'ep-content-protection-enabled';
879 $content_locked_class = 'ep-content-locked';
880 if(empty($settings['embedpress_pdf_lock_content']) || empty($settings['embedpress_pdf_lock_content_password']) || $hash_pass === $password_correct) {
881 $content_locked_class = '';
882 $content_protection_class = 'ep-content-protection-disabled';
883 }
884
885 $pass_hash_key = md5($settings['embedpress_pdf_lock_content_password']);
886 // Generate content ID for analytics tracking
887 $content_id = md5($url . 'pdf-elementor');
888
889 // Track PDF widget usage for analytics
890 $this->track_pdf_widget_usage($settings, $url, $content_id);
891
892 $this->add_render_attribute('embedpres-pdf-render', [
893 'class' => ['embedpress-embed-document-pdf', esc_attr($id)],
894 'data-emid' => esc_attr($id),
895 // 'data-embedpress-content' => esc_attr($content_id),
896 'data-embed-type' => 'PDF'
897 ]);
898 $this->add_render_attribute('embedpress-document', [
899 'class' => ['embedpress-document-embed', 'ep-doc-' . md5($id), 'ose-document', $unitoption, $content_locked_class ],
900 'data-thememode' => isset($settings['embedpress_theme_mode']) ? esc_attr($settings['embedpress_theme_mode']) : '',
901 'data-customcolor' => isset($custom_color) ? esc_attr($custom_color) : '',
902 'data-toolbar' => isset($settings['pdf_toolbar']) ? esc_attr($settings['pdf_toolbar']) : '',
903 'data-toolbar-position' => isset($settings['pdf_toolbar_position']) ? esc_attr($settings['pdf_toolbar_position']) : 'top',
904 'data-open' => 'no', // Assuming 'no' is a static value, no need to sanitize
905 'data-presentation-mode' => isset($settings['pdf_presentation_mode']) ? esc_attr($settings['pdf_presentation_mode']) : '',
906 'data-download' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION') ? esc_attr($settings['pdf_print_download']) : 'yes', // Assuming 'yes' is a safe fallback
907 'data-copy' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION') ? esc_attr($settings['pdf_text_copy']) : 'yes', // Assuming 'yes' is a safe fallback
908 'data-add-image' => isset($settings['add_image']) ? esc_attr($settings['add_image']) : '',
909 'data-rotate' => isset($settings['pdf_rotate_access']) ? esc_attr($settings['pdf_rotate_access']) : '',
910 'data-details' => isset($settings['pdf_details']) ? esc_attr($settings['pdf_details']) : '',
911 'data-id' => $id, // Assuming $id is safe, no need to sanitize
912 'data-selection-tool' => isset($settings['selection_tool']) ? esc_attr($settings['selection_tool']) : '0',
913 'data-scrolling' => isset($settings['scrolling']) ? esc_attr($settings['scrolling']) : '-1',
914 'data-spreads' => isset($settings['spreads']) ? esc_attr($settings['spreads']) : '-1',
915 ]);
916
917 $embed_settings = [];
918 $embed_settings['customThumbnail'] = !empty($settings['embedpress_pdf_content_share_custom_thumbnail']['url']) ? esc_url($settings['embedpress_pdf_content_share_custom_thumbnail']['url']) : '';
919
920 $embed_settings['customTitle'] = !empty($settings['embedpress_pdf_content_title']) ? sanitize_text_field($settings['embedpress_pdf_content_title']) : Helper::get_file_title($url);
921
922 $embed_settings['customDescription'] = !empty($settings['embedpress_pdf_content_descripiton']) ? sanitize_text_field($settings['embedpress_pdf_content_descripiton']) : Helper::get_file_title($url);
923
924 $embed_settings['sharePosition'] = !empty($settings['embedpress_pdf_content_share_position']) ? sanitize_text_field($settings['embedpress_pdf_content_share_position']) : 'right';
925
926 // Add social share platform settings
927 $embed_settings['shareFacebook'] = !empty($settings['embedpress_pdf_share_facebook']) ? true : false;
928 $embed_settings['shareTwitter'] = !empty($settings['embedpress_pdf_share_twitter']) ? true : false;
929 $embed_settings['sharePinterest'] = !empty($settings['embedpress_pdf_share_pinterest']) ? true : false;
930 $embed_settings['shareLinkedin'] = !empty($settings['embedpress_pdf_share_linkedin']) ? true : false;
931
932 $embed_settings['lockHeading'] = !empty($settings['embedpress_pdf_lock_content_heading']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_heading']) : '';
933
934 $embed_settings['lockSubHeading'] = !empty($settings['embedpress_pdf_lock_content_sub_heading']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_sub_heading']) : '';
935
936 $embed_settings['lockErrorMessage'] = !empty($settings['embedpress_pdf_lock_content_error_message']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_error_message']) : '';
937
938 $embed_settings['passwordPlaceholder'] = !empty($settings['embedpress_pdf_password_placeholder']) ? sanitize_text_field($settings['embedpress_pdf_password_placeholder']) : '';
939
940 $embed_settings['submitButtonText'] = !empty($settings['embedpress_pdf_submit_button_text']) ? sanitize_text_field($settings['embedpress_pdf_submit_button_text']) : '';
941
942 $embed_settings['submitUnlockingText'] = !empty($settings['embedpress_pdf_submit_Unlocking_text']) ? sanitize_text_field($settings['embedpress_pdf_submit_Unlocking_text']) : '';
943
944 $embed_settings['enableFooterMessage'] = !empty($settings['embedpress_pdf_enable_footer_message']) ? sanitize_text_field($settings['embedpress_pdf_enable_footer_message']) : '';
945
946 $embed_settings['footerMessage'] = !empty($settings['embedpress_pdf_lock_content_footer_message']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_footer_message']) : '';
947
948 $embed_settings['userRole'] = !empty($settings['embedpress_pdf_select_roles']) ? $settings['embedpress_pdf_select_roles'] : [];
949
950 $embed_settings['protectionMessage'] = !empty($settings['embedpress_pdf_protection_message']) ? $settings['embedpress_pdf_protection_message'] : '';
951
952
953 if($settings['embedpress_elementor_document_width']['unit'] === '%'){
954 $width_class = ' ep-percentage-width';
955 }
956 else{
957 $width_class = 'ep-fixed-width';
958 }
959 $content_share_class = '';
960 $share_position_class = '';
961 $share_position = isset($settings['embedpress_pdf_content_share_position']) ? $settings['embedpress_pdf_content_share_position'] : 'right';
962
963 if(!empty($settings['embedpress_pdf_content_share'])) {
964 $content_share_class = 'ep-content-share-enabled';
965 $share_position_class = 'ep-share-position-'.$share_position;
966 }
967
968 $adsAtts = '';
969
970 if (!empty($settings['adManager'])) {
971 $ad = base64_encode(json_encode($settings)); // Using WordPress JSON encoding function
972 $adsAtts = 'data-sponsored-id="' . esc_attr($client_id) . '" data-sponsored-attrs="' . esc_attr($ad) . '" class="sponsored-mask"';
973 }
974
975 ?>
976 <div <?php echo $this->get_render_attribute_string('embedpress-document'); ?> style=" max-width:100%; display: inline-block">
977
978 <?php
979 do_action('embedpress_pdf_after_embed', $settings, $url, $id, $this);
980
981 if ($url != '') {
982 $url = esc_url($url);
983
984 if ($this->is_pdf($url) && !$this->is_external_url($url)) {
985 $renderer = Helper::get_pdf_renderer();
986 $src = $renderer . ((strpos($renderer, '?') === false) ? '?' : '&')
987 . 'file=' . urlencode($url)
988 . '&scrolling=' . $settings['scrolling']
989 . '&selection_tool=' . $settings['selection_tool']
990 . '&spreads=' . $settings['spreads']
991 . $this->getParamData($settings);
992
993
994 if (!empty($settings['embedpress_pdf_zoom'])) {
995 $zoom = $settings['embedpress_pdf_zoom'];
996 if ($zoom == 'custom') {
997 if (!empty($settings['embedpress_pdf_zoom_custom'])) {
998 $zoom = $settings['embedpress_pdf_zoom_custom'];
999 } else {
1000 $zoom = null;
1001 }
1002 }
1003 if ($zoom) {
1004 $src = $src . "&zoom=$zoom";
1005 }
1006 }
1007
1008 if(isset($settings['embedpress_pdf_viewer_style']) && $settings['embedpress_pdf_viewer_style'] === 'modern') {
1009 $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).'"';
1010 }
1011 else{
1012 $src = urlencode($url).$this->getParamData($settings);
1013 $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).'"';
1014 }
1015
1016
1017 $embed_content .= ' '.$this->get_render_attribute_string('embedpres-pdf-render').' frameborder="0"></iframe>';
1018 if ($settings['embedpress_pdf_powered_by'] === 'yes') {
1019 $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
1020 }
1021
1022 } else {
1023 $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).'"';
1024 $embed_content .= ' '.$this->get_render_attribute_string('embedpres-pdf-render').'></iframe>';
1025
1026 if ($settings['embedpress_pdf_powered_by'] === 'yes') {
1027 $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
1028 }
1029 }
1030
1031 ?>
1032
1033 <div <?php echo $adsAtts; ?>>
1034
1035 <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); ?>">
1036 <div id="<?php echo esc_attr( $this->get_id() ); ?>" class="ep-embed-content-wraper">
1037 <?php
1038 $embed = '<div>'.$embed_content.'</div>';
1039
1040 $content_id = $client_id;
1041 if(
1042
1043 (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') ||
1044 ($settings['embedpress_pdf_protection_type'] == 'password' && !empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct) ) ||
1045 !apply_filters('embedpress/is_allow_rander', false) ||
1046 ($settings['embedpress_pdf_protection_type'] == 'user-role' && Helper::has_allowed_roles($embed_settings['userRole']))
1047
1048 ){
1049 if(!empty($settings['embedpress_pdf_content_share'])){
1050 $embed .= Helper::embed_content_share($content_id, $embed_settings);
1051 }
1052 echo $embed ;
1053
1054 } else {
1055 if(!empty($settings['embedpress_pdf_content_share'])){
1056 $embed .= Helper::embed_content_share($content_id, $embed_settings);
1057 }
1058
1059 if ($settings['embedpress_pdf_protection_type'] == 'password') {
1060 do_action('embedpress/display_password_form', $client_id, $embed, $pass_hash_key, $embed_settings);
1061 } else {
1062 do_action('embedpress/content_protection_content', $client_id, $embed_settings['protectionMessage'], $embed_settings['userRole']);
1063 }
1064 }
1065 ?>
1066 </div>
1067
1068 </div>
1069
1070
1071 <?php
1072 $isAdEnabled = !empty($settings['adManager']);
1073 $isContentUnlocked = empty($settings['embedpress_pdf_lock_content']);
1074 $isPasswordCorrect = Helper::is_password_correct($client_id) && ($hash_pass === $password_correct);
1075
1076 if ($isAdEnabled && ($isContentUnlocked || $isPasswordCorrect)) {
1077 $embed_content = apply_filters('embedpress/generate_ad_template', $embed_content, $client_id, $settings, 'elementor');
1078 }
1079 ?>
1080
1081 </div>
1082 <?php
1083
1084 }
1085 ?>
1086
1087 </div>
1088
1089 <?php
1090 }
1091
1092 private function get_file_url()
1093 {
1094 $settings = $this->get_settings();
1095 return $settings['embedpress_pdf_type'] === 'url' ? $settings['embedpress_pdf_file_link']['url'] : $settings['embedpress_pdf_Uploader']['url'];
1096 }
1097
1098 protected function is_external_url($url)
1099 {
1100 return strpos($url, get_site_url()) === false;
1101 }
1102
1103 /**
1104 * Track PDF widget usage for analytics
1105 *
1106 * @param array $settings
1107 * @param string $url
1108 * @param string $content_id
1109 * @return void
1110 */
1111 private function track_pdf_widget_usage($settings, $url, $content_id)
1112 {
1113 // Only track if analytics is enabled and we have the necessary classes
1114 if (class_exists('EmbedPress\Includes\Classes\Analytics\Analytics_Manager')) {
1115 if (empty($url)) {
1116 return;
1117 }
1118
1119 $provider_name = 'PDF';
1120
1121 $tracking_data = [
1122 'embed_type' => $provider_name,
1123 'embed_url' => $url,
1124 'post_id' => get_the_ID(),
1125 'page_url' => get_permalink(),
1126 'title' => get_the_title()
1127 ];
1128
1129 // Track content creation
1130 do_action('embedpress_content_embedded', $content_id, 'elementor-pdf', $tracking_data);
1131 }
1132 }
1133 }
1134