| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* E2Pdf Templates Controller |
| 5 |
* @copyright Copyright 2017 https://e2pdf.com |
| 6 |
* @license GPLv3 |
| 7 |
* @version 1 |
| 8 |
* @link https://e2pdf.com |
| 9 |
* @since 0.00.01 |
| 10 |
*/ |
| 11 |
if (!defined('ABSPATH')) { |
| 12 |
die('Access denied.'); |
| 13 |
} |
| 14 |
|
| 15 |
class Controller_E2pdf_Templates extends Helper_E2pdf_View { |
| 16 |
|
| 17 |
/** |
| 18 |
* @url admin.php?page=e2pdf-templates |
| 19 |
*/ |
| 20 |
public function index_action() { |
| 21 |
if ($this->post->get('screenoptionnonce')) { |
| 22 |
if (wp_verify_nonce($this->post->get('screenoptionnonce'), 'screen-options-nonce')) { |
| 23 |
$this->screen_action(); |
| 24 |
} else { |
| 25 |
wp_die($this->message('wp_verify_nonce_error')); |
| 26 |
} |
| 27 |
} elseif ($this->post->get('_wpnonce')) { |
| 28 |
if (wp_verify_nonce($this->post->get('_wpnonce'), 'e2pdf_templates')) { |
| 29 |
if ($this->post->get('action') == '-1' && $this->post->get('action2') == '-1') { |
| 30 |
$redirect_url = [ |
| 31 |
'page' => 'e2pdf-templates', |
| 32 |
'status' => $this->get->get('status'), |
| 33 |
'orderby' => $this->get->get('orderby'), |
| 34 |
'order' => $this->get->get('order'), |
| 35 |
]; |
| 36 |
if ($this->post->get('s')) { |
| 37 |
$redirect_url['s'] = $this->post->get('s'); |
| 38 |
} |
| 39 |
$this->redirect( |
| 40 |
$this->helper->get_url($redirect_url) |
| 41 |
); |
| 42 |
} else { |
| 43 |
$action = $this->post->get('action') != '-1' ? $this->post->get('action') : $this->post->get('action2'); |
| 44 |
if ($this->post->get('post')) { |
| 45 |
if ($action == 'trash') { |
| 46 |
foreach ($this->post->get('post') as $key => $value) { |
| 47 |
$this->trash_template($value); |
| 48 |
} |
| 49 |
$this->add_notification('update', sprintf(__('Templates Trashed: %d', 'e2pdf'), count($this->post->get('post')))); |
| 50 |
} elseif ($action == 'activate') { |
| 51 |
foreach ($this->post->get('post') as $key => $value) { |
| 52 |
$this->activate_template($value); |
| 53 |
} |
| 54 |
$this->add_notification('update', sprintf(__('Templates Activated: %d', 'e2pdf'), count($this->post->get('post')))); |
| 55 |
} elseif ($action == 'deactivate') { |
| 56 |
foreach ($this->post->get('post') as $key => $value) { |
| 57 |
$this->deactivate_template($value); |
| 58 |
} |
| 59 |
$this->add_notification('update', sprintf(__('Templates Deactivated: %d', 'e2pdf'), count($this->post->get('post')))); |
| 60 |
} elseif ($action == 'restore') { |
| 61 |
foreach ($this->post->get('post') as $key => $value) { |
| 62 |
$this->restore_template($value); |
| 63 |
} |
| 64 |
$this->add_notification('update', sprintf(__('Templates Restored: %d', 'e2pdf'), count($this->post->get('post')))); |
| 65 |
} elseif ($action == 'delete') { |
| 66 |
foreach ($this->post->get('post') as $key => $value) { |
| 67 |
$this->delete_template($value); |
| 68 |
} |
| 69 |
$this->add_notification('update', sprintf(__('Templates Deleted: %d', 'e2pdf'), count($this->post->get('post')))); |
| 70 |
} |
| 71 |
$this->helper->load('license')->load(); |
| 72 |
} |
| 73 |
} |
| 74 |
} else { |
| 75 |
wp_die($this->message('wp_verify_nonce_error')); |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* @url admin.php?page=e2pdf-templates&action=view&id=$id |
| 82 |
* @return file |
| 83 |
*/ |
| 84 |
public function view_action() { |
| 85 |
if ($this->get->get('id')) { |
| 86 |
$template = new Model_E2pdf_Template(); |
| 87 |
if ($template->load($this->get->get('id'))) { |
| 88 |
$pages = $template->get('pages'); |
| 89 |
foreach ($pages as $page_key => $page) { |
| 90 |
if (!empty($page['elements'])) { |
| 91 |
foreach ($page['elements'] as $element_key => $element) { |
| 92 |
if (isset($element['type'])) { |
| 93 |
switch ($element['type']) { |
| 94 |
case 'e2pdf-image': |
| 95 |
if (isset($element['properties']['quality']) && $element['properties']['quality']) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf |
| 96 |
} else { |
| 97 |
$element['properties']['quality'] = $template->get('optimization'); |
| 98 |
$pages[$page_key]['elements'][$element_key]['properties']['quality'] = $template->get('optimization'); |
| 99 |
} |
| 100 |
if ($image = $this->helper->load('image')->get_image($element['value'], null, $element)) { |
| 101 |
$pages[$page_key]['elements'][$element_key]['value'] = $image; |
| 102 |
} else { |
| 103 |
$pages[$page_key]['elements'][$element_key]['value'] = $this->helper->load('image')->get_image($this->helper->get('plugin_dir') . 'img/upload.svg'); |
| 104 |
$pages[$page_key]['elements'][$element_key]['properties']['preview'] = '1'; |
| 105 |
} |
| 106 |
break; |
| 107 |
case 'e2pdf-signature': |
| 108 |
$esig = isset($element['properties']['esig']) && $element['properties']['esig'] ? true : false; |
| 109 |
if (!$esig) { |
| 110 |
if ($image = $this->helper->load('image')->get_image($element['value'])) { |
| 111 |
$pages[$page_key]['elements'][$element_key]['value'] = $image; |
| 112 |
} else { |
| 113 |
$pages[$page_key]['elements'][$element_key]['value'] = $this->helper->load('image')->get_image($this->helper->get('plugin_dir') . 'img/signature.svg'); |
| 114 |
$pages[$page_key]['elements'][$element_key]['properties']['preview'] = '1'; |
| 115 |
} |
| 116 |
} |
| 117 |
break; |
| 118 |
case 'e2pdf-qrcode': |
| 119 |
$pages[$page_key]['elements'][$element_key]['type'] = 'e2pdf-image'; |
| 120 |
$pages[$page_key]['elements'][$element_key]['value'] = $this->helper->load('image')->get_image($this->helper->get('plugin_dir') . 'img/qrcode.svg'); |
| 121 |
$pages[$page_key]['elements'][$element_key]['properties']['preview'] = '1'; |
| 122 |
break; |
| 123 |
case 'e2pdf-barcode': |
| 124 |
$pages[$page_key]['elements'][$element_key]['type'] = 'e2pdf-image'; |
| 125 |
$pages[$page_key]['elements'][$element_key]['value'] = $this->helper->load('image')->get_image($this->helper->get('plugin_dir') . 'img/barcode.svg'); |
| 126 |
$pages[$page_key]['elements'][$element_key]['properties']['preview'] = '1'; |
| 127 |
break; |
| 128 |
case 'e2pdf-graph': |
| 129 |
$pages[$page_key]['elements'][$element_key]['type'] = 'e2pdf-image'; |
| 130 |
$pages[$page_key]['elements'][$element_key]['value'] = $this->helper->load('image')->get_image($this->helper->get('plugin_dir') . 'img/graph.svg'); |
| 131 |
$pages[$page_key]['elements'][$element_key]['properties']['preview'] = '1'; |
| 132 |
break; |
| 133 |
case 'e2pdf-html': |
| 134 |
if (isset($pages[$page_key]['elements'][$element_key]['properties']['hide_page_if_empty'])) { |
| 135 |
unset($pages[$page_key]['elements'][$element_key]['properties']['hide_page_if_empty']); |
| 136 |
} |
| 137 |
if (isset($pages[$page_key]['elements'][$element_key]['properties']['hide_if_empty'])) { |
| 138 |
unset($pages[$page_key]['elements'][$element_key]['properties']['hide_if_empty']); |
| 139 |
} |
| 140 |
if (isset($element['properties']['nl2br']) && $element['properties']['nl2br']) { |
| 141 |
$element['value'] = nl2br($element['value']); |
| 142 |
} |
| 143 |
if (isset($element['properties']['html_worker']) && $element['properties']['html_worker']) { |
| 144 |
$element['value'] = $this->helper->load('properties')->html_worker( |
| 145 |
$element['value'] |
| 146 |
); |
| 147 |
} |
| 148 |
$pages[$page_key]['elements'][$element_key]['value'] = $this->helper->load('filter')->filter_html_tags( |
| 149 |
$element['value'] |
| 150 |
); |
| 151 |
break; |
| 152 |
case 'e2pdf-page-number': |
| 153 |
if (isset($element['properties']['html_worker']) && $element['properties']['html_worker']) { |
| 154 |
$element['value'] = $this->helper->load('properties')->html_worker( |
| 155 |
$element['value'] |
| 156 |
); |
| 157 |
} |
| 158 |
$pages[$page_key]['elements'][$element_key]['value'] = $this->helper->load('filter')->filter_html_tags( |
| 159 |
$element['value'] |
| 160 |
); |
| 161 |
break; |
| 162 |
default: |
| 163 |
break; |
| 164 |
} |
| 165 |
} |
| 166 |
} |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
$template->set('pages', $pages); |
| 171 |
$request = $template->render(); |
| 172 |
|
| 173 |
if (isset($request['error'])) { |
| 174 |
$this->add_notification('error', $request['error']); |
| 175 |
$this->render('blocks', 'notifications'); |
| 176 |
} else { |
| 177 |
$this->download_response($template->get('format'), $request['file'], $template->get_name(), 'inline'); |
| 178 |
exit; |
| 179 |
} |
| 180 |
} else { |
| 181 |
$this->add_notification('error', __('Something went wrong!', 'e2pdf')); |
| 182 |
$this->render('blocks', 'notifications'); |
| 183 |
} |
| 184 |
} else { |
| 185 |
$this->redirect( |
| 186 |
$this->helper->get_url( |
| 187 |
[ |
| 188 |
'page' => 'e2pdf', |
| 189 |
] |
| 190 |
) |
| 191 |
); |
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
/** |
| 196 |
* @url admin.php?page=e2pdf-templates&action=preview |
| 197 |
*/ |
| 198 |
public function preview_action() { |
| 199 |
$preview = array(); |
| 200 |
if ($this->post->get('preview')) { |
| 201 |
$preview = json_decode(stripslashes($this->post->get('preview')), true); |
| 202 |
} |
| 203 |
if (empty($preview)) { |
| 204 |
$this->close_tab_response(); |
| 205 |
} else { |
| 206 |
$data = $preview; |
| 207 |
$pages = $preview['pages']; |
| 208 |
unset($preview['pages']); |
| 209 |
if (wp_verify_nonce(isset($preview['_wpnonce']) ? $preview['_wpnonce'] : '', 'e2pdf_templates')) { |
| 210 |
$template = new Model_E2pdf_Template(); |
| 211 |
foreach ($data as $key => $value) { |
| 212 |
$template->set($key, $value); |
| 213 |
} |
| 214 |
$template->set('uid', $template->get('uid', true)); |
| 215 |
$template->set('activated', $template->get('activated', true)); |
| 216 |
|
| 217 |
$preview_pages = array(); |
| 218 |
foreach ($pages as $page_key => $page) { |
| 219 |
$new_page = new Model_E2pdf_Page(); |
| 220 |
foreach ($page as $page_set_key => $page_set_value) { |
| 221 |
$new_page->set($page_set_key, $page_set_value); |
| 222 |
} |
| 223 |
$new_page->set('page_id', $page_key); |
| 224 |
|
| 225 |
$elements = array(); |
| 226 |
foreach ($page['elements'] as $element_key => $element) { |
| 227 |
if (isset($element['type'])) { |
| 228 |
switch ($element['type']) { |
| 229 |
case 'e2pdf-image': |
| 230 |
if (isset($element['properties']['quality']) && $element['properties']['quality']) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf |
| 231 |
} else { |
| 232 |
$element['properties']['quality'] = $template->get('optimization'); |
| 233 |
$pages[$page_key]['elements'][$element_key]['properties']['quality'] = $template->get('optimization'); |
| 234 |
} |
| 235 |
if ($image = $this->helper->load('image')->get_image($element['value'], null, $element)) { |
| 236 |
$element['value'] = $image; |
| 237 |
} else { |
| 238 |
$element['value'] = $this->helper->load('image')->get_image($this->helper->get('plugin_dir') . 'img/upload.svg'); |
| 239 |
$element['properties']['preview'] = '1'; |
| 240 |
} |
| 241 |
break; |
| 242 |
case 'e2pdf-signature': |
| 243 |
$esig = isset($element['properties']['esig']) && $element['properties']['esig'] ? true : false; |
| 244 |
if (!$esig) { |
| 245 |
if ($image = $this->helper->load('image')->get_image($element['value'])) { |
| 246 |
$element['value'] = $image; |
| 247 |
} else { |
| 248 |
$element['value'] = $this->helper->load('image')->get_image($this->helper->get('plugin_dir') . 'img/signature.svg'); |
| 249 |
$element['properties']['preview'] = '1'; |
| 250 |
} |
| 251 |
} |
| 252 |
break; |
| 253 |
case 'e2pdf-qrcode': |
| 254 |
$element['type'] = 'e2pdf-image'; |
| 255 |
$element['value'] = $this->helper->load('image')->get_image($this->helper->get('plugin_dir') . 'img/qrcode.svg'); |
| 256 |
$element['properties']['preview'] = '1'; |
| 257 |
break; |
| 258 |
case 'e2pdf-barcode': |
| 259 |
$element['type'] = 'e2pdf-image'; |
| 260 |
$element['value'] = $this->helper->load('image')->get_image($this->helper->get('plugin_dir') . 'img/barcode.svg'); |
| 261 |
$element['properties']['preview'] = '1'; |
| 262 |
break; |
| 263 |
case 'e2pdf-graph': |
| 264 |
$element['type'] = 'e2pdf-image'; |
| 265 |
$element['value'] = $this->helper->load('image')->get_image($this->helper->get('plugin_dir') . 'img/graph.svg'); |
| 266 |
$element['properties']['preview'] = '1'; |
| 267 |
break; |
| 268 |
case 'e2pdf-html': |
| 269 |
if (isset($element['properties']['hide_page_if_empty'])) { |
| 270 |
unset($element['properties']['hide_page_if_empty']); |
| 271 |
} |
| 272 |
if (isset($element['properties']['hide_if_empty'])) { |
| 273 |
unset($element['properties']['hide_if_empty']); |
| 274 |
} |
| 275 |
if (isset($element['properties']['nl2br']) && $element['properties']['nl2br']) { |
| 276 |
$element['value'] = nl2br($element['value']); |
| 277 |
} |
| 278 |
if (isset($element['properties']['html_worker']) && $element['properties']['html_worker']) { |
| 279 |
$element['value'] = $this->helper->load('properties')->html_worker( |
| 280 |
$element['value'] |
| 281 |
); |
| 282 |
} |
| 283 |
$element['value'] = $this->helper->load('filter')->filter_html_tags( |
| 284 |
$element['value'] |
| 285 |
); |
| 286 |
break; |
| 287 |
case 'e2pdf-page-number': |
| 288 |
$element['value'] = str_replace(array('[e2pdf-page-number]', '[e2pdf-page-total]'), array('e2pdf-page-number', 'e2pdf-page-total'), $element['value']); |
| 289 |
if (isset($element['properties']['html_worker']) && $element['properties']['html_worker']) { |
| 290 |
$element['value'] = $this->helper->load('properties')->html_worker( |
| 291 |
$element['value'] |
| 292 |
); |
| 293 |
} |
| 294 |
$element['value'] = $this->helper->load('filter')->filter_html_tags( |
| 295 |
$element['value'] |
| 296 |
); |
| 297 |
break; |
| 298 |
default: |
| 299 |
break; |
| 300 |
} |
| 301 |
} |
| 302 |
|
| 303 |
$new_element = new Model_E2pdf_Element(); |
| 304 |
foreach ($element as $element_set_key => $element_set_value) { |
| 305 |
$new_element->set($element_set_key, $element_set_value); |
| 306 |
} |
| 307 |
|
| 308 |
if (isset($element['properties'])) { |
| 309 |
$element_properties = $element['properties']; |
| 310 |
} else { |
| 311 |
$element_properties = array(); |
| 312 |
} |
| 313 |
$new_element->set('properties', $element_properties); |
| 314 |
$elements[] = $new_element->get_element(); |
| 315 |
} |
| 316 |
|
| 317 |
$new_page->set('elements', $elements); |
| 318 |
$preview_pages[] = $new_page->get_page(); |
| 319 |
} |
| 320 |
|
| 321 |
$template->set('pages', $preview_pages); |
| 322 |
$template->load_fonts(); |
| 323 |
|
| 324 |
$type = isset($_GET['type']) ? sanitize_text_field(wp_unslash($_GET['type'])) : false; |
| 325 |
if ($type == 'php') { |
| 326 |
$request = $template->render('php'); |
| 327 |
if (isset($request['error'])) { |
| 328 |
$this->add_notification('error', $request['error']); |
| 329 |
$this->render('blocks', 'notifications'); |
| 330 |
} else { |
| 331 |
$this->download_response('php', $request['file'], 'template'); |
| 332 |
exit; |
| 333 |
} |
| 334 |
} else { |
| 335 |
$request = $template->render(); |
| 336 |
if (isset($request['error'])) { |
| 337 |
$this->add_notification('error', $request['error']); |
| 338 |
$this->render('blocks', 'notifications'); |
| 339 |
} else { |
| 340 |
$this->download_response($template->get('format'), $request['file'], $template->get_name(), 'inline', false, true); |
| 341 |
exit; |
| 342 |
} |
| 343 |
} |
| 344 |
} else { |
| 345 |
wp_die($this->message('wp_verify_nonce_error')); |
| 346 |
} |
| 347 |
} |
| 348 |
} |
| 349 |
|
| 350 |
/** |
| 351 |
* @url admin.php?page=e2pdf-templates&action=create |
| 352 |
*/ |
| 353 |
public function create_action() { |
| 354 |
$template = new Model_E2pdf_Template(); |
| 355 |
$this->load_metaboxes(); |
| 356 |
$this->load_scripts(); |
| 357 |
$this->load_styles(); |
| 358 |
$this->view('license', $this->helper->get('license')); |
| 359 |
$this->view('template', $template); |
| 360 |
} |
| 361 |
|
| 362 |
/** |
| 363 |
* @url admin.php?page=e2pdf-templates&action=edit&id=$id |
| 364 |
*/ |
| 365 |
public function edit_action() { |
| 366 |
if ($this->get->get('id')) { |
| 367 |
$template = new Model_E2pdf_Template(); |
| 368 |
$revision_id = (int) $this->get->get('revision_id'); |
| 369 |
if ($template->load($this->get->get('id'), true, $revision_id)) { |
| 370 |
if (is_array($this->helper->get('license')->get('activated_templates'))) { |
| 371 |
if ($template->get('activated') && !in_array($template->get('uid'), $this->helper->get('license')->get('activated_templates'))) { |
| 372 |
$template->deactivate(); |
| 373 |
} elseif (!$template->get('activated') && in_array($template->get('uid'), $this->helper->get('license')->get('activated_templates'))) { |
| 374 |
$template->activate(); |
| 375 |
} |
| 376 |
} |
| 377 |
$this->view('license', $this->helper->get('license')); |
| 378 |
$this->view('template', $template); |
| 379 |
$this->load_metaboxes(); |
| 380 |
$this->load_scripts(); |
| 381 |
$this->load_styles($template->get('extension')); |
| 382 |
} else { |
| 383 |
$this->add_notification('error', __('Something went wrong!', 'e2pdf')); |
| 384 |
$this->render('blocks', 'notifications'); |
| 385 |
} |
| 386 |
} else { |
| 387 |
$this->redirect( |
| 388 |
$this->helper->get_url( |
| 389 |
[ |
| 390 |
'page' => 'e2pdf-templates', |
| 391 |
] |
| 392 |
) |
| 393 |
); |
| 394 |
} |
| 395 |
} |
| 396 |
|
| 397 |
/** |
| 398 |
* @url admin.php?page=e2pdf-templates&action=trash&id=$id |
| 399 |
*/ |
| 400 |
public function trash_action() { |
| 401 |
$notification = ''; |
| 402 |
if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) { |
| 403 |
if ($this->get->get('id')) { |
| 404 |
$this->trash_template($this->get->get('id')); |
| 405 |
$notification = $this->add_notification('update', __('Template Trashed', 'e2pdf')); |
| 406 |
} |
| 407 |
} else { |
| 408 |
wp_die($this->message('wp_verify_nonce_error')); |
| 409 |
} |
| 410 |
$this->redirect( |
| 411 |
$this->helper->get_url( |
| 412 |
[ |
| 413 |
'page' => 'e2pdf-templates', |
| 414 |
'status' => $this->get->get('status'), |
| 415 |
'orderby' => $this->get->get('orderby'), |
| 416 |
'order' => $this->get->get('order'), |
| 417 |
's' => $this->get->get('s'), |
| 418 |
'notification' => $notification, |
| 419 |
] |
| 420 |
) |
| 421 |
); |
| 422 |
} |
| 423 |
|
| 424 |
/** |
| 425 |
* @url admin.php?page=e2pdf-templates&action=restore&id=$id&status=$status |
| 426 |
*/ |
| 427 |
public function restore_action() { |
| 428 |
$notification = ''; |
| 429 |
if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) { |
| 430 |
if ($this->get->get('id')) { |
| 431 |
$this->restore_template($this->get->get('id')); |
| 432 |
$notification = $this->add_notification('update', __('Template Restored', 'e2pdf')); |
| 433 |
} |
| 434 |
} else { |
| 435 |
wp_die($this->message('wp_verify_nonce_error')); |
| 436 |
} |
| 437 |
$this->redirect( |
| 438 |
$this->helper->get_url( |
| 439 |
[ |
| 440 |
'page' => 'e2pdf-templates', |
| 441 |
'status' => $this->get->get('status'), |
| 442 |
'orderby' => $this->get->get('orderby'), |
| 443 |
'order' => $this->get->get('order'), |
| 444 |
's' => $this->get->get('s'), |
| 445 |
'notification' => $notification, |
| 446 |
] |
| 447 |
) |
| 448 |
); |
| 449 |
} |
| 450 |
|
| 451 |
/** |
| 452 |
* @url admin.php?page=e2pdf-templates&action=delete&id=$id&status=$status |
| 453 |
*/ |
| 454 |
public function delete_action() { |
| 455 |
$notification = ''; |
| 456 |
if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) { |
| 457 |
if ($this->get->get('id')) { |
| 458 |
$this->delete_template($this->get->get('id')); |
| 459 |
$notification = $this->add_notification('update', __('Template Deleted', 'e2pdf')); |
| 460 |
} |
| 461 |
} else { |
| 462 |
wp_die($this->message('wp_verify_nonce_error')); |
| 463 |
} |
| 464 |
|
| 465 |
$this->redirect( |
| 466 |
$this->helper->get_url( |
| 467 |
[ |
| 468 |
'page' => 'e2pdf-templates', |
| 469 |
'status' => $this->get->get('status'), |
| 470 |
'orderby' => $this->get->get('orderby'), |
| 471 |
'order' => $this->get->get('order'), |
| 472 |
's' => $this->get->get('s'), |
| 473 |
'notification' => $notification, |
| 474 |
] |
| 475 |
) |
| 476 |
); |
| 477 |
} |
| 478 |
|
| 479 |
/** |
| 480 |
* @url admin.php?page=e2pdf-templates&action=duplicate&id=$id |
| 481 |
*/ |
| 482 |
public function duplicate_action() { |
| 483 |
$notification = ''; |
| 484 |
if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) { |
| 485 |
if ($this->get->get('id')) { |
| 486 |
$this->duplicate_template($this->get->get('id')); |
| 487 |
$notification = $this->add_notification('update', __('Template Duplicated', 'e2pdf')); |
| 488 |
} |
| 489 |
} else { |
| 490 |
wp_die($this->message('wp_verify_nonce_error')); |
| 491 |
} |
| 492 |
$this->redirect( |
| 493 |
$this->helper->get_url( |
| 494 |
[ |
| 495 |
'page' => 'e2pdf-templates', |
| 496 |
'status' => $this->get->get('status'), |
| 497 |
'orderby' => $this->get->get('orderby'), |
| 498 |
'order' => $this->get->get('order'), |
| 499 |
's' => $this->get->get('s'), |
| 500 |
'notification' => $notification, |
| 501 |
] |
| 502 |
) |
| 503 |
); |
| 504 |
} |
| 505 |
|
| 506 |
/** |
| 507 |
* @url admin.php?page=e2pdf-templates&action=import |
| 508 |
*/ |
| 509 |
public function import_action() { |
| 510 |
if ($this->post->get('_wpnonce')) { |
| 511 |
|
| 512 |
if (!wp_verify_nonce($this->post->get('_wpnonce'), 'e2pdf_templates')) { |
| 513 |
wp_die($this->message('wp_verify_nonce_error')); |
| 514 |
} |
| 515 |
|
| 516 |
$errors = array(); |
| 517 |
$import = $this->files->get('template'); |
| 518 |
$name = $import['name']; |
| 519 |
$tmp = $import['tmp_name']; |
| 520 |
$ext = strtolower(pathinfo($name, PATHINFO_EXTENSION)); |
| 521 |
if (!$tmp) { |
| 522 |
$this->add_notification('error', __('Choose Template file to upload', 'e2pdf')); |
| 523 |
} elseif ($import['error']) { |
| 524 |
$this->add_notification('error', $import['error']); |
| 525 |
} elseif (!in_array($ext, array('xml'))) { |
| 526 |
$this->add_notification('error', sprintf(__('Only %s files allowed', 'e2pdf'), '.xml')); |
| 527 |
} elseif ($import['type'] != 'text/xml') { |
| 528 |
$this->add_notification('error', __('Invalid Type', 'e2pdf')); |
| 529 |
} else { |
| 530 |
$options = $this->post->get('options'); |
| 531 |
$xml = simplexml_load_file($import['tmp_name'], 'SimpleXMLElement', LIBXML_PARSEHUGE); |
| 532 |
if (!isset($xml->template->pages)) { |
| 533 |
$this->add_notification('error', __('The file is not a valid E2Pdf Template', 'e2pdf')); |
| 534 |
} else { |
| 535 |
$pages = $this->helper->load('convert')->unserialize(base64_decode((string) $xml->template->pages)); |
| 536 |
if (is_array($pages)) { |
| 537 |
foreach ($pages as $page_key => $page) { |
| 538 |
if (isset($page['elements']) && !empty($page['elements'])) { |
| 539 |
foreach ($page['elements'] as $element_key => $element) { |
| 540 |
if ($element['type'] === 'e2pdf-image' && isset($element['base64']) && $element['base64']) { |
| 541 |
if ($options['images']) { |
| 542 |
$image = base64_decode($element['base64']); |
| 543 |
$file_name = basename($element['value']); |
| 544 |
$upload_file = wp_upload_bits($file_name, null, $image); |
| 545 |
if (!$upload_file['error']) { |
| 546 |
$wp_filetype = wp_check_filetype($file_name, null); |
| 547 |
$attachment = array( |
| 548 |
'post_mime_type' => $wp_filetype['type'], |
| 549 |
'post_parent' => 0, |
| 550 |
'post_title' => preg_replace('/\.[^.]+$/', '', $file_name), |
| 551 |
'post_content' => '', |
| 552 |
'post_status' => 'inherit', |
| 553 |
); |
| 554 |
$attachment_id = wp_insert_attachment($attachment, $upload_file['file'], 0); |
| 555 |
if (!is_wp_error($attachment_id)) { |
| 556 |
require_once ABSPATH . 'wp-admin/includes/image.php'; |
| 557 |
$attachment_data = wp_generate_attachment_metadata($attachment_id, $upload_file['file']); |
| 558 |
wp_update_attachment_metadata($attachment_id, $attachment_data); |
| 559 |
$pages[$page_key]['elements'][$element_key]['value'] = $upload_file['url']; |
| 560 |
} |
| 561 |
} |
| 562 |
} |
| 563 |
unset($pages[$page_key]['elements'][$element_key]['base64']); |
| 564 |
} |
| 565 |
} |
| 566 |
} |
| 567 |
} |
| 568 |
} |
| 569 |
|
| 570 |
$template = new Model_E2pdf_Template(); |
| 571 |
if ($options['overwrite']) { |
| 572 |
if ($options['overwrite'] == '1' && $options['template_id']) { |
| 573 |
$template->load((int) $options['template_id']); |
| 574 |
} elseif ($options['overwrite'] == '2' && $options['custom_template_id']) { |
| 575 |
if (!$template->load((int) $options['custom_template_id'])) { |
| 576 |
$template->set('TMP_ID', (int) $options['custom_template_id']); |
| 577 |
} |
| 578 |
} elseif ($options['overwrite'] == '3') { |
| 579 |
if (!$template->load((int) $xml->template->ID)) { |
| 580 |
$template->set('TMP_ID', (int) $xml->template->ID); |
| 581 |
} |
| 582 |
} |
| 583 |
} |
| 584 |
$template->set('title', (string) $xml->template->title); |
| 585 |
$template->set('flatten', (string) $xml->template->flatten); |
| 586 |
if (isset($xml->template->tab_order)) { |
| 587 |
$template->set('tab_order', (string) $xml->template->tab_order); |
| 588 |
} |
| 589 |
$template->set('compression', (string) $xml->template->compression); |
| 590 |
if (isset($xml->template->optimization)) { |
| 591 |
$template->set('optimization', (string) $xml->template->optimization); |
| 592 |
} |
| 593 |
$template->set('appearance', (string) $xml->template->appearance); |
| 594 |
$template->set('width', (string) $xml->template->width); |
| 595 |
$template->set('height', (string) $xml->template->height); |
| 596 |
$template->set('extension', (string) $xml->template->extension); |
| 597 |
if (isset($xml->template->item)) { |
| 598 |
$template->set('item', (string) $xml->template->item); |
| 599 |
} |
| 600 |
if (isset($xml->template->item1)) { |
| 601 |
$template->set('item1', (string) $xml->template->item1); |
| 602 |
} |
| 603 |
if (isset($xml->template->item2)) { |
| 604 |
$template->set('item2', (string) $xml->template->item2); |
| 605 |
} |
| 606 |
|
| 607 |
$fpro2pdf_backup = false; |
| 608 |
if ($xml->source) { |
| 609 |
if ((string) $xml->source == 'fpro2pdf') { |
| 610 |
$fpro2pdf_backup = true; |
| 611 |
} |
| 612 |
} |
| 613 |
|
| 614 |
$extension = new Model_E2pdf_Extension(); |
| 615 |
$extension->load($template->get('extension')); |
| 616 |
if ($options['item'] && $xml->item && !$fpro2pdf_backup) { |
| 617 |
$extension->set('item', $template->get('item')); |
| 618 |
if ($template->get('item') == '-2') { |
| 619 |
$extension->set('item1', $template->get('item1')); |
| 620 |
$extension->set('item2', $template->get('item2')); |
| 621 |
} |
| 622 |
|
| 623 |
$updated_items = $extension->import($xml->item, $options); |
| 624 |
if ($updated_items) { |
| 625 |
if (isset($updated_items['errors'])) { |
| 626 |
$errors = array_merge($errors, $updated_items['errors']); |
| 627 |
} else { |
| 628 |
if ($template->get('item') == '-2') { |
| 629 |
if ($template->get('item1') && isset($updated_items[$template->get('item1')])) { |
| 630 |
$item1 = $updated_items[$template->get('item1')]; |
| 631 |
$template->set('item1', $item1); |
| 632 |
$extension->set('item1', $item1); |
| 633 |
} else { |
| 634 |
$template->set('item1', ''); |
| 635 |
$extension->set('item1', ''); |
| 636 |
} |
| 637 |
if ($template->get('item2') && isset($updated_items[$template->get('item2')])) { |
| 638 |
$item2 = $updated_items[$template->get('item2')]; |
| 639 |
$template->set('item2', $item2); |
| 640 |
$extension->set('item2', $item2); |
| 641 |
} else { |
| 642 |
$template->set('item2', ''); |
| 643 |
$extension->set('item2', ''); |
| 644 |
} |
| 645 |
} else { |
| 646 |
if (isset($updated_items[$template->get('item')])) { |
| 647 |
$item = $updated_items[$template->get('item')]; |
| 648 |
$template->set('item', $item); |
| 649 |
$extension->set('item', $item); |
| 650 |
} else { |
| 651 |
$template->set('item', ''); |
| 652 |
$extension->set('item', ''); |
| 653 |
} |
| 654 |
} |
| 655 |
} |
| 656 |
} |
| 657 |
} |
| 658 |
|
| 659 |
$template->set('format', (string) $xml->template->format); |
| 660 |
if (isset($xml->template->resample)) { |
| 661 |
$template->set('resample', (string) $xml->template->resample); |
| 662 |
} |
| 663 |
$template->set( |
| 664 |
'dataset_title', |
| 665 |
apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->dataset_title, $options, $xml, $template, $extension) |
| 666 |
); |
| 667 |
if (isset($xml->template->dataset_title1)) { |
| 668 |
$template->set( |
| 669 |
'dataset_title1', |
| 670 |
apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->dataset_title1, $options, $xml, $template, $extension) |
| 671 |
); |
| 672 |
} |
| 673 |
if (isset($xml->template->dataset_title2)) { |
| 674 |
$template->set( |
| 675 |
'dataset_title2', |
| 676 |
apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->dataset_title2, $options, $xml, $template, $extension) |
| 677 |
); |
| 678 |
} |
| 679 |
$template->set( |
| 680 |
'button_title', |
| 681 |
apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->button_title, $options, $xml, $template, $extension) |
| 682 |
); |
| 683 |
if (isset($xml->template->dpdf)) { |
| 684 |
$template->set( |
| 685 |
'dpdf', |
| 686 |
apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->dpdf, $options, $xml, $template, $extension) |
| 687 |
); |
| 688 |
} |
| 689 |
if (isset($xml->template->attachments)) { |
| 690 |
$template->set( |
| 691 |
'attachments', |
| 692 |
apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->attachments, $options, $xml, $template, $extension) |
| 693 |
); |
| 694 |
} |
| 695 |
$template->set('inline', (string) $xml->template->inline); |
| 696 |
$template->set('auto', (string) $xml->template->auto); |
| 697 |
if (isset($xml->template->rtl)) { |
| 698 |
$template->set('rtl', (string) $xml->template->rtl); |
| 699 |
} |
| 700 |
if (isset($xml->template->font_processor)) { |
| 701 |
$template->set('font_processor', (string) $xml->template->font_processor); |
| 702 |
} |
| 703 |
$template->set( |
| 704 |
'name', |
| 705 |
apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->name, $options, $xml, $template, $extension) |
| 706 |
); |
| 707 |
if (isset($xml->template->savename)) { |
| 708 |
$template->set( |
| 709 |
'savename', |
| 710 |
apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->savename, $options, $xml, $template, $extension) |
| 711 |
); |
| 712 |
} |
| 713 |
$template->set( |
| 714 |
'password', |
| 715 |
apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->password, $options, $xml, $template, $extension) |
| 716 |
); |
| 717 |
if (isset($xml->template->owner_password)) { |
| 718 |
$template->set( |
| 719 |
'owner_password', |
| 720 |
apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->owner_password, $options, $xml, $template, $extension) |
| 721 |
); |
| 722 |
} |
| 723 |
if (isset($xml->template->permissions)) { |
| 724 |
$template->set('permissions', $this->helper->load('convert')->unserialize(base64_decode((string) $xml->template->permissions))); |
| 725 |
} else { |
| 726 |
$template->set('permissions', array('printing')); |
| 727 |
} |
| 728 |
if (isset($xml->template->hooks)) { |
| 729 |
$template->set( |
| 730 |
'hooks', |
| 731 |
(string) $xml->template->hooks |
| 732 |
); |
| 733 |
} |
| 734 |
|
| 735 |
$template->set( |
| 736 |
'meta_title', |
| 737 |
apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->meta_title, $options, $xml, $template, $extension) |
| 738 |
); |
| 739 |
$template->set( |
| 740 |
'meta_subject', |
| 741 |
apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->meta_subject, $options, $xml, $template, $extension) |
| 742 |
); |
| 743 |
$template->set( |
| 744 |
'meta_author', |
| 745 |
apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->meta_author, $options, $xml, $template, $extension) |
| 746 |
); |
| 747 |
$template->set( |
| 748 |
'meta_keywords', |
| 749 |
apply_filters('e2pdf_controller_templates_import_replace_shortcodes', (string) $xml->template->meta_keywords, $options, $xml, $template, $extension) |
| 750 |
); |
| 751 |
if (isset($xml->template->lang_code)) { |
| 752 |
$template->set('lang_code', (string) $xml->template->lang_code); |
| 753 |
} |
| 754 |
$template->set('font', (string) $xml->template->font); |
| 755 |
$template->set('font_size', (string) $xml->template->font_size); |
| 756 |
$template->set('font_color', (string) $xml->template->font_color); |
| 757 |
$template->set('line_height', (string) $xml->template->line_height); |
| 758 |
if (isset($xml->template->text_align)) { |
| 759 |
$template->set('text_align', (string) $xml->template->text_align); |
| 760 |
} |
| 761 |
$template->set('fonts', $this->helper->load('convert')->unserialize(base64_decode((string) $xml->template->fonts))); |
| 762 |
$template->set( |
| 763 |
'properties', |
| 764 |
apply_filters('e2pdf_controller_templates_import_properties', $this->helper->load('convert')->unserialize(base64_decode((string) $xml->template->properties)), $options, $xml, $template, $extension) |
| 765 |
); |
| 766 |
$template->set( |
| 767 |
'actions', |
| 768 |
apply_filters('e2pdf_controller_templates_import_actions', $this->helper->load('convert')->unserialize(base64_decode((string) $xml->template->actions)), $options, $xml, $template, $extension) |
| 769 |
); |
| 770 |
$template->set( |
| 771 |
'pages', |
| 772 |
apply_filters('e2pdf_controller_templates_import_pages', $pages, $options, $xml, $template, $extension) |
| 773 |
); |
| 774 |
|
| 775 |
if ($options['fonts'] && $xml->fonts) { |
| 776 |
$model_e2pdf_font = new Model_E2pdf_Font(); |
| 777 |
$fonts = $model_e2pdf_font->get_fonts(); |
| 778 |
|
| 779 |
if ($xml->fonts) { |
| 780 |
foreach ($xml->fonts->children() as $key => $font) { |
| 781 |
$title = (string) $font->title; |
| 782 |
$name = (string) $font->name; |
| 783 |
$value = (string) $font->value; |
| 784 |
|
| 785 |
if ($title == 'Noto Sans' && $name == 'NotoSans-Regular.ttf') { |
| 786 |
$title = 'Noto Sans Regular'; |
| 787 |
} |
| 788 |
|
| 789 |
$exist = array_search($title, $fonts); |
| 790 |
if (!$exist) { |
| 791 |
if (!file_exists($this->helper->get('fonts_dir') . $name)) { |
| 792 |
$f_name = $name; |
| 793 |
} else { |
| 794 |
$i = 0; |
| 795 |
do { |
| 796 |
$f_name = $i . '_' . $name; |
| 797 |
$i++; |
| 798 |
} while (file_exists($this->helper->get('fonts_dir') . $f_name)); |
| 799 |
} |
| 800 |
$font_ext = strtolower(pathinfo($f_name, PATHINFO_EXTENSION)); |
| 801 |
if (in_array($font_ext, $model_e2pdf_font->get_allowed_extensions())) { |
| 802 |
file_put_contents($this->helper->get('fonts_dir') . $f_name, base64_decode($value), LOCK_EX); |
| 803 |
} |
| 804 |
} |
| 805 |
} |
| 806 |
} |
| 807 |
} |
| 808 |
|
| 809 |
if ($xml->pdf && $xml->pdf->source) { |
| 810 |
|
| 811 |
$pdf_name = md5(time()); |
| 812 |
$pdf_dir = $this->helper->get('pdf_dir') . $pdf_name . '/'; |
| 813 |
$pdf_images_dir = $pdf_dir . 'images/'; |
| 814 |
|
| 815 |
$this->helper->create_dir($pdf_dir); |
| 816 |
$this->helper->create_dir($pdf_images_dir); |
| 817 |
|
| 818 |
$pdf_source = (string) $xml->pdf->source; |
| 819 |
file_put_contents($pdf_dir . $pdf_name . '.pdf', base64_decode($pdf_source), LOCK_EX); |
| 820 |
|
| 821 |
if ($xml->pdf->images) { |
| 822 |
foreach ($xml->pdf->images->children() as $key => $image) { |
| 823 |
$page_id = (string) $image->page_id; |
| 824 |
$image_source = (string) $image->source; |
| 825 |
file_put_contents($pdf_dir . 'images/' . $page_id . '.png', base64_decode($image_source), LOCK_EX); |
| 826 |
} |
| 827 |
} |
| 828 |
$template->set('pdf', $pdf_name); |
| 829 |
} |
| 830 |
|
| 831 |
if (empty($errors)) { |
| 832 |
$template->save(true); |
| 833 |
if ($options['item']) { |
| 834 |
$extension->after_import((string) $xml->template->ID, $template->get('ID')); |
| 835 |
} |
| 836 |
$template->activate(); |
| 837 |
if ($template->get('ID')) { |
| 838 |
$this->add_notification( |
| 839 |
'update', sprintf( |
| 840 |
__('Template Imported: <a target="_blank" href="%1$s">View</a> | <a target="_blank" href="%2$s">Edit</a>', 'e2pdf'), |
| 841 |
$this->helper->get_url( |
| 842 |
[ |
| 843 |
'page' => 'e2pdf-templates', |
| 844 |
'action' => 'view', |
| 845 |
'id' => $template->get('ID') |
| 846 |
] |
| 847 |
), |
| 848 |
$this->helper->get_url( |
| 849 |
[ |
| 850 |
'page' => 'e2pdf-templates', |
| 851 |
'action' => 'edit', |
| 852 |
'id' => $template->get('ID') |
| 853 |
] |
| 854 |
) |
| 855 |
) |
| 856 |
); |
| 857 |
} else { |
| 858 |
$this->add_notification('error', __('Something went wrong!', 'e2pdf')); |
| 859 |
} |
| 860 |
} else { |
| 861 |
foreach ($errors as $key => $error) { |
| 862 |
$this->add_notification('error', $error); |
| 863 |
} |
| 864 |
} |
| 865 |
} |
| 866 |
unlink($import['tmp_name']); |
| 867 |
} |
| 868 |
} |
| 869 |
|
| 870 |
$this->view('import_disabled', false); |
| 871 |
if (!$this->helper->load('xml')->check()) { |
| 872 |
$this->add_notification('error', sprintf(__('The PHP %s extension is required', 'e2pdf'), 'SimpleXml')); |
| 873 |
$this->view('import_disabled', true); |
| 874 |
} |
| 875 |
|
| 876 |
global $wpdb; |
| 877 |
|
| 878 |
$order_condition = array( |
| 879 |
'orderby' => 'ID', |
| 880 |
'order' => 'desc', |
| 881 |
); |
| 882 |
$orderby = $this->helper->load('db')->prepare_orderby($order_condition); |
| 883 |
$tpls = $wpdb->get_results($wpdb->prepare('SELECT `ID`, `title` FROM `' . (new Model_E2pdf_Template())->get_table() . '`' . $orderby . '')); |
| 884 |
$templates = [ |
| 885 |
'' => __('--- Select ---', 'e2pdf') |
| 886 |
]; |
| 887 |
if (!empty($tpls)) { |
| 888 |
foreach ($tpls as $tpl) { |
| 889 |
$templates[$tpl->ID] = $tpl->ID . ' | ' . $tpl->title; |
| 890 |
} |
| 891 |
} |
| 892 |
|
| 893 |
$options = array( |
| 894 |
'overwrite' => [ |
| 895 |
'name' => __('Overwrite Options', 'e2pdf'), |
| 896 |
'options' => [ |
| 897 |
[ |
| 898 |
'name' => __('Overwrite Template by ID', 'e2pdf'), |
| 899 |
'key' => 'options[overwrite]', |
| 900 |
'value' => '', |
| 901 |
'default_value' => '', |
| 902 |
'type' => 'select', |
| 903 |
'options' => [ |
| 904 |
'' => __('Create New E2Pdf Template ID', 'e2pdf'), |
| 905 |
'1' => __('Existing Template ID', 'e2pdf'), |
| 906 |
'2' => __('Custom Template ID', 'e2pdf'), |
| 907 |
'3' => __('Backup Template ID', 'e2pdf'), |
| 908 |
] |
| 909 |
], |
| 910 |
[ |
| 911 |
'name' => __('Template ID', 'e2pdf'), |
| 912 |
'key' => 'options[template_id]', |
| 913 |
'value' => '', |
| 914 |
'default_value' => '', |
| 915 |
'type' => 'select', |
| 916 |
'options' => $templates, |
| 917 |
'li' => array( |
| 918 |
'class' => 'e2pdf-import-overwrite-option e2pdf-hide', |
| 919 |
), |
| 920 |
], |
| 921 |
[ |
| 922 |
'name' => __('Template ID', 'e2pdf'), |
| 923 |
'key' => 'options[custom_template_id]', |
| 924 |
'value' => '', |
| 925 |
'default_value' => '', |
| 926 |
'type' => 'text', |
| 927 |
'class' => 'e2pdf-numbers', |
| 928 |
'placeholder' => __('Template ID', 'e2pdf'), |
| 929 |
'li' => array( |
| 930 |
'class' => 'e2pdf-import-overwrite-option e2pdf-hide', |
| 931 |
), |
| 932 |
], |
| 933 |
], |
| 934 |
], |
| 935 |
'template' => array( |
| 936 |
'name' => __('Template Options', 'e2pdf'), |
| 937 |
'options' => array( |
| 938 |
array( |
| 939 |
'name' => __('Import Images', 'e2pdf'), |
| 940 |
'key' => 'options[images]', |
| 941 |
'value' => '1', |
| 942 |
'default_value' => '0', |
| 943 |
'type' => 'checkbox', |
| 944 |
'placeholder' => '', |
| 945 |
), |
| 946 |
array( |
| 947 |
'name' => __('Import Fonts', 'e2pdf'), |
| 948 |
'key' => 'options[fonts]', |
| 949 |
'value' => '1', |
| 950 |
'default_value' => '0', |
| 951 |
'type' => 'checkbox', |
| 952 |
'placeholder' => '', |
| 953 |
), |
| 954 |
), |
| 955 |
), |
| 956 |
'item' => array( |
| 957 |
'name' => __('Connection Options', 'e2pdf'), |
| 958 |
'options' => array( |
| 959 |
array( |
| 960 |
'name' => __('Import Connection', 'e2pdf'), |
| 961 |
'key' => 'options[item]', |
| 962 |
'value' => '0', |
| 963 |
'default_value' => '0', |
| 964 |
'type' => 'checkbox', |
| 965 |
'placeholder' => '', |
| 966 |
'class' => 'e2pdf-collapse', |
| 967 |
'data-collapse' => 'e2pdf-import-extension-option', |
| 968 |
), |
| 969 |
), |
| 970 |
), |
| 971 |
); |
| 972 |
|
| 973 |
$options = apply_filters('e2pdf_controller_templates_import_options', $options); |
| 974 |
$this->view('options', $options); |
| 975 |
$this->view('upload_max_filesize', $this->helper->load('files')->get_upload_max_filesize()); |
| 976 |
} |
| 977 |
|
| 978 |
/** |
| 979 |
* @url admin.php?page=e2pdf-templates&action=backup&id=$id |
| 980 |
*/ |
| 981 |
public function download_action() { |
| 982 |
if ($this->post->get('_wpnonce')) { |
| 983 |
if (wp_verify_nonce($this->post->get('_wpnonce'), 'e2pdf_templates')) { |
| 984 |
if ($this->helper->load('xml')->check()) { |
| 985 |
$options = $this->post->get('options'); |
| 986 |
$xml = $this->helper->load('xml')->create('backup'); |
| 987 |
$template = new Model_E2pdf_Template(); |
| 988 |
if ($template->load($this->post->get('id'))) { |
| 989 |
if ($template->get('title') != '') { |
| 990 |
$filename = $template->get('ID') . ' - ' . $template->get('title') . '.' . date('Y-m-d.H-i-s') . '.e2pdf'; |
| 991 |
} else { |
| 992 |
$filename = date('Y-m-d.H-i-s') . '.e2pdf'; |
| 993 |
} |
| 994 |
$pages = $template->get('pages'); |
| 995 |
if ($options['images']) { |
| 996 |
foreach ($pages as $page_key => $page) { |
| 997 |
if (isset($page['elements']) && !empty($page['elements'])) { |
| 998 |
foreach ($page['elements'] as $element_key => $element) { |
| 999 |
if ($element['type'] === 'e2pdf-image') { |
| 1000 |
$file = false; |
| 1001 |
if ($this->helper->load('pdf')->get_extension($element['value'])) { |
| 1002 |
$file = $this->helper->load('pdf')->get_pdf($element['value']); |
| 1003 |
} else { |
| 1004 |
$file = $this->helper->load('image')->get_image($element['value']); |
| 1005 |
} |
| 1006 |
if ($file) { |
| 1007 |
$pages[$page_key]['elements'][$element_key]['base64'] = $file; |
| 1008 |
} |
| 1009 |
} |
| 1010 |
} |
| 1011 |
} |
| 1012 |
} |
| 1013 |
} |
| 1014 |
|
| 1015 |
/* |
| 1016 |
* Build Xml |
| 1017 |
*/ |
| 1018 |
$xml->addChildCData('version', $this->helper->get('version')); |
| 1019 |
$xml->addChildCData('date', date('Y-m-d H:i:s')); |
| 1020 |
|
| 1021 |
$options_xml = $xml->addChild('options'); |
| 1022 |
foreach ($options as $option_key => $option) { |
| 1023 |
$options_xml->addChildCData($option_key, $option); |
| 1024 |
} |
| 1025 |
$template_xml = $xml->addChild('template'); |
| 1026 |
$template_xml->addChildCData('ID', $template->get('ID')); |
| 1027 |
$template_xml->addChildCData('title', $template->get('title')); |
| 1028 |
$template_xml->addChildCData('created_at', $template->get('created_at')); |
| 1029 |
$template_xml->addChildCData('updated_at', $template->get('updated_at')); |
| 1030 |
$template_xml->addChildCData('flatten', $template->get('flatten')); |
| 1031 |
$template_xml->addChildCData('tab_order', $template->get('tab_order')); |
| 1032 |
$template_xml->addChildCData('compression', $template->get('compression')); |
| 1033 |
$template_xml->addChildCData('optimization', $template->get('optimization')); |
| 1034 |
$template_xml->addChildCData('appearance', $template->get('appearance')); |
| 1035 |
$template_xml->addChildCData('width', $template->get('width')); |
| 1036 |
$template_xml->addChildCData('height', $template->get('height')); |
| 1037 |
$template_xml->addChildCData('extension', $template->get('extension')); |
| 1038 |
$template_xml->addChildCData('item', $template->get('item')); |
| 1039 |
$template_xml->addChildCData('item1', $template->get('item1')); |
| 1040 |
$template_xml->addChildCData('item2', $template->get('item2')); |
| 1041 |
$template_xml->addChildCData('format', $template->get('format')); |
| 1042 |
$template_xml->addChildCData('resample', $template->get('resample')); |
| 1043 |
$template_xml->addChildCData( |
| 1044 |
'dataset_title', |
| 1045 |
apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('dataset_title'), $options, $template, $template->extension()) |
| 1046 |
); |
| 1047 |
$template_xml->addChildCData( |
| 1048 |
'dataset_title1', |
| 1049 |
apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('dataset_title1'), $options, $template, $template->extension()) |
| 1050 |
); |
| 1051 |
$template_xml->addChildCData( |
| 1052 |
'dataset_title2', |
| 1053 |
apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('dataset_title2'), $options, $template, $template->extension()) |
| 1054 |
); |
| 1055 |
$template_xml->addChildCData( |
| 1056 |
'button_title', |
| 1057 |
apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('button_title'), $options, $template, $template->extension()) |
| 1058 |
); |
| 1059 |
$template_xml->addChildCData( |
| 1060 |
'dpdf', |
| 1061 |
apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('dpdf'), $options, $template, $template->extension()) |
| 1062 |
); |
| 1063 |
$template_xml->addChildCData( |
| 1064 |
'attachments', |
| 1065 |
apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('attachments'), $options, $template, $template->extension()) |
| 1066 |
); |
| 1067 |
$template_xml->addChildCData('inline', $template->get('inline')); |
| 1068 |
$template_xml->addChildCData('auto', $template->get('auto')); |
| 1069 |
$template_xml->addChildCData('rtl', $template->get('rtl')); |
| 1070 |
$template_xml->addChildCData('font_processor', $template->get('font_processor')); |
| 1071 |
$template_xml->addChildCData( |
| 1072 |
'name', |
| 1073 |
apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('name'), $options, $template, $template->extension()) |
| 1074 |
); |
| 1075 |
$template_xml->addChildCData( |
| 1076 |
'savename', |
| 1077 |
apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('savename'), $options, $template, $template->extension()) |
| 1078 |
); |
| 1079 |
$template_xml->addChildCData( |
| 1080 |
'password', |
| 1081 |
apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('password'), $options, $template, $template->extension()) |
| 1082 |
); |
| 1083 |
$template_xml->addChildCData( |
| 1084 |
'owner_password', |
| 1085 |
apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('owner_password'), $options, $template, $template->extension()) |
| 1086 |
); |
| 1087 |
$template_xml->addChildCData('permissions', base64_encode(serialize($template->get('permissions')))); |
| 1088 |
$template_xml->addChildCData('hooks', $template->get('hooks')); |
| 1089 |
$template_xml->addChildCData( |
| 1090 |
'meta_title', |
| 1091 |
apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('meta_title'), $options, $template, $template->extension()) |
| 1092 |
); |
| 1093 |
$template_xml->addChildCData( |
| 1094 |
'meta_subject', |
| 1095 |
apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('meta_subject'), $options, $template, $template->extension()) |
| 1096 |
); |
| 1097 |
$template_xml->addChildCData( |
| 1098 |
'meta_author', |
| 1099 |
apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('meta_author'), $options, $template, $template->extension()) |
| 1100 |
); |
| 1101 |
$template_xml->addChildCData( |
| 1102 |
'meta_keywords', |
| 1103 |
apply_filters('e2pdf_controller_templates_backup_replace_shortcodes', $template->get('meta_keywords'), $options, $template, $template->extension()) |
| 1104 |
); |
| 1105 |
$template_xml->addChildCData('lang_code', $template->get('lang_code')); |
| 1106 |
$template_xml->addChildCData('font', $template->get('font')); |
| 1107 |
$template_xml->addChildCData('font_size', $template->get('font_size')); |
| 1108 |
$template_xml->addChildCData('font_color', $template->get('font_color')); |
| 1109 |
$template_xml->addChildCData('line_height', $template->get('line_height')); |
| 1110 |
$template_xml->addChildCData('text_align', $template->get('text_align')); |
| 1111 |
$template_xml->addChildCData('fonts', base64_encode(serialize($template->get('fonts')))); |
| 1112 |
$template_xml->addChildCData( |
| 1113 |
'properties', base64_encode( |
| 1114 |
serialize( |
| 1115 |
apply_filters('e2pdf_controller_templates_backup_properties', $template->get('properties'), $options, $template, $template->extension()) |
| 1116 |
) |
| 1117 |
) |
| 1118 |
); |
| 1119 |
$template_xml->addChildCData( |
| 1120 |
'actions', base64_encode( |
| 1121 |
serialize( |
| 1122 |
apply_filters('e2pdf_controller_templates_backup_actions', $template->get('actions'), $options, $template, $template->extension()) |
| 1123 |
) |
| 1124 |
) |
| 1125 |
); |
| 1126 |
$template_xml->addChildCData('pages', base64_encode( |
| 1127 |
serialize( |
| 1128 |
apply_filters('e2pdf_controller_templates_backup_pages', $pages, $options, $template, $template->extension()) |
| 1129 |
) |
| 1130 |
) |
| 1131 |
); |
| 1132 |
|
| 1133 |
// include pdf |
| 1134 |
if ($template->get('pdf')) { |
| 1135 |
$pdf_xml = $xml->addChild('pdf'); |
| 1136 |
$pdf_xml->addChildCData('source', base64_encode(file_get_contents($this->helper->get('pdf_dir') . $template->get('pdf') . '/' . $template->get('pdf') . '.pdf'))); |
| 1137 |
$pdf_xml_images = $pdf_xml->addChild('images'); |
| 1138 |
foreach ($template->get('pages') as $key => $page) { |
| 1139 |
$pdf_xml_image = $pdf_xml_images->addChild('image'); |
| 1140 |
$pdf_xml_image->addChildCData('page_id', $page['page_id']); |
| 1141 |
$pdf_xml_image->addChildCData('source', base64_encode(file_get_contents($this->helper->get('pdf_dir') . $template->get('pdf') . '/images/' . $page['page_id'] . '.png'))); |
| 1142 |
} |
| 1143 |
} |
| 1144 |
|
| 1145 |
// include fonts |
| 1146 |
if ($options['fonts']) { |
| 1147 |
$fonts_xml = $xml->addChild('fonts'); |
| 1148 |
if ($template->get('fonts')) { |
| 1149 |
$model_e2pdf_font = new Model_E2pdf_Font(); |
| 1150 |
foreach ($template->get('fonts') as $key => $value) { |
| 1151 |
$font = $fonts_xml->addChild('font'); |
| 1152 |
$font->addChildCData('title', $value); |
| 1153 |
$font->addChildCData('name', $key); |
| 1154 |
$font->addChildCData('value', $model_e2pdf_font->get_font($key)); |
| 1155 |
} |
| 1156 |
} |
| 1157 |
} |
| 1158 |
|
| 1159 |
// include item |
| 1160 |
if ($options['item']) { |
| 1161 |
if ($template->extension()->method('backup')) { |
| 1162 |
$item = $xml->addChild('item'); |
| 1163 |
$template->extension()->backup($item); |
| 1164 |
} |
| 1165 |
} |
| 1166 |
$this->download_response('xml', $this->helper->load('xml')->get_xml(), $filename); |
| 1167 |
exit; |
| 1168 |
} else { |
| 1169 |
$this->add_notification('error', __('Something went wrong!', 'e2pdf')); |
| 1170 |
$this->render('blocks', 'notifications'); |
| 1171 |
} |
| 1172 |
} |
| 1173 |
} else { |
| 1174 |
wp_die($this->message('wp_verify_nonce_error')); |
| 1175 |
} |
| 1176 |
} |
| 1177 |
|
| 1178 |
$this->view('export_disabled', false); |
| 1179 |
|
| 1180 |
if (!$this->helper->load('xml')->check()) { |
| 1181 |
$this->add_notification('error', sprintf(__('The PHP %s extension is required', 'e2pdf'), 'SimpleXml')); |
| 1182 |
$this->view('export_disabled', true); |
| 1183 |
} |
| 1184 |
|
| 1185 |
$template = new Model_E2pdf_Template(); |
| 1186 |
if ($template->load($this->get->get('id'))) { |
| 1187 |
|
| 1188 |
$this->view('template', $template); |
| 1189 |
|
| 1190 |
$options = array( |
| 1191 |
'common' => array( |
| 1192 |
'name' => __('Options', 'e2pdf'), |
| 1193 |
'options' => array( |
| 1194 |
array( |
| 1195 |
'name' => __('Include Connection', 'e2pdf'), |
| 1196 |
'key' => 'options[item]', |
| 1197 |
'value' => $template->extension()->method('backup') ? '1' : '0', |
| 1198 |
'default_value' => 0, |
| 1199 |
'type' => 'checkbox', |
| 1200 |
'placeholder' => '', |
| 1201 |
'disabled' => $template->extension()->method('backup') ? false : 'disabled', |
| 1202 |
), |
| 1203 |
array( |
| 1204 |
'name' => __('Include Images', 'e2pdf'), |
| 1205 |
'key' => 'options[images]', |
| 1206 |
'value' => 1, |
| 1207 |
'default_value' => 0, |
| 1208 |
'type' => 'checkbox', |
| 1209 |
'placeholder' => '', |
| 1210 |
), |
| 1211 |
array( |
| 1212 |
'name' => __('Include Fonts', 'e2pdf'), |
| 1213 |
'key' => 'options[fonts]', |
| 1214 |
'value' => 1, |
| 1215 |
'default_value' => 0, |
| 1216 |
'type' => 'checkbox', |
| 1217 |
'placeholder' => '', |
| 1218 |
), |
| 1219 |
), |
| 1220 |
), |
| 1221 |
); |
| 1222 |
|
| 1223 |
$options = apply_filters('e2pdf_controller_templates_backup_options', $options, $template, $template->extension()); |
| 1224 |
$this->view('options', $options); |
| 1225 |
} else { |
| 1226 |
$this->add_notification('error', __('Something went wrong!', 'e2pdf')); |
| 1227 |
$this->render('blocks', 'notifications'); |
| 1228 |
} |
| 1229 |
} |
| 1230 |
|
| 1231 |
// screen action |
| 1232 |
public function screen_action() { |
| 1233 |
$option = $this->post->get('wp_screen_options'); |
| 1234 |
if (is_array($option) && isset($option['option'], $option['value']) && $option['option'] === 'e2pdf_templates_screen_per_page') { |
| 1235 |
$per_page = (int) $option['value']; |
| 1236 |
if ($per_page > 0) { |
| 1237 |
update_option($option['option'], $per_page); |
| 1238 |
} |
| 1239 |
} |
| 1240 |
$this->redirect( |
| 1241 |
$this->helper->get_url( |
| 1242 |
[ |
| 1243 |
'page' => 'e2pdf-templates', |
| 1244 |
] |
| 1245 |
) |
| 1246 |
); |
| 1247 |
} |
| 1248 |
|
| 1249 |
// ajax save form |
| 1250 |
public function ajax_save_form() { |
| 1251 |
global $wpdb; |
| 1252 |
if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) { |
| 1253 |
$data = json_decode($this->post->get('data'), true); |
| 1254 |
$template = new Model_E2pdf_Template(); |
| 1255 |
if (isset($data['ID'])) { |
| 1256 |
$template->load($data['ID']); |
| 1257 |
} |
| 1258 |
if (!isset($data['permissions'])) { |
| 1259 |
$data['permissions'] = array(); |
| 1260 |
} |
| 1261 |
foreach ($data as $key => $value) { |
| 1262 |
if ($key == 'pdf' && $value) { |
| 1263 |
if (file_exists($this->helper->get('pdf_dir') . $value . '/' . $value . '.pdf')) { |
| 1264 |
$template->set($key, $value); |
| 1265 |
} |
| 1266 |
} else { |
| 1267 |
$template->set($key, $value); |
| 1268 |
} |
| 1269 |
} |
| 1270 |
$template_id = $template->save(true); |
| 1271 |
if (!$template_id) { |
| 1272 |
if ($wpdb->last_error) { |
| 1273 |
$response = array( |
| 1274 |
'error' => $wpdb->last_error, |
| 1275 |
); |
| 1276 |
} else { |
| 1277 |
$response = array( |
| 1278 |
'error' => __('Something went wrong!', 'e2pdf'), |
| 1279 |
); |
| 1280 |
} |
| 1281 |
} else { |
| 1282 |
if (isset($data['item']) && $data['item'] == '-1') { |
| 1283 |
$template->load($template_id); |
| 1284 |
if ($template->extension()->method('auto_form')) { |
| 1285 |
$template = $template->extension()->auto_form($template, $data); |
| 1286 |
} else { |
| 1287 |
$template->set('item', ''); |
| 1288 |
} |
| 1289 |
$template->save(true); |
| 1290 |
} |
| 1291 |
if (!isset($data['ID'])) { |
| 1292 |
$template->activate(); |
| 1293 |
} |
| 1294 |
$response = array( |
| 1295 |
'redirect' => $this->helper->get_url( |
| 1296 |
array( |
| 1297 |
'page' => 'e2pdf-templates', |
| 1298 |
'action' => 'edit', |
| 1299 |
'id' => $template->get('ID'), |
| 1300 |
'notification' => $this->add_notification('update', __('Template Saved', 'e2pdf')), |
| 1301 |
) |
| 1302 |
), |
| 1303 |
); |
| 1304 |
} |
| 1305 |
} else { |
| 1306 |
$response['error'] = $this->message('wp_verify_nonce_error'); |
| 1307 |
} |
| 1308 |
$this->json_response($response); |
| 1309 |
} |
| 1310 |
|
| 1311 |
public function ajax_get_styles() { |
| 1312 |
|
| 1313 |
if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) { |
| 1314 |
$data = $this->post->get('data'); |
| 1315 |
$content = array(); |
| 1316 |
if (isset($data['extension']) && isset($data['item'])) { |
| 1317 |
$extension = new Model_E2pdf_Extension(); |
| 1318 |
if ($extension->load($data['extension'])) { |
| 1319 |
$content = $extension->styles($data['item']); |
| 1320 |
} |
| 1321 |
} |
| 1322 |
$response = array( |
| 1323 |
'content' => $content, |
| 1324 |
); |
| 1325 |
} else { |
| 1326 |
$response['error'] = $this->message('wp_verify_nonce_error'); |
| 1327 |
} |
| 1328 |
$this->json_response($response); |
| 1329 |
} |
| 1330 |
|
| 1331 |
// ajax extension |
| 1332 |
public function ajax_extension() { |
| 1333 |
if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) { |
| 1334 |
$data = $this->post->get('data'); |
| 1335 |
$extension = new Model_E2pdf_Extension(); |
| 1336 |
$content = array(); |
| 1337 |
if ($extension->load($data)) { |
| 1338 |
$content = $extension->items(); |
| 1339 |
if ($extension->method('merged_items')) { |
| 1340 |
$select = new stdClass(); |
| 1341 |
$select->id = '-2'; |
| 1342 |
$select->url = ''; |
| 1343 |
$select->name = __('Merged Connections', 'e2pdf'); |
| 1344 |
array_unshift($content, $select); |
| 1345 |
} |
| 1346 |
if ($extension->method('auto_form')) { |
| 1347 |
$select = new stdClass(); |
| 1348 |
$select->id = '-1'; |
| 1349 |
$select->url = ''; |
| 1350 |
$select->name = __('Auto Form from PDF', 'e2pdf'); |
| 1351 |
array_unshift($content, $select); |
| 1352 |
} |
| 1353 |
} |
| 1354 |
$select = new stdClass(); |
| 1355 |
$select->id = ''; |
| 1356 |
$select->url = ''; |
| 1357 |
$select->name = __('--- Select ---', 'e2pdf'); |
| 1358 |
array_unshift($content, $select); |
| 1359 |
$response = array( |
| 1360 |
'content' => $content, |
| 1361 |
); |
| 1362 |
} else { |
| 1363 |
$response['error'] = $this->message('wp_verify_nonce_error'); |
| 1364 |
} |
| 1365 |
$this->json_response($response); |
| 1366 |
} |
| 1367 |
|
| 1368 |
// ajax visual mapper |
| 1369 |
public function ajax_visual_mapper() { |
| 1370 |
if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) { |
| 1371 |
$data = $this->post->get('data'); |
| 1372 |
$item = isset($data['item']) ? $data['item'] : ''; |
| 1373 |
$item1 = isset($data['item1']) ? $data['item1'] : ''; |
| 1374 |
$item2 = isset($data['item2']) ? $data['item2'] : ''; |
| 1375 |
$extension = new Model_E2pdf_Extension(); |
| 1376 |
$extension->load($data['extension']); |
| 1377 |
$extension->set('item', $item); |
| 1378 |
if ($item == '-2') { |
| 1379 |
$extension->set('item1', $item1); |
| 1380 |
$extension->set('item2', $item2); |
| 1381 |
} |
| 1382 |
$visual_mapper = $extension->visual_mapper(); |
| 1383 |
if ($visual_mapper) { |
| 1384 |
$response = array( |
| 1385 |
'content' => $visual_mapper, |
| 1386 |
); |
| 1387 |
} elseif (!$item || ($item == '-2' && !$item1 && !$item2)) { |
| 1388 |
$response = array( |
| 1389 |
'content' => __('You must set the Connection to use the Visual Mapper', 'e2pdf'), |
| 1390 |
); |
| 1391 |
} else { |
| 1392 |
$response = array( |
| 1393 |
'content' => __("Sorry, this Extension doesn't support the Visual Mapper", 'e2pdf'), |
| 1394 |
); |
| 1395 |
} |
| 1396 |
} else { |
| 1397 |
$response['error'] = $this->message('wp_verify_nonce_error'); |
| 1398 |
} |
| 1399 |
$this->json_response($response); |
| 1400 |
} |
| 1401 |
|
| 1402 |
// ajax upload |
| 1403 |
public function ajax_upload() { |
| 1404 |
|
| 1405 |
if (!wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) { |
| 1406 |
$this->json_response( |
| 1407 |
[ |
| 1408 |
'error' => $this->message('wp_verify_nonce_error'), |
| 1409 |
] |
| 1410 |
); |
| 1411 |
} |
| 1412 |
|
| 1413 |
$data = $this->post->get(); |
| 1414 |
$post_extension = $data['extension']; |
| 1415 |
$item = isset($data['item']) ? $data['item'] : ''; |
| 1416 |
$template_id = isset($data['template_id']) && $data['template_id'] ? $data['template_id'] : false; |
| 1417 |
$font = isset($data['font']) ? $data['font'] : false; |
| 1418 |
$font_size = isset($data['font_size']) ? $data['font_size'] : false; |
| 1419 |
$line_height = isset($data['line_height']) ? $data['line_height'] : false; |
| 1420 |
$title = isset($data['title']) ? $data['title'] : __('(no title)', 'e2pdf'); |
| 1421 |
$rtl = isset($data['rtl']) && $data['rtl'] ? '1' : '0'; |
| 1422 |
$text_align = isset($data['text_align']) ? $data['text_align'] : 'left'; |
| 1423 |
$pdf = $this->files->get('pdf'); |
| 1424 |
$name = strtolower($pdf['name']); |
| 1425 |
$ext = strtolower(pathinfo($name, PATHINFO_EXTENSION)); |
| 1426 |
|
| 1427 |
if (!empty($pdf['error'])) { |
| 1428 |
$this->json_response( |
| 1429 |
[ |
| 1430 |
'error' => $pdf['error'], |
| 1431 |
] |
| 1432 |
); |
| 1433 |
} elseif (!in_array($ext, array('pdf'))) { |
| 1434 |
$this->json_response( |
| 1435 |
[ |
| 1436 |
'error' => sprintf(__('Only %s files allowed', 'e2pdf'), '.pdf'), |
| 1437 |
] |
| 1438 |
); |
| 1439 |
} elseif ($pdf['type'] != 'application/pdf') { |
| 1440 |
$this->json_response( |
| 1441 |
[ |
| 1442 |
'error' => __('Invalid Type', 'e2pdf'), |
| 1443 |
] |
| 1444 |
); |
| 1445 |
} |
| 1446 |
|
| 1447 |
wp_raise_memory_limit('admin'); |
| 1448 |
if (get_option('e2pdf_api_protocol', '0') == '1') { |
| 1449 |
$upload = class_exists('CURLFile') ? new CURLFile(realpath($pdf['tmp_name'])) : '@' . realpath($pdf['tmp_name']); |
| 1450 |
} else { |
| 1451 |
$upload = base64_encode(file_get_contents($pdf['tmp_name'])); |
| 1452 |
} |
| 1453 |
|
| 1454 |
$model_e2pdf_api = new Model_E2pdf_Api(); |
| 1455 |
$model_e2pdf_api->set( |
| 1456 |
array( |
| 1457 |
'action' => 'template/upload2', |
| 1458 |
'data' => array( |
| 1459 |
'title' => $name, |
| 1460 |
'pdf' => $upload, |
| 1461 |
), |
| 1462 |
) |
| 1463 |
); |
| 1464 |
$request = $model_e2pdf_api->request(); |
| 1465 |
|
| 1466 |
if (isset($request['error'])) { |
| 1467 |
$this->json_response( |
| 1468 |
[ |
| 1469 |
'error' => $request['error'], |
| 1470 |
] |
| 1471 |
); |
| 1472 |
} |
| 1473 |
|
| 1474 |
$extension = new Model_E2pdf_Extension(); |
| 1475 |
if ($post_extension) { |
| 1476 |
$extension->load($post_extension); |
| 1477 |
if ($item && $item != '-1') { |
| 1478 |
$extension->set('item', $item); |
| 1479 |
} |
| 1480 |
} |
| 1481 |
|
| 1482 |
$pdf_name = md5(time()); |
| 1483 |
$pdf_dir = $this->helper->get('pdf_dir') . $pdf_name . '/'; |
| 1484 |
$pdf_images_dir = $pdf_dir . 'images/'; |
| 1485 |
$this->helper->create_dir($pdf_dir); |
| 1486 |
$this->helper->create_dir($pdf_images_dir); |
| 1487 |
move_uploaded_file($pdf['tmp_name'], $pdf_dir . $pdf_name . '.pdf'); |
| 1488 |
|
| 1489 |
try { |
| 1490 |
$xml_template = []; |
| 1491 |
$pages = []; |
| 1492 |
if (class_exists('XMLReader')) { |
| 1493 |
$reader = new XMLReader(); |
| 1494 |
if (!$reader->XML($request['file'])) { |
| 1495 |
throw new Exception(__('Failed to parse PDF', 'e2pdf')); |
| 1496 |
} |
| 1497 |
while ($reader->read()) { |
| 1498 |
if ($reader->nodeType == XMLReader::ELEMENT) { |
| 1499 |
switch ($reader->name) { |
| 1500 |
case 'template': |
| 1501 |
$template_node = new SimpleXMLElement($reader->readOuterXML(), LIBXML_PARSEHUGE); |
| 1502 |
$xml_template = [ |
| 1503 |
'width' => (string) $template_node->width, |
| 1504 |
'height' => (string) $template_node->height, |
| 1505 |
'format' => (string) $template_node->format, |
| 1506 |
'compression' => (string) $template_node->compression, |
| 1507 |
'appearance' => (string) $template_node->appearance, |
| 1508 |
'meta_title' => (string) $template_node->meta_title, |
| 1509 |
'meta_subject' => (string) $template_node->meta_subject, |
| 1510 |
'meta_author' => (string) $template_node->meta_author, |
| 1511 |
'meta_keywords' => (string) $template_node->meta_keywords, |
| 1512 |
'lang_code' => (string) $template_node->lang_code, |
| 1513 |
'font' => (string) $template_node->font, |
| 1514 |
'font_size' => (string) $template_node->font_size, |
| 1515 |
'font_color' => (string) $template_node->font_color, |
| 1516 |
]; |
| 1517 |
break; |
| 1518 |
case 'page': |
| 1519 |
$page_node = new SimpleXMLElement($reader->readOuterXML(), LIBXML_PARSEHUGE); |
| 1520 |
$this->helper->load('xml')->parse_xml_page($page_node, $pages, $pdf_images_dir, $extension); |
| 1521 |
break; |
| 1522 |
case 'fonts': |
| 1523 |
$fonts_node = new SimpleXMLElement($reader->readOuterXML(), LIBXML_PARSEHUGE); |
| 1524 |
foreach ($fonts_node->children() as $xml_font) { |
| 1525 |
$this->helper->load('xml')->parse_xml_font($xml_font); |
| 1526 |
} |
| 1527 |
break; |
| 1528 |
default: |
| 1529 |
break; |
| 1530 |
} |
| 1531 |
} |
| 1532 |
} |
| 1533 |
|
| 1534 |
$reader->close(); |
| 1535 |
unset($reader); |
| 1536 |
} elseif (is_callable('simplexml_load_string')) { |
| 1537 |
$xml = simplexml_load_string($request['file'], 'SimpleXMLElement', LIBXML_PARSEHUGE); |
| 1538 |
if (isset($xml->pages)) { |
| 1539 |
foreach ($xml->pages->page as $page_node) { |
| 1540 |
$this->helper->load('xml')->parse_xml_page($page_node, $pages, $pdf_images_dir, $extension); |
| 1541 |
} |
| 1542 |
} |
| 1543 |
if (isset($xml->template)) { |
| 1544 |
$xml_template = [ |
| 1545 |
'width' => (string) $xml->template->width, |
| 1546 |
'height' => (string) $xml->template->height, |
| 1547 |
'format' => (string) $xml->template->format, |
| 1548 |
'compression' => (string) $xml->template->compression, |
| 1549 |
'appearance' => (string) $xml->template->appearance, |
| 1550 |
'meta_title' => (string) $xml->template->meta_title, |
| 1551 |
'meta_subject' => (string) $xml->template->meta_subject, |
| 1552 |
'meta_author' => (string) $xml->template->meta_author, |
| 1553 |
'meta_keywords' => (string) $xml->template->meta_keywords, |
| 1554 |
'lang_code' => (string) $xml->template->lang_code, |
| 1555 |
'font' => (string) $xml->template->font, |
| 1556 |
'font_size' => (string) $xml->template->font_size, |
| 1557 |
'font_color' => (string) $xml->template->font_color, |
| 1558 |
]; |
| 1559 |
} |
| 1560 |
if (isset($xml->fonts) && $xml->fonts) { |
| 1561 |
foreach ($xml->fonts->children() as $key => $xml_font) { |
| 1562 |
$this->helper->load('xml')->parse_xml_font($xml_font); |
| 1563 |
} |
| 1564 |
} |
| 1565 |
} |
| 1566 |
|
| 1567 |
if (empty($pages) || !is_array($pages)) { |
| 1568 |
throw new Exception(__('Failed to parse PDF pages', 'e2pdf')); |
| 1569 |
} |
| 1570 |
|
| 1571 |
$this->helper->load('sort')->stable_uasort($pages, 'sort_by_pageid'); |
| 1572 |
|
| 1573 |
$template = new Model_E2pdf_Template(); |
| 1574 |
if ($template_id) { |
| 1575 |
$template->load($template_id); |
| 1576 |
$template->set('title', $title); |
| 1577 |
$template->set('pages', $pages); |
| 1578 |
$template->set('pdf', $pdf_name); |
| 1579 |
$template->set('width', $xml_template['width']); |
| 1580 |
$template->set('height', $xml_template['height']); |
| 1581 |
$template->set('extension', $post_extension); |
| 1582 |
$template->set('item', $item); |
| 1583 |
$template->set('rtl', $rtl); |
| 1584 |
$template->set('font', $font ? $font : $xml_template['font']); |
| 1585 |
$template->set('font_size', $font_size ? $font_size : $xml_template['font_size']); |
| 1586 |
$template->set('line_height', $line_height ? $line_height : $xml_template['font_size']); |
| 1587 |
$template->set('text_align', $text_align); |
| 1588 |
} else { |
| 1589 |
$template->set('title', $title); |
| 1590 |
$template->set('flatten', '1'); |
| 1591 |
$template->set('format', $xml_template['format']); |
| 1592 |
$template->set('compression', $xml_template['compression']); |
| 1593 |
$template->set('appearance', $xml_template['appearance']); |
| 1594 |
$template->set('width', $xml_template['width']); |
| 1595 |
$template->set('height', $xml_template['height']); |
| 1596 |
$template->set('extension', $post_extension); |
| 1597 |
$template->set('item', $item); |
| 1598 |
$template->set('dataset_title', ''); |
| 1599 |
$template->set('button_title', ''); |
| 1600 |
$template->set('dpdf', ''); |
| 1601 |
$template->set('attachments', ''); |
| 1602 |
$template->set('inline', ''); |
| 1603 |
$template->set('auto', ''); |
| 1604 |
$template->set('rtl', $rtl); |
| 1605 |
$template->set('name', '[e2pdf-dataset]'); |
| 1606 |
$template->set('savename', '[e2pdf-dataset]'); |
| 1607 |
$template->set('password', ''); |
| 1608 |
$template->set('meta_title', $xml_template['meta_title']); |
| 1609 |
$template->set('meta_subject', $xml_template['meta_subject']); |
| 1610 |
$template->set('meta_author', $xml_template['meta_author']); |
| 1611 |
$template->set('meta_keywords', $xml_template['meta_keywords']); |
| 1612 |
$template->set('lang_code', $xml_template['lang_code']); |
| 1613 |
$template->set('font', $font ? $font : $xml_template['font']); |
| 1614 |
$template->set('font_size', $font_size ? $font_size : $xml_template['font_size']); |
| 1615 |
$template->set('line_height', $line_height ? $line_height : $xml_template['font_size']); |
| 1616 |
$template->set('text_align', $text_align); |
| 1617 |
$template->set('font_color', $xml_template['font_color']); |
| 1618 |
$template->set('pages', $pages); |
| 1619 |
$template->set('pdf', $pdf_name); |
| 1620 |
} |
| 1621 |
$template->save(true); |
| 1622 |
|
| 1623 |
if ($item == '-1' && $extension->method('auto_form')) { |
| 1624 |
$template = $extension->auto_form($template, $data); |
| 1625 |
$template->save(true); |
| 1626 |
} |
| 1627 |
|
| 1628 |
if (!$template_id) { |
| 1629 |
$template->activate(); |
| 1630 |
} |
| 1631 |
|
| 1632 |
$this->json_response( |
| 1633 |
[ |
| 1634 |
'redirect' => $this->helper->get_url( |
| 1635 |
[ |
| 1636 |
'page' => 'e2pdf-templates', |
| 1637 |
'action' => 'edit', |
| 1638 |
'id' => $template->get('ID'), |
| 1639 |
] |
| 1640 |
), |
| 1641 |
] |
| 1642 |
); |
| 1643 |
} catch (Exception $ex) { |
| 1644 |
if (file_exists($pdf_dir)) { |
| 1645 |
$this->helper->delete_dir($pdf_dir); |
| 1646 |
} |
| 1647 |
$this->json_response( |
| 1648 |
[ |
| 1649 |
'error' => $ex->getMessage(), |
| 1650 |
] |
| 1651 |
); |
| 1652 |
} |
| 1653 |
} |
| 1654 |
|
| 1655 |
// ajax reupload |
| 1656 |
public function ajax_reupload() { |
| 1657 |
|
| 1658 |
if (!wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) { |
| 1659 |
$this->json_response( |
| 1660 |
[ |
| 1661 |
'error' => $this->message('wp_verify_nonce_error'), |
| 1662 |
] |
| 1663 |
); |
| 1664 |
} |
| 1665 |
|
| 1666 |
$data = $this->post->get(); |
| 1667 |
$new = isset($data['new']) ? $data['new'] : array(); |
| 1668 |
$flush = isset($data['flush']) ? $data['flush'] : array(); |
| 1669 |
$positions = isset($data['positions']) ? $data['positions'] : array(); |
| 1670 |
$template_id = isset($data['template_id']) && $data['template_id'] ? $data['template_id'] : false; |
| 1671 |
if (!$template_id) { |
| 1672 |
return false; |
| 1673 |
} |
| 1674 |
|
| 1675 |
$pdf = $this->files->get('pdf'); |
| 1676 |
$name = strtolower($pdf['name']); |
| 1677 |
$ext = strtolower(pathinfo($name, PATHINFO_EXTENSION)); |
| 1678 |
|
| 1679 |
if (!empty($pdf['error'])) { |
| 1680 |
$this->json_response( |
| 1681 |
[ |
| 1682 |
'error' => $pdf['error'], |
| 1683 |
] |
| 1684 |
); |
| 1685 |
} elseif (!in_array($ext, array('pdf'))) { |
| 1686 |
$this->json_response( |
| 1687 |
[ |
| 1688 |
'error' => sprintf(__('Only %s files allowed', 'e2pdf'), '.pdf'), |
| 1689 |
] |
| 1690 |
); |
| 1691 |
} elseif ($pdf['type'] != 'application/pdf') { |
| 1692 |
$this->json_response( |
| 1693 |
[ |
| 1694 |
'error' => __('Invalid Type', 'e2pdf'), |
| 1695 |
] |
| 1696 |
); |
| 1697 |
} |
| 1698 |
|
| 1699 |
wp_raise_memory_limit('admin'); |
| 1700 |
if (get_option('e2pdf_api_protocol', '0') == '1') { |
| 1701 |
$upload = class_exists('CURLFile') ? new CURLFile(realpath($pdf['tmp_name'])) : '@' . realpath($pdf['tmp_name']); |
| 1702 |
} else { |
| 1703 |
$upload = base64_encode(file_get_contents($pdf['tmp_name'])); |
| 1704 |
} |
| 1705 |
|
| 1706 |
$model_e2pdf_api = new Model_E2pdf_Api(); |
| 1707 |
$model_e2pdf_api->set( |
| 1708 |
array( |
| 1709 |
'action' => 'template/upload2', |
| 1710 |
'data' => array( |
| 1711 |
'title' => $name, |
| 1712 |
'pdf' => $upload, |
| 1713 |
), |
| 1714 |
) |
| 1715 |
); |
| 1716 |
$request = $model_e2pdf_api->request(); |
| 1717 |
|
| 1718 |
if (isset($request['error'])) { |
| 1719 |
$this->json_response( |
| 1720 |
[ |
| 1721 |
'error' => $request['error'], |
| 1722 |
] |
| 1723 |
); |
| 1724 |
} |
| 1725 |
|
| 1726 |
$template = new Model_E2pdf_Template(); |
| 1727 |
if (!$template->load($template_id)) { |
| 1728 |
$this->json_response( |
| 1729 |
[ |
| 1730 |
'error' => __('Failed to load E2Pdf Template', 'e2pdf'), |
| 1731 |
] |
| 1732 |
); |
| 1733 |
} |
| 1734 |
|
| 1735 |
$extension = new Model_E2pdf_Extension(); |
| 1736 |
if ($template->get('extension') && $template->get('item')) { |
| 1737 |
$extension->load($template->get('extension')); |
| 1738 |
$extension->set('item', $template->get('item')); |
| 1739 |
} |
| 1740 |
|
| 1741 |
$pdf_name = md5(time()); |
| 1742 |
$pdf_dir = $this->helper->get('pdf_dir') . $pdf_name . '/'; |
| 1743 |
$pdf_images_dir = $pdf_dir . 'images/'; |
| 1744 |
$this->helper->create_dir($pdf_dir); |
| 1745 |
$this->helper->create_dir($pdf_images_dir); |
| 1746 |
move_uploaded_file($pdf['tmp_name'], $pdf_dir . $pdf_name . '.pdf'); |
| 1747 |
|
| 1748 |
try { |
| 1749 |
$pages = []; |
| 1750 |
$pos_pages = []; |
| 1751 |
if (class_exists('XMLReader')) { |
| 1752 |
$reader = new XMLReader(); |
| 1753 |
if (!$reader->XML($request['file'])) { |
| 1754 |
throw new Exception(__('Failed to parse PDF', 'e2pdf')); |
| 1755 |
} |
| 1756 |
while ($reader->read()) { |
| 1757 |
if ($reader->nodeType == XMLReader::ELEMENT) { |
| 1758 |
if ($reader->name == 'page') { |
| 1759 |
$page_node = new SimpleXMLElement($reader->readOuterXML(), LIBXML_PARSEHUGE); |
| 1760 |
$pos_pages[] = (string) $page_node['number']; |
| 1761 |
} |
| 1762 |
} |
| 1763 |
} |
| 1764 |
$reader->close(); |
| 1765 |
unset($reader); |
| 1766 |
foreach ($positions as $pos_key => $pos_page) { |
| 1767 |
if (!in_array($pos_key, $flush)) { |
| 1768 |
if ($pos_page == '0') { |
| 1769 |
$flush[] = $pos_key; |
| 1770 |
} elseif (!in_array($pos_page, $pos_pages, false)) { |
| 1771 |
throw new Exception(sprintf(__('Invalid position of %s page', 'e2pdf'), $pos_key)); |
| 1772 |
} |
| 1773 |
} |
| 1774 |
} |
| 1775 |
$reader = new XMLReader(); |
| 1776 |
$reader->XML($request['file']); |
| 1777 |
while ($reader->read()) { |
| 1778 |
if ($reader->nodeType == XMLReader::ELEMENT) { |
| 1779 |
switch ($reader->name) { |
| 1780 |
case 'page': |
| 1781 |
$page_node = new SimpleXMLElement($reader->readOuterXML(), LIBXML_PARSEHUGE); |
| 1782 |
$this->helper->load('xml')->parse_xml_page($page_node, $pages, $pdf_images_dir, $extension); |
| 1783 |
break; |
| 1784 |
default: |
| 1785 |
break; |
| 1786 |
} |
| 1787 |
} |
| 1788 |
} |
| 1789 |
$reader->close(); |
| 1790 |
unset($reader); |
| 1791 |
} elseif (is_callable('simplexml_load_string')) { |
| 1792 |
$xml = simplexml_load_string($request['file'], 'SimpleXMLElement', LIBXML_PARSEHUGE); |
| 1793 |
if (isset($xml->pages)) { |
| 1794 |
foreach ($xml->pages->page as $page_node) { |
| 1795 |
$pos_pages[] = (string) $page_node['number']; |
| 1796 |
} |
| 1797 |
} |
| 1798 |
foreach ($positions as $pos_key => $pos_page) { |
| 1799 |
if (!in_array($pos_key, $flush)) { |
| 1800 |
if ($pos_page == '0') { |
| 1801 |
$flush[] = $pos_key; |
| 1802 |
} elseif (!in_array($pos_page, $pos_pages, false)) { |
| 1803 |
throw new Exception(sprintf(__('Invalid position of %s page', 'e2pdf'), $pos_key)); |
| 1804 |
} |
| 1805 |
} |
| 1806 |
} |
| 1807 |
if (isset($xml->pages)) { |
| 1808 |
foreach ($xml->pages->page as $page_node) { |
| 1809 |
$this->helper->load('xml')->parse_xml_page($page_node, $pages, $pdf_images_dir, $extension); |
| 1810 |
} |
| 1811 |
} |
| 1812 |
} |
| 1813 |
|
| 1814 |
if (empty($pages) || !is_array($pages)) { |
| 1815 |
throw new Exception(__('Failed to parse PDF pages', 'e2pdf')); |
| 1816 |
} |
| 1817 |
|
| 1818 |
$this->helper->load('sort')->stable_uasort($pages, 'sort_by_pageid'); |
| 1819 |
|
| 1820 |
$model_e2pdf_element = new Model_E2pdf_Element(); |
| 1821 |
$last_element_id = $model_e2pdf_element->get_last_element_id($template_id); |
| 1822 |
$original_pages = $template->get('pages'); |
| 1823 |
|
| 1824 |
foreach ($pages as $page_key => $page) { |
| 1825 |
if (isset($page['elements']) && !empty($page['elements'])) { |
| 1826 |
foreach ($page['elements'] as $element_key => $element) { |
| 1827 |
$last_element_id++; |
| 1828 |
$pages[$page_key]['elements'][$element_key]['element_id'] = $last_element_id; |
| 1829 |
} |
| 1830 |
} |
| 1831 |
foreach ($positions as $pos_key => $pos_page) { |
| 1832 |
if ($pos_page == $page_key) { |
| 1833 |
if (in_array($pos_key, $new)) { |
| 1834 |
if (isset($original_pages[$pos_key]['elements']) && !in_array($pos_key, $flush)) { |
| 1835 |
$elements = $original_pages[$pos_key]['elements']; |
| 1836 |
$pages[$page_key]['elements'] = array_merge($pages[$page_key]['elements'], $elements); |
| 1837 |
} |
| 1838 |
} else { |
| 1839 |
if (isset($original_pages[$pos_key]['elements']) && !in_array($pos_key, $flush)) { |
| 1840 |
$elements = $original_pages[$pos_key]['elements']; |
| 1841 |
$pages[$page_key]['elements'] = $elements; |
| 1842 |
} else { |
| 1843 |
$pages[$page_key]['elements'] = array(); |
| 1844 |
} |
| 1845 |
} |
| 1846 |
if (isset($original_pages[$pos_key]['actions'])) { |
| 1847 |
$pages[$page_key]['actions'] = $original_pages[$pos_key]['actions']; |
| 1848 |
} |
| 1849 |
} |
| 1850 |
} |
| 1851 |
} |
| 1852 |
|
| 1853 |
$template->set('pdf', $pdf_name); |
| 1854 |
$template->set('pages', $pages); |
| 1855 |
$template->save(true); |
| 1856 |
|
| 1857 |
$this->json_response( |
| 1858 |
[ |
| 1859 |
'redirect' => $this->helper->get_url( |
| 1860 |
array( |
| 1861 |
'page' => 'e2pdf-templates', |
| 1862 |
'action' => 'edit', |
| 1863 |
'id' => $template->get('ID'), |
| 1864 |
) |
| 1865 |
), |
| 1866 |
] |
| 1867 |
); |
| 1868 |
} catch (Exception $ex) { |
| 1869 |
if (file_exists($pdf_dir)) { |
| 1870 |
$this->helper->delete_dir($pdf_dir); |
| 1871 |
} |
| 1872 |
$this->json_response( |
| 1873 |
[ |
| 1874 |
'error' => $ex->getMessage(), |
| 1875 |
] |
| 1876 |
); |
| 1877 |
} |
| 1878 |
} |
| 1879 |
|
| 1880 |
// ajax auto |
| 1881 |
public function ajax_auto() { |
| 1882 |
if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) { |
| 1883 |
$data = $this->post->get('data'); |
| 1884 |
|
| 1885 |
$extension = $data['extension']; |
| 1886 |
$item = isset($data['item']) ? $data['item'] : ''; |
| 1887 |
$item1 = isset($data['item1']) ? $data['item1'] : ''; |
| 1888 |
$item2 = isset($data['item2']) ? $data['item2'] : ''; |
| 1889 |
$font_size = isset($data['font_size']) ? $data['font_size'] : '14'; |
| 1890 |
$line_height = isset($data['line_height']) ? $data['line_height'] : '14'; |
| 1891 |
|
| 1892 |
if (!$extension || !$item) { |
| 1893 |
return; |
| 1894 |
} |
| 1895 |
|
| 1896 |
$model_e2pdf_extension = new Model_E2pdf_Extension(); |
| 1897 |
$model_e2pdf_extension->load($extension); |
| 1898 |
$model_e2pdf_extension->set('item', $item); |
| 1899 |
$model_e2pdf_extension->set('item1', $item1); |
| 1900 |
$model_e2pdf_extension->set('item2', $item2); |
| 1901 |
$model_e2pdf_extension->set('font_size', $font_size); |
| 1902 |
$model_e2pdf_extension->set('line_height', $line_height); |
| 1903 |
|
| 1904 |
if (method_exists($model_e2pdf_extension->extension(), 'auto')) { |
| 1905 |
$content = $model_e2pdf_extension->auto(); |
| 1906 |
} else { |
| 1907 |
$content = array(); |
| 1908 |
} |
| 1909 |
|
| 1910 |
$response = array( |
| 1911 |
'content' => $content, |
| 1912 |
); |
| 1913 |
} else { |
| 1914 |
$response['error'] = $this->message('wp_verify_nonce_error'); |
| 1915 |
} |
| 1916 |
$this->json_response($response); |
| 1917 |
} |
| 1918 |
|
| 1919 |
// ajax activate template |
| 1920 |
public function ajax_activate_template() { |
| 1921 |
if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) { |
| 1922 |
$data = $this->post->get('data'); |
| 1923 |
$id = $data['id']; |
| 1924 |
if (!$id) { |
| 1925 |
return; |
| 1926 |
} |
| 1927 |
$request = $this->activate_template($id); |
| 1928 |
if (isset($request['error'])) { |
| 1929 |
$response = array( |
| 1930 |
'error' => $request['error'], |
| 1931 |
); |
| 1932 |
} else { |
| 1933 |
$response = array( |
| 1934 |
'content' => 'activated', |
| 1935 |
); |
| 1936 |
} |
| 1937 |
} else { |
| 1938 |
$response['error'] = $this->message('wp_verify_nonce_error'); |
| 1939 |
} |
| 1940 |
$this->json_response($response); |
| 1941 |
} |
| 1942 |
|
| 1943 |
// ajax deactivaate template |
| 1944 |
public function ajax_deactivate_template() { |
| 1945 |
if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) { |
| 1946 |
$data = $this->post->get('data'); |
| 1947 |
$id = $data['id']; |
| 1948 |
if (!$id) { |
| 1949 |
return; |
| 1950 |
} |
| 1951 |
$request = $this->deactivate_template($id); |
| 1952 |
if (isset($request['error'])) { |
| 1953 |
$response = array( |
| 1954 |
'error' => $request['error'], |
| 1955 |
); |
| 1956 |
} else { |
| 1957 |
$response = array( |
| 1958 |
'content' => 'deactivated', |
| 1959 |
); |
| 1960 |
} |
| 1961 |
} else { |
| 1962 |
$response['error'] = $this->message('wp_verify_nonce_error'); |
| 1963 |
} |
| 1964 |
$this->json_response($response); |
| 1965 |
} |
| 1966 |
|
| 1967 |
// ajax email |
| 1968 |
public function ajax_email() { |
| 1969 |
if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_templates')) { |
| 1970 |
$data = $this->post->get('data'); |
| 1971 |
$email = isset($data['email']) ? trim($data['email']) : ''; |
| 1972 |
$email_code = isset($data['email_code']) ? trim($data['email_code']) : ''; |
| 1973 |
$model_e2pdf_api = new Model_E2pdf_Api(); |
| 1974 |
$model_e2pdf_api->set( |
| 1975 |
array( |
| 1976 |
'action' => 'common/email', |
| 1977 |
'data' => array( |
| 1978 |
'email' => $email, |
| 1979 |
'email_code' => $email_code, |
| 1980 |
'email_confirm' => isset($data['email_code']), |
| 1981 |
), |
| 1982 |
) |
| 1983 |
); |
| 1984 |
$request = $model_e2pdf_api->request(); |
| 1985 |
if (isset($request['error'])) { |
| 1986 |
if ($request['error'] === 'incorrect_email') { |
| 1987 |
$response = array( |
| 1988 |
'error' => __('Invalid E-mail address format', 'e2pdf'), |
| 1989 |
); |
| 1990 |
} elseif ($request['error'] === 'incorrect_code') { |
| 1991 |
$response = array( |
| 1992 |
'error' => __('Invalid Confirmation Code', 'e2pdf'), |
| 1993 |
); |
| 1994 |
} else { |
| 1995 |
$response = array( |
| 1996 |
'error' => $request['error'], |
| 1997 |
); |
| 1998 |
} |
| 1999 |
} elseif (isset($request['success'])) { |
| 2000 |
$response = array( |
| 2001 |
'content' => $request['success'], |
| 2002 |
); |
| 2003 |
if ($request['success'] == 'subscribed') { |
| 2004 |
update_option('e2pdf_email', $email); |
| 2005 |
} |
| 2006 |
} |
| 2007 |
} else { |
| 2008 |
$response['error'] = $this->message('wp_verify_nonce_error'); |
| 2009 |
} |
| 2010 |
$this->json_response($response); |
| 2011 |
} |
| 2012 |
|
| 2013 |
// trash template |
| 2014 |
public function trash_template($id = false) { |
| 2015 |
$id = (int) $id; |
| 2016 |
$template = new Model_E2pdf_Template(); |
| 2017 |
if ($id && $template->load($id, false)) { |
| 2018 |
$template->set('trash', '1'); |
| 2019 |
$template->update(array('trash')); |
| 2020 |
$this->deactivate_template($template->get('ID')); |
| 2021 |
return true; |
| 2022 |
} |
| 2023 |
return false; |
| 2024 |
} |
| 2025 |
|
| 2026 |
// delete template |
| 2027 |
public function delete_template($id = false) { |
| 2028 |
$id = (int) $id; |
| 2029 |
$template = new Model_E2pdf_Template(); |
| 2030 |
if ($id && $template->load($id)) { |
| 2031 |
$this->deactivate_template($template->get('ID')); |
| 2032 |
$template->delete(); |
| 2033 |
return true; |
| 2034 |
} |
| 2035 |
return false; |
| 2036 |
} |
| 2037 |
|
| 2038 |
// restore template |
| 2039 |
public function restore_template($id = false) { |
| 2040 |
$id = (int) $id; |
| 2041 |
$template = new Model_E2pdf_Template(); |
| 2042 |
if ($id && $template->load($id, false)) { |
| 2043 |
$template->set('trash', '0'); |
| 2044 |
$template->update(array('trash')); |
| 2045 |
return true; |
| 2046 |
} |
| 2047 |
return false; |
| 2048 |
} |
| 2049 |
|
| 2050 |
// duplicate template |
| 2051 |
public function duplicate_template($id = false) { |
| 2052 |
|
| 2053 |
$id = (int) $id; |
| 2054 |
|
| 2055 |
$template = new Model_E2pdf_Template(); |
| 2056 |
if ($id && $template->load($id)) { |
| 2057 |
$title = $template->get('title') . ' ' . __('(Copy)', 'e2pdf'); |
| 2058 |
$template->set('ID', false); |
| 2059 |
$template->set('title', $title); |
| 2060 |
$template->set('uid', ''); |
| 2061 |
$template->set('activated', '0'); |
| 2062 |
if ($template->get('pdf')) { |
| 2063 |
$pdf_name = md5(time()); |
| 2064 |
$pdf_dir = $this->helper->get('pdf_dir') . $pdf_name . '/'; |
| 2065 |
$pdf_images_dir = $pdf_dir . 'images/'; |
| 2066 |
|
| 2067 |
$this->helper->create_dir($pdf_dir); |
| 2068 |
$this->helper->create_dir($pdf_images_dir); |
| 2069 |
|
| 2070 |
if (file_exists($this->helper->get('pdf_dir') . $template->get('pdf') . '/' . $template->get('pdf') . '.pdf')) { |
| 2071 |
$images = glob($this->helper->get('pdf_dir') . $template->get('pdf') . '/images/*'); |
| 2072 |
foreach ($images as $image) { |
| 2073 |
copy($image, $pdf_images_dir . pathinfo($image, PATHINFO_BASENAME)); |
| 2074 |
} |
| 2075 |
copy($this->helper->get('pdf_dir') . $template->get('pdf') . '/' . $template->get('pdf') . '.pdf', $this->helper->get('pdf_dir') . $pdf_name . '/' . $pdf_name . '.pdf'); |
| 2076 |
$template->set('pdf', $pdf_name); |
| 2077 |
} |
| 2078 |
} |
| 2079 |
$template->save(true); |
| 2080 |
return true; |
| 2081 |
} |
| 2082 |
return false; |
| 2083 |
} |
| 2084 |
|
| 2085 |
// activate template |
| 2086 |
public function activate_template($id = false) { |
| 2087 |
$id = (int) $id; |
| 2088 |
$template = new Model_E2pdf_Template(); |
| 2089 |
if ($id && $template->load($id, false)) { |
| 2090 |
return $template->activate(); |
| 2091 |
} else { |
| 2092 |
return array( |
| 2093 |
'error' => __('Something went wrong!', 'e2pdf'), |
| 2094 |
); |
| 2095 |
} |
| 2096 |
} |
| 2097 |
|
| 2098 |
// deactivate template |
| 2099 |
public function deactivate_template($id = false) { |
| 2100 |
$id = (int) $id; |
| 2101 |
$template = new Model_E2pdf_Template(); |
| 2102 |
if ($id && $template->load($id, false)) { |
| 2103 |
return $template->deactivate(); |
| 2104 |
} else { |
| 2105 |
return array( |
| 2106 |
'error' => __('Something went wrong!', 'e2pdf'), |
| 2107 |
); |
| 2108 |
} |
| 2109 |
} |
| 2110 |
|
| 2111 |
// get templates list |
| 2112 |
public function get_templates_list($filters = array(), $count = false) { |
| 2113 |
global $wpdb; |
| 2114 |
|
| 2115 |
$model_e2pdf_template = new Model_E2pdf_Template(); |
| 2116 |
$condition = array(); |
| 2117 |
if (isset($filters['status']) && $filters['status'] == 'trash') { |
| 2118 |
$condition = array( |
| 2119 |
'trash' => array( |
| 2120 |
'condition' => '=', |
| 2121 |
'value' => '1', |
| 2122 |
'type' => '%d', |
| 2123 |
), |
| 2124 |
); |
| 2125 |
} else { |
| 2126 |
$condition = array( |
| 2127 |
'trash' => array( |
| 2128 |
'condition' => '<>', |
| 2129 |
'value' => '1', |
| 2130 |
'type' => '%d', |
| 2131 |
), |
| 2132 |
); |
| 2133 |
} |
| 2134 |
|
| 2135 |
if (isset($filters['s']) && $filters['s']) { |
| 2136 |
$condition['title'] = array( |
| 2137 |
'condition' => 'LIKE', |
| 2138 |
'value' => '%%' . $filters['s'] . '%%', |
| 2139 |
'type' => '%s', |
| 2140 |
'or' => array( |
| 2141 |
array( |
| 2142 |
'ID' => array( |
| 2143 |
'condition' => 'LIKE', |
| 2144 |
'value' => '%%' . $filters['s'] . '%%', |
| 2145 |
'type' => '%s', |
| 2146 |
), |
| 2147 |
), |
| 2148 |
), |
| 2149 |
); |
| 2150 |
} |
| 2151 |
|
| 2152 |
$order_condition = array(); |
| 2153 |
$sortable = array('id', 'title', 'updated_at'); |
| 2154 |
if (isset($filters['orderby']) && in_array($filters['orderby'], $sortable) && isset($filters['order'])) { |
| 2155 |
$order_condition = array( |
| 2156 |
'orderby' => $filters['orderby'], |
| 2157 |
'order' => $filters['order'] == 'asc' ? 'asc' : 'desc', |
| 2158 |
); |
| 2159 |
} else { |
| 2160 |
$order_condition = array( |
| 2161 |
'orderby' => 'id', |
| 2162 |
'order' => 'desc', |
| 2163 |
); |
| 2164 |
} |
| 2165 |
|
| 2166 |
$limit_condition = array(); |
| 2167 |
if (!$count) { |
| 2168 |
$paged = isset($filters['paged']) && $filters['paged'] ? $filters['paged'] : '0'; |
| 2169 |
$paged = (int) $paged <= 0 ? 1 : (int) $paged; |
| 2170 |
$per_page = (int) get_option('e2pdf_templates_screen_per_page', '20'); |
| 2171 |
$limit_condition = array( |
| 2172 |
'limit' => (int) $per_page, |
| 2173 |
'offset' => (int) ($paged - 1) * $per_page, |
| 2174 |
); |
| 2175 |
} |
| 2176 |
|
| 2177 |
$where = $this->helper->load('db')->prepare_where($condition); |
| 2178 |
$orderby = $this->helper->load('db')->prepare_orderby($order_condition); |
| 2179 |
$limit = $this->helper->load('db')->prepare_limit($limit_condition); |
| 2180 |
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare |
| 2181 |
$tpls = $wpdb->get_results($wpdb->prepare('SELECT `ID` FROM `' . $model_e2pdf_template->get_table() . '`' . $where['sql'] . $orderby . $limit . '', $where['filter'])); |
| 2182 |
|
| 2183 |
if ($count) { |
| 2184 |
return count($tpls); |
| 2185 |
} |
| 2186 |
|
| 2187 |
$templates = array(); |
| 2188 |
foreach ($tpls as $key => $tpl) { |
| 2189 |
$template = new Model_E2pdf_Template(); |
| 2190 |
$template->load($tpl->ID, false); |
| 2191 |
if (is_array($this->helper->get('license')->get('activated_templates'))) { |
| 2192 |
if ($template->get('activated') && !in_array($template->get('uid'), $this->helper->get('license')->get('activated_templates'))) { |
| 2193 |
$template->deactivate(); |
| 2194 |
} elseif (!$template->get('activated') && in_array($template->get('uid'), $this->helper->get('license')->get('activated_templates'))) { |
| 2195 |
$template->activate(); |
| 2196 |
} |
| 2197 |
} |
| 2198 |
$templates[] = $template; |
| 2199 |
} |
| 2200 |
return $templates; |
| 2201 |
} |
| 2202 |
|
| 2203 |
// get sizes list |
| 2204 |
public function get_sizes_list($size = false, $attr = false) { |
| 2205 |
|
| 2206 |
$sizes = array( |
| 2207 |
'A4 (PORTRAIT)' => array( |
| 2208 |
'width' => '595', |
| 2209 |
'height' => '842', |
| 2210 |
), |
| 2211 |
'A4 (LANDSCAPE)' => array( |
| 2212 |
'width' => '842', |
| 2213 |
'height' => '595', |
| 2214 |
), |
| 2215 |
'LETTER' => array( |
| 2216 |
'width' => '612', |
| 2217 |
'height' => '792', |
| 2218 |
), |
| 2219 |
'NOTE' => array( |
| 2220 |
'width' => '540', |
| 2221 |
'height' => '720', |
| 2222 |
), |
| 2223 |
'LEGAL' => array( |
| 2224 |
'width' => '612', |
| 2225 |
'height' => '1008', |
| 2226 |
), |
| 2227 |
'TABLOID' => array( |
| 2228 |
'width' => '792', |
| 2229 |
'height' => '1224', |
| 2230 |
), |
| 2231 |
'EXECUTIVE' => array( |
| 2232 |
'width' => '522', |
| 2233 |
'height' => '756', |
| 2234 |
), |
| 2235 |
'POSTCARD' => array( |
| 2236 |
'width' => '283', |
| 2237 |
'height' => '416', |
| 2238 |
), |
| 2239 |
); |
| 2240 |
|
| 2241 |
if (!$size) { |
| 2242 |
return $sizes; |
| 2243 |
} else { |
| 2244 |
if (isset($sizes[$size][$attr])) { |
| 2245 |
return $sizes[$size][$attr]; |
| 2246 |
} |
| 2247 |
return false; |
| 2248 |
} |
| 2249 |
} |
| 2250 |
|
| 2251 |
// get fonts |
| 2252 |
public function get_fonts($with_path = false) { |
| 2253 |
$model_e2pdf_font = new Model_E2pdf_Font(); |
| 2254 |
$fonts = $model_e2pdf_font->get_fonts(); |
| 2255 |
|
| 2256 |
if ($with_path) { |
| 2257 |
foreach ($fonts as $key => $value) { |
| 2258 |
$fonts[$key] = array( |
| 2259 |
'key' => $value, |
| 2260 |
'subfield' => array( |
| 2261 |
'path' => $key, |
| 2262 |
), |
| 2263 |
'value' => $value, |
| 2264 |
); |
| 2265 |
} |
| 2266 |
} |
| 2267 |
|
| 2268 |
return $fonts; |
| 2269 |
} |
| 2270 |
|
| 2271 |
// get font sizes |
| 2272 |
public function get_font_sizes() { |
| 2273 |
$max_font_size = apply_filters('e2pdf_controller_templates_max_font_size', 512); |
| 2274 |
$sizes = array(); |
| 2275 |
for ($i = 1; $i <= $max_font_size; $i++) { |
| 2276 |
$sizes[$i] = $i; |
| 2277 |
} |
| 2278 |
return $sizes; |
| 2279 |
} |
| 2280 |
|
| 2281 |
// get line heights |
| 2282 |
public function get_line_heights() { |
| 2283 |
|
| 2284 |
$max_line_height = apply_filters('e2pdf_controller_templates_max_line_height', 512); |
| 2285 |
$line_heights = array(); |
| 2286 |
for ($i = 1; $i <= $max_line_height; $i++) { |
| 2287 |
$line_heights[$i] = $i; |
| 2288 |
} |
| 2289 |
return $line_heights; |
| 2290 |
} |
| 2291 |
|
| 2292 |
// get lang codes |
| 2293 |
public function get_lang_codes() { |
| 2294 |
return array( |
| 2295 |
'' => '', |
| 2296 |
'aa' => 'aa', |
| 2297 |
'ab' => 'ab', |
| 2298 |
'ae' => 'ae', |
| 2299 |
'af' => 'af', |
| 2300 |
'ak' => 'ak', |
| 2301 |
'am' => 'am', |
| 2302 |
'an' => 'an', |
| 2303 |
'ar' => 'ar', |
| 2304 |
'ar-AE' => 'ar-AE', |
| 2305 |
'ar-BH' => 'ar-BH', |
| 2306 |
'ar-DZ' => 'ar-DZ', |
| 2307 |
'ar-EG' => 'ar-EG', |
| 2308 |
'ar-IQ' => 'ar-IQ', |
| 2309 |
'ar-JO' => 'ar-JO', |
| 2310 |
'ar-KW' => 'ar-KW', |
| 2311 |
'ar-LB' => 'ar-LB', |
| 2312 |
'ar-LY' => 'ar-LY', |
| 2313 |
'ar-MA' => 'ar-MA', |
| 2314 |
'ar-OM' => 'ar-OM', |
| 2315 |
'ar-QA' => 'ar-QA', |
| 2316 |
'ar-SA' => 'ar-SA', |
| 2317 |
'ar-SY' => 'ar-SY', |
| 2318 |
'ar-TN' => 'ar-TN', |
| 2319 |
'ar-YE' => 'ar-YE', |
| 2320 |
'as' => 'as', |
| 2321 |
'av' => 'av', |
| 2322 |
'ay' => 'ay', |
| 2323 |
'az' => 'az', |
| 2324 |
'ba' => 'ba', |
| 2325 |
'be' => 'be', |
| 2326 |
'bg' => 'bg', |
| 2327 |
'bh' => 'bh', |
| 2328 |
'bi' => 'bi', |
| 2329 |
'bm' => 'bm', |
| 2330 |
'bn' => 'bn', |
| 2331 |
'bo' => 'bo', |
| 2332 |
'br' => 'br', |
| 2333 |
'bs' => 'bs', |
| 2334 |
'ca' => 'ca', |
| 2335 |
'ce' => 'ce', |
| 2336 |
'ch' => 'ch', |
| 2337 |
'co' => 'co', |
| 2338 |
'cr' => 'cr', |
| 2339 |
'cs' => 'cs', |
| 2340 |
'cu' => 'cu', |
| 2341 |
'cv' => 'cv', |
| 2342 |
'cy' => 'cy', |
| 2343 |
'da' => 'da', |
| 2344 |
'de' => 'de', |
| 2345 |
'de-AT' => 'de-AT', |
| 2346 |
'de-CH' => 'de-CH', |
| 2347 |
'de-DE' => 'de-DE', |
| 2348 |
'de-LI' => 'de-LI', |
| 2349 |
'de-LU' => 'de-LU', |
| 2350 |
'div' => 'div', |
| 2351 |
'dv' => 'dv', |
| 2352 |
'dz' => 'dz', |
| 2353 |
'ee' => 'ee', |
| 2354 |
'el' => 'el', |
| 2355 |
'en' => 'en', |
| 2356 |
'en-AU' => 'en-AU', |
| 2357 |
'en-BZ' => 'en-BZ', |
| 2358 |
'en-CA' => 'en-CA', |
| 2359 |
'en-CB' => 'en-CB', |
| 2360 |
'en-GB' => 'en-GB', |
| 2361 |
'en-IE' => 'en-IE', |
| 2362 |
'en-JM' => 'en-JM', |
| 2363 |
'en-NZ' => 'en-NZ', |
| 2364 |
'en-PH' => 'en-PH', |
| 2365 |
'en-TT' => 'en-TT', |
| 2366 |
'en-US' => 'en-US', |
| 2367 |
'en-ZA' => 'en-ZA', |
| 2368 |
'en-ZW' => 'en-ZW', |
| 2369 |
'eo' => 'eo', |
| 2370 |
'es' => 'es', |
| 2371 |
'es-AR' => 'es-AR', |
| 2372 |
'es-BO' => 'es-BO', |
| 2373 |
'es-CL' => 'es-CL', |
| 2374 |
'es-CO' => 'es-CO', |
| 2375 |
'es-CR' => 'es-CR', |
| 2376 |
'es-DO' => 'es-DO', |
| 2377 |
'es-EC' => 'es-EC', |
| 2378 |
'es-ES' => 'es-ES', |
| 2379 |
'es-GT' => 'es-GT', |
| 2380 |
'es-HN' => 'es-HN', |
| 2381 |
'es-MX' => 'es-MX', |
| 2382 |
'es-NI' => 'es-NI', |
| 2383 |
'es-PA' => 'es-PA', |
| 2384 |
'es-PE' => 'es-PE', |
| 2385 |
'es-PR' => 'es-PR', |
| 2386 |
'es-PY' => 'es-PY', |
| 2387 |
'es-SV' => 'es-SV', |
| 2388 |
'es-US' => 'es-US', |
| 2389 |
'es-UY' => 'es-UY', |
| 2390 |
'es-VE' => 'es-VE', |
| 2391 |
'et' => 'et', |
| 2392 |
'eu' => 'eu', |
| 2393 |
'fa' => 'fa', |
| 2394 |
'ff' => 'ff', |
| 2395 |
'fi' => 'fi', |
| 2396 |
'fj' => 'fj', |
| 2397 |
'fo' => 'fo', |
| 2398 |
'fr' => 'fr', |
| 2399 |
'fr-BE' => 'fr-BE', |
| 2400 |
'fr-CA' => 'fr-CA', |
| 2401 |
'fr-CH' => 'fr-CH', |
| 2402 |
'fr-FR' => 'fr-FR', |
| 2403 |
'fr-LU' => 'fr-LU', |
| 2404 |
'fr-MC' => 'fr-MC', |
| 2405 |
'fy' => 'fy', |
| 2406 |
'ga' => 'ga', |
| 2407 |
'gd' => 'gd', |
| 2408 |
'gl' => 'gl', |
| 2409 |
'gn' => 'gn', |
| 2410 |
'gu' => 'gu', |
| 2411 |
'gv' => 'gv', |
| 2412 |
'ha' => 'ha', |
| 2413 |
'he' => 'he', |
| 2414 |
'hi' => 'hi', |
| 2415 |
'ho' => 'ho', |
| 2416 |
'hr' => 'hr', |
| 2417 |
'hr-BA' => 'hr-BA', |
| 2418 |
'hr-HR' => 'hr-HR', |
| 2419 |
'ht' => 'ht', |
| 2420 |
'hu' => 'hu', |
| 2421 |
'hy' => 'hy', |
| 2422 |
'hz' => 'hz', |
| 2423 |
'ia' => 'ia', |
| 2424 |
'id' => 'id', |
| 2425 |
'ie' => 'ie', |
| 2426 |
'ig' => 'ig', |
| 2427 |
'ii' => 'ii', |
| 2428 |
'ik' => 'ik', |
| 2429 |
'in' => 'in', |
| 2430 |
'io' => 'io', |
| 2431 |
'is' => 'is', |
| 2432 |
'it' => 'it', |
| 2433 |
'it-CH' => 'it-CH', |
| 2434 |
'it-IT' => 'it-IT', |
| 2435 |
'iu' => 'iu', |
| 2436 |
'iw' => 'iw', |
| 2437 |
'ja' => 'ja', |
| 2438 |
'ji' => 'ji', |
| 2439 |
'jv' => 'jv', |
| 2440 |
'jw' => 'jw', |
| 2441 |
'ka' => 'ka', |
| 2442 |
'kg' => 'kg', |
| 2443 |
'ki' => 'ki', |
| 2444 |
'kj' => 'kj', |
| 2445 |
'kk' => 'kk', |
| 2446 |
'kl' => 'kl', |
| 2447 |
'km' => 'km', |
| 2448 |
'kn' => 'kn', |
| 2449 |
'ko' => 'ko', |
| 2450 |
'kok' => 'kok', |
| 2451 |
'kr' => 'kr', |
| 2452 |
'ks' => 'ks', |
| 2453 |
'ku' => 'ku', |
| 2454 |
'kv' => 'kv', |
| 2455 |
'kw' => 'kw', |
| 2456 |
'ky' => 'ky', |
| 2457 |
'kz' => 'kz', |
| 2458 |
'la' => 'la', |
| 2459 |
'lb' => 'lb', |
| 2460 |
'lg' => 'lg', |
| 2461 |
'li' => 'li', |
| 2462 |
'ln' => 'ln', |
| 2463 |
'lo' => 'lo', |
| 2464 |
'ls' => 'ls', |
| 2465 |
'lt' => 'lt', |
| 2466 |
'lu' => 'lu', |
| 2467 |
'lv' => 'lv', |
| 2468 |
'mg' => 'mg', |
| 2469 |
'mh' => 'mh', |
| 2470 |
'mi' => 'mi', |
| 2471 |
'mk' => 'mk', |
| 2472 |
'ml' => 'ml', |
| 2473 |
'mn' => 'mn', |
| 2474 |
'mo' => 'mo', |
| 2475 |
'mr' => 'mr', |
| 2476 |
'ms' => 'ms', |
| 2477 |
'ms-BN' => 'ms-BN', |
| 2478 |
'ms-MY' => 'ms-MY', |
| 2479 |
'mt' => 'mt', |
| 2480 |
'my' => 'my', |
| 2481 |
'na' => 'na', |
| 2482 |
'nb' => 'nb', |
| 2483 |
'nd' => 'nd', |
| 2484 |
'ne' => 'ne', |
| 2485 |
'ng' => 'ng', |
| 2486 |
'nl' => 'nl', |
| 2487 |
'nl-BE' => 'nl-BE', |
| 2488 |
'nl-NL' => 'nl-NL', |
| 2489 |
'nn' => 'nn', |
| 2490 |
'no' => 'no', |
| 2491 |
'nr' => 'nr', |
| 2492 |
'ns' => 'ns', |
| 2493 |
'nv' => 'nv', |
| 2494 |
'ny' => 'ny', |
| 2495 |
'oc' => 'oc', |
| 2496 |
'oj' => 'oj', |
| 2497 |
'om' => 'om', |
| 2498 |
'or' => 'or', |
| 2499 |
'os' => 'os', |
| 2500 |
'pa' => 'pa', |
| 2501 |
'pi' => 'pi', |
| 2502 |
'pl' => 'pl', |
| 2503 |
'ps' => 'ps', |
| 2504 |
'pt' => 'pt', |
| 2505 |
'pt-BR' => 'pt-BR', |
| 2506 |
'pt-PT' => 'pt-PT', |
| 2507 |
'qu' => 'qu', |
| 2508 |
'qu-BO' => 'qu-BO', |
| 2509 |
'qu-EC' => 'qu-EC', |
| 2510 |
'qu-PE' => 'qu-PE', |
| 2511 |
'rm' => 'rm', |
| 2512 |
'rn' => 'rn', |
| 2513 |
'ro' => 'ro', |
| 2514 |
'ru' => 'ru', |
| 2515 |
'rw' => 'rw', |
| 2516 |
'sa' => 'sa', |
| 2517 |
'sb' => 'sb', |
| 2518 |
'sc' => 'sc', |
| 2519 |
'sd' => 'sd', |
| 2520 |
'se' => 'se', |
| 2521 |
'se-FI' => 'se-FI', |
| 2522 |
'se-NO' => 'se-NO', |
| 2523 |
'se-SE' => 'se-SE', |
| 2524 |
'sg' => 'sg', |
| 2525 |
'sh' => 'sh', |
| 2526 |
'si' => 'si', |
| 2527 |
'sk' => 'sk', |
| 2528 |
'sl' => 'sl', |
| 2529 |
'sm' => 'sm', |
| 2530 |
'sn' => 'sn', |
| 2531 |
'so' => 'so', |
| 2532 |
'sq' => 'sq', |
| 2533 |
'sr' => 'sr', |
| 2534 |
'sr-BA' => 'sr-BA', |
| 2535 |
'sr-SP' => 'sr-SP', |
| 2536 |
'ss' => 'ss', |
| 2537 |
'st' => 'st', |
| 2538 |
'su' => 'su', |
| 2539 |
'sv' => 'sv', |
| 2540 |
'sv-FI' => 'sv-FI', |
| 2541 |
'sv-SE' => 'sv-SE', |
| 2542 |
'sw' => 'sw', |
| 2543 |
'sx' => 'sx', |
| 2544 |
'syr' => 'syr', |
| 2545 |
'ta' => 'ta', |
| 2546 |
'te' => 'te', |
| 2547 |
'tg' => 'tg', |
| 2548 |
'th' => 'th', |
| 2549 |
'ti' => 'ti', |
| 2550 |
'tk' => 'tk', |
| 2551 |
'tl' => 'tl', |
| 2552 |
'tn' => 'tn', |
| 2553 |
'to' => 'to', |
| 2554 |
'tr' => 'tr', |
| 2555 |
'ts' => 'ts', |
| 2556 |
'tt' => 'tt', |
| 2557 |
'tw' => 'tw', |
| 2558 |
'ty' => 'ty', |
| 2559 |
'ug' => 'ug', |
| 2560 |
'uk' => 'uk', |
| 2561 |
'ur' => 'ur', |
| 2562 |
'us' => 'us', |
| 2563 |
'uz' => 'uz', |
| 2564 |
've' => 've', |
| 2565 |
'vi' => 'vi', |
| 2566 |
'vo' => 'vo', |
| 2567 |
'wa' => 'wa', |
| 2568 |
'wo' => 'wo', |
| 2569 |
'xh' => 'xh', |
| 2570 |
'yi' => 'yi', |
| 2571 |
'yo' => 'yo', |
| 2572 |
'za' => 'za', |
| 2573 |
'zh' => 'zh', |
| 2574 |
'zh-CN' => 'zh-CN', |
| 2575 |
'zh-HK' => 'zh-HK', |
| 2576 |
'zh-MO' => 'zh-MO', |
| 2577 |
'zh-SG' => 'zh-SG', |
| 2578 |
'zh-TW' => 'zh-TW', |
| 2579 |
'zu' => 'zu', |
| 2580 |
); |
| 2581 |
} |
| 2582 |
|
| 2583 |
// load metaboxes |
| 2584 |
public function load_metaboxes() { |
| 2585 |
add_meta_box( |
| 2586 |
'e2pdf_templates_save', __('Preset', 'e2pdf'), array($this, 'render_metabox'), null, 'side', 'default', array('tpl' => 'e2pdf_templates_save') |
| 2587 |
); |
| 2588 |
add_meta_box( |
| 2589 |
'e2pdf_templates_builder', __('PDF Builder', 'e2pdf'), array($this, 'render_metabox'), null, 'side', 'default', array('tpl' => 'e2pdf_templates_builder') |
| 2590 |
); |
| 2591 |
add_meta_box( |
| 2592 |
'e2pdf_templates_settings', __('Settings', 'e2pdf'), array($this, 'render_metabox'), null, 'side', 'default', array('tpl' => 'e2pdf_templates_settings') |
| 2593 |
); |
| 2594 |
} |
| 2595 |
|
| 2596 |
// load scripts |
| 2597 |
public function load_scripts() { |
| 2598 |
wp_enqueue_script('postbox'); |
| 2599 |
wp_enqueue_script('jquery-ui-droppable'); |
| 2600 |
wp_enqueue_script('jquery-ui-resizable'); |
| 2601 |
wp_enqueue_script('jquery-ui-selectable'); |
| 2602 |
wp_enqueue_script('jquery-ui-dialog'); |
| 2603 |
wp_enqueue_script('jquery-ui-autocomplete'); |
| 2604 |
wp_enqueue_script('wp-color-picker'); |
| 2605 |
wp_enqueue_media(); |
| 2606 |
} |
| 2607 |
|
| 2608 |
// load styles |
| 2609 |
public function load_styles($ext = false) { |
| 2610 |
$version = get_option('e2pdf_debug', '0') === '1' ? strtotime('now') : $this->helper->get('version'); |
| 2611 |
wp_enqueue_style('css/e2pdf.jquery-ui', plugins_url('css/jquery-ui.css', $this->helper->get('plugin_file_path')), false, $version, false); |
| 2612 |
wp_enqueue_style('wp-color-picker'); |
| 2613 |
if ($ext) { |
| 2614 |
$extension = new Model_E2pdf_Extension(); |
| 2615 |
if ($extension->load($ext)) { |
| 2616 |
$styles = $extension->styles(); |
| 2617 |
if ($styles && is_array($styles)) { |
| 2618 |
foreach ($styles as $key => $value) { |
| 2619 |
wp_enqueue_style('e2pdf-dynamic-style-' . $key, $value, false, $version, false); |
| 2620 |
} |
| 2621 |
} |
| 2622 |
} |
| 2623 |
} |
| 2624 |
} |
| 2625 |
} |
| 2626 |
|