| @@ -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,475 +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 (isset($field['properties']['preg_pattern']) && $field['properties']['preg_pattern'] && isset($field['properties']['preg_replacement']) && $value) { | |
| 378 | - $value = $this->helper->load('convert')->preg_replace($field['properties']['preg_pattern'], $field['properties']['preg_replacement'], $value); | |
| 379 | - } | |
| 380 | - | |
| 381 | - if (!$this->helper->load('image')->get_image($value)) { | |
| 382 | - $value = $this->strip_shortcodes($value); | |
| 383 | - if ( | |
| 384 | - $value && | |
| 385 | - trim($value) != "" && | |
| 386 | - extension_loaded('gd') && | |
| 387 | - function_exists('imagettftext') | |
| 388 | - ) { | |
| 389 | - if (isset($field['properties']['text_color']) && $field['properties']['text_color']) { | |
| 390 | - $penColour = $this->helper->load('convert')->to_hex_color($field['properties']['text_color']); | |
| 391 | - } else { | |
| 392 | - $penColour = array(0x14, 0x53, 0x94); | |
| 393 | - } | |
| 394 | - | |
| 395 | - $default_options = array( | |
| 396 | - 'imageSize' => array(isset($field['width']) ? $field['width'] : '400', isset($field['height']) ? $field['height'] : '150'), | |
| 397 | - 'bgColour' => 'transparent', | |
| 398 | - 'penColour' => $penColour | |
| 399 | - ); | |
| 400 | - | |
| 401 | - $options = array(); | |
| 402 | - $options = apply_filters('e2pdf_image_sig_output_options', $options, $element_id, $template_id); | |
| 403 | - $options = array_merge($default_options, $options); | |
| 404 | - | |
| 405 | - $model_e2pdf_font = new Model_E2pdf_Font(); | |
| 406 | - | |
| 407 | - $font = false; | |
| 408 | - if (isset($field['properties']['text_font']) && $field['properties']['text_font']) { | |
| 409 | - $font = $model_e2pdf_font->get_font_path($field['properties']['text_font']); | |
| 410 | - } | |
| 411 | - | |
| 412 | - if (!$font) { | |
| 413 | - $font = $model_e2pdf_font->get_font_path('Noto Sans'); | |
| 414 | - } | |
| 415 | - | |
| 416 | - $size = 150; | |
| 417 | - if (isset($field['properties']['text_font_size']) && $field['properties']['text_font_size']) { | |
| 418 | - $size = $field['properties']['text_font_size']; | |
| 419 | - } | |
| 420 | - | |
| 421 | - $model_e2pdf_signature = new Model_E2pdf_Signature(); | |
| 422 | - $value = $model_e2pdf_signature->ttf_signature($value, $size, $font, $options); | |
| 423 | - } else { | |
| 424 | - $value = ""; | |
| 425 | - } | |
| 426 | - } | |
| 427 | - } | |
| 428 | - } else { | |
| 429 | - | |
| 430 | - $value = $this->convert_shortcodes($value); | |
| 431 | - | |
| 432 | - if (isset($field['properties']['preg_pattern']) && $field['properties']['preg_pattern'] && isset($field['properties']['preg_replacement']) && $value) { | |
| 433 | - $value = $this->helper->load('convert')->preg_replace($field['properties']['preg_pattern'], $field['properties']['preg_replacement'], $value); | |
| 434 | - } | |
| 237 | + $value = $this->helper->load('field')->do_shortcodes($value, $this, $field); | |
| 238 | + if ($gv_request !== false) { | |
| 239 | + gravityview()->request = $gv_request; | |
| 435 | 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 | + ); | |
| 436 | 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 | + } | |
| 437 | 260 | |
| 438 | - $value = apply_filters('e2pdf_extension_render_shortcodes_value', $value, $element_id, $template_id, $item, $dataset); | |
| 439 | - | |
| 261 | + // strip shortcodes | |
| 262 | + public function strip_shortcodes($value) { | |
| 263 | + $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', '', $value); | |
| 264 | + $value = preg_replace('~a\:\d+\:{[^}]*}(*SKIP)(*FAIL)|{[^}]*}~', '', $value); | |
| 440 | 265 | return $value; |
| 441 | 266 | } |
| 442 | 267 | |
| 443 | - /** | |
| 444 | - * Strip unused shortcodes | |
| 445 | - * | |
| 446 | - * @param string $value - Content | |
| 447 | - * | |
| 448 | - * @return string - Value with removed unused shortcodes | |
| 449 | - */ | |
| 450 | - public function strip_shortcodes($value) { | |
| 451 | - $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', "", $value); | |
| 452 | - $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 | + } | |
| 453 | 278 | return $value; |
| 454 | 279 | } |
| 455 | 280 | |
| 456 | - /** | |
| 457 | - * Convert "shortcodes" inside value string | |
| 458 | - * | |
| 459 | - * @param string $value - Value string | |
| 460 | - * @param bool $to - Convert From/To | |
| 461 | - * | |
| 462 | - * @return string - Converted value | |
| 463 | - */ | |
| 464 | - public function convert_shortcodes($value, $to = false) { | |
| 281 | + // convert shortcodes | |
| 282 | + public function convert_shortcodes($value, $to = false, $html = false) { | |
| 465 | 283 | if ($value) { |
| 466 | 284 | if ($to) { |
| 467 | - $value = str_replace('[', '[', $value); | |
| 468 | - $value = str_replace(']', ']', $value); | |
| 285 | + $search = array('[', ']', '[', ']'); | |
| 286 | + $replace = array('[', ']', '[', ']'); | |
| 287 | + $value = str_replace($search, $replace, $value); | |
| 288 | + if (!$html) { | |
| 289 | + $value = wp_specialchars_decode($value, ENT_QUOTES); | |
| 290 | + } | |
| 469 | 291 | } else { |
| 470 | - $value = str_replace('[', '[', $value); | |
| 471 | - $value = str_replace(']', ']', $value); | |
| 472 | - $value = str_replace('[', '[', $value); | |
| 473 | - $value = str_replace(']', ']', $value); | |
| 292 | + $search = array('[', ']', '[', ']'); | |
| 293 | + $replace = array('[', ']', '[', ']'); | |
| 294 | + $value = str_replace($search, $replace, $value); | |
| 474 | 295 | } |
| 475 | 296 | } |
| 476 | 297 | return $value; |
| 477 | 298 | } |
| 478 | 299 | |
| 479 | - /** | |
| 480 | - * Auto Generate of Template for this extension | |
| 481 | - * | |
| 482 | - * @return array - List of elements | |
| 483 | - */ | |
| 300 | + // auto | |
| 484 | 301 | public function auto() { |
| 485 | - | |
| 486 | 302 | $item = $this->get('item'); |
| 487 | - | |
| 488 | 303 | $response = array(); |
| 489 | 304 | $elements = array(); |
| 490 | 305 | $merged_tags = array(); |
| 491 | 306 | $form = false; |
| @@ -492,57 +307,108 @@ | ||
| 492 | 307 | |
| 493 | 308 | if (class_exists('GFFormsModel')) { |
| 494 | 309 | $form = GFFormsModel::get_form_meta($item); |
| 495 | 310 | } |
| 496 | - | |
| 497 | 311 | if ($form) { |
| 498 | 312 | if (class_exists('GFCommon')) { |
| 499 | 313 | foreach ($form['fields'] as $field) { |
| 500 | - $tags = GFCommon::get_field_merge_tags($field); | |
| 501 | - foreach ($tags as $tag) { | |
| 502 | - if (isset($tag['tag'])) { | |
| 503 | - if ($field->type == 'list') { | |
| 504 | - $field_id = preg_replace('/\{(?:.*)\:(.*)\:\}/', '${1}', $tag['tag']); | |
| 505 | - } else { | |
| 506 | - $field_id = preg_replace('/\{(?:.*)\:(.*)\}/', '${1}', $tag['tag']); | |
| 507 | - } | |
| 508 | - if ($field_id) { | |
| 509 | - $merged_tags[$field_id] = $tag['tag']; | |
| 510 | - } | |
| 511 | - } | |
| 512 | - } | |
| 314 | + $merged_tags = $this->get_field_merge_tags($merged_tags, $field); | |
| 513 | 315 | } |
| 514 | 316 | } |
| 515 | - | |
| 516 | 317 | foreach ($form['fields'] as $field) { |
| 517 | - 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') { | |
| 518 | 322 | if ($field->inputType == 'select') { |
| 519 | 323 | $field->type = 'select'; |
| 520 | 324 | } elseif ($field->inputType == 'radio') { |
| 521 | 325 | $field->type = 'radio'; |
| 326 | + } elseif ($field->inputType == 'checkbox') { | |
| 327 | + $field->type = 'checkbox'; | |
| 522 | 328 | } elseif ($field->inputType == 'price') { |
| 523 | 329 | $field->type = 'text'; |
| 524 | 330 | } |
| 525 | 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 | + } | |
| 526 | 373 | |
| 527 | - switch ($field->type) { | |
| 528 | - case 'text': | |
| 529 | - case 'number': | |
| 530 | - case 'date': | |
| 531 | - case 'time': | |
| 532 | - case 'phone': | |
| 533 | - case 'website': | |
| 534 | - case 'email': | |
| 535 | - case 'fileupload': | |
| 536 | - case 'post_title': | |
| 537 | - case 'post_excerpt': | |
| 538 | - case 'post_tags': | |
| 539 | - case 'post_custom_field': | |
| 540 | - case 'quantity': | |
| 541 | - case 'shipping': | |
| 542 | - case 'total': | |
| 543 | - $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : ''; | |
| 544 | - $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( | |
| 545 | 411 | 'type' => 'e2pdf-html', |
| 546 | 412 | 'block' => true, |
| 547 | 413 | 'properties' => array( |
| 548 | 414 | 'top' => '20', |
| @@ -550,13 +416,16 @@ | ||
| 550 | 416 | 'right' => '20', |
| 551 | 417 | 'width' => '100%', |
| 552 | 418 | 'height' => 'auto', |
| 553 | 419 | 'value' => $field->label, |
| 554 | - 'pass' => $field->enablePasswordInput ? '1' : '0' | |
| 555 | - ) | |
| 556 | - )); | |
| 420 | + 'pass' => $field->enablePasswordInput ? '1' : '0', | |
| 421 | + ), | |
| 422 | + ) | |
| 423 | + ); | |
| 557 | 424 | |
| 558 | - $elements[] = $this->auto_field($field, array( | |
| 425 | + $elements[] = $this->auto_field( | |
| 426 | + $field, | |
| 427 | + array( | |
| 559 | 428 | 'type' => 'e2pdf-input', |
| 560 | 429 | 'properties' => array( |
| 561 | 430 | 'top' => '5', |
| 562 | 431 | 'width' => '100%', |
| @@ -561,13 +430,16 @@ | ||
| 561 | 430 | 'top' => '5', |
| 562 | 431 | 'width' => '100%', |
| 563 | 432 | 'height' => 'auto', |
| 564 | 433 | 'value' => $value, |
| 565 | - ) | |
| 566 | - )); | |
| 567 | - break; | |
| 568 | - case 'list': | |
| 569 | - $elements[] = $this->auto_field($field, array( | |
| 434 | + ), | |
| 435 | + ) | |
| 436 | + ); | |
| 437 | + break; | |
| 438 | + case 'list': | |
| 439 | + $elements[] = $this->auto_field( | |
| 440 | + $field, | |
| 441 | + array( | |
| 570 | 442 | 'type' => 'e2pdf-html', |
| 571 | 443 | 'block' => true, |
| 572 | 444 | 'properties' => array( |
| 573 | 445 | 'top' => '20', |
| @@ -575,28 +447,34 @@ | ||
| 575 | 447 | 'right' => '20', |
| 576 | 448 | 'width' => '100%', |
| 577 | 449 | 'height' => 'auto', |
| 578 | 450 | 'value' => $field->label, |
| 579 | - ) | |
| 580 | - )); | |
| 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] : ''; | |
| 581 | 459 | |
| 582 | - 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 | + } | |
| 583 | 469 | |
| 584 | - $width = number_format(floor((100 / count($field->choices)) * 100) / 100, 2); | |
| 585 | - | |
| 586 | - foreach ($field->choices as $key => $choice) { | |
| 587 | - | |
| 588 | - $field_id = (int) $key + 1; | |
| 589 | - $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : ''; | |
| 590 | - if (substr($value, -1) == '}') { | |
| 591 | - $value = substr($value, 0, -1) . '1_' . $field_id . '}'; | |
| 592 | - } | |
| 593 | - | |
| 594 | - $float = true; | |
| 595 | - if ($key == '0') { | |
| 596 | - $float = false; | |
| 597 | - } | |
| 598 | - $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( | |
| 599 | 477 | 'type' => 'e2pdf-html', |
| 600 | 478 | 'block' => true, |
| 601 | 479 | 'float' => $float, |
| 602 | 480 | 'properties' => array( |
| @@ -605,12 +483,14 @@ | ||
| 605 | 483 | 'right' => '20', |
| 606 | 484 | 'width' => $width . '%', |
| 607 | 485 | 'height' => 'auto', |
| 608 | 486 | 'value' => $choice['text'], |
| 609 | - ) | |
| 610 | - )); | |
| 611 | - | |
| 612 | - $elements[] = $this->auto_field($field, array( | |
| 487 | + ), | |
| 488 | + ) | |
| 489 | + ); | |
| 490 | + $elements[] = $this->auto_field( | |
| 491 | + $field, | |
| 492 | + array( | |
| 613 | 493 | 'type' => 'e2pdf-input', |
| 614 | 494 | 'properties' => array( |
| 615 | 495 | 'top' => '5', |
| 616 | 496 | 'width' => '100%', |
| @@ -615,18 +495,26 @@ | ||
| 615 | 495 | 'top' => '5', |
| 616 | 496 | 'width' => '100%', |
| 617 | 497 | 'height' => 'auto', |
| 618 | 498 | 'value' => $value, |
| 619 | - ) | |
| 620 | - )); | |
| 621 | - } | |
| 622 | - } else { | |
| 623 | - $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : ''; | |
| 624 | - if (substr($value, -1) == '}') { | |
| 625 | - $value = substr($value, 0, -1) . '1}'; | |
| 626 | - } | |
| 627 | - | |
| 628 | - $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( | |
| 629 | 517 | 'type' => 'e2pdf-input', |
| 630 | 518 | 'properties' => array( |
| 631 | 519 | 'top' => '5', |
| 632 | 520 | 'width' => '100%', |
| @@ -631,15 +519,25 @@ | ||
| 631 | 519 | 'top' => '5', |
| 632 | 520 | 'width' => '100%', |
| 633 | 521 | 'height' => 'auto', |
| 634 | 522 | 'value' => $value, |
| 635 | - ) | |
| 636 | - )); | |
| 637 | - } | |
| 638 | - break; | |
| 639 | - case 'textarea': | |
| 640 | - case 'post_content': | |
| 641 | - $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( | |
| 642 | 540 | 'type' => 'e2pdf-html', |
| 643 | 541 | 'block' => true, |
| 644 | 542 | 'properties' => array( |
| 645 | 543 | 'top' => '20', |
| @@ -647,26 +545,31 @@ | ||
| 647 | 545 | 'right' => '20', |
| 648 | 546 | 'width' => '100%', |
| 649 | 547 | 'height' => 'auto', |
| 650 | 548 | 'value' => $field->label, |
| 651 | - ) | |
| 652 | - )); | |
| 653 | - | |
| 654 | - $elements[] = $this->auto_field($field, array( | |
| 549 | + ), | |
| 550 | + ) | |
| 551 | + ); | |
| 552 | + $elements[] = $this->auto_field( | |
| 553 | + $field, | |
| 554 | + array( | |
| 655 | 555 | 'type' => 'e2pdf-textarea', |
| 656 | 556 | 'properties' => array( |
| 657 | 557 | 'top' => '5', |
| 658 | 558 | 'width' => '100%', |
| 659 | 559 | 'height' => 'auto', |
| 660 | - 'value' => isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '', | |
| 661 | - ) | |
| 662 | - )); | |
| 663 | - break; | |
| 664 | - case 'select': | |
| 665 | - case 'multiselect': | |
| 666 | - case 'post_category': | |
| 667 | - case 'option': | |
| 668 | - $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( | |
| 669 | 572 | 'type' => 'e2pdf-html', |
| 670 | 573 | 'block' => true, |
| 671 | 574 | 'properties' => array( |
| 672 | 575 | 'top' => '20', |
| @@ -674,26 +577,38 @@ | ||
| 674 | 577 | 'right' => '20', |
| 675 | 578 | 'width' => '100%', |
| 676 | 579 | 'height' => 'auto', |
| 677 | 580 | 'value' => $field->label, |
| 678 | - ) | |
| 679 | - )); | |
| 680 | - | |
| 681 | - $options_tmp = array(); | |
| 682 | - if (isset($field->choices) && is_array($field->choices)) { | |
| 683 | - foreach ($field->choices as $opt_key => $option) { | |
| 684 | - $options_tmp[] = isset($option['value']) ? $option['value'] : ''; | |
| 685 | - } | |
| 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]}'; | |
| 686 | 595 | } |
| 687 | - | |
| 688 | - $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : ''; | |
| 689 | - if ($field->enableChoiceValue && $value) { | |
| 690 | - if (substr($value, -1) == '}') { | |
| 691 | - $value = substr($value, 0, -1) . ':value}'; | |
| 692 | - } | |
| 596 | + } else { | |
| 597 | + if (substr($value, -1) == '}') { | |
| 598 | + $value = substr($value, 0, -1) . ':filter[' . $field->id . '],index[0]}'; | |
| 693 | 599 | } |
| 694 | - | |
| 695 | - $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( | |
| 696 | 611 | 'type' => 'e2pdf-select', |
| 697 | 612 | 'properties' => array( |
| 698 | 613 | 'top' => '5', |
| 699 | 614 | 'width' => '100%', |
| @@ -701,13 +616,16 @@ | ||
| 701 | 616 | 'options' => implode("\n", $options_tmp), |
| 702 | 617 | 'value' => $value, |
| 703 | 618 | 'height' => $field->type == 'multiselect' ? '80' : 'auto', |
| 704 | 619 | 'multiline' => $field->type == 'multiselect' ? '1' : '0', |
| 705 | - ) | |
| 706 | - )); | |
| 707 | - break; | |
| 708 | - case 'checkbox': | |
| 709 | - $elements[] = $this->auto_field($field, array( | |
| 620 | + ), | |
| 621 | + ) | |
| 622 | + ); | |
| 623 | + break; | |
| 624 | + case 'checkbox': | |
| 625 | + $elements[] = $this->auto_field( | |
| 626 | + $field, | |
| 627 | + array( | |
| 710 | 628 | 'type' => 'e2pdf-html', |
| 711 | 629 | 'block' => true, |
| 712 | 630 | 'properties' => array( |
| 713 | 631 | 'top' => '20', |
| @@ -715,22 +633,35 @@ | ||
| 715 | 633 | 'right' => '20', |
| 716 | 634 | 'width' => '100%', |
| 717 | 635 | 'height' => 'auto', |
| 718 | 636 | 'value' => $field->label, |
| 719 | - ) | |
| 720 | - )); | |
| 637 | + ), | |
| 638 | + ) | |
| 639 | + ); | |
| 721 | 640 | |
| 722 | - if (isset($field->choices) && is_array($field->choices)) { | |
| 723 | - | |
| 724 | - $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : ''; | |
| 725 | - if ($field->enableChoiceValue && $value) { | |
| 726 | - if (substr($value, -1) == '}') { | |
| 727 | - $value = substr($value, 0, -1) . ':value}'; | |
| 728 | - } | |
| 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]}'; | |
| 729 | 647 | } |
| 730 | - | |
| 731 | - foreach ($field->choices as $opt_key => $option) { | |
| 732 | - $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( | |
| 733 | 664 | 'type' => 'e2pdf-checkbox', |
| 734 | 665 | 'properties' => array( |
| 735 | 666 | 'top' => '5', |
| 736 | 667 | 'width' => 'auto', |
| @@ -735,12 +666,15 @@ | ||
| 735 | 666 | 'top' => '5', |
| 736 | 667 | 'width' => 'auto', |
| 737 | 668 | 'height' => 'auto', |
| 738 | 669 | 'value' => $value, |
| 739 | - 'option' => isset($option['value']) ? $option['value'] : '' | |
| 740 | - ) | |
| 741 | - )); | |
| 742 | - $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( | |
| 743 | 677 | 'type' => 'e2pdf-html', |
| 744 | 678 | 'float' => true, |
| 745 | 679 | 'properties' => array( |
| 746 | 680 | 'left' => '5', |
| @@ -745,16 +679,19 @@ | ||
| 745 | 679 | 'properties' => array( |
| 746 | 680 | 'left' => '5', |
| 747 | 681 | 'width' => '100%', |
| 748 | 682 | 'height' => 'auto', |
| 749 | - 'value' => isset($option['text']) ? $option['text'] : '' | |
| 750 | - ) | |
| 751 | - )); | |
| 752 | - } | |
| 753 | - } | |
| 754 | - break; | |
| 755 | - case 'radio': | |
| 756 | - $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( | |
| 757 | 694 | 'type' => 'e2pdf-html', |
| 758 | 695 | 'block' => true, |
| 759 | 696 | 'properties' => array( |
| 760 | 697 | 'top' => '20', |
| @@ -762,22 +699,48 @@ | ||
| 762 | 699 | 'right' => '20', |
| 763 | 700 | 'width' => '100%', |
| 764 | 701 | 'height' => 'auto', |
| 765 | 702 | 'value' => $field->label, |
| 766 | - ) | |
| 767 | - )); | |
| 703 | + ), | |
| 704 | + ) | |
| 705 | + ); | |
| 768 | 706 | |
| 769 | - 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 | + } | |
| 770 | 726 | |
| 771 | - $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']] : ''; | |
| 772 | 731 | if ($field->enableChoiceValue && $value) { |
| 773 | 732 | if (substr($value, -1) == '}') { |
| 774 | - $value = substr($value, 0, -1) . ':value}'; | |
| 733 | + $value = substr($value, 0, -1) . (substr_count($value, ':') >= 2 ? ',value' : ':value') . '}'; | |
| 775 | 734 | } |
| 776 | 735 | } |
| 777 | - | |
| 778 | - foreach ($field->choices as $opt_key => $option) { | |
| 779 | - $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( | |
| 780 | 743 | 'type' => 'e2pdf-radio', |
| 781 | 744 | 'properties' => array( |
| 782 | 745 | 'top' => '5', |
| 783 | 746 | 'width' => 'auto', |
| @@ -783,12 +746,15 @@ | ||
| 783 | 746 | 'width' => 'auto', |
| 784 | 747 | 'height' => 'auto', |
| 785 | 748 | 'value' => $value, |
| 786 | 749 | 'option' => isset($option['value']) ? $option['value'] : '', |
| 787 | - 'group' => $value | |
| 788 | - ) | |
| 789 | - )); | |
| 790 | - $elements[] = $this->auto_field($field, array( | |
| 750 | + 'group' => $value, | |
| 751 | + ), | |
| 752 | + ) | |
| 753 | + ); | |
| 754 | + $elements[] = $this->auto_field( | |
| 755 | + $field, | |
| 756 | + array( | |
| 791 | 757 | 'type' => 'e2pdf-html', |
| 792 | 758 | 'float' => true, |
| 793 | 759 | 'properties' => array( |
| 794 | 760 | 'left' => '5', |
| @@ -793,31 +759,104 @@ | ||
| 793 | 759 | 'properties' => array( |
| 794 | 760 | 'left' => '5', |
| 795 | 761 | 'width' => '100%', |
| 796 | 762 | 'height' => 'auto', |
| 797 | - 'value' => isset($option['text']) ? $option['text'] : '' | |
| 798 | - ) | |
| 799 | - )); | |
| 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 | + ); | |
| 800 | 787 | } |
| 801 | - } | |
| 802 | - break; | |
| 803 | - case 'name': | |
| 804 | - foreach ($field['inputs'] as $key => $input) { | |
| 805 | - if (isset($input->isHidden) && $input->isHidden) { | |
| 806 | - unset($field['inputs'][$key]); | |
| 807 | - } | |
| 808 | - } | |
| 809 | 788 | |
| 810 | - $width = '100%'; | |
| 811 | - if (count($field['inputs']) == '3') { | |
| 812 | - $width = '33.3%'; | |
| 813 | - } else { | |
| 814 | - $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 | + ); | |
| 815 | 810 | } |
| 816 | - | |
| 817 | - foreach ($field['inputs'] as $key => $sub_field) { | |
| 818 | - | |
| 819 | - $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( | |
| 820 | 859 | 'type' => 'e2pdf-html', |
| 821 | 860 | 'block' => true, |
| 822 | 861 | 'float' => $key == '0' ? false : true, |
| 823 | 862 | 'properties' => array( |
| @@ -826,19 +865,27 @@ | ||
| 826 | 865 | 'right' => '20', |
| 827 | 866 | 'width' => $width, |
| 828 | 867 | 'height' => 'auto', |
| 829 | 868 | 'value' => isset($sub_field['label']) && $sub_field['label'] ? $sub_field['label'] : '', |
| 830 | - ) | |
| 831 | - )); | |
| 869 | + ), | |
| 870 | + ) | |
| 871 | + ); | |
| 832 | 872 | |
| 833 | - 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 | + } | |
| 834 | 879 | |
| 835 | - $options_tmp = array(); | |
| 836 | - foreach ($sub_field['choices'] as $opt_key => $option) { | |
| 837 | - $options_tmp[] = isset($option['value']) ? $option['value'] : ''; | |
| 838 | - } | |
| 839 | - | |
| 840 | - $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( | |
| 841 | 888 | 'type' => 'e2pdf-select', |
| 842 | 889 | 'properties' => array( |
| 843 | 890 | 'top' => '5', |
| 844 | 891 | 'width' => '100%', |
| @@ -843,34 +890,44 @@ | ||
| 843 | 890 | 'top' => '5', |
| 844 | 891 | 'width' => '100%', |
| 845 | 892 | 'height' => 'auto', |
| 846 | 893 | 'options' => implode("\n", $options_tmp), |
| 847 | - 'value' => isset($merged_tags[$sub_field['id']]) ? $merged_tags[$sub_field['id']] : '', | |
| 894 | + 'value' => $value, | |
| 848 | 895 | 'height' => 'auto', |
| 849 | 896 | 'multiline' => '0', |
| 850 | - ) | |
| 851 | - )); | |
| 852 | - } else { | |
| 853 | - $elements[] = $this->auto_field($sub_field, array( | |
| 897 | + ), | |
| 898 | + ) | |
| 899 | + ); | |
| 900 | + } else { | |
| 901 | + $elements[] = $this->auto_field( | |
| 902 | + $sub_field, | |
| 903 | + array( | |
| 854 | 904 | 'type' => 'e2pdf-input', |
| 855 | 905 | 'properties' => array( |
| 856 | 906 | 'top' => '5', |
| 857 | 907 | 'width' => '100%', |
| 858 | 908 | 'height' => 'auto', |
| 859 | - 'value' => isset($merged_tags[$sub_field['id']]) ? $merged_tags[$sub_field['id']] : '', | |
| 860 | - ) | |
| 861 | - )); | |
| 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]}'; | |
| 862 | 925 | } |
| 863 | 926 | } |
| 864 | - break; | |
| 865 | - case 'address': | |
| 866 | - $index = 0; | |
| 867 | - foreach ($field['inputs'] as $key => $sub_field) { | |
| 868 | - | |
| 869 | - if (isset($sub_field['isHidden']) && $sub_field['isHidden']) { | |
| 870 | - | |
| 871 | - } else { | |
| 872 | - $elements[] = $this->auto_field($sub_field, array( | |
| 927 | + $elements[] = $this->auto_field( | |
| 928 | + $sub_field, | |
| 929 | + array( | |
| 873 | 930 | 'type' => 'e2pdf-html', |
| 874 | 931 | 'block' => true, |
| 875 | 932 | 'float' => $index == '0' ? false : true, |
| 876 | 933 | 'properties' => array( |
| @@ -879,26 +936,31 @@ | ||
| 879 | 936 | 'right' => '20', |
| 880 | 937 | 'width' => $key == '0' || $key == '1' ? '100%' : '50%', |
| 881 | 938 | 'height' => 'auto', |
| 882 | 939 | 'value' => isset($sub_field['label']) && $sub_field['label'] ? $sub_field['label'] : '', |
| 883 | - ) | |
| 884 | - )); | |
| 885 | - | |
| 886 | - $elements[] = $this->auto_field($sub_field, array( | |
| 940 | + ), | |
| 941 | + ) | |
| 942 | + ); | |
| 943 | + $elements[] = $this->auto_field( | |
| 944 | + $sub_field, | |
| 945 | + array( | |
| 887 | 946 | 'type' => 'e2pdf-input', |
| 888 | 947 | 'properties' => array( |
| 889 | 948 | 'top' => '5', |
| 890 | 949 | 'width' => '100%', |
| 891 | 950 | 'height' => 'auto', |
| 892 | - 'value' => isset($merged_tags[$sub_field['id']]) ? $merged_tags[$sub_field['id']] : '', | |
| 893 | - ) | |
| 894 | - )); | |
| 895 | - $index++; | |
| 896 | - } | |
| 897 | - } | |
| 898 | - break; | |
| 899 | - case 'consent': | |
| 900 | - $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( | |
| 901 | 963 | 'type' => 'e2pdf-html', |
| 902 | 964 | 'block' => true, |
| 903 | 965 | 'properties' => array( |
| 904 | 966 | 'top' => '20', |
| @@ -906,22 +968,33 @@ | ||
| 906 | 968 | 'right' => '20', |
| 907 | 969 | 'width' => '100%', |
| 908 | 970 | 'height' => 'auto', |
| 909 | 971 | 'value' => $field->label, |
| 910 | - ) | |
| 911 | - )); | |
| 912 | - | |
| 913 | - $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( | |
| 914 | 984 | 'type' => 'e2pdf-checkbox', |
| 915 | 985 | 'properties' => array( |
| 916 | 986 | 'top' => '5', |
| 917 | 987 | 'width' => 'auto', |
| 918 | 988 | 'height' => 'auto', |
| 919 | - 'value' => isset($merged_tags[$field->id . '.1']) ? $merged_tags[$field->id . '.1'] : '', | |
| 920 | - 'option' => '1' | |
| 921 | - ) | |
| 922 | - )); | |
| 923 | - $elements[] = $this->auto_field($field, array( | |
| 989 | + 'value' => $value, | |
| 990 | + 'option' => '1', | |
| 991 | + ), | |
| 992 | + ) | |
| 993 | + ); | |
| 994 | + $elements[] = $this->auto_field( | |
| 995 | + $field, | |
| 996 | + array( | |
| 924 | 997 | 'type' => 'e2pdf-html', |
| 925 | 998 | 'float' => true, |
| 926 | 999 | 'properties' => array( |
| 927 | 1000 | 'left' => '5', |
| @@ -926,17 +999,23 @@ | ||
| 926 | 999 | 'properties' => array( |
| 927 | 1000 | 'left' => '5', |
| 928 | 1001 | 'width' => '100%', |
| 929 | 1002 | 'height' => 'auto', |
| 930 | - 'value' => $field->checkboxLabel | |
| 931 | - ) | |
| 932 | - )); | |
| 933 | - break; | |
| 934 | - case 'post_image': | |
| 935 | - | |
| 936 | - $value = isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : ''; | |
| 937 | - | |
| 938 | - $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( | |
| 939 | 1018 | 'type' => 'e2pdf-html', |
| 940 | 1019 | 'block' => true, |
| 941 | 1020 | 'properties' => array( |
| 942 | 1021 | 'top' => '20', |
| @@ -944,12 +1023,14 @@ | ||
| 944 | 1023 | 'right' => '20', |
| 945 | 1024 | 'width' => '100%', |
| 946 | 1025 | 'height' => 'auto', |
| 947 | 1026 | 'value' => $field->label, |
| 948 | - ) | |
| 949 | - )); | |
| 950 | - | |
| 951 | - $elements[] = $this->auto_field($field, array( | |
| 1027 | + ), | |
| 1028 | + ) | |
| 1029 | + ); | |
| 1030 | + $elements[] = $this->auto_field( | |
| 1031 | + $field, | |
| 1032 | + array( | |
| 952 | 1033 | 'type' => 'e2pdf-image', |
| 953 | 1034 | 'properties' => array( |
| 954 | 1035 | 'top' => '5', |
| 955 | 1036 | 'width' => '100', |
| @@ -954,15 +1035,26 @@ | ||
| 954 | 1035 | 'top' => '5', |
| 955 | 1036 | 'width' => '100', |
| 956 | 1037 | 'height' => '100', |
| 957 | 1038 | 'value' => $value, |
| 958 | - 'dimension' => '1' | |
| 959 | - ) | |
| 960 | - )); | |
| 961 | - | |
| 962 | - if ($field->displayTitle) { | |
| 963 | - | |
| 964 | - $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( | |
| 965 | 1057 | 'type' => 'e2pdf-html', |
| 966 | 1058 | 'block' => true, |
| 967 | 1059 | 'properties' => array( |
| 968 | 1060 | 'top' => '20', |
| @@ -970,25 +1062,39 @@ | ||
| 970 | 1062 | 'right' => '20', |
| 971 | 1063 | 'width' => '100%', |
| 972 | 1064 | 'height' => 'auto', |
| 973 | 1065 | 'value' => __('Title', 'gravityforms'), |
| 974 | - ) | |
| 975 | - )); | |
| 976 | - | |
| 977 | - $elements[] = $this->auto_field($field, array( | |
| 1066 | + ), | |
| 1067 | + ) | |
| 1068 | + ); | |
| 1069 | + $elements[] = $this->auto_field( | |
| 1070 | + $field, | |
| 1071 | + array( | |
| 978 | 1072 | 'type' => 'e2pdf-input', |
| 979 | 1073 | 'properties' => array( |
| 980 | 1074 | 'top' => '5', |
| 981 | 1075 | 'width' => '100%', |
| 982 | 1076 | 'height' => 'auto', |
| 983 | - 'value' => $value && substr($value, -1) == '}' ? substr($value, 0, -1) . ':title}' : '', | |
| 984 | - 'dimension' => '1' | |
| 985 | - ) | |
| 986 | - )); | |
| 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]}'; | |
| 987 | 1088 | } |
| 988 | - | |
| 989 | - if ($field->displayCaption) { | |
| 990 | - $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( | |
| 991 | 1097 | 'type' => 'e2pdf-html', |
| 992 | 1098 | 'block' => true, |
| 993 | 1099 | 'properties' => array( |
| 994 | 1100 | 'top' => '20', |
| @@ -996,25 +1102,39 @@ | ||
| 996 | 1102 | 'right' => '20', |
| 997 | 1103 | 'width' => '100%', |
| 998 | 1104 | 'height' => 'auto', |
| 999 | 1105 | 'value' => __('Caption', 'gravityforms'), |
| 1000 | - ) | |
| 1001 | - )); | |
| 1002 | - | |
| 1003 | - $elements[] = $this->auto_field($field, array( | |
| 1106 | + ), | |
| 1107 | + ) | |
| 1108 | + ); | |
| 1109 | + $elements[] = $this->auto_field( | |
| 1110 | + $field, | |
| 1111 | + array( | |
| 1004 | 1112 | 'type' => 'e2pdf-input', |
| 1005 | 1113 | 'properties' => array( |
| 1006 | 1114 | 'top' => '5', |
| 1007 | 1115 | 'width' => '100%', |
| 1008 | 1116 | 'height' => 'auto', |
| 1009 | - 'value' => $value && substr($value, -1) == '}' ? substr($value, 0, -1) . ':caption}' : '', | |
| 1010 | - 'dimension' => '1' | |
| 1011 | - ) | |
| 1012 | - )); | |
| 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]}'; | |
| 1013 | 1128 | } |
| 1014 | - | |
| 1015 | - if ($field->displayDescription) { | |
| 1016 | - $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( | |
| 1017 | 1137 | 'type' => 'e2pdf-html', |
| 1018 | 1138 | 'block' => true, |
| 1019 | 1139 | 'properties' => array( |
| 1020 | 1140 | 'top' => '20', |
| @@ -1022,12 +1142,14 @@ | ||
| 1022 | 1142 | 'right' => '20', |
| 1023 | 1143 | 'width' => '100%', |
| 1024 | 1144 | 'height' => 'auto', |
| 1025 | 1145 | 'value' => __('Description', 'gravityforms'), |
| 1026 | - ) | |
| 1027 | - )); | |
| 1028 | - | |
| 1029 | - $elements[] = $this->auto_field($field, array( | |
| 1146 | + ), | |
| 1147 | + ) | |
| 1148 | + ); | |
| 1149 | + $elements[] = $this->auto_field( | |
| 1150 | + $field, | |
| 1151 | + array( | |
| 1030 | 1152 | 'type' => 'e2pdf-input', |
| 1031 | 1153 | 'properties' => array( |
| 1032 | 1154 | 'top' => '5', |
| 1033 | 1155 | 'width' => '100%', |
| @@ -1032,16 +1154,18 @@ | ||
| 1032 | 1154 | 'top' => '5', |
| 1033 | 1155 | 'width' => '100%', |
| 1034 | 1156 | 'height' => 'auto', |
| 1035 | 1157 | 'value' => $value && substr($value, -1) == '}' ? substr($value, 0, -1) . ':description}' : '', |
| 1036 | - 'dimension' => '1' | |
| 1037 | - ) | |
| 1038 | - )); | |
| 1039 | - } | |
| 1040 | - | |
| 1041 | - break; | |
| 1042 | - case 'html': | |
| 1043 | - $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( | |
| 1044 | 1168 | 'type' => 'e2pdf-html', |
| 1045 | 1169 | 'block' => true, |
| 1046 | 1170 | 'properties' => array( |
| 1047 | 1171 | 'top' => '20', |
| @@ -1049,16 +1173,17 @@ | ||
| 1049 | 1173 | 'right' => '20', |
| 1050 | 1174 | 'width' => '100%', |
| 1051 | 1175 | 'height' => 'auto', |
| 1052 | 1176 | 'value' => $field->content, |
| 1053 | - ) | |
| 1054 | - )); | |
| 1055 | - break; | |
| 1056 | - case 'product': | |
| 1057 | - | |
| 1058 | - if ($field->inputType != 'hiddenproduct') { | |
| 1059 | - | |
| 1060 | - $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( | |
| 1061 | 1186 | 'type' => 'e2pdf-html', |
| 1062 | 1187 | 'block' => true, |
| 1063 | 1188 | 'properties' => array( |
| 1064 | 1189 | 'top' => '20', |
| @@ -1066,25 +1191,29 @@ | ||
| 1066 | 1191 | 'right' => '20', |
| 1067 | 1192 | 'width' => '100%', |
| 1068 | 1193 | 'height' => 'auto', |
| 1069 | 1194 | 'value' => $field->label, |
| 1070 | - ) | |
| 1071 | - )); | |
| 1072 | - | |
| 1073 | - if ($field->inputType == 'singleproduct' || $field->inputType == 'calculation') { | |
| 1074 | - | |
| 1075 | - if ($field->disableQuantity) { | |
| 1076 | - $width = '50%'; | |
| 1077 | - } else { | |
| 1078 | - $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 | + } | |
| 1079 | 1212 | } |
| 1080 | - | |
| 1081 | - foreach ($field['inputs'] as $key => $sub_field) { | |
| 1082 | - | |
| 1083 | - if ($field->disableQuantity && $key == '2') { | |
| 1084 | - | |
| 1085 | - } else { | |
| 1086 | - $elements[] = $this->auto_field($sub_field, array( | |
| 1213 | + $elements[] = $this->auto_field( | |
| 1214 | + $sub_field, | |
| 1215 | + array( | |
| 1087 | 1216 | 'type' => 'e2pdf-html', |
| 1088 | 1217 | 'block' => true, |
| 1089 | 1218 | 'float' => $key == '0' ? false : true, |
| 1090 | 1219 | 'properties' => array( |
| @@ -1093,28 +1222,32 @@ | ||
| 1093 | 1222 | 'right' => '20', |
| 1094 | 1223 | 'width' => $width, |
| 1095 | 1224 | 'height' => 'auto', |
| 1096 | 1225 | 'value' => isset($sub_field['label']) && $sub_field['label'] ? $sub_field['label'] : '', |
| 1097 | - ) | |
| 1098 | - )); | |
| 1099 | - | |
| 1100 | - $elements[] = $this->auto_field($sub_field, array( | |
| 1226 | + ), | |
| 1227 | + ) | |
| 1228 | + ); | |
| 1229 | + $elements[] = $this->auto_field( | |
| 1230 | + $sub_field, | |
| 1231 | + array( | |
| 1101 | 1232 | 'type' => 'e2pdf-input', |
| 1102 | 1233 | 'properties' => array( |
| 1103 | 1234 | 'top' => '5', |
| 1104 | 1235 | 'width' => '100%', |
| 1105 | 1236 | 'height' => 'auto', |
| 1106 | - 'value' => isset($merged_tags[$sub_field['id']]) ? $merged_tags[$sub_field['id']] : '', | |
| 1107 | - ) | |
| 1108 | - )); | |
| 1109 | - } | |
| 1110 | - } | |
| 1237 | + 'value' => $value, | |
| 1238 | + ), | |
| 1239 | + ) | |
| 1240 | + ); | |
| 1111 | 1241 | } |
| 1112 | 1242 | } |
| 1113 | - break; | |
| 1114 | - | |
| 1115 | - case 'signature': | |
| 1116 | - $elements[] = $this->auto_field($field, array( | |
| 1243 | + } | |
| 1244 | + } | |
| 1245 | + break; | |
| 1246 | + case 'signature': | |
| 1247 | + $elements[] = $this->auto_field( | |
| 1248 | + $field, | |
| 1249 | + array( | |
| 1117 | 1250 | 'type' => 'e2pdf-html', |
| 1118 | 1251 | 'block' => true, |
| 1119 | 1252 | 'properties' => array( |
| 1120 | 1253 | 'top' => '20', |
| @@ -1122,85 +1255,235 @@ | ||
| 1122 | 1255 | 'right' => '20', |
| 1123 | 1256 | 'width' => '100%', |
| 1124 | 1257 | 'height' => 'auto', |
| 1125 | 1258 | 'value' => $field->label, |
| 1126 | - ) | |
| 1127 | - )); | |
| 1128 | - | |
| 1129 | - $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( | |
| 1130 | 1271 | 'type' => 'e2pdf-signature', |
| 1131 | 1272 | 'properties' => array( |
| 1132 | 1273 | 'top' => '5', |
| 1133 | 1274 | 'width' => '100%', |
| 1134 | 1275 | 'height' => '150', |
| 1135 | - 'scale' => '1', | |
| 1136 | 1276 | 'dimension' => '1', |
| 1137 | - 'value' => isset($merged_tags[$field->id]) ? $merged_tags[$field->id] : '' | |
| 1138 | - ) | |
| 1139 | - )); | |
| 1140 | - break; | |
| 1141 | - default: | |
| 1142 | - //non-supported fields | |
| 1143 | - 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 | + } | |
| 1144 | 1301 | } |
| 1145 | - } | |
| 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; | |
| 1146 | 1457 | } |
| 1147 | - | |
| 1148 | - $response['page'] = array( | |
| 1149 | - 'bottom' => '20', | |
| 1150 | - 'top' => '20', | |
| 1151 | - 'left' => '20', | |
| 1152 | - 'right' => '20' | |
| 1153 | - ); | |
| 1154 | - | |
| 1155 | - $response['elements'] = $elements; | |
| 1156 | - return $response; | |
| 1458 | + return $elements; | |
| 1157 | 1459 | } |
| 1158 | 1460 | |
| 1461 | + // auto field | |
| 1159 | 1462 | public function auto_field($field = false, $element = array()) { |
| 1160 | - | |
| 1161 | 1463 | if (!$field) { |
| 1162 | 1464 | return false; |
| 1163 | 1465 | } |
| 1164 | - | |
| 1165 | 1466 | if (!isset($element['block'])) { |
| 1166 | 1467 | $element['block'] = false; |
| 1167 | 1468 | } |
| 1168 | - | |
| 1169 | 1469 | if (!isset($element['float'])) { |
| 1170 | 1470 | $element['float'] = false; |
| 1171 | 1471 | } |
| 1172 | - | |
| 1173 | 1472 | return $element; |
| 1174 | 1473 | } |
| 1175 | 1474 | |
| 1176 | - /** | |
| 1177 | - * Verify if item and dataset exists | |
| 1178 | - * | |
| 1179 | - * @return bool - item and dataset exists | |
| 1180 | - */ | |
| 1475 | + // verify | |
| 1181 | 1476 | public function verify() { |
| 1182 | - $item = $this->get('item'); | |
| 1183 | - $dataset = $this->get('dataset'); | |
| 1184 | - | |
| 1185 | - if ($item && $dataset && class_exists('GFFormsModel')) { | |
| 1186 | - $entry = GFFormsModel::get_entry($dataset); | |
| 1187 | - 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')) { | |
| 1188 | 1479 | return true; |
| 1189 | 1480 | } |
| 1190 | 1481 | } |
| 1191 | - | |
| 1192 | 1482 | return false; |
| 1193 | 1483 | } |
| 1194 | 1484 | |
| 1195 | - /** | |
| 1196 | - * Create Form based on uploaded PDF | |
| 1197 | - * | |
| 1198 | - * @param object $template - Template Object to work with | |
| 1199 | - * @param array $data - Settings to create labels/shortcodes | |
| 1200 | - * | |
| 1201 | - * @return object - Mapped Template Object | |
| 1202 | - */ | |
| 1485 | + // auto form | |
| 1203 | 1486 | public function auto_form($template, $data = array()) { |
| 1204 | 1487 | |
| 1205 | 1488 | if ($template->get('ID')) { |
| 1206 | 1489 | |
| @@ -1212,9 +1495,9 @@ | ||
| 1212 | 1495 | $form = array( |
| 1213 | 1496 | 'title' => $template->get('title'), |
| 1214 | 1497 | 'fields' => array( |
| 1215 | 1498 | ), |
| 1216 | - 'confirmations' => array() | |
| 1499 | + 'confirmations' => array(), | |
| 1217 | 1500 | ); |
| 1218 | 1501 | |
| 1219 | 1502 | $form['confirmations'][$confirmation_id] = array( |
| 1220 | 1503 | 'id' => $confirmation_id, |
| @@ -1220,9 +1503,10 @@ | ||
| 1220 | 1503 | 'id' => $confirmation_id, |
| 1221 | 1504 | 'name' => __('Default Confirmation', 'gravityforms'), |
| 1222 | 1505 | 'isDefault' => true, |
| 1223 | 1506 | 'type' => 'message', |
| 1224 | - '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')), | |
| 1225 | 1509 | 'url' => '', |
| 1226 | 1510 | 'pageId' => '', |
| 1227 | 1511 | 'queryString' => '', |
| 1228 | 1512 | ); |
| @@ -1250,16 +1534,15 @@ | ||
| 1250 | 1534 | } |
| 1251 | 1535 | |
| 1252 | 1536 | if ($element['type'] == 'e2pdf-input' || $element['type'] == 'e2pdf-signature') { |
| 1253 | 1537 | $type = 'text'; |
| 1254 | - $label = !empty($labels) ? implode(' ', $labels) : __('Text', 'e2pdf'); | |
| 1538 | + $label = !empty($labels) ? implode(' ', $labels) : 'Text'; | |
| 1255 | 1539 | } elseif ($element['type'] == 'e2pdf-textarea') { |
| 1256 | - | |
| 1257 | 1540 | $type = 'textarea'; |
| 1258 | - $label = !empty($labels) ? implode(' ', $labels) : __('Textarea', 'e2pdf'); | |
| 1541 | + $label = !empty($labels) ? implode(' ', $labels) : 'Textarea'; | |
| 1259 | 1542 | } elseif ($element['type'] == 'e2pdf-select') { |
| 1260 | 1543 | $type = 'select'; |
| 1261 | - $label = !empty($labels) ? implode(' ', $labels) : __('Select', 'e2pdf'); | |
| 1544 | + $label = !empty($labels) ? implode(' ', $labels) : 'Select'; | |
| 1262 | 1545 | |
| 1263 | 1546 | $choices = array(); |
| 1264 | 1547 | $field_options = array(); |
| 1265 | 1548 | |
| @@ -1267,16 +1550,16 @@ | ||
| 1267 | 1550 | $field_options = explode("\n", $element['properties']['options']); |
| 1268 | 1551 | foreach ($field_options as $option) { |
| 1269 | 1552 | $choices[] = array( |
| 1270 | 1553 | 'text' => $option, |
| 1271 | - 'value' => $option | |
| 1554 | + 'value' => $option, | |
| 1272 | 1555 | ); |
| 1273 | 1556 | } |
| 1274 | 1557 | } |
| 1275 | 1558 | } elseif ($element['type'] == 'e2pdf-checkbox') { |
| 1276 | - $field_key = array_search($element['name'], array_column($checkboxes, 'name')); | |
| 1559 | + $field_key = array_search($element['name'], array_column($checkboxes, 'name'), false); | |
| 1277 | 1560 | if ($field_key !== false) { |
| 1278 | - $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); | |
| 1279 | 1562 | if ($checkbox !== false) { |
| 1280 | 1563 | $form['fields'][$checkbox]['choices'][] = array( |
| 1281 | 1564 | 'text' => $element['properties']['option'], |
| 1282 | 1565 | 'value' => $element['properties']['option'], |
| @@ -1289,9 +1572,9 @@ | ||
| 1289 | 1572 | ); |
| 1290 | 1573 | $pages[$page_key]['elements'][$element_key]['value'] = '{' . $form['fields'][$checkbox]['label'] . ':' . $form['fields'][$checkbox]['id'] . '}'; |
| 1291 | 1574 | } |
| 1292 | 1575 | } else { |
| 1293 | - $label = !empty($labels) ? implode(' ', $labels) : __('Checkbox', 'e2pdf'); | |
| 1576 | + $label = !empty($labels) ? implode(' ', $labels) : 'Checkbox'; | |
| 1294 | 1577 | $type = 'checkbox'; |
| 1295 | 1578 | $checkboxes[] = array( |
| 1296 | 1579 | 'id' => $field_id, |
| 1297 | 1580 | 'name' => $element['name'], |
| @@ -1299,9 +1582,9 @@ | ||
| 1299 | 1582 | $choices = array( |
| 1300 | 1583 | array( |
| 1301 | 1584 | 'text' => $element['properties']['option'], |
| 1302 | 1585 | 'value' => $element['properties']['option'], |
| 1303 | - ) | |
| 1586 | + ), | |
| 1304 | 1587 | ); |
| 1305 | 1588 | |
| 1306 | 1589 | $inputs = array( |
| 1307 | 1590 | array( |
| @@ -1306,9 +1589,9 @@ | ||
| 1306 | 1589 | $inputs = array( |
| 1307 | 1590 | array( |
| 1308 | 1591 | 'id' => $field_id . '.1', |
| 1309 | 1592 | 'label' => $element['properties']['option'], |
| 1310 | - ) | |
| 1593 | + ), | |
| 1311 | 1594 | ); |
| 1312 | 1595 | } |
| 1313 | 1596 | } elseif ($element['type'] == 'e2pdf-radio') { |
| 1314 | 1597 | if (isset($element['properties']['group']) && $element['properties']['group']) { |
| @@ -1315,12 +1598,11 @@ | ||
| 1315 | 1598 | $element['name'] = $element['properties']['group']; |
| 1316 | 1599 | } else { |
| 1317 | 1600 | $element['name'] = $element['element_id']; |
| 1318 | 1601 | } |
| 1319 | - | |
| 1320 | - $field_key = array_search($element['name'], array_column($radios, 'name')); | |
| 1602 | + $field_key = array_search($element['name'], array_column($radios, 'name'), false); | |
| 1321 | 1603 | if ($field_key !== false) { |
| 1322 | - $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); | |
| 1323 | 1605 | if ($radio !== false) { |
| 1324 | 1606 | $form['fields'][$radio]['choices'][] = array( |
| 1325 | 1607 | 'text' => $element['properties']['option'], |
| 1326 | 1608 | 'value' => $element['properties']['option'], |
| @@ -1325,12 +1607,12 @@ | ||
| 1325 | 1607 | 'text' => $element['properties']['option'], |
| 1326 | 1608 | 'value' => $element['properties']['option'], |
| 1327 | 1609 | ); |
| 1328 | 1610 | |
| 1329 | - $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'] . '}'; | |
| 1330 | 1612 | } |
| 1331 | 1613 | } else { |
| 1332 | - $label = !empty($labels) ? implode(' ', $labels) : __('Radio', 'e2pdf'); | |
| 1614 | + $label = !empty($labels) ? implode(' ', $labels) : 'Radio'; | |
| 1333 | 1615 | $type = 'radio'; |
| 1334 | 1616 | $radios[] = array( |
| 1335 | 1617 | 'id' => $field_id, |
| 1336 | 1618 | 'name' => $element['name'], |
| @@ -1338,13 +1620,12 @@ | ||
| 1338 | 1620 | $choices = array( |
| 1339 | 1621 | array( |
| 1340 | 1622 | 'text' => $element['properties']['option'], |
| 1341 | 1623 | 'value' => $element['properties']['option'], |
| 1342 | - ) | |
| 1624 | + ), | |
| 1343 | 1625 | ); |
| 1344 | 1626 | } |
| 1345 | 1627 | } |
| 1346 | - | |
| 1347 | 1628 | if ($type) { |
| 1348 | 1629 | $field = array( |
| 1349 | 1630 | 'id' => $field_id, |
| 1350 | 1631 | 'type' => $type, |
| @@ -1380,13 +1661,9 @@ | ||
| 1380 | 1661 | |
| 1381 | 1662 | return $template; |
| 1382 | 1663 | } |
| 1383 | 1664 | |
| 1384 | - /** | |
| 1385 | - * Init Visual Mapper data | |
| 1386 | - * | |
| 1387 | - * @return bool|string - HTML data source for Visual Mapper | |
| 1388 | - */ | |
| 1665 | + // visual mapper | |
| 1389 | 1666 | public function visual_mapper() { |
| 1390 | 1667 | |
| 1391 | 1668 | $item = $this->get('item'); |
| 1392 | 1669 | $html = ''; |
| @@ -1392,49 +1669,57 @@ | ||
| 1392 | 1669 | $html = ''; |
| 1393 | 1670 | $source = ''; |
| 1394 | 1671 | |
| 1395 | 1672 | if ($item && function_exists('gravity_form')) { |
| 1396 | - | |
| 1673 | + ob_start(); | |
| 1397 | 1674 | $form = false; |
| 1398 | 1675 | if (class_exists('GFFormsModel')) { |
| 1399 | 1676 | $form = GFFormsModel::get_form_meta($item); |
| 1400 | 1677 | } |
| 1401 | - | |
| 1402 | - if (!$form) { | |
| 1403 | - 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 | + } | |
| 1404 | 1691 | } |
| 1405 | - | |
| 1406 | - add_filter('gform_pre_render', array($this, 'filter_gform_pre_render'), 30, 1); | |
| 1407 | - $source = gravity_form($item, true, true, false, null, false, 0, false); | |
| 1408 | - remove_filter('gform_pre_render', array($this, 'filter_gform_pre_render'), 30); | |
| 1409 | - | |
| 1410 | - if ($source) { | |
| 1411 | - libxml_use_internal_errors(true); | |
| 1412 | - $dom = new DOMDocument(); | |
| 1413 | - if (function_exists('mb_convert_encoding')) { | |
| 1414 | - $html = $dom->loadHTML(mb_convert_encoding($source, 'HTML-ENTITIES', 'UTF-8')); | |
| 1415 | - } else { | |
| 1416 | - $html = $dom->loadHTML('<?xml encoding="UTF-8">' . $source); | |
| 1417 | - } | |
| 1418 | - libxml_clear_errors(); | |
| 1692 | + if (ob_get_length() > 0) { | |
| 1693 | + while (@ob_end_clean()); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged | |
| 1419 | 1694 | } |
| 1420 | - | |
| 1421 | 1695 | if (!$source) { |
| 1422 | - return __('Form source is empty', 'e2pdf'); | |
| 1696 | + return '<div class="e2pdf-vm-error">' . __("The form source is empty or doesn't exist", 'e2pdf') . '</div>'; | |
| 1423 | 1697 | } elseif (!$html) { |
| 1424 | - 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>'; | |
| 1425 | 1699 | } else { |
| 1426 | 1700 | |
| 1427 | - $xml = $this->helper->load('xml'); | |
| 1428 | - $xml->set('dom', $dom); | |
| 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(); | |
| 1429 | 1708 | $xpath = new DomXPath($dom); |
| 1430 | 1709 | |
| 1710 | + // remove by class | |
| 1431 | 1711 | $remove_by_class = array( |
| 1432 | 1712 | 'gf_progressbar_wrapper', |
| 1433 | 1713 | 'gform_previous_button', |
| 1434 | 1714 | 'gform_next_button', |
| 1435 | - 'gform_button button' | |
| 1715 | + 'gform_button button', | |
| 1716 | + 'gform_save_link', | |
| 1717 | + 'gfield--type-captcha', | |
| 1436 | 1718 | ); |
| 1719 | + if ($this->get('nested')) { | |
| 1720 | + $remove_by_class[] = 'gform_heading'; | |
| 1721 | + } | |
| 1437 | 1722 | foreach ($remove_by_class as $key => $class) { |
| 1438 | 1723 | $elements = $xpath->query("//*[contains(@class, '{$class}')]"); |
| 1439 | 1724 | foreach ($elements as $element) { |
| 1440 | 1725 | $element->parentNode->removeChild($element); |
| @@ -1440,113 +1725,202 @@ | ||
| 1440 | 1725 | $element->parentNode->removeChild($element); |
| 1441 | 1726 | } |
| 1442 | 1727 | } |
| 1443 | 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 | |
| 1444 | 1743 | $remove_by_tag = array( |
| 1445 | - 'script' | |
| 1744 | + 'script', | |
| 1446 | 1745 | ); |
| 1447 | 1746 | foreach ($remove_by_tag as $key => $tag) { |
| 1448 | - $elements = $xpath->query("//{$tag}"); | |
| 1747 | + $elements = $xpath->query('//' . $tag); | |
| 1449 | 1748 | foreach ($elements as $element) { |
| 1450 | 1749 | $element->parentNode->removeChild($element); |
| 1451 | 1750 | } |
| 1452 | 1751 | } |
| 1453 | 1752 | |
| 1454 | - //replace time fields | |
| 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')]"); | |
| 1774 | + foreach ($elements as $element) { | |
| 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); | |
| 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', ''); | |
| 1797 | + } | |
| 1798 | + } | |
| 1799 | + | |
| 1800 | + // replace time fields | |
| 1455 | 1801 | $elements = $xpath->query("//*[contains(@class, 'gfield_time_hour')]"); |
| 1456 | 1802 | foreach ($elements as $element) { |
| 1457 | - | |
| 1458 | - $sub_elements = $xpath->query(".//*[self::input or self::select]", $element->parentNode); | |
| 1803 | + $sub_elements = $xpath->query('.//*[self::input or self::select]', $element->parentNode); | |
| 1459 | 1804 | foreach ($sub_elements as $sub_element) { |
| 1460 | - $sub_element = $xml->set_node_value($sub_element, 'class', $xml->get_node_value($sub_element, 'class') . ' e2pdf-no-vm'); | |
| 1805 | + $xml->set_node_value($sub_element, 'class', $xml->get_node_value($sub_element, 'class') . ' e2pdf-no-vm'); | |
| 1461 | 1806 | } |
| 1462 | - | |
| 1463 | - $element = $xml->set_node_value($element, 'class', $xml->get_node_value($element->parentNode, 'class') . ' e2pdf-vm-field-wrapper', true); | |
| 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'); |
| 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')); | |
| 1467 | 1813 | |
| 1468 | - $field = $xml->set_node_value($field, 'type', 'text'); | |
| 1469 | - $field = $xml->set_node_value($field, 'class', 'e2pdf-vm-field'); | |
| 1470 | - $field = $xml->set_node_value($field, 'name', $xml->get_node_value($input, 'name')); | |
| 1471 | - | |
| 1472 | 1814 | $element->parentNode->appendChild($field); |
| 1473 | 1815 | } |
| 1474 | 1816 | |
| 1475 | - //replace multiupload field | |
| 1817 | + // replace multiupload field | |
| 1476 | 1818 | $elements = $xpath->query("//*[contains(@class, 'gform_drop_area')]"); |
| 1477 | 1819 | foreach ($elements as $element) { |
| 1478 | - | |
| 1479 | - $element = $xml->set_node_value($element, 'class', $xml->get_node_value($element, 'class') . ' e2pdf-vm-field-wrapper', true); | |
| 1480 | - | |
| 1820 | + $xml->set_node_value($element, 'class', $xml->get_node_value($element, 'class') . ' e2pdf-vm-rel-field'); | |
| 1481 | 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 | + } | |
| 1482 | 1828 | |
| 1483 | - $field = $dom->createElement('input'); | |
| 1484 | - $field = $xml->set_node_value($field, 'type', 'text'); | |
| 1485 | - $field = $xml->set_node_value($field, 'class', 'e2pdf-vm-field'); | |
| 1486 | - $field = $xml->set_node_value($field, 'name', 'input_' . $field_id); | |
| 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'))); | |
| 1836 | + } | |
| 1837 | + } | |
| 1487 | 1838 | |
| 1488 | - $element->appendChild($field); | |
| 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); | |
| 1849 | + } | |
| 1489 | 1850 | } |
| 1490 | 1851 | |
| 1491 | - //replace single product | |
| 1492 | - $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')]"); | |
| 1493 | 1854 | foreach ($elements as $element) { |
| 1494 | - $spans = $xpath->query(".//span", $element); | |
| 1855 | + $spans = $xpath->query('.//span', $element); | |
| 1495 | 1856 | foreach ($spans as $key => $sub_element) { |
| 1496 | 1857 | $sub_element->parentNode->removeChild($sub_element); |
| 1497 | 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 | + } | |
| 1498 | 1865 | |
| 1499 | - $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); | |
| 1500 | 1880 | foreach ($inputs as $key => $sub_element) { |
| 1501 | - $sub_element = $xml->set_node_value($sub_element, 'type', 'text'); | |
| 1502 | - $sub_element = $xml->set_node_value($sub_element, 'class', ''); | |
| 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 | + } | |
| 1503 | 1886 | } |
| 1504 | 1887 | } |
| 1505 | 1888 | |
| 1506 | - $merged_tags = array(); | |
| 1507 | - if (class_exists('GFCommon')) { | |
| 1508 | - foreach ($form['fields'] as $field) { | |
| 1509 | - $tags = GFCommon::get_field_merge_tags($field); | |
| 1510 | - foreach ($tags as $tag) { | |
| 1511 | - if (isset($tag['tag'])) { | |
| 1512 | - if ($field->type == 'list') { | |
| 1513 | - $field_id = preg_replace('/\{(?:.*)\:(.*)\:\}/', '${1}', $tag['tag']); | |
| 1514 | - } else { | |
| 1515 | - $field_id = preg_replace('/\{(?:.*)\:(.*)\}/', '${1}', $tag['tag']); | |
| 1516 | - } | |
| 1517 | - if ($field_id) { | |
| 1518 | - $merged_tags[$field_id] = $tag['tag']; | |
| 1519 | - } | |
| 1520 | - } | |
| 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); | |
| 1521 | 1896 | } |
| 1522 | 1897 | } |
| 1523 | 1898 | } |
| 1524 | 1899 | |
| 1525 | - $fields = array(); | |
| 1526 | - foreach ($form['fields'] as $field) { | |
| 1527 | - $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'); | |
| 1528 | 1903 | } |
| 1529 | 1904 | |
| 1905 | + // replace by types | |
| 1530 | 1906 | $replace_by_types = array( |
| 1531 | - "//input", | |
| 1532 | - "//textarea", | |
| 1533 | - "//select" | |
| 1907 | + '//input', | |
| 1908 | + '//textarea', | |
| 1909 | + '//select', | |
| 1534 | 1910 | ); |
| 1535 | - | |
| 1536 | 1911 | foreach ($replace_by_types as $replace_by_type) { |
| 1537 | 1912 | $inputs = $xpath->query($replace_by_type); |
| 1538 | 1913 | foreach ($inputs as $element) { |
| 1539 | - if ($element->attributes->getNamedItem("name")) { | |
| 1540 | - | |
| 1914 | + if ($element->attributes->getNamedItem('name')) { | |
| 1541 | 1915 | $field_id = false; |
| 1542 | 1916 | $field = false; |
| 1543 | - | |
| 1544 | 1917 | $sub_field_id = preg_replace('/input_([^\[]+)(?:.*)/', '${1}', $xml->get_node_value($element, 'name')); |
| 1545 | - | |
| 1546 | 1918 | if ($sub_field_id) { |
| 1547 | 1919 | if (substr($sub_field_id, -6) == '_valid') { |
| 1548 | 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); | |
| 1549 | 1923 | } else { |
| 1550 | 1924 | $field_id = preg_replace('/([\d]+)\.(?:.*)/', '${1}', $sub_field_id); |
| 1551 | 1925 | } |
| 1552 | 1926 | if (isset($fields[$field_id])) { |
| @@ -1552,14 +1926,12 @@ | ||
| 1552 | 1926 | if (isset($fields[$field_id])) { |
| 1553 | 1927 | $field = $fields[$field_id]; |
| 1554 | 1928 | } |
| 1555 | 1929 | } |
| 1556 | - | |
| 1557 | 1930 | if ($field) { |
| 1558 | 1931 | if ( |
| 1559 | 1932 | $field->type == 'name' || |
| 1560 | - $field->type == 'address' || | |
| 1561 | - ( | |
| 1933 | + $field->type == 'address' || ( | |
| 1562 | 1934 | $field->type == 'product' && |
| 1563 | 1935 | $field->inputType && |
| 1564 | 1936 | ($field->inputType == 'singleproduct' || $field->inputType == 'calculation') |
| 1565 | 1937 | ) |
| @@ -1564,12 +1936,34 @@ | ||
| 1564 | 1936 | ($field->inputType == 'singleproduct' || $field->inputType == 'calculation') |
| 1565 | 1937 | ) |
| 1566 | 1938 | ) { |
| 1567 | 1939 | $value = $merged_tags[$sub_field_id]; |
| 1568 | - $element = $xml->set_node_value($element, 'name', $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); | |
| 1569 | 1946 | } elseif ($field->type == 'consent') { |
| 1570 | 1947 | $value = isset($merged_tags[$field_id . '.1']) ? $merged_tags[$field_id . '.1'] : ''; |
| 1571 | - $element = $xml->set_node_value($element, 'name', $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); | |
| 1572 | 1966 | } else { |
| 1573 | 1967 | if (isset($merged_tags[$field_id])) { |
| 1574 | 1968 | $value = $merged_tags[$field_id]; |
| 1575 | 1969 | if (substr($value, -1) == '}') { |
| @@ -1574,13 +1968,25 @@ | ||
| 1574 | 1968 | $value = $merged_tags[$field_id]; |
| 1575 | 1969 | if (substr($value, -1) == '}') { |
| 1576 | 1970 | if (false !== strpos($xml->get_node_value($element->parentNode, 'class'), 'ginput_post_image_')) { |
| 1577 | 1971 | if (false !== strpos($xml->get_node_value($element->parentNode, 'class'), 'ginput_post_image_title')) { |
| 1578 | - $value = substr($value, 0, -1) . ':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 | + } | |
| 1579 | 1977 | } elseif (false !== strpos($xml->get_node_value($element->parentNode, 'class'), 'ginput_post_image_caption')) { |
| 1580 | - $value = substr($value, 0, -1) . ':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 | + } | |
| 1581 | 1983 | } elseif (false !== strpos($xml->get_node_value($element->parentNode, 'class'), 'ginput_post_image_description')) { |
| 1582 | - $value = substr($value, 0, -1) . ':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 | + } | |
| 1583 | 1989 | } |
| 1584 | 1990 | } elseif ($field->type == 'list') { |
| 1585 | 1991 | if ($field->enableColumns) { |
| 1586 | 1992 | $parent_class = $xml->get_node_value($element->parentNode, 'class'); |
| @@ -1588,17 +1994,33 @@ | ||
| 1588 | 1994 | $td = $xpath->query("./td[contains(@class, '{$parent_class}')]/preceding-sibling::td", $element->parentNode->parentNode); |
| 1589 | 1995 | if ($td && isset($td->length)) { |
| 1590 | 1996 | $index = (int) $td->length + 1; |
| 1591 | 1997 | } |
| 1592 | - $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 | + } | |
| 1593 | 2003 | } else { |
| 1594 | - $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 | + } | |
| 1595 | 2009 | } |
| 1596 | 2010 | } elseif ($field->enableChoiceValue && $value) { |
| 1597 | - $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 | + } | |
| 1598 | 2020 | } |
| 1599 | 2021 | } |
| 1600 | - $element = $xml->set_node_value($element, 'name', $value); | |
| 2022 | + $xml->set_node_value($element, 'name', $value); | |
| 1601 | 2023 | } |
| 1602 | 2024 | } |
| 1603 | 2025 | } |
| 1604 | 2026 | } |
| @@ -1604,9 +2026,27 @@ | ||
| 1604 | 2026 | } |
| 1605 | 2027 | } |
| 1606 | 2028 | } |
| 1607 | 2029 | |
| 1608 | - 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 | + } | |
| 1609 | 2049 | } |
| 1610 | 2050 | } |
| 1611 | 2051 | |
| 1612 | 2052 | return false; |
| @@ -1611,16 +2051,9 @@ | ||
| 1611 | 2051 | |
| 1612 | 2052 | return false; |
| 1613 | 2053 | } |
| 1614 | 2054 | |
| 1615 | - /** | |
| 1616 | - * Convert Field name to Value | |
| 1617 | - * @since 0.01.34 | |
| 1618 | - * | |
| 1619 | - * @param string $name - Field name | |
| 1620 | - * | |
| 1621 | - * @return bool|string - Converted value or false | |
| 1622 | - */ | |
| 2055 | + // auto map | |
| 1623 | 2056 | public function auto_map($name = false) { |
| 1624 | 2057 | |
| 1625 | 2058 | $item = $this->get('item'); |
| 1626 | 2059 | |
| @@ -1639,24 +2072,11 @@ | ||
| 1639 | 2072 | |
| 1640 | 2073 | if ($form) { |
| 1641 | 2074 | if (class_exists('GFCommon')) { |
| 1642 | 2075 | foreach ($form['fields'] as $field) { |
| 1643 | - $tags = GFCommon::get_field_merge_tags($field); | |
| 1644 | - foreach ($tags as $tag) { | |
| 1645 | - if (isset($tag['tag'])) { | |
| 1646 | - if ($field->type == 'list') { | |
| 1647 | - $field_id = preg_replace('/\{(?:.*)\:(.*)\:\}/', '${1}', $tag['tag']); | |
| 1648 | - } else { | |
| 1649 | - $field_id = preg_replace('/\{(?:.*)\:(.*)\}/', '${1}', $tag['tag']); | |
| 1650 | - } | |
| 1651 | - if ($field_id) { | |
| 1652 | - $merged_tags[$field_id] = $tag['tag']; | |
| 1653 | - } | |
| 1654 | - } | |
| 1655 | - } | |
| 2076 | + $merged_tags = $this->get_field_merge_tags($merged_tags, $field); | |
| 1656 | 2077 | } |
| 1657 | 2078 | } |
| 1658 | - | |
| 1659 | 2079 | if (isset($merged_tags[$sub_field_id])) { |
| 1660 | 2080 | return $merged_tags[$sub_field_id]; |
| 1661 | 2081 | } |
| 1662 | 2082 | } |
| @@ -1664,81 +2084,115 @@ | ||
| 1664 | 2084 | |
| 1665 | 2085 | return false; |
| 1666 | 2086 | } |
| 1667 | 2087 | |
| 1668 | - /** | |
| 1669 | - * Load additional shortcodes for this extension | |
| 1670 | - */ | |
| 1671 | - public function load_shortcodes() { | |
| 1672 | - | |
| 2088 | + // load shortcodes | |
| 2089 | + public function load_shortcodes() { // phpcs:ignore Squiz.WhiteSpace.SuperfluousWhitespace.EndLine | |
| 1673 | 2090 | } |
| 1674 | 2091 | |
| 1675 | - 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 | + } | |
| 1676 | 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'] : ''; | |
| 1677 | 2136 | if (false === strpos($content, '[')) { |
| 1678 | - return $content; | |
| 2137 | + return $notification; | |
| 1679 | 2138 | } |
| 1680 | 2139 | |
| 1681 | 2140 | $shortcode_tags = array( |
| 1682 | 2141 | 'e2pdf-download', |
| 1683 | - 'e2pdf-save', | |
| 1684 | 2142 | 'e2pdf-view', |
| 1685 | - 'e2pdf-adobesign' | |
| 1686 | 2143 | ); |
| 1687 | - | |
| 1688 | 2144 | preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); |
| 1689 | 2145 | $tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 1690 | - | |
| 1691 | 2146 | if (!empty($tagnames)) { |
| 1692 | - | |
| 1693 | - $pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames); | |
| 1694 | - | |
| 1695 | - preg_match_all("/$pattern/", $content, $shortcodes); | |
| 2147 | + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes); | |
| 1696 | 2148 | foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 1697 | - | |
| 1698 | - $shortcode = array(); | |
| 1699 | - $shortcode[1] = $shortcodes[1][$key]; | |
| 1700 | - $shortcode[2] = $shortcodes[2][$key]; | |
| 1701 | - $shortcode[3] = $shortcodes[3][$key]; | |
| 1702 | - $shortcode[4] = $shortcodes[4][$key]; | |
| 1703 | - $shortcode[5] = $shortcodes[5][$key]; | |
| 1704 | - $shortcode[6] = $shortcodes[6][$key]; | |
| 1705 | - | |
| 2149 | + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); | |
| 1706 | 2150 | $atts = shortcode_parse_atts($shortcode[3]); |
| 1707 | - | |
| 1708 | - if (($shortcode[2] === 'e2pdf-save' && isset($atts['attachment']) && $atts['attachment'] == 'true') || $shortcode[2] === 'e2pdf-attachment') { | |
| 1709 | - | |
| 1710 | - } else { | |
| 1711 | - if (!isset($atts['dataset']) && isset($atts['id'])) { | |
| 1712 | - $template = new Model_E2pdf_Template(); | |
| 1713 | - $template->load($atts['id']); | |
| 1714 | - if ($template->get('extension') === 'gravity') { | |
| 1715 | - $entry_id = $dataset && isset($dataset['id']) ? $dataset['id'] : false; | |
| 1716 | - if ($entry_id) { | |
| 1717 | - $atts['dataset'] = $entry_id; | |
| 1718 | - $shortcode[3] .= " dataset=\"{$entry_id}\""; | |
| 1719 | - } | |
| 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 . '"'; | |
| 1720 | 2159 | } |
| 1721 | 2160 | } |
| 1722 | - | |
| 1723 | - if (!isset($atts['apply'])) { | |
| 1724 | - $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'); | |
| 1725 | 2171 | } |
| 2172 | + $notification['body'] = str_replace($shortcode_value, do_shortcode_tag($shortcode), $notification['body']); | |
| 2173 | + } | |
| 2174 | + } | |
| 2175 | + } | |
| 2176 | + return $notification; | |
| 2177 | + } | |
| 1726 | 2178 | |
| 1727 | - if (!isset($atts['filter'])) { | |
| 1728 | - $shortcode[3] .= " filter=\"true\""; | |
| 1729 | - } | |
| 1730 | - | |
| 1731 | - $new_shortcode = "[" . $shortcode[2] . $shortcode[3] . "]"; | |
| 1732 | - $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); | |
| 1733 | 2187 | } |
| 1734 | 2188 | } |
| 1735 | 2189 | } |
| 1736 | - | |
| 1737 | - return $content; | |
| 2190 | + return $entry; | |
| 1738 | 2191 | } |
| 1739 | 2192 | |
| 1740 | - public function filter_gform_notification($notification, $form, $dataset) { | |
| 2193 | + // gform notification filter | |
| 2194 | + public function filter_gform_notification($notification, $form, $entry) { | |
| 1741 | 2195 | |
| 1742 | 2196 | $content = isset($notification['message']) && $notification['message'] ? $notification['message'] : ''; |
| 1743 | 2197 | |
| 1744 | 2198 | if (false === strpos($content, '[')) { |
| @@ -1744,88 +2198,160 @@ | ||
| 1744 | 2198 | if (false === strpos($content, '[')) { |
| 1745 | 2199 | return $notification; |
| 1746 | 2200 | } |
| 1747 | 2201 | |
| 2202 | + // conditional shortcode fix since 1.13.18 | |
| 1748 | 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( | |
| 1749 | 2237 | 'e2pdf-download', |
| 1750 | 2238 | 'e2pdf-save', |
| 1751 | 2239 | 'e2pdf-view', |
| 1752 | 2240 | 'e2pdf-adobesign', |
| 1753 | - 'e2pdf-attachment' | |
| 2241 | + 'e2pdf-attachment', | |
| 2242 | + 'e2pdf-zapier', | |
| 1754 | 2243 | ); |
| 1755 | - | |
| 1756 | 2244 | preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); |
| 1757 | 2245 | $tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 1758 | - | |
| 1759 | 2246 | if (!empty($tagnames)) { |
| 1760 | - | |
| 1761 | - $pattern = $this->helper->load('shortcode')->get_shortcode_regex($tagnames); | |
| 1762 | - | |
| 1763 | - preg_match_all("/$pattern/", $content, $shortcodes); | |
| 1764 | - | |
| 2247 | + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes); | |
| 1765 | 2248 | foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 1766 | - | |
| 1767 | - $shortcode = array(); | |
| 1768 | - $shortcode[1] = $shortcodes[1][$key]; | |
| 1769 | - $shortcode[2] = $shortcodes[2][$key]; | |
| 1770 | - $shortcode[3] = $shortcodes[3][$key]; | |
| 1771 | - $shortcode[4] = $shortcodes[4][$key]; | |
| 1772 | - $shortcode[5] = $shortcodes[5][$key]; | |
| 1773 | - $shortcode[6] = $shortcodes[6][$key]; | |
| 1774 | - | |
| 2249 | + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); | |
| 1775 | 2250 | $atts = shortcode_parse_atts($shortcode[3]); |
| 1776 | - | |
| 1777 | 2251 | if (!isset($atts['dataset']) && isset($atts['id'])) { |
| 1778 | 2252 | $template = new Model_E2pdf_Template(); |
| 1779 | 2253 | $template->load($atts['id']); |
| 1780 | 2254 | if ($template->get('extension') === 'gravity') { |
| 1781 | - $entry_id = $dataset && isset($dataset['id']) ? $dataset['id'] : false; | |
| 2255 | + $entry_id = $entry && isset($entry['id']) ? $entry['id'] : false; | |
| 1782 | 2256 | if ($entry_id) { |
| 1783 | 2257 | $atts['dataset'] = $entry_id; |
| 1784 | - $shortcode[3] .= " dataset=\"{$entry_id}\""; | |
| 2258 | + $shortcode[3] .= ' dataset="' . $entry_id . '"'; | |
| 1785 | 2259 | } |
| 1786 | 2260 | } |
| 1787 | 2261 | } |
| 1788 | - | |
| 1789 | 2262 | if (!isset($atts['apply'])) { |
| 1790 | - $shortcode[3] .= " apply=\"true\""; | |
| 2263 | + $shortcode[3] .= ' apply="true"'; | |
| 1791 | 2264 | } |
| 1792 | - | |
| 1793 | 2265 | if (!isset($atts['filter'])) { |
| 1794 | - $shortcode[3] .= " filter=\"true\""; | |
| 2266 | + $shortcode[3] .= ' filter="true"'; | |
| 1795 | 2267 | } |
| 1796 | - | |
| 1797 | 2268 | $file = false; |
| 1798 | - | |
| 1799 | - if (($shortcode[2] === 'e2pdf-save' && isset($atts['attachment']) && $atts['attachment'] == 'true') || $shortcode[2] === 'e2pdf-attachment') { | |
| 1800 | - | |
| 2269 | + if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { | |
| 1801 | 2270 | if (class_exists('GFCommon')) { |
| 1802 | - $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); | |
| 1803 | 2274 | } |
| 1804 | - | |
| 1805 | 2275 | $file = do_shortcode_tag($shortcode); |
| 1806 | 2276 | if ($file) { |
| 1807 | - 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 { | |
| 1808 | 2287 | $this->helper->add('gravity_attachments', $file); |
| 1809 | 2288 | } |
| 1810 | - | |
| 1811 | - $notification['attachments'] = ( is_array(rgget('attachments', $notification)) ) ? rgget('attachments', $notification) : array(); | |
| 2289 | + $notification['attachments'] = (is_array(rgget('attachments', $notification))) ? rgget('attachments', $notification) : array(); | |
| 1812 | 2290 | $notification['attachments'][] = $file; |
| 1813 | 2291 | } |
| 1814 | - | |
| 1815 | 2292 | $notification['message'] = str_replace($shortcode_value, '', $notification['message']); |
| 1816 | 2293 | } else { |
| 1817 | - $new_shortcode = "[" . $shortcode[2] . $shortcode[3] . "]"; | |
| 1818 | - $notification['message'] = str_replace($shortcode_value, $new_shortcode, $notification['message']); | |
| 2294 | + $notification['message'] = str_replace($shortcode_value, '[' . $shortcode[2] . $shortcode[3] . ']', $notification['message']); | |
| 1819 | 2295 | } |
| 1820 | 2296 | } |
| 1821 | 2297 | } |
| 2298 | + return $notification; | |
| 2299 | + } | |
| 1822 | 2300 | |
| 1823 | - 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; | |
| 1824 | 2350 | } |
| 1825 | 2351 | |
| 2352 | + // gform pre render filter | |
| 1826 | 2353 | public function filter_gform_pre_render($form) { |
| 1827 | - | |
| 1828 | 2354 | if (isset($form['fields'])) { |
| 1829 | 2355 | foreach ($form['fields'] as $key => $field) { |
| 1830 | 2356 | if ($field->pageNumber != '1') { |
| 1831 | 2357 | $field->pageNumber = '1'; |
| @@ -1832,27 +2358,54 @@ | ||
| 1832 | 2358 | $form['fields'][$key] = $field; |
| 1833 | 2359 | } |
| 1834 | 2360 | } |
| 1835 | 2361 | } |
| 2362 | + return $form; | |
| 2363 | + } | |
| 1836 | 2364 | |
| 1837 | - 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; | |
| 1838 | 2371 | } |
| 1839 | 2372 | |
| 1840 | - 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) { | |
| 1841 | 2375 | |
| 1842 | 2376 | if ($field && $value) { |
| 1843 | 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 | + } | |
| 1844 | 2384 | $mod = explode('.', $merge_tag); |
| 1845 | 2385 | if (isset($mod[1]) && $mod[1] == '1') { |
| 1846 | 2386 | $value = '1'; |
| 1847 | 2387 | } |
| 1848 | 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 | + } | |
| 1849 | 2404 | |
| 1850 | 2405 | if ($modifier && $modifier != 'text') { |
| 1851 | - | |
| 1852 | 2406 | $list_id = false; |
| 1853 | 2407 | $field_id = false; |
| 1854 | - | |
| 1855 | 2408 | if (false !== strpos($modifier, '_')) { |
| 1856 | 2409 | $mod = explode('_', $modifier); |
| 1857 | 2410 | if (isset($mod[0]) && is_numeric($mod[0])) { |
| 1858 | 2411 | $list_id = $mod[0] - 1; |
| @@ -1862,12 +2415,15 @@ | ||
| 1862 | 2415 | } |
| 1863 | 2416 | } elseif (is_numeric($modifier)) { |
| 1864 | 2417 | $list_id = $modifier - 1; |
| 1865 | 2418 | } |
| 1866 | - | |
| 1867 | 2419 | if ($list_id !== false) { |
| 1868 | 2420 | $value = ''; |
| 1869 | - $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 | + } | |
| 1870 | 2426 | if (is_array($list)) { |
| 1871 | 2427 | if (isset($list[$list_id])) { |
| 1872 | 2428 | if ($field_id !== false) { |
| 1873 | 2429 | if (is_array($list[$list_id]) && isset(array_values($list[$list_id])[$field_id])) { |
| @@ -1883,17 +2439,73 @@ | ||
| 1883 | 2439 | } |
| 1884 | 2440 | } |
| 1885 | 2441 | } |
| 1886 | 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 | + } | |
| 1887 | 2502 | } |
| 1888 | 2503 | } |
| 1889 | - | |
| 1890 | 2504 | return $value; |
| 1891 | 2505 | } |
| 1892 | 2506 | |
| 1893 | - /** | |
| 1894 | - * Delete attachments that were sent by email | |
| 1895 | - */ | |
| 2507 | + // delete attachments | |
| 1896 | 2508 | public function action_gform_after_email($is_success) { |
| 1897 | 2509 | |
| 1898 | 2510 | $files = $this->helper->get('gravity_attachments'); |
| 1899 | 2511 | if (is_array($files) && !empty($files)) { |
| @@ -1903,29 +2515,208 @@ | ||
| 1903 | 2515 | $this->helper->deset('gravity_attachments'); |
| 1904 | 2516 | } |
| 1905 | 2517 | } |
| 1906 | 2518 | |
| 1907 | - /** | |
| 1908 | - * Get styles for generating Map Field function | |
| 1909 | - * | |
| 1910 | - * @return array - List of css files to load | |
| 1911 | - */ | |
| 1912 | - 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) { | |
| 1913 | 2539 | $styles = array(); |
| 1914 | - | |
| 1915 | 2540 | if (class_exists('GFCommon') && class_exists('GFForms')) { |
| 1916 | 2541 | $base_url = GFCommon::get_base_url(); |
| 2542 | + $base_path = GFCommon::get_base_path(); | |
| 1917 | 2543 | $version = GFForms::$version; |
| 1918 | 2544 | $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
| 1919 | - $styles[] = $base_url . "/css/formreset{$min}.css?ver=" . $version; | |
| 1920 | - $styles[] = $base_url . "/css/datepicker{$min}.css?ver=" . $version; | |
| 1921 | - $styles[] = $base_url . "/css/formsmain{$min}.css?ver=" . $version; | |
| 1922 | - $styles[] = $base_url . "/css/readyclass{$min}.css?ver=" . $version; | |
| 1923 | - $styles[] = $base_url . "/css/browsers{$min}.css?ver=" . $version; | |
| 1924 | - $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 | + } | |
| 1925 | 2567 | $styles[] = plugins_url('css/extension/gravity.css?v=' . time(), $this->helper->get('plugin_file_path')); |
| 1926 | 2568 | } |
| 2569 | + return $styles; | |
| 2570 | + } | |
| 1927 | 2571 | |
| 1928 | - 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; | |
| 1929 | 2588 | } |
| 1930 | 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 | + } | |
| 1931 | 2722 | } |