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