PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 2.7.4
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v2.7.4
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_Document.php 5 years ago Embedpress_Elementor.php 5 years ago
Embedpress_Document.php
284 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
11 ( defined( 'ABSPATH' ) ) or die( "No direct script access allowed." );
12
13 class Embedpress_Document extends Widget_Base
14 {
15
16 public function get_name()
17 {
18 return 'embedpres_document';
19 }
20
21 public function get_title()
22 {
23 return esc_html__( 'EmbedPress Document', 'embedoress' );
24 }
25
26 public function get_categories()
27 {
28 return ['embedpress'];
29 }
30
31 public function get_custom_help_url()
32 {
33 return 'https://embedpress.com/documentation';
34 }
35
36 public function get_icon()
37 {
38 return 'icon-pdf';
39 }
40
41 /**
42 * Get widget keywords.
43 *
44 * Retrieve the list of keywords the widget belongs to.
45 *
46 * @return array Widget keywords.
47 * @since 2.5.5
48 * @access public
49 *
50 */
51 public function get_keywords()
52 {
53 return ['embedpress', 'pdf', 'doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'embedpress-document'];
54 }
55
56 protected function _register_controls()
57 {
58
59 /**
60 * EmbedPress Content Settings
61 */
62 $this->start_controls_section(
63 'embedpress_document_content_settings',
64 [
65 'label' => esc_html__( 'Content Settings', 'embedpress' ),
66 ]
67 );
68
69 $this->add_control(
70 'embedpress_document_type',
71 [
72 'label' => __( 'Document Type', 'embedpress' ),
73 'type' => Controls_Manager::SELECT,
74 'default' => 'file',
75 'options' => [
76 'file' => __( 'File', 'embedpress' ),
77 'url' => __( 'URL', 'embedpress' )
78 ],
79 ]
80 );
81
82 $this->add_control(
83 'embedpress_document_Uploader',
84 [
85
86 'label' => __( 'Upload File', 'embedpress' ),
87 'type' => Controls_Manager::MEDIA,
88 'dynamic' => [
89 'active' => true,
90 'categories' => [
91 TagsModule::MEDIA_CATEGORY,
92 ],
93 ],
94 'media_type' => [
95 'application/pdf',
96 'application/msword',
97 'application/vnd.ms-powerpoint',
98 'application/vnd.ms-excel',
99 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
100 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
101 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
102 ],
103 'description' => __( 'Upload a file or pick one from your media library for embed. Supported File Type: PDF, DOC/DOCX, PPT/PPTX, XLS/XLSX etc.',
104 'embedpress' ),
105 'condition' => [
106 'embedpress_document_type' => 'file'
107 ],
108 ]
109 );
110
111 $this->add_control(
112 'embedpress_document_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_document_type' => 'url'
123 ],
124 ]
125 );
126
127 $this->add_control(
128 'embedpress_elementor_document_width',
129 [
130 'label' => __( 'Width', 'embedpress' ),
131 'type' => Controls_Manager::SLIDER,
132 'separator' => 'before',
133 'default' => [
134 'unit' => 'px',
135 'size' => 600,
136 ],
137 'range' => [
138 'px' => [
139 'min' => 6,
140 'max' => 1000,
141 ],
142 ],
143 'selectors' => [
144 '{{WRAPPER}} .embedpress-document-embed iframe' => 'width: {{SIZE}}{{UNIT}} !important;',
145 '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'width: {{SIZE}}{{UNIT}} !important;',
146 ],
147 ]
148 );
149
150 $this->add_control(
151 'embedpress_elementor_document_height',
152 [
153 'label' => __( 'Height', 'embedpress' ),
154 'type' => Controls_Manager::SLIDER,
155 'default' => [
156 'unit' => 'px',
157 'size' => 600,
158 ],
159 'range' => [
160 'px' => [
161 'min' => 6,
162 'max' => 1000,
163 ],
164 ],
165 'selectors' => [
166 '{{WRAPPER}} .embedpress-document-embed iframe' => 'height: {{SIZE}}{{UNIT}};',
167 '{{WRAPPER}} .embedpress-document-embed .pdfobject-container' => 'height: {{SIZE}}{{UNIT}};',
168 ],
169 ]
170 );
171
172 $this->add_control(
173 'embedpress_elementor_document_align',
174 [
175 'label' => __( 'Alignment', 'embedpress' ),
176 'type' => Controls_Manager::CHOOSE,
177 'options' => [
178 'left' => [
179 'title' => __( 'Left', 'embedpress' ),
180 'icon' => 'eicon-text-align-left',
181 ],
182 'center' => [
183 'title' => __( 'Center', 'embedpress' ),
184 'icon' => 'eicon-text-align-center',
185 ],
186 'right' => [
187 'title' => __( 'Right', 'embedpress' ),
188 'icon' => 'eicon-text-align-right',
189 ]
190 ],
191 'default' => 'center',
192 ]
193 );
194
195 $this->add_control(
196 'embedpress_document_powered_by',
197 [
198 'label' => __( 'Powered By', 'embedpress' ),
199 'type' => Controls_Manager::SWITCHER,
200 'label_on' => __( 'Show', 'embedpress' ),
201 'label_off' => __( 'Hide', 'embedpress' ),
202 'return_value' => 'yes',
203 'default' => apply_filters( 'embedpress_document_powered_by_control', 'yes' ),
204 ]
205 );
206
207
208 $this->end_controls_section();
209 }
210
211 private function is_pdf( $url )
212 {
213 $arr = explode( '.', $url );
214 return end( $arr ) === 'pdf';
215 }
216
217 protected function render()
218 {
219 $settings = $this->get_settings();
220 $url = $this->get_file_url();
221 $id = 'embedpress-pdf-' . $this->get_id();
222 $dimension = "width: {$settings['embedpress_elementor_document_width']['size']}px;height: {$settings['embedpress_elementor_document_height']['size']}px";
223 $this->add_render_attribute( 'embedpres-pdf-render', [
224 'class' => ['embedpress-embed-document-pdf', $id],
225 'data-emid' => $id
226 ] );
227 $this->add_render_attribute( 'embedpress-document', [
228 'class' => ['embedpress-document-embed']
229 ] );
230 ?>
231 <div <?php echo $this->get_render_attribute_string( 'embedpress-document' ); ?>>
232 <?php if ( $url != '' ) {
233 if ( $this->is_pdf( $url ) ) {
234 $this->add_render_attribute( 'embedpres-pdf-render', 'data-emsrc', $url );
235 ?>
236 <div <?php echo $this->get_render_attribute_string( 'embedpres-pdf-render' ); ?>></div>
237 <?php
238
239 if ( Plugin::$instance->editor->is_edit_mode() ) {
240 $this->render_editor_script( $id, $url );
241 }
242
243 } else {
244 $view_link = 'https://docs.google.com/viewer?url=' . $url . '&embedded=true';
245 ?>
246 <iframe allowfullscreen="true"
247 mozallowfullscreen="true" webkitallowfullscreen="true" style="<?php echo $dimension; ?>" src="<?php echo $view_link; ?>"/>
248 <?php
249
250 }
251 if ( $settings[ 'embedpress_document_powered_by' ] === 'yes' ) {
252 printf( '<p class="embedpress-el-powered">%s</p>', __( 'Powered By EmbedPress', 'embedpress' ) );
253 }
254 } ?>
255
256 </div>
257
258 <?php
259 }
260
261 private function get_file_url()
262 {
263 $settings = $this->get_settings();
264 return $settings[ 'embedpress_document_type' ] === 'url' ? $settings[ 'embedpress_document_file_link' ][ 'url' ] : $settings[ 'embedpress_document_Uploader' ][ 'url' ];
265 }
266
267 protected function render_editor_script( $id, $url )
268 {
269 ?>
270 <script>
271 (function ($) {
272 'use strict';
273 $(document).ready(function () {
274 var selector = $('.embedpress-embed-document-pdf');
275 if (selector.length) {
276 PDFObject.embed("<?php echo $url; ?>", "<?php echo '.' . $id; ?>");
277 }
278 });
279 })(jQuery);
280 </script>
281 <?php
282 }
283 }
284