| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* File: /extension/e2pdf-everest.php |
| 5 |
* |
| 6 |
* @package E2Pdf |
| 7 |
* @license GPLv3 |
| 8 |
* @link https://e2pdf.com |
| 9 |
*/ |
| 10 |
if (!defined('ABSPATH')) { |
| 11 |
die('Access denied.'); |
| 12 |
} |
| 13 |
|
| 14 |
class Extension_E2pdf_Everest extends Model_E2pdf_Model { |
| 15 |
|
| 16 |
private $options; |
| 17 |
private $info = array( |
| 18 |
'key' => 'everest', |
| 19 |
'title' => 'Everest Forms', |
| 20 |
); |
| 21 |
|
| 22 |
// info |
| 23 |
public function info($key = false) { |
| 24 |
if ($key && isset($this->info[$key])) { |
| 25 |
return $this->info[$key]; |
| 26 |
} else { |
| 27 |
return array( |
| 28 |
$this->info['key'] => $this->info['title'], |
| 29 |
); |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
// active |
| 34 |
public function active() { |
| 35 |
if (defined('E2PDF_EVEREST_EXTENSION') || $this->helper->load('extension')->is_plugin_active('everest-forms/everest-forms.php')) { |
| 36 |
return true; |
| 37 |
} |
| 38 |
return false; |
| 39 |
} |
| 40 |
|
| 41 |
// set |
| 42 |
public function set($key, $value) { |
| 43 |
if (!isset($this->options)) { |
| 44 |
$this->options = new stdClass(); |
| 45 |
} |
| 46 |
$this->options->$key = $value; |
| 47 |
switch ($key) { |
| 48 |
case 'item': |
| 49 |
$this->set('cached_form', false); |
| 50 |
$this->set('cached_form_data', false); |
| 51 |
$form = get_post($this->get('item')); |
| 52 |
if (function_exists('evf_decode') && $form && !empty($form->post_content)) { |
| 53 |
$this->set('cached_form', $form); |
| 54 |
$this->set('cached_form_data', evf_decode($this->get('cached_form')->post_content)); |
| 55 |
} |
| 56 |
break; |
| 57 |
case 'dataset': |
| 58 |
$this->set('cached_entry', false); |
| 59 |
$this->set('cached_fields', false); |
| 60 |
if (function_exists('evf_decode') && function_exists('evf_get_entry') && $this->get('cached_form') && $this->get('dataset')) { |
| 61 |
$entry = evf_get_entry($this->get('dataset'), false); |
| 62 |
if (!empty($entry->form_id) && $entry->form_id == $this->get('cached_form')->ID) { |
| 63 |
$this->set('cached_entry', $entry); |
| 64 |
$this->set('cached_fields', evf_decode($entry->fields)); |
| 65 |
} |
| 66 |
} |
| 67 |
break; |
| 68 |
default: |
| 69 |
break; |
| 70 |
} |
| 71 |
return true; |
| 72 |
} |
| 73 |
|
| 74 |
// get |
| 75 |
public function get($key) { |
| 76 |
if (isset($this->options->$key)) { |
| 77 |
$value = $this->options->$key; |
| 78 |
} else { |
| 79 |
switch ($key) { |
| 80 |
case 'args': |
| 81 |
$value = array(); |
| 82 |
break; |
| 83 |
default: |
| 84 |
$value = false; |
| 85 |
break; |
| 86 |
} |
| 87 |
} |
| 88 |
return $value; |
| 89 |
} |
| 90 |
|
| 91 |
// load actions |
| 92 |
public function load_actions() { |
| 93 |
add_action('everest_forms_email_send_after', array($this, 'action_everest_forms_email_send_after')); |
| 94 |
add_action('everest_forms_entry_details_sidebar_details', array($this, 'hook_everest_entry_view'), 10); |
| 95 |
} |
| 96 |
|
| 97 |
// load filters |
| 98 |
public function load_filters() { |
| 99 |
add_filter('everest_forms_add_success', array($this, 'filter_everest_forms_add_success')); |
| 100 |
add_filter('everest_forms_email_attachments', array($this, 'filter_everest_forms_email_attachments'), 10, 2); |
| 101 |
add_filter('everest_forms_email_message', array($this, 'filter_everest_forms_email_message'), 10); |
| 102 |
add_filter('everest_forms_email_template_message', array($this, 'filter_everest_forms_email_message'), 10); |
| 103 |
add_filter('everest_forms_entry_table_actions', array($this, 'hook_everest_row_actions'), 10, 2); |
| 104 |
add_filter('everest_forms_after_success_ajax_message', array($this, 'filter_everest_forms_after_success_ajax_message'), 99, 3); |
| 105 |
} |
| 106 |
|
| 107 |
// items |
| 108 |
public function items() { |
| 109 |
$items = array(); |
| 110 |
$forms = get_posts( |
| 111 |
array( |
| 112 |
'post_status' => 'publish', |
| 113 |
'posts_per_page' => -1, |
| 114 |
'post_type' => 'everest_form', |
| 115 |
) |
| 116 |
); |
| 117 |
if ($forms) { |
| 118 |
foreach ($forms as $key => $form) { |
| 119 |
$items[] = $this->item($form->ID); |
| 120 |
} |
| 121 |
} |
| 122 |
return $items; |
| 123 |
} |
| 124 |
|
| 125 |
// item |
| 126 |
public function item($item_id = false) { |
| 127 |
if (!$item_id && $this->get('item')) { |
| 128 |
$item_id = $this->get('item'); |
| 129 |
} |
| 130 |
$item = new stdClass(); |
| 131 |
$form = get_post($item_id); |
| 132 |
if ($form) { |
| 133 |
$item->id = (string) $item_id; |
| 134 |
$item->name = $form->post_title ? $form->post_title : $item_id; |
| 135 |
$item->url = $this->helper->get_url( |
| 136 |
array( |
| 137 |
'page' => 'evf-builder', |
| 138 |
'tab' => 'fields', |
| 139 |
'form_id' => $item_id, |
| 140 |
'action' => 'edit', |
| 141 |
), 'admin.php?' |
| 142 |
); |
| 143 |
} else { |
| 144 |
$item->id = ''; |
| 145 |
$item->name = ''; |
| 146 |
$item->url = ''; |
| 147 |
} |
| 148 |
return $item; |
| 149 |
} |
| 150 |
|
| 151 |
// datasets |
| 152 |
public function datasets($item_id = false, $name = false) { |
| 153 |
$datasets = array(); |
| 154 |
if (function_exists('evf_get_entries_ids')) { |
| 155 |
$entries = array_reverse(evf_get_entries_ids($item_id)); |
| 156 |
$this->set('item', $item_id); |
| 157 |
foreach ($entries as $key => $entry) { |
| 158 |
$this->set('dataset', $entry); |
| 159 |
$entry_title = $this->render($name); |
| 160 |
if (!$entry_title) { |
| 161 |
$entry_title = $entry; |
| 162 |
} |
| 163 |
$datasets[] = array( |
| 164 |
'key' => $entry, |
| 165 |
'value' => $entry_title, |
| 166 |
); |
| 167 |
} |
| 168 |
} |
| 169 |
return $datasets; |
| 170 |
} |
| 171 |
|
| 172 |
// get dataset actions |
| 173 |
public function get_dataset_actions($dataset_id = false) { |
| 174 |
$dataset_id = (int) $dataset_id; |
| 175 |
if (!$dataset_id) { |
| 176 |
return false; |
| 177 |
} |
| 178 |
$item = evf_get_entry($dataset_id); |
| 179 |
$actions = new stdClass(); |
| 180 |
$actions->view = $this->helper->get_url( |
| 181 |
array( |
| 182 |
'page' => 'evf-entries', |
| 183 |
'form_id' => !empty($item->form_id) ? $item->form_id : '0', |
| 184 |
'view-entry' => $dataset_id, |
| 185 |
) |
| 186 |
); |
| 187 |
$actions->delete = false; |
| 188 |
return $actions; |
| 189 |
} |
| 190 |
|
| 191 |
// render |
| 192 |
public function render($value, $field = array(), $convert_shortcodes = true, $raw = false) { |
| 193 |
$value = $this->render_shortcodes($value, $field); |
| 194 |
if (!$raw) { |
| 195 |
$value = $this->strip_shortcodes($value); |
| 196 |
$value = $this->convert_shortcodes($value, $convert_shortcodes, isset($field['type']) && $field['type'] == 'e2pdf-html' ? true : false); |
| 197 |
$value = $this->helper->load('field')->render_checkbox($value, $this, $field); |
| 198 |
} |
| 199 |
return $value; |
| 200 |
} |
| 201 |
|
| 202 |
// render shortcodes |
| 203 |
public function render_shortcodes($value, $field = array()) { |
| 204 |
$element_id = isset($field['element_id']) ? $field['element_id'] : false; |
| 205 |
if ($this->verify()) { |
| 206 |
if (false !== strpos($value, '[')) { |
| 207 |
$value = $this->helper->load('field')->pre_shortcodes($value, $this, $field); |
| 208 |
$value = $this->helper->load('field')->inner_shortcodes($value, $this, $field); |
| 209 |
$value = $this->helper->load('field')->wrapper_shortcodes($value, $this, $field); |
| 210 |
} |
| 211 |
$value = $this->helper->load('field')->do_shortcodes($value, $this, $field); |
| 212 |
|
| 213 |
add_filter('everest_forms_process_smart_tags', array($this, 'filter_everest_forms_process_smart_tags'), 0, 3); |
| 214 |
$value = apply_filters('everest_forms_process_smart_tags', $value, $this->get('cached_form_data'), $this->get('cached_fields'), $this->get('dataset')); |
| 215 |
remove_filter('everest_forms_process_smart_tags', array($this, 'filter_everest_forms_process_smart_tags'), 99); |
| 216 |
|
| 217 |
$value = $this->helper->load('field')->render( |
| 218 |
apply_filters('e2pdf_extension_render_shortcodes_pre_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false), |
| 219 |
$this, |
| 220 |
$field |
| 221 |
); |
| 222 |
} |
| 223 |
return apply_filters( |
| 224 |
'e2pdf_extension_render_shortcodes_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false |
| 225 |
); |
| 226 |
} |
| 227 |
|
| 228 |
// strip shortcodes |
| 229 |
public function strip_shortcodes($value) { |
| 230 |
$value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', '', $value); |
| 231 |
$value = preg_replace('~a\:\d+\:{[^}]*}(*SKIP)(*FAIL)|{[^}]*}~', '', $value); |
| 232 |
return $value; |
| 233 |
} |
| 234 |
|
| 235 |
// strip math |
| 236 |
public function strip_math($value, &$replacements) { |
| 237 |
if ($value) { |
| 238 |
preg_match_all('/\{[^}]+\}/', $value, $matches); |
| 239 |
foreach ($matches[0] as $match) { |
| 240 |
$index = count($replacements) + 1; |
| 241 |
$replacements[] = $match; |
| 242 |
$value = str_replace($match, '%' . $index . '$s', $value); |
| 243 |
} |
| 244 |
} |
| 245 |
return $value; |
| 246 |
} |
| 247 |
|
| 248 |
// convert shortcodes |
| 249 |
public function convert_shortcodes($value, $to = false, $html = false) { |
| 250 |
if ($value) { |
| 251 |
if ($to) { |
| 252 |
$value = stripslashes_deep($value); |
| 253 |
$value = str_replace('[', '[', $value); |
| 254 |
if (!$html) { |
| 255 |
$value = wp_specialchars_decode($value, ENT_QUOTES); |
| 256 |
} |
| 257 |
} else { |
| 258 |
$value = str_replace('[', '[', $value); |
| 259 |
} |
| 260 |
} |
| 261 |
return $value; |
| 262 |
} |
| 263 |
|
| 264 |
// verify |
| 265 |
public function verify() { |
| 266 |
if ($this->get('cached_entry')) { |
| 267 |
return true; |
| 268 |
} |
| 269 |
return false; |
| 270 |
} |
| 271 |
|
| 272 |
// visual mapper |
| 273 |
public function visual_mapper() { |
| 274 |
$source = ''; |
| 275 |
$html = ''; |
| 276 |
if ($this->get('item')) { |
| 277 |
$source = do_shortcode('[everest_form id="' . $this->get('item') . '"]'); |
| 278 |
if ($source) { |
| 279 |
$dom = new DOMDocument(); |
| 280 |
$html = $this->helper->load('convert')->load_html($source, $dom, true); |
| 281 |
} |
| 282 |
if (!$source) { |
| 283 |
return '<div class="e2pdf-vm-error">' . __("The form source is empty or doesn't exist", 'e2pdf') . '</div>'; |
| 284 |
} elseif (!$html) { |
| 285 |
return '<div class="e2pdf-vm-error">' . __('The form could not be parsed due the incorrect HTML', 'e2pdf') . '</div>'; |
| 286 |
} else { |
| 287 |
$form = get_post($this->get('item')); |
| 288 |
$form_fields = array(); |
| 289 |
if (function_exists('evf_decode') && $form && !empty($form->post_content)) { |
| 290 |
$post_content = evf_decode($form->post_content); |
| 291 |
if (!empty($post_content['form_fields'])) { |
| 292 |
$form_fields = $post_content['form_fields']; |
| 293 |
} |
| 294 |
} |
| 295 |
$xml = $this->helper->load('xml'); |
| 296 |
$xpath = new DomXPath($dom); |
| 297 |
|
| 298 |
// remove by name |
| 299 |
$remove_by_name = array( |
| 300 |
'everest_forms[id]', |
| 301 |
'everest_forms[author]', |
| 302 |
'_wpnonce6090', |
| 303 |
'_wp_http_referer', |
| 304 |
); |
| 305 |
foreach ($remove_by_name as $key => $name) { |
| 306 |
$elements = $xpath->query('//*[@name="' . $name . '"]'); |
| 307 |
foreach ($elements as $element) { |
| 308 |
$element->parentNode->removeChild($element); |
| 309 |
} |
| 310 |
} |
| 311 |
|
| 312 |
$elements = $xpath->query("//*[contains(@class, 'dropzone-input')]"); |
| 313 |
foreach ($elements as $element) { |
| 314 |
$field_id = preg_replace('/everest_forms_(\d+)_([^\]\.*]+)/', '$2', $xml->get_node_value($element, 'name')); |
| 315 |
if (isset($form_fields[$field_id])) { |
| 316 |
$field_id = $this->get_field_id_for_smarttags($form_fields[$field_id]); |
| 317 |
$xml->set_node_value($element, 'name', '{field_id="' . $field_id . '"}'); |
| 318 |
$parent = $element->parentNode; |
| 319 |
if ($parent && strpos($parent->getAttribute('class'), 'evf-field-image-upload') !== false) { |
| 320 |
$dropzone = $xpath->query(".//*[contains(@class, 'everest-forms-uploader')]", $parent)->item(0); |
| 321 |
$max_file_number = (int) $xml->get_node_value($dropzone, 'data-max-file-number'); |
| 322 |
if ($max_file_number > 1) { |
| 323 |
$xml->set_node_value($element, 'name', '[e2pdf-format-output explode=", " output="{0}"]' . $xml->get_node_value($element, 'name') . '[/e2pdf-format-output]'); |
| 324 |
} |
| 325 |
} |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
$elements = $xpath->query("//*[contains(@data-field-type, 'repeater-fields')]"); |
| 330 |
foreach ($elements as $element) { |
| 331 |
$sub_element = $xpath->query(".//div[contains(@class, 'repeater_button_add_remove_label')]", $element)->item(0); |
| 332 |
if ($sub_element) { |
| 333 |
$input = $element->ownerDocument->createElement('input'); |
| 334 |
$input->setAttribute('type', 'text'); |
| 335 |
$field_id = $xml->get_node_value($element, 'data-repeater-field-id'); |
| 336 |
if (isset($form_fields[$field_id])) { |
| 337 |
$field_id = $this->get_field_id_for_smarttags($form_fields[$field_id]); |
| 338 |
$input->setAttribute('name', '{field_id="' . $field_id . '"}'); |
| 339 |
$sub_element->appendChild($input); |
| 340 |
} |
| 341 |
} |
| 342 |
} |
| 343 |
|
| 344 |
$elements = $xpath->query("//*[contains(@class, 'evf-signature-input') or contains(@class, 'evf-payment-price') or contains(@class, 'evf-payment-subtotal') or contains(@class, 'evf-payment-total')]"); |
| 345 |
foreach ($elements as $element) { |
| 346 |
$xml->set_node_value($element, 'type', 'text'); |
| 347 |
} |
| 348 |
|
| 349 |
$elements = $xpath->query('//input|//textarea|//select'); |
| 350 |
foreach ($elements as $element) { |
| 351 |
$field_id = preg_replace('/everest_forms\[form_fields\]\[([^\]\.*]+)\].*/', '$1', $xml->get_node_value($element, 'name')); |
| 352 |
if (isset($form_fields[$field_id])) { |
| 353 |
$field_id = $this->get_field_id_for_smarttags($form_fields[$field_id]); |
| 354 |
$xml->set_node_value($element, 'name', '{field_id="' . $field_id . '"}'); |
| 355 |
} |
| 356 |
} |
| 357 |
$submit_buttons = $xpath->query("//input[@type='submit']|//button[@type='submit']"); |
| 358 |
foreach ($submit_buttons as $element) { |
| 359 |
$element->parentNode->removeChild($element); |
| 360 |
} |
| 361 |
|
| 362 |
if (defined('LIBXML_HTML_NOIMPLIED') && defined('LIBXML_HTML_NODEFDTD')) { |
| 363 |
return str_replace(array('<html>', '</html>'), '', $dom->saveHTML()); |
| 364 |
} else { |
| 365 |
return $dom->saveHTML(); |
| 366 |
} |
| 367 |
} |
| 368 |
} |
| 369 |
return false; |
| 370 |
} |
| 371 |
|
| 372 |
// auto |
| 373 |
public function auto() { |
| 374 |
$response = array(); |
| 375 |
$elements = array(); |
| 376 |
$fields = array(); |
| 377 |
|
| 378 |
$form = evf()->form->get( |
| 379 |
$this->get('item'), |
| 380 |
array( |
| 381 |
'content_only' => true, |
| 382 |
) |
| 383 |
); |
| 384 |
$fields = $form['form_fields']; |
| 385 |
|
| 386 |
foreach ($fields as $field) { |
| 387 |
|
| 388 |
$field_value = '{field_id="' . $this->get_field_id_for_smarttags($field) . '"}'; |
| 389 |
$field_label = isset($field['label']) ? $field['label'] : ''; |
| 390 |
|
| 391 |
switch ($field['type']) { |
| 392 |
case 'text': |
| 393 |
case 'email': |
| 394 |
case 'first-name': |
| 395 |
case 'last-name': |
| 396 |
case 'number': |
| 397 |
case 'url': |
| 398 |
case 'phone': |
| 399 |
case 'date-time': |
| 400 |
case 'rating': |
| 401 |
case 'scale-rating': |
| 402 |
case 'payment-quantity': |
| 403 |
$elements[] = $this->auto_field( |
| 404 |
$field, |
| 405 |
array( |
| 406 |
'type' => 'e2pdf-html', |
| 407 |
'block' => true, |
| 408 |
'float' => true, |
| 409 |
'properties' => array( |
| 410 |
'top' => '20', |
| 411 |
'left' => '20', |
| 412 |
'right' => '20', |
| 413 |
'width' => '100%', |
| 414 |
'height' => 'auto', |
| 415 |
'value' => $field_label, |
| 416 |
), |
| 417 |
) |
| 418 |
); |
| 419 |
$elements[] = $this->auto_field( |
| 420 |
$field, |
| 421 |
array( |
| 422 |
'type' => 'e2pdf-input', |
| 423 |
'properties' => array( |
| 424 |
'top' => '5', |
| 425 |
'width' => '100%', |
| 426 |
'height' => 'auto', |
| 427 |
'value' => $field_value, |
| 428 |
), |
| 429 |
) |
| 430 |
); |
| 431 |
break; |
| 432 |
case 'select': |
| 433 |
$elements[] = $this->auto_field( |
| 434 |
$field, |
| 435 |
array( |
| 436 |
'type' => 'e2pdf-html', |
| 437 |
'block' => true, |
| 438 |
'float' => true, |
| 439 |
'properties' => array( |
| 440 |
'top' => '20', |
| 441 |
'left' => '20', |
| 442 |
'right' => '20', |
| 443 |
'width' => '100%', |
| 444 |
'height' => 'auto', |
| 445 |
'value' => $field_label, |
| 446 |
), |
| 447 |
) |
| 448 |
); |
| 449 |
$field_options = array(); |
| 450 |
foreach ($field['choices'] as $option) { |
| 451 |
$option_value = isset($option['label']) ? $option['label'] : ''; |
| 452 |
$field_options[] = $option_value; |
| 453 |
} |
| 454 |
$elements[] = $this->auto_field( |
| 455 |
$field, |
| 456 |
array( |
| 457 |
'type' => 'e2pdf-select', |
| 458 |
'properties' => array( |
| 459 |
'top' => '5', |
| 460 |
'width' => '100%', |
| 461 |
'height' => 'auto', |
| 462 |
'options' => implode("\n", $field_options), |
| 463 |
'value' => $field_value, |
| 464 |
), |
| 465 |
) |
| 466 |
); |
| 467 |
break; |
| 468 |
case 'yes-no': |
| 469 |
case 'radio': |
| 470 |
$elements[] = $this->auto_field( |
| 471 |
$field, |
| 472 |
array( |
| 473 |
'type' => 'e2pdf-html', |
| 474 |
'block' => true, |
| 475 |
'float' => true, |
| 476 |
'properties' => array( |
| 477 |
'top' => '20', |
| 478 |
'left' => '20', |
| 479 |
'right' => '20', |
| 480 |
'width' => '100%', |
| 481 |
'height' => 'auto', |
| 482 |
'value' => $field_label, |
| 483 |
), |
| 484 |
) |
| 485 |
); |
| 486 |
|
| 487 |
if ($field['type'] == 'yes-no') { |
| 488 |
$field['choices'] = array( |
| 489 |
array( |
| 490 |
'label' => $field['yes_label'], |
| 491 |
'value' => $field['yes_value'], |
| 492 |
), |
| 493 |
array( |
| 494 |
'label' => $field['no_label'], |
| 495 |
'value' => $field['no_value'], |
| 496 |
), |
| 497 |
); |
| 498 |
} |
| 499 |
|
| 500 |
foreach ($field['choices'] as $opt_key => $option) { |
| 501 |
if ($field['type'] == 'yes-no') { |
| 502 |
$option_value = isset($option['value']) ? $option['value'] : ''; |
| 503 |
} else { |
| 504 |
$option_value = isset($option['label']) ? $option['label'] : ''; |
| 505 |
} |
| 506 |
$elements[] = $this->auto_field( |
| 507 |
$field, |
| 508 |
array( |
| 509 |
'type' => 'e2pdf-radio', |
| 510 |
'properties' => array( |
| 511 |
'top' => '5', |
| 512 |
'width' => 'auto', |
| 513 |
'height' => 'auto', |
| 514 |
'value' => $field_value, |
| 515 |
'option' => $option_value, |
| 516 |
'group' => $field_value, |
| 517 |
), |
| 518 |
) |
| 519 |
); |
| 520 |
$elements[] = $this->auto_field( |
| 521 |
$field, |
| 522 |
array( |
| 523 |
'type' => 'e2pdf-html', |
| 524 |
'float' => true, |
| 525 |
'properties' => array( |
| 526 |
'left' => '5', |
| 527 |
'width' => '100%', |
| 528 |
'height' => 'auto', |
| 529 |
'value' => $option['label'], |
| 530 |
), |
| 531 |
) |
| 532 |
); |
| 533 |
} |
| 534 |
break; |
| 535 |
case 'checkbox': |
| 536 |
$elements[] = $this->auto_field( |
| 537 |
$field, |
| 538 |
array( |
| 539 |
'type' => 'e2pdf-html', |
| 540 |
'block' => true, |
| 541 |
'float' => true, |
| 542 |
'properties' => array( |
| 543 |
'top' => '20', |
| 544 |
'left' => '20', |
| 545 |
'right' => '20', |
| 546 |
'width' => '100%', |
| 547 |
'height' => 'auto', |
| 548 |
'value' => $field_label, |
| 549 |
), |
| 550 |
) |
| 551 |
); |
| 552 |
foreach ($field['choices'] as $opt_key => $option) { |
| 553 |
$option_value = isset($option['label']) ? $option['label'] : ''; |
| 554 |
$elements[] = $this->auto_field( |
| 555 |
$field, |
| 556 |
array( |
| 557 |
'type' => 'e2pdf-checkbox', |
| 558 |
'properties' => array( |
| 559 |
'top' => '5', |
| 560 |
'width' => 'auto', |
| 561 |
'height' => 'auto', |
| 562 |
'value' => $field_value, |
| 563 |
'option' => $option_value, |
| 564 |
), |
| 565 |
) |
| 566 |
); |
| 567 |
$elements[] = $this->auto_field( |
| 568 |
$field, |
| 569 |
array( |
| 570 |
'type' => 'e2pdf-html', |
| 571 |
'float' => true, |
| 572 |
'properties' => array( |
| 573 |
'left' => '5', |
| 574 |
'width' => '100%', |
| 575 |
'height' => 'auto', |
| 576 |
'value' => $option['label'], |
| 577 |
), |
| 578 |
) |
| 579 |
); |
| 580 |
} |
| 581 |
break; |
| 582 |
case 'image-upload': |
| 583 |
$elements[] = $this->auto_field( |
| 584 |
$field, |
| 585 |
array( |
| 586 |
'type' => 'e2pdf-html', |
| 587 |
'block' => true, |
| 588 |
'float' => true, |
| 589 |
'properties' => array( |
| 590 |
'top' => '20', |
| 591 |
'left' => '20', |
| 592 |
'right' => '20', |
| 593 |
'width' => '100%', |
| 594 |
'height' => 'auto', |
| 595 |
'value' => $field_label, |
| 596 |
), |
| 597 |
) |
| 598 |
); |
| 599 |
|
| 600 |
$max_file_number = 1; |
| 601 |
if (!empty($field['max_file_number'])) { |
| 602 |
$max_file_number = (int) $field['max_file_number']; |
| 603 |
} |
| 604 |
|
| 605 |
for ($i = 0; $i < $max_file_number; $i++) { |
| 606 |
$elements[] = $this->auto_field( |
| 607 |
$field, |
| 608 |
array( |
| 609 |
'type' => 'e2pdf-image', |
| 610 |
'float' => true, |
| 611 |
'block' => true, |
| 612 |
'properties' => array( |
| 613 |
'top' => '5', |
| 614 |
'left' => '20', |
| 615 |
'right' => '0', |
| 616 |
'width' => '170', |
| 617 |
'height' => '150', |
| 618 |
'value' => $max_file_number > 1 ? '[e2pdf-format-output explode=", " output="{' . $i . '}"]' . $field_value . '[/e2pdf-format-output]' : $field_value, |
| 619 |
), |
| 620 |
) |
| 621 |
); |
| 622 |
} |
| 623 |
break; |
| 624 |
case 'textarea': |
| 625 |
case 'file-upload': |
| 626 |
case 'address': |
| 627 |
case 'country': |
| 628 |
case 'likert': |
| 629 |
$elements[] = $this->auto_field( |
| 630 |
$field, |
| 631 |
array( |
| 632 |
'type' => 'e2pdf-html', |
| 633 |
'block' => true, |
| 634 |
'float' => true, |
| 635 |
'properties' => array( |
| 636 |
'top' => '20', |
| 637 |
'left' => '20', |
| 638 |
'right' => '20', |
| 639 |
'width' => '100%', |
| 640 |
'height' => 'auto', |
| 641 |
'value' => $field_label, |
| 642 |
), |
| 643 |
) |
| 644 |
); |
| 645 |
|
| 646 |
$elements[] = $this->auto_field( |
| 647 |
$field, |
| 648 |
array( |
| 649 |
'type' => 'e2pdf-textarea', |
| 650 |
'properties' => array( |
| 651 |
'top' => '5', |
| 652 |
'width' => '100%', |
| 653 |
'height' => 'auto', |
| 654 |
'value' => $field_value, |
| 655 |
), |
| 656 |
) |
| 657 |
); |
| 658 |
break; |
| 659 |
case 'privacy-policy': |
| 660 |
$elements[] = $this->auto_field( |
| 661 |
$field, |
| 662 |
array( |
| 663 |
'type' => 'e2pdf-html', |
| 664 |
'block' => true, |
| 665 |
'float' => true, |
| 666 |
'properties' => array( |
| 667 |
'top' => '20', |
| 668 |
'left' => '20', |
| 669 |
'right' => '20', |
| 670 |
'width' => '100%', |
| 671 |
'height' => 'auto', |
| 672 |
'value' => $field_label, |
| 673 |
), |
| 674 |
) |
| 675 |
); |
| 676 |
|
| 677 |
$elements[] = $this->auto_field( |
| 678 |
$field, |
| 679 |
array( |
| 680 |
'type' => 'e2pdf-checkbox', |
| 681 |
'properties' => array( |
| 682 |
'top' => '5', |
| 683 |
'width' => 'auto', |
| 684 |
'height' => 'auto', |
| 685 |
'value' => $field_value, |
| 686 |
'option' => isset($field['consent_message']) ? $field['consent_message'] : '', |
| 687 |
), |
| 688 |
) |
| 689 |
); |
| 690 |
|
| 691 |
$elements[] = $this->auto_field( |
| 692 |
$field, |
| 693 |
array( |
| 694 |
'type' => 'e2pdf-html', |
| 695 |
'float' => true, |
| 696 |
'properties' => array( |
| 697 |
'left' => '5', |
| 698 |
'width' => '100%', |
| 699 |
'height' => 'auto', |
| 700 |
'value' => $field['consent_message'], |
| 701 |
), |
| 702 |
) |
| 703 |
); |
| 704 |
break; |
| 705 |
case 'signature': |
| 706 |
$elements[] = $this->auto_field( |
| 707 |
$field, |
| 708 |
array( |
| 709 |
'type' => 'e2pdf-html', |
| 710 |
'block' => true, |
| 711 |
'float' => true, |
| 712 |
'properties' => array( |
| 713 |
'top' => '20', |
| 714 |
'left' => '20', |
| 715 |
'right' => '20', |
| 716 |
'width' => '100%', |
| 717 |
'height' => 'auto', |
| 718 |
'value' => isset($field['settings']['label']) ? $field['settings']['label'] : '', |
| 719 |
), |
| 720 |
) |
| 721 |
); |
| 722 |
|
| 723 |
$elements[] = $this->auto_field( |
| 724 |
$field, |
| 725 |
array( |
| 726 |
'type' => 'e2pdf-signature', |
| 727 |
'properties' => array( |
| 728 |
'top' => '5', |
| 729 |
'width' => '100%', |
| 730 |
'height' => '150', |
| 731 |
'dimension' => '1', |
| 732 |
'block_dimension' => '1', |
| 733 |
'value' => $field_value, |
| 734 |
), |
| 735 |
) |
| 736 |
); |
| 737 |
break; |
| 738 |
case 'wysiwyg': |
| 739 |
$elements[] = $this->auto_field( |
| 740 |
$field, |
| 741 |
array( |
| 742 |
'type' => 'e2pdf-html', |
| 743 |
'block' => true, |
| 744 |
'float' => true, |
| 745 |
'properties' => array( |
| 746 |
'top' => '20', |
| 747 |
'left' => '20', |
| 748 |
'right' => '20', |
| 749 |
'width' => '100%', |
| 750 |
'height' => 'auto', |
| 751 |
'value' => $field_label, |
| 752 |
), |
| 753 |
) |
| 754 |
); |
| 755 |
|
| 756 |
$elements[] = $this->auto_field( |
| 757 |
$field, |
| 758 |
array( |
| 759 |
'type' => 'e2pdf-html', |
| 760 |
'properties' => array( |
| 761 |
'top' => '5', |
| 762 |
'width' => '100%', |
| 763 |
'height' => '150', |
| 764 |
'value' => $field_value, |
| 765 |
), |
| 766 |
) |
| 767 |
); |
| 768 |
break; |
| 769 |
case 'html': |
| 770 |
$elements[] = $this->auto_field( |
| 771 |
$field, |
| 772 |
array( |
| 773 |
'type' => 'e2pdf-html', |
| 774 |
'block' => true, |
| 775 |
'float' => true, |
| 776 |
'properties' => array( |
| 777 |
'top' => '20', |
| 778 |
'left' => '20', |
| 779 |
'right' => '20', |
| 780 |
'width' => '100%', |
| 781 |
'height' => 'auto', |
| 782 |
'value' => isset($field['code']) ? $field['code'] : '', |
| 783 |
), |
| 784 |
) |
| 785 |
); |
| 786 |
break; |
| 787 |
case 'title': |
| 788 |
$elements[] = $this->auto_field( |
| 789 |
$field, |
| 790 |
array( |
| 791 |
'type' => 'e2pdf-html', |
| 792 |
'block' => true, |
| 793 |
'float' => true, |
| 794 |
'properties' => array( |
| 795 |
'top' => '20', |
| 796 |
'left' => '20', |
| 797 |
'right' => '20', |
| 798 |
'width' => '100%', |
| 799 |
'height' => 'auto', |
| 800 |
'value' => $field_label, |
| 801 |
), |
| 802 |
) |
| 803 |
); |
| 804 |
if (!empty($field['description'])) { |
| 805 |
$elements[] = $this->auto_field( |
| 806 |
$field, |
| 807 |
array( |
| 808 |
'type' => 'e2pdf-html', |
| 809 |
'block' => true, |
| 810 |
'float' => true, |
| 811 |
'properties' => array( |
| 812 |
'top' => '5', |
| 813 |
'left' => '20', |
| 814 |
'right' => '20', |
| 815 |
'width' => '100%', |
| 816 |
'height' => 'auto', |
| 817 |
'value' => isset($field['description']) ? $field['description'] : '', |
| 818 |
), |
| 819 |
) |
| 820 |
); |
| 821 |
} |
| 822 |
break; |
| 823 |
case 'payment-single': |
| 824 |
$elements[] = $this->auto_field( |
| 825 |
$field, |
| 826 |
array( |
| 827 |
'type' => 'e2pdf-html', |
| 828 |
'block' => true, |
| 829 |
'float' => true, |
| 830 |
'properties' => array( |
| 831 |
'top' => '20', |
| 832 |
'left' => '20', |
| 833 |
'right' => '20', |
| 834 |
'width' => '100%', |
| 835 |
'height' => 'auto', |
| 836 |
'value' => $field_label, |
| 837 |
), |
| 838 |
) |
| 839 |
); |
| 840 |
if (!empty($field['description'])) { |
| 841 |
$elements[] = $this->auto_field( |
| 842 |
$field, |
| 843 |
array( |
| 844 |
'type' => 'e2pdf-html', |
| 845 |
'block' => true, |
| 846 |
'float' => true, |
| 847 |
'properties' => array( |
| 848 |
'top' => '5', |
| 849 |
'left' => '20', |
| 850 |
'right' => '20', |
| 851 |
'width' => '100%', |
| 852 |
'height' => 'auto', |
| 853 |
'value' => isset($field['description']) ? $field['description'] : '', |
| 854 |
), |
| 855 |
) |
| 856 |
); |
| 857 |
} |
| 858 |
$elements[] = $this->auto_field( |
| 859 |
$field, |
| 860 |
array( |
| 861 |
'type' => 'e2pdf-html', |
| 862 |
'properties' => array( |
| 863 |
'top' => '5', |
| 864 |
'width' => '100%', |
| 865 |
'height' => 'auto', |
| 866 |
'value' => $field_value, |
| 867 |
), |
| 868 |
) |
| 869 |
); |
| 870 |
|
| 871 |
break; |
| 872 |
case 'payment-subtotal': |
| 873 |
case 'payment-total': |
| 874 |
$elements[] = $this->auto_field( |
| 875 |
$field, |
| 876 |
array( |
| 877 |
'type' => 'e2pdf-html', |
| 878 |
'block' => true, |
| 879 |
'float' => true, |
| 880 |
'properties' => array( |
| 881 |
'top' => '20', |
| 882 |
'left' => '20', |
| 883 |
'right' => '20', |
| 884 |
'width' => '100%', |
| 885 |
'height' => 'auto', |
| 886 |
'value' => $field_label, |
| 887 |
), |
| 888 |
) |
| 889 |
); |
| 890 |
$elements[] = $this->auto_field( |
| 891 |
$field, |
| 892 |
array( |
| 893 |
'type' => 'e2pdf-html', |
| 894 |
'properties' => array( |
| 895 |
'top' => '5', |
| 896 |
'width' => '100%', |
| 897 |
'height' => 'auto', |
| 898 |
'value' => $field_value, |
| 899 |
), |
| 900 |
) |
| 901 |
); |
| 902 |
break; |
| 903 |
case 'divider': |
| 904 |
case 'hidden': |
| 905 |
case 'repeater-fields': |
| 906 |
break; |
| 907 |
default: |
| 908 |
break; |
| 909 |
} |
| 910 |
} |
| 911 |
|
| 912 |
$response['page'] = array( |
| 913 |
'bottom' => '20', |
| 914 |
'top' => '20', |
| 915 |
); |
| 916 |
$response['elements'] = $elements; |
| 917 |
return $response; |
| 918 |
} |
| 919 |
|
| 920 |
// auto field |
| 921 |
public function auto_field($field = false, $element = array()) { |
| 922 |
if (!$field) { |
| 923 |
return false; |
| 924 |
} |
| 925 |
if (!isset($element['block'])) { |
| 926 |
$element['block'] = false; |
| 927 |
} |
| 928 |
if (!isset($element['float'])) { |
| 929 |
$element['float'] = false; |
| 930 |
} |
| 931 |
return $element; |
| 932 |
} |
| 933 |
|
| 934 |
// styles |
| 935 |
public function styles($item_id = false) { |
| 936 |
$styles = array(); |
| 937 |
if (function_exists('evf')) { |
| 938 |
$styles[] = evf()->plugin_url() . '/assets/css/everest-forms.css?v=' . time(); |
| 939 |
} |
| 940 |
$styles[] = plugins_url('css/extension/everest.css?v=' . time(), $this->helper->get('plugin_file_path')); |
| 941 |
return $styles; |
| 942 |
} |
| 943 |
|
| 944 |
// get field id for smarttags |
| 945 |
public function get_field_id_for_smarttags($field) { |
| 946 |
$field_id = isset($field['id']) ? $field['id'] : ''; |
| 947 |
$field_label = isset($field['label']) ? $field['label'] : ''; |
| 948 |
$field_type = isset($field['type']) ? $field['type'] : ''; |
| 949 |
if ('fullname' !== $field_id && 'email' !== $field_id && 'subject' !== $field_id && 'message' !== $field_id) { |
| 950 |
$field_label = preg_split('/[\s\-\_]/', $field_label); |
| 951 |
foreach ($field_label as $key => $value) { |
| 952 |
if (0 === $key) { |
| 953 |
$field_label[$key] = strtolower($value); |
| 954 |
} else { |
| 955 |
$field_label[$key] = ucfirst($value); |
| 956 |
} |
| 957 |
} |
| 958 |
$field_label = implode('', $field_label); |
| 959 |
$field_id = $field_label . '_' . $field_id; |
| 960 |
} else { |
| 961 |
$field_id = $field_id; |
| 962 |
} |
| 963 |
if ($field_type != 'repeater-fields' && isset($field['repeater-fields']) && $field['repeater-fields'] == 'yes') { |
| 964 |
$field_id .= '_1'; |
| 965 |
} |
| 966 |
return $field_id; |
| 967 |
} |
| 968 |
|
| 969 |
// get merge tag value |
| 970 |
public function get_merge_tag_value($value) { |
| 971 |
if (isset($value['type'])) { |
| 972 |
switch ($value['type']) { |
| 973 |
case 'checkbox': |
| 974 |
case 'payment-checkbox': |
| 975 |
$value = isset($value['label']) ? implode(', ', $value['label']) : ''; |
| 976 |
break; |
| 977 |
case 'country': |
| 978 |
$value = isset($value['country_code']) ? $value['country_code'] : ''; |
| 979 |
break; |
| 980 |
case 'image-upload': |
| 981 |
case 'file-upload': |
| 982 |
$files = []; |
| 983 |
$uploads = wp_upload_dir(); |
| 984 |
if (!empty($value['value_raw'])) { |
| 985 |
foreach ($value['value_raw'] as $files_key => $files_value) { |
| 986 |
if (!is_array($files_value['value']) && false !== strpos($files_value['value'], $uploads['basedir'])) { |
| 987 |
$value = trailingslashit(content_url()) . str_replace(str_replace('uploads', '', $uploads['basedir']), '', $files_value['value']); |
| 988 |
} |
| 989 |
if (!empty($value)) { |
| 990 |
$files[] = $files_value['value']; |
| 991 |
} |
| 992 |
} |
| 993 |
} |
| 994 |
$value = implode(', ', $files); |
| 995 |
break; |
| 996 |
} |
| 997 |
return $value; |
| 998 |
} |
| 999 |
return ''; |
| 1000 |
} |
| 1001 |
|
| 1002 |
// email send after action |
| 1003 |
public function action_everest_forms_email_send_after() { |
| 1004 |
$files = $this->helper->get('tmp_everest_attachments'); |
| 1005 |
if (is_array($files) && !empty($files)) { |
| 1006 |
foreach ($files as $key => $file) { |
| 1007 |
$this->helper->delete_dir(dirname($file) . '/'); |
| 1008 |
} |
| 1009 |
$this->helper->deset('tmp_everest_attachments'); |
| 1010 |
$this->helper->deset('everest_attachments'); |
| 1011 |
} |
| 1012 |
} |
| 1013 |
|
| 1014 |
// before template part action |
| 1015 |
public function action_everest_forms_before_template_part($template_name) { |
| 1016 |
if ($template_name == 'notices/success.php') { |
| 1017 |
ob_start(); |
| 1018 |
} |
| 1019 |
} |
| 1020 |
|
| 1021 |
// after template part action |
| 1022 |
public function action_everest_forms_after_template_part($template_name) { |
| 1023 |
if ($template_name == 'notices/success.php') { |
| 1024 |
$content = ob_get_clean(); |
| 1025 |
$content = $this->filter_message($content); |
| 1026 |
echo $content; |
| 1027 |
remove_action('everest_forms_before_template_part', array($this, 'action_everest_forms_before_template_part'), 99); |
| 1028 |
remove_action('everest_forms_after_template_part', array($this, 'action_everest_forms_after_template_part'), 99); |
| 1029 |
} |
| 1030 |
} |
| 1031 |
|
| 1032 |
// after success ajax message filter |
| 1033 |
public function filter_everest_forms_after_success_ajax_message($response_data, $form_data, $entry) { |
| 1034 |
if (!empty($response_data['message'])) { |
| 1035 |
$response_data['message'] = $this->filter_message($response_data['message']); |
| 1036 |
} |
| 1037 |
return $response_data; |
| 1038 |
} |
| 1039 |
|
| 1040 |
// email attachments filter |
| 1041 |
public function filter_everest_forms_email_attachments($attachments, $mail) { |
| 1042 |
$files = $this->helper->get('everest_attachments'); |
| 1043 |
if (is_array($files) && !empty($files)) { |
| 1044 |
$attachments = $this->helper->load('convert')->is_string_array($attachments); |
| 1045 |
foreach ($files as $key => $file) { |
| 1046 |
$attachments[] = $file; |
| 1047 |
} |
| 1048 |
} |
| 1049 |
return $attachments; |
| 1050 |
} |
| 1051 |
|
| 1052 |
// email message filter |
| 1053 |
public function filter_everest_forms_email_message($message) { |
| 1054 |
$message = $this->filter_message($message, 'mail'); |
| 1055 |
return $message; |
| 1056 |
} |
| 1057 |
|
| 1058 |
// add success filter |
| 1059 |
public function filter_everest_forms_add_success($message) { |
| 1060 |
if (is_string($message) && false !== strpos($message, '[e2pdf-')) { |
| 1061 |
add_action('everest_forms_before_template_part', array($this, 'action_everest_forms_before_template_part'), 99); |
| 1062 |
add_action('everest_forms_after_template_part', array($this, 'action_everest_forms_after_template_part'), 99); |
| 1063 |
} |
| 1064 |
return $message; |
| 1065 |
} |
| 1066 |
|
| 1067 |
// process smart tags filter |
| 1068 |
public function filter_everest_forms_process_smart_tags($content, $form_data, $fields = '') { |
| 1069 |
|
| 1070 |
preg_match_all('/\{field_id="(.+?)"\}/', $content, $ids); |
| 1071 |
|
| 1072 |
if (!empty($ids[1]) && !empty($fields)) { |
| 1073 |
foreach ($ids[1] as $key => $field_id) { |
| 1074 |
$mixed_field_id = explode('_', $field_id); |
| 1075 |
$sub_field_id = isset($mixed_field_id[1]) ? $mixed_field_id['1'] : ''; |
| 1076 |
|
| 1077 |
$repeater_index = false; |
| 1078 |
if (isset($mixed_field_id[2])) { |
| 1079 |
$field_id = $mixed_field_id[0] . '_' . $sub_field_id; |
| 1080 |
$repeater_index = $mixed_field_id[2]; |
| 1081 |
} |
| 1082 |
|
| 1083 |
if ('fullname' !== $field_id && 'email' !== $field_id && 'subject' !== $field_id && 'message' !== $field_id) { |
| 1084 |
$value = isset($fields[$sub_field_id]['value']) && !empty($fields[$sub_field_id]['value']) ? evf_sanitize_textarea_field($fields[$sub_field_id]['value']) : ''; |
| 1085 |
} else { |
| 1086 |
$value = isset($fields[$field_id]['value']) && !empty($fields[$field_id]['value']) ? evf_sanitize_textarea_field($fields[$field_id]['value']) : ''; |
| 1087 |
} |
| 1088 |
$value = apply_filters('everest_forms_smart_tags_value', $value, $field_id, $fields, $form_data); |
| 1089 |
|
| 1090 |
// repeater |
| 1091 |
if (!isset($fields[$sub_field_id])) { |
| 1092 |
if (!empty($form_data['form_fields'])) { |
| 1093 |
foreach ($form_data['form_fields'] as $fid => $field) { |
| 1094 |
if ('repeater-fields' === $field['type']) { |
| 1095 |
if (!empty($fields[$field['id']])) { |
| 1096 |
$value = ''; |
| 1097 |
$repeater_rows = $fields[$field['id']]['value_raw']; |
| 1098 |
if ($repeater_index) { |
| 1099 |
if (isset($repeater_rows[$repeater_index]) && array_key_exists($sub_field_id, $repeater_rows[$repeater_index])) { |
| 1100 |
$value = isset($repeater_rows[$repeater_index][$sub_field_id]['value']) && !empty($repeater_rows[$repeater_index][$sub_field_id]['value']) ? evf_sanitize_textarea_field($repeater_rows[$repeater_index][$sub_field_id]['value']) : ''; |
| 1101 |
if (isset($repeater_rows[$repeater_index][$sub_field_id]['type']) && ('image-upload' === $repeater_rows[$repeater_index][$sub_field_id]['type'] || 'file-upload' === $repeater_rows[$repeater_index][$sub_field_id]['type'])) { |
| 1102 |
$value = $repeater_rows[$repeater_index][$sub_field_id]; |
| 1103 |
} |
| 1104 |
if (isset($value['type']) && in_array($value['type'], array('country', 'checkbox', 'payment-checkbox', 'image-upload', 'file-upload'), true)) { |
| 1105 |
$value = $this->get_merge_tag_value($value); |
| 1106 |
} |
| 1107 |
} |
| 1108 |
$content = str_replace('{field_id="' . $field_id . '_' . $repeater_index . '"}', $value, $content); |
| 1109 |
} else { |
| 1110 |
$values = array(); |
| 1111 |
foreach ($repeater_rows as $row_id => $row) { |
| 1112 |
if (array_key_exists($sub_field_id, $row)) { |
| 1113 |
if (isset($row[$sub_field_id]['type']) && ('image-upload' === $row[$sub_field_id]['type'] || 'file-upload' === $row[$sub_field_id]['type'])) { |
| 1114 |
$value = $row[$sub_field_id]; |
| 1115 |
} |
| 1116 |
if (isset($value['type']) && in_array($value['type'], array('country', 'checkbox', 'payment-checkbox', 'image-upload', 'file-upload'), true)) { |
| 1117 |
$values[] = $this->get_merge_tag_value($value['value']); |
| 1118 |
} else { |
| 1119 |
$values[] = $row[$sub_field_id]['value']; |
| 1120 |
} |
| 1121 |
} |
| 1122 |
} |
| 1123 |
$value = implode(',', array_filter($values)); |
| 1124 |
$content = str_replace('{field_id="' . $field_id . '"}', $value, $content); |
| 1125 |
break; |
| 1126 |
} |
| 1127 |
} |
| 1128 |
} |
| 1129 |
} |
| 1130 |
} |
| 1131 |
} else { |
| 1132 |
if (isset($fields[$sub_field_id]['type']) && ($fields[$sub_field_id]['type'] === 'image-upload' || $fields[$sub_field_id]['type'] === 'file-upload' || ($fields[$sub_field_id]['type'] === 'repeater-fields' && apply_filters('e2pdf_for_do_shortcode_data_process', false)))) { |
| 1133 |
$value = $fields[$sub_field_id]; |
| 1134 |
} |
| 1135 |
if (isset($value['type'])) { |
| 1136 |
if ($value['type'] === 'repeater-fields') { |
| 1137 |
$repeaters = array(); |
| 1138 |
if (!empty($value['value_raw']) && is_array($repeaters)) { |
| 1139 |
$repeaters = $value['value_raw']; |
| 1140 |
} |
| 1141 |
$content = str_replace('{field_id="' . $field_id . '"}', serialize($repeaters), $content); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize |
| 1142 |
} elseif (in_array($value['type'], array('country', 'checkbox', 'payment-checkbox', 'image-upload', 'file-upload'), true)) { |
| 1143 |
$content = str_replace('{field_id="' . $field_id . '"}', $this->get_merge_tag_value($value), $content); |
| 1144 |
} |
| 1145 |
} |
| 1146 |
} |
| 1147 |
} |
| 1148 |
} |
| 1149 |
return $content; |
| 1150 |
} |
| 1151 |
|
| 1152 |
// message filter |
| 1153 |
public function filter_message($message = '', $type = 'message') { |
| 1154 |
if (false !== strpos($message, '[')) { |
| 1155 |
$shortcode_tags = array( |
| 1156 |
'e2pdf-download', |
| 1157 |
'e2pdf-save', |
| 1158 |
'e2pdf-view', |
| 1159 |
'e2pdf-adobesign', |
| 1160 |
'e2pdf-zapier', |
| 1161 |
'e2pdf-attachment', |
| 1162 |
); |
| 1163 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $message, $matches); |
| 1164 |
$tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 1165 |
if (!empty($tagnames)) { |
| 1166 |
preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $message, $shortcodes); |
| 1167 |
foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 1168 |
$shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); |
| 1169 |
$atts = shortcode_parse_atts($shortcode[3]); |
| 1170 |
if (!isset($atts['dataset']) && isset($atts['id'])) { |
| 1171 |
$template = new Model_E2pdf_Template(); |
| 1172 |
$template->load($atts['id']); |
| 1173 |
if ($template->get('extension') === 'everest') { |
| 1174 |
$atts['dataset'] = evf()->task->entry_id; |
| 1175 |
$shortcode[3] .= ' dataset="' . evf()->task->entry_id . '"'; |
| 1176 |
} |
| 1177 |
} |
| 1178 |
if (!isset($atts['apply'])) { |
| 1179 |
$shortcode[3] .= ' apply="true"'; |
| 1180 |
} |
| 1181 |
if ($type == 'message' && !isset($atts['iframe_download'])) { |
| 1182 |
$shortcode[3] .= ' iframe_download="true"'; |
| 1183 |
} |
| 1184 |
$file = false; |
| 1185 |
if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { |
| 1186 |
if ($type == 'mail') { |
| 1187 |
$file = do_shortcode_tag($shortcode); |
| 1188 |
if ($file) { |
| 1189 |
$tmp = false; |
| 1190 |
if (substr($file, 0, 4) === 'tmp:') { |
| 1191 |
$file = substr($file, 4); |
| 1192 |
$tmp = true; |
| 1193 |
} |
| 1194 |
if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) { |
| 1195 |
if ($tmp) { |
| 1196 |
$this->helper->add('tmp_everest_attachments', $file); |
| 1197 |
} |
| 1198 |
} else { |
| 1199 |
$this->helper->add('tmp_everest_attachments', $file); |
| 1200 |
} |
| 1201 |
$this->helper->add('everest_attachments', $file); |
| 1202 |
} |
| 1203 |
} |
| 1204 |
$message = str_replace($shortcode_value, '', $message); |
| 1205 |
} else { |
| 1206 |
$message = str_replace($shortcode_value, do_shortcode_tag($shortcode), $message); |
| 1207 |
} |
| 1208 |
} |
| 1209 |
} |
| 1210 |
} |
| 1211 |
return $message; |
| 1212 |
} |
| 1213 |
|
| 1214 |
// row actions hook |
| 1215 |
public function hook_everest_row_actions($actions, $entry) { |
| 1216 |
if (!empty($entry->form_id)) { |
| 1217 |
$hooks = $this->helper->load('hooks')->get('everest', 'hook_everest_row_actions', $entry->form_id); |
| 1218 |
if (!empty($hooks)) { |
| 1219 |
foreach ($hooks as $hook) { |
| 1220 |
if ($this->helper->load('hooks')->process_hook( |
| 1221 |
$hook, |
| 1222 |
[ |
| 1223 |
'dataset' => $entry->entry_id, |
| 1224 |
], |
| 1225 |
'hook_everest_row_actions' |
| 1226 |
) |
| 1227 |
) { |
| 1228 |
$action = apply_filters( |
| 1229 |
'e2pdf_hook_action_button', |
| 1230 |
array( |
| 1231 |
'html' => '<a class="e2pdf-download-hook" target="_blank" href="%s">%s</a>', |
| 1232 |
'url' => $this->helper->get_url( |
| 1233 |
array( |
| 1234 |
'page' => 'e2pdf', |
| 1235 |
'action' => 'export', |
| 1236 |
'id' => $hook, |
| 1237 |
'dataset' => $entry->entry_id, |
| 1238 |
), 'admin.php?' |
| 1239 |
), |
| 1240 |
'title' => 'PDF #' . $hook, |
| 1241 |
), 'hook_everest_row_actions', $hook, $entry->entry_id |
| 1242 |
); |
| 1243 |
if (!empty($action)) { |
| 1244 |
$actions['e2pdf_' . $hook] = sprintf( |
| 1245 |
$action['html'], $action['url'], $action['title'] |
| 1246 |
); |
| 1247 |
} |
| 1248 |
} |
| 1249 |
} |
| 1250 |
} |
| 1251 |
} |
| 1252 |
return $actions; |
| 1253 |
} |
| 1254 |
|
| 1255 |
// entry view hook |
| 1256 |
public function hook_everest_entry_view($entry) { |
| 1257 |
if (!empty($entry->form_id)) { |
| 1258 |
$hooks = $this->helper->load('hooks')->get('everest', 'hook_everest_entry_view', $entry->form_id); |
| 1259 |
if (!empty($hooks)) { |
| 1260 |
foreach ($hooks as $hook) { |
| 1261 |
if ($this->helper->load('hooks')->process_hook( |
| 1262 |
$hook, |
| 1263 |
[ |
| 1264 |
'dataset' => $entry->entry_id, |
| 1265 |
], |
| 1266 |
'hook_everest_entry_view' |
| 1267 |
) |
| 1268 |
) { |
| 1269 |
$action = apply_filters( |
| 1270 |
'e2pdf_hook_action_button', |
| 1271 |
array( |
| 1272 |
'html' => '<p><a class="e2pdf-download-hook" target="_blank" title="%2$s" href="%1$s"><span class="dashicons dashicons-pdf"></span> %2$s</a></p>', |
| 1273 |
'url' => $this->helper->get_url( |
| 1274 |
array( |
| 1275 |
'page' => 'e2pdf', |
| 1276 |
'action' => 'export', |
| 1277 |
'id' => $hook, |
| 1278 |
'dataset' => $entry->entry_id, |
| 1279 |
), 'admin.php?' |
| 1280 |
), |
| 1281 |
'title' => 'PDF #' . $hook, |
| 1282 |
), 'hook_everest_entry_view', $hook, $entry->entry_id |
| 1283 |
); |
| 1284 |
if (!empty($action)) { |
| 1285 |
echo sprintf( |
| 1286 |
$action['html'], $action['url'], $action['title'] |
| 1287 |
); |
| 1288 |
} |
| 1289 |
} |
| 1290 |
} |
| 1291 |
} |
| 1292 |
} |
| 1293 |
} |
| 1294 |
} |
| 1295 |
|