PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 3.6.7
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v3.6.7
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_Pdf.php
embedpress / EmbedPress / Elementor / Widgets Last commit date
Embedpress_Calendar.php 3 years ago Embedpress_Document.php 3 years ago Embedpress_Elementor.php 3 years ago Embedpress_Pdf.php 3 years ago
Embedpress_Pdf.php
593 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 EmbedPress\Includes\Classes\Helper;
10 use EmbedPress\Includes\Traits\Branding;
11
12 (defined('ABSPATH')) or die("No direct script access allowed.");
13
14 class Embedpress_Pdf extends Widget_Base
15 {
16
17 use Branding;
18 protected $pro_class = '';
19 protected $pro_text = '';
20 public function get_name()
21 {
22 return 'embedpress_pdf';
23 }
24
25 public function get_title()
26 {
27 return esc_html__('EmbedPress PDF', '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-pdf';
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', '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_content_settings',
69 [
70 'label' => esc_html__('Content Settings', 'embedpress'),
71 ]
72 );
73
74 $this->add_control(
75 'embedpress_pdf_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
87 $this->add_control(
88 'embedpress_pdf_Uploader',
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 ],
101 'description' => __(
102 'Upload a file or pick one from your media library for embed. Supported File Type: PDF',
103 'embedpress'
104 ),
105 'condition' => [
106 'embedpress_pdf_type' => 'file'
107 ],
108 ]
109 );
110
111 $this->add_control(
112 'embedpress_pdf_file_link',
113 [
114 'label' => __('URL', 'embedpress'),
115 'type' => Controls_Manager::URL,
116 'placeholder' => __('https://your-link.com/file.pdf', 'embedpress'),
117 'show_external' => false,
118 'default' => [
119 'url' => ''
120 ],
121 'condition' => [
122 'embedpress_pdf_type' => 'url'
123 ],
124 ]
125 );
126
127 $this->add_control(
128 'embedpress_pdf_zoom',
129 [
130 'label' => __('Zoom', 'embedpress'),
131 'type' => Controls_Manager::SELECT,
132 'default' => 'auto',
133 'options' => [
134 'auto' => __('Automatic Zoom', 'embedpress'),
135 'page-actual' => __('Actual Size', 'embedpress'),
136 'page-fit' => __('Page Fit', 'embedpress'),
137 'page-width' => __('Page Width', 'embedpress'),
138 'custom' => __('Custom', 'embedpress'),
139 '50' => __('50%', 'embedpress'),
140 '75' => __('75%', 'embedpress'),
141 '100' => __('100%', 'embedpress'),
142 '125' => __('125%', 'embedpress'),
143 '150' => __('150%', 'embedpress'),
144 '200' => __('200%', 'embedpress'),
145 '300' => __('300%', 'embedpress'),
146 '400' => __('400%', 'embedpress'),
147 ],
148 ]
149 );
150 $this->add_control(
151 'embedpress_pdf_zoom_custom',
152 [
153 'label' => __('Custom Zoom', 'embedpress'),
154 'type' => Controls_Manager::NUMBER,
155 'condition' => [
156 'embedpress_pdf_zoom' => 'custom'
157 ],
158 ]
159 );
160
161 $this->add_control(
162 'embedpress_elementor_document_width',
163 [
164 'label' => __('Width', 'embedpress'),
165 'type' => Controls_Manager::SLIDER,
166 'separator' => 'before',
167 'size_units' => [ 'px', '%' ],
168 'default' => [
169 'unit' => 'px',
170 'size' => 600,
171 ],
172 'range' => [
173 '%' => [
174 'min' => 0,
175 'max' => 100,
176 ],
177 'px' => [
178 'min' => 6,
179 'max' => 1000,
180 ],
181 ],
182 'selectors' => [
183 '{{WRAPPER}} .embedpress-document-embed iframe' => 'width: {{SIZE}}{{UNIT}}; max-width: 100%',
184 '{{WRAPPER}} .embedpress-document-embed' => 'width: {{SIZE}}{{UNIT}}; max-width: 100%',
185 '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%',
186 ],
187 'render_type' => 'template',
188 ]
189 );
190
191 $this->add_control(
192 'embedpress_elementor_document_height',
193 [
194 'label' => __('Height', 'embedpress'),
195 'type' => Controls_Manager::SLIDER,
196 'default' => [
197 'unit' => 'px',
198 'size' => 600,
199 ],
200 'range' => [
201 'px' => [
202 'min' => 6,
203 'max' => 1000,
204 ],
205 ],
206 'selectors' => [
207 '{{WRAPPER}} .embedpress-document-embed iframe' => 'height: {{SIZE}}{{UNIT}};',
208 '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'height: {{SIZE}}{{UNIT}};',
209 ],
210 'render_type' => 'template',
211 ]
212 );
213
214 $this->add_responsive_control(
215 'embedpress_elementor_document_align',
216 [
217 'label' => __('Alignment', 'embedpress'),
218 'type' => Controls_Manager::CHOOSE,
219 'options' => [
220 'left' => [
221 'title' => __('Left', 'embedpress'),
222 'icon' => 'eicon-text-align-left',
223 ],
224 'center' => [
225 'title' => __('Center', 'embedpress'),
226 'icon' => 'eicon-text-align-center',
227 ],
228 'right' => [
229 'title' => __('Right', 'embedpress'),
230 'icon' => 'eicon-text-align-right',
231 ]
232 ],
233 'prefix_class' => 'elementor%s-align-',
234 'default' => '',
235 ]
236 );
237
238 $this->add_control(
239 'embedpress_pdf_powered_by',
240 [
241 'label' => __('Powered By', 'embedpress'),
242 'type' => Controls_Manager::SWITCHER,
243 'label_on' => __('Show', 'embedpress'),
244 'label_off' => __('Hide', 'embedpress'),
245 'return_value' => 'yes',
246 'default' => apply_filters('embedpress_document_powered_by_control', 'yes'),
247 ]
248 );
249
250 $this->init_branding_controls('document');
251
252 $this->end_controls_section();
253
254
255 /**
256 * EmbedPress PDF Control Settings
257 */
258
259 $this->start_controls_section(
260 'embedpress_pdf_content_settings',
261 [
262 'label' => esc_html__('PDF Control Settings', 'embedpress'),
263 'condition' => [
264 'embedpress_pdf_type' => 'file'
265 ],
266 ]
267 );
268
269 $this->add_control(
270 'embedpress_theme_mode',
271 [
272 'label' => __('Theme', 'embedpress'),
273 'type' => Controls_Manager::SELECT,
274 'default' => 'default',
275 'options' => [
276 'default' => __('System Default', 'embedpress'),
277 'dark' => __('Dark', 'embedpress'),
278 'light' => __('Light', 'embedpress'),
279 'custom' => __('Custom', 'embedpress')
280 ],
281 ]
282 );
283
284 $this->add_control(
285 'embedpress_pdf_custom_color',
286 [
287 'label' => esc_html__( 'Color', 'embedpress' ),
288 'type' => \Elementor\Controls_Manager::COLOR,
289 'condition' => [
290 'embedpress_theme_mode' => 'custom',
291 ],
292 ]
293 );
294
295 $this->add_control(
296 'pdf_toolbar',
297 [
298 'label' => sprintf(__('Toolbar %s', 'embedpress'), $this->pro_text),
299 'type' => Controls_Manager::SWITCHER,
300 'label_on' => __('Show', 'embedpress'),
301 'label_off' => __('Hide', 'embedpress'),
302 'return_value' => 'yes',
303 'default' => 'yes',
304 'classes' => $this->pro_class,
305 ]
306 );
307
308
309 $this->add_control(
310 'pdf_toolbar_position',
311 [
312 'label' => esc_html__('Toolbar Position', 'embedpress'),
313 'type' => \Elementor\Controls_Manager::CHOOSE,
314 'options' => [
315 'top' => [
316 'title' => esc_html__('Top', 'embedpress'),
317 'icon' => 'eicon-arrow-up',
318 ],
319 'bottom' => [
320 'title' => esc_html__('Bottom', 'embedpress'),
321 'icon' => 'eicon-arrow-down',
322 ],
323 ],
324 'default' => 'top',
325 'toggle' => true,
326 'condition' => [
327 'pdf_toolbar' => 'yes',
328 ],
329 ]
330 );
331
332
333 $this->add_control(
334 'pdf_presentation_mode',
335 [
336 'label' => __('PDF Presentation Mode', 'embedpress'),
337 'type' => Controls_Manager::SWITCHER,
338 'label_on' => __('Show', 'embedpress'),
339 'label_off' => __('Hide', 'embedpress'),
340 'return_value' => 'yes',
341 'default' => 'yes',
342 'condition' => [
343 'pdf_toolbar' => 'yes',
344 ],
345 ]
346 );
347
348 $this->add_control(
349 'pdf_print_download',
350 [
351 'label' => sprintf(__('Print/Download %s', 'embedpress'), $this->pro_text),
352 'type' => Controls_Manager::SWITCHER,
353 'label_on' => __('Show', 'embedpress'),
354 'label_off' => __('Hide', 'embedpress'),
355 'return_value' => 'yes',
356 'default' => 'yes',
357 'classes' => $this->pro_class,
358 'condition' => [
359 'pdf_toolbar' => 'yes',
360 ],
361 ]
362 );
363 $this->add_control(
364 'pdf_text_copy',
365 [
366 'label' => sprintf(__('Copy Text %s', 'embedpress'), $this->pro_text),
367 'type' => Controls_Manager::SWITCHER,
368 'label_on' => __('Show', 'embedpress'),
369 'label_off' => __('Hide', 'embedpress'),
370 'return_value' => 'yes',
371 'default' => 'yes',
372 'classes' => $this->pro_class,
373 'condition' => [
374 'pdf_toolbar' => 'yes',
375 ],
376 ]
377 );
378
379 $this->add_control(
380 'add_text',
381 [
382 'label' => sprintf(__('Add Text', '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 'pdf_toolbar' => 'yes',
390 ],
391 ]
392 );
393 $this->add_control(
394 'draw',
395 [
396 'label' => sprintf(__('Draw %s', 'embedpress'), $this->pro_text),
397 'type' => Controls_Manager::SWITCHER,
398 'label_on' => __('Show', 'embedpress'),
399 'label_off' => __('Hide', 'embedpress'),
400 'return_value' => 'yes',
401 'default' => 'yes',
402 'classes' => $this->pro_class,
403 'condition' => [
404 'pdf_toolbar' => 'yes',
405 ],
406 ]
407 );
408
409 $this->add_control(
410 'pdf_rotate_access',
411 [
412 'label' => __('Rotation', 'embedpress'),
413 'type' => Controls_Manager::SWITCHER,
414 'label_on' => __('Show', 'embedpress'),
415 'label_off' => __('Hide', 'embedpress'),
416 'return_value' => 'yes',
417 'default' => 'yes',
418 'condition' => [
419 'pdf_toolbar' => 'yes',
420 ],
421 ]
422 );
423
424 $this->add_control(
425 'pdf_details',
426 [
427 'label' => __('Properties', 'embedpress'),
428 'type' => Controls_Manager::SWITCHER,
429 'label_on' => __('Show', 'embedpress'),
430 'label_off' => __('Hide', 'embedpress'),
431 'return_value' => 'yes',
432 'default' => 'yes',
433 'condition' => [
434 'pdf_toolbar' => 'yes',
435 ],
436 ]
437 );
438
439 $this->end_controls_section();
440
441
442 if (!is_embedpress_pro_active()) {
443 $this->start_controls_section(
444 'embedpress_pro_section',
445 [
446 'label' => __('Go Premium for More Features', 'embedpress'),
447 ]
448 );
449
450 $this->add_control(
451 'embedpress_pro_cta',
452 [
453 'label' => __('Unlock more possibilities', 'embedpress'),
454 'type' => Controls_Manager::CHOOSE,
455 'options' => [
456 '1' => [
457 'title' => '',
458 'icon' => 'eicon-lock',
459 ],
460 ],
461 'default' => '1',
462 '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>',
463 ]
464 );
465
466 $this->end_controls_section();
467 }
468 }
469
470 private function is_pdf($url)
471 {
472 $arr = explode('.', $url);
473 return end($arr) === 'pdf';
474 }
475
476 protected function render()
477 {
478 $settings = $this->get_settings();
479 $url = $this->get_file_url();
480 $id = $this->get_id();
481 $this->_render($url, $settings, $id);
482
483 }
484
485 public function getParamData($settings){
486 $urlParamData = array(
487 'themeMode' => $settings['embedpress_theme_mode'],
488 'toolbar' => !empty($settings['pdf_toolbar']) ? 'true' : 'false',
489 'position' => $settings['pdf_toolbar_position'],
490 'presentation' => !empty($settings['pdf_presentation_mode']) ? 'true' : 'false',
491 'download' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['pdf_print_download'] : 'true',
492 'copy_text' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['pdf_text_copy'] : 'true',
493 'add_text' => !empty($settings['add_text']) ? 'true' : 'false',
494 'draw' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['draw'] : 'true',
495 'doc_rotation' => !empty($settings['pdf_rotate_access']) ? 'true' : 'false',
496 'doc_details' => !empty($settings['pdf_details']) ? 'true' : 'false',
497 );
498
499 if($settings['embedpress_theme_mode'] == 'custom') {
500 $urlParamData['customColor'] = $settings['embedpress_pdf_custom_color'];
501 }
502
503 if($settings['embedpress_pdf_type'] == 'file'){
504 return "#" .http_build_query($urlParamData) ;
505 }
506 return '';
507
508 }
509
510 public function _render($url, $settings, $id)
511 {
512 $unitoption = 'emebedpress-unit-px';
513 if($settings['embedpress_elementor_document_width']['unit'] === '%'){
514 $unitoption = 'emebedpress-unit-percent';
515 }
516 $id = 'embedpress-pdf-' . $id;
517 $dimension = "width: {$settings['embedpress_elementor_document_width']['size']}{$settings['embedpress_elementor_document_width']['unit']};height: {$settings['embedpress_elementor_document_height']['size']}px";
518 $this->add_render_attribute('embedpres-pdf-render', [
519 'class' => ['embedpress-embed-document-pdf', $id],
520 'data-emid' => $id
521 ]);
522 $this->add_render_attribute('embedpress-document', [
523 'class' => ['embedpress-document-embed', 'ep-doc-' . md5($id), 'ose-document', $unitoption ],
524 'data-thememode' => $settings['embedpress_theme_mode'],
525 'data-customcolor' => $settings['embedpress_pdf_custom_color'],
526 'data-toolbar' => $settings['pdf_toolbar'],
527 'data-toolbar-position' => $settings['pdf_toolbar_position'],
528 'data-open' => 'no',
529 'data-presentation-mode' => $settings['pdf_presentation_mode'],
530 'data-download' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['pdf_print_download'] : 'yes',
531 'data-copy' => defined('EMBEDPRESS_PRO_PLUGIN_VERSION')? $settings['pdf_text_copy'] : 'yes',
532 'data-rotate' => $settings['pdf_rotate_access'],
533 'data-details' => $settings['pdf_details'],
534 'data-id' => $id
535 ]);
536 ?>
537 <div <?php echo $this->get_render_attribute_string('embedpress-document'); ?> style="<?php echo esc_attr($dimension); ?>; max-width:100%; display: inline-block">
538 <?php
539 do_action('embedpress_pdf_after_embed', $settings, $url, $id, $this);
540 ?>
541 <?php if ($url != '') {
542 if ($this->is_pdf($url) && !$this->is_external_url($url)) {
543 $this->add_render_attribute('embedpres-pdf-render', 'data-emsrc', $url);
544 $renderer = Helper::get_pdf_renderer();
545 $src = $renderer . ((strpos($renderer, '?') == false) ? '?' : '&') . 'file=' . $url.$this->getParamData($settings);
546 if (!empty($settings['embedpress_pdf_zoom'])) {
547 $zoom = $settings['embedpress_pdf_zoom'];
548 if ($zoom == 'custom') {
549 if (!empty($settings['embedpress_pdf_zoom_custom'])) {
550 $zoom = $settings['embedpress_pdf_zoom_custom'];
551 } else {
552 $zoom = null;
553 }
554 }
555 if ($zoom) {
556 $src = $src . "&zoom=$zoom";
557 }
558 }
559 ?>
560 <iframe title="<?php echo esc_attr(Helper::get_file_title($url)); ?>" class="embedpress-embed-document-pdf <?php echo esc_attr($id); ?>" style="<?php echo esc_attr($dimension); ?>; max-width:100%; display: inline-block" src="<?php echo esc_attr($src); ?>" <?php $this->get_render_attribute_string('embedpres-pdf-render'); ?> frameborder="0"></iframe>
561 <?php
562
563 } else {
564 ?>
565 <div>
566 <iframe title="<?php echo esc_attr(Helper::get_file_title($url)); ?>" class="embedpress-embed-document-pdf <?php echo esc_attr($id); ?>" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" style="<?php echo esc_attr($dimension); ?>; max-width:100%;" src="<?php echo esc_url($url); ?>" <?php $this->get_render_attribute_string('embedpres-pdf-render'); ?>></iframe>
567 </div>
568
569 <?php
570 }
571 if ($settings['embedpress_pdf_powered_by'] === 'yes') {
572
573 printf('<p class="embedpress-el-powered">%s</p>', __('Powered By EmbedPress', 'embedpress'));
574 }
575 }
576 ?>
577 </div>
578
579 <?php
580 }
581
582 private function get_file_url()
583 {
584 $settings = $this->get_settings();
585 return $settings['embedpress_pdf_type'] === 'url' ? $settings['embedpress_pdf_file_link']['url'] : $settings['embedpress_pdf_Uploader']['url'];
586 }
587
588 protected function is_external_url($url)
589 {
590 return strpos($url, get_site_url()) === false;
591 }
592 }
593