| @@ -1,11 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * E2pdf Caldera Extension | |
| 5 | - * | |
| 4 | + * E2Pdf Caldera 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.01.47 |
| 11 | 10 | */ |
| @@ -15,45 +14,34 @@ | ||
| 15 | 14 | |
| 16 | 15 | class Extension_E2pdf_Caldera extends Model_E2pdf_Model { |
| 17 | 16 | |
| 18 | 17 | private $options; |
| 18 | + private $info = array( | |
| 19 | + 'key' => 'caldera', | |
| 20 | + 'title' => 'Caldera Forms', | |
| 21 | + ); | |
| 19 | 22 | |
| 20 | - function __construct() { | |
| 21 | - parent::__construct(); | |
| 22 | - } | |
| 23 | - | |
| 24 | 23 | /** |
| 25 | 24 | * Get info about extension |
| 26 | - * | |
| 27 | - * @return array() - Extension key and name | |
| 25 | + * @param string $key - Key to get assigned extension info value | |
| 26 | + * @return array|string - Extension Key and Title or Assigned extension info value | |
| 28 | 27 | */ |
| 29 | - public function info() { | |
| 30 | - return array( | |
| 31 | - 'caldera' => __('Caldera', 'e2pdf') | |
| 32 | - ); | |
| 28 | + public function info($key = false) { | |
| 29 | + if ($key && isset($this->info[$key])) { | |
| 30 | + return $this->info[$key]; | |
| 31 | + } else { | |
| 32 | + return array( | |
| 33 | + $this->info['key'] => $this->info['title'], | |
| 34 | + ); | |
| 35 | + } | |
| 33 | 36 | } |
| 34 | 37 | |
| 35 | 38 | /** |
| 36 | - * Check if export item function available | |
| 37 | - * | |
| 38 | - * @return bool - Item export available/not available | |
| 39 | - */ | |
| 40 | - public function export() { | |
| 41 | - return false; | |
| 42 | - } | |
| 43 | - | |
| 44 | - /** | |
| 45 | 39 | * Check if needed plugin active |
| 46 | - * | |
| 47 | 40 | * @return bool - Activated/Not Activated plugin |
| 48 | 41 | */ |
| 49 | 42 | public function active() { |
| 50 | - | |
| 51 | - if (!function_exists('is_plugin_active')) { | |
| 52 | - include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); | |
| 53 | - } | |
| 54 | - | |
| 55 | - if (is_plugin_active('caldera-forms/caldera-core.php')) { | |
| 43 | + if (defined('E2PDF_CALDERA_EXTENSION') || $this->helper->load('extension')->is_plugin_active('caldera-forms/caldera-core.php')) { | |
| 56 | 44 | return true; |
| 57 | 45 | } |
| 58 | 46 | return false; |
| 59 | 47 | } |
| @@ -59,12 +47,10 @@ | ||
| 59 | 47 | } |
| 60 | 48 | |
| 61 | 49 | /** |
| 62 | 50 | * Set option |
| 63 | - * | |
| 64 | 51 | * @param string $key - Key of option |
| 65 | 52 | * @param string $value - Value of option |
| 66 | - * | |
| 67 | 53 | * @return bool - Status of setting option |
| 68 | 54 | */ |
| 69 | 55 | public function set($key, $value) { |
| 70 | 56 | if (!isset($this->options)) { |
| @@ -69,44 +55,109 @@ | ||
| 69 | 55 | public function set($key, $value) { |
| 70 | 56 | if (!isset($this->options)) { |
| 71 | 57 | $this->options = new stdClass(); |
| 72 | 58 | } |
| 59 | + $this->options->$key = $value; | |
| 60 | + switch ($key) { | |
| 61 | + case 'item': | |
| 62 | + global $form; | |
| 63 | + $this->set('cached_form', false); | |
| 64 | + $this->set('cached_tmp_form', false); | |
| 65 | + if (class_exists('Caldera_Forms_Forms') && $this->get('item')) { | |
| 66 | + if ($form && isset($form['ID'])) { | |
| 67 | + $this->set('cached_tmp_form', $form); | |
| 68 | + if ($form['ID'] != $this->get('item')) { | |
| 69 | + $form = Caldera_Forms_Forms::get_form($this->get('item')); | |
| 70 | + } | |
| 71 | + } | |
| 72 | + if ($form == null) { | |
| 73 | + $form = Caldera_Forms_Forms::get_form($this->get('item')); | |
| 74 | + } | |
| 75 | + if (isset($form['_last_updated'])) { | |
| 76 | + $this->set('cached_form', $form); | |
| 77 | + } | |
| 78 | + } | |
| 79 | + break; | |
| 80 | + case 'dataset': | |
| 81 | + $this->set('cached_entry', false); | |
| 82 | + if (class_exists('Caldera_Forms_Entry') && class_exists('Caldera_Forms') && $this->get('cached_form') && $this->get('dataset')) { | |
| 83 | + $entry = new Caldera_Forms_Entry($this->get('cached_form'), $this->get('dataset')); | |
| 84 | + if ($entry->found()) { | |
| 85 | + $this->set('cached_entry', $entry); | |
| 86 | + } | |
| 87 | + if (!empty($this->get('cached_form')['is_connected_form'])) { | |
| 88 | + $form = $this->get('cached_form'); | |
| 89 | + $form['processors']['_connected_form'] = array( | |
| 90 | + 'type' => 'form-connector', | |
| 91 | + 'runtimes' => array( | |
| 92 | + 'insert' => true, | |
| 93 | + ), | |
| 94 | + 'config' => array(), | |
| 95 | + ); | |
| 96 | + $form_fields = array(); | |
| 97 | + $meta = Caldera_Forms::get_entry_meta((int) $this->get('dataset'), $form); | |
| 98 | + if (!empty($meta['form-connector']['data']['_connected_form']['entry']['form']['meta_value'])) { | |
| 99 | + foreach ((array) $meta['form-connector']['data']['_connected_form']['entry']['form']['meta_value'] as $form_meta) { | |
| 100 | + $form_fields = array_merge($form_fields, $form_meta); | |
| 101 | + } | |
| 102 | + } | |
| 103 | + if (!empty($form['condition_points']['forms'])) { | |
| 104 | + $form['fields'] = array(); | |
| 105 | + foreach ($form['condition_points']['forms'] as $connected_id => $connected_form) { | |
| 106 | + if (!empty($form_fields[$connected_id]) && !empty($connected_form['fields'])) { | |
| 107 | + $form['fields'] = array_merge($form['fields'], $connected_form['fields']); | |
| 108 | + } | |
| 109 | + } | |
| 73 | 110 | |
| 74 | - $this->options->$key = $value; | |
| 111 | + if (function_exists('cf_form_connector_setup_processors_meta')) { | |
| 112 | + add_filter('caldera_forms_get_entry_detail', 'cf_form_connector_setup_processors_meta', 10, 3); | |
| 113 | + } | |
| 114 | + } | |
| 115 | + if (isset($form['node']) && function_exists('cf_from_connector_merge_fields')) { | |
| 116 | + $form['fields'] = cf_from_connector_merge_fields($form); | |
| 117 | + } | |
| 118 | + $this->set('cached_form', $form); | |
| 119 | + } | |
| 120 | + } | |
| 121 | + break; | |
| 122 | + default: | |
| 123 | + break; | |
| 124 | + } | |
| 75 | 125 | return true; |
| 76 | 126 | } |
| 77 | 127 | |
| 78 | 128 | /** |
| 79 | 129 | * Get option by key |
| 80 | - * | |
| 81 | 130 | * @param string $key - Key to get assigned option value |
| 82 | - * | |
| 83 | 131 | * @return mixed |
| 84 | 132 | */ |
| 85 | 133 | public function get($key) { |
| 86 | 134 | if (isset($this->options->$key)) { |
| 87 | 135 | $value = $this->options->$key; |
| 88 | - return $value; | |
| 89 | 136 | } else { |
| 90 | - return false; | |
| 137 | + switch ($key) { | |
| 138 | + case 'args': | |
| 139 | + $value = array(); | |
| 140 | + break; | |
| 141 | + default: | |
| 142 | + $value = false; | |
| 143 | + break; | |
| 144 | + } | |
| 91 | 145 | } |
| 146 | + return $value; | |
| 92 | 147 | } |
| 93 | 148 | |
| 94 | 149 | /** |
| 95 | 150 | * Get items to work with |
| 96 | - * | |
| 97 | 151 | * @return array() - List of available items |
| 98 | 152 | */ |
| 99 | - public function get_items() { | |
| 153 | + public function items() { | |
| 100 | 154 | $content = array(); |
| 101 | - if (class_exists("Caldera_Forms_Forms")) { | |
| 155 | + if (class_exists('Caldera_Forms_Forms')) { | |
| 102 | 156 | $forms = Caldera_Forms_Forms::get_forms(true); |
| 103 | 157 | if ($forms) { |
| 104 | 158 | foreach ($forms as $key => $value) { |
| 105 | - $content[] = array( | |
| 106 | - 'key' => $value['ID'], | |
| 107 | - 'value' => $value['name'] | |
| 108 | - ); | |
| 159 | + $content[] = $this->item($value['ID']); | |
| 109 | 160 | } |
| 110 | 161 | } |
| 111 | 162 | } |
| 112 | 163 | return $content; |
| @@ -113,283 +164,488 @@ | ||
| 113 | 164 | } |
| 114 | 165 | |
| 115 | 166 | /** |
| 116 | 167 | * Get entries for export |
| 117 | - * | |
| 118 | - * @param int $item - Form ID | |
| 168 | + * @param int $item_id - Item ID | |
| 119 | 169 | * @param string $name - Entries names |
| 120 | - * | |
| 121 | 170 | * @return array() - Entries list |
| 122 | 171 | */ |
| 123 | - public function get_datasets($item = false, $name = false) { | |
| 124 | - | |
| 172 | + public function datasets($item_id = false, $name = false) { | |
| 125 | 173 | $datasets = array(); |
| 126 | - | |
| 127 | - if (class_exists("Caldera_Forms_Admin") && $item) { | |
| 128 | - | |
| 129 | - $form = Caldera_Forms_Admin::get_entries($item, 1, 9999999999); | |
| 130 | - | |
| 174 | + if (class_exists('Caldera_Forms_Admin') && $item_id) { | |
| 175 | + $form = Caldera_Forms_Admin::get_entries($item_id, 1, 9999999999); | |
| 131 | 176 | if ($form && isset($form['entries']) && is_array($form['entries'])) { |
| 132 | - foreach ($form['entries'] as $key => $dataset) { | |
| 133 | - $this->set('item', $item); | |
| 134 | - $this->set('dataset', $dataset['_entry_id']); | |
| 135 | - | |
| 136 | - $dataset_title = $this->render($name); | |
| 137 | - if (!$dataset_title) { | |
| 138 | - $dataset_title = $dataset['_date']; | |
| 177 | + $this->set('item', $item_id); | |
| 178 | + foreach ($form['entries'] as $key => $entry) { | |
| 179 | + $this->set('dataset', $entry['_entry_id']); | |
| 180 | + $entry_title = $this->render($name); | |
| 181 | + if (!$entry_title) { | |
| 182 | + $entry_title = $entry['_date']; | |
| 139 | 183 | } |
| 140 | 184 | $datasets[] = array( |
| 141 | - 'key' => $dataset['_entry_id'], | |
| 142 | - 'value' => $dataset_title | |
| 185 | + 'key' => $entry['_entry_id'], | |
| 186 | + 'value' => $entry_title, | |
| 143 | 187 | ); |
| 144 | 188 | } |
| 145 | 189 | } |
| 146 | 190 | } |
| 147 | - | |
| 148 | - | |
| 149 | 191 | return $datasets; |
| 150 | 192 | } |
| 151 | 193 | |
| 152 | 194 | /** |
| 153 | - * Get dataset | |
| 154 | - * | |
| 155 | - * @param int $dataset - Dataset ID | |
| 156 | - * | |
| 157 | - * @return object - Dataset | |
| 195 | + * Get Dataset Actions | |
| 196 | + * @param int $dataset_id - Dataset ID | |
| 197 | + * @return object | |
| 158 | 198 | */ |
| 159 | - public function get_dataset($dataset = false) { | |
| 160 | - $dataset = (int) $dataset; | |
| 161 | - | |
| 162 | - if (!$dataset) { | |
| 199 | + public function get_dataset_actions($dataset_id = false) { | |
| 200 | + $dataset_id = (int) $dataset_id; | |
| 201 | + if (!$dataset_id) { | |
| 163 | 202 | return false; |
| 164 | 203 | } |
| 204 | + $actions = new stdClass(); | |
| 205 | + $actions->view = false; | |
| 206 | + $actions->delete = false; | |
| 207 | + return $actions; | |
| 208 | + } | |
| 165 | 209 | |
| 166 | - $data = new stdClass(); | |
| 167 | - $data->url = false; | |
| 168 | - | |
| 169 | - return $data; | |
| 210 | + /** | |
| 211 | + * Get Template Actions | |
| 212 | + * @param int $template - Template ID | |
| 213 | + * @return object | |
| 214 | + */ | |
| 215 | + public function get_template_actions($template = false) { | |
| 216 | + $template = (int) $template; | |
| 217 | + if (!$template) { | |
| 218 | + return; | |
| 219 | + } | |
| 220 | + $actions = new stdClass(); | |
| 221 | + $actions->delete = false; | |
| 222 | + return $actions; | |
| 170 | 223 | } |
| 171 | 224 | |
| 172 | 225 | /** |
| 173 | 226 | * Get item |
| 174 | - * | |
| 175 | - * @param string $item - Item ID | |
| 176 | - * | |
| 227 | + * @param string $item_id - Item ID | |
| 177 | 228 | * @return object - Item |
| 178 | 229 | */ |
| 179 | - public function get_item($item = false) { | |
| 180 | - | |
| 181 | - $form = new stdClass(); | |
| 182 | - | |
| 183 | - $caldera_form = false; | |
| 184 | - if (class_exists("Caldera_Forms_Forms")) { | |
| 185 | - $caldera_form = Caldera_Forms_Forms::get_form($item); | |
| 230 | + public function item($item_id = false) { | |
| 231 | + if (!$item_id && $this->get('item')) { | |
| 232 | + $item_id = $this->get('item'); | |
| 186 | 233 | } |
| 187 | - | |
| 188 | - if ($caldera_form) { | |
| 189 | - $form->url = $this->helper->get_url(array('page' => 'caldera-forms', 'edit' => $caldera_form['ID'])); | |
| 190 | - $form->name = $caldera_form['name']; | |
| 234 | + $form = false; | |
| 235 | + if (class_exists('Caldera_Forms_Forms')) { | |
| 236 | + $form = Caldera_Forms_Forms::get_form($item_id); | |
| 237 | + } | |
| 238 | + $item = new stdClass(); | |
| 239 | + if ($form) { | |
| 240 | + $item->id = (string) $form['ID']; | |
| 241 | + $item->url = $this->helper->get_url( | |
| 242 | + array( | |
| 243 | + 'page' => 'caldera-forms', | |
| 244 | + 'edit' => $form['ID'], | |
| 245 | + ) | |
| 246 | + ); | |
| 247 | + $item->name = isset($form['name']) ? $form['name'] : ''; | |
| 191 | 248 | } else { |
| 192 | - $form->url = 'javascript:void(0);'; | |
| 193 | - $form->name = ''; | |
| 249 | + $item->id = ''; | |
| 250 | + $item->url = ''; | |
| 251 | + $item->name = ''; | |
| 194 | 252 | } |
| 195 | - return $form; | |
| 253 | + return $item; | |
| 196 | 254 | } |
| 197 | 255 | |
| 198 | 256 | /** |
| 199 | 257 | * Render value according to content |
| 200 | - * | |
| 201 | 258 | * @param string $value - Content |
| 202 | 259 | * @param string $type - Type of rendering value |
| 203 | 260 | * @param array $field - Field details |
| 204 | - * | |
| 205 | 261 | * @return string - Fully rendered value |
| 206 | 262 | */ |
| 207 | - public function render($value, $type = false, $field = array()) { | |
| 208 | - | |
| 209 | - $value = $this->render_shortcodes($value, $type, $field); | |
| 210 | - $value = $this->strip_shortcodes($value); | |
| 211 | - | |
| 212 | - if ($type === 'value' && isset($field['type']) && $field['type'] === 'e2pdf-checkbox' && isset($field['properties']['option'])) { | |
| 213 | - $option = $this->render($field['properties']['option']); | |
| 214 | - $options = explode(', ', $value); | |
| 215 | - $option_options = explode(', ', $option); | |
| 216 | - if (is_array($options) && is_array($option_options) && !array_diff($option_options, $options)) { | |
| 217 | - return $option; | |
| 218 | - } else { | |
| 219 | - return ""; | |
| 220 | - } | |
| 263 | + public function render($value, $field = array(), $convert_shortcodes = true, $raw = false) { | |
| 264 | + $value = $this->render_shortcodes($value, $field); | |
| 265 | + if (!$raw) { | |
| 266 | + $value = $this->strip_shortcodes($value); | |
| 267 | + $value = $this->convert_shortcodes($value, $convert_shortcodes, isset($field['type']) && $field['type'] == 'e2pdf-html' ? true : false); | |
| 268 | + $value = $this->helper->load('field')->render_checkbox($value, $this, $field); | |
| 221 | 269 | } |
| 222 | - | |
| 223 | 270 | return $value; |
| 224 | 271 | } |
| 225 | 272 | |
| 226 | 273 | /** |
| 227 | 274 | * Render shortcodes which available in this extension |
| 228 | - * | |
| 229 | 275 | * @param string $value - Content |
| 230 | 276 | * @param string $type - Type of rendering value |
| 231 | 277 | * @param array $field - Field details |
| 232 | - * | |
| 233 | 278 | * @return string - Value with rendered shortcodes |
| 234 | 279 | */ |
| 235 | - public function render_shortcodes($value, $type = false, $field = array()) { | |
| 236 | - | |
| 237 | - $dataset = $this->get('dataset'); | |
| 238 | - | |
| 239 | - if ($this->verify() && class_exists("Caldera_Forms_Entry") && class_exists("Caldera_Forms_Forms") && class_exists("Caldera_Forms")) { | |
| 280 | + public function render_shortcodes($value, $field = array()) { | |
| 281 | + $element_id = isset($field['element_id']) ? $field['element_id'] : false; | |
| 282 | + if ($this->verify()) { | |
| 240 | 283 | if (false !== strpos($value, '[')) { |
| 241 | - | |
| 242 | - $shortcode_tags = array( | |
| 243 | - 'e2pdf-format-number', | |
| 244 | - 'e2pdf-format-date', | |
| 245 | - 'e2pdf-format-output', | |
| 246 | - ); | |
| 247 | - preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches); | |
| 248 | - $tagnames = array_intersect($shortcode_tags, $matches[1]); | |
| 249 | - | |
| 250 | - if (!empty($tagnames)) { | |
| 251 | - | |
| 252 | - $pattern = get_shortcode_regex($tagnames); | |
| 253 | - preg_match_all("/$pattern/", $value, $shortcodes); | |
| 254 | - foreach ($shortcodes[0] as $key => $shortcode_value) { | |
| 255 | - $shortcode = array(); | |
| 256 | - $shortcode[1] = $shortcodes[1][$key]; | |
| 257 | - $shortcode[2] = $shortcodes[2][$key]; | |
| 258 | - $shortcode[3] = $shortcodes[3][$key]; | |
| 259 | - $shortcode[4] = $shortcodes[4][$key]; | |
| 260 | - $shortcode[5] = $shortcodes[5][$key]; | |
| 261 | - $shortcode[6] = $shortcodes[6][$key]; | |
| 262 | - | |
| 263 | - if (isset($shortcode['5'])) { | |
| 264 | - $sub_value = $this->strip_shortcodes(Caldera_Forms::do_magic_tags($shortcode['5'], $dataset)); | |
| 265 | - $value = str_replace($shortcode_value, "[" . $shortcode['2'] . $shortcode['3'] . "]" . $sub_value . "[/" . $shortcode['2'] . "]", $value); | |
| 266 | - } | |
| 267 | - } | |
| 268 | - } | |
| 284 | + $value = $this->helper->load('field')->pre_shortcodes($value, $this, $field); | |
| 285 | + $value = $this->helper->load('field')->inner_shortcodes($value, $this, $field); | |
| 286 | + $value = $this->helper->load('field')->wrapper_shortcodes($value, $this, $field); | |
| 269 | 287 | } |
| 288 | + $value = $this->helper->load('field')->do_shortcodes($value, $this, $field); | |
| 270 | 289 | |
| 271 | - $value = do_shortcode($value); | |
| 272 | - | |
| 273 | 290 | add_filter('caldera_forms_magic_form', array($this, 'filter_caldera_forms_magic_form'), 30, 2); |
| 274 | 291 | add_filter('caldera_forms_render_get_field', array($this, 'filter_caldera_forms_render_get_field'), 30, 2); |
| 275 | - add_filter('caldera_forms_do_field_magic_value', array($this, 'filter_caldera_forms_do_field_magic_value'), 30, 4); | |
| 292 | + add_filter('caldera_forms_pre_do_field_magic', array($this, 'filter_caldera_forms_pre_do_field_magic'), 30, 5); | |
| 293 | + add_filter('caldera_forms_get_field_entry', array($this, 'filter_caldera_forms_get_field_entry'), 30, 4); | |
| 294 | + add_filter('caldera_forms_pre_check_condition', array($this, 'filter_caldera_forms_pre_check_condition'), 30); | |
| 276 | 295 | |
| 277 | - $value = Caldera_Forms::do_magic_tags($value, $dataset); | |
| 278 | - | |
| 279 | - if (isset($field['type']) && ($field['type'] === 'e2pdf-image' || $field['type'] === 'e2pdf-signature')) { | |
| 280 | - $esig = isset($field['properties']['esig']) && $field['properties']['esig'] ? true : false; | |
| 281 | - if ($esig) { | |
| 282 | - //process e-signature | |
| 283 | - $value = ""; | |
| 284 | - } else { | |
| 285 | - $helper_e2pdf_image = new Helper_E2pdf_Image(); | |
| 286 | - if (!$helper_e2pdf_image->get_image($value)) { | |
| 287 | - $value = $this->strip_shortcodes($value); | |
| 288 | - if ( | |
| 289 | - $value && | |
| 290 | - trim($value) != "" && | |
| 291 | - extension_loaded('gd') && | |
| 292 | - function_exists('imagettftext') | |
| 293 | - ) { | |
| 294 | - if (isset($field['properties']['text_color']) && $field['properties']['text_color']) { | |
| 295 | - $penColour = $this->helper->hexColorAllocate($field['properties']['text_color']); | |
| 296 | - } else { | |
| 297 | - $penColour = array(0x14, 0x53, 0x94); | |
| 298 | - } | |
| 299 | - | |
| 300 | - $default_options = array( | |
| 301 | - 'imageSize' => array(isset($field['width']) ? $field['width'] : '400', isset($field['height']) ? $field['height'] : '150'), | |
| 302 | - 'bgColour' => 'transparent', | |
| 303 | - 'penColour' => $penColour | |
| 304 | - ); | |
| 305 | - | |
| 306 | - $options = array(); | |
| 307 | - $options = array_merge($default_options, $options); | |
| 308 | - | |
| 309 | - $model_e2pdf_font = new Model_E2pdf_Font(); | |
| 310 | - | |
| 311 | - $font = false; | |
| 312 | - if (isset($field['properties']['text_font']) && $field['properties']['text_font']) { | |
| 313 | - $font = $model_e2pdf_font->get_font_path($field['properties']['text_font']); | |
| 314 | - } | |
| 315 | - if (!$font) { | |
| 316 | - $font = $model_e2pdf_font->get_font_path('Noto Sans'); | |
| 317 | - } | |
| 318 | - | |
| 319 | - $size = 150; | |
| 320 | - if (isset($field['properties']['text_font_size']) && $field['properties']['text_font_size']) { | |
| 321 | - $size = $field['properties']['text_font_size']; | |
| 322 | - } | |
| 323 | - | |
| 324 | - $model_e2pdf_signature = new Model_E2pdf_Signature(); | |
| 325 | - $value = $model_e2pdf_signature->ttf_signature($value, $size, $font, $options); | |
| 326 | - } else { | |
| 327 | - $value = ""; | |
| 328 | - } | |
| 329 | - } | |
| 330 | - } | |
| 296 | + global $form; | |
| 297 | + if ($this->get('cached_form')) { | |
| 298 | + $form = $this->get('cached_form'); | |
| 331 | 299 | } |
| 300 | + $value = Caldera_Forms::do_magic_tags($value, $this->get('dataset')); | |
| 301 | + if ($this->get('cached_tmp_form')) { | |
| 302 | + $form = $this->get('cached_tmp_form'); | |
| 303 | + } | |
| 304 | + $value = $this->helper->load('field')->render( | |
| 305 | + apply_filters('e2pdf_extension_render_shortcodes_pre_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false), | |
| 306 | + $this, | |
| 307 | + $field | |
| 308 | + ); | |
| 332 | 309 | |
| 333 | 310 | remove_filter('caldera_forms_magic_form', array($this, 'filter_caldera_forms_magic_form'), 30); |
| 334 | 311 | remove_filter('caldera_forms_render_get_field', array($this, 'filter_caldera_forms_render_get_field'), 30); |
| 335 | - remove_filter('caldera_forms_do_field_magic_value', array($this, 'filter_caldera_forms_do_field_magic_value'), 30); | |
| 312 | + remove_filter('caldera_forms_pre_do_field_magic', array($this, 'filter_caldera_forms_pre_do_field_magic'), 30); | |
| 313 | + remove_filter('caldera_forms_get_field_entry', array($this, 'filter_caldera_forms_get_field_entry'), 30); | |
| 314 | + remove_filter('caldera_forms_pre_check_condition', array($this, 'filter_caldera_forms_pre_check_condition'), 30); | |
| 336 | 315 | } |
| 337 | - | |
| 338 | - return $value; | |
| 316 | + return apply_filters( | |
| 317 | + 'e2pdf_extension_render_shortcodes_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false | |
| 318 | + ); | |
| 339 | 319 | } |
| 340 | 320 | |
| 341 | 321 | /** |
| 342 | 322 | * Strip unused shortcodes |
| 343 | - * | |
| 344 | 323 | * @param string $value - Content |
| 345 | - * | |
| 346 | 324 | * @return string - Value with removed unused shortcodes |
| 347 | 325 | */ |
| 348 | 326 | public function strip_shortcodes($value) { |
| 349 | - $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', "", $value); | |
| 350 | - $value = preg_replace('~(?:%/?)[^/%]+/?%~', "", $value); | |
| 327 | + $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', '', $value); | |
| 328 | + $value = preg_replace('~%[a-z0-9_]*%~', '', $value); | |
| 351 | 329 | return $value; |
| 352 | 330 | } |
| 353 | 331 | |
| 354 | - public function verify() { | |
| 355 | - $item = $this->get('item'); | |
| 356 | - $dataset = $this->get('dataset'); | |
| 332 | + // strip math | |
| 333 | + public function strip_math($value, &$replacements) { | |
| 334 | + if ($value) { | |
| 335 | + preg_match_all('/%[a-z0-9_]*%/', $value, $matches); | |
| 336 | + foreach ($matches[0] as $match) { | |
| 337 | + $index = count($replacements) + 1; | |
| 338 | + $replacements[] = $match; | |
| 339 | + $value = str_replace($match, '%' . $index . '$s', $value); | |
| 340 | + } | |
| 341 | + } | |
| 342 | + return $value; | |
| 343 | + } | |
| 357 | 344 | |
| 358 | - if ($item && $dataset && class_exists('Caldera_Forms_Entry') && class_exists('Caldera_Forms_Forms')) { | |
| 359 | - $form = Caldera_Forms_Forms::get_form($item); | |
| 360 | - if ($form && isset($form['_last_updated'])) { | |
| 361 | - $entry = new Caldera_Forms_Entry($form, $dataset); | |
| 362 | - if ($entry->found()) { | |
| 363 | - return true; | |
| 345 | + /** | |
| 346 | + * Convert shortcodes inside value string | |
| 347 | + * @param string $value - Value string | |
| 348 | + * @param bool $to - Convert From/To | |
| 349 | + * @return string - Converted value | |
| 350 | + */ | |
| 351 | + public function convert_shortcodes($value, $to = false, $html = false) { | |
| 352 | + if ($value) { | |
| 353 | + if ($to) { | |
| 354 | + $value = stripslashes_deep($value); | |
| 355 | + $value = str_replace('[', '[', $value); | |
| 356 | + if (!$html) { | |
| 357 | + $value = wp_specialchars_decode($value, ENT_QUOTES); | |
| 364 | 358 | } |
| 359 | + } else { | |
| 360 | + $value = str_replace('[', '[', $value); | |
| 365 | 361 | } |
| 366 | 362 | } |
| 363 | + return $value; | |
| 364 | + } | |
| 365 | + | |
| 366 | + /** | |
| 367 | + * Verify if item and dataset exists | |
| 368 | + * @return bool - item and dataset exists | |
| 369 | + */ | |
| 370 | + public function verify() { | |
| 371 | + if ($this->get('cached_entry')) { | |
| 372 | + return true; | |
| 373 | + } | |
| 367 | 374 | return false; |
| 368 | 375 | } |
| 369 | 376 | |
| 370 | - public function visual_mapper() { | |
| 377 | + /** | |
| 378 | + * Create Form based on uploaded PDF | |
| 379 | + * @param object $template - Template Object to work with | |
| 380 | + * @param array $data - Settings to create labels/shortcodes | |
| 381 | + * @return object - Mapped Template Object | |
| 382 | + */ | |
| 383 | + public function auto_form($template, $data = array()) { | |
| 384 | + if ($template->get('ID')) { | |
| 385 | + $auto_form_label = isset($data['auto_form_label']) && $data['auto_form_label'] ? $data['auto_form_label'] : false; | |
| 386 | + $auto_form_shortcode = isset($data['auto_form_shortcode']) ? true : false; | |
| 387 | + $form = array( | |
| 388 | + '_last_updated' => date('r'), | |
| 389 | + 'success' => sprintf(__('Success. [e2pdf-download id="%s"]', 'e2pdf'), $template->get('ID')), | |
| 390 | + 'name' => $template->get('title'), | |
| 391 | + 'db_support' => '1', | |
| 392 | + 'hide_form' => '1', | |
| 393 | + 'form_ajax' => '1', | |
| 394 | + 'custom_callback' => '', | |
| 395 | + 'fields' => array(), | |
| 396 | + 'layout_grid' => array( | |
| 397 | + 'fields' => array(), | |
| 398 | + 'strucutre' => '', | |
| 399 | + ), | |
| 400 | + 'settings' => array( | |
| 401 | + 'responsive' => array( | |
| 402 | + 'break_point' => 'sm', | |
| 403 | + ), | |
| 404 | + ), | |
| 405 | + ); | |
| 406 | + $pages = $template->get('pages'); | |
| 407 | + $checkboxes = array(); | |
| 408 | + $radios = array(); | |
| 409 | + foreach ($pages as $page_key => $page) { | |
| 410 | + if (isset($page['elements']) && !empty($page['elements'])) { | |
| 411 | + foreach ($page['elements'] as $element_key => $element) { | |
| 412 | + $type = false; | |
| 413 | + $label = ''; | |
| 414 | + if ($element['type'] == 'e2pdf-input' || $element['type'] == 'e2pdf-signature') { | |
| 415 | + $type = 'text'; | |
| 416 | + $label = 'Text'; | |
| 417 | + } elseif ($element['type'] == 'e2pdf-textarea') { | |
| 418 | + $type = 'paragraph'; | |
| 419 | + $label = 'Textarea'; | |
| 420 | + } elseif ($element['type'] == 'e2pdf-select') { | |
| 421 | + $type = 'dropdown'; | |
| 422 | + $label = 'Select'; | |
| 423 | + $options = array(); | |
| 424 | + $field_options = array(); | |
| 425 | + if (isset($element['properties']['options'])) { | |
| 426 | + $field_options = explode("\n", $element['properties']['options']); | |
| 427 | + foreach ($field_options as $option) { | |
| 428 | + $option_id = 'opt' . $this->random(); | |
| 429 | + $options[$option_id] = array( | |
| 430 | + 'calc_value' => '', | |
| 431 | + 'label' => $option, | |
| 432 | + 'value' => $option, | |
| 433 | + ); | |
| 434 | + } | |
| 435 | + } | |
| 436 | + } elseif ($element['type'] == 'e2pdf-checkbox') { | |
| 437 | + $field_key = array_search($element['name'], array_column($checkboxes, 'name'), false); | |
| 438 | + if ($field_key !== false) { | |
| 439 | + $option_id = 'opt' . $this->random(); | |
| 440 | + $checkboxes[$field_key]['options'][$option_id] = array( | |
| 441 | + 'calc_value' => $element['properties']['option'], | |
| 442 | + 'label' => $element['properties']['option'], | |
| 443 | + 'value' => $element['properties']['option'], | |
| 444 | + ); | |
| 445 | + $pages[$page_key]['elements'][$element_key]['value'] = '%element_' . $checkboxes[$field_key]['element_id'] . '%'; | |
| 446 | + } else { | |
| 447 | + $type = 'checkbox'; | |
| 448 | + $label = 'Checkbox'; | |
| 449 | + } | |
| 450 | + } elseif ($element['type'] == 'e2pdf-radio') { | |
| 451 | + if (isset($element['properties']['group']) && $element['properties']['group']) { | |
| 452 | + $element['name'] = $element['properties']['group']; | |
| 453 | + } else { | |
| 454 | + $element['name'] = $element['element_id']; | |
| 455 | + } | |
| 456 | + $field_key = array_search($element['name'], array_column($radios, 'name'), false); | |
| 457 | + if ($field_key !== false) { | |
| 458 | + $option_id = 'opt' . $this->random(); | |
| 459 | + $radios[$field_key]['options'][$option_id] = array( | |
| 460 | + 'calc_value' => $element['properties']['option'], | |
| 461 | + 'label' => $element['properties']['option'], | |
| 462 | + 'value' => $element['properties']['option'], | |
| 463 | + ); | |
| 464 | + $pages[$page_key]['elements'][$element_key]['value'] = '%element_' . $radios[$field_key]['element_id'] . '%'; | |
| 465 | + } else { | |
| 466 | + $type = 'radio'; | |
| 467 | + $label = 'Radio'; | |
| 468 | + } | |
| 469 | + } | |
| 470 | + if ($type) { | |
| 471 | + $labels = array(); | |
| 472 | + if ($auto_form_shortcode) { | |
| 473 | + $labels[] = '%element_' . $element['element_id'] . '%'; | |
| 474 | + } | |
| 475 | + if ($auto_form_label && $auto_form_label == 'value' && isset($element['value']) && $element['value']) { | |
| 476 | + $labels[] = $element['value']; | |
| 477 | + } elseif ($auto_form_label && $auto_form_label == 'name' && isset($element['name']) && $element['name']) { | |
| 478 | + $labels[] = $element['name']; | |
| 479 | + } | |
| 480 | + if ($type == 'checkbox' || $type == 'radio') { | |
| 481 | + $field_id = 'opt' . $this->random(); | |
| 482 | + $field_data = array( | |
| 483 | + 'name' => $element['name'], | |
| 484 | + 'element_id' => $element['element_id'], | |
| 485 | + 'label' => !empty($labels) ? implode(' ', $labels) : $label, | |
| 486 | + 'options' => array( | |
| 487 | + $field_id => array( | |
| 488 | + 'calc_value' => $element['properties']['option'], | |
| 489 | + 'label' => $element['properties']['option'], | |
| 490 | + 'value' => $element['properties']['option'], | |
| 491 | + ), | |
| 492 | + ), | |
| 493 | + ); | |
| 494 | + if ($type == 'checkbox') { | |
| 495 | + $checkboxes[] = $field_data; | |
| 496 | + } else { | |
| 497 | + $radios[] = $field_data; | |
| 498 | + } | |
| 499 | + } else { | |
| 500 | + $field_id = 'fld_' . $this->random(); | |
| 501 | + $form['fields'][$field_id] = array( | |
| 502 | + 'ID' => $field_id, | |
| 503 | + 'slug' => 'element_' . $element['element_id'], | |
| 504 | + 'type' => $type, | |
| 505 | + 'label' => !empty($labels) ? implode(' ', $labels) : $label, | |
| 506 | + ); | |
| 371 | 507 | |
| 372 | - $item = $this->get('item'); | |
| 508 | + if ($type == 'select') { | |
| 509 | + $form['fields'][$field_id]['config'] = array( | |
| 510 | + 'option' => $options, | |
| 511 | + ); | |
| 512 | + } | |
| 513 | + } | |
| 514 | + $pages[$page_key]['elements'][$element_key]['value'] = '%element_' . $element['element_id'] . '%'; | |
| 515 | + if (isset($element['properties']['esig'])) { | |
| 516 | + unset($pages[$page_key]['elements'][$element_key]['properties']['esig']); | |
| 517 | + } | |
| 518 | + } | |
| 519 | + } | |
| 520 | + } | |
| 521 | + } | |
| 522 | + foreach ($checkboxes as $element) { | |
| 523 | + $field_id = 'fld_' . $this->random(); | |
| 524 | + $form['fields'][$field_id] = array( | |
| 525 | + 'ID' => $field_id, | |
| 526 | + 'slug' => 'element_' . $element['element_id'], | |
| 527 | + 'type' => 'checkbox', | |
| 528 | + 'label' => $element['label'], | |
| 529 | + 'config' => array( | |
| 530 | + 'option' => $element['options'], | |
| 531 | + ), | |
| 532 | + ); | |
| 533 | + } | |
| 534 | + foreach ($radios as $element) { | |
| 535 | + $field_id = 'fld_' . $this->random(); | |
| 536 | + $form['fields'][$field_id] = array( | |
| 537 | + 'ID' => $field_id, | |
| 538 | + 'slug' => 'element_' . $element['element_id'], | |
| 539 | + 'type' => 'radio', | |
| 540 | + 'label' => $element['label'], | |
| 541 | + 'config' => array( | |
| 542 | + 'option' => $element['options'], | |
| 543 | + ), | |
| 544 | + ); | |
| 545 | + } | |
| 546 | + $field_id = 'fld_' . $this->random(); | |
| 547 | + $form['fields'][$field_id] = array( | |
| 548 | + 'ID' => $field_id, | |
| 549 | + 'slug' => 'submit', | |
| 550 | + 'type' => 'button', | |
| 551 | + 'label' => 'Submit', | |
| 552 | + 'class' => 'btn btn-default', | |
| 553 | + ); | |
| 373 | 554 | |
| 374 | - if ($item && class_exists("Caldera_Forms") && class_exists("Caldera_Forms_Forms") && class_exists("Caldera_Forms_Field_Util")) { | |
| 555 | + $fields = array_keys($form['fields']); | |
| 556 | + $x = 1; | |
| 557 | + foreach ($fields as $field) { | |
| 558 | + $form['layout_grid']['fields'][$field] = $x . ':1'; | |
| 559 | + if ($x == 1) { | |
| 560 | + $form['layout_grid']['structure'] .= '12'; | |
| 561 | + } else { | |
| 562 | + $form['layout_grid']['structure'] .= '|12'; | |
| 563 | + } | |
| 564 | + $x++; | |
| 565 | + } | |
| 566 | + $item = Caldera_Forms_Forms::create_form($form); | |
| 567 | + if ($item) { | |
| 568 | + $template->set('item', $item['ID']); | |
| 569 | + $template->set('pages', $pages); | |
| 570 | + } | |
| 571 | + } | |
| 572 | + return $template; | |
| 573 | + } | |
| 375 | 574 | |
| 376 | - $source = Caldera_Forms::render_form($item); | |
| 575 | + /** | |
| 576 | + * Generate Random number for Field ID | |
| 577 | + * @return int - Generated number | |
| 578 | + */ | |
| 579 | + private function random() { | |
| 580 | + return round((float) rand() / (float) getrandmax() * 10000000); | |
| 581 | + } | |
| 377 | 582 | |
| 378 | - $form = Caldera_Forms_Forms::get_form($item); | |
| 379 | - | |
| 380 | - libxml_use_internal_errors(true); | |
| 381 | - $dom = new DOMDocument; | |
| 382 | - $html = $dom->loadHTML($source); | |
| 383 | - libxml_clear_errors(); | |
| 384 | - | |
| 385 | - if (!$html) { | |
| 386 | - return __('Form could not be parsed due incorrect HTML', 'e2pdf'); | |
| 583 | + /** | |
| 584 | + * Init Visual Mapper data | |
| 585 | + * @return bool|string - HTML data source for Visual Mapper | |
| 586 | + */ | |
| 587 | + public function visual_mapper() { | |
| 588 | + $forms = array(); | |
| 589 | + $source = ''; | |
| 590 | + $html = ''; | |
| 591 | + if ($this->get('item') && class_exists('Caldera_Forms') && class_exists('Caldera_Forms_Forms') && class_exists('Caldera_Forms_Field_Util')) { | |
| 592 | + add_filter('caldera_forms_render_get_form', array($this, 'filter_caldera_forms_render_get_form')); | |
| 593 | + $form = Caldera_Forms_Forms::get_form($this->get('item')); | |
| 594 | + if (!empty($form['is_connected_form']) && isset($form['node']) && !empty($form['node'])) { | |
| 595 | + foreach ($form['node'] as $node) { | |
| 596 | + if (isset($node['form']) && $node['form']) { | |
| 597 | + $source .= Caldera_Forms::render_form($node['form']); | |
| 598 | + $forms[] = Caldera_Forms_Forms::get_form($node['form']); | |
| 599 | + } | |
| 600 | + } | |
| 387 | 601 | } else { |
| 602 | + $source = Caldera_Forms::render_form($this->get('item')); | |
| 603 | + } | |
| 604 | + remove_filter('caldera_forms_render_get_form', array($this, 'filter_caldera_forms_render_get_form')); | |
| 605 | + if ($source) { | |
| 606 | + $dom = new DOMDocument(); | |
| 607 | + $html = $this->helper->load('convert')->load_html($source, $dom, true); | |
| 608 | + } | |
| 609 | + if (!$source) { | |
| 610 | + return '<div class="e2pdf-vm-error">' . __("The form source is empty or doesn't exist", 'e2pdf') . '</div>'; | |
| 611 | + } elseif (!$html) { | |
| 612 | + return '<div class="e2pdf-vm-error">' . __('The form could not be parsed due the incorrect HTML', 'e2pdf') . '</div>'; | |
| 613 | + } else { | |
| 614 | + $xml = $this->helper->load('xml'); | |
| 615 | + $xpath = new DomXPath($dom); | |
| 388 | 616 | |
| 389 | - $xpath = new DomXPath($dom); | |
| 617 | + $conditional_fields = $xpath->query("//*[contains(@class, 'caldera-forms-conditional-field')]"); | |
| 618 | + foreach ($conditional_fields as $element) { | |
| 619 | + $conditional_field_id = $xml->get_node_value($element, 'data-field-id'); | |
| 620 | + if ($conditional_field_id) { | |
| 621 | + preg_match('/<script type="text\/html" id="conditional-' . $conditional_field_id . '-tmpl">(.*?)<\/script>/s', $source, $matches); | |
| 622 | + if (isset($matches[1])) { | |
| 623 | + $conditional_dom = new DOMDocument(); | |
| 624 | + $conditional_dom_html = $this->helper->load('convert')->load_html($matches[1], $dom); | |
| 625 | + if ($conditional_dom_html) { | |
| 626 | + $element->appendChild($dom->importNode($conditional_dom->documentElement, true)); | |
| 627 | + } | |
| 628 | + } | |
| 629 | + } | |
| 630 | + } | |
| 390 | 631 | |
| 632 | + // remove by name | |
| 633 | + $remove_by_name = array( | |
| 634 | + '_cf_verify', | |
| 635 | + '_wp_http_referer', | |
| 636 | + '_cf_frm_id', | |
| 637 | + '_cf_frm_ct', | |
| 638 | + 'cfajax', | |
| 639 | + ); | |
| 640 | + foreach ($remove_by_name as $key => $name) { | |
| 641 | + $elements = $xpath->query('//*[@name="' . $name . '"]'); | |
| 642 | + foreach ($elements as $element) { | |
| 643 | + $element->parentNode->removeChild($element); | |
| 644 | + } | |
| 645 | + } | |
| 391 | 646 | |
| 647 | + // remove by class | |
| 392 | 648 | $remove_by_class = array( |
| 393 | 649 | 'live-gravatar', |
| 394 | 650 | ); |
| 395 | 651 | foreach ($remove_by_class as $key => $class) { |
| @@ -398,117 +654,127 @@ | ||
| 398 | 654 | $element->parentNode->removeChild($element); |
| 399 | 655 | } |
| 400 | 656 | } |
| 401 | 657 | |
| 658 | + // remove by tag | |
| 402 | 659 | $remove_by_tag = array( |
| 403 | - 'script' | |
| 660 | + 'script', | |
| 404 | 661 | ); |
| 405 | 662 | foreach ($remove_by_tag as $key => $tag) { |
| 406 | - $elements = $xpath->query("//{$tag}"); | |
| 663 | + $elements = $xpath->query('//' . $tag); | |
| 407 | 664 | foreach ($elements as $element) { |
| 408 | 665 | $element->parentNode->removeChild($element); |
| 409 | 666 | } |
| 410 | 667 | } |
| 411 | 668 | |
| 412 | - | |
| 413 | - // Replace names | |
| 414 | 669 | $fields = $xpath->query("//*[contains(@name, 'fld_')]"); |
| 415 | 670 | foreach ($fields as $element) { |
| 416 | - if ($element->attributes->getNamedItem("type")->nodeValue == 'checkbox') { | |
| 417 | - preg_match("/(.*?)\[(.*?)\]/i", $element->attributes->getNamedItem("name")->nodeValue, $matches); | |
| 671 | + $field_id = false; | |
| 672 | + if ($xml->get_node_value($element, 'type') == 'checkbox') { | |
| 673 | + preg_match('/(.*?)\[(.*?)\]/i', $xml->get_node_value($element, 'name'), $matches); | |
| 418 | 674 | if (isset($matches[1])) { |
| 419 | 675 | $field_id = $matches[1]; |
| 420 | 676 | } |
| 421 | 677 | } else { |
| 422 | - $field_id = $element->attributes->getNamedItem("name")->nodeValue; | |
| 678 | + $field_id = $xml->get_node_value($element, 'name'); | |
| 423 | 679 | } |
| 424 | 680 | |
| 425 | - | |
| 426 | - // Modify Star field | |
| 427 | - if ($element->attributes->getNamedItem("data-type")->nodeValue == 'star') { | |
| 428 | - $element->attributes->getNamedItem("style")->nodeValue = ''; | |
| 681 | + // modify rating field | |
| 682 | + if ($xml->get_node_value($element, 'data-type') == 'star') { | |
| 683 | + $xml->set_node_value($element, 'style', ''); | |
| 429 | 684 | } |
| 430 | 685 | |
| 431 | - // Modify Range field | |
| 432 | - if ($element->attributes->getNamedItem("type")->nodeValue == 'range') { | |
| 433 | - $element->parentNode->attributes->getNamedItem("style")->nodeValue = ''; | |
| 434 | - $element->parentNode->attributes->getNamedItem("class")->nodeValue = 'col-xs-12'; | |
| 435 | - | |
| 436 | - $next_element = $xpath->query(".//following-sibling::div[1]", $element->parentNode)->item(0); | |
| 437 | - $next_element->parentNode->removeChild($next_element); | |
| 686 | + // modify range field | |
| 687 | + if ($xml->get_node_value($element, 'type') == 'range') { | |
| 688 | + $xml->set_node_value($element, 'style', '', true); | |
| 689 | + $xml->set_node_value($element, 'class', 'col-xs-12', true); | |
| 690 | + $next_element = $xpath->query('.//following-sibling::div[1]', $element->parentNode)->item(0); | |
| 691 | + if ($next_element) { | |
| 692 | + $next_element->parentNode->removeChild($next_element); | |
| 693 | + } | |
| 438 | 694 | } |
| 439 | 695 | |
| 440 | - | |
| 441 | - $field = Caldera_Forms_Field_Util::get_field($field_id, $form); | |
| 442 | - if ($field && isset($field['slug'])) { | |
| 443 | - $element->attributes->getNamedItem("name")->nodeValue = "%" . $field['slug'] . "%"; | |
| 696 | + if ($field_id) { | |
| 697 | + if (!empty($form['is_connected_form'])) { | |
| 698 | + foreach ($forms as $sub_form) { | |
| 699 | + $field = Caldera_Forms_Field_Util::get_field($field_id, $sub_form); | |
| 700 | + if ($field && isset($field['slug'])) { | |
| 701 | + $xml->set_node_value($element, 'name', '%' . $field['slug'] . '%'); | |
| 702 | + break; | |
| 703 | + } | |
| 704 | + } | |
| 705 | + } else { | |
| 706 | + $field = Caldera_Forms_Field_Util::get_field($field_id, $form); | |
| 707 | + if ($field && isset($field['slug'])) { | |
| 708 | + $xml->set_node_value($element, 'name', '%' . $field['slug'] . '%'); | |
| 709 | + } | |
| 710 | + } | |
| 444 | 711 | } |
| 445 | 712 | } |
| 446 | 713 | |
| 447 | - // Convert Calculation Fields | |
| 714 | + // calculation | |
| 448 | 715 | $calculation_fields = $xpath->query("//input[@data-type='calculation']"); |
| 449 | - foreach ($calculation_fields as $calculation_field) { | |
| 450 | - $calculation_field->attributes->getNamedItem("type")->nodeValue = 'text'; | |
| 716 | + foreach ($calculation_fields as $element) { | |
| 717 | + $xml->set_node_value($element, 'type', 'text'); | |
| 718 | + $xml->set_node_value($element, 'class', $xml->get_node_value($element, 'class') . ' form-control'); | |
| 719 | + $calculation_text = $xpath->query('.//h3', $element->parentNode)->item(0); | |
| 720 | + if ($calculation_text) { | |
| 721 | + $element->parentNode->removeChild($calculation_text); | |
| 722 | + } | |
| 723 | + } | |
| 451 | 724 | |
| 452 | - $calculation_text = $xpath->query(".//h3", $calculation_field->parentNode)->item(0); | |
| 453 | - $calculation_field->parentNode->removeChild($calculation_text); | |
| 725 | + // file upload | |
| 726 | + $file_uploads = $xpath->query("//input[@type='file']"); | |
| 727 | + foreach ($file_uploads as $element) { | |
| 728 | + $xml->set_node_value($element, 'class', $xml->get_node_value($element, 'type') . ' form-control'); | |
| 454 | 729 | } |
| 455 | 730 | |
| 456 | - | |
| 457 | - // Modify Toggle Fields | |
| 731 | + // toggle | |
| 458 | 732 | $toggle_gorups = $xpath->query("//*[contains(@class, 'cf-toggle-switch')]"); |
| 459 | - foreach ($toggle_gorups as $toogle_group) { | |
| 460 | - $toggle_elements = $xpath->query(".//*[contains(@class, 'cf-toggle-group-buttons')]//a", $toogle_group); | |
| 461 | - foreach ($toggle_elements as $toggle_element) { | |
| 462 | - $toggle_id = $toggle_element->attributes->getNamedItem("id")->nodeValue; | |
| 463 | - | |
| 464 | - $radio = $toggle_elements = $xpath->query(".//input[@id='{$toggle_id}']", $toogle_group)->item(0); | |
| 465 | - | |
| 466 | - if ($radio) { | |
| 467 | - $radio_cloned = $radio->cloneNode(true); | |
| 468 | - | |
| 469 | - $attr = $dom->createAttribute('style'); | |
| 470 | - $attr->value = 'position: absolute;width: 100%;top: 0;left: 0;height: 100%; opacity: 0;'; | |
| 471 | - $radio_cloned->appendChild($attr); | |
| 472 | - | |
| 473 | - $toggle_element->appendChild($radio_cloned); | |
| 733 | + foreach ($toggle_gorups as $element) { | |
| 734 | + $toggle_elements = $xpath->query(".//*[contains(@class, 'cf-toggle-group-buttons')]//a", $element); | |
| 735 | + foreach ($toggle_elements as $sub_element) { | |
| 736 | + if ($sub_element->attributes->getNamedItem('id')) { | |
| 737 | + $toggle_id = $xml->get_node_value($sub_element, 'id'); | |
| 738 | + $radio = $xpath->query(".//input[@id='{$toggle_id}']", $element)->item(0); | |
| 739 | + if ($radio) { | |
| 740 | + $radio_cloned = $radio->cloneNode(true); | |
| 741 | + $xml->set_node_value($radio_cloned, 'style', 'position: absolute;width: 100%;top: 0;left: 0;height: 100%; opacity: 0;'); | |
| 742 | + $sub_element->appendChild($radio_cloned); | |
| 743 | + } | |
| 474 | 744 | } |
| 475 | 745 | } |
| 476 | 746 | } |
| 477 | 747 | |
| 478 | - // Modify Advanced File Upload | |
| 748 | + // ajax uploader | |
| 479 | 749 | $advanced_uploaders = $xpath->query("//*[contains(@class, 'cf-uploader-trigger')]"); |
| 480 | - foreach ($advanced_uploaders as $advanced_uploader) { | |
| 481 | - $input = $xpath->query(".//input[@type='hidden']", $advanced_uploader->parentNode)->item(0); | |
| 482 | - | |
| 483 | - | |
| 750 | + foreach ($advanced_uploaders as $element) { | |
| 751 | + $input = $xpath->query(".//input[@type='hidden']", $element->parentNode)->item(0); | |
| 484 | 752 | $attr = $dom->createAttribute('style'); |
| 485 | 753 | $attr->value = 'position: relative;'; |
| 486 | - $advanced_uploader->appendChild($attr); | |
| 487 | - | |
| 488 | - | |
| 754 | + $element->appendChild($attr); | |
| 489 | 755 | if ($input) { |
| 490 | 756 | $input_cloned = $input->cloneNode(true); |
| 491 | - $attr = $dom->createAttribute('style'); | |
| 492 | - $attr->value = 'position: absolute;width: 100%;top: 0;left: 0;height: 100%; opacity: 0;'; | |
| 493 | - $input_cloned->appendChild($attr); | |
| 757 | + $xml->set_node_value($input_cloned, 'style', 'position: absolute;width: 100%;top: 0;left: 0;height: 100%; opacity: 0;'); | |
| 758 | + $xml->set_node_value($input_cloned, 'type', 'text'); | |
| 759 | + $element->appendChild($input_cloned); | |
| 760 | + } | |
| 761 | + } | |
| 494 | 762 | |
| 495 | - $input_cloned->attributes->getNamedItem('type')->nodeValue = 'text'; | |
| 496 | - | |
| 497 | - $advanced_uploader->appendChild($input_cloned); | |
| 498 | - } | |
| 763 | + $textareas = $xpath->query('//textarea'); | |
| 764 | + foreach ($textareas as $element) { | |
| 765 | + $xml->set_node_value($element, 'rows', '4'); | |
| 499 | 766 | } |
| 500 | 767 | |
| 501 | - // Remove unecessary elements | |
| 502 | 768 | $submit_buttons = $xpath->query("//input[@type='submit']"); |
| 503 | - foreach ($submit_buttons as $submit_button) { | |
| 504 | - $submit_button->parentNode->removeChild($submit_button); | |
| 769 | + foreach ($submit_buttons as $element) { | |
| 770 | + $element->parentNode->removeChild($element); | |
| 505 | 771 | } |
| 506 | - | |
| 507 | - | |
| 508 | - | |
| 509 | - | |
| 510 | - return $dom->saveHTML(); | |
| 772 | + if (defined('LIBXML_HTML_NOIMPLIED') && defined('LIBXML_HTML_NODEFDTD')) { | |
| 773 | + return str_replace(array('<html>', '</html>'), '', $dom->saveHTML()); | |
| 774 | + } else { | |
| 775 | + return $dom->saveHTML(); | |
| 776 | + } | |
| 511 | 777 | } |
| 512 | 778 | } |
| 513 | 779 | return false; |
| 514 | 780 | } |
| @@ -514,314 +780,357 @@ | ||
| 514 | 780 | } |
| 515 | 781 | |
| 516 | 782 | /** |
| 517 | 783 | * Auto Generate of Template for this extension |
| 518 | - * | |
| 519 | 784 | * @return array - List of elements |
| 520 | 785 | */ |
| 521 | 786 | public function auto() { |
| 522 | 787 | $response = array(); |
| 523 | 788 | $elements = array(); |
| 524 | - | |
| 525 | - $item = $this->get('item'); | |
| 526 | - | |
| 527 | 789 | $fields = array(); |
| 528 | - | |
| 529 | - if (class_exists("Caldera_Forms_Forms")) { | |
| 530 | - $form = Caldera_Forms_Forms::get_form($item); | |
| 531 | - if ($form && isset($form['fields'])) { | |
| 790 | + $forms = array(); | |
| 791 | + if (class_exists('Caldera_Forms_Forms')) { | |
| 792 | + $form = Caldera_Forms_Forms::get_form($this->get('item')); | |
| 793 | + if (!empty($form['is_connected_form']) && isset($form['node']) && !empty($form['node'])) { | |
| 794 | + foreach ($form['node'] as $node) { | |
| 795 | + if (isset($node['form']) && $node['form']) { | |
| 796 | + $sub_form = Caldera_Forms_Forms::get_form($node['form']); | |
| 797 | + $forms[] = $sub_form; | |
| 798 | + if ($sub_form && isset($sub_form['fields']) && is_array($sub_form['fields'])) { | |
| 799 | + $fields = array_merge($fields, $sub_form['fields']); | |
| 800 | + } | |
| 801 | + } | |
| 802 | + } | |
| 803 | + } else { | |
| 804 | + $forms[] = $form; | |
| 532 | 805 | $fields = $form['fields']; |
| 533 | 806 | } |
| 534 | - } | |
| 807 | + foreach ($forms as $sub_form) { | |
| 808 | + if (isset($sub_form['layout_grid']['structure']) && $sub_form['layout_grid']['structure']) { | |
| 809 | + $sub_form['layout_grid']['structure'] = str_replace('#', '|', $sub_form['layout_grid']['structure']); | |
| 810 | + } | |
| 811 | + if ($sub_form && isset($sub_form['layout_grid']['structure']) && isset($sub_form['layout_grid']['fields'])) { | |
| 812 | + $struct = explode('|', $sub_form['layout_grid']['structure']); | |
| 813 | + foreach ($struct as $row_num => $row) { | |
| 814 | + $float = false; | |
| 815 | + $columns = explode(':', $row); | |
| 816 | + foreach ($columns as $column_num => $column) { | |
| 817 | + $column_fields = array_keys($sub_form['layout_grid']['fields'], ($row_num + 1) . ':' . ($column_num + 1)); | |
| 818 | + $width = 100 / (12 / $column) . '%'; | |
| 819 | + foreach ($column_fields as $column_field_key) { | |
| 820 | + if (isset($fields[$column_field_key])) { | |
| 821 | + $field = $fields[$column_field_key]; | |
| 822 | + switch ($field['type']) { | |
| 823 | + case 'text': | |
| 824 | + case 'email': | |
| 825 | + case 'phone_better': | |
| 826 | + case 'phone_better': | |
| 827 | + case 'number': | |
| 828 | + case 'phone': | |
| 829 | + case 'url': | |
| 830 | + case 'date_picker': | |
| 831 | + case 'color_picker': | |
| 832 | + case 'credit_card_number': | |
| 833 | + case 'credit_card_exp': | |
| 834 | + case 'credit_card_cvc': | |
| 835 | + case 'calculation': | |
| 836 | + case 'range_slider': | |
| 837 | + case 'star_rating': | |
| 838 | + case 'utm': | |
| 839 | + $elements[] = $this->auto_field( | |
| 840 | + $field, | |
| 841 | + array( | |
| 842 | + 'type' => 'e2pdf-html', | |
| 843 | + 'block' => true, | |
| 844 | + 'float' => $float, | |
| 845 | + 'properties' => array( | |
| 846 | + 'top' => '20', | |
| 847 | + 'left' => '20', | |
| 848 | + 'right' => '20', | |
| 849 | + 'width' => $width, | |
| 850 | + 'height' => 'auto', | |
| 851 | + 'value' => $field['label'], | |
| 852 | + ), | |
| 853 | + ) | |
| 854 | + ); | |
| 535 | 855 | |
| 856 | + $elements[] = $this->auto_field( | |
| 857 | + $field, | |
| 858 | + array( | |
| 859 | + 'type' => 'e2pdf-input', | |
| 860 | + 'properties' => array( | |
| 861 | + 'top' => '5', | |
| 862 | + 'width' => '100%', | |
| 863 | + 'height' => 'auto', | |
| 864 | + 'value' => '%' . $field['slug'] . '%', | |
| 865 | + ), | |
| 866 | + ) | |
| 867 | + ); | |
| 868 | + break; | |
| 869 | + case 'file': | |
| 870 | + case 'advanced_file': | |
| 871 | + case 'cf2_file': | |
| 872 | + case 'paragraph': | |
| 873 | + $elements[] = $this->auto_field( | |
| 874 | + $field, | |
| 875 | + array( | |
| 876 | + 'type' => 'e2pdf-html', | |
| 877 | + 'block' => true, | |
| 878 | + 'float' => $float, | |
| 879 | + 'properties' => array( | |
| 880 | + 'top' => '20', | |
| 881 | + 'left' => '20', | |
| 882 | + 'right' => '20', | |
| 883 | + 'width' => $width, | |
| 884 | + 'height' => 'auto', | |
| 885 | + 'value' => $field['label'], | |
| 886 | + ), | |
| 887 | + ) | |
| 888 | + ); | |
| 536 | 889 | |
| 537 | - if ($form && isset($form['layout_grid']['structure']) && isset($form['layout_grid']['fields'])) { | |
| 538 | - $struct = explode('|', $form['layout_grid']['structure']); | |
| 539 | - foreach ($struct as $row_num => $row) { | |
| 890 | + $elements[] = $this->auto_field( | |
| 891 | + $field, | |
| 892 | + array( | |
| 893 | + 'type' => 'e2pdf-textarea', | |
| 894 | + 'properties' => array( | |
| 895 | + 'top' => '5', | |
| 896 | + 'width' => '100%', | |
| 897 | + 'height' => '150', | |
| 898 | + 'value' => '%' . $field['slug'] . '%', | |
| 899 | + ), | |
| 900 | + ) | |
| 901 | + ); | |
| 902 | + break; | |
| 903 | + case 'wysiwyg': | |
| 904 | + case 'html': | |
| 905 | + case 'summary': | |
| 906 | + $elements[] = $this->auto_field( | |
| 907 | + $field, | |
| 908 | + array( | |
| 909 | + 'type' => 'e2pdf-html', | |
| 910 | + 'block' => true, | |
| 911 | + 'float' => $float, | |
| 912 | + 'properties' => array( | |
| 913 | + 'top' => '20', | |
| 914 | + 'left' => '20', | |
| 915 | + 'right' => '20', | |
| 916 | + 'width' => $width, | |
| 917 | + 'height' => 'auto', | |
| 918 | + 'value' => $field['label'], | |
| 919 | + ), | |
| 920 | + ) | |
| 921 | + ); | |
| 540 | 922 | |
| 541 | - $float = false; | |
| 923 | + $elements[] = $this->auto_field( | |
| 924 | + $field, | |
| 925 | + array( | |
| 926 | + 'type' => 'e2pdf-html', | |
| 927 | + 'properties' => array( | |
| 928 | + 'top' => '5', | |
| 929 | + 'width' => '100%', | |
| 930 | + 'height' => '150', | |
| 931 | + 'value' => '%' . $field['slug'] . '%', | |
| 932 | + ), | |
| 933 | + ) | |
| 934 | + ); | |
| 935 | + break; | |
| 936 | + case 'dropdown': | |
| 937 | + case 'filtered_select2': | |
| 938 | + case 'states': | |
| 939 | + $elements[] = $this->auto_field( | |
| 940 | + $field, | |
| 941 | + array( | |
| 942 | + 'type' => 'e2pdf-html', | |
| 943 | + 'block' => true, | |
| 944 | + 'float' => $float, | |
| 945 | + 'properties' => array( | |
| 946 | + 'top' => '20', | |
| 947 | + 'left' => '20', | |
| 948 | + 'right' => '20', | |
| 949 | + 'width' => $width, | |
| 950 | + 'height' => 'auto', | |
| 951 | + 'value' => $field['label'], | |
| 952 | + ), | |
| 953 | + ) | |
| 954 | + ); | |
| 542 | 955 | |
| 543 | - $columns = explode(':', $row); | |
| 544 | - foreach ($columns as $column_num => $column) { | |
| 545 | - $column_fields = array_keys($form['layout_grid']['fields'], ( $row_num + 1) . ':' . ( $column_num + 1)); | |
| 956 | + $options_tmp = array(); | |
| 546 | 957 | |
| 547 | - $width = 100 / (12 / $column) . "%"; | |
| 548 | - | |
| 549 | - foreach ($column_fields as $column_field_key) { | |
| 550 | - if (isset($fields[$column_field_key])) { | |
| 551 | - $field = $fields[$column_field_key]; | |
| 552 | - | |
| 553 | - | |
| 554 | - switch ($field['type']) { | |
| 555 | - case 'text': | |
| 556 | - case 'email': | |
| 557 | - case 'phone_better': | |
| 558 | - case 'phone_better': | |
| 559 | - case 'number': | |
| 560 | - case 'phone': | |
| 561 | - case 'url': | |
| 562 | - case 'date_picker': | |
| 563 | - case 'color_picker': | |
| 564 | - case 'credit_card_number': | |
| 565 | - case 'credit_card_exp': | |
| 566 | - case 'credit_card_cvc': | |
| 567 | - case 'calculation': | |
| 568 | - case 'range_slider': | |
| 569 | - case 'star_rating': | |
| 570 | - case 'utm': | |
| 571 | - case 'file': | |
| 572 | - case 'advanced_file': | |
| 573 | - $elements[] = $this->auto_field($field, 'e2pdf-html', array( | |
| 574 | - 'top' => '20', | |
| 575 | - 'left' => '20', | |
| 576 | - 'right' => '20', | |
| 577 | - 'block' => true, | |
| 578 | - 'float' => $float, | |
| 579 | - 'width' => $width, | |
| 580 | - 'properties' => array( | |
| 581 | - 'value' => $field['label'], | |
| 582 | - ) | |
| 583 | - )); | |
| 584 | - | |
| 585 | - | |
| 586 | - $elements[] = $this->auto_field($field, 'e2pdf-input', array( | |
| 587 | - 'properties' => array( | |
| 588 | - 'value' => "%{$field['slug']}%", | |
| 589 | - ) | |
| 590 | - )); | |
| 591 | - break; | |
| 592 | - | |
| 593 | - | |
| 594 | - case 'paragraph': | |
| 595 | - | |
| 596 | - $elements[] = $this->auto_field($field, 'e2pdf-html', array( | |
| 597 | - 'top' => '20', | |
| 598 | - 'left' => '20', | |
| 599 | - 'right' => '20', | |
| 600 | - 'block' => true, | |
| 601 | - 'float' => $float, | |
| 602 | - 'width' => $width, | |
| 603 | - 'properties' => array( | |
| 604 | - 'value' => $field['label'], | |
| 605 | - ) | |
| 606 | - )); | |
| 607 | - | |
| 608 | - $elements[] = $this->auto_field($field, 'e2pdf-textarea', array( | |
| 609 | - 'properties' => array( | |
| 610 | - 'value' => "%{$field['slug']}%", | |
| 611 | - ) | |
| 612 | - )); | |
| 613 | - break; | |
| 614 | - | |
| 615 | - | |
| 616 | - case 'wysiwyg': | |
| 617 | - case 'html': | |
| 618 | - case 'summary': | |
| 619 | - $elements[] = $this->auto_field($field, 'e2pdf-html', array( | |
| 620 | - 'top' => '20', | |
| 621 | - 'left' => '20', | |
| 622 | - 'right' => '20', | |
| 623 | - 'block' => true, | |
| 624 | - 'float' => $float, | |
| 625 | - 'width' => $width, | |
| 626 | - 'properties' => array( | |
| 627 | - 'value' => $field['label'], | |
| 628 | - ) | |
| 629 | - )); | |
| 630 | - | |
| 631 | - $elements[] = $this->auto_field($field, 'e2pdf-html', array( | |
| 632 | - 'properties' => array( | |
| 633 | - 'height' => '100', | |
| 634 | - 'value' => "%{$field['slug']}%", | |
| 635 | - ) | |
| 636 | - )); | |
| 637 | - break; | |
| 638 | - | |
| 639 | - | |
| 640 | - case 'dropdown': | |
| 641 | - case 'filtered_select2': | |
| 642 | - case 'states': | |
| 643 | - $elements[] = $this->auto_field($field, 'e2pdf-html', array( | |
| 644 | - 'top' => '20', | |
| 645 | - 'left' => '20', | |
| 646 | - 'right' => '20', | |
| 647 | - 'block' => true, | |
| 648 | - 'float' => $float, | |
| 649 | - 'width' => $width, | |
| 650 | - 'properties' => array( | |
| 651 | - 'value' => $field['label'], | |
| 652 | - ) | |
| 653 | - )); | |
| 654 | - | |
| 655 | - $options_tmp = array(); | |
| 656 | - | |
| 657 | - if (isset($field['config']['option']) && is_array($field['config']['option'])) { | |
| 658 | - foreach ($field['config']['option'] as $opt_key => $option) { | |
| 659 | - if (is_array($option)) { | |
| 660 | - $options_tmp[] = $option['value']; | |
| 958 | + if (isset($field['config']['option']) && is_array($field['config']['option'])) { | |
| 959 | + foreach ($field['config']['option'] as $opt_key => $option) { | |
| 960 | + if (is_array($option)) { | |
| 961 | + $options_tmp[] = $option['value']; | |
| 962 | + } | |
| 963 | + } | |
| 661 | 964 | } |
| 662 | - } | |
| 663 | - } | |
| 664 | 965 | |
| 665 | - if ($field['type'] == 'states' && defined("CFCORE_PATH")) { | |
| 666 | - if (file_exists(CFCORE_PATH . "fields/states/field.php")) { | |
| 667 | - $contents = file_get_contents(CFCORE_PATH . "fields/states/field.php"); | |
| 668 | - preg_match_all('/<option value="(.*?)">(.*?)<\/option>/', $contents, $matches); | |
| 669 | - if (isset($matches[1])) { | |
| 670 | - foreach ($matches[1] as $state) { | |
| 671 | - $options_tmp[] = $state; | |
| 966 | + if ($field['type'] == 'states' && defined('CFCORE_PATH')) { | |
| 967 | + if (file_exists(CFCORE_PATH . 'fields/states/field.php')) { | |
| 968 | + $contents = file_get_contents(CFCORE_PATH . 'fields/states/field.php'); | |
| 969 | + preg_match_all('/<option value="(.*?)">(.*?)<\/option>/', $contents, $matches); | |
| 970 | + if (isset($matches[1])) { | |
| 971 | + foreach ($matches[1] as $state) { | |
| 972 | + $options_tmp[] = $state; | |
| 973 | + } | |
| 974 | + } | |
| 672 | 975 | } |
| 673 | 976 | } |
| 674 | - } | |
| 675 | - } | |
| 676 | 977 | |
| 677 | - $elements[] = $this->auto_field($field, 'e2pdf-select', array( | |
| 678 | - 'properties' => array( | |
| 679 | - 'options' => implode("\n", $options_tmp), | |
| 680 | - 'value' => "%{$field['slug']}%", | |
| 681 | - ) | |
| 682 | - )); | |
| 683 | - break; | |
| 684 | - | |
| 685 | - | |
| 686 | - case 'checkbox': | |
| 687 | - $elements[] = $this->auto_field($field, 'e2pdf-html', array( | |
| 688 | - 'top' => '20', | |
| 689 | - 'left' => '20', | |
| 690 | - 'right' => '20', | |
| 691 | - 'block' => true, | |
| 692 | - 'float' => $float, | |
| 693 | - 'width' => $width, | |
| 694 | - 'properties' => array( | |
| 695 | - 'value' => $field['label'], | |
| 696 | - ) | |
| 697 | - )); | |
| 698 | - | |
| 699 | - $top = 0; | |
| 700 | - | |
| 701 | - | |
| 702 | - | |
| 703 | - if (isset($field['config']['option']) && is_array($field['config']['option'])) { | |
| 704 | - foreach ($field['config']['option'] as $opt_key => $option) { | |
| 705 | - if (is_array($option)) { | |
| 706 | - $elements[] = $this->auto_field($field, 'e2pdf-checkbox', array( | |
| 707 | - 'top' => $top, | |
| 708 | - 'properties' => array( | |
| 709 | - 'width' => '15', | |
| 710 | - 'height' => '15', | |
| 711 | - 'value' => "%{$field['slug']}%", | |
| 712 | - 'option' => $option['label'] | |
| 978 | + $elements[] = $this->auto_field( | |
| 979 | + $field, | |
| 980 | + array( | |
| 981 | + 'type' => 'e2pdf-select', | |
| 982 | + 'properties' => array( | |
| 983 | + 'top' => '5', | |
| 984 | + 'width' => '100%', | |
| 985 | + 'height' => 'auto', | |
| 986 | + 'options' => implode("\n", $options_tmp), | |
| 987 | + 'value' => '%' . $field['slug'] . '%', | |
| 988 | + ), | |
| 713 | 989 | ) |
| 714 | - )); | |
| 715 | - $elements[] = $this->auto_field($field, 'e2pdf-html', array( | |
| 716 | - 'top' => $top, | |
| 717 | - 'left' => '20', | |
| 718 | - 'properties' => array( | |
| 719 | - 'value' => $option['label'] | |
| 990 | + ); | |
| 991 | + break; | |
| 992 | + case 'checkbox': | |
| 993 | + $elements[] = $this->auto_field( | |
| 994 | + $field, | |
| 995 | + array( | |
| 996 | + 'type' => 'e2pdf-html', | |
| 997 | + 'block' => true, | |
| 998 | + 'float' => $float, | |
| 999 | + 'properties' => array( | |
| 1000 | + 'top' => '20', | |
| 1001 | + 'left' => '20', | |
| 1002 | + 'right' => '20', | |
| 1003 | + 'width' => $width, | |
| 1004 | + 'height' => 'auto', | |
| 1005 | + 'value' => $field['label'], | |
| 1006 | + ), | |
| 720 | 1007 | ) |
| 721 | - )); | |
| 1008 | + ); | |
| 1009 | + | |
| 1010 | + if (isset($field['config']['option']) && is_array($field['config']['option'])) { | |
| 1011 | + foreach ($field['config']['option'] as $opt_key => $option) { | |
| 1012 | + if (is_array($option)) { | |
| 1013 | + $elements[] = $this->auto_field( | |
| 1014 | + $field, | |
| 1015 | + array( | |
| 1016 | + 'type' => 'e2pdf-checkbox', | |
| 1017 | + 'properties' => array( | |
| 1018 | + 'top' => '5', | |
| 1019 | + 'width' => 'auto', | |
| 1020 | + 'height' => 'auto', | |
| 1021 | + 'value' => '%' . $field['slug'] . '%', | |
| 1022 | + 'option' => $option['value'], | |
| 1023 | + ), | |
| 1024 | + ) | |
| 1025 | + ); | |
| 1026 | + $elements[] = $this->auto_field( | |
| 1027 | + $field, | |
| 1028 | + array( | |
| 1029 | + 'type' => 'e2pdf-html', | |
| 1030 | + 'float' => true, | |
| 1031 | + 'properties' => array( | |
| 1032 | + 'left' => '5', | |
| 1033 | + 'width' => '100%', | |
| 1034 | + 'height' => 'auto', | |
| 1035 | + 'value' => $option['label'], | |
| 1036 | + ), | |
| 1037 | + ) | |
| 1038 | + ); | |
| 1039 | + } | |
| 1040 | + } | |
| 722 | 1041 | } |
| 723 | - $top = $top + 20; | |
| 724 | - } | |
| 725 | - } | |
| 726 | - break; | |
| 1042 | + break; | |
| 1043 | + case 'radio': | |
| 1044 | + case 'toggle_switch': | |
| 1045 | + $elements[] = $this->auto_field( | |
| 1046 | + $field, | |
| 1047 | + array( | |
| 1048 | + 'type' => 'e2pdf-html', | |
| 1049 | + 'block' => true, | |
| 1050 | + 'float' => $float, | |
| 1051 | + 'properties' => array( | |
| 1052 | + 'top' => '20', | |
| 1053 | + 'left' => '20', | |
| 1054 | + 'right' => '20', | |
| 1055 | + 'width' => $width, | |
| 1056 | + 'height' => 'auto', | |
| 1057 | + 'value' => $field['label'], | |
| 1058 | + ), | |
| 1059 | + ) | |
| 1060 | + ); | |
| 727 | 1061 | |
| 728 | - | |
| 729 | - case 'radio': | |
| 730 | - case 'toggle_switch': | |
| 731 | - $elements[] = $this->auto_field($field, 'e2pdf-html', array( | |
| 732 | - 'top' => '20', | |
| 733 | - 'left' => '20', | |
| 734 | - 'right' => '20', | |
| 735 | - 'block' => true, | |
| 736 | - 'float' => $float, | |
| 737 | - 'width' => $width, | |
| 738 | - 'properties' => array( | |
| 739 | - 'value' => $field['label'], | |
| 740 | - ) | |
| 741 | - )); | |
| 742 | - | |
| 743 | - $top = 0; | |
| 744 | - | |
| 745 | - | |
| 746 | - | |
| 747 | - if (isset($field['config']['option']) && is_array($field['config']['option'])) { | |
| 748 | - foreach ($field['config']['option'] as $opt_key => $option) { | |
| 749 | - if (is_array($option)) { | |
| 750 | - $elements[] = $this->auto_field($field, 'e2pdf-radio', array( | |
| 751 | - 'top' => $top, | |
| 752 | - 'properties' => array( | |
| 753 | - 'width' => '15', | |
| 754 | - 'height' => '15', | |
| 755 | - 'value' => "%{$field['slug']}%", | |
| 756 | - 'option' => $option['label'], | |
| 757 | - 'group' => "group_" . $field['slug'], | |
| 758 | - ) | |
| 759 | - )); | |
| 760 | - $elements[] = $this->auto_field($field, 'e2pdf-html', array( | |
| 761 | - 'top' => $top, | |
| 762 | - 'left' => '20', | |
| 763 | - 'properties' => array( | |
| 764 | - 'value' => $option['label'] | |
| 765 | - ) | |
| 766 | - )); | |
| 1062 | + if (isset($field['config']['option']) && is_array($field['config']['option'])) { | |
| 1063 | + foreach ($field['config']['option'] as $opt_key => $option) { | |
| 1064 | + if (is_array($option)) { | |
| 1065 | + $elements[] = $this->auto_field( | |
| 1066 | + $field, | |
| 1067 | + array( | |
| 1068 | + 'type' => 'e2pdf-radio', | |
| 1069 | + 'properties' => array( | |
| 1070 | + 'top' => '5', | |
| 1071 | + 'width' => 'auto', | |
| 1072 | + 'height' => 'auto', | |
| 1073 | + 'value' => '%' . $field['slug'] . '%', | |
| 1074 | + 'option' => $option['value'], | |
| 1075 | + 'group' => '%' . $field['slug'] . '%', | |
| 1076 | + ), | |
| 1077 | + ) | |
| 1078 | + ); | |
| 1079 | + $elements[] = $this->auto_field( | |
| 1080 | + $field, | |
| 1081 | + array( | |
| 1082 | + 'type' => 'e2pdf-html', | |
| 1083 | + 'float' => true, | |
| 1084 | + 'properties' => array( | |
| 1085 | + 'left' => '5', | |
| 1086 | + 'width' => '100%', | |
| 1087 | + 'height' => 'auto', | |
| 1088 | + 'value' => $option['label'], | |
| 1089 | + ), | |
| 1090 | + ) | |
| 1091 | + ); | |
| 1092 | + } | |
| 1093 | + } | |
| 767 | 1094 | } |
| 768 | - $top = $top + 20; | |
| 769 | - } | |
| 1095 | + break; | |
| 1096 | + default: | |
| 1097 | + /* Unsupported fields: section_break, live_gravatar, button */ | |
| 1098 | + break; | |
| 770 | 1099 | } |
| 771 | - break; | |
| 1100 | + } | |
| 1101 | + } | |
| 772 | 1102 | |
| 773 | - | |
| 774 | - | |
| 775 | - default: | |
| 776 | - /* | |
| 777 | - * Unsupported fields: section_break, live_gravatar, button | |
| 778 | - */ | |
| 779 | - break; | |
| 780 | - } | |
| 1103 | + $float = true; | |
| 781 | 1104 | } |
| 782 | 1105 | } |
| 783 | - | |
| 784 | - $float = true; | |
| 785 | 1106 | } |
| 786 | 1107 | } |
| 787 | 1108 | } |
| 788 | - | |
| 789 | - | |
| 790 | 1109 | $response['page'] = array( |
| 791 | 1110 | 'bottom' => '20', |
| 792 | 1111 | 'top' => '20', |
| 793 | 1112 | ); |
| 794 | - | |
| 795 | 1113 | $response['elements'] = $elements; |
| 796 | 1114 | return $response; |
| 797 | 1115 | } |
| 798 | 1116 | |
| 799 | - public function auto_field($field = false, $type = false, $options = array()) { | |
| 800 | - | |
| 801 | - if (!$field || !$type) { | |
| 1117 | + /** | |
| 1118 | + * Element generation for Auto PDF | |
| 1119 | + * @param array $field - Field options | |
| 1120 | + * @param array $element - Element options | |
| 1121 | + * @return array - Element with modified options | |
| 1122 | + */ | |
| 1123 | + public function auto_field($field = false, $element = array()) { | |
| 1124 | + if (!$field) { | |
| 802 | 1125 | return false; |
| 803 | 1126 | } |
| 804 | - | |
| 805 | - | |
| 806 | - $element = array( | |
| 807 | - 'type' => $type, | |
| 808 | - 'properties' => isset($options['properties']) ? $options['properties'] : array(), | |
| 809 | - ); | |
| 810 | - | |
| 811 | - | |
| 812 | - $element['top'] = isset($options['top']) ? $options['top'] : '0'; | |
| 813 | - $element['left'] = isset($options['left']) ? $options['left'] : '0'; | |
| 814 | - $element['right'] = isset($options['right']) ? $options['right'] : '0'; | |
| 815 | - $element['block'] = isset($options['block']) ? $options['block'] : false; | |
| 816 | - $element['float'] = isset($options['float']) ? $options['float'] : false; | |
| 817 | - | |
| 818 | - if (isset($options['width']) && $element['block']) { | |
| 819 | - $element['width'] = $options['width']; | |
| 1127 | + if (!isset($element['block'])) { | |
| 1128 | + $element['block'] = false; | |
| 820 | 1129 | } |
| 821 | - | |
| 822 | - | |
| 823 | - | |
| 1130 | + if (!isset($element['float'])) { | |
| 1131 | + $element['float'] = false; | |
| 1132 | + } | |
| 824 | 1133 | return $element; |
| 825 | 1134 | } |
| 826 | 1135 | |
| 827 | 1136 | /** |
| @@ -827,10 +1136,11 @@ | ||
| 827 | 1136 | /** |
| 828 | 1137 | * Load actions for this extension |
| 829 | 1138 | */ |
| 830 | 1139 | public function load_actions() { |
| 831 | - add_action('caldera_forms_submit_complete', array($this, 'action_caldera_forms_submit_complete'), 99, 3); | |
| 832 | - add_action('caldera_forms_mailer_complete', array($this, 'action_caldera_forms_mailer_complete'), 99, 3); | |
| 1140 | + add_action('caldera_forms_mailer_complete', array($this, 'action_caldera_forms_mailer_complete'), 99, 0); | |
| 1141 | + add_action('caldera_forms_mailer_failed', array($this, 'action_caldera_forms_mailer_complete'), 99, 0); | |
| 1142 | + add_action('caldera_forms_submit_complete', array($this, 'action_caldera_forms_mailer_complete'), 99, 0); | |
| 833 | 1143 | } |
| 834 | 1144 | |
| 835 | 1145 | /** |
| 836 | 1146 | * Delete attachments that were sent by email |
| @@ -835,11 +1145,9 @@ | ||
| 835 | 1145 | /** |
| 836 | 1146 | * Delete attachments that were sent by email |
| 837 | 1147 | */ |
| 838 | 1148 | public function action_caldera_forms_mailer_complete() { |
| 839 | - | |
| 840 | 1149 | $files = $this->helper->get('caldera_attachments'); |
| 841 | - | |
| 842 | 1150 | if (is_array($files) && !empty($files)) { |
| 843 | 1151 | foreach ($files as $key => $file) { |
| 844 | 1152 | $this->helper->delete_dir(dirname($file) . '/'); |
| 845 | 1153 | } |
| @@ -847,14 +1155,70 @@ | ||
| 847 | 1155 | } |
| 848 | 1156 | } |
| 849 | 1157 | |
| 850 | 1158 | /** |
| 1159 | + * Remove Page Breaks | |
| 1160 | + * @param array $form - Form | |
| 1161 | + * @return array - Form | |
| 1162 | + */ | |
| 1163 | + public function filter_caldera_forms_render_get_form($form) { | |
| 1164 | + if (isset($form['layout_grid']['structure']) && $form['layout_grid']['structure']) { | |
| 1165 | + $form['layout_grid']['structure'] = str_replace('#', '|', $form['layout_grid']['structure']); | |
| 1166 | + } | |
| 1167 | + return $form; | |
| 1168 | + } | |
| 1169 | + | |
| 1170 | + /** | |
| 1171 | + * Incorrectly rendered Checkbox Value | |
| 1172 | + * @param array $entry - Field | |
| 1173 | + * @param array $field_id - Field ID | |
| 1174 | + * @param array $form - Current Form | |
| 1175 | + * @param array $entry_id - Entry ID | |
| 1176 | + * @return mixed - Fixed entry | |
| 1177 | + */ | |
| 1178 | + public function filter_caldera_forms_get_field_entry($entry, $field_id, $form, $entry_id) { | |
| 1179 | + if (class_exists('Caldera_Forms_Field_Util') && $field_id) { | |
| 1180 | + if (Caldera_Forms_Field_Util::get_type($field_id, $form) == 'checkbox' && $entry && is_array($entry)) { | |
| 1181 | + $last = array_pop($entry); | |
| 1182 | + if ($last && is_array($last) && isset($last['value'])) { | |
| 1183 | + $json = @json_decode($last['value'], ARRAY_A); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged | |
| 1184 | + if (!empty($json)) { | |
| 1185 | + $entry = array( | |
| 1186 | + '0' => array( | |
| 1187 | + 'value' => $json, | |
| 1188 | + ), | |
| 1189 | + ); | |
| 1190 | + } else { | |
| 1191 | + if (is_serialized($last['value'])) { | |
| 1192 | + $serialized = $this->helper->load('convert')->unserialize($last['value']); | |
| 1193 | + if (!empty($serialized)) { | |
| 1194 | + $entry = array( | |
| 1195 | + '0' => array( | |
| 1196 | + 'value' => $serialized, | |
| 1197 | + ), | |
| 1198 | + ); | |
| 1199 | + } | |
| 1200 | + } | |
| 1201 | + } | |
| 1202 | + } | |
| 1203 | + } | |
| 1204 | + } | |
| 1205 | + return $entry; | |
| 1206 | + } | |
| 1207 | + | |
| 1208 | + /** | |
| 1209 | + * Disable conditions to render inside PDF | |
| 1210 | + * @return boolean | |
| 1211 | + */ | |
| 1212 | + public function filter_caldera_forms_pre_check_condition($result) { | |
| 1213 | + return true; | |
| 1214 | + } | |
| 1215 | + | |
| 1216 | + /** | |
| 851 | 1217 | * Convert file and advanced_file field type to not rendered |
| 852 | - * | |
| 853 | 1218 | * @param array $field - Field |
| 854 | - * @param array $form - Current form | |
| 855 | - * | |
| 856 | - @return array - Updated field | |
| 1219 | + * @param array $form - Current form | |
| 1220 | + * @return array - Updated field | |
| 857 | 1221 | */ |
| 858 | 1222 | public function filter_caldera_forms_render_get_field($field, $form) { |
| 859 | 1223 | if (isset($field['type']) && ($field['type'] == 'file' || $field['type'] == 'advanced_file')) { |
| 860 | 1224 | $field['config']['media_lib'] = false; |
| @@ -863,16 +1227,14 @@ | ||
| 863 | 1227 | } |
| 864 | 1228 | |
| 865 | 1229 | /** |
| 866 | 1230 | * Fix for {entry_id} |
| 867 | - * | |
| 868 | 1231 | * @param array $form - Current form |
| 869 | 1232 | * @param int $entry_id - Current entry_id |
| 870 | - * | |
| 871 | - @return array - Updated form | |
| 1233 | + * @return array - Updated form | |
| 872 | 1234 | */ |
| 873 | 1235 | public function filter_caldera_forms_magic_form($form, $entry_id) { |
| 874 | - if (class_exists("Caldera_Forms") && $entry_id) { | |
| 1236 | + if (class_exists('Caldera_Forms') && $entry_id) { | |
| 875 | 1237 | Caldera_Forms::set_field_data('_entry_id', $entry_id, $form); |
| 876 | 1238 | } |
| 877 | 1239 | return $form; |
| 878 | 1240 | } |
| @@ -878,100 +1240,168 @@ | ||
| 878 | 1240 | } |
| 879 | 1241 | |
| 880 | 1242 | /** |
| 881 | 1243 | * Render file and advanced_file field types to url instead image and link |
| 882 | - * | |
| 883 | - * @param string $value - Text value | |
| 1244 | + * @param string $_value - NULL value to overide | |
| 1245 | + * @param string $value - Value to replace shortcodes | |
| 884 | 1246 | * @param array $matches - List of matches of magic tags |
| 885 | 1247 | * @param int $entry_id - Current entry |
| 886 | - * @param array $form - Current form | |
| 887 | - * | |
| 1248 | + * @param array $form - Current form | |
| 888 | 1249 | * @return string - Updated value |
| 889 | 1250 | */ |
| 890 | - public function filter_caldera_forms_do_field_magic_value($value, $matches, $entry_id, $form) { | |
| 891 | - | |
| 892 | - if (class_exists("Caldera_Forms") && class_exists("Caldera_Forms_Field_Util")) { | |
| 893 | - if (isset($matches[1])) { | |
| 1251 | + public function filter_caldera_forms_pre_do_field_magic($_value, $value, $matches, $entry_id, $form) { | |
| 1252 | + if (class_exists('Caldera_Forms') && $value) { | |
| 1253 | + if (!empty($matches[1])) { | |
| 894 | 1254 | foreach ($matches[1] as $key => $tag) { |
| 895 | - | |
| 896 | 1255 | $part_tags = explode(':', $tag); |
| 897 | 1256 | if (!empty($part_tags[1])) { |
| 898 | 1257 | $tag = $part_tags[0]; |
| 899 | 1258 | } |
| 900 | 1259 | $entry = Caldera_Forms::get_slug_data($tag, $form, $entry_id); |
| 901 | - | |
| 902 | 1260 | $field = false; |
| 903 | 1261 | if ($entry !== null) { |
| 904 | 1262 | $field = Caldera_Forms_Field_Util::get_field_by_slug($tag, $form); |
| 905 | 1263 | } |
| 906 | - | |
| 907 | - if (Caldera_Forms_Field_Util::is_file_field($field, $form)) { | |
| 908 | - if (filter_var($entry, FILTER_VALIDATE_URL)) { | |
| 909 | - $value = $entry; | |
| 1264 | + if ('html' === $this->get_field_type_by_slug($tag, $form)) { | |
| 1265 | + $field = Caldera_Forms_Field_Util::get_field_by_slug($tag, $form); | |
| 1266 | + $entry = Caldera_Forms::do_magic_tags(Caldera_Forms_Field_Util::get_default($field, $form)); | |
| 1267 | + } | |
| 1268 | + if (!empty($field) && Caldera_Forms_Field_Util::is_file_field($field, $form)) { | |
| 1269 | + if (is_string($entry) && Caldera_Forms_Field_Util::is_file_field($field, $form)) { | |
| 1270 | + if (!filter_var($entry, FILTER_VALIDATE_URL)) { | |
| 1271 | + $entry = ''; | |
| 1272 | + } | |
| 910 | 1273 | } |
| 911 | - continue; | |
| 912 | 1274 | } |
| 1275 | + if (is_string($entry)) { | |
| 1276 | + if (!empty($field) && !empty($part_tags[1]) && $part_tags[1] == 'label') { | |
| 1277 | + $_entry = @json_decode($entry); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged | |
| 1278 | + if (is_object($_entry)) { | |
| 1279 | + $entry = $_entry; | |
| 1280 | + } | |
| 1281 | + } else { | |
| 1282 | + $entry = $this->maybe_implode_opts($entry); | |
| 1283 | + } | |
| 1284 | + } | |
| 1285 | + if (!empty($field) && !empty($part_tags[1]) && $part_tags[1] == 'label') { | |
| 1286 | + if (!is_array($entry)) { | |
| 1287 | + $entry = (array) $entry; | |
| 1288 | + } | |
| 1289 | + foreach ((array) $entry as $entry_key => $entry_line) { | |
| 1290 | + if (!empty($field['config']['option'])) { | |
| 1291 | + foreach ($field['config']['option'] as $option) { | |
| 1292 | + if ($option['value'] == $entry_line) { | |
| 1293 | + $entry[$entry_key] = $option['label']; | |
| 1294 | + } | |
| 1295 | + } | |
| 1296 | + } | |
| 1297 | + } | |
| 1298 | + } | |
| 1299 | + if (is_array($entry)) { | |
| 1300 | + if (count($entry) === 1) { | |
| 1301 | + $entry = array_shift($entry); | |
| 1302 | + } elseif (count($entry) === 2) { | |
| 1303 | + $entry = implode(', ', $entry); | |
| 1304 | + } elseif (count($entry) > 2) { | |
| 1305 | + $last = array_pop($entry); | |
| 1306 | + $entry = implode(', ', $entry) . ', ' . $last; | |
| 1307 | + } else { | |
| 1308 | + $entry = null; | |
| 1309 | + } | |
| 1310 | + } | |
| 913 | 1311 | $value = str_replace($matches[0][$key], $entry, $value); |
| 914 | 1312 | } |
| 1313 | + return apply_filters('caldera_forms_do_field_magic_value', $value, $matches, $entry_id, $form); | |
| 915 | 1314 | } |
| 916 | 1315 | } |
| 1316 | + return $_value; | |
| 1317 | + } | |
| 917 | 1318 | |
| 1319 | + /** | |
| 1320 | + * Implode "opts" -- IE checkboxes stored as "opts" as needed | |
| 1321 | + * @param string $value Value to check and possibly convert | |
| 1322 | + * @return string | |
| 1323 | + */ | |
| 1324 | + public function maybe_implode_opts($value) { | |
| 1325 | + if (is_string($value) && '{"opt' == substr($value, 0, 5)) { | |
| 1326 | + $_value = @json_decode($value); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged | |
| 1327 | + if (is_object($_value)) { | |
| 1328 | + $value = implode(', ', (array) $_value); | |
| 1329 | + } | |
| 1330 | + } elseif (is_array($value)) { | |
| 1331 | + $value = implode(', ', $value); | |
| 1332 | + } | |
| 1333 | + return $value; | |
| 1334 | + } | |
| 918 | 1335 | |
| 919 | - return $value; | |
| 1336 | + /** | |
| 1337 | + * Get field type by slug for HTML field render | |
| 1338 | + * @param string $slug Slug to check | |
| 1339 | + * @param array $form Form to check | |
| 1340 | + * @return boolean|mixed | |
| 1341 | + */ | |
| 1342 | + public function get_field_type_by_slug($slug, $form) { | |
| 1343 | + if (is_array($form) && isset($form['fields'])) { | |
| 1344 | + foreach ($form['fields'] as $field_id => $field) { | |
| 1345 | + if ($field['slug'] == $slug) { | |
| 1346 | + if (isset($field['type'])) { | |
| 1347 | + return $field['type']; | |
| 1348 | + } else { | |
| 1349 | + return false; | |
| 1350 | + } | |
| 1351 | + } | |
| 1352 | + } | |
| 1353 | + } | |
| 1354 | + return false; | |
| 920 | 1355 | } |
| 921 | 1356 | |
| 922 | 1357 | /** |
| 923 | 1358 | * [e2pdf-view] shortcode fix |
| 924 | - * | |
| 1359 | + * @param string $out - HTML Output | |
| 1360 | + * @param array $form - Current form | |
| 1361 | + * @return string - Updated HTML Output | |
| 1362 | + */ | |
| 1363 | + public function filter_caldera_forms_render_form($out, $form) { | |
| 1364 | + if (false === strpos($out, '[')) { | |
| 1365 | + return $out; | |
| 1366 | + } | |
| 1367 | + $shortcode_tags = array( | |
| 1368 | + 'e2pdf-view', | |
| 1369 | + 'e2pdf-download', | |
| 1370 | + ); | |
| 1371 | + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $out, $matches); | |
| 1372 | + $tagnames = array_intersect($shortcode_tags, $matches[1]); | |
| 1373 | + if (!empty($tagnames)) { | |
| 1374 | + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $out, $shortcodes); | |
| 1375 | + foreach ($shortcodes[0] as $key => $shortcode_value) { | |
| 1376 | + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); | |
| 1377 | + $out = str_replace($shortcode_value, do_shortcode_tag($shortcode), $out); | |
| 1378 | + } | |
| 1379 | + } | |
| 1380 | + return $out; | |
| 1381 | + } | |
| 1382 | + | |
| 1383 | + /** | |
| 1384 | + * [e2pdf-view] shortcode fix | |
| 925 | 1385 | * @param array $out - Array with response |
| 926 | - * @param array $form - Current form | |
| 927 | - * | |
| 928 | - @return array - Updated response | |
| 1386 | + * @param array $form - Current form | |
| 1387 | + * @return array - Updated response | |
| 929 | 1388 | */ |
| 930 | 1389 | public function filter_caldera_forms_ajax_return($out, $form) { |
| 931 | - | |
| 932 | 1390 | if (isset($out['html'])) { |
| 933 | - | |
| 934 | 1391 | if (false === strpos($out['html'], '[')) { |
| 935 | 1392 | return $out; |
| 936 | 1393 | } |
| 937 | - | |
| 938 | 1394 | $shortcode_tags = array( |
| 939 | - 'e2pdf-view' | |
| 1395 | + 'e2pdf-view', | |
| 1396 | + 'e2pdf-download', | |
| 940 | 1397 | ); |
| 941 | - | |
| 942 | - preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $form['success'], $matches); | |
| 943 | - | |
| 1398 | + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $out['html'], $matches); | |
| 944 | 1399 | $tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 945 | - | |
| 946 | 1400 | if (!empty($tagnames)) { |
| 947 | - $pattern = get_shortcode_regex($tagnames); | |
| 948 | - | |
| 949 | - preg_match_all("/$pattern/", $out['html'], $shortcodes); | |
| 1401 | + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $out['html'], $shortcodes); | |
| 950 | 1402 | foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 951 | - | |
| 952 | - $extension = false; | |
| 953 | - $item = false; | |
| 954 | - | |
| 955 | - $shortcode = array(); | |
| 956 | - $shortcode[1] = $shortcodes[1][$key]; | |
| 957 | - $shortcode[2] = $shortcodes[2][$key]; | |
| 958 | - $shortcode[3] = $shortcodes[3][$key]; | |
| 959 | - $shortcode[4] = $shortcodes[4][$key]; | |
| 960 | - $shortcode[5] = $shortcodes[5][$key]; | |
| 961 | - $shortcode[6] = $shortcodes[6][$key]; | |
| 962 | - | |
| 963 | - $atts = shortcode_parse_atts($shortcode[3]); | |
| 964 | - | |
| 965 | - if (array_key_exists('id', $atts)) { | |
| 966 | - $template = new Model_E2pdf_Template(); | |
| 967 | - $template->load($atts['id']); | |
| 968 | - if ($template->get('extension') === 'caldera') { | |
| 969 | - $extension = $template->get('extension'); | |
| 970 | - $item = $template->get('item'); | |
| 971 | - } | |
| 972 | - } | |
| 973 | - | |
| 1403 | + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); | |
| 974 | 1404 | $out['html'] = str_replace($shortcode_value, do_shortcode_tag($shortcode), $out['html']); |
| 975 | 1405 | } |
| 976 | 1406 | } |
| 977 | 1407 | } |
| @@ -978,87 +1408,54 @@ | ||
| 978 | 1408 | |
| 979 | 1409 | return $out; |
| 980 | 1410 | } |
| 981 | 1411 | |
| 982 | - public function action_caldera_forms_submit_complete($form, $referrer, $process_id) { | |
| 983 | - global $form, $transdata; | |
| 984 | - | |
| 985 | - if (isset($form['success'])) { | |
| 986 | - | |
| 987 | - if (false === strpos($form['success'], '[')) { | |
| 988 | - return; | |
| 989 | - } | |
| 990 | - | |
| 1412 | + public function filter_success_message($message = '', $form = array(), $dataset_id = false) { | |
| 1413 | + if (false !== strpos($message, '[')) { | |
| 991 | 1414 | $shortcode_tags = array( |
| 992 | 1415 | 'e2pdf-download', |
| 993 | 1416 | 'e2pdf-save', |
| 994 | - 'e2pdf-view' | |
| 1417 | + 'e2pdf-view', | |
| 1418 | + 'e2pdf-adobesign', | |
| 1419 | + 'e2pdf-zapier', | |
| 995 | 1420 | ); |
| 996 | - | |
| 997 | - preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $form['success'], $matches); | |
| 998 | - | |
| 1421 | + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $message, $matches); | |
| 999 | 1422 | $tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 1000 | - | |
| 1001 | 1423 | if (!empty($tagnames)) { |
| 1002 | - $pattern = get_shortcode_regex($tagnames); | |
| 1003 | - | |
| 1004 | - preg_match_all("/$pattern/", $form['success'], $shortcodes); | |
| 1424 | + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $message, $shortcodes); | |
| 1005 | 1425 | foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 1006 | - | |
| 1007 | - $extension = false; | |
| 1008 | - $item = false; | |
| 1009 | - | |
| 1010 | - $shortcode = array(); | |
| 1011 | - $shortcode[1] = $shortcodes[1][$key]; | |
| 1012 | - $shortcode[2] = $shortcodes[2][$key]; | |
| 1013 | - $shortcode[3] = $shortcodes[3][$key]; | |
| 1014 | - $shortcode[4] = $shortcodes[4][$key]; | |
| 1015 | - $shortcode[5] = $shortcodes[5][$key]; | |
| 1016 | - $shortcode[6] = $shortcodes[6][$key]; | |
| 1017 | - | |
| 1426 | + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); | |
| 1018 | 1427 | $atts = shortcode_parse_atts($shortcode[3]); |
| 1019 | - | |
| 1020 | - if (array_key_exists('id', $atts)) { | |
| 1021 | - $template = new Model_E2pdf_Template(); | |
| 1022 | - $template->load($atts['id']); | |
| 1023 | - if ($template->get('extension') === 'caldera') { | |
| 1024 | - $extension = $template->get('extension'); | |
| 1025 | - $item = $template->get('item'); | |
| 1026 | - } | |
| 1027 | - } | |
| 1028 | - | |
| 1029 | - if ($extension) { | |
| 1030 | - if (!array_key_exists('dataset', $atts)) { | |
| 1031 | - $dataset_id = isset($transdata['entry_id']) ? $transdata['entry_id'] : false; | |
| 1032 | - if ($dataset_id) { | |
| 1033 | - $atts['dataset'] = $dataset_id; | |
| 1034 | - $shortcode[3] .= " dataset='{$dataset_id}'"; | |
| 1035 | - | |
| 1036 | - if ($shortcode[2] === 'e2pdf-save') { | |
| 1037 | - $shortcode[3] .= " apply='true'"; | |
| 1428 | + if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf | |
| 1429 | + } else { | |
| 1430 | + if (!isset($atts['dataset']) && isset($atts['id'])) { | |
| 1431 | + $template = new Model_E2pdf_Template(); | |
| 1432 | + $template->load($atts['id']); | |
| 1433 | + if ($template->get('extension') === 'caldera') { | |
| 1434 | + if ($dataset_id) { | |
| 1435 | + $atts['dataset'] = $dataset_id; | |
| 1436 | + $shortcode[3] .= ' dataset="' . $dataset_id . '"'; | |
| 1038 | 1437 | } |
| 1039 | - | |
| 1040 | - if ($shortcode[2] === 'e2pdf-view') { | |
| 1041 | - $new_shortcode = $shortcode[2] . $shortcode[3]; | |
| 1042 | - $form['success'] = str_replace($shortcode_value, "[{$new_shortcode}]", $form['success']); | |
| 1043 | - } else { | |
| 1044 | - $form['success'] = str_replace($shortcode_value, do_shortcode_tag($shortcode), $form['success']); | |
| 1045 | - } | |
| 1046 | 1438 | } |
| 1439 | + } | |
| 1440 | + if (!isset($atts['apply'])) { | |
| 1441 | + $shortcode[3] .= ' apply="true"'; | |
| 1442 | + } | |
| 1443 | + if (!isset($atts['iframe_download'])) { | |
| 1444 | + $shortcode[3] .= ' iframe_download="true"'; | |
| 1445 | + } | |
| 1446 | + if ($shortcode[2] === 'e2pdf-view' || $shortcode[2] === 'e2pdf-download') { | |
| 1447 | + $new_shortcode = $shortcode[2] . $shortcode[3]; | |
| 1448 | + $message = str_replace($shortcode_value, '[' . $new_shortcode . ']', $message); | |
| 1047 | 1449 | } else { |
| 1048 | - | |
| 1049 | - if ($shortcode[2] === 'e2pdf-save') { | |
| 1050 | - $shortcode[3] .= " apply='true'"; | |
| 1051 | - } | |
| 1052 | - | |
| 1053 | - if ($shortcode[2] !== 'e2pdf-view') { | |
| 1054 | - $form['success'] = str_replace($shortcode_value, do_shortcode_tag($shortcode), $form['success']); | |
| 1055 | - } | |
| 1450 | + $message = str_replace($shortcode_value, do_shortcode_tag($shortcode), $message); | |
| 1056 | 1451 | } |
| 1057 | 1452 | } |
| 1058 | 1453 | } |
| 1059 | 1454 | } |
| 1060 | 1455 | } |
| 1456 | + | |
| 1457 | + return $message; | |
| 1061 | 1458 | } |
| 1062 | 1459 | |
| 1063 | 1460 | /** |
| 1064 | 1461 | * Load filters for this extension |
| @@ -1063,96 +1460,120 @@ | ||
| 1063 | 1460 | /** |
| 1064 | 1461 | * Load filters for this extension |
| 1065 | 1462 | */ |
| 1066 | 1463 | public function load_filters() { |
| 1067 | - add_filter('caldera_forms_mailer', array($this, 'filter_caldera_forms_mailer'), 10, 3); | |
| 1068 | - add_filter('caldera_forms_ajax_return', array($this, 'filter_caldera_forms_ajax_return'), 10, 2); | |
| 1464 | + /* 1.15.06 SendGripd Priority Fix (30 to 25) */ | |
| 1465 | + add_filter('caldera_forms_mailer', array($this, 'filter_caldera_forms_mailer'), 25, 4); | |
| 1466 | + add_filter('caldera_forms_autoresponse_mail', array($this, 'filter_caldera_forms_mailer'), 30, 4); | |
| 1467 | + add_filter('caldera_forms_render_notices', array($this, 'filter_caldera_forms_render_notices'), 99, 2); | |
| 1468 | + add_filter('caldera_forms_ajax_return', array($this, 'filter_caldera_forms_ajax_return'), 30, 2); | |
| 1469 | + add_filter('caldera_forms_render_form', array($this, 'filter_caldera_forms_render_form'), 30, 2); | |
| 1069 | 1470 | } |
| 1070 | 1471 | |
| 1071 | - public function filter_caldera_forms_mailer($mail, $data, $form) { | |
| 1472 | + public function filter_caldera_forms_render_notices($notices, $form) { | |
| 1473 | + if (class_exists('Caldera_Forms')) { | |
| 1474 | + if (!empty($notices['success']['note'])) { | |
| 1475 | + $dataset_id = false; | |
| 1476 | + if (!empty($form['form_ajax'])) { | |
| 1477 | + if (!empty($form['stage_form'])) { | |
| 1478 | + if (function_exists('cf_form_connector_get_current_position')) { | |
| 1479 | + $process_record = cf_form_connector_get_current_position(); | |
| 1480 | + if (!empty($process_record[$form['stage_form']]['entry_id'])) { | |
| 1481 | + $dataset_id = $process_record[$form['stage_form']]['entry_id']; | |
| 1482 | + } | |
| 1483 | + } | |
| 1484 | + } else { | |
| 1485 | + $dataset_id = (int) Caldera_Forms::do_magic_tags('{entry_id}'); | |
| 1486 | + } | |
| 1487 | + } else { | |
| 1488 | + if (isset($_GET['cf_id']) && isset($_GET['cf_su'])) { | |
| 1489 | + $dataset_id = absint($_GET['cf_id']); | |
| 1490 | + } | |
| 1491 | + } | |
| 1492 | + $notices['success']['note'] = $this->filter_success_message($notices['success']['note'], $form, $dataset_id); | |
| 1493 | + } | |
| 1494 | + } | |
| 1495 | + return $notices; | |
| 1496 | + } | |
| 1072 | 1497 | |
| 1498 | + /** | |
| 1499 | + * Filter to replace mail message E2Pdf shortcodes | |
| 1500 | + */ | |
| 1501 | + public function filter_caldera_forms_mailer($mail, $data, $form, $entryid) { | |
| 1073 | 1502 | if ($mail && isset($mail['message'])) { |
| 1074 | 1503 | if (false !== strpos($mail['message'], '[')) { |
| 1075 | 1504 | $shortcode_tags = array( |
| 1076 | 1505 | 'e2pdf-download', |
| 1506 | + 'e2pdf-save', | |
| 1077 | 1507 | 'e2pdf-attachment', |
| 1078 | - 'e2pdf-save' | |
| 1508 | + 'e2pdf-adobesign', | |
| 1509 | + 'e2pdf-zapier', | |
| 1079 | 1510 | ); |
| 1080 | - | |
| 1081 | 1511 | preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $mail['message'], $matches); |
| 1082 | 1512 | $tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 1083 | - | |
| 1084 | 1513 | if (!empty($tagnames)) { |
| 1085 | - $pattern = get_shortcode_regex($tagnames); | |
| 1086 | - | |
| 1087 | - preg_match_all("/$pattern/", $mail['message'], $shortcodes); | |
| 1088 | - | |
| 1514 | + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $mail['message'], $shortcodes); | |
| 1089 | 1515 | foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 1090 | - $extension = false; | |
| 1091 | - $item = false; | |
| 1092 | - | |
| 1093 | - $shortcode = array(); | |
| 1094 | - $shortcode[1] = $shortcodes[1][$key]; | |
| 1095 | - $shortcode[2] = $shortcodes[2][$key]; | |
| 1096 | - $shortcode[3] = $shortcodes[3][$key]; | |
| 1097 | - $shortcode[4] = $shortcodes[4][$key]; | |
| 1098 | - $shortcode[5] = $shortcodes[5][$key]; | |
| 1099 | - $shortcode[6] = $shortcodes[6][$key]; | |
| 1100 | - | |
| 1516 | + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); | |
| 1101 | 1517 | $atts = shortcode_parse_atts($shortcode[3]); |
| 1102 | - | |
| 1103 | - if (array_key_exists('id', $atts)) { | |
| 1518 | + if (!isset($atts['dataset']) && isset($atts['id'])) { | |
| 1104 | 1519 | $template = new Model_E2pdf_Template(); |
| 1105 | 1520 | $template->load($atts['id']); |
| 1106 | 1521 | if ($template->get('extension') === 'caldera') { |
| 1107 | - $extension = $template->get('extension'); | |
| 1108 | - $item = $template->get('item'); | |
| 1109 | - | |
| 1110 | - if (!array_key_exists('dataset', $atts)) { | |
| 1522 | + $dataset_id = $entryid; | |
| 1523 | + if (!$dataset_id) { | |
| 1111 | 1524 | $dataset_id = isset($data['_entry_id']) ? $data['_entry_id'] : false; |
| 1112 | - if ($dataset_id) { | |
| 1113 | - $atts['dataset'] = $dataset_id; | |
| 1114 | - $shortcode[3] .= " dataset='{$dataset_id}' apply='true'"; | |
| 1115 | - } | |
| 1116 | - } else { | |
| 1117 | - $shortcode[3] .= " apply='true'"; | |
| 1118 | 1525 | } |
| 1119 | - | |
| 1120 | - if ($shortcode[2] === 'e2pdf-download' || $shortcode[2] === 'e2pdf-save') { | |
| 1121 | - $mail['message'] = str_replace($shortcode_value, do_shortcode_tag($shortcode), $mail['message']); | |
| 1122 | - } elseif ($shortcode[2] === 'e2pdf-attachment') { | |
| 1123 | - $file = do_shortcode_tag($shortcode); | |
| 1124 | - | |
| 1125 | - if ($file) { | |
| 1526 | + if ($dataset_id) { | |
| 1527 | + $atts['dataset'] = $dataset_id; | |
| 1528 | + $shortcode[3] .= ' dataset="' . $dataset_id . '"'; | |
| 1529 | + } | |
| 1530 | + } | |
| 1531 | + } | |
| 1532 | + if (!isset($atts['apply'])) { | |
| 1533 | + $shortcode[3] .= ' apply="true"'; | |
| 1534 | + } | |
| 1535 | + if (!isset($atts['filter'])) { | |
| 1536 | + $shortcode[3] .= ' filter="true"'; | |
| 1537 | + } | |
| 1538 | + $file = false; | |
| 1539 | + if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { | |
| 1540 | + $file = do_shortcode_tag($shortcode); | |
| 1541 | + if ($file) { | |
| 1542 | + $tmp = false; | |
| 1543 | + if (substr($file, 0, 4) === 'tmp:') { | |
| 1544 | + $file = substr($file, 4); | |
| 1545 | + $tmp = true; | |
| 1546 | + } | |
| 1547 | + if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) { | |
| 1548 | + if ($tmp) { | |
| 1126 | 1549 | $this->helper->add('caldera_attachments', $file); |
| 1127 | - $mail['attachments'][] = $file; | |
| 1128 | 1550 | } |
| 1129 | - $mail['message'] = str_replace($shortcode_value, '', $mail['message']); | |
| 1551 | + } else { | |
| 1552 | + $this->helper->add('caldera_attachments', $file); | |
| 1130 | 1553 | } |
| 1554 | + $mail['attachments'][] = $file; | |
| 1131 | 1555 | } |
| 1556 | + $mail['message'] = str_replace($shortcode_value, '', $mail['message']); | |
| 1557 | + } else { | |
| 1558 | + $mail['message'] = str_replace($shortcode_value, do_shortcode_tag($shortcode), $mail['message']); | |
| 1132 | 1559 | } |
| 1133 | 1560 | } |
| 1134 | 1561 | } |
| 1135 | 1562 | } |
| 1136 | 1563 | } |
| 1137 | - | |
| 1138 | - | |
| 1139 | 1564 | return $mail; |
| 1140 | 1565 | } |
| 1141 | 1566 | |
| 1142 | 1567 | /** |
| 1143 | 1568 | * Get styles for generating Map Field function |
| 1144 | - * | |
| 1145 | 1569 | * @return array - List of css files to load |
| 1146 | 1570 | */ |
| 1147 | - public function get_styles() { | |
| 1148 | - | |
| 1571 | + public function styles($item_id = false) { | |
| 1149 | 1572 | $styles = array(); |
| 1150 | 1573 | if (class_exists('Caldera_Forms_Render_Assets')) { |
| 1151 | 1574 | $url = Caldera_Forms_Render_Assets::make_url('caldera-forms-front', false); |
| 1152 | 1575 | $styles[] = $url; |
| 1153 | 1576 | } |
| 1154 | - | |
| 1155 | 1577 | return $styles; |
| 1156 | 1578 | } |
| 1157 | - | |
| 1158 | 1579 | } |