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 +43 -99 1.32.151.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 GPLv3
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,68 +36,55 @@
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();
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 - * @param string $key - Tpl key
55 - * @return mixed - Tpl value
56 - */
50 + // render
57 51 public function render($type, $element, $args = array()) {
58 52 $this->tpl_args = new Helper_E2pdf_Tplargs($args);
59 53 $this->tpl = $this->view_dir . $type . '/' . $element . '.php';
60 54 if (file_exists($this->tpl)) {
61 - include($this->tpl);
55 + include $this->tpl;
62 56 }
63 57 }
64 58
65 - /**
66 - * Get Tpl Value
67 - * @param string $key - Tpl key
68 - * @return mixed - Tpl value
69 - */
59 + // render metabox
70 60 public function render_metabox($post, $metabox) {
71 61 $this->render('metaboxes', $metabox['args']['tpl']);
72 62 }
73 63
74 - /**
75 - * Get Tpl Value
76 - * @param string $key - Tpl key
77 - * @return mixed - Tpl value
78 - */
64 + // render page
79 65 public function render_page() {
80 66 $this->tpl_page = $this->view_dir . 'page-' . $this->page . '.php';
81 67 $controller = $this->page_to_controller($this->page);
82 68 if (class_exists($controller)) {
83 69 $this->controller = new $controller();
70 + $method = 'index_action';
84 71 if ($this->get->get('action')) {
85 72 $method = $this->get->get('action') . '_action';
86 - } else {
87 - $method = 'index_action';
88 73 }
89 74 if (method_exists($this->controller, $method)) {
90 75 $this->controller->$method();
91 76 $this->view = $this->controller->view;
77 + if (file_exists($this->tpl_page)) {
78 + include $this->tpl_page;
79 + }
92 80 } else {
93 81 $this->handle_404();
94 82 }
95 83 }
96 -
97 - if (file_exists($this->tpl_page)) {
98 - include($this->tpl_page);
99 - }
100 84 }
101 85
86 + // render frontend page
102 87 public function render_frontend_page() {
103 88 if ($this->page == 'e2pdf-download' || get_query_var('e2pdf')) {
104 89 $this->tpl_page = $this->view_dir . '/frontend/page-e2pdf-download.php';
105 90 $controller = $this->page_to_controller('e2pdf-download', true);
@@ -104,23 +89,21 @@
104 89 $this->tpl_page = $this->view_dir . '/frontend/page-e2pdf-download.php';
105 90 $controller = $this->page_to_controller('e2pdf-download', true);
106 91 if (class_exists($controller)) {
107 92 $this->controller = new $controller();
93 + $method = 'index_action';
108 94 if ($this->get->get('action')) {
109 95 $method = $this->get->get('action') . '_action';
110 - } else {
111 - $method = 'index_action';
112 96 }
113 97 if (method_exists($this->controller, $method)) {
114 98 $this->controller->$method();
99 + if (file_exists($this->tpl_page)) {
100 + include $this->tpl_page;
101 + }
115 102 } else {
116 103 $this->handle_404();
117 104 }
118 105 }
119 -
120 - if (file_exists($this->tpl_page)) {
121 - include($this->tpl_page);
122 - }
123 106 } elseif ($this->page == 'e2pdf-activation') {
124 107 if (get_transient('e2pdf_activation_key')) {
125 108 $activation_key = get_transient('e2pdf_activation_key');
126 109 if ($this->get->get('key') == $activation_key) {
@@ -134,8 +117,9 @@
134 117 }
135 118 }
136 119 }
137 120
121 + // rpc
138 122 public function rpc() {
139 123 if (ob_get_length() > 0) {
140 124 while (@ob_end_clean());
141 125 }
@@ -142,23 +126,22 @@
142 126 $rpc = new Model_E2pdf_Rpc($this->helper->load('server')->get('REQUEST_URI'));
143 127 $controller = $this->page_to_controller('e2pdf-rpc-' . $rpc->get('version'), true);
144 128 if (class_exists($controller)) {
145 129 $this->controller = new $controller();
146 - $method = $rpc->get('method');
147 - if ($method && method_exists($this->controller, $method)) {
130 + $method = 'index_action';
131 + if ($rpc->get('method')) {
132 + $method = $rpc->get('method') . '_action';
133 + }
134 + if (method_exists($this->controller, $method)) {
148 135 $this->controller->$method($rpc);
149 136 }
150 137 }
151 138 }
152 139
153 - /**
154 - * Get Tpl Value
155 - * @param string $key - Tpl key
156 - * @return mixed - Tpl value
157 - */
140 + // page to controller
158 141 public function page_to_controller($page, $frontend = false) {
159 142 $controller = array(
160 - 'Controller'
143 + 'Controller',
161 144 );
162 145 if ($frontend) {
163 146 $controller[] = 'Frontend';
164 147 }
@@ -166,12 +149,9 @@
166 149 $controller = array_map('ucfirst', $controller);
167 150 return implode("_", $controller);
168 151 }
169 152
170 - /**
171 - * Redirect to page
172 - * @param string $location - Full url where to redirect
173 - */
153 + // redirect
174 154 public function redirect($location) {
175 155 if (headers_sent()) {
176 156 die("<script>window.location='{$location}';</script>");
177 157 } else {
@@ -179,31 +159,19 @@
179 159 exit();
180 160 }
181 161 }
182 162
183 - /**
184 - * Add notification
185 - * @param string $type - Type of notification error|update
186 - * @param string $text - Text of notification
187 - */
163 + // add notification
188 164 public function add_notification($type, $text) {
189 - $this->notification->add_notification($type, $text);
165 + return $this->notification->add_notification($type, $text);
190 166 }
191 167
192 - /**
193 - * Get notifications
194 - * @return array - List of notifications
195 - */
196 - public function get_notifications() {
197 - $notifications = $this->notification->get_notifications();
198 - return $notifications;
168 + // get notifications
169 + public function get_notifications($notification_id = '') {
170 + return $this->notification->get_notifications($notification_id);
199 171 }
200 172
201 - /**
202 - * Force Json response
203 - * @param array $data - Array of data
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 176 if (function_exists('wp_json_encode')) {
209 177 echo wp_json_encode($data, JSON_FORCE_OBJECT);
@@ -212,8 +180,9 @@
212 180 }
213 181 wp_die();
214 182 }
215 183
184 + // json response ajax
216 185 public function json_response_ajax($data = array(), $status = 200) {
217 186 if (ob_get_length() > 0) {
218 187 while (@ob_end_clean());
219 188 }
@@ -227,11 +196,9 @@
227 196 }
228 197 exit;
229 198 }
230 199
231 - /**
232 - * Force close browser tab from PHP
233 - */
200 + // close tab response
234 201 public function close_tab_response() {
235 202 echo "
236 203 <script>
237 204 self.close();
@@ -238,16 +205,9 @@
238 205 </script>
239 206 ";
240 207 }
241 208
242 - /**
243 - * Force Download response
244 - * @param string $format - Format of file
245 - * @param string $file - Base64 Encoded File
246 - * @param string $name - Name of file when download
247 - * @param string $disposition - Disposition of file inline|attachment
248 - * @return string
249 - */
209 + // download response
250 210 public function download_response($format, $file, $name = '', $disposition = '', $fpassthru = false, $preview = false) {
251 211
252 212 $content_length = true;
253 213 /**
@@ -423,15 +383,9 @@
423 383 echo $file;
424 384 }
425 385 }
426 386
427 - /**
428 - * Check if exists in array
429 - * @param string $value - Array Key
430 - * @param mixed $compare
431 - * @param array $data - Array of data
432 - * @return bool
433 - */
387 + // exist
434 388 public function exist($value, $compare = false, $data = array()) {
435 389 if (isset($data[$value]) && $value === $compare) {
436 390 return true;
437 391 } else {
@@ -438,12 +392,9 @@
438 392 return false;
439 393 }
440 394 }
441 395
442 - /**
443 - * Force Error
444 - * @param string $code - Error Code
445 - */
396 + // handle 404
446 397 public function handle_404() {
447 398 global $wp_query;
448 399 $wp_query->set_404();
449 400 status_header(404);
@@ -452,22 +403,14 @@
452 403 wp_die('404');
453 404 }
454 405 }
455 406
456 - /**
457 - * Set var available to view template
458 - * @param string $key - Key of value
459 - * @param mixed $value - Value
460 - */
407 + // view
461 408 public function view($key, $value) {
462 409 $this->view->$key = $value;
463 410 }
464 411
465 - /**
466 - * Check if Array/Object Empty
467 - * @param mixed $data - Object/Array to check
468 - * @return bool
469 - */
412 + // is empty
470 413 public function is_empty($data) {
471 414 if (is_object($data) || is_array($data)) {
472 415
473 416 if (is_object($data)) {
@@ -480,8 +423,9 @@
480 423
481 424 return true;
482 425 }
483 426
427 + // message
484 428 public function message($key) {
485 429 $message = '';
486 430 switch ($key) {
487 431 case 'wp_verify_nonce_error':