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