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