PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 3.9.13
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v3.9.13
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 2 years ago Embedpress_Document.php 2 years ago Embedpress_Elementor.php 2 years ago Embedpress_Pdf.php 2 years ago
Embedpress_Document.php
749 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 /**
46 * Get widget keywords.
47 *
48 * Retrieve the list of keywords the widget belongs to.
49 *
50 * @return array Widget keywords.
51 * @since 2.5.5
52 * @access public
53 *
54 */
55 public function get_keywords()
56 {
57 return ['embedpress', 'pdf', 'doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'embedpress-document'];
58 }
59
60 protected function register_controls()
61 {
62 $this->pro_class = is_embedpress_pro_active() ? '': 'embedpress-pro-control not-active';
63 $this->pro_text = is_embedpress_pro_active() ? '': '<sup class="embedpress-pro-label" style="color:red">'.__('Pro', 'embedpress').'</sup>';
64 /**
65 * EmbedPress Content Settings
66 */
67 $this->start_controls_section(
68 'embedpress_document_content_settings',
69 [
70 'label' => esc_html__( 'General', 'embedpress' ),
71 ]
72 );
73
74 $this->add_control(
75 'embedpress_document_type',
76 [
77 'label' => __( 'Document Type', 'embedpress' ),
78 'type' => Controls_Manager::SELECT,
79 'default' => 'file',
80 'options' => [
81 'file' => __( 'File', 'embedpress' ),
82 'url' => __( 'URL', 'embedpress' )
83 ],
84 ]
85 );
86 $this->add_control(
87 'embedpress_document_Uploader',
88 [
89
90 'label' => __( 'Upload File', 'embedpress' ),
91 'type' => Controls_Manager::MEDIA,
92 'dynamic' => [
93 'active' => true,
94 'categories' => [
95 TagsModule::MEDIA_CATEGORY,
96 ],
97 ],
98 'media_type' => [
99 'application/pdf',
100 'application/msword',
101 'application/vnd.ms-powerpoint',
102 'application/vnd.ms-excel',
103 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
104 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
105 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
106 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' // Added PPSX MIME type
107
108 ],
109 'description' => __( 'Upload a file or pick one from your media library for embed. Supported File Type: PDF, DOC/DOCX, PPT/PPTX, XLS/XLSX etc.',
110 'embedpress' ),
111 'condition' => [
112 'embedpress_document_type' => 'file'
113 ],
114 ]
115 );
116
117 $this->add_control(
118 'embedpress_document_file_link',
119 [
120 'label' => __( 'URL', 'embedpress' ),
121 'type' => Controls_Manager::URL,
122 'placeholder' => __( 'https://your-link.com/file.pdf', 'embedpress' ),
123 'show_external' => false,
124 'dynamic' => [
125 'active' => true,
126 ],
127 'default' => [
128 'url' => ''
129 ],
130 'condition' => [
131 'embedpress_document_type' => 'url'
132 ],
133 ]
134 );
135
136 $this->add_responsive_control(
137 'embedpress_elementor_document_width',
138 [
139 'type' => \Elementor\Controls_Manager::SLIDER,
140 'label' => esc_html__( 'Width', 'embedpress' ),
141 'range' => [
142 'px' => [
143 'min' => 1,
144 'max' => 1000,
145 ],
146 ],
147 'devices' => [ 'desktop', 'tablet', 'mobile' ],
148 'default' => [
149 'unit' => 'px',
150 'size' => 600,
151 ],
152 'desktop_default' => [
153 'unit' => 'px',
154 'size' => 600,
155 ],
156 'tablet_default' => [
157 'size' => 400,
158 'unit' => 'px',
159 ],
160 'mobile_default' => [
161 'size' => 300,
162 'unit' => 'px',
163 ],
164 'selectors' => [
165 '{{WRAPPER}} .embedpress-document-embed iframe' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%',
166 '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%',
167 '{{WRAPPER}} .embedpress-document-embed' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%',
168 ],
169 ]
170 );
171 $this->add_responsive_control(
172 'embedpress_elementor_document_height',
173 [
174 'type' => \Elementor\Controls_Manager::SLIDER,
175 'label' => esc_html__( 'Height', 'embedpress' ),
176 'range' => [
177 'px' => [
178 'min' => 1,
179 'max' => 1000,
180 ],
181 ],
182 'devices' => [ 'desktop', 'tablet', 'mobile' ],
183 'default' => [
184 'unit' => 'px',
185 'size' => 600,
186 ],
187 'desktop_default' => [
188 'unit' => 'px',
189 'size' => 600,
190 ],
191 'tablet_default' => [
192 'size' => 400,
193 'unit' => 'px',
194 ],
195 'mobile_default' => [
196 'size' => 300,
197 'unit' => 'px',
198 ],
199 'selectors' => [
200 '{{WRAPPER}} .embedpress-document-embed iframe' => 'height: {{SIZE}}{{UNIT}}!important;',
201 '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'height: {{SIZE}}{{UNIT}};',
202 '{{WRAPPER}} .embedpress-document-embed ' => 'max-height: {{SIZE}}{{UNIT}};',
203 ],
204 ]
205 );
206
207 $this->add_responsive_control(
208 'embedpress_elementor_document_align',
209 [
210 'label' => __( 'Alignment', 'embedpress' ),
211 'type' => Controls_Manager::CHOOSE,
212 'options' => [
213 'left' => [
214 'title' => __( 'Left', 'embedpress' ),
215 'icon' => 'eicon-text-align-left',
216 ],
217 'center' => [
218 'title' => __( 'Center', 'embedpress' ),
219 'icon' => 'eicon-text-align-center',
220 ],
221 'right' => [
222 'title' => __( 'Right', 'embedpress' ),
223 'icon' => 'eicon-text-align-right',
224 ]
225 ],
226 'prefix_class' => 'elementor%s-align-',
227 'default' => '',
228 ]
229 );
230
231 $this->add_control(
232 'embedpress_document_powered_by',
233 [
234 'label' => __( 'Powered By', 'embedpress' ),
235 'type' => Controls_Manager::SWITCHER,
236 'label_on' => __( 'Show', 'embedpress' ),
237 'label_off' => __( 'Hide', 'embedpress' ),
238 'return_value' => 'yes',
239 'default' => apply_filters( 'embedpress_document_powered_by_control', 'yes' ),
240 ]
241 );
242
243 $this->init_branding_controls( 'document');
244
245 $this->end_controls_section();
246
247 /**
248 * EmbedPress Document control settings
249 */
250
251 $this->start_controls_section(
252 'embedpress_doc_content_settings',
253 [
254 'label' => esc_html__('Controls', 'embedpress'),
255 ]
256 );
257
258 $this->add_control(
259 'important_note',
260 [
261 'type' => \Elementor\Controls_Manager::RAW_HTML,
262 'raw' => esc_html__( 'Download feature is available when link has the document extension at the end.', 'embedpress' ),
263 'content_classes' => 'elementor-panel-alert elementor-panel-alert-info',
264 'condition' => [
265 'embedpress_document_type' => 'url',
266 ],
267 ]
268 );
269
270 $this->add_control(
271 'important_note_2',
272 [
273 'type' => \Elementor\Controls_Manager::RAW_HTML,
274 'raw' => esc_html__( 'Toolbar and additional feature options become accessible upon selecting the Custom Viewer mode.', 'embedpress' ),
275 'content_classes' => 'elementor-panel-alert elementor-panel-alert-info',
276 'condition' => [
277 'embedpress_document_type' => 'file',
278 'embedpress_document_viewer' => 'office',
279 ],
280 ]
281 );
282
283
284 $this->add_control(
285 'embedpress_document_viewer',
286 [
287 'label' => __('Viewer', 'embedpress'),
288 'type' => Controls_Manager::SELECT,
289 'default' => 'custom',
290 'options' => [
291 'custom' => __('Custom', 'embedpress'),
292 'office' => __('MS Office', 'embedpress'),
293 ],
294 ]
295 );
296
297 $this->add_control(
298 'embedpress_theme_mode',
299 [
300 'label' => __('Theme', 'embedpress'),
301 'type' => Controls_Manager::SELECT,
302 'default' => 'default',
303 'options' => [
304 'default' => __('System Default', 'embedpress'),
305 'dark' => __('Dark', 'embedpress'),
306 'light' => __('Light', 'embedpress'),
307 'custom' => __('Custom', 'embedpress')
308 ],
309 'condition' => [
310 'embedpress_document_viewer' => 'custom',
311 ],
312
313 ]
314 );
315
316 $this->add_control(
317 'embedpress_doc_custom_color',
318 [
319 'label' => esc_html__( 'Color', 'embedpress' ),
320 'type' => \Elementor\Controls_Manager::COLOR,
321 'condition' => [
322 'embedpress_theme_mode' => 'custom',
323 'embedpress_document_viewer' => 'custom',
324 ],
325 ]
326 );
327
328 $this->add_control(
329 'doc_toolbar',
330 [
331 'label' => sprintf(__('Toolbar %s', 'embedpress'), $this->pro_text),
332 'type' => Controls_Manager::SWITCHER,
333 'label_on' => __('Show', 'embedpress'),
334 'label_off' => __('Hide', 'embedpress'),
335 'return_value' => 'yes',
336 'default' => 'yes',
337 'classes' => $this->pro_class,
338 'condition' => [
339 'embedpress_document_viewer' => 'custom',
340 ],
341 ]
342 );
343
344
345 $this->add_control(
346 'doc_fullscreen_mode',
347 [
348 'label' => __('Fullscreen', 'embedpress'),
349 'type' => Controls_Manager::SWITCHER,
350 'label_on' => __('Show', 'embedpress'),
351 'label_off' => __('Hide', 'embedpress'),
352 'return_value' => 'yes',
353 'default' => 'yes',
354 'condition' => [
355 'doc_toolbar' => 'yes',
356 'embedpress_document_viewer' => 'custom',
357 ],
358 ]
359 );
360
361 $this->add_control(
362 'doc_print_download',
363 [
364 'label' => sprintf(__('Print/Download %s', 'embedpress'), $this->pro_text),
365 'type' => Controls_Manager::SWITCHER,
366 'label_on' => __('Show', 'embedpress'),
367 'label_off' => __('Hide', 'embedpress'),
368 'return_value' => 'yes',
369 'default' => 'yes',
370 'classes' => $this->pro_class,
371 'condition' => [
372 'doc_toolbar' => 'yes',
373 'embedpress_document_viewer' => 'custom',
374 ],
375 ]
376 );
377
378
379 $this->add_control(
380 'doc_draw',
381 [
382 'label' => __('Draw', 'embedpress'),
383 'type' => Controls_Manager::SWITCHER,
384 'label_on' => __('Show', 'embedpress'),
385 'label_off' => __('Hide', 'embedpress'),
386 'return_value' => 'yes',
387 'default' => 'yes',
388 'condition' => [
389 'doc_toolbar' => 'yes',
390 'embedpress_document_viewer' => 'custom',
391 ],
392 ]
393 );
394
395
396 $this->end_controls_section();
397
398 do_action( 'extend_elementor_controls', $this, '_doc_', $this->pro_text, $this->pro_class);
399
400 if (! is_embedpress_pro_active()) {
401 $this->start_controls_section(
402 'embedpress_pro_section',
403 [
404 'label' => __('Go Premium for More Features', 'embedpress'),
405 ]
406 );
407
408 $this->add_control(
409 'embedpress_pro_cta',
410 [
411 'label' => __('Unlock more possibilities', 'embedpress'),
412 'type' => Controls_Manager::CHOOSE,
413 'options' => [
414 '1' => [
415 'title' => '',
416 'icon' => 'eicon-lock',
417 ],
418 ],
419 'default' => '1',
420 'description' => '<span class="pro-feature"> Get the <a href="https://wpdeveloper.com/in/upgrade-embedpress" target="_blank">Pro version</a> for more provider support and customization options.</span>',
421 ]
422 );
423
424 $this->end_controls_section();
425 }
426 }
427
428 private function is_pdf( $url )
429 {
430 $arr = explode( '.', $url );
431 return end( $arr ) === 'pdf';
432 }
433
434 protected function render()
435 {
436 $settings = $this->get_settings();
437
438 $client_id = esc_attr($this->get_id());
439 $pass_hash_key = md5($settings['embedpress_doc_lock_content_password']);
440 $url = esc_url($this->get_file_url());
441 $id = 'embedpress-pdf-' . $this->get_id();
442
443 if ($settings['embedpress_document_type'] === 'url') {
444 if (class_exists('ACF') && function_exists('get_field')) {
445 if (!empty($settings['__dynamic__']) && !empty($settings['__dynamic__']['embedpress_document_file_link'])) {
446 $decode_url = urldecode(($settings['__dynamic__']['embedpress_document_file_link']));
447 preg_match('/"key":"([^"]+):([^"]+)"/', $decode_url, $matches);
448 if (isset($matches[0])) {
449 if (isset($matches[1])) {
450 $get_acf_key = $matches[1];
451 $url = esc_url(get_field($get_acf_key));
452
453 if (empty($url)) {
454 $pattern = '/"fallback":"([^"]+)"/';
455 preg_match($pattern, $decode_url, $matches);
456
457 if (isset($matches[1])) {
458 $url = esc_url($matches[1]);
459 }
460 }
461 }
462 }
463 }
464 }
465 }
466 $hash_pass = hash('sha256', wp_salt(32) . md5($settings['embedpress_doc_lock_content_password']));
467
468 $dimension = '';
469 if (empty($settings['embedpress_doc_lock_content']) && empty($settings['embedpress_doc_lock_content_password'])) {
470 $dimension = "width: " . esc_attr($settings['embedpress_elementor_document_width']['size']) . "px; height: " . esc_attr($settings['embedpress_elementor_document_height']['size']) . "px";
471 }
472
473 $content_locked_class = '';
474 if (!empty($settings['embedpress_doc_lock_content']) && !empty($settings['embedpress_doc_lock_content_password'])) {
475 $content_locked_class = 'ep-content-locked';
476 }
477
478 $this->add_render_attribute('embedpres-pdf-render', [
479 'class' => ['embedpress-embed-document-pdf', $id],
480 'data-emid' => $id
481 ]);
482
483 Helper::get_source_data(md5($this->get_id()) . '_eb_elementor', $url, 'elementor_source_data', 'elementor_temp_source_data');
484
485 $this->add_render_attribute('embedpress-document', [
486 'class' => ['embedpress-document-embed', 'ep-doc-' . md5($id), 'ose-document', $content_locked_class]
487 ]);
488
489 $embed_settings = [];
490 $embed_settings['customThumbnail'] = !empty($settings['embedpress_doc_content_share_custom_thumbnail']['url']) ? esc_url($settings['embedpress_doc_content_share_custom_thumbnail']['url']) : '';
491
492 $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));
493
494 $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));
495
496 $embed_settings['sharePosition'] = !empty($settings['embedpress_doc_content_share_position']) ? esc_attr($settings['embedpress_doc_content_share_position']) : 'right';
497
498 $embed_settings['lockHeading'] = !empty($settings['embedpress_doc_lock_content_heading']) ? sanitize_text_field($settings['embedpress_doc_lock_content_heading']) : '';
499
500 $embed_settings['lockSubHeading'] = !empty($settings['embedpress_doc_lock_content_sub_heading']) ? sanitize_text_field($settings['embedpress_doc_lock_content_sub_heading']) : '';
501
502 $embed_settings['lockErrorMessage'] = !empty($settings['embedpress_doc_lock_content_error_message']) ? sanitize_text_field($settings['embedpress_doc_lock_content_error_message']) : '';
503
504 $embed_settings['passwordPlaceholder'] = !empty($settings['embedpress_doc_password_placeholder']) ? esc_attr($settings['embedpress_doc_password_placeholder']) : '';
505
506 $embed_settings['submitButtonText'] = !empty($settings['embedpress_doc_submit_button_text']) ? sanitize_text_field($settings['embedpress_doc_submit_button_text']) : '';
507
508 $embed_settings['submitUnlockingText'] = !empty($settings['embedpress_doc_submit_Unlocking_text']) ? sanitize_text_field($settings['embedpress_doc_submit_Unlocking_text']) : '';
509
510 $embed_settings['enableFooterMessage'] = !empty($settings['embedpress_doc_enable_footer_message']) ? esc_attr($settings['embedpress_doc_enable_footer_message']) : '';
511
512 $embed_settings['footerMessage'] = !empty($settings['embedpress_doc_lock_content_footer_message']) ? sanitize_text_field($settings['embedpress_doc_lock_content_footer_message']) : '';
513
514
515 $content_share_class = '';
516 $share_position_class = '';
517 $share_position = isset($settings['embedpress_doc_content_share_position']) ? esc_attr($settings['embedpress_doc_content_share_position']) : 'right';
518
519 if (!empty($settings['embedpress_doc_content_share'])) {
520 $content_share_class = 'ep-content-share-enabled';
521 $share_position_class = 'ep-share-position-' . $share_position;
522 }
523
524 $password_correct = isset($_COOKIE['password_correct_' . $client_id]) ? sanitize_text_field($_COOKIE['password_correct_' . $client_id]) : '';
525
526 $content_protection_class = 'ep-content-protection-enabled';
527 if (empty($settings['embedpress_doc_lock_content']) || empty($settings['embedpress_doc_lock_content_password']) || $hash_pass === $password_correct) {
528 $content_protection_class = 'ep-content-protection-disabled';
529 }
530
531 $adsAtts = '';
532
533 if (!empty($settings['adManager'])) {
534 $ad = base64_encode(json_encode($settings)); // Using WordPress JSON encoding function
535 $adsAtts = 'data-ad-id="' . esc_attr($client_id) . '" data-ad-attrs="' . esc_attr($ad) . '" class="ad-mask"';
536 }
537
538 ?>
539
540 <div <?php echo $this->get_render_attribute_string('embedpress-document'); ?> style="<?php echo esc_attr($dimension); ?>; max-width:100%; display: inline-block">
541
542 <?php
543 do_action('embedpress_document_after_embed', $settings, $url, $id, $this);
544
545 if ($url != '') {
546 $url = esc_url($url);
547
548 if ($this->is_pdf($url)) {
549 $this->add_render_attribute('embedpres-pdf-render', 'data-emsrc', esc_url($url));
550 $embed_content = '<div ' . $this->get_render_attribute_string('embedpres-pdf-render') . '>';
551
552 $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>';
553
554 if ($settings['embedpress_document_powered_by'] === 'yes') {
555 $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', esc_html__('Powered By EmbedPress', 'embedpress'));
556 }
557 $embed_content .= '</div>';
558
559 if (Plugin::$instance->editor->is_edit_mode()) {
560 $embed_content .= $this->render_editor_script($id, $url);
561 }
562 } else {
563 if (Helper::is_file_url($url)) {
564 $view_link = '//view.officeapps.live.com/op/embed.aspx?src=' . urlencode($url) . '&embedded=true';
565 } else {
566 $view_link = 'https://drive.google.com/viewerng/viewer?url=' . urlencode($url) . '&embedded=true&chrome=false';
567 }
568
569
570 if($settings['embedpress_document_viewer'] === 'custom')
571 {
572 if (Helper::is_file_url($url)) {
573 $view_link = '//view.officeapps.live.com/op/embed.aspx?src=' . urlencode($url) . '&embedded=true';
574 } else {
575 $view_link = 'https://drive.google.com/viewerng/viewer?url=' . urlencode($url) . '&embedded=true&chrome=false';
576 }
577 }
578 elseif($settings['embedpress_document_viewer'] === 'office')
579 {
580 $view_link = '//view.officeapps.live.com/op/embed.aspx?src=' . urlencode($url) . '&embedded=true';
581 }
582
583
584 $hostname = parse_url($url, PHP_URL_HOST);
585 $domain = implode(".", array_slice(explode(".", $hostname), -2));
586
587 if ($domain == "google.com") {
588 $view_link = $url . '?embedded=true';
589 if (strpos($view_link, '/presentation/')) {
590 $view_link = Helper::get_google_presentation_url($url);
591 }
592 }
593
594 $embed_content = '<div ' . $this->get_render_attribute_string('embedpres-pdf-render') . '>';
595
596 $is_powered_by = '';
597 if ($settings['embedpress_document_powered_by'] === 'yes') {
598 $is_powered_by = 'ep-powered-by-enabled';
599 }
600
601 $is_download_enabled = ' enabled-file-download';
602 if ($settings['doc_print_download'] !== 'yes') {
603 $is_download_enabled = '';
604 }
605
606 $file_extenstion = 'link';
607 if (!empty(Helper::is_file_url($url))) {
608 $file_extenstion = Helper::get_extension_from_file_url($url);
609 }
610
611 $is_masked = '';
612
613 if($settings['embedpress_document_viewer'] === 'custom')
614 {
615 $is_masked = 'ep-file-download-option-masked ';
616 }
617
618 $is_custom_theme = '';
619
620 if ($settings['embedpress_theme_mode'] == 'custom') {
621 $custom_color = sanitize_text_field($settings['embedpress_doc_custom_color']);
622
623 $is_custom_theme = 'data-custom-color="'.esc_attr($custom_color).'"';
624 }
625
626 $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()) . '">';
627
628 $sandbox = '';
629 if ($settings['doc_print_download'] === 'yes') {
630 $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"';
631 }
632
633 $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 . '>
634 </iframe>';
635
636 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')) {
637 $embed_content .= '<div class="embed-download-disabled"></div>';
638 }
639
640 if ($settings['doc_draw'] === 'yes') {
641 $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>';
642 }
643
644 if ($settings['doc_print_download'] === 'yes' && Helper::get_extension_from_file_url($url) !== 'pptx') {
645 $embed_content .= '<div style="width: 40px; height: 40px; position: absolute; opacity: 0; right: 12px; top: 12px;"></div>';
646 }
647
648 if (!empty($settings['doc_toolbar']) && $settings['embedpress_document_viewer'] === 'custom') {
649 $embed_content .= '<div class="ep-external-doc-icons">';
650
651 if (empty(Helper::is_file_url($url))) {
652 $embed_content .= Helper::ep_get_popup_icon();
653 }
654
655 if (!empty(Helper::is_file_url($url))) {
656 if (!empty($settings['doc_print_download'])) {
657 $embed_content .= Helper::ep_get_print_icon();
658 $embed_content .= Helper::ep_get_download_icon();
659 }
660 }
661 if (!empty($settings['doc_draw'])) {
662 $embed_content .= Helper::ep_get_draw_icon();
663 }
664 if (!empty($settings['doc_fullscreen_mode'])) {
665 $embed_content .= Helper::ep_get_fullscreen_icon();
666 $embed_content .= Helper::ep_get_minimize_icon();
667 }
668
669 $embed_content .= '</div>';
670 }
671 $embed_content .= '</div>';
672
673 if ($settings['embedpress_document_powered_by'] === 'yes') {
674 $embed_content .= '<div>';
675 $embed_content .= sprintf('<p class="embedpress-el-powered">%s</p>', esc_html__('Powered By EmbedPress', 'embedpress'));
676 $embed_content .= '</div>';
677 }
678
679 $embed_content .= '</div>';
680 }
681 }
682
683
684 ?>
685 <div <?php echo $adsAtts; ?>>
686
687 <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); ?>">
688 <div id="<?php echo esc_attr($this->get_id()); ?>" class="ep-embed-content-wraper">
689 <?php
690
691 $content_id = $client_id;
692 if ((empty($settings['embedpress_doc_lock_content']) || $settings['embedpress_doc_lock_content'] == 'no' || empty($settings['embedpress_doc_lock_content_password'])) || (!empty(Helper::is_password_correct($client_id)) && ($hash_pass === $_COOKIE['password_correct_' . $client_id]))) {
693
694 if (!empty($settings['embedpress_doc_content_share'])) {
695 $embed_content .= Helper::embed_content_share($content_id, $embed_settings);
696 }
697 if (!empty($embed_content)) {
698 echo $embed_content;
699 }
700 } else {
701 if (!empty($settings['embedpress_doc_content_share'])) {
702 $embed_content .= Helper::embed_content_share($content_id, $embed_settings);
703 }
704 Helper::display_password_form($client_id, $embed_content, $pass_hash_key, $embed_settings);
705 }
706 ?>
707 </div>
708 </div>
709 <?php
710 if (!empty($settings['adManager'])) {
711 $embed_content .= Helper::generateAdTemplate($client_id, $settings, 'elementor');
712 }
713 ?>
714 </div>
715 </div>
716
717 <?php
718 }
719
720
721 private function get_file_url()
722 {
723 $settings = $this->get_settings();
724 $file_url = $settings['embedpress_document_type'] === 'url' ? esc_url($settings['embedpress_document_file_link']['url']) : esc_url($settings['embedpress_document_Uploader']['url']);
725 return $file_url;
726 }
727
728
729 protected function render_editor_script( $id, $url )
730 {
731 ?>
732 <script>
733 (function ($) {
734 'use strict';
735 $(document).ready(function () {
736 var selector = $('.embedpress-embed-document-pdf');
737 let option = {
738 forceObject: false,
739 };
740 if (selector.length) {
741 PDFObject.embed("<?php echo $url; ?>", "<?php echo '.' . $id; ?>", option);
742 }
743 });
744 })(jQuery);
745 </script>
746 <?php
747 }
748 }
749