| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* E2pdf Forminator Extension |
| 5 |
* |
| 6 |
* @copyright Copyright 2017 https://e2pdf.com |
| 7 |
* @license GPL v2 |
| 8 |
* @version 1 |
| 9 |
* @link https://e2pdf.com |
| 10 |
* @since 01.01.01 |
| 11 |
*/ |
| 12 |
if (!defined('ABSPATH')) { |
| 13 |
die('Access denied.'); |
| 14 |
} |
| 15 |
|
| 16 |
class Extension_E2pdf_Forminator extends Model_E2pdf_Model { |
| 17 |
|
| 18 |
private $options; |
| 19 |
private $info = array( |
| 20 |
'key' => 'forminator', |
| 21 |
'title' => 'Forminator' |
| 22 |
); |
| 23 |
|
| 24 |
function __construct() { |
| 25 |
parent::__construct(); |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Get info about extension |
| 30 |
* |
| 31 |
* @param string $key - Key to get assigned extension info value |
| 32 |
* |
| 33 |
* @return array|string - Extension Key and Title or Assigned extension info value |
| 34 |
*/ |
| 35 |
public function info($key = false) { |
| 36 |
if ($key && isset($this->info[$key])) { |
| 37 |
return $this->info[$key]; |
| 38 |
} else { |
| 39 |
return array( |
| 40 |
$this->info['key'] => $this->info['title'] |
| 41 |
); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
public function active() { |
| 46 |
|
| 47 |
if (!function_exists('is_plugin_active')) { |
| 48 |
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 49 |
} |
| 50 |
|
| 51 |
if (is_plugin_active('forminator/forminator.php')) { |
| 52 |
return true; |
| 53 |
} |
| 54 |
return false; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Set option |
| 59 |
* |
| 60 |
* @param string $key - Key of option |
| 61 |
* @param string $value - Value of option |
| 62 |
* |
| 63 |
* @return bool - Status of setting option |
| 64 |
*/ |
| 65 |
public function set($key, $value) { |
| 66 |
if (!isset($this->options)) { |
| 67 |
$this->options = new stdClass(); |
| 68 |
} |
| 69 |
|
| 70 |
$this->options->$key = $value; |
| 71 |
return true; |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Get option by key |
| 76 |
* |
| 77 |
* @param string $key - Key to get assigned option value |
| 78 |
* |
| 79 |
* @return mixed |
| 80 |
*/ |
| 81 |
public function get($key) { |
| 82 |
if (isset($this->options->$key)) { |
| 83 |
$value = $this->options->$key; |
| 84 |
return $value; |
| 85 |
} elseif ($key == 'args') { |
| 86 |
return array(); |
| 87 |
} else { |
| 88 |
return false; |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Get items to work with |
| 94 |
* |
| 95 |
* @return array() - List of available items |
| 96 |
*/ |
| 97 |
public function items() { |
| 98 |
$content = array(); |
| 99 |
if (class_exists("Forminator_API")) { |
| 100 |
$forms = Forminator_API::get_forms(); |
| 101 |
foreach ($forms as $key => $value) { |
| 102 |
$content[] = $this->item($value->id); |
| 103 |
} |
| 104 |
} |
| 105 |
return $content; |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* Get entries for export |
| 110 |
* |
| 111 |
* @param int $item - Form ID |
| 112 |
* @param string $name - Entries names |
| 113 |
* |
| 114 |
* @return array() - Entries list |
| 115 |
*/ |
| 116 |
public function datasets($item = false, $name = false) { |
| 117 |
|
| 118 |
$datasets = array(); |
| 119 |
|
| 120 |
if (class_exists("Forminator_API") && $item) { |
| 121 |
$entries = Forminator_API::get_entries($item); |
| 122 |
foreach ($entries as $key => $dataset) { |
| 123 |
$this->set('item', $item); |
| 124 |
$this->set('dataset', $dataset->entry_id); |
| 125 |
|
| 126 |
$dataset_title = $this->render($name); |
| 127 |
if (!$dataset_title) { |
| 128 |
$dataset_title = $dataset->entry_id; |
| 129 |
} |
| 130 |
$datasets[] = array( |
| 131 |
'key' => $dataset->entry_id, |
| 132 |
'value' => $dataset_title |
| 133 |
); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
return $datasets; |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* Get dataset |
| 142 |
* |
| 143 |
* @param int $dataset - Dataset ID |
| 144 |
* |
| 145 |
* @return object - Dataset |
| 146 |
*/ |
| 147 |
public function dataset($dataset = false) { |
| 148 |
$dataset = (int) $dataset; |
| 149 |
|
| 150 |
if (!$dataset) { |
| 151 |
return false; |
| 152 |
} |
| 153 |
|
| 154 |
$data = new stdClass(); |
| 155 |
$data->url = false; |
| 156 |
|
| 157 |
return $data; |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* Get item |
| 162 |
* |
| 163 |
* @param string $item - Item ID |
| 164 |
* |
| 165 |
* @return object - Item |
| 166 |
*/ |
| 167 |
public function item($item = false) { |
| 168 |
|
| 169 |
$form = new stdClass(); |
| 170 |
|
| 171 |
if (!$item && $this->get('item')) { |
| 172 |
$item = $this->get('item'); |
| 173 |
} |
| 174 |
|
| 175 |
$forminator_form = false; |
| 176 |
if (class_exists("Forminator_API")) { |
| 177 |
$forminator_form = Forminator_API::get_form($item); |
| 178 |
} |
| 179 |
|
| 180 |
if (!is_wp_error($forminator_form)) { |
| 181 |
$form->id = (string) $item; |
| 182 |
$form->url = $this->helper->get_url(array('page' => 'forminator-cform-wizard', 'id' => $forminator_form->id)); |
| 183 |
$form->name = $forminator_form->name; |
| 184 |
} else { |
| 185 |
$form->id = ''; |
| 186 |
$form->url = 'javascript:void(0);'; |
| 187 |
$form->name = ''; |
| 188 |
} |
| 189 |
return $form; |
| 190 |
} |
| 191 |
|
| 192 |
/** |
| 193 |
* Render value according to content |
| 194 |
* |
| 195 |
* @param string $value - Content |
| 196 |
* @param string $type - Type of rendering value |
| 197 |
* @param string $field - Field |
| 198 |
* |
| 199 |
* @return string - Fully rendered value |
| 200 |
*/ |
| 201 |
public function render($value, $type = false, $field = array()) { |
| 202 |
|
| 203 |
$value = $this->render_shortcodes($value, $type, $field); |
| 204 |
$value = $this->strip_shortcodes($value); |
| 205 |
|
| 206 |
if ($type === 'value' && isset($field['type']) && $field['type'] === 'e2pdf-checkbox' && isset($field['properties']['option'])) { |
| 207 |
$option = $this->render($field['properties']['option']); |
| 208 |
$options = explode(', ', $value); |
| 209 |
$option_options = explode(', ', $option); |
| 210 |
if (is_array($options) && is_array($option_options) && !array_diff($option_options, $options)) { |
| 211 |
return $option; |
| 212 |
} else { |
| 213 |
return ""; |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
if ($type === 'value') { |
| 218 |
$value = $this->convert_shortcodes($value, true); |
| 219 |
} |
| 220 |
|
| 221 |
return $value; |
| 222 |
} |
| 223 |
|
| 224 |
/** |
| 225 |
* Render shortcodes which available in this extension |
| 226 |
* |
| 227 |
* @param string $type - Type of rendering value |
| 228 |
* @param string $value - Content |
| 229 |
* |
| 230 |
* @return string - Value with rendered shortcodes |
| 231 |
*/ |
| 232 |
public function render_shortcodes($value, $type = false, $field = array()) { |
| 233 |
|
| 234 |
$dataset = $this->get('dataset'); |
| 235 |
$item = $this->get('item'); |
| 236 |
$user_id = $this->get('user_id'); |
| 237 |
$args = $this->get('args'); |
| 238 |
$template_id = $this->get('template_id') ? $this->get('template_id') : '0'; |
| 239 |
$element_id = isset($field['element_id']) ? $field['element_id'] : '0'; |
| 240 |
|
| 241 |
if ($this->verify() && function_exists("forminator_replace_form_data") && class_exists("Forminator_API")) { |
| 242 |
|
| 243 |
$args = apply_filters('e2pdf_extension_render_shortcodes_args', $args, $element_id, $template_id, $item, $dataset); |
| 244 |
|
| 245 |
$form = Forminator_API::get_form($item); |
| 246 |
|
| 247 |
$metas = array(); |
| 248 |
$data = array(); |
| 249 |
|
| 250 |
if ($form->is_prevent_store()) { |
| 251 |
if (class_exists('Forminator_Form_Entry_Model')) { |
| 252 |
$entry = new Forminator_Form_Entry_Model(); |
| 253 |
if ($this->get('field_data_array') && is_array($this->get('field_data_array'))) { |
| 254 |
$entry->set_fields($this->get('field_data_array')); |
| 255 |
$metas = $entry->meta_data; |
| 256 |
} |
| 257 |
} else { |
| 258 |
$entry = null; |
| 259 |
} |
| 260 |
} else { |
| 261 |
$entry = Forminator_API::get_entry($item, $dataset); |
| 262 |
$metas = $entry->meta_data; |
| 263 |
} |
| 264 |
|
| 265 |
foreach ($metas as $key => $meta) { |
| 266 |
if (is_array($meta['value'])) { |
| 267 |
if (array_unique(array_map("is_int", array_keys($meta['value']))) === array(true)) { |
| 268 |
$data[$key] = $meta['value']; |
| 269 |
} else { |
| 270 |
if (isset($meta['value']['file']['file_url'])) { |
| 271 |
$data[$key] = $meta['value']['file']['file_url']; |
| 272 |
} else { |
| 273 |
foreach ($meta['value'] as $sub_key => $sub_meta) { |
| 274 |
$data[$key . "-" . $sub_key] = $sub_meta; |
| 275 |
} |
| 276 |
} |
| 277 |
} |
| 278 |
} else { |
| 279 |
$data[$key] = $meta['value']; |
| 280 |
} |
| 281 |
} |
| 282 |
|
| 283 |
if (false !== strpos($value, '[')) { |
| 284 |
|
| 285 |
$shortcode_tags = array( |
| 286 |
'e2pdf-user', |
| 287 |
'e2pdf-arg' |
| 288 |
); |
| 289 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches); |
| 290 |
$tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 291 |
|
| 292 |
if (!empty($tagnames)) { |
| 293 |
|
| 294 |
$pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames); |
| 295 |
|
| 296 |
preg_match_all("/$pattern/", $value, $shortcodes); |
| 297 |
|
| 298 |
foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 299 |
$shortcode = array(); |
| 300 |
$shortcode[1] = $shortcodes[1][$key]; |
| 301 |
$shortcode[2] = $shortcodes[2][$key]; |
| 302 |
$shortcode[3] = $shortcodes[3][$key]; |
| 303 |
$shortcode[4] = $shortcodes[4][$key]; |
| 304 |
$shortcode[5] = $shortcodes[5][$key]; |
| 305 |
$shortcode[6] = $shortcodes[6][$key]; |
| 306 |
|
| 307 |
$atts = shortcode_parse_atts($shortcode[3]); |
| 308 |
|
| 309 |
if ($shortcode['2'] == 'e2pdf-user') { |
| 310 |
if (!isset($atts['id']) && $user_id) { |
| 311 |
$shortcode[3] .= " id=\"" . $user_id . "\""; |
| 312 |
$value = str_replace($shortcode_value, "[" . $shortcode['2'] . $shortcode['3'] . "]", $value); |
| 313 |
} |
| 314 |
} elseif ($shortcode['2'] == 'e2pdf-arg') { |
| 315 |
if (isset($atts['key']) && isset($args[$atts['key']])) { |
| 316 |
$sub_value = $this->strip_shortcodes($args[$atts['key']]); |
| 317 |
$value = str_replace($shortcode_value, $sub_value, $value); |
| 318 |
} else { |
| 319 |
$value = str_replace($shortcode_value, '', $value); |
| 320 |
} |
| 321 |
} |
| 322 |
} |
| 323 |
} |
| 324 |
|
| 325 |
$shortcode_tags = array( |
| 326 |
'e2pdf-format-number', |
| 327 |
'e2pdf-format-date', |
| 328 |
'e2pdf-format-output', |
| 329 |
); |
| 330 |
$shortcode_tags = apply_filters('e2pdf_extension_render_shortcodes_tags', $shortcode_tags); |
| 331 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches); |
| 332 |
$tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 333 |
|
| 334 |
if (!empty($tagnames)) { |
| 335 |
|
| 336 |
$pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames); |
| 337 |
|
| 338 |
preg_match_all("/$pattern/", $value, $shortcodes); |
| 339 |
foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 340 |
$shortcode = array(); |
| 341 |
$shortcode[1] = $shortcodes[1][$key]; |
| 342 |
$shortcode[2] = $shortcodes[2][$key]; |
| 343 |
$shortcode[3] = $shortcodes[3][$key]; |
| 344 |
$shortcode[4] = $shortcodes[4][$key]; |
| 345 |
$shortcode[5] = $shortcodes[5][$key]; |
| 346 |
$shortcode[6] = $shortcodes[6][$key]; |
| 347 |
|
| 348 |
if (!$shortcode['5']) { |
| 349 |
$sub_value = ''; |
| 350 |
} elseif (isset($field['type']) && ($field['type'] === 'e2pdf-image' || $field['type'] === 'e2pdf-signature')) { |
| 351 |
$sub_value = $this->render($shortcode['5'], $type); |
| 352 |
} else { |
| 353 |
$sub_value = $this->render($shortcode['5'], $type, $field); |
| 354 |
} |
| 355 |
$value = str_replace($shortcode_value, "[" . $shortcode['2'] . $shortcode['3'] . "]" . $sub_value . "[/" . $shortcode['2'] . "]", $value); |
| 356 |
} |
| 357 |
} |
| 358 |
} |
| 359 |
|
| 360 |
$value = do_shortcode($value); |
| 361 |
$value = forminator_replace_form_data($value, $data, $form, $entry); |
| 362 |
$value = forminator_replace_variables($value, $item); |
| 363 |
|
| 364 |
if (isset($field['type']) && ($field['type'] === 'e2pdf-image' || $field['type'] === 'e2pdf-signature')) { |
| 365 |
$esig = isset($field['properties']['esig']) && $field['properties']['esig'] ? true : false; |
| 366 |
if ($esig) { |
| 367 |
//process e-signature |
| 368 |
$value = ""; |
| 369 |
} else { |
| 370 |
|
| 371 |
if (!$this->helper->load('image')->get_image($value)) { |
| 372 |
$value = $this->strip_shortcodes($value); |
| 373 |
if ( |
| 374 |
$value && |
| 375 |
trim($value) != "" && |
| 376 |
extension_loaded('gd') && |
| 377 |
function_exists('imagettftext') |
| 378 |
) { |
| 379 |
if (isset($field['properties']['text_color']) && $field['properties']['text_color']) { |
| 380 |
$penColour = $this->helper->load('convert')->to_hex_color($field['properties']['text_color']); |
| 381 |
} else { |
| 382 |
$penColour = array(0x14, 0x53, 0x94); |
| 383 |
} |
| 384 |
|
| 385 |
$default_options = array( |
| 386 |
'imageSize' => array(isset($field['width']) ? $field['width'] : '400', isset($field['height']) ? $field['height'] : '150'), |
| 387 |
'bgColour' => 'transparent', |
| 388 |
'penColour' => $penColour |
| 389 |
); |
| 390 |
|
| 391 |
$options = array(); |
| 392 |
$options = apply_filters('e2pdf_image_sig_output_options', $options, $element_id, $template_id); |
| 393 |
$options = array_merge($default_options, $options); |
| 394 |
|
| 395 |
$model_e2pdf_font = new Model_E2pdf_Font(); |
| 396 |
|
| 397 |
$font = false; |
| 398 |
if (isset($field['properties']['text_font']) && $field['properties']['text_font']) { |
| 399 |
$font = $model_e2pdf_font->get_font_path($field['properties']['text_font']); |
| 400 |
} |
| 401 |
|
| 402 |
if (!$font) { |
| 403 |
$font = $model_e2pdf_font->get_font_path('Noto Sans'); |
| 404 |
} |
| 405 |
|
| 406 |
$size = 150; |
| 407 |
if (isset($field['properties']['text_font_size']) && $field['properties']['text_font_size']) { |
| 408 |
$size = $field['properties']['text_font_size']; |
| 409 |
} |
| 410 |
|
| 411 |
$model_e2pdf_signature = new Model_E2pdf_Signature(); |
| 412 |
$value = $model_e2pdf_signature->ttf_signature($value, $size, $font, $options); |
| 413 |
} else { |
| 414 |
$value = ""; |
| 415 |
} |
| 416 |
} |
| 417 |
} |
| 418 |
} else { |
| 419 |
$value = $this->convert_shortcodes($value); |
| 420 |
} |
| 421 |
} |
| 422 |
|
| 423 |
$value = apply_filters('e2pdf_extension_render_shortcodes_value', $value, $element_id, $template_id, $item, $dataset); |
| 424 |
|
| 425 |
return $value; |
| 426 |
} |
| 427 |
|
| 428 |
/** |
| 429 |
* Strip unused shortcodes |
| 430 |
* |
| 431 |
* @param string $value - Content |
| 432 |
* |
| 433 |
* @return string - Value with removed unused shortcodes |
| 434 |
*/ |
| 435 |
public function strip_shortcodes($value) { |
| 436 |
$value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', "", $value); |
| 437 |
$value = preg_replace('~(?:{/?)[^/}]+/?}~s', "", $value); |
| 438 |
return $value; |
| 439 |
} |
| 440 |
|
| 441 |
/** |
| 442 |
* Convert "shortcodes" inside value string |
| 443 |
* |
| 444 |
* @param string $value - Value string |
| 445 |
* @param bool $to - Convert From/To |
| 446 |
* |
| 447 |
* @return string - Converted value |
| 448 |
*/ |
| 449 |
public function convert_shortcodes($value, $to = false) { |
| 450 |
if ($value) { |
| 451 |
if ($to) { |
| 452 |
$value = str_replace("[", "[", $value); |
| 453 |
//$value = str_replace("%", "%", $value); |
| 454 |
} else { |
| 455 |
$value = str_replace("[", "[", $value); |
| 456 |
//$value = str_replace("%", "%", $value); |
| 457 |
} |
| 458 |
} |
| 459 |
return $value; |
| 460 |
} |
| 461 |
|
| 462 |
/** |
| 463 |
* Verify if item and dataset exists |
| 464 |
* |
| 465 |
* @return bool - item and dataset exists |
| 466 |
*/ |
| 467 |
public function verify() { |
| 468 |
$item = $this->get('item'); |
| 469 |
$dataset = $this->get('dataset'); |
| 470 |
|
| 471 |
if ($item && $dataset && class_exists('Forminator_API')) { |
| 472 |
$form = Forminator_API::get_form($item); |
| 473 |
if (!is_wp_error($form)) { |
| 474 |
if ($form->is_prevent_store()) { |
| 475 |
if ($dataset == 'is_prevent_store') { |
| 476 |
return true; |
| 477 |
} |
| 478 |
} else { |
| 479 |
$entry = Forminator_API::get_entry($item, $dataset); |
| 480 |
if (!is_wp_error($entry)) { |
| 481 |
return true; |
| 482 |
} |
| 483 |
} |
| 484 |
} |
| 485 |
} |
| 486 |
return false; |
| 487 |
} |
| 488 |
|
| 489 |
public function auto_form($template, $data = array()) { |
| 490 |
|
| 491 |
if ($template->get('ID')) { |
| 492 |
|
| 493 |
$auto_form_label = isset($data['auto_form_label']) && $data['auto_form_label'] ? $data['auto_form_label'] : false; |
| 494 |
$auto_form_shortcode = isset($data['auto_form_shortcode']) ? true : false; |
| 495 |
|
| 496 |
$wrappers = array(); |
| 497 |
|
| 498 |
$pages = $template->get('pages'); |
| 499 |
|
| 500 |
$checkboxes = array(); |
| 501 |
$radios = array(); |
| 502 |
|
| 503 |
foreach ($pages as $page_key => $page) { |
| 504 |
if (isset($page['elements']) && !empty($page['elements'])) { |
| 505 |
foreach ($page['elements'] as $element_key => $element) { |
| 506 |
|
| 507 |
$type = false; |
| 508 |
$label = ''; |
| 509 |
|
| 510 |
if ($element['type'] == 'e2pdf-input' || $element['type'] == 'e2pdf-signature') { |
| 511 |
$type = 'text'; |
| 512 |
$label = __('Text', 'e2pdf'); |
| 513 |
} elseif ($element['type'] == 'e2pdf-textarea') { |
| 514 |
$type = 'textarea'; |
| 515 |
$label = __('Textarea', 'e2pdf'); |
| 516 |
} elseif ($element['type'] == 'e2pdf-select') { |
| 517 |
|
| 518 |
$type = 'select'; |
| 519 |
$label = __('Select', 'e2pdf'); |
| 520 |
|
| 521 |
$options = array(); |
| 522 |
$field_options = array(); |
| 523 |
|
| 524 |
if (isset($element['properties']['options'])) { |
| 525 |
$field_options = explode("\n", $element['properties']['options']); |
| 526 |
foreach ($field_options as $option) { |
| 527 |
$options[] = array( |
| 528 |
'label' => $option, |
| 529 |
'value' => '' |
| 530 |
); |
| 531 |
} |
| 532 |
} |
| 533 |
} elseif ($element['type'] == 'e2pdf-checkbox') { |
| 534 |
$field_key = array_search($element['name'], array_column($checkboxes, 'name')); |
| 535 |
if ($field_key !== false) { |
| 536 |
$checkboxes[$field_key]['options'][] = array( |
| 537 |
'label' => $element['properties']['option'], |
| 538 |
'value' => $element['properties']['option'], |
| 539 |
); |
| 540 |
$pages[$page_key]['elements'][$element_key]['value'] = '{checkbox-' . $checkboxes[$field_key]['element_id'] . '}'; |
| 541 |
} else { |
| 542 |
$type = 'checkbox'; |
| 543 |
$label = __('Checkbox', 'e2pdf'); |
| 544 |
$options = array( |
| 545 |
'label' => $element['properties']['option'], |
| 546 |
'value' => $element['properties']['option'], |
| 547 |
); |
| 548 |
} |
| 549 |
} elseif ($element['type'] == 'e2pdf-radio') { |
| 550 |
if (isset($element['properties']['group']) && $element['properties']['group']) { |
| 551 |
$element['name'] = $element['properties']['group']; |
| 552 |
} else { |
| 553 |
$element['name'] = $element['element_id']; |
| 554 |
} |
| 555 |
|
| 556 |
$field_key = array_search($element['name'], array_column($radios, 'name')); |
| 557 |
if ($field_key !== false) { |
| 558 |
$radios[$field_key]['options'][] = array( |
| 559 |
'label' => $element['properties']['option'], |
| 560 |
'value' => '', |
| 561 |
); |
| 562 |
$pages[$page_key]['elements'][$element_key]['value'] = '{radio-' . $radios[$field_key]['element_id'] . '}'; |
| 563 |
} else { |
| 564 |
$type = 'radio'; |
| 565 |
$label = __('Radio', 'e2pdf'); |
| 566 |
$options = array( |
| 567 |
'label' => $element['properties']['option'], |
| 568 |
'value' => '', |
| 569 |
); |
| 570 |
} |
| 571 |
} |
| 572 |
|
| 573 |
if ($type) { |
| 574 |
$labels = array(); |
| 575 |
if ($auto_form_shortcode) { |
| 576 |
$labels[] = '{' . $type . '-' . $element['element_id'] . '}'; |
| 577 |
} |
| 578 |
|
| 579 |
if ($auto_form_label && $auto_form_label == 'value' && isset($element['value']) && $element['value']) { |
| 580 |
$labels[] = $element['value']; |
| 581 |
} elseif ($auto_form_label && $auto_form_label == 'name' && isset($element['name']) && $element['name']) { |
| 582 |
$labels[] = $element['name']; |
| 583 |
} |
| 584 |
|
| 585 |
if ($type == 'checkbox' || $type == 'radio') { |
| 586 |
|
| 587 |
$field_data = array( |
| 588 |
'name' => $element['name'], |
| 589 |
'element_id' => $element['element_id'], |
| 590 |
'field_label' => !empty($labels) ? implode(' ', $labels) : $label, |
| 591 |
'options' => array( |
| 592 |
$options |
| 593 |
) |
| 594 |
); |
| 595 |
|
| 596 |
if ($type == 'checkbox') { |
| 597 |
$checkboxes[] = $field_data; |
| 598 |
} else { |
| 599 |
$radios[] = $field_data; |
| 600 |
} |
| 601 |
} else { |
| 602 |
$field_data = array( |
| 603 |
'element_id' => $type . '-' . $element['element_id'], |
| 604 |
'type' => $type, |
| 605 |
'cols' => '12', |
| 606 |
'required' => false, |
| 607 |
'field_label' => !empty($labels) ? implode(' ', $labels) : $label, |
| 608 |
'placeholder' => '', |
| 609 |
'validation' => false, |
| 610 |
); |
| 611 |
|
| 612 |
if ($type == 'select') { |
| 613 |
$field_data['options'] = $options; |
| 614 |
} |
| 615 |
|
| 616 |
$wrappers[] = array( |
| 617 |
'wrapper_id' => 'wrapper-' . mt_rand(1000000000000, 9999999999999) . '-' . mt_rand(1000, 9999), |
| 618 |
'fields' => array( |
| 619 |
$field_data |
| 620 |
), |
| 621 |
); |
| 622 |
} |
| 623 |
|
| 624 |
$pages[$page_key]['elements'][$element_key]['value'] = '{' . $type . '-' . $element['element_id'] . '}'; |
| 625 |
if (isset($element['properties']['esig'])) { |
| 626 |
unset($pages[$page_key]['elements'][$element_key]['properties']['esig']); |
| 627 |
} |
| 628 |
} |
| 629 |
} |
| 630 |
} |
| 631 |
} |
| 632 |
|
| 633 |
foreach ($checkboxes as $element) { |
| 634 |
$wrappers[] = array( |
| 635 |
'wrapper_id' => 'wrapper-' . mt_rand(1000000000000, 9999999999999) . '-' . mt_rand(1000, 9999), |
| 636 |
'fields' => array( |
| 637 |
array( |
| 638 |
'element_id' => 'checkbox-' . $element['element_id'], |
| 639 |
'type' => 'checkbox', |
| 640 |
'cols' => '12', |
| 641 |
'required' => false, |
| 642 |
'options' => $element['options'], |
| 643 |
'field_label' => $element['field_label'], |
| 644 |
'placeholder' => '', |
| 645 |
'validation' => false, |
| 646 |
), |
| 647 |
), |
| 648 |
); |
| 649 |
} |
| 650 |
|
| 651 |
foreach ($radios as $element) { |
| 652 |
$wrappers[] = array( |
| 653 |
'wrapper_id' => 'wrapper-' . mt_rand(1000000000000, 9999999999999) . '-' . mt_rand(1000, 9999), |
| 654 |
'fields' => array( |
| 655 |
array( |
| 656 |
'element_id' => 'radio-' . $element['element_id'], |
| 657 |
'type' => 'radio', |
| 658 |
'cols' => '12', |
| 659 |
'required' => false, |
| 660 |
'options' => $element['options'], |
| 661 |
'field_label' => $element['field_label'], |
| 662 |
'placeholder' => '', |
| 663 |
'validation' => false, |
| 664 |
), |
| 665 |
), |
| 666 |
); |
| 667 |
} |
| 668 |
|
| 669 |
$template->set('pages', $pages); |
| 670 |
$settings = array( |
| 671 |
'formName' => $template->get('title'), |
| 672 |
'thankyou' => "true", |
| 673 |
'thankyou-message' => sprintf(__("Success. [e2pdf-download id=\"%s\"]", 'e2pdf'), $template->get('ID')), |
| 674 |
'use-custom-submit' => "true", |
| 675 |
'custom-submit-text' => __("Send Message", Forminator::DOMAIN), |
| 676 |
'use-custom-invalid-form' => "true", |
| 677 |
'custom-invalid-form-message' => __("Error: Your form is not valid, please fix the errors!", Forminator::DOMAIN), |
| 678 |
'enable-ajax' => "true", |
| 679 |
'validation' => "on_submit" |
| 680 |
); |
| 681 |
|
| 682 |
if (class_exists('Forminator_API')) { |
| 683 |
if ($item = Forminator_API::add_form($template->get('title'), $wrappers, $settings)) { |
| 684 |
$template->set('item', $item); |
| 685 |
} |
| 686 |
} |
| 687 |
} |
| 688 |
|
| 689 |
return $template; |
| 690 |
} |
| 691 |
|
| 692 |
/** |
| 693 |
* Init Visual Mapper data |
| 694 |
* |
| 695 |
* @return bool|string - HTML data source for Visual Mapper |
| 696 |
*/ |
| 697 |
public function visual_mapper() { |
| 698 |
|
| 699 |
$item = $this->get('item'); |
| 700 |
$html = ''; |
| 701 |
$source = ''; |
| 702 |
|
| 703 |
if ($item && function_exists("forminator_form_preview") && class_exists("Forminator_API")) { |
| 704 |
|
| 705 |
$form = Forminator_API::get_form($item); |
| 706 |
if (is_wp_error($form)) { |
| 707 |
return __('Form could not be found', 'e2pdf'); |
| 708 |
} |
| 709 |
|
| 710 |
ob_start(); |
| 711 |
forminator_form_preview($item, true, array()); |
| 712 |
$source = ob_get_clean(); |
| 713 |
if (!$source) { |
| 714 |
$source = forminator_form_preview($item, false, array()); |
| 715 |
} |
| 716 |
|
| 717 |
if ($source) { |
| 718 |
libxml_use_internal_errors(true); |
| 719 |
$dom = new DOMDocument(); |
| 720 |
if (function_exists('mb_convert_encoding')) { |
| 721 |
$html = $dom->loadHTML(mb_convert_encoding($source, 'HTML-ENTITIES', 'UTF-8')); |
| 722 |
} else { |
| 723 |
$html = $dom->loadHTML('<?xml encoding="UTF-8">' . $source); |
| 724 |
} |
| 725 |
libxml_clear_errors(); |
| 726 |
} |
| 727 |
|
| 728 |
if (!$source) { |
| 729 |
return __('Form source is empty', 'e2pdf'); |
| 730 |
} elseif (!$html) { |
| 731 |
return __('Form could not be parsed due incorrect HTML', 'e2pdf'); |
| 732 |
} else { |
| 733 |
|
| 734 |
$xpath = new DomXPath($dom); |
| 735 |
|
| 736 |
$remove_by_class = array( |
| 737 |
'forminator-pagination-submit' |
| 738 |
); |
| 739 |
foreach ($remove_by_class as $key => $class) { |
| 740 |
$elements = $xpath->query("//*[contains(@class, '{$class}')]"); |
| 741 |
foreach ($elements as $element) { |
| 742 |
$element->parentNode->removeChild($element); |
| 743 |
} |
| 744 |
} |
| 745 |
|
| 746 |
$remove_by_tag = array( |
| 747 |
'script' |
| 748 |
); |
| 749 |
foreach ($remove_by_tag as $key => $tag) { |
| 750 |
$elements = $xpath->query("//{$tag}"); |
| 751 |
foreach ($elements as $element) { |
| 752 |
$element->parentNode->removeChild($element); |
| 753 |
} |
| 754 |
} |
| 755 |
|
| 756 |
$inputs = $xpath->query("//*[contains(@class, 'forminator-input')]"); |
| 757 |
foreach ($inputs as $element) { |
| 758 |
if (!$element->attributes->getNamedItem("type")->nodeValue) { |
| 759 |
$element->setAttribute("type", "text"); |
| 760 |
} |
| 761 |
} |
| 762 |
|
| 763 |
//remove pagination |
| 764 |
$pagination = $xpath->query("//*[contains(@class, 'forminator-pagination')]"); |
| 765 |
foreach ($pagination as $element) { |
| 766 |
if ($element->attributes->getNamedItem("style")) { |
| 767 |
$element->attributes->getNamedItem("style")->nodeValue = ""; |
| 768 |
} |
| 769 |
} |
| 770 |
|
| 771 |
//remove buttons |
| 772 |
$remove_rows = $xpath->query("//*[contains(@class, 'forminator-row')][.//button[contains(@class, 'forminator-button') and not(contains(@class, 'forminator-upload-button'))]]"); |
| 773 |
foreach ($remove_rows as $element) { |
| 774 |
$element->parentNode->removeChild($element); |
| 775 |
} |
| 776 |
|
| 777 |
//replace name on fileuploads |
| 778 |
$fileuploads = $xpath->query("//*[contains(@class, 'forminator-upload')]"); |
| 779 |
foreach ($fileuploads as $element) { |
| 780 |
$file = $xpath->query(".//input[contains(@class, 'forminator-input-file')]", $element)->item(0); |
| 781 |
$button = $xpath->query(".//button[contains(@class, 'forminator-upload-button')]", $element)->item(0); |
| 782 |
if ($file && $button) { |
| 783 |
if ($button->attributes->getNamedItem("type")) { |
| 784 |
$button->attributes->getNamedItem("type")->nodeValue = "upload"; |
| 785 |
} |
| 786 |
$button->setAttribute("name", "{" . $file->attributes->getNamedItem("name")->nodeValue . "}"); |
| 787 |
} |
| 788 |
} |
| 789 |
|
| 790 |
//replace names on inputs |
| 791 |
$inputs = $xpath->query("//input"); |
| 792 |
foreach ($inputs as $element) { |
| 793 |
$type = $element->attributes->getNamedItem("type")->nodeValue; |
| 794 |
if ($type == 'checkbox') { |
| 795 |
if ($element->attributes->getNamedItem("name")) { |
| 796 |
$element->attributes->getNamedItem("name")->nodeValue = str_replace("[]", "", $element->attributes->getNamedItem("name")->nodeValue); |
| 797 |
} |
| 798 |
} |
| 799 |
|
| 800 |
if ($element->attributes->getNamedItem("name")) { |
| 801 |
$element->attributes->getNamedItem("name")->nodeValue = "{" . $element->attributes->getNamedItem("name")->nodeValue . "}"; |
| 802 |
} |
| 803 |
|
| 804 |
if ($element->attributes->getNamedItem("class")) { |
| 805 |
if (strpos($element->attributes->getNamedItem("class")->nodeValue, 'forminator-checkbox--input') !== false) { |
| 806 |
$element->attributes->getNamedItem("class")->nodeValue = $element->attributes->getNamedItem("class")->nodeValue . " forminator-checkbox--design"; |
| 807 |
} |
| 808 |
if (strpos($element->attributes->getNamedItem("class")->nodeValue, 'forminator-radio--input') !== false) { |
| 809 |
$element->attributes->getNamedItem("class")->nodeValue = $element->attributes->getNamedItem("class")->nodeValue . " forminator-radio--design"; |
| 810 |
} |
| 811 |
} |
| 812 |
} |
| 813 |
|
| 814 |
//replace names on textareas |
| 815 |
$textareas = $xpath->query("//textarea"); |
| 816 |
foreach ($textareas as $element) { |
| 817 |
if ($element->attributes->getNamedItem("name")) { |
| 818 |
$element->attributes->getNamedItem("name")->nodeValue = "{" . $element->attributes->getNamedItem("name")->nodeValue . "}"; |
| 819 |
} |
| 820 |
} |
| 821 |
|
| 822 |
//replace names on selects |
| 823 |
$selects = $xpath->query("//select"); |
| 824 |
foreach ($selects as $element) { |
| 825 |
if ($element->attributes->getNamedItem("name")) { |
| 826 |
$element->attributes->getNamedItem("name")->nodeValue = "{" . $element->attributes->getNamedItem("name")->nodeValue . "}"; |
| 827 |
} |
| 828 |
} |
| 829 |
|
| 830 |
//multiselects |
| 831 |
$multiselect = $xpath->query("//ul[contains(@class, 'forminator-multiselect')]"); |
| 832 |
foreach ($multiselect as $element) { |
| 833 |
$name = ''; |
| 834 |
$options = array(); |
| 835 |
$inputs = $xpath->query(".//*[contains(@class, 'forminator-multiselect--item')]", $element); |
| 836 |
|
| 837 |
foreach ($inputs as $sub_element) { |
| 838 |
$input = $xpath->query(".//input", $sub_element)->item(0); |
| 839 |
$label = $xpath->query(".//label", $sub_element)->item(0); |
| 840 |
|
| 841 |
if ($input && $label) { |
| 842 |
$options[] = array( |
| 843 |
'value' => $input->attributes->getNamedItem("value")->nodeValue, |
| 844 |
'label' => $label->childNodes->item(0)->nodeValue |
| 845 |
); |
| 846 |
|
| 847 |
$name = $input->attributes->getNamedItem("name")->nodeValue; |
| 848 |
} |
| 849 |
|
| 850 |
$sub_element->parentNode->removeChild($sub_element); |
| 851 |
} |
| 852 |
|
| 853 |
$li = $dom->createElement('li'); |
| 854 |
$field_atts = array( |
| 855 |
'class' => 'forminator-multiselect--item', |
| 856 |
); |
| 857 |
foreach ($field_atts as $key => $value) { |
| 858 |
$attr = $dom->createAttribute($key); |
| 859 |
$attr->value = $value; |
| 860 |
$li->appendChild($attr); |
| 861 |
} |
| 862 |
$element->appendChild($li); |
| 863 |
|
| 864 |
|
| 865 |
$field = $dom->createElement('select'); |
| 866 |
$field_atts = array( |
| 867 |
'multiple' => 'multiple', |
| 868 |
'name' => $name, |
| 869 |
); |
| 870 |
foreach ($field_atts as $key => $value) { |
| 871 |
$attr = $dom->createAttribute($key); |
| 872 |
$attr->value = $value; |
| 873 |
$field->appendChild($attr); |
| 874 |
} |
| 875 |
|
| 876 |
$li->appendChild($field); |
| 877 |
|
| 878 |
foreach ($options as $option) { |
| 879 |
$option_field = $dom->createElement('option'); |
| 880 |
$field_atts = array( |
| 881 |
'value' => $option['value'], |
| 882 |
); |
| 883 |
foreach ($field_atts as $key => $value) { |
| 884 |
$attr = $dom->createAttribute($key); |
| 885 |
$attr->value = $value; |
| 886 |
$option_field->appendChild($attr); |
| 887 |
} |
| 888 |
|
| 889 |
$label = $dom->createTextNode($option['label']); |
| 890 |
$option_field->appendChild($label); |
| 891 |
$field->appendChild($option_field); |
| 892 |
} |
| 893 |
} |
| 894 |
|
| 895 |
return $dom->saveHTML(); |
| 896 |
} |
| 897 |
} |
| 898 |
return false; |
| 899 |
} |
| 900 |
|
| 901 |
/** |
| 902 |
* Auto Generate of Template for this extension |
| 903 |
* |
| 904 |
* @return array - List of elements |
| 905 |
*/ |
| 906 |
public function auto() { |
| 907 |
|
| 908 |
$item = $this->get('item'); |
| 909 |
|
| 910 |
$response = array(); |
| 911 |
$elements = array(); |
| 912 |
$fields = array(); |
| 913 |
$form = false; |
| 914 |
|
| 915 |
if (class_exists("Forminator_API")) { |
| 916 |
$forminator_form = Forminator_API::get_form($item); |
| 917 |
if (!is_wp_error($forminator_form)) { |
| 918 |
$form = $forminator_form; |
| 919 |
$fields = $form->fields; |
| 920 |
} |
| 921 |
} |
| 922 |
|
| 923 |
if ($form && $fields) { |
| 924 |
|
| 925 |
foreach ($fields as $field_obj) { |
| 926 |
$field = $field_obj->raw; |
| 927 |
$float = true; |
| 928 |
$width = 100 / (12 / $field['cols']); |
| 929 |
|
| 930 |
switch ($field['type']) { |
| 931 |
case 'name': |
| 932 |
case 'email': |
| 933 |
case 'phone': |
| 934 |
case 'url': |
| 935 |
case 'upload': |
| 936 |
case 'number': |
| 937 |
case 'date': |
| 938 |
//multiple name field |
| 939 |
if ($field['type'] == 'name' && isset($field['multiple_name']) && $field['multiple_name']) { |
| 940 |
|
| 941 |
if (!$field['prefix'] && !$field['fname']) { |
| 942 |
if ($field['mname']) { |
| 943 |
$elements[] = $this->auto_field($field, array( |
| 944 |
'type' => 'e2pdf-html', |
| 945 |
'block' => true, |
| 946 |
'float' => true, |
| 947 |
'properties' => array( |
| 948 |
'top' => '20', |
| 949 |
'left' => '20', |
| 950 |
'right' => '20', |
| 951 |
'width' => $field['lname'] ? $width / 2 . '%' : $width . '%', |
| 952 |
'height' => 'auto', |
| 953 |
'value' => $field['mname_label'], |
| 954 |
) |
| 955 |
)); |
| 956 |
|
| 957 |
$elements[] = $this->auto_field($field, array( |
| 958 |
'type' => 'e2pdf-input', |
| 959 |
'properties' => array( |
| 960 |
'top' => '5', |
| 961 |
'width' => '100%', |
| 962 |
'height' => 'auto', |
| 963 |
'value' => "{" . $field['element_id'] . "-middle-name" . "}", |
| 964 |
) |
| 965 |
)); |
| 966 |
} |
| 967 |
|
| 968 |
if ($field['lname']) { |
| 969 |
$elements[] = $this->auto_field($field, array( |
| 970 |
'type' => 'e2pdf-html', |
| 971 |
'block' => true, |
| 972 |
'float' => true, |
| 973 |
'properties' => array( |
| 974 |
'top' => '20', |
| 975 |
'left' => '20', |
| 976 |
'right' => '20', |
| 977 |
'width' => $field['mname'] ? $width / 2 . '%' : $width . '%', |
| 978 |
'height' => 'auto', |
| 979 |
'value' => $field['lname_label'], |
| 980 |
) |
| 981 |
)); |
| 982 |
|
| 983 |
$elements[] = $this->auto_field($field, array( |
| 984 |
'type' => 'e2pdf-input', |
| 985 |
'properties' => array( |
| 986 |
'top' => '5', |
| 987 |
'width' => '100%', |
| 988 |
'height' => 'auto', |
| 989 |
'value' => "{" . $field['element_id'] . "-last-name" . "}", |
| 990 |
) |
| 991 |
)); |
| 992 |
} |
| 993 |
} else { |
| 994 |
|
| 995 |
if ($field['prefix']) { |
| 996 |
$elements[] = $this->auto_field($field, array( |
| 997 |
'type' => 'e2pdf-html', |
| 998 |
'block' => true, |
| 999 |
'float' => true, |
| 1000 |
'properties' => array( |
| 1001 |
'top' => '20', |
| 1002 |
'left' => '20', |
| 1003 |
'right' => '20', |
| 1004 |
'width' => $field['fname'] ? $width / 2 . '%' : $width . '%', |
| 1005 |
'height' => 'auto', |
| 1006 |
'value' => $field['prefix_label'], |
| 1007 |
) |
| 1008 |
)); |
| 1009 |
|
| 1010 |
$options_tmp = array(); |
| 1011 |
if (function_exists('forminator_get_name_prefixes')) { |
| 1012 |
$options = forminator_get_name_prefixes(); |
| 1013 |
foreach ($options as $key => $option) { |
| 1014 |
$options_tmp[] = $key; |
| 1015 |
} |
| 1016 |
} |
| 1017 |
|
| 1018 |
$elements[] = $this->auto_field($field, array( |
| 1019 |
'type' => 'e2pdf-select', |
| 1020 |
'properties' => array( |
| 1021 |
'top' => '5', |
| 1022 |
'width' => '100%', |
| 1023 |
'height' => 'auto', |
| 1024 |
'options' => implode("\n", $options_tmp), |
| 1025 |
'value' => "{" . $field['element_id'] . "-prefix" . "}", |
| 1026 |
) |
| 1027 |
)); |
| 1028 |
|
| 1029 |
if ($field['mname'] && $field['fname']) { |
| 1030 |
$elements[] = $this->auto_field($field, array( |
| 1031 |
'type' => 'e2pdf-html', |
| 1032 |
'properties' => array( |
| 1033 |
'top' => '20', |
| 1034 |
'width' => $field['lname'] ? '100%' : '200%', |
| 1035 |
'right' => $field['lname'] ? '0' : '-40', |
| 1036 |
'height' => 'auto', |
| 1037 |
'value' => $field['mname_label'], |
| 1038 |
) |
| 1039 |
)); |
| 1040 |
|
| 1041 |
$elements[] = $this->auto_field($field, array( |
| 1042 |
'type' => 'e2pdf-input', |
| 1043 |
'properties' => array( |
| 1044 |
'top' => '5', |
| 1045 |
'width' => $field['lname'] ? '100%' : '200%', |
| 1046 |
'height' => 'auto', |
| 1047 |
'right' => $field['lname'] ? '0' : '-40', |
| 1048 |
'value' => "{" . $field['element_id'] . "-middle-name" . "}", |
| 1049 |
) |
| 1050 |
)); |
| 1051 |
} elseif ($field['lname'] && !$field['mname'] && $field['fname']) { |
| 1052 |
|
| 1053 |
$elements[] = $this->auto_field($field, array( |
| 1054 |
'type' => 'e2pdf-html', |
| 1055 |
'properties' => array( |
| 1056 |
'top' => '20', |
| 1057 |
'width' => $field['mname'] ? '100%' : '200%', |
| 1058 |
'height' => 'auto', |
| 1059 |
'right' => $field['mname'] ? '0' : '-40', |
| 1060 |
'value' => $field['lname_label'], |
| 1061 |
) |
| 1062 |
)); |
| 1063 |
|
| 1064 |
$elements[] = $this->auto_field($field, array( |
| 1065 |
'type' => 'e2pdf-input', |
| 1066 |
'properties' => array( |
| 1067 |
'top' => '5', |
| 1068 |
'width' => $field['mname'] ? '100%' : '200%', |
| 1069 |
'height' => 'auto', |
| 1070 |
'right' => $field['mname'] ? '0' : '-40', |
| 1071 |
'value' => "{" . $field['element_id'] . "-last-name" . "}", |
| 1072 |
) |
| 1073 |
)); |
| 1074 |
} |
| 1075 |
} |
| 1076 |
|
| 1077 |
if ($field['fname']) { |
| 1078 |
$elements[] = $this->auto_field($field, array( |
| 1079 |
'type' => 'e2pdf-html', |
| 1080 |
'block' => true, |
| 1081 |
'float' => true, |
| 1082 |
'properties' => array( |
| 1083 |
'top' => '20', |
| 1084 |
'left' => '20', |
| 1085 |
'right' => '20', |
| 1086 |
'width' => $field['prefix'] ? ($width / 2) . '%' : $width . '%', |
| 1087 |
'height' => 'auto', |
| 1088 |
'value' => $field['fname_label'], |
| 1089 |
) |
| 1090 |
)); |
| 1091 |
|
| 1092 |
$elements[] = $this->auto_field($field, array( |
| 1093 |
'type' => 'e2pdf-input', |
| 1094 |
'properties' => array( |
| 1095 |
'top' => '5', |
| 1096 |
'width' => '100%', |
| 1097 |
'height' => 'auto', |
| 1098 |
'value' => "{" . $field['element_id'] . "-first-name" . "}", |
| 1099 |
) |
| 1100 |
)); |
| 1101 |
|
| 1102 |
if ($field['lname'] && $field['mname'] && $field['prefix']) { |
| 1103 |
$elements[] = $this->auto_field($field, array( |
| 1104 |
'type' => 'e2pdf-html', |
| 1105 |
'properties' => array( |
| 1106 |
'top' => '20', |
| 1107 |
'width' => $field['mname'] ? '100%' : '200%', |
| 1108 |
'height' => 'auto', |
| 1109 |
'right' => $field['mname'] ? '0' : '-40', |
| 1110 |
'value' => $field['lname_label'], |
| 1111 |
) |
| 1112 |
)); |
| 1113 |
|
| 1114 |
$elements[] = $this->auto_field($field, array( |
| 1115 |
'type' => 'e2pdf-input', |
| 1116 |
'properties' => array( |
| 1117 |
'top' => '5', |
| 1118 |
'width' => $field['mname'] ? '100%' : '200%', |
| 1119 |
'height' => 'auto', |
| 1120 |
'right' => $field['mname'] ? '0' : '-40', |
| 1121 |
'value' => "{" . $field['element_id'] . "-last-name" . "}", |
| 1122 |
) |
| 1123 |
)); |
| 1124 |
} |
| 1125 |
} |
| 1126 |
|
| 1127 |
if (!$field['prefix'] || !$field['fname']) { |
| 1128 |
if ($field['mname']) { |
| 1129 |
$elements[] = $this->auto_field($field, array( |
| 1130 |
'type' => 'e2pdf-html', |
| 1131 |
'properties' => array( |
| 1132 |
'top' => '20', |
| 1133 |
'right' => $field['lname'] ? '20' : '0', |
| 1134 |
'width' => $field['lname'] ? '50%' : '100%', |
| 1135 |
'height' => 'auto', |
| 1136 |
'value' => $field['mname_label'], |
| 1137 |
) |
| 1138 |
)); |
| 1139 |
} |
| 1140 |
|
| 1141 |
if ($field['lname']) { |
| 1142 |
$elements[] = $this->auto_field($field, array( |
| 1143 |
'type' => 'e2pdf-html', |
| 1144 |
'float' => $field['mname'] ? true : false, |
| 1145 |
'properties' => array( |
| 1146 |
'top' => '20', |
| 1147 |
'left' => $field['mname'] ? '20' : '0', |
| 1148 |
'width' => $field['mname'] ? '50%' : '100%', |
| 1149 |
'height' => 'auto', |
| 1150 |
'value' => $field['lname_label'], |
| 1151 |
) |
| 1152 |
)); |
| 1153 |
} |
| 1154 |
|
| 1155 |
if ($field['mname']) { |
| 1156 |
$elements[] = $this->auto_field($field, array( |
| 1157 |
'type' => 'e2pdf-input', |
| 1158 |
'properties' => array( |
| 1159 |
'top' => '5', |
| 1160 |
'right' => $field['lname'] ? '20' : '0', |
| 1161 |
'width' => $field['lname'] ? '50%' : '100%', |
| 1162 |
'height' => 'auto', |
| 1163 |
'value' => "{" . $field['element_id'] . "-middle-name" . "}", |
| 1164 |
) |
| 1165 |
)); |
| 1166 |
} |
| 1167 |
|
| 1168 |
if ($field['lname']) { |
| 1169 |
$elements[] = $this->auto_field($field, array( |
| 1170 |
'type' => 'e2pdf-input', |
| 1171 |
'float' => $field['mname'] ? true : false, |
| 1172 |
'properties' => array( |
| 1173 |
'top' => '5', |
| 1174 |
'left' => $field['mname'] ? '20' : '0', |
| 1175 |
'width' => $field['mname'] ? '50%' : '100%', |
| 1176 |
'height' => 'auto', |
| 1177 |
'value' => "{" . $field['element_id'] . "-last-name" . "}", |
| 1178 |
) |
| 1179 |
)); |
| 1180 |
} |
| 1181 |
} |
| 1182 |
} |
| 1183 |
} elseif ($field['type'] == 'date' && $field['field_type'] == 'select') { |
| 1184 |
|
| 1185 |
$elements[] = $this->auto_field($field, array( |
| 1186 |
'type' => 'e2pdf-html', |
| 1187 |
'block' => true, |
| 1188 |
'float' => $float, |
| 1189 |
'properties' => array( |
| 1190 |
'top' => '20', |
| 1191 |
'left' => '20', |
| 1192 |
'right' => '20', |
| 1193 |
'width' => $width . "%", |
| 1194 |
'height' => 'auto', |
| 1195 |
'value' => $field['field_label'], |
| 1196 |
) |
| 1197 |
)); |
| 1198 |
|
| 1199 |
$days = array(); |
| 1200 |
$months = array(); |
| 1201 |
$years = array(); |
| 1202 |
if (class_exists('Forminator_Date')) { |
| 1203 |
$forminator_date = new Forminator_Date(); |
| 1204 |
$options = $forminator_date->get_day(); |
| 1205 |
foreach ($options as $option) { |
| 1206 |
$days[] = $option['value']; |
| 1207 |
} |
| 1208 |
|
| 1209 |
$options = $forminator_date->get_months(); |
| 1210 |
foreach ($options as $option) { |
| 1211 |
$months[] = $option['value']; |
| 1212 |
} |
| 1213 |
|
| 1214 |
$options = $forminator_date->get_years($field['min_year'], $field['max_year']); |
| 1215 |
foreach ($options as $option) { |
| 1216 |
$years[] = $option['value']; |
| 1217 |
} |
| 1218 |
} |
| 1219 |
|
| 1220 |
$elements[] = $this->auto_field($field, array( |
| 1221 |
'type' => 'e2pdf-select', |
| 1222 |
'properties' => array( |
| 1223 |
'top' => '5', |
| 1224 |
'width' => '30%', |
| 1225 |
'height' => 'auto', |
| 1226 |
'options' => implode("\n", $days), |
| 1227 |
'value' => "{" . $field['element_id'] . "-month" . "}", |
| 1228 |
) |
| 1229 |
)); |
| 1230 |
|
| 1231 |
$elements[] = $this->auto_field($field, array( |
| 1232 |
'type' => 'e2pdf-select', |
| 1233 |
'float' => true, |
| 1234 |
'properties' => array( |
| 1235 |
'top' => '5', |
| 1236 |
'left' => '5%', |
| 1237 |
'right' => '5%', |
| 1238 |
'width' => '40%', |
| 1239 |
'height' => 'auto', |
| 1240 |
'options' => implode("\n", $months), |
| 1241 |
'value' => "{" . $field['element_id'] . "-day" . "}", |
| 1242 |
) |
| 1243 |
)); |
| 1244 |
|
| 1245 |
$elements[] = $this->auto_field($field, array( |
| 1246 |
'type' => 'e2pdf-select', |
| 1247 |
'float' => true, |
| 1248 |
'properties' => array( |
| 1249 |
'top' => '5', |
| 1250 |
'width' => '30%', |
| 1251 |
'height' => 'auto', |
| 1252 |
'options' => implode("\n", $years), |
| 1253 |
'value' => "{" . $field['element_id'] . "-year" . "}", |
| 1254 |
) |
| 1255 |
)); |
| 1256 |
} elseif ($field['type'] == 'date' && $field['field_type'] == 'input') { |
| 1257 |
|
| 1258 |
$elements[] = $this->auto_field($field, array( |
| 1259 |
'type' => 'e2pdf-html', |
| 1260 |
'block' => true, |
| 1261 |
'float' => $float, |
| 1262 |
'properties' => array( |
| 1263 |
'top' => '20', |
| 1264 |
'left' => '20', |
| 1265 |
'right' => '20', |
| 1266 |
'width' => $width . "%", |
| 1267 |
'height' => 'auto', |
| 1268 |
'value' => $field['field_label'], |
| 1269 |
) |
| 1270 |
)); |
| 1271 |
|
| 1272 |
$elements[] = $this->auto_field($field, array( |
| 1273 |
'type' => 'e2pdf-input', |
| 1274 |
'properties' => array( |
| 1275 |
'top' => '5', |
| 1276 |
'width' => '30%', |
| 1277 |
'height' => 'auto', |
| 1278 |
'value' => "{" . $field['element_id'] . "-month" . "}", |
| 1279 |
) |
| 1280 |
)); |
| 1281 |
|
| 1282 |
$elements[] = $this->auto_field($field, array( |
| 1283 |
'type' => 'e2pdf-input', |
| 1284 |
'float' => true, |
| 1285 |
'properties' => array( |
| 1286 |
'top' => '5', |
| 1287 |
'left' => '5%', |
| 1288 |
'right' => '5%', |
| 1289 |
'width' => '40%', |
| 1290 |
'height' => 'auto', |
| 1291 |
'value' => "{" . $field['element_id'] . "-day" . "}", |
| 1292 |
) |
| 1293 |
)); |
| 1294 |
|
| 1295 |
$elements[] = $this->auto_field($field, array( |
| 1296 |
'float' => true, |
| 1297 |
'type' => 'e2pdf-input', |
| 1298 |
'properties' => array( |
| 1299 |
'top' => '5', |
| 1300 |
'width' => '30%', |
| 1301 |
'height' => 'auto', |
| 1302 |
'value' => "{" . $field['element_id'] . "-year" . "}", |
| 1303 |
) |
| 1304 |
)); |
| 1305 |
} else { |
| 1306 |
|
| 1307 |
$elements[] = $this->auto_field($field, array( |
| 1308 |
'type' => 'e2pdf-html', |
| 1309 |
'block' => true, |
| 1310 |
'float' => $float, |
| 1311 |
'properties' => array( |
| 1312 |
'top' => '20', |
| 1313 |
'left' => '20', |
| 1314 |
'right' => '20', |
| 1315 |
'width' => $width . "%", |
| 1316 |
'height' => 'auto', |
| 1317 |
'value' => $field['field_label'], |
| 1318 |
) |
| 1319 |
)); |
| 1320 |
|
| 1321 |
$elements[] = $this->auto_field($field, array( |
| 1322 |
'type' => 'e2pdf-input', |
| 1323 |
'properties' => array( |
| 1324 |
'top' => '5', |
| 1325 |
'width' => '100%', |
| 1326 |
'height' => 'auto', |
| 1327 |
'value' => "{" . $field['element_id'] . "}", |
| 1328 |
) |
| 1329 |
)); |
| 1330 |
} |
| 1331 |
break; |
| 1332 |
case 'address': |
| 1333 |
if (!$field['street_address'] && !$field['address_line']) { |
| 1334 |
|
| 1335 |
if (!$field['address_city'] && !$field['address_state']) { |
| 1336 |
if ($field['address_zip']) { |
| 1337 |
$elements[] = $this->auto_field($field, array( |
| 1338 |
'type' => 'e2pdf-html', |
| 1339 |
'block' => true, |
| 1340 |
'float' => true, |
| 1341 |
'properties' => array( |
| 1342 |
'top' => '20', |
| 1343 |
'left' => '20', |
| 1344 |
'right' => '20', |
| 1345 |
'width' => $field['address_country'] ? $width / 2 . '%' : $width . '%', |
| 1346 |
'height' => 'auto', |
| 1347 |
'value' => $field['address_zip_label'] |
| 1348 |
) |
| 1349 |
)); |
| 1350 |
|
| 1351 |
$elements[] = $this->auto_field($field, array( |
| 1352 |
'type' => 'e2pdf-input', |
| 1353 |
'properties' => array( |
| 1354 |
'top' => '5', |
| 1355 |
'width' => '100%', |
| 1356 |
'height' => 'auto', |
| 1357 |
'value' => "{" . $field['element_id'] . "-zip" . "}", |
| 1358 |
) |
| 1359 |
)); |
| 1360 |
} |
| 1361 |
|
| 1362 |
if ($field['address_country']) { |
| 1363 |
$elements[] = $this->auto_field($field, array( |
| 1364 |
'type' => 'e2pdf-html', |
| 1365 |
'block' => true, |
| 1366 |
'float' => true, |
| 1367 |
'properties' => array( |
| 1368 |
'top' => '20', |
| 1369 |
'left' => '20', |
| 1370 |
'right' => '20', |
| 1371 |
'width' => $field['address_zip'] ? $width / 2 . '%' : $width . '%', |
| 1372 |
'height' => 'auto', |
| 1373 |
'value' => $field['address_country_label'], |
| 1374 |
) |
| 1375 |
)); |
| 1376 |
|
| 1377 |
$options_tmp = array(); |
| 1378 |
if (function_exists('forminator_to_field_array') && function_exists('forminator_get_countries_list')) { |
| 1379 |
$options = forminator_to_field_array(forminator_get_countries_list(), true); |
| 1380 |
foreach ($options as $option) { |
| 1381 |
$options_tmp[] = $option['value']; |
| 1382 |
} |
| 1383 |
//can be value or label |
| 1384 |
} |
| 1385 |
|
| 1386 |
$elements[] = $this->auto_field($field, array( |
| 1387 |
'type' => 'e2pdf-select', |
| 1388 |
'properties' => array( |
| 1389 |
'top' => '5', |
| 1390 |
'width' => '100%', |
| 1391 |
'height' => 'auto', |
| 1392 |
'options' => implode("\n", $options_tmp), |
| 1393 |
'value' => "{" . $field['element_id'] . "-country" . "}", |
| 1394 |
) |
| 1395 |
)); |
| 1396 |
} |
| 1397 |
} else { |
| 1398 |
|
| 1399 |
if ($field['address_city']) { |
| 1400 |
$elements[] = $this->auto_field($field, array( |
| 1401 |
'type' => 'e2pdf-html', |
| 1402 |
'block' => true, |
| 1403 |
'float' => true, |
| 1404 |
'properties' => array( |
| 1405 |
'top' => '20', |
| 1406 |
'left' => '20', |
| 1407 |
'right' => '20', |
| 1408 |
'width' => $field['address_state'] ? $width / 2 . '%' : $width . '%', |
| 1409 |
'height' => 'auto', |
| 1410 |
'value' => $field['address_city_label'], |
| 1411 |
) |
| 1412 |
)); |
| 1413 |
|
| 1414 |
$elements[] = $this->auto_field($field, array( |
| 1415 |
'type' => 'e2pdf-input', |
| 1416 |
'properties' => array( |
| 1417 |
'top' => '5', |
| 1418 |
'width' => '100%', |
| 1419 |
'height' => 'auto', |
| 1420 |
'value' => "{" . $field['element_id'] . "-city" . "}", |
| 1421 |
) |
| 1422 |
)); |
| 1423 |
|
| 1424 |
if ($field['address_zip'] && $field['address_state']) { |
| 1425 |
$elements[] = $this->auto_field($field, array( |
| 1426 |
'type' => 'e2pdf-html', |
| 1427 |
'properties' => array( |
| 1428 |
'top' => '20', |
| 1429 |
'right' => $field['address_country'] ? '0' : '-40', |
| 1430 |
'width' => $field['address_country'] ? '100%' : '200%', |
| 1431 |
'height' => 'auto', |
| 1432 |
'value' => $field['address_zip_label'], |
| 1433 |
) |
| 1434 |
)); |
| 1435 |
|
| 1436 |
$elements[] = $this->auto_field($field, array( |
| 1437 |
'type' => 'e2pdf-input', |
| 1438 |
'properties' => array( |
| 1439 |
'top' => '5', |
| 1440 |
'right' => $field['address_country'] ? '0' : '-40', |
| 1441 |
'width' => $field['address_country'] ? '100%' : '200%', |
| 1442 |
'height' => 'auto', |
| 1443 |
'value' => "{" . $field['element_id'] . "-zip" . "}", |
| 1444 |
) |
| 1445 |
)); |
| 1446 |
} elseif ($field['address_country'] && !$field['address_zip'] && $field['address_state']) { |
| 1447 |
|
| 1448 |
$elements[] = $this->auto_field($field, array( |
| 1449 |
'type' => 'e2pdf-html', |
| 1450 |
'properties' => array( |
| 1451 |
'top' => '20', |
| 1452 |
'right' => $field['address_zip'] ? '0' : '-40', |
| 1453 |
'width' => $field['address_zip'] ? '100%' : '200%', |
| 1454 |
'height' => 'auto', |
| 1455 |
'value' => $field['address_country_label'], |
| 1456 |
) |
| 1457 |
)); |
| 1458 |
|
| 1459 |
$options_tmp = array(); |
| 1460 |
if (function_exists('forminator_to_field_array') && function_exists('forminator_get_countries_list')) { |
| 1461 |
$options = forminator_to_field_array(forminator_get_countries_list(), true); |
| 1462 |
foreach ($options as $option) { |
| 1463 |
$options_tmp[] = $option['value']; |
| 1464 |
} |
| 1465 |
//can be value or label |
| 1466 |
} |
| 1467 |
|
| 1468 |
$elements[] = $this->auto_field($field, array( |
| 1469 |
'type' => 'e2pdf-select', |
| 1470 |
'properties' => array( |
| 1471 |
'top' => '5', |
| 1472 |
'right' => $field['address_zip'] ? '0' : '-40', |
| 1473 |
'width' => $field['address_zip'] ? '100%' : '200%', |
| 1474 |
'height' => 'auto', |
| 1475 |
'options' => implode("\n", $options_tmp), |
| 1476 |
'value' => "{" . $field['element_id'] . "-country" . "}", |
| 1477 |
) |
| 1478 |
)); |
| 1479 |
} |
| 1480 |
} |
| 1481 |
|
| 1482 |
if ($field['address_state']) { |
| 1483 |
$elements[] = $this->auto_field($field, array( |
| 1484 |
'type' => 'e2pdf-html', |
| 1485 |
'block' => true, |
| 1486 |
'float' => true, |
| 1487 |
'properties' => array( |
| 1488 |
'top' => '20', |
| 1489 |
'left' => '20', |
| 1490 |
'right' => '20', |
| 1491 |
'width' => $field['address_city'] ? ($width / 2) . '%' : $width . '%', |
| 1492 |
'height' => 'auto', |
| 1493 |
'value' => $field['address_state_label'], |
| 1494 |
) |
| 1495 |
)); |
| 1496 |
|
| 1497 |
$elements[] = $this->auto_field($field, array( |
| 1498 |
'type' => 'e2pdf-input', |
| 1499 |
'properties' => array( |
| 1500 |
'top' => '5', |
| 1501 |
'width' => '100%', |
| 1502 |
'height' => 'auto', |
| 1503 |
'value' => "{" . $field['element_id'] . "-state" . "}", |
| 1504 |
) |
| 1505 |
)); |
| 1506 |
|
| 1507 |
if ($field['address_country'] && $field['address_zip'] && $field['address_city']) { |
| 1508 |
|
| 1509 |
$elements[] = $this->auto_field($field, array( |
| 1510 |
'type' => 'e2pdf-html', |
| 1511 |
'properties' => array( |
| 1512 |
'top' => '20', |
| 1513 |
'right' => $field['address_zip'] ? '0' : '-40', |
| 1514 |
'width' => $field['address_zip'] ? '100%' : '200%', |
| 1515 |
'height' => 'auto', |
| 1516 |
'value' => $field['address_country_label'], |
| 1517 |
) |
| 1518 |
)); |
| 1519 |
|
| 1520 |
$options_tmp = array(); |
| 1521 |
if (function_exists('forminator_to_field_array') && function_exists('forminator_get_countries_list')) { |
| 1522 |
$options = forminator_to_field_array(forminator_get_countries_list(), true); |
| 1523 |
foreach ($options as $option) { |
| 1524 |
$options_tmp[] = $option['value']; |
| 1525 |
} |
| 1526 |
//can be value or label |
| 1527 |
} |
| 1528 |
|
| 1529 |
$elements[] = $this->auto_field($field, array( |
| 1530 |
'type' => 'e2pdf-select', |
| 1531 |
'properties' => array( |
| 1532 |
'top' => '5', |
| 1533 |
'right' => $field['address_zip'] ? '0' : '-40', |
| 1534 |
'width' => $field['address_zip'] ? '100%' : '200%', |
| 1535 |
'height' => 'auto', |
| 1536 |
'options' => implode("\n", $options_tmp), |
| 1537 |
'value' => "{" . $field['element_id'] . "-country" . "}", |
| 1538 |
) |
| 1539 |
)); |
| 1540 |
} |
| 1541 |
} |
| 1542 |
|
| 1543 |
if (!$field['address_city'] || !$field['address_state']) { |
| 1544 |
if ($field['address_zip']) { |
| 1545 |
$elements[] = $this->auto_field($field, array( |
| 1546 |
'type' => 'e2pdf-html', |
| 1547 |
'properties' => array( |
| 1548 |
'top' => '20', |
| 1549 |
'right' => $field['address_country'] ? '20' : '0', |
| 1550 |
'width' => $field['address_country'] ? '50%' : '100%', |
| 1551 |
'height' => 'auto', |
| 1552 |
'value' => $field['address_zip_label'], |
| 1553 |
) |
| 1554 |
)); |
| 1555 |
} |
| 1556 |
|
| 1557 |
if ($field['address_country']) { |
| 1558 |
|
| 1559 |
$elements[] = $this->auto_field($field, array( |
| 1560 |
'type' => 'e2pdf-html', |
| 1561 |
'float' => $field['address_zip'] ? true : false, |
| 1562 |
'properties' => array( |
| 1563 |
'top' => '20', |
| 1564 |
'left' => $field['address_zip'] ? '20' : '0', |
| 1565 |
'width' => $field['address_zip'] ? '50%' : '100%', |
| 1566 |
'height' => 'auto', |
| 1567 |
'value' => $field['address_country_label'], |
| 1568 |
) |
| 1569 |
)); |
| 1570 |
} |
| 1571 |
|
| 1572 |
if ($field['address_zip']) { |
| 1573 |
$elements[] = $this->auto_field($field, array( |
| 1574 |
'type' => 'e2pdf-input', |
| 1575 |
'properties' => array( |
| 1576 |
'top' => '5', |
| 1577 |
'right' => $field['address_country'] ? '20' : '0', |
| 1578 |
'width' => $field['address_country'] ? '50%' : '100%', |
| 1579 |
'height' => 'auto', |
| 1580 |
'value' => "{" . $field['element_id'] . "-zip" . "}", |
| 1581 |
) |
| 1582 |
)); |
| 1583 |
} |
| 1584 |
|
| 1585 |
if ($field['address_country']) { |
| 1586 |
$options_tmp = array(); |
| 1587 |
if (function_exists('forminator_to_field_array') && function_exists('forminator_get_countries_list')) { |
| 1588 |
$options = forminator_to_field_array(forminator_get_countries_list(), true); |
| 1589 |
foreach ($options as $option) { |
| 1590 |
$options_tmp[] = $option['value']; |
| 1591 |
} |
| 1592 |
//can be value or label |
| 1593 |
} |
| 1594 |
|
| 1595 |
$elements[] = $this->auto_field($field, array( |
| 1596 |
'type' => 'e2pdf-select', |
| 1597 |
'float' => $field['address_zip'] ? true : false, |
| 1598 |
'properties' => array( |
| 1599 |
'top' => '5', |
| 1600 |
'left' => $field['address_zip'] ? '20' : '0', |
| 1601 |
'width' => $field['address_zip'] ? '50%' : '100%', |
| 1602 |
'height' => 'auto', |
| 1603 |
'options' => implode("\n", $options_tmp), |
| 1604 |
'value' => "{" . $field['element_id'] . "-country" . "}", |
| 1605 |
) |
| 1606 |
)); |
| 1607 |
} |
| 1608 |
} |
| 1609 |
} |
| 1610 |
} else { |
| 1611 |
|
| 1612 |
if ($field['street_address']) { |
| 1613 |
$elements[] = $this->auto_field($field, array( |
| 1614 |
'type' => 'e2pdf-html', |
| 1615 |
'block' => true, |
| 1616 |
'float' => true, |
| 1617 |
'properties' => array( |
| 1618 |
'top' => '20', |
| 1619 |
'left' => '20', |
| 1620 |
'right' => '20', |
| 1621 |
'width' => $width . '%', |
| 1622 |
'height' => 'auto', |
| 1623 |
'value' => $field['street_address_label'], |
| 1624 |
) |
| 1625 |
)); |
| 1626 |
|
| 1627 |
$elements[] = $this->auto_field($field, array( |
| 1628 |
'type' => 'e2pdf-input', |
| 1629 |
'properties' => array( |
| 1630 |
'top' => '5', |
| 1631 |
'width' => '100%', |
| 1632 |
'height' => 'auto', |
| 1633 |
'value' => "{" . $field['element_id'] . "-street_address" . "}", |
| 1634 |
) |
| 1635 |
)); |
| 1636 |
} |
| 1637 |
|
| 1638 |
if ($field['address_line']) { |
| 1639 |
|
| 1640 |
if ($field['address_line_label']) { |
| 1641 |
$elements[] = $this->auto_field($field, array( |
| 1642 |
'type' => 'e2pdf-html', |
| 1643 |
'block' => $field['street_address'] ? false : true, |
| 1644 |
'float' => $field['street_address'] ? false : true, |
| 1645 |
'properties' => array( |
| 1646 |
'top' => '20', |
| 1647 |
'left' => $field['street_address'] ? '0' : '20', |
| 1648 |
'right' => $field['street_address'] ? '0' : '20', |
| 1649 |
'width' => $field['street_address'] ? '100%' : $width . '%', |
| 1650 |
'height' => 'auto', |
| 1651 |
'value' => $field['address_line_label'], |
| 1652 |
) |
| 1653 |
)); |
| 1654 |
} |
| 1655 |
|
| 1656 |
$elements[] = $this->auto_field($field, array( |
| 1657 |
'type' => 'e2pdf-input', |
| 1658 |
'properties' => array( |
| 1659 |
'top' => $field['address_line_label'] ? '0' : '20', |
| 1660 |
'width' => '100%', |
| 1661 |
'height' => 'auto', |
| 1662 |
'value' => "{" . $field['element_id'] . "-address_line" . "}", |
| 1663 |
) |
| 1664 |
)); |
| 1665 |
} |
| 1666 |
|
| 1667 |
if ($field['address_city']) { |
| 1668 |
|
| 1669 |
$elements[] = $this->auto_field($field, array( |
| 1670 |
'type' => 'e2pdf-html', |
| 1671 |
'properties' => array( |
| 1672 |
'top' => '20', |
| 1673 |
'right' => $field['address_state'] ? '20' : '0', |
| 1674 |
'width' => $field['address_state'] ? '50%' : '100%', |
| 1675 |
'height' => 'auto', |
| 1676 |
'value' => $field['address_city_label'], |
| 1677 |
) |
| 1678 |
)); |
| 1679 |
} |
| 1680 |
|
| 1681 |
if ($field['address_state']) { |
| 1682 |
$elements[] = $this->auto_field($field, array( |
| 1683 |
'type' => 'e2pdf-html', |
| 1684 |
'float' => $field['address_city'] ? true : false, |
| 1685 |
'properties' => array( |
| 1686 |
'top' => $field['address_city'] ? '0' : '20', |
| 1687 |
'left' => $field['address_city'] ? '20' : '0', |
| 1688 |
'width' => $field['address_city'] ? '50%' : '100%', |
| 1689 |
'height' => 'auto', |
| 1690 |
'value' => $field['address_state_label'], |
| 1691 |
) |
| 1692 |
)); |
| 1693 |
} |
| 1694 |
|
| 1695 |
if ($field['address_city']) { |
| 1696 |
$elements[] = $this->auto_field($field, array( |
| 1697 |
'type' => 'e2pdf-input', |
| 1698 |
'properties' => array( |
| 1699 |
'top' => '5', |
| 1700 |
'right' => $field['address_state'] ? '20' : '0', |
| 1701 |
'width' => $field['address_state'] ? '50%' : '100%', |
| 1702 |
'height' => 'auto', |
| 1703 |
'value' => "{" . $field['element_id'] . "-city" . "}", |
| 1704 |
) |
| 1705 |
)); |
| 1706 |
} |
| 1707 |
|
| 1708 |
if ($field['address_state']) { |
| 1709 |
$elements[] = $this->auto_field($field, array( |
| 1710 |
'type' => 'e2pdf-input', |
| 1711 |
'float' => $field['address_city'] ? true : false, |
| 1712 |
'properties' => array( |
| 1713 |
'top' => '5', |
| 1714 |
'left' => $field['address_city'] ? '20' : '0', |
| 1715 |
'width' => $field['address_city'] ? '50%' : '100%', |
| 1716 |
'height' => 'auto', |
| 1717 |
'value' => "{" . $field['element_id'] . "-state" . "}", |
| 1718 |
) |
| 1719 |
)); |
| 1720 |
} |
| 1721 |
|
| 1722 |
if ($field['address_zip']) { |
| 1723 |
|
| 1724 |
$elements[] = $this->auto_field($field, array( |
| 1725 |
'type' => 'e2pdf-html', |
| 1726 |
'properties' => array( |
| 1727 |
'top' => '20', |
| 1728 |
'right' => $field['address_country'] ? '20' : '0', |
| 1729 |
'width' => $field['address_country'] ? '50%' : '100%', |
| 1730 |
'height' => 'auto', |
| 1731 |
'value' => $field['address_zip_label'], |
| 1732 |
) |
| 1733 |
)); |
| 1734 |
} |
| 1735 |
|
| 1736 |
if ($field['address_country']) { |
| 1737 |
$elements[] = $this->auto_field($field, array( |
| 1738 |
'type' => 'e2pdf-html', |
| 1739 |
'float' => $field['address_zip'] ? true : false, |
| 1740 |
'properties' => array( |
| 1741 |
'top' => '20', |
| 1742 |
'left' => $field['address_zip'] ? '20' : '0', |
| 1743 |
'width' => $field['address_zip'] ? '50%' : '100%', |
| 1744 |
'height' => 'auto', |
| 1745 |
'value' => $field['address_country_label'], |
| 1746 |
) |
| 1747 |
)); |
| 1748 |
} |
| 1749 |
|
| 1750 |
if ($field['address_zip']) { |
| 1751 |
$elements[] = $this->auto_field($field, array( |
| 1752 |
'type' => 'e2pdf-input', |
| 1753 |
'properties' => array( |
| 1754 |
'top' => '5', |
| 1755 |
'right' => $field['address_country'] ? '20' : '0', |
| 1756 |
'width' => $field['address_country'] ? '50%' : '100%', |
| 1757 |
'height' => 'auto', |
| 1758 |
'value' => "{" . $field['element_id'] . "-zip" . "}", |
| 1759 |
) |
| 1760 |
)); |
| 1761 |
} |
| 1762 |
|
| 1763 |
if ($field['address_country']) { |
| 1764 |
$options_tmp = array(); |
| 1765 |
if (function_exists('forminator_to_field_array') && function_exists('forminator_get_countries_list')) { |
| 1766 |
$options = forminator_to_field_array(forminator_get_countries_list(), true); |
| 1767 |
foreach ($options as $option) { |
| 1768 |
$options_tmp[] = $option['value']; |
| 1769 |
} |
| 1770 |
//can be value or label |
| 1771 |
} |
| 1772 |
|
| 1773 |
$elements[] = $this->auto_field($field, array( |
| 1774 |
'type' => 'e2pdf-select', |
| 1775 |
'float' => $field['address_zip'] ? true : false, |
| 1776 |
'properties' => array( |
| 1777 |
'top' => '5', |
| 1778 |
'left' => $field['address_zip'] ? '20' : '0', |
| 1779 |
'width' => $field['address_zip'] ? '50%' : '100%', |
| 1780 |
'height' => 'auto', |
| 1781 |
'options' => implode("\n", $options_tmp), |
| 1782 |
'value' => "{" . $field['element_id'] . "-country" . "}", |
| 1783 |
) |
| 1784 |
)); |
| 1785 |
} |
| 1786 |
} |
| 1787 |
break; |
| 1788 |
case 'time': |
| 1789 |
$hours = array(); |
| 1790 |
$minutes = array(); |
| 1791 |
|
| 1792 |
if (class_exists('Forminator_Time')) { |
| 1793 |
$forminator_time = new Forminator_Time(); |
| 1794 |
$options = $forminator_time->get_hours($field['time_type']); |
| 1795 |
foreach ($options as $option) { |
| 1796 |
$hours[] = $option['value']; |
| 1797 |
} |
| 1798 |
|
| 1799 |
$options = $forminator_time->get_minutes(); |
| 1800 |
foreach ($options as $option) { |
| 1801 |
$minutes[] = $option['value']; |
| 1802 |
} |
| 1803 |
} |
| 1804 |
|
| 1805 |
$elements[] = $this->auto_field($field, array( |
| 1806 |
'type' => 'e2pdf-html', |
| 1807 |
'block' => true, |
| 1808 |
'float' => true, |
| 1809 |
'properties' => array( |
| 1810 |
'top' => '20', |
| 1811 |
'left' => '20', |
| 1812 |
'right' => '20', |
| 1813 |
'width' => ($field['time_type'] == 'twelve' ? $width / 3 : $width / 2) . '%', |
| 1814 |
'height' => 'auto', |
| 1815 |
'value' => $field['hh_label'], |
| 1816 |
) |
| 1817 |
)); |
| 1818 |
|
| 1819 |
if ($field['field_type'] == 'select') { |
| 1820 |
$elements[] = $this->auto_field($field, array( |
| 1821 |
'type' => 'e2pdf-select', |
| 1822 |
'properties' => array( |
| 1823 |
'top' => '5', |
| 1824 |
'width' => '100%', |
| 1825 |
'height' => 'auto', |
| 1826 |
'options' => implode("\n", $hours), |
| 1827 |
'value' => "{" . $field['element_id'] . "-hours" . "}", |
| 1828 |
) |
| 1829 |
)); |
| 1830 |
} else { |
| 1831 |
$elements[] = $this->auto_field($field, array( |
| 1832 |
'type' => 'e2pdf-input', |
| 1833 |
'properties' => array( |
| 1834 |
'top' => '5', |
| 1835 |
'width' => '100%', |
| 1836 |
'height' => 'auto', |
| 1837 |
'value' => "{" . $field['element_id'] . "-hours" . "}", |
| 1838 |
) |
| 1839 |
)); |
| 1840 |
} |
| 1841 |
|
| 1842 |
$elements[] = $this->auto_field($field, array( |
| 1843 |
'type' => 'e2pdf-html', |
| 1844 |
'block' => true, |
| 1845 |
'float' => true, |
| 1846 |
'properties' => array( |
| 1847 |
'top' => '20', |
| 1848 |
'left' => '20', |
| 1849 |
'right' => '20', |
| 1850 |
'width' => ($field['time_type'] == 'twelve' ? $width / 3 : $width / 2) . '%', |
| 1851 |
'height' => 'auto', |
| 1852 |
'value' => $field['mm_label'], |
| 1853 |
) |
| 1854 |
)); |
| 1855 |
|
| 1856 |
if ($field['field_type'] == 'select') { |
| 1857 |
$elements[] = $this->auto_field($field, array( |
| 1858 |
'type' => 'e2pdf-select', |
| 1859 |
'properties' => array( |
| 1860 |
'top' => '5', |
| 1861 |
'width' => '100%', |
| 1862 |
'height' => 'auto', |
| 1863 |
'options' => implode("\n", $minutes), |
| 1864 |
'value' => "{" . $field['element_id'] . "-minutes" . "}", |
| 1865 |
) |
| 1866 |
)); |
| 1867 |
} else { |
| 1868 |
$elements[] = $this->auto_field($field, array( |
| 1869 |
'type' => 'e2pdf-input', |
| 1870 |
'properties' => array( |
| 1871 |
'top' => '5', |
| 1872 |
'width' => '100%', |
| 1873 |
'height' => 'auto', |
| 1874 |
'value' => "{" . $field['element_id'] . "-minutes" . "}", |
| 1875 |
) |
| 1876 |
)); |
| 1877 |
} |
| 1878 |
|
| 1879 |
if ($field['time_type'] == 'twelve') { |
| 1880 |
$elements[] = $this->auto_field($field, array( |
| 1881 |
'type' => 'e2pdf-html', |
| 1882 |
'block' => true, |
| 1883 |
'float' => $float, |
| 1884 |
'properties' => array( |
| 1885 |
'top' => '20', |
| 1886 |
'left' => '20', |
| 1887 |
'right' => '20', |
| 1888 |
'width' => ($width / 3) . '%', |
| 1889 |
'height' => 'auto', |
| 1890 |
'value' => '', |
| 1891 |
) |
| 1892 |
)); |
| 1893 |
|
| 1894 |
$ampm = array( |
| 1895 |
'am', 'pm' |
| 1896 |
); |
| 1897 |
|
| 1898 |
$elements[] = $this->auto_field($field, array( |
| 1899 |
'type' => 'e2pdf-select', |
| 1900 |
'properties' => array( |
| 1901 |
'top' => '5', |
| 1902 |
'width' => '100%', |
| 1903 |
'height' => 'auto', |
| 1904 |
'options' => implode("\n", $ampm), |
| 1905 |
'value' => "{" . $field['element_id'] . "-ampm" . "}", |
| 1906 |
) |
| 1907 |
)); |
| 1908 |
} |
| 1909 |
break; |
| 1910 |
case 'html': |
| 1911 |
if ($field['field_label']) { |
| 1912 |
$elements[] = $this->auto_field($field, array( |
| 1913 |
'type' => 'e2pdf-html', |
| 1914 |
'block' => true, |
| 1915 |
'properties' => array( |
| 1916 |
'top' => '20', |
| 1917 |
'left' => '20', |
| 1918 |
'right' => '20', |
| 1919 |
'width' => $width . '%', |
| 1920 |
'height' => 'auto', |
| 1921 |
'value' => $field['field_label'], |
| 1922 |
) |
| 1923 |
)); |
| 1924 |
|
| 1925 |
$elements[] = $this->auto_field($field, array( |
| 1926 |
'type' => 'e2pdf-html', |
| 1927 |
'properties' => array( |
| 1928 |
'top' => '5', |
| 1929 |
'width' => '100%', |
| 1930 |
'height' => 'auto', |
| 1931 |
'value' => $field['variations'], |
| 1932 |
) |
| 1933 |
)); |
| 1934 |
} else { |
| 1935 |
$elements[] = $this->auto_field($field, array( |
| 1936 |
'type' => 'e2pdf-html', |
| 1937 |
'block' => true, |
| 1938 |
'properties' => array( |
| 1939 |
'top' => '20', |
| 1940 |
'left' => '20', |
| 1941 |
'right' => '20', |
| 1942 |
'width' => $width . '%', |
| 1943 |
'height' => 'auto', |
| 1944 |
'value' => $field['variations'], |
| 1945 |
) |
| 1946 |
)); |
| 1947 |
} |
| 1948 |
break; |
| 1949 |
case 'section': |
| 1950 |
$section = ''; |
| 1951 |
if ($field['section_title']) { |
| 1952 |
$section .= "<h2>" . $field['section_title'] . "</h2>"; |
| 1953 |
} |
| 1954 |
if ($field['section_subtitle']) { |
| 1955 |
$section .= $field['section_subtitle']; |
| 1956 |
} |
| 1957 |
if ($section) { |
| 1958 |
$elements[] = $this->auto_field($field, array( |
| 1959 |
'type' => 'e2pdf-html', |
| 1960 |
'block' => true, |
| 1961 |
'properties' => array( |
| 1962 |
'top' => '20', |
| 1963 |
'left' => '20', |
| 1964 |
'right' => '20', |
| 1965 |
'width' => $width . '%', |
| 1966 |
'height' => 'auto', |
| 1967 |
'value' => $section, |
| 1968 |
) |
| 1969 |
)); |
| 1970 |
} |
| 1971 |
break; |
| 1972 |
case 'text': |
| 1973 |
$elements[] = $this->auto_field($field, array( |
| 1974 |
'type' => 'e2pdf-html', |
| 1975 |
'block' => true, |
| 1976 |
'properties' => array( |
| 1977 |
'top' => '20', |
| 1978 |
'left' => '20', |
| 1979 |
'right' => '20', |
| 1980 |
'width' => $width . '%', |
| 1981 |
'height' => 'auto', |
| 1982 |
'value' => $field['field_label'], |
| 1983 |
) |
| 1984 |
)); |
| 1985 |
|
| 1986 |
if (isset($field['input_type']) && $field['input_type'] == 'line') { |
| 1987 |
$elements[] = $this->auto_field($field, array( |
| 1988 |
'type' => 'e2pdf-input', |
| 1989 |
'properties' => array( |
| 1990 |
'top' => '5', |
| 1991 |
'width' => '100%', |
| 1992 |
'height' => 'auto', |
| 1993 |
'value' => "{" . $field['element_id'] . "}", |
| 1994 |
) |
| 1995 |
)); |
| 1996 |
} else { |
| 1997 |
$elements[] = $this->auto_field($field, array( |
| 1998 |
'type' => 'e2pdf-textarea', |
| 1999 |
'properties' => array( |
| 2000 |
'top' => '5', |
| 2001 |
'width' => '100%', |
| 2002 |
'height' => 'auto', |
| 2003 |
'value' => "{" . $field['element_id'] . "}", |
| 2004 |
) |
| 2005 |
)); |
| 2006 |
} |
| 2007 |
break; |
| 2008 |
case 'textarea': |
| 2009 |
$elements[] = $this->auto_field($field, array( |
| 2010 |
'type' => 'e2pdf-html', |
| 2011 |
'block' => true, |
| 2012 |
'properties' => array( |
| 2013 |
'top' => '20', |
| 2014 |
'left' => '20', |
| 2015 |
'right' => '20', |
| 2016 |
'width' => $width . '%', |
| 2017 |
'height' => 'auto', |
| 2018 |
'value' => $field['field_label'], |
| 2019 |
) |
| 2020 |
)); |
| 2021 |
$elements[] = $this->auto_field($field, array( |
| 2022 |
'type' => 'e2pdf-textarea', |
| 2023 |
'properties' => array( |
| 2024 |
'top' => '5', |
| 2025 |
'width' => '100%', |
| 2026 |
'height' => 'auto', |
| 2027 |
'value' => "{" . $field['element_id'] . "}", |
| 2028 |
) |
| 2029 |
)); |
| 2030 |
break; |
| 2031 |
case 'select': |
| 2032 |
$elements[] = $this->auto_field($field, array( |
| 2033 |
'type' => 'e2pdf-html', |
| 2034 |
'block' => true, |
| 2035 |
'float' => true, |
| 2036 |
'properties' => array( |
| 2037 |
'top' => '20', |
| 2038 |
'left' => '20', |
| 2039 |
'right' => '20', |
| 2040 |
'width' => $width . '%', |
| 2041 |
'height' => 'auto', |
| 2042 |
'value' => $field['field_label'], |
| 2043 |
) |
| 2044 |
)); |
| 2045 |
|
| 2046 |
if ($field['value_type'] == 'radio') { |
| 2047 |
foreach ($field['options'] as $opt_key => $option) { |
| 2048 |
if (is_array($option)) { |
| 2049 |
$elements[] = $this->auto_field($field, array( |
| 2050 |
'type' => 'e2pdf-radio', |
| 2051 |
'properties' => array( |
| 2052 |
'top' => '5', |
| 2053 |
'width' => 'auto', |
| 2054 |
'height' => 'auto', |
| 2055 |
'value' => "{" . $field['element_id'] . "}", |
| 2056 |
'option' => $option['value'] ? $option['value'] : $option['label'], |
| 2057 |
'group' => "{" . $field['element_id'] . "}", |
| 2058 |
) |
| 2059 |
)); |
| 2060 |
$elements[] = $this->auto_field($field, array( |
| 2061 |
'type' => 'e2pdf-html', |
| 2062 |
'float' => true, |
| 2063 |
'properties' => array( |
| 2064 |
'left' => '5', |
| 2065 |
'width' => '100%', |
| 2066 |
'height' => 'auto', |
| 2067 |
'value' => $option['label'] |
| 2068 |
) |
| 2069 |
)); |
| 2070 |
} |
| 2071 |
} |
| 2072 |
} else { |
| 2073 |
$options_tmp = array(); |
| 2074 |
foreach ($field['options'] as $option) { |
| 2075 |
$options_tmp[] = $option['value'] ? $option['value'] : $option['label']; |
| 2076 |
} |
| 2077 |
$elements[] = $this->auto_field($field, array( |
| 2078 |
'type' => 'e2pdf-select', |
| 2079 |
'properties' => array( |
| 2080 |
'top' => '5', |
| 2081 |
'width' => '100%', |
| 2082 |
'height' => 'auto', |
| 2083 |
'options' => implode("\n", $options_tmp), |
| 2084 |
'value' => "{" . $field['element_id'] . "}", |
| 2085 |
) |
| 2086 |
)); |
| 2087 |
} |
| 2088 |
break; |
| 2089 |
case 'checkbox': |
| 2090 |
$elements[] = $this->auto_field($field, array( |
| 2091 |
'type' => 'e2pdf-html', |
| 2092 |
'block' => true, |
| 2093 |
'float' => true, |
| 2094 |
'properties' => array( |
| 2095 |
'top' => '20', |
| 2096 |
'left' => '20', |
| 2097 |
'right' => '20', |
| 2098 |
'width' => $width . '%', |
| 2099 |
'height' => 'auto', |
| 2100 |
'value' => $field['field_label'], |
| 2101 |
) |
| 2102 |
)); |
| 2103 |
|
| 2104 |
if ($field['value_type'] == 'multiselect') { |
| 2105 |
$options_tmp = array(); |
| 2106 |
foreach ($field['options'] as $opt_key => $option) { |
| 2107 |
$options_tmp[] = $option['value'] ? $option['value'] : $option['label']; |
| 2108 |
} |
| 2109 |
$elements[] = $this->auto_field($field, array( |
| 2110 |
'type' => 'e2pdf-select', |
| 2111 |
'properties' => array( |
| 2112 |
'top' => '5', |
| 2113 |
'width' => '100%', |
| 2114 |
'height' => '44', |
| 2115 |
'multiline' => '1', |
| 2116 |
'options' => implode("\n", $options_tmp), |
| 2117 |
'value' => "{" . $field['element_id'] . "}", |
| 2118 |
) |
| 2119 |
)); |
| 2120 |
} else { |
| 2121 |
foreach ($field['options'] as $opt_key => $option) { |
| 2122 |
if (is_array($option)) { |
| 2123 |
$elements[] = $this->auto_field($field, array( |
| 2124 |
'type' => 'e2pdf-checkbox', |
| 2125 |
'properties' => array( |
| 2126 |
'top' => '5', |
| 2127 |
'width' => 'auto', |
| 2128 |
'height' => 'auto', |
| 2129 |
'value' => "{" . $field['element_id'] . "}", |
| 2130 |
'option' => $option['value'] ? $option['value'] : $option['label'] |
| 2131 |
) |
| 2132 |
)); |
| 2133 |
$elements[] = $this->auto_field($field, array( |
| 2134 |
'type' => 'e2pdf-html', |
| 2135 |
'float' => true, |
| 2136 |
'properties' => array( |
| 2137 |
'left' => '5', |
| 2138 |
'width' => '100%', |
| 2139 |
'height' => 'auto', |
| 2140 |
'value' => $option['label'] |
| 2141 |
) |
| 2142 |
)); |
| 2143 |
} |
| 2144 |
} |
| 2145 |
} |
| 2146 |
break; |
| 2147 |
case 'gdprcheckbox': |
| 2148 |
$elements[] = $this->auto_field($field, array( |
| 2149 |
'type' => 'e2pdf-html', |
| 2150 |
'block' => true, |
| 2151 |
'float' => true, |
| 2152 |
'properties' => array( |
| 2153 |
'top' => '20', |
| 2154 |
'left' => '20', |
| 2155 |
'right' => '20', |
| 2156 |
'width' => $width . '%', |
| 2157 |
'height' => 'auto', |
| 2158 |
'value' => '', |
| 2159 |
) |
| 2160 |
)); |
| 2161 |
|
| 2162 |
$elements[] = $this->auto_field($field, array( |
| 2163 |
'type' => 'e2pdf-checkbox', |
| 2164 |
'properties' => array( |
| 2165 |
'top' => '5', |
| 2166 |
'width' => 'auto', |
| 2167 |
'height' => 'auto', |
| 2168 |
'value' => "{" . $field['element_id'] . "}", |
| 2169 |
'option' => 'true' |
| 2170 |
) |
| 2171 |
)); |
| 2172 |
$elements[] = $this->auto_field($field, array( |
| 2173 |
'type' => 'e2pdf-html', |
| 2174 |
'float' => true, |
| 2175 |
'properties' => array( |
| 2176 |
'left' => '5', |
| 2177 |
'width' => '100%', |
| 2178 |
'height' => 'auto', |
| 2179 |
'value' => $field['gdpr_description'] |
| 2180 |
) |
| 2181 |
)); |
| 2182 |
break; |
| 2183 |
default: |
| 2184 |
break; |
| 2185 |
} |
| 2186 |
} |
| 2187 |
} |
| 2188 |
|
| 2189 |
$response['page'] = array( |
| 2190 |
'bottom' => '20', |
| 2191 |
'top' => '20', |
| 2192 |
'left' => '20', |
| 2193 |
'right' => '20' |
| 2194 |
); |
| 2195 |
|
| 2196 |
$response['elements'] = $elements; |
| 2197 |
return $response; |
| 2198 |
} |
| 2199 |
|
| 2200 |
public function auto_field($field = false, $element = array()) { |
| 2201 |
|
| 2202 |
if (!$field) { |
| 2203 |
return false; |
| 2204 |
} |
| 2205 |
|
| 2206 |
if (!isset($element['block'])) { |
| 2207 |
$element['block'] = false; |
| 2208 |
} |
| 2209 |
|
| 2210 |
if (!isset($element['float'])) { |
| 2211 |
$element['float'] = false; |
| 2212 |
} |
| 2213 |
|
| 2214 |
return $element; |
| 2215 |
} |
| 2216 |
|
| 2217 |
/** |
| 2218 |
* Load actions for this extension |
| 2219 |
*/ |
| 2220 |
public function load_actions() { |
| 2221 |
add_action('forminator_custom_form_submit_before_set_fields', array($this, 'action_forminator_custom_form_submit_before_set_fields'), 30, 3); |
| 2222 |
add_action('forminator_custom_form_mail_admin_message', array($this, 'action_forminator_mail_message'), 30, 5); |
| 2223 |
add_action('forminator_custom_form_mail_user_message', array($this, 'action_forminator_mail_message'), 30, 5); |
| 2224 |
add_action('forminator_custom_form_mail_before_send_mail', array($this, 'action_forminator_custom_form_mail_before_send_mail'), 30, 4); |
| 2225 |
add_action('forminator_custom_form_mail_after_send_mail', array($this, 'action_forminator_custom_form_mail_after_send_mail'), 30, 3); |
| 2226 |
} |
| 2227 |
|
| 2228 |
/** |
| 2229 |
* Load filters for this extension |
| 2230 |
*/ |
| 2231 |
public function load_filters() { |
| 2232 |
add_filter('forminator_custom_form_submit_response', array($this, 'filter_forminator_custom_form_submit_response'), 30, 2); |
| 2233 |
add_filter('forminator_custom_form_ajax_submit_response', array($this, 'filter_forminator_custom_form_submit_response'), 30, 2); |
| 2234 |
} |
| 2235 |
|
| 2236 |
public function action_forminator_custom_form_submit_before_set_fields($entry, $form_id, $field_data_array) { |
| 2237 |
if (class_exists('Forminator_API')) { |
| 2238 |
$form = Forminator_API::get_form($form_id); |
| 2239 |
if (!is_wp_error($form)) { |
| 2240 |
if ($form->is_prevent_store()) { |
| 2241 |
$this->set('field_data_array', $field_data_array); |
| 2242 |
$this->set('dataset', 'is_prevent_store'); |
| 2243 |
} elseif ($entry && is_object($entry) && property_exists($entry, 'entry_id') && isset($entry->entry_id)) { |
| 2244 |
$this->set('dataset', $entry->entry_id); |
| 2245 |
} |
| 2246 |
} |
| 2247 |
} |
| 2248 |
} |
| 2249 |
|
| 2250 |
public function action_forminator_custom_form_mail_before_send_mail($mail, $custom_form, $data, $entry) { |
| 2251 |
add_filter('wp_mail', array($this, 'filter_wp_mail'), 30, 1); |
| 2252 |
} |
| 2253 |
|
| 2254 |
public function action_forminator_custom_form_mail_after_send_mail($mail, $custom_form, $data) { |
| 2255 |
remove_filter('wp_mail', array($this, 'filter_wp_mail'), 30); |
| 2256 |
$files = $this->helper->get('forminator_attachments'); |
| 2257 |
if (is_array($files) && !empty($files)) { |
| 2258 |
foreach ($files as $key => $file) { |
| 2259 |
$this->helper->delete_dir(dirname($file) . '/'); |
| 2260 |
} |
| 2261 |
$this->helper->deset('forminator_attachments'); |
| 2262 |
$this->helper->deset('forminator_mail_attachments'); |
| 2263 |
} |
| 2264 |
} |
| 2265 |
|
| 2266 |
public function action_forminator_mail_message($message, $custom_form, $data, $entry, $mail) { |
| 2267 |
if (isset($message) && false !== strpos($message, '[')) { |
| 2268 |
$shortcode_tags = array( |
| 2269 |
'e2pdf-download', |
| 2270 |
'e2pdf-save', |
| 2271 |
'e2pdf-attachment', |
| 2272 |
'e2pdf-adobesign' |
| 2273 |
); |
| 2274 |
|
| 2275 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $message, $matches); |
| 2276 |
|
| 2277 |
$tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 2278 |
|
| 2279 |
if (!empty($tagnames)) { |
| 2280 |
|
| 2281 |
$pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames); |
| 2282 |
|
| 2283 |
preg_match_all("/$pattern/", $message, $shortcodes); |
| 2284 |
foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 2285 |
$shortcode = array(); |
| 2286 |
$shortcode[1] = $shortcodes[1][$key]; |
| 2287 |
$shortcode[2] = $shortcodes[2][$key]; |
| 2288 |
$shortcode[3] = $shortcodes[3][$key]; |
| 2289 |
$shortcode[4] = $shortcodes[4][$key]; |
| 2290 |
$shortcode[5] = $shortcodes[5][$key]; |
| 2291 |
$shortcode[6] = $shortcodes[6][$key]; |
| 2292 |
|
| 2293 |
$atts = shortcode_parse_atts($shortcode[3]); |
| 2294 |
|
| 2295 |
$file = false; |
| 2296 |
|
| 2297 |
if (!isset($atts['dataset']) && isset($atts['id'])) { |
| 2298 |
$template = new Model_E2pdf_Template(); |
| 2299 |
$template->load($atts['id']); |
| 2300 |
if ($template->get('extension') === 'forminator') { |
| 2301 |
$entry_id = $this->get('dataset'); |
| 2302 |
if ($entry_id) { |
| 2303 |
if (($shortcode[2] === 'e2pdf-download' || $shortcode['2'] === 'e2pdf-view') && $entry_id == 'is_prevent_store') { |
| 2304 |
//data is empty to fill pdf |
| 2305 |
} else { |
| 2306 |
if ($entry_id == 'is_prevent_store') { |
| 2307 |
add_filter('e2pdf_model_shortcode_extension_options', array($this, 'filter_e2pdf_model_shortcode_extension_options'), 30, 2); |
| 2308 |
} |
| 2309 |
$atts['dataset'] = $entry_id; |
| 2310 |
$shortcode[3] .= " dataset=\"{$entry_id}\""; |
| 2311 |
} |
| 2312 |
} |
| 2313 |
} |
| 2314 |
} |
| 2315 |
|
| 2316 |
if (!isset($atts['apply'])) { |
| 2317 |
$shortcode[3] .= " apply=\"true\""; |
| 2318 |
} |
| 2319 |
|
| 2320 |
if (!isset($atts['filter'])) { |
| 2321 |
$shortcode[3] .= " filter=\"true\""; |
| 2322 |
} |
| 2323 |
|
| 2324 |
if (($shortcode[2] === 'e2pdf-save' && isset($atts['attachment']) && $atts['attachment'] == 'true') || $shortcode[2] === 'e2pdf-attachment') { |
| 2325 |
$file = do_shortcode_tag($shortcode); |
| 2326 |
if ($file) { |
| 2327 |
if ($shortcode[2] != 'e2pdf-save' && !isset($atts['pdf'])) { |
| 2328 |
$this->helper->add('forminator_attachments', $file); |
| 2329 |
} |
| 2330 |
$this->helper->add('forminator_mail_attachments', $file); |
| 2331 |
} |
| 2332 |
$message = str_replace($shortcode_value, '', $message); |
| 2333 |
} else { |
| 2334 |
$message = str_replace($shortcode_value, do_shortcode_tag($shortcode), $message); |
| 2335 |
} |
| 2336 |
remove_filter('e2pdf_model_shortcode_extension_options', array($this, 'filter_e2pdf_model_shortcode_extension_options'), 30); |
| 2337 |
} |
| 2338 |
} |
| 2339 |
} |
| 2340 |
|
| 2341 |
return $message; |
| 2342 |
} |
| 2343 |
|
| 2344 |
public function filter_e2pdf_model_shortcode_extension_options($options = array(), $template) { |
| 2345 |
if ($this->get('dataset') && $this->get('dataset') == 'is_prevent_store') { |
| 2346 |
$options['field_data_array'] = $this->get('field_data_array'); |
| 2347 |
} |
| 2348 |
return $options; |
| 2349 |
} |
| 2350 |
|
| 2351 |
public function filter_forminator_custom_form_submit_response($response, $form_id) { |
| 2352 |
|
| 2353 |
if (isset($response['message']) && false !== strpos($response['message'], '[') && isset($response['success']) && $response['success']) { |
| 2354 |
$shortcode_tags = array( |
| 2355 |
'e2pdf-download', |
| 2356 |
'e2pdf-save', |
| 2357 |
'e2pdf-view', |
| 2358 |
'e2pdf-adobesign' |
| 2359 |
); |
| 2360 |
|
| 2361 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $response['message'], $matches); |
| 2362 |
|
| 2363 |
$tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 2364 |
|
| 2365 |
if (!empty($tagnames)) { |
| 2366 |
|
| 2367 |
$pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames); |
| 2368 |
|
| 2369 |
preg_match_all("/$pattern/", $response['message'], $shortcodes); |
| 2370 |
foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 2371 |
$shortcode = array(); |
| 2372 |
$shortcode[1] = $shortcodes[1][$key]; |
| 2373 |
$shortcode[2] = $shortcodes[2][$key]; |
| 2374 |
$shortcode[3] = $shortcodes[3][$key]; |
| 2375 |
$shortcode[4] = $shortcodes[4][$key]; |
| 2376 |
$shortcode[5] = $shortcodes[5][$key]; |
| 2377 |
$shortcode[6] = $shortcodes[6][$key]; |
| 2378 |
|
| 2379 |
$atts = shortcode_parse_atts($shortcode[3]); |
| 2380 |
|
| 2381 |
if (($shortcode[2] === 'e2pdf-save' && isset($atts['attachment']) && $atts['attachment'] == 'true') || $shortcode[2] === 'e2pdf-attachment') { |
| 2382 |
|
| 2383 |
} else { |
| 2384 |
if (!isset($atts['dataset']) && isset($atts['id'])) { |
| 2385 |
$template = new Model_E2pdf_Template(); |
| 2386 |
$template->load($atts['id']); |
| 2387 |
if ($template->get('extension') === 'forminator') { |
| 2388 |
$entry_id = $this->get('dataset'); |
| 2389 |
if ($entry_id) { |
| 2390 |
if (($shortcode[2] === 'e2pdf-download' || $shortcode['2'] === 'e2pdf-view') && $entry_id == 'is_prevent_store') { |
| 2391 |
//data is empty to fill pdf |
| 2392 |
} else { |
| 2393 |
if ($entry_id == 'is_prevent_store') { |
| 2394 |
add_filter('e2pdf_model_shortcode_extension_options', array($this, 'filter_e2pdf_model_shortcode_extension_options'), 30, 2); |
| 2395 |
} |
| 2396 |
$atts['dataset'] = $entry_id; |
| 2397 |
$shortcode[3] .= " dataset=\"{$entry_id}\""; |
| 2398 |
} |
| 2399 |
} |
| 2400 |
} |
| 2401 |
} |
| 2402 |
|
| 2403 |
if (!isset($atts['apply'])) { |
| 2404 |
$shortcode[3] .= " apply=\"true\""; |
| 2405 |
} |
| 2406 |
|
| 2407 |
if (!isset($atts['filter'])) { |
| 2408 |
$shortcode[3] .= " filter=\"true\""; |
| 2409 |
} |
| 2410 |
|
| 2411 |
$response['message'] = str_replace($shortcode_value, do_shortcode_tag($shortcode), $response['message']); |
| 2412 |
remove_filter('e2pdf_model_shortcode_extension_options', array($this, 'filter_e2pdf_model_shortcode_extension_options'), 30); |
| 2413 |
} |
| 2414 |
} |
| 2415 |
} |
| 2416 |
} |
| 2417 |
$this->set('dataset', false); |
| 2418 |
return $response; |
| 2419 |
} |
| 2420 |
|
| 2421 |
public function filter_wp_mail($args = array()) { |
| 2422 |
$files = $this->helper->get('forminator_mail_attachments'); |
| 2423 |
if (is_array($files) && !empty($files)) { |
| 2424 |
foreach ($files as $file) { |
| 2425 |
$args['attachments'][] = $file; |
| 2426 |
} |
| 2427 |
} |
| 2428 |
$wp_mail = array( |
| 2429 |
'to' => $args['to'], |
| 2430 |
'subject' => $args['subject'], |
| 2431 |
'message' => $args['message'], |
| 2432 |
'headers' => $args['headers'], |
| 2433 |
'attachments' => $args['attachments'], |
| 2434 |
); |
| 2435 |
|
| 2436 |
return $wp_mail; |
| 2437 |
} |
| 2438 |
|
| 2439 |
/** |
| 2440 |
* Get styles for generating Map Field function |
| 2441 |
* |
| 2442 |
* @return array - List of css files to load |
| 2443 |
*/ |
| 2444 |
public function styles() { |
| 2445 |
$styles = array(); |
| 2446 |
if (function_exists(forminator_plugin_url)) { |
| 2447 |
if (defined("FORMINATOR_VERSION")) { |
| 2448 |
$version = FORMINATOR_VERSION; |
| 2449 |
} else { |
| 2450 |
$version = '0'; |
| 2451 |
} |
| 2452 |
$styles = array( |
| 2453 |
forminator_plugin_url() . 'assets/css/front.min.css?v=' . $version, |
| 2454 |
plugins_url('css/extension/forminator.css?v=' . time(), $this->helper->get('plugin_file_path')) |
| 2455 |
); |
| 2456 |
} |
| 2457 |
return $styles; |
| 2458 |
} |
| 2459 |
|
| 2460 |
} |
| 2461 |
|