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