PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 4.5.4
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v4.5.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 month ago Embedpress_Document.php 1 month ago Embedpress_Elementor.php 2 months ago Embedpress_Pdf.php 1 month ago Embedpress_Pdf_Gallery.php 2 months ago
Embedpress_Pdf.php
1489 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\DynamicFieldResolver;
14 use EmbedPress\Includes\Classes\Helper;
15 use EmbedPress\Includes\Traits\Branding;
16
17
18
19 (defined('ABSPATH')) or die("No direct script access allowed.");
20
21 class Embedpress_Pdf extends Widget_Base
22 {
23
24 use Branding;
25 protected $pro_class = '';
26 protected $pro_text = '';
27 public function get_name()
28 {
29 return 'embedpress_pdf';
30 }
31
32 public function get_title()
33 {
34 return esc_html__('EmbedPress PDF', 'embedpress');
35 }
36
37 public function get_categories()
38 {
39 return ['embedpress'];
40 }
41
42 public function get_custom_help_url()
43 {
44 return 'https://embedpress.com/documentation';
45 }
46
47 public function get_icon()
48 {
49 return 'icon-pdf';
50 }
51
52 public function get_style_depends()
53 {
54 return [
55 'embedpress-elementor-css',
56 'embedpress-css',
57 ];
58 }
59
60 public function get_script_depends()
61 {
62
63 $handler_keys = get_option('enabled_elementor_scripts', []);
64
65 $handles = [];
66
67 $handles[] = 'embedpress-pdfobject';
68 $handles[] = 'embedpress-front';
69
70 if (isset($handler_keys['enabled_ads']) && $handler_keys['enabled_ads'] === 'yes') {
71 $handles[] = 'embedpress-ads';
72 }
73
74 return $handles;
75 }
76
77 /**
78 * Get widget keywords.
79 *
80 * Retrieve the list of keywords the widget belongs to.
81 *
82 * @return array Widget keywords.
83 * @since 2.5.5
84 * @access public
85 *
86 */
87 public function get_keywords()
88 {
89 return ['embedpress', 'pdf', 'doc', 'embedpress-document'];
90 }
91
92
93 /**
94 * Performance Settings Section
95 */
96 public function init_performance_controls()
97 {
98 // Get global lazy load setting
99 $g_settings = get_option(EMBEDPRESS_PLG_NAME, []);
100 $lazy_load_default = isset($g_settings['g_lazyload']) && $g_settings['g_lazyload'] == 1 ? 'yes' : '';
101
102 $this->start_controls_section(
103 'embedpress_performance_section',
104 [
105 'label' => __('Performance', 'embedpress'),
106 ]
107 );
108
109 $this->add_control(
110 'enable_lazy_load',
111 [
112 'label' => sprintf(__('Enable Lazy Loading %s', 'embedpress'), $this->pro_text),
113 'type' => \Elementor\Controls_Manager::SWITCHER,
114 'label_on' => __('Yes', 'embedpress'),
115 'label_off' => __('No', 'embedpress'),
116 'return_value' => 'yes',
117 'default' => $lazy_load_default,
118 'description' => __('Load iframe only when it enters the viewport for better performance', 'embedpress'),
119 'classes' => $this->pro_class,
120 ]
121 );
122
123 $this->end_controls_section();
124 }
125
126 protected function register_controls()
127 {
128 $class = 'embedpress-pro-control not-active';
129 $text = '<sup class="embedpress-pro-label" style="color:red">' . __('Pro', 'embedpress') . '</sup>';
130 $this->pro_class = apply_filters('embedpress/pro_class', $class);
131 $this->pro_text = apply_filters('embedpress/pro_text', $text);
132
133 /**
134 * EmbedPress Content Settings
135 */
136 $this->start_controls_section(
137 'embedpress_content_settings',
138 [
139 'label' => esc_html__('General', 'embedpress'),
140 ]
141 );
142
143 $this->add_control(
144 'embedpress_pdf_type',
145 [
146 'label' => __('Document Type', 'embedpress'),
147 'type' => Controls_Manager::SELECT,
148 'default' => 'file',
149 'options' => [
150 'file' => __('File', 'embedpress'),
151 'url' => __('URL', 'embedpress')
152 ],
153 ]
154 );
155
156 $this->add_control(
157 'embedpress_pdf_file_link_from',
158 [
159 'label' => __( 'URL From', 'embedpress' ),
160 'type' => Controls_Manager::SELECT,
161 'default' => 'external',
162 'options' => [
163 'self' => __( 'Self', 'embedpress' ),
164 'external' => __( 'External', 'embedpress' )
165 ],
166 'condition' => [
167 'embedpress_pdf_type' => 'url'
168 ]
169 ]
170 );
171
172 $this->add_control(
173 'embedpress_pdf_Uploader',
174 [
175 'label' => __('Upload File', 'embedpress'),
176 'type' => Controls_Manager::MEDIA,
177 'dynamic' => [
178 'active' => true,
179 'categories' => [
180 TagsModule::MEDIA_CATEGORY,
181 ],
182 ],
183 'media_type' => [
184 'application/pdf',
185 ],
186 'description' => __(
187 'Upload a file or pick one from your media library for embed. Supported File Type: PDF',
188 'embedpress'
189 ),
190 'condition' => [
191 'embedpress_pdf_type' => 'file'
192 ],
193 ]
194 );
195
196 $this->add_control(
197 'embedpress_pdf_file_link',
198 [
199 'label' => __('URL', 'embedpress'),
200 'type' => Controls_Manager::URL,
201 'placeholder' => __('https://your-link.com/file.pdf', 'embedpress'),
202 'dynamic' => [
203 'active' => true,
204 ],
205 'show_external' => false,
206 'dynamic' => [
207 'active' => true,
208 ],
209 'default' => [
210 'url' => ''
211 ],
212 'condition' => [
213 'embedpress_pdf_type' => 'url'
214 ],
215 ]
216 );
217
218
219 $this->add_control(
220 'embedpress_pdf_viewer_style',
221 [
222 'label' => __('Viewer Style', 'embedpress'),
223 'type' => Controls_Manager::SELECT,
224 'default' => 'modern',
225 'options' => [
226 'modern' => __('Modern', 'embedpress'),
227 'flip-book' => __('Flip Book', 'embedpress'),
228 ],
229 'conditions' => [
230 'relation' => 'or',
231 'terms' => [
232 ['name' => 'embedpress_pdf_type', 'operator' => '===', 'value' => 'file'],
233 ['name' => 'embedpress_pdf_file_link_from', 'operator' => '===', 'value' => 'self'],
234 ],
235 ],
236 ]
237 );
238
239 $this->add_control(
240 'embedpress_pdf_display_mode',
241 [
242 'label' => __('Display Mode', 'embedpress'),
243 'type' => Controls_Manager::SELECT,
244 'default' => 'inline',
245 'options' => [
246 'inline' => __('Inline Viewer', 'embedpress'),
247 'lightbox' => __('Thumbnail + Lightbox', 'embedpress'),
248 'button' => __('Button + Lightbox', 'embedpress'),
249 'link' => __('Link + Lightbox', 'embedpress'),
250 'text' => __('Text + Lightbox', 'embedpress'),
251 ],
252 'conditions' => [
253 'relation' => 'or',
254 'terms' => [
255 ['name' => 'embedpress_pdf_type', 'operator' => '===', 'value' => 'file'],
256 ['name' => 'embedpress_pdf_file_link_from', 'operator' => '===', 'value' => 'self'],
257 ],
258 ],
259 ]
260 );
261
262 $this->add_control(
263 'embedpress_pdf_lightbox_thumbnail',
264 [
265 'label' => sprintf(__('Custom Thumbnail %s', 'embedpress'), $this->pro_text),
266 'type' => Controls_Manager::MEDIA,
267 'default' => ['url' => ''],
268 'condition' => [
269 'embedpress_pdf_display_mode' => 'lightbox',
270 ],
271 'classes' => $this->pro_class,
272 ]
273 );
274
275 $this->add_control(
276 'embedpress_pdf_lightbox_align',
277 [
278 'label' => __('Thumbnail Alignment', 'embedpress'),
279 'type' => Controls_Manager::CHOOSE,
280 'options' => [
281 'left' => ['title' => __('Left', 'embedpress'), 'icon' => 'eicon-text-align-left'],
282 'center' => ['title' => __('Center', 'embedpress'), 'icon' => 'eicon-text-align-center'],
283 'right' => ['title' => __('Right', 'embedpress'), 'icon' => 'eicon-text-align-right'],
284 ],
285 'default' => 'left',
286 'condition' => [
287 'embedpress_pdf_display_mode' => 'lightbox',
288 ],
289 ]
290 );
291
292 $this->add_control(
293 'embedpress_pdf_trigger_text',
294 [
295 'label' => __('Display Text', 'embedpress'),
296 'type' => Controls_Manager::TEXT,
297 'default' => 'View PDF',
298 'condition' => [
299 'embedpress_pdf_display_mode' => ['button', 'link', 'text'],
300 ],
301 ]
302 );
303
304 $this->add_control(
305 'embedpress_pdf_trigger_color',
306 [
307 'label' => __('Text Color', 'embedpress'),
308 'type' => Controls_Manager::COLOR,
309 'condition' => [
310 'embedpress_pdf_display_mode' => ['button', 'link', 'text'],
311 ],
312 'selectors' => [
313 '{{WRAPPER}} .ep-pdf-trigger' => 'color: {{VALUE}};',
314 ],
315 ]
316 );
317
318 $this->add_control(
319 'embedpress_pdf_trigger_bg_color',
320 [
321 'label' => __('Background Color', 'embedpress'),
322 'type' => Controls_Manager::COLOR,
323 'condition' => [
324 'embedpress_pdf_display_mode' => 'button',
325 ],
326 'selectors' => [
327 '{{WRAPPER}} .ep-pdf-trigger--button' => 'background-color: {{VALUE}};',
328 ],
329 ]
330 );
331
332 $this->add_group_control(
333 \Elementor\Group_Control_Typography::get_type(),
334 [
335 'name' => 'embedpress_pdf_trigger_typography',
336 'label' => __('Typography', 'embedpress'),
337 'condition' => [
338 'embedpress_pdf_display_mode' => ['button', 'link', 'text'],
339 ],
340 'selector' => '{{WRAPPER}} .ep-pdf-trigger',
341 ]
342 );
343
344 $this->add_responsive_control(
345 'embedpress_pdf_trigger_padding',
346 [
347 'label' => __('Padding', 'embedpress'),
348 'type' => Controls_Manager::DIMENSIONS,
349 'size_units' => ['px', 'em', '%'],
350 'condition' => [
351 'embedpress_pdf_display_mode' => 'button',
352 ],
353 'selectors' => [
354 '{{WRAPPER}} .ep-pdf-trigger--button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
355 ],
356 ]
357 );
358
359 $this->add_control(
360 'embedpress_pdf_trigger_border_radius',
361 [
362 'label' => __('Border Radius', 'embedpress'),
363 'type' => Controls_Manager::SLIDER,
364 'size_units' => ['px', '%'],
365 'range' => ['px' => ['min' => 0, 'max' => 50]],
366 'condition' => [
367 'embedpress_pdf_display_mode' => 'button',
368 ],
369 'selectors' => [
370 '{{WRAPPER}} .ep-pdf-trigger--button' => 'border-radius: {{SIZE}}{{UNIT}};',
371 ],
372 ]
373 );
374
375 $this->add_control(
376 'embedpress_pdf_zoom',
377 [
378 'label' => __('Zoom', 'embedpress'),
379 'type' => Controls_Manager::SELECT,
380 'default' => 'auto',
381 'options' => [
382 'auto' => __('Automatic Zoom', 'embedpress'),
383 'page-actual' => __('Actual Size', 'embedpress'),
384 'page-fit' => __('Page Fit', 'embedpress'),
385 'page-width' => __('Page Width', 'embedpress'),
386 'custom' => __('Custom', 'embedpress'),
387 '50' => __('50%', 'embedpress'),
388 '75' => __('75%', 'embedpress'),
389 '100' => __('100%', 'embedpress'),
390 '125' => __('125%', 'embedpress'),
391 '150' => __('150%', 'embedpress'),
392 '200' => __('200%', 'embedpress'),
393 '300' => __('300%', 'embedpress'),
394 '400' => __('400%', 'embedpress'),
395 ],
396 'condition' => [
397 'embedpress_pdf_viewer_style' => 'modern'
398 ]
399 ]
400 );
401 $this->add_control(
402 'embedpress_pdf_zoom_custom',
403 [
404 'label' => __('Custom Zoom', 'embedpress'),
405 'type' => Controls_Manager::NUMBER,
406 'condition' => [
407 'embedpress_pdf_zoom' => 'custom'
408 ],
409 ]
410 );
411 $this->add_control(
412 'embedpress_pdf_page_number',
413 [
414 'label' => __('Open at Page', 'embedpress'),
415 'description' => __('Set the page number to open the PDF at. Visitors can also use ?eppage=N in the URL.', 'embedpress'),
416 'type' => Controls_Manager::NUMBER,
417 'default' => 1,
418 'min' => 1,
419 ]
420 );
421 $this->add_responsive_control(
422 'embedpress_elementor_document_width',
423 [
424 'type' => \Elementor\Controls_Manager::SLIDER,
425 'label' => esc_html__( 'Width', 'embedpress' ),
426 'size_units' => [ 'px', '%' ],
427 'range' => [
428 'px' => [
429 'min' => 1,
430 'max' => 1500,
431 ],
432 ],
433 'devices' => [ 'desktop', 'tablet', 'mobile' ],
434 'default' => [
435 'unit' => '%',
436 'size' => !empty($value = intval(Helper::get_options_value('enableEmbedResizeWidth'))) ? $value : 600,
437 ],
438 'desktop_default' => [
439 'unit' => 'px',
440 'size' => 600,
441 ],
442 'tablet_default' => [
443 'size' => 400,
444 'unit' => 'px',
445 ],
446 'mobile_default' => [
447 'size' => 300,
448 'unit' => 'px',
449 ],
450 'selectors' => [
451 '{{WRAPPER}} .embedpress-document-embed iframe, , {{WRAPPER}} .ep-share-position-bottom .ep-embed-content-wraper' => 'width: {{SIZE}}{{UNIT}}!important; max-width: {{SIZE}}{{UNIT}}!important',
452 // '{{WRAPPER}} .embedpress-document-embed' => 'width: {{SIZE}}{{UNIT}}; max-width: 100%',
453 // '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%',
454 ],
455 'render_type' => 'template',
456 ]
457 );
458 $this->add_responsive_control(
459 'embedpress_elementor_document_height',
460 [
461 'type' => \Elementor\Controls_Manager::SLIDER,
462 'label' => esc_html__( 'Height', 'embedpress' ),
463 'range' => [
464 'px' => [
465 'min' => 1,
466 'max' => 2000,
467 ],
468 ],
469 'devices' => [ 'desktop', 'tablet', 'mobile' ],
470 'default' => [
471 'unit' => 'px',
472 'size' => !empty($value = intval(Helper::get_options_value('enableEmbedResizeHeight'))) ? $value : 600,
473
474 ],
475 'desktop_default' => [
476 'unit' => 'px',
477 'size' => 600,
478 ],
479 'tablet_default' => [
480 'size' => 400,
481 'unit' => 'px',
482 ],
483 'mobile_default' => [
484 'size' => 300,
485 'unit' => 'px',
486 ],
487 'selectors' => [
488 '{{WRAPPER}} .embedpress-document-embed iframe' => 'height: {{SIZE}}{{UNIT}}!important;',
489 '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'height: {{SIZE}}{{UNIT}}!important;',
490 ],
491 'render_type' => 'template',
492 ]
493 );
494
495 $this->add_responsive_control(
496 'embedpress_elementor_document_align',
497 [
498 'label' => __('Alignment', 'embedpress'),
499 'type' => Controls_Manager::CHOOSE,
500 'options' => [
501 'left' => [
502 'title' => __('Left', 'embedpress'),
503 'icon' => 'eicon-text-align-left',
504 ],
505 'center' => [
506 'title' => __('Center', 'embedpress'),
507 'icon' => 'eicon-text-align-center',
508 ],
509 'right' => [
510 'title' => __('Right', 'embedpress'),
511 'icon' => 'eicon-text-align-right',
512 ]
513 ],
514 'prefix_class' => 'elementor%s-align-',
515 'default' => '',
516 ]
517 );
518
519 // Get global powered_by setting
520 $g_settings = get_option(EMBEDPRESS_PLG_NAME, []);
521 $powered_by_default = isset($g_settings['embedpress_document_powered_by']) && $g_settings['embedpress_document_powered_by'] === 'yes' ? 'yes' : 'no';
522
523 $this->add_control(
524 'embedpress_pdf_powered_by',
525 [
526 'label' => __('Powered By', 'embedpress'),
527 'type' => Controls_Manager::SWITCHER,
528 'label_on' => __('Show', 'embedpress'),
529 'label_off' => __('Hide', 'embedpress'),
530 'return_value' => 'yes',
531 'default' => apply_filters('embedpress_document_powered_by_control', $powered_by_default),
532 'condition' => [
533 'embedpress_pdf_display_mode' => 'inline',
534 ],
535 ]
536 );
537
538 $this->init_branding_controls('document');
539
540 $this->end_controls_section();
541
542
543 /**
544 * EmbedPress PDF Control Settings
545 */
546
547 $this->start_controls_section(
548 'embedpress_pdf_content_settings',
549 [
550 'label' => esc_html__('Controls', 'embedpress'),
551 'conditions' => [
552 'relation' => 'or',
553 'terms' => [
554 ['name' => 'embedpress_pdf_type', 'operator' => '===', 'value' => 'file'],
555 ['name' => 'embedpress_pdf_file_link_from', 'operator' => '===', 'value' => 'self'],
556 ],
557 ],
558 ]
559 );
560
561
562 $this->add_control(
563 'embedpress_theme_mode',
564 [
565 'label' => __('Theme', 'embedpress'),
566 'type' => Controls_Manager::SELECT,
567 'default' => 'default',
568 'options' => [
569 'default' => __('System Default', 'embedpress'),
570 'dark' => __('Dark', 'embedpress'),
571 'light' => __('Light', 'embedpress'),
572 'custom' => __('Custom', 'embedpress')
573 ],
574 ]
575 );
576
577 $this->add_control(
578 'embedpress_pdf_custom_color',
579 [
580 'label' => esc_html__( 'Color', 'embedpress' ),
581 'type' => \Elementor\Controls_Manager::COLOR,
582 // 'default' => Helper::get_options_value('custom_color'),
583 'global' => [
584 'default' => Global_Colors::COLOR_PRIMARY,
585 ],
586 'condition' => [
587 'embedpress_theme_mode' => 'custom',
588 ],
589 ]
590 );
591
592 $this->add_control(
593 'pdf_toolbar',
594 [
595 'label' => sprintf(__('Toolbar %s', 'embedpress'), $this->pro_text),
596 'type' => Controls_Manager::SWITCHER,
597 'label_on' => __('Show', 'embedpress'),
598 'label_off' => __('Hide', 'embedpress'),
599 'return_value' => 'yes',
600 'default' => 'yes',
601 'classes' => $this->pro_class,
602 ]
603 );
604
605
606 $this->add_control(
607 'pdf_toolbar_position',
608 [
609 'label' => esc_html__('Toolbar Position', 'embedpress'),
610 'type' => \Elementor\Controls_Manager::CHOOSE,
611 'options' => [
612 'top' => [
613 'title' => esc_html__('Top', 'embedpress'),
614 'icon' => 'eicon-arrow-up',
615 ],
616 'bottom' => [
617 'title' => esc_html__('Bottom', 'embedpress'),
618 'icon' => 'eicon-arrow-down',
619 ],
620 ],
621 'default' => 'top',
622 'toggle' => true,
623 'condition' => [
624 'pdf_toolbar' => 'yes',
625 'embedpress_pdf_viewer_style' => 'modern',
626 ],
627 ]
628 );
629 $this->add_control(
630 'flipbook_toolbar_position',
631 [
632 'label' => esc_html__('Toolbar Position', 'embedpress'),
633 'type' => \Elementor\Controls_Manager::CHOOSE,
634 'options' => [
635 'top' => [
636 'title' => esc_html__('Top', 'embedpress'),
637 'icon' => 'eicon-arrow-up',
638 ],
639 'bottom' => [
640 'title' => esc_html__('Bottom', 'embedpress'),
641 'icon' => 'eicon-arrow-down',
642 ],
643 ],
644 'default' => 'bottom',
645 'toggle' => true,
646 'condition' => [
647 'pdf_toolbar' => 'yes',
648 'embedpress_pdf_viewer_style' => 'flip-book',
649 ],
650 ]
651 );
652
653
654 $this->add_control(
655 'pdf_print_download',
656 [
657 'label' => sprintf(__('Print/Download %s', 'embedpress'), $this->pro_text),
658 'type' => Controls_Manager::SWITCHER,
659 'label_on' => __('Show', 'embedpress'),
660 'label_off' => __('Hide', 'embedpress'),
661 'return_value' => 'yes',
662 'default' => 'yes',
663 'classes' => $this->pro_class,
664 'condition' => [
665 'pdf_toolbar' => 'yes',
666 ],
667 ]
668 );
669
670
671
672 $this->add_control(
673 'pdf_zoom_in',
674 [
675 'label' => __('Zoom In', 'embedpress'),
676 'type' => Controls_Manager::SWITCHER,
677 'label_on' => __('Show', 'embedpress'),
678 'label_off' => __('Hide', 'embedpress'),
679 'return_value' => 'yes',
680 'default' => 'yes',
681 'condition' => [
682 'pdf_toolbar' => 'yes',
683 'embedpress_pdf_viewer_style' => 'flip-book',
684 ],
685 ]
686 );
687 $this->add_control(
688 'pdf_zoom_out',
689 [
690 'label' => __('Zoom Out', 'embedpress'),
691 'type' => Controls_Manager::SWITCHER,
692 'label_on' => __('Show', 'embedpress'),
693 'label_off' => __('Hide', 'embedpress'),
694 'return_value' => 'yes',
695 'default' => 'yes',
696 'condition' => [
697 'pdf_toolbar' => 'yes',
698 'embedpress_pdf_viewer_style' => 'flip-book',
699 ],
700 ]
701 );
702 $this->add_control(
703 'pdf_fit_view',
704 [
705 'label' => __('Fit View', 'embedpress'),
706 'type' => Controls_Manager::SWITCHER,
707 'label_on' => __('Show', 'embedpress'),
708 'label_off' => __('Hide', 'embedpress'),
709 'return_value' => 'yes',
710 'default' => 'yes',
711 'condition' => [
712 'pdf_toolbar' => 'yes',
713 'embedpress_pdf_viewer_style' => 'flip-book',
714 ],
715 ]
716 );
717 $this->add_control(
718 'pdf_bookmark',
719 [
720 'label' => __('Bookmark', 'embedpress'),
721 'type' => Controls_Manager::SWITCHER,
722 'label_on' => __('Show', 'embedpress'),
723 'label_off' => __('Hide', 'embedpress'),
724 'return_value' => 'yes',
725 'default' => 'yes',
726 'condition' => [
727 'pdf_toolbar' => 'yes',
728 'embedpress_pdf_viewer_style' => 'flip-book',
729 ],
730 ]
731 );
732
733 $this->add_control(
734 'pdf_sound',
735 [
736 'label' => __('Flip Sound', 'embedpress'),
737 'type' => Controls_Manager::SWITCHER,
738 'label_on' => __('On', 'embedpress'),
739 'label_off' => __('Off', 'embedpress'),
740 'return_value' => 'yes',
741 'default' => 'yes',
742 'condition' => [
743 'embedpress_pdf_viewer_style' => 'flip-book',
744 ],
745 ]
746 );
747
748
749 $this->add_control(
750 'pdf_presentation_mode',
751 [
752 'label' => __('PDF Presentation Mode', 'embedpress'),
753 'type' => Controls_Manager::SWITCHER,
754 'label_on' => __('Show', 'embedpress'),
755 'label_off' => __('Hide', 'embedpress'),
756 'return_value' => 'yes',
757 'default' => 'yes',
758 'condition' => [
759 'pdf_toolbar' => 'yes',
760 ],
761 ]
762 );
763 $this->add_control(
764 'pdf_lazyload',
765 [
766 'label' => __('Lazy Load', 'embedpress'),
767 'type' => Controls_Manager::SWITCHER,
768 'label_on' => __('Yes', 'embedpress'),
769 'label_off' => __('No', 'embedpress'),
770 'return_value' => 'yes',
771 'default' => '',
772 'condition' => [
773 'pdf_toolbar' => 'yes',
774 ],
775 ]
776 );
777
778 $this->add_control(
779 'pdf_text_copy',
780 [
781 'label' => sprintf(__('Copy Text %s', 'embedpress'), $this->pro_text),
782 'type' => Controls_Manager::SWITCHER,
783 'label_on' => __('Show', 'embedpress'),
784 'label_off' => __('Hide', 'embedpress'),
785 'return_value' => 'yes',
786 'default' => 'yes',
787 'classes' => $this->pro_class,
788 'condition' => [
789 'pdf_toolbar' => 'yes',
790 'embedpress_pdf_viewer_style' => 'modern',
791 ],
792 ]
793 );
794
795 $this->add_control(
796 'add_text',
797 [
798 'label' => sprintf(__('Add Text', 'embedpress')),
799 'type' => Controls_Manager::SWITCHER,
800 'label_on' => __('Show', 'embedpress'),
801 'label_off' => __('Hide', 'embedpress'),
802 'return_value' => 'yes',
803 'default' => 'yes',
804 'condition' => [
805 'pdf_toolbar' => 'yes',
806 'embedpress_pdf_viewer_style' => 'modern',
807 ],
808 ]
809 );
810 $this->add_control(
811 'draw',
812 [
813 'label' => sprintf(__('Draw %s', 'embedpress'), $this->pro_text),
814 'type' => Controls_Manager::SWITCHER,
815 'label_on' => __('Show', 'embedpress'),
816 'label_off' => __('Hide', 'embedpress'),
817 'return_value' => 'yes',
818 'default' => 'yes',
819 'classes' => $this->pro_class,
820 'condition' => [
821 'pdf_toolbar' => 'yes',
822 'embedpress_pdf_viewer_style' => 'modern',
823 ],
824 ]
825 );
826
827 $this->add_control(
828 'add_image',
829 [
830 'label' => __('Add Image', 'embedpress'),
831 'type' => Controls_Manager::SWITCHER,
832 'label_on' => __('Show', 'embedpress'),
833 'label_off' => __('Hide', 'embedpress'),
834 'return_value' => 'yes',
835 'default' => 'yes',
836 'condition' => [
837 'pdf_toolbar' => 'yes',
838 'embedpress_pdf_viewer_style' => 'modern',
839 ],
840 ]
841 );
842 $this->add_control(
843 'pdf_rotate_access',
844 [
845 'label' => __('Rotation', 'embedpress'),
846 'type' => Controls_Manager::SWITCHER,
847 'label_on' => __('Show', 'embedpress'),
848 'label_off' => __('Hide', 'embedpress'),
849 'return_value' => 'yes',
850 'default' => 'yes',
851 'condition' => [
852 'pdf_toolbar' => 'yes',
853 'embedpress_pdf_viewer_style' => 'modern',
854 ],
855 ]
856 );
857
858 $this->add_control(
859 'pdf_details',
860 [
861 'label' => __('Properties', 'embedpress'),
862 'type' => Controls_Manager::SWITCHER,
863 'label_on' => __('Show', 'embedpress'),
864 'label_off' => __('Hide', 'embedpress'),
865 'return_value' => 'yes',
866 'default' => 'yes',
867 'condition' => [
868 'pdf_toolbar' => 'yes',
869 'embedpress_pdf_viewer_style' => 'modern',
870 ],
871 ]
872 );
873
874 $this->add_control(
875 'selection_tool',
876 [
877 'label' => sprintf(__('Default Selection Tool %s', 'embedpress'), $this->pro_text),
878 'type' => \Elementor\Controls_Manager::SELECT,
879 'options' => [
880 '0' => esc_html__('Text Tool', 'embedpress'),
881 '1' => esc_html__('Hand Tool', 'embedpress'),
882 ],
883 'default' => '0',
884 'classes' => $this->pro_class,
885
886 ]
887 );
888
889 $this->add_control(
890 'scrolling',
891 [
892 'label' => sprintf(__('Default Scrolling %s', 'embedpress'), $this->pro_text),
893 'type' => \Elementor\Controls_Manager::SELECT,
894 'options' => [
895 '-1' => esc_html__('Page Scrolling', 'embedpress'),
896 '0' => esc_html__('Vertical Scrolling', 'embedpress'),
897 '1' => esc_html__('Horizontal Scrolling', 'embedpress'),
898 '2' => esc_html__('Wrapped Scrolling', 'embedpress'),
899 ],
900 'default' => '0',
901 'classes' => $this->pro_class,
902 ]
903 );
904
905 $this->add_control(
906 'spreads',
907 [
908 'label' => esc_html__('Default Spreads', 'embedpress'),
909 'type' => \Elementor\Controls_Manager::SELECT,
910 'options' => [
911 '0' => esc_html__('No Spreads', 'embedpress'),
912 '1' => esc_html__('Odd Spreads', 'embedpress'),
913 '2' => esc_html__('Even Spreads', 'embedpress'),
914 ],
915 'default' => '-1',
916 'condition' => [
917 'scrolling!' => '1',
918 ],
919 ]
920 );
921
922 $this->end_controls_section();
923
924 // Watermark Controls Section
925 $this->start_controls_section(
926 'embedpress_pdf_watermark_section',
927 [
928 'label' => __('Watermark', 'embedpress'),
929 ]
930 );
931
932 $this->add_control(
933 'embedpress_watermark_text',
934 [
935 'label' => sprintf(__('Watermark Text %s', 'embedpress'), $this->pro_text),
936 'type' => \Elementor\Controls_Manager::TEXT,
937 'default' => '',
938 'placeholder' => __('e.g. CONFIDENTIAL', 'embedpress'),
939 'classes' => $this->pro_class,
940 ]
941 );
942
943 $this->add_control(
944 'embedpress_watermark_style',
945 [
946 'label' => __('Watermark Style', 'embedpress'),
947 'type' => \Elementor\Controls_Manager::SELECT,
948 'options' => [
949 'center' => __('Center Diagonal', 'embedpress'),
950 'tiled' => __('Tiled / Repeated', 'embedpress'),
951 ],
952 'default' => 'center',
953 'condition' => defined('EMBEDPRESS_SL_ITEM_SLUG') ? ['embedpress_watermark_text!' => ''] : [],
954 'classes' => $this->pro_class,
955 ]
956 );
957
958 $this->add_control(
959 'embedpress_watermark_font_size',
960 [
961 'label' => __('Font Size (px)', 'embedpress'),
962 'type' => \Elementor\Controls_Manager::NUMBER,
963 'default' => 48,
964 'min' => 10,
965 'max' => 200,
966 'condition' => defined('EMBEDPRESS_SL_ITEM_SLUG') ? ['embedpress_watermark_text!' => ''] : [],
967 'classes' => $this->pro_class,
968 ]
969 );
970
971 $this->add_control(
972 'embedpress_watermark_color',
973 [
974 'label' => __('Color', 'embedpress'),
975 'type' => \Elementor\Controls_Manager::COLOR,
976 'default' => '#000000',
977 'global' => [
978 'default' => Global_Colors::COLOR_PRIMARY,
979 ],
980 'condition' => defined('EMBEDPRESS_SL_ITEM_SLUG') ? ['embedpress_watermark_text!' => ''] : [],
981 'classes' => $this->pro_class,
982 ]
983 );
984
985 $this->add_control(
986 'embedpress_watermark_opacity',
987 [
988 'label' => __('Opacity (%)', 'embedpress'),
989 'type' => \Elementor\Controls_Manager::NUMBER,
990 'default' => 15,
991 'min' => 1,
992 'max' => 100,
993 'condition' => defined('EMBEDPRESS_SL_ITEM_SLUG') ? ['embedpress_watermark_text!' => ''] : [],
994 'classes' => $this->pro_class,
995 ]
996 );
997
998 $this->end_controls_section();
999
1000 do_action( 'extend_elementor_controls', $this, '_pdf_', $this->pro_text, $this->pro_class);
1001 $this->init_performance_controls();
1002
1003 }
1004
1005 private function render_lightbox_thumbnail($url, $settings, $client_id)
1006 {
1007 $viewerStyle = $settings['embedpress_pdf_viewer_style'] ?? 'modern';
1008 $maxWidth = $settings['embedpress_elementor_document_width']['size'] . $settings['embedpress_elementor_document_width']['unit'];
1009 $customThumb = !empty($settings['embedpress_pdf_lightbox_thumbnail']['url']) ? $settings['embedpress_pdf_lightbox_thumbnail']['url'] : '';
1010 $align = $settings['embedpress_pdf_lightbox_align'] ?? 'left';
1011
1012 $alignStyle = '';
1013 if ($align === 'center') {
1014 $alignStyle = 'text-align: center;';
1015 } elseif ($align === 'right') {
1016 $alignStyle = 'text-align: right;';
1017 }
1018
1019 // Generate base64 viewer params (reuse getParamData but extract just the base64 key)
1020 $paramString = $this->getParamData($settings);
1021 $viewerParams = '';
1022 if (preg_match('/key=(.+)$/', $paramString, $matches)) {
1023 $viewerParams = $matches[1];
1024 }
1025
1026 $pdfTitle = Helper::get_file_title($url);
1027 ?>
1028 <div class="embedpress-document-embed ose-document ep-doc-<?php echo esc_attr(md5('embedpress-pdf-' . $client_id)); ?>"
1029 style="max-width: <?php echo esc_attr($maxWidth); ?>; <?php echo esc_attr($alignStyle); ?>"
1030 data-embed-type="PDF">
1031 <div class="ep-pdf-thumbnail-card" style="display:inline-block;text-align:center;max-width:100%;cursor:pointer;">
1032 <div class="ep-pdf-thumbnail-wrap"
1033 style="position:relative;display:inline-block;max-width:100%;"
1034 data-pdf-url="<?php echo esc_url($url); ?>"
1035 data-viewer-style="<?php echo esc_attr($viewerStyle); ?>"
1036 data-viewer-params="<?php echo esc_attr($viewerParams); ?>">
1037 <div class="ep-pdf-thumbnail-inner" style="position:relative;display:inline-block;max-width:100%;background:#fff;border-radius:4px;overflow:hidden;">
1038 <?php if (!empty($customThumb)): ?>
1039 <img class="ep-pdf-thumbnail-custom" src="<?php echo esc_url($customThumb); ?>" alt="<?php echo esc_attr($pdfTitle); ?>" style="display:block;max-width:100%;height:auto;" />
1040 <?php else: ?>
1041 <canvas class="ep-pdf-thumbnail-canvas"
1042 data-pdf-url="<?php echo esc_url($url); ?>"
1043 data-loading="true"
1044 style="display:block;max-width:100%;height:auto;min-height:280px;min-width:200px;"></canvas>
1045 <?php endif; ?>
1046 <div class="ep-pdf-thumbnail-overlay" style="position:absolute;inset:0;display:flex;align-items:center;justify-content:center;pointer-events:none;">
1047 <div class="ep-pdf-thumbnail-icon-circle">
1048 <svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path fill="#333" d="M8 5v14l11-7z"/></svg>
1049 </div>
1050 </div>
1051 </div>
1052 </div>
1053
1054 </div>
1055 </div>
1056 <?php
1057 }
1058
1059 private function render_trigger_element($url, $settings, $client_id, $mode)
1060 {
1061 $viewerStyle = $settings['embedpress_pdf_viewer_style'] ?? 'modern';
1062 $triggerText = !empty($settings['embedpress_pdf_trigger_text']) ? $settings['embedpress_pdf_trigger_text'] : 'View PDF';
1063
1064 $paramString = $this->getParamData($settings);
1065 $viewerParams = '';
1066 if (preg_match('/key=(.+)$/', $paramString, $matches)) {
1067 $viewerParams = $matches[1];
1068 }
1069 ?>
1070 <div class="embedpress-document-embed ose-document ep-doc-<?php echo esc_attr(md5('embedpress-pdf-' . $client_id)); ?>"
1071 data-embed-type="PDF">
1072 <div class="ep-pdf-thumbnail-wrap"
1073 data-pdf-url="<?php echo esc_url($url); ?>"
1074 data-viewer-style="<?php echo esc_attr($viewerStyle); ?>"
1075 data-viewer-params="<?php echo esc_attr($viewerParams); ?>">
1076 <span class="ep-pdf-trigger ep-pdf-trigger--<?php echo esc_attr($mode); ?>"><?php echo esc_html($triggerText); ?></span>
1077 </div>
1078 </div>
1079 <?php
1080 }
1081
1082 private function is_pdf($url)
1083 {
1084 $arr = explode('.', $url);
1085 return end($arr) === 'pdf';
1086 }
1087
1088 public function render()
1089 {
1090 $settings = $this->get_settings();
1091
1092 Helper::get_enable_settings_data_for_scripts($settings);
1093
1094 $is_editor_view = Plugin::$instance->editor->is_edit_mode();
1095 $url = $this->get_file_url();
1096
1097 if ($settings['embedpress_pdf_type'] === 'url' && !empty($settings['__dynamic__']['embedpress_pdf_file_link'])) {
1098 $resolved = DynamicFieldResolver::resolve_elementor_dynamic($settings['__dynamic__']['embedpress_pdf_file_link']);
1099 if ($resolved !== '') {
1100 $url = $resolved;
1101 }
1102 }
1103
1104 $client_id = $this->get_id();
1105
1106 $this->_render($url, $settings, $client_id, $is_editor_view);
1107 Helper::get_source_data(md5($this->get_id()).'_eb_elementor', $url, 'elementor_source_data', 'elementor_temp_source_data');
1108 }
1109
1110
1111 public function getParamData($settings){
1112 $urlParamData = array(
1113 'themeMode' => $settings['embedpress_theme_mode'],
1114 'toolbar' => !empty($settings['pdf_toolbar']) ? 'true' : 'false',
1115 'position' => $settings['pdf_toolbar_position'],
1116 'presentation' => !empty($settings['pdf_presentation_mode']) ? 'true' : 'false',
1117 'lazyLoad' => !empty($settings['pdf_lazyload']) ? 'true' : 'false',
1118 'download' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['pdf_print_download'] : 'true',
1119 'copy_text' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['pdf_text_copy'] : 'true',
1120 'add_text' => !empty($settings['add_text']) ? 'true' : 'false',
1121 'draw' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['draw'] : 'true',
1122 'add_image' => !empty($settings['add_image']) ? 'true' : 'false',
1123 'pdf_rotation' => !empty($settings['pdf_rotate_access']) ? 'true' : 'false',
1124 'pdf_details' => !empty($settings['pdf_details']) ? 'true' : 'false',
1125 'zoom_in' => !empty($settings['pdf_zoom_in']) ? 'true' : 'false',
1126 'zoom_out' => !empty($settings['pdf_zoom_out']) ? 'true' : 'false',
1127 'fit_view' => !empty($settings['pdf_fit_view']) ? 'true' : 'false',
1128 'bookmark' => !empty($settings['pdf_bookmark']) ? 'true' : 'false',
1129 'sound' => !empty($settings['pdf_sound']) ? 'true' : 'false',
1130 'flipbook_toolbar_position' => !empty($settings['flipbook_toolbar_position']) ? $settings['flipbook_toolbar_position'] : 'bottom',
1131 'selection_tool' => isset($settings['selection_tool']) ? esc_attr($settings['selection_tool']) : '0',
1132 'scrolling' => isset($settings['scrolling']) ? esc_attr($settings['scrolling']) : '-1',
1133 'spreads' => isset($settings['spreads']) ? esc_attr($settings['spreads']) : '-1',
1134 'is_pro_active' => apply_filters('embedpress/is_allow_rander', false),
1135 'pageNumber' => !empty($settings['embedpress_pdf_page_number']) ? absint($settings['embedpress_pdf_page_number']) : 1,
1136 'watermark_text' => defined('EMBEDPRESS_SL_ITEM_SLUG') && !empty($settings['embedpress_watermark_text']) ? $settings['embedpress_watermark_text'] : '',
1137 'watermark_font_size' => defined('EMBEDPRESS_SL_ITEM_SLUG') && !empty($settings['embedpress_watermark_font_size']) ? $settings['embedpress_watermark_font_size'] : '48',
1138 'watermark_color' => defined('EMBEDPRESS_SL_ITEM_SLUG') && !empty($settings['embedpress_watermark_color']) ? Helper::get_elementor_global_color($settings, 'embedpress_watermark_color') : '#000000',
1139 'watermark_opacity' => defined('EMBEDPRESS_SL_ITEM_SLUG') && isset($settings['embedpress_watermark_opacity']) ? $settings['embedpress_watermark_opacity'] : '15',
1140 'watermark_style' => defined('EMBEDPRESS_SL_ITEM_SLUG') && !empty($settings['embedpress_watermark_style']) ? $settings['embedpress_watermark_style'] : 'center',
1141
1142 );
1143
1144 $custom_color = Helper::get_elementor_global_color($settings, 'embedpress_pdf_custom_color');
1145
1146 if($settings['embedpress_theme_mode'] == 'custom') {
1147 $urlParamData['customColor'] = $custom_color;
1148 }
1149
1150 if($settings['embedpress_pdf_viewer_style'] == 'flip-book'){
1151 return "&key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), "UTF-8"));
1152 }
1153
1154 return "#key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), "UTF-8"));
1155
1156 }
1157
1158 public function _render($url, $settings, $id, $is_editor_view = false)
1159 {
1160
1161 $custom_color = Helper::get_elementor_global_color($settings, 'embedpress_pdf_custom_color');
1162
1163 $unitoption = 'emebedpress-unit-px';
1164 if($settings['embedpress_elementor_document_width']['unit'] === '%'){
1165 $unitoption = 'emebedpress-unit-percent';
1166 }
1167 $client_id = $id;
1168 $id = 'embedpress-pdf-' . $id;
1169 $hash_pass = hash('sha256', wp_salt(32) . md5($settings['embedpress_pdf_lock_content_password']));
1170
1171 $dimension = '';
1172
1173 $password_correct = isset($_COOKIE['password_correct_' . $client_id]) ? sanitize_text_field($_COOKIE['password_correct_' . $client_id]) : '';
1174
1175 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))){
1176 $dimension = "width: {$settings['embedpress_elementor_document_width']['size']}{$settings['embedpress_elementor_document_width']['unit']}!important;height: {$settings['embedpress_elementor_document_height']['size']}px;";
1177 }
1178
1179 $content_protection_class = 'ep-content-protection-enabled';
1180 $content_locked_class = 'ep-content-locked';
1181 if(empty($settings['embedpress_pdf_lock_content']) || empty($settings['embedpress_pdf_lock_content_password']) || $hash_pass === $password_correct) {
1182 $content_locked_class = '';
1183 $content_protection_class = 'ep-content-protection-disabled';
1184 }
1185
1186 $pass_hash_key = md5($settings['embedpress_pdf_lock_content_password']);
1187 // Generate content ID for analytics tracking
1188 $content_id = md5($url . 'pdf-elementor');
1189
1190 // Track PDF widget usage for analytics
1191 $this->track_pdf_widget_usage($settings, $url, $content_id);
1192
1193 $this->add_render_attribute('embedpres-pdf-render', [
1194 'class' => ['embedpress-embed-document-pdf', esc_attr($id)],
1195 'data-emid' => esc_attr($id),
1196 // 'data-embedpress-content' => esc_attr($content_id),
1197 'data-embed-type' => 'PDF'
1198 ]);
1199 $this->add_render_attribute('embedpress-document', [
1200 'class' => ['embedpress-document-embed', 'ep-doc-' . md5($id), 'ose-document', $unitoption, $content_locked_class ],
1201 'data-thememode' => isset($settings['embedpress_theme_mode']) ? esc_attr($settings['embedpress_theme_mode']) : '',
1202 'data-customcolor' => isset($custom_color) ? esc_attr($custom_color) : '',
1203 'data-toolbar' => isset($settings['pdf_toolbar']) ? esc_attr($settings['pdf_toolbar']) : '',
1204 'data-toolbar-position' => isset($settings['pdf_toolbar_position']) ? esc_attr($settings['pdf_toolbar_position']) : 'top',
1205 'data-open' => 'no', // Assuming 'no' is a static value, no need to sanitize
1206 'data-presentation-mode' => isset($settings['pdf_presentation_mode']) ? esc_attr($settings['pdf_presentation_mode']) : '',
1207 'data-download' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION') ? esc_attr($settings['pdf_print_download']) : 'yes', // Assuming 'yes' is a safe fallback
1208 'data-copy' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION') ? esc_attr($settings['pdf_text_copy']) : 'yes', // Assuming 'yes' is a safe fallback
1209 'data-add-image' => isset($settings['add_image']) ? esc_attr($settings['add_image']) : '',
1210 'data-rotate' => isset($settings['pdf_rotate_access']) ? esc_attr($settings['pdf_rotate_access']) : '',
1211 'data-details' => isset($settings['pdf_details']) ? esc_attr($settings['pdf_details']) : '',
1212 'data-id' => $id, // Assuming $id is safe, no need to sanitize
1213 'data-selection-tool' => isset($settings['selection_tool']) ? esc_attr($settings['selection_tool']) : '0',
1214 'data-scrolling' => isset($settings['scrolling']) ? esc_attr($settings['scrolling']) : '-1',
1215 'data-spreads' => isset($settings['spreads']) ? esc_attr($settings['spreads']) : '-1',
1216 ]);
1217
1218 $embed_settings = [];
1219 $embed_settings['customThumbnail'] = !empty($settings['embedpress_pdf_content_share_custom_thumbnail']['url']) ? esc_url($settings['embedpress_pdf_content_share_custom_thumbnail']['url']) : '';
1220
1221 $embed_settings['customTitle'] = !empty($settings['embedpress_pdf_content_title']) ? sanitize_text_field($settings['embedpress_pdf_content_title']) : Helper::get_file_title($url);
1222
1223 $embed_settings['customDescription'] = !empty($settings['embedpress_pdf_content_descripiton']) ? sanitize_text_field($settings['embedpress_pdf_content_descripiton']) : Helper::get_file_title($url);
1224
1225 $embed_settings['sharePosition'] = !empty($settings['embedpress_pdf_content_share_position']) ? sanitize_text_field($settings['embedpress_pdf_content_share_position']) : 'right';
1226
1227 // Add social share platform settings
1228 $embed_settings['shareFacebook'] = !empty($settings['embedpress_pdf_share_facebook']) ? true : false;
1229 $embed_settings['shareTwitter'] = !empty($settings['embedpress_pdf_share_twitter']) ? true : false;
1230 $embed_settings['sharePinterest'] = !empty($settings['embedpress_pdf_share_pinterest']) ? true : false;
1231 $embed_settings['shareLinkedin'] = !empty($settings['embedpress_pdf_share_linkedin']) ? true : false;
1232
1233 $embed_settings['lockHeading'] = !empty($settings['embedpress_pdf_lock_content_heading']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_heading']) : '';
1234
1235 $embed_settings['lockSubHeading'] = !empty($settings['embedpress_pdf_lock_content_sub_heading']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_sub_heading']) : '';
1236
1237 $embed_settings['lockErrorMessage'] = !empty($settings['embedpress_pdf_lock_content_error_message']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_error_message']) : '';
1238
1239 $embed_settings['passwordPlaceholder'] = !empty($settings['embedpress_pdf_password_placeholder']) ? sanitize_text_field($settings['embedpress_pdf_password_placeholder']) : '';
1240
1241 $embed_settings['submitButtonText'] = !empty($settings['embedpress_pdf_submit_button_text']) ? sanitize_text_field($settings['embedpress_pdf_submit_button_text']) : '';
1242
1243 $embed_settings['submitUnlockingText'] = !empty($settings['embedpress_pdf_submit_Unlocking_text']) ? sanitize_text_field($settings['embedpress_pdf_submit_Unlocking_text']) : '';
1244
1245 $embed_settings['enableFooterMessage'] = !empty($settings['embedpress_pdf_enable_footer_message']) ? sanitize_text_field($settings['embedpress_pdf_enable_footer_message']) : '';
1246
1247 $embed_settings['footerMessage'] = !empty($settings['embedpress_pdf_lock_content_footer_message']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_footer_message']) : '';
1248
1249 $embed_settings['userRole'] = !empty($settings['embedpress_pdf_select_roles']) ? $settings['embedpress_pdf_select_roles'] : [];
1250
1251 $embed_settings['protectionMessage'] = !empty($settings['embedpress_pdf_protection_message']) ? $settings['embedpress_pdf_protection_message'] : '';
1252
1253
1254 if($settings['embedpress_elementor_document_width']['unit'] === '%'){
1255 $width_class = ' ep-percentage-width';
1256 }
1257 else{
1258 $width_class = 'ep-fixed-width';
1259 }
1260 $content_share_class = '';
1261 $share_position_class = '';
1262 $share_position = isset($settings['embedpress_pdf_content_share_position']) ? $settings['embedpress_pdf_content_share_position'] : 'right';
1263
1264 if(!empty($settings['embedpress_pdf_content_share'])) {
1265 $content_share_class = 'ep-content-share-enabled';
1266 $share_position_class = 'ep-share-position-'.$share_position;
1267 }
1268
1269 $adsAtts = '';
1270
1271 if (!empty($settings['adManager'])) {
1272 $ad = base64_encode(json_encode($settings)); // Using WordPress JSON encoding function
1273 $adsAtts = 'data-sponsored-id="' . esc_attr($client_id) . '" data-sponsored-attrs="' . esc_attr($ad) . '" class="sponsored-mask"';
1274 }
1275
1276 // Lightbox mode: render thumbnail instead of inline viewer
1277 $displayMode = !empty($settings['embedpress_pdf_display_mode']) ? $settings['embedpress_pdf_display_mode'] : 'inline';
1278 if ($displayMode === 'lightbox' && $url != '' && $this->is_pdf($url) && !$this->is_external_url($url) && empty($content_locked_class)) {
1279 $this->render_lightbox_thumbnail($url, $settings, $client_id);
1280 return;
1281 }
1282 if (in_array($displayMode, ['button', 'link', 'text']) && $url != '' && $this->is_pdf($url) && !$this->is_external_url($url) && empty($content_locked_class)) {
1283 $this->render_trigger_element($url, $settings, $client_id, $displayMode);
1284 return;
1285 }
1286
1287 ?>
1288 <div <?php echo $this->get_render_attribute_string('embedpress-document'); ?> style=" max-width:100%; display: inline-block">
1289
1290 <?php
1291 do_action('embedpress_pdf_after_embed', $settings, $url, $id, $this);
1292
1293 if ($url != '') {
1294 $url = esc_url($url);
1295
1296 if ($this->is_pdf($url) && !$this->is_external_url($url)) {
1297 $renderer = Helper::get_pdf_renderer();
1298 $src = $renderer . ((strpos($renderer, '?') === false) ? '?' : '&')
1299 . 'file=' . urlencode($url)
1300 . '&scrolling=' . $settings['scrolling']
1301 . '&selection_tool=' . $settings['selection_tool']
1302 . '&spreads=' . $settings['spreads']
1303 . $this->getParamData($settings);
1304
1305
1306 if (!empty($settings['embedpress_pdf_zoom'])) {
1307 $zoom = $settings['embedpress_pdf_zoom'];
1308 if ($zoom == 'custom') {
1309 if (!empty($settings['embedpress_pdf_zoom_custom'])) {
1310 $zoom = $settings['embedpress_pdf_zoom_custom'];
1311 } else {
1312 $zoom = null;
1313 }
1314 }
1315 if ($zoom) {
1316 $src = $src . "&zoom=$zoom";
1317 }
1318 }
1319
1320 if(isset($settings['embedpress_pdf_viewer_style']) && $settings['embedpress_pdf_viewer_style'] === 'modern') {
1321 $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).'"';
1322 }
1323 else{
1324 $src = urlencode($url).$this->getParamData($settings);
1325 $renderer = Helper::get_flipbook_renderer();
1326 $src_url = $renderer . ((strpos($renderer, '?') === false) ? '?' : '&') . 'file=' . $src;
1327 $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_url).'"';
1328 }
1329
1330
1331 $embed_content .= ' '.$this->get_render_attribute_string('embedpres-pdf-render').' frameborder="0"></iframe>';
1332 if ($settings['embedpress_pdf_powered_by'] === 'yes') {
1333 $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
1334 }
1335
1336 } else {
1337 $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).'"';
1338 $embed_content .= ' '.$this->get_render_attribute_string('embedpres-pdf-render').'></iframe>';
1339
1340 if ($settings['embedpress_pdf_powered_by'] === 'yes') {
1341 $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
1342 }
1343 }
1344
1345 ?>
1346
1347 <div <?php echo $adsAtts; ?>>
1348
1349 <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); ?>">
1350 <div id="<?php echo esc_attr( $this->get_id() ); ?>" class="ep-embed-content-wraper">
1351 <?php
1352 // Apply lazy loading if enabled (but not in editor mode)
1353 if (!empty($settings['enable_lazy_load']) && $settings['enable_lazy_load'] === 'yes' && !$is_editor_view) {
1354 $embed_content = preg_replace_callback(
1355 '/<iframe([^>]*)src=["\']([^"\']+)["\']([^>]*)>/i',
1356 function($matches) {
1357 $before = $matches[1];
1358 $src = $matches[2];
1359 $after = $matches[3];
1360
1361 // Extract style attribute if exists
1362 $style = '';
1363 if (preg_match('/style=["\']([^"\']+)["\']/i', $before . $after, $style_match)) {
1364 $style = $style_match[1];
1365 }
1366
1367 return sprintf(
1368 '<div class="ep-lazy-iframe-placeholder" data-ep-lazy-src="%s" data-ep-iframe-style="%s" %s %s style="%s"></div>',
1369 esc_attr($src),
1370 esc_attr($style),
1371 $before,
1372 $after,
1373 esc_attr($style)
1374 );
1375 },
1376 $embed_content
1377 );
1378 }
1379
1380 $embed = '<div>'.$embed_content.'</div>';
1381
1382 $content_id = $client_id;
1383 if(
1384
1385 (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') ||
1386 ($settings['embedpress_pdf_protection_type'] == 'password' && !empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct) ) ||
1387 !apply_filters('embedpress/is_allow_rander', false) ||
1388 ($settings['embedpress_pdf_protection_type'] == 'user-role' && Helper::has_allowed_roles($embed_settings['userRole']))
1389
1390 ){
1391 if(!empty($settings['embedpress_pdf_content_share'])){
1392 $embed .= Helper::embed_content_share($content_id, $embed_settings);
1393 }
1394 echo $embed ;
1395
1396 } else {
1397 if(!empty($settings['embedpress_pdf_content_share'])){
1398 $embed .= Helper::embed_content_share($content_id, $embed_settings);
1399 }
1400
1401 if ($settings['embedpress_pdf_protection_type'] == 'password') {
1402 do_action('embedpress/display_password_form', $client_id, $embed, $pass_hash_key, $embed_settings);
1403 } else {
1404 do_action('embedpress/content_protection_content', $client_id, $embed_settings['protectionMessage'], $embed_settings['userRole']);
1405 }
1406 }
1407 ?>
1408 </div>
1409
1410 </div>
1411
1412
1413 <?php
1414 $isAdEnabled = !empty($settings['adManager']);
1415 $isContentUnlocked = empty($settings['embedpress_pdf_lock_content']);
1416 $isPasswordCorrect = Helper::is_password_correct($client_id) && ($hash_pass === $password_correct);
1417
1418 if ($isAdEnabled && ($isContentUnlocked || $isPasswordCorrect)) {
1419 $embed_content = apply_filters('embedpress/generate_ad_template', $embed_content, $client_id, $settings, 'elementor');
1420 }
1421 ?>
1422
1423 </div>
1424 <?php
1425
1426 }
1427 ?>
1428
1429 </div>
1430
1431 <?php
1432 }
1433
1434 private function get_file_url()
1435 {
1436 $settings = $this->get_settings();
1437
1438 if (isset($settings['embedpress_pro_secure_mode']) && $settings['embedpress_pro_secure_mode'] === 'yes') {
1439 if (!empty($settings['embedpress_pdf_Uploader']['id'])) {
1440 $attachment_id = $settings['embedpress_pdf_Uploader']['id'];
1441 if (class_exists('\Embedpress\Pro\Classes\SecureFileHandler')) {
1442 $secure_url = \Embedpress\Pro\Classes\SecureFileHandler::get_instance()->ensure_secure_copy($attachment_id);
1443 if ($secure_url) {
1444 return $secure_url;
1445 }
1446 }
1447 }
1448 }
1449
1450 return $settings['embedpress_pdf_type'] === 'url' ? $settings['embedpress_pdf_file_link']['url'] : $settings['embedpress_pdf_Uploader']['url'];
1451 }
1452
1453 protected function is_external_url($url)
1454 {
1455 return strpos($url, get_site_url()) === false;
1456 }
1457
1458 /**
1459 * Track PDF widget usage for analytics
1460 *
1461 * @param array $settings
1462 * @param string $url
1463 * @param string $content_id
1464 * @return void
1465 */
1466 private function track_pdf_widget_usage($settings, $url, $content_id)
1467 {
1468 // Only track if analytics is enabled and we have the necessary classes
1469 if (class_exists('EmbedPress\Includes\Classes\Analytics\Analytics_Manager')) {
1470 if (empty($url)) {
1471 return;
1472 }
1473
1474 $provider_name = 'PDF';
1475
1476 $tracking_data = [
1477 'embed_type' => $provider_name,
1478 'embed_url' => $url,
1479 'post_id' => get_the_ID(),
1480 'page_url' => get_permalink(),
1481 'title' => get_the_title()
1482 ];
1483
1484 // Track content creation
1485 do_action('embedpress_content_embedded', $content_id, 'elementor-pdf', $tracking_data);
1486 }
1487 }
1488 }
1489