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