PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 4.6.0
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v4.6.0
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_Document.php
embedpress / EmbedPress / Elementor / Widgets Last commit date
Embedpress_Calendar.php 1 month ago Embedpress_Document.php 2 weeks ago Embedpress_Elementor.php 1 month ago Embedpress_Google_Reviews.php 5 days ago Embedpress_Pdf.php 5 days ago Embedpress_Pdf_Gallery.php 5 days ago
Embedpress_Document.php
1040 lines
1 <?php
2
3 namespace EmbedPress\Elementor\Widgets;
4
5
6 use \Elementor\Controls_Manager as Controls_Manager;
7 use \Elementor\Modules\DynamicTags\Module as TagsModule;
8 use \Elementor\Widget_Base as Widget_Base;
9 use \Elementor\Plugin;
10 use EmbedPress\Includes\Classes\DynamicFieldResolver;
11 use EmbedPress\Includes\Traits\Branding;
12 use EmbedPress\Includes\Classes\Helper;
13
14 ( defined( 'ABSPATH' ) ) or die( "No direct script access allowed." );
15
16 class Embedpress_Document extends Widget_Base
17 {
18 use Branding;
19 protected $pro_class = '';
20 protected $pro_text = '';
21 public function get_name()
22 {
23 return 'embedpres_document';
24 }
25
26 public function get_title()
27 {
28 return esc_html__( 'EmbedPress Document', 'embedpress' );
29 }
30
31 public function get_categories()
32 {
33 return ['embedpress'];
34 }
35
36 public function get_custom_help_url()
37 {
38 return 'https://embedpress.com/documentation';
39 }
40
41 public function get_icon()
42 {
43 return 'icon-document';
44 }
45
46 public function get_style_depends()
47 {
48 return [
49 'embedpress-elementor-css',
50 'embedpress-css'
51 ];
52 }
53
54 public function get_script_depends()
55 {
56
57 $handler_keys = get_option('enabled_elementor_scripts', []);
58
59 $handles = [];
60
61 $handles[] = 'embedpress-pdfobject';
62 $handles[] = 'embedpress-front';
63
64 if (isset($handler_keys['enabled_ads']) && $handler_keys['enabled_ads'] === 'yes') {
65 $handles[] = 'embedpress-ads';
66 }
67 if (isset($handler_keys['enabled_docs_custom_viewer']) && $handler_keys['enabled_docs_custom_viewer'] === 'yes') {
68 $handles[] = 'embedpress-documents-viewer';
69 }
70
71 return $handles;
72 }
73
74 /**
75 * Get widget keywords.
76 *
77 * Retrieve the list of keywords the widget belongs to.
78 *
79 * @return array Widget keywords.
80 * @since 2.5.5
81 * @access public
82 *
83 */
84 public function get_keywords()
85 {
86 return ['embedpress', 'pdf', 'doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'embedpress-document'];
87 }
88
89 /**
90 * Performance Settings Section
91 */
92 public function init_performance_controls()
93 {
94 // Get global lazy load setting
95 $g_settings = get_option(EMBEDPRESS_PLG_NAME, []);
96 $lazy_load_default = isset($g_settings['g_lazyload']) && $g_settings['g_lazyload'] == 1 ? 'yes' : '';
97
98 $this->start_controls_section(
99 'embedpress_performance_section',
100 [
101 'label' => __('Performance', 'embedpress'),
102 ]
103 );
104
105 $this->add_control(
106 'enable_lazy_load',
107 [
108 'label' => sprintf(__('Enable Lazy Loading %s', 'embedpress'), $this->pro_text),
109 'type' => \Elementor\Controls_Manager::SWITCHER,
110 'label_on' => __('Yes', 'embedpress'),
111 'label_off' => __('No', 'embedpress'),
112 'return_value' => 'yes',
113 'default' => $lazy_load_default,
114 'description' => __('Load iframe only when it enters the viewport for better performance', 'embedpress'),
115 'classes' => $this->pro_class,
116 ]
117 );
118
119 $this->end_controls_section();
120 }
121
122 /**
123 * Per-embed toggles for the visitor view-count / download-count badge.
124 * Default on; the frontend script honours the global option as the master
125 * gate and treats these switches as a per-embed opt-out.
126 */
127 public function init_stats_controls()
128 {
129 $this->start_controls_section(
130 'embedpress_stats_section',
131 [
132 'label' => __('Engagement Stats', 'embedpress'),
133 ]
134 );
135
136 $this->add_control(
137 'embedpress_doc_show_view_count',
138 [
139 'label' => __('Show View Count', 'embedpress'),
140 'type' => \Elementor\Controls_Manager::SWITCHER,
141 'label_on' => __('Show', 'embedpress'),
142 'label_off' => __('Hide', 'embedpress'),
143 'return_value' => 'yes',
144 'default' => '',
145 'description' => __('Display the visitor view counter on this embed.', 'embedpress'),
146 ]
147 );
148
149 $this->add_control(
150 'embedpress_doc_show_download_count',
151 [
152 'label' => __('Show Download Count', 'embedpress'),
153 'type' => \Elementor\Controls_Manager::SWITCHER,
154 'label_on' => __('Show', 'embedpress'),
155 'label_off' => __('Hide', 'embedpress'),
156 'return_value' => 'yes',
157 'default' => '',
158 'description' => __('Display the download counter on this embed.', 'embedpress'),
159 ]
160 );
161
162 // Count badge position — Pro-only (free keeps the default 'below').
163 $this->add_control(
164 'embedpress_doc_count_position',
165 [
166 'label' => sprintf(__('Count Position %s', 'embedpress'), $this->pro_text),
167 'type' => \Elementor\Controls_Manager::SELECT,
168 'default' => 'below',
169 'classes' => $this->pro_class,
170 'options' => [
171 'below' => __('Below — Left (default)', 'embedpress'),
172 'below-center' => __('Below — Center', 'embedpress'),
173 'below-right' => __('Below — Right', 'embedpress'),
174 'above-left' => __('Above — Left', 'embedpress'),
175 'above-center' => __('Above — Center', 'embedpress'),
176 'above-right' => __('Above — Right', 'embedpress'),
177 ],
178 'description' => __('Where the count badge sits relative to the embed.', 'embedpress'),
179 'condition' => [
180 'embedpress_doc_show_view_count' => 'yes',
181 ],
182 ]
183 );
184
185 $this->end_controls_section();
186 }
187
188 protected function register_controls()
189 {
190 $class = 'embedpress-pro-control not-active';
191 $text = '<sup class="embedpress-pro-label" style="color:red">' . __('Pro', 'embedpress') . '</sup>';
192 $this->pro_class = apply_filters('embedpress/pro_class', $class);
193 $this->pro_text = apply_filters('embedpress/pro_text', $text);
194
195 /**
196 * EmbedPress Content Settings
197 */
198 $this->start_controls_section(
199 'embedpress_document_content_settings',
200 [
201 'label' => esc_html__( 'General', 'embedpress' ),
202 ]
203 );
204
205 $this->add_control(
206 'embedpress_document_type',
207 [
208 'label' => __( 'Document Type', 'embedpress' ),
209 'type' => Controls_Manager::SELECT,
210 'default' => 'file',
211 'options' => [
212 'file' => __( 'File', 'embedpress' ),
213 'url' => __( 'URL', 'embedpress' )
214 ],
215 ]
216 );
217 $this->add_control(
218 'embedpress_document_Uploader',
219 [
220
221 'label' => __( 'Upload File', 'embedpress' ),
222 'type' => Controls_Manager::MEDIA,
223 'dynamic' => [
224 'active' => true,
225 'categories' => [
226 TagsModule::MEDIA_CATEGORY,
227 ],
228 ],
229 'media_type' => [
230 'application/pdf',
231 'application/msword',
232 'application/vnd.ms-powerpoint',
233 'application/vnd.ms-excel',
234 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
235 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
236 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
237 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' // Added PPSX MIME type
238
239 ],
240 'description' => __( 'Upload a file or pick one from your media library for embed. Supported File Type: PDF, DOC/DOCX, PPT/PPTX, XLS/XLSX etc.',
241 'embedpress' ),
242 'condition' => [
243 'embedpress_document_type' => 'file'
244 ],
245 ]
246 );
247
248 $this->add_control(
249 'embedpress_document_file_link',
250 [
251 'label' => __( 'URL', 'embedpress' ),
252 'type' => Controls_Manager::URL,
253 'placeholder' => __( 'https://your-link.com/file.pdf', 'embedpress' ),
254 'show_external' => false,
255 'dynamic' => [
256 'active' => true,
257 ],
258 'default' => [
259 'url' => ''
260 ],
261 'condition' => [
262 'embedpress_document_type' => 'url'
263 ],
264 ]
265 );
266
267 $this->add_responsive_control(
268 'embedpress_elementor_document_width',
269 [
270 'type' => \Elementor\Controls_Manager::SLIDER,
271 'label' => esc_html__( 'Width', 'embedpress' ),
272 'range' => [
273 'px' => [
274 'min' => 1,
275 'max' => 1000,
276 ],
277 ],
278 // 'devices' => [ 'desktop', 'tablet', 'mobile' ],
279 'default' => [
280 'unit' => 'px',
281 'size' => !empty($value = intval(Helper::get_options_value('enableEmbedResizeWidth'))) ? $value : 600,
282 ],
283 // 'desktop_default' => [
284 // 'unit' => 'px',
285 // 'size' => 600,
286 // ],
287 // 'tablet_default' => [
288 // 'size' => 400,
289 // 'unit' => 'px',
290 // ],
291 // 'mobile_default' => [
292 // 'size' => 300,
293 // 'unit' => 'px',
294 // ],
295 'selectors' => [
296 '{{WRAPPER}} .embedpress-document-embed iframe' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%; background-color: #fff',
297 '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%',
298 '{{WRAPPER}} .embedpress-document-embed' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%',
299 ],
300 ]
301 );
302 $this->add_responsive_control(
303 'embedpress_elementor_document_height',
304 [
305 'type' => \Elementor\Controls_Manager::SLIDER,
306 'label' => esc_html__( 'Height', 'embedpress' ),
307 'range' => [
308 'px' => [
309 'min' => 1,
310 'max' => 1500,
311 ],
312 ],
313 // 'devices' => [ 'desktop', 'tablet', 'mobile' ],
314 'default' => [
315 'unit' => 'px',
316 'size' => !empty($value = intval(Helper::get_options_value('enableEmbedResizeHeight'))) ? $value : 600,
317 ],
318 // 'desktop_default' => [
319 // 'unit' => 'px',
320 // 'size' => 600,
321 // ],
322 // 'tablet_default' => [
323 // 'size' => 400,
324 // 'unit' => 'px',
325 // ],
326 // 'mobile_default' => [
327 // 'size' => 300,
328 // 'unit' => 'px',
329 // ],
330 'selectors' => [
331 '{{WRAPPER}} .embedpress-document-embed iframe' => 'height: {{SIZE}}{{UNIT}}!important;',
332 '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'height: {{SIZE}}{{UNIT}};',
333 '{{WRAPPER}} .embedpress-document-embed ' => 'max-height: {{SIZE}}{{UNIT}};',
334 ],
335 ]
336 );
337
338 $this->add_responsive_control(
339 'embedpress_elementor_document_align',
340 [
341 'label' => __( 'Alignment', 'embedpress' ),
342 'type' => Controls_Manager::CHOOSE,
343 'options' => [
344 'left' => [
345 'title' => __( 'Left', 'embedpress' ),
346 'icon' => 'eicon-text-align-left',
347 ],
348 'center' => [
349 'title' => __( 'Center', 'embedpress' ),
350 'icon' => 'eicon-text-align-center',
351 ],
352 'right' => [
353 'title' => __( 'Right', 'embedpress' ),
354 'icon' => 'eicon-text-align-right',
355 ]
356 ],
357 'prefix_class' => 'elementor%s-align-',
358 'default' => '',
359 ]
360 );
361
362 // Get global powered_by setting
363 $g_settings = get_option(EMBEDPRESS_PLG_NAME, []);
364 $powered_by_default = isset($g_settings['embedpress_document_powered_by']) && $g_settings['embedpress_document_powered_by'] === 'yes' ? 'yes' : 'no';
365
366 $this->add_control(
367 'embedpress_document_powered_by',
368 [
369 'label' => __( 'Powered By', 'embedpress' ),
370 'type' => Controls_Manager::SWITCHER,
371 'label_on' => __( 'Show', 'embedpress' ),
372 'label_off' => __( 'Hide', 'embedpress' ),
373 'return_value' => 'yes',
374 'default' => apply_filters( 'embedpress_document_powered_by_control', $powered_by_default ),
375 ]
376 );
377
378 $this->init_branding_controls( 'document');
379
380
381
382 $this->end_controls_section();
383
384 /**
385 * EmbedPress Document control settings
386 */
387
388 $this->start_controls_section(
389 'embedpress_doc_content_settings',
390 [
391 'label' => esc_html__('Controls', 'embedpress'),
392 ]
393 );
394
395 $this->add_control(
396 'important_note',
397 [
398 'type' => \Elementor\Controls_Manager::RAW_HTML,
399 'raw' => esc_html__( 'Download feature is available when link has the document extension at the end.', 'embedpress' ),
400 'content_classes' => 'elementor-panel-alert elementor-panel-alert-info',
401 'condition' => [
402 'embedpress_document_type' => 'url',
403 ],
404 ]
405 );
406
407 $this->add_control(
408 'important_note_2',
409 [
410 'type' => \Elementor\Controls_Manager::RAW_HTML,
411 'raw' => esc_html__( 'Toolbar and additional feature options become accessible upon selecting the Custom Viewer mode.', 'embedpress' ),
412 'content_classes' => 'elementor-panel-alert elementor-panel-alert-info',
413 'condition' => [
414 'embedpress_document_type' => 'file',
415 'embedpress_document_viewer' => 'office',
416 ],
417 ]
418 );
419
420
421 $this->add_control(
422 'embedpress_document_viewer',
423 [
424 'label' => __('Viewer', 'embedpress'),
425 'type' => Controls_Manager::SELECT,
426 'default' => 'custom',
427 'options' => [
428 'custom' => __('Custom', 'embedpress'),
429 'office' => __('MS Office', 'embedpress'),
430 'google' => __('Google', 'embedpress'),
431 ],
432 ]
433 );
434
435 $this->add_control(
436 'embedpress_theme_mode',
437 [
438 'label' => __('Theme', 'embedpress'),
439 'type' => Controls_Manager::SELECT,
440 'default' => 'default',
441 'options' => [
442 'default' => __('System Default', 'embedpress'),
443 'dark' => __('Dark', 'embedpress'),
444 'light' => __('Light', 'embedpress'),
445 'custom' => __('Custom', 'embedpress')
446 ],
447 'condition' => [
448 'embedpress_document_viewer' => 'custom',
449 ],
450
451 ]
452 );
453
454 $this->add_control(
455 'embedpress_doc_custom_color',
456 [
457 'label' => esc_html__( 'Color', 'embedpress' ),
458 'type' => \Elementor\Controls_Manager::COLOR,
459 'condition' => [
460 'embedpress_theme_mode' => 'custom',
461 'embedpress_document_viewer' => 'custom',
462 ],
463 ]
464 );
465
466 $this->add_control(
467 'doc_toolbar',
468 [
469 'label' => sprintf(__('Toolbar %s', 'embedpress'), $this->pro_text),
470 'type' => Controls_Manager::SWITCHER,
471 'label_on' => __('Show', 'embedpress'),
472 'label_off' => __('Hide', 'embedpress'),
473 'return_value' => 'yes',
474 'default' => 'yes',
475 'classes' => $this->pro_class,
476 'condition' => [
477 'embedpress_document_viewer' => 'custom',
478 ],
479 ]
480 );
481
482
483 $this->add_control(
484 'doc_fullscreen_mode',
485 [
486 'label' => __('Fullscreen', 'embedpress'),
487 'type' => Controls_Manager::SWITCHER,
488 'label_on' => __('Show', 'embedpress'),
489 'label_off' => __('Hide', 'embedpress'),
490 'return_value' => 'yes',
491 'default' => 'yes',
492 'condition' => [
493 'doc_toolbar' => 'yes',
494 'embedpress_document_viewer' => 'custom',
495 ],
496 ]
497 );
498
499 $this->add_control(
500 'doc_print_download',
501 [
502 'label' => sprintf(__('Print/Download %s', 'embedpress'), $this->pro_text),
503 'type' => Controls_Manager::SWITCHER,
504 'label_on' => __('Show', 'embedpress'),
505 'label_off' => __('Hide', 'embedpress'),
506 'return_value' => 'yes',
507 'default' => 'yes',
508 'classes' => $this->pro_class,
509 'condition' => [
510 'doc_toolbar' => 'yes',
511 'embedpress_document_viewer' => 'custom',
512 ],
513 ]
514 );
515
516
517 $this->add_control(
518 'doc_draw',
519 [
520 'label' => __('Draw', 'embedpress'),
521 'type' => Controls_Manager::SWITCHER,
522 'label_on' => __('Show', 'embedpress'),
523 'label_off' => __('Hide', 'embedpress'),
524 'return_value' => 'yes',
525 'default' => 'yes',
526 'condition' => [
527 'doc_toolbar' => 'yes',
528 'embedpress_document_viewer' => 'custom',
529 ],
530 ]
531 );
532
533
534 $this->end_controls_section();
535
536 do_action( 'extend_elementor_controls', $this, '_doc_', $this->pro_text, $this->pro_class);
537
538 $this->init_performance_controls();
539 $this->init_stats_controls();
540
541
542 }
543
544 private function getParamData($settings)
545 {
546 $urlParamData = array(
547 'themeMode' => isset($settings['embedpress_theme_mode']) ? $settings['embedpress_theme_mode'] : 'default',
548 'toolbar' => !empty($settings['doc_toolbar']) ? 'true' : 'false',
549 'position' => 'top',
550 'presentation' => 'false',
551 'lazyLoad' => 'false',
552 'download' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION') ? $settings['doc_print_download'] : 'true',
553 'copy_text' => 'true',
554 'add_text' => 'false',
555 'draw' => !empty($settings['doc_draw']) ? 'true' : 'false',
556 'add_image' => 'false',
557 'pdf_rotation' => 'false',
558 'pdf_details' => 'false',
559 'zoom_in' => 'true',
560 'zoom_out' => 'true',
561 'fit_view' => 'true',
562 'bookmark' => 'false',
563 'sound' => 'false',
564 'flipbook_toolbar_position' => 'bottom',
565 'selection_tool' => '0',
566 'scrolling' => '-1',
567 'spreads' => '-1',
568 'is_pro_active' => apply_filters('embedpress/is_allow_rander', false),
569 'watermark_text' => '',
570 'watermark_font_size' => '48',
571 'watermark_color' => '#000000',
572 'watermark_opacity' => '15',
573 'watermark_style' => 'center',
574 );
575
576 $custom_color = Helper::get_elementor_global_color($settings, 'embedpress_doc_custom_color');
577
578 if (isset($settings['embedpress_theme_mode']) && $settings['embedpress_theme_mode'] == 'custom') {
579 $urlParamData['customColor'] = $custom_color;
580 }
581
582 return "#key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), "UTF-8"));
583 }
584
585 private function is_pdf( $url )
586 {
587 $arr = explode( '.', $url );
588 return end( $arr ) === 'pdf';
589 }
590
591 protected function render()
592 {
593 $settings = $this->get_settings();
594
595 Helper::get_enable_settings_data_for_scripts($settings);
596
597 $is_editor_view = Plugin::$instance->editor->is_edit_mode();
598 $client_id = esc_attr($this->get_id());
599 $pass_hash_key = md5($settings['embedpress_doc_lock_content_password']);
600 $url = esc_url($this->get_file_url());
601 $id = 'embedpress-pdf-' . esc_attr($this->get_id());
602
603 if (
604 $settings['embedpress_document_type'] === 'url'
605 && !empty($settings['__dynamic__']['embedpress_document_file_link'])
606 ) {
607 // ACF / Toolset / JetEngine dynamic-tag resolution has been a free
608 // capability of this widget since 2024 — do NOT Pro-gate it. The
609 // newer Gutenberg / shortcode "Dynamic Source" flow is gated
610 // separately in EmbedPressBlockRenderer::apply_dynamic_source
611 // and Shortcode::parseContent.
612 $resolved = DynamicFieldResolver::resolve_elementor_dynamic($settings['__dynamic__']['embedpress_document_file_link']);
613 if ($resolved !== '') {
614 $url = $resolved;
615 }
616 }
617 $hash_pass = hash('sha256', wp_salt(32) . md5($settings['embedpress_doc_lock_content_password']));
618
619 $dimension = '';
620 if (
621 empty($settings['embedpress_doc_lock_content']) &&
622 empty($settings['embedpress_doc_lock_content_password']) &&
623 isset($settings['embedpress_elementor_document_width']) &&
624 isset($settings['embedpress_elementor_document_height'])
625 ) {
626 $dimension = "width: " . esc_attr($settings['embedpress_elementor_document_width']['size']) . "px; height: " . esc_attr($settings['embedpress_elementor_document_height']['size']) . "px";
627 }
628
629 $content_locked_class = '';
630 if (!empty($settings['embedpress_doc_lock_content']) && !empty($settings['embedpress_doc_lock_content_password'])) {
631 $content_locked_class = 'ep-content-locked';
632 }
633
634 // Generate content ID for analytics tracking
635 $content_id = md5($url . 'document-elementor');
636
637 // Track Document widget usage for analytics
638 $this->track_document_widget_usage($settings, $url, $content_id);
639
640 $doc_render_attrs = [
641 'class' => ['embedpress-embed-document-pdf', $id],
642 'data-emid' => esc_attr($id),
643 'data-embedpress-content' => esc_attr($content_id),
644 'data-embed-type' => 'Document'
645 ];
646 // Per-embed override for the engagement-stats badge (default = off).
647 // Explicit on/off lets the per-embed toggle win over the global option.
648 $doc_render_attrs['data-ep-views'] = (isset($settings['embedpress_doc_show_view_count']) && $settings['embedpress_doc_show_view_count'] === 'yes') ? 'on' : 'off';
649 $doc_render_attrs['data-ep-downloads'] = (isset($settings['embedpress_doc_show_download_count']) && $settings['embedpress_doc_show_download_count'] === 'yes') ? 'on' : 'off';
650 // Badge position is Pro-only; only emit a non-default placement when
651 // Pro is active so free installs always use the default 'below'.
652 $doc_position = isset($settings['embedpress_doc_count_position']) ? (string) $settings['embedpress_doc_count_position'] : 'below';
653 if ($doc_position !== 'below' && \EmbedPress\Includes\Classes\Helper::is_pro_active()) {
654 $doc_render_attrs['data-ep-count-position'] = $doc_position;
655 }
656 $this->add_render_attribute('embedpres-pdf-render', $doc_render_attrs);
657
658 Helper::get_source_data(md5($this->get_id()) . '_eb_elementor', $url, 'elementor_source_data', 'elementor_temp_source_data');
659
660 $this->add_render_attribute('embedpress-document', [
661 'class' => ['embedpress-document-embed', 'ep-doc-' . md5($id), 'ose-document', $content_locked_class]
662 ]);
663
664 $embed_settings = [];
665 $embed_settings['customThumbnail'] = !empty($settings['embedpress_doc_content_share_custom_thumbnail']['url']) ? esc_url($settings['embedpress_doc_content_share_custom_thumbnail']['url']) : '';
666
667 $embed_settings['customTitle'] = !empty($settings['embedpress_doc_content_title']) ? sanitize_text_field($settings['embedpress_doc_content_title']) : sanitize_text_field(Helper::get_file_title($url));
668
669 $embed_settings['customDescription'] = !empty($settings['embedpress_doc_content_descripiton']) ? sanitize_text_field($settings['embedpress_doc_content_descripiton']) : sanitize_text_field(Helper::get_file_title($url));
670
671 $embed_settings['sharePosition'] = !empty($settings['embedpress_doc_content_share_position']) ? esc_attr($settings['embedpress_doc_content_share_position']) : 'right';
672
673 // Add social share platform settings
674 $embed_settings['shareFacebook'] = !empty($settings['embedpress_doc_share_facebook']) ? true : false;
675 $embed_settings['shareTwitter'] = !empty($settings['embedpress_doc_share_twitter']) ? true : false;
676 $embed_settings['sharePinterest'] = !empty($settings['embedpress_doc_share_pinterest']) ? true : false;
677 $embed_settings['shareLinkedin'] = !empty($settings['embedpress_doc_share_linkedin']) ? true : false;
678
679 $embed_settings['lockHeading'] = !empty($settings['embedpress_doc_lock_content_heading']) ? sanitize_text_field($settings['embedpress_doc_lock_content_heading']) : '';
680
681 $embed_settings['lockSubHeading'] = !empty($settings['embedpress_doc_lock_content_sub_heading']) ? sanitize_text_field($settings['embedpress_doc_lock_content_sub_heading']) : '';
682
683 $embed_settings['lockErrorMessage'] = !empty($settings['embedpress_doc_lock_content_error_message']) ? sanitize_text_field($settings['embedpress_doc_lock_content_error_message']) : '';
684
685 $embed_settings['passwordPlaceholder'] = !empty($settings['embedpress_doc_password_placeholder']) ? esc_attr($settings['embedpress_doc_password_placeholder']) : '';
686
687 $embed_settings['submitButtonText'] = !empty($settings['embedpress_doc_submit_button_text']) ? sanitize_text_field($settings['embedpress_doc_submit_button_text']) : '';
688
689 $embed_settings['submitUnlockingText'] = !empty($settings['embedpress_doc_submit_Unlocking_text']) ? sanitize_text_field($settings['embedpress_doc_submit_Unlocking_text']) : '';
690
691 $embed_settings['enableFooterMessage'] = !empty($settings['embedpress_doc_enable_footer_message']) ? esc_attr($settings['embedpress_doc_enable_footer_message']) : '';
692
693 $embed_settings['footerMessage'] = !empty($settings['embedpress_doc_lock_content_footer_message']) ? sanitize_text_field($settings['embedpress_doc_lock_content_footer_message']) : '';
694
695 $embed_settings['userRole'] = !empty($settings['embedpress_doc_select_roles']) ? $settings['embedpress_doc_select_roles'] : [];
696
697 $embed_settings['protectionMessage'] = !empty($settings['embedpress_doc_protection_message']) ? $settings['embedpress_doc_protection_message'] : '';
698
699
700 $content_share_class = '';
701 $share_position_class = '';
702 $share_position = isset($settings['embedpress_doc_content_share_position']) ? esc_attr($settings['embedpress_doc_content_share_position']) : 'right';
703
704 if (!empty($settings['embedpress_doc_content_share'])) {
705 $content_share_class = 'ep-content-share-enabled';
706 $share_position_class = 'ep-share-position-' . $share_position;
707 }
708
709 $password_correct = isset($_COOKIE['password_correct_' . $client_id]) ? sanitize_text_field($_COOKIE['password_correct_' . $client_id]) : '';
710
711 $content_protection_class = 'ep-content-protection-enabled';
712 if (empty($settings['embedpress_doc_lock_content']) || empty($settings['embedpress_doc_lock_content_password']) || $hash_pass === $password_correct) {
713 $content_protection_class = 'ep-content-protection-disabled';
714 }
715
716 $adsAtts = '';
717
718 if (!empty($settings['adManager'])) {
719 $ad = base64_encode(json_encode($settings)); // Using WordPress JSON encoding function
720 $adsAtts = 'data-sponsored-id="' . esc_attr($client_id) . '" data-sponsored-attrs="' . esc_attr($ad) . '" class="sponsored-mask"';
721 }
722
723 ?>
724
725 <div <?php echo $this->get_render_attribute_string('embedpress-document'); ?> style="<?php echo esc_attr($dimension); ?>; max-width:100%; display: inline-block">
726
727 <?php
728 do_action('embedpress_document_after_embed', $settings, $url, $id, $this);
729
730 if ($url != '') {
731 $url = esc_url($url);
732
733 if ($this->is_pdf($url)) {
734 $renderer = Helper::get_pdf_renderer();
735 $src = $renderer . ((strpos($renderer, '?') === false) ? '?' : '&')
736 . 'file=' . urlencode($url)
737 . $this->getParamData($settings);
738
739 $this->add_render_attribute('embedpres-pdf-render', 'data-emsrc', esc_url($url));
740 $embed_content = '<div ' . $this->get_render_attribute_string('embedpres-pdf-render') . '>';
741
742 $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) . '" frameborder="0"></iframe>';
743
744 if ($settings['embedpress_document_powered_by'] === 'yes') {
745 $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', esc_html__('Powered By EmbedPress', 'embedpress'));
746 }
747 $embed_content .= '</div>';
748 } else {
749 if (Helper::is_file_url($url)) {
750 $view_link = '//view.officeapps.live.com/op/embed.aspx?src=' . urlencode($url) . '&embedded=true';
751 } else {
752 $view_link = 'https://drive.google.com/viewerng/viewer?url=' . urlencode($url) . '&embedded=true&chrome=false';
753 }
754
755
756 if($settings['embedpress_document_viewer'] === 'custom')
757 {
758 if (Helper::is_file_url($url)) {
759 $view_link = '//view.officeapps.live.com/op/embed.aspx?src=' . urlencode($url) . '&embedded=true';
760 } else {
761 $view_link = 'https://drive.google.com/viewerng/viewer?url=' . urlencode($url) . '&embedded=true&chrome=false';
762 }
763 }
764 elseif($settings['embedpress_document_viewer'] === 'office')
765 {
766 $view_link = '//view.officeapps.live.com/op/embed.aspx?src=' . urlencode($url) . '&embedded=true';
767 }
768 elseif($settings['embedpress_document_viewer'] === 'google')
769 {
770 $view_link = '//docs.google.com/gview?embedded=true&url=' . urlencode($url);
771 }
772
773 $hostname = parse_url($url, PHP_URL_HOST);
774 $domain = implode(".", array_slice(explode(".", $hostname), -2));
775
776 if ($domain == "google.com") {
777 $view_link = $url . '?embedded=true';
778 if (strpos($view_link, '/presentation/')) {
779 $view_link = Helper::get_google_presentation_url($url);
780 }
781 }
782
783 $embed_content = '<div ' . $this->get_render_attribute_string('embedpres-pdf-render') . '>';
784
785 $is_powered_by = '';
786 if ($settings['embedpress_document_powered_by'] === 'yes') {
787 $is_powered_by = 'ep-powered-by-enabled';
788 }
789
790 $is_download_enabled = ' enabled-file-download';
791 if ($settings['doc_print_download'] !== 'yes') {
792 $is_download_enabled = '';
793 }
794
795 $file_extenstion = 'link';
796 if (!empty(Helper::is_file_url($url))) {
797 $file_extenstion = Helper::get_extension_from_file_url($url);
798 }
799
800 $is_masked = '';
801
802 if($settings['embedpress_document_viewer'] === 'custom')
803 {
804 $is_masked = 'ep-file-download-option-masked ';
805 }
806
807 $is_custom_theme = '';
808
809 if ($settings['embedpress_theme_mode'] == 'custom') {
810 $custom_color = sanitize_text_field($settings['embedpress_doc_custom_color']);
811
812 $is_custom_theme = 'data-custom-color="'.esc_attr($custom_color).'"';
813 }
814
815 $embed_content .= '<div class="'.esc_attr( $is_masked ).'ep-file-' . esc_attr($file_extenstion) . ' ' . $is_powered_by . '' . $is_download_enabled . '" data-theme-mode="' . esc_attr($settings['embedpress_theme_mode']) . '"' . $is_custom_theme . ' data-id="' . esc_attr($this->get_id()) . '">';
816
817 $sandbox = '';
818 if ($settings['doc_print_download'] === 'yes') {
819 $sandbox = 'sandbox="allow-forms allow-modals allow-orientation-lock allow-pointer-lock allow-presentation allow-same-origin allow-scripts allow-top-navigation allow-top-navigation-by-user-activation"';
820 }
821
822 $embed_content .= '<iframe title="' . esc_attr(Helper::get_file_title($url)) . '" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" style="' . esc_attr($dimension) . '; max-width:100%;" src="' . esc_url($view_link) . '" ' . $sandbox . '>
823 </iframe>';
824
825 if ($settings['embedpress_document_viewer'] === 'custom' && $settings['doc_print_download'] === 'yes' && (Helper::get_extension_from_file_url($url) === 'pptx' || Helper::get_extension_from_file_url($url) === 'ppt' || Helper::get_extension_from_file_url($url) === 'xls' || Helper::get_extension_from_file_url($url) === 'xlsx')) {
826 $embed_content .= '<div class="embed-download-disabled"></div>';
827 }
828
829 if (
830 $settings['doc_draw'] === 'yes' &&
831 isset($settings['embedpress_elementor_document_width']) &&
832 isset($settings['embedpress_elementor_document_height'])
833 ) {
834 $embed_content .= '<canvas class="ep-doc-canvas" width="' . esc_attr($settings['embedpress_elementor_document_width']['size']) . '" height="' . esc_attr($settings['embedpress_elementor_document_height']['size']) . '" ></canvas>';
835 }
836
837 if ($settings['doc_print_download'] === 'yes' && Helper::get_extension_from_file_url($url) !== 'pptx') {
838 $embed_content .= '<div style="width: 40px; height: 40px; position: absolute; opacity: 0; right: 12px; top: 12px;"></div>';
839 }
840
841 if (!empty($settings['doc_toolbar']) && $settings['embedpress_document_viewer'] === 'custom') {
842 $embed_content .= '<div class="ep-external-doc-icons">';
843
844 if (empty(Helper::is_file_url($url))) {
845 $embed_content .= Helper::ep_get_popup_icon();
846 }
847
848 if (!empty(Helper::is_file_url($url))) {
849 if (!empty($settings['doc_print_download'])) {
850 $embed_content .= Helper::ep_get_print_icon();
851 $embed_content .= Helper::ep_get_download_icon();
852 }
853 }
854 if (!empty($settings['doc_draw'])) {
855 $embed_content .= Helper::ep_get_draw_icon();
856 }
857 if (!empty($settings['doc_fullscreen_mode'])) {
858 $embed_content .= Helper::ep_get_fullscreen_icon();
859 $embed_content .= Helper::ep_get_minimize_icon();
860 }
861
862 $embed_content .= '</div>';
863 }
864 $embed_content .= '</div>';
865
866 if ($settings['embedpress_document_powered_by'] === 'yes') {
867 $embed_content .= '<div>';
868 $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', esc_html__('Powered By EmbedPress', 'embedpress'));
869 $embed_content .= '</div>';
870 }
871
872 $embed_content .= '</div>';
873 }
874 }
875
876
877 ?>
878 <div <?php echo $adsAtts; ?>>
879
880 <div id="ep-elementor-content-<?php echo esc_attr($client_id) ?>" class="ep-elementor-content <?php if (!empty($settings['embedpress_doc_content_share'])) : echo esc_attr('position-' . $settings['embedpress_doc_content_share_position'] . '-wraper'); endif; ?> <?php echo esc_attr($content_share_class . ' ' . $share_position_class . ' ' . $content_protection_class); ?>">
881 <div id="<?php echo esc_attr($this->get_id()); ?>" class="ep-embed-content-wraper">
882 <?php
883
884 $content_id = $client_id;
885 if (
886 (empty($settings['embedpress_doc_lock_content']) || ($settings['embedpress_doc_protection_type'] == 'password' && empty($settings['embedpress_doc_lock_content_password'])) || $settings['embedpress_doc_lock_content'] == 'no') ||
887 ($settings['embedpress_doc_protection_type'] == 'password' && !empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct) ) ||
888 !apply_filters('embedpress/is_allow_rander', false) ||
889 ($settings['embedpress_doc_protection_type'] == 'user-role' && Helper::has_allowed_roles($embed_settings['userRole']))
890 ) {
891
892 if (!empty($settings['embedpress_doc_content_share'])) {
893 $embed_content .= Helper::embed_content_share($content_id, $embed_settings);
894 }
895
896 // Apply lazy loading if enabled (but not in editor mode)
897 if (!empty($settings['enable_lazy_load']) && $settings['enable_lazy_load'] === 'yes' && !empty($embed_content) && !$is_editor_view) {
898 $embed_content = preg_replace_callback(
899 '/<iframe([^>]*)src=["\']([^"\']+)["\']([^>]*)>/i',
900 function($matches) {
901 $before = $matches[1];
902 $src = $matches[2];
903 $after = $matches[3];
904
905 // Extract style attribute if exists
906 $style = '';
907 if (preg_match('/style=["\']([^"\']+)["\']/i', $before . $after, $style_match)) {
908 $style = $style_match[1];
909 }
910
911 return sprintf(
912 '<div class="ep-lazy-iframe-placeholder" data-ep-lazy-src="%s" data-ep-iframe-style="%s" %s %s style="%s"></div>',
913 esc_attr($src),
914 esc_attr($style),
915 $before,
916 $after,
917 esc_attr($style)
918 );
919 },
920 $embed_content
921 );
922 }
923
924 if (!empty($embed_content)) {
925 echo $embed_content;
926 }
927 } else {
928 if (!empty($settings['embedpress_doc_content_share'])) {
929 $embed_content .= Helper::embed_content_share($content_id, $embed_settings);
930 }
931
932 // Apply lazy loading if enabled (but not in editor mode)
933 if (!empty($settings['enable_lazy_load']) && $settings['enable_lazy_load'] === 'yes' && !empty($embed_content) && !$is_editor_view) {
934 $embed_content = preg_replace_callback(
935 '/<iframe([^>]*)src=["\']([^"\']+)["\']([^>]*)>/i',
936 function($matches) {
937 $before = $matches[1];
938 $src = $matches[2];
939 $after = $matches[3];
940
941 // Extract style attribute if exists
942 $style = '';
943 if (preg_match('/style=["\']([^"\']+)["\']/i', $before . $after, $style_match)) {
944 $style = $style_match[1];
945 }
946
947 return sprintf(
948 '<div class="ep-lazy-iframe-placeholder" data-ep-lazy-src="%s" data-ep-iframe-style="%s" %s %s style="%s"></div>',
949 esc_attr($src),
950 esc_attr($style),
951 $before,
952 $after,
953 esc_attr($style)
954 );
955 },
956 $embed_content
957 );
958 }
959
960 if ($settings['embedpress_doc_protection_type'] == 'password') {
961 do_action('embedpress/display_password_form', $client_id, $embed_content, $pass_hash_key, $embed_settings);
962 } else {
963 do_action('embedpress/content_protection_content', $client_id, $embed_settings['protectionMessage'], $embed_settings['userRole']);
964 }
965 }
966 ?>
967 </div>
968 </div>
969 <?php
970 if (!empty($settings['adManager'])) {
971 $embed_content = apply_filters('embedpress/generate_ad_template', $embed_content, $client_id, $settings, 'elementor');
972 }
973 ?>
974 </div>
975 </div>
976
977 <?php
978 }
979
980
981 private function get_file_url()
982 {
983 $settings = $this->get_settings();
984 $file_url = $settings['embedpress_document_type'] === 'url' ? esc_url($settings['embedpress_document_file_link']['url']) : esc_url($settings['embedpress_document_Uploader']['url']);
985 return $file_url;
986 }
987
988
989 protected function render_editor_script( $id, $url )
990 {
991 ?>
992 <script>
993 (function ($) {
994 'use strict';
995 $(document).ready(function () {
996 var selector = $('.embedpress-embed-document-pdf');
997 let option = {
998 forceObject: false,
999 };
1000 if (selector.length && typeof PDFObject !== 'undefined') {
1001 PDFObject.embed("<?php echo $url; ?>", "<?php echo '.' . $id; ?>", option);
1002 }
1003 });
1004 })(jQuery);
1005 </script>
1006 <?php
1007 }
1008
1009 /**
1010 * Track Document widget usage for analytics
1011 *
1012 * @param array $settings
1013 * @param string $url
1014 * @param string $content_id
1015 * @return void
1016 */
1017 private function track_document_widget_usage($settings, $url, $content_id)
1018 {
1019 // Only track if analytics is enabled and we have the necessary classes
1020 if (class_exists('EmbedPress\Includes\Classes\Analytics\Analytics_Manager')) {
1021 if (empty($url)) {
1022 return;
1023 }
1024
1025 $provider_name = 'Document';
1026
1027 $tracking_data = [
1028 'embed_type' => $provider_name,
1029 'embed_url' => $url,
1030 'post_id' => get_the_ID(),
1031 'page_url' => get_permalink(),
1032 'title' => get_the_title()
1033 ];
1034
1035 // Track content creation
1036 do_action('embedpress_content_embedded', $content_id, 'elementor-document', $tracking_data);
1037 }
1038 }
1039 }
1040