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