PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.53
E2Pdf – Export Pdf Tool for WordPress v1.32.53
1.32.53 1.32.51 1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 1.06.02 1.07.11 All 74 releases
← All changes | classes/extension/e2pdf-gravity.php +1783 -1006 1.07.11 → 1.32.53 View file →
@@ -1,14 +1,12 @@
1 1 <?php
2 2
3 3 /**
4 - * E2pdf Gravity Forms Extension
5 - *
6 - * @copyright Copyright 2017 https://e2pdf.com
7 - * @license GPL v2
8 - * @version 1
9 - * @link https://e2pdf.com
10 - * @since 1.07.04
4 + * File: /extension/e2pdf-gravity.php
5 + *
6 + * @package E2Pdf
7 + * @license GPLv3
8 + * @link https://e2pdf.com
11 9 */
12 10 if (!defined('ABSPATH')) {
13 11 die('Access denied.');
14 12 }
@@ -17,466 +15,292 @@
17 15
18 16 private $options;
19 17 private $info = array(
20 18 'key' => 'gravity',
21 - 'title' => 'Gravity Forms'
19 + 'title' => 'Gravity Forms',
22 20 );
23 21
24 - function __construct() {
25 - parent::__construct();
26 - }
27 -
28 - /**
29 - * Get info about extension
30 - *
31 - * @param string $key - Key to get assigned extension info value
32 - *
33 - * @return array|string - Extension Key and Title or Assigned extension info value
34 - */
22 + // info
35 23 public function info($key = false) {
36 24 if ($key && isset($this->info[$key])) {
37 25 return $this->info[$key];
38 26 } else {
39 27 return array(
40 - $this->info['key'] => $this->info['title']
28 + $this->info['key'] => $this->info['title'],
41 29 );
42 30 }
43 31 }
44 32
45 - /**
46 - * Check if needed plugin active
47 - *
48 - * @return bool - Activated/Not Activated plugin
49 - */
33 + // active
50 34 public function active() {
51 35
52 - if (!function_exists('is_plugin_active')) {
53 - include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
54 - }
55 -
56 - if (is_plugin_active('gravityforms/gravityforms.php')) {
36 + if (defined('E2PDF_GRAVITY_EXTENSION') || $this->helper->load('extension')->is_plugin_active('gravityforms/gravityforms.php')) {
57 37 return true;
58 38 }
59 39 return false;
60 40 }
61 41
62 - /**
63 - * Set option
64 - *
65 - * @param string $key - Key of option
66 - * @param string $value - Value of option
67 - *
68 - * @return bool - Status of setting option
69 - */
42 + // set
70 43 public function set($key, $value) {
71 -
72 44 if (!isset($this->options)) {
73 45 $this->options = new stdClass();
74 46 }
75 -
76 47 $this->options->$key = $value;
48 + switch ($key) {
49 + case 'item':
50 + $this->set('cached_form', false);
51 + if ($this->get('item') && class_exists('GFFormsModel')) {
52 + $this->set('cached_form', GFFormsModel::get_form_meta($this->get('item')));
53 + }
54 + break;
55 + case 'dataset':
56 + $this->set('cached_entry', array());
57 + if ($this->get('dataset') && class_exists('GFFormsModel')) {
58 + $entry = GFFormsModel::get_entry($this->get('dataset'));
59 + if ($entry && !is_wp_error($entry) && isset($entry['form_id'])) {
60 + $this->set('cached_entry', $entry);
61 + }
62 + }
63 + break;
64 + default:
65 + break;
66 + }
77 67 return true;
78 68 }
79 69
80 - /**
81 - * Get option by key
82 - *
83 - * @param string $key - Key to get assigned option value
84 - *
85 - * @return mixed
86 - */
70 + // get
87 71 public function get($key) {
88 72 if (isset($this->options->$key)) {
89 73 $value = $this->options->$key;
90 - return $value;
91 - } elseif ($key == 'args') {
92 - return array();
93 74 } else {
94 - return false;
75 + switch ($key) {
76 + case 'args':
77 + $value = array();
78 + break;
79 + default:
80 + $value = false;
81 + break;
82 + }
95 83 }
84 + return $value;
96 85 }
97 86
98 - /**
99 - * Get items to work with
100 - *
101 - * @return array() - List of available items
102 - */
87 + // items
103 88 public function items() {
104 -
105 - $content = array();
106 -
89 + $items = array();
107 90 if (class_exists('GFFormsModel')) {
108 91 $forms = GFFormsModel::get_forms(null, 'title');
109 92 if ($forms) {
110 - foreach ($forms as $key => $value) {
111 - $content[] = $this->item($value->id);
93 + foreach ($forms as $key => $form) {
94 + $items[] = $this->item($form->id);
112 95 }
113 96 }
114 97 }
115 -
116 - return $content;
98 + return $items;
117 99 }
118 100
119 - /**
120 - * Get entries for export
121 - *
122 - * @param int $item - Form ID
123 - * @param string $name - Entries names
124 - *
125 - * @return array() - Entries list
126 - */
127 - public function datasets($item = false, $name = false) {
128 -
129 - $item = (int) $item;
101 + // datasets
102 + public function datasets($item_id = false, $name = false) {
103 + $item_id = (int) $item_id;
130 104 $datasets = array();
131 -
132 - if (class_exists('GFAPI') && $item) {
133 - $datasets_tmp = GFAPI::get_entries($item);
134 - if ($datasets_tmp) {
135 - foreach ($datasets_tmp as $key => $dataset) {
136 - $this->set('item', $item);
137 - $this->set('dataset', $dataset['id']);
138 -
139 - $dataset_title = $this->render($name);
140 - if (!$dataset_title) {
141 - $dataset_title = $dataset['id'];
105 + if (class_exists('GFAPI') && $item_id) {
106 + $paging = array(
107 + 'offset' => 0,
108 + 'page_size' => 9999999,
109 + );
110 + $entries = GFAPI::get_entries($item_id, array(), array(), $paging);
111 + if ($entries) {
112 + $this->set('item', $item_id);
113 + foreach ($entries as $key => $entry) {
114 + $this->set('dataset', $entry['id']);
115 + $entry_title = $this->render($name);
116 + if (!$entry_title) {
117 + $entry_title = $entry['id'];
142 118 }
143 119 $datasets[] = array(
144 - 'key' => $dataset['id'],
145 - 'value' => $dataset_title
120 + 'key' => $entry['id'],
121 + 'value' => $entry_title,
146 122 );
147 123 }
148 124 }
149 125 }
150 -
151 126 return $datasets;
152 127 }
153 128
154 - /**
155 - * Get dataset
156 - *
157 - * @param int $dataset - Dataset ID
158 - *
159 - * @return object - Dataset
160 - */
161 - public function dataset($dataset = false) {
162 -
163 - $dataset = (int) $dataset;
164 -
165 - if (!$dataset) {
129 + // dataset actions
130 + public function get_dataset_actions($dataset_id = false) {
131 + $dataset_id = (int) $dataset_id;
132 + if (!$dataset_id) {
166 133 return false;
167 134 }
135 + $entry = GFFormsModel::get_entry($dataset_id);
136 + $item = $entry && !is_wp_error($entry) && is_array($entry) && isset($entry['form_id']) ? $entry['form_id'] : '0';
137 + $actions = new stdClass();
138 + $actions->view = $this->helper->get_url(
139 + array(
140 + 'page' => 'gf_entries',
141 + 'view' => 'entry',
142 + 'id' => $item,
143 + 'lid' => $dataset_id,
144 + )
145 + );
146 + $actions->delete = false;
147 + return $actions;
148 + }
168 149
169 - $entry = GFFormsModel::get_entry($dataset);
170 - $item = $entry && isset($entry['form_id']) ? $entry['form_id'] : '0';
171 -
172 - $data = new stdClass();
173 - $data->url = $this->helper->get_url(array('page' => 'gf_entries', 'view' => 'entry', 'id' => $item, 'lid' => $dataset));
174 -
175 - return $data;
150 + // template actions
151 + public function get_template_actions($template = false) {
152 + $template = (int) $template;
153 + if (!$template) {
154 + return;
155 + }
156 + $actions = new stdClass();
157 + $actions->delete = false;
158 + return $actions;
176 159 }
177 160
178 - /**
179 - * Get item
180 - *
181 - * @param int $item - Item ID
182 - *
183 - * @return object - Item
184 - */
185 - public function item($item = false) {
186 -
187 - $item = (int) $item;
188 - if (!$item && $this->get('item')) {
189 - $item = $this->get('item');
161 + // item
162 + public function item($item_id = false) {
163 + $item_id = (int) $item_id;
164 + if (!$item_id && $this->get('item')) {
165 + $item_id = $this->get('item');
190 166 }
191 -
192 - $gravity_form = false;
167 + $form = false;
193 168 if (class_exists('GFFormsModel')) {
194 - $gravity_form = GFFormsModel::get_form_meta($item);
169 + $form = GFFormsModel::get_form_meta($item_id);
195 170 }
196 -
197 - $form = new stdClass();
198 - if ($gravity_form) {
199 - $form->id = (string) $item;
200 - $form->url = $this->helper->get_url(array('page' => 'gf_edit_forms', 'id' => $item));
201 - $form->name = $gravity_form['title'];
171 + $item = new stdClass();
172 + if ($form) {
173 + $item->id = (string) $item_id;
174 + $item->url = $this->helper->get_url(
175 + array(
176 + 'page' => 'gf_edit_forms',
177 + 'id' => $item_id,
178 + )
179 + );
180 + $item->name = $form['title'];
202 181 } else {
203 - $form->id = '';
204 - $form->url = 'javascript:void(0);';
205 - $form->name = '';
182 + $item->id = '';
183 + $item->url = '';
184 + $item->name = '';
206 185 }
207 - return $form;
186 + return $item;
208 187 }
209 188
210 - /**
211 - * Render value according to content
212 - *
213 - * @param string $value - Content
214 - * @param string $type - Type of rendering value
215 - * @param array $field - Field details
216 - *
217 - * @return string - Fully rendered value
218 - */
219 - public function render($value, $type = false, $field = array()) {
220 -
221 - $value = $this->render_shortcodes($value, $type, $field);
222 - $value = $this->strip_shortcodes($value);
223 -
224 - if ($type === 'value' && isset($field['type']) && $field['type'] === 'e2pdf-checkbox' && isset($field['properties']['option'])) {
225 - $option = $this->render($field['properties']['option']);
226 - $options = explode(', ', $value);
227 - $option_options = explode(', ', $option);
228 - if (is_array($options) && is_array($option_options) && !array_diff($option_options, $options)) {
229 - return $option;
230 - } else {
231 - return "";
232 - }
189 + // render
190 + public function render($value, $field = array(), $convert_shortcodes = true, $raw = false) {
191 + $value = $this->render_shortcodes($value, $field);
192 + if (!$raw) {
193 + $value = $this->strip_shortcodes($value);
194 + $value = $this->convert_shortcodes($value, $convert_shortcodes, isset($field['type']) && $field['type'] == 'e2pdf-html' ? true : false);
195 + $value = $this->helper->load('field')->render_checkbox($value, $this, $field);
233 196 }
234 -
235 - if ($type === 'value') {
236 - $value = $this->convert_shortcodes($value, true);
237 - }
238 -
239 197 return $value;
240 198 }
241 199
242 - /**
243 - * Load actions for this extension
244 - */
200 + // load actions
245 201 public function load_actions() {
246 - add_action('gform_after_email', array($this, 'action_gform_after_email'), 30, 1);
202 + add_action('gform_after_email', array($this, 'action_gform_after_email'), 30);
203 + add_action('gform_after_update_entry', array($this, 'action_gform_after_update_entry'), 0, 2);
204 +
205 + // hooks
206 + add_action('gform_entries_first_column_actions', array($this, 'hook_gravity_row_actions'), 10, 4);
247 207 }
248 208
249 - /**
250 - * Load filters for this extension
251 - */
209 + // load filters
252 210 public function load_filters() {
253 211 add_filter('gform_confirmation', array($this, 'filter_gform_confirmation'), 30, 4);
254 212 add_filter('gform_notification', array($this, 'filter_gform_notification'), 30, 3);
213 + add_filter('gform_twilio_message', array($this, 'filter_gform_twilio_message'), 30, 4);
214 + add_filter('gform_entry_post_save', array($this, 'filter_gform_entry_post_save'), 0, 2);
215 + add_filter('gform_entry_field_value', array($this, 'filter_gform_entry_field_value'), 10, 4);
216 + add_filter('gform_merge_tag_filter', array($this, 'filter_gform_merge_tag_filter'), 10, 5);
217 + add_filter('gform_entries_field_value', array($this, 'filter_gform_entries_field_value'), 10, 4);
218 +
219 + /* Hooks */
220 + add_filter('gform_entry_detail_meta_boxes', array($this, 'hook_gravity_entry_view'), 10, 3);
255 221 }
256 222
257 - /**
258 - * Render shortcodes which available in this extension
259 - *
260 - * @param string $value - Content
261 - * @param string $type - Type of rendering value
262 - * @param array $field - Field details
263 - *
264 - * @return string - Value with rendered shortcodes
265 - */
266 - public function render_shortcodes($value, $type = false, $field = array()) {
267 -
268 - $dataset = $this->get('dataset');
269 - $item = $this->get('item');
270 - $user_id = $this->get('user_id');
271 - $args = $this->get('args');
272 - $template_id = $this->get('template_id') ? $this->get('template_id') : '0';
273 - $element_id = isset($field['element_id']) ? $field['element_id'] : '0';
274 -
275 - $form = false;
276 - $entry = false;
277 -
223 + // render shortcodes
224 + public function render_shortcodes($value, $field = array()) {
225 + $element_id = isset($field['element_id']) ? $field['element_id'] : false;
278 226 if ($this->verify()) {
279 -
280 - $args = apply_filters('e2pdf_extension_render_shortcodes_args', $args, $element_id, $template_id, $item, $dataset);
281 -
282 - $form = GFFormsModel::get_form_meta($item);
283 - $entry = GFFormsModel::get_entry($dataset);
284 -
285 227 if (false !== strpos($value, '[')) {
286 -
287 - $shortcode_tags = array(
288 - 'e2pdf-user',
289 - 'e2pdf-arg'
290 - );
291 - preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches);
292 - $tagnames = array_intersect($shortcode_tags, $matches[1]);
293 -
294 - if (!empty($tagnames)) {
295 -
296 - $pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames);
297 -
298 - preg_match_all("/$pattern/", $value, $shortcodes);
299 -
300 - foreach ($shortcodes[0] as $key => $shortcode_value) {
301 - $shortcode = array();
302 - $shortcode[1] = $shortcodes[1][$key];
303 - $shortcode[2] = $shortcodes[2][$key];
304 - $shortcode[3] = $shortcodes[3][$key];
305 - $shortcode[4] = $shortcodes[4][$key];
306 - $shortcode[5] = $shortcodes[5][$key];
307 - $shortcode[6] = $shortcodes[6][$key];
308 -
309 - $atts = shortcode_parse_atts($shortcode[3]);
310 -
311 - if ($shortcode['2'] == 'e2pdf-user') {
312 - if (!isset($atts['id']) && $user_id) {
313 - $shortcode[3] .= " id=\"" . $user_id . "\"";
314 - $value = str_replace($shortcode_value, "[" . $shortcode['2'] . $shortcode['3'] . "]", $value);
315 - }
316 - } elseif ($shortcode['2'] == 'e2pdf-arg') {
317 - if (isset($atts['key']) && isset($args[$atts['key']])) {
318 - $sub_value = $this->strip_shortcodes($args[$atts['key']]);
319 - $value = str_replace($shortcode_value, $sub_value, $value);
320 - } else {
321 - $value = str_replace($shortcode_value, '', $value);
322 - }
323 - }
324 - }
325 - }
326 -
327 - $shortcode_tags = array(
328 - 'e2pdf-format-number',
329 - 'e2pdf-format-date',
330 - 'e2pdf-format-output',
331 - );
332 - $shortcode_tags = apply_filters('e2pdf_extension_render_shortcodes_tags', $shortcode_tags);
333 - preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches);
334 - $tagnames = array_intersect($shortcode_tags, $matches[1]);
335 -
336 - if (!empty($tagnames)) {
337 -
338 - $pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames);
339 -
340 - preg_match_all("/$pattern/", $value, $shortcodes);
341 - foreach ($shortcodes[0] as $key => $shortcode_value) {
342 - $shortcode = array();
343 - $shortcode[1] = $shortcodes[1][$key];
344 - $shortcode[2] = $shortcodes[2][$key];
345 - $shortcode[3] = $shortcodes[3][$key];
346 - $shortcode[4] = $shortcodes[4][$key];
347 - $shortcode[5] = $shortcodes[5][$key];
348 - $shortcode[6] = $shortcodes[6][$key];
349 -
350 - if (!$shortcode['5']) {
351 - $sub_value = '';
352 - } elseif (isset($field['type']) && ($field['type'] === 'e2pdf-image' || $field['type'] === 'e2pdf-signature')) {
353 - $sub_value = $this->render($shortcode['5'], $type);
354 - } else {
355 - $sub_value = $this->render($shortcode['5'], $type, $field);
356 - }
357 - $value = str_replace($shortcode_value, "[" . $shortcode['2'] . $shortcode['3'] . "]" . $sub_value . "[/" . $shortcode['2'] . "]", $value);
358 - }
359 - }
228 + $value = $this->helper->load('field')->pre_shortcodes($value, $this, $field);
229 + $value = $this->helper->load('field')->inner_shortcodes($value, $this, $field);
230 + $value = $this->helper->load('field')->wrapper_shortcodes($value, $this, $field);
360 231 }
361 -
362 - $value = do_shortcode($value);
363 -
364 - if (class_exists('GFCommon')) {
365 - add_filter('gform_merge_tag_filter', array($this, 'filter_gform_merge_tag_filter'), 30, 5);
366 - $value = GFCommon::replace_variables($value, $form, $entry, false, false, false, 'text');
367 - remove_filter('gform_merge_tag_filter', array($this, 'filter_gform_merge_tag_filter'), 30, 5);
232 + $gv_request = false;
233 + if (false !== strpos($value, '[gravityview') && function_exists('gravityview') && gravityview()->request->is_admin()) {
234 + $gv_request = gravityview()->request;
235 + gravityview()->request = new GV\Frontend_Request();
368 236 }
369 -
370 - if (isset($field['type']) && ($field['type'] === 'e2pdf-image' || $field['type'] === 'e2pdf-signature')) {
371 - $esig = isset($field['properties']['esig']) && $field['properties']['esig'] ? true : false;
372 - if ($esig) {
373 - //process e-signature
374 - $value = "";
375 - } else {
376 -
377 - if (!$this->helper->load('image')->get_image($value)) {
378 - $value = $this->strip_shortcodes($value);
379 - if (
380 - $value &&
381 - trim($value) != "" &&
382 - extension_loaded('gd') &&
383 - function_exists('imagettftext')
384 - ) {
385 - if (isset($field['properties']['text_color']) && $field['properties']['text_color']) {
386 - $penColour = $this->helper->load('convert')->to_hex_color($field['properties']['text_color']);
387 - } else {
388 - $penColour = array(0x14, 0x53, 0x94);
389 - }
390 -
391 - $default_options = array(
392 - 'imageSize' => array(isset($field['width']) ? $field['width'] : '400', isset($field['height']) ? $field['height'] : '150'),
393 - 'bgColour' => 'transparent',
394 - 'penColour' => $penColour
395 - );
396 -
397 - $options = array();
398 - $options = apply_filters('e2pdf_image_sig_output_options', $options, $element_id, $template_id);
399 - $options = array_merge($default_options, $options);
400 -
401 - $model_e2pdf_font = new Model_E2pdf_Font();
402 -
403 - $font = false;
404 - if (isset($field['properties']['text_font']) && $field['properties']['text_font']) {
405 - $font = $model_e2pdf_font->get_font_path($field['properties']['text_font']);
406 - }
407 -
408 - if (!$font) {
409 - $font = $model_e2pdf_font->get_font_path('Noto Sans');
410 - }
411 -
412 - $size = 150;
413 - if (isset($field['properties']['text_font_size']) && $field['properties']['text_font_size']) {
414 - $size = $field['properties']['text_font_size'];
415 - }
416 -
417 - $model_e2pdf_signature = new Model_E2pdf_Signature();
418 - $value = $model_e2pdf_signature->ttf_signature($value, $size, $font, $options);
419 - } else {
420 - $value = "";
421 - }
422 - }
423 - }
424 - } else {
425 - $value = $this->convert_shortcodes($value);
237 + $value = $this->helper->load('field')->do_shortcodes($value, $this, $field);
238 + if ($gv_request !== false) {
239 + gravityview()->request = $gv_request;
426 240 }
241 + if (class_exists('GFCommon') && $this->get('cached_form') && $this->get('cached_entry')) {
242 + add_filter('gp_template_paths', array($this, 'filter_gp_template_paths'), 30, 2);
243 + add_filter('gform_merge_tag_filter', array($this, 'filter_gform_merge_tag_filter_tags'), 30, 5);
244 + add_filter('gform_display_product_summary', '__return_false', 30);
245 + $value = GFCommon::replace_variables($value, $this->get('cached_form'), $this->get('cached_entry'), false, false, false, 'text');
246 + remove_filter('gform_display_product_summary', '__return_false', 30);
247 + remove_filter('gform_merge_tag_filter', array($this, 'filter_gform_merge_tag_filter_tags'), 30, 5);
248 + remove_filter('gp_template_paths', array($this, 'filter_gp_template_paths'), 30, 2);
249 + }
250 + $value = $this->helper->load('field')->render(
251 + apply_filters('e2pdf_extension_render_shortcodes_pre_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false),
252 + $this,
253 + $field
254 + );
427 255 }
256 + return apply_filters(
257 + 'e2pdf_extension_render_shortcodes_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false
258 + );
259 + }
428 260
429 - $value = apply_filters('e2pdf_extension_render_shortcodes_value', $value, $element_id, $template_id, $item, $dataset);
430 -
261 + // strip shortcodes
262 + public function strip_shortcodes($value) {
263 + $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', '', $value);
264 + $value = preg_replace('~a\:\d+\:{[^}]*}(*SKIP)(*FAIL)|{[^}]*}~', '', $value);
431 265 return $value;
432 266 }
433 267
434 - /**
435 - * Strip unused shortcodes
436 - *
437 - * @param string $value - Content
438 - *
439 - * @return string - Value with removed unused shortcodes
440 - */
441 - public function strip_shortcodes($value) {
442 - $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', "", $value);
443 - $value = preg_replace('~(?:{/?)[^/}]+/?}~s', "", $value);
268 + // strip math
269 + public function strip_math($value, &$replacements) {
270 + if ($value) {
271 + preg_match_all('/\{[^}]+\}/', $value, $matches);
272 + foreach ($matches[0] as $match) {
273 + $index = count($replacements) + 1;
274 + $replacements[] = $match;
275 + $value = str_replace($match, '%' . $index . '$s', $value);
276 + }
277 + }
444 278 return $value;
445 279 }
446 280
447 - /**
448 - * Convert "shortcodes" inside value string
449 - *
450 - * @param string $value - Value string
451 - * @param bool $to - Convert From/To
452 - *
453 - * @return string - Converted value
454 - */
455 - public function convert_shortcodes($value, $to = false) {
281 + // convert shortcodes
282 + public function convert_shortcodes($value, $to = false, $html = false) {
456 283 if ($value) {
457 284 if ($to) {
458 - $value = str_replace('&#91;', '[', $value);
459 - $value = str_replace('&#93;', ']', $value);
285 + $search = array('&#91;', '&#93;', '&#091;', '&#093;');
286 + $replace = array('[', ']', '[', ']');
287 + $value = str_replace($search, $replace, $value);
288 + if (!$html) {
289 + $value = wp_specialchars_decode($value, ENT_QUOTES);
290 + }
460 291 } else {
461 - $value = str_replace('[', '&#91;', $value);
462 - $value = str_replace(']', '&#93;', $value);
463 - $value = str_replace('&#091;', '&#91;', $value);
464 - $value = str_replace('&#093;', '&#93;', $value);
292 + $search = array('[', ']', '&#091;', '&#093;');
293 + $replace = array('&#91;', '&#93;', '&#91;', '&#93;');
294 + $value = str_replace($search, $replace, $value);
465 295 }
466 296 }
467 297 return $value;
468 298 }
469 299
470 - /**
471 - * Auto Generate of Template for this extension
472 - *
473 - * @return array - List of elements
474 - */
300 + // auto
475 301 public function auto() {
476 -
477 302 $item = $this->get('item');
478 -
479 303 $response = array();
480 304 $elements = array();
481 305 $merged_tags = array();
482 306 $form = false;
@@ -483,57 +307,108 @@
483 307
484 308 if (class_exists('GFFormsModel')) {
485 309 $form = GFFormsModel::get_form_meta($item);
486 310 }
487 -
488 311 if ($form) {
489 312 if (class_exists('GFCommon')) {
490 313 foreach ($form['fields'] as $field) {
491 - $tags = GFCommon::get_field_merge_tags($field);
492 - foreach ($tags as $tag) {
493 - if (isset($tag['tag'])) {
494 - if ($field->type == 'list') {
495 - $field_id = preg_replace('/\{(?:.*)\:(.*)\:\}/', '${1}', $tag['tag']);
496 - } else {
497 - $field_id = preg_replace('/\{(?:.*)\:(.*)\}/', '${1}', $tag['tag']);
498 - }
499 - if ($field_id) {
500 - $merged_tags[$field_id] = $tag['tag'];
501 - }
502 - }
503 - }
314 + $merged_tags = $this->get_field_merge_tags($merged_tags, $field);
504 315 }
505 316 }
506 -
507 317 foreach ($form['fields'] as $field) {
508 - if ($field->type == 'product' || $field->type == 'shipping') {
318 + if ($this->get('nested') && !in_array($field->id, $this->get('nested_fields'), false)) {
319 + continue;
320 + }
321 + if ($field->type == 'product' || $field->type == 'shipping' || $field->type == 'option') {
509 322 if ($field->inputType == 'select') {
510 323 $field->type = 'select';
511 324 } elseif ($field->inputType == 'radio') {
512 325 $field->type = 'radio';
326 + } elseif ($field->inputType == 'checkbox') {
327 + $field->type = 'checkbox';
513 328 } elseif ($field->inputType == 'price') {
514 329 $field->type = 'text';
515 330 }
516 331 }
332 + if ($field->type == 'survey') {
333 + if ($field->inputType == 'rating') {
334 + $field->type = 'radio';
335 + foreach ($field->choices as $key => $choice) {
336 + $field->choices[$key]['value'] = $choice['text'];
337 + }
338 + } elseif ($field->inputType == 'select') {
339 + $field->type = 'select';
340 + $field->enableChoiceValue = false;
341 + foreach ($field->choices as $key => $choice) {
342 + $field->choices[$key]['value'] = $choice['text'];
343 + }
344 + } elseif ($field->inputType == 'rank') {
345 + $field->type = 'textarea';
346 + } else {
347 + $field->type = $field->inputType;
348 + }
349 + }
350 + switch ($field->type) {
351 + case 'repeater':
352 + $value = isset($field->label) ? $field->label : '';
353 + $value .= isset($field->id) ? ':' . $field->id : '';
354 + if ($value) {
355 + if (!empty($field->fields)) {
356 + foreach ($field->fields as $sub_field) {
357 + $sub_value = isset($sub_field->label) ? $sub_field->label : '';
358 + $sub_value .= isset($field->id) ? ':' . $field->id : '';
359 + if ($sub_value) {
360 + $sub_field->id = $sub_field->id;
361 + $elements = $this->auto_fields($elements, $sub_field, $merged_tags, $item);
362 + }
363 + }
364 + }
365 + }
366 + break;
367 + default:
368 + $elements = $this->auto_fields($elements, $field, $merged_tags, $item);
369 + break;
370 + }
371 + }
372 + }
517 373
518 - switch ($field->type) {
519 - case 'text':
520 - case 'number':
521 - case 'date':
522 - case 'time':
523 - case 'phone':
524 - case 'website':
525 - case 'email':
526 - case 'fileupload':
527 - case 'post_title':
528 - case 'post_excerpt':
529 - case 'post_tags':
530 - case 'post_custom_field':
531 - case 'quantity':
532 - case 'shipping':
533 - case 'total':
534 - $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
535 - $elements[] = $this->auto_field($field, array(
374 + $response['page'] = array(
375 + 'bottom' => '20',
376 + 'top' => '20',
377 + 'left' => '20',
378 + 'right' => '20',
379 + );
380 +
381 + $response['elements'] = $elements;
382 + return $response;
383 + }
384 +
385 + // auto fields
386 + public function auto_fields($elements, $field, $merged_tags, $item) {
387 + switch ($field->type) {
388 + case 'text':
389 + case 'number':
390 + case 'date':
391 + case 'time':
392 + case 'phone':
393 + case 'website':
394 + case 'email':
395 + case 'post_title':
396 + case 'post_excerpt':
397 + case 'post_tags':
398 + case 'post_custom_field':
399 + case 'quantity':
400 + case 'shipping':
401 + case 'total':
402 + $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
403 + if ($this->get('nested')) {
404 + if (substr($value, -1) == '}') {
405 + $value = substr($value, 0, -1) . ':filter[' . $field->id . '],index[0]}';
406 + }
407 + }
408 + $elements[] = $this->auto_field(
409 + $field,
410 + array(
536 411 'type' => 'e2pdf-html',
537 412 'block' => true,
538 413 'properties' => array(
539 414 'top' => '20',
@@ -541,13 +416,16 @@
541 416 'right' => '20',
542 417 'width' => '100%',
543 418 'height' => 'auto',
544 419 'value' => $field->label,
545 - 'pass' => $field->enablePasswordInput ? '1' : '0'
546 - )
547 - ));
420 + 'pass' => $field->enablePasswordInput ? '1' : '0',
421 + ),
422 + )
423 + );
548 424
549 - $elements[] = $this->auto_field($field, array(
425 + $elements[] = $this->auto_field(
426 + $field,
427 + array(
550 428 'type' => 'e2pdf-input',
551 429 'properties' => array(
552 430 'top' => '5',
553 431 'width' => '100%',
@@ -552,13 +430,16 @@
552 430 'top' => '5',
553 431 'width' => '100%',
554 432 'height' => 'auto',
555 433 'value' => $value,
556 - )
557 - ));
558 - break;
559 - case 'list':
560 - $elements[] = $this->auto_field($field, array(
434 + ),
435 + )
436 + );
437 + break;
438 + case 'list':
439 + $elements[] = $this->auto_field(
440 + $field,
441 + array(
561 442 'type' => 'e2pdf-html',
562 443 'block' => true,
563 444 'properties' => array(
564 445 'top' => '20',
@@ -566,28 +447,34 @@
566 447 'right' => '20',
567 448 'width' => '100%',
568 449 'height' => 'auto',
569 450 'value' => $field->label,
570 - )
571 - ));
451 + ),
452 + )
453 + );
454 + if ($field->enableColumns) {
455 + $width = number_format(floor((100 / count($field->choices)) * 100) / 100, 2);
456 + foreach ($field->choices as $key => $choice) {
457 + $field_id = (int) $key + 1;
458 + $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
572 459
573 - if ($field->enableColumns) {
460 + if ($this->get('nested')) {
461 + if (substr($value, -1) == '}') {
462 + $value = substr($value, 0, -1) . ':filter[' . $field->id . ':1_' . $field_id . '],index[0]}';
463 + }
464 + } else {
465 + if (substr($value, -1) == '}') {
466 + $value = substr($value, 0, -1) . '1_' . $field_id . '}';
467 + }
468 + }
574 469
575 - $width = number_format(floor((100 / count($field->choices)) * 100) / 100, 2);
576 -
577 - foreach ($field->choices as $key => $choice) {
578 -
579 - $field_id = (int) $key + 1;
580 - $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
581 - if (substr($value, -1) == '}') {
582 - $value = substr($value, 0, -1) . '1_' . $field_id . '}';
583 - }
584 -
585 - $float = true;
586 - if ($key == '0') {
587 - $float = false;
588 - }
589 - $elements[] = $this->auto_field($field, array(
470 + $float = true;
471 + if ($key == '0') {
472 + $float = false;
473 + }
474 + $elements[] = $this->auto_field(
475 + $field,
476 + array(
590 477 'type' => 'e2pdf-html',
591 478 'block' => true,
592 479 'float' => $float,
593 480 'properties' => array(
@@ -596,12 +483,14 @@
596 483 'right' => '20',
597 484 'width' => $width . '%',
598 485 'height' => 'auto',
599 486 'value' => $choice['text'],
600 - )
601 - ));
602 -
603 - $elements[] = $this->auto_field($field, array(
487 + ),
488 + )
489 + );
490 + $elements[] = $this->auto_field(
491 + $field,
492 + array(
604 493 'type' => 'e2pdf-input',
605 494 'properties' => array(
606 495 'top' => '5',
607 496 'width' => '100%',
@@ -606,18 +495,26 @@
606 495 'top' => '5',
607 496 'width' => '100%',
608 497 'height' => 'auto',
609 498 'value' => $value,
610 - )
611 - ));
612 - }
613 - } else {
614 - $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
615 - if (substr($value, -1) == '}') {
616 - $value = substr($value, 0, -1) . '1}';
617 - }
618 -
619 - $elements[] = $this->auto_field($field, array(
499 + ),
500 + )
501 + );
502 + }
503 + } else {
504 + $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
505 + if ($this->get('nested')) {
506 + if (substr($value, -1) == '}') {
507 + $value = substr($value, 0, -1) . ':filter[' . $field->id . ':1],index[0]}';
508 + }
509 + } else {
510 + if (substr($value, -1) == '}') {
511 + $value = substr($value, 0, -1) . '1}';
512 + }
513 + }
514 + $elements[] = $this->auto_field(
515 + $field,
516 + array(
620 517 'type' => 'e2pdf-input',
621 518 'properties' => array(
622 519 'top' => '5',
623 520 'width' => '100%',
@@ -622,15 +519,25 @@
622 519 'top' => '5',
623 520 'width' => '100%',
624 521 'height' => 'auto',
625 522 'value' => $value,
626 - )
627 - ));
628 - }
629 - break;
630 - case 'textarea':
631 - case 'post_content':
632 - $elements[] = $this->auto_field($field, array(
523 + ),
524 + )
525 + );
526 + }
527 + break;
528 + case 'fileupload':
529 + case 'textarea':
530 + case 'post_content':
531 + $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
532 + if ($this->get('nested')) {
533 + if (substr($value, -1) == '}') {
534 + $value = substr($value, 0, -1) . ':filter[' . $field->id . '],index[0]}';
535 + }
536 + }
537 + $elements[] = $this->auto_field(
538 + $field,
539 + array(
633 540 'type' => 'e2pdf-html',
634 541 'block' => true,
635 542 'properties' => array(
636 543 'top' => '20',
@@ -638,26 +545,31 @@
638 545 'right' => '20',
639 546 'width' => '100%',
640 547 'height' => 'auto',
641 548 'value' => $field->label,
642 - )
643 - ));
644 -
645 - $elements[] = $this->auto_field($field, array(
549 + ),
550 + )
551 + );
552 + $elements[] = $this->auto_field(
553 + $field,
554 + array(
646 555 'type' => 'e2pdf-textarea',
647 556 'properties' => array(
648 557 'top' => '5',
649 558 'width' => '100%',
650 559 'height' => 'auto',
651 - 'value' => isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '',
652 - )
653 - ));
654 - break;
655 - case 'select':
656 - case 'multiselect':
657 - case 'post_category':
658 - case 'option':
659 - $elements[] = $this->auto_field($field, array(
560 + 'value' => $value,
561 + ),
562 + )
563 + );
564 + break;
565 + case 'select':
566 + case 'multiselect':
567 + case 'post_category':
568 + case 'option':
569 + $elements[] = $this->auto_field(
570 + $field,
571 + array(
660 572 'type' => 'e2pdf-html',
661 573 'block' => true,
662 574 'properties' => array(
663 575 'top' => '20',
@@ -665,26 +577,38 @@
665 577 'right' => '20',
666 578 'width' => '100%',
667 579 'height' => 'auto',
668 580 'value' => $field->label,
669 - )
670 - ));
671 -
672 - $options_tmp = array();
673 - if (isset($field->choices) && is_array($field->choices)) {
674 - foreach ($field->choices as $opt_key => $option) {
675 - $options_tmp[] = isset($option['value']) ? $option['value'] : '';
676 - }
581 + ),
582 + )
583 + );
584 + $options_tmp = array();
585 + if (isset($field->choices) && is_array($field->choices)) {
586 + foreach ($field->choices as $opt_key => $option) {
587 + $options_tmp[] = isset($option['value']) ? $option['value'] : '';
588 + }
589 + }
590 + $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
591 + if ($this->get('nested')) {
592 + if ($field->enableChoiceValue && $value) {
593 + if (substr($value, -1) == '}') {
594 + $value = substr($value, 0, -1) . ':value,filter[' . $field->id . '],index[0]}';
677 595 }
678 -
679 - $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
680 - if ($field->enableChoiceValue && $value) {
681 - if (substr($value, -1) == '}') {
682 - $value = substr($value, 0, -1) . ':value}';
683 - }
596 + } else {
597 + if (substr($value, -1) == '}') {
598 + $value = substr($value, 0, -1) . ':filter[' . $field->id . '],index[0]}';
684 599 }
685 -
686 - $elements[] = $this->auto_field($field, array(
600 + }
601 + } else {
602 + if ($field->enableChoiceValue && $value) {
603 + if (substr($value, -1) == '}') {
604 + $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}';
605 + }
606 + }
607 + }
608 + $elements[] = $this->auto_field(
609 + $field,
610 + array(
687 611 'type' => 'e2pdf-select',
688 612 'properties' => array(
689 613 'top' => '5',
690 614 'width' => '100%',
@@ -692,13 +616,16 @@
692 616 'options' => implode("\n", $options_tmp),
693 617 'value' => $value,
694 618 'height' => $field->type == 'multiselect' ? '80' : 'auto',
695 619 'multiline' => $field->type == 'multiselect' ? '1' : '0',
696 - )
697 - ));
698 - break;
699 - case 'checkbox':
700 - $elements[] = $this->auto_field($field, array(
620 + ),
621 + )
622 + );
623 + break;
624 + case 'checkbox':
625 + $elements[] = $this->auto_field(
626 + $field,
627 + array(
701 628 'type' => 'e2pdf-html',
702 629 'block' => true,
703 630 'properties' => array(
704 631 'top' => '20',
@@ -706,22 +633,35 @@
706 633 'right' => '20',
707 634 'width' => '100%',
708 635 'height' => 'auto',
709 636 'value' => $field->label,
710 - )
711 - ));
637 + ),
638 + )
639 + );
712 640
713 - if (isset($field->choices) && is_array($field->choices)) {
714 -
715 - $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
716 - if ($field->enableChoiceValue && $value) {
717 - if (substr($value, -1) == '}') {
718 - $value = substr($value, 0, -1) . ':value}';
719 - }
641 + if (isset($field->choices) && is_array($field->choices)) {
642 + $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
643 + if ($this->get('nested')) {
644 + if ($field->enableChoiceValue && $value) {
645 + if (substr($value, -1) == '}') {
646 + $value = substr($value, 0, -1) . ':value,filter[' . $field->id . '],index[0]}';
720 647 }
721 -
722 - foreach ($field->choices as $opt_key => $option) {
723 - $elements[] = $this->auto_field($field, array(
648 + } else {
649 + if (substr($value, -1) == '}') {
650 + $value = substr($value, 0, -1) . ':filter[' . $field->id . '],index[0]}';
651 + }
652 + }
653 + } else {
654 + if ($field->enableChoiceValue && $value) {
655 + if (substr($value, -1) == '}') {
656 + $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}';
657 + }
658 + }
659 + }
660 + foreach ($field->choices as $opt_key => $option) {
661 + $elements[] = $this->auto_field(
662 + $field,
663 + array(
724 664 'type' => 'e2pdf-checkbox',
725 665 'properties' => array(
726 666 'top' => '5',
727 667 'width' => 'auto',
@@ -726,12 +666,15 @@
726 666 'top' => '5',
727 667 'width' => 'auto',
728 668 'height' => 'auto',
729 669 'value' => $value,
730 - 'option' => isset($option['value']) ? $option['value'] : ''
731 - )
732 - ));
733 - $elements[] = $this->auto_field($field, array(
670 + 'option' => isset($option['value']) ? $option['value'] : '',
671 + ),
672 + )
673 + );
674 + $elements[] = $this->auto_field(
675 + $field,
676 + array(
734 677 'type' => 'e2pdf-html',
735 678 'float' => true,
736 679 'properties' => array(
737 680 'left' => '5',
@@ -736,16 +679,19 @@
736 679 'properties' => array(
737 680 'left' => '5',
738 681 'width' => '100%',
739 682 'height' => 'auto',
740 - 'value' => isset($option['text']) ? $option['text'] : ''
741 - )
742 - ));
743 - }
744 - }
745 - break;
746 - case 'radio':
747 - $elements[] = $this->auto_field($field, array(
683 + 'value' => isset($option['text']) ? $option['text'] : '',
684 + ),
685 + )
686 + );
687 + }
688 + }
689 + break;
690 + case 'radio':
691 + $elements[] = $this->auto_field(
692 + $field,
693 + array(
748 694 'type' => 'e2pdf-html',
749 695 'block' => true,
750 696 'properties' => array(
751 697 'top' => '20',
@@ -753,22 +699,48 @@
753 699 'right' => '20',
754 700 'width' => '100%',
755 701 'height' => 'auto',
756 702 'value' => $field->label,
757 - )
758 - ));
703 + ),
704 + )
705 + );
759 706
760 - if (isset($field->choices) && is_array($field->choices)) {
707 + if (isset($field->choices) && is_array($field->choices)) {
708 + $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
709 + if ($this->get('nested')) {
710 + if ($field->enableChoiceValue && $value) {
711 + if (substr($value, -1) == '}') {
712 + $value = substr($value, 0, -1) . ':value,filter[' . $field->id . '],index[0]}';
713 + }
714 + } else {
715 + if (substr($value, -1) == '}') {
716 + $value = substr($value, 0, -1) . ':filter[' . $field->id . '],index[0]}';
717 + }
718 + }
719 + } else {
720 + if ($field->enableChoiceValue && $value) {
721 + if (substr($value, -1) == '}') {
722 + $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}';
723 + }
724 + }
725 + }
761 726
762 - $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
727 + $choices = array();
728 + foreach ($field->choices as $opt_key => $option) {
729 + if (!$value && isset($field->inputs) && isset($field->inputs[$opt_key]['id'])) {
730 + $value = isset($merged_tags[$field->inputs[$opt_key]['id']]) ? $merged_tags[$field->inputs[$opt_key]['id']] : '';
763 731 if ($field->enableChoiceValue && $value) {
764 732 if (substr($value, -1) == '}') {
765 - $value = substr($value, 0, -1) . ':value}';
733 + $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}';
766 734 }
767 735 }
768 -
769 - foreach ($field->choices as $opt_key => $option) {
770 - $elements[] = $this->auto_field($field, array(
736 + }
737 + if (isset($option['value'])) {
738 + $choices[] = $option['value'];
739 + }
740 + $elements[] = $this->auto_field(
741 + $field,
742 + array(
771 743 'type' => 'e2pdf-radio',
772 744 'properties' => array(
773 745 'top' => '5',
774 746 'width' => 'auto',
@@ -774,12 +746,15 @@
774 746 'width' => 'auto',
775 747 'height' => 'auto',
776 748 'value' => $value,
777 749 'option' => isset($option['value']) ? $option['value'] : '',
778 - 'group' => $value
779 - )
780 - ));
781 - $elements[] = $this->auto_field($field, array(
750 + 'group' => $value,
751 + ),
752 + )
753 + );
754 + $elements[] = $this->auto_field(
755 + $field,
756 + array(
782 757 'type' => 'e2pdf-html',
783 758 'float' => true,
784 759 'properties' => array(
785 760 'left' => '5',
@@ -784,31 +759,104 @@
784 759 'properties' => array(
785 760 'left' => '5',
786 761 'width' => '100%',
787 762 'height' => 'auto',
788 - 'value' => isset($option['text']) ? $option['text'] : ''
789 - )
790 - ));
763 + 'value' => isset($option['text']) ? $option['text'] : '',
764 + ),
765 + )
766 + );
767 + }
768 +
769 + //other choice
770 + if ($field->enableOtherChoice) {
771 + $actions_radio = array();
772 + $actions_input = array();
773 + if (!empty($choices)) {
774 + $conditions = array();
775 + $conditions[1] = array(
776 + 'condition' => '!=',
777 + 'if' => $value,
778 + 'value' => '',
779 + );
780 +
781 + foreach ($choices as $choice) {
782 + $conditions[] = array(
783 + 'condition' => '!=',
784 + 'if' => $value,
785 + 'value' => $choice,
786 + );
791 787 }
792 - }
793 - break;
794 - case 'name':
795 - foreach ($field['inputs'] as $key => $input) {
796 - if ($input->isHidden) {
797 - unset($field['inputs'][$key]);
798 - }
799 - }
800 788
801 - $width = '100%';
802 - if (count($field['inputs']) == '3') {
803 - $width = '33.3%';
804 - } else {
805 - $width = 100 / count($field['inputs']) . '%';
789 + $actions_radio = array(
790 + '0' => array(
791 + 'order' => '0',
792 + 'action' => 'change',
793 + 'apply' => 'all',
794 + 'change' => 'gf_other_choice',
795 + 'property' => 'value',
796 + 'conditions' => $conditions,
797 + ),
798 + );
799 +
800 + $actions_input = array(
801 + '0' => array(
802 + 'order' => '0',
803 + 'action' => 'change',
804 + 'apply' => 'all',
805 + 'change' => $value,
806 + 'property' => 'value',
807 + 'conditions' => $conditions,
808 + ),
809 + );
806 810 }
807 -
808 - foreach ($field['inputs'] as $key => $sub_field) {
809 -
810 - $elements[] = $this->auto_field($sub_field, array(
811 + $elements[] = $this->auto_field(
812 + $field,
813 + array(
814 + 'type' => 'e2pdf-radio',
815 + 'properties' => array(
816 + 'top' => '5',
817 + 'width' => 'auto',
818 + 'height' => 'auto',
819 + 'value' => $value,
820 + 'option' => 'gf_other_choice',
821 + 'group' => $value,
822 + ),
823 + 'actions' => $actions_radio,
824 + )
825 + );
826 + $elements[] = $this->auto_field(
827 + $field,
828 + array(
829 + 'type' => 'e2pdf-input',
830 + 'float' => true,
831 + 'properties' => array(
832 + 'left' => '5',
833 + 'width' => '100%',
834 + 'height' => 'auto',
835 + 'value' => '',
836 + ),
837 + 'actions' => $actions_input,
838 + )
839 + );
840 + }
841 + }
842 + break;
843 + case 'name':
844 + foreach ($field['inputs'] as $key => $input) {
845 + if (isset($input->isHidden) && $input->isHidden) {
846 + unset($field['inputs'][$key]);
847 + }
848 + }
849 + $width = '100%';
850 + if (count($field['inputs']) == '3') {
851 + $width = '33.3%';
852 + } else {
853 + $width = 100 / count($field['inputs']) . '%';
854 + }
855 + foreach ($field['inputs'] as $key => $sub_field) {
856 + $elements[] = $this->auto_field(
857 + $sub_field,
858 + array(
811 859 'type' => 'e2pdf-html',
812 860 'block' => true,
813 861 'float' => $key == '0' ? false : true,
814 862 'properties' => array(
@@ -817,19 +865,27 @@
817 865 'right' => '20',
818 866 'width' => $width,
819 867 'height' => 'auto',
820 868 'value' => isset($sub_field['label']) && $sub_field['label'] ? $sub_field['label'] : '',
821 - )
822 - ));
869 + ),
870 + )
871 + );
823 872
824 - if (isset($sub_field['choices']) && is_array($sub_field['choices'])) {
873 + $value = isset($merged_tags[$sub_field['id']]) ? $merged_tags[$sub_field['id']] : '';
874 + if ($this->get('nested')) {
875 + if (substr($value, -1) == '}') {
876 + $value = substr($value, 0, -1) . ':filter[' . $sub_field['id'] . '],index[0]}';
877 + }
878 + }
825 879
826 - $options_tmp = array();
827 - foreach ($sub_field['choices'] as $opt_key => $option) {
828 - $options_tmp[] = isset($option['value']) ? $option['value'] : '';
829 - }
830 -
831 - $elements[] = $this->auto_field($field, array(
880 + if (isset($sub_field['choices']) && is_array($sub_field['choices'])) {
881 + $options_tmp = array();
882 + foreach ($sub_field['choices'] as $opt_key => $option) {
883 + $options_tmp[] = isset($option['value']) ? $option['value'] : '';
884 + }
885 + $elements[] = $this->auto_field(
886 + $field,
887 + array(
832 888 'type' => 'e2pdf-select',
833 889 'properties' => array(
834 890 'top' => '5',
835 891 'width' => '100%',
@@ -834,34 +890,44 @@
834 890 'top' => '5',
835 891 'width' => '100%',
836 892 'height' => 'auto',
837 893 'options' => implode("\n", $options_tmp),
838 - 'value' => isset($merged_tags[$sub_field['id']]) ? $merged_tags[$sub_field['id']] : '',
894 + 'value' => $value,
839 895 'height' => 'auto',
840 896 'multiline' => '0',
841 - )
842 - ));
843 - } else {
844 - $elements[] = $this->auto_field($sub_field, array(
897 + ),
898 + )
899 + );
900 + } else {
901 + $elements[] = $this->auto_field(
902 + $sub_field,
903 + array(
845 904 'type' => 'e2pdf-input',
846 905 'properties' => array(
847 906 'top' => '5',
848 907 'width' => '100%',
849 908 'height' => 'auto',
850 - 'value' => isset($merged_tags[$sub_field['id']]) ? $merged_tags[$sub_field['id']] : '',
851 - )
852 - ));
909 + 'value' => $value,
910 + ),
911 + )
912 + );
913 + }
914 + }
915 + break;
916 + case 'address':
917 + $index = 0;
918 + foreach ($field['inputs'] as $key => $sub_field) {
919 + if (isset($sub_field['isHidden']) && $sub_field['isHidden']) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
920 + } else {
921 + $value = isset($merged_tags[$sub_field['id']]) ? $merged_tags[$sub_field['id']] : '';
922 + if ($this->get('nested')) {
923 + if (substr($value, -1) == '}') {
924 + $value = substr($value, 0, -1) . ':filter[' . $sub_field['id'] . '],index[0]}';
853 925 }
854 926 }
855 - break;
856 - case 'address':
857 - $index = 0;
858 - foreach ($field['inputs'] as $key => $sub_field) {
859 -
860 - if (isset($sub_field['isHidden']) && $sub_field['isHidden']) {
861 -
862 - } else {
863 - $elements[] = $this->auto_field($sub_field, array(
927 + $elements[] = $this->auto_field(
928 + $sub_field,
929 + array(
864 930 'type' => 'e2pdf-html',
865 931 'block' => true,
866 932 'float' => $index == '0' ? false : true,
867 933 'properties' => array(
@@ -870,26 +936,31 @@
870 936 'right' => '20',
871 937 'width' => $key == '0' || $key == '1' ? '100%' : '50%',
872 938 'height' => 'auto',
873 939 'value' => isset($sub_field['label']) && $sub_field['label'] ? $sub_field['label'] : '',
874 - )
875 - ));
876 -
877 - $elements[] = $this->auto_field($sub_field, array(
940 + ),
941 + )
942 + );
943 + $elements[] = $this->auto_field(
944 + $sub_field,
945 + array(
878 946 'type' => 'e2pdf-input',
879 947 'properties' => array(
880 948 'top' => '5',
881 949 'width' => '100%',
882 950 'height' => 'auto',
883 - 'value' => isset($merged_tags[$sub_field['id']]) ? $merged_tags[$sub_field['id']] : '',
884 - )
885 - ));
886 - $index++;
887 - }
888 - }
889 - break;
890 - case 'consent':
891 - $elements[] = $this->auto_field($field, array(
951 + 'value' => $value,
952 + ),
953 + )
954 + );
955 + $index++;
956 + }
957 + }
958 + break;
959 + case 'consent':
960 + $elements[] = $this->auto_field(
961 + $field,
962 + array(
892 963 'type' => 'e2pdf-html',
893 964 'block' => true,
894 965 'properties' => array(
895 966 'top' => '20',
@@ -897,22 +968,33 @@
897 968 'right' => '20',
898 969 'width' => '100%',
899 970 'height' => 'auto',
900 971 'value' => $field->label,
901 - )
902 - ));
903 -
904 - $elements[] = $this->auto_field($field, array(
972 + ),
973 + )
974 + );
975 + $value = isset($merged_tags[$field->id . '.1']) ? $merged_tags[$field->id . '.1'] : '';
976 + if ($this->get('nested')) {
977 + if (substr($value, -1) == '}') {
978 + $value = substr($value, 0, -1) . ':filter[' . $field->id . '.1],index[0]}';
979 + }
980 + }
981 + $elements[] = $this->auto_field(
982 + $field,
983 + array(
905 984 'type' => 'e2pdf-checkbox',
906 985 'properties' => array(
907 986 'top' => '5',
908 987 'width' => 'auto',
909 988 'height' => 'auto',
910 - 'value' => isset($merged_tags[$field->id . '.1']) ? $merged_tags[$field->id . '.1'] : '',
911 - 'option' => '1'
912 - )
913 - ));
914 - $elements[] = $this->auto_field($field, array(
989 + 'value' => $value,
990 + 'option' => '1',
991 + ),
992 + )
993 + );
994 + $elements[] = $this->auto_field(
995 + $field,
996 + array(
915 997 'type' => 'e2pdf-html',
916 998 'float' => true,
917 999 'properties' => array(
918 1000 'left' => '5',
@@ -917,17 +999,23 @@
917 999 'properties' => array(
918 1000 'left' => '5',
919 1001 'width' => '100%',
920 1002 'height' => 'auto',
921 - 'value' => $field->checkboxLabel
922 - )
923 - ));
924 - break;
925 - case 'post_image':
926 -
927 - $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
928 -
929 - $elements[] = $this->auto_field($field, array(
1003 + 'value' => $field->checkboxLabel,
1004 + ),
1005 + )
1006 + );
1007 + break;
1008 + case 'post_image':
1009 + $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
1010 + if ($this->get('nested')) {
1011 + if (substr($value, -1) == '}') {
1012 + $value = substr($value, 0, -1) . ':filter[' . $field->id . '],index[0]}';
1013 + }
1014 + }
1015 + $elements[] = $this->auto_field(
1016 + $field,
1017 + array(
930 1018 'type' => 'e2pdf-html',
931 1019 'block' => true,
932 1020 'properties' => array(
933 1021 'top' => '20',
@@ -935,12 +1023,14 @@
935 1023 'right' => '20',
936 1024 'width' => '100%',
937 1025 'height' => 'auto',
938 1026 'value' => $field->label,
939 - )
940 - ));
941 -
942 - $elements[] = $this->auto_field($field, array(
1027 + ),
1028 + )
1029 + );
1030 + $elements[] = $this->auto_field(
1031 + $field,
1032 + array(
943 1033 'type' => 'e2pdf-image',
944 1034 'properties' => array(
945 1035 'top' => '5',
946 1036 'width' => '100',
@@ -945,15 +1035,26 @@
945 1035 'top' => '5',
946 1036 'width' => '100',
947 1037 'height' => '100',
948 1038 'value' => $value,
949 - 'dimension' => '1'
950 - )
951 - ));
952 -
953 - if ($field->displayTitle) {
954 -
955 - $elements[] = $this->auto_field($field, array(
1039 + 'dimension' => '1',
1040 + ),
1041 + )
1042 + );
1043 + if ($field->displayTitle) {
1044 + $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
1045 + if ($this->get('nested')) {
1046 + if (substr($value, -1) == '}') {
1047 + $value = substr($value, 0, -1) . ':title,filter[' . $field->id . '],index[0]}';
1048 + }
1049 + } else {
1050 + if (substr($value, -1) == '}') {
1051 + $value = substr($value, 0, -1) . ':title}';
1052 + }
1053 + }
1054 + $elements[] = $this->auto_field(
1055 + $field,
1056 + array(
956 1057 'type' => 'e2pdf-html',
957 1058 'block' => true,
958 1059 'properties' => array(
959 1060 'top' => '20',
@@ -961,25 +1062,39 @@
961 1062 'right' => '20',
962 1063 'width' => '100%',
963 1064 'height' => 'auto',
964 1065 'value' => __('Title', 'gravityforms'),
965 - )
966 - ));
967 -
968 - $elements[] = $this->auto_field($field, array(
1066 + ),
1067 + )
1068 + );
1069 + $elements[] = $this->auto_field(
1070 + $field,
1071 + array(
969 1072 'type' => 'e2pdf-input',
970 1073 'properties' => array(
971 1074 'top' => '5',
972 1075 'width' => '100%',
973 1076 'height' => 'auto',
974 - 'value' => $value && substr($value, -1) == '}' ? substr($value, 0, -1) . ':title}' : '',
975 - 'dimension' => '1'
976 - )
977 - ));
1077 + 'value' => $value,
1078 + 'dimension' => '1',
1079 + ),
1080 + )
1081 + );
1082 + }
1083 + if ($field->displayCaption) {
1084 + $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
1085 + if ($this->get('nested')) {
1086 + if (substr($value, -1) == '}') {
1087 + $value = substr($value, 0, -1) . ':caption,filter[' . $field->id . '],index[0]}';
978 1088 }
979 -
980 - if ($field->displayCaption) {
981 - $elements[] = $this->auto_field($field, array(
1089 + } else {
1090 + if (substr($value, -1) == '}') {
1091 + $value = substr($value, 0, -1) . ':caption}';
1092 + }
1093 + }
1094 + $elements[] = $this->auto_field(
1095 + $field,
1096 + array(
982 1097 'type' => 'e2pdf-html',
983 1098 'block' => true,
984 1099 'properties' => array(
985 1100 'top' => '20',
@@ -987,25 +1102,39 @@
987 1102 'right' => '20',
988 1103 'width' => '100%',
989 1104 'height' => 'auto',
990 1105 'value' => __('Caption', 'gravityforms'),
991 - )
992 - ));
993 -
994 - $elements[] = $this->auto_field($field, array(
1106 + ),
1107 + )
1108 + );
1109 + $elements[] = $this->auto_field(
1110 + $field,
1111 + array(
995 1112 'type' => 'e2pdf-input',
996 1113 'properties' => array(
997 1114 'top' => '5',
998 1115 'width' => '100%',
999 1116 'height' => 'auto',
1000 - 'value' => $value && substr($value, -1) == '}' ? substr($value, 0, -1) . ':caption}' : '',
1001 - 'dimension' => '1'
1002 - )
1003 - ));
1117 + 'value' => $value,
1118 + 'dimension' => '1',
1119 + ),
1120 + )
1121 + );
1122 + }
1123 + if ($field->displayDescription) {
1124 + $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
1125 + if ($this->get('nested')) {
1126 + if (substr($value, -1) == '}') {
1127 + $value = substr($value, 0, -1) . ':description,filter[' . $field->id . '],index[0]}';
1004 1128 }
1005 -
1006 - if ($field->displayDescription) {
1007 - $elements[] = $this->auto_field($field, array(
1129 + } else {
1130 + if (substr($value, -1) == '}') {
1131 + $value = substr($value, 0, -1) . ':description}';
1132 + }
1133 + }
1134 + $elements[] = $this->auto_field(
1135 + $field,
1136 + array(
1008 1137 'type' => 'e2pdf-html',
1009 1138 'block' => true,
1010 1139 'properties' => array(
1011 1140 'top' => '20',
@@ -1013,12 +1142,14 @@
1013 1142 'right' => '20',
1014 1143 'width' => '100%',
1015 1144 'height' => 'auto',
1016 1145 'value' => __('Description', 'gravityforms'),
1017 - )
1018 - ));
1019 -
1020 - $elements[] = $this->auto_field($field, array(
1146 + ),
1147 + )
1148 + );
1149 + $elements[] = $this->auto_field(
1150 + $field,
1151 + array(
1021 1152 'type' => 'e2pdf-input',
1022 1153 'properties' => array(
1023 1154 'top' => '5',
1024 1155 'width' => '100%',
@@ -1023,16 +1154,18 @@
1023 1154 'top' => '5',
1024 1155 'width' => '100%',
1025 1156 'height' => 'auto',
1026 1157 'value' => $value && substr($value, -1) == '}' ? substr($value, 0, -1) . ':description}' : '',
1027 - 'dimension' => '1'
1028 - )
1029 - ));
1030 - }
1031 -
1032 - break;
1033 - case 'html':
1034 - $elements[] = $this->auto_field($field, array(
1158 + 'dimension' => '1',
1159 + ),
1160 + )
1161 + );
1162 + }
1163 + break;
1164 + case 'html':
1165 + $elements[] = $this->auto_field(
1166 + $field,
1167 + array(
1035 1168 'type' => 'e2pdf-html',
1036 1169 'block' => true,
1037 1170 'properties' => array(
1038 1171 'top' => '20',
@@ -1040,16 +1173,17 @@
1040 1173 'right' => '20',
1041 1174 'width' => '100%',
1042 1175 'height' => 'auto',
1043 1176 'value' => $field->content,
1044 - )
1045 - ));
1046 - break;
1047 - case 'product':
1048 -
1049 - if ($field->inputType != 'hiddenproduct') {
1050 -
1051 - $elements[] = $this->auto_field($field, array(
1177 + ),
1178 + )
1179 + );
1180 + break;
1181 + case 'product':
1182 + if ($field->inputType != 'hiddenproduct') {
1183 + $elements[] = $this->auto_field(
1184 + $field,
1185 + array(
1052 1186 'type' => 'e2pdf-html',
1053 1187 'block' => true,
1054 1188 'properties' => array(
1055 1189 'top' => '20',
@@ -1057,25 +1191,29 @@
1057 1191 'right' => '20',
1058 1192 'width' => '100%',
1059 1193 'height' => 'auto',
1060 1194 'value' => $field->label,
1061 - )
1062 - ));
1063 -
1064 - if ($field->inputType == 'singleproduct' || $field->inputType == 'calculation') {
1065 -
1066 - if ($field->disableQuantity) {
1067 - $width = '50%';
1068 - } else {
1069 - $width = '33.3%';
1195 + ),
1196 + )
1197 + );
1198 + if ($field->inputType == 'singleproduct' || $field->inputType == 'calculation') {
1199 + if ($field->disableQuantity) {
1200 + $width = '50%';
1201 + } else {
1202 + $width = '33.3%';
1203 + }
1204 + foreach ($field['inputs'] as $key => $sub_field) {
1205 + if ($field->disableQuantity && $key == '2') { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
1206 + } else {
1207 + $value = isset($merged_tags[$sub_field['id']]) ? $merged_tags[$sub_field['id']] : '';
1208 + if ($this->get('nested')) {
1209 + if (substr($value, -1) == '}') {
1210 + $value = substr($value, 0, -1) . ':filter[' . $sub_field['id'] . '],index[0]}';
1211 + }
1070 1212 }
1071 -
1072 - foreach ($field['inputs'] as $key => $sub_field) {
1073 -
1074 - if ($field->disableQuantity && $key == '2') {
1075 -
1076 - } else {
1077 - $elements[] = $this->auto_field($sub_field, array(
1213 + $elements[] = $this->auto_field(
1214 + $sub_field,
1215 + array(
1078 1216 'type' => 'e2pdf-html',
1079 1217 'block' => true,
1080 1218 'float' => $key == '0' ? false : true,
1081 1219 'properties' => array(
@@ -1084,28 +1222,32 @@
1084 1222 'right' => '20',
1085 1223 'width' => $width,
1086 1224 'height' => 'auto',
1087 1225 'value' => isset($sub_field['label']) && $sub_field['label'] ? $sub_field['label'] : '',
1088 - )
1089 - ));
1090 -
1091 - $elements[] = $this->auto_field($sub_field, array(
1226 + ),
1227 + )
1228 + );
1229 + $elements[] = $this->auto_field(
1230 + $sub_field,
1231 + array(
1092 1232 'type' => 'e2pdf-input',
1093 1233 'properties' => array(
1094 1234 'top' => '5',
1095 1235 'width' => '100%',
1096 1236 'height' => 'auto',
1097 - 'value' => isset($merged_tags[$sub_field['id']]) ? $merged_tags[$sub_field['id']] : '',
1098 - )
1099 - ));
1100 - }
1101 - }
1237 + 'value' => $value,
1238 + ),
1239 + )
1240 + );
1102 1241 }
1103 1242 }
1104 - break;
1105 -
1106 - case 'signature':
1107 - $elements[] = $this->auto_field($field, array(
1243 + }
1244 + }
1245 + break;
1246 + case 'signature':
1247 + $elements[] = $this->auto_field(
1248 + $field,
1249 + array(
1108 1250 'type' => 'e2pdf-html',
1109 1251 'block' => true,
1110 1252 'properties' => array(
1111 1253 'top' => '20',
@@ -1113,85 +1255,235 @@
1113 1255 'right' => '20',
1114 1256 'width' => '100%',
1115 1257 'height' => 'auto',
1116 1258 'value' => $field->label,
1117 - )
1118 - ));
1119 -
1120 - $elements[] = $this->auto_field($field, array(
1259 + ),
1260 + )
1261 + );
1262 + $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
1263 + if ($this->get('nested')) {
1264 + if (substr($value, -1) == '}') {
1265 + $value = substr($value, 0, -1) . ':filter[' . $field->id . '],index[0]}';
1266 + }
1267 + }
1268 + $elements[] = $this->auto_field(
1269 + $field,
1270 + array(
1121 1271 'type' => 'e2pdf-signature',
1122 1272 'properties' => array(
1123 1273 'top' => '5',
1124 1274 'width' => '100%',
1125 1275 'height' => '150',
1126 - 'scale' => '1',
1127 1276 'dimension' => '1',
1128 - 'value' => isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : ''
1129 - )
1130 - ));
1131 - break;
1132 - default:
1133 - //non-supported fields
1134 - break;
1277 + 'block_dimension' => '1',
1278 + 'value' => $value,
1279 + ),
1280 + )
1281 + );
1282 + break;
1283 + case 'form':
1284 + if (isset($field->gpnfForm) && $field->gpnfForm) {
1285 + $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
1286 + if ($value) {
1287 + $this->set('item', $field->gpnfForm);
1288 + $this->set('nested', $value);
1289 + $nested_fields = array();
1290 + if (isset($field->gpnfFields) && is_array($field->gpnfFields)) {
1291 + $nested_fields = $field->gpnfFields;
1292 + }
1293 + $this->set('nested_fields', $nested_fields);
1294 + $nested_form = $this->auto();
1295 + if (!empty($nested_form['elements'])) {
1296 + $elements = array_merge($elements, $nested_form['elements']);
1297 + }
1298 + $this->set('item', $item);
1299 + $this->set('nested', '');
1300 + }
1135 1301 }
1136 - }
1302 + break;
1303 + case 'likert':
1304 + $elements[] = $this->auto_field(
1305 + $field,
1306 + array(
1307 + 'type' => 'e2pdf-html',
1308 + 'block' => true,
1309 + 'properties' => array(
1310 + 'top' => '20',
1311 + 'left' => '20',
1312 + 'right' => '20',
1313 + 'width' => '100%',
1314 + 'height' => 'auto',
1315 + 'value' => $field->label,
1316 + ),
1317 + )
1318 + );
1319 + if (isset($field->gsurveyLikertEnableMultipleRows) && $field->gsurveyLikertEnableMultipleRows) {
1320 + foreach ($field['inputs'] as $key => $sub_field) {
1321 + $elements[] = $this->auto_field(
1322 + $field,
1323 + array(
1324 + 'type' => 'e2pdf-html',
1325 + 'block' => true,
1326 + 'properties' => array(
1327 + 'top' => '5',
1328 + 'left' => '20',
1329 + 'right' => '20',
1330 + 'width' => '100%',
1331 + 'height' => 'auto',
1332 + 'value' => $sub_field['label'],
1333 + ),
1334 + )
1335 + );
1336 + if (isset($field->choices) && is_array($field->choices)) {
1337 + $value = isset($merged_tags[$sub_field['id']]) ? $merged_tags[$sub_field['id']] : '';
1338 + if ($field->enableChoiceValue && $value) {
1339 + if (substr($value, -1) == '}') {
1340 + $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}';
1341 + }
1342 + }
1343 + $choices = array();
1344 + foreach ($field->choices as $opt_key => $option) {
1345 +
1346 + if (!$value && isset($field->inputs) && isset($field->inputs[$opt_key]['id'])) {
1347 + $value = isset($merged_tags[$field->inputs[$opt_key]['id']]) ? $merged_tags[$field->inputs[$opt_key]['id']] : '';
1348 + if ($field->enableChoiceValue && $value) {
1349 + if (substr($value, -1) == '}') {
1350 + $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}';
1351 + }
1352 + }
1353 + }
1354 + if (isset($option['value'])) {
1355 + $choices[] = $option['value'];
1356 + }
1357 + $elements[] = $this->auto_field(
1358 + $field,
1359 + array(
1360 + 'type' => 'e2pdf-radio',
1361 + 'properties' => array(
1362 + 'top' => '5',
1363 + 'width' => 'auto',
1364 + 'height' => 'auto',
1365 + 'value' => $value,
1366 + 'option' => isset($option['text']) ? $option['text'] : '',
1367 + 'group' => $value,
1368 + ),
1369 + )
1370 + );
1371 + $elements[] = $this->auto_field(
1372 + $field,
1373 + array(
1374 + 'type' => 'e2pdf-html',
1375 + 'float' => true,
1376 + 'properties' => array(
1377 + 'left' => '5',
1378 + 'width' => '100%',
1379 + 'height' => 'auto',
1380 + 'value' => isset($option['text']) ? $option['text'] : '',
1381 + ),
1382 + )
1383 + );
1384 + }
1385 + }
1386 + }
1387 + } else {
1388 + if (isset($field->choices) && is_array($field->choices)) {
1389 + $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '';
1390 + if ($field->enableChoiceValue && $value) {
1391 + if (substr($value, -1) == '}') {
1392 + $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}';
1393 + }
1394 + }
1395 + $choices = array();
1396 + foreach ($field->choices as $opt_key => $option) {
1397 + if (!$value && isset($field->inputs) && isset($field->inputs[$opt_key]['id'])) {
1398 + $value = isset($merged_tags[$field->inputs[$opt_key]['id']]) ? $merged_tags[$field->inputs[$opt_key]['id']] : '';
1399 + if ($field->enableChoiceValue && $value) {
1400 + if (substr($value, -1) == '}') {
1401 + $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}';
1402 + }
1403 + }
1404 + }
1405 + if (isset($option['value'])) {
1406 + $choices[] = $option['value'];
1407 + }
1408 + $elements[] = $this->auto_field(
1409 + $field,
1410 + array(
1411 + 'type' => 'e2pdf-radio',
1412 + 'properties' => array(
1413 + 'top' => '5',
1414 + 'width' => 'auto',
1415 + 'height' => 'auto',
1416 + 'value' => $value,
1417 + 'option' => isset($option['text']) ? $option['text'] : '',
1418 + 'group' => $value,
1419 + ),
1420 + )
1421 + );
1422 + $elements[] = $this->auto_field(
1423 + $field,
1424 + array(
1425 + 'type' => 'e2pdf-html',
1426 + 'float' => true,
1427 + 'properties' => array(
1428 + 'left' => '5',
1429 + 'width' => '100%',
1430 + 'height' => 'auto',
1431 + 'value' => isset($option['text']) ? $option['text'] : '',
1432 + ),
1433 + )
1434 + );
1435 + }
1436 + }
1437 + }
1438 + break;
1439 + case 'repeater':
1440 + $value = isset($field->label) ? $field->label : '';
1441 + $value .= isset($field->id) ? ':' . $field->id : '';
1442 + if ($value) {
1443 + if (!empty($field->fields)) {
1444 + foreach ($field->fields as $sub_field) {
1445 + $sub_value = isset($sub_field->label) ? $sub_field->label : '';
1446 + $sub_value .= isset($field->id) ? ':' . $field->id : '';
1447 + if ($sub_value) {
1448 + $sub_field->id = $sub_field->id;
1449 + $elements = $this->auto_fields($elements, $sub_field, $merged_tags, $item);
1450 + }
1451 + }
1452 + }
1453 + }
1454 + break;
1455 + default:
1456 + break;
1137 1457 }
1138 -
1139 - $response['page'] = array(
1140 - 'bottom' => '20',
1141 - 'top' => '20',
1142 - 'left' => '20',
1143 - 'right' => '20'
1144 - );
1145 -
1146 - $response['elements'] = $elements;
1147 - return $response;
1458 + return $elements;
1148 1459 }
1149 1460
1461 + // auto field
1150 1462 public function auto_field($field = false, $element = array()) {
1151 -
1152 1463 if (!$field) {
1153 1464 return false;
1154 1465 }
1155 -
1156 1466 if (!isset($element['block'])) {
1157 1467 $element['block'] = false;
1158 1468 }
1159 -
1160 1469 if (!isset($element['float'])) {
1161 1470 $element['float'] = false;
1162 1471 }
1163 -
1164 1472 return $element;
1165 1473 }
1166 1474
1167 - /**
1168 - * Verify if item and dataset exists
1169 - *
1170 - * @return bool - item and dataset exists
1171 - */
1475 + // verify
1172 1476 public function verify() {
1173 - $item = $this->get('item');
1174 - $dataset = $this->get('dataset');
1175 -
1176 - if ($item && $dataset && class_exists('GFFormsModel')) {
1177 - $entry = GFFormsModel::get_entry($dataset);
1178 - if ($entry && isset($entry['form_id']) && $entry['form_id'] == $item) {
1477 + if ($this->get('cached_form') && $this->get('cached_entry')) {
1478 + if ($this->get('cached_entry')['form_id'] == $this->get('item')) {
1179 1479 return true;
1180 1480 }
1181 1481 }
1182 -
1183 1482 return false;
1184 1483 }
1185 1484
1186 - /**
1187 - * Create Form based on uploaded PDF
1188 - *
1189 - * @param object $template - Template Object to work with
1190 - * @param array $data - Settings to create labels/shortcodes
1191 - *
1192 - * @return object - Mapped Template Object
1193 - */
1485 + // auto form
1194 1486 public function auto_form($template, $data = array()) {
1195 1487
1196 1488 if ($template->get('ID')) {
1197 1489
@@ -1203,9 +1495,9 @@
1203 1495 $form = array(
1204 1496 'title' => $template->get('title'),
1205 1497 'fields' => array(
1206 1498 ),
1207 - 'confirmations' => array()
1499 + 'confirmations' => array(),
1208 1500 );
1209 1501
1210 1502 $form['confirmations'][$confirmation_id] = array(
1211 1503 'id' => $confirmation_id,
@@ -1211,9 +1503,10 @@
1211 1503 'id' => $confirmation_id,
1212 1504 'name' => __('Default Confirmation', 'gravityforms'),
1213 1505 'isDefault' => true,
1214 1506 'type' => 'message',
1215 - 'message' => sprintf(__('Thanks for contacting us! We will get in touch with you shortly. [e2pdf-download id="%s"]', 'gravityforms'), $template->get('ID')),
1507 + /* translators: %d: E2Pdf Template ID */
1508 + 'message' => sprintf(__('Thanks for contacting us! We will get in touch with you shortly. [e2pdf-download id="%d"]', 'e2pdf'), $template->get('ID')),
1216 1509 'url' => '',
1217 1510 'pageId' => '',
1218 1511 'queryString' => '',
1219 1512 );
@@ -1241,16 +1534,15 @@
1241 1534 }
1242 1535
1243 1536 if ($element['type'] == 'e2pdf-input' || $element['type'] == 'e2pdf-signature') {
1244 1537 $type = 'text';
1245 - $label = !empty($labels) ? implode(' ', $labels) : __('Text', 'e2pdf');
1538 + $label = !empty($labels) ? implode(' ', $labels) : 'Text';
1246 1539 } elseif ($element['type'] == 'e2pdf-textarea') {
1247 -
1248 1540 $type = 'textarea';
1249 - $label = !empty($labels) ? implode(' ', $labels) : __('Textarea', 'e2pdf');
1541 + $label = !empty($labels) ? implode(' ', $labels) : 'Textarea';
1250 1542 } elseif ($element['type'] == 'e2pdf-select') {
1251 1543 $type = 'select';
1252 - $label = !empty($labels) ? implode(' ', $labels) : __('Select', 'e2pdf');
1544 + $label = !empty($labels) ? implode(' ', $labels) : 'Select';
1253 1545
1254 1546 $choices = array();
1255 1547 $field_options = array();
1256 1548
@@ -1258,16 +1550,16 @@
1258 1550 $field_options = explode("\n", $element['properties']['options']);
1259 1551 foreach ($field_options as $option) {
1260 1552 $choices[] = array(
1261 1553 'text' => $option,
1262 - 'value' => $option
1554 + 'value' => $option,
1263 1555 );
1264 1556 }
1265 1557 }
1266 1558 } elseif ($element['type'] == 'e2pdf-checkbox') {
1267 - $field_key = array_search($element['name'], array_column($checkboxes, 'name'));
1559 + $field_key = array_search($element['name'], array_column($checkboxes, 'name'), false);
1268 1560 if ($field_key !== false) {
1269 - $checkbox = array_search($checkboxes[$field_key]['id'], array_column($form['fields'], 'id'));
1561 + $checkbox = array_search($checkboxes[$field_key]['id'], array_column($form['fields'], 'id'), false);
1270 1562 if ($checkbox !== false) {
1271 1563 $form['fields'][$checkbox]['choices'][] = array(
1272 1564 'text' => $element['properties']['option'],
1273 1565 'value' => $element['properties']['option'],
@@ -1280,9 +1572,9 @@
1280 1572 );
1281 1573 $pages[$page_key]['elements'][$element_key]['value'] = '{' . $form['fields'][$checkbox]['label'] . ':' . $form['fields'][$checkbox]['id'] . '}';
1282 1574 }
1283 1575 } else {
1284 - $label = !empty($labels) ? implode(' ', $labels) : __('Checkbox', 'e2pdf');
1576 + $label = !empty($labels) ? implode(' ', $labels) : 'Checkbox';
1285 1577 $type = 'checkbox';
1286 1578 $checkboxes[] = array(
1287 1579 'id' => $field_id,
1288 1580 'name' => $element['name'],
@@ -1290,9 +1582,9 @@
1290 1582 $choices = array(
1291 1583 array(
1292 1584 'text' => $element['properties']['option'],
1293 1585 'value' => $element['properties']['option'],
1294 - )
1586 + ),
1295 1587 );
1296 1588
1297 1589 $inputs = array(
1298 1590 array(
@@ -1297,9 +1589,9 @@
1297 1589 $inputs = array(
1298 1590 array(
1299 1591 'id' => $field_id . '.1',
1300 1592 'label' => $element['properties']['option'],
1301 - )
1593 + ),
1302 1594 );
1303 1595 }
1304 1596 } elseif ($element['type'] == 'e2pdf-radio') {
1305 1597 if (isset($element['properties']['group']) && $element['properties']['group']) {
@@ -1306,12 +1598,11 @@
1306 1598 $element['name'] = $element['properties']['group'];
1307 1599 } else {
1308 1600 $element['name'] = $element['element_id'];
1309 1601 }
1310 -
1311 - $field_key = array_search($element['name'], array_column($radios, 'name'));
1602 + $field_key = array_search($element['name'], array_column($radios, 'name'), false);
1312 1603 if ($field_key !== false) {
1313 - $radio = array_search($radios[$field_key]['id'], array_column($form['fields'], 'id'));
1604 + $radio = array_search($radios[$field_key]['id'], array_column($form['fields'], 'id'), false);
1314 1605 if ($radio !== false) {
1315 1606 $form['fields'][$radio]['choices'][] = array(
1316 1607 'text' => $element['properties']['option'],
1317 1608 'value' => $element['properties']['option'],
@@ -1316,12 +1607,12 @@
1316 1607 'text' => $element['properties']['option'],
1317 1608 'value' => $element['properties']['option'],
1318 1609 );
1319 1610
1320 - $pages[$page_key]['elements'][$element_key]['value'] = '{' . $form['fields'][$checkbox]['label'] . ':' . $form['fields'][$checkbox]['id'] . '}';
1611 + $pages[$page_key]['elements'][$element_key]['value'] = '{' . $form['fields'][$radio]['label'] . ':' . $form['fields'][$radio]['id'] . '}';
1321 1612 }
1322 1613 } else {
1323 - $label = !empty($labels) ? implode(' ', $labels) : __('Radio', 'e2pdf');
1614 + $label = !empty($labels) ? implode(' ', $labels) : 'Radio';
1324 1615 $type = 'radio';
1325 1616 $radios[] = array(
1326 1617 'id' => $field_id,
1327 1618 'name' => $element['name'],
@@ -1329,13 +1620,12 @@
1329 1620 $choices = array(
1330 1621 array(
1331 1622 'text' => $element['properties']['option'],
1332 1623 'value' => $element['properties']['option'],
1333 - )
1624 + ),
1334 1625 );
1335 1626 }
1336 1627 }
1337 -
1338 1628 if ($type) {
1339 1629 $field = array(
1340 1630 'id' => $field_id,
1341 1631 'type' => $type,
@@ -1371,13 +1661,9 @@
1371 1661
1372 1662 return $template;
1373 1663 }
1374 1664
1375 - /**
1376 - * Init Visual Mapper data
1377 - *
1378 - * @return bool|string - HTML data source for Visual Mapper
1379 - */
1665 + // visual mapper
1380 1666 public function visual_mapper() {
1381 1667
1382 1668 $item = $this->get('item');
1383 1669 $html = '';
@@ -1383,46 +1669,57 @@
1383 1669 $html = '';
1384 1670 $source = '';
1385 1671
1386 1672 if ($item && function_exists('gravity_form')) {
1387 -
1673 + ob_start();
1388 1674 $form = false;
1389 1675 if (class_exists('GFFormsModel')) {
1390 1676 $form = GFFormsModel::get_form_meta($item);
1391 1677 }
1392 -
1393 - if (!$form) {
1394 - return __('Form could not be found', 'e2pdf');
1678 + if ($form) {
1679 + add_filter('gform_pre_render', array($this, 'filter_gform_pre_render'), 30);
1680 + $source = gravity_form($item, true, true, false, null, false, 0, false);
1681 + remove_filter('gform_pre_render', array($this, 'filter_gform_pre_render'), 30);
1682 + if ($source) {
1683 + $dom = new DOMDocument();
1684 + if ($this->get('nested')) {
1685 + $source = str_replace(array('<form', '</form>'), array('<div', '</div>'), $source);
1686 + } else {
1687 + $source = '<div class="gf_browser_chrome gform_wrapper gform-theme gform-theme--foundation gform-theme--framework gform-theme--orbital">' . $source . '</div>';
1688 + }
1689 + $html = $this->helper->load('convert')->load_html($source, $dom, true);
1690 + }
1395 1691 }
1396 -
1397 - add_filter('gform_pre_render', array($this, 'filter_gform_pre_render'), 30, 1);
1398 - $source = gravity_form($item, true, true, false, null, false, 0, false);
1399 - remove_filter('gform_pre_render', array($this, 'filter_gform_pre_render'), 30);
1400 -
1401 - if ($source) {
1402 - libxml_use_internal_errors(true);
1403 - $dom = new DOMDocument();
1404 - if (function_exists('mb_convert_encoding')) {
1405 - $html = $dom->loadHTML(mb_convert_encoding($source, 'HTML-ENTITIES', 'UTF-8'));
1406 - } else {
1407 - $html = $dom->loadHTML('<?xml encoding="UTF-8">' . $source);
1408 - }
1409 - libxml_clear_errors();
1692 + if (ob_get_length() > 0) {
1693 + while (@ob_end_clean()); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
1410 1694 }
1411 -
1412 1695 if (!$source) {
1413 - return __('Form source is empty', 'e2pdf');
1696 + return '<div class="e2pdf-vm-error">' . __("The form source is empty or doesn't exist", 'e2pdf') . '</div>';
1414 1697 } elseif (!$html) {
1415 - return __('Form could not be parsed due incorrect HTML', 'e2pdf');
1698 + return '<div class="e2pdf-vm-error">' . __('The form could not be parsed due the incorrect HTML', 'e2pdf') . '</div>';
1416 1699 } else {
1700 +
1701 + $merged_tags = array();
1702 + if (class_exists('GFCommon')) {
1703 + foreach ($form['fields'] as $field) {
1704 + $merged_tags = $this->get_field_merge_tags($merged_tags, $field);
1705 + }
1706 + }
1707 + $xml = new Helper_E2pdf_Xml();
1417 1708 $xpath = new DomXPath($dom);
1418 1709
1710 + // remove by class
1419 1711 $remove_by_class = array(
1420 1712 'gf_progressbar_wrapper',
1421 1713 'gform_previous_button',
1422 1714 'gform_next_button',
1423 - 'gform_button button'
1715 + 'gform_button button',
1716 + 'gform_save_link',
1717 + 'gfield--type-captcha',
1424 1718 );
1719 + if ($this->get('nested')) {
1720 + $remove_by_class[] = 'gform_heading';
1721 + }
1425 1722 foreach ($remove_by_class as $key => $class) {
1426 1723 $elements = $xpath->query("//*[contains(@class, '{$class}')]");
1427 1724 foreach ($elements as $element) {
1428 1725 $element->parentNode->removeChild($element);
@@ -1428,192 +1725,302 @@
1428 1725 $element->parentNode->removeChild($element);
1429 1726 }
1430 1727 }
1431 1728
1729 + // display:none fix in case fields with conditional logic
1730 + $gform_wrappers = array(
1731 + 'gform_wrapper',
1732 + );
1733 + foreach ($gform_wrappers as $key => $class) {
1734 + $elements = $xpath->query("//*[contains(@class, '{$class}')]");
1735 + foreach ($elements as $element) {
1736 + if ($element->hasAttribute('style')) {
1737 + $element->removeAttribute('style');
1738 + }
1739 + }
1740 + }
1741 +
1742 + // remove by tag
1432 1743 $remove_by_tag = array(
1433 - 'script'
1744 + 'script',
1434 1745 );
1435 1746 foreach ($remove_by_tag as $key => $tag) {
1436 - $elements = $xpath->query("//{$tag}");
1747 + $elements = $xpath->query('//' . $tag);
1437 1748 foreach ($elements as $element) {
1438 1749 $element->parentNode->removeChild($element);
1439 1750 }
1440 1751 }
1441 1752
1442 - //replace time fields
1443 - $elements = $xpath->query("//*[contains(@class, 'gfield_time_hour')]");
1753 + // remove by name
1754 + $remove_by_name = array(
1755 + 'gform_field_values',
1756 + 'gform_uploaded_files',
1757 + 'MAX_FILE_SIZE',
1758 + 'is_submit_' . $item,
1759 + 'gform_submit',
1760 + 'gform_unique_id',
1761 + 'state_' . $item,
1762 + 'gform_target_page_number_' . $item,
1763 + 'gform_source_page_number_' . $item,
1764 + );
1765 + foreach ($remove_by_name as $key => $name) {
1766 + $elements = $xpath->query('//*[@name="' . $name . '"]');
1767 + foreach ($elements as $element) {
1768 + $element->parentNode->removeChild($element);
1769 + }
1770 + }
1771 +
1772 + // replace nested forms
1773 + $elements = $xpath->query("//*[contains(@class, 'gpnf-nested-entries-container')]");
1444 1774 foreach ($elements as $element) {
1445 -
1446 - $sub_elements = $xpath->query(".//*[self::input or self::select]", $element->parentNode);
1447 - foreach ($sub_elements as $sub_element) {
1448 - if ($sub_element->attributes->getNamedItem("class")->nodeValue) {
1449 - $sub_element->attributes->getNamedItem("class")->nodeValue = $sub_element->attributes->getNamedItem("class")->nodeValue . " e2pdf-no-vm";
1450 - } else {
1451 - $attr = $dom->createAttribute('class');
1452 - $attr->value = 'e2pdf-no-vm';
1453 - $sub_element->appendChild($attr);
1775 + $button = $xpath->query('./*[@data-nestedformid]', $element)->item(0);
1776 + $field = $xpath->query("following-sibling::input[@type='hidden']", $element)->item(0);
1777 + if ($button && $field) {
1778 + $form_id = $xml->get_node_value($button, 'data-nestedformid');
1779 + if ($form_id) {
1780 + $this->set('item', $form_id);
1454 1781 }
1782 + if ($field->attributes->getNamedItem('name')) {
1783 + $field_id = preg_replace('/input_([^\[]+)(?:.*)/', '${1}', $xml->get_node_value($field, 'name'));
1784 + if ($field_id) {
1785 + $value = isset($merged_tags[$field_id]) ? $merged_tags[$field_id] : '';
1786 + if (isset($merged_tags[$field_id])) {
1787 + $this->set('nested', $value);
1788 + }
1789 + }
1790 + }
1791 + $nested_form = $this->visual_mapper();
1792 + if ($nested_form) {
1793 + $element->parentNode->replaceChild($dom->importNode($nested_form->documentElement, true), $element);
1794 + }
1795 + $this->set('item', $item);
1796 + $this->set('nested', '');
1455 1797 }
1798 + }
1456 1799
1457 - if ($element->parentNode->attributes->getNamedItem("class")->nodeValue) {
1458 - $element->parentNode->attributes->getNamedItem("class")->nodeValue = $element->parentNode->attributes->getNamedItem("class")->nodeValue . ' e2pdf-vm-field-wrapper';
1459 - } else {
1460 - $attr = $dom->createAttribute('class');
1461 - $attr->value = 'e2pdf-vm-field-wrapper';
1462 - $element->parentNode->appendChild($attr);
1800 + // replace time fields
1801 + $elements = $xpath->query("//*[contains(@class, 'gfield_time_hour')]");
1802 + foreach ($elements as $element) {
1803 + $sub_elements = $xpath->query('.//*[self::input or self::select]', $element->parentNode);
1804 + foreach ($sub_elements as $sub_element) {
1805 + $xml->set_node_value($sub_element, 'class', $xml->get_node_value($sub_element, 'class') . ' e2pdf-no-vm');
1463 1806 }
1464 -
1465 - $input = $xpath->query("./input", $element)->item(0);
1807 + $xml->set_node_value($element, 'class', $xml->get_node_value($element->parentNode, 'class') . ' e2pdf-vm-rel-field', true);
1808 + $input = $xpath->query('./input', $element)->item(0);
1466 1809 $field = $dom->createElement('input');
1467 - $field_atts = array(
1468 - 'type' => 'text',
1469 - 'class' => 'e2pdf-vm-field',
1470 - 'name' => $input->attributes->getNamedItem("name")->nodeValue
1471 - );
1810 + $xml->set_node_value($field, 'type', 'text');
1811 + $xml->set_node_value($field, 'class', 'e2pdf-vm-abs-field');
1812 + $xml->set_node_value($field, 'name', $xml->get_node_value($input, 'name'));
1472 1813
1473 - foreach ($field_atts as $key => $value) {
1474 - $attr = $dom->createAttribute($key);
1475 - $attr->value = $value;
1476 - $field->appendChild($attr);
1477 - }
1478 1814 $element->parentNode->appendChild($field);
1479 1815 }
1480 1816
1481 - //replace multiupload field
1817 + // replace multiupload field
1482 1818 $elements = $xpath->query("//*[contains(@class, 'gform_drop_area')]");
1483 1819 foreach ($elements as $element) {
1484 - $element->attributes->getNamedItem("class")->nodeValue = $element->attributes->getNamedItem("class")->nodeValue . ' e2pdf-vm-field-wrapper';
1820 + $xml->set_node_value($element, 'class', $xml->get_node_value($element, 'class') . ' e2pdf-vm-rel-field');
1821 + $field_id = preg_replace('/(?:.*)_([\d]+)/', '${1}', $xml->get_node_value($element, 'id'));
1822 + $field = $dom->createElement('input');
1823 + $xml->set_node_value($field, 'type', 'text');
1824 + $xml->set_node_value($field, 'class', 'e2pdf-vm-abs-field');
1825 + $xml->set_node_value($field, 'name', 'input_' . $field_id);
1826 + $element->appendChild($field);
1827 + }
1485 1828
1486 - $field_id = '0';
1487 - if ($element->attributes->getNamedItem("id")->nodeValue) {
1488 - $field_id = preg_replace('/(?:.*)_([\d]+)/', '${1}', $element->attributes->getNamedItem("id")->nodeValue);
1829 + // hidden fields
1830 + $elements = $xpath->query("//*[contains(@class, 'gfield--input-type-hidden')]");
1831 + foreach ($elements as $element) {
1832 + $xml->set_node_value($element, 'class', str_replace('gform_hidden', '', $xml->get_node_value($element, 'class')));
1833 + $inputs = $xpath->query('.//input', $element);
1834 + foreach ($inputs as $key => $sub_element) {
1835 + $xml->set_node_value($sub_element, 'class', str_replace('gform_hidden', '', $xml->get_node_value($sub_element, 'class')));
1489 1836 }
1837 + }
1490 1838
1491 - $field = $dom->createElement('input');
1492 - $field_atts = array(
1493 - 'type' => 'text',
1494 - 'class' => 'e2pdf-vm-field',
1495 - 'name' => 'input_' . $field_id
1496 - );
1497 -
1498 - foreach ($field_atts as $key => $value) {
1499 - $attr = $dom->createAttribute($key);
1500 - $attr->value = $value;
1501 - $field->appendChild($attr);
1839 + // signature
1840 + $elements = $xpath->query("//*[contains(@class, 'gfield_signature_container') and contains(@class, 'ginput_container')]");
1841 + foreach ($elements as $element) {
1842 + $xml->set_node_value($element, 'class', $xml->get_node_value($element, 'class') . ' e2pdf-vm-rel-field');
1843 + $signature = $xpath->query('.//parent::*/input', $element);
1844 + if ($signature->item(0)) {
1845 + $field = $signature->item(0);
1846 + $xml->set_node_value($field, 'type', 'text');
1847 + $xml->set_node_value($field, 'class', 'e2pdf-vm-abs-field');
1848 + $element->appendChild($field);
1502 1849 }
1503 -
1504 - $element->appendChild($field);
1505 1850 }
1506 1851
1507 - //replace single product
1508 - $elements = $xpath->query("//*[contains(@class, 'ginput_container_singleproduct') or contains(@class, 'ginput_container_product_calculation') or contains(@class, 'ginput_container_singleshipping') or contains(@class, 'ginput_container_total') or contains(@class, 'gfield_signature_container')]");
1852 + // replace single product
1853 + $elements = $xpath->query("//*[contains(@class, 'ginput_container_singleproduct') or contains(@class, 'ginput_container_product_calculation') or contains(@class, 'ginput_container_singleshipping') or contains(@class, 'ginput_container_total')]");
1509 1854 foreach ($elements as $element) {
1510 - $spans = $xpath->query(".//span", $element);
1855 + $spans = $xpath->query('.//span', $element);
1511 1856 foreach ($spans as $key => $sub_element) {
1512 1857 $sub_element->parentNode->removeChild($sub_element);
1513 1858 }
1859 + $inputs = $xpath->query('.//input', $element);
1860 + foreach ($inputs as $key => $sub_element) {
1861 + $xml->set_node_value($sub_element, 'type', 'text');
1862 + $xml->set_node_value($sub_element, 'class', '');
1863 + }
1864 + }
1514 1865
1515 - $inputs = $xpath->query(".//input", $element);
1866 + $fields = $this->get_form_fields(array(), $form['fields']);
1867 +
1868 + $elements = $xpath->query("//*[contains(@class, 'gsurvey-likert-choice')]");
1869 + foreach ($elements as $element) {
1870 + $label = $xml->get_node_value($element, 'data-label');
1871 + $sub_element = $xpath->query('.//input', $element)->item(0);
1872 + if ($label && $sub_element) {
1873 + $xml->set_node_value($sub_element, 'value', $label);
1874 + }
1875 + }
1876 +
1877 + $elements = $xpath->query("//*[contains(@class, 'gsurvey-rating')]");
1878 + foreach ($elements as $element) {
1879 + $inputs = $xpath->query('.//input', $element);
1516 1880 foreach ($inputs as $key => $sub_element) {
1517 - $sub_element->attributes->getNamedItem("type")->nodeValue = 'text';
1518 - $sub_element->attributes->getNamedItem("class")->nodeValue = '';
1881 + $label = $xpath->query('.//following-sibling::label[1]', $sub_element)->item(0);
1882 + if ($label) {
1883 + $title = $xml->get_node_value($label, 'title');
1884 + $xml->set_node_value($sub_element, 'value', $title);
1885 + }
1519 1886 }
1520 1887 }
1521 1888
1522 - $merged_tags = array();
1523 - if (class_exists('GFCommon')) {
1524 - foreach ($form['fields'] as $field) {
1525 - $tags = GFCommon::get_field_merge_tags($field);
1526 - foreach ($tags as $tag) {
1527 - if (isset($tag['tag'])) {
1528 - if ($field->type == 'list') {
1529 - $field_id = preg_replace('/\{(?:.*)\:(.*)\:\}/', '${1}', $tag['tag']);
1530 - } else {
1531 - $field_id = preg_replace('/\{(?:.*)\:(.*)\}/', '${1}', $tag['tag']);
1532 - }
1533 - if ($field_id) {
1534 - $merged_tags[$field_id] = $tag['tag'];
1535 - }
1536 - }
1889 + $elements = $xpath->query("//*[contains(@class, 'gsurvey-survey-field')]//select");
1890 + foreach ($elements as $element) {
1891 + $inputs = $xpath->query('.//option', $element);
1892 + foreach ($inputs as $key => $sub_element) {
1893 + $label = $sub_element->nodeValue;
1894 + if ($label) {
1895 + $xml->set_node_value($sub_element, 'value', $label);
1537 1896 }
1538 1897 }
1539 1898 }
1540 1899
1541 - $fields = array();
1542 - foreach ($form['fields'] as $field) {
1543 - $fields[$field->id] = $field;
1900 + $elements = $xpath->query("//*[contains(@class, 'ginput_container_rank')]//input");
1901 + foreach ($elements as $element) {
1902 + $xml->set_node_value($element, 'type', 'text');
1544 1903 }
1545 1904
1905 + // replace by types
1546 1906 $replace_by_types = array(
1547 - "//input",
1548 - "//textarea",
1549 - "//select"
1907 + '//input',
1908 + '//textarea',
1909 + '//select',
1550 1910 );
1551 -
1552 1911 foreach ($replace_by_types as $replace_by_type) {
1553 1912 $inputs = $xpath->query($replace_by_type);
1554 1913 foreach ($inputs as $element) {
1555 - $type = $element->attributes->getNamedItem("type")->nodeValue;
1556 - if ($element->attributes->getNamedItem("name")) {
1557 -
1914 + if ($element->attributes->getNamedItem('name')) {
1558 1915 $field_id = false;
1559 1916 $field = false;
1560 - $sub_field_id = preg_replace('/input_([^\[]+)(?:.*)/', '${1}', $element->attributes->getNamedItem("name")->nodeValue);
1561 -
1917 + $sub_field_id = preg_replace('/input_([^\[]+)(?:.*)/', '${1}', $xml->get_node_value($element, 'name'));
1562 1918 if ($sub_field_id) {
1563 -
1564 1919 if (substr($sub_field_id, -6) == '_valid') {
1565 1920 $field_id = preg_replace('/(?:.*)\_([\d]+)\_valid/', '${1}', $sub_field_id);
1921 + } elseif (substr($sub_field_id, -5) == '_data') {
1922 + $field_id = preg_replace('/(?:.*)\_([\d]+)\_data/', '${1}', $sub_field_id);
1566 1923 } else {
1567 1924 $field_id = preg_replace('/([\d]+)\.(?:.*)/', '${1}', $sub_field_id);
1568 1925 }
1569 -
1570 1926 if (isset($fields[$field_id])) {
1571 1927 $field = $fields[$field_id];
1572 1928 }
1573 1929 }
1574 -
1575 1930 if ($field) {
1576 1931 if (
1577 1932 $field->type == 'name' ||
1578 - $field->type == 'address' ||
1579 - ($field->type == 'product' && $field->inputType && ($field->inputType == 'singleproduct' || $field->inputType == 'calculation'))
1933 + $field->type == 'address' || (
1934 + $field->type == 'product' &&
1935 + $field->inputType &&
1936 + ($field->inputType == 'singleproduct' || $field->inputType == 'calculation')
1937 + )
1580 1938 ) {
1581 1939 $value = $merged_tags[$sub_field_id];
1582 - $element->attributes->getNamedItem("name")->nodeValue = $value;
1940 + if ($this->get('nested')) {
1941 + if (substr($value, -1) == '}') {
1942 + $value = substr($value, 0, -1) . ':filter[' . $sub_field_id . '],index[0]}';
1943 + }
1944 + }
1945 + $xml->set_node_value($element, 'name', $value);
1583 1946 } elseif ($field->type == 'consent') {
1584 1947 $value = isset($merged_tags[$field_id . '.1']) ? $merged_tags[$field_id . '.1'] : '';
1585 - $element->attributes->getNamedItem("name")->nodeValue = $value;
1948 + if ($this->get('nested')) {
1949 + if (substr($value, -1) == '}') {
1950 + $value = substr($value, 0, -1) . ':filter[' . $field_id . '.1],index[0]}';
1951 + }
1952 + }
1953 + $xml->set_node_value($element, 'name', $value);
1954 + } elseif ($field->type == 'survey') {
1955 + $value = isset($merged_tags[$sub_field_id]) ? $merged_tags[$sub_field_id] : '';
1956 + if (isset($field['inputType']) &&
1957 + $field['inputType'] != 'text' &&
1958 + $field['inputType'] != 'textarea' &&
1959 + $field['inputType'] != 'select' &&
1960 + $field['inputType'] != 'rank') {
1961 + if (isset($field['enableChoiceValue'])) {
1962 + $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}';
1963 + }
1964 + }
1965 + $xml->set_node_value($element, 'name', $value);
1586 1966 } else {
1587 1967 if (isset($merged_tags[$field_id])) {
1588 1968 $value = $merged_tags[$field_id];
1589 1969 if (substr($value, -1) == '}') {
1590 - if ($element->parentNode->attributes->getNamedItem("class") && (false !== strpos($element->parentNode->attributes->getNamedItem("class")->nodeValue, 'ginput_post_image_'))) {
1591 - if (false !== strpos($element->parentNode->attributes->getNamedItem("class")->nodeValue, 'ginput_post_image_title')) {
1592 - $value = substr($value, 0, -1) . ':title}';
1593 - } elseif (false !== strpos($element->parentNode->attributes->getNamedItem("class")->nodeValue, 'ginput_post_image_caption')) {
1594 - $value = substr($value, 0, -1) . ':caption}';
1595 - } elseif (false !== strpos($element->parentNode->attributes->getNamedItem("class")->nodeValue, 'ginput_post_image_description')) {
1596 - $value = substr($value, 0, -1) . ':description}';
1970 + if (false !== strpos($xml->get_node_value($element->parentNode, 'class'), 'ginput_post_image_')) {
1971 + if (false !== strpos($xml->get_node_value($element->parentNode, 'class'), 'ginput_post_image_title')) {
1972 + if ($this->get('nested')) {
1973 + $value = substr($value, 0, -1) . ':title,filter[' . $field_id . '],index[0]}';
1974 + } else {
1975 + $value = substr($value, 0, -1) . ':title}';
1976 + }
1977 + } elseif (false !== strpos($xml->get_node_value($element->parentNode, 'class'), 'ginput_post_image_caption')) {
1978 + if ($this->get('nested')) {
1979 + $value = substr($value, 0, -1) . ':caption,filter[' . $field_id . '],index[0]}';
1980 + } else {
1981 + $value = substr($value, 0, -1) . ':caption}';
1982 + }
1983 + } elseif (false !== strpos($xml->get_node_value($element->parentNode, 'class'), 'ginput_post_image_description')) {
1984 + if ($this->get('nested')) {
1985 + $value = substr($value, 0, -1) . ':description,filter[' . $field_id . '],index[0]}';
1986 + } else {
1987 + $value = substr($value, 0, -1) . ':description}';
1988 + }
1597 1989 }
1598 1990 } elseif ($field->type == 'list') {
1599 1991 if ($field->enableColumns) {
1600 - $parent_class = $element->parentNode->attributes->getNamedItem("class")->nodeValue;
1992 + $parent_class = $xml->get_node_value($element->parentNode, 'class');
1601 1993 $index = 1;
1602 1994 $td = $xpath->query("./td[contains(@class, '{$parent_class}')]/preceding-sibling::td", $element->parentNode->parentNode);
1603 1995 if ($td && isset($td->length)) {
1604 1996 $index = (int) $td->length + 1;
1605 1997 }
1606 - $value = substr($value, 0, -1) . '1_' . $index . '}';
1998 + if ($this->get('nested')) {
1999 + $value = substr($value, 0, -1) . ':value,filter[' . $field_id . ':1_' . $index . '],index[0]}';
2000 + } else {
2001 + $value = substr($value, 0, -1) . '1_' . $index . '}';
2002 + }
1607 2003 } else {
1608 - $value = substr($value, 0, -1) . '1}';
2004 + if ($this->get('nested')) {
2005 + $value = substr($value, 0, -1) . ':filter[' . $field_id . ':1],index[0]}';
2006 + } else {
2007 + $value = substr($value, 0, -1) . '1}';
2008 + }
1609 2009 }
1610 2010 } elseif ($field->enableChoiceValue && $value) {
1611 - $value = substr($value, 0, -1) . ':value}';
2011 + if ($this->get('nested')) {
2012 + $value = substr($value, 0, -1) . ':value,filter[' . $field_id . '],index[0]}';
2013 + } else {
2014 + $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}';
2015 + }
2016 + } else {
2017 + if ($this->get('nested')) {
2018 + $value = substr($value, 0, -1) . ':filter[' . $field_id . '],index[0]}';
2019 + }
1612 2020 }
1613 2021 }
1614 -
1615 - $element->attributes->getNamedItem("name")->nodeValue = $value;
2022 + $xml->set_node_value($element, 'name', $value);
1616 2023 }
1617 2024 }
1618 2025 }
1619 2026 }
@@ -1619,9 +2026,27 @@
1619 2026 }
1620 2027 }
1621 2028 }
1622 2029
1623 - return $dom->saveHTML();
2030 + /* Replace other choice */
2031 + $elements = $xpath->query("//*[@value='gf_other_choice']/parent::*");
2032 + foreach ($elements as $element) {
2033 + $radio = $xpath->query(".//input[@type='radio']", $element)->item(0);
2034 + $input = $xpath->query(".//input[@type='text']", $element)->item(0);
2035 + if ($radio && $input) {
2036 + $xml->set_node_value($input, 'name', $xml->get_node_value($radio, 'name'));
2037 + }
2038 + }
2039 +
2040 + if ($this->get('nested')) {
2041 + return $dom;
2042 + } else {
2043 + if (defined('LIBXML_HTML_NOIMPLIED') && defined('LIBXML_HTML_NODEFDTD')) {
2044 + return str_replace(array('<html>', '</html>'), '', $dom->saveHTML());
2045 + } else {
2046 + return $dom->saveHTML();
2047 + }
2048 + }
1624 2049 }
1625 2050 }
1626 2051
1627 2052 return false;
@@ -1626,16 +2051,9 @@
1626 2051
1627 2052 return false;
1628 2053 }
1629 2054
1630 - /**
1631 - * Convert Field name to Value
1632 - * @since 0.01.34
1633 - *
1634 - * @param string $name - Field name
1635 - *
1636 - * @return bool|string - Converted value or false
1637 - */
2055 + // auto map
1638 2056 public function auto_map($name = false) {
1639 2057
1640 2058 $item = $this->get('item');
1641 2059
@@ -1654,24 +2072,11 @@
1654 2072
1655 2073 if ($form) {
1656 2074 if (class_exists('GFCommon')) {
1657 2075 foreach ($form['fields'] as $field) {
1658 - $tags = GFCommon::get_field_merge_tags($field);
1659 - foreach ($tags as $tag) {
1660 - if (isset($tag['tag'])) {
1661 - if ($field->type == 'list') {
1662 - $field_id = preg_replace('/\{(?:.*)\:(.*)\:\}/', '${1}', $tag['tag']);
1663 - } else {
1664 - $field_id = preg_replace('/\{(?:.*)\:(.*)\}/', '${1}', $tag['tag']);
1665 - }
1666 - if ($field_id) {
1667 - $merged_tags[$field_id] = $tag['tag'];
1668 - }
1669 - }
1670 - }
2076 + $merged_tags = $this->get_field_merge_tags($merged_tags, $field);
1671 2077 }
1672 2078 }
1673 -
1674 2079 if (isset($merged_tags[$sub_field_id])) {
1675 2080 return $merged_tags[$sub_field_id];
1676 2081 }
1677 2082 }
@@ -1679,81 +2084,115 @@
1679 2084
1680 2085 return false;
1681 2086 }
1682 2087
1683 - /**
1684 - * Load additional shortcodes for this extension
1685 - */
1686 - public function load_shortcodes() {
1687 -
2088 + // load shortcodes
2089 + public function load_shortcodes() { // phpcs:ignore Squiz.WhiteSpace.SuperfluousWhitespace.EndLine
1688 2090 }
1689 2091
1690 - public function filter_gform_confirmation($content, $form, $dataset, $ajax) {
2092 + // entry field value filter
2093 + public function filter_gform_entry_field_value($display_value, $field, $lead, $form) {
2094 + if (isset($field->defaultValue) && (false !== strpos($field->defaultValue, '[e2pdf-download') || false !== strpos($field->defaultValue, '[e2pdf-save'))) {
2095 + $display_value = wp_specialchars_decode($display_value, ENT_QUOTES);
2096 + }
2097 + return $display_value;
2098 + }
1691 2099
2100 + // merge tag filter
2101 + public function filter_gform_merge_tag_filter($value, $merge_tag, $modifier, $field, $raw_value) {
2102 + if (isset($field->defaultValue) && (false !== strpos($field->defaultValue, '[e2pdf-download') || false !== strpos($field->defaultValue, '[e2pdf-save'))) {
2103 + return $raw_value;
2104 + }
2105 + return $value;
2106 + }
2107 +
2108 + // entries field value filter
2109 + public function filter_gform_entries_field_value($value, $form_id, $field_id, $entry) {
2110 + $field = GFAPI::get_field($form_id, $field_id);
2111 + if (isset($field->defaultValue) && (false !== strpos($field->defaultValue, '[e2pdf-download') || false !== strpos($field->defaultValue, '[e2pdf-save'))) {
2112 + $value = wp_specialchars_decode($value, ENT_QUOTES);
2113 + }
2114 + return $value;
2115 + }
2116 +
2117 + // gp template path filter
2118 + public function filter_gp_template_paths($file_paths, $gp_template) {
2119 + $template_dir = $gp_template->get_theme_template_dir_name();
2120 + $e2pdf_file_paths = array(
2121 + -100 => trailingslashit(get_stylesheet_directory()) . $template_dir . 'e2pdf/',
2122 + -99 => trailingslashit(get_template_directory()) . $template_dir . 'e2pdf/',
2123 + );
2124 + $file_paths = $file_paths + $e2pdf_file_paths;
2125 + return $file_paths;
2126 + }
2127 +
2128 + // gform confirmation filter
2129 + public function filter_gform_confirmation($content, $form, $entry, $ajax) {
2130 + return $this->filter_content($content, isset($entry['id']) ? $entry['id'] : 0, false, 'message');
2131 + }
2132 +
2133 + // twilio message filter
2134 + public function filter_gform_twilio_message($notification, $feed, $entry, $form) {
2135 + $content = isset($notification['body']) && $notification['body'] ? $notification['body'] : '';
1692 2136 if (false === strpos($content, '[')) {
1693 - return $content;
2137 + return $notification;
1694 2138 }
1695 2139
1696 2140 $shortcode_tags = array(
1697 2141 'e2pdf-download',
1698 - 'e2pdf-save',
1699 2142 'e2pdf-view',
1700 - 'e2pdf-adobesign'
1701 2143 );
1702 -
1703 2144 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
1704 2145 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1705 -
1706 2146 if (!empty($tagnames)) {
1707 -
1708 - $pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames);
1709 -
1710 - preg_match_all("/$pattern/", $content, $shortcodes);
2147 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
1711 2148 foreach ($shortcodes[0] as $key => $shortcode_value) {
1712 -
1713 - $shortcode = array();
1714 - $shortcode[1] = $shortcodes[1][$key];
1715 - $shortcode[2] = $shortcodes[2][$key];
1716 - $shortcode[3] = $shortcodes[3][$key];
1717 - $shortcode[4] = $shortcodes[4][$key];
1718 - $shortcode[5] = $shortcodes[5][$key];
1719 - $shortcode[6] = $shortcodes[6][$key];
1720 -
2149 + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
1721 2150 $atts = shortcode_parse_atts($shortcode[3]);
1722 -
1723 - if (($shortcode[2] === 'e2pdf-save' && isset($atts['attachment']) && $atts['attachment'] == 'true') || $shortcode[2] === 'e2pdf-attachment') {
1724 -
1725 - } else {
1726 - if (!isset($atts['dataset']) && isset($atts['id'])) {
1727 - $template = new Model_E2pdf_Template();
1728 - $template->load($atts['id']);
1729 - if ($template->get('extension') === 'gravity') {
1730 - $entry_id = $dataset && isset($dataset['id']) ? $dataset['id'] : false;
1731 - if ($entry_id) {
1732 - $atts['dataset'] = $entry_id;
1733 - $shortcode[3] .= " dataset=\"{$entry_id}\"";
1734 - }
2151 + if (!isset($atts['dataset']) && isset($atts['id'])) {
2152 + $template = new Model_E2pdf_Template();
2153 + $template->load($atts['id']);
2154 + if ($template->get('extension') === 'gravity') {
2155 + $entry_id = $entry && isset($entry['id']) ? $entry['id'] : false;
2156 + if ($entry_id) {
2157 + $atts['dataset'] = $entry_id;
2158 + $shortcode[3] .= ' dataset="' . $entry_id . '"';
1735 2159 }
1736 2160 }
1737 -
1738 - if (!isset($atts['apply'])) {
1739 - $shortcode[3] .= " apply=\"true\"";
2161 + }
2162 + if (!isset($atts['apply'])) {
2163 + $shortcode[3] .= ' apply="true"';
2164 + }
2165 + if (!isset($atts['filter'])) {
2166 + $shortcode[3] .= ' filter="true"';
2167 + }
2168 + if ($shortcode[2] === 'e2pdf-download' || ($shortcode[2] === 'e2pdf-view' && isset($atts['output']) && $atts['output'] == 'url')) {
2169 + if (class_exists('GFCommon')) {
2170 + $shortcode[3] = GFCommon::replace_variables($shortcode[3], $form, $entry, false, false, false, 'text');
1740 2171 }
2172 + $notification['body'] = str_replace($shortcode_value, do_shortcode_tag($shortcode), $notification['body']);
2173 + }
2174 + }
2175 + }
2176 + return $notification;
2177 + }
1741 2178
1742 - if (!isset($atts['filter'])) {
1743 - $shortcode[3] .= " filter=\"true\"";
1744 - }
1745 -
1746 - $new_shortcode = "[" . $shortcode[2] . $shortcode[3] . "]";
1747 - $content = str_replace($shortcode_value, $new_shortcode, $content);
2179 + // gfrom post save filter
2180 + public function filter_gform_entry_post_save($entry, $form) {
2181 + if (isset($form['fields'])) {
2182 + foreach ($form['fields'] as $key => $field) {
2183 + if (isset($field->defaultValue) && (false !== strpos($field->defaultValue, '[e2pdf-download') || false !== strpos($field->defaultValue, '[e2pdf-save'))) {
2184 + $value = $this->filter_content($field->defaultValue, isset($entry['id']) ? $entry['id'] : 0, true);
2185 + $entry[$field['id']] = $value;
2186 + GFAPI::update_entry_field($entry['id'], $field['id'], $value);
1748 2187 }
1749 2188 }
1750 2189 }
1751 -
1752 - return $content;
2190 + return $entry;
1753 2191 }
1754 2192
1755 - public function filter_gform_notification($notification, $form, $dataset) {
2193 + // gform notification filter
2194 + public function filter_gform_notification($notification, $form, $entry) {
1756 2195
1757 2196 $content = isset($notification['message']) && $notification['message'] ? $notification['message'] : '';
1758 2197
1759 2198 if (false === strpos($content, '[')) {
@@ -1759,88 +2198,160 @@
1759 2198 if (false === strpos($content, '[')) {
1760 2199 return $notification;
1761 2200 }
1762 2201
2202 + // conditional shortcode fix since 1.13.18
1763 2203 $shortcode_tags = array(
2204 + 'gravityforms',
2205 + );
2206 + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
2207 + $tagnames = array_intersect($shortcode_tags, $matches[1]);
2208 + if (!empty($tagnames)) {
2209 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
2210 + foreach ($shortcodes[0] as $key => $shortcode_value) {
2211 + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
2212 + $conditional_shortcode_tags = array(
2213 + 'e2pdf-download',
2214 + 'e2pdf-save',
2215 + 'e2pdf-view',
2216 + 'e2pdf-adobesign',
2217 + 'e2pdf-attachment',
2218 + 'e2pdf-zapier',
2219 + );
2220 + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $shortcode[5], $conditional_matches);
2221 + $conditional_tagnames = array_intersect($conditional_shortcode_tags, $conditional_matches[1]);
2222 + $atts = shortcode_parse_atts($shortcode[3]);
2223 + if (isset($atts['action']) && $atts['action'] == 'conditional' && !empty($conditional_tagnames)) {
2224 + $shortcode[5] = '1';
2225 + if (class_exists('GFCommon')) {
2226 + $shortcode[3] = GFCommon::replace_variables($shortcode[3], $form, $entry, false, false, false, 'text');
2227 + }
2228 + $value = do_shortcode_tag($shortcode);
2229 + if ($value !== '1') {
2230 + $content = str_replace($shortcode_value, '', $content);
2231 + }
2232 + }
2233 + }
2234 + }
2235 +
2236 + $shortcode_tags = array(
1764 2237 'e2pdf-download',
1765 2238 'e2pdf-save',
1766 2239 'e2pdf-view',
1767 2240 'e2pdf-adobesign',
1768 - 'e2pdf-attachment'
2241 + 'e2pdf-attachment',
2242 + 'e2pdf-zapier',
1769 2243 );
1770 -
1771 2244 preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
1772 2245 $tagnames = array_intersect($shortcode_tags, $matches[1]);
1773 -
1774 2246 if (!empty($tagnames)) {
1775 -
1776 - $pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames);
1777 -
1778 - preg_match_all("/$pattern/", $content, $shortcodes);
1779 -
2247 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
1780 2248 foreach ($shortcodes[0] as $key => $shortcode_value) {
1781 -
1782 - $shortcode = array();
1783 - $shortcode[1] = $shortcodes[1][$key];
1784 - $shortcode[2] = $shortcodes[2][$key];
1785 - $shortcode[3] = $shortcodes[3][$key];
1786 - $shortcode[4] = $shortcodes[4][$key];
1787 - $shortcode[5] = $shortcodes[5][$key];
1788 - $shortcode[6] = $shortcodes[6][$key];
1789 -
2249 + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
1790 2250 $atts = shortcode_parse_atts($shortcode[3]);
1791 -
1792 2251 if (!isset($atts['dataset']) && isset($atts['id'])) {
1793 2252 $template = new Model_E2pdf_Template();
1794 2253 $template->load($atts['id']);
1795 2254 if ($template->get('extension') === 'gravity') {
1796 - $entry_id = $dataset && isset($dataset['id']) ? $dataset['id'] : false;
2255 + $entry_id = $entry && isset($entry['id']) ? $entry['id'] : false;
1797 2256 if ($entry_id) {
1798 2257 $atts['dataset'] = $entry_id;
1799 - $shortcode[3] .= " dataset=\"{$entry_id}\"";
2258 + $shortcode[3] .= ' dataset="' . $entry_id . '"';
1800 2259 }
1801 2260 }
1802 2261 }
1803 -
1804 2262 if (!isset($atts['apply'])) {
1805 - $shortcode[3] .= " apply=\"true\"";
2263 + $shortcode[3] .= ' apply="true"';
1806 2264 }
1807 -
1808 2265 if (!isset($atts['filter'])) {
1809 - $shortcode[3] .= " filter=\"true\"";
2266 + $shortcode[3] .= ' filter="true"';
1810 2267 }
1811 -
1812 2268 $file = false;
1813 -
1814 - if (($shortcode[2] === 'e2pdf-save' && isset($atts['attachment']) && $atts['attachment'] == 'true') || $shortcode[2] === 'e2pdf-attachment') {
1815 -
2269 + if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) {
1816 2270 if (class_exists('GFCommon')) {
1817 - $shortcode[3] = GFCommon::replace_variables($shortcode[3], $form, $dataset, false, false, false, 'text');
2271 + add_filter('gform_merge_tag_filter', array($this, 'filter_gform_merge_tag_filter_attributes'), 30, 5);
2272 + $shortcode[3] = GFCommon::replace_variables($shortcode[3], $form, $entry, false, false, false, 'text');
2273 + remove_filter('gform_merge_tag_filter', array($this, 'filter_gform_merge_tag_filter_attributes'), 30);
1818 2274 }
1819 -
1820 2275 $file = do_shortcode_tag($shortcode);
1821 2276 if ($file) {
1822 - if ($shortcode[2] != 'e2pdf-save' && !isset($atts['pdf'])) {
2277 + $tmp = false;
2278 + if (substr($file, 0, 4) === 'tmp:') {
2279 + $file = substr($file, 4);
2280 + $tmp = true;
2281 + }
2282 + if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) {
2283 + if ($tmp) {
2284 + $this->helper->add('gravity_attachments', $file);
2285 + }
2286 + } else {
1823 2287 $this->helper->add('gravity_attachments', $file);
1824 2288 }
1825 -
1826 - $notification['attachments'] = ( is_array(rgget('attachments', $notification)) ) ? rgget('attachments', $notification) : array();
2289 + $notification['attachments'] = (is_array(rgget('attachments', $notification))) ? rgget('attachments', $notification) : array();
1827 2290 $notification['attachments'][] = $file;
1828 2291 }
1829 -
1830 2292 $notification['message'] = str_replace($shortcode_value, '', $notification['message']);
1831 2293 } else {
1832 - $new_shortcode = "[" . $shortcode[2] . $shortcode[3] . "]";
1833 - $notification['message'] = str_replace($shortcode_value, $new_shortcode, $notification['message']);
2294 + $notification['message'] = str_replace($shortcode_value, '[' . $shortcode[2] . $shortcode[3] . ']', $notification['message']);
1834 2295 }
1835 2296 }
1836 2297 }
2298 + return $notification;
2299 + }
1837 2300
1838 - return $notification;
2301 + // filter content
2302 + public function filter_content($content = '', $entry_id = 0, $do_shortcode = false, $type = '') {
2303 + if (is_array($content) || false === strpos($content, '[')) {
2304 + return $content;
2305 + }
2306 + $shortcode_tags = array(
2307 + 'e2pdf-download',
2308 + 'e2pdf-save',
2309 + 'e2pdf-view',
2310 + 'e2pdf-adobesign',
2311 + 'e2pdf-zapier',
2312 + );
2313 + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches);
2314 + $tagnames = array_intersect($shortcode_tags, $matches[1]);
2315 + if (!empty($tagnames)) {
2316 + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes);
2317 + foreach ($shortcodes[0] as $key => $shortcode_value) {
2318 + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key);
2319 + $atts = shortcode_parse_atts($shortcode[3]);
2320 + if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf
2321 + } else {
2322 + if (!isset($atts['dataset']) && isset($atts['id'])) {
2323 + $template = new Model_E2pdf_Template();
2324 + $template->load($atts['id']);
2325 + if ($template->get('extension') === 'gravity') {
2326 + if ($entry_id) {
2327 + $atts['dataset'] = $entry_id;
2328 + $shortcode[3] .= ' dataset="' . $entry_id . '"';
2329 + }
2330 + }
2331 + }
2332 + if (!isset($atts['apply'])) {
2333 + $shortcode[3] .= ' apply="true"';
2334 + }
2335 + if (!isset($atts['filter'])) {
2336 + $shortcode[3] .= ' filter="true"';
2337 + }
2338 + if (!isset($atts['iframe_download']) && $type == 'message') {
2339 + $shortcode[3] .= ' iframe_download="true"';
2340 + }
2341 + if ($do_shortcode) {
2342 + $content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content);
2343 + } else {
2344 + $content = str_replace($shortcode_value, '[' . $shortcode[2] . $shortcode[3] . ']', $content);
2345 + }
2346 + }
2347 + }
2348 + }
2349 + return $content;
1839 2350 }
1840 2351
2352 + // gform pre render filter
1841 2353 public function filter_gform_pre_render($form) {
1842 -
1843 2354 if (isset($form['fields'])) {
1844 2355 foreach ($form['fields'] as $key => $field) {
1845 2356 if ($field->pageNumber != '1') {
1846 2357 $field->pageNumber = '1';
@@ -1847,27 +2358,54 @@
1847 2358 $form['fields'][$key] = $field;
1848 2359 }
1849 2360 }
1850 2361 }
2362 + return $form;
2363 + }
1851 2364
1852 - return $form;
2365 + // merge tag attributes filter
2366 + public function filter_gform_merge_tag_filter_attributes($value, $merge_tag, $modifier, $field, $raw_value) {
2367 + if ($value) {
2368 + return esc_attr($value);
2369 + }
2370 + return $value;
1853 2371 }
1854 2372
1855 - public function filter_gform_merge_tag_filter($value, $merge_tag, $modifier, $field, $raw_value) {
2373 + // merge tag args filter
2374 + public function filter_gform_merge_tag_filter_tags($value, $merge_tag, $modifier, $field, $raw_value) {
1856 2375
1857 2376 if ($field && $value) {
1858 2377 if ($field->type == 'consent') {
2378 + if (false !== strpos($modifier, 'filter') && is_callable('gw_all_fields_template')) {
2379 + $modifiers = gw_all_fields_template()->parse_modifiers($modifier);
2380 + if (isset($modifiers['filter']) && $modifiers['filter'] && !is_array($modifiers['filter'])) {
2381 + $merge_tag = $modifiers['filter'];
2382 + }
2383 + }
1859 2384 $mod = explode('.', $merge_tag);
1860 2385 if (isset($mod[1]) && $mod[1] == '1') {
1861 2386 $value = '1';
1862 2387 }
1863 2388 } elseif ($field->type == 'list') {
2389 + if (false !== strpos($modifier, 'filter') && is_callable('gw_all_fields_template')) {
2390 + $modifiers = gw_all_fields_template()->parse_modifiers($modifier);
2391 + if (isset($modifiers['filter']) && $modifiers['filter'] && !is_array($modifiers['filter'])) {
2392 + if (false !== strpos($modifiers['filter'], ':')) {
2393 + $mods = explode(':', $modifiers['filter']);
2394 + $merge_tag = $mods[0];
2395 + $modifier = $mods[1];
2396 + } else {
2397 + $merge_tag = $modifiers['filter'];
2398 + }
2399 + }
2400 + if ($merge_tag != $field->id) {
2401 + return false;
2402 + }
2403 + }
1864 2404
1865 2405 if ($modifier && $modifier != 'text') {
1866 -
1867 2406 $list_id = false;
1868 2407 $field_id = false;
1869 -
1870 2408 if (false !== strpos($modifier, '_')) {
1871 2409 $mod = explode('_', $modifier);
1872 2410 if (isset($mod[0]) && is_numeric($mod[0])) {
1873 2411 $list_id = $mod[0] - 1;
@@ -1877,12 +2415,15 @@
1877 2415 }
1878 2416 } elseif (is_numeric($modifier)) {
1879 2417 $list_id = $modifier - 1;
1880 2418 }
1881 -
1882 2419 if ($list_id !== false) {
1883 2420 $value = '';
1884 - $list = maybe_unserialize($raw_value);
2421 + if (is_serialized($raw_value)) {
2422 + $list = $this->helper->load('convert')->unserialize(trim($raw_value));
2423 + } else {
2424 + $list = $raw_value;
2425 + }
1885 2426 if (is_array($list)) {
1886 2427 if (isset($list[$list_id])) {
1887 2428 if ($field_id !== false) {
1888 2429 if (is_array($list[$list_id]) && isset(array_values($list[$list_id])[$field_id])) {
@@ -1898,17 +2439,73 @@
1898 2439 }
1899 2440 }
1900 2441 }
1901 2442 }
2443 + } elseif ($field->type == 'name' || $field->type == 'address') {
2444 + if (false !== strpos($modifier, 'filter') && is_callable('gw_all_fields_template')) {
2445 + $modifiers = gw_all_fields_template()->parse_modifiers($modifier);
2446 + if (isset($modifiers['filter']) && $modifiers['filter'] && !is_array($modifiers['filter'])) {
2447 + if (is_array($raw_value) && isset($raw_value[$modifiers['filter']])) {
2448 + return $raw_value[$modifiers['filter']];
2449 + }
2450 + }
2451 + }
2452 + } elseif ($field->type == 'repeater') {
2453 + if (false !== strpos($modifier, 'repeater')) {
2454 + $modifiers = explode(',', $modifier);
2455 + foreach ($modifiers as $filter) {
2456 + if (preg_match('/^repeater(?:\.\d+)+$/', $filter)) {
2457 + $value = '';
2458 + $path = explode('.', $filter);
2459 + if (apply_filters('e2pdf_for_do_shortcode_data_process', false)) {
2460 + array_shift($path);
2461 + $lead = $this->helper->load('shortcode')->apply_path_attribute($raw_value, implode('.', $path));
2462 + if (!empty($lead)) {
2463 + $value = serialize($lead); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
2464 + }
2465 + } else {
2466 + $merge_field_id = end($path);
2467 + array_shift($path);
2468 + array_pop($path);
2469 + if (!empty($path)) {
2470 + $lead = $this->helper->load('shortcode')->apply_path_attribute($raw_value, implode('.', $path));
2471 + if (!empty($lead)) {
2472 + $filters = preg_replace('/repeater(?:\.\d+)+,?/', '', $modifier);
2473 + $merge_tag = '{:' . $merge_field_id . ($filters ? ':' . $filters : '') . '}';
2474 + $value = GFCommon::replace_variables($merge_tag, $this->get('cached_form'), $lead, false, false, false, 'text');
2475 + }
2476 + }
2477 + }
2478 + break;
2479 + }
2480 + }
2481 + } elseif (apply_filters('e2pdf_for_do_shortcode_data_process', false)) {
2482 + $value = serialize($raw_value); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
2483 + }
2484 + } elseif (false !== strpos($modifier, 'json')) {
2485 + $modifiers = explode(',', $modifier);
2486 + foreach ($modifiers as $filter) {
2487 + if ($filter == 'json') {
2488 + $value = '';
2489 + if (!empty($raw_value)) {
2490 + $json = @json_decode($raw_value, true); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
2491 + if (!empty($json)) {
2492 + if (is_array($json)) {
2493 + $value = serialize($json); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
2494 + } else {
2495 + $value = $json;
2496 + }
2497 + }
2498 + }
2499 + break;
2500 + }
2501 + }
1902 2502 }
1903 2503 }
1904 -
1905 2504 return $value;
1906 2505 }
1907 2506
1908 - /**
1909 - * Delete attachments that were sent by email
1910 - */
2507 + // delete attachments
1911 2508 public function action_gform_after_email($is_success) {
1912 2509
1913 2510 $files = $this->helper->get('gravity_attachments');
1914 2511 if (is_array($files) && !empty($files)) {
@@ -1918,28 +2515,208 @@
1918 2515 $this->helper->deset('gravity_attachments');
1919 2516 }
1920 2517 }
1921 2518
1922 - /**
1923 - * Get styles for generating Map Field function
1924 - *
1925 - * @return array - List of css files to load
1926 - */
1927 - public function styles() {
2519 + // after update entry action
2520 + public function action_gform_after_update_entry($form, $entry_id) {
2521 + if (isset($form['fields'])) {
2522 + foreach ($form['fields'] as $key => $field) {
2523 + if (isset($field->defaultValue) && (false !== strpos($field->defaultValue, '[e2pdf-download') || false !== strpos($field->defaultValue, '[e2pdf-save'))) {
2524 + $entry = GFFormsModel::get_entry($entry_id);
2525 + if ($entry && !is_wp_error($entry) && is_array($entry)) {
2526 + if (!rgar($entry, $field['id'])) {
2527 + $value = $this->filter_content($field->defaultValue, $entry_id, true);
2528 + $entry[$field['id']] = $value;
2529 + GFAPI::update_entry_field($entry['id'], $field['id'], $value);
2530 + }
2531 + }
2532 + }
2533 + }
2534 + }
2535 + }
2536 +
2537 + // styles
2538 + public function styles($item_id = false) {
1928 2539 $styles = array();
1929 -
1930 2540 if (class_exists('GFCommon') && class_exists('GFForms')) {
1931 2541 $base_url = GFCommon::get_base_url();
2542 + $base_path = GFCommon::get_base_path();
1932 2543 $version = GFForms::$version;
1933 2544 $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
1934 - $styles[] = $base_url . "/css/formreset{$min}.css?ver=" . $version;
1935 - $styles[] = $base_url . "/css/datepicker{$min}.css?ver=" . $version;
1936 - $styles[] = $base_url . "/css/formsmain{$min}.css?ver=" . $version;
1937 - $styles[] = $base_url . "/css/readyclass{$min}.css?ver=" . $version;
1938 - $styles[] = $base_url . "/css/browsers{$min}.css?ver=" . $version;
1939 - $styles[] = $base_url . "/css/rtl{$min}.css?ver=" . $version;
2545 + if (file_exists($base_path . '/legacy/css/')) {
2546 + $styles[] = $base_url . '/legacy/css/formreset' . $min . '.css?ver=' . $version;
2547 + $styles[] = $base_url . '/legacy/css/datepicker' . $min . '.css?ver=' . $version;
2548 + $styles[] = $base_url . '/legacy/css/formsmain' . $min . '.css?ver=' . $version;
2549 + $styles[] = $base_url . '/legacy/css/readyclass' . $min . '.css?ver=' . $version;
2550 + $styles[] = $base_url . '/legacy/css/browsers' . $min . '.css?ver=' . $version;
2551 + $styles[] = $base_url . '/legacy/css/rtl' . $min . '.css?ver=' . $version;
2552 + if (version_compare($version, '2.9', '>=')) {
2553 + $styles[] = $base_url . '/assets/css/dist/basic' . $min . '.css?ver=' . $version;
2554 + $styles[] = $base_url . '/assets/css/dist/gravity-forms-theme-reset' . $min . '.css?ver=' . $version;
2555 + $styles[] = $base_url . '/assets/css/dist/gravity-forms-theme-foundation' . $min . '.css?ver=' . $version;
2556 + $styles[] = $base_url . '/assets/css/dist/gravity-forms-theme-framework' . $min . '.css?ver=' . $version;
2557 + $styles[] = $base_url . '/assets/css/dist/gravity-forms-orbital-theme' . $min . '.css?ver=' . $version;
2558 + }
2559 + } else {
2560 + $styles[] = $base_url . '/css/formreset' . $min . '.css?ver=' . $version;
2561 + $styles[] = $base_url . '/css/datepicker' . $min . '.css?ver=' . $version;
2562 + $styles[] = $base_url . '/css/formsmain' . $min . '.css?ver=' . $version;
2563 + $styles[] = $base_url . '/css/readyclass' . $min . '.css?ver=' . $version;
2564 + $styles[] = $base_url . '/css/browsers' . $min . '.css?ver=' . $version;
2565 + $styles[] = $base_url . '/css/rtl' . $min . '.css?ver=' . $version;
2566 + }
2567 + $styles[] = plugins_url('css/extension/gravity.css?v=' . time(), $this->helper->get('plugin_file_path'));
1940 2568 }
2569 + return $styles;
2570 + }
1941 2571
1942 - return $styles;
2572 + public function hook_gravity_entry_view($metaboxes, $entry, $form) {
2573 + if (!empty($form['id'])) {
2574 + $hooks = $this->helper->load('hooks')->get('gravity', 'hook_gravity_entry_view', $form['id']);
2575 + if (!empty($hooks)) {
2576 + $metaboxes['e2pdf'] = array(
2577 + 'title' => apply_filters('e2pdf_hook_section_title', __('E2Pdf Actions', 'e2pdf'), 'hook_gravity_entry_view'),
2578 + 'callback' => array($this, 'hook_gravity_entry_view_callback'),
2579 + 'context' => 'side',
2580 + 'callback_args' => array(
2581 + 'entry' => $entry,
2582 + 'hooks' => $hooks,
2583 + ),
2584 + );
2585 + }
2586 + }
2587 + return $metaboxes;
1943 2588 }
1944 2589
2590 + // entry view callback hook
2591 + public function hook_gravity_entry_view_callback($post, $metabox) {
2592 + if (!empty($metabox['args']['entry']['id'])) {
2593 + foreach ($metabox['args']['hooks'] as $hook) {
2594 + if ($this->helper->load('hooks')->process_hook(
2595 + $hook,
2596 + [
2597 + 'dataset' => $metabox['args']['entry']['id'],
2598 + ],
2599 + 'hook_gravity_entry_view'
2600 + )
2601 + ) {
2602 + $action = apply_filters(
2603 + 'e2pdf_hook_action_button',
2604 + array(
2605 + '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>',
2606 + 'url' => $this->helper->get_url(
2607 + array(
2608 + 'page' => 'e2pdf',
2609 + 'action' => 'export',
2610 + 'id' => $hook,
2611 + 'dataset' => $metabox['args']['entry']['id'],
2612 + ), 'admin.php?'
2613 + ),
2614 + 'title' => 'PDF #' . $hook,
2615 + ), 'hook_gravity_entry_view', $hook, $metabox['args']['entry']['id']
2616 + );
2617 + if (!empty($action)) {
2618 + echo sprintf(
2619 + $action['html'], $action['url'], $action['title']
2620 + );
2621 + }
2622 + }
2623 + }
2624 + }
2625 + }
2626 +
2627 + // row actions hook
2628 + public function hook_gravity_row_actions($form_id, $field_id, $value, $entry) {
2629 + if (!empty($entry['form_id']) && !empty($entry['id'])) {
2630 + $hooks = $this->helper->load('hooks')->get('gravity', 'hook_gravity_row_actions', $entry['form_id']);
2631 + foreach ($hooks as $hook) {
2632 + if ($this->helper->load('hooks')->process_hook(
2633 + $hook,
2634 + [
2635 + 'dataset' => $entry['id'],
2636 + ],
2637 + 'hook_gravity_row_actions'
2638 + )
2639 + ) {
2640 + $action = apply_filters(
2641 + 'e2pdf_hook_action_button',
2642 + array(
2643 + 'html' => '<span> | <a class="e2pdf-download-hook" target="_blank" href="%s">%s</a></span>',
2644 + 'url' => $this->helper->get_url(
2645 + array(
2646 + 'page' => 'e2pdf',
2647 + 'action' => 'export',
2648 + 'id' => $hook,
2649 + 'dataset' => $entry['id'],
2650 + ), 'admin.php?'
2651 + ),
2652 + 'title' => 'PDF #' . $hook,
2653 + ), 'hook_gravity_row_actions', $hook, $entry['id']
2654 + );
2655 + if (!empty($action)) {
2656 + echo sprintf(
2657 + $action['html'], $action['url'], $action['title']
2658 + );
2659 + }
2660 + }
2661 + }
2662 + }
2663 + }
2664 +
2665 + // get field merge tags
2666 + public function get_field_merge_tags($merged_tags, $field, $repeater = null, $repeaters = array()) {
2667 + $tags = GFCommon::get_field_merge_tags($field);
2668 + foreach ($tags as $tag) {
2669 + if (isset($tag['tag'])) {
2670 + if ($field->type == 'list') {
2671 + $field_id = preg_replace('/\{(?:.*)\:(.*)\:\}/', '${1}', $tag['tag']);
2672 + } else {
2673 + $field_id = preg_replace('/\{(?:.*)\:(.*)\}/', '${1}', $tag['tag']);
2674 + }
2675 + if ($field_id) {
2676 + if ($this->get('nested')) {
2677 + $merged_tags[$field_id] = $this->get('nested');
2678 + } elseif ($field->type == 'repeater') {
2679 + $merged_tags[$field_id] = $tag['tag'];
2680 + if (!empty($field->fields)) {
2681 + foreach ($field->fields as $sub_field) {
2682 + $sub_value = isset($sub_field->label) ? $sub_field->label : '';
2683 + if ($repeater) {
2684 + $sub_value .= isset($repeater->id) ? ':' . $repeater->id : '';
2685 + } else {
2686 + $sub_value .= isset($field->id) ? ':' . $field->id : '';
2687 + }
2688 + if ($sub_value) {
2689 + $merged_tags[$sub_field->id] = '{' . $sub_value . ':repeater' . (!empty($repeaters) ? '.0.' . implode('.0', $repeaters) : '') . '.0.' . $sub_field->id . '}';
2690 + }
2691 + if (isset($sub_field->type) && $sub_field->type == 'repeater') {
2692 + if (isset($sub_field->id)) {
2693 + $repeaters[] = $sub_field->id;
2694 + if ($repeater) {
2695 + $merged_tags = $this->get_field_merge_tags($merged_tags, $sub_field, $repeater, $repeaters);
2696 + } else {
2697 + $merged_tags = $this->get_field_merge_tags($merged_tags, $sub_field, $field, $repeaters);
2698 + }
2699 + }
2700 + }
2701 + }
2702 + }
2703 + } else {
2704 + $merged_tags[$field_id] = $tag['tag'];
2705 + }
2706 + }
2707 + }
2708 + }
2709 + return $merged_tags;
2710 + }
2711 +
2712 + // get form fields
2713 + public function get_form_fields($form_fields, $fields) {
2714 + foreach ($fields as $field) {
2715 + $form_fields[$field->id] = $field;
2716 + if (!empty($field->fields)) {
2717 + $form_fields = $this->get_form_fields($form_fields, $field->fields);
2718 + }
2719 + }
2720 + return $form_fields;
2721 + }
1945 2722 }