PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 4.4.6
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v4.4.6
4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / EmbedPress / Elementor / Widgets / Embedpress_Document.php
embedpress / EmbedPress / Elementor / Widgets Last commit date
Embedpress_Calendar.php 11 months ago Embedpress_Document.php 10 months ago Embedpress_Elementor.php 10 months ago Embedpress_Pdf.php 10 months ago
Embedpress_Document.php
858 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 protected function register_controls()
89 {
90 $class = 'embedpress-pro-control not-active';
91 $text = '<sup class="embedpress-pro-label" style="color:red">' . __('Pro', 'embedpress') . '</sup>';
92 $this->pro_class = apply_filters('embedpress/pro_class', $class);
93 $this->pro_text = apply_filters('embedpress/pro_text', $text);
94
95 /**
96 * EmbedPress Content Settings
97 */
98 $this->start_controls_section(
99 'embedpress_document_content_settings',
100 [
101 'label' => esc_html__( 'General', 'embedpress' ),
102 ]
103 );
104
105 $this->add_control(
106 'embedpress_document_type',
107 [
108 'label' => __( 'Document Type', 'embedpress' ),
109 'type' => Controls_Manager::SELECT,
110 'default' => 'file',
111 'options' => [
112 'file' => __( 'File', 'embedpress' ),
113 'url' => __( 'URL', 'embedpress' )
114 ],
115 ]
116 );
117 $this->add_control(
118 'embedpress_document_Uploader',
119 [
120
121 'label' => __( 'Upload File', 'embedpress' ),
122 'type' => Controls_Manager::MEDIA,
123 'dynamic' => [
124 'active' => true,
125 'categories' => [
126 TagsModule::MEDIA_CATEGORY,
127 ],
128 ],
129 'media_type' => [
130 'application/pdf',
131 'application/msword',
132 'application/vnd.ms-powerpoint',
133 'application/vnd.ms-excel',
134 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
135 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
136 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
137 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' // Added PPSX MIME type
138
139 ],
140 'description' => __( 'Upload a file or pick one from your media library for embed. Supported File Type: PDF, DOC/DOCX, PPT/PPTX, XLS/XLSX etc.',
141 'embedpress' ),
142 'condition' => [
143 'embedpress_document_type' => 'file'
144 ],
145 ]
146 );
147
148 $this->add_control(
149 'embedpress_document_file_link',
150 [
151 'label' => __( 'URL', 'embedpress' ),
152 'type' => Controls_Manager::URL,
153 'placeholder' => __( 'https://your-link.com/file.pdf', 'embedpress' ),
154 'show_external' => false,
155 'dynamic' => [
156 'active' => true,
157 ],
158 'default' => [
159 'url' => ''
160 ],
161 'condition' => [
162 'embedpress_document_type' => 'url'
163 ],
164 ]
165 );
166
167 $this->add_responsive_control(
168 'embedpress_elementor_document_width',
169 [
170 'type' => \Elementor\Controls_Manager::SLIDER,
171 'label' => esc_html__( 'Width', 'embedpress' ),
172 'range' => [
173 'px' => [
174 'min' => 1,
175 'max' => 1000,
176 ],
177 ],
178 // 'devices' => [ 'desktop', 'tablet', 'mobile' ],
179 'default' => [
180 'unit' => 'px',
181 'size' => !empty($value = intval(Helper::get_options_value('enableEmbedResizeWidth'))) ? $value : 600,
182 ],
183 // 'desktop_default' => [
184 // 'unit' => 'px',
185 // 'size' => 600,
186 // ],
187 // 'tablet_default' => [
188 // 'size' => 400,
189 // 'unit' => 'px',
190 // ],
191 // 'mobile_default' => [
192 // 'size' => 300,
193 // 'unit' => 'px',
194 // ],
195 'selectors' => [
196 '{{WRAPPER}} .embedpress-document-embed iframe' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%; background-color: #fff',
197 '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%',
198 '{{WRAPPER}} .embedpress-document-embed' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%',
199 ],
200 ]
201 );
202 $this->add_responsive_control(
203 'embedpress_elementor_document_height',
204 [
205 'type' => \Elementor\Controls_Manager::SLIDER,
206 'label' => esc_html__( 'Height', 'embedpress' ),
207 'range' => [
208 'px' => [
209 'min' => 1,
210 'max' => 1500,
211 ],
212 ],
213 // 'devices' => [ 'desktop', 'tablet', 'mobile' ],
214 'default' => [
215 'unit' => 'px',
216 'size' => !empty($value = intval(Helper::get_options_value('enableEmbedResizeHeight'))) ? $value : 600,
217 ],
218 // 'desktop_default' => [
219 // 'unit' => 'px',
220 // 'size' => 600,
221 // ],
222 // 'tablet_default' => [
223 // 'size' => 400,
224 // 'unit' => 'px',
225 // ],
226 // 'mobile_default' => [
227 // 'size' => 300,
228 // 'unit' => 'px',
229 // ],
230 'selectors' => [
231 '{{WRAPPER}} .embedpress-document-embed iframe' => 'height: {{SIZE}}{{UNIT}}!important;',
232 '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'height: {{SIZE}}{{UNIT}};',
233 '{{WRAPPER}} .embedpress-document-embed ' => 'max-height: {{SIZE}}{{UNIT}};',
234 ],
235 ]
236 );
237
238 $this->add_responsive_control(
239 'embedpress_elementor_document_align',
240 [
241 'label' => __( 'Alignment', 'embedpress' ),
242 'type' => Controls_Manager::CHOOSE,
243 'options' => [
244 'left' => [
245 'title' => __( 'Left', 'embedpress' ),
246 'icon' => 'eicon-text-align-left',
247 ],
248 'center' => [
249 'title' => __( 'Center', 'embedpress' ),
250 'icon' => 'eicon-text-align-center',
251 ],
252 'right' => [
253 'title' => __( 'Right', 'embedpress' ),
254 'icon' => 'eicon-text-align-right',
255 ]
256 ],
257 'prefix_class' => 'elementor%s-align-',
258 'default' => '',
259 ]
260 );
261
262 // Get global powered_by setting
263 $g_settings = get_option(EMBEDPRESS_PLG_NAME, []);
264 $powered_by_default = isset($g_settings['embedpress_document_powered_by']) && $g_settings['embedpress_document_powered_by'] === 'yes' ? 'yes' : 'no';
265
266 $this->add_control(
267 'embedpress_document_powered_by',
268 [
269 'label' => __( 'Powered By', 'embedpress' ),
270 'type' => Controls_Manager::SWITCHER,
271 'label_on' => __( 'Show', 'embedpress' ),
272 'label_off' => __( 'Hide', 'embedpress' ),
273 'return_value' => 'yes',
274 'default' => apply_filters( 'embedpress_document_powered_by_control', $powered_by_default ),
275 ]
276 );
277
278 $this->init_branding_controls( 'document');
279
280 $this->end_controls_section();
281
282 /**
283 * EmbedPress Document control settings
284 */
285
286 $this->start_controls_section(
287 'embedpress_doc_content_settings',
288 [
289 'label' => esc_html__('Controls', 'embedpress'),
290 ]
291 );
292
293 $this->add_control(
294 'important_note',
295 [
296 'type' => \Elementor\Controls_Manager::RAW_HTML,
297 'raw' => esc_html__( 'Download feature is available when link has the document extension at the end.', 'embedpress' ),
298 'content_classes' => 'elementor-panel-alert elementor-panel-alert-info',
299 'condition' => [
300 'embedpress_document_type' => 'url',
301 ],
302 ]
303 );
304
305 $this->add_control(
306 'important_note_2',
307 [
308 'type' => \Elementor\Controls_Manager::RAW_HTML,
309 'raw' => esc_html__( 'Toolbar and additional feature options become accessible upon selecting the Custom Viewer mode.', 'embedpress' ),
310 'content_classes' => 'elementor-panel-alert elementor-panel-alert-info',
311 'condition' => [
312 'embedpress_document_type' => 'file',
313 'embedpress_document_viewer' => 'office',
314 ],
315 ]
316 );
317
318
319 $this->add_control(
320 'embedpress_document_viewer',
321 [
322 'label' => __('Viewer', 'embedpress'),
323 'type' => Controls_Manager::SELECT,
324 'default' => 'custom',
325 'options' => [
326 'custom' => __('Custom', 'embedpress'),
327 'office' => __('MS Office', 'embedpress'),
328 'google' => __('Google', 'embedpress'),
329 ],
330 ]
331 );
332
333 $this->add_control(
334 'embedpress_theme_mode',
335 [
336 'label' => __('Theme', 'embedpress'),
337 'type' => Controls_Manager::SELECT,
338 'default' => 'default',
339 'options' => [
340 'default' => __('System Default', 'embedpress'),
341 'dark' => __('Dark', 'embedpress'),
342 'light' => __('Light', 'embedpress'),
343 'custom' => __('Custom', 'embedpress')
344 ],
345 'condition' => [
346 'embedpress_document_viewer' => 'custom',
347 ],
348
349 ]
350 );
351
352 $this->add_control(
353 'embedpress_doc_custom_color',
354 [
355 'label' => esc_html__( 'Color', 'embedpress' ),
356 'type' => \Elementor\Controls_Manager::COLOR,
357 'condition' => [
358 'embedpress_theme_mode' => 'custom',
359 'embedpress_document_viewer' => 'custom',
360 ],
361 ]
362 );
363
364 $this->add_control(
365 'doc_toolbar',
366 [
367 'label' => sprintf(__('Toolbar %s', 'embedpress'), $this->pro_text),
368 'type' => Controls_Manager::SWITCHER,
369 'label_on' => __('Show', 'embedpress'),
370 'label_off' => __('Hide', 'embedpress'),
371 'return_value' => 'yes',
372 'default' => 'yes',
373 'classes' => $this->pro_class,
374 'condition' => [
375 'embedpress_document_viewer' => 'custom',
376 ],
377 ]
378 );
379
380
381 $this->add_control(
382 'doc_fullscreen_mode',
383 [
384 'label' => __('Fullscreen', 'embedpress'),
385 'type' => Controls_Manager::SWITCHER,
386 'label_on' => __('Show', 'embedpress'),
387 'label_off' => __('Hide', 'embedpress'),
388 'return_value' => 'yes',
389 'default' => 'yes',
390 'condition' => [
391 'doc_toolbar' => 'yes',
392 'embedpress_document_viewer' => 'custom',
393 ],
394 ]
395 );
396
397 $this->add_control(
398 'doc_print_download',
399 [
400 'label' => sprintf(__('Print/Download %s', 'embedpress'), $this->pro_text),
401 'type' => Controls_Manager::SWITCHER,
402 'label_on' => __('Show', 'embedpress'),
403 'label_off' => __('Hide', 'embedpress'),
404 'return_value' => 'yes',
405 'default' => 'yes',
406 'classes' => $this->pro_class,
407 'condition' => [
408 'doc_toolbar' => 'yes',
409 'embedpress_document_viewer' => 'custom',
410 ],
411 ]
412 );
413
414
415 $this->add_control(
416 'doc_draw',
417 [
418 'label' => __('Draw', 'embedpress'),
419 'type' => Controls_Manager::SWITCHER,
420 'label_on' => __('Show', 'embedpress'),
421 'label_off' => __('Hide', 'embedpress'),
422 'return_value' => 'yes',
423 'default' => 'yes',
424 'condition' => [
425 'doc_toolbar' => 'yes',
426 'embedpress_document_viewer' => 'custom',
427 ],
428 ]
429 );
430
431
432 $this->end_controls_section();
433
434 do_action( 'extend_elementor_controls', $this, '_doc_', $this->pro_text, $this->pro_class);
435
436 }
437
438 private function is_pdf( $url )
439 {
440 $arr = explode( '.', $url );
441 return end( $arr ) === 'pdf';
442 }
443
444 protected function render()
445 {
446 $settings = $this->get_settings();
447
448 Helper::get_enable_settings_data_for_scripts($settings);
449
450 $client_id = esc_attr($this->get_id());
451 $pass_hash_key = md5($settings['embedpress_doc_lock_content_password']);
452 $url = esc_url($this->get_file_url());
453 $id = 'embedpress-pdf-' . esc_attr($this->get_id());
454
455 if ($settings['embedpress_document_type'] === 'url') {
456 if (!empty($settings['__dynamic__']['embedpress_document_file_link'])) {
457 $decode_url = urldecode($settings['__dynamic__']['embedpress_document_file_link']);
458 preg_match('/name="([^"]+)"/', $decode_url, $name_matches);
459
460 if (!empty($name_matches[1])) {
461 $name_key = $name_matches[1];
462 $pattern = '';
463
464 if ($name_key === 'acf-url' && class_exists('ACF') && function_exists('get_field')) {
465 $pattern = '/"key":"[^"]+:(.*?)"/';
466 } elseif ($name_key === 'toolset-url' && class_exists('Types_Helper_Output_Meta_Box')) {
467 $pattern = '/"key":"[^"]+:(.*?)"/';
468 } elseif ($name_key === 'jet-post-custom-field' && class_exists('Jet_Engine')) {
469 $pattern = '/"meta_field":"([^"]+)"/';
470 }
471
472 if ($pattern) {
473 preg_match($pattern, $decode_url, $matches);
474
475 if (!empty($matches[1])) {
476 $get_field_key = sanitize_key($matches[1]);
477
478 $url = '';
479
480 if ($name_key === 'acf-url') {
481 $url = get_field($get_field_key);
482 } elseif ($name_key === 'toolset-url') {
483 $url = get_post_meta(get_the_ID(), 'wpcf-' . $get_field_key, true);
484 } elseif ($name_key === 'jet-post-custom-field') {
485 $url = get_post_meta(get_the_ID(), $get_field_key, true);
486 }
487
488 $url = apply_filters('embedpress/custom_meta_field_value', $url, $get_field_key);
489
490 // Fallback
491 if (empty($url)) {
492 preg_match('/"fallback":"([^"]+)"/', $decode_url, $fallback_matches);
493 if (!empty($fallback_matches[1])) {
494 $url = $fallback_matches[1];
495 }
496 }
497
498 // Final sanitization before output
499 $url = esc_url_raw($url);
500 }
501 }
502 }
503 }
504 }
505 $hash_pass = hash('sha256', wp_salt(32) . md5($settings['embedpress_doc_lock_content_password']));
506
507 $dimension = '';
508 if (
509 empty($settings['embedpress_doc_lock_content']) &&
510 empty($settings['embedpress_doc_lock_content_password']) &&
511 isset($settings['embedpress_elementor_document_width']) &&
512 isset($settings['embedpress_elementor_document_height'])
513 ) {
514 $dimension = "width: " . esc_attr($settings['embedpress_elementor_document_width']['size']) . "px; height: " . esc_attr($settings['embedpress_elementor_document_height']['size']) . "px";
515 }
516
517 $content_locked_class = '';
518 if (!empty($settings['embedpress_doc_lock_content']) && !empty($settings['embedpress_doc_lock_content_password'])) {
519 $content_locked_class = 'ep-content-locked';
520 }
521
522 // Generate content ID for analytics tracking
523 $content_id = md5($url . 'document-elementor');
524
525 // Track Document widget usage for analytics
526 $this->track_document_widget_usage($settings, $url, $content_id);
527
528 $this->add_render_attribute('embedpres-pdf-render', [
529 'class' => ['embedpress-embed-document-pdf', $id],
530 'data-emid' => esc_attr($id),
531 'data-embedpress-content' => esc_attr($content_id),
532 'data-embed-type' => 'Document'
533 ]);
534
535 Helper::get_source_data(md5($this->get_id()) . '_eb_elementor', $url, 'elementor_source_data', 'elementor_temp_source_data');
536
537 $this->add_render_attribute('embedpress-document', [
538 'class' => ['embedpress-document-embed', 'ep-doc-' . md5($id), 'ose-document', $content_locked_class]
539 ]);
540
541 $embed_settings = [];
542 $embed_settings['customThumbnail'] = !empty($settings['embedpress_doc_content_share_custom_thumbnail']['url']) ? esc_url($settings['embedpress_doc_content_share_custom_thumbnail']['url']) : '';
543
544 $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));
545
546 $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));
547
548 $embed_settings['sharePosition'] = !empty($settings['embedpress_doc_content_share_position']) ? esc_attr($settings['embedpress_doc_content_share_position']) : 'right';
549
550 // Add social share platform settings
551 $embed_settings['shareFacebook'] = !empty($settings['embedpress_doc_share_facebook']) ? true : false;
552 $embed_settings['shareTwitter'] = !empty($settings['embedpress_doc_share_twitter']) ? true : false;
553 $embed_settings['sharePinterest'] = !empty($settings['embedpress_doc_share_pinterest']) ? true : false;
554 $embed_settings['shareLinkedin'] = !empty($settings['embedpress_doc_share_linkedin']) ? true : false;
555
556 $embed_settings['lockHeading'] = !empty($settings['embedpress_doc_lock_content_heading']) ? sanitize_text_field($settings['embedpress_doc_lock_content_heading']) : '';
557
558 $embed_settings['lockSubHeading'] = !empty($settings['embedpress_doc_lock_content_sub_heading']) ? sanitize_text_field($settings['embedpress_doc_lock_content_sub_heading']) : '';
559
560 $embed_settings['lockErrorMessage'] = !empty($settings['embedpress_doc_lock_content_error_message']) ? sanitize_text_field($settings['embedpress_doc_lock_content_error_message']) : '';
561
562 $embed_settings['passwordPlaceholder'] = !empty($settings['embedpress_doc_password_placeholder']) ? esc_attr($settings['embedpress_doc_password_placeholder']) : '';
563
564 $embed_settings['submitButtonText'] = !empty($settings['embedpress_doc_submit_button_text']) ? sanitize_text_field($settings['embedpress_doc_submit_button_text']) : '';
565
566 $embed_settings['submitUnlockingText'] = !empty($settings['embedpress_doc_submit_Unlocking_text']) ? sanitize_text_field($settings['embedpress_doc_submit_Unlocking_text']) : '';
567
568 $embed_settings['enableFooterMessage'] = !empty($settings['embedpress_doc_enable_footer_message']) ? esc_attr($settings['embedpress_doc_enable_footer_message']) : '';
569
570 $embed_settings['footerMessage'] = !empty($settings['embedpress_doc_lock_content_footer_message']) ? sanitize_text_field($settings['embedpress_doc_lock_content_footer_message']) : '';
571
572 $embed_settings['userRole'] = !empty($settings['embedpress_doc_select_roles']) ? $settings['embedpress_doc_select_roles'] : [];
573
574 $embed_settings['protectionMessage'] = !empty($settings['embedpress_doc_protection_message']) ? $settings['embedpress_doc_protection_message'] : '';
575
576
577 $content_share_class = '';
578 $share_position_class = '';
579 $share_position = isset($settings['embedpress_doc_content_share_position']) ? esc_attr($settings['embedpress_doc_content_share_position']) : 'right';
580
581 if (!empty($settings['embedpress_doc_content_share'])) {
582 $content_share_class = 'ep-content-share-enabled';
583 $share_position_class = 'ep-share-position-' . $share_position;
584 }
585
586 $password_correct = isset($_COOKIE['password_correct_' . $client_id]) ? sanitize_text_field($_COOKIE['password_correct_' . $client_id]) : '';
587
588 $content_protection_class = 'ep-content-protection-enabled';
589 if (empty($settings['embedpress_doc_lock_content']) || empty($settings['embedpress_doc_lock_content_password']) || $hash_pass === $password_correct) {
590 $content_protection_class = 'ep-content-protection-disabled';
591 }
592
593 $adsAtts = '';
594
595 if (!empty($settings['adManager'])) {
596 $ad = base64_encode(json_encode($settings)); // Using WordPress JSON encoding function
597 $adsAtts = 'data-sponsored-id="' . esc_attr($client_id) . '" data-sponsored-attrs="' . esc_attr($ad) . '" class="sponsored-mask"';
598 }
599
600 ?>
601
602 <div <?php echo $this->get_render_attribute_string('embedpress-document'); ?> style="<?php echo esc_attr($dimension); ?>; max-width:100%; display: inline-block">
603
604 <?php
605 do_action('embedpress_document_after_embed', $settings, $url, $id, $this);
606
607 if ($url != '') {
608 $url = esc_url($url);
609
610 if ($this->is_pdf($url)) {
611 $this->add_render_attribute('embedpres-pdf-render', 'data-emsrc', esc_url($url));
612 $embed_content = '<div ' . $this->get_render_attribute_string('embedpres-pdf-render') . '>';
613
614 $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>';
615
616 if ($settings['embedpress_document_powered_by'] === 'yes') {
617 $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', esc_html__('Powered By EmbedPress', 'embedpress'));
618 }
619 $embed_content .= '</div>';
620
621 if (Plugin::$instance->editor->is_edit_mode()) {
622 $embed_content .= $this->render_editor_script($id, $url);
623 }
624 } else {
625 if (Helper::is_file_url($url)) {
626 $view_link = '//view.officeapps.live.com/op/embed.aspx?src=' . urlencode($url) . '&embedded=true';
627 } else {
628 $view_link = 'https://drive.google.com/viewerng/viewer?url=' . urlencode($url) . '&embedded=true&chrome=false';
629 }
630
631
632 if($settings['embedpress_document_viewer'] === 'custom')
633 {
634 if (Helper::is_file_url($url)) {
635 $view_link = '//view.officeapps.live.com/op/embed.aspx?src=' . urlencode($url) . '&embedded=true';
636 } else {
637 $view_link = 'https://drive.google.com/viewerng/viewer?url=' . urlencode($url) . '&embedded=true&chrome=false';
638 }
639 }
640 elseif($settings['embedpress_document_viewer'] === 'office')
641 {
642 $view_link = '//view.officeapps.live.com/op/embed.aspx?src=' . urlencode($url) . '&embedded=true';
643 }
644 elseif($settings['embedpress_document_viewer'] === 'google')
645 {
646 $view_link = '//docs.google.com/gview?embedded=true&url=' . urlencode($url);
647 }
648
649 $hostname = parse_url($url, PHP_URL_HOST);
650 $domain = implode(".", array_slice(explode(".", $hostname), -2));
651
652 if ($domain == "google.com") {
653 $view_link = $url . '?embedded=true';
654 if (strpos($view_link, '/presentation/')) {
655 $view_link = Helper::get_google_presentation_url($url);
656 }
657 }
658
659 $embed_content = '<div ' . $this->get_render_attribute_string('embedpres-pdf-render') . '>';
660
661 $is_powered_by = '';
662 if ($settings['embedpress_document_powered_by'] === 'yes') {
663 $is_powered_by = 'ep-powered-by-enabled';
664 }
665
666 $is_download_enabled = ' enabled-file-download';
667 if ($settings['doc_print_download'] !== 'yes') {
668 $is_download_enabled = '';
669 }
670
671 $file_extenstion = 'link';
672 if (!empty(Helper::is_file_url($url))) {
673 $file_extenstion = Helper::get_extension_from_file_url($url);
674 }
675
676 $is_masked = '';
677
678 if($settings['embedpress_document_viewer'] === 'custom')
679 {
680 $is_masked = 'ep-file-download-option-masked ';
681 }
682
683 $is_custom_theme = '';
684
685 if ($settings['embedpress_theme_mode'] == 'custom') {
686 $custom_color = sanitize_text_field($settings['embedpress_doc_custom_color']);
687
688 $is_custom_theme = 'data-custom-color="'.esc_attr($custom_color).'"';
689 }
690
691 $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()) . '">';
692
693 $sandbox = '';
694 if ($settings['doc_print_download'] === 'yes') {
695 $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"';
696 }
697
698 $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 . '>
699 </iframe>';
700
701 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')) {
702 $embed_content .= '<div class="embed-download-disabled"></div>';
703 }
704
705 if (
706 $settings['doc_draw'] === 'yes' &&
707 isset($settings['embedpress_elementor_document_width']) &&
708 isset($settings['embedpress_elementor_document_height'])
709 ) {
710 $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>';
711 }
712
713 if ($settings['doc_print_download'] === 'yes' && Helper::get_extension_from_file_url($url) !== 'pptx') {
714 $embed_content .= '<div style="width: 40px; height: 40px; position: absolute; opacity: 0; right: 12px; top: 12px;"></div>';
715 }
716
717 if (!empty($settings['doc_toolbar']) && $settings['embedpress_document_viewer'] === 'custom') {
718 $embed_content .= '<div class="ep-external-doc-icons">';
719
720 if (empty(Helper::is_file_url($url))) {
721 $embed_content .= Helper::ep_get_popup_icon();
722 }
723
724 if (!empty(Helper::is_file_url($url))) {
725 if (!empty($settings['doc_print_download'])) {
726 $embed_content .= Helper::ep_get_print_icon();
727 $embed_content .= Helper::ep_get_download_icon();
728 }
729 }
730 if (!empty($settings['doc_draw'])) {
731 $embed_content .= Helper::ep_get_draw_icon();
732 }
733 if (!empty($settings['doc_fullscreen_mode'])) {
734 $embed_content .= Helper::ep_get_fullscreen_icon();
735 $embed_content .= Helper::ep_get_minimize_icon();
736 }
737
738 $embed_content .= '</div>';
739 }
740 $embed_content .= '</div>';
741
742 if ($settings['embedpress_document_powered_by'] === 'yes') {
743 $embed_content .= '<div>';
744 $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', esc_html__('Powered By EmbedPress', 'embedpress'));
745 $embed_content .= '</div>';
746 }
747
748 $embed_content .= '</div>';
749 }
750 }
751
752
753 ?>
754 <div <?php echo $adsAtts; ?>>
755
756 <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); ?>">
757 <div id="<?php echo esc_attr($this->get_id()); ?>" class="ep-embed-content-wraper">
758 <?php
759
760 $content_id = $client_id;
761 if (
762 (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') ||
763 ($settings['embedpress_doc_protection_type'] == 'password' && !empty(Helper::is_password_correct($client_id)) && ($hash_pass === $password_correct) ) ||
764 !apply_filters('embedpress/is_allow_rander', false) ||
765 ($settings['embedpress_doc_protection_type'] == 'user-role' && Helper::has_allowed_roles($embed_settings['userRole']))
766 ) {
767
768 if (!empty($settings['embedpress_doc_content_share'])) {
769 $embed_content .= Helper::embed_content_share($content_id, $embed_settings);
770 }
771 if (!empty($embed_content)) {
772 echo $embed_content;
773 }
774 } else {
775 if (!empty($settings['embedpress_doc_content_share'])) {
776 $embed_content .= Helper::embed_content_share($content_id, $embed_settings);
777 }
778 if ($settings['embedpress_doc_protection_type'] == 'password') {
779 do_action('embedpress/display_password_form', $client_id, $embed_content, $pass_hash_key, $embed_settings);
780 } else {
781 do_action('embedpress/content_protection_content', $client_id, $embed_settings['protectionMessage'], $embed_settings['userRole']);
782 }
783 }
784 ?>
785 </div>
786 </div>
787 <?php
788 if (!empty($settings['adManager'])) {
789 $embed_content = apply_filters('embedpress/generate_ad_template', $embed_content, $client_id, $settings, 'elementor');
790 }
791 ?>
792 </div>
793 </div>
794
795 <?php
796 }
797
798
799 private function get_file_url()
800 {
801 $settings = $this->get_settings();
802 $file_url = $settings['embedpress_document_type'] === 'url' ? esc_url($settings['embedpress_document_file_link']['url']) : esc_url($settings['embedpress_document_Uploader']['url']);
803 return $file_url;
804 }
805
806
807 protected function render_editor_script( $id, $url )
808 {
809 ?>
810 <script>
811 (function ($) {
812 'use strict';
813 $(document).ready(function () {
814 var selector = $('.embedpress-embed-document-pdf');
815 let option = {
816 forceObject: false,
817 };
818 if (selector.length && typeof PDFObject !== 'undefined') {
819 PDFObject.embed("<?php echo $url; ?>", "<?php echo '.' . $id; ?>", option);
820 }
821 });
822 })(jQuery);
823 </script>
824 <?php
825 }
826
827 /**
828 * Track Document widget usage for analytics
829 *
830 * @param array $settings
831 * @param string $url
832 * @param string $content_id
833 * @return void
834 */
835 private function track_document_widget_usage($settings, $url, $content_id)
836 {
837 // Only track if analytics is enabled and we have the necessary classes
838 if (class_exists('EmbedPress\Includes\Classes\Analytics\Analytics_Manager')) {
839 if (empty($url)) {
840 return;
841 }
842
843 $provider_name = 'Document';
844
845 $tracking_data = [
846 'embed_type' => $provider_name,
847 'embed_url' => $url,
848 'post_id' => get_the_ID(),
849 'page_url' => get_permalink(),
850 'title' => get_the_title()
851 ];
852
853 // Track content creation
854 do_action('embedpress_content_embedded', $content_id, 'elementor-document', $tracking_data);
855 }
856 }
857 }
858