PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 3.7.1
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v3.7.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 3 years ago Embedpress_Document.php 3 years ago Embedpress_Elementor.php 3 years ago Embedpress_Pdf.php 3 years ago
Embedpress_Document.php
427 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__( 'Content Settings', '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
87 $this->add_control(
88 'embedpress_document_Uploader',
89 [
90
91 'label' => __( 'Upload File', 'embedpress' ),
92 'type' => Controls_Manager::MEDIA,
93 'dynamic' => [
94 'active' => true,
95 'categories' => [
96 TagsModule::MEDIA_CATEGORY,
97 ],
98 ],
99 'media_type' => [
100 'application/pdf',
101 'application/msword',
102 'application/vnd.ms-powerpoint',
103 'application/vnd.ms-excel',
104 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
105 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
106 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
107 ],
108 'description' => __( 'Upload a file or pick one from your media library for embed. Supported File Type: PDF, DOC/DOCX, PPT/PPTX, XLS/XLSX etc.',
109 'embedpress' ),
110 'condition' => [
111 'embedpress_document_type' => 'file'
112 ],
113 ]
114 );
115
116 $this->add_control(
117 'embedpress_document_file_link',
118 [
119 'label' => __( 'URL', 'embedpress' ),
120 'type' => Controls_Manager::URL,
121 'placeholder' => __( 'https://your-link.com/file.pdf', 'embedpress' ),
122 'show_external' => false,
123 'default' => [
124 'url' => ''
125 ],
126 'condition' => [
127 'embedpress_document_type' => 'url'
128 ],
129 ]
130 );
131
132 $this->add_control(
133 'embedpress_elementor_document_width',
134 [
135 'label' => __( 'Width', 'embedpress' ),
136 'type' => Controls_Manager::SLIDER,
137 'separator' => 'before',
138 'default' => [
139 'unit' => 'px',
140 'size' => 600,
141 ],
142 'range' => [
143 'px' => [
144 'min' => 6,
145 'max' => 1000,
146 ],
147 ],
148 'selectors' => [
149 '{{WRAPPER}} .embedpress-document-embed iframe' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%',
150 '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%',
151 '{{WRAPPER}} .embedpress-document-embed' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%',
152 ],
153 ]
154 );
155
156 $this->add_control(
157 'embedpress_elementor_document_height',
158 [
159 'label' => __( 'Height', 'embedpress' ),
160 'type' => Controls_Manager::SLIDER,
161 'default' => [
162 'unit' => 'px',
163 'size' => 600,
164 ],
165 'range' => [
166 'px' => [
167 'min' => 6,
168 'max' => 1000,
169 ],
170 ],
171 'selectors' => [
172 '{{WRAPPER}} .embedpress-document-embed iframe' => 'height: {{SIZE}}{{UNIT}}!important;',
173 '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'height: {{SIZE}}{{UNIT}};',
174 ],
175 ]
176 );
177
178 $this->add_responsive_control(
179 'embedpress_elementor_document_align',
180 [
181 'label' => __( 'Alignment', 'embedpress' ),
182 'type' => Controls_Manager::CHOOSE,
183 'options' => [
184 'left' => [
185 'title' => __( 'Left', 'embedpress' ),
186 'icon' => 'eicon-text-align-left',
187 ],
188 'center' => [
189 'title' => __( 'Center', 'embedpress' ),
190 'icon' => 'eicon-text-align-center',
191 ],
192 'right' => [
193 'title' => __( 'Right', 'embedpress' ),
194 'icon' => 'eicon-text-align-right',
195 ]
196 ],
197 'prefix_class' => 'elementor%s-align-',
198 'default' => '',
199 ]
200 );
201
202 $this->add_control(
203 'embedpress_document_powered_by',
204 [
205 'label' => __( 'Powered By', 'embedpress' ),
206 'type' => Controls_Manager::SWITCHER,
207 'label_on' => __( 'Show', 'embedpress' ),
208 'label_off' => __( 'Hide', 'embedpress' ),
209 'return_value' => 'yes',
210 'default' => apply_filters( 'embedpress_document_powered_by_control', 'yes' ),
211 ]
212 );
213
214 $this->init_branding_controls( 'document');
215
216 $this->end_controls_section();
217
218 do_action( 'extend_elementor_controls', $this, '_doc_', $this->pro_text, $this->pro_class);
219
220 if (! is_embedpress_pro_active()) {
221 $this->start_controls_section(
222 'embedpress_pro_section',
223 [
224 'label' => __('Go Premium for More Features', 'embedpress'),
225 ]
226 );
227
228 $this->add_control(
229 'embedpress_pro_cta',
230 [
231 'label' => __('Unlock more possibilities', 'embedpress'),
232 'type' => Controls_Manager::CHOOSE,
233 'options' => [
234 '1' => [
235 'title' => '',
236 'icon' => 'eicon-lock',
237 ],
238 ],
239 'default' => '1',
240 '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>',
241 ]
242 );
243
244 $this->end_controls_section();
245 }
246 }
247
248 private function is_pdf( $url )
249 {
250 $arr = explode( '.', $url );
251 return end( $arr ) === 'pdf';
252 }
253
254 protected function render()
255 {
256 $settings = $this->get_settings();
257 $client_id = $this->get_id();
258 $pass_hash_key = md5($settings['embedpress_doc_lock_content_password']);
259 $url = $this->get_file_url();
260 $id = 'embedpress-pdf-' . $this->get_id();
261
262 $hash_pass = hash('sha256', wp_salt(32) . md5($settings['embedpress_doc_lock_content_password']));
263
264 $dimension = '';
265 if(empty($settings['embedpress_doc_lock_content']) && empty($settings['embedpress_doc_lock_content_password'])){
266 $dimension = "width: {$settings['embedpress_elementor_document_width']['size']}px;height: {$settings['embedpress_elementor_document_height']['size']}px";
267 }
268
269 $content_locked_class = '';
270 if(!empty($settings['embedpress_doc_lock_content']) && !empty($settings['embedpress_doc_lock_content_password'])){
271 $content_locked_class = 'ep-content-locked';
272 }
273
274
275 $this->add_render_attribute( 'embedpres-pdf-render', [
276 'class' => ['embedpress-embed-document-pdf', $id],
277 'data-emid' => $id
278 ] );
279
280 Helper::get_source_data(md5($this->get_id()).'_eb_elementor', $url, 'elementor_source_data', 'elementor_temp_source_data');
281
282 $this->add_render_attribute( 'embedpress-document', [
283 'class' => ['embedpress-document-embed', 'ep-doc-'.md5( $id), 'ose-document', $content_locked_class]
284 ] );
285
286 $embed_settings = [];
287 $embed_settings['customThumbnail'] = !empty($settings['embedpress_doc_content_share_custom_thumbnail']['url']) ? $settings['embedpress_doc_content_share_custom_thumbnail']['url'] : '';
288
289 $embed_settings['customTitle'] = !empty($settings['embedpress_doc_content_title']) ? $settings['embedpress_doc_content_title'] : Helper::get_file_title($url);
290
291 $embed_settings['customDescription'] = !empty($settings['embedpress_doc_content_descripiton']) ? $settings['embedpress_doc_content_descripiton'] : Helper::get_file_title($url);
292
293 $embed_settings['sharePosition'] = !empty($settings['embedpress_doc_content_share_position']) ? $settings['embedpress_doc_content_share_position'] : 'right';
294
295 $embed_settings['lockHeading'] = !empty($settings['embedpress_doc_lock_content_heading']) ? $settings['embedpress_doc_lock_content_heading'] : '';
296
297 $embed_settings['lockSubHeading'] = !empty($settings['embedpress_doc_lock_content_sub_heading']) ? $settings['embedpress_doc_lock_content_sub_heading'] : '';
298
299 $embed_settings['lockErrorMessage'] = !empty($settings['embedpress_doc_lock_content_error_message']) ? $settings['embedpress_doc_lock_content_error_message'] : '';
300
301
302 $embed_settings['passwordPlaceholder'] = !empty($settings['embedpress_doc_password_placeholder']) ? $settings['embedpress_doc_password_placeholder'] : '';
303
304 $embed_settings['submitButtonText'] = !empty($settings['embedpress_doc_submit_button_text']) ? $settings['embedpress_doc_submit_button_text'] : '';
305
306 $embed_settings['submitUnlockingText'] = !empty($settings['embedpress_doc_submit_Unlocking_text']) ? $settings['embedpress_doc_submit_Unlocking_text'] : '';
307
308
309 $embed_settings['enableFooterMessage'] = !empty($settings['embedpress_doc_enable_footer_message']) ? $settings['embedpress_doc_enable_footer_message'] : '';
310
311 $embed_settings['footerMessage'] = !empty($settings['embedpress_doc_lock_content_footer_message']) ? $settings['embedpress_doc_lock_content_footer_message'] : '';
312
313
314 $content_share_class = '';
315 $share_position_class = '';
316 $share_position = isset($settings['embedpress_doc_content_share_position']) ? $settings['embedpress_doc_content_share_position'] : 'right';
317
318 if(!empty($settings['embedpress_doc_content_share'])) {
319 $content_share_class = 'ep-content-share-enabled';
320 $share_position_class = 'ep-share-position-'.$share_position;
321 }
322
323 $password_correct = isset($_COOKIE['password_correct_'.$client_id]) ? $_COOKIE['password_correct_'.$client_id] : '';
324
325 $content_protection_class = 'ep-content-protection-enabled';
326 if(empty($settings['embedpress_doc_lock_content']) || empty($settings['embedpress_doc_lock_content_password']) || $hash_pass === $password_correct) {
327 $content_protection_class = 'ep-content-protection-disabled';
328 }
329
330 ?>
331
332
333 <div <?php echo $this->get_render_attribute_string('embedpress-document'); ?> style="<?php echo esc_attr($dimension); ?>; max-width:100%; display: inline-block">
334
335 <?php
336
337 do_action( 'embedpress_document_after_embed', $settings, $url, $id, $this);
338
339 if ( $url != '' ) {
340 if ( $this->is_pdf( $url ) ) {
341 $this->add_render_attribute( 'embedpres-pdf-render', 'data-emsrc', $url );
342 $embed_content = '<div ' . $this->get_render_attribute_string( 'embedpres-pdf-render' ) . '>';
343
344 $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>';
345
346 if ( $settings[ 'embedpress_document_powered_by' ] === 'yes' ) {
347 $embed_content .= sprintf( '<p class="embedpress-el-powered">%s</p>', __( 'Powered By EmbedPress', 'embedpress' ) );
348 }
349 $embed_content .= '</div>';
350
351 if ( Plugin::$instance->editor->is_edit_mode() ) {
352 $embed_content .= $this->render_editor_script( $id, $url );
353 }
354
355 } else {
356 $view_link = '//view.officeapps.live.com/op/embed.aspx?src=' . $url . '&embedded=true';
357
358 $hostname = parse_url($url, PHP_URL_HOST);
359 $domain = implode(".", array_slice(explode(".", $hostname), -2));
360
361 if ($domain == "google.com") {
362 $view_link = $url.'?embedded=true';
363 }
364
365 $embed_content = '<div ' . $this->get_render_attribute_string( 'embedpres-pdf-render' ) . '><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 ) . '"></iframe>';
366
367 if ( $settings[ 'embedpress_document_powered_by' ] === 'yes' ) {
368 $embed_content .= sprintf( '<p class="embedpress-el-powered">%s</p>', __( 'Powered By EmbedPress', 'embedpress' ) );
369 }
370 $embed_content .='</div>';
371 }
372 }
373
374
375 ?>
376 <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); ?>">
377 <div id="<?php echo esc_attr( $this->get_id() ); ?>" class="ep-embed-content-wraper">
378 <?php
379
380 $content_id = $client_id;
381 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]))) {
382
383 if(!empty($settings['embedpress_doc_content_share'])){
384 $embed_content .= Helper::embed_content_share($content_id, $embed_settings);
385 }
386 echo $embed_content;
387 } else {
388 if(!empty($settings['embedpress_doc_content_share'])){
389 $embed_content .= Helper::embed_content_share($content_id, $embed_settings);
390 }
391 Helper::display_password_form($client_id, $embed_content, $pass_hash_key, $embed_settings);
392 }
393 ?>
394 </div>
395 </div>
396 </div>
397
398 <?php
399 }
400
401 private function get_file_url()
402 {
403 $settings = $this->get_settings();
404 return $settings[ 'embedpress_document_type' ] === 'url' ? $settings[ 'embedpress_document_file_link' ][ 'url' ] : $settings[ 'embedpress_document_Uploader' ][ 'url' ];
405 }
406
407 protected function render_editor_script( $id, $url )
408 {
409 ?>
410 <script>
411 (function ($) {
412 'use strict';
413 $(document).ready(function () {
414 var selector = $('.embedpress-embed-document-pdf');
415 let option = {
416 forceObject: false,
417 };
418 if (selector.length) {
419 PDFObject.embed("<?php echo $url; ?>", "<?php echo '.' . $id; ?>", option);
420 }
421 });
422 })(jQuery);
423 </script>
424 <?php
425 }
426 }
427