| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
if (!function_exists('fpropdf_custom_capitalize')) { |
| 8 |
|
| 9 |
function fpropdf_custom_capitalize($m) { |
| 10 |
$s = $m[1]; |
| 11 |
$s = function_exists('mb_strtoupper') ? mb_strtoupper($s) : strtoupper($s); |
| 12 |
return $s; |
| 13 |
} |
| 14 |
|
| 15 |
} |
| 16 |
|
| 17 |
if (!function_exists('fpropdf_is_number')) { |
| 18 |
|
| 19 |
function fpropdf_is_number($m) { |
| 20 |
if ($m === '' || ($m && preg_match('/[^0-9\.\,\-\s]+/', $m))) { |
| 21 |
return false; |
| 22 |
} |
| 23 |
return true; |
| 24 |
} |
| 25 |
|
| 26 |
} |
| 27 |
|
| 28 |
if (!function_exists('fpropdf_if_shortcode')) { |
| 29 |
|
| 30 |
function fpropdf_if_shortcode($string, $type = '', $val, $key, $this_field_key, $debug = false) { |
| 31 |
|
| 32 |
/* Prepare local/global shortcodes */ |
| 33 |
$updated_string = ''; |
| 34 |
if (false !== strpos($string, '[if')) { |
| 35 |
preg_match_all('/\[if(.*?)\](((?R)|.*?)+)\[\/if (.*?)\]/is', $string, $matches); |
| 36 |
if (isset($matches[0]) && !empty($matches[0])) { |
| 37 |
foreach ($matches[0] as $shortcode_key => $shortcode_value) { |
| 38 |
$atts = shortcode_parse_atts($shortcode_value); |
| 39 |
if (isset($atts[1])) { |
| 40 |
$value_to_compare = $atts[1]; |
| 41 |
if ($value_to_compare == $key . $type || $value_to_compare == $this_field_key . $type) { |
| 42 |
$updated_string .= $shortcode_value; |
| 43 |
} |
| 44 |
} |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
/* Check if local/global shortcodes exists */ |
| 50 |
if ($type) { |
| 51 |
if (!$updated_string) { |
| 52 |
return $val; |
| 53 |
} else { |
| 54 |
$string = $updated_string; |
| 55 |
} |
| 56 |
} else { |
| 57 |
if (!$updated_string) { |
| 58 |
return $string; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
/* Working with local/global shortcodes */ |
| 63 |
if (false !== strpos($string, '[if')) { |
| 64 |
preg_match_all('/\[if(.*?)\](((?R)|.*?)+)\[\/if (.*?)\]/is', $string, $matches); |
| 65 |
if (isset($matches[0]) && !empty($matches[0])) { |
| 66 |
foreach ($matches[0] as $shortcode_key => $shortcode_value) { |
| 67 |
|
| 68 |
/* Replace nested shortcodes */ |
| 69 |
preg_match_all('/\[if(.*?)\](((?R)|.*?)+)\[\/if (.*?)\]/is', $shortcode_value, $sub_matches); |
| 70 |
if (isset($sub_matches[2]) && !empty($sub_matches[2])) { |
| 71 |
foreach ($sub_matches[2] as $sub_string) { |
| 72 |
if (false !== strpos($sub_string, '[if')) { |
| 73 |
$string = str_replace($sub_string, fpropdf_if_shortcode($sub_string, $type, $val, $key, $this_field_key), $string); |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
/* Replace if conditions */ |
| 79 |
preg_match_all('@\[(if\s+[^<>&/\[\]\x00-\x20=]++)@', $string, $value_matches); |
| 80 |
if (isset($value_matches[1]) && !empty($value_matches[1])) { |
| 81 |
$pattern = get_shortcode_regex($value_matches[1]); |
| 82 |
preg_match_all("/$pattern/", $string, $shortcodes); |
| 83 |
foreach ($shortcodes[0] as $shortcode_key => $sub_shortcode_value) { |
| 84 |
$shortcode = array(); |
| 85 |
$shortcode[1] = $shortcodes[1][$shortcode_key]; |
| 86 |
$shortcode[2] = $shortcodes[2][$shortcode_key]; |
| 87 |
$shortcode[3] = $shortcodes[3][$shortcode_key]; |
| 88 |
$shortcode[4] = $shortcodes[4][$shortcode_key]; |
| 89 |
$shortcode[5] = $shortcodes[5][$shortcode_key]; |
| 90 |
$shortcode[6] = $shortcodes[6][$shortcode_key]; |
| 91 |
|
| 92 |
$atts = shortcode_parse_atts($shortcode[3]); |
| 93 |
|
| 94 |
$value_to_compare = trim(str_replace('if', '', $shortcode[2])); |
| 95 |
|
| 96 |
if ($value_to_compare == $key . $type || $value_to_compare == $this_field_key . $type) { |
| 97 |
|
| 98 |
$value_to_compare = $val; |
| 99 |
|
| 100 |
if ($type) { |
| 101 |
$shortcode[5] = str_replace('[' . str_replace(':', '', $type) . ']', $val, $shortcode[5]); |
| 102 |
} |
| 103 |
|
| 104 |
if (isset($atts['equals']) && $value_to_compare === $atts['equals']) { |
| 105 |
$string = str_replace($sub_shortcode_value, $shortcode['5'], $string); |
| 106 |
} elseif (isset($atts['not_equal']) && $value_to_compare !== $atts['not_equal']) { |
| 107 |
$string = str_replace($sub_shortcode_value, $shortcode['5'], $string); |
| 108 |
} elseif (isset($atts['like']) && stripos($value_to_compare, $atts['like']) !== false) { |
| 109 |
$string = str_replace($sub_shortcode_value, $shortcode['5'], $string); |
| 110 |
} elseif (isset($atts['not_like']) && stripos($value_to_compare, $atts['not_like']) === false) { |
| 111 |
$string = str_replace($sub_shortcode_value, $shortcode['5'], $string); |
| 112 |
} elseif (isset($atts['greater_than']) && $value_to_compare > $atts['greater_than']) { |
| 113 |
$string = str_replace($sub_shortcode_value, $shortcode['5'], $string); |
| 114 |
} elseif (isset($atts['less_than']) && $value_to_compare < $atts['less_than']) { |
| 115 |
$string = str_replace($sub_shortcode_value, $shortcode['5'], $string); |
| 116 |
} else { |
| 117 |
$string = str_replace($sub_shortcode_value, '', $string); |
| 118 |
} |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
} |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
return $string; |
| 127 |
} |
| 128 |
|
| 129 |
} |
| 130 |
|
| 131 |
if (!function_exists('fpropdf_format_field')) { |
| 132 |
|
| 133 |
function fpropdf_format_field($v, $_format, $level = 0) { |
| 134 |
|
| 135 |
if ($level > 1) { |
| 136 |
return $v; |
| 137 |
} |
| 138 |
|
| 139 |
global $currentLayout; |
| 140 |
|
| 141 |
$key = $_format[0]; |
| 142 |
$format = $_format[1]; |
| 143 |
|
| 144 |
if ($format != 'repeatable' && $format != 'repeatable2') { |
| 145 |
$fieldId = false; |
| 146 |
foreach ($currentLayout['data'] as $__v) { |
| 147 |
if ($__v[1] == $key) { |
| 148 |
$fieldId = $__v[0]; |
| 149 |
global $wpdb; |
| 150 |
$row2 = $wpdb->get_row( |
| 151 |
$wpdb->prepare( |
| 152 |
'SELECT * FROM `' . $wpdb->prefix . 'frm_fields` WHERE `id` = %d', intval(fpropdf_field_key_to_id($fieldId)) |
| 153 |
), ARRAY_A |
| 154 |
); |
| 155 |
if ($row2) { |
| 156 |
$field_options = @unserialize($row2['field_options']); |
| 157 |
if ($row2['type'] === 'select' && array_key_exists('multiple', $field_options) && $field_options['multiple'] === '1') { |
| 158 |
$_tmp = @unserialize($v); |
| 159 |
if ($_tmp && is_array($_tmp) && count($_tmp)) { |
| 160 |
$v = implode(', ', $_tmp); |
| 161 |
} |
| 162 |
} |
| 163 |
} |
| 164 |
} |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
if ($format == 'html') { |
| 169 |
$v = strip_tags($v . ''); |
| 170 |
$format = 'removeEmptyLines'; |
| 171 |
} |
| 172 |
|
| 173 |
$additional = apply_filters('fpropdf_additional_formatting', array()); |
| 174 |
foreach ($additional as $title => $callback) { |
| 175 |
if (!function_exists($callback) && !is_callable($callback)) { |
| 176 |
continue; |
| 177 |
} |
| 178 |
if ($format != $title) { |
| 179 |
continue; |
| 180 |
} |
| 181 |
$v = call_user_func($callback, $v); |
| 182 |
} |
| 183 |
|
| 184 |
switch ($format) { |
| 185 |
case 'number_f1': |
| 186 |
if (fpropdf_is_number($v)) { |
| 187 |
$v = number_format((float) $v, 2, '.', ','); |
| 188 |
} else { |
| 189 |
$v = ''; |
| 190 |
} |
| 191 |
break; |
| 192 |
case 'number_f2': |
| 193 |
if (fpropdf_is_number($v)) { |
| 194 |
$v = number_format((float) $v, 2, ',', '.'); |
| 195 |
} else { |
| 196 |
$v = ''; |
| 197 |
} |
| 198 |
break; |
| 199 |
case 'number_f3': |
| 200 |
if (fpropdf_is_number($v)) { |
| 201 |
$v = number_format((float) $v, 2, '.', ' '); |
| 202 |
} else { |
| 203 |
$v = ''; |
| 204 |
} |
| 205 |
break; |
| 206 |
case 'number_f4': |
| 207 |
if (fpropdf_is_number($v)) { |
| 208 |
$v = number_format((float) $v, 2, ',', ' '); |
| 209 |
} else { |
| 210 |
$v = ''; |
| 211 |
} |
| 212 |
break; |
| 213 |
case 'number_f5': |
| 214 |
if (fpropdf_is_number($v)) { |
| 215 |
$v = number_format((float) $v, 0, '.', ','); |
| 216 |
} else { |
| 217 |
$v = ''; |
| 218 |
} |
| 219 |
break; |
| 220 |
case 'number_f6': |
| 221 |
if (fpropdf_is_number($v)) { |
| 222 |
$v = number_format((float) $v, 0, '.', '.'); |
| 223 |
} else { |
| 224 |
$v = ''; |
| 225 |
} |
| 226 |
break; |
| 227 |
case 'number_f7': |
| 228 |
if (fpropdf_is_number($v)) { |
| 229 |
$v = number_format((float) $v, 0, '.', ' '); |
| 230 |
} else { |
| 231 |
$v = ''; |
| 232 |
} |
| 233 |
break; |
| 234 |
case 'number_f8': |
| 235 |
if (fpropdf_is_number($v)) { |
| 236 |
$v = number_format((float) $v, 2, ',', ''); |
| 237 |
} else { |
| 238 |
$v = ''; |
| 239 |
} |
| 240 |
break; |
| 241 |
case 'number_f9': |
| 242 |
if (fpropdf_is_number($v)) { |
| 243 |
$v = number_format((float) $v, 2, ', ', '. '); |
| 244 |
} else { |
| 245 |
$v = ''; |
| 246 |
} |
| 247 |
break; |
| 248 |
case 'number_f10': |
| 249 |
if (fpropdf_is_number($v)) { |
| 250 |
$v = number_format((float) $v, 2, '. ', ', '); |
| 251 |
} else { |
| 252 |
$v = ''; |
| 253 |
} |
| 254 |
break; |
| 255 |
case 'number_f11': |
| 256 |
if (fpropdf_is_number($v)) { |
| 257 |
$v = number_format((float) $v, 0, '.', ''); |
| 258 |
} else { |
| 259 |
$v = ''; |
| 260 |
} |
| 261 |
break; |
| 262 |
case 'number_f12': |
| 263 |
if (fpropdf_is_number($v)) { |
| 264 |
$v = number_format((float) $v, 2, '.', ''); |
| 265 |
} else { |
| 266 |
$v = ''; |
| 267 |
} |
| 268 |
break; |
| 269 |
case 'number_f13': |
| 270 |
$v = intval($v); |
| 271 |
break; |
| 272 |
|
| 273 |
case 'removeEmptyLines': |
| 274 |
$v = $v . ''; |
| 275 |
$v = explode("\n", $v); |
| 276 |
foreach ($v as $_k => $_v) { |
| 277 |
$_v = str_replace("\r", '', $_v); |
| 278 |
$_v = preg_replace('/(^\s+)|(\s+$)/us', '', $_v); |
| 279 |
if (strlen($_v)) { |
| 280 |
$v[$_k] = $_v; |
| 281 |
} else { |
| 282 |
unset($v[$_k]); |
| 283 |
} |
| 284 |
} |
| 285 |
$v = array_values($v); |
| 286 |
$v = implode("\n", $v); |
| 287 |
break; |
| 288 |
|
| 289 |
case 'label': |
| 290 |
$fieldId = false; |
| 291 |
foreach ($currentLayout['data'] as $__v) { |
| 292 |
if ($__v[1] == $key) { |
| 293 |
|
| 294 |
$fieldId = $__v[0]; |
| 295 |
global $wpdb; |
| 296 |
|
| 297 |
$row2 = $wpdb->get_row( |
| 298 |
$wpdb->prepare( |
| 299 |
'SELECT * FROM `' . $wpdb->prefix . 'frm_fields` WHERE `id` = %d', intval(fpropdf_field_key_to_id($fieldId)) |
| 300 |
), ARRAY_A |
| 301 |
); |
| 302 |
|
| 303 |
if ($row2) { |
| 304 |
if (in_array($row2['type'], explode(' ', 'select checkbox radio'), true)) { |
| 305 |
$opts = @unserialize($row2['options']); |
| 306 |
foreach ($opts as $_v) { |
| 307 |
if (!is_array($v)) { |
| 308 |
if (isset($_v['value']) && $_v['value'] == $v) { |
| 309 |
$v = $_v['label']; |
| 310 |
break; |
| 311 |
} |
| 312 |
} else { |
| 313 |
foreach ($v as $v_k => $v_v) { |
| 314 |
if (isset($_v['value']) && $_v['value'] == $v_v) { |
| 315 |
$v[$v_k] = $_v['label']; |
| 316 |
} |
| 317 |
} |
| 318 |
} |
| 319 |
} |
| 320 |
} |
| 321 |
} |
| 322 |
} |
| 323 |
} |
| 324 |
|
| 325 |
if (is_array($v)) { |
| 326 |
$_opts = isset($_format[3]) ? @json_decode($_format[3]) : array(); |
| 327 |
if ($_opts && is_array($_opts) && count($_opts)) { |
| 328 |
foreach ($v as $_k => $_v) { |
| 329 |
if (!in_array($_v, $_opts)) { |
| 330 |
unset($v[$_k]); |
| 331 |
} |
| 332 |
} |
| 333 |
} |
| 334 |
} else { |
| 335 |
$v = str_replace("\r", '', $v); |
| 336 |
} |
| 337 |
|
| 338 |
break; |
| 339 |
|
| 340 |
case 'signature': |
| 341 |
global $fpropdfSignatures; |
| 342 |
if (!$fpropdfSignatures) { |
| 343 |
$fpropdfSignatures = array(); |
| 344 |
} |
| 345 |
|
| 346 |
$v = @unserialize($v); |
| 347 |
if (isset($v['typed']) && !isset($v['output']) && is_serialized($v['typed'])) { |
| 348 |
$v['output'] = $v['typed']; |
| 349 |
} |
| 350 |
|
| 351 |
if (isset($v['content']) && isset($v['format']) && $v['format'] == 'drawn') { |
| 352 |
$uploads = wp_upload_dir(); |
| 353 |
$target_path = $uploads['basedir'] . '/'; |
| 354 |
$target_path .= apply_filters('frm_sig_upload_folder', 'formidable/signatures'); |
| 355 |
$target_path = untrailingslashit($target_path); |
| 356 |
$file = $target_path . '/' . $v['content']; |
| 357 |
|
| 358 |
if (file_exists($file)) { |
| 359 |
$v = base64_encode(file_get_contents($file)); |
| 360 |
} |
| 361 |
} elseif (isset($v['content']) && isset($v['format']) && $v['format'] == 'typed') { |
| 362 |
$v['typed'] = $v['content']; |
| 363 |
} |
| 364 |
|
| 365 |
$v = apply_filters('fpro2pdf_signature', $v, $key, isset($_POST['wpfx_dataset']) ? intval($_POST['wpfx_dataset']) : 0); |
| 366 |
|
| 367 |
if (is_array($v)) { |
| 368 |
$options = array(); |
| 369 |
$options = apply_filters('fpro2pdf_sig_output_options', $options, $key); |
| 370 |
$v['options'] = $options; |
| 371 |
} |
| 372 |
|
| 373 |
$v = @serialize($v); |
| 374 |
|
| 375 |
$fpropdfSignatures[] = array( |
| 376 |
'data' => $v, |
| 377 |
'alignment' => isset($_format[4]) ? $_format[4] : 'top_left', |
| 378 |
'rotation' => isset($_format[7]) ? $_format[7] : '0', |
| 379 |
'field' => $key, |
| 380 |
); |
| 381 |
|
| 382 |
$v = ''; |
| 383 |
break; |
| 384 |
|
| 385 |
case 'curDate': |
| 386 |
$v = date('m/d/y'); |
| 387 |
break; |
| 388 |
|
| 389 |
case 'curDate2': |
| 390 |
$v = date('d/m/Y'); |
| 391 |
break; |
| 392 |
|
| 393 |
case 'curDate3': |
| 394 |
$v = date('m/d/Y'); |
| 395 |
break; |
| 396 |
|
| 397 |
case 'curDate4': |
| 398 |
$v = date('Y/m/d'); |
| 399 |
break; |
| 400 |
|
| 401 |
case 'curDate5': |
| 402 |
$v = date('d-m-Y'); |
| 403 |
break; |
| 404 |
|
| 405 |
case 'curDate6': |
| 406 |
$v = date('d.m.Y'); |
| 407 |
break; |
| 408 |
|
| 409 |
case 'curDate7': |
| 410 |
$v = date_i18n('j. F Y', time()); |
| 411 |
break; |
| 412 |
|
| 413 |
case 'curDate8': |
| 414 |
$v = date('d/m/y'); |
| 415 |
break; |
| 416 |
|
| 417 |
case 'repeatable': |
| 418 |
case 'repeatable2': |
| 419 |
$v = @unserialize($v); |
| 420 |
$vals = array(); |
| 421 |
try { |
| 422 |
if (!$v || !is_array($v)) { |
| 423 |
throw new Exception('Not an array'); |
| 424 |
} |
| 425 |
|
| 426 |
foreach ($v as $id) { |
| 427 |
$string = isset($_format[2]) ? $_format[2] : ''; |
| 428 |
|
| 429 |
global $wpdb; |
| 430 |
$rows = $wpdb->get_results( |
| 431 |
$wpdb->prepare( |
| 432 |
'SELECT * FROM `' . $wpdb->prefix . 'frm_item_metas` WHERE `item_id` = %d', intval($id) |
| 433 |
), ARRAY_A |
| 434 |
); |
| 435 |
if (!$rows) { |
| 436 |
$rows = array(); |
| 437 |
} |
| 438 |
foreach ($rows as $row) { |
| 439 |
$key = $row['field_id']; |
| 440 |
$this_field_key = 'unknown_field_key'; |
| 441 |
$val = $row['meta_value']; |
| 442 |
$val_label = $val; |
| 443 |
$address_labels = array(); |
| 444 |
$credit_card_labels = array(); |
| 445 |
|
| 446 |
$_tmp = @unserialize($val_label); |
| 447 |
if ($_tmp && is_array($_tmp) && count($_tmp)) { |
| 448 |
$val_label = implode(', ', $_tmp); |
| 449 |
} |
| 450 |
|
| 451 |
$row2 = $wpdb->get_row( |
| 452 |
$wpdb->prepare( |
| 453 |
'SELECT * FROM `' . $wpdb->prefix . 'frm_fields` WHERE `id` = %d', intval($key) |
| 454 |
), ARRAY_A |
| 455 |
); |
| 456 |
|
| 457 |
if ($row2) { |
| 458 |
$this_field_key = $row2['field_key']; |
| 459 |
if ($row2['type'] === 'select' || $row2['type'] === 'radio') { |
| 460 |
$opts = @unserialize($row2['options']); |
| 461 |
foreach ($opts as $v) { |
| 462 |
if ($v['value'] == $val) { |
| 463 |
$val_label = $v['label']; |
| 464 |
$_tmp = @unserialize($val_label); |
| 465 |
if ($_tmp && is_array($_tmp) && count($_tmp)) { |
| 466 |
$val_label = $_tmp[0]; |
| 467 |
} |
| 468 |
} |
| 469 |
} |
| 470 |
} elseif ($row2['type'] === 'checkbox') { |
| 471 |
$opts = @unserialize($row2['options']); |
| 472 |
$_tmp = @unserialize($val); |
| 473 |
$labels = array(); |
| 474 |
foreach ($opts as $v) { |
| 475 |
if (is_array($_tmp)) { |
| 476 |
if (in_array($v['value'], $_tmp)) { |
| 477 |
$labels[] = $v['label']; |
| 478 |
} |
| 479 |
} else { |
| 480 |
if ($v['value'] === $val) { |
| 481 |
$labels[] = $v['label']; |
| 482 |
} |
| 483 |
} |
| 484 |
} |
| 485 |
if (is_array($labels)) { |
| 486 |
foreach ($labels as $label_key => $label_value) { |
| 487 |
/* Apply if conditions for label */ |
| 488 |
$formatted_label = fpropdf_if_shortcode($string, ':label', $label_value, $key, $this_field_key); |
| 489 |
if ($formatted_label) { |
| 490 |
$labels[$label_key] = $formatted_label; |
| 491 |
} else { |
| 492 |
unset($labels[$label_key]); |
| 493 |
} |
| 494 |
} |
| 495 |
$val_label = implode(', ', $labels); |
| 496 |
} |
| 497 |
} elseif ($row2['type'] === 'address') { |
| 498 |
$_tmp = @unserialize($val); |
| 499 |
if (is_array($_tmp)) { |
| 500 |
$address_labels = $_tmp; |
| 501 |
$val = implode(' ', $address_labels); |
| 502 |
} |
| 503 |
} elseif ($row2['type'] === 'credit_card') { |
| 504 |
$_tmp = @unserialize($val); |
| 505 |
if (is_array($_tmp)) { |
| 506 |
$credit_card_labels = $_tmp; |
| 507 |
$val = implode(' ', $credit_card_labels); |
| 508 |
} |
| 509 |
} |
| 510 |
|
| 511 |
$field_options = @unserialize($row2['field_options']); |
| 512 |
if ($row2['type'] === 'select' && array_key_exists('multiple', $field_options) && $field_options['multiple'] === '1') { |
| 513 |
$_tmp = @unserialize($val); |
| 514 |
if ($_tmp && is_array($_tmp) && count($_tmp)) { |
| 515 |
/* Apply if conditions for values */ |
| 516 |
foreach ($_tmp as $_tmp_key => $_tmp_value) { |
| 517 |
$formatted_tmp = fpropdf_if_shortcode($string, ':value', $_tmp_value, $key, $this_field_key); |
| 518 |
if ($formatted_tmp) { |
| 519 |
$_tmp[$_tmp_key] = $formatted_tmp; |
| 520 |
} else { |
| 521 |
unset($_tmp[$_tmp_key]); |
| 522 |
} |
| 523 |
} |
| 524 |
|
| 525 |
$val = implode(', ', $_tmp); |
| 526 |
} elseif ($val) { |
| 527 |
$val = fpropdf_if_shortcode($string, ':value', $val, $key, $this_field_key); |
| 528 |
} |
| 529 |
} |
| 530 |
|
| 531 |
if ($row2['type'] === 'checkbox') { |
| 532 |
$_tmp = @unserialize($val); |
| 533 |
if ($_tmp && is_array($_tmp) && count($_tmp)) { |
| 534 |
/* Apply if conditions for values */ |
| 535 |
foreach ($_tmp as $_tmp_key => $_tmp_value) { |
| 536 |
$formatted_tmp = fpropdf_if_shortcode($string, ':value', $_tmp_value, $key, $this_field_key, true); |
| 537 |
if ($formatted_tmp) { |
| 538 |
$_tmp[$_tmp_key] = $formatted_tmp; |
| 539 |
} else { |
| 540 |
unset($_tmp[$_tmp_key]); |
| 541 |
} |
| 542 |
} |
| 543 |
$val = implode(', ', $_tmp); |
| 544 |
} elseif ($val) { |
| 545 |
$val = fpropdf_if_shortcode($string, ':value', $val, $key, $this_field_key); |
| 546 |
} |
| 547 |
} |
| 548 |
} |
| 549 |
|
| 550 |
/* Apply global if conditions */ |
| 551 |
$string = fpropdf_if_shortcode($string, '', $val, $key, $this_field_key); |
| 552 |
|
| 553 |
$string = str_replace(':Show label for checkbox/select/radio]', ':label]', $string); |
| 554 |
|
| 555 |
$string = str_replace('[' . $key . ']', $val, $string); |
| 556 |
$string = str_replace('[' . $key . ':label]', $val_label, $string); |
| 557 |
$string = str_replace('[' . $this_field_key . ']', $val, $string); |
| 558 |
$string = str_replace('[' . $this_field_key . ':label]', $val_label, $string); |
| 559 |
|
| 560 |
/* Render Address Field Vales */ |
| 561 |
foreach ($address_labels as $address_key => $address_label) { |
| 562 |
$string = str_replace('[' . $key . ':' . $address_key . ']', $address_label, $string); |
| 563 |
} |
| 564 |
|
| 565 |
/* Render Creadit Card Values */ |
| 566 |
foreach ($credit_card_labels as $credit_card_key => $credit_card_label) { |
| 567 |
$string = str_replace('[' . $key . ':' . $credit_card_key . ']', $credit_card_label, $string); |
| 568 |
} |
| 569 |
|
| 570 |
$_formats = array( |
| 571 |
'dd' => 'd', |
| 572 |
'mm' => 'm', |
| 573 |
'yyyy' => 'Y', |
| 574 |
'yy' => 'y', |
| 575 |
); |
| 576 |
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $val)) { |
| 577 |
foreach ($_formats as $format1 => $date1) { |
| 578 |
foreach ($_formats as $format2 => $date2) { |
| 579 |
foreach ($_formats as $format3 => $date3) { |
| 580 |
$f = $format1 . '/' . $format2 . '/' . $format3; |
| 581 |
$datef = $date1 . '/' . $date2 . '/' . $date3; |
| 582 |
$string = str_ireplace('[' . $key . ':' . $f . ']', date($datef, strtotime($val)), $string); |
| 583 |
$string = str_ireplace('[' . $this_field_key . ':' . $f . ']', date($datef, strtotime($val)), $string); |
| 584 |
} |
| 585 |
} |
| 586 |
} |
| 587 |
} |
| 588 |
|
| 589 |
$_formats = array( |
| 590 |
'none' => '(no formatting)', |
| 591 |
'tel' => 'Telephone', |
| 592 |
'address' => 'Address', |
| 593 |
'credit_card' => 'Credit Card', |
| 594 |
'date' => 'Date MM/DD/YY', |
| 595 |
'date2' => 'Date DD/MM/YYYY', |
| 596 |
'date3' => 'Date MM/DD/YYYY', |
| 597 |
'date4' => 'Date YYYY/MM/DD', |
| 598 |
'date5' => 'Date DD-MM-YYYY', |
| 599 |
'date6' => 'Date DD.MM.YYYY', |
| 600 |
'date7' => 'Date DD. month year', |
| 601 |
'date8' => 'Date DD/MM/YY', |
| 602 |
'capitalize' => 'Capitalize', |
| 603 |
'capitalizeAll' => 'CAPITALIZE ALL', |
| 604 |
'returnToComma' => 'Carriage return to comma', |
| 605 |
'returnToCarriage' => 'Comma to carriage return', |
| 606 |
'removeEmptyLines' => 'Remove empty lines in text', |
| 607 |
'html' => 'Remove HTML tags', |
| 608 |
'number_f1' => 'Number 1,000.00', |
| 609 |
'number_f2' => 'Number 1.000,00', |
| 610 |
'number_f3' => 'Number 1 000.00', |
| 611 |
'number_f4' => 'Number 1 000,00', |
| 612 |
'number_f5' => 'Number 1,000', |
| 613 |
'number_f6' => 'Number 1.000', |
| 614 |
'number_f7' => 'Number 1 000', |
| 615 |
'number_f8' => 'Number 1000,00', |
| 616 |
'number_f9' => 'Number 1. 000, 00', |
| 617 |
'number_f10' => 'Number 1, 000. 00', |
| 618 |
'number_f11' => 'Number 1000', |
| 619 |
'number_f12' => 'Number 1000.00', |
| 620 |
'number_f13' => 'Number Intval', |
| 621 |
'lowercase' => 'Lowercase', |
| 622 |
); |
| 623 |
|
| 624 |
foreach ($_formats as $format_key => $format_string) { |
| 625 |
$val_formatted = fpropdf_format_field($val, array($key, $format_key), $level + 1); |
| 626 |
$string = str_ireplace('[' . $key . ':' . $format_string . ']', $val_formatted, $string); |
| 627 |
$string = str_ireplace('[' . $this_field_key . ':' . $format_string . ']', $val_formatted, $string); |
| 628 |
} |
| 629 |
|
| 630 |
$_formats = array( |
| 631 |
'curDate' => 'Current Date MM/DD/YY', |
| 632 |
'curDate2' => 'Current Date DD/MM/YYYY', |
| 633 |
'curDate3' => 'Current Date MM/DD/YYYY', |
| 634 |
'curDate4' => 'Current Date YYYY/MM/DD', |
| 635 |
'curDate5' => 'Current Date DD-MM-YYYY', |
| 636 |
'curDate6' => 'Current Date DD.MM.YYYY', |
| 637 |
'curDate7' => 'Current Date DD. month year', |
| 638 |
'curDate8' => 'Current Date DD/MM/YY', |
| 639 |
); |
| 640 |
|
| 641 |
foreach ($_formats as $format_key => $format_string) { |
| 642 |
$val_formatted = fpropdf_format_field('', array($key, $format_key), $level + 1); |
| 643 |
$string = str_ireplace('[' . $format_string . ']', $val_formatted, $string); |
| 644 |
} |
| 645 |
} |
| 646 |
|
| 647 |
/* Remove unsued if conditions */ |
| 648 |
if (false !== strpos($string, '[if')) { |
| 649 |
preg_match_all('/\[if(.*?)\](((?R)|.*?)+)\[\/if (.*?)\]/is', $string, $matches); |
| 650 |
if (isset($matches[0]) && !empty($matches[0])) { |
| 651 |
foreach ($matches[0] as $shortcode_key => $shortcode_value) { |
| 652 |
$string = str_replace($shortcode_value, '', $string); |
| 653 |
} |
| 654 |
} |
| 655 |
} |
| 656 |
|
| 657 |
$vals[] = $string; |
| 658 |
} |
| 659 |
} catch (Exception $e) { |
| 660 |
$e->getMessage(); |
| 661 |
} |
| 662 |
|
| 663 |
foreach ($vals as $_k => $_v) { |
| 664 |
$_v = preg_replace('/\[[^\]]+?\]/', '', $_v); |
| 665 |
$_v = preg_replace('/\[[^\]\:]+\:[^\]]+\]/', '', $_v); |
| 666 |
$_v = str_replace("\r", '', $_v); |
| 667 |
$vals[$_k] = $_v; |
| 668 |
} |
| 669 |
|
| 670 |
if ($format == 'repeatable2') { |
| 671 |
|
| 672 |
$_opts = isset($_format[3]) ? @json_decode($_format[3]) : array(); |
| 673 |
if ($_opts && is_array($_opts) && count($_opts)) { |
| 674 |
foreach ($vals as $val_key => $vvals) { |
| 675 |
if (in_array($vvals, $_opts)) { |
| 676 |
continue; |
| 677 |
} |
| 678 |
$vals[$val_key] = ''; |
| 679 |
$vvals = explode(', ', $vvals); |
| 680 |
foreach ($vvals as $__k => $__v) { |
| 681 |
if (in_array($__v, $_opts)) { |
| 682 |
$vals[$val_key] = $__v; |
| 683 |
} |
| 684 |
} |
| 685 |
} |
| 686 |
} |
| 687 |
|
| 688 |
global $separateRepeatable; |
| 689 |
global $currentKey; |
| 690 |
if (!$separateRepeatable) { |
| 691 |
$separateRepeatable = array(); |
| 692 |
} |
| 693 |
$separateRepeatable[$currentKey] = $vals; |
| 694 |
$v = ''; |
| 695 |
} else { |
| 696 |
$v = implode('', $vals); |
| 697 |
} |
| 698 |
break; |
| 699 |
|
| 700 |
case 'tel': |
| 701 |
if (trim($v) !== '') { |
| 702 |
$v2 = preg_replace('/[^0-9]+/', '', $v); |
| 703 |
$v2 = intval($v2); |
| 704 |
$v2 = sprintf('%010d', $v2); |
| 705 |
if (preg_match('/(\d{3})(\d{3})(\d{4})$/', $v2, $matches)) { |
| 706 |
$v = $matches[1] . '-' . $matches[2] . '-' . $matches[3]; |
| 707 |
} |
| 708 |
} |
| 709 |
break; |
| 710 |
|
| 711 |
case 'address': |
| 712 |
$v = @unserialize($v); |
| 713 |
$string = isset($_format[5]) ? $_format[5] : ''; |
| 714 |
|
| 715 |
if (is_array($v)) { |
| 716 |
foreach ($v as $key => $val) { |
| 717 |
$string = str_replace('[' . $key . ']', $val, $string); |
| 718 |
} |
| 719 |
} |
| 720 |
/* for remove empty [] shorcode and line feed issue */ |
| 721 |
$string_array = preg_split("/[\n ]+/", $string); |
| 722 |
$text_inside = array(); |
| 723 |
foreach ($string_array as $key => $val) { |
| 724 |
$length = strlen($val); |
| 725 |
for ($i = 0; $i < $length; $i++) { |
| 726 |
if ($val[$i] == '[') { |
| 727 |
$t1 = ''; |
| 728 |
$i++; |
| 729 |
while ($val[$i] != ']') { |
| 730 |
$t1 .= $val[$i]; |
| 731 |
$i++; |
| 732 |
} |
| 733 |
if ($val != '') { |
| 734 |
unset($string_array[$key]); |
| 735 |
} |
| 736 |
} |
| 737 |
} |
| 738 |
} |
| 739 |
$string = implode(' ', $string_array); |
| 740 |
$v = $string; |
| 741 |
break; |
| 742 |
|
| 743 |
case 'credit_card': |
| 744 |
$v = @unserialize($v); |
| 745 |
$string = isset($_format[6]) ? $_format[6] : ''; |
| 746 |
|
| 747 |
if (is_array($v)) { |
| 748 |
foreach ($v as $key => $val) { |
| 749 |
$string = str_replace('[' . $key . ']', $val, $string); |
| 750 |
} |
| 751 |
} |
| 752 |
|
| 753 |
$v = $string; |
| 754 |
break; |
| 755 |
|
| 756 |
case 'date': |
| 757 |
if (preg_match('/^(\d{4})\-(\d{2})\-(\d{2})/', $v, $m)) { |
| 758 |
$v = $m[2] . '/' . $m[3] . '/' . substr($m[1], 2, 4); |
| 759 |
} |
| 760 |
break; |
| 761 |
|
| 762 |
case 'date2': |
| 763 |
if (preg_match('/^(\d{4})\-(\d{2})\-(\d{2})/', $v, $m)) { |
| 764 |
$v = $m[3] . '/' . $m[2] . '/' . $m[1]; |
| 765 |
} |
| 766 |
break; |
| 767 |
|
| 768 |
case 'date3': |
| 769 |
if (preg_match('/^(\d{4})\-(\d{2})\-(\d{2})/', $v, $m)) { |
| 770 |
$v = $m[2] . '/' . $m[3] . '/' . $m[1]; |
| 771 |
} |
| 772 |
break; |
| 773 |
|
| 774 |
case 'date4': |
| 775 |
if (preg_match('/^(\d{4})\-(\d{2})\-(\d{2})/', $v, $m)) { |
| 776 |
$v = $m[1] . '/' . $m[2] . '/' . $m[3]; |
| 777 |
} |
| 778 |
break; |
| 779 |
|
| 780 |
case 'date5': |
| 781 |
if (preg_match('/^(\d{4})\-(\d{2})\-(\d{2})/', $v, $m)) { |
| 782 |
$v = $m[3] . '-' . $m[2] . '-' . $m[1]; |
| 783 |
} |
| 784 |
break; |
| 785 |
|
| 786 |
case 'date6': |
| 787 |
if (preg_match('/^(\d{4})\-(\d{2})\-(\d{2})/', $v, $m)) { |
| 788 |
$v = $m[3] . '.' . $m[2] . '.' . $m[1]; |
| 789 |
} |
| 790 |
break; |
| 791 |
|
| 792 |
case 'date7': |
| 793 |
if (preg_match('/^(\d{4})\-(\d{2})\-(\d{2})/', $v, $m)) { |
| 794 |
$v = date_i18n('j. F Y', strtotime($m[1] . '-' . $m[2] . '-' . $m[3])); |
| 795 |
} |
| 796 |
break; |
| 797 |
|
| 798 |
case 'date8': |
| 799 |
if (preg_match('/^(\d{4})\-(\d{2})\-(\d{2})/', $v, $m)) { |
| 800 |
$v = $m[3] . '/' . $m[2] . '/' . substr($m[1], 2, 4); |
| 801 |
} |
| 802 |
break; |
| 803 |
|
| 804 |
case 'returnToComma': |
| 805 |
$v = str_replace("\r", '', $v); |
| 806 |
$v = str_replace("\n", ', ', $v); |
| 807 |
$v = preg_replace('/ +/', ' ', $v); |
| 808 |
$v = preg_replace('/\, +$/', '', $v); |
| 809 |
break; |
| 810 |
|
| 811 |
case 'returnToCarriage': |
| 812 |
$v = str_replace('', "\r", $v); |
| 813 |
$v = str_replace(', ', "\n", $v); |
| 814 |
$v = preg_replace('/ +/', ' ', $v); |
| 815 |
$v = preg_replace('/\, +$/', '', $v); |
| 816 |
break; |
| 817 |
|
| 818 |
case 'capitalize': |
| 819 |
$v = preg_replace_callback('/(^[a-z]| [a-z])/u', 'fpropdf_custom_capitalize', strtolower($v)); |
| 820 |
break; |
| 821 |
|
| 822 |
case 'capitalizeAll': |
| 823 |
$v = function_exists('mb_strtoupper') ? mb_strtoupper($v) : strtoupper($v); |
| 824 |
break; |
| 825 |
|
| 826 |
case 'lowercase': |
| 827 |
$v = function_exists('mb_strtolower') ? mb_strtolower($v) : strtolower($v); |
| 828 |
break; |
| 829 |
|
| 830 |
default: |
| 831 |
if (is_array($v)) { |
| 832 |
$_opts = isset($_format[3]) ? @json_decode($_format[3]) : array(); |
| 833 |
if ($_opts && is_array($_opts) && count($_opts)) { |
| 834 |
$_opts2 = str_replace('&', '&', $_opts); |
| 835 |
|
| 836 |
//3.04 Special Characters as ΓΌ fix for Checkbox due incorrect encoding |
| 837 |
$_opts3 = array(); |
| 838 |
foreach ($_opts2 as $_opts2_k => $_opts2_v) { |
| 839 |
if ($_opts2_v && is_string($_opts2_v)) { |
| 840 |
$_opts3[] = html_entity_decode($_opts2_v); |
| 841 |
} |
| 842 |
} |
| 843 |
|
| 844 |
foreach ($v as $_k => $_v) { |
| 845 |
if (!in_array($_v, $_opts) && !in_array($_v, $_opts2) && !in_array($_v, $_opts3)) { |
| 846 |
unset($v[$_k]); |
| 847 |
} |
| 848 |
} |
| 849 |
} |
| 850 |
} else { |
| 851 |
$v = str_replace("\r", '', $v); |
| 852 |
} |
| 853 |
break; |
| 854 |
} |
| 855 |
|
| 856 |
if (!is_array($v)) { |
| 857 |
if (preg_match('/^FPROPDF\_IMAGE\:(.*)$/', $v, $m)) { |
| 858 |
global $fpropdfSignatures; |
| 859 |
if (!$fpropdfSignatures) { |
| 860 |
$fpropdfSignatures = array(); |
| 861 |
} |
| 862 |
|
| 863 |
$fpropdfSignatures[] = array( |
| 864 |
'data' => serialize(base64_encode(file_get_contents(ABSPATH . $m[1]))), |
| 865 |
'field' => $key, |
| 866 |
'alignment' => isset($_format[4]) ? $_format[4] : 'top_left', |
| 867 |
'rotation' => isset($_format[7]) ? $_format[7] : '0', |
| 868 |
'is_file' => basename($m[1]), |
| 869 |
); |
| 870 |
|
| 871 |
$v = ''; |
| 872 |
} |
| 873 |
|
| 874 |
if (preg_match('/^FPROPDF\_IMAGE\_FIELD\:([^\:]+)\:([^\:]+)$/', $v, $m)) { |
| 875 |
global $fpropdfSignatures; |
| 876 |
if (!$fpropdfSignatures) { |
| 877 |
$fpropdfSignatures = array(); |
| 878 |
} |
| 879 |
|
| 880 |
$fpropdfSignatures[] = array( |
| 881 |
'data' => serialize($m[2]), |
| 882 |
'field' => $key, |
| 883 |
'alignment' => isset($_format[4]) ? $_format[4] : 'top_left', |
| 884 |
'rotation' => isset($_format[7]) ? $_format[7] : '0', |
| 885 |
'is_file' => $m[1], |
| 886 |
); |
| 887 |
|
| 888 |
$v = ''; |
| 889 |
} |
| 890 |
} |
| 891 |
return $v; |
| 892 |
} |
| 893 |
|
| 894 |
} |
| 895 |
|