PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 4.5.1
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v4.5.1
4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / EmbedPress / Elementor / Widgets / Embedpress_Document.php
embedpress / EmbedPress / Elementor / Widgets Last commit date
Embedpress_Calendar.php 7 months ago Embedpress_Document.php 3 months ago Embedpress_Elementor.php 3 months ago Embedpress_Pdf.php 3 months ago Embedpress_Pdf_Gallery.php 2 months ago
Embedpress_Document.php
997 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
476 private function getParamData($settings)
477 {
478 $urlParamData = array(
479 'themeMode' => isset($settings['embedpress_theme_mode']) ? $settings['embedpress_theme_mode'] : 'default',
480 'toolbar' => !empty($settings['doc_toolbar']) ? 'true' : 'false',
481 'position' => 'top',
482 'presentation' => 'false',
483 'lazyLoad' => 'false',
484 'download' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION') ? $settings['doc_print_download'] : 'true',
485 'copy_text' => 'true',
486 'add_text' => 'false',
487 'draw' => !empty($settings['doc_draw']) ? 'true' : 'false',
488 'add_image' => 'false',
489 'pdf_rotation' => 'false',
490 'pdf_details' => 'false',
491 'zoom_in' => 'true',
492 'zoom_out' => 'true',
493 'fit_view' => 'true',
494 'bookmark' => 'false',
495 'sound' => 'false',
496 'flipbook_toolbar_position' => 'bottom',
497 'selection_tool' => '0',
498 'scrolling' => '-1',
499 'spreads' => '-1',
500 'is_pro_active' => apply_filters('embedpress/is_allow_rander', false),
501 'watermark_text' => '',
502 'watermark_font_size' => '48',
503 'watermark_color' => '#000000',
504 'watermark_opacity' => '15',
505 'watermark_style' => 'center',
506 );
507
508 $custom_color = Helper::get_elementor_global_color($settings, 'embedpress_doc_custom_color');
509
510 if (isset($settings['embedpress_theme_mode']) && $settings['embedpress_theme_mode'] == 'custom') {
511 $urlParamData['customColor'] = $custom_color;
512 }
513
514 return "#key=" . base64_encode(mb_convert_encoding(http_build_query($urlParamData), "UTF-8"));
515 }
516
517 private function is_pdf( $url )
518 {
519 $arr = explode( '.', $url );
520 return end( $arr ) === 'pdf';
521 }
522
523 protected function render()
524 {
525 $settings = $this->get_settings();
526
527 Helper::get_enable_settings_data_for_scripts($settings);
528
529 $is_editor_view = Plugin::$instance->editor->is_edit_mode();
530 $client_id = esc_attr($this->get_id());
531 $pass_hash_key = md5($settings['embedpress_doc_lock_content_password']);
532 $url = esc_url($this->get_file_url());
533 $id = 'embedpress-pdf-' . esc_attr($this->get_id());
534
535 if ($settings['embedpress_document_type'] === 'url') {
536 if (!empty($settings['__dynamic__']['embedpress_document_file_link'])) {
537 $decode_url = urldecode($settings['__dynamic__']['embedpress_document_file_link']);
538 preg_match('/name="([^"]+)"/', $decode_url, $name_matches);
539
540 if (!empty($name_matches[1])) {
541 $name_key = $name_matches[1];
542 $pattern = '';
543
544 if ($name_key === 'acf-url' && class_exists('ACF') && function_exists('get_field')) {
545 $pattern = '/"key":"[^"]+:(.*?)"/';
546 } elseif ($name_key === 'toolset-url' && class_exists('Types_Helper_Output_Meta_Box')) {
547 $pattern = '/"key":"[^"]+:(.*?)"/';
548 } elseif ($name_key === 'jet-post-custom-field' && class_exists('Jet_Engine')) {
549 $pattern = '/"meta_field":"([^"]+)"/';
550 }
551
552 if ($pattern) {
553 preg_match($pattern, $decode_url, $matches);
554
555 if (!empty($matches[1])) {
556 $get_field_key = sanitize_key($matches[1]);
557
558 $url = '';
559
560 if ($name_key === 'acf-url') {
561 $url = get_field($get_field_key);
562 } elseif ($name_key === 'toolset-url') {
563 $url = get_post_meta(get_the_ID(), 'wpcf-' . $get_field_key, true);
564 } elseif ($name_key === 'jet-post-custom-field') {
565 $url = get_post_meta(get_the_ID(), $get_field_key, true);
566 }
567
568 $url = apply_filters('embedpress/custom_meta_field_value', $url, $get_field_key);
569
570 // Fallback
571 if (empty($url)) {
572 preg_match('/"fallback":"([^"]+)"/', $decode_url, $fallback_matches);
573 if (!empty($fallback_matches[1])) {
574 $url = $fallback_matches[1];
575 }
576 }
577
578 // Final sanitization before output
579 $url = esc_url_raw($url);
580 }
581 }
582 }
583 }
584 }
585 $hash_pass = hash('sha256', wp_salt(32) . md5($settings['embedpress_doc_lock_content_password']));
586
587 $dimension = '';
588 if (
589 empty($settings['embedpress_doc_lock_content']) &&
590 empty($settings['embedpress_doc_lock_content_password']) &&
591 isset($settings['embedpress_elementor_document_width']) &&
592 isset($settings['embedpress_elementor_document_height'])
593 ) {
594 $dimension = "width: " . esc_attr($settings['embedpress_elementor_document_width']['size']) . "px; height: " . esc_attr($settings['embedpress_elementor_document_height']['size']) . "px";
595 }
596
597 $content_locked_class = '';
598 if (!empty($settings['embedpress_doc_lock_content']) && !empty($settings['embedpress_doc_lock_content_password'])) {
599 $content_locked_class = 'ep-content-locked';
600 }
601
602 // Generate content ID for analytics tracking
603 $content_id = md5($url . 'document-elementor');
604
605 // Track Document widget usage for analytics
606 $this->track_document_widget_usage($settings, $url, $content_id);
607
608 $this->add_render_attribute('embedpres-pdf-render', [
609 'class' => ['embedpress-embed-document-pdf', $id],
610 'data-emid' => esc_attr($id),
611 'data-embedpress-content' => esc_attr($content_id),
612 'data-embed-type' => 'Document'
613 ]);
614
615 Helper::get_source_data(md5($this->get_id()) . '_eb_elementor', $url, 'elementor_source_data', 'elementor_temp_source_data');
616
617 $this->add_render_attribute('embedpress-document', [
618 'class' => ['embedpress-document-embed', 'ep-doc-' . md5($id), 'ose-document', $content_locked_class]
619 ]);
620
621 $embed_settings = [];
622 $embed_settings['customThumbnail'] = !empty($settings['embedpress_doc_content_share_custom_thumbnail']['url']) ? esc_url($settings['embedpress_doc_content_share_custom_thumbnail']['url']) : '';
623
624 $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));
625
626 $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));
627
628 $embed_settings['sharePosition'] = !empty($settings['embedpress_doc_content_share_position']) ? esc_attr($settings['embedpress_doc_content_share_position']) : 'right';
629
630 // Add social share platform settings
631 $embed_settings['shareFacebook'] = !empty($settings['embedpress_doc_share_facebook']) ? true : false;
632 $embed_settings['shareTwitter'] = !empty($settings['embedpress_doc_share_twitter']) ? true : false;
633 $embed_settings['sharePinterest'] = !empty($settings['embedpress_doc_share_pinterest']) ? true : false;
634 $embed_settings['shareLinkedin'] = !empty($settings['embedpress_doc_share_linkedin']) ? true : false;
635
636 $embed_settings['lockHeading'] = !empty($settings['embedpress_doc_lock_content_heading']) ? sanitize_text_field($settings['embedpress_doc_lock_content_heading']) : '';
637
638 $embed_settings['lockSubHeading'] = !empty($settings['embedpress_doc_lock_content_sub_heading']) ? sanitize_text_field($settings['embedpress_doc_lock_content_sub_heading']) : '';
639
640 $embed_settings['lockErrorMessage'] = !empty($settings['embedpress_doc_lock_content_error_message']) ? sanitize_text_field($settings['embedpress_doc_lock_content_error_message']) : '';
641
642 $embed_settings['passwordPlaceholder'] = !empty($settings['embedpress_doc_password_placeholder']) ? esc_attr($settings['embedpress_doc_password_placeholder']) : '';
643
644 $embed_settings['submitButtonText'] = !empty($settings['embedpress_doc_submit_button_text']) ? sanitize_text_field($settings['embedpress_doc_submit_button_text']) : '';
645
646 $embed_settings['submitUnlockingText'] = !empty($settings['embedpress_doc_submit_Unlocking_text']) ? sanitize_text_field($settings['embedpress_doc_submit_Unlocking_text']) : '';
647
648 $embed_settings['enableFooterMessage'] = !empty($settings['embedpress_doc_enable_footer_message']) ? esc_attr($settings['embedpress_doc_enable_footer_message']) : '';
649
650 $embed_settings['footerMessage'] = !empty($settings['embedpress_doc_lock_content_footer_message']) ? sanitize_text_field($settings['embedpress_doc_lock_content_footer_message']) : '';
651
652 $embed_settings['userRole'] = !empty($settings['embedpress_doc_select_roles']) ? $settings['embedpress_doc_select_roles'] : [];
653
654 $embed_settings['protectionMessage'] = !empty($settings['embedpress_doc_protection_message']) ? $settings['embedpress_doc_protection_message'] : '';
655
656
657 $content_share_class = '';
658 $share_position_class = '';
659 $share_position = isset($settings['embedpress_doc_content_share_position']) ? esc_attr($settings['embedpress_doc_content_share_position']) : 'right';
660
661 if (!empty($settings['embedpress_doc_content_share'])) {
662 $content_share_class = 'ep-content-share-enabled';
663 $share_position_class = 'ep-share-position-' . $share_position;
664 }
665
666 $password_correct = isset($_COOKIE['password_correct_' . $client_id]) ? sanitize_text_field($_COOKIE['password_correct_' . $client_id]) : '';
667
668 $content_protection_class = 'ep-content-protection-enabled';
669 if (empty($settings['embedpress_doc_lock_content']) || empty($settings['embedpress_doc_lock_content_password']) || $hash_pass === $password_correct) {
670 $content_protection_class = 'ep-content-protection-disabled';
671 }
672
673 $adsAtts = '';
674
675 if (!empty($settings['adManager'])) {
676 $ad = base64_encode(json_encode($settings)); // Using WordPress JSON encoding function
677 $adsAtts = 'data-sponsored-id="' . esc_attr($client_id) . '" data-sponsored-attrs="' . esc_attr($ad) . '" class="sponsored-mask"';
678 }
679
680 ?>
681
682 <div <?php echo $this->get_render_attribute_string('embedpress-document'); ?> style="<?php echo esc_attr($dimension); ?>; max-width:100%; display: inline-block">
683
684 <?php
685 do_action('embedpress_document_after_embed', $settings, $url, $id, $this);
686
687 if ($url != '') {
688 $url = esc_url($url);
689
690 if ($this->is_pdf($url)) {
691 $renderer = Helper::get_pdf_renderer();
692 $src = $renderer . ((strpos($renderer, '?') === false) ? '?' : '&')
693 . 'file=' . urlencode($url)
694 . $this->getParamData($settings);
695
696 $this->add_render_attribute('embedpres-pdf-render', 'data-emsrc', esc_url($url));
697 $embed_content = '<div ' . $this->get_render_attribute_string('embedpres-pdf-render') . '>';
698
699 $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>';
700
701 if ($settings['embedpress_document_powered_by'] === 'yes') {
702 $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', esc_html__('Powered By EmbedPress', 'embedpress'));
703 }
704 $embed_content .= '</div>';
705 } else {
706 if (Helper::is_file_url($url)) {
707 $view_link = '//view.officeapps.live.com/op/embed.aspx?src=' . urlencode($url) . '&embedded=true';
708 } else {
709 $view_link = 'https://drive.google.com/viewerng/viewer?url=' . urlencode($url) . '&embedded=true&chrome=false';
710 }
711
712
713 if($settings['embedpress_document_viewer'] === 'custom')
714 {
715 if (Helper::is_file_url($url)) {
716 $view_link = '//view.officeapps.live.com/op/embed.aspx?src=' . urlencode($url) . '&embedded=true';
717 } else {
718 $view_link = 'https://drive.google.com/viewerng/viewer?url=' . urlencode($url) . '&embedded=true&chrome=false';
719 }
720 }
721 elseif($settings['embedpress_document_viewer'] === 'office')
722 {
723 $view_link = '//view.officeapps.live.com/op/embed.aspx?src=' . urlencode($url) . '&embedded=true';
724 }
725 elseif($settings['embedpress_document_viewer'] === 'google')
726 {
727 $view_link = '//docs.google.com/gview?embedded=true&url=' . urlencode($url);
728 }
729
730 $hostname = parse_url($url, PHP_URL_HOST);
731 $domain = implode(".", array_slice(explode(".", $hostname), -2));
732
733 if ($domain == "google.com") {
734 $view_link = $url . '?embedded=true';
735 if (strpos($view_link, '/presentation/')) {
736 $view_link = Helper::get_google_presentation_url($url);
737 }
738 }
739
740 $embed_content = '<div ' . $this->get_render_attribute_string('embedpres-pdf-render') . '>';
741
742 $is_powered_by = '';
743 if ($settings['embedpress_document_powered_by'] === 'yes') {
744 $is_powered_by = 'ep-powered-by-enabled';
745 }
746
747 $is_download_enabled = ' enabled-file-download';
748 if ($settings['doc_print_download'] !== 'yes') {
749 $is_download_enabled = '';
750 }
751
752 $file_extenstion = 'link';
753 if (!empty(Helper::is_file_url($url))) {
754 $file_extenstion = Helper::get_extension_from_file_url($url);
755 }
756
757 $is_masked = '';
758
759 if($settings['embedpress_document_viewer'] === 'custom')
760 {
761 $is_masked = 'ep-file-download-option-masked ';
762 }
763
764 $is_custom_theme = '';
765
766 if ($settings['embedpress_theme_mode'] == 'custom') {
767 $custom_color = sanitize_text_field($settings['embedpress_doc_custom_color']);
768
769 $is_custom_theme = 'data-custom-color="'.esc_attr($custom_color).'"';
770 }
771
772 $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()) . '">';
773
774 $sandbox = '';
775 if ($settings['doc_print_download'] === 'yes') {
776 $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"';
777 }
778
779 $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 . '>
780 </iframe>';
781
782 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')) {
783 $embed_content .= '<div class="embed-download-disabled"></div>';
784 }
785
786 if (
787 $settings['doc_draw'] === 'yes' &&
788 isset($settings['embedpress_elementor_document_width']) &&
789 isset($settings['embedpress_elementor_document_height'])
790 ) {
791 $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>';
792 }
793
794 if ($settings['doc_print_download'] === 'yes' && Helper::get_extension_from_file_url($url) !== 'pptx') {
795 $embed_content .= '<div style="width: 40px; height: 40px; position: absolute; opacity: 0; right: 12px; top: 12px;"></div>';
796 }
797
798 if (!empty($settings['doc_toolbar']) && $settings['embedpress_document_viewer'] === 'custom') {
799 $embed_content .= '<div class="ep-external-doc-icons">';
800
801 if (empty(Helper::is_file_url($url))) {
802 $embed_content .= Helper::ep_get_popup_icon();
803 }
804
805 if (!empty(Helper::is_file_url($url))) {
806 if (!empty($settings['doc_print_download'])) {
807 $embed_content .= Helper::ep_get_print_icon();
808 $embed_content .= Helper::ep_get_download_icon();
809 }
810 }
811 if (!empty($settings['doc_draw'])) {
812 $embed_content .= Helper::ep_get_draw_icon();
813 }
814 if (!empty($settings['doc_fullscreen_mode'])) {
815 $embed_content .= Helper::ep_get_fullscreen_icon();
816 $embed_content .= Helper::ep_get_minimize_icon();
817 }
818
819 $embed_content .= '</div>';
820 }
821 $embed_content .= '</div>';
822
823 if ($settings['embedpress_document_powered_by'] === 'yes') {
824 $embed_content .= '<div>';
825 $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', esc_html__('Powered By EmbedPress', 'embedpress'));
826 $embed_content .= '</div>';
827 }
828
829 $embed_content .= '</div>';
830 }
831 }
832
833
834 ?>
835 <div <?php echo $adsAtts; ?>>
836
837 <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); ?>">
838 <div id="<?php echo esc_attr($this->get_id()); ?>" class="ep-embed-content-wraper">
839 <?php
840
841 $content_id = $client_id;
842 if (
843 (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') ||
844 ($settings['embedpress_doc_protection_type'] == 'password' && !empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct) ) ||
845 !apply_filters('embedpress/is_allow_rander', false) ||
846 ($settings['embedpress_doc_protection_type'] == 'user-role' && Helper::has_allowed_roles($embed_settings['userRole']))
847 ) {
848
849 if (!empty($settings['embedpress_doc_content_share'])) {
850 $embed_content .= Helper::embed_content_share($content_id, $embed_settings);
851 }
852
853 // Apply lazy loading if enabled (but not in editor mode)
854 if (!empty($settings['enable_lazy_load']) && $settings['enable_lazy_load'] === 'yes' && !empty($embed_content) && !$is_editor_view) {
855 $embed_content = preg_replace_callback(
856 '/<iframe([^>]*)src=["\']([^"\']+)["\']([^>]*)>/i',
857 function($matches) {
858 $before = $matches[1];
859 $src = $matches[2];
860 $after = $matches[3];
861
862 // Extract style attribute if exists
863 $style = '';
864 if (preg_match('/style=["\']([^"\']+)["\']/i', $before . $after, $style_match)) {
865 $style = $style_match[1];
866 }
867
868 return sprintf(
869 '<div class="ep-lazy-iframe-placeholder" data-ep-lazy-src="%s" data-ep-iframe-style="%s" %s %s style="%s"></div>',
870 esc_attr($src),
871 esc_attr($style),
872 $before,
873 $after,
874 esc_attr($style)
875 );
876 },
877 $embed_content
878 );
879 }
880
881 if (!empty($embed_content)) {
882 echo $embed_content;
883 }
884 } else {
885 if (!empty($settings['embedpress_doc_content_share'])) {
886 $embed_content .= Helper::embed_content_share($content_id, $embed_settings);
887 }
888
889 // Apply lazy loading if enabled (but not in editor mode)
890 if (!empty($settings['enable_lazy_load']) && $settings['enable_lazy_load'] === 'yes' && !empty($embed_content) && !$is_editor_view) {
891 $embed_content = preg_replace_callback(
892 '/<iframe([^>]*)src=["\']([^"\']+)["\']([^>]*)>/i',
893 function($matches) {
894 $before = $matches[1];
895 $src = $matches[2];
896 $after = $matches[3];
897
898 // Extract style attribute if exists
899 $style = '';
900 if (preg_match('/style=["\']([^"\']+)["\']/i', $before . $after, $style_match)) {
901 $style = $style_match[1];
902 }
903
904 return sprintf(
905 '<div class="ep-lazy-iframe-placeholder" data-ep-lazy-src="%s" data-ep-iframe-style="%s" %s %s style="%s"></div>',
906 esc_attr($src),
907 esc_attr($style),
908 $before,
909 $after,
910 esc_attr($style)
911 );
912 },
913 $embed_content
914 );
915 }
916
917 if ($settings['embedpress_doc_protection_type'] == 'password') {
918 do_action('embedpress/display_password_form', $client_id, $embed_content, $pass_hash_key, $embed_settings);
919 } else {
920 do_action('embedpress/content_protection_content', $client_id, $embed_settings['protectionMessage'], $embed_settings['userRole']);
921 }
922 }
923 ?>
924 </div>
925 </div>
926 <?php
927 if (!empty($settings['adManager'])) {
928 $embed_content = apply_filters('embedpress/generate_ad_template', $embed_content, $client_id, $settings, 'elementor');
929 }
930 ?>
931 </div>
932 </div>
933
934 <?php
935 }
936
937
938 private function get_file_url()
939 {
940 $settings = $this->get_settings();
941 $file_url = $settings['embedpress_document_type'] === 'url' ? esc_url($settings['embedpress_document_file_link']['url']) : esc_url($settings['embedpress_document_Uploader']['url']);
942 return $file_url;
943 }
944
945
946 protected function render_editor_script( $id, $url )
947 {
948 ?>
949 <script>
950 (function ($) {
951 'use strict';
952 $(document).ready(function () {
953 var selector = $('.embedpress-embed-document-pdf');
954 let option = {
955 forceObject: false,
956 };
957 if (selector.length && typeof PDFObject !== 'undefined') {
958 PDFObject.embed("<?php echo $url; ?>", "<?php echo '.' . $id; ?>", option);
959 }
960 });
961 })(jQuery);
962 </script>
963 <?php
964 }
965
966 /**
967 * Track Document widget usage for analytics
968 *
969 * @param array $settings
970 * @param string $url
971 * @param string $content_id
972 * @return void
973 */
974 private function track_document_widget_usage($settings, $url, $content_id)
975 {
976 // Only track if analytics is enabled and we have the necessary classes
977 if (class_exists('EmbedPress\Includes\Classes\Analytics\Analytics_Manager')) {
978 if (empty($url)) {
979 return;
980 }
981
982 $provider_name = 'Document';
983
984 $tracking_data = [
985 'embed_type' => $provider_name,
986 'embed_url' => $url,
987 'post_id' => get_the_ID(),
988 'page_url' => get_permalink(),
989 'title' => get_the_title()
990 ];
991
992 // Track content creation
993 do_action('embedpress_content_embedded', $content_id, 'elementor-document', $tracking_data);
994 }
995 }
996 }
997