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