PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more / 3.3.0
EmbedPress – PDF Embedder, Embed PDF viewer, YouTube Videos, 3D FlipBook, Social feeds & more v3.3.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 4 years ago Embedpress_Document.php 4 years ago Embedpress_Elementor.php 4 years ago Embedpress_Pdf.php 4 years ago
Embedpress_Document.php
326 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
12 ( defined( 'ABSPATH' ) ) or die( "No direct script access allowed." );
13
14 class Embedpress_Document extends Widget_Base
15 {
16 use Branding;
17 protected $pro_class = '';
18 protected $pro_text = '';
19 public function get_name()
20 {
21 return 'embedpres_document';
22 }
23
24 public function get_title()
25 {
26 return esc_html__( 'EmbedPress Document', 'embedpress' );
27 }
28
29 public function get_categories()
30 {
31 return ['embedpress'];
32 }
33
34 public function get_custom_help_url()
35 {
36 return 'https://embedpress.com/documentation';
37 }
38
39 public function get_icon()
40 {
41 return 'icon-document';
42 }
43
44 /**
45 * Get widget keywords.
46 *
47 * Retrieve the list of keywords the widget belongs to.
48 *
49 * @return array Widget keywords.
50 * @since 2.5.5
51 * @access public
52 *
53 */
54 public function get_keywords()
55 {
56 return ['embedpress', 'pdf', 'doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'embedpress-document'];
57 }
58
59 protected function _register_controls()
60 {
61 $this->pro_class = is_embedpress_pro_active() ? '': 'embedpress-pro-control';
62 $this->pro_text = is_embedpress_pro_active() ? '': '<sup class="embedpress-pro-label" style="color:red">'.__('Pro', 'embedpress').'</sup>';
63 /**
64 * EmbedPress Content Settings
65 */
66 $this->start_controls_section(
67 'embedpress_document_content_settings',
68 [
69 'label' => esc_html__( 'Content Settings', 'embedpress' ),
70 ]
71 );
72
73 $this->add_control(
74 'embedpress_document_type',
75 [
76 'label' => __( 'Document Type', 'embedpress' ),
77 'type' => Controls_Manager::SELECT,
78 'default' => 'file',
79 'options' => [
80 'file' => __( 'File', 'embedpress' ),
81 'url' => __( 'URL', 'embedpress' )
82 ],
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 ],
107 'description' => __( 'Upload a file or pick one from your media library for embed. Supported File Type: PDF, DOC/DOCX, PPT/PPTX, XLS/XLSX etc.',
108 'embedpress' ),
109 'condition' => [
110 'embedpress_document_type' => 'file'
111 ],
112 ]
113 );
114
115 $this->add_control(
116 'embedpress_document_file_link',
117 [
118 'label' => __( 'URL', 'embedpress' ),
119 'type' => Controls_Manager::URL,
120 'placeholder' => __( 'https://your-link.com/file.pdf', 'embedpress' ),
121 'show_external' => false,
122 'default' => [
123 'url' => ''
124 ],
125 'condition' => [
126 'embedpress_document_type' => 'url'
127 ],
128 ]
129 );
130
131 $this->add_control(
132 'embedpress_elementor_document_width',
133 [
134 'label' => __( 'Width', 'embedpress' ),
135 'type' => Controls_Manager::SLIDER,
136 'separator' => 'before',
137 'default' => [
138 'unit' => 'px',
139 'size' => 600,
140 ],
141 'range' => [
142 'px' => [
143 'min' => 6,
144 'max' => 1000,
145 ],
146 ],
147 'selectors' => [
148 '{{WRAPPER}} .embedpress-document-embed iframe' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%',
149 '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%',
150 ],
151 ]
152 );
153
154 $this->add_control(
155 'embedpress_elementor_document_height',
156 [
157 'label' => __( 'Height', 'embedpress' ),
158 'type' => Controls_Manager::SLIDER,
159 'default' => [
160 'unit' => 'px',
161 'size' => 600,
162 ],
163 'range' => [
164 'px' => [
165 'min' => 6,
166 'max' => 1000,
167 ],
168 ],
169 'selectors' => [
170 '{{WRAPPER}}' => 'height: {{SIZE}}{{UNIT}};',
171 '{{WRAPPER}} .embedpress-document-embed iframe' => 'height: {{SIZE}}{{UNIT}};',
172 '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'height: {{SIZE}}{{UNIT}};',
173 ],
174 ]
175 );
176
177 $this->add_responsive_control(
178 'embedpress_elementor_document_align',
179 [
180 'label' => __( 'Alignment', 'embedpress' ),
181 'type' => Controls_Manager::CHOOSE,
182 'options' => [
183 'left' => [
184 'title' => __( 'Left', 'embedpress' ),
185 'icon' => 'eicon-text-align-left',
186 ],
187 'center' => [
188 'title' => __( 'Center', 'embedpress' ),
189 'icon' => 'eicon-text-align-center',
190 ],
191 'right' => [
192 'title' => __( 'Right', 'embedpress' ),
193 'icon' => 'eicon-text-align-right',
194 ]
195 ],
196 'prefix_class' => 'elementor%s-align-',
197 'default' => '',
198 ]
199 );
200
201 $this->add_control(
202 'embedpress_document_powered_by',
203 [
204 'label' => __( 'Powered By', 'embedpress' ),
205 'type' => Controls_Manager::SWITCHER,
206 'label_on' => __( 'Show', 'embedpress' ),
207 'label_off' => __( 'Hide', 'embedpress' ),
208 'return_value' => 'yes',
209 'default' => apply_filters( 'embedpress_document_powered_by_control', 'yes' ),
210 ]
211 );
212
213 $this->init_branding_controls( 'document');
214
215 $this->end_controls_section();
216
217 if (! is_embedpress_pro_active()) {
218 $this->start_controls_section(
219 'embedpress_pro_section',
220 [
221 'label' => __('Go Premium for More Features', 'embedpress'),
222 ]
223 );
224
225 $this->add_control(
226 'embedpress_pro_cta',
227 [
228 'label' => __('Unlock more possibilities', 'embedpress'),
229 'type' => Controls_Manager::CHOOSE,
230 'options' => [
231 '1' => [
232 'title' => '',
233 'icon' => 'eicon-lock',
234 ],
235 ],
236 'default' => '1',
237 '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>',
238 ]
239 );
240
241 $this->end_controls_section();
242 }
243 }
244
245 private function is_pdf( $url )
246 {
247 $arr = explode( '.', $url );
248 return end( $arr ) === 'pdf';
249 }
250
251 protected function render()
252 {
253 $settings = $this->get_settings();
254 $url = $this->get_file_url();
255 $id = 'embedpress-pdf-' . $this->get_id();
256 $dimension = "width: {$settings['embedpress_elementor_document_width']['size']}px;height: {$settings['embedpress_elementor_document_height']['size']}px";
257 $this->add_render_attribute( 'embedpres-pdf-render', [
258 'class' => ['embedpress-embed-document-pdf', $id],
259 'data-emid' => $id
260 ] );
261 $this->add_render_attribute( 'embedpress-document', [
262 'class' => ['embedpress-document-embed', 'ep-doc-'.md5( $id), 'ose-document']
263 ] );
264 ?>
265 <div <?php echo $this->get_render_attribute_string( 'embedpress-document' ); ?> style="<?php echo esc_attr( $dimension); ?>; max-width:100%; display: inline-block">
266 <?php
267 do_action( 'embedpress_document_after_embed', $settings, $url, $id, $this);
268 ?>
269 <?php if ( $url != '' ) {
270 if ( $this->is_pdf( $url ) ) {
271 $this->add_render_attribute( 'embedpres-pdf-render', 'data-emsrc', $url );
272 ?>
273 <div <?php echo $this->get_render_attribute_string( 'embedpres-pdf-render' ); ?>>
274 </div>
275 <?php
276
277 if ( Plugin::$instance->editor->is_edit_mode() ) {
278 $this->render_editor_script( $id, $url );
279 }
280
281 } else {
282 $view_link = 'https://docs.google.com/viewer?url=' . $url . '&embedded=true';
283 ?>
284 <div>
285 <iframe allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" style="<?php echo esc_attr( $dimension); ?>; max-width:100%;" src="<?php echo esc_url( $view_link); ?>"></iframe>
286 </div>
287
288 <?php
289 }
290 if ( $settings[ 'embedpress_document_powered_by' ] === 'yes' ) {
291 printf( '<p class="embedpress-el-powered">%s</p>', __( 'Powered By EmbedPress', 'embedpress' ) );
292 }
293 }
294 ?>
295 </div>
296
297 <?php
298 }
299
300 private function get_file_url()
301 {
302 $settings = $this->get_settings();
303 return $settings[ 'embedpress_document_type' ] === 'url' ? $settings[ 'embedpress_document_file_link' ][ 'url' ] : $settings[ 'embedpress_document_Uploader' ][ 'url' ];
304 }
305
306 protected function render_editor_script( $id, $url )
307 {
308 ?>
309 <script>
310 (function ($) {
311 'use strict';
312 $(document).ready(function () {
313 var selector = $('.embedpress-embed-document-pdf');
314 let option = {
315 forceObject: false,
316 };
317 if (selector.length) {
318 PDFObject.embed("<?php echo $url; ?>", "<?php echo '.' . $id; ?>", option);
319 }
320 });
321 })(jQuery);
322 </script>
323 <?php
324 }
325 }
326