PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 4.6.3
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v4.6.3
4.6.3 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / EmbedPress / Elementor / Widgets / Embedpress_Pdf.php
embedpress / EmbedPress / Elementor / Widgets Last commit date
Embedpress_Calendar.php 2 months ago Embedpress_Document.php 1 month ago Embedpress_Elementor.php 2 months ago Embedpress_Google_Reviews.php 1 month ago Embedpress_Pdf.php 4 days ago Embedpress_Pdf_Gallery.php 1 month ago
Embedpress_Pdf.php
1657 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 /**
127 * Per-embed toggles for the visitor view-count / download-count badge.
128 * Default on; the frontend script honours the global option as the master
129 * gate and treats these switches as a per-embed opt-out.
130 */
131 public function init_stats_controls()
132 {
133 $this->start_controls_section(
134 'embedpress_stats_section',
135 [
136 'label' => __('Engagement Stats', 'embedpress'),
137 ]
138 );
139
140 $this->add_control(
141 'embedpress_pdf_show_view_count',
142 [
143 'label' => __('Show View Count', 'embedpress'),
144 'type' => \Elementor\Controls_Manager::SWITCHER,
145 'label_on' => __('Show', 'embedpress'),
146 'label_off' => __('Hide', 'embedpress'),
147 'return_value' => 'yes',
148 'default' => '',
149 'description' => __('Display the visitor view counter on this embed.', 'embedpress'),
150 ]
151 );
152
153 $this->add_control(
154 'embedpress_pdf_show_download_count',
155 [
156 'label' => __('Show Download Count', 'embedpress'),
157 'type' => \Elementor\Controls_Manager::SWITCHER,
158 'label_on' => __('Show', 'embedpress'),
159 'label_off' => __('Hide', 'embedpress'),
160 'return_value' => 'yes',
161 'default' => '',
162 'description' => __('Display the download counter on this embed.', 'embedpress'),
163 ]
164 );
165
166 // Count badge position. The control is a Pro feature — free installs
167 // keep the default 'below' (the dropdown is disabled via pro_class);
168 // Pro unlocks the six placements. Mirrors the Gutenberg blocks.
169 $this->add_control(
170 'embedpress_pdf_count_position',
171 [
172 'label' => sprintf(__('Count Position %s', 'embedpress'), $this->pro_text),
173 'type' => Controls_Manager::SELECT,
174 'default' => 'below',
175 'classes' => $this->pro_class,
176 'options' => [
177 'below' => __('Below — Left (default)', 'embedpress'),
178 'below-center' => __('Below — Center', 'embedpress'),
179 'below-right' => __('Below — Right', 'embedpress'),
180 'above-left' => __('Above — Left', 'embedpress'),
181 'above-center' => __('Above — Center', 'embedpress'),
182 'above-right' => __('Above — Right', 'embedpress'),
183 ],
184 'description' => __('Where the count badge sits relative to the embed.', 'embedpress'),
185 'condition' => [
186 'embedpress_pdf_show_view_count' => 'yes',
187 ],
188 ]
189 );
190
191 $this->end_controls_section();
192 }
193
194 /**
195 * Build the per-embed stats override attribute string for inline echoing.
196 * Emits an explicit ` data-ep-views="on|off" data-ep-downloads="on|off"` so
197 * the frontend lets the per-embed toggle win over the global option:
198 * "on" -> show this counter, "off" -> hide it. Counters default off.
199 */
200 private function get_stats_optout_attrs($settings)
201 {
202 $view = (isset($settings['embedpress_pdf_show_view_count']) && $settings['embedpress_pdf_show_view_count'] === 'yes') ? 'on' : 'off';
203 $download = (isset($settings['embedpress_pdf_show_download_count']) && $settings['embedpress_pdf_show_download_count'] === 'yes') ? 'on' : 'off';
204 $attrs = ' data-ep-views="' . $view . '" data-ep-downloads="' . $download . '"';
205
206 // Badge position is Pro-only; free installs always use the default
207 // 'below'. Only emit the marker for a non-default Pro position when Pro
208 // is active, so a free site never renders a gated placement.
209 $position = isset($settings['embedpress_pdf_count_position']) ? (string) $settings['embedpress_pdf_count_position'] : 'below';
210 if ($position !== 'below' && \EmbedPress\Includes\Classes\Helper::is_pro_active()) {
211 $attrs .= ' data-ep-count-position="' . esc_attr($position) . '"';
212 }
213
214 return $attrs;
215 }
216
217 protected function register_controls()
218 {
219 $class = 'embedpress-pro-control not-active';
220 $text = '<sup class="embedpress-pro-label" style="color:red">' . __('Pro', 'embedpress') . '</sup>';
221 $this->pro_class = apply_filters('embedpress/pro_class', $class);
222 $this->pro_text = apply_filters('embedpress/pro_text', $text);
223
224 /**
225 * EmbedPress Content Settings
226 */
227 $this->start_controls_section(
228 'embedpress_content_settings',
229 [
230 'label' => esc_html__('General', 'embedpress'),
231 ]
232 );
233
234 $this->add_control(
235 'embedpress_pdf_type',
236 [
237 'label' => __('Document Type', 'embedpress'),
238 'type' => Controls_Manager::SELECT,
239 'default' => 'file',
240 'options' => [
241 'file' => __('File', 'embedpress'),
242 'url' => __('URL', 'embedpress')
243 ],
244 ]
245 );
246
247 $this->add_control(
248 'embedpress_pdf_file_link_from',
249 [
250 'label' => __( 'URL From', 'embedpress' ),
251 'type' => Controls_Manager::SELECT,
252 'default' => 'external',
253 'options' => [
254 'self' => __( 'Self', 'embedpress' ),
255 'external' => __( 'External', 'embedpress' )
256 ],
257 'condition' => [
258 'embedpress_pdf_type' => 'url'
259 ]
260 ]
261 );
262
263 $this->add_control(
264 'embedpress_pdf_Uploader',
265 [
266 'label' => __('Upload File', 'embedpress'),
267 'type' => Controls_Manager::MEDIA,
268 'dynamic' => [
269 'active' => true,
270 'categories' => [
271 TagsModule::MEDIA_CATEGORY,
272 ],
273 ],
274 'media_type' => [
275 'application/pdf',
276 ],
277 'description' => __(
278 'Upload a file or pick one from your media library for embed. Supported File Type: PDF',
279 'embedpress'
280 ),
281 'condition' => [
282 'embedpress_pdf_type' => 'file'
283 ],
284 ]
285 );
286
287 $this->add_control(
288 'embedpress_pdf_file_link',
289 [
290 'label' => __('URL', 'embedpress'),
291 'type' => Controls_Manager::URL,
292 'placeholder' => __('https://your-link.com/file.pdf', 'embedpress'),
293 'dynamic' => [
294 'active' => true,
295 ],
296 'show_external' => false,
297 'dynamic' => [
298 'active' => true,
299 ],
300 'default' => [
301 'url' => ''
302 ],
303 'condition' => [
304 'embedpress_pdf_type' => 'url'
305 ],
306 ]
307 );
308
309
310 $this->add_control(
311 'embedpress_pdf_viewer_style',
312 [
313 'label' => __('Viewer Style', 'embedpress'),
314 'type' => Controls_Manager::SELECT,
315 'default' => 'modern',
316 'options' => [
317 'modern' => __('Modern', 'embedpress'),
318 'flip-book' => __('Flip Book', 'embedpress'),
319 ],
320 'conditions' => [
321 'relation' => 'or',
322 'terms' => [
323 ['name' => 'embedpress_pdf_type', 'operator' => '===', 'value' => 'file'],
324 ['name' => 'embedpress_pdf_file_link_from', 'operator' => '===', 'value' => 'self'],
325 ],
326 ],
327 ]
328 );
329
330 $this->add_control(
331 'embedpress_pdf_display_mode',
332 [
333 'label' => __('Display Mode', 'embedpress'),
334 'type' => Controls_Manager::SELECT,
335 'default' => 'inline',
336 'options' => [
337 'inline' => __('Inline Viewer', 'embedpress'),
338 'lightbox' => __('Thumbnail + Lightbox', 'embedpress'),
339 'button' => __('Button + Lightbox', 'embedpress'),
340 'link' => __('Link + Lightbox', 'embedpress'),
341 'text' => __('Text + Lightbox', 'embedpress'),
342 ],
343 'conditions' => [
344 'relation' => 'or',
345 'terms' => [
346 ['name' => 'embedpress_pdf_type', 'operator' => '===', 'value' => 'file'],
347 ['name' => 'embedpress_pdf_file_link_from', 'operator' => '===', 'value' => 'self'],
348 ],
349 ],
350 ]
351 );
352
353 $this->add_control(
354 'embedpress_pdf_lightbox_thumbnail',
355 [
356 'label' => sprintf(__('Custom Thumbnail %s', 'embedpress'), $this->pro_text),
357 'type' => Controls_Manager::MEDIA,
358 'default' => ['url' => ''],
359 'condition' => [
360 'embedpress_pdf_display_mode' => 'lightbox',
361 ],
362 'classes' => $this->pro_class,
363 ]
364 );
365
366 $this->add_control(
367 'embedpress_pdf_lightbox_align',
368 [
369 'label' => __('Thumbnail Alignment', 'embedpress'),
370 'type' => Controls_Manager::CHOOSE,
371 'options' => [
372 'left' => ['title' => __('Left', 'embedpress'), 'icon' => 'eicon-text-align-left'],
373 'center' => ['title' => __('Center', 'embedpress'), 'icon' => 'eicon-text-align-center'],
374 'right' => ['title' => __('Right', 'embedpress'), 'icon' => 'eicon-text-align-right'],
375 ],
376 'default' => 'left',
377 'condition' => [
378 'embedpress_pdf_display_mode' => 'lightbox',
379 ],
380 ]
381 );
382
383 $this->add_control(
384 'embedpress_pdf_trigger_text',
385 [
386 'label' => __('Display Text', 'embedpress'),
387 'type' => Controls_Manager::TEXT,
388 'default' => 'View PDF',
389 'condition' => [
390 'embedpress_pdf_display_mode' => ['button', 'link', 'text'],
391 ],
392 ]
393 );
394
395 $this->add_control(
396 'embedpress_pdf_trigger_color',
397 [
398 'label' => __('Text Color', 'embedpress'),
399 'type' => Controls_Manager::COLOR,
400 'condition' => [
401 'embedpress_pdf_display_mode' => ['button', 'link', 'text'],
402 ],
403 'selectors' => [
404 '{{WRAPPER}} .ep-pdf-trigger' => 'color: {{VALUE}};',
405 ],
406 ]
407 );
408
409 $this->add_control(
410 'embedpress_pdf_trigger_bg_color',
411 [
412 'label' => __('Background Color', 'embedpress'),
413 'type' => Controls_Manager::COLOR,
414 'condition' => [
415 'embedpress_pdf_display_mode' => 'button',
416 ],
417 'selectors' => [
418 '{{WRAPPER}} .ep-pdf-trigger--button' => 'background-color: {{VALUE}};',
419 ],
420 ]
421 );
422
423 $this->add_group_control(
424 \Elementor\Group_Control_Typography::get_type(),
425 [
426 'name' => 'embedpress_pdf_trigger_typography',
427 'label' => __('Typography', 'embedpress'),
428 'condition' => [
429 'embedpress_pdf_display_mode' => ['button', 'link', 'text'],
430 ],
431 'selector' => '{{WRAPPER}} .ep-pdf-trigger',
432 ]
433 );
434
435 $this->add_responsive_control(
436 'embedpress_pdf_trigger_padding',
437 [
438 'label' => __('Padding', 'embedpress'),
439 'type' => Controls_Manager::DIMENSIONS,
440 'size_units' => ['px', 'em', '%'],
441 'condition' => [
442 'embedpress_pdf_display_mode' => 'button',
443 ],
444 'selectors' => [
445 '{{WRAPPER}} .ep-pdf-trigger--button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
446 ],
447 ]
448 );
449
450 $this->add_control(
451 'embedpress_pdf_trigger_border_radius',
452 [
453 'label' => __('Border Radius', 'embedpress'),
454 'type' => Controls_Manager::SLIDER,
455 'size_units' => ['px', '%'],
456 'range' => ['px' => ['min' => 0, 'max' => 50]],
457 'condition' => [
458 'embedpress_pdf_display_mode' => 'button',
459 ],
460 'selectors' => [
461 '{{WRAPPER}} .ep-pdf-trigger--button' => 'border-radius: {{SIZE}}{{UNIT}};',
462 ],
463 ]
464 );
465
466 $this->add_control(
467 'embedpress_pdf_zoom',
468 [
469 'label' => __('Zoom', 'embedpress'),
470 'type' => Controls_Manager::SELECT,
471 'default' => 'auto',
472 'options' => [
473 'auto' => __('Automatic Zoom', 'embedpress'),
474 'page-actual' => __('Actual Size', 'embedpress'),
475 'page-fit' => __('Page Fit', 'embedpress'),
476 'page-width' => __('Page Width', 'embedpress'),
477 'custom' => __('Custom', 'embedpress'),
478 '50' => __('50%', 'embedpress'),
479 '75' => __('75%', 'embedpress'),
480 '100' => __('100%', 'embedpress'),
481 '125' => __('125%', 'embedpress'),
482 '150' => __('150%', 'embedpress'),
483 '200' => __('200%', 'embedpress'),
484 '300' => __('300%', 'embedpress'),
485 '400' => __('400%', 'embedpress'),
486 ],
487 'condition' => [
488 'embedpress_pdf_viewer_style' => 'modern'
489 ]
490 ]
491 );
492 $this->add_control(
493 'embedpress_pdf_zoom_custom',
494 [
495 'label' => __('Custom Zoom', 'embedpress'),
496 'type' => Controls_Manager::NUMBER,
497 'condition' => [
498 'embedpress_pdf_zoom' => 'custom'
499 ],
500 ]
501 );
502 $this->add_control(
503 'embedpress_pdf_page_number',
504 [
505 'label' => __('Open at Page', 'embedpress'),
506 'description' => __('Set the page number to open the PDF at. Visitors can also use ?eppage=N in the URL.', 'embedpress'),
507 'type' => Controls_Manager::NUMBER,
508 'default' => 1,
509 'min' => 1,
510 ]
511 );
512 $this->add_responsive_control(
513 'embedpress_elementor_document_width',
514 [
515 'type' => \Elementor\Controls_Manager::SLIDER,
516 'label' => esc_html__( 'Width', 'embedpress' ),
517 'size_units' => [ 'px', '%' ],
518 'range' => [
519 'px' => [
520 'min' => 1,
521 'max' => 1500,
522 ],
523 ],
524 'devices' => [ 'desktop', 'tablet', 'mobile' ],
525 'default' => [
526 'unit' => '%',
527 'size' => !empty($value = intval(Helper::get_options_value('enableEmbedResizeWidth'))) ? $value : 600,
528 ],
529 'desktop_default' => [
530 'unit' => 'px',
531 'size' => 600,
532 ],
533 'tablet_default' => [
534 'size' => 400,
535 'unit' => 'px',
536 ],
537 'mobile_default' => [
538 'size' => 300,
539 'unit' => 'px',
540 ],
541 'selectors' => [
542 '{{WRAPPER}} .embedpress-document-embed iframe, , {{WRAPPER}} .ep-share-position-bottom .ep-embed-content-wraper' => 'width: {{SIZE}}{{UNIT}}!important; max-width: {{SIZE}}{{UNIT}}!important',
543 // '{{WRAPPER}} .embedpress-document-embed' => 'width: {{SIZE}}{{UNIT}}; max-width: 100%',
544 // '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%',
545 ],
546 'render_type' => 'template',
547 ]
548 );
549 $this->add_responsive_control(
550 'embedpress_elementor_document_height',
551 [
552 'type' => \Elementor\Controls_Manager::SLIDER,
553 'label' => esc_html__( 'Height', 'embedpress' ),
554 'range' => [
555 'px' => [
556 'min' => 1,
557 'max' => 2000,
558 ],
559 ],
560 'devices' => [ 'desktop', 'tablet', 'mobile' ],
561 'default' => [
562 'unit' => 'px',
563 'size' => !empty($value = intval(Helper::get_options_value('enableEmbedResizeHeight'))) ? $value : 600,
564
565 ],
566 'desktop_default' => [
567 'unit' => 'px',
568 'size' => 600,
569 ],
570 'tablet_default' => [
571 'size' => 400,
572 'unit' => 'px',
573 ],
574 'mobile_default' => [
575 'size' => 300,
576 'unit' => 'px',
577 ],
578 'selectors' => [
579 '{{WRAPPER}} .embedpress-document-embed iframe' => 'height: {{SIZE}}{{UNIT}}!important;',
580 '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'height: {{SIZE}}{{UNIT}}!important;',
581 ],
582 'render_type' => 'template',
583 ]
584 );
585
586 $this->add_responsive_control(
587 'embedpress_elementor_document_align',
588 [
589 'label' => __('Alignment', 'embedpress'),
590 'type' => Controls_Manager::CHOOSE,
591 'options' => [
592 'left' => [
593 'title' => __('Left', 'embedpress'),
594 'icon' => 'eicon-text-align-left',
595 ],
596 'center' => [
597 'title' => __('Center', 'embedpress'),
598 'icon' => 'eicon-text-align-center',
599 ],
600 'right' => [
601 'title' => __('Right', 'embedpress'),
602 'icon' => 'eicon-text-align-right',
603 ]
604 ],
605 'prefix_class' => 'elementor%s-align-',
606 'default' => '',
607 ]
608 );
609
610 // Get global powered_by setting
611 $g_settings = get_option(EMBEDPRESS_PLG_NAME, []);
612 $powered_by_default = isset($g_settings['embedpress_document_powered_by']) && $g_settings['embedpress_document_powered_by'] === 'yes' ? 'yes' : 'no';
613
614 $this->add_control(
615 'embedpress_pdf_powered_by',
616 [
617 'label' => __('Powered By', 'embedpress'),
618 'type' => Controls_Manager::SWITCHER,
619 'label_on' => __('Show', 'embedpress'),
620 'label_off' => __('Hide', 'embedpress'),
621 'return_value' => 'yes',
622 'default' => apply_filters('embedpress_document_powered_by_control', $powered_by_default),
623 'condition' => [
624 'embedpress_pdf_display_mode' => 'inline',
625 ],
626 ]
627 );
628
629 $this->init_branding_controls('document');
630
631 $this->end_controls_section();
632
633
634 /**
635 * EmbedPress PDF Control Settings
636 */
637
638 $this->start_controls_section(
639 'embedpress_pdf_content_settings',
640 [
641 'label' => esc_html__('Controls', 'embedpress'),
642 'conditions' => [
643 'relation' => 'or',
644 'terms' => [
645 ['name' => 'embedpress_pdf_type', 'operator' => '===', 'value' => 'file'],
646 ['name' => 'embedpress_pdf_file_link_from', 'operator' => '===', 'value' => 'self'],
647 ],
648 ],
649 ]
650 );
651
652
653 $this->add_control(
654 'embedpress_theme_mode',
655 [
656 'label' => __('Theme', 'embedpress'),
657 'type' => Controls_Manager::SELECT,
658 'default' => 'default',
659 'options' => [
660 'default' => __('System Default', 'embedpress'),
661 'dark' => __('Dark', 'embedpress'),
662 'light' => __('Light', 'embedpress'),
663 'custom' => __('Custom', 'embedpress')
664 ],
665 ]
666 );
667
668 $this->add_control(
669 'embedpress_pdf_custom_color',
670 [
671 'label' => esc_html__( 'Color', 'embedpress' ),
672 'type' => \Elementor\Controls_Manager::COLOR,
673 // 'default' => Helper::get_options_value('custom_color'),
674 'global' => [
675 'default' => Global_Colors::COLOR_PRIMARY,
676 ],
677 'condition' => [
678 'embedpress_theme_mode' => 'custom',
679 ],
680 ]
681 );
682
683 $this->add_control(
684 'pdf_toolbar',
685 [
686 'label' => sprintf(__('Toolbar %s', 'embedpress'), $this->pro_text),
687 'type' => Controls_Manager::SWITCHER,
688 'label_on' => __('Show', 'embedpress'),
689 'label_off' => __('Hide', 'embedpress'),
690 'return_value' => 'yes',
691 'default' => 'yes',
692 'classes' => $this->pro_class,
693 ]
694 );
695
696
697 $this->add_control(
698 'pdf_toolbar_position',
699 [
700 'label' => esc_html__('Toolbar Position', 'embedpress'),
701 'type' => \Elementor\Controls_Manager::CHOOSE,
702 'options' => [
703 'top' => [
704 'title' => esc_html__('Top', 'embedpress'),
705 'icon' => 'eicon-arrow-up',
706 ],
707 'bottom' => [
708 'title' => esc_html__('Bottom', 'embedpress'),
709 'icon' => 'eicon-arrow-down',
710 ],
711 ],
712 'default' => 'top',
713 'toggle' => true,
714 'condition' => [
715 'pdf_toolbar' => 'yes',
716 'embedpress_pdf_viewer_style' => 'modern',
717 ],
718 ]
719 );
720 $this->add_control(
721 'flipbook_toolbar_position',
722 [
723 'label' => esc_html__('Toolbar Position', 'embedpress'),
724 'type' => \Elementor\Controls_Manager::CHOOSE,
725 'options' => [
726 'top' => [
727 'title' => esc_html__('Top', 'embedpress'),
728 'icon' => 'eicon-arrow-up',
729 ],
730 'bottom' => [
731 'title' => esc_html__('Bottom', 'embedpress'),
732 'icon' => 'eicon-arrow-down',
733 ],
734 ],
735 'default' => 'bottom',
736 'toggle' => true,
737 'condition' => [
738 'pdf_toolbar' => 'yes',
739 'embedpress_pdf_viewer_style' => 'flip-book',
740 ],
741 ]
742 );
743
744
745 $this->add_control(
746 'pdf_print_download',
747 [
748 'label' => sprintf(__('Print/Download %s', 'embedpress'), $this->pro_text),
749 'type' => Controls_Manager::SWITCHER,
750 'label_on' => __('Show', 'embedpress'),
751 'label_off' => __('Hide', 'embedpress'),
752 'return_value' => 'yes',
753 'default' => 'yes',
754 'classes' => $this->pro_class,
755 'condition' => [
756 'pdf_toolbar' => 'yes',
757 ],
758 ]
759 );
760
761
762
763 $this->add_control(
764 'pdf_zoom_in',
765 [
766 'label' => __('Zoom In', 'embedpress'),
767 'type' => Controls_Manager::SWITCHER,
768 'label_on' => __('Show', 'embedpress'),
769 'label_off' => __('Hide', 'embedpress'),
770 'return_value' => 'yes',
771 'default' => 'yes',
772 'condition' => [
773 'pdf_toolbar' => 'yes',
774 'embedpress_pdf_viewer_style' => 'flip-book',
775 ],
776 ]
777 );
778 $this->add_control(
779 'pdf_zoom_out',
780 [
781 'label' => __('Zoom Out', 'embedpress'),
782 'type' => Controls_Manager::SWITCHER,
783 'label_on' => __('Show', 'embedpress'),
784 'label_off' => __('Hide', 'embedpress'),
785 'return_value' => 'yes',
786 'default' => 'yes',
787 'condition' => [
788 'pdf_toolbar' => 'yes',
789 'embedpress_pdf_viewer_style' => 'flip-book',
790 ],
791 ]
792 );
793 $this->add_control(
794 'pdf_fit_view',
795 [
796 'label' => __('Fit View', 'embedpress'),
797 'type' => Controls_Manager::SWITCHER,
798 'label_on' => __('Show', 'embedpress'),
799 'label_off' => __('Hide', 'embedpress'),
800 'return_value' => 'yes',
801 'default' => 'yes',
802 'condition' => [
803 'pdf_toolbar' => 'yes',
804 'embedpress_pdf_viewer_style' => 'flip-book',
805 ],
806 ]
807 );
808 $this->add_control(
809 'pdf_bookmark',
810 [
811 'label' => __('Bookmark', 'embedpress'),
812 'type' => Controls_Manager::SWITCHER,
813 'label_on' => __('Show', 'embedpress'),
814 'label_off' => __('Hide', 'embedpress'),
815 'return_value' => 'yes',
816 'default' => 'yes',
817 'condition' => [
818 'pdf_toolbar' => 'yes',
819 'embedpress_pdf_viewer_style' => 'flip-book',
820 ],
821 ]
822 );
823
824 $this->add_control(
825 'pdf_sound',
826 [
827 'label' => __('Flip Sound', 'embedpress'),
828 'type' => Controls_Manager::SWITCHER,
829 'label_on' => __('On', 'embedpress'),
830 'label_off' => __('Off', 'embedpress'),
831 'return_value' => 'yes',
832 'default' => 'yes',
833 'condition' => [
834 'embedpress_pdf_viewer_style' => 'flip-book',
835 ],
836 ]
837 );
838
839 $this->add_control(
840 'pdf_flipbook_rtl',
841 [
842 'label' => sprintf(__('RTL Page Flip %s', 'embedpress'), $this->pro_text),
843 'description' => __('Reverse the page-turn direction so the flipbook opens and flips from right to left.', 'embedpress'),
844 'type' => Controls_Manager::SWITCHER,
845 'label_on' => __('On', 'embedpress'),
846 'label_off' => __('Off', 'embedpress'),
847 'return_value' => 'yes',
848 'default' => '',
849 'classes' => $this->pro_class,
850 'condition' => [
851 'embedpress_pdf_viewer_style' => 'flip-book',
852 ],
853 ]
854 );
855
856 $this->add_control(
857 'pdf_flipbook_highlight_links',
858 [
859 'label' => __('Highlight Links', 'embedpress'),
860 'description' => __('Show a colored background behind hyperlinks in the flipbook.', 'embedpress'),
861 'type' => Controls_Manager::SWITCHER,
862 'label_on' => __('On', 'embedpress'),
863 'label_off' => __('Off', 'embedpress'),
864 'return_value' => 'yes',
865 'default' => '',
866 'condition' => [
867 'embedpress_pdf_viewer_style' => 'flip-book',
868 ],
869 ]
870 );
871
872 $this->add_control(
873 'pdf_flipbook_highlight_color',
874 [
875 'label' => __('Highlight Color', 'embedpress'),
876 'type' => Controls_Manager::COLOR,
877 'default' => 'rgba(255, 255, 0, 0.1)',
878 'condition' => [
879 'embedpress_pdf_viewer_style' => 'flip-book',
880 'pdf_flipbook_highlight_links' => 'yes',
881 ],
882 ]
883 );
884
885
886 $this->add_control(
887 'pdf_presentation_mode',
888 [
889 'label' => __('PDF Presentation Mode', 'embedpress'),
890 'type' => Controls_Manager::SWITCHER,
891 'label_on' => __('Show', 'embedpress'),
892 'label_off' => __('Hide', 'embedpress'),
893 'return_value' => 'yes',
894 'default' => 'yes',
895 'condition' => [
896 'pdf_toolbar' => 'yes',
897 ],
898 ]
899 );
900 $this->add_control(
901 'pdf_lazyload',
902 [
903 'label' => __('Lazy Load', 'embedpress'),
904 'type' => Controls_Manager::SWITCHER,
905 'label_on' => __('Yes', 'embedpress'),
906 'label_off' => __('No', 'embedpress'),
907 'return_value' => 'yes',
908 'default' => '',
909 'condition' => [
910 'pdf_toolbar' => 'yes',
911 ],
912 ]
913 );
914
915 $this->add_control(
916 'pdf_text_copy',
917 [
918 'label' => sprintf(__('Copy Text %s', 'embedpress'), $this->pro_text),
919 'type' => Controls_Manager::SWITCHER,
920 'label_on' => __('Show', 'embedpress'),
921 'label_off' => __('Hide', 'embedpress'),
922 'return_value' => 'yes',
923 'default' => 'yes',
924 'classes' => $this->pro_class,
925 'condition' => [
926 'pdf_toolbar' => 'yes',
927 'embedpress_pdf_viewer_style' => 'modern',
928 ],
929 ]
930 );
931
932 $this->add_control(
933 'add_text',
934 [
935 'label' => sprintf(__('Add Text', 'embedpress')),
936 'type' => Controls_Manager::SWITCHER,
937 'label_on' => __('Show', 'embedpress'),
938 'label_off' => __('Hide', 'embedpress'),
939 'return_value' => 'yes',
940 'default' => 'yes',
941 'condition' => [
942 'pdf_toolbar' => 'yes',
943 'embedpress_pdf_viewer_style' => 'modern',
944 ],
945 ]
946 );
947 $this->add_control(
948 'draw',
949 [
950 'label' => sprintf(__('Draw %s', 'embedpress'), $this->pro_text),
951 'type' => Controls_Manager::SWITCHER,
952 'label_on' => __('Show', 'embedpress'),
953 'label_off' => __('Hide', 'embedpress'),
954 'return_value' => 'yes',
955 'default' => 'yes',
956 'classes' => $this->pro_class,
957 'condition' => [
958 'pdf_toolbar' => 'yes',
959 'embedpress_pdf_viewer_style' => 'modern',
960 ],
961 ]
962 );
963
964 $this->add_control(
965 'add_image',
966 [
967 'label' => __('Add Image', 'embedpress'),
968 'type' => Controls_Manager::SWITCHER,
969 'label_on' => __('Show', 'embedpress'),
970 'label_off' => __('Hide', 'embedpress'),
971 'return_value' => 'yes',
972 'default' => 'yes',
973 'condition' => [
974 'pdf_toolbar' => 'yes',
975 'embedpress_pdf_viewer_style' => 'modern',
976 ],
977 ]
978 );
979 $this->add_control(
980 'pdf_rotate_access',
981 [
982 'label' => __('Rotation', 'embedpress'),
983 'type' => Controls_Manager::SWITCHER,
984 'label_on' => __('Show', 'embedpress'),
985 'label_off' => __('Hide', 'embedpress'),
986 'return_value' => 'yes',
987 'default' => 'yes',
988 'condition' => [
989 'pdf_toolbar' => 'yes',
990 'embedpress_pdf_viewer_style' => 'modern',
991 ],
992 ]
993 );
994
995 $this->add_control(
996 'pdf_details',
997 [
998 'label' => __('Properties', 'embedpress'),
999 'type' => Controls_Manager::SWITCHER,
1000 'label_on' => __('Show', 'embedpress'),
1001 'label_off' => __('Hide', 'embedpress'),
1002 'return_value' => 'yes',
1003 'default' => 'yes',
1004 'condition' => [
1005 'pdf_toolbar' => 'yes',
1006 'embedpress_pdf_viewer_style' => 'modern',
1007 ],
1008 ]
1009 );
1010
1011 $this->add_control(
1012 'selection_tool',
1013 [
1014 'label' => sprintf(__('Default Selection Tool %s', 'embedpress'), $this->pro_text),
1015 'type' => \Elementor\Controls_Manager::SELECT,
1016 'options' => [
1017 '0' => esc_html__('Text Tool', 'embedpress'),
1018 '1' => esc_html__('Hand Tool', 'embedpress'),
1019 ],
1020 'default' => '0',
1021 'classes' => $this->pro_class,
1022
1023 ]
1024 );
1025
1026 $this->add_control(
1027 'scrolling',
1028 [
1029 'label' => sprintf(__('Default Scrolling %s', 'embedpress'), $this->pro_text),
1030 'type' => \Elementor\Controls_Manager::SELECT,
1031 'options' => [
1032 '-1' => esc_html__('Page Scrolling', 'embedpress'),
1033 '0' => esc_html__('Vertical Scrolling', 'embedpress'),
1034 '1' => esc_html__('Horizontal Scrolling', 'embedpress'),
1035 '2' => esc_html__('Wrapped Scrolling', 'embedpress'),
1036 ],
1037 'default' => '0',
1038 'classes' => $this->pro_class,
1039 ]
1040 );
1041
1042 $this->add_control(
1043 'spreads',
1044 [
1045 'label' => esc_html__('Default Spreads', 'embedpress'),
1046 'type' => \Elementor\Controls_Manager::SELECT,
1047 'options' => [
1048 '0' => esc_html__('No Spreads', 'embedpress'),
1049 '1' => esc_html__('Odd Spreads', 'embedpress'),
1050 '2' => esc_html__('Even Spreads', 'embedpress'),
1051 ],
1052 'default' => '-1',
1053 'condition' => [
1054 'scrolling!' => '1',
1055 ],
1056 ]
1057 );
1058
1059 $this->end_controls_section();
1060
1061 // Watermark Controls Section
1062 $this->start_controls_section(
1063 'embedpress_pdf_watermark_section',
1064 [
1065 'label' => __('Watermark', 'embedpress'),
1066 ]
1067 );
1068
1069 $this->add_control(
1070 'embedpress_watermark_text',
1071 [
1072 'label' => sprintf(__('Watermark Text %s', 'embedpress'), $this->pro_text),
1073 'type' => \Elementor\Controls_Manager::TEXT,
1074 'default' => '',
1075 'placeholder' => __('e.g. CONFIDENTIAL', 'embedpress'),
1076 'classes' => $this->pro_class,
1077 ]
1078 );
1079
1080 $this->add_control(
1081 'embedpress_watermark_style',
1082 [
1083 'label' => __('Watermark Style', 'embedpress'),
1084 'type' => \Elementor\Controls_Manager::SELECT,
1085 'options' => [
1086 'center' => __('Center Diagonal', 'embedpress'),
1087 'tiled' => __('Tiled / Repeated', 'embedpress'),
1088 ],
1089 'default' => 'center',
1090 'condition' => defined('EMBEDPRESS_SL_ITEM_SLUG') ? ['embedpress_watermark_text!' => ''] : [],
1091 'classes' => $this->pro_class,
1092 ]
1093 );
1094
1095 $this->add_control(
1096 'embedpress_watermark_font_size',
1097 [
1098 'label' => __('Font Size (px)', 'embedpress'),
1099 'type' => \Elementor\Controls_Manager::NUMBER,
1100 'default' => 48,
1101 'min' => 10,
1102 'max' => 200,
1103 'condition' => defined('EMBEDPRESS_SL_ITEM_SLUG') ? ['embedpress_watermark_text!' => ''] : [],
1104 'classes' => $this->pro_class,
1105 ]
1106 );
1107
1108 $this->add_control(
1109 'embedpress_watermark_color',
1110 [
1111 'label' => __('Color', 'embedpress'),
1112 'type' => \Elementor\Controls_Manager::COLOR,
1113 'default' => '#000000',
1114 'global' => [
1115 'default' => Global_Colors::COLOR_PRIMARY,
1116 ],
1117 'condition' => defined('EMBEDPRESS_SL_ITEM_SLUG') ? ['embedpress_watermark_text!' => ''] : [],
1118 'classes' => $this->pro_class,
1119 ]
1120 );
1121
1122 $this->add_control(
1123 'embedpress_watermark_opacity',
1124 [
1125 'label' => __('Opacity (%)', 'embedpress'),
1126 'type' => \Elementor\Controls_Manager::NUMBER,
1127 'default' => 15,
1128 'min' => 1,
1129 'max' => 100,
1130 'condition' => defined('EMBEDPRESS_SL_ITEM_SLUG') ? ['embedpress_watermark_text!' => ''] : [],
1131 'classes' => $this->pro_class,
1132 ]
1133 );
1134
1135 $this->end_controls_section();
1136
1137 do_action( 'extend_elementor_controls', $this, '_pdf_', $this->pro_text, $this->pro_class);
1138 $this->init_performance_controls();
1139 $this->init_stats_controls();
1140
1141 }
1142
1143 private function render_lightbox_thumbnail($url, $settings, $client_id)
1144 {
1145 $viewerStyle = $settings['embedpress_pdf_viewer_style'] ?? 'modern';
1146 $maxWidth = $settings['embedpress_elementor_document_width']['size'] . $settings['embedpress_elementor_document_width']['unit'];
1147 $customThumb = !empty($settings['embedpress_pdf_lightbox_thumbnail']['url']) ? $settings['embedpress_pdf_lightbox_thumbnail']['url'] : '';
1148
1149 // Fall back to WP's upload-time PDF poster so the browser does not have
1150 // to fetch the whole document to draw a preview (FB #84167).
1151 if (empty($customThumb)) {
1152 $customThumb = Helper::get_pdf_poster_url($url);
1153 }
1154 $align = $settings['embedpress_pdf_lightbox_align'] ?? 'left';
1155
1156 $alignStyle = '';
1157 if ($align === 'center') {
1158 $alignStyle = 'text-align: center;';
1159 } elseif ($align === 'right') {
1160 $alignStyle = 'text-align: right;';
1161 }
1162
1163 // Generate base64 viewer params (reuse getParamData but extract just the base64 key)
1164 $paramString = $this->getParamData($settings);
1165 $viewerParams = '';
1166 if (preg_match('/key=(.+)$/', $paramString, $matches)) {
1167 $viewerParams = $matches[1];
1168 }
1169
1170 $pdfTitle = Helper::get_file_title($url);
1171 $stats_attrs = $this->get_stats_optout_attrs($settings);
1172 ?>
1173 <div class="embedpress-document-embed ose-document ep-doc-<?php echo esc_attr(md5('embedpress-pdf-' . $client_id)); ?>"
1174 style="max-width: <?php echo esc_attr($maxWidth); ?>; <?php echo esc_attr($alignStyle); ?>"
1175 data-embed-type="PDF"<?php echo $stats_attrs; // phpcs:ignore -- attrs are pre-escaped in helper ?>>
1176 <div class="ep-pdf-thumbnail-card" style="display:inline-block;text-align:center;max-width:100%;cursor:pointer;">
1177 <div class="ep-pdf-thumbnail-wrap"
1178 style="position:relative;display:inline-block;max-width:100%;"
1179 data-pdf-url="<?php echo esc_url($url); ?>"
1180 data-viewer-style="<?php echo esc_attr($viewerStyle); ?>"
1181 data-viewer-params="<?php echo esc_attr($viewerParams); ?>">
1182 <div class="ep-pdf-thumbnail-inner" style="position:relative;display:inline-block;max-width:100%;background:#fff;border-radius:4px;overflow:hidden;">
1183 <?php if (!empty($customThumb)): ?>
1184 <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;" />
1185 <?php else: ?>
1186 <canvas class="ep-pdf-thumbnail-canvas"
1187 data-pdf-url="<?php echo esc_url($url); ?>"
1188 data-loading="true"
1189 style="display:block;max-width:100%;height:auto;min-height:280px;min-width:200px;"></canvas>
1190 <?php endif; ?>
1191 <div class="ep-pdf-thumbnail-overlay" style="position:absolute;inset:0;display:flex;align-items:center;justify-content:center;pointer-events:none;">
1192 <div class="ep-pdf-thumbnail-icon-circle">
1193 <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>
1194 </div>
1195 </div>
1196 </div>
1197 </div>
1198
1199 </div>
1200 </div>
1201 <?php
1202 }
1203
1204 private function render_trigger_element($url, $settings, $client_id, $mode)
1205 {
1206 $viewerStyle = $settings['embedpress_pdf_viewer_style'] ?? 'modern';
1207 $triggerText = !empty($settings['embedpress_pdf_trigger_text']) ? $settings['embedpress_pdf_trigger_text'] : 'View PDF';
1208
1209 $paramString = $this->getParamData($settings);
1210 $viewerParams = '';
1211 if (preg_match('/key=(.+)$/', $paramString, $matches)) {
1212 $viewerParams = $matches[1];
1213 }
1214 $stats_attrs = $this->get_stats_optout_attrs($settings);
1215 ?>
1216 <div class="embedpress-document-embed ose-document ep-doc-<?php echo esc_attr(md5('embedpress-pdf-' . $client_id)); ?>"
1217 data-embed-type="PDF"<?php echo $stats_attrs; // phpcs:ignore -- attrs are pre-escaped in helper ?>>
1218 <div class="ep-pdf-thumbnail-wrap"
1219 data-pdf-url="<?php echo esc_url($url); ?>"
1220 data-viewer-style="<?php echo esc_attr($viewerStyle); ?>"
1221 data-viewer-params="<?php echo esc_attr($viewerParams); ?>">
1222 <span class="ep-pdf-trigger ep-pdf-trigger--<?php echo esc_attr($mode); ?>"><?php echo esc_html($triggerText); ?></span>
1223 </div>
1224 </div>
1225 <?php
1226 }
1227
1228 private function is_pdf($url)
1229 {
1230 $arr = explode('.', $url);
1231 return end($arr) === 'pdf';
1232 }
1233
1234 public function render()
1235 {
1236 $settings = $this->get_settings();
1237
1238 Helper::get_enable_settings_data_for_scripts($settings);
1239
1240 $is_editor_view = Plugin::$instance->editor->is_edit_mode();
1241 $url = $this->get_file_url();
1242
1243 if (
1244 $settings['embedpress_pdf_type'] === 'url'
1245 && !empty($settings['__dynamic__']['embedpress_pdf_file_link'])
1246 ) {
1247 // ACF / Toolset / JetEngine dynamic-tag resolution has been a free
1248 // capability of this widget since ddb2e1efe (Jun 2024) — do NOT
1249 // Pro-gate it. The newer Gutenberg block / shortcode "Dynamic
1250 // Source" flow is gated separately in
1251 // EmbedPressBlockRenderer::apply_dynamic_source and
1252 // Shortcode::parseContent.
1253 $resolved = DynamicFieldResolver::resolve_elementor_dynamic($settings['__dynamic__']['embedpress_pdf_file_link']);
1254 if ($resolved !== '') {
1255 $url = $resolved;
1256 }
1257 }
1258
1259 $client_id = $this->get_id();
1260
1261 $this->_render($url, $settings, $client_id, $is_editor_view);
1262 Helper::get_source_data(md5($this->get_id()).'_eb_elementor', $url, 'elementor_source_data', 'elementor_temp_source_data');
1263 }
1264
1265
1266 public function getParamData($settings){
1267 $urlParamData = array(
1268 'themeMode' => $settings['embedpress_theme_mode'],
1269 'toolbar' => !empty($settings['pdf_toolbar']) ? 'true' : 'false',
1270 'position' => $settings['pdf_toolbar_position'],
1271 'presentation' => !empty($settings['pdf_presentation_mode']) ? 'true' : 'false',
1272 'lazyLoad' => !empty($settings['pdf_lazyload']) ? 'true' : 'false',
1273 'download' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['pdf_print_download'] : 'true',
1274 'copy_text' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['pdf_text_copy'] : 'true',
1275 'add_text' => !empty($settings['add_text']) ? 'true' : 'false',
1276 'draw' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['draw'] : 'true',
1277 'add_image' => !empty($settings['add_image']) ? 'true' : 'false',
1278 'pdf_rotation' => !empty($settings['pdf_rotate_access']) ? 'true' : 'false',
1279 'pdf_details' => !empty($settings['pdf_details']) ? 'true' : 'false',
1280 'zoom_in' => !empty($settings['pdf_zoom_in']) ? 'true' : 'false',
1281 'zoom_out' => !empty($settings['pdf_zoom_out']) ? 'true' : 'false',
1282 'fit_view' => !empty($settings['pdf_fit_view']) ? 'true' : 'false',
1283 'bookmark' => !empty($settings['pdf_bookmark']) ? 'true' : 'false',
1284 'sound' => !empty($settings['pdf_sound']) ? 'true' : 'false',
1285 'flipbook_toolbar_position' => !empty($settings['flipbook_toolbar_position']) ? $settings['flipbook_toolbar_position'] : 'bottom',
1286 'flipbook_rtl' => defined('EMBEDPRESS_SL_ITEM_SLUG') && !empty($settings['pdf_flipbook_rtl']) && $settings['pdf_flipbook_rtl'] === 'yes' ? 'true' : 'false',
1287 'flipbook_highlight_links' => !empty($settings['pdf_flipbook_highlight_links']) && $settings['pdf_flipbook_highlight_links'] === 'yes' ? 'true' : 'false',
1288 'flipbook_highlight_color' => !empty($settings['pdf_flipbook_highlight_color']) ? esc_attr($settings['pdf_flipbook_highlight_color']) : '',
1289 'selection_tool' => isset($settings['selection_tool']) ? esc_attr($settings['selection_tool']) : '0',
1290 'scrolling' => isset($settings['scrolling']) ? esc_attr($settings['scrolling']) : '-1',
1291 'spreads' => isset($settings['spreads']) ? esc_attr($settings['spreads']) : '-1',
1292 'is_pro_active' => apply_filters('embedpress/is_allow_rander', false),
1293 'pageNumber' => !empty($settings['embedpress_pdf_page_number']) ? absint($settings['embedpress_pdf_page_number']) : 1,
1294 'watermark_text' => defined('EMBEDPRESS_SL_ITEM_SLUG') && !empty($settings['embedpress_watermark_text']) ? $settings['embedpress_watermark_text'] : '',
1295 'watermark_font_size' => defined('EMBEDPRESS_SL_ITEM_SLUG') && !empty($settings['embedpress_watermark_font_size']) ? $settings['embedpress_watermark_font_size'] : '48',
1296 'watermark_color' => defined('EMBEDPRESS_SL_ITEM_SLUG') && !empty($settings['embedpress_watermark_color']) ? Helper::get_elementor_global_color($settings, 'embedpress_watermark_color') : '#000000',
1297 'watermark_opacity' => defined('EMBEDPRESS_SL_ITEM_SLUG') && isset($settings['embedpress_watermark_opacity']) ? $settings['embedpress_watermark_opacity'] : '15',
1298 'watermark_style' => defined('EMBEDPRESS_SL_ITEM_SLUG') && !empty($settings['embedpress_watermark_style']) ? $settings['embedpress_watermark_style'] : 'center',
1299
1300 );
1301
1302 $custom_color = Helper::get_elementor_global_color($settings, 'embedpress_pdf_custom_color');
1303
1304 if($settings['embedpress_theme_mode'] == 'custom') {
1305 $urlParamData['customColor'] = $custom_color;
1306 }
1307
1308 if($settings['embedpress_pdf_viewer_style'] == 'flip-book'){
1309 return "&key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), "UTF-8"));
1310 }
1311
1312 return "#key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), "UTF-8"));
1313
1314 }
1315
1316 public function _render($url, $settings, $id, $is_editor_view = false)
1317 {
1318
1319 $custom_color = Helper::get_elementor_global_color($settings, 'embedpress_pdf_custom_color');
1320
1321 $unitoption = 'emebedpress-unit-px';
1322 if($settings['embedpress_elementor_document_width']['unit'] === '%'){
1323 $unitoption = 'emebedpress-unit-percent';
1324 }
1325 $client_id = $id;
1326 $id = 'embedpress-pdf-' . $id;
1327 $hash_pass = hash('sha256', wp_salt(32) . md5($settings['embedpress_pdf_lock_content_password']));
1328
1329 $dimension = '';
1330
1331 $password_correct = isset($_COOKIE['password_correct_' . $client_id]) ? sanitize_text_field($_COOKIE['password_correct_' . $client_id]) : '';
1332
1333 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))){
1334 $dimension = "width: {$settings['embedpress_elementor_document_width']['size']}{$settings['embedpress_elementor_document_width']['unit']}!important;height: {$settings['embedpress_elementor_document_height']['size']}px;";
1335 }
1336
1337 $content_protection_class = 'ep-content-protection-enabled';
1338 $content_locked_class = 'ep-content-locked';
1339 if(empty($settings['embedpress_pdf_lock_content']) || empty($settings['embedpress_pdf_lock_content_password']) || $hash_pass === $password_correct) {
1340 $content_locked_class = '';
1341 $content_protection_class = 'ep-content-protection-disabled';
1342 }
1343
1344 $pass_hash_key = md5($settings['embedpress_pdf_lock_content_password']);
1345 // Generate content ID for analytics tracking
1346 $content_id = md5($url . 'pdf-elementor');
1347
1348 // Track PDF widget usage for analytics
1349 $this->track_pdf_widget_usage($settings, $url, $content_id);
1350
1351 $pdf_render_attrs = [
1352 'class' => ['embedpress-embed-document-pdf', esc_attr($id)],
1353 'data-emid' => esc_attr($id),
1354 // 'data-embedpress-content' => esc_attr($content_id),
1355 'data-embed-type' => 'PDF'
1356 ];
1357 // Per-embed override for the engagement-stats badge (default = off).
1358 // Explicit on/off lets the per-embed toggle win over the global option.
1359 $pdf_render_attrs['data-ep-views'] = (isset($settings['embedpress_pdf_show_view_count']) && $settings['embedpress_pdf_show_view_count'] === 'yes') ? 'on' : 'off';
1360 $pdf_render_attrs['data-ep-downloads'] = (isset($settings['embedpress_pdf_show_download_count']) && $settings['embedpress_pdf_show_download_count'] === 'yes') ? 'on' : 'off';
1361 // Badge position is Pro-only; only emit a non-default placement when Pro is active.
1362 $pdf_position = isset($settings['embedpress_pdf_count_position']) ? (string) $settings['embedpress_pdf_count_position'] : 'below';
1363 if ($pdf_position !== 'below' && \EmbedPress\Includes\Classes\Helper::is_pro_active()) {
1364 $pdf_render_attrs['data-ep-count-position'] = $pdf_position;
1365 }
1366 $this->add_render_attribute('embedpres-pdf-render', $pdf_render_attrs);
1367 $this->add_render_attribute('embedpress-document', [
1368 'class' => ['embedpress-document-embed', 'ep-doc-' . md5($id), 'ose-document', $unitoption, $content_locked_class ],
1369 'data-thememode' => isset($settings['embedpress_theme_mode']) ? esc_attr($settings['embedpress_theme_mode']) : '',
1370 'data-customcolor' => isset($custom_color) ? esc_attr($custom_color) : '',
1371 'data-toolbar' => isset($settings['pdf_toolbar']) ? esc_attr($settings['pdf_toolbar']) : '',
1372 'data-toolbar-position' => isset($settings['pdf_toolbar_position']) ? esc_attr($settings['pdf_toolbar_position']) : 'top',
1373 'data-open' => 'no', // Assuming 'no' is a static value, no need to sanitize
1374 'data-presentation-mode' => isset($settings['pdf_presentation_mode']) ? esc_attr($settings['pdf_presentation_mode']) : '',
1375 'data-download' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION') ? esc_attr($settings['pdf_print_download']) : 'yes', // Assuming 'yes' is a safe fallback
1376 'data-copy' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION') ? esc_attr($settings['pdf_text_copy']) : 'yes', // Assuming 'yes' is a safe fallback
1377 'data-add-image' => isset($settings['add_image']) ? esc_attr($settings['add_image']) : '',
1378 'data-rotate' => isset($settings['pdf_rotate_access']) ? esc_attr($settings['pdf_rotate_access']) : '',
1379 'data-details' => isset($settings['pdf_details']) ? esc_attr($settings['pdf_details']) : '',
1380 'data-id' => $id, // Assuming $id is safe, no need to sanitize
1381 'data-selection-tool' => isset($settings['selection_tool']) ? esc_attr($settings['selection_tool']) : '0',
1382 'data-scrolling' => isset($settings['scrolling']) ? esc_attr($settings['scrolling']) : '-1',
1383 'data-spreads' => isset($settings['spreads']) ? esc_attr($settings['spreads']) : '-1',
1384 ]);
1385
1386 $embed_settings = [];
1387 $embed_settings['customThumbnail'] = !empty($settings['embedpress_pdf_content_share_custom_thumbnail']['url']) ? esc_url($settings['embedpress_pdf_content_share_custom_thumbnail']['url']) : '';
1388
1389 $embed_settings['customTitle'] = !empty($settings['embedpress_pdf_content_title']) ? sanitize_text_field($settings['embedpress_pdf_content_title']) : Helper::get_file_title($url);
1390
1391 $embed_settings['customDescription'] = !empty($settings['embedpress_pdf_content_descripiton']) ? sanitize_text_field($settings['embedpress_pdf_content_descripiton']) : Helper::get_file_title($url);
1392
1393 $embed_settings['sharePosition'] = !empty($settings['embedpress_pdf_content_share_position']) ? sanitize_text_field($settings['embedpress_pdf_content_share_position']) : 'right';
1394
1395 // Add social share platform settings
1396 $embed_settings['shareFacebook'] = !empty($settings['embedpress_pdf_share_facebook']) ? true : false;
1397 $embed_settings['shareTwitter'] = !empty($settings['embedpress_pdf_share_twitter']) ? true : false;
1398 $embed_settings['sharePinterest'] = !empty($settings['embedpress_pdf_share_pinterest']) ? true : false;
1399 $embed_settings['shareLinkedin'] = !empty($settings['embedpress_pdf_share_linkedin']) ? true : false;
1400
1401 $embed_settings['lockHeading'] = !empty($settings['embedpress_pdf_lock_content_heading']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_heading']) : '';
1402
1403 $embed_settings['lockSubHeading'] = !empty($settings['embedpress_pdf_lock_content_sub_heading']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_sub_heading']) : '';
1404
1405 $embed_settings['lockErrorMessage'] = !empty($settings['embedpress_pdf_lock_content_error_message']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_error_message']) : '';
1406
1407 $embed_settings['passwordPlaceholder'] = !empty($settings['embedpress_pdf_password_placeholder']) ? sanitize_text_field($settings['embedpress_pdf_password_placeholder']) : '';
1408
1409 $embed_settings['submitButtonText'] = !empty($settings['embedpress_pdf_submit_button_text']) ? sanitize_text_field($settings['embedpress_pdf_submit_button_text']) : '';
1410
1411 $embed_settings['submitUnlockingText'] = !empty($settings['embedpress_pdf_submit_Unlocking_text']) ? sanitize_text_field($settings['embedpress_pdf_submit_Unlocking_text']) : '';
1412
1413 $embed_settings['enableFooterMessage'] = !empty($settings['embedpress_pdf_enable_footer_message']) ? sanitize_text_field($settings['embedpress_pdf_enable_footer_message']) : '';
1414
1415 $embed_settings['footerMessage'] = !empty($settings['embedpress_pdf_lock_content_footer_message']) ? sanitize_text_field($settings['embedpress_pdf_lock_content_footer_message']) : '';
1416
1417 $embed_settings['userRole'] = !empty($settings['embedpress_pdf_select_roles']) ? $settings['embedpress_pdf_select_roles'] : [];
1418
1419 $embed_settings['protectionMessage'] = !empty($settings['embedpress_pdf_protection_message']) ? $settings['embedpress_pdf_protection_message'] : '';
1420
1421
1422 if($settings['embedpress_elementor_document_width']['unit'] === '%'){
1423 $width_class = ' ep-percentage-width';
1424 }
1425 else{
1426 $width_class = 'ep-fixed-width';
1427 }
1428 $content_share_class = '';
1429 $share_position_class = '';
1430 $share_position = isset($settings['embedpress_pdf_content_share_position']) ? $settings['embedpress_pdf_content_share_position'] : 'right';
1431
1432 if(!empty($settings['embedpress_pdf_content_share'])) {
1433 $content_share_class = 'ep-content-share-enabled';
1434 $share_position_class = 'ep-share-position-'.$share_position;
1435 }
1436
1437 $adsAtts = '';
1438
1439 if (!empty($settings['adManager'])) {
1440 $ad = base64_encode(json_encode($settings)); // Using WordPress JSON encoding function
1441 $adsAtts = 'data-sponsored-id="' . esc_attr($client_id) . '" data-sponsored-attrs="' . esc_attr($ad) . '" class="sponsored-mask"';
1442 }
1443
1444 // Lightbox mode: render thumbnail instead of inline viewer
1445 $displayMode = !empty($settings['embedpress_pdf_display_mode']) ? $settings['embedpress_pdf_display_mode'] : 'inline';
1446 if ($displayMode === 'lightbox' && $url != '' && $this->is_pdf($url) && !$this->is_external_url($url) && empty($content_locked_class)) {
1447 $this->render_lightbox_thumbnail($url, $settings, $client_id);
1448 return;
1449 }
1450 if (in_array($displayMode, ['button', 'link', 'text']) && $url != '' && $this->is_pdf($url) && !$this->is_external_url($url) && empty($content_locked_class)) {
1451 $this->render_trigger_element($url, $settings, $client_id, $displayMode);
1452 return;
1453 }
1454
1455 ?>
1456 <div <?php echo $this->get_render_attribute_string('embedpress-document'); ?> style=" max-width:100%; display: inline-block">
1457
1458 <?php
1459 do_action('embedpress_pdf_after_embed', $settings, $url, $id, $this);
1460
1461 if ($url != '') {
1462 $url = esc_url($url);
1463
1464 if ($this->is_pdf($url) && !$this->is_external_url($url)) {
1465 $renderer = Helper::get_pdf_renderer();
1466 $src = $renderer . ((strpos($renderer, '?') === false) ? '?' : '&')
1467 . 'file=' . urlencode($url)
1468 . '&scrolling=' . $settings['scrolling']
1469 . '&selection_tool=' . $settings['selection_tool']
1470 . '&spreads=' . $settings['spreads']
1471 . $this->getParamData($settings);
1472
1473
1474 if (!empty($settings['embedpress_pdf_zoom'])) {
1475 $zoom = $settings['embedpress_pdf_zoom'];
1476 if ($zoom == 'custom') {
1477 if (!empty($settings['embedpress_pdf_zoom_custom'])) {
1478 $zoom = $settings['embedpress_pdf_zoom_custom'];
1479 } else {
1480 $zoom = null;
1481 }
1482 }
1483 if ($zoom) {
1484 $src = $src . "&zoom=$zoom";
1485 }
1486 }
1487
1488 if(isset($settings['embedpress_pdf_viewer_style']) && $settings['embedpress_pdf_viewer_style'] === 'modern') {
1489 $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).'"';
1490 }
1491 else{
1492 $src = urlencode($url).$this->getParamData($settings);
1493 $renderer = Helper::get_flipbook_renderer();
1494 $src_url = $renderer . ((strpos($renderer, '?') === false) ? '?' : '&') . 'file=' . $src;
1495 $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).'"';
1496 }
1497
1498
1499 $embed_content .= ' '.$this->get_render_attribute_string('embedpres-pdf-render').' frameborder="0"></iframe>';
1500 if ($settings['embedpress_pdf_powered_by'] === 'yes') {
1501 $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
1502 }
1503
1504 } else {
1505 $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).'"';
1506 $embed_content .= ' '.$this->get_render_attribute_string('embedpres-pdf-render').'></iframe>';
1507
1508 if ($settings['embedpress_pdf_powered_by'] === 'yes') {
1509 $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
1510 }
1511 }
1512
1513 ?>
1514
1515 <div <?php echo $adsAtts; ?>>
1516
1517 <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); ?>">
1518 <div id="<?php echo esc_attr( $this->get_id() ); ?>" class="ep-embed-content-wraper">
1519 <?php
1520 // Apply lazy loading if enabled (but not in editor mode)
1521 if (!empty($settings['enable_lazy_load']) && $settings['enable_lazy_load'] === 'yes' && !$is_editor_view) {
1522 $embed_content = preg_replace_callback(
1523 '/<iframe([^>]*)src=["\']([^"\']+)["\']([^>]*)>/i',
1524 function($matches) {
1525 $before = $matches[1];
1526 $src = $matches[2];
1527 $after = $matches[3];
1528
1529 // Extract style attribute if exists
1530 $style = '';
1531 if (preg_match('/style=["\']([^"\']+)["\']/i', $before . $after, $style_match)) {
1532 $style = $style_match[1];
1533 }
1534
1535 return sprintf(
1536 '<div class="ep-lazy-iframe-placeholder" data-ep-lazy-src="%s" data-ep-iframe-style="%s" %s %s style="%s"></div>',
1537 esc_attr($src),
1538 esc_attr($style),
1539 $before,
1540 $after,
1541 esc_attr($style)
1542 );
1543 },
1544 $embed_content
1545 );
1546 }
1547
1548 $embed = '<div>'.$embed_content.'</div>';
1549
1550 $content_id = $client_id;
1551 if(
1552
1553 (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') ||
1554 ($settings['embedpress_pdf_protection_type'] == 'password' && !empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct) ) ||
1555 !apply_filters('embedpress/is_allow_rander', false) ||
1556 ($settings['embedpress_pdf_protection_type'] == 'user-role' && Helper::has_allowed_roles($embed_settings['userRole']))
1557
1558 ){
1559 if(!empty($settings['embedpress_pdf_content_share'])){
1560 $embed .= Helper::embed_content_share($content_id, $embed_settings);
1561 }
1562 echo $embed ;
1563
1564 } else {
1565 if(!empty($settings['embedpress_pdf_content_share'])){
1566 $embed .= Helper::embed_content_share($content_id, $embed_settings);
1567 }
1568
1569 if ($settings['embedpress_pdf_protection_type'] == 'password') {
1570 do_action('embedpress/display_password_form', $client_id, $embed, $pass_hash_key, $embed_settings);
1571 } else {
1572 do_action('embedpress/content_protection_content', $client_id, $embed_settings['protectionMessage'], $embed_settings['userRole']);
1573 }
1574 }
1575 ?>
1576 </div>
1577
1578 </div>
1579
1580
1581 <?php
1582 $isAdEnabled = !empty($settings['adManager']);
1583 $isContentUnlocked = empty($settings['embedpress_pdf_lock_content']);
1584 $isPasswordCorrect = Helper::is_password_correct($client_id) && ($hash_pass === $password_correct);
1585
1586 if ($isAdEnabled && ($isContentUnlocked || $isPasswordCorrect)) {
1587 $embed_content = apply_filters('embedpress/generate_ad_template', $embed_content, $client_id, $settings, 'elementor');
1588 }
1589 ?>
1590
1591 </div>
1592 <?php
1593
1594 }
1595 ?>
1596
1597 </div>
1598
1599 <?php
1600 }
1601
1602 private function get_file_url()
1603 {
1604 $settings = $this->get_settings();
1605
1606 if (isset($settings['embedpress_pro_secure_mode']) && $settings['embedpress_pro_secure_mode'] === 'yes') {
1607 if (!empty($settings['embedpress_pdf_Uploader']['id'])) {
1608 $attachment_id = $settings['embedpress_pdf_Uploader']['id'];
1609 if (class_exists('\Embedpress\Pro\Classes\SecureFileHandler')) {
1610 $secure_url = \Embedpress\Pro\Classes\SecureFileHandler::get_instance()->ensure_secure_copy($attachment_id);
1611 if ($secure_url) {
1612 return $secure_url;
1613 }
1614 }
1615 }
1616 }
1617
1618 return $settings['embedpress_pdf_type'] === 'url' ? $settings['embedpress_pdf_file_link']['url'] : $settings['embedpress_pdf_Uploader']['url'];
1619 }
1620
1621 protected function is_external_url($url)
1622 {
1623 return strpos($url, get_site_url()) === false;
1624 }
1625
1626 /**
1627 * Track PDF widget usage for analytics
1628 *
1629 * @param array $settings
1630 * @param string $url
1631 * @param string $content_id
1632 * @return void
1633 */
1634 private function track_pdf_widget_usage($settings, $url, $content_id)
1635 {
1636 // Only track if analytics is enabled and we have the necessary classes
1637 if (class_exists('EmbedPress\Includes\Classes\Analytics\Analytics_Manager')) {
1638 if (empty($url)) {
1639 return;
1640 }
1641
1642 $provider_name = 'PDF';
1643
1644 $tracking_data = [
1645 'embed_type' => $provider_name,
1646 'embed_url' => $url,
1647 'post_id' => get_the_ID(),
1648 'page_url' => get_permalink(),
1649 'title' => get_the_title()
1650 ];
1651
1652 // Track content creation
1653 do_action('embedpress_content_embedded', $content_id, 'elementor-pdf', $tracking_data);
1654 }
1655 }
1656 }
1657