PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.49
E2Pdf – Export Pdf Tool for WordPress v1.32.49
1.32.51 1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 1.06.02 1.07.11 1.08.00 All 73 releases
← All changes | classes/helper/e2pdf-view.php +244 -178 1.04.07 → 1.32.49 View file →
@@ -1,14 +1,12 @@
1 1 <?php
2 2
3 3 /**
4 - * E2pdf View Helper
5 - *
6 - * @copyright Copyright 2017 https://e2pdf.com
7 - * @license GPL v2
8 - * @version 1
9 - * @link https://e2pdf.com
10 - * @since 0.00.01
4 + * File: /helper/e2pdf-view.php
5 + *
6 + * @package E2Pdf
7 + * @license GPLv3
8 + * @link https://e2pdf.com
11 9 */
12 10 if (!defined('ABSPATH')) {
13 11 die('Access denied.');
14 12 }
@@ -44,131 +42,116 @@
44 42 $this->post = new Helper_E2pdf_Post();
45 43 $this->files = new Helper_E2pdf_Files();
46 44 $this->page = $this->get->get_page();
47 45 $this->helper = Helper_E2pdf_Helper::instance();
48 - $this->notification = new Model_E2pdf_Notification();
46 + $this->notification = Model_E2pdf_Notification::instance();
49 47 $this->view_dir = $this->helper->get('plugin_dir') . 'classes/view/';
50 48 }
51 49
52 - /**
53 - * Get Tpl Value
54 - *
55 - * @param string $key - Tpl key
56 - *
57 - * @return mixed - Tpl value
58 - */
50 + // render
59 51 public function render($type, $element, $args = array()) {
60 52 $this->tpl_args = new Helper_E2pdf_Tplargs($args);
61 53 $this->tpl = $this->view_dir . $type . '/' . $element . '.php';
62 54 if (file_exists($this->tpl)) {
63 - include($this->tpl);
55 + include $this->tpl;
64 56 }
65 57 }
66 58
67 - /**
68 - * Get Tpl Value
69 - *
70 - * @param string $key - Tpl key
71 - *
72 - * @return mixed - Tpl value
73 - */
59 + // render metabox
74 60 public function render_metabox($post, $metabox) {
75 61 $this->render('metaboxes', $metabox['args']['tpl']);
76 62 }
77 63
78 - /**
79 - * Get Tpl Value
80 - *
81 - * @param string $key - Tpl key
82 - *
83 - * @return mixed - Tpl value
84 - */
64 + // render page
85 65 public function render_page() {
86 -
87 - if (get_option('e2pdf_developer')) {
88 - $model_e2pdf_options = new Model_E2pdf_Options();
89 - if (in_array($this->helper->get_ip(), $model_e2pdf_options->get_option('e2pdf_developer_ips'))) {
90 - error_reporting(E_ALL);
91 - ini_set('display_startup_errors', 1);
92 - ini_set('display_errors', 1);
93 - }
94 - }
95 -
96 -
97 66 $this->tpl_page = $this->view_dir . 'page-' . $this->page . '.php';
98 67 $controller = $this->page_to_controller($this->page);
99 68 if (class_exists($controller)) {
100 69 $this->controller = new $controller();
70 + $method = 'index_action';
101 71 if ($this->get->get('action')) {
102 72 $method = $this->get->get('action') . '_action';
103 - } else {
104 - $method = 'index_action';
105 73 }
106 74 if (method_exists($this->controller, $method)) {
107 75 $this->controller->$method();
108 76 $this->view = $this->controller->view;
77 + if (file_exists($this->tpl_page)) {
78 + include $this->tpl_page;
79 + }
109 80 } else {
110 - $this->error('404');
81 + $this->handle_404();
111 82 }
112 83 }
113 -
114 - if (file_exists($this->tpl_page)) {
115 - include($this->tpl_page);
116 - }
117 84 }
118 85
86 + // render frontend page
119 87 public function render_frontend_page() {
120 - if ($this->page == 'e2pdf-download') {
121 - $this->tpl_page = $this->view_dir . '/frontend/page-' . $this->page . '.php';
122 - $controller = $this->page_to_controller($this->page, true);
88 + if ($this->page == 'e2pdf-download' || get_query_var('e2pdf')) {
89 + $this->tpl_page = $this->view_dir . '/frontend/page-e2pdf-download.php';
90 + $controller = $this->page_to_controller('e2pdf-download', true);
123 91 if (class_exists($controller)) {
124 92 $this->controller = new $controller();
93 + $method = 'index_action';
125 94 if ($this->get->get('action')) {
126 95 $method = $this->get->get('action') . '_action';
127 - } else {
128 - $method = 'index_action';
129 96 }
130 97 if (method_exists($this->controller, $method)) {
131 98 $this->controller->$method();
99 + if (file_exists($this->tpl_page)) {
100 + include $this->tpl_page;
101 + }
132 102 } else {
133 - $this->error('404');
103 + $this->handle_404();
134 104 }
135 105 }
106 + } elseif ($this->page == 'e2pdf-activation') {
107 + if (get_transient('e2pdf_activation_key')) {
108 + $activation_key = get_transient('e2pdf_activation_key');
109 + if ($this->get->get('key') == $activation_key) {
110 + if (ob_get_length() > 0) {
111 + while (@ob_end_clean());
112 + }
113 + header('Content-Type: text/plain');
114 + echo $activation_key;
115 + die();
116 + }
117 + }
118 + }
119 + }
136 120
137 - if (file_exists($this->tpl_page)) {
138 - include($this->tpl_page);
121 + // rpc
122 + public function rpc() {
123 + if (ob_get_length() > 0) {
124 + while (@ob_end_clean());
125 + }
126 + $rpc = new Model_E2pdf_Rpc($this->helper->load('server')->get('REQUEST_URI'));
127 + $controller = $this->page_to_controller('e2pdf-rpc-' . $rpc->get('version'), true);
128 + if (class_exists($controller)) {
129 + $this->controller = new $controller();
130 + $method = 'index_action';
131 + if ($rpc->get('method')) {
132 + $method = $rpc->get('method') . '_action';
139 133 }
134 + if (method_exists($this->controller, $method)) {
135 + $this->controller->$method($rpc);
136 + }
140 137 }
141 138 }
142 139
143 - /**
144 - * Get Tpl Value
145 - *
146 - * @param string $key - Tpl key
147 - *
148 - * @return mixed - Tpl value
149 - */
140 + // page to controller
150 141 public function page_to_controller($page, $frontend = false) {
151 -
152 142 $controller = array(
153 - 'Controller'
143 + 'Controller',
154 144 );
155 -
156 145 if ($frontend) {
157 146 $controller[] = 'Frontend';
158 147 }
159 -
160 148 $controller = array_merge($controller, explode('-', $page));
161 149 $controller = array_map('ucfirst', $controller);
162 -
163 150 return implode("_", $controller);
164 151 }
165 152
166 - /**
167 - * Redirect to page
168 - *
169 - * @param string $location - Full url where to redirect
170 - */
153 + // redirect
171 154 public function redirect($location) {
172 155 if (headers_sent()) {
173 156 die("<script>window.location='{$location}';</script>");
174 157 } else {
@@ -176,44 +159,46 @@
176 159 exit();
177 160 }
178 161 }
179 162
180 - /**
181 - * Add notification
182 - *
183 - * @param string $type - Type of notification error|update
184 - * @param string $text - Text of notification
185 - */
163 + // add notification
186 164 public function add_notification($type, $text) {
187 - $this->notification->add_notification($type, $text);
165 + return $this->notification->add_notification($type, $text);
188 166 }
189 167
190 - /**
191 - * Get notifications
192 - *
193 - * @return array - List of notifications
194 - */
195 - public function get_notifications() {
196 - $notifications = $this->notification->get_notifications();
197 - return $notifications;
168 + // get notifications
169 + public function get_notifications($notification_id = '') {
170 + return $this->notification->get_notifications($notification_id);
198 171 }
199 172
200 - /**
201 - * Force Json response
202 - *
203 - * @param array $data - Array of data
204 - *
205 - * @return json
206 - */
173 + // json response
207 174 public function json_response($data = array()) {
208 175 @header('Content-Type: application/json; charset=' . get_option('blog_charset'));
209 - echo wp_json_encode($data, JSON_FORCE_OBJECT);
176 + if (function_exists('wp_json_encode')) {
177 + echo wp_json_encode($data, JSON_FORCE_OBJECT);
178 + } else {
179 + echo json_encode($data, JSON_FORCE_OBJECT);
180 + }
210 181 wp_die();
211 182 }
212 183
213 - /**
214 - * Force close browser tab from PHP
215 - */
184 + // json response ajax
185 + public function json_response_ajax($data = array(), $status = 200) {
186 + if (ob_get_length() > 0) {
187 + while (@ob_end_clean());
188 + }
189 + status_header($status);
190 + header('X-Robots-Tag: noindex, nofollow');
191 + @header('Content-Type: application/json; charset=' . get_option('blog_charset'));
192 + if (function_exists('wp_json_encode')) {
193 + echo wp_json_encode($data, JSON_FORCE_OBJECT);
194 + } else {
195 + echo json_encode($data, JSON_FORCE_OBJECT);
196 + }
197 + exit;
198 + }
199 +
200 + // close tab response
216 201 public function close_tab_response() {
217 202 echo "
218 203 <script>
219 204 self.close();
@@ -220,83 +205,187 @@
220 205 </script>
221 206 ";
222 207 }
223 208
224 - /**
225 - * Force Download response
226 - *
227 - * @param string $format - Format of file
228 - * @param string $file - Base64 Encoded File
229 - * @param string $name - Name of file when download
230 - * @param string $disposition - Disposition of file inline|attachment
231 - *
232 - * @return string
233 - */
234 - public function download_response($format = 'pdf', $file, $name = false, $disposition = false) {
235 - ob_end_clean();
209 + // download response
210 + public function download_response($format, $file, $name = '', $disposition = '', $fpassthru = false, $preview = false) {
236 211
212 + $content_length = true;
213 + /**
214 + * External Links – nofollow, noopener & new window compatibility fix filter
215 + * https://wordpress.org/plugins/wp-external-links/
216 + */
217 + add_filter('wpel_apply_settings', '__return_false');
218 +
219 + /**
220 + * Compatibility fix with TranslatePress
221 + * https://wordpress.org/plugins/translatepress-multilingual/
222 + */
223 + add_filter('trp_stop_translating_page', '__return_true');
224 +
225 + if (ob_get_length() > 0) {
226 + while (@ob_end_clean());
227 + }
228 +
229 + /**
230 + * PHP 8.0.17 & PHP 8.1.4 compatibility with zlib enabled
231 + */
232 + header_remove("Content-Encoding");
233 +
234 + /**
235 + * W3 Total Cache + OVH compatibility fix
236 + * https://wordpress.org/plugins/w3-total-cache/
237 + */
238 + if (function_exists('w3tc_config')) {
239 + $w3tc_config = w3tc_config();
240 + if ($w3tc_config->get_boolean('browsercache.enabled') && $w3tc_config->get_boolean('browsercache.html.compression') && function_exists('php_uname') && false !== stripos(@php_uname(), '.ovh.net')) {
241 + $content_length = false;
242 + }
243 + }
244 +
245 + /**
246 + * WP Rocket + OVH compatibility fix
247 + * https://wp-rocket.me/
248 + */
249 + if (function_exists('rocket_generate_config_file') && !function_exists('WP_Rocket\Helpers\htaccess\remove_gzip\flush_wp_rocket') && function_exists('php_uname') && false !== stripos(@php_uname(), '.ovh.net')) {
250 + $content_length = false;
251 + }
252 +
237 253 if (!$name) {
238 254 $name = time();
239 255 }
256 + $name = rawurlencode($this->helper->load('convert')->to_file_name($name));
240 257
258 + status_header(200);
241 259 header('Content-Transfer-Encoding: binary');
242 - header('Content-Length: ' . strlen(base64_decode($file)));
260 + header('X-Robots-Tag: noindex, nofollow');
243 261 switch ($format) {
244 262 case 'pdf':
263 + if ($content_length) {
264 + header('Content-Length: ' . strlen($file));
265 + }
245 266 if (!$disposition) {
246 267 $disposition = 'inline';
247 268 }
248 - header("Content-Disposition: {$disposition}; filename=\"{$name}.pdf\"");
249 - header("Content-type: application/pdf");
269 + if (isset($_SERVER['HTTP_USER_AGENT']) && stripos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== false) {
270 + header("Content-Disposition: {$disposition}; filename*=UTF-8''{$name}.pdf");
271 + } else {
272 + header("Content-Disposition: {$disposition}; filename=\"{$name}.pdf\"");
273 + }
274 + header("Content-Type: application/pdf");
275 + if ($preview && $disposition == 'inline' && isset($_SERVER['HTTP_USER_AGENT']) && stripos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== false) {
276 + header('Cache-Control: private');
277 + }
250 278 break;
279 + case 'jpg':
280 + if ($content_length) {
281 + header('Content-Length: ' . strlen($file));
282 + }
283 + if (!$disposition) {
284 + $disposition = 'attachment';
285 + }
286 + if (isset($_SERVER['HTTP_USER_AGENT']) && stripos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== false) {
287 + header("Content-Disposition: {$disposition}; filename*=UTF-8''{$name}.jpg");
288 + } else {
289 + header("Content-Disposition: {$disposition}; filename=\"{$name}.jpg\"");
290 + }
291 + header('Content-Type: image/jpeg');
292 + if ($preview && $disposition == 'inline' && isset($_SERVER['HTTP_USER_AGENT']) && stripos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== false) {
293 + header('Cache-Control: private');
294 + }
295 + break;
251 296 case 'zip':
297 + if ($content_length) {
298 + if ($fpassthru) {
299 + if (ini_get('zlib.output_compression')) {
300 + ini_set('zlib.output_compression', 'Off');
301 + }
302 + header('Content-Length: ' . filesize(trim($file)));
303 + } else {
304 + header('Content-Length: ' . strlen($file));
305 + }
306 + }
252 307 if (!$disposition) {
253 308 $disposition = 'attachment';
254 309 }
255 - header("Content-Disposition: {$disposition}; filename=\"{$name}.zip\"");
256 - header('Content-type: application/zip');
310 + if (isset($_SERVER['HTTP_USER_AGENT']) && stripos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== false) {
311 + header("Content-Disposition: {$disposition}; filename*=UTF-8''{$name}.zip");
312 + } else {
313 + header("Content-Disposition: {$disposition}; filename=\"{$name}.zip\"");
314 + }
315 + header('Content-Type: application/zip');
257 316 break;
258 -
259 317 case 'xml':
260 318 if (!$disposition) {
261 319 $disposition = 'attachment';
262 320 }
263 - header("Content-Disposition: {$disposition}; filename=\"{$name}.xml\"");
264 - header('Content-type: text/xml');
321 + if (isset($_SERVER['HTTP_USER_AGENT']) && stripos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== false) {
322 + header("Content-Disposition: {$disposition}; filename*=UTF-8''{$name}.xml");
323 + } else {
324 + header("Content-Disposition: {$disposition}; filename=\"{$name}.xml\"");
325 + }
326 + header('Content-Type: text/xml');
265 327 break;
266 -
267 328 case 'txt':
268 329 if (!$disposition) {
269 330 $disposition = 'attachment';
270 331 }
271 - header("Content-Disposition: {$disposition}; filename=\"{$name}.txt\"");
272 - header('Content-type: text/html');
332 + if (isset($_SERVER['HTTP_USER_AGENT']) && stripos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== false) {
333 + header("Content-Disposition: {$disposition}; filename*=UTF-8''{$name}.txt");
334 + } else {
335 + header("Content-Disposition: {$disposition}; filename=\"{$name}.txt\"");
336 + }
337 + header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
273 338 break;
274 -
339 + case 'doc':
340 + if (!$disposition) {
341 + $disposition = 'attachment';
342 + }
343 + if (isset($_SERVER['HTTP_USER_AGENT']) && stripos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== false) {
344 + header("Content-Disposition: {$disposition}; filename*=UTF-8''{$name}.txt");
345 + } else {
346 + header("Content-Disposition: {$disposition}; filename=\"{$name}.txt\"");
347 + }
348 + header('Content-Type: application/msword');
349 + break;
350 + case 'docx':
351 + if (!$disposition) {
352 + $disposition = 'attachment';
353 + }
354 + if (isset($_SERVER['HTTP_USER_AGENT']) && stripos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== false) {
355 + header("Content-Disposition: {$disposition}; filename*=UTF-8''{$name}.txt");
356 + } else {
357 + header("Content-Disposition: {$disposition}; filename=\"{$name}.txt\"");
358 + }
359 + header('Content-Type: text/html');
360 + break;
275 361 case 'php':
276 362 if (!$disposition) {
277 363 $disposition = 'attachment';
278 364 }
279 - header("Content-Disposition: {$disposition}; filename=\"{$name}.php\"");
280 - header('Content-type: text/html');
365 + if (isset($_SERVER['HTTP_USER_AGENT']) && stripos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== false) {
366 + header("Content-Disposition: {$disposition}; filename*=UTF-8''{$name}.php");
367 + } else {
368 + header("Content-Disposition: {$disposition}; filename=\"{$name}.php\"");
369 + }
370 + header('Content-Type: text/html');
281 371 break;
282 -
283 372 default:
284 373 break;
285 374 }
286 - echo base64_decode($file);
287 - die();
375 +
376 + if ($fpassthru) {
377 + $handle = @fopen($file, 'rb');
378 + while (!feof($handle)) {
379 + echo fread($handle, 8192);
380 + }
381 + fclose($handle);
382 + } else {
383 + echo $file;
384 + }
288 385 }
289 386
290 - /**
291 - * Check if exists in array
292 - *
293 - * @param string $value - Array Key
294 - * @param mixed $compare
295 - * @param array $data - Array of data
296 - *
297 - * @return bool
298 - */
387 + // exist
299 388 public function exist($value, $compare = false, $data = array()) {
300 389 if (isset($data[$value]) && $value === $compare) {
301 390 return true;
302 391 } else {
@@ -303,40 +392,25 @@
303 392 return false;
304 393 }
305 394 }
306 395
307 - /**
308 - * Force Error
309 - *
310 - * @param string $code - Error Code
311 - */
312 - public function error($code = '404') {
396 + // handle 404
397 + public function handle_404() {
313 398 global $wp_query;
314 - if ($code === '404') {
315 - $wp_query->set_404();
316 - status_header(404);
317 - $this->redirect(site_url('wp-admin'));
399 + $wp_query->set_404();
400 + status_header(404);
401 + nocache_headers();
402 + if (is_admin()) {
318 403 wp_die('404');
319 404 }
320 405 }
321 406
322 - /**
323 - * Set var available to view template
324 - *
325 - * @param string $key - Key of value
326 - * @param mixed $value - Value
327 - */
407 + // view
328 408 public function view($key, $value) {
329 409 $this->view->$key = $value;
330 410 }
331 411
332 - /**
333 - * Check if Array/Object Empty
334 - *
335 - * @param mixed $data - Object/Array to check
336 - *
337 - * @return bool
338 - */
412 + // is empty
339 413 public function is_empty($data) {
340 414 if (is_object($data) || is_array($data)) {
341 415
342 416 if (is_object($data)) {
@@ -349,25 +423,17 @@
349 423
350 424 return true;
351 425 }
352 426
353 - /**
354 - * Verify nonce
355 - *
356 - * @param string $nonce - Nonce value
357 - * @param string $key - Nonce Key
358 - */
359 - public function check_nonce($nonce, $key) {
360 - $message = __('Security Issue: Nonce Incorrect', 'e2pdf');
361 - if ($key === 'e2pdf_ajax') {
362 - if (!wp_verify_nonce($nonce, $key)) {
363 - $data['error'] = $message;
364 - $this->json_response($data);
365 - }
366 - } else {
367 - if (!wp_verify_nonce($nonce, $key)) {
368 - die('<div id="message" class="error e2pdf-notice">' . $message . '</div>');
369 - }
427 + // message
428 + public function message($key) {
429 + $message = '';
430 + switch ($key) {
431 + case 'wp_verify_nonce_error':
432 + $message = 'E2Pdf Bad Request';
433 + break;
434 + default:
435 + break;
370 436 }
437 + return $message;
371 438 }
372 -
373 439 }