PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.51
E2Pdf – Export Pdf Tool for WordPress v1.32.51
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 +245 -178 1.00.001.32.51 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 }
@@ -38,9 +36,9 @@
38 36 }
39 37
40 38 public function __construct() {
41 39 $this->view = new stdClass();
42 - $this->uri = home_url(add_query_arg(null, null));
40 + $this->uri = home_url(add_query_arg([], false));
43 41 $this->get = new Helper_E2pdf_Get($this->uri);
44 42 $this->post = new Helper_E2pdf_Post();
45 43 $this->files = new Helper_E2pdf_Files();
46 44 $this->page = $this->get->get_page();
@@ -48,171 +46,159 @@
48 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 {
175 158 wp_redirect($location);
159 + exit();
176 160 }
177 161 }
178 162
179 - /**
180 - * Add notification
181 - *
182 - * @param string $type - Type of notification error|update
183 - * @param string $text - Text of notification
184 - */
163 + // add notification
185 164 public function add_notification($type, $text) {
186 - $this->notification->add_notification($type, $text);
165 + return $this->notification->add_notification($type, $text);
187 166 }
188 167
189 - /**
190 - * Get notifications
191 - *
192 - * @return array - List of notifications
193 - */
194 - public function get_notifications() {
195 - $notifications = $this->notification->get_notifications();
196 - return $notifications;
168 + // get notifications
169 + public function get_notifications($notification_id = '') {
170 + return $this->notification->get_notifications($notification_id);
197 171 }
198 172
199 - /**
200 - * Force Json response
201 - *
202 - * @param array $data - Array of data
203 - *
204 - * @return json
205 - */
173 + // json response
206 174 public function json_response($data = array()) {
207 175 @header('Content-Type: application/json; charset=' . get_option('blog_charset'));
208 - 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 + }
209 181 wp_die();
210 182 }
211 183
212 - /**
213 - * Force close browser tab from PHP
214 - */
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
215 201 public function close_tab_response() {
216 202 echo "
217 203 <script>
218 204 self.close();
@@ -219,83 +205,187 @@
219 205 </script>
220 206 ";
221 207 }
222 208
223 - /**
224 - * Force Download response
225 - *
226 - * @param string $format - Format of file
227 - * @param string $file - Base64 Encoded File
228 - * @param string $name - Name of file when download
229 - * @param string $disposition - Disposition of file inline|attachment
230 - *
231 - * @return string
232 - */
233 - public function download_response($format = 'pdf', $file, $name = false, $disposition = false) {
234 - ob_end_clean();
209 + // download response
210 + public function download_response($format, $file, $name = '', $disposition = '', $fpassthru = false, $preview = false) {
235 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 +
236 253 if (!$name) {
237 254 $name = time();
238 255 }
256 + $name = rawurlencode($this->helper->load('convert')->to_file_name($name));
239 257
258 + status_header(200);
240 259 header('Content-Transfer-Encoding: binary');
241 - header('Content-Length: ' . strlen(base64_decode($file)));
260 + header('X-Robots-Tag: noindex, nofollow');
242 261 switch ($format) {
243 262 case 'pdf':
263 + if ($content_length) {
264 + header('Content-Length: ' . strlen($file));
265 + }
244 266 if (!$disposition) {
245 267 $disposition = 'inline';
246 268 }
247 - header("Content-Disposition: {$disposition}; filename=\"{$name}.pdf\"");
248 - 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 + }
249 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;
250 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 + }
251 307 if (!$disposition) {
252 308 $disposition = 'attachment';
253 309 }
254 - header("Content-Disposition: {$disposition}; filename=\"{$name}.zip\"");
255 - 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');
256 316 break;
257 -
258 317 case 'xml':
259 318 if (!$disposition) {
260 319 $disposition = 'attachment';
261 320 }
262 - header("Content-Disposition: {$disposition}; filename=\"{$name}.xml\"");
263 - 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');
264 327 break;
265 -
266 328 case 'txt':
267 329 if (!$disposition) {
268 330 $disposition = 'attachment';
269 331 }
270 - header("Content-Disposition: {$disposition}; filename=\"{$name}.txt\"");
271 - 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');
272 338 break;
273 -
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;
274 361 case 'php':
275 362 if (!$disposition) {
276 363 $disposition = 'attachment';
277 364 }
278 - header("Content-Disposition: {$disposition}; filename=\"{$name}.php\"");
279 - 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');
280 371 break;
281 -
282 372 default:
283 373 break;
284 374 }
285 - echo base64_decode($file);
286 - 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 + }
287 385 }
288 386
289 - /**
290 - * Check if exists in array
291 - *
292 - * @param string $value - Array Key
293 - * @param mixed $compare
294 - * @param array $data - Array of data
295 - *
296 - * @return bool
297 - */
387 + // exist
298 388 public function exist($value, $compare = false, $data = array()) {
299 389 if (isset($data[$value]) && $value === $compare) {
300 390 return true;
301 391 } else {
@@ -302,40 +392,25 @@
302 392 return false;
303 393 }
304 394 }
305 395
306 - /**
307 - * Force Error
308 - *
309 - * @param string $code - Error Code
310 - */
311 - public function error($code = '404') {
396 + // handle 404
397 + public function handle_404() {
312 398 global $wp_query;
313 - if ($code === '404') {
314 - $wp_query->set_404();
315 - status_header(404);
316 - $this->redirect(site_url('wp-admin'));
399 + $wp_query->set_404();
400 + status_header(404);
401 + nocache_headers();
402 + if (is_admin()) {
317 403 wp_die('404');
318 404 }
319 405 }
320 406
321 - /**
322 - * Set var available to view template
323 - *
324 - * @param string $key - Key of value
325 - * @param mixed $value - Value
326 - */
407 + // view
327 408 public function view($key, $value) {
328 409 $this->view->$key = $value;
329 410 }
330 411
331 - /**
332 - * Check if Array/Object Empty
333 - *
334 - * @param mixed $data - Object/Array to check
335 - *
336 - * @return bool
337 - */
412 + // is empty
338 413 public function is_empty($data) {
339 414 if (is_object($data) || is_array($data)) {
340 415
341 416 if (is_object($data)) {
@@ -348,25 +423,17 @@
348 423
349 424 return true;
350 425 }
351 426
352 - /**
353 - * Verify nonce
354 - *
355 - * @param string $nonce - Nonce value
356 - * @param string $key - Nonce Key
357 - */
358 - public function check_nonce($nonce, $key) {
359 - $message = __('Security Issue: Nonce Incorrect', 'e2pdf');
360 - if ($key === 'e2pdf_ajax') {
361 - if (!wp_verify_nonce($nonce, $key)) {
362 - $data['error'] = $message;
363 - $this->json_response($data);
364 - }
365 - } else {
366 - if (!wp_verify_nonce($nonce, $key)) {
367 - die('<div id="message" class="error e2pdf-notice">' . $message . '</div>');
368 - }
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;
369 436 }
437 + return $message;
370 438 }
371 -
372 439 }