PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 3.5.1
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v3.5.1
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_Pdf.php
embedpress / EmbedPress / Elementor / Widgets Last commit date
Embedpress_Calendar.php 4 years ago Embedpress_Document.php 3 years ago Embedpress_Elementor.php 4 years ago Embedpress_Pdf.php 4 years ago
Embedpress_Pdf.php
357 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 use Branding;
17 protected $pro_class = '';
18 protected $pro_text = '';
19 public function get_name()
20 {
21 return 'embedpress_pdf';
22 }
23
24 public function get_title()
25 {
26 return esc_html__( 'EmbedPress PDF', '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-pdf';
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', '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_pdf_content_settings',
68 [
69 'label' => esc_html__( 'Content Settings', 'embedpress' ),
70 ]
71 );
72
73 $this->add_control(
74 'embedpress_pdf_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_pdf_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 ],
101 'description' => __( 'Upload a file or pick one from your media library for embed. Supported File Type: PDF',
102 'embedpress' ),
103 'condition' => [
104 'embedpress_pdf_type' => 'file'
105 ],
106 ]
107 );
108
109 $this->add_control(
110 'embedpress_pdf_file_link',
111 [
112 'label' => __( 'URL', 'embedpress' ),
113 'type' => Controls_Manager::URL,
114 'placeholder' => __( 'https://your-link.com/file.pdf', 'embedpress' ),
115 'show_external' => false,
116 'default' => [
117 'url' => ''
118 ],
119 'condition' => [
120 'embedpress_pdf_type' => 'url'
121 ],
122 ]
123 );
124
125 $this->add_control(
126 'embedpress_pdf_zoom',
127 [
128 'label' => __( 'Zoom', 'embedpress' ),
129 'type' => Controls_Manager::SELECT,
130 'default' => 'auto',
131 'options' => [
132 'auto' => __( 'Automatic Zoom', 'embedpress' ),
133 'page-actual' => __( 'Actual Size', 'embedpress' ),
134 'page-fit' => __( 'Page Fit', 'embedpress' ),
135 'page-width' => __( 'Page Width', 'embedpress' ),
136 'custom' => __( 'Custom', 'embedpress' ),
137 '50' => __( '50%', 'embedpress' ),
138 '75' => __( '75%', 'embedpress' ),
139 '100' => __( '100%', 'embedpress' ),
140 '125' => __( '125%', 'embedpress' ),
141 '150' => __( '150%', 'embedpress' ),
142 '200' => __( '200%', 'embedpress' ),
143 '300' => __( '300%', 'embedpress' ),
144 '400' => __( '400%', 'embedpress' ),
145 ],
146 ]
147 );
148 $this->add_control(
149 'embedpress_pdf_zoom_custom',
150 [
151 'label' => __( 'Custom Zoom', 'embedpress' ),
152 'type' => Controls_Manager::NUMBER,
153 'condition' => [
154 'embedpress_pdf_zoom' => 'custom'
155 ],
156 ]
157 );
158
159 $this->add_control(
160 'embedpress_elementor_document_width',
161 [
162 'label' => __( 'Width', 'embedpress' ),
163 'type' => Controls_Manager::SLIDER,
164 'separator' => 'before',
165 'default' => [
166 'unit' => 'px',
167 'size' => 600,
168 ],
169 'range' => [
170 'px' => [
171 'min' => 6,
172 'max' => 1000,
173 ],
174 ],
175 'selectors' => [
176 '{{WRAPPER}} .embedpress-document-embed iframe' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%',
177 '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'width: {{SIZE}}{{UNIT}} !important; max-width: 100%',
178 ],
179 'render_type' => 'template',
180 ]
181 );
182
183 $this->add_control(
184 'embedpress_elementor_document_height',
185 [
186 'label' => __( 'Height', 'embedpress' ),
187 'type' => Controls_Manager::SLIDER,
188 'default' => [
189 'unit' => 'px',
190 'size' => 600,
191 ],
192 'range' => [
193 'px' => [
194 'min' => 6,
195 'max' => 1000,
196 ],
197 ],
198 'selectors' => [
199 '{{WRAPPER}} .embedpress-document-embed iframe' => 'height: {{SIZE}}{{UNIT}};',
200 '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'height: {{SIZE}}{{UNIT}};',
201 ],
202 'render_type' => 'template',
203 ]
204 );
205
206 $this->add_responsive_control(
207 'embedpress_elementor_document_align',
208 [
209 'label' => __( 'Alignment', 'embedpress' ),
210 'type' => Controls_Manager::CHOOSE,
211 'options' => [
212 'left' => [
213 'title' => __( 'Left', 'embedpress' ),
214 'icon' => 'eicon-text-align-left',
215 ],
216 'center' => [
217 'title' => __( 'Center', 'embedpress' ),
218 'icon' => 'eicon-text-align-center',
219 ],
220 'right' => [
221 'title' => __( 'Right', 'embedpress' ),
222 'icon' => 'eicon-text-align-right',
223 ]
224 ],
225 'prefix_class' => 'elementor%s-align-',
226 'default' => '',
227 ]
228 );
229
230 $this->add_control(
231 'embedpress_pdf_powered_by',
232 [
233 'label' => __( 'Powered By', 'embedpress' ),
234 'type' => Controls_Manager::SWITCHER,
235 'label_on' => __( 'Show', 'embedpress' ),
236 'label_off' => __( 'Hide', 'embedpress' ),
237 'return_value' => 'yes',
238 'default' => apply_filters( 'embedpress_document_powered_by_control', 'yes' ),
239 ]
240 );
241
242 $this->init_branding_controls( 'document');
243
244 $this->end_controls_section();
245
246 if (! is_embedpress_pro_active()) {
247 $this->start_controls_section(
248 'embedpress_pro_section',
249 [
250 'label' => __('Go Premium for More Features', 'embedpress'),
251 ]
252 );
253
254 $this->add_control(
255 'embedpress_pro_cta',
256 [
257 'label' => __('Unlock more possibilities', 'embedpress'),
258 'type' => Controls_Manager::CHOOSE,
259 'options' => [
260 '1' => [
261 'title' => '',
262 'icon' => 'eicon-lock',
263 ],
264 ],
265 'default' => '1',
266 '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>',
267 ]
268 );
269
270 $this->end_controls_section();
271 }
272 }
273
274 private function is_pdf( $url )
275 {
276 $arr = explode( '.', $url );
277 return end( $arr ) === 'pdf';
278 }
279
280 protected function render()
281 {
282 $settings = $this->get_settings();
283 $url = $this->get_file_url();
284 $id = $this->get_id();
285 $this->_render($url, $settings, $id);
286 }
287
288 public function _render($url, $settings, $id)
289 {
290 $id = 'embedpress-pdf-' . $id;
291 $dimension = "width: {$settings['embedpress_elementor_document_width']['size']}px;height: {$settings['embedpress_elementor_document_height']['size']}px";
292 $this->add_render_attribute( 'embedpres-pdf-render', [
293 'class' => ['embedpress-embed-document-pdf', $id],
294 'data-emid' => $id
295 ] );
296 $this->add_render_attribute( 'embedpress-document', [
297 'class' => ['embedpress-document-embed', 'ep-doc-'.md5( $id), 'ose-document']
298 ] );
299 ?>
300 <div <?php echo $this->get_render_attribute_string( 'embedpress-document' ); ?> style="<?php echo esc_attr( $dimension); ?>; max-width:100%; display: inline-block">
301 <?php
302 do_action( 'embedpress_pdf_after_embed', $settings, $url, $id, $this);
303 ?>
304 <?php if ( $url != '' ) {
305 if ( $this->is_pdf( $url ) && ! $this->is_external_url( $url) ) {
306 $this->add_render_attribute( 'embedpres-pdf-render', 'data-emsrc', $url );
307 $renderer = Helper::get_pdf_renderer();
308 $src = $renderer . ((strpos($renderer, '?') == false) ? '?' : '&') . 'file=' . $url;
309 if(!empty($settings['embedpress_pdf_zoom'])){
310 $zoom = $settings['embedpress_pdf_zoom'];
311 if($zoom == 'custom'){
312 if(!empty($settings['embedpress_pdf_zoom_custom'])){
313 $zoom = $settings['embedpress_pdf_zoom_custom'];
314 }
315 else{
316 $zoom = null;
317 }
318 }
319 if($zoom){
320 $src = $src . "#zoom=$zoom";
321 }
322 }
323 ?>
324 <iframe 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' ); ?>
325 frameborder="0"></iframe>
326 <?php
327
328 } else {
329 ?>
330 <div>
331 <iframe 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>
332 </div>
333
334 <?php
335 }
336 if ( $settings[ 'embedpress_pdf_powered_by' ] === 'yes' ) {
337
338 printf( '<p class="embedpress-el-powered">%s</p>', __( 'Powered By EmbedPress', 'embedpress' ) );
339 }
340 }
341 ?>
342 </div>
343
344 <?php
345 }
346
347 private function get_file_url()
348 {
349 $settings = $this->get_settings();
350 return $settings[ 'embedpress_pdf_type' ] === 'url' ? $settings[ 'embedpress_pdf_file_link' ][ 'url' ] : $settings[ 'embedpress_pdf_Uploader' ][ 'url' ];
351 }
352
353 protected function is_external_url( $url ) {
354 return strpos( $url, get_site_url()) === false;
355 }
356 }
357