PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.55
E2Pdf – Export Pdf Tool for WordPress v1.32.55
1.32.55 1.32.56 1.32.53 1.32.51 1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 All 76 releases
← All changes | classes/extension/e2pdf-formidable.php +2874 -1375 1.05.03 → 1.32.55 View file →
@@ -1,11 +1,10 @@
1 1 <?php
2 2
3 3 /**
4 - * E2pdf Formidable Extension
5 - *
4 + * E2Pdf Formidable Extension
6 5 * @copyright Copyright 2017 https://e2pdf.com
7 - * @license GPL v2
6 + * @license GPLv3
8 7 * @version 1
9 8 * @link https://e2pdf.com
10 9 * @since 0.00.01
11 10 */
@@ -17,20 +16,14 @@
17 16
18 17 private $options;
19 18 private $info = array(
20 19 'key' => 'formidable',
21 - 'title' => 'Formidable Forms'
20 + 'title' => 'Formidable Forms',
22 21 );
23 22
24 - function __construct() {
25 - parent::__construct();
26 - }
27 -
28 23 /**
29 24 * Get info about extension
30 - *
31 25 * @param string $key - Key to get assigned extension info value
32 - *
33 26 * @return array|string - Extension Key and Title or Assigned extension info value
34 27 */
35 28 public function info($key = false) {
36 29 if ($key && isset($this->info[$key])) {
@@ -36,9 +29,9 @@
36 29 if ($key && isset($this->info[$key])) {
37 30 return $this->info[$key];
38 31 } else {
39 32 return array(
40 - $this->info['key'] => $this->info['title']
33 + $this->info['key'] => $this->info['title'],
41 34 );
42 35 }
43 36 }
44 37
@@ -43,18 +36,12 @@
43 36 }
44 37
45 38 /**
46 39 * Check if needed plugin active
47 - *
48 40 * @return bool - Activated/Not Activated plugin
49 41 */
50 42 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')) {
43 + if (defined('E2PDF_FORMIDABLE_EXTENSION') || $this->helper->load('extension')->is_plugin_active('formidable/formidable.php')) {
57 44 return true;
58 45 }
59 46 return false;
60 47 }
@@ -60,192 +47,246 @@
60 47 }
61 48
62 49 /**
63 50 * Set option
64 - *
65 51 * @param string $key - Key of option
66 52 * @param string $value - Value of option
67 - *
68 53 * @return bool - Status of setting option
69 54 */
70 55 public function set($key, $value) {
71 -
72 56 if (!isset($this->options)) {
73 57 $this->options = new stdClass();
74 58 }
75 -
76 59 $this->options->$key = $value;
60 + switch ($key) {
61 + case 'item':
62 + $this->set('cached_form', false);
63 + if ($this->get('item') && $this->get('item') != '-2' && class_exists('FrmForm')) {
64 + $form = FrmForm::getOne($this->get('item'));
65 + if (isset($form->id)) {
66 + $this->set('cached_form', $form);
67 + }
68 + }
69 + break;
70 + case 'item1':
71 + $this->set('cached_form', false);
72 + if ($this->get('item1') && class_exists('FrmForm')) {
73 + $form = FrmForm::getOne($this->get('item1'));
74 + if (isset($form->id)) {
75 + $this->set('cached_form', $form);
76 + }
77 + }
78 + break;
79 + case 'item2':
80 + $this->set('cached_form2', false);
81 + if ($this->get('item2') && class_exists('FrmForm')) {
82 + $form = FrmForm::getOne($this->get('item2'));
83 + if (isset($form->id)) {
84 + $this->set('cached_form2', $form);
85 + }
86 + }
87 + break;
88 + case 'dataset':
89 + $this->set('cached_entry', false);
90 + if ($this->get('cached_form') && $this->get('dataset') && class_exists('FrmEntry')) {
91 + if (substr($this->get('dataset'), 0, 4) === 'tmp_') {
92 + $this->set('cached_entry', get_transient('e2pdf_' . $this->get('dataset')));
93 + } else {
94 + $entry = FrmEntry::getOne($this->get('dataset'));
95 + if ($entry && isset($entry->form_id) && $entry->form_id == $this->get('cached_form')->id) {
96 + if (!empty($entry->parent_item_id)) {
97 + $parent_entry = FrmEntry::getOne($entry->parent_item_id);
98 + if ($parent_entry && isset($parent_entry->form_id)) {
99 + $entry->parent_entry = $parent_entry;
100 + }
101 + }
102 + $this->set('cached_entry', $entry);
103 + }
104 + }
105 + }
106 + break;
107 + case 'dataset2':
108 + if ($this->get('cached_form2') && $this->get('dataset2') && class_exists('FrmEntry')) {
109 + $entry = FrmEntry::getOne($this->get('dataset2'));
110 + if ($entry && isset($entry->form_id) && $entry->form_id == $this->get('cached_form2')->id) {
111 + if (!empty($entry->parent_item_id)) {
112 + $parent_entry = FrmEntry::getOne($entry->parent_item_id);
113 + if ($parent_entry && isset($parent_entry->form_id)) {
114 + $entry->parent_entry = $parent_entry;
115 + }
116 + }
117 + $this->set('cached_entry2', $entry);
118 + }
119 + }
120 + break;
121 + default:
122 + break;
123 + }
77 124 return true;
78 125 }
79 126
80 127 /**
81 128 * Get option by key
82 - *
83 129 * @param string $key - Key to get assigned option value
84 - *
85 130 * @return mixed
86 131 */
87 132 public function get($key) {
88 -
89 133 if (isset($this->options->$key)) {
90 134 $value = $this->options->$key;
91 - return $value;
92 135 } else {
93 - return false;
136 + switch ($key) {
137 + case 'args':
138 + $value = array();
139 + break;
140 + default:
141 + $value = false;
142 + break;
143 + }
94 144 }
145 + return $value;
95 146 }
96 147
97 148 /**
98 149 * Get items to work with
99 - *
100 150 * @return array() - List of available items
101 151 */
102 152 public function items() {
103 -
104 - $content = array();
105 -
153 + $items = array();
106 154 if (class_exists('FrmForm')) {
107 155 $where = array(
108 156 'is_template' => 0,
109 - 'status' => 'published'
157 + 'status' => 'published',
110 158 );
111 -
112 159 $forms = FrmForm::getAll($where, 'name');
113 160 if ($forms) {
114 - foreach ($forms as $key => $value) {
115 - $content[] = $this->item($value->id);
161 + foreach ($forms as $key => $form) {
162 + $items[] = $this->item($form->id);
116 163 }
117 164 }
118 165 }
119 -
120 - return $content;
166 + return $items;
121 167 }
122 168
123 169 /**
124 170 * Get entries for export
125 - *
126 171 * @param int $item - Form ID
127 172 * @param string $name - Entries names
128 - *
129 173 * @return array() - Entries list
130 174 */
131 - public function datasets($item = false, $name = false) {
132 -
133 - $item = (int) $item;
175 + public function datasets($item_id = false, $name = false) {
176 + $item_id = (int) $item_id;
134 177 $datasets = array();
135 -
136 - if (class_exists('FrmEntry') && $item) {
178 + if (class_exists('FrmEntry') && $item_id) {
137 179 $where = array(
138 - 'it.form_id' => $item
180 + 'it.form_id' => $item_id,
139 181 );
140 -
141 - $datasets_tmp = FrmEntry::getAll($where, ' ORDER BY id DESC');
142 -
143 - if ($datasets_tmp) {
144 - foreach ($datasets_tmp as $key => $dataset) {
145 - $this->set('item', $item);
146 - $this->set('dataset', $dataset->id);
147 -
148 - $dataset_title = $this->render($name);
149 - if (!$dataset_title) {
150 - $dataset_title = $dataset->item_key;
182 + $entries = FrmEntry::getAll($where, ' ORDER BY id DESC');
183 + if ($entries) {
184 + $this->set('item', $item_id);
185 + if (class_exists('FrmFieldsHelper') && class_exists('FrmFormsController') && method_exists('FrmFormsController', 'replace_form_name_shortcodes')) {
186 + $this->set('cached_shortcodes', FrmFieldsHelper::get_shortcodes($name, $item_id));
187 + }
188 + foreach ($entries as $key => $entry) {
189 + $this->set('dataset', $entry->id);
190 + $entry_title = $this->render($name);
191 + if (!$entry_title) {
192 + $entry_title = $entry->item_key;
151 193 }
152 194 $datasets[] = array(
153 - 'key' => $dataset->id,
154 - 'value' => $dataset_title
195 + 'key' => $entry->id,
196 + 'value' => $entry_title,
155 197 );
156 198 }
199 + $this->set('cached_shortcodes', false);
157 200 }
158 201 }
159 -
160 -
161 202 return $datasets;
162 203 }
163 204
164 205 /**
165 - * Get dataset
166 - *
167 - * @param int $dataset - Dataset ID
168 - *
169 - * @return object - Dataset
206 + * Get Dataset Actions
207 + * @param int $dataset_id - Dataset ID
208 + * @return object
170 209 */
171 - public function dataset($dataset = false) {
172 -
173 - $dataset = (int) $dataset;
174 -
175 - if (!$dataset) {
210 + public function get_dataset_actions($dataset_id = false) {
211 + $dataset_id = (int) $dataset_id;
212 + if (!$dataset_id) {
176 213 return false;
177 214 }
215 + $actions = new stdClass();
216 + $actions->view = $this->helper->get_url(
217 + array(
218 + 'page' => 'formidable-entries',
219 + 'frm_action' => 'show',
220 + 'id' => $dataset_id,
221 + )
222 + );
223 + $actions->delete = false;
224 + return $actions;
225 + }
178 226
179 - $data = new stdClass();
180 - $data->url = $this->helper->get_url(array('page' => 'formidable-entries', 'frm_action' => 'show', 'id' => $dataset));
181 -
182 - return $data;
227 + /**
228 + * Get Template Actions
229 + * @param int $template - Template ID
230 + * @return object
231 + */
232 + public function get_template_actions($template = false) {
233 + $template = (int) $template;
234 + if (!$template) {
235 + return;
236 + }
237 + $actions = new stdClass();
238 + $actions->delete = false;
239 + return $actions;
183 240 }
184 241
185 242 /**
186 243 * Get item
187 - *
188 - * @param int $item - Item ID
189 - *
244 + * @param int $item_id - Item ID
190 245 * @return object - Item
191 246 */
192 - public function item($item = false) {
193 -
194 - $item = (int) $item;
195 - if (!$item && $this->get('item')) {
196 - $item = $this->get('item');
247 + public function item($item_id = false) {
248 + $item_id = (int) $item_id;
249 + if (!$item_id && $this->get('item')) {
250 + $item_id = $this->get('item');
197 251 }
198 -
199 - $form = new stdClass();
200 -
201 -
202 - $formidable_form = false;
252 + $form = false;
203 253 if (class_exists('FrmForm')) {
204 - $formidable_form = FrmForm::getOne($item);
254 + $form = FrmForm::getOne($item_id);
205 255 }
206 -
207 - if ($formidable_form) {
208 - $form->id = (string) $item;
209 - $form->url = $this->helper->get_url(array('page' => 'formidable', 'frm_action' => 'edit', 'id' => $item));
210 - $form->name = $formidable_form->name;
256 + $item = new stdClass();
257 + if ($form) {
258 + $item->id = (string) $item_id;
259 + $item->url = $this->helper->get_url(
260 + array(
261 + 'page' => 'formidable',
262 + 'frm_action' => 'edit',
263 + 'id' => $item_id,
264 + )
265 + );
266 + $item->name = esc_html('' === $form->name ? __('(no title)', 'formidable') : $form->name . ($form->parent_form_id ? __(' (child)', 'formidable') : ''));
211 267 } else {
212 - $form->id = '';
213 - $form->url = 'javascript:void(0);';
214 - $form->name = '';
268 + $item->id = '';
269 + $item->url = '';
270 + $item->name = '';
215 271 }
216 - return $form;
272 + return $item;
217 273 }
218 274
219 275 /**
220 276 * Render value according to content
221 - *
222 277 * @param string $value - Content
223 278 * @param string $type - Type of rendering value
224 279 * @param array $field - Field details
225 - *
226 280 * @return string - Fully rendered value
227 281 */
228 - public function render($value, $type = false, $field = array()) {
229 -
230 - $value = $this->render_shortcodes($value, $type, $field);
231 - $value = $this->strip_shortcodes($value);
232 -
233 - if ($type === 'value' && isset($field['type']) && $field['type'] === 'e2pdf-checkbox' && isset($field['properties']['option'])) {
234 - $option = $this->render($field['properties']['option']);
235 - $options = explode(', ', $value);
236 - $option_options = explode(', ', $option);
237 - if (is_array($options) && is_array($option_options) && !array_diff($option_options, $options)) {
238 - return $option;
239 - } else {
240 - return "";
241 - }
282 + public function render($value, $field = array(), $convert_shortcodes = true, $raw = false) {
283 + $value = $this->render_shortcodes($value, $field);
284 + if (!$raw) {
285 + $value = $this->strip_shortcodes($value);
286 + $value = $this->convert_shortcodes($value, $convert_shortcodes, isset($field['type']) && $field['type'] == 'e2pdf-html' ? true : false);
287 + $value = $this->helper->load('field')->render_checkbox($value, $this, $field);
242 288 }
243 -
244 - if ($type === 'value') {
245 - $value = $this->convert_shortcodes($value, true);
246 - }
247 -
248 289 return $value;
249 290 }
250 291
251 292 /**
@@ -252,10 +293,16 @@
252 293 * Load actions for this extension
253 294 */
254 295 public function load_actions() {
255 296 add_action('frm_notification', array($this, 'action_frm_notification'), 30, 3);
256 - add_action('e2pdf_model_template_fill_pre', array($this, 'action_e2pdf_model_template_fill_pre'), 10, 2);
257 - add_action('e2pdf_model_template_fill_after', array($this, 'action_e2pdf_model_template_fill_after'), 10, 2);
297 + add_action('check_ajax_referer', array($this, 'action_check_ajax_referer'), 10, 2);
298 + add_action('frm_after_create_entry', array($this, 'action_frm_default_value'), 0, 2);
299 + add_action('frm_after_update_entry', array($this, 'action_frm_default_value'), 0, 2);
300 + add_action('frm_success_action', array($this, 'action_frm_success_action'));
301 +
302 + /* Hooks */
303 + add_action('frm_show_entry_sidebar', array($this, 'hook_formidable_entry_view'));
304 + add_action('frm_edit_entry_sidebar', array($this, 'hook_formidable_entry_edit'));
258 305 }
259 306
260 307 /**
261 308 * Load filters for this extension
@@ -260,106 +307,127 @@
260 307 /**
261 308 * Load filters for this extension
262 309 */
263 310 public function load_filters() {
311 +
312 + if (!get_option('e2pdf_formidable_disable_filter', '0')) {
313 + add_filter('frm_display_entry_content', array(new Model_E2pdf_Filter(), 'pre_filter'), 9);
314 + add_filter('frm_display_entry_content', array(new Model_E2pdf_Filter(), 'filter'), 25);
315 + add_filter('frm_display_entry_content', array($this, 'filter_frm_display_entry_content'), 30);
316 + add_filter('frm_content', array(new Model_E2pdf_Filter(), 'pre_filter'));
317 + add_filter('frm_content', array(new Model_E2pdf_Filter(), 'filter'), 25);
318 + }
319 +
264 320 add_filter('frm_content', array($this, 'filter_frm_content'), 30, 3);
321 + add_filter('frm_image_html_array', array($this, 'filter_frm_image_html_array'), 10, 2);
265 322 add_filter('frm_notification_attachment', array($this, 'filter_frm_notification_attachment'), 30, 3);
266 - add_filter('e2pdf_model_options_get_options_options', array($this, 'filter_e2pdf_model_options_get_options_options'), 10, 1);
323 + add_filter('e2pdf_model_options_get_options_options', array($this, 'filter_e2pdf_model_options_get_options_options'));
324 + add_filter('frm_main_feedback', array($this, 'filter_frm_main_feedback'));
325 +
326 + // replace shortcodes on backup
267 327 add_filter('e2pdf_controller_templates_backup_options', array($this, 'filter_e2pdf_controller_templates_backup_options'), 10, 3);
328 + add_filter('e2pdf_controller_templates_backup_pages', array($this, 'filter_e2pdf_controller_templates_backup_pages'), 10, 4);
329 + add_filter('e2pdf_controller_templates_backup_actions', array($this, 'filter_e2pdf_controller_templates_backup_actions'), 10, 4);
330 + add_filter('e2pdf_controller_templates_backup_replace_shortcodes', array($this, 'filter_e2pdf_controller_templates_backup_replace_shortcodes'), 10, 4);
331 +
332 + // replace shortcodes on import
268 333 add_filter('e2pdf_controller_templates_import_options', array($this, 'filter_e2pdf_controller_templates_import_options'), 10, 3);
334 + add_filter('e2pdf_controller_templates_import_pages', array($this, 'filter_e2pdf_controller_templates_import_pages'), 10, 5);
335 + add_filter('e2pdf_controller_templates_import_actions', array($this, 'filter_e2pdf_controller_templates_import_actions'), 10, 5);
336 + add_filter('e2pdf_controller_templates_import_replace_shortcodes', array($this, 'filter_e2pdf_controller_templates_import_replace_shortcodes'), 10, 5);
269 337
270 - add_filter('e2pdf_controller_templates_backup_pages', array($this, 'filter_e2pdf_controller_templates_backup_pages'), 10, 4);
271 - add_filter('e2pdf_controller_templates_backup_dataset_title', array($this, 'filter_e2pdf_controller_templates_backup_replace_shortcodes'), 10, 4);
272 - add_filter('e2pdf_controller_templates_backup_button_title', array($this, 'filter_e2pdf_controller_templates_backup_replace_shortcodes'), 10, 4);
273 - add_filter('e2pdf_controller_templates_backup_name', array($this, 'filter_e2pdf_controller_templates_backup_replace_shortcodes'), 10, 4);
274 - add_filter('e2pdf_controller_templates_backup_password', array($this, 'filter_e2pdf_controller_templates_backup_replace_shortcodes'), 10, 4);
338 + // hooks
339 + add_filter('frm_row_actions', array($this, 'hook_formidable_row_actions'), 10, 2);
275 340
276 - add_filter('e2pdf_controller_templates_import_pages', array($this, 'filter_e2pdf_controller_templates_import_pages'), 10, 5);
277 - add_filter('e2pdf_controller_templates_import_dataset_title', array($this, 'filter_e2pdf_controller_templates_import_replace_shortcodes'), 10, 5);
278 - add_filter('e2pdf_controller_templates_import_button_title', array($this, 'filter_e2pdf_controller_templates_import_replace_shortcodes'), 10, 5);
279 - add_filter('e2pdf_controller_templates_import_name', array($this, 'filter_e2pdf_controller_templates_import_replace_shortcodes'), 10, 5);
280 - add_filter('e2pdf_controller_templates_import_password', array($this, 'filter_e2pdf_controller_templates_import_replace_shortcodes'), 10, 5);
341 + // frm-graph
342 + add_filter('frm_graph_shortcode_custom_html', array($this, 'filter_frm_graph_shortcode_custom_html'), 99, 2);
343 +
344 + // extension hooks
345 + add_filter('e2pdf_extension_hooks', function ($hooks) {
346 + $hooks[$this->info['key']] = [
347 + 'hook_formidable_entry_view' => __('WP Admin Entry View', 'e2pdf'),
348 + 'hook_formidable_entry_edit' => __('WP Admin Entry Edit', 'e2pdf'),
349 + 'hook_formidable_row_actions' => __('WP Admin Entry Row Actions', 'e2pdf')
350 + ];
351 + return $hooks;
352 + });
281 353 }
282 354
355 + public function action_frm_success_action() {
356 + $this->set('iframe_download', true);
357 + }
358 +
359 + public function filter_frm_main_feedback($message) {
360 + $this->set('iframe_download', false);
361 + return $message;
362 + }
363 +
283 364 /**
284 365 * Render shortcodes which available in this extension
285 - *
286 366 * @param string $value - Content
287 367 * @param string $type - Type of rendering value
288 368 * @param array $field - Field details
289 - *
290 369 * @return string - Value with rendered shortcodes
291 370 */
292 - public function render_shortcodes($value, $type = false, $field = array()) {
293 -
294 - $dataset = $this->get('dataset');
295 - $item = $this->get('item');
296 -
297 - $form = false;
298 - $entry = false;
299 - $maybe_checkbox_separated = false;
300 -
371 + public function render_shortcodes($value, $field = array()) {
372 + $element_id = isset($field['element_id']) ? $field['element_id'] : false;
373 + $checkbox_separated = false;
374 + $foreach_wrapper_shortcodes = false;
375 + $foreach_inner_shortcodes = false;
376 + $signature = false;
301 377 if ($this->verify()) {
302 -
303 - $form = FrmForm::getOne($item);
304 - $entry = FrmEntry::getOne($dataset);
305 -
306 378 if (false !== strpos($value, '[')) {
307 -
308 - // Start render Separatable fields shortcode
379 + $value = $this->helper->load('field')->pre_shortcodes($value, $this, $field);
309 380 if (class_exists('FrmProEntry')) {
310 381 $shortcode_tags = array();
311 382 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches);
312 383 $tagnames = array_intersect($shortcode_tags, $matches[1]);
313 -
314 384 foreach ($matches[1] as $key => $shortcode) {
315 - if (strpos($shortcode, ':') !== false) {
385 + if (false !== strpos($shortcode, ':')) {
316 386 $shortcode_tags[] = $shortcode;
317 387 }
318 388 }
319 -
320 389 $tagnames = array_intersect($shortcode_tags, $matches[1]);
321 390 if (!empty($tagnames)) {
322 - $pattern = get_shortcode_regex($tagnames);
323 - preg_match_all("/$pattern/", $value, $shortcodes);
391 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $value, $shortcodes);
324 392 foreach ($shortcodes[0] as $key => $shortcode_value) {
325 - $shortcode = array();
326 - $shortcode[1] = $shortcodes[1][$key];
327 - $shortcode[2] = $shortcodes[2][$key];
328 - $shortcode[3] = $shortcodes[3][$key];
329 - $shortcode[4] = $shortcodes[4][$key];
330 - $shortcode[5] = $shortcodes[5][$key];
331 - $shortcode[6] = $shortcodes[6][$key];
332 -
333 - $shortcode_details = explode(":", $shortcode[2]);
334 -
393 + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
394 + $shortcode_details = explode(':', $shortcode[2]);
335 395 $field_id = $shortcode_details['0'];
336 396 $child_id = $shortcode_details['1'];
337 397 $child_entry = 0;
338 -
339 398 $child_field = false;
340 399 $child_form = false;
341 -
342 - if (class_exists("FrmField")) {
400 + if (class_exists('FrmField')) {
343 401 $child_field = FrmField::getOne($field_id);
344 402 if ($child_field) {
345 403 $child_form = $child_field->form_id;
346 404 }
347 405 }
348 -
349 - $childs = FrmProEntry::get_sub_entries($dataset, true);
350 406 $child_entries = array();
351 -
352 - if ($childs && $child_form) {
353 - foreach ($childs as $child) {
354 - if ($child->form_id == $child_form) {
355 - $child_entries[] = $child->id;
407 + if ($this->get('cached_entry')) {
408 + $childs = FrmEntry::getAll(array('parent_item_id' => $this->get('cached_entry')->id), ' ORDER BY it.id ASC', '', true, false);
409 + if ($childs && $child_form) {
410 + foreach ($childs as $child) {
411 + if ($child->form_id == $child_form) {
412 + $child_entries[] = $child->id;
413 + }
356 414 }
357 415 }
358 416 }
359 -
360 - $new_shortcode = "";
361 -
417 + if ($this->get('item') == '-2') {
418 + if ($this->get('cached_entry2')) {
419 + $childs = FrmEntry::getAll(array('parent_item_id' => $this->get('cached_entry2')->id), ' ORDER BY it.id ASC', '', true, false);
420 + if ($childs && $child_form) {
421 + foreach ($childs as $child) {
422 + if ($child->form_id == $child_form) {
423 + $child_entries[] = $child->id;
424 + }
425 + }
426 + }
427 + }
428 + }
429 + $new_shortcode = '';
362 430 if (!empty($child_entries) && count($child_entries) >= $child_id) {
363 431 $start = 1;
364 432 foreach ($child_entries as $key => $sub_entry) {
365 433 if ($start == $child_id) {
@@ -368,254 +436,317 @@
368 436 }
369 437 $start++;
370 438 }
371 439
372 - $shortcode[2] = "frm-field-value field_id={$field_id} entry={$child_entry}";
373 - $new_shortcode = "[" . $shortcode[2] . $shortcode[3] . "]";
440 + $shortcode[2] = 'frm-field-value field_id=' . $field_id . ' entry=' . $child_entry;
441 + $new_shortcode = '[' . $shortcode[2] . $shortcode[3] . ']';
374 442 }
375 -
376 - $maybe_checkbox_separated = true;
443 + $checkbox_separated = true;
377 444 $value = str_replace($shortcode_value, $new_shortcode, $value);
378 445 }
379 446 }
380 447 }
381 - // End render Separatable fields shortcode
382 448
449 + // Foreach Inner Shortcodes
450 + preg_match_all('/\[foreach[^\]]*?\]((?:(?!\[\/foreach).)+)(e2pdf-if|e2pdf-for)((?:(?!\[\/foreach).)+)\[\/foreach[^\]]*?\]/s', $value, $matches);
451 + if (!empty($matches[0])) {
452 + foreach ($matches[0] as $match) {
453 + $new_match = preg_replace('/(\[)(\/?(e2pdf-if|e2pdf-for)[^\]]*?)(\])/', '{{$2}}', $match);
454 + $if_shortcodes = $this->helper->load('if')->get_shortcodes();
455 + $if_shortcodes_new = array_map(
456 + function ($str) {
457 + return str_replace(array('[', ']'), array('{{', '}}'), $str);
458 + },
459 + $if_shortcodes
460 + );
461 + $value = str_replace($match, str_replace($if_shortcodes, $if_shortcodes_new, $new_match), $value);
462 + }
463 + $foreach_inner_shortcodes = true;
464 + }
465 +
466 + $value = $this->helper->load('field')->inner_shortcodes($value, $this, $field);
467 +
468 + /* Default shortcodes support */
383 469 $shortcode_tags = array(
384 - 'e2pdf-format-number',
385 - 'e2pdf-format-date',
386 - 'e2pdf-format-output',
470 + 'e2pdf-frm-lookup-values',
471 + 'e2pdf-frm-data-values',
472 + 'default-message',
473 + 'default_message',
474 + 'default-message2',
475 + 'default_message2',
387 476 );
388 477 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches);
389 478 $tagnames = array_intersect($shortcode_tags, $matches[1]);
479 + if (!empty($tagnames)) {
480 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $value, $shortcodes);
481 + foreach ($shortcodes[0] as $key => $shortcode_value) {
482 + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
483 + $atts = shortcode_parse_atts($shortcode[3]);
484 + if ($shortcode[2] === 'e2pdf-frm-lookup-values' || $shortcode[2] === 'e2pdf-frm-data-values') {
485 + if (!isset($atts['user_id']) && $this->get('user_id')) {
486 + $shortcode[3] .= ' user_id="' . $this->get('user_id') . '"';
487 + $value = str_replace($shortcode_value, '[' . $shortcode[2] . $shortcode[3] . ']', $value);
488 + }
489 + } elseif (($shortcode[2] === 'default-message' || $shortcode[2] === 'default_message') && $this->get('cached_entry') && class_exists('FrmEntriesHelper')) {
490 + $default_message = FrmEntriesHelper::replace_default_message(
491 + $shortcode_value,
492 + array(
493 + 'id' => $this->get('cached_entry')->id,
494 + 'entry' => clone $this->get('cached_entry'),
495 + 'plain_text' => isset($atts['is_plain_text']) && $atts['is_plain_text'] == 'true' ? true : false,
496 + 'user_info' => isset($atts['user_info']) && $atts['user_info'] == 'true' ? true : false,
497 + )
498 + );
499 + $value = str_replace($shortcode_value, $default_message, $value);
500 + } elseif (($shortcode[2] === 'default-message2' || $shortcode[2] == 'default_message2') && $this->get('cached_entry2') && class_exists('FrmEntriesHelper')) {
501 + $default_message = FrmEntriesHelper::replace_default_message(
502 + str_replace(array('default-message2', 'default_message2'), array('default-message', 'default_message'), $shortcode_value),
503 + array(
504 + 'id' => $this->get('cached_entry2')->id,
505 + 'entry' => clone $this->get('cached_entry2'),
506 + 'plain_text' => isset($atts['is_plain_text']) && $atts['is_plain_text'] == 'true' ? true : false,
507 + 'user_info' => isset($atts['user_info']) && $atts['user_info'] == 'true' ? true : false,
508 + )
509 + );
510 + $value = str_replace($shortcode_value, $default_message, $value);
511 + }
512 + }
513 + }
390 514
391 - if (!empty($tagnames)) {
515 + // Foreach Wrapper Shortcodes
516 + preg_match_all('/\[foreach[^\]]*?\]((?:(?!\[\/foreach).)+)(e2pdf-format-number|e2pdf-format-date|e2pdf-format-output|e2pdf-math)((?:(?!\[\/foreach).)+)\[\/foreach[^\]]*?\]/s', $value, $matches);
517 + if (!empty($matches[0])) {
518 + foreach ($matches[0] as $match) {
519 + $new_match = preg_replace('/(\[)(\/?(e2pdf-format-number|e2pdf-format-date|e2pdf-format-output|e2pdf-math)[^\]]*?)(\])/', '{{$2}}', $match);
520 + $value = str_replace($match, $new_match, $value);
521 + $foreach_wrapper_shortcodes = true;
522 + }
523 + }
524 + $value = $this->helper->load('field')->wrapper_shortcodes($value, $this, $field);
392 525
393 - $pattern = get_shortcode_regex($tagnames);
394 - preg_match_all("/$pattern/", $value, $shortcodes);
395 - foreach ($shortcodes[0] as $key => $shortcode_value) {
396 - $shortcode = array();
397 - $shortcode[1] = $shortcodes[1][$key];
398 - $shortcode[2] = $shortcodes[2][$key];
399 - $shortcode[3] = $shortcodes[3][$key];
400 - $shortcode[4] = $shortcodes[4][$key];
401 - $shortcode[5] = $shortcodes[5][$key];
402 - $shortcode[6] = $shortcodes[6][$key];
526 + if (false !== strpos($value, '[')) {
527 + if (strpos($value, '[foreach') !== false) {
528 + if ($this->get('cached_entry')) {
529 + $value = preg_replace('/\[foreach[^\]]*?\](.*?)\[\/foreach(*SKIP)(*FAIL)|\[id\]/is', $this->get('cached_entry')->id, $value);
530 + $value = preg_replace('/\[foreach[^\]]*?\](.*?)\[\/foreach(*SKIP)(*FAIL)|\[key\]/is', $this->get('cached_entry')->item_key, $value);
531 + } else {
532 + $value = preg_replace('/\[foreach[^\]]*?\](.*?)\[\/foreach(*SKIP)(*FAIL)|\[id\]/is', '', $value);
533 + $value = preg_replace('/\[foreach[^\]]*?\](.*?)\[\/foreach(*SKIP)(*FAIL)|\[key\]/is', '', $value);
534 + }
403 535
404 - if (isset($shortcode['5'])) {
405 - if (isset($field['type']) && ($field['type'] === 'e2pdf-image' || $field['type'] === 'e2pdf-signature')) {
406 - $sub_value = $this->render($shortcode['5'], $type);
407 - } else {
408 - $sub_value = $this->render($shortcode['5'], $type, $field);
409 - }
410 - $value = str_replace($shortcode_value, "[" . $shortcode['2'] . $shortcode['3'] . "]" . $sub_value . "[/" . $shortcode['2'] . "]", $value);
536 + if ($this->get('cached_entry2')) {
537 + $value = preg_replace('/\[foreach[^\]]*?\](.*?)\[\/foreach(*SKIP)(*FAIL)|\[id2\]/is', $this->get('cached_entry2')->id, $value);
538 + $value = preg_replace('/\[foreach[^\]]*?\](.*?)\[\/foreach(*SKIP)(*FAIL)|\[key2\]/is', $this->get('cached_entry2')->item_key, $value);
539 + } else {
540 + $value = preg_replace('/\[foreach[^\]]*?\](.*?)\[\/foreach(*SKIP)(*FAIL)|\[id2\]/is', '', $value);
541 + $value = preg_replace('/\[foreach[^\]]*?\](.*?)\[\/foreach(*SKIP)(*FAIL)|\[key2\]/is', '', $value);
411 542 }
543 + } else {
544 + $replace = array(
545 + '[id]' => $this->get('cached_entry') ? $this->get('cached_entry')->id : '',
546 + '[key]' => $this->get('cached_entry') ? $this->get('cached_entry')->item_key : '',
547 + '[id2]' => $this->get('cached_entry2') ? $this->get('cached_entry2')->id : '',
548 + '[key2]' => $this->get('cached_entry2') ? $this->get('cached_entry2')->item_key : '',
549 + );
550 + $value = str_replace(array_keys($replace), $replace, $value);
412 551 }
413 552 }
414 553 }
415 554
416 -
417 555 /*
418 556 * Checkboxes separatable fix filter add
419 557 * @since 0.01.43
420 558 */
421 - if ($maybe_checkbox_separated) {
559 + if ($checkbox_separated) {
422 560 add_filter('frm_display_value_custom', array($this, 'filter_frm_display_value_custom'), 0, 3);
423 561 }
424 562
425 - $value = do_shortcode($value);
563 + /* [display-frm-data] shortcode support */
564 + if (false !== strpos($value, '[')) {
565 + preg_match_all('/(?=\[display-frm-data\b)(\[(?:[^\[\]]+|(?1))+\])/', $value, $matches);
566 + if (!empty($matches[1])) {
567 + add_filter('frmpro_fields_replace_shortcodes', array($this, 'filter_frmpro_fields_replace_shortcodes'), 20, 4);
568 + foreach ($matches[1] as $match) {
569 + if ($this->get('item') == '-2') {
570 + if ($this->get('cached_entry') && $this->get('cached_entry2')) {
571 + $new_match = apply_filters('frm_content', $match, $this->get('cached_form'), $this->get('cached_entry'));
572 + $new_match = apply_filters('frm_content', $new_match, $this->get('cached_form2'), $this->get('cached_entry2'));
573 + } elseif ($this->get('cached_entry')) {
574 + $new_match = apply_filters('frm_content', $match, $this->get('cached_form'), $this->get('cached_entry'));
575 + if ($this->get('cached_form2')) {
576 + $new_match = apply_filters('frm_content', $new_match, $this->get('cached_form2'), $this->get('cached_entry'));
577 + }
578 + } elseif ($this->get('cached_entry2')) {
579 + $new_match = apply_filters('frm_content', $match, $this->get('cached_form2'), $this->get('cached_entry2'));
580 + if ($this->get('cached_form')) {
581 + $new_match = apply_filters('frm_content', $new_match, $this->get('cached_form'), $this->get('cached_entry2'));
582 + }
583 + }
584 + } else {
585 + $new_match = apply_filters('frm_content', $match, $this->get('cached_form'), $this->get('cached_entry'));
586 + }
587 + $value = str_replace($match, $new_match, $value);
588 + }
589 + remove_filter('frmpro_fields_replace_shortcodes', array($this, 'filter_frmpro_fields_replace_shortcodes'), 20);
590 + }
591 + }
426 592
593 + add_filter('frm_filter_view', array($this, 'filter_frm_filter_view'));
594 + $value = $this->helper->load('field')->do_shortcodes($value, $this, $field);
595 + remove_filter('frm_filter_view', array($this, 'filter_frm_filter_view'));
596 +
427 597 /*
428 598 * Checkboxes separatable fix filter remove
429 599 * @since 0.01.43
430 600 */
431 - if ($maybe_checkbox_separated) {
601 + if ($checkbox_separated) {
432 602 remove_filter('frm_display_value_custom', array($this, 'filter_frm_display_value_custom'), 0);
433 603 }
434 604
435 - //Bug fix for Formidable Forms Signature (2.0.1)
436 - $upd_signature = false;
605 + /* Bug fix for Formidable Forms Signature (2.0.1) */
437 606 if (class_exists('FrmFieldFactory')) {
438 - $sig_obj = FrmFieldFactory::get_field_type('signature');
439 - if ($sig_obj->get_display_value('signature') == '') {
440 - $upd_signature = true;
607 + $signature_field = FrmFieldFactory::get_field_type('signature');
608 + if ($signature_field->get_display_value('signature') == '') {
609 + $signature = true;
441 610 }
442 611 }
443 -
444 - if ($upd_signature) {
445 - remove_filter('frm_get_signature_display_value', 'FrmSigAppController::display_signature', 10);
446 - remove_filter('frmpro_fields_replace_shortcodes', 'FrmSigAppController::custom_display_signature', 10);
612 + if ($signature) {
613 + remove_filter('frm_get_signature_display_value', 'FrmSigAppController::display_signature');
614 + remove_filter('frmpro_fields_replace_shortcodes', 'FrmSigAppController::custom_display_signature');
447 615 add_filter('frm_keep_signature_value_array', array($this, 'filter_frm_keep_signature_value_array'), 10, 2);
448 616 }
617 + add_filter('frmpro_fields_replace_shortcodes', array($this, 'filter_frmpro_fields_replace_shortcodes'), 20, 4);
449 618
450 - $value = apply_filters('frm_content', $value, $form, $entry);
451 -
452 - if ($upd_signature) {
453 - remove_filter('frm_keep_signature_value_array', array($this, 'filter_frm_keep_signature_value_array'), 10);
454 - add_filter('frm_get_signature_display_value', 'FrmSigAppController::display_signature', 10, 3);
455 - add_filter('frmpro_fields_replace_shortcodes', 'FrmSigAppController::custom_display_signature', 10, 4);
619 + $text_signature = !empty($field['type']) && ($field['type'] == 'e2pdf-image' || $field['type'] == 'e2pdf-signature') ? true : false;
620 + if ($text_signature) {
621 + add_filter('frm_get_signature_display_value', array($this, 'filter_frm_get_signature_display_value'), 20, 3);
456 622 }
457 -
458 - if (isset($field['type']) && ($field['type'] === 'e2pdf-image' || $field['type'] === 'e2pdf-signature')) {
459 - $esig = isset($field['properties']['esig']) && $field['properties']['esig'] ? true : false;
460 - if ($esig) {
461 - //process e-signature
462 - $value = "";
463 - } else {
464 - preg_match('/src="([^"]*)"/', $value, $matches);
465 -
466 - if (isset($matches[1])) {
467 - $value = $matches[1];
623 + if ($this->get('item') == '-2') {
624 + if ($this->get('cached_entry') && $this->get('cached_entry2')) {
625 + $value = apply_filters('frm_content', $value, $this->get('cached_form'), $this->get('cached_entry'));
626 + $value = apply_filters('frm_content', $value, $this->get('cached_form2'), $this->get('cached_entry2'));
627 + } elseif ($this->get('cached_entry')) {
628 + $value = apply_filters('frm_content', $value, $this->get('cached_form'), $this->get('cached_entry'));
629 + if ($this->get('cached_form2')) {
630 + $value = apply_filters('frm_content', $value, $this->get('cached_form2'), $this->get('cached_entry'));
468 631 }
469 -
470 - if (!$this->helper->load('image')->get_image($value)) {
471 - $value = $this->strip_shortcodes($value);
472 - if (
473 - $value &&
474 - trim($value) != "" &&
475 - extension_loaded('gd') &&
476 - function_exists('imagettftext')
477 - ) {
478 - if (isset($field['properties']['text_color']) && $field['properties']['text_color']) {
479 - $penColour = $this->helper->load('convert')->to_hex_color($field['properties']['text_color']);
480 - } else {
481 - $penColour = array(0x14, 0x53, 0x94);
482 - }
483 -
484 - $default_options = array(
485 - 'imageSize' => array(isset($field['width']) ? $field['width'] : '400', isset($field['height']) ? $field['height'] : '150'),
486 - 'bgColour' => 'transparent',
487 - 'penColour' => $penColour
488 - );
489 -
490 - $options = array();
491 - $options = apply_filters('e2pdf_frm_sig_output_options', $options, $field_id);
492 - $options = array_merge($default_options, $options);
493 -
494 - $model_e2pdf_font = new Model_E2pdf_Font();
495 -
496 - $font = false;
497 - if (isset($field['properties']['text_font']) && $field['properties']['text_font']) {
498 - $font = $model_e2pdf_font->get_font_path($field['properties']['text_font']);
499 - } elseif (class_exists('FrmSigAppHelper')) {
500 - if (file_exists(FrmSigAppHelper::plugin_path() . '/assets/journal.ttf')) {
501 - $font = FrmSigAppHelper::plugin_path() . '/assets/journal.ttf';
502 - }
503 - }
504 -
505 - if (!$font) {
506 - $font = $model_e2pdf_font->get_font_path('Noto Sans');
507 - }
508 -
509 - $size = 150;
510 - if (isset($field['properties']['text_font_size']) && $field['properties']['text_font_size']) {
511 - $size = $field['properties']['text_font_size'];
512 - }
513 -
514 - $model_e2pdf_signature = new Model_E2pdf_Signature();
515 - $value = $model_e2pdf_signature->ttf_signature($value, $size, $font, $options);
516 - } else {
517 - $value = "";
518 - }
632 + } elseif ($this->get('cached_entry2')) {
633 + $value = apply_filters('frm_content', $value, $this->get('cached_form2'), $this->get('cached_entry2'));
634 + if ($this->get('cached_form')) {
635 + $value = apply_filters('frm_content', $value, $this->get('cached_form'), $this->get('cached_entry2'));
519 636 }
520 637 }
521 - }
522 -
523 - if ((false !== strpos($value, '[referer]') || false !== strpos($value, '[browser]')) && isset($entry->description)) {
524 - $description = maybe_unserialize($entry->description);
525 - $referer = "";
526 - if (isset($description['referrer'])) {
527 - if (@preg_match('/Referer +\d+\:[ \t]+([^\n\t]+)/', $description['referrer'], $m)) {
528 - $referer = $m[1];
529 - } else {
530 - $referer = $description['referrer'];
531 - }
638 + } else {
639 + if ($this->get('cached_shortcodes')) {
640 + remove_filter('frm_content', 'FrmFormsController::filter_content', 10, 3);
641 + add_filter('frm_content', array($this, 'filter_filter_content'), 10, 3);
532 642 }
533 -
534 - $browser = "";
535 - if (isset($description['browser'])) {
536 - $browser = $description['browser'];
643 + $value = apply_filters('frm_content', $value, $this->get('cached_form'), $this->get('cached_entry'));
644 + if ($this->get('cached_shortcodes')) {
645 + remove_filter('frm_content', array($this, 'filter_filter_content'), 10, 3);
646 + add_filter('frm_content', 'FrmFormsController::filter_content', 10, 3);
537 647 }
648 + }
538 649
539 - $replace = array(
540 - 'from' => array(
541 - '[referer]',
542 - '[browser]'
543 - ),
544 - 'to' => array(
545 - $referer,
546 - $browser
547 - )
548 - );
549 - $value = str_replace($replace['from'], $replace['to'], $value);
650 + // Foreach Wrapper Shortcodes Reverse
651 + if ($foreach_wrapper_shortcodes) {
652 + $value = preg_replace('/(\{\{)(\/?(e2pdf-format-number|e2pdf-format-date|e2pdf-format-output|e2pdf-math)[^\}]*?)(\}\})/', '[$2]', $value);
653 + $value = $this->helper->load('field')->wrapper_shortcodes($value, $this, $field, true);
550 654 }
551 655
552 - if (false !== strpos($value, '[entry_num]')) {
553 - $entry_num = '';
554 - if (class_exists("FrmDb")) {
555 - $entry_num = FrmDb::get_count('frm_items', array("form_id = '{$form->id}' AND id <= '{$entry->id}' AND 1" => "1"));
656 + // Foreach Inner Shortcodes Reverse
657 + if ($foreach_inner_shortcodes) {
658 + preg_match_all('/\{\{(e2pdf-if|e2pdf-for)\}\}(.*?)+\{\{\/(e2pdf-if|e2pdf-for)\}\}/s', $value, $matches);
659 + if (!empty($matches[0])) {
660 + foreach ($matches[0] as $match) {
661 + $new_match = preg_replace('/(\{\{)(\/?(e2pdf-if|e2pdf-for)[^\}]*?)(\}\})/', '[$2]', $match);
662 + $value = str_replace($match, str_replace($if_shortcodes_new, $if_shortcodes, $new_match), $value);
663 + }
556 664 }
557 -
558 - $replace = array(
559 - 'from' => array(
560 - '[entry_num]'
561 - ),
562 - 'to' => array(
563 - $entry_num
564 - )
565 - );
566 - $value = str_replace($replace['from'], $replace['to'], $value);
665 + $value = $this->helper->load('field')->inner_shortcodes($value, $this, $field);
567 666 }
568 667
569 - if (false !== strpos($value, '[pdf_num]')) {
570 - $pdf_num = '0';
571 - $uid = $this->get('uid');
572 - if ($uid) {
573 - $entry = new Model_E2pdf_Entry();
574 - if ($entry->load_by_uid($uid)) {
575 - $pdf_num = $entry->get('pdf_num') + 1;
576 - }
668 + // Text Signature
669 + if ($text_signature) {
670 + remove_filter('frm_get_signature_display_value', array($this, 'filter_frm_get_signature_display_value'), 20);
671 + if ($value && false !== strpos($value, ':e2pdf-text-filter:')) {
672 + $value = str_replace(':e2pdf-text-filter:', '', $value);
673 + $field['properties']['text'] = '1';
577 674 }
578 -
579 - $replace = array(
580 - 'from' => array(
581 - '[pdf_num]'
582 - ),
583 - 'to' => array(
584 - $pdf_num
585 - )
586 - );
587 -
588 - $value = str_replace($replace['from'], $replace['to'], $value);
589 675 }
676 + remove_filter('frmpro_fields_replace_shortcodes', array($this, 'filter_frmpro_fields_replace_shortcodes'), 20);
677 + if ($signature) {
678 + remove_filter('frm_keep_signature_value_array', array($this, 'filter_frm_keep_signature_value_array'));
679 + add_filter('frm_get_signature_display_value', 'FrmSigAppController::display_signature', 10, 3);
680 + add_filter('frmpro_fields_replace_shortcodes', 'FrmSigAppController::custom_display_signature', 10, 4);
681 + }
682 + $value = $this->replace_meta_shortcodes($value);
683 + $value = $this->helper->load('field')->render(
684 + apply_filters('e2pdf_extension_render_shortcodes_pre_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), $this->get('item2'), $this->get('dataset2')),
685 + $this,
686 + $field
687 + );
590 688 }
591 - return $value;
689 + return apply_filters(
690 + 'e2pdf_extension_render_shortcodes_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), $this->get('item2'), $this->get('dataset2')
691 + );
592 692 }
593 693
594 694 /**
595 695 * Strip unused shortcodes
596 - *
597 696 * @param string $value - Content
598 - *
599 697 * @return string - Value with removed unused shortcodes
600 698 */
601 699 public function strip_shortcodes($value) {
602 - $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', "", $value);
700 + $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', '', $value);
603 701 return $value;
604 702 }
605 703
606 - public function convert_shortcodes($value, $to = false) {
704 + /**
705 + * Convert "shortcodes" inside value string
706 + * @param string $value - Value string
707 + * @param bool $to - Convert From/To
708 + * @return string - Converted value
709 + */
710 + public function convert_shortcodes($value, $to = false, $html = false) {
607 711 if ($value) {
608 712 if ($to) {
609 - $value = str_replace("&#91;", "[", $value);
713 + $search = array('&#91;', '&#93;', '&#091;', '&#093;');
714 + $replace = array('[', ']', '[', ']');
715 + $value = str_replace($search, $replace, $value);
716 + if (!$html) {
717 + $value = wp_specialchars_decode($value, ENT_QUOTES);
718 + }
610 719 } else {
611 - $value = str_replace("[", "&#91;", $value);
720 + $search = array('[', ']', '&#091;', '&#093;');
721 + $replace = array('&#91;', '&#93;', '&#91;', '&#93;');
722 + $value = str_replace($search, $replace, $value);
612 723 }
613 724 }
614 725 return $value;
615 726 }
616 727
617 - function filter_frm_keep_signature_value_array($keep_array, $atts) {
728 + public function filter_frm_filter_view($view) {
729 + if (isset($view->frm_before_content) && $view->frm_before_content) {
730 + $view->frm_before_content = str_replace('[e2pdf-exclude]', '[e2pdf-exclude apply="true"]', $view->frm_before_content);
731 + }
732 + if (isset($view->post_content) && $view->post_content) {
733 + $view->post_content = str_replace('[e2pdf-exclude]', '[e2pdf-exclude apply="true"]', $view->post_content);
734 + }
735 + if (isset($view->frm_after_content) && $view->frm_after_content) {
736 + $view->frm_after_content = str_replace('[e2pdf-exclude]', '[e2pdf-exclude apply="true"]', $view->frm_after_content);
737 + }
738 + return $view;
739 + }
740 +
741 + public function filter_frm_lookup_is_current_user_filter_needed($is_filter_needed, $field_id, $field_options) {
742 + if (FrmField::is_option_true_in_array($field_options, 'lookup_filter_current_user')) {
743 + return true;
744 + }
745 + return $is_filter_needed;
746 + }
747 +
748 + public function filter_frm_keep_signature_value_array($keep_array, $atts) {
618 749 return true;
619 750 }
620 751
621 752 /**
@@ -620,63 +751,104 @@
620 751
621 752 /**
622 753 * Search and update shortcodes for this extension inside content
623 754 * Auto set of dataset id
624 - *
625 755 * @param string $content - Content
626 756 * @param int $form - ID of form
627 - * @param int $dataset - ID of dataset
628 - *
757 + * @param int $dataset_id - ID of dataset
629 758 * @return string - Content with updates shortcodes
630 759 */
631 - public function filter_frm_content($content, $form, $dataset) {
760 + public function filter_frm_content($content, $form, $dataset_id) {
632 761
633 762 if (false === strpos($content, '[')) {
634 763 return $content;
635 764 }
636 -
637 765 $shortcode_tags = array(
638 766 'e2pdf-download',
639 767 'e2pdf-save',
640 768 'e2pdf-view',
641 - 'e2pdf-adobesign'
769 + 'e2pdf-adobesign',
770 + 'e2pdf-zapier',
642 771 );
643 -
644 772 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
645 773 $tagnames = array_intersect($shortcode_tags, $matches[1]);
646 -
647 774 if (!empty($tagnames)) {
648 - $pattern = get_shortcode_regex($tagnames);
775 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
776 + foreach ($shortcodes[0] as $key => $shortcode_value) {
777 + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
778 + $atts = shortcode_parse_atts($shortcode[3]);
779 + if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
780 + } else {
781 + if (!isset($atts['dataset']) && isset($atts['id'])) {
782 + $template = new Model_E2pdf_Template();
783 + $template->load($atts['id']);
784 + if ($template->get('extension') === 'formidable') {
785 + $entry_id = is_object($dataset_id) ? $dataset_id->id : $dataset_id;
786 + if ($entry_id) {
787 + if ($template->get('item') == '-2') {
788 + if ($template->get('item1') == $form->id) {
789 + $atts['dataset'] = $entry_id;
790 + $shortcode[3] .= ' dataset="' . $entry_id . '"';
791 + } elseif (!isset($atts['dataset2']) && $template->get('item2') == $form->id) {
792 + $atts['dataset2'] = $entry_id;
793 + $shortcode[3] .= ' dataset2="' . $entry_id . '"';
794 + }
795 + } else {
796 + $atts['dataset'] = $entry_id;
797 + $shortcode[3] .= ' dataset="' . $entry_id . '"';
798 + }
799 + }
800 + }
801 + }
802 + if (!isset($atts['apply'])) {
803 + $shortcode[3] .= ' apply="true"';
804 + }
805 + if (!isset($atts['filter'])) {
806 + $shortcode[3] .= ' filter="true"';
807 + }
808 + if (!isset($atts['iframe_download']) && $this->get('iframe_download')) {
809 + $shortcode[3] .= ' iframe_download="true"';
810 + }
811 + $content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content);
812 + }
813 + }
814 + }
649 815
650 - preg_match_all("/$pattern/", $content, $shortcodes);
651 - foreach ($shortcodes[0] as $key => $shortcode_value) {
816 + return $content;
817 + }
652 818
653 - $shortcode = array();
654 - $shortcode[1] = $shortcodes[1][$key];
655 - $shortcode[2] = $shortcodes[2][$key];
656 - $shortcode[3] = $shortcodes[3][$key];
657 - $shortcode[4] = $shortcodes[4][$key];
658 - $shortcode[5] = $shortcodes[5][$key];
659 - $shortcode[6] = $shortcodes[6][$key];
819 + public function filter_frm_display_entry_content($content) {
660 820
821 + if (false === strpos($content, '[')) {
822 + return $content;
823 + }
824 + $shortcode_tags = array(
825 + 'e2pdf-download',
826 + 'e2pdf-save',
827 + 'e2pdf-view',
828 + 'e2pdf-adobesign',
829 + 'e2pdf-zapier',
830 + );
831 + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
832 + $tagnames = array_intersect($shortcode_tags, $matches[1]);
833 + if (!empty($tagnames)) {
834 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
835 + foreach ($shortcodes[0] as $key => $shortcode_value) {
836 + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
661 837 $atts = shortcode_parse_atts($shortcode[3]);
662 -
663 - if (!array_key_exists('dataset', $atts) && array_key_exists('id', $atts)) {
664 - $template = new Model_E2pdf_Template();
665 - $template->load($atts['id']);
666 - if ($template->get('extension') === 'formidable') {
667 - $entry_id = is_object($dataset) ? $dataset->id : $dataset;
668 - if ($entry_id) {
669 - $atts['dataset'] = $entry_id;
670 - $shortcode[3] .= " dataset=\"{$entry_id}\"";
671 - }
838 + if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
839 + } else {
840 + if (!isset($atts['apply'])) {
841 + $shortcode[3] .= ' apply="true"';
672 842 }
843 + if (!isset($atts['filter'])) {
844 + $shortcode[3] .= ' filter="true"';
845 + }
846 + if (!isset($atts['iframe_download'])) {
847 + $shortcode[3] .= ' iframe_download="true"';
848 + }
849 + $content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content);
673 850 }
674 - if ($shortcode[2] === 'e2pdf-save' || $shortcode[2] === 'e2pdf-adobesign') {
675 - $shortcode[3] .= " apply=\"true\"";
676 - }
677 - $shortcode[3] .= " filter=\"true\"";
678 - $content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content);
679 851 }
680 852 }
681 853
682 854 return $content;
@@ -683,20 +855,21 @@
683 855 }
684 856
685 857 /**
686 858 * Filter for checkbox repeatable Label/Value fix
687 - *
688 859 * @param array $value - Value
689 860 * @param obj $field - Field
690 861 * @param array $atts - Shortcode Attributes
691 - *
692 862 * @return mixed - Updated value
693 863 */
694 864 public function filter_frm_display_value_custom($value, $field, $atts = array()) {
695 - if (class_exists("FrmProEntriesController")) {
696 - $defaults = array('html' => 0, 'type' => $field->type, 'keepjs' => 0);
865 + if (class_exists('FrmProEntriesController')) {
866 + $defaults = array(
867 + 'html' => 0,
868 + 'type' => $field->type,
869 + 'keepjs' => 0,
870 + );
697 871 $atts = array_merge($defaults, $atts);
698 -
699 872 if ($atts['type'] === 'checkbox') {
700 873 $value = FrmProEntriesController::get_option_label_for_saved_value($value, $field, $atts);
701 874 }
702 875 }
@@ -703,36 +876,84 @@
703 876 return $value;
704 877 }
705 878
706 879 /**
880 + * Filter for Signature
881 + * @param array $value - Value
882 + * @param obj $field - Field
883 + * @param array $atts - Shortcode Attributes
884 + * @return mixed - Updated value
885 + */
886 + public function filter_frm_get_signature_display_value($value, $field, $atts = array()) {
887 + if ($value && !empty($value['format']) && $value['format'] == 'typed' && !empty($value['content'])) {
888 + $value['content'] = ':e2pdf-text-filter:' . $value['content'];
889 + }
890 + return $value;
891 + }
892 +
893 + public function filter_frmpro_fields_replace_shortcodes($replace_with, $tag, $atts, $field) {
894 +
895 + /* Backward compatibility with Formidable Forms PRO < 5.0 */
896 + if (class_exists('FrmProDb') && property_exists('FrmProDb', 'plug_version') && version_compare(FrmProDb::$plug_version, '5.0', '<')) {
897 + if ($this->get('item') == '-2' && $this->get('cached_entry2') && $field->form_id == $this->get('cached_entry2')->form_id) {
898 + $atts['entry_id'] = $this->get('cached_entry2')->id;
899 + $replace_with = FrmProEntryMetaHelper::get_post_or_meta_value($this->get('cached_entry2'), $field, $atts);
900 + }
901 + }
902 +
903 + if ($field->type === 'checkbox' && is_array($replace_with)) {
904 + if (isset($atts['key']) && $atts['key']) {
905 + if (isset($replace_with[$atts['key']])) {
906 + $replace_with = $replace_with[$atts['key']];
907 + } else {
908 + $replace_with = '';
909 + }
910 + }
911 + }
912 +
913 + if ($field->type === 'radio') {
914 + if (isset($atts['key']) && $atts['key'] === 'other') {
915 + if (isset($field->options) && is_array($field->options)) {
916 + $field_key = array_search($replace_with, array_column($field->options, 'value'));
917 + if ($field_key !== false) {
918 + $replace_with = '';
919 + }
920 + }
921 + }
922 + }
923 +
924 + if ($field->type === 'signature' && is_array($replace_with)) {
925 + if (!empty($replace_with['format']) && $replace_with['format'] == 'drawn' && !empty($replace_with['output'])) {
926 + return $replace_with['output'];
927 + }
928 + }
929 +
930 + return $replace_with;
931 + }
932 +
933 + /**
707 934 * Generate attachments according shortcodes in Email template
708 - *
709 935 * @param array $attachments - List of attachments
710 936 * @param int $form - ID of form
711 937 * @param array $args - Arguments
712 - *
713 938 * @return array - Updated list of attachments
714 939 */
715 - public function filter_frm_notification_attachment($attachments = array(), $form, $args) {
716 -
940 + public function filter_frm_notification_attachment($attachments, $form, $args) {
717 941 if (!isset($args['email_key'])) {
718 942 return $attachments;
719 943 }
720 -
721 944 $form_actions = FrmFormAction::get_action_for_form($form->id);
722 -
723 - $dataset = $args['entry']->id;
945 + $dataset_id = $args['entry']->id;
724 946 $email_key = $args['email_key'];
725 947
726 948 $shortcode_tags = array(
727 949 'e2pdf-attachment',
950 + 'e2pdf-save',
728 951 );
729 952
730 953 foreach ($form_actions as $key => $action) {
731 954 if ($action->ID === $email_key) {
732 -
733 955 $content = $action->post_content['email_message'];
734 -
735 956 if (false === strpos($content, '[')) {
736 957 return $attachments;
737 958 }
738 959
@@ -741,61 +962,159 @@
741 962 add_filter('frm_content', array($this, 'filter_frm_content'), 30, 3);
742 963
743 964 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
744 965 $tagnames = array_intersect($shortcode_tags, $matches[1]);
745 -
746 966 if (!empty($tagnames)) {
747 - $pattern = get_shortcode_regex($tagnames);
748 -
749 - preg_match_all("/$pattern/", $content, $shortcodes);
750 -
967 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
751 968 foreach ($shortcodes[0] as $key => $shortcode_value) {
752 -
753 - $shortcode = array();
754 - $shortcode[1] = $shortcodes[1][$key];
755 - $shortcode[2] = $shortcodes[2][$key];
756 - $shortcode[3] = $shortcodes[3][$key];
757 - $shortcode[4] = $shortcodes[4][$key];
758 - $shortcode[5] = $shortcodes[5][$key];
759 - $shortcode[6] = $shortcodes[6][$key];
760 -
969 + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
761 970 $atts = shortcode_parse_atts($shortcode[3]);
762 -
763 - if (!array_key_exists('dataset', $atts) && array_key_exists('id', $atts)) {
764 - $template = new Model_E2pdf_Template();
765 - $template->load($atts['id']);
766 - if ($template->get('extension') === 'formidable') {
767 - $entry_id = is_object($dataset) ? $dataset->id : $dataset;
768 - if ($entry_id) {
769 - $atts['dataset'] = $entry_id;
770 - $shortcode[3] .= " dataset=\"{$entry_id}\"";
971 + $file = false;
972 + if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) {
973 + if (!isset($atts['dataset']) && isset($atts['id'])) {
974 + $template = new Model_E2pdf_Template();
975 + $template->load($atts['id']);
976 + if ($template->get('extension') === 'formidable') {
977 + $entry_id = is_object($dataset_id) ? $dataset_id->id : $dataset_id;
978 + if ($entry_id) {
979 + if ($template->get('item') == '-2') {
980 + if ($template->get('item1') == $form->id) {
981 + $atts['dataset'] = $entry_id;
982 + $shortcode[3] .= ' dataset="' . $entry_id . '"';
983 + } elseif (!isset($atts['dataset2']) && $template->get('item2') == $form->id) {
984 + $atts['dataset2'] = $entry_id;
985 + $shortcode[3] .= ' dataset2="' . $entry_id . '"';
986 + }
987 + } else {
988 + $atts['dataset'] = $entry_id;
989 + $shortcode[3] .= ' dataset="' . $entry_id . '"';
990 + }
991 + }
771 992 }
772 993 }
994 + if (!isset($atts['apply'])) {
995 + $shortcode[3] .= ' apply="true"';
996 + }
997 + if (!isset($atts['filter'])) {
998 + $shortcode[3] .= ' filter="true"';
999 + }
1000 + $transient = false;
1001 + if (isset($atts['use_args_entry']) && $atts['use_args_entry'] == 'true' && $atts['dataset'] == $dataset_id) {
1002 + $dataset = 'tmp_' . $this->helper->load('encryption')->random_md5();
1003 + $transient = 'e2pdf_' . $dataset;
1004 + set_transient($transient, $args['entry'], 1800);
1005 + $atts['dataset'] = $dataset;
1006 + $shortcode[3] .= ' dataset="' . $dataset . '"';
1007 + }
1008 + $file = do_shortcode_tag($shortcode);
1009 + if ($file) {
1010 + $tmp = false;
1011 + if (substr($file, 0, 4) === 'tmp:') {
1012 + $file = substr($file, 4);
1013 + $tmp = true;
1014 + }
1015 + if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
1016 + if ($tmp) {
1017 + $this->helper->add('formidable_attachments', $file);
1018 + }
1019 + } else {
1020 + $this->helper->add('formidable_attachments', $file);
1021 + }
1022 + $attachments[] = $file;
1023 + }
1024 + if ($transient) {
1025 + delete_transient($transient);
1026 + }
773 1027 }
1028 + }
1029 + }
1030 + }
1031 + }
1032 + return $attachments;
1033 + }
774 1034
775 - $shortcode[3] .= " apply=\"true\" filter=\"true\"";
1035 + /**
1036 + * Decrypt protected uploaded file in a File Upload field
1037 + * @param string $html
1038 + * @param array $atts
1039 + * @return string $html
1040 + */
1041 + public function filter_frm_image_html_array($html, $atts) {
776 1042
777 - $file = do_shortcode_tag($shortcode);
1043 + if (isset($atts['decrypt']) &&
1044 + $atts['decrypt'] &&
1045 + class_exists('FrmProFileField') &&
1046 + class_exists('FrmProFilePayloadBuilder') &&
1047 + class_exists('FrmAppHelper')
1048 + ) {
778 1049
779 - if ($file) {
780 - $this->helper->add('formidable_attachments', $file);
781 - $attachments[] = $file;
782 - }
1050 + $id = $atts['media_id'];
1051 + $permission = isset($atts['permission']) && $atts['permission'] ? true : false;
1052 +
1053 + remove_filter('wp_get_attachment_url', 'FrmProFileField::filter_attachment_url');
1054 + remove_filter('wp_get_attachment_image_src', 'FrmProFileField::filter_attachment_image_src');
1055 +
1056 + $is_image = wp_attachment_is_image($id);
1057 + $url = $this->get_file_url($id, $is_image ? $atts['size'] : false);
1058 +
1059 + if (!FrmProFileField::user_has_permission($id) && !$permission) {
1060 + $frm_settings = FrmAppHelper::get_settings();
1061 + $html = $frm_settings->admin_permission;
1062 + } else {
1063 + $html = $atts['show_image'] ? wp_get_attachment_image($id, $atts['size'], !$is_image) : '';
1064 +
1065 + /* If show_filename=1 is included */
1066 + if ($atts['show_filename']) {
1067 + $label = $this->get_single_file_name($id);
1068 + if ($atts['show_image']) {
1069 + $html .= ' <span id="frm_media_' . absint($id) . '" class="frm_upload_label">' . $label . '</span>';
1070 + } else {
1071 + $html .= $label;
783 1072 }
784 1073 }
1074 +
1075 + /* If neither show_image or show_filename are included, get file URL */
1076 + if (!$html) {
1077 + $html = $url;
1078 + }
1079 +
1080 + /* If add_link=1 is included */
1081 + if ($atts['add_link'] || (!$is_image && $atts['add_link_for_non_image'])) {
1082 + $href = $is_image ? $this->get_file_url($id) : $url;
1083 + $target = !empty($atts['new_tab']) ? ' target="_blank"' : '';
1084 + $html = '<a href="' . esc_url($href) . '" class="frm_file_link"' . $target . '>' . $html . '</a>';
1085 + }
1086 +
1087 + if (!empty($atts['class'])) {
1088 + $html = str_replace(' class="', ' class="' . esc_attr($atts['class'] . ' '), $html);
1089 + }
1090 +
1091 + add_filter('wp_get_attachment_url', 'FrmProFileField::filter_attachment_url', 10, 2);
1092 + add_filter('wp_get_attachment_image_src', 'FrmProFileField::filter_attachment_image_src', 10, 4);
785 1093 }
786 1094 }
787 - return $attachments;
1095 +
1096 + return $html;
788 1097 }
789 1098
790 1099 /**
1100 + * @param int $id
1101 + * @param string|int[]|bool $size
1102 + * @param array $args supported keys include "url" and "leave_size_out_of_payload"
1103 + * @return string unprotected url to use for our specified file id and size.
1104 + */
1105 + public function get_file_url($id, $size = false, $args = array()) {
1106 + $url = isset($args['url']) ? $args['url'] : false;
1107 + $builder = new FrmProFilePayloadBuilder($id, $size, $url);
1108 + return $builder->get_url();
1109 + }
1110 +
1111 + /**
791 1112 * Remove Page Breaks for Visual Mapper
792 - *
793 - * @param array $fields - List of fields
794 - *
1113 + * @param array $fields - List of fields
795 1114 * @return array - Updated fields
796 1115 */
797 - function filter_remove_pagebreaks($fields) {
1116 + public function filter_remove_pagebreaks($fields) {
798 1117 foreach ((array) $fields as $field_key => $field) {
799 1118 if ($field->type == 'break') {
800 1119 unset($fields[$field_key]);
801 1120 }
@@ -802,29 +1121,34 @@
802 1121 }
803 1122 return $fields;
804 1123 }
805 1124
806 - function filter_frm_match_xml_form($edit_query, $form) {
1125 + public function filter_frm_match_xml_form($edit_query, $form) {
807 1126 if (isset($edit_query['created_at'])) {
808 - $edit_query['created_at'] = date('Y-m-d H:i:s', strtotime("now"));
1127 + $edit_query['created_at'] = date('Y-m-d H:i:s', strtotime('now'));
809 1128 }
810 1129 return $edit_query;
811 1130 }
812 1131
813 - function filter_frm_show_new_entry_page() {
1132 + public function filter_frm_show_new_entry_page() {
814 1133 return 'new';
815 1134 }
816 1135
1136 + public function filter_frm_pre_display_form($form) {
1137 + if (!empty($form->options['single_entry'])) {
1138 + $form->options['single_entry'] = 0;
1139 + }
1140 + return $form;
1141 + }
1142 +
817 1143 /**
818 1144 * Add options for Formidable extension
819 - *
820 - * @param array $options - List of options
821 - *
1145 + * @param array $options - List of options
822 1146 * @return array - Updated options list
823 1147 */
824 1148 public function filter_e2pdf_model_options_get_options_options($options = array()) {
825 1149 $options['formidable_group'] = array(
826 - 'name' => __('Formidable Forms', 'e2pdf'),
1150 + 'name' => 'Formidable Forms',
827 1151 'action' => 'extension',
828 1152 'group' => 'formidable_group',
829 1153 'options' => array(
830 1154 array(
@@ -829,15 +1153,24 @@
829 1153 'options' => array(
830 1154 array(
831 1155 'name' => __('Auto PDF and Visual Mapper', 'e2pdf'),
832 1156 'key' => 'e2pdf_formidable_use_keys',
833 - 'value' => get_option('e2pdf_formidable_use_keys') === false ? '0' : get_option('e2pdf_formidable_use_keys'),
1157 + 'value' => get_option('e2pdf_formidable_use_keys', '0'),
834 1158 'default_value' => '0',
835 1159 'type' => 'checkbox',
836 1160 'checkbox_value' => '1',
837 1161 'placeholder' => __('Use Field Keys instead Field IDs', 'e2pdf'),
838 1162 ),
839 - )
1163 + array(
1164 + 'name' => __('Filter', 'e2pdf'),
1165 + 'key' => 'e2pdf_formidable_disable_filter',
1166 + 'value' => get_option('e2pdf_formidable_disable_filter', '0'),
1167 + 'default_value' => '0',
1168 + 'type' => 'checkbox',
1169 + 'checkbox_value' => '1',
1170 + 'placeholder' => __('Disable Filter', 'e2pdf'),
1171 + ),
1172 + ),
840 1173 );
841 1174 return $options;
842 1175 }
843 1176
@@ -844,11 +1177,11 @@
844 1177 public function filter_e2pdf_controller_templates_import_options($options) {
845 1178
846 1179 if (isset($options['item'])) {
847 1180 $options['item']['options'][] = array(
848 - 'name' => __('Formidable Forms', 'e2pdf'),
1181 + 'name' => 'Formidable Forms',
849 1182 'key' => 'options[formidable_item_new_form]',
850 - 'value' => 0,
1183 + 'value' => 1,
851 1184 'default_value' => 0,
852 1185 'type' => 'radio',
853 1186 'li' => array(
854 1187 'class' => 'e2pdf-import-extension-option e2pdf-hide',
@@ -853,10 +1186,11 @@
853 1186 'li' => array(
854 1187 'class' => 'e2pdf-import-extension-option e2pdf-hide',
855 1188 ),
856 1189 'options' => array(
857 - 'Overwrite Web Form', 'Recreate Web Form'
858 - )
1190 + '1' => 'Recreate Web Form',
1191 + '0' => 'Overwrite Web Form',
1192 + ),
859 1193 );
860 1194 }
861 1195
862 1196 return $options;
@@ -864,11 +1198,10 @@
864 1198
865 1199 public function filter_e2pdf_controller_templates_backup_options($options, $template, $extension) {
866 1200
867 1201 if ($extension->loaded('formidable')) {
868 -
869 1202 $options['formidable'] = array(
870 - 'name' => __('Formidable', 'e2pdf'),
1203 + 'name' => 'Formidable Forms',
871 1204 'options' => array(
872 1205 array(
873 1206 'name' => __('Force shortcodes to use', 'e2pdf'),
874 1207 'key' => 'options[formidable_force_shortcodes]',
@@ -878,11 +1211,11 @@
878 1211 'options' => array(
879 1212 '0' => __('None', 'e2pdf'),
880 1213 '1' => __('Fields IDs', 'e2pdf'),
881 1214 '2' => __('Field Keys', 'e2pdf'),
882 - )
1215 + ),
883 1216 ),
884 - )
1217 + ),
885 1218 );
886 1219 }
887 1220
888 1221 return $options;
@@ -890,12 +1223,29 @@
890 1223
891 1224 public function filter_e2pdf_controller_templates_backup_pages($pages, $options, $template, $extension) {
892 1225
893 1226 if ($extension->loaded('formidable') && (isset($options['formidable_force_shortcodes']) && $options['formidable_force_shortcodes'])) {
1227 + $fields = array();
1228 + if ($template->get('item') == '-2') {
1229 + if ($template->get('item1')) {
1230 + $where = array('fi.form_id' => (int) $template->get('item1'));
1231 + $item_fields = FrmField::getAll($where, 'id ASC');
1232 + if ($item_fields) {
1233 + $fields = array_merge($fields, $item_fields);
1234 + }
1235 + }
1236 + if ($template->get('item2')) {
1237 + $where = array('fi.form_id' => (int) $template->get('item2'));
1238 + $item_fields = FrmField::getAll($where, 'id ASC');
1239 + if ($item_fields) {
1240 + $fields = array_merge($fields, $item_fields);
1241 + }
1242 + }
1243 + } else {
1244 + $where = array('fi.form_id' => (int) $template->get('item'));
1245 + $fields = FrmField::getAll($where, 'id ASC');
1246 + }
894 1247
895 - $where = array('fi.form_id' => (int) $template->get('item'));
896 - $fields = FrmField::getAll($where, 'id ASC');
897 -
898 1248 $search = array();
899 1249 $replace = array();
900 1250
901 1251 if ($options['formidable_force_shortcodes'] == '1') {
@@ -902,13 +1252,14 @@
902 1252 foreach ($fields as $field_key => $field) {
903 1253 if (isset($field->field_options['form_select']) && $field->field_options['form_select']) {
904 1254 $sub_where = array('fi.form_id' => $field->field_options['form_select']);
905 1255 $sub_fields = FrmField::getAll($sub_where, 'id ASC');
906 -
907 1256 foreach ($sub_fields as $sub_field_key => $sub_field) {
908 1257 $search[] = $sub_field->field_key;
909 1258 $replace[] = $sub_field->id;
910 1259 }
1260 + $search[] = $field->field_key;
1261 + $replace[] = $field->id;
911 1262 } else {
912 1263 $search[] = $field->field_key;
913 1264 $replace[] = $field->id;
914 1265 }
@@ -918,13 +1269,14 @@
918 1269
919 1270 if (isset($field->field_options['form_select']) && $field->field_options['form_select']) {
920 1271 $sub_where = array('fi.form_id' => $field->field_options['form_select']);
921 1272 $sub_fields = FrmField::getAll($sub_where, 'id ASC');
922 -
923 1273 foreach ($sub_fields as $sub_field_key => $sub_field) {
924 1274 $search[] = $sub_field->id;
925 1275 $replace[] = $sub_field->field_key;
926 1276 }
1277 + $search[] = $field->id;
1278 + $replace[] = $field->field_key;
927 1279 } else {
928 1280 $search[] = $field->id;
929 1281 $replace[] = $field->field_key;
930 1282 }
@@ -932,11 +1284,9 @@
932 1284 }
933 1285
934 1286 $search = array_reverse($search);
935 1287 $replace = array_reverse($replace);
936 -
937 1288 $list = array_combine($search, $replace);
938 -
939 1289 $pages = $this->pages_replace_shortcodes($pages, $list);
940 1290 }
941 1291
942 1292 return $pages;
@@ -941,13 +1291,102 @@
941 1291
942 1292 return $pages;
943 1293 }
944 1294
1295 + public function filter_e2pdf_controller_templates_backup_actions($actions, $options, $template, $extension) {
1296 +
1297 + if ($extension->loaded('formidable') && (isset($options['formidable_force_shortcodes']) && $options['formidable_force_shortcodes'])) {
1298 + $fields = array();
1299 + if ($template->get('item') == '-2') {
1300 + if ($template->get('item1')) {
1301 + $where = array('fi.form_id' => (int) $template->get('item1'));
1302 + $item_fields = FrmField::getAll($where, 'id ASC');
1303 + if ($item_fields) {
1304 + $fields = array_merge($fields, $item_fields);
1305 + }
1306 + }
1307 + if ($template->get('item2')) {
1308 + $where = array('fi.form_id' => (int) $template->get('item2'));
1309 + $item_fields = FrmField::getAll($where, 'id ASC');
1310 + if ($item_fields) {
1311 + $fields = array_merge($fields, $item_fields);
1312 + }
1313 + }
1314 + } else {
1315 + $where = array('fi.form_id' => (int) $template->get('item'));
1316 + $fields = FrmField::getAll($where, 'id ASC');
1317 + }
1318 +
1319 + $search = array();
1320 + $replace = array();
1321 +
1322 + if ($options['formidable_force_shortcodes'] == '1') {
1323 + foreach ($fields as $field_key => $field) {
1324 + if (isset($field->field_options['form_select']) && $field->field_options['form_select']) {
1325 + $sub_where = array('fi.form_id' => $field->field_options['form_select']);
1326 + $sub_fields = FrmField::getAll($sub_where, 'id ASC');
1327 + foreach ($sub_fields as $sub_field_key => $sub_field) {
1328 + $search[] = $sub_field->field_key;
1329 + $replace[] = $sub_field->id;
1330 + }
1331 + $search[] = $field->field_key;
1332 + $replace[] = $field->id;
1333 + } else {
1334 + $search[] = $field->field_key;
1335 + $replace[] = $field->id;
1336 + }
1337 + }
1338 + } elseif ($options['formidable_force_shortcodes'] == '2') {
1339 + foreach ($fields as $field_key => $field) {
1340 +
1341 + if (isset($field->field_options['form_select']) && $field->field_options['form_select']) {
1342 + $sub_where = array('fi.form_id' => $field->field_options['form_select']);
1343 + $sub_fields = FrmField::getAll($sub_where, 'id ASC');
1344 + foreach ($sub_fields as $sub_field_key => $sub_field) {
1345 + $search[] = $sub_field->id;
1346 + $replace[] = $sub_field->field_key;
1347 + }
1348 + $search[] = $field->id;
1349 + $replace[] = $field->field_key;
1350 + } else {
1351 + $search[] = $field->id;
1352 + $replace[] = $field->field_key;
1353 + }
1354 + }
1355 + }
1356 +
1357 + $search = array_reverse($search);
1358 + $replace = array_reverse($replace);
1359 + $list = array_combine($search, $replace);
1360 + $actions = $this->actions_replace_shortcodes($actions, $list);
1361 + }
1362 +
1363 + return $actions;
1364 + }
1365 +
945 1366 public function filter_e2pdf_controller_templates_backup_replace_shortcodes($value, $options, $template, $extension) {
946 1367
947 1368 if ($extension->loaded('formidable') && (isset($options['formidable_force_shortcodes']) && $options['formidable_force_shortcodes'])) {
948 - $where = array('fi.form_id' => (int) $template->get('item'));
949 - $fields = FrmField::getAll($where, 'id ASC');
1369 + $fields = array();
1370 + if ($template->get('item') == '-2') {
1371 + if ($template->get('item1')) {
1372 + $where = array('fi.form_id' => (int) $template->get('item1'));
1373 + $item_fields = FrmField::getAll($where, 'id ASC');
1374 + if ($item_fields) {
1375 + $fields = array_merge($fields, $item_fields);
1376 + }
1377 + }
1378 + if ($template->get('item2')) {
1379 + $where = array('fi.form_id' => (int) $template->get('item2'));
1380 + $item_fields = FrmField::getAll($where, 'id ASC');
1381 + if ($item_fields) {
1382 + $fields = array_merge($fields, $item_fields);
1383 + }
1384 + }
1385 + } else {
1386 + $where = array('fi.form_id' => (int) $template->get('item'));
1387 + $fields = FrmField::getAll($where, 'id ASC');
1388 + }
950 1389
951 1390 $search = array();
952 1391 $replace = array();
953 1392
@@ -955,13 +1394,14 @@
955 1394 foreach ($fields as $field_key => $field) {
956 1395 if (isset($field->field_options['form_select']) && $field->field_options['form_select']) {
957 1396 $sub_where = array('fi.form_id' => $field->field_options['form_select']);
958 1397 $sub_fields = FrmField::getAll($sub_where, 'id ASC');
959 -
960 1398 foreach ($sub_fields as $sub_field_key => $sub_field) {
961 1399 $search[] = $sub_field->field_key;
962 1400 $replace[] = $sub_field->id;
963 1401 }
1402 + $search[] = $field->field_key;
1403 + $replace[] = $field->id;
964 1404 } else {
965 1405 $search[] = $field->field_key;
966 1406 $replace[] = $field->id;
967 1407 }
@@ -971,13 +1411,14 @@
971 1411
972 1412 if (isset($field->field_options['form_select']) && $field->field_options['form_select']) {
973 1413 $sub_where = array('fi.form_id' => $field->field_options['form_select']);
974 1414 $sub_fields = FrmField::getAll($sub_where, 'id ASC');
975 -
976 1415 foreach ($sub_fields as $sub_field_key => $sub_field) {
977 1416 $search[] = $sub_field->id;
978 1417 $replace[] = $sub_field->field_key;
979 1418 }
1419 + $search[] = $field->id;
1420 + $replace[] = $field->field_key;
980 1421 } else {
981 1422 $search[] = $field->id;
982 1423 $replace[] = $field->field_key;
983 1424 }
@@ -985,11 +1426,9 @@
985 1426 }
986 1427
987 1428 $search = array_reverse($search);
988 1429 $replace = array_reverse($replace);
989 -
990 1430 $list = array_combine($search, $replace);
991 -
992 1431 $value = $this->replace_shortcodes($value, $list);
993 1432 }
994 1433
995 1434 return $value;
@@ -998,9 +1437,9 @@
998 1437 public function filter_e2pdf_controller_templates_import_pages($pages, $options, $xml, $template, $extension) {
999 1438
1000 1439 if ($extension->loaded('formidable') &&
1001 1440 $template->get('item') &&
1002 - $template->get('item') != (String) $xml->template->item &&
1441 + (($template->get('item') != '-2' && $template->get('item') != (string) $xml->template->item) || ($template->get('item') == '-2' && ($template->get('item1') != (string) $xml->template->item1 || $template->get('item2') != (string) $xml->template->item2))) &&
1003 1442 $xml->item->formidable &&
1004 1443 $options['item'] &&
1005 1444 class_exists('FrmXMLHelper') &&
1006 1445 class_exists('FrmField')
@@ -1006,35 +1445,33 @@
1006 1445 class_exists('FrmField')
1007 1446 ) {
1008 1447
1009 1448 $tmp = tempnam($this->helper->get('tmp_dir'), 'e2pdf');
1010 - file_put_contents($tmp, base64_decode((String) $xml->item->formidable));
1011 -
1012 - $dom = new DOMDocument;
1449 + file_put_contents($tmp, base64_decode((string) $xml->item->formidable), LOCK_EX);
1450 + $dom = new DOMDocument();
1013 1451 $success = $dom->loadXML(file_get_contents($tmp));
1014 -
1015 1452 $old_ids = array();
1016 1453 $old_keys = array();
1017 -
1018 1454 if ($success && function_exists('simplexml_import_dom')) {
1019 1455 $item_xml = simplexml_import_dom($dom);
1020 -
1021 1456 foreach ($item_xml->form as $form_key => $form) {
1022 - if ((String) $form->id == (String) $xml->template->item) {
1457 + if (($template->get('item') != '-2' && (string) $form->id == (string) $xml->template->item) || ($template->get('item') == '-2' && ((string) $form->id == (string) $xml->template->item1 || (string) $form->id == (string) $xml->template->item2))) {
1023 1458 foreach ($form->field as $field_key => $field) {
1024 - $field_options = @json_decode((String) $field->field_options, true);
1459 + $field_options = @json_decode((string) $field->field_options, true); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
1025 1460 if (isset($field_options['form_select']) && $field_options['form_select']) {
1026 1461 foreach ($item_xml->form as $sub_form_key => $sub_form) {
1027 - if ((String) $sub_form->id == $field_options['form_select']) {
1462 + if ((string) $sub_form->id == $field_options['form_select']) {
1028 1463 foreach ($sub_form->field as $sub_field_key => $sub_field) {
1029 - $old_ids[] = (String) $sub_field->id;
1030 - $old_keys[] = (String) $sub_field->field_key;
1464 + $old_ids[] = (string) $sub_field->id;
1465 + $old_keys[] = (string) $sub_field->field_key;
1031 1466 }
1032 1467 }
1033 1468 }
1469 + $old_ids[] = (string) $field->id;
1470 + $old_keys[] = (string) $field->field_key;
1034 1471 } else {
1035 - $old_ids[] = (String) $field->id;
1036 - $old_keys[] = (String) $field->field_key;
1472 + $old_ids[] = (string) $field->id;
1473 + $old_keys[] = (string) $field->field_key;
1037 1474 }
1038 1475 }
1039 1476 }
1040 1477 }
@@ -1039,11 +1476,30 @@
1039 1476 }
1040 1477 }
1041 1478 }
1042 1479
1043 - $where = array('fi.form_id' => (int) $template->get('item'));
1044 - $fields = FrmField::getAll($where, 'id ASC');
1480 + $fields = array();
1481 + if ($template->get('item') == '-2') {
1482 + if ($template->get('item1')) {
1483 + $where = array('fi.form_id' => (int) $template->get('item1'));
1484 + $item_fields = FrmField::getAll($where, 'id ASC');
1485 + if ($item_fields) {
1486 + $fields = array_merge($fields, $item_fields);
1487 + }
1488 + }
1045 1489
1490 + if ($template->get('item2')) {
1491 + $where = array('fi.form_id' => (int) $template->get('item2'));
1492 + $item_fields = FrmField::getAll($where, 'id ASC');
1493 + if ($item_fields) {
1494 + $fields = array_merge($fields, $item_fields);
1495 + }
1496 + }
1497 + } else {
1498 + $where = array('fi.form_id' => (int) $template->get('item'));
1499 + $fields = FrmField::getAll($where, 'id ASC');
1500 + }
1501 +
1046 1502 $new_ids = array();
1047 1503 $new_keys = array();
1048 1504
1049 1505 foreach ($fields as $field_key => $field) {
@@ -1050,13 +1506,14 @@
1050 1506
1051 1507 if (isset($field->field_options['form_select']) && $field->field_options['form_select']) {
1052 1508 $sub_where = array('fi.form_id' => (int) $field->field_options['form_select']);
1053 1509 $sub_fields = FrmField::getAll($sub_where, 'id ASC');
1054 -
1055 1510 foreach ($sub_fields as $sub_field_key => $sub_field) {
1056 1511 $new_ids[] = $sub_field->id;
1057 1512 $new_keys[] = $sub_field->field_key;
1058 1513 }
1514 + $new_ids[] = $field->id;
1515 + $new_keys[] = $field->field_key;
1059 1516 } else {
1060 1517 $new_ids[] = $field->id;
1061 1518 $new_keys[] = $field->field_key;
1062 1519 }
@@ -1082,13 +1539,13 @@
1082 1539
1083 1540 return $pages;
1084 1541 }
1085 1542
1086 - public function filter_e2pdf_controller_templates_import_replace_shortcodes($value, $options, $xml, $template, $extension) {
1543 + public function filter_e2pdf_controller_templates_import_actions($actions, $options, $xml, $template, $extension) {
1087 1544
1088 1545 if ($extension->loaded('formidable') &&
1089 1546 $template->get('item') &&
1090 - $template->get('item') != (String) $xml->template->item &&
1547 + (($template->get('item') != '-2' && $template->get('item') != (string) $xml->template->item) || ($template->get('item') == '-2' && ($template->get('item1') != (string) $xml->template->item1 || $template->get('item2') != (string) $xml->template->item2))) &&
1091 1548 $xml->item->formidable &&
1092 1549 $options['item'] &&
1093 1550 class_exists('FrmXMLHelper') &&
1094 1551 class_exists('FrmField')
@@ -1094,11 +1551,11 @@
1094 1551 class_exists('FrmField')
1095 1552 ) {
1096 1553
1097 1554 $tmp = tempnam($this->helper->get('tmp_dir'), 'e2pdf');
1098 - file_put_contents($tmp, base64_decode((String) $xml->item->formidable));
1555 + file_put_contents($tmp, base64_decode((string) $xml->item->formidable), LOCK_EX);
1099 1556
1100 - $dom = new DOMDocument;
1557 + $dom = new DOMDocument();
1101 1558 $success = $dom->loadXML(file_get_contents($tmp));
1102 1559
1103 1560 $old_ids = array();
1104 1561 $old_keys = array();
@@ -1106,23 +1563,25 @@
1106 1563 if ($success && function_exists('simplexml_import_dom')) {
1107 1564 $item_xml = simplexml_import_dom($dom);
1108 1565
1109 1566 foreach ($item_xml->form as $form_key => $form) {
1110 - if ((String) $form->id == (String) $xml->template->item) {
1567 + if (($template->get('item') != '-2' && (string) $form->id == (string) $xml->template->item) || ($template->get('item') == '-2' && ((string) $form->id == (string) $xml->template->item1 || (string) $form->id == (string) $xml->template->item2))) {
1111 1568 foreach ($form->field as $field_key => $field) {
1112 - $field_options = @json_decode((String) $field->field_options, true);
1569 + $field_options = @json_decode((string) $field->field_options, true); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
1113 1570 if (isset($field_options['form_select']) && $field_options['form_select']) {
1114 1571 foreach ($item_xml->form as $sub_form_key => $sub_form) {
1115 - if ((String) $sub_form->id == $field_options['form_select']) {
1572 + if ((string) $sub_form->id == $field_options['form_select']) {
1116 1573 foreach ($sub_form->field as $sub_field_key => $sub_field) {
1117 - $old_ids[] = (String) $sub_field->id;
1118 - $old_keys[] = (String) $sub_field->field_key;
1574 + $old_ids[] = (string) $sub_field->id;
1575 + $old_keys[] = (string) $sub_field->field_key;
1119 1576 }
1120 1577 }
1121 1578 }
1579 + $old_ids[] = (string) $field->id;
1580 + $old_keys[] = (string) $field->field_key;
1122 1581 } else {
1123 - $old_ids[] = (String) $field->id;
1124 - $old_keys[] = (String) $field->field_key;
1582 + $old_ids[] = (string) $field->id;
1583 + $old_keys[] = (string) $field->field_key;
1125 1584 }
1126 1585 }
1127 1586 }
1128 1587 }
@@ -1127,11 +1586,31 @@
1127 1586 }
1128 1587 }
1129 1588 }
1130 1589
1131 - $where = array('fi.form_id' => (int) $template->get('item'));
1132 - $fields = FrmField::getAll($where, 'id ASC');
1590 + $fields = array();
1591 + if ($template->get('item') == '-2') {
1592 + if ($template->get('item1')) {
1593 + $where = array('fi.form_id' => (int) $template->get('item1'));
1594 + $item_fields = FrmField::getAll($where, 'id ASC');
1595 + if ($item_fields) {
1596 + $fields = array_merge($fields, $item_fields);
1597 + }
1598 + }
1133 1599
1600 + if ($template->get('item2')) {
1601 + $where = array('fi.form_id' => (int) $template->get('item2'));
1602 + $item_fields = FrmField::getAll($where, 'id ASC');
1603 +
1604 + if ($item_fields) {
1605 + $fields = array_merge($fields, $item_fields);
1606 + }
1607 + }
1608 + } else {
1609 + $where = array('fi.form_id' => (int) $template->get('item'));
1610 + $fields = FrmField::getAll($where, 'id ASC');
1611 + }
1612 +
1134 1613 $new_ids = array();
1135 1614 $new_keys = array();
1136 1615
1137 1616 foreach ($fields as $field_key => $field) {
@@ -1138,13 +1617,129 @@
1138 1617
1139 1618 if (isset($field->field_options['form_select']) && $field->field_options['form_select']) {
1140 1619 $sub_where = array('fi.form_id' => (int) $field->field_options['form_select']);
1141 1620 $sub_fields = FrmField::getAll($sub_where, 'id ASC');
1621 + foreach ($sub_fields as $sub_field_key => $sub_field) {
1622 + $new_ids[] = $sub_field->id;
1623 + $new_keys[] = $sub_field->field_key;
1624 + }
1625 + $new_ids[] = $field->id;
1626 + $new_keys[] = $field->field_key;
1627 + } else {
1628 + $new_ids[] = $field->id;
1629 + $new_keys[] = $field->field_key;
1630 + }
1631 + }
1142 1632
1633 + if (count($old_ids) === count($new_ids)) {
1634 + $old_ids = array_reverse($old_ids);
1635 + $new_ids = array_reverse($new_ids);
1636 +
1637 + $old_keys = array_reverse($old_keys);
1638 + $new_keys = array_reverse($new_keys);
1639 +
1640 + $list_ids = array_combine($old_ids, $new_ids);
1641 + $actions = $this->actions_replace_shortcodes($actions, $list_ids);
1642 +
1643 + $list_keys = array_combine($old_keys, $new_keys);
1644 + $actions = $this->pages_replace_shortcodes($actions, $list_keys);
1645 + }
1646 + unset($dom);
1647 + unlink($tmp);
1648 + }
1649 +
1650 + return $actions;
1651 + }
1652 +
1653 + public function filter_frm_graph_shortcode_custom_html($html, $data) {
1654 + if (apply_filters('e2pdf_pdf_render', false)) {
1655 + return serialize($data['graph_data']);
1656 + }
1657 + return $html;
1658 + }
1659 +
1660 + public function filter_e2pdf_controller_templates_import_replace_shortcodes($value, $options, $xml, $template, $extension) {
1661 +
1662 + if ($extension->loaded('formidable') &&
1663 + $template->get('item') &&
1664 + (($template->get('item') != '-2' && $template->get('item') != (string) $xml->template->item) || ($template->get('item') == '-2' && ($template->get('item1') != (string) $xml->template->item1 || $template->get('item2') != (string) $xml->template->item2))) &&
1665 + $xml->item->formidable &&
1666 + $options['item'] &&
1667 + class_exists('FrmXMLHelper') &&
1668 + class_exists('FrmField')
1669 + ) {
1670 +
1671 + $tmp = tempnam($this->helper->get('tmp_dir'), 'e2pdf');
1672 + file_put_contents($tmp, base64_decode((string) $xml->item->formidable), LOCK_EX);
1673 +
1674 + $dom = new DOMDocument();
1675 + $success = $dom->loadXML(file_get_contents($tmp));
1676 +
1677 + $old_ids = array();
1678 + $old_keys = array();
1679 +
1680 + if ($success && function_exists('simplexml_import_dom')) {
1681 + $item_xml = simplexml_import_dom($dom);
1682 + foreach ($item_xml->form as $form_key => $form) {
1683 + if (($template->get('item') != '-2' && (string) $form->id == (string) $xml->template->item) || ($template->get('item') == '-2' && ((string) $form->id == (string) $xml->template->item1 || (string) $form->id == (string) $xml->template->item2))) {
1684 + foreach ($form->field as $field_key => $field) {
1685 + $field_options = @json_decode((string) $field->field_options, true); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
1686 + if (isset($field_options['form_select']) && $field_options['form_select']) {
1687 + foreach ($item_xml->form as $sub_form_key => $sub_form) {
1688 + if ((string) $sub_form->id == $field_options['form_select']) {
1689 + foreach ($sub_form->field as $sub_field_key => $sub_field) {
1690 + $old_ids[] = (string) $sub_field->id;
1691 + $old_keys[] = (string) $sub_field->field_key;
1692 + }
1693 + }
1694 + }
1695 + $old_ids[] = (string) $field->id;
1696 + $old_keys[] = (string) $field->field_key;
1697 + } else {
1698 + $old_ids[] = (string) $field->id;
1699 + $old_keys[] = (string) $field->field_key;
1700 + }
1701 + }
1702 + }
1703 + }
1704 + }
1705 +
1706 + $fields = array();
1707 + if ($template->get('item') == '-2') {
1708 + if ($template->get('item1')) {
1709 + $where = array('fi.form_id' => (int) $template->get('item1'));
1710 + $item_fields = FrmField::getAll($where, 'id ASC');
1711 + if ($item_fields) {
1712 + $fields = array_merge($fields, $item_fields);
1713 + }
1714 + }
1715 +
1716 + if ($template->get('item2')) {
1717 + $where = array('fi.form_id' => (int) $template->get('item2'));
1718 + $item_fields = FrmField::getAll($where, 'id ASC');
1719 +
1720 + if ($item_fields) {
1721 + $fields = array_merge($fields, $item_fields);
1722 + }
1723 + }
1724 + } else {
1725 + $where = array('fi.form_id' => (int) $template->get('item'));
1726 + $fields = FrmField::getAll($where, 'id ASC');
1727 + }
1728 +
1729 + $new_ids = array();
1730 + $new_keys = array();
1731 +
1732 + foreach ($fields as $field_key => $field) {
1733 + if (isset($field->field_options['form_select']) && $field->field_options['form_select']) {
1734 + $sub_where = array('fi.form_id' => (int) $field->field_options['form_select']);
1735 + $sub_fields = FrmField::getAll($sub_where, 'id ASC');
1143 1736 foreach ($sub_fields as $sub_field_key => $sub_field) {
1144 1737 $new_ids[] = $sub_field->id;
1145 1738 $new_keys[] = $sub_field->field_key;
1146 1739 }
1740 + $new_ids[] = $field->id;
1741 + $new_keys[] = $field->field_key;
1147 1742 } else {
1148 1743 $new_ids[] = $field->id;
1149 1744 $new_keys[] = $field->field_key;
1150 1745 }
@@ -1167,9 +1762,8 @@
1167 1762
1168 1763 unset($dom);
1169 1764 unlink($tmp);
1170 1765 }
1171 -
1172 1766 return $value;
1173 1767 }
1174 1768
1175 1769 /**
@@ -1177,9 +1771,8 @@
1177 1771 */
1178 1772 public function action_frm_notification() {
1179 1773
1180 1774 $files = $this->helper->get('formidable_attachments');
1181 -
1182 1775 if (is_array($files) && !empty($files)) {
1183 1776 foreach ($files as $key => $file) {
1184 1777 $this->helper->delete_dir(dirname($file) . '/');
1185 1778 }
@@ -1187,21 +1780,35 @@
1187 1780 }
1188 1781 }
1189 1782
1190 1783 /**
1191 - * Fix for user_id shortcode
1192 - *
1193 - * @param object $template - Current Template
1194 - * @param object $extension - Loaded extension
1195 - *
1784 + * Fix to render E2Pdf shortcodes with beforeContent and afterContent inside Formidable Form View Preview
1196 1785 */
1197 - public function action_e2pdf_model_template_fill_pre($template, $extension) {
1198 - if ($extension->loaded("formidable")) {
1199 - if ($extension->get('dataset') && class_exists("FrmEntry") && is_admin()) {
1200 - $extension->set('user_id', get_current_user_id());
1201 - $entry = FrmEntry::getOne($extension->get('dataset'));
1202 - if ($entry) {
1203 - set_current_user($entry->user_id);
1786 + public function action_check_ajax_referer($action, $result) {
1787 + if ($action == 'frm_ajax' && false !== $result && isset($_POST['action']) && $_POST['action'] == 'frm_views_process_box_preview') {
1788 + if (isset($_POST['beforeContent']) && $_POST['beforeContent']) {
1789 + $_POST['beforeContent'] = $this->filter_view_preview_before_after_content($_POST['beforeContent']);
1790 + }
1791 + if (isset($_POST['afterContent']) && $_POST['afterContent']) {
1792 + $_POST['afterContent'] = $this->filter_view_preview_before_after_content($_POST['afterContent']);
1793 + }
1794 + }
1795 + }
1796 +
1797 + public function action_frm_default_value($entry_id, $form_id) {
1798 + global $wpdb;
1799 + if ($form_id) {
1800 + $fields = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . $wpdb->prefix . 'frm_fields` WHERE form_id = %d AND (default_value LIKE %s OR default_value LIKE %s)', $form_id, '%[e2pdf-download%', '%[e2pdf-save%'));
1801 + if (!empty($fields)) {
1802 + foreach ($fields as $key => $field) {
1803 + $meta = FrmEntryMeta::get_entry_meta_by_field($entry_id, $field->id);
1804 + if ($meta === null) {
1805 + $new_value = $this->filter_frm_content($field->default_value, FrmForm::getOne($form_id), $entry_id);
1806 + $added = FrmEntryMeta::add_entry_meta($entry_id, $field->id, null, $new_value);
1807 + if (!$added) {
1808 + FrmEntryMeta::update_entry_meta($entry_id, $field->id, null, $new_value);
1809 + }
1810 + }
1204 1811 }
1205 1812 }
1206 1813 }
1207 1814 }
@@ -1206,25 +1813,55 @@
1206 1813 }
1207 1814 }
1208 1815
1209 1816 /**
1210 - * Revert Fix for user_id shortcode
1211 - *
1212 - * @param object $template - Current Template
1213 - * @param object $extension - Loaded extension
1214 - *
1817 + * Filter "get" shortcodes with beforeContent and afterContent inside Formidable Form View Preview
1818 + * @param type $content
1819 + * @return type
1215 1820 */
1216 - public function action_e2pdf_model_template_fill_after($template, $extension) {
1217 - if ($extension->loaded("formidable")) {
1218 - if ($extension->get('dataset') && class_exists("FrmEntry") && is_admin()) {
1219 - set_current_user($extension->get('user_id'));
1821 + public function filter_view_preview_before_after_content($content) {
1822 +
1823 + if (false !== strpos($content, '[get ') && (
1824 + false !== strpos($content, 'e2pdf-download') ||
1825 + false !== strpos($content, 'e2pdf-save') ||
1826 + false !== strpos($content, 'e2pdf-view') ||
1827 + false !== strpos($content, 'e2pdf-adobesign') ||
1828 + false !== strpos($content, 'e2pdf-zapier') ||
1829 + false !== strpos($content, 'e2pdf-attachment')
1830 + )) {
1831 + $shortcode_tags = array(
1832 + 'get',
1833 + );
1834 + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
1835 + $tagnames = array_intersect($shortcode_tags, $matches[1]);
1836 + if (!empty($tagnames)) {
1837 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
1838 + foreach ($shortcodes[0] as $key => $shortcode_value) {
1839 + $content = str_replace($shortcode_value, $this->convert_shortcodes($shortcode_value), $content);
1840 + }
1220 1841 }
1221 1842 }
1843 + return $content;
1222 1844 }
1223 1845
1846 + public function filter_filter_content($content, $form, $entry = false) {
1847 + $content = FrmFormsController::replace_form_name_shortcodes($content, $form);
1848 + if (!$entry) {
1849 + return $content;
1850 + }
1851 + if (is_object($form)) {
1852 + $form = $form->id;
1853 + }
1854 + if (!empty($entry->parent_entry)) {
1855 + $form = $entry->parent_entry->form_id;
1856 + }
1857 + $shortcodes = $this->get('cached_shortcodes');
1858 + $content = apply_filters('frm_replace_content_shortcodes', $content, $entry, $shortcodes);
1859 + return $content;
1860 + }
1861 +
1224 1862 /**
1225 1863 * Auto Generate of Template for this extension
1226 - *
1227 1864 * @return array - List of elements
1228 1865 */
1229 1866 public function auto() {
1230 1867
@@ -1233,73 +1870,75 @@
1233 1870
1234 1871 $form_id = $this->get('item');
1235 1872
1236 1873 $fields = array();
1237 -
1238 1874 if (class_exists('FrmField')) {
1239 - $fields = FrmField::get_all_for_form($form_id);
1875 + $fields = FrmField::get_all_for_form($form_id, '', 'include', 'include');
1240 1876 }
1241 1877
1242 1878 if ($fields) {
1243 1879 foreach ($fields as $key => $field) {
1880 + $field_id = get_option('e2pdf_formidable_use_keys', '0') ? $field->field_key : $field->id;
1244 1881
1245 - $field_id = get_option('e2pdf_formidable_use_keys') ? $field->field_key : $field->id;
1246 -
1247 - if ($field->type === 'lookup' || $field->type === 'data') {
1248 -
1249 - $dynamic_field_id = false;
1250 - $dynamic_form_id = false;
1251 -
1252 - if ($field->type === 'lookup' && isset($field->field_options['get_values_field']) && isset($field->field_options['get_values_form'])) {
1253 -
1254 - $dynamic_form_id = $field->field_options['get_values_form'];
1255 - $dynamic_field_id = $field->field_options['get_values_field'];
1256 -
1257 - if (get_option('e2pdf_formidable_use_keys')) {
1258 - $dynamic_field_data = FrmField::getOne($dynamic_field_id);
1259 -
1260 - if ($dynamic_field_data) {
1261 - $dynamic_field_id = $dynamic_field_data->field_key;
1882 + if ($field->type === 'lookup' && isset($field->field_options['data_type'])) {
1883 + if ($field->field_options['data_type'] == 'select') {
1884 + $field->options = array(
1885 + '[e2pdf-frm-lookup-values id="' . $field_id . '"]',
1886 + );
1887 + } elseif ($field->field_options['data_type'] == 'radio' || $field->field_options['data_type'] == 'checkbox') {
1888 + $options = array();
1889 + $frm_filter = false;
1890 + if (class_exists('FrmProFieldsHelper') && method_exists('FrmProFieldsHelper', 'add_default_field_settings')) {
1891 + if (!has_filter('frm_default_field_options', 'FrmProFieldsHelper::add_default_field_settings')) {
1892 + add_filter('frm_default_field_options', 'FrmProFieldsHelper::add_default_field_settings', 10, 2);
1893 + $frm_filter = true;
1262 1894 }
1263 1895 }
1264 - } elseif ($field->type === 'data' && isset($field->field_options['form_select']) && $field->field_options['form_select'] !== 'taxonomy' && class_exists('FrmField')) {
1265 1896
1266 - $dynamic_field_id = $field->field_options['form_select'];
1267 - $dynamic_field_data = FrmField::getOne($dynamic_field_id);
1268 -
1269 - if ($dynamic_field_data) {
1270 - $dynamic_form_id = $dynamic_field_data->form_id;
1271 -
1272 - if (get_option('e2pdf_formidable_use_keys')) {
1273 - $dynamic_field_id = $dynamic_field_data->field_key;
1274 - }
1897 + $args = array();
1898 + $field_array = FrmAppHelper::start_field_array($field);
1899 + FrmFieldsHelper::prepare_new_front_field($field_array, $field, $args);
1900 + $field_array = array_merge($field->field_options, $field_array);
1901 + if (isset($field_array['options']) && is_array($field_array['options'])) {
1902 + $options = $field_array['options'];
1275 1903 }
1904 + if ($frm_filter) {
1905 + remove_filter('frm_default_field_options', 'FrmProFieldsHelper::add_default_field_settings');
1906 + }
1907 + $field->options = $options;
1276 1908 }
1277 -
1278 1909 $field->type = $field->field_options['data_type'];
1279 - if ($dynamic_field_id && $dynamic_form_id) {
1280 - if ($field->field_options['data_type'] == 'select') {
1910 + } elseif ($field->type === 'data' && isset($field->field_options['data_type'])) {
1911 + if ($field->field_options['data_type'] == 'select') {
1912 + $field->options = array(
1913 + '[e2pdf-frm-data-values id="' . $field_id . '"]',
1914 + );
1915 + } elseif ($field->field_options['data_type'] == 'radio' || $field->field_options['data_type'] == 'checkbox') {
1916 + $options = array();
1917 + $frm_filter = false;
1918 + if (class_exists('FrmProFieldsHelper') && method_exists('FrmProFieldsHelper', 'add_default_field_settings')) {
1919 + if (!has_filter('frm_default_field_options', 'FrmProFieldsHelper::add_default_field_settings')) {
1920 + add_filter('frm_default_field_options', 'FrmProFieldsHelper::add_default_field_settings', 10, 2);
1921 + $frm_filter = true;
1922 + }
1923 + }
1281 1924
1282 - $field->options = array(
1283 - "[e2pdf-frm-entry-values id='$dynamic_form_id' field_id='$dynamic_field_id']"
1284 - );
1285 - } elseif ($field->field_options['data_type'] == 'radio' || $field->field_options['data_type'] == 'checkbox') {
1925 + $args = array();
1926 + $field->field_options['restrict'] = '0';
1927 + $field_array = FrmAppHelper::start_field_array($field);
1928 + FrmFieldsHelper::prepare_new_front_field($field_array, $field, $args);
1286 1929
1287 - $options = array();
1930 + $field_array = array_merge($field->field_options, $field_array);
1931 + if (isset($field_array['options']) && is_array($field_array['options'])) {
1932 + $options = $field_array['options'];
1933 + }
1288 1934
1289 - if (class_exists('FrmEntry') && class_exists('FrmEntryMeta')) {
1290 - $where = array(
1291 - 'it.form_id' => $dynamic_form_id
1292 - );
1293 -
1294 - $entries_tmp = FrmEntry::getAll($where, ' ORDER BY id ASC');
1295 - foreach ($entries_tmp as $key => $entry) {
1296 - $options[] = FrmEntryMeta::get_meta_value($entry, $dynamic_field_id);
1297 - }
1298 - }
1299 - $field->options = $options;
1935 + if ($frm_filter) {
1936 + remove_filter('frm_default_field_options', 'FrmProFieldsHelper::add_default_field_settings');
1300 1937 }
1938 + $field->options = $options;
1301 1939 }
1940 + $field->type = $field->field_options['data_type'];
1302 1941 }
1303 1942
1304 1943 /*
1305 1944 * Repeatable fields Field ID modification
@@ -1305,101 +1944,136 @@
1305 1944 * Repeatable fields Field ID modification
1306 1945 * @since 0.01.42
1307 1946 */
1308 1947 if ($field->type !== 'lookup' && $field->type !== 'data' && isset($field->form_id) && $field->form_id != $form_id) {
1309 - $field_id = $field_id . ":1";
1948 + $field_id = $field_id . ':1';
1310 1949 }
1311 1950
1312 1951 switch ($field->type) {
1952 + case 'divider':
1953 + if ($field->name) {
1954 + $elements[] = $this->auto_field(
1955 + $field,
1956 + array(
1957 + 'type' => 'e2pdf-html',
1958 + 'block' => true,
1959 + 'properties' => array(
1960 + 'top' => '20',
1961 + 'left' => '20',
1962 + 'right' => '20',
1963 + 'width' => '100%',
1964 + 'height' => 'auto',
1965 + 'value' => '<h2>' . $field->name . '</h2>',
1966 + ),
1967 + )
1968 + );
1969 + }
1970 + break;
1313 1971 case 'html':
1314 1972 if ($field->description) {
1315 - $elements[] = $this->auto_field($field, array(
1316 - 'type' => 'e2pdf-html',
1317 - 'block' => true,
1318 - 'properties' => array(
1319 - 'top' => '20',
1320 - 'left' => '20',
1321 - 'right' => '20',
1322 - 'width' => '100%',
1323 - 'height' => 'auto',
1324 - 'value' => $field->description,
1325 - )
1326 - ));
1973 + $elements[] = $this->auto_field(
1974 + $field,
1975 + array(
1976 + 'type' => 'e2pdf-html',
1977 + 'block' => true,
1978 + 'properties' => array(
1979 + 'top' => '20',
1980 + 'left' => '20',
1981 + 'right' => '20',
1982 + 'width' => '100%',
1983 + 'height' => 'auto',
1984 + 'value' => $field->description,
1985 + ),
1986 + )
1987 + );
1327 1988 }
1328 1989 break;
1329 -
1330 1990 case 'signature':
1331 - $elements[] = $this->auto_field($field, array(
1332 - 'type' => 'e2pdf-html',
1333 - 'block' => true,
1334 - 'properties' => array(
1335 - 'top' => '20',
1336 - 'left' => '20',
1337 - 'right' => '20',
1338 - 'width' => '100%',
1339 - 'height' => 'auto',
1340 - 'value' => $field->name,
1341 - )
1342 - ));
1991 + $elements[] = $this->auto_field(
1992 + $field,
1993 + array(
1994 + 'type' => 'e2pdf-html',
1995 + 'block' => true,
1996 + 'properties' => array(
1997 + 'top' => '20',
1998 + 'left' => '20',
1999 + 'right' => '20',
2000 + 'width' => '100%',
2001 + 'height' => 'auto',
2002 + 'value' => $field->name,
2003 + ),
2004 + )
2005 + );
1343 2006
1344 - $elements[] = $this->auto_field($field, array(
1345 - 'type' => 'e2pdf-signature',
1346 - 'properties' => array(
1347 - 'top' => '5',
1348 - 'width' => '100%',
1349 - 'height' => '150',
1350 - 'scale' => '1',
1351 - 'dimension' => '1',
1352 - 'value' => "[$field_id]"
1353 - )
1354 - ));
2007 + $elements[] = $this->auto_field(
2008 + $field,
2009 + array(
2010 + 'type' => 'e2pdf-signature',
2011 + 'properties' => array(
2012 + 'top' => '5',
2013 + 'width' => '100%',
2014 + 'height' => '150',
2015 + 'dimension' => '1',
2016 + 'block_dimension' => '1',
2017 + 'value' => '[' . $field_id . ']',
2018 + ),
2019 + )
2020 + );
1355 2021 break;
1356 -
1357 2022 case 'scale':
1358 - $elements[] = $this->auto_field($field, array(
1359 - 'type' => 'e2pdf-html',
1360 - 'block' => true,
1361 - 'properties' => array(
1362 - 'top' => '20',
1363 - 'left' => '20',
1364 - 'right' => '20',
1365 - 'width' => '100%',
1366 - 'height' => 'auto',
1367 - 'value' => $field->name,
1368 - )
1369 - ));
2023 + $elements[] = $this->auto_field(
2024 + $field,
2025 + array(
2026 + 'type' => 'e2pdf-html',
2027 + 'block' => true,
2028 + 'properties' => array(
2029 + 'top' => '20',
2030 + 'left' => '20',
2031 + 'right' => '20',
2032 + 'width' => '100%',
2033 + 'height' => 'auto',
2034 + 'value' => $field->name,
2035 + ),
2036 + )
2037 + );
1370 2038
1371 2039 if (isset($field->options) && is_array($field->options)) {
1372 2040 $start = true;
1373 2041 foreach ($field->options as $opt_key => $option) {
1374 2042 if (is_array($option)) {
1375 - $elements[] = $this->auto_field($field, array(
1376 - 'type' => 'e2pdf-radio',
1377 - 'float' => $start ? false : true,
1378 - 'properties' => array(
1379 - 'top' => $start ? '5' : '0',
1380 - 'left' => $start ? '0' : '5',
1381 - 'width' => 'auto',
1382 - 'height' => 'auto',
1383 - 'value' => "[$field_id]",
1384 - 'option' => $option['value'],
1385 - 'group' => "group_" . $field_id
1386 - )
1387 - ));
2043 + $elements[] = $this->auto_field(
2044 + $field,
2045 + array(
2046 + 'type' => 'e2pdf-radio',
2047 + 'float' => $start ? false : true,
2048 + 'properties' => array(
2049 + 'top' => $start ? '5' : '0',
2050 + 'left' => $start ? '0' : '5',
2051 + 'width' => 'auto',
2052 + 'height' => 'auto',
2053 + 'value' => '[' . $field_id . ']',
2054 + 'option' => $option['value'],
2055 + 'group' => 'group_' . $field_id,
2056 + ),
2057 + )
2058 + );
1388 2059 } else {
1389 - $elements[] = $this->auto_field($field, array(
1390 - 'type' => 'e2pdf-radio',
1391 - 'float' => $start ? false : true,
1392 - 'properties' => array(
1393 - 'top' => $start ? '5' : '0',
1394 - 'left' => $start ? '0' : '5',
1395 - 'width' => 'auto',
1396 - 'height' => 'auto',
1397 - 'value' => "[$field_id]",
1398 - 'option' => $option,
1399 - 'group' => "group_" . $field_id
1400 - )
1401 - ));
2060 + $elements[] = $this->auto_field(
2061 + $field,
2062 + array(
2063 + 'type' => 'e2pdf-radio',
2064 + 'float' => $start ? false : true,
2065 + 'properties' => array(
2066 + 'top' => $start ? '5' : '0',
2067 + 'left' => $start ? '0' : '5',
2068 + 'width' => 'auto',
2069 + 'height' => 'auto',
2070 + 'value' => '[' . $field_id . ']',
2071 + 'option' => $option,
2072 + 'group' => 'group_' . $field_id,
2073 + ),
2074 + )
2075 + );
1402 2076 }
1403 2077
1404 2078 $start = false;
1405 2079 }
@@ -1407,65 +2081,74 @@
1407 2081 $start = true;
1408 2082 foreach ($field->options as $opt_key => $option) {
1409 2083 if (is_array($option)) {
1410 2084
1411 - $elements[] = $this->auto_field($field, array(
1412 - 'type' => 'e2pdf-html',
1413 - 'float' => $start ? false : true,
1414 - 'properties' => array(
1415 - 'top' => $start ? '5' : '0',
1416 - 'left' => $start ? '0' : '5',
1417 - 'width' => 'auto',
1418 - 'height' => 'auto',
1419 - 'value' => $option['label'],
1420 - 'text_align' => 'center',
1421 - )
1422 - ));
2085 + $elements[] = $this->auto_field(
2086 + $field,
2087 + array(
2088 + 'type' => 'e2pdf-html',
2089 + 'float' => $start ? false : true,
2090 + 'properties' => array(
2091 + 'top' => $start ? '5' : '0',
2092 + 'left' => $start ? '0' : '5',
2093 + 'width' => 'auto',
2094 + 'height' => 'auto',
2095 + 'value' => $option['label'],
2096 + 'text_align' => 'center',
2097 + ),
2098 + )
2099 + );
1423 2100 } else {
1424 - $elements[] = $this->auto_field($field, array(
1425 - 'type' => 'e2pdf-html',
1426 - 'float' => $start ? false : true,
1427 - 'properties' => array(
1428 - 'top' => $start ? '5' : '0',
1429 - 'left' => $start ? '0' : '5',
1430 - 'width' => 'auto',
1431 - 'height' => 'auto',
1432 - 'value' => $option,
1433 - 'text_align' => 'center',
1434 - )
1435 - ));
2101 + $elements[] = $this->auto_field(
2102 + $field,
2103 + array(
2104 + 'type' => 'e2pdf-html',
2105 + 'float' => $start ? false : true,
2106 + 'properties' => array(
2107 + 'top' => $start ? '5' : '0',
2108 + 'left' => $start ? '0' : '5',
2109 + 'width' => 'auto',
2110 + 'height' => 'auto',
2111 + 'value' => $option,
2112 + 'text_align' => 'center',
2113 + ),
2114 + )
2115 + );
1436 2116 }
1437 2117 $start = false;
1438 2118 }
1439 2119 }
1440 2120 break;
1441 -
1442 2121 case 'rte':
1443 - $elements[] = $this->auto_field($field, array(
1444 - 'type' => 'e2pdf-html',
1445 - 'block' => true,
1446 - 'properties' => array(
1447 - 'top' => '20',
1448 - 'left' => '20',
1449 - 'right' => '20',
1450 - 'width' => '100%',
1451 - 'height' => 'auto',
1452 - 'value' => $field->name,
1453 - )
1454 - ));
2122 + $elements[] = $this->auto_field(
2123 + $field,
2124 + array(
2125 + 'type' => 'e2pdf-html',
2126 + 'block' => true,
2127 + 'properties' => array(
2128 + 'top' => '20',
2129 + 'left' => '20',
2130 + 'right' => '20',
2131 + 'width' => '100%',
2132 + 'height' => 'auto',
2133 + 'value' => $field->name,
2134 + ),
2135 + )
2136 + );
1455 2137
1456 - $elements[] = $this->auto_field($field, array(
1457 - 'type' => 'e2pdf-html',
1458 - 'properties' => array(
1459 - 'top' => '5',
1460 - 'width' => '100%',
1461 - 'height' => '150',
1462 - 'value' => "[$field_id wpautop=0]"
1463 - )
1464 - ));
2138 + $elements[] = $this->auto_field(
2139 + $field,
2140 + array(
2141 + 'type' => 'e2pdf-html',
2142 + 'properties' => array(
2143 + 'top' => '5',
2144 + 'width' => '100%',
2145 + 'height' => '150',
2146 + 'value' => '[' . $field_id . ' wpautop=0]',
2147 + ),
2148 + )
2149 + );
1465 2150 break;
1466 -
1467 - case 'file':
1468 2151 case 'text':
1469 2152 case 'email':
1470 2153 case 'url':
1471 2154 case 'number':
@@ -1470,58 +2153,151 @@
1470 2153 case 'url':
1471 2154 case 'number':
1472 2155 case 'phone':
1473 2156 case 'date':
1474 - case 'time':
1475 2157 case 'image':
1476 2158 case 'tag':
1477 2159 case 'password':
1478 - $elements[] = $this->auto_field($field, array(
1479 - 'type' => 'e2pdf-html',
1480 - 'block' => true,
1481 - 'properties' => array(
1482 - 'top' => '20',
1483 - 'left' => '20',
1484 - 'right' => '20',
1485 - 'width' => '100%',
1486 - 'height' => 'auto',
1487 - 'value' => $field->name,
1488 - )
1489 - ));
2160 + case 'quiz_score':
2161 + $elements[] = $this->auto_field(
2162 + $field,
2163 + array(
2164 + 'type' => 'e2pdf-html',
2165 + 'block' => true,
2166 + 'properties' => array(
2167 + 'top' => '20',
2168 + 'left' => '20',
2169 + 'right' => '20',
2170 + 'width' => '100%',
2171 + 'height' => 'auto',
2172 + 'value' => $field->name,
2173 + ),
2174 + )
2175 + );
1490 2176
1491 - if ($field->type == 'file') {
1492 - if (strpos($field_id, ':') !== false) {
1493 - $field_id .= " size='full' show_image='0' add_link='0'";
1494 - } else {
1495 - $field_id .= " size='full'";
2177 + $elements[] = $this->auto_field(
2178 + $field,
2179 + array(
2180 + 'type' => 'e2pdf-input',
2181 + 'properties' => array(
2182 + 'top' => '5',
2183 + 'width' => '100%',
2184 + 'height' => 'auto',
2185 + 'value' => '[' . $field_id . ']',
2186 + 'pass' => $field->type === 'password' ? '1' : '0',
2187 + ),
2188 + )
2189 + );
2190 + break;
2191 + case 'time':
2192 + $elements[] = $this->auto_field(
2193 + $field,
2194 + array(
2195 + 'type' => 'e2pdf-html',
2196 + 'block' => true,
2197 + 'properties' => array(
2198 + 'top' => '20',
2199 + 'left' => '20',
2200 + 'right' => '20',
2201 + 'width' => '100%',
2202 + 'height' => 'auto',
2203 + 'value' => $field->name,
2204 + ),
2205 + )
2206 + );
2207 +
2208 + $options_tmp = array();
2209 + if (class_exists('FrmProFieldTime')) {
2210 + $frm_pro_field_time = new FrmProFieldTime($field);
2211 + $options_tmp = $frm_pro_field_time->get_options($field->field_options);
2212 + }
2213 +
2214 + if (isset($field->field_options['single_time']) && $field->field_options['single_time']) {
2215 + $elements[] = $this->auto_field(
2216 + $field,
2217 + array(
2218 + 'type' => 'e2pdf-select',
2219 + 'properties' => array(
2220 + 'top' => '5',
2221 + 'width' => '100%',
2222 + 'height' => 'auto',
2223 + 'options' => implode("\n", $options_tmp),
2224 + 'value' => '[' . $field_id . ']',
2225 + ),
2226 + )
2227 + );
2228 + } else {
2229 +
2230 + $options_h = isset($options_tmp['H']) && is_array($options_tmp['H']) ? $options_tmp['H'] : array();
2231 + $options_m = isset($options_tmp['m']) && is_array($options_tmp['m']) ? $options_tmp['m'] : array();
2232 + $options_a = isset($options_tmp['A']) && is_array($options_tmp['A']) ? $options_tmp['A'] : array();
2233 +
2234 + $elements[] = $this->auto_field(
2235 + $field,
2236 + array(
2237 + 'type' => 'e2pdf-select',
2238 + 'float' => true,
2239 + 'properties' => array(
2240 + 'top' => '5',
2241 + 'width' => isset($field->field_options['clock']) && $field->field_options['clock'] == '12' ? '33.3%' : '50%',
2242 + 'height' => 'auto',
2243 + 'options' => implode("\n", $options_h),
2244 + 'value' => isset($field->field_options['clock']) && $field->field_options['clock'] == '12' ? '[' . $field_id . ' format="g"]' : '[' . $field_id . ' format="H"]',
2245 + ),
2246 + )
2247 + );
2248 +
2249 + $elements[] = $this->auto_field(
2250 + $field,
2251 + array(
2252 + 'type' => 'e2pdf-select',
2253 + 'float' => true,
2254 + 'properties' => array(
2255 + 'top' => '5',
2256 + 'left' => '20',
2257 + 'width' => isset($field->field_options['clock']) && $field->field_options['clock'] == '12' ? '33.3%' : '50%',
2258 + 'height' => 'auto',
2259 + 'options' => implode("\n", $options_m),
2260 + 'value' => '[' . $field_id . ' format="i"]',
2261 + ),
2262 + )
2263 + );
2264 +
2265 + if (isset($field->field_options['clock']) && $field->field_options['clock'] == '12') {
2266 + $elements[] = $this->auto_field(
2267 + $field,
2268 + array(
2269 + 'type' => 'e2pdf-select',
2270 + 'float' => true,
2271 + 'properties' => array(
2272 + 'top' => '5',
2273 + 'left' => '20',
2274 + 'width' => '33.3%',
2275 + 'height' => 'auto',
2276 + 'options' => implode("\n", $options_a),
2277 + 'value' => '[' . $field_id . ' format="A"]',
2278 + ),
2279 + )
2280 + );
1496 2281 }
1497 2282 }
1498 -
1499 - $elements[] = $this->auto_field($field, array(
1500 - 'type' => 'e2pdf-input',
1501 - 'properties' => array(
1502 - 'top' => '5',
1503 - 'width' => '100%',
1504 - 'height' => 'auto',
1505 - 'value' => "[$field_id]",
1506 - 'pass' => $field->type === 'password' ? '1' : '0',
1507 - )
1508 - ));
1509 2283 break;
1510 -
1511 2284 case 'select':
1512 - $elements[] = $this->auto_field($field, array(
1513 - 'type' => 'e2pdf-html',
1514 - 'block' => true,
1515 - 'properties' => array(
1516 - 'top' => '20',
1517 - 'left' => '20',
1518 - 'right' => '20',
1519 - 'width' => '100%',
1520 - 'height' => 'auto',
1521 - 'value' => $field->name,
1522 - )
1523 - ));
2285 + $elements[] = $this->auto_field(
2286 + $field,
2287 + array(
2288 + 'type' => 'e2pdf-html',
2289 + 'block' => true,
2290 + 'properties' => array(
2291 + 'top' => '20',
2292 + 'left' => '20',
2293 + 'right' => '20',
2294 + 'width' => '100%',
2295 + 'height' => 'auto',
2296 + 'value' => $field->name,
2297 + ),
2298 + )
2299 + );
1524 2300
1525 2301 $options_tmp = array();
1526 2302 if (isset($field->options) && is_array($field->options)) {
1527 2303 foreach ($field->options as $opt_key => $option) {
@@ -1532,203 +2308,664 @@
1532 2308 }
1533 2309 }
1534 2310 }
1535 2311
1536 - $elements[] = $this->auto_field($field, array(
1537 - 'type' => 'e2pdf-select',
1538 - 'properties' => array(
1539 - 'top' => '5',
1540 - 'width' => '100%',
1541 - 'height' => 'auto',
1542 - 'options' => implode("\n", $options_tmp),
1543 - 'value' => "[$field_id]",
1544 - 'height' => isset($field->field_options['multiple']) && $field->field_options['multiple'] ? '80' : 'auto',
1545 - 'multiline' => isset($field->field_options['multiple']) && $field->field_options['multiple'] ? '1' : '0',
1546 - )
1547 - ));
2312 + $elements[] = $this->auto_field(
2313 + $field,
2314 + array(
2315 + 'type' => 'e2pdf-select',
2316 + 'properties' => array(
2317 + 'top' => '5',
2318 + 'width' => '100%',
2319 + 'height' => 'auto',
2320 + 'options' => implode("\n", $options_tmp),
2321 + 'value' => '[' . $field_id . ']',
2322 + 'height' => isset($field->field_options['multiple']) && $field->field_options['multiple'] ? '80' : 'auto',
2323 + 'multiline' => isset($field->field_options['multiple']) && $field->field_options['multiple'] ? '1' : '0',
2324 + ),
2325 + )
2326 + );
1548 2327 break;
2328 + case 'credit_card':
2329 + $elements[] = $this->auto_field(
2330 + $field,
2331 + array(
2332 + 'type' => 'e2pdf-html',
2333 + 'block' => true,
2334 + 'properties' => array(
2335 + 'top' => '20',
2336 + 'left' => '20',
2337 + 'right' => '20',
2338 + 'width' => '100%',
2339 + 'height' => 'auto',
2340 + 'value' => $field->name,
2341 + ),
2342 + )
2343 + );
1549 2344
1550 - case 'credit_card':
1551 - case 'address':
1552 - $elements[] = $this->auto_field($field, array(
1553 - 'type' => 'e2pdf-html',
1554 - 'block' => true,
1555 - 'properties' => array(
1556 - 'top' => '20',
1557 - 'left' => '20',
1558 - 'right' => '20',
1559 - 'width' => '100%',
1560 - 'height' => 'auto',
1561 - 'value' => $field->name,
1562 - )
1563 - ));
2345 + $elements[] = $this->auto_field(
2346 + $field,
2347 + array(
2348 + 'type' => 'e2pdf-input',
2349 + 'properties' => array(
2350 + 'top' => '5',
2351 + 'width' => '100%',
2352 + 'height' => 'auto',
2353 + 'value' => '[' . $field_id . ' show="cc"]',
2354 + ),
2355 + )
2356 + );
1564 2357
1565 - $elements[] = $this->auto_field($field, array(
1566 - 'type' => 'e2pdf-textarea',
1567 - 'properties' => array(
1568 - 'top' => '5',
1569 - 'width' => '100%',
1570 - 'height' => '150',
1571 - 'value' => "[$field_id]",
1572 - )
1573 - ));
1574 - break;
2358 + $elements[] = $this->auto_field(
2359 + $field,
2360 + array(
2361 + 'type' => 'e2pdf-select',
2362 + 'properties' => array(
2363 + 'top' => '5',
2364 + 'width' => '33.3%',
2365 + 'left' => '0',
2366 + 'height' => 'auto',
2367 + 'options' => implode("\n", range(1, 12)),
2368 + 'value' => '[' . $field_id . ' show="month"]',
2369 + ),
2370 + )
2371 + );
1575 2372
1576 - case 'textarea':
1577 - $elements[] = $this->auto_field($field, array(
1578 - 'type' => 'e2pdf-html',
1579 - 'block' => true,
1580 - 'properties' => array(
1581 - 'top' => '20',
1582 - 'left' => '20',
1583 - 'right' => '20',
1584 - 'width' => '100%',
1585 - 'height' => 'auto',
1586 - 'value' => $field->name,
1587 - )
1588 - ));
2373 + $elements[] = $this->auto_field(
2374 + $field,
2375 + array(
2376 + 'type' => 'e2pdf-select',
2377 + 'float' => true,
2378 + 'properties' => array(
2379 + 'top' => '5',
2380 + 'left' => '20',
2381 + 'width' => '33.3%',
2382 + 'height' => 'auto',
2383 + 'options' => implode("\n", range(date('Y'), date('Y') + 10)),
2384 + 'value' => '[' . $field_id . ' show="year"]',
2385 + ),
2386 + )
2387 + );
1589 2388
1590 - $elements[] = $this->auto_field($field, array(
1591 - 'type' => 'e2pdf-textarea',
1592 - 'properties' => array(
1593 - 'top' => '5',
1594 - 'width' => '100%',
1595 - 'height' => '150',
1596 - 'value' => "[$field_id wpautop=0]",
1597 - )
1598 - ));
2389 + $elements[] = $this->auto_field(
2390 + $field,
2391 + array(
2392 + 'type' => 'e2pdf-input',
2393 + 'float' => true,
2394 + 'properties' => array(
2395 + 'top' => '5',
2396 + 'left' => '20',
2397 + 'width' => '33.3%',
2398 + 'height' => 'auto',
2399 + 'value' => '[' . $field_id . ' show="cvc"]',
2400 + ),
2401 + )
2402 + );
1599 2403 break;
2404 + case 'address':
2405 + $elements[] = $this->auto_field(
2406 + $field,
2407 + array(
2408 + 'type' => 'e2pdf-html',
2409 + 'block' => true,
2410 + 'properties' => array(
2411 + 'top' => '20',
2412 + 'left' => '20',
2413 + 'right' => '20',
2414 + 'width' => '100%',
2415 + 'height' => 'auto',
2416 + 'value' => $field->name,
2417 + ),
2418 + )
2419 + );
1600 2420
1601 - case 'radio':
1602 - $elements[] = $this->auto_field($field, array(
1603 - 'type' => 'e2pdf-html',
1604 - 'block' => true,
1605 - 'properties' => array(
1606 - 'top' => '20',
1607 - 'left' => '20',
1608 - 'right' => '20',
1609 - 'width' => '100%',
1610 - 'height' => 'auto',
1611 - 'value' => $field->name,
1612 - )
1613 - ));
1614 -
1615 - if (isset($field->options) && is_array($field->options)) {
1616 -
1617 - foreach ($field->options as $opt_key => $option) {
1618 - if (is_array($option)) {
1619 - $elements[] = $this->auto_field($field, array(
1620 - 'type' => 'e2pdf-radio',
2421 + if (isset($field->field_options['line1_desc']) && $field->field_options['line1_desc']) {
2422 + $elements[] = $this->auto_field(
2423 + $field,
2424 + array(
2425 + 'type' => 'e2pdf-html',
1621 2426 'properties' => array(
1622 2427 'top' => '5',
1623 - 'width' => 'auto',
2428 + 'width' => '100%',
1624 2429 'height' => 'auto',
1625 - 'value' => "[$field_id]",
1626 - 'option' => $option['label'],
1627 - 'group' => "group_" . $field_id
1628 - )
1629 - ));
1630 - $elements[] = $this->auto_field($field, array(
2430 + 'value' => $field->field_options['line1_desc'],
2431 + ),
2432 + )
2433 + );
2434 + }
2435 +
2436 + $elements[] = $this->auto_field(
2437 + $field,
2438 + array(
2439 + 'type' => 'e2pdf-input',
2440 + 'properties' => array(
2441 + 'top' => '5',
2442 + 'width' => '100%',
2443 + 'height' => 'auto',
2444 + 'value' => '[' . $field_id . ' show="line1"]',
2445 + ),
2446 + )
2447 + );
2448 +
2449 + if (isset($field->field_options['line2_desc']) && $field->field_options['line2_desc']) {
2450 + $elements[] = $this->auto_field(
2451 + $field,
2452 + array(
1631 2453 'type' => 'e2pdf-html',
1632 - 'float' => true,
1633 2454 'properties' => array(
1634 - 'left' => '5',
2455 + 'top' => '5',
1635 2456 'width' => '100%',
1636 2457 'height' => 'auto',
1637 - 'value' => $option['label']
2458 + 'value' => $field->field_options['line2_desc'],
2459 + ),
2460 + )
2461 + );
2462 + }
2463 +
2464 + $elements[] = $this->auto_field(
2465 + $field,
2466 + array(
2467 + 'type' => 'e2pdf-input',
2468 + 'properties' => array(
2469 + 'top' => '5',
2470 + 'width' => '100%',
2471 + 'height' => 'auto',
2472 + 'value' => '[' . $field_id . ' show="line2"]',
2473 + ),
2474 + )
2475 + );
2476 +
2477 + if (
2478 + (isset($field->field_options['city_desc']) && $field->field_options['city_desc']) ||
2479 + (isset($field->field_options['state_desc']) && $field->field_options['state_desc'] && isset($field->field_options['address_type']) && $field->field_options['address_type'] != 'europe') ||
2480 + (isset($field->field_options['zip_desc']) && $field->field_options['zip_desc'])
2481 + ) {
2482 +
2483 + $float = false;
2484 + if (isset($field->field_options['address_type']) && $field->field_options['address_type'] != 'europe') {
2485 + $elements[] = $this->auto_field(
2486 + $field,
2487 + array(
2488 + 'type' => 'e2pdf-html',
2489 + 'float' => $float,
2490 + 'properties' => array(
2491 + 'top' => '5',
2492 + 'left' => $float ? '20' : '0',
2493 + 'width' => '33.3%',
2494 + 'height' => 'auto',
2495 + 'value' => isset($field->field_options['city_desc']) && $field->field_options['city_desc'] ? $field->field_options['city_desc'] : '',
2496 + ),
1638 2497 )
1639 - ));
1640 - } else {
2498 + );
2499 + $float = true;
2500 + }
1641 2501
1642 - $elements[] = $this->auto_field($field, array(
1643 - 'type' => 'e2pdf-radio',
1644 - 'properties' => array(
1645 - 'top' => '5',
1646 - 'width' => 'auto',
1647 - 'height' => 'auto',
1648 - 'value' => "[$field_id]",
1649 - 'option' => $option,
1650 - 'group' => "group_" . $field_id
2502 + if (isset($field->field_options['address_type']) && (
2503 + $field->field_options['address_type'] == 'international' ||
2504 + $field->field_options['address_type'] == 'us' ||
2505 + $field->field_options['address_type'] == 'generic'
2506 + )
2507 + ) {
2508 +
2509 + $elements[] = $this->auto_field(
2510 + $field,
2511 + array(
2512 + 'type' => 'e2pdf-html',
2513 + 'float' => $float,
2514 + 'properties' => array(
2515 + 'top' => '5',
2516 + 'left' => $float ? '20' : '0',
2517 + 'width' => '33.3%',
2518 + 'height' => 'auto',
2519 + 'value' => isset($field->field_options['state_desc']) && $field->field_options['state_desc'] ? $field->field_options['state_desc'] : '',
2520 + ),
1651 2521 )
1652 - ));
1653 - $elements[] = $this->auto_field($field, array(
2522 + );
2523 + $float = true;
2524 + }
2525 +
2526 + $elements[] = $this->auto_field(
2527 + $field,
2528 + array(
1654 2529 'type' => 'e2pdf-html',
1655 - 'float' => true,
2530 + 'float' => $float,
1656 2531 'properties' => array(
1657 - 'left' => '5',
1658 - 'width' => '100%',
2532 + 'top' => '5',
2533 + 'left' => $float ? '20' : '0',
2534 + 'width' => '33.3%',
1659 2535 'height' => 'auto',
1660 - 'value' => $option
2536 + 'value' => isset($field->field_options['zip_desc']) && $field->field_options['zip_desc'] ? $field->field_options['zip_desc'] : '',
2537 + ),
2538 + )
2539 + );
2540 + $float = true;
2541 +
2542 + if (isset($field->field_options['address_type']) && $field->field_options['address_type'] == 'europe') {
2543 +
2544 + $elements[] = $this->auto_field(
2545 + $field,
2546 + array(
2547 + 'type' => 'e2pdf-html',
2548 + 'float' => $float,
2549 + 'properties' => array(
2550 + 'top' => '5',
2551 + 'left' => $float ? '20' : '0',
2552 + 'width' => '33.3%',
2553 + 'height' => 'auto',
2554 + 'value' => isset($field->field_options['city_desc']) && $field->field_options['city_desc'] ? $field->field_options['city_desc'] : '',
2555 + ),
1661 2556 )
1662 - ));
1663 - }
2557 + );
1664 2558 }
1665 2559 }
1666 - break;
1667 2560
1668 - case 'checkbox':
1669 - $elements[] = $this->auto_field($field, array(
1670 - 'type' => 'e2pdf-html',
1671 - 'block' => true,
1672 - 'properties' => array(
1673 - 'top' => '20',
1674 - 'left' => '20',
1675 - 'right' => '20',
1676 - 'width' => '100%',
1677 - 'height' => 'auto',
1678 - 'value' => $field->name,
1679 - )
1680 - ));
1681 -
1682 - if (isset($field->options) && is_array($field->options)) {
1683 - foreach ($field->options as $opt_key => $option) {
1684 - if (is_array($option)) {
1685 - $elements[] = $this->auto_field($field, array(
1686 - 'type' => 'e2pdf-checkbox',
2561 + $float = false;
2562 + if (isset($field->field_options['address_type']) && $field->field_options['address_type'] != 'europe') {
2563 + $elements[] = $this->auto_field(
2564 + $field,
2565 + array(
2566 + 'type' => 'e2pdf-input',
2567 + 'float' => $float,
1687 2568 'properties' => array(
1688 2569 'top' => '5',
1689 - 'width' => 'auto',
2570 + 'left' => $float ? '20' : '0',
2571 + 'width' => '33.3%',
1690 2572 'height' => 'auto',
1691 - 'value' => "[$field_id]",
1692 - 'option' => $option['label']
2573 + 'value' => '[' . $field_id . ' show="city"]',
2574 + ),
2575 + )
2576 + );
2577 + $float = true;
2578 + }
2579 +
2580 + if (isset($field->field_options['address_type']) && (
2581 + $field->field_options['address_type'] == 'international' ||
2582 + $field->field_options['address_type'] == 'us' ||
2583 + $field->field_options['address_type'] == 'generic'
2584 + )
2585 + ) {
2586 + if ($field->field_options['address_type'] == 'us') {
2587 + $options_tmp = array();
2588 + if (class_exists('FrmFieldsHelper')) {
2589 + $options_tmp = array_values(FrmFieldsHelper::get_us_states());
2590 + }
2591 +
2592 + $elements[] = $this->auto_field(
2593 + $field,
2594 + array(
2595 + 'type' => 'e2pdf-select',
2596 + 'float' => $float,
2597 + 'properties' => array(
2598 + 'top' => '5',
2599 + 'left' => $float ? '20' : '0',
2600 + 'width' => '33.3%',
2601 + 'height' => 'auto',
2602 + 'options' => implode("\n", $options_tmp),
2603 + 'value' => '[' . $field_id . ' show="state"]',
2604 + ),
1693 2605 )
1694 - ));
1695 - $elements[] = $this->auto_field($field, array(
1696 - 'type' => 'e2pdf-html',
1697 - 'float' => true,
1698 - 'properties' => array(
1699 - 'left' => '5',
1700 - 'width' => '100%',
1701 - 'height' => 'auto',
1702 - 'value' => $option['label']
2606 + );
2607 + } else {
2608 + $elements[] = $this->auto_field(
2609 + $field,
2610 + array(
2611 + 'type' => 'e2pdf-input',
2612 + 'float' => $float,
2613 + 'properties' => array(
2614 + 'top' => '5',
2615 + 'left' => $float ? '20' : '0',
2616 + 'width' => '33.3%',
2617 + 'height' => 'auto',
2618 + 'value' => '[' . $field_id . ' show="state"]',
2619 + ),
1703 2620 )
1704 - ));
1705 - } else {
1706 - $elements[] = $this->auto_field($field, array(
1707 - 'type' => 'e2pdf-checkbox',
2621 + );
2622 + }
2623 + $float = true;
2624 + }
2625 +
2626 + $elements[] = $this->auto_field(
2627 + $field,
2628 + array(
2629 + 'type' => 'e2pdf-input',
2630 + 'float' => $float,
2631 + 'properties' => array(
2632 + 'top' => '5',
2633 + 'left' => $float ? '20' : '0',
2634 + 'width' => '33.3%',
2635 + 'height' => 'auto',
2636 + 'value' => '[' . $field_id . ' show="zip"]',
2637 + ),
2638 + )
2639 + );
2640 + $float = true;
2641 +
2642 + if (isset($field->field_options['address_type']) && $field->field_options['address_type'] == 'europe') {
2643 + $elements[] = $this->auto_field(
2644 + $field,
2645 + array(
2646 + 'type' => 'e2pdf-input',
2647 + 'float' => $float,
1708 2648 'properties' => array(
1709 2649 'top' => '5',
1710 - 'width' => 'auto',
2650 + 'left' => $float ? '20' : '0',
2651 + 'width' => '33.3%',
1711 2652 'height' => 'auto',
1712 - 'value' => "[$field_id]",
1713 - 'option' => $option
2653 + 'value' => '[' . $field_id . ' show="city"]',
2654 + ),
2655 + )
2656 + );
2657 + }
2658 +
2659 + if (isset($field->field_options['address_type']) && ($field->field_options['address_type'] == 'international' || $field->field_options['address_type'] == 'europe')) {
2660 + if (isset($field->field_options['country_desc']) && $field->field_options['country_desc']) {
2661 + $elements[] = $this->auto_field(
2662 + $field,
2663 + array(
2664 + 'type' => 'e2pdf-html',
2665 + 'properties' => array(
2666 + 'top' => '5',
2667 + 'width' => '100%',
2668 + 'height' => 'auto',
2669 + 'value' => $field->field_options['country_desc'],
2670 + ),
1714 2671 )
1715 - ));
1716 - $elements[] = $this->auto_field($field, array(
1717 - 'type' => 'e2pdf-html',
1718 - 'float' => true,
2672 + );
2673 + }
2674 +
2675 + $options_tmp = array();
2676 + if (class_exists('FrmFieldsHelper')) {
2677 + $options_tmp = array_values(FrmFieldsHelper::get_countries());
2678 + }
2679 +
2680 + $elements[] = $this->auto_field(
2681 + $field,
2682 + array(
2683 + 'type' => 'e2pdf-select',
1719 2684 'properties' => array(
1720 - 'left' => '5',
2685 + 'top' => '5',
1721 2686 'width' => '100%',
1722 2687 'height' => 'auto',
1723 - 'value' => $option
1724 - )
1725 - ));
2688 + 'options' => implode("\n", $options_tmp),
2689 + 'value' => '[' . $field_id . ' show="country"]',
2690 + ),
2691 + )
2692 + );
2693 + }
2694 + break;
2695 + case 'textarea':
2696 + $elements[] = $this->auto_field(
2697 + $field,
2698 + array(
2699 + 'type' => 'e2pdf-html',
2700 + 'block' => true,
2701 + 'properties' => array(
2702 + 'top' => '20',
2703 + 'left' => '20',
2704 + 'right' => '20',
2705 + 'width' => '100%',
2706 + 'height' => 'auto',
2707 + 'value' => $field->name,
2708 + ),
2709 + )
2710 + );
2711 + $elements[] = $this->auto_field(
2712 + $field,
2713 + array(
2714 + 'type' => 'e2pdf-textarea',
2715 + 'properties' => array(
2716 + 'top' => '5',
2717 + 'width' => '100%',
2718 + 'height' => '150',
2719 + 'value' => '[' . $field_id . ' wpautop=0]',
2720 + ),
2721 + )
2722 + );
2723 + break;
2724 + case 'file':
2725 + $elements[] = $this->auto_field(
2726 + $field,
2727 + array(
2728 + 'type' => 'e2pdf-html',
2729 + 'block' => true,
2730 + 'properties' => array(
2731 + 'top' => '20',
2732 + 'left' => '20',
2733 + 'right' => '20',
2734 + 'width' => '100%',
2735 + 'height' => 'auto',
2736 + 'value' => $field->name,
2737 + ),
2738 + )
2739 + );
2740 + if (strpos($field_id, ':') !== false) {
2741 + $field_id .= ' size="full" show_image="0" add_link="0"';
2742 + } else {
2743 + $field_id .= ' size="full"';
2744 + }
2745 + $elements[] = $this->auto_field(
2746 + $field,
2747 + array(
2748 + 'type' => 'e2pdf-textarea',
2749 + 'properties' => array(
2750 + 'top' => '5',
2751 + 'width' => '100%',
2752 + 'height' => '150',
2753 + 'value' => '[' . $field_id . ']',
2754 + ),
2755 + )
2756 + );
2757 + break;
2758 + case 'radio':
2759 + $elements[] = $this->auto_field(
2760 + $field,
2761 + array(
2762 + 'type' => 'e2pdf-html',
2763 + 'block' => true,
2764 + 'properties' => array(
2765 + 'top' => '20',
2766 + 'left' => '20',
2767 + 'right' => '20',
2768 + 'width' => '100%',
2769 + 'height' => 'auto',
2770 + 'value' => $field->name,
2771 + ),
2772 + )
2773 + );
2774 +
2775 + $image_options = false;
2776 + if (isset($field->field_options['image_options']) && $field->field_options['image_options']) {
2777 + $image_options = true;
2778 + }
2779 +
2780 + $separate_value = false;
2781 + if (isset($field->field_options['separate_value']) && $field->field_options['separate_value']) {
2782 + $separate_value = true;
2783 + }
2784 +
2785 + if (isset($field->options) && is_array($field->options)) {
2786 +
2787 + foreach ($field->options as $opt_key => $option) {
2788 + if (is_array($option)) {
2789 + $elements[] = $this->auto_field(
2790 + $field,
2791 + array(
2792 + 'type' => 'e2pdf-radio',
2793 + 'properties' => array(
2794 + 'top' => '5',
2795 + 'width' => 'auto',
2796 + 'height' => 'auto',
2797 + 'value' => $image_options ? '[' . $field_id . ' show="value"]' : '[' . $field_id . ']',
2798 + 'option' => $image_options && $separate_value && isset($option['value']) ? $option['value'] : $option['label'],
2799 + 'group' => '[' . $field_id . ']',
2800 + ),
2801 + )
2802 + );
2803 + $elements[] = $this->auto_field(
2804 + $field,
2805 + array(
2806 + 'type' => 'e2pdf-html',
2807 + 'float' => true,
2808 + 'properties' => array(
2809 + 'left' => '5',
2810 + 'width' => '100%',
2811 + 'height' => 'auto',
2812 + 'value' => $option['label'],
2813 + ),
2814 + )
2815 + );
2816 + } else {
2817 +
2818 + $elements[] = $this->auto_field(
2819 + $field,
2820 + array(
2821 + 'type' => 'e2pdf-radio',
2822 + 'properties' => array(
2823 + 'top' => '5',
2824 + 'width' => 'auto',
2825 + 'height' => 'auto',
2826 + 'value' => '[' . $field_id . ']',
2827 + 'option' => substr($opt_key, 0, 6) === 'other_' ? '[' . $field_id . ' show="value" key="other"]' : $option,
2828 + 'group' => '[' . $field_id . ']',
2829 + ),
2830 + )
2831 + );
2832 + $elements[] = $this->auto_field(
2833 + $field,
2834 + array(
2835 + 'type' => 'e2pdf-html',
2836 + 'float' => true,
2837 + 'properties' => array(
2838 + 'left' => '5',
2839 + 'width' => '100%',
2840 + 'height' => 'auto',
2841 + 'value' => $option,
2842 + ),
2843 + )
2844 + );
2845 +
2846 + if (substr($opt_key, 0, 6) === 'other_') {
2847 + $elements[] = $this->auto_field(
2848 + $field,
2849 + array(
2850 + 'type' => 'e2pdf-input',
2851 + 'properties' => array(
2852 + 'top' => '5',
2853 + 'width' => '100%',
2854 + 'height' => 'auto',
2855 + 'value' => '[' . $field_id . ' show="value" key="other"]',
2856 + ),
2857 + )
2858 + );
2859 + }
1726 2860 }
1727 2861 }
1728 2862 }
1729 2863 break;
2864 + case 'checkbox':
2865 + $elements[] = $this->auto_field(
2866 + $field,
2867 + array(
2868 + 'type' => 'e2pdf-html',
2869 + 'block' => true,
2870 + 'properties' => array(
2871 + 'top' => '20',
2872 + 'left' => '20',
2873 + 'right' => '20',
2874 + 'width' => '100%',
2875 + 'height' => 'auto',
2876 + 'value' => $field->name,
2877 + ),
2878 + )
2879 + );
1730 2880
2881 + $image_options = false;
2882 + if (isset($field->field_options['image_options']) && $field->field_options['image_options']) {
2883 + $image_options = true;
2884 + }
2885 +
2886 + $separate_value = false;
2887 + if (isset($field->field_options['separate_value']) && $field->field_options['separate_value']) {
2888 + $separate_value = true;
2889 + }
2890 +
2891 + if (isset($field->options) && is_array($field->options)) {
2892 + foreach ($field->options as $opt_key => $option) {
2893 + if (is_array($option)) {
2894 + $elements[] = $this->auto_field(
2895 + $field,
2896 + array(
2897 + 'type' => 'e2pdf-checkbox',
2898 + 'properties' => array(
2899 + 'top' => '5',
2900 + 'width' => 'auto',
2901 + 'height' => 'auto',
2902 + 'value' => $image_options ? '[' . $field_id . ' show="value"]' : '[' . $field_id . ']',
2903 + 'option' => $image_options && $separate_value && isset($option['value']) ? $option['value'] : $option['label'],
2904 + ),
2905 + )
2906 + );
2907 + $elements[] = $this->auto_field(
2908 + $field,
2909 + array(
2910 + 'type' => 'e2pdf-html',
2911 + 'float' => true,
2912 + 'properties' => array(
2913 + 'left' => '5',
2914 + 'width' => '100%',
2915 + 'height' => 'auto',
2916 + 'value' => $option['label'],
2917 + ),
2918 + )
2919 + );
2920 + } else {
2921 +
2922 + $elements[] = $this->auto_field(
2923 + $field,
2924 + array(
2925 + 'type' => 'e2pdf-checkbox',
2926 + 'properties' => array(
2927 + 'top' => '5',
2928 + 'width' => 'auto',
2929 + 'height' => 'auto',
2930 + 'value' => '[' . $field_id . ']',
2931 + 'option' => substr($opt_key, 0, 6) === 'other_' ? '[' . $field_id . ' show="value" key="' . $opt_key . '"]' : $option,
2932 + ),
2933 + )
2934 + );
2935 +
2936 + $elements[] = $this->auto_field(
2937 + $field,
2938 + array(
2939 + 'type' => 'e2pdf-html',
2940 + 'float' => true,
2941 + 'properties' => array(
2942 + 'left' => '5',
2943 + 'width' => '100%',
2944 + 'height' => 'auto',
2945 + 'value' => $option,
2946 + ),
2947 + )
2948 + );
2949 +
2950 + if (substr($opt_key, 0, 6) === 'other_') {
2951 + $elements[] = $this->auto_field(
2952 + $field,
2953 + array(
2954 + 'type' => 'e2pdf-input',
2955 + 'properties' => array(
2956 + 'top' => '5',
2957 + 'width' => '100%',
2958 + 'height' => 'auto',
2959 + 'value' => '[' . $field_id . ' show="value" key="' . $opt_key . '"]',
2960 + ),
2961 + )
2962 + );
2963 + }
2964 + }
2965 + }
2966 + }
2967 + break;
1731 2968 default:
1732 2969 break;
1733 2970 }
1734 2971 }
@@ -1737,9 +2974,9 @@
1737 2974 $response['page'] = array(
1738 2975 'bottom' => '20',
1739 2976 'top' => '20',
1740 2977 'right' => '20',
1741 - 'left' => '20'
2978 + 'left' => '20',
1742 2979 );
1743 2980
1744 2981 $response['elements'] = $elements;
1745 2982 return $response;
@@ -1746,13 +2983,11 @@
1746 2983 }
1747 2984
1748 2985 /**
1749 2986 * Generate field for Auto PDF
1750 - *
1751 2987 * @param object $field - Formidable field object
1752 2988 * @param string $type - Field type
1753 2989 * @param array $options - Field additional options
1754 - *
1755 2990 * @return array - Prepared auto field
1756 2991 */
1757 2992 public function auto_field($field = false, $element = array()) {
1758 2993
@@ -1769,9 +3004,9 @@
1769 3004 }
1770 3005
1771 3006 $classes = array();
1772 3007 if (isset($field->field_options['classes'])) {
1773 - $classes = explode(" ", $field->field_options['classes']);
3008 + $classes = explode(' ', $field->field_options['classes']);
1774 3009 }
1775 3010
1776 3011 $float_classes = array(
1777 3012 'frm_half',
@@ -1782,9 +3017,9 @@
1782 3017 'frm_fifth',
1783 3018 'frm_two_fifths',
1784 3019 'frm_sixth',
1785 3020 'frm_seventh',
1786 - 'frm_eighth'
3021 + 'frm_eighth',
1787 3022 );
1788 3023
1789 3024 $array_intersect = array_intersect($classes, $float_classes);
1790 3025
@@ -1789,9 +3024,9 @@
1789 3024 $array_intersect = array_intersect($classes, $float_classes);
1790 3025
1791 3026 if (!empty($array_intersect) && !in_array('frm_first', $classes) && isset($element['block']) && $element['block']) {
1792 3027 $element['float'] = true;
1793 - };
3028 + }
1794 3029
1795 3030 $primary_class = false;
1796 3031 if (!empty($array_intersect)) {
1797 3032 $primary_class = end($array_intersect);
@@ -1801,45 +3036,35 @@
1801 3036 switch ($primary_class) {
1802 3037 case 'frm_half':
1803 3038 $element['properties']['width'] = '50%';
1804 3039 break;
1805 -
1806 3040 case 'frm_third':
1807 3041 $element['properties']['width'] = '33.3%';
1808 3042 break;
1809 -
1810 3043 case 'frm_two_thirds':
1811 3044 $element['properties']['width'] = '66.67%';
1812 3045 break;
1813 -
1814 3046 case 'frm_fourth':
1815 3047 $element['properties']['width'] = '25%';
1816 3048 break;
1817 -
1818 3049 case 'frm_three_fourths':
1819 3050 $element['properties']['width'] = '75%';
1820 3051 break;
1821 -
1822 3052 case 'frm_fifth':
1823 3053 $element['properties']['width'] = '20%';
1824 3054 break;
1825 -
1826 3055 case 'frm_two_fifths':
1827 3056 $element['properties']['width'] = '80%';
1828 3057 break;
1829 -
1830 3058 case 'frm_sixth':
1831 3059 $element['properties']['width'] = '16.67%';
1832 3060 break;
1833 -
1834 3061 case 'frm_seventh':
1835 3062 $element['properties']['width'] = '14.29%';
1836 3063 break;
1837 -
1838 3064 case 'frm_eighth':
1839 3065 $element['properties']['width'] = '12.5%';
1840 3066 break;
1841 -
1842 3067 default:
1843 3068 break;
1844 3069 }
1845 3070 }
@@ -1848,9 +3073,8 @@
1848 3073 }
1849 3074
1850 3075 /**
1851 3076 * Backup form action
1852 - *
1853 3077 * @param object xml - XML object where to add params for saved item
1854 3078 */
1855 3079 public function backup($xml = false) {
1856 3080 if (class_exists('FrmXMLController')) {
@@ -1855,9 +3079,14 @@
1855 3079 public function backup($xml = false) {
1856 3080 if (class_exists('FrmXMLController')) {
1857 3081
1858 3082 $ids = array();
1859 - $ids[] = $this->get('item');
3083 + if ($this->get('item') == '-2') {
3084 + $ids[] = $this->get('item1');
3085 + $ids[] = $this->get('item2');
3086 + } else {
3087 + $ids[] = $this->get('item');
3088 + }
1860 3089
1861 3090 $type = array();
1862 3091 $type[] = 'forms';
1863 3092
@@ -1869,33 +3098,30 @@
1869 3098 }
1870 3099
1871 3100 /**
1872 3101 * Import form action
1873 - *
1874 3102 * @param object xml - XML object to parse data to import form
1875 3103 */
1876 - public function import($xml, $item, $options = array()) {
3104 + public function import($xml, $options = array()) {
1877 3105
1878 - $updated_item = '';
3106 + $updated_items = array();
1879 3107 $new_form = isset($options['formidable_item_new_form']) && $options['formidable_item_new_form'] ? true : false;
1880 3108
1881 - if (class_exists('FrmXMLHelper') && class_exists('FrmField')) {
3109 + if (class_exists('FrmXMLHelper') && class_exists('FrmField') && $this->get('item')) {
1882 3110
1883 - if ($xml->formidable) {
3111 + if (isset($xml->formidable) && $xml->formidable) {
1884 3112
1885 3113 $tmp = tempnam($this->helper->get('tmp_dir'), 'e2pdf');
1886 - file_put_contents($tmp, base64_decode((String) $xml->formidable));
3114 + file_put_contents($tmp, base64_decode((string) $xml->formidable), LOCK_EX);
1887 3115
1888 3116 if ($new_form) {
1889 3117 add_filter('frm_match_xml_form', array($this, 'filter_frm_match_xml_form'), 10, 2);
1890 3118 }
1891 -
1892 3119 $result = FrmXMLHelper::import_xml($tmp);
1893 3120
1894 3121 if ($new_form) {
1895 - remove_filter('frm_match_xml_form', array($this, 'filter_frm_match_xml_form'), 10);
3122 + remove_filter('frm_match_xml_form', array($this, 'filter_frm_match_xml_form'));
1896 3123 }
1897 -
1898 3124 unlink($tmp);
1899 3125
1900 3126 FrmXMLHelper::parse_message($result, $message, $errors);
1901 3127
@@ -1900,33 +3126,137 @@
1900 3126 FrmXMLHelper::parse_message($result, $message, $errors);
1901 3127
1902 3128 if ($errors) {
1903 3129 return array(
1904 - 'errors' => $errors
3130 + 'errors' => $errors,
1905 3131 );
1906 3132 } else {
1907 - if (isset($result['forms'][$item])) {
1908 - $updated_item = $result['forms'][$item];
3133 + if ($this->get('item') == '-2') {
3134 + if ($this->get('item1') && isset($result['forms'][$this->get('item1')])) {
3135 + $updated_items[$this->get('item1')] = $result['forms'][$this->get('item1')];
3136 + }
3137 + if ($this->get('item2') && isset($result['forms'][$this->get('item2')])) {
3138 + $updated_items[$this->get('item2')] = $result['forms'][$this->get('item2')];
3139 + }
3140 + } elseif (isset($result['forms'][$this->get('item')])) {
3141 + $updated_items[$this->get('item')] = $result['forms'][$this->get('item')];
1909 3142 }
1910 3143 }
1911 3144 }
1912 3145 }
3146 + return $updated_items;
3147 + }
1913 3148
1914 - return $updated_item;
3149 + public function after_import($old_template_id, $new_template_id) {
3150 +
3151 + if ($this->get('item') && $old_template_id && $new_template_id && $old_template_id != $new_template_id && class_exists('FrmForm')) {
3152 + $forms = array();
3153 + if ($this->get('item') == '-2') {
3154 + if ($this->get('item1')) {
3155 + $forms[] = $this->get('item1');
3156 + }
3157 + if ($this->get('item2')) {
3158 + $forms[] = $this->get('item2');
3159 + }
3160 + } else {
3161 + $forms[] = $this->get('item');
3162 + }
3163 +
3164 + foreach ($forms as $form_id) {
3165 + $form = FrmForm::getOne($form_id);
3166 + if ($form) {
3167 + if (isset($form->options['success_msg'])) {
3168 + $success_msg = $this->replace_template_id($form->options['success_msg'], $old_template_id, $new_template_id);
3169 + if ($success_msg != $form->options['success_msg']) {
3170 + $update = array(
3171 + 'options' => array(
3172 + 'success_msg' => $success_msg,
3173 + ),
3174 + );
3175 + FrmForm::update($form_id, $update);
3176 + }
3177 + }
3178 +
3179 + if (class_exists('FrmFormAction')) {
3180 + $actions = FrmFormAction::get_action_for_form($form_id, 'email');
3181 + foreach ($actions as $action) {
3182 + if (isset($action->post_content['email_message'])) {
3183 + $email_message = $this->replace_template_id($action->post_content['email_message'], $old_template_id, $new_template_id);
3184 + if ($email_message != $action->post_content['email_message']) {
3185 + $action->post_content['email_message'] = $email_message;
3186 + FrmFormAction::clear_cache();
3187 + FrmDb::save_settings($action, 'frm_actions');
3188 + }
3189 + }
3190 + }
3191 + }
3192 + }
3193 + }
3194 + }
3195 + return false;
1915 3196 }
1916 3197
3198 + public function replace_template_id($message, $old_template_id, $new_template_id) {
3199 + $old_template_id = (int) $old_template_id;
3200 + $new_template_id = (int) $new_template_id;
3201 + $message = preg_replace('/\[(e2pdf-download|e2pdf-view|e2pdf-save|e2pdf-attachment|e2pdf-adobesign|e2pdf-zapier)(.*) id=(|\'|")' . $old_template_id . '(|\'|")(.*)\]/i', '[${1}${2} id=${3}' . $new_template_id . '${4}${5}]', $message);
3202 + return $message;
3203 + }
3204 +
3205 + public function replace_meta_shortcodes($value) {
3206 + if (false !== strpos($value, '[')) {
3207 + $replace = array(
3208 + '[referer]' => '',
3209 + '[browser]' => '',
3210 + '[referer2]' => '',
3211 + '[browser2]' => '',
3212 + '[entry_num]' => '',
3213 + '[entry_num2]' => '',
3214 + );
3215 + if ((false !== strpos($value, '[referer]') || false !== strpos($value, '[browser]')) && $this->get('cached_entry') && isset($this->get('cached_entry')->description)) {
3216 + if (is_serialized($this->get('cached_entry')->description)) {
3217 + $description = $this->helper->load('convert')->unserialize(trim($this->get('cached_entry')->description));
3218 + } else {
3219 + $description = $this->get('cached_entry')->description;
3220 + }
3221 + if (isset($description['referrer'])) {
3222 + $replace['[referer]'] = @preg_match('/Referer +\d+\:[ \t]+([^\n\t]+)/', $description['referrer'], $m) ? $m[1] : $description['referrer']; // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
3223 + }
3224 + $replace['[browser]'] = isset($description['browser']) ? $description['browser'] : '';
3225 + }
3226 + if ((false !== strpos($value, '[referer2]') || false !== strpos($value, '[browser2]')) && $this->get('cached_entry2') && isset($this->get('cached_entry2')->description)) {
3227 + if (is_serialized($this->get('cached_entry2')->description)) {
3228 + $description = $this->helper->load('convert')->unserialize(trim($this->get('cached_entry2')->description));
3229 + } else {
3230 + $description = $this->get('cached_entry2')->description;
3231 + }
3232 + $replace['[referer2]'] = '';
3233 + if (isset($description['referrer'])) {
3234 + $replace['[referer2]'] = @preg_match('/Referer +\d+\:[ \t]+([^\n\t]+)/', $description['referrer'], $m) ? $m[1] : $description['referrer']; // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
3235 + }
3236 + $replace['[browser2]'] = isset($description['browser']) ? $description['browser'] : '';
3237 + }
3238 + if (false !== strpos($value, '[entry_num]')) {
3239 + $replace['[entry_num]'] = class_exists('FrmDb') && $this->get('cached_entry') ? FrmDb::get_count('frm_items', array("form_id = '{$this->get('cached_form')->id}' AND id <= '{$this->get('cached_entry')->id}' AND 1" => '1')) : '';
3240 + }
3241 + if (false !== strpos($value, '[entry_num2]')) {
3242 + $replace['[entry_num2]'] = class_exists('FrmDb') && $this->get('cached_entry2') ? FrmDb::get_count('frm_items', array("form_id = '{$this->get('cached_form2')->id}' AND id <= '{$this->get('cached_entry2')->id}' AND 1" => '1')) : '';
3243 + }
3244 + $value = str_replace(array_keys($replace), $replace, $value);
3245 + }
3246 + return $value;
3247 + }
3248 +
1917 3249 /**
1918 3250 * Replace Old Formidable shortcodes to new values on pages
1919 - *
1920 3251 * @param array $pages - List of pages to replace shortcodes
1921 3252 * @param array $shortcodes_list - List of new/old shortcodes to replace
1922 - *
1923 3253 * @return array - List of updated pages
1924 3254 */
1925 3255 public function pages_replace_shortcodes($pages = array(), $shortcodes_list = array()) {
1926 3256
1927 3257 foreach ($pages as $page_key => $page) {
1928 - //replace page actions and conditions shortcodes
3258 + /* Replace page actions and conditions shortcodes */
1929 3259 if (isset($page['actions']) && !empty($page['actions'])) {
1930 3260 foreach ($page['actions'] as $action_key => $action_value) {
1931 3261 if (isset($action_value['change'])) {
1932 3262 $pages[$page_key]['actions'][$action_key]['change'] = $this->replace_shortcodes($action_value['change'], $shortcodes_list);
@@ -1948,9 +3278,21 @@
1948 3278
1949 3279 foreach ($page['elements'] as $element_key => $element_value) {
1950 3280 $pages[$page_key]['elements'][$element_key]['value'] = $this->replace_shortcodes($element_value['value'], $shortcodes_list);
1951 3281
1952 - //replace element actions and conditions shortcodes
3282 + if (isset($element_value['properties']['option'])) {
3283 + $pages[$page_key]['elements'][$element_key]['properties']['option'] = $this->replace_shortcodes($element_value['properties']['option'], $shortcodes_list);
3284 + }
3285 +
3286 + if (isset($element_value['properties']['options'])) {
3287 + $pages[$page_key]['elements'][$element_key]['properties']['options'] = $this->replace_shortcodes($element_value['properties']['options'], $shortcodes_list);
3288 + }
3289 +
3290 + if (isset($element_value['properties']['group'])) {
3291 + $pages[$page_key]['elements'][$element_key]['properties']['group'] = $this->replace_shortcodes($element_value['properties']['group'], $shortcodes_list);
3292 + }
3293 +
3294 + /* Replace element actions and conditions shortcodes */
1953 3295 if (isset($element_value['actions']) && !empty($element_value['actions'])) {
1954 3296 foreach ($element_value['actions'] as $action_key => $action_value) {
1955 3297 if (isset($action_value['change'])) {
1956 3298 $pages[$page_key]['elements'][$element_key]['actions'][$action_key]['change'] = $this->replace_shortcodes($action_value['change'], $shortcodes_list);
@@ -1974,50 +3316,83 @@
1974 3316
1975 3317 return $pages;
1976 3318 }
1977 3319
3320 + public function actions_replace_shortcodes($actions = array(), $shortcodes_list = array()) {
3321 +
3322 + foreach ($actions as $action_key => $action_value) {
3323 + if (isset($action_value['change'])) {
3324 + $actions[$action_key]['change'] = $this->replace_shortcodes($action_value['change'], $shortcodes_list);
3325 + }
3326 +
3327 + if (isset($action_value['conditions']) && !empty($action_value['conditions'])) {
3328 + foreach ($action_value['conditions'] as $condition_key => $condition_value) {
3329 + if (isset($condition_value['if'])) {
3330 + $actions[$action_key]['conditions'][$condition_key]['if'] = $this->replace_shortcodes($condition_value['if'], $shortcodes_list);
3331 + }
3332 +
3333 + if (isset($condition_value['value'])) {
3334 + $actions[$action_key]['conditions'][$condition_key]['value'] = $this->replace_shortcodes($condition_value['value'], $shortcodes_list);
3335 + }
3336 + }
3337 + }
3338 + }
3339 +
3340 + return $actions;
3341 + }
3342 +
1978 3343 /**
1979 3344 * Replace Old Formidable shortcodes to new values
1980 - *
1981 3345 * @param string $content - Value that can contains old shortcodes
1982 3346 * @param array $shortcodes_list - List of new/old shortcodes to replace
1983 - *
1984 3347 * @return string - Updated value
1985 3348 */
1986 - public function replace_shortcodes($content = "", $shortcodes_list = array()) {
1987 -
3349 + public function replace_shortcodes($content = '', $shortcodes_list = array()) {
1988 3350 if (false === strpos($content, '[')) {
1989 3351 return $content;
1990 3352 }
1991 -
1992 3353 foreach ($shortcodes_list as $list_key => $list_value) {
1993 - $content = preg_replace("/(\[|\[(?:[^\]]*?)\s|\[(?:[^\]]*?)field_id=(?:\'|\"|)){$list_key}(\:(?:.*?)\]|\s(?:.*?)\]|(?:\'|\")(?:.*?)\]|\])/", '${1}' . $list_value . '${2}', $content);
3354 + $content = preg_replace("/(\[|\[(?:[^\]]*?)\s|\[(?:[^\]]*?)(?:field_id|e2pdf-frm-data-values id|e2pdf-frm-lookup-values id)=(?:\'|\"|)){$list_key}(\:(?:.*?)\]|\s(?:.*?)\]|(?:\'|\")(?:.*?)\]|\])/", '${1}' . $list_value . '${2}', $content);
1994 3355 }
1995 -
1996 3356 return $content;
1997 3357 }
1998 3358
1999 3359 /**
2000 - * Verify if form and dataset exists
2001 - *
2002 - * @return bool - Exists/Not exists
3360 + * Verify if item and dataset exists
3361 + * @return bool - item and dataset exists
2003 3362 */
2004 3363 public function verify() {
2005 - $item = $this->get('item');
2006 - $dataset = $this->get('dataset');
2007 -
2008 - if ($item && $dataset && class_exists('FrmEntry') && class_exists('FrmForm')) {
2009 - $entry = FrmEntry::getOne($dataset);
2010 - if (is_object($entry) && $entry->form_id == $item) {
2011 - return true;
3364 + $verify = false;
3365 + if ($this->get('item') == '-2') {
3366 + if ($this->get('cached_entry')) {
3367 + $verify = true;
3368 + } else {
3369 + $this->set('dataset', false);
2012 3370 }
3371 + if ($this->get('cached_entry2')) {
3372 + $verify = true;
3373 + } else {
3374 + $this->set('dataset2', false);
3375 + }
3376 + } elseif ($this->get('cached_entry')) {
3377 + $verify = true;
2013 3378 }
2014 - return false;
3379 + return $verify;
2015 3380 }
2016 3381
2017 - public function add_form($template) {
3382 + /**
3383 + * Create Form based on uploaded PDF
3384 + * @param object $template - Template Object to work with
3385 + * @param array $data - Settings to create labels/shortcodes
3386 + * @return object - Mapped Template Object
3387 + */
3388 + public function auto_form($template, $data = array()) {
3389 +
2018 3390 if ($template->get('ID')) {
2019 3391
3392 + $auto_form_label = isset($data['auto_form_label']) && $data['auto_form_label'] ? $data['auto_form_label'] : false;
3393 + $auto_form_shortcode = isset($data['auto_form_shortcode']) ? true : false;
3394 +
2020 3395 $form = array(
2021 3396 'form_key' => '',
2022 3397 'name' => $template->get('title'),
2023 3398 'description' => '',
@@ -2022,13 +3397,14 @@
2022 3397 'name' => $template->get('title'),
2023 3398 'description' => '',
2024 3399 'status' => 'published',
2025 3400 'options' => array(
2026 - 'success_msg' => sprintf(__('Success. [e2pdf-download id="%s"]', 'e2pdf'), $template->get('ID'))
2027 - )
3401 + 'success_msg' => sprintf(__('Success. [e2pdf-download id="%s"]', 'e2pdf'), $template->get('ID')),
3402 + ),
2028 3403 );
2029 3404
2030 - if ($item = FrmForm::create($form)) {
3405 + $item = FrmForm::create($form);
3406 + if ($item) {
2031 3407 $template->set('item', $item);
2032 3408
2033 3409 $checkboxes = array();
2034 3410 $radios = array();
@@ -2037,70 +3413,18 @@
2037 3413
2038 3414 foreach ($pages as $page_key => $page) {
2039 3415 if (isset($page['elements']) && !empty($page['elements'])) {
2040 3416 foreach ($page['elements'] as $element_key => $element) {
3417 + $field_values = array();
2041 3418 if ($element['type'] == 'e2pdf-input' || ($element['type'] == 'e2pdf-signature' && !class_exists('FrmSigAppHelper'))) {
2042 3419 $field_values = FrmFieldsHelper::setup_new_vars('text', $item);
2043 -
2044 - if ($field_id = FrmField::create($field_values)) {
2045 - $field = FrmField::getOne($field_id);
2046 - $update = array(
2047 - 'name' => $element['value'] ? '[' . $field->id . '] ' . $element['value'] : '[' . $field->id . ']'
2048 - );
2049 - if (get_option('e2pdf_formidable_use_keys')) {
2050 - $field_id = $field->field_key;
2051 - $update = array(
2052 - 'name' => $element['value'] ? '[' . $field->field_key . '] ' . $element['value'] : '[' . $field->field_key . ']'
2053 - );
2054 - }
2055 - FrmField::update($field_id, $update);
2056 - $pages[$page_key]['elements'][$element_key]['value'] = '[' . $field_id . ']';
2057 - if (isset($element['properties']['esig'])) {
2058 - unset($pages[$page_key]['elements'][$element_key]['properties']['esig']);
2059 - }
2060 - }
2061 - } if ($element['type'] == 'e2pdf-signature' && class_exists('FrmSigAppHelper')) {
2062 -
3420 + } elseif ($element['type'] == 'e2pdf-signature' && class_exists('FrmSigAppHelper')) {
2063 3421 $field_values = FrmFieldsHelper::setup_new_vars('signature', $item);
2064 -
2065 - if ($field_id = FrmField::create($field_values)) {
2066 - $field = FrmField::getOne($field_id);
2067 - $update = array(
2068 - 'name' => $element['value'] ? '[' . $field->id . '] ' . $element['value'] : '[' . $field->id . ']'
2069 - );
2070 - if (get_option('e2pdf_formidable_use_keys')) {
2071 - $field_id = $field->field_key;
2072 - $update = array(
2073 - 'name' => $element['value'] ? '[' . $field->field_key . '] ' . $element['value'] : '[' . $field->field_key . ']'
2074 - );
2075 - }
2076 - FrmField::update($field_id, $update);
2077 - $pages[$page_key]['elements'][$element_key]['value'] = '[' . $field_id . ']';
2078 - if (isset($element['properties']['esig'])) {
2079 - unset($pages[$page_key]['elements'][$element_key]['properties']['esig']);
2080 - }
2081 - }
2082 3422 } elseif ($element['type'] == 'e2pdf-textarea') {
2083 3423 $field_values = FrmFieldsHelper::setup_new_vars('textarea', $item);
2084 -
2085 - if ($field_id = FrmField::create($field_values)) {
2086 - $field = FrmField::getOne($field_id);
2087 - $update = array(
2088 - 'name' => $element['value'] ? '[' . $field->id . '] ' . $element['value'] : '[' . $field->id . ']'
2089 - );
2090 - if (get_option('e2pdf_formidable_use_keys')) {
2091 - $field_id = $field->field_key;
2092 - $update = array(
2093 - 'name' => $element['value'] ? '[' . $field->field_key . '] ' . $element['value'] : '[' . $field->field_key . ']'
2094 - );
2095 - }
2096 - FrmField::update($field_id, $update);
2097 - $pages[$page_key]['elements'][$element_key]['value'] = '[' . $field_id . ']';
2098 - }
2099 3424 } elseif ($element['type'] == 'e2pdf-select') {
2100 3425 $field_values = FrmFieldsHelper::setup_new_vars('select', $item);
2101 3426 $field_values['options'] = array();
2102 -
2103 3427 if (isset($element['properties']['options'])) {
2104 3428 $field_options = explode("\n", $element['properties']['options']);
2105 3429 foreach ($field_options as $option) {
2106 3430 $field_values['options'][] = $option;
@@ -2105,23 +3429,8 @@
2105 3429 foreach ($field_options as $option) {
2106 3430 $field_values['options'][] = $option;
2107 3431 }
2108 3432 }
2109 -
2110 - if ($field_id = FrmField::create($field_values)) {
2111 - $field = FrmField::getOne($field_id);
2112 - $update = array(
2113 - 'name' => '[' . $field->id . ']'
2114 - );
2115 - if (get_option('e2pdf_formidable_use_keys')) {
2116 - $field_id = $field->field_key;
2117 - $update = array(
2118 - 'name' => '[' . $field->field_key . ']'
2119 - );
2120 - }
2121 - FrmField::update($field_id, $update);
2122 - $pages[$page_key]['elements'][$element_key]['value'] = '[' . $field_id . ']';
2123 - }
2124 3433 } elseif ($element['type'] == 'e2pdf-checkbox') {
2125 3434 $field_key = array_search($element['name'], array_column($checkboxes, 'name'));
2126 3435 if ($field_key !== false) {
2127 3436 $checkboxes[$field_key]['options'][] = $element['properties']['option'];
@@ -2126,70 +3435,79 @@
2126 3435 if ($field_key !== false) {
2127 3436 $checkboxes[$field_key]['options'][] = $element['properties']['option'];
2128 3437 $pages[$page_key]['elements'][$element_key]['value'] = '[' . $checkboxes[$field_key]['element_id'] . ']';
2129 3438 } else {
2130 -
2131 3439 $field_values = FrmFieldsHelper::setup_new_vars('checkbox', $item);
2132 3440 $field_values['options'] = array();
2133 -
2134 - if ($field_id = FrmField::create($field_values)) {
2135 - $field = FrmField::getOne($field_id);
2136 - $update = array(
2137 - 'name' => '[' . $field->id . ']'
2138 - );
2139 - if (get_option('e2pdf_formidable_use_keys')) {
2140 - $field_id = $field->field_key;
2141 - $update = array(
2142 - 'name' => '[' . $field->field_key . ']'
2143 - );
2144 - }
2145 - FrmField::update($field_id, $update);
2146 - $pages[$page_key]['elements'][$element_key]['value'] = '[' . $field_id . ']';
2147 -
2148 - $checkboxes[] = array(
2149 - 'name' => $element['name'],
2150 - 'element_id' => $field_id,
2151 - 'field_id' => $field->id,
2152 - 'options' => array(
2153 - $element['properties']['option'],
2154 - )
2155 - );
2156 - }
2157 3441 }
2158 3442 } elseif ($element['type'] == 'e2pdf-radio') {
3443 + if (isset($element['properties']['group']) && $element['properties']['group']) {
3444 + $element['name'] = $element['properties']['group'];
3445 + } else {
3446 + $element['name'] = $element['element_id'];
3447 + }
3448 +
2159 3449 $field_key = array_search($element['name'], array_column($radios, 'name'));
2160 3450 if ($field_key !== false) {
2161 3451 $radios[$field_key]['options'][] = $element['properties']['option'];
2162 3452 $pages[$page_key]['elements'][$element_key]['value'] = '[' . $radios[$field_key]['element_id'] . ']';
2163 3453 } else {
2164 -
2165 3454 $field_values = FrmFieldsHelper::setup_new_vars('radio', $item);
2166 3455 $field_values['options'] = array();
3456 + }
3457 + }
2167 3458
2168 - if ($field_id = FrmField::create($field_values)) {
2169 - $field = FrmField::getOne($field_id);
2170 - $update = array(
2171 - 'name' => '[' . $field->id . ']'
2172 - );
2173 - if (get_option('e2pdf_formidable_use_keys')) {
2174 - $field_id = $field->field_key;
2175 - $update = array(
2176 - 'name' => '[' . $field->field_key . ']'
2177 - );
2178 - }
2179 - FrmField::update($field_id, $update);
2180 - $pages[$page_key]['elements'][$element_key]['value'] = '[' . $field_id . ']';
3459 + $field_id = !empty($field_values) ? FrmField::create($field_values) : false;
3460 + if ($field_id) {
3461 + $field = FrmField::getOne($field_id);
3462 + $labels = array();
2181 3463
2182 - $radios[] = array(
2183 - 'name' => $element['name'],
2184 - 'element_id' => $field_id,
2185 - 'field_id' => $field->id,
2186 - 'options' => array(
2187 - $element['properties']['option'],
2188 - )
2189 - );
2190 - }
3464 + if ($auto_form_shortcode) {
3465 + $labels[] = get_option('e2pdf_formidable_use_keys', '0') ? '[' . $field->field_key . ']' : '[' . $field->id . ']';
2191 3466 }
3467 +
3468 + if ($auto_form_label && $auto_form_label == 'value' && isset($element['value']) && $element['value']) {
3469 + $labels[] = $element['value'];
3470 + } elseif ($auto_form_label && $auto_form_label == 'name' && isset($element['name']) && $element['name']) {
3471 + $labels[] = $element['name'];
3472 + }
3473 +
3474 + if (!empty($labels)) {
3475 + $update = array(
3476 + 'name' => implode(' ', $labels),
3477 + );
3478 + FrmField::update($field_id, $update);
3479 + }
3480 +
3481 + if ($element['type'] == 'e2pdf-textarea') {
3482 + $pages[$page_key]['elements'][$element_key]['value'] = get_option('e2pdf_formidable_use_keys', '0') ? '[' . $field->field_key . ' wpautop=0]' : '[' . $field->id . ' wpautop=0]';
3483 + } else {
3484 + $pages[$page_key]['elements'][$element_key]['value'] = get_option('e2pdf_formidable_use_keys', '0') ? '[' . $field->field_key . ']' : '[' . $field->id . ']';
3485 + }
3486 +
3487 + if (isset($element['properties']['esig'])) {
3488 + unset($pages[$page_key]['elements'][$element_key]['properties']['esig']);
3489 + }
3490 +
3491 + if ($element['type'] == 'e2pdf-checkbox') {
3492 + $checkboxes[] = array(
3493 + 'name' => $element['name'],
3494 + 'element_id' => $field_id,
3495 + 'field_id' => $field->id,
3496 + 'options' => array(
3497 + $element['properties']['option'],
3498 + ),
3499 + );
3500 + } elseif ($element['type'] == 'e2pdf-radio') {
3501 + $radios[] = array(
3502 + 'name' => $element['name'],
3503 + 'element_id' => $field_id,
3504 + 'field_id' => $field->id,
3505 + 'options' => array(
3506 + $element['properties']['option'],
3507 + ),
3508 + );
3509 + }
2192 3510 }
2193 3511 }
2194 3512 }
2195 3513 }
@@ -2195,9 +3513,9 @@
2195 3513 }
2196 3514
2197 3515 foreach ($checkboxes as $element) {
2198 3516 $update = array(
2199 - 'options' => $element['options']
3517 + 'options' => $element['options'],
2200 3518 );
2201 3519 FrmField::update($element['field_id'], $update);
2202 3520 }
2203 3521
@@ -2202,9 +3520,9 @@
2202 3520 }
2203 3521
2204 3522 foreach ($radios as $element) {
2205 3523 $update = array(
2206 - 'options' => $element['options']
3524 + 'options' => $element['options'],
2207 3525 );
2208 3526 FrmField::update($element['field_id'], $update);
2209 3527 }
2210 3528
@@ -2215,49 +3533,66 @@
2215 3533 return $template;
2216 3534 }
2217 3535
2218 3536 /**
2219 - * Visual Mapper for Mapping field
2220 - *
2221 - * @return bool|string - Prepared form or false
3537 + * Init Visual Mapper data
3538 + * @return bool|string - HTML data source for Visual Mapper
2222 3539 */
2223 3540 public function visual_mapper() {
2224 3541
2225 - $item = $this->get('item');
2226 3542 $html = '';
2227 3543 $source = '';
2228 3544
2229 - if ($item && class_exists('FrmformsController')) {
2230 -
3545 + if ($this->get('item') && class_exists('FrmformsController')) {
3546 + $child = false;
3547 + if ($this->get('cached_form') && !empty($this->get('cached_form')->parent_form_id)) {
3548 + $child = true;
3549 + $this->set('item', $this->get('cached_form')->parent_form_id);
3550 + }
2231 3551 if (class_exists('FrmProFieldsHelper')) {
2232 - add_filter('frm_get_paged_fields', array($this, 'filter_remove_pagebreaks'), 9, 1);
3552 + add_filter('frm_get_paged_fields', array($this, 'filter_remove_pagebreaks'), 9);
2233 3553 }
2234 3554 add_filter('frm_show_new_entry_page', array($this, 'filter_frm_show_new_entry_page'), 99);
2235 - $source = FrmformsController::show_form($item, '', true, true);
2236 - if (class_exists("FrmProFieldsHelper")) {
3555 + add_filter('frm_pre_display_form', array($this, 'filter_frm_pre_display_form'));
3556 + $source = FrmformsController::show_form($this->get('item'), '', true, true);
3557 + if (class_exists('FrmProFieldsHelper')) {
2237 3558 remove_filter('frm_get_paged_fields', array($this, 'filter_remove_pagebreaks'), 9);
2238 3559 }
2239 3560 remove_filter('frm_show_new_entry_page', array($this, 'filter_frm_show_new_entry_page'), 99);
2240 -
3561 + remove_filter('frm_pre_display_form', array($this, 'filter_frm_pre_display_form'));
2241 3562 if ($source) {
2242 - libxml_use_internal_errors(true);
2243 3563 $dom = new DOMDocument();
2244 - if (function_exists('mb_convert_encoding')) {
2245 - $html = $dom->loadHTML(mb_convert_encoding($source, 'HTML-ENTITIES', 'UTF-8'));
2246 - } else {
2247 - $html = $dom->loadHTML('<?xml encoding="UTF-8">' . $source);
2248 - }
2249 - libxml_clear_errors();
3564 + $html = $this->helper->load('convert')->load_html($source, $dom, true);
2250 3565 }
2251 -
2252 3566 if (!$source) {
2253 - return __('Form source is empty', 'e2pdf');
3567 + return '<div class="e2pdf-vm-error">' . __("The form source is empty or doesn't exist", 'e2pdf') . '</div>';
2254 3568 } elseif (!$html) {
2255 - return __('Form could not be parsed due incorrect HTML', 'e2pdf');
3569 + return '<div class="e2pdf-vm-error">' . __('The form could not be parsed due the incorrect HTML', 'e2pdf') . '</div>';
2256 3570 } else {
2257 3571
3572 + $xml = $this->helper->load('xml');
2258 3573 $xpath = new DomXPath($dom);
2259 3574
3575 + // remove by name
3576 + $remove_by_name = array(
3577 + 'frm_action',
3578 + 'form_id',
3579 + 'frm_hide_fields_' . $this->get('item'),
3580 + 'form_key',
3581 + '0',
3582 + 'frm_submit_entry_' . $this->get('item'),
3583 + '_wp_http_referer',
3584 + 'item_key',
3585 + 'frm_state',
3586 + );
3587 + foreach ($remove_by_name as $key => $name) {
3588 + $elements = $xpath->query('//*[@name="' . $name . '"]');
3589 + foreach ($elements as $element) {
3590 + $element->parentNode->removeChild($element);
3591 + }
3592 + }
3593 +
3594 + // remove by class
2260 3595 $remove_by_class = array(
2261 3596 'frm_ajax_loading',
2262 3597 'wp-editor-tools',
2263 3598 'quicktags-toolbar',
@@ -2265,9 +3600,10 @@
2265 3600 'frm_range_value',
2266 3601 'star-rating',
2267 3602 'frm_repeat_buttons',
2268 3603 'frm_save_draft',
2269 - 'frm_final_submit'
3604 + 'frm_final_submit',
3605 + 'frm_verify',
2270 3606 );
2271 3607 foreach ($remove_by_class as $key => $class) {
2272 3608 $elements = $xpath->query("//*[contains(@class, '{$class}')]");
2273 3609 foreach ($elements as $element) {
@@ -2274,44 +3610,42 @@
2274 3610 $element->parentNode->removeChild($element);
2275 3611 }
2276 3612 }
2277 3613
3614 + // remove by tag
2278 3615 $remove_by_tag = array(
2279 3616 'link',
2280 3617 'style',
2281 - 'script'
3618 + 'script',
2282 3619 );
2283 3620 foreach ($remove_by_tag as $key => $tag) {
2284 - $elements = $xpath->query("//{$tag}");
3621 + $elements = $xpath->query('//' . $tag);
2285 3622 foreach ($elements as $element) {
2286 3623 $element->parentNode->removeChild($element);
2287 3624 }
2288 3625 }
2289 3626
3627 + // remove classes
2290 3628 $remove_classes = array(
2291 3629 'wp-editor-container',
2292 - 'frm_logic_form'
3630 + 'frm_logic_form',
3631 + 'frm_pos_none',
2293 3632 );
2294 -
2295 3633 foreach ($remove_classes as $key => $class) {
2296 3634 $elements = $xpath->query("//*[contains(@class, '{$class}')]");
2297 3635 foreach ($elements as $element) {
2298 - if ($element->attributes->getNamedItem("class")) {
2299 - $element->attributes->getNamedItem("class")->nodeValue = str_replace($class, '', $element->attributes->getNamedItem("class")->nodeValue);
2300 - }
3636 + $xml->set_node_value($element, 'class', str_replace($class, '', $xml->get_node_value($element, 'class')));
2301 3637 }
2302 3638 }
2303 3639
3640 + // remove styles
2304 3641 $remove_styles = array(
2305 - 'frm_toggle_container'
3642 + 'frm_toggle_container',
2306 3643 );
2307 -
2308 3644 foreach ($remove_styles as $key => $class) {
2309 3645 $elements = $xpath->query("//*[contains(@class, '{$class}')]");
2310 3646 foreach ($elements as $element) {
2311 - if ($element->attributes->getNamedItem("style")) {
2312 - $element->attributes->getNamedItem("style")->nodeValue = '';
2313 - }
3647 + $xml->set_node_value($element, 'style', '');
2314 3648 }
2315 3649 }
2316 3650
2317 3651 /*
@@ -2317,24 +3651,24 @@
2317 3651 /*
2318 3652 * Metas patterns to replace field names
2319 3653 * @since 0.01.42
2320 3654 */
2321 - $metas_pattern = array(
2322 - '/item_meta\[(?:.*?)\]\[0\]\[(.*?)\](?:\[\])?/i' => '$1:1',
3655 + $metas_pattern = [
3656 + '/item_meta\[(?:.*?)\]\[0\]\[(.*?)\](?:\[\])?/i' => $child ? '$1' : '$1:1',
2323 3657 '/item_meta\[(.*?)\](\[\])?/i' => '$1',
2324 - );
3658 + ];
2325 3659
2326 - // Replace names
3660 + // replace names
2327 3661 $metas = $xpath->query("//*[contains(@name, 'item_meta')]");
2328 3662 foreach ($metas as $element) {
2329 - $field_id = preg_replace(array_keys($metas_pattern), $metas_pattern, $element->attributes->getNamedItem("name")->nodeValue);
2330 - if (get_option('e2pdf_formidable_use_keys') && class_exists('FrmField')) {
3663 + $field_id = preg_replace(array_keys($metas_pattern), $metas_pattern, $xml->get_node_value($element, 'name'));
3664 + if (get_option('e2pdf_formidable_use_keys', '0') && class_exists('FrmField')) {
2331 3665 if (strpos($field_id, ':') !== false) {
2332 - $repeat_data = explode(":", $field_id);
3666 + $repeat_data = explode(':', $field_id);
2333 3667 if (isset($repeat_data['0'])) {
2334 3668 $field_data = FrmField::getOne($repeat_data['0']);
2335 3669 if ($field_data) {
2336 - $field_id = $field_data->field_key . ":1";
3670 + $field_id = $field_data->field_key . ':1';
2337 3671 }
2338 3672 }
2339 3673 } else {
2340 3674 $field_data = FrmField::getOne($field_id);
@@ -2342,186 +3676,66 @@
2342 3676 $field_id = $field_data->field_key;
2343 3677 }
2344 3678 }
2345 3679 }
2346 -
2347 - if ($element->attributes->getNamedItem("name")) {
2348 - $element->attributes->getNamedItem("name")->nodeValue = $field_id;
2349 - }
3680 + $xml->set_node_value($element, 'name', $field_id);
2350 3681 }
2351 3682
2352 - // Time field replace
2353 - $time_fields = $xpath->query("//div/select[contains(@class, 'frm_time_select')]/parent::*");
2354 - foreach ($time_fields as $key => $element) {
2355 - $span = $xpath->query("./span", $element)->item(0);
2356 - $select = $xpath->query("./select", $element)->item(0);
2357 -
2358 - if ($span && $select) {
2359 -
2360 - $span_cloned = $span->cloneNode(true);
2361 - $select_cloned = $select->cloneNode(true);
2362 -
2363 - foreach ($xpath->query("./select", $span_cloned) as $key => $sub_select) {
2364 - if ($sub_select->attributes->getNamedItem("class")) {
2365 - $sub_select->attributes->getNamedItem("class")->nodeValue = $sub_select->attributes->getNamedItem("class")->nodeValue . " e2pdf-no-vm";
2366 - }
2367 - }
2368 -
2369 - if ($select_cloned->attributes->getNamedItem("class")) {
2370 - $select_cloned->attributes->getNamedItem("class")->nodeValue = $select_cloned->attributes->getNamedItem("class")->nodeValue . " e2pdf-no-vm";
2371 - }
2372 -
2373 - $span->parentNode->removeChild($span);
2374 - $select->parentNode->removeChild($select);
2375 -
2376 - $wrapper = $dom->createElement('div');
2377 - $wrapper_atts = array(
2378 - 'class' => 'e2pdf-vm-field-wrapper',
2379 - );
2380 -
2381 - foreach ($wrapper_atts as $key => $value) {
2382 - $attr = $dom->createAttribute($key);
2383 - $attr->value = $value;
2384 - $wrapper->appendChild($attr);
2385 - }
2386 -
2387 - $field = $dom->createElement('input');
2388 -
2389 - $field_id = preg_replace('/\[(.*?)\]/i', '', $select_cloned->attributes->getNamedItem("name")->nodeValue);
2390 - if (get_option('e2pdf_formidable_use_keys') && class_exists("FrmField")) {
2391 - $field_data = FrmField::getOne($field_id);
2392 - if ($field_data) {
2393 - $field_id = $field_data->field_key;
2394 - }
2395 - }
2396 -
2397 - $field_atts = array(
2398 - 'type' => 'text',
2399 - 'class' => 'e2pdf-vm-field',
2400 - 'name' => $field_id
2401 - );
2402 -
2403 - foreach ($field_atts as $key => $value) {
2404 - $attr = $dom->createAttribute($key);
2405 - $attr->value = $value;
2406 - $field->appendChild($attr);
2407 - }
2408 -
2409 - $wrapper->appendChild($field);
2410 - $wrapper->appendChild($span_cloned);
2411 - $wrapper->appendChild($select_cloned);
2412 -
2413 - $element->appendChild($wrapper);
2414 - }
2415 - }
2416 -
2417 - // Combo fields
2418 3683 $frm_combo_inputs_container = $xpath->query("//*[contains(@class, 'frm_combo_inputs_container')]");
2419 3684 foreach ($frm_combo_inputs_container as $element) {
3685 + $inputs = $xpath->query('.//input', $element);
3686 + $selects = $xpath->query('.//select', $element);
2420 3687
2421 - $inputs = $xpath->query(".//input", $element);
2422 - $selects = $xpath->query(".//select", $element);
2423 -
2424 3688 foreach ($selects as $key => $sub_element) {
2425 - if ($sub_element->attributes->getNamedItem("class")) {
2426 - $sub_element->attributes->getNamedItem("class")->nodeValue = $sub_element->attributes->getNamedItem("class")->nodeValue . " e2pdf-no-vm";
2427 - } else {
2428 - $class = $dom->createAttribute('class');
2429 - $class->value = 'e2pdf-no-vm';
2430 - $sub_element->appendChild($class);
3689 + $field_data = array();
3690 + preg_match('/(.*?)\[(.*?)\]/i', $xml->get_node_value($sub_element, 'name'), $field_data);
3691 + if (!empty($field_data) && isset($field_data[1]) && isset($field_data[2])) {
3692 + $field_id = $field_data[1] . ' show="' . $field_data[2] . '"';
3693 + $xml->set_node_value($sub_element, 'name', $field_id);
2431 3694 }
2432 3695 }
2433 3696
2434 3697 foreach ($inputs as $key => $sub_element) {
2435 - if ($sub_element->attributes->getNamedItem("class")) {
2436 - $sub_element->attributes->getNamedItem("class")->nodeValue = $sub_element->attributes->getNamedItem("class")->nodeValue . " e2pdf-no-vm";
2437 - } else {
2438 - $class = $dom->createAttribute('class');
2439 - $class->value = 'e2pdf-no-vm';
2440 - $sub_element->appendChild($class);
3698 + $field_data = array();
3699 + preg_match('/(.*?)\[(.*?)\]/i', $xml->get_node_value($sub_element, 'name'), $field_data);
3700 + if (!empty($field_data) && isset($field_data[1]) && isset($field_data[2])) {
3701 + $field_id = $field_data[1] . ' show="' . $field_data[2] . '"';
3702 + $xml->set_node_value($sub_element, 'name', $field_id);
2441 3703 }
2442 3704 }
2443 -
2444 - $name = "";
2445 - if ($inputs->item(0)) {
2446 - $name = $inputs->item(0)->attributes->getNamedItem("name")->nodeValue;
2447 - } else {
2448 - $name = $selects->item(0)->attributes->getNamedItem("name")->nodeValue;
2449 - }
2450 -
2451 - $field_id = preg_replace('/\[(.*?)\]/i', '', $name);
2452 - if (get_option('e2pdf_formidable_use_keys') && class_exists("FrmField")) {
2453 - $field_data = FrmField::getOne($field_id);
2454 - if ($field_data) {
2455 - $field_id = $field_data->field_key;
2456 - }
2457 - }
2458 -
2459 - $field = $dom->createElement('input');
2460 - $field_atts = array(
2461 - 'type' => 'text',
2462 - 'class' => 'e2pdf-vm-field',
2463 - 'name' => $field_id
2464 - );
2465 -
2466 - foreach ($field_atts as $key => $value) {
2467 - $attr = $dom->createAttribute($key);
2468 - $attr->value = $value;
2469 - $field->appendChild($attr);
2470 - }
2471 - $element->appendChild($field);
2472 -
2473 - if ($element->attributes->getNamedItem("class")) {
2474 - $element->attributes->getNamedItem("class")->nodeValue = $element->attributes->getNamedItem("class")->nodeValue . " e2pdf-vm-field-wrapper";
2475 - }
2476 3705 }
2477 3706
2478 3707 $frm_dropzone = $xpath->query("//*[contains(@class, 'frm_dropzone')]/parent::*");
2479 3708 foreach ($frm_dropzone as $element) {
2480 3709 $dropzone = $xpath->query(".//*[contains(@class, 'frm_dropzone')]", $element)->item(0);
2481 - $input = $xpath->query(".//input", $element)->item(0);
3710 + $input = $xpath->query('.//input', $element)->item(0);
2482 3711 if ($input && $dropzone) {
2483 3712 $input_cloned = $input->cloneNode(true);
2484 3713
2485 - if ($input_cloned->attributes->getNamedItem("type")) {
2486 - $input_cloned->attributes->getNamedItem("type")->nodeValue = 'text';
2487 - }
3714 + $xml->set_node_value($input_cloned, 'type', 'text');
3715 + $xml->set_node_value($input_cloned, 'value', __('File Upload', 'formidable'));
3716 + $xml->set_node_value($input_cloned, 'style', 'width: 100%; height: 200px; text-align: center;');
2488 3717
2489 - if ($input_cloned->attributes->getNamedItem("value")) {
2490 - $input_cloned->attributes->getNamedItem("value")->nodeValue = __('File Upload', 'e2pdf');
3718 + if (strpos($xml->get_node_value($input_cloned, 'name'), ':') !== false) {
3719 + $xml->set_node_value($input_cloned, 'name', $xml->get_node_value($input_cloned, 'name') . ' size="full" show_image="0" add_link="0"');
3720 + } else {
3721 + $xml->set_node_value($input_cloned, 'name', $xml->get_node_value($input_cloned, 'name') . ' size="full"');
2491 3722 }
2492 3723
2493 - if ($input_cloned->attributes->getNamedItem("name")) {
2494 - if (strpos($input_cloned->attributes->getNamedItem("name")->nodeValue, ':') !== false) {
2495 - $input_cloned->attributes->getNamedItem("name")->nodeValue = $input_cloned->attributes->getNamedItem("name")->nodeValue . " size='full' show_image='0' add_link='0'";
2496 - } else {
2497 - $input_cloned->attributes->getNamedItem("name")->nodeValue = $input_cloned->attributes->getNamedItem("name")->nodeValue . " size='full'";
2498 - }
2499 - }
2500 -
2501 - $style = $dom->createAttribute('style');
2502 - $style->value = 'width: 100%; height: 200px; text-align: center;';
2503 - $input_cloned->appendChild($style);
2504 -
2505 3724 $input->parentNode->replaceChild($input_cloned, $input);
2506 3725 $dropzone->parentNode->removeChild($dropzone);
2507 3726 }
2508 3727 }
2509 3728
2510 - // Replace signature
3729 + // replace signature
2511 3730 $sigpad = $xpath->query("//*[contains(@class, 'sigPad')]");
2512 3731 foreach ($sigpad as $element) {
2513 - $input = $xpath->query(".//input", $element)->item(0);
3732 + $input = $xpath->query('.//input', $element)->item(0);
2514 3733 if ($input) {
2515 3734 $input_cloned = $input->cloneNode(true);
2516 3735
2517 - $style = $dom->createAttribute('style');
2518 - $style->value = 'width: 300px; height: 100px;';
2519 - $input_cloned->appendChild($style);
2520 -
2521 - $field_id = preg_replace('/\[(.*?)\]/i', '', $input_cloned->attributes->getNamedItem("name")->nodeValue);
2522 -
2523 - if (get_option('e2pdf_formidable_use_keys') && class_exists("FrmField")) {
3736 + $field_id = preg_replace('/\[(.*?)\]/i', '', $xml->get_node_value($input_cloned, 'name'));
3737 + if (get_option('e2pdf_formidable_use_keys', '0') && class_exists('FrmField')) {
2524 3738 $field_data = FrmField::getOne($field_id);
2525 3739 if ($field_data) {
2526 3740 $field_id = $field_data->field_key;
2527 3741 }
@@ -2526,173 +3740,219 @@
2526 3740 $field_id = $field_data->field_key;
2527 3741 }
2528 3742 }
2529 3743
2530 - if ($input_cloned->attributes->getNamedItem("name")) {
2531 - $input_cloned->attributes->getNamedItem("name")->nodeValue = $field_id;
2532 - }
2533 -
3744 + $xml->set_node_value($input_cloned, 'style', 'width: 300px; height: 100px;');
3745 + $xml->set_node_value($input_cloned, 'name', $field_id);
2534 3746 $element->parentNode->replaceChild($input_cloned, $element);
2535 3747 }
2536 3748 }
2537 3749
2538 - // Replace names
2539 - $fields = $xpath->query("//input");
3750 + // replace names
3751 + $fields = $xpath->query('//input');
2540 3752 foreach ($fields as $element) {
2541 3753
2542 - if (class_exists('FrmField')) {
3754 + $image_options = false;
3755 + $separate_value = false;
2543 3756
2544 - if ($element->attributes->getNamedItem("type")->nodeValue == 'checkbox' || $element->attributes->getNamedItem("type")->nodeValue == 'radio') {
3757 + if (class_exists('FrmField') && ($xml->get_node_value($element, 'type') == 'checkbox' || $xml->get_node_value($element, 'type') == 'radio')) {
2545 3758
2546 - $field_id = $element->attributes->getNamedItem("name")->nodeValue;
2547 - if (false !== strpos($element->attributes->getNamedItem("name")->nodeValue, ':')) {
2548 - $field_id = substr($element->attributes->getNamedItem("name")->nodeValue, 0, strpos($element->attributes->getNamedItem("name")->nodeValue, ":"));
3759 + $field_id = $xml->get_node_value($element, 'name');
3760 + if (false !== strpos($xml->get_node_value($element, 'name'), ':')) {
3761 + $field_id = substr($xml->get_node_value($element, 'name'), 0, strpos($xml->get_node_value($element, 'name'), ':'));
3762 + }
3763 + if (preg_match('/\[(other(.*?[^\]]))\]/', $field_id)) {
3764 + $field_id = preg_replace('/\[(other(.*?[^\]]))\]/', '', $field_id);
3765 + }
3766 +
3767 + $field_data = FrmField::getOne($field_id);
3768 +
3769 + if (isset($field_data->field_options['image_options']) && $field_data->field_options['image_options']) {
3770 + $image_options = true;
3771 + }
3772 +
3773 + if (isset($field_data->field_options['separate_value']) && $field_data->field_options['separate_value']) {
3774 + $separate_value = true;
3775 + }
3776 +
3777 + if (isset($field_data->type) && $field_data->type === 'data' && isset($field_data->field_options['form_select'])) {
3778 + $dynamic_form_id = false;
3779 + $dynamic_field_id = false;
3780 +
3781 + $dynamic_field_id = $field_data->field_options['form_select'];
3782 + $dynamic_field_data = FrmField::getOne($dynamic_field_id);
3783 + if ($dynamic_field_data) {
3784 + $dynamic_form_id = $dynamic_field_data->form_id;
2549 3785 }
2550 3786
2551 - $field_data = FrmField::getOne($field_id);
3787 + $options = array();
3788 + if (class_exists('FrmEntry') && class_exists('FrmEntryMeta')) {
3789 + $where = array(
3790 + 'it.form_id' => $dynamic_form_id,
3791 + );
3792 + $entries_tmp = FrmEntry::getAll($where, ' ORDER BY id ASC');
3793 + foreach ($entries_tmp as $key => $entry) {
3794 + $options[] = array(
3795 + 'label' => FrmEntryMeta::get_meta_value($entry, $dynamic_field_id),
3796 + 'value' => $key,
3797 + );
3798 + }
3799 + }
3800 + $field_data->options = $options;
3801 + }
2552 3802
2553 - if (isset($field_data->type) && $field_data->type === 'data' && isset($field_data->field_options['form_select'])) {
2554 - $dynamic_form_id = false;
2555 - $dynamic_field_id = false;
3803 + if (isset($field_data->options) && is_array($field_data->options)) {
2556 3804
2557 - $dynamic_field_id = $field_data->field_options['form_select'];
2558 - $dynamic_field_data = FrmField::getOne($dynamic_field_id);
2559 - if ($dynamic_field_data) {
2560 - $dynamic_form_id = $dynamic_field_data->form_id;
2561 - }
3805 + $field_options = $field_data->options;
3806 + $field_value = $xml->get_node_value($element, 'value');
2562 3807
2563 - $options = array();
2564 - if (class_exists('FrmEntry') && class_exists('FrmEntryMeta')) {
2565 - $where = array(
2566 - 'it.form_id' => $dynamic_form_id
2567 - );
2568 - $entries_tmp = FrmEntry::getAll($where, ' ORDER BY id ASC');
2569 - foreach ($entries_tmp as $key => $entry) {
2570 - $options[] = array(
2571 - 'label' => FrmEntryMeta::get_meta_value($entry, $dynamic_field_id),
2572 - 'value' => $key,
2573 - );
2574 - }
3808 + $field_key = false;
3809 + foreach ($field_options as $fv_key => $fv) {
3810 + if (isset($fv['value']) && $fv['value'] == $field_value) {
3811 + $field_key = $fv_key;
3812 + break;
2575 3813 }
2576 - $field_data->options = $options;
2577 3814 }
2578 3815
2579 - if (isset($field_data->options) && is_array($field_data->options)) {
2580 - $field_options = $field_data->options;
2581 - $field_value = $element->attributes->getNamedItem("value")->nodeValue;
2582 - $field_key = array_search($field_value, array_column($field_options, 'value'));
3816 + if ($field_key !== false) {
3817 + if ($image_options && $separate_value) {
3818 + $field_label = isset($field_options[$field_key]['value']) ? $field_options[$field_key]['value'] : $field_value;
3819 + } else {
3820 + $field_label = isset($field_options[$field_key]['label']) ? $field_options[$field_key]['label'] : $field_value;
3821 + }
3822 + $xml->set_node_value($element, 'value', $field_label);
3823 + } elseif ($xml->get_node_value($element, 'type') == 'radio') {
3824 + $xml->set_node_value($element, 'value', '[' . $field_id . ' show="value" key="other"]');
3825 + } else {
3826 + $field_key = array_search($field_value, $field_options);
2583 3827 if ($field_key !== false) {
2584 - $field_label = isset($field_options[$field_key]['label']) ? $field_options[$field_key]['label'] : $field_value;
3828 + $xml->set_node_value($element, 'value', '[' . $field_id . ' show="value" key="' . $field_key . '"]');
3829 + }
3830 + }
3831 + }
3832 + }
2585 3833
2586 - if ($element->attributes->getNamedItem("value")) {
2587 - $element->attributes->getNamedItem("value")->nodeValue = $field_label;
2588 - }
2589 - }
3834 + $name = false;
3835 + if ($xml->get_node_value($element, 'type') == 'text') {
3836 + if (preg_match('/other\[(.*?[^\]])\]\[(other(.*?[^\]]))\]/', $xml->get_node_value($element, 'name'))) {
3837 + $name = preg_replace('/other\[(.*?[^\]])\]\[(other(.*?[^\]]))\]/', '$1 show="value" key="$2"', $xml->get_node_value($element, 'name'));
3838 + } elseif (preg_match('/other\[(.*?[^\]])\]/', $xml->get_node_value($element, 'name'))) {
3839 + $name = preg_replace('/other\[(.*?[^\]])\]/', '$1 show="value" key="other"', $xml->get_node_value($element, 'name'));
3840 + }
3841 + } elseif ($xml->get_node_value($element, 'type') == 'checkbox') {
3842 + if (preg_match('/\[(other(.*?[^\]]))\]/', $xml->get_node_value($element, 'name'))) {
3843 + $name = preg_replace('/\[(other(.*?[^\]]))\]/', '', $xml->get_node_value($element, 'name'));
3844 + } else {
3845 + if ($image_options) {
3846 + $name = $xml->get_node_value($element, 'name') . ' show="value"';
2590 3847 }
2591 3848 }
3849 + } elseif ($xml->get_node_value($element, 'type') == 'radio') {
3850 + if ($image_options) {
3851 + $name = $xml->get_node_value($element, 'name') . ' show="value"';
3852 + }
2592 3853 }
2593 3854
2594 - if ($element->attributes->getNamedItem("name")) {
2595 - $element->attributes->getNamedItem("name")->nodeValue = "[" . $element->attributes->getNamedItem("name")->nodeValue . "]";
3855 + if (!$name) {
3856 + $name = $xml->get_node_value($element, 'name');
2596 3857 }
3858 +
3859 + $xml->set_node_value($element, 'name', '[' . $name . ']');
2597 3860 }
2598 3861
2599 - // Replace names
2600 - $textareas = $xpath->query("//textarea");
3862 + // replace names
3863 + $textareas = $xpath->query('//textarea');
2601 3864 foreach ($textareas as $element) {
2602 - if ($element->attributes->getNamedItem("name")) {
2603 - $element->attributes->getNamedItem("name")->nodeValue = "[" . $element->attributes->getNamedItem("name")->nodeValue . " wpautop=0]";
2604 - }
3865 + $xml->set_node_value($element, 'name', '[' . $xml->get_node_value($element, 'name') . ' wpautop=0]');
2605 3866 }
2606 3867
2607 - // Replace names
2608 - $selects = $xpath->query("//select");
3868 + // replace names
3869 + $selects = $xpath->query('//select');
2609 3870 foreach ($selects as $element) {
2610 3871
2611 3872 if (class_exists('FrmField')) {
2612 3873
2613 - $options = $xpath->query(".//option", $element);
3874 + $options = $xpath->query('.//option', $element);
3875 + $field_id = $xml->get_node_value($element, 'name');
2614 3876
2615 - $field_id = $element->attributes->getNamedItem("name")->nodeValue;
2616 - if (false !== strpos($element->attributes->getNamedItem("name")->nodeValue, ':')) {
2617 - $field_id = substr($element->attributes->getNamedItem("name")->nodeValue, 0, strpos($element->attributes->getNamedItem("name")->nodeValue, ":"));
3877 + /* Time Field names */
3878 + if (false !== strpos($xml->get_node_value($element, 'name'), ':')) {
3879 + $field_id = substr($xml->get_node_value($element, 'name'), 0, strpos($xml->get_node_value($element, 'name'), ':'));
2618 3880 }
3881 + $field_id = str_replace(array('[H]', '[m]', '[A]'), '', $field_id);
2619 3882
2620 3883 $field_data = FrmField::getOne($field_id);
2621 -
2622 - if (isset($field_data->type) && ($field_data->type === 'lookup' || $field_data->type === 'data')) {
2623 - $dynamic_form_id = false;
2624 - $dynamic_field_id = false;
2625 -
2626 - if ($field_data->type === 'lookup' && isset($field_data->field_options['get_values_field']) && isset($field_data->field_options['get_values_form'])) {
2627 - $dynamic_form_id = $field_data->field_options['get_values_form'];
2628 - $dynamic_field_id = $field_data->field_options['get_values_field'];
2629 -
2630 - if (get_option('e2pdf_formidable_use_keys')) {
2631 - $dynamic_field_data = FrmField::getOne($dynamic_field_id);
2632 -
2633 - if ($dynamic_field_data) {
2634 - $dynamic_field_id = $dynamic_field_data->field_key;
2635 - }
2636 - }
2637 - } elseif ($field_data->type === 'data' && isset($field_data->field_options['form_select'])) {
2638 - $dynamic_field_id = $field_data->field_options['form_select'];
2639 - $dynamic_field_data = FrmField::getOne($dynamic_field_id);
2640 -
2641 - if ($dynamic_field_data) {
2642 - $dynamic_form_id = $dynamic_field_data->form_id;
2643 -
2644 - if (get_option('e2pdf_formidable_use_keys')) {
2645 - $dynamic_field_id = $dynamic_field_data->field_key;
2646 - }
2647 - }
3884 + if (isset($field_data->type) && $field_data->type === 'lookup') {
3885 + foreach ($options as $option) {
3886 + $option->parentNode->removeChild($option);
2648 3887 }
3888 + $wrapper = $dom->createElement('option');
3889 + $wrapper_atts = array(
3890 + 'value' => '[e2pdf-frm-lookup-values id="' . $field_id . '"]',
3891 + );
3892 + foreach ($wrapper_atts as $key => $value) {
3893 + $attr = $dom->createAttribute($key);
3894 + $attr->value = $value;
3895 + $wrapper->appendChild($attr);
3896 + }
3897 + $element->appendChild($wrapper);
3898 + } elseif (isset($field_data->type) && $field_data->type === 'data') {
3899 + foreach ($options as $option) {
3900 + $option->parentNode->removeChild($option);
3901 + }
3902 + $wrapper = $dom->createElement('option');
3903 + $wrapper_atts = array(
3904 + 'value' => '[e2pdf-frm-data-values id="' . $field_id . '"]',
3905 + );
3906 + foreach ($wrapper_atts as $key => $value) {
3907 + $attr = $dom->createAttribute($key);
3908 + $attr->value = $value;
3909 + $wrapper->appendChild($attr);
3910 + }
3911 + $element->appendChild($wrapper);
3912 + } elseif (isset($field_data->type) && $field_data->type === 'time') {
3913 + $replace = array(
3914 + '[m]' => ' format="i"',
3915 + '[A]' => ' format="A"',
3916 + );
3917 + if (isset($field_data->field_options['clock']) && $field_data->field_options['clock'] == '12') {
3918 + $replace['[H]'] = ' format="g"';
3919 + } else {
3920 + $replace['[H]'] = ' format="H"';
3921 + }
3922 + $xml->set_node_value($element, 'name', str_replace(array_keys($replace), $replace, $xml->get_node_value($element, 'name')));
3923 + }
2649 3924
2650 - if ($dynamic_form_id && $dynamic_field_id) {
2651 -
2652 - foreach ($options as $option) {
2653 - $option->parentNode->removeChild($option);
2654 - }
2655 -
2656 - $wrapper = $dom->createElement('option');
2657 - $wrapper_atts = array(
2658 - 'value' => "[e2pdf-frm-entry-values id='{$dynamic_form_id}' field_id='{$dynamic_field_id}']",
2659 - );
2660 - foreach ($wrapper_atts as $key => $value) {
2661 - $attr = $dom->createAttribute($key);
2662 - $attr->value = $value;
2663 - $wrapper->appendChild($attr);
2664 - }
2665 - $element->appendChild($wrapper);
2666 - }
2667 - } else if (isset($field_data->options) && is_array($field_data->options)) {
3925 + if (isset($field_data->options) && is_array($field_data->options)) {
2668 3926 $field_options = $field_data->options;
2669 3927 foreach ($options as $option) {
2670 - $field_value = $option->attributes->getNamedItem("value")->nodeValue;
3928 + $field_value = $xml->get_node_value($option, 'value');
2671 3929 foreach ($field_options as $field_option) {
2672 3930 if (isset($field_option['value']) && $field_option['value'] === $field_value) {
2673 3931 $field_label = isset($field_option['label']) ? $field_option['label'] : $field_value;
2674 - if ($option->attributes->getNamedItem("value")) {
2675 - $option->attributes->getNamedItem("value")->nodeValue = $field_label;
2676 - }
3932 + $xml->set_node_value($option, 'value', $field_label);
2677 3933 }
2678 3934 }
2679 3935 }
2680 3936 }
2681 3937 }
3938 + $xml->set_node_value($element, 'name', '[' . $xml->get_node_value($element, 'name') . ']');
3939 + }
2682 3940
2683 - if ($element->attributes->getNamedItem("name")) {
2684 - $element->attributes->getNamedItem("name")->nodeValue = "[" . $element->attributes->getNamedItem("name")->nodeValue . "]";
3941 + // show total formatted fields
3942 + $total_formatted = $xpath->query("//*[contains(@class, 'frm_total_formatted')]/parent::*");
3943 + foreach ($total_formatted as $element) {
3944 + $elements = $xpath->query("//*[contains(@class, 'frm_hidden')]");
3945 + foreach ($elements as $element) {
3946 + $xml->set_node_value($element, 'class', str_replace('frm_hidden', '', $xml->get_node_value($element, 'class')));
2685 3947 }
2686 3948 }
2687 3949
2688 - if ($xpath->query("//form")->item(0) && class_exists('FrmStylesHelper')) {
2689 - $autocomplete = $dom->createAttribute('autocomplete');
2690 - $autocomplete->value = 'off';
2691 - $xpath->query("//form")->item(0)->appendChild($autocomplete);
3950 + if (defined('LIBXML_HTML_NOIMPLIED') && defined('LIBXML_HTML_NODEFDTD')) {
3951 + return str_replace(array('<html>', '</html>'), '', $dom->saveHTML());
3952 + } else {
3953 + return $dom->saveHTML();
2692 3954 }
2693 -
2694 - return $dom->saveHTML();
2695 3955 }
2696 3956 }
2697 3957 return false;
2698 3958 }
@@ -2699,11 +3959,9 @@
2699 3959
2700 3960 /**
2701 3961 * Convert Field name to Value
2702 3962 * @since 0.01.34
2703 - *
2704 3963 * @param string $name - Field name
2705 - *
2706 3964 * @return bool|string - Converted value or false
2707 3965 */
2708 3966 public function auto_map($name = false) {
2709 3967
@@ -2708,19 +3966,25 @@
2708 3966 public function auto_map($name = false) {
2709 3967
2710 3968 $item = $this->get('item');
2711 3969
2712 - if ($item && class_exists("FrmField")) {
2713 - $where = array('fi.form_id' => (int) $item,
2714 - "(fi.field_key = '{$name}' OR fi.name = '{$name}') AND 1" => "1"
3970 + if ($item && class_exists('FrmField')) {
3971 + $where = array(
3972 + 'fi.form_id' => (int) $item,
3973 + array(
3974 + 'or' => 1,
3975 + 'fi.field_key' => $name,
3976 + 'fi.name' => $name,
3977 + ),
2715 3978 );
2716 3979 $field = FrmField::getAll($where, 'id ASC', '1');
2717 3980
2718 3981 if ($field && is_object($field)) {
3982 + $field_id = get_option('e2pdf_formidable_use_keys', '0') ? $field->field_key : $field->id;
2719 3983 if ($field->type == 'textarea' || $field->type == 'rte') {
2720 - return "[" . $field->id . " wpautop=0]";
3984 + return '[' . $field_id . ' wpautop=0]';
2721 3985 } else {
2722 - return "[" . $field->id . "]";
3986 + return '[' . $field_id . ']';
2723 3987 }
2724 3988 }
2725 3989 }
2726 3990
@@ -2731,31 +3995,29 @@
2731 3995 * Load additional shortcodes for this extension
2732 3996 */
2733 3997 public function load_shortcodes() {
2734 3998 add_shortcode('e2pdf-frm-entry-values', array($this, 'shortcode_e2pdf_frm_entry_values'));
3999 + add_shortcode('e2pdf-frm-lookup-values', array($this, 'shortcode_e2pdf_frm_lookup_values'));
4000 + add_shortcode('e2pdf-frm-data-values', array($this, 'shortcode_e2pdf_frm_data_values'));
2735 4001 add_shortcode('e2pdf-frm-repeatable', array($this, 'shortcode_e2pdf_frm_repeatable'));
2736 4002 }
2737 4003
2738 4004 /**
2739 - * [e2pdf-frm-repeatable id='{entry_id}' field_id='{field_id}'] shortcode
2740 - *
4005 + * [e2pdf-frm-repeatable id="entry_id' field_id="field_id"] shortcode
2741 4006 * @param array $atts - Atributes for shortcode
2742 - *
2743 - * @return string - Output of shortcodes
4007 + * @return string - Output of shortcode
2744 4008 */
2745 4009 public function shortcode_e2pdf_frm_repeatable($atts = array()) {
2746 4010 $id = (int) $atts['id'];
2747 4011 $field_id = $atts['field_id'];
2748 4012
2749 - $response = "[frm-field-value field_id='{$field_id}' entry='{$id}']";
4013 + $response = '[frm-field-value field_id="' . $field_id . '" entry="' . $id . '"]';
2750 4014 return $response;
2751 4015 }
2752 4016
2753 4017 /**
2754 4018 * [e2pdf-frm-entry-values id='{form_id}' field_id='{field_id}' separator=''] shortcode
2755 - *
2756 4019 * @param array $atts - Atributes for shortcode
2757 - *
2758 4020 * @return string - Output of shortcodes
2759 4021 */
2760 4022 public function shortcode_e2pdf_frm_entry_values($atts = array()) {
2761 4023 $form_id = (int) $atts['id'];
@@ -2764,10 +4026,11 @@
2764 4026
2765 4027 $response = '';
2766 4028 $values = array();
2767 4029 if ($form_id && $field_id && class_exists('FrmEntry') && class_exists('FrmEntryMeta')) {
4030 +
2768 4031 $where = array(
2769 - 'it.form_id' => $form_id
4032 + 'it.form_id' => $form_id,
2770 4033 );
2771 4034 $entries_tmp = FrmEntry::getAll($where, ' ORDER BY id ASC');
2772 4035 foreach ($entries_tmp as $key => $entry) {
2773 4036 $values[] = FrmEntryMeta::get_meta_value($entry, $field_id);
@@ -2777,13 +4040,125 @@
2777 4040 return $response;
2778 4041 }
2779 4042
2780 4043 /**
4044 + * [e2pdf-frm-lookup-values id='{field_id}'] shortcode
4045 + * @param array $atts - Atributes for shortcode
4046 + * @return string - Output of shortcode
4047 + */
4048 + public function shortcode_e2pdf_frm_lookup_values($atts = array()) {
4049 +
4050 + $id = isset($atts['id']) ? $atts['id'] : false;
4051 + $user_id = isset($atts['user_id']) ? $atts['user_id'] : '0';
4052 + $separator = isset($atts['separator']) ? $atts['separator'] : "\r\n";
4053 +
4054 + $response = '';
4055 + $values = array();
4056 +
4057 + if ($id && class_exists('FrmField') && class_exists('FrmAppHelper') && class_exists('FrmFieldsHelper')) {
4058 + $field = FrmField::getOne($id);
4059 + if ($field && $field->type === 'lookup') {
4060 +
4061 + $frm_filter = false;
4062 + if (class_exists('FrmProFieldsHelper') && method_exists('FrmProFieldsHelper', 'add_default_field_settings')) {
4063 + if (!has_filter('frm_default_field_options', 'FrmProFieldsHelper::add_default_field_settings')) {
4064 + add_filter('frm_default_field_options', 'FrmProFieldsHelper::add_default_field_settings', 10, 2);
4065 + $frm_filter = true;
4066 + }
4067 + }
4068 +
4069 + $args = array();
4070 + if (is_admin()) {
4071 + $original_user_id = get_current_user_id();
4072 + wp_set_current_user($user_id);
4073 + if (!current_user_can('administrator')) {
4074 + add_filter('frm_lookup_is_current_user_filter_needed', array($this, 'filter_frm_lookup_is_current_user_filter_needed'), 10, 3);
4075 + }
4076 + }
4077 +
4078 + $field_array = FrmAppHelper::start_field_array($field);
4079 + FrmFieldsHelper::prepare_new_front_field($field_array, $field, $args);
4080 + $field_array = array_merge($field->field_options, $field_array);
4081 + if (isset($field_array['options']) && is_array($field_array['options'])) {
4082 + $values = $field_array['options'];
4083 + }
4084 +
4085 + if (is_admin()) {
4086 + if (!current_user_can('administrator')) {
4087 + remove_filter('frm_lookup_is_current_user_filter_needed', array($this, 'filter_frm_lookup_is_current_user_filter_needed'));
4088 + }
4089 + wp_set_current_user($original_user_id);
4090 + }
4091 + if ($frm_filter) {
4092 + remove_filter('frm_default_field_options', 'FrmProFieldsHelper::add_default_field_settings');
4093 + }
4094 + }
4095 + }
4096 +
4097 + $response = implode($separator, $values);
4098 + return $response;
4099 + }
4100 +
4101 + /**
4102 + * [e2pdf-frm-data-values id='{field_id}'] shortcode
4103 + * @param array $atts - Atributes for shortcode
4104 + * @return string - Output of shortcode
4105 + */
4106 + public function shortcode_e2pdf_frm_data_values($atts = array()) {
4107 +
4108 + $id = isset($atts['id']) ? $atts['id'] : false;
4109 + $user_id = isset($atts['user_id']) ? $atts['user_id'] : '0';
4110 + $separator = isset($atts['separator']) ? $atts['separator'] : "\r\n";
4111 +
4112 + $response = '';
4113 + $values = array();
4114 +
4115 + if ($id && class_exists('FrmField') && class_exists('FrmAppHelper') && class_exists('FrmFieldsHelper')) {
4116 + $field = FrmField::getOne($id);
4117 + if ($field && $field->type === 'data') {
4118 + $frm_filter = false;
4119 + if (class_exists('FrmProFieldsHelper') && method_exists('FrmProFieldsHelper', 'add_default_field_settings')) {
4120 + if (!has_filter('frm_default_field_options', 'FrmProFieldsHelper::add_default_field_settings')) {
4121 + add_filter('frm_default_field_options', 'FrmProFieldsHelper::add_default_field_settings', 10, 2);
4122 + $frm_filter = true;
4123 + }
4124 + }
4125 +
4126 + $args = array();
4127 + if (is_admin()) {
4128 + $original_user_id = get_current_user_id();
4129 + wp_set_current_user($user_id);
4130 + if (current_user_can('administrator')) {
4131 + $field->field_options['restrict'] = '0';
4132 + }
4133 + }
4134 +
4135 + $field_array = FrmAppHelper::start_field_array($field);
4136 + FrmFieldsHelper::prepare_new_front_field($field_array, $field, $args);
4137 +
4138 + $field_array = array_merge($field->field_options, $field_array);
4139 + if (isset($field_array['options']) && is_array($field_array['options'])) {
4140 + $values = $field_array['options'];
4141 + }
4142 +
4143 + if (is_admin()) {
4144 + wp_set_current_user($original_user_id);
4145 + }
4146 + if ($frm_filter) {
4147 + remove_filter('frm_default_field_options', 'FrmProFieldsHelper::add_default_field_settings');
4148 + }
4149 + }
4150 + }
4151 +
4152 + $response = implode($separator, $values);
4153 + return $response;
4154 + }
4155 +
4156 + /**
2781 4157 * Get styles for generating Map Field function
2782 - *
2783 4158 * @return array - List of css files to load
2784 4159 */
2785 - public function styles() {
4160 + public function styles($item_id = false) {
2786 4161
2787 4162 $styles = array();
2788 4163 if (class_exists('FrmStylesHelper')) {
2789 4164 $uploads = FrmStylesHelper::get_upload_base();
@@ -2792,12 +4167,136 @@
2792 4167 $url = $uploads['baseurl'] . $saved_css_path;
2793 4168 } else {
2794 4169 $url = admin_url('admin-ajax.php?action=frmpro_css');
2795 4170 }
4171 + $styles[] = $url;
4172 + $styles[] = plugins_url('css/extension/formidable.css?v=' . time(), $this->helper->get('plugin_file_path'));
4173 + }
4174 + return $styles;
4175 + }
2796 4176
2797 - $styles[] = $url;
4177 + public function merged_items() {
4178 + return true;
4179 + }
4180 +
4181 + public function hook_formidable_entry_view($entry) {
4182 + if (!empty($entry->form_id)) {
4183 + $hooks = $this->helper->load('hooks')->get('formidable', 'hook_formidable_entry_view', $entry->form_id);
4184 + if (!empty($hooks)) {
4185 + echo '<h3>' . apply_filters('e2pdf_hook_section_title', __('E2Pdf Actions', 'e2pdf'), 'hook_formidable_entry_view') . '</h3>';
4186 + echo '<div class="inside">';
4187 + foreach ($hooks as $hook) {
4188 + if ($this->helper->load('hooks')->process_hook(
4189 + $hook,
4190 + [
4191 + 'dataset' => $entry->id,
4192 + ],
4193 + 'hook_formidable_entry_view'
4194 + )
4195 + ) {
4196 + $action = apply_filters(
4197 + 'e2pdf_hook_action_button',
4198 + array(
4199 + 'html' => '<div class="misc-pub-section"><a class="e2pdf-download-hook" target="_blank" title="%2$s" href="%1$s"><span class="dashicons dashicons-pdf"></span> %2$s</a></div>',
4200 + 'url' => $this->helper->get_url(
4201 + array(
4202 + 'page' => 'e2pdf',
4203 + 'action' => 'export',
4204 + 'id' => $hook,
4205 + 'dataset' => $entry->id,
4206 + ), 'admin.php?'
4207 + ),
4208 + 'title' => 'PDF #' . $hook,
4209 + ), 'hook_formidable_entry_view', $hook, $entry->id
4210 + );
4211 + if (!empty($action)) {
4212 + echo sprintf(
4213 + $action['html'], $action['url'], $action['title']
4214 + );
4215 + }
4216 + }
4217 + }
4218 + echo '</div>';
4219 + }
2798 4220 }
4221 + }
2799 4222
2800 - return $styles;
4223 + public function hook_formidable_entry_edit($entry) {
4224 + if (!empty($entry->form_id)) {
4225 + $hooks = $this->helper->load('hooks')->get('formidable', 'hook_formidable_entry_edit', $entry->form_id);
4226 + if (!empty($hooks)) {
4227 + echo '<h3>' . apply_filters('e2pdf_hook_section_title', __('E2Pdf Actions', 'e2pdf'), 'hook_formidable_entry_view') . '</h3>';
4228 + echo '<div class="inside">';
4229 + foreach ($hooks as $hook) {
4230 + if ($this->helper->load('hooks')->process_hook(
4231 + $hook,
4232 + [
4233 + 'dataset' => $entry->id,
4234 + ],
4235 + 'hook_formidable_entry_edit'
4236 + )
4237 + ) {
4238 + $action = apply_filters(
4239 + 'e2pdf_hook_action_button',
4240 + array(
4241 + 'html' => '<div class="misc-pub-section"><a class="e2pdf-download-hook" target="_blank" title="%2$s" href="%1$s"><span class="dashicons dashicons-pdf"></span> %2$s</a></div>',
4242 + 'url' => $this->helper->get_url(
4243 + array(
4244 + 'page' => 'e2pdf',
4245 + 'action' => 'export',
4246 + 'id' => $hook,
4247 + 'dataset' => $entry->id,
4248 + ), 'admin.php?'
4249 + ),
4250 + 'title' => 'PDF #' . $hook,
4251 + ), 'hook_formidable_entry_edit', $hook, $entry->id
4252 + );
4253 + if (!empty($action)) {
4254 + echo sprintf(
4255 + $action['html'], $action['url'], $action['title']
4256 + );
4257 + }
4258 + }
4259 + }
4260 + echo '</div>';
4261 + }
4262 + }
2801 4263 }
2802 4264
4265 + public function hook_formidable_row_actions($actions, $entry) {
4266 + if (!empty($entry->form_id) && !empty($entry->id)) {
4267 + $hooks = $this->helper->load('hooks')->get('formidable', 'hook_formidable_row_actions', $entry->form_id);
4268 + foreach ($hooks as $hook) {
4269 + if ($this->helper->load('hooks')->process_hook(
4270 + $hook,
4271 + [
4272 + 'dataset' => $entry->id,
4273 + ],
4274 + 'hook_formidable_row_actions'
4275 + )
4276 + ) {
4277 + $action = apply_filters(
4278 + 'e2pdf_hook_action_button',
4279 + array(
4280 + 'html' => '<a class="e2pdf-download-hook" target="_blank" href="%s">%s</a>',
4281 + 'url' => $this->helper->get_url(
4282 + array(
4283 + 'page' => 'e2pdf',
4284 + 'action' => 'export',
4285 + 'id' => $hook,
4286 + 'dataset' => $entry->id,
4287 + ), 'admin.php?'
4288 + ),
4289 + 'title' => 'PDF #' . $hook,
4290 + ), 'hook_formidable_row_actions', $hook, $entry->id
4291 + );
4292 + if (!empty($action)) {
4293 + $actions['e2pdf_' . $hook] = sprintf(
4294 + $action['html'], $action['url'], $action['title']
4295 + );
4296 + }
4297 + }
4298 + }
4299 + }
4300 + return $actions;
4301 + }
2803 4302 }