| @@ -1,13 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * E2Pdf Divi Extension | |
| 5 | - * @copyright Copyright 2017 https://e2pdf.com | |
| 6 | - * @license GPLv3 | |
| 7 | - * @version 1 | |
| 8 | - * @link https://e2pdf.com | |
| 9 | - * @since 0.00.01 | |
| 4 | + * File: /extension/e2pdf-divi.php | |
| 5 | + * | |
| 6 | + * @package E2Pdf | |
| 7 | + * @license GPLv3 | |
| 8 | + * @link https://e2pdf.com | |
| 10 | 9 | */ |
| 11 | 10 | if (!defined('ABSPATH')) { |
| 12 | 11 | die('Access denied.'); |
| 13 | 12 | } |
| @@ -14,12 +13,12 @@ | ||
| 14 | 13 | |
| 15 | 14 | class Extension_E2pdf_Divi extends Model_E2pdf_Model { |
| 16 | 15 | |
| 17 | 16 | private $options; |
| 18 | - private $info = array( | |
| 17 | + private $info = [ | |
| 19 | 18 | 'key' => 'divi', |
| 20 | 19 | 'title' => 'Divi Forms', |
| 21 | - ); | |
| 20 | + ]; | |
| 22 | 21 | |
| 23 | 22 | // info |
| 24 | 23 | public function info($key = false) { |
| 25 | 24 | if ($key && isset($this->info[$key])) { |
| @@ -24,11 +23,11 @@ | ||
| 24 | 23 | public function info($key = false) { |
| 25 | 24 | if ($key && isset($this->info[$key])) { |
| 26 | 25 | return $this->info[$key]; |
| 27 | 26 | } else { |
| 28 | - return array( | |
| 27 | + return [ | |
| 29 | 28 | $this->info['key'] => $this->info['title'], |
| 30 | - ); | |
| 29 | + ]; | |
| 31 | 30 | } |
| 32 | 31 | } |
| 33 | 32 | |
| 34 | 33 | // active |
| @@ -57,80 +56,109 @@ | ||
| 57 | 56 | $entry = new Model_E2pdf_Dataset(); |
| 58 | 57 | if ($entry->load($this->get('dataset'), $this->get('item'), 'divi')) { |
| 59 | 58 | $cached_entry = $entry->get('entry'); |
| 60 | 59 | $this->set('cached_entry', $cached_entry); |
| 61 | - $processed_fields_values = []; | |
| 60 | + | |
| 61 | + $meta_data = []; | |
| 62 | 62 | if ($cached_entry && is_array($cached_entry)) { |
| 63 | - $et_contact_proccess = array_search('et_contact_proccess', $cached_entry); | |
| 64 | - $et_pb_contact_form_num = $et_contact_proccess === false ? 0 : str_replace('et_pb_contactform_submit_', '', $et_contact_proccess); | |
| 65 | - $current_form_fields = isset($cached_entry['et_pb_contact_email_fields_' . $et_pb_contact_form_num]) ? $cached_entry['et_pb_contact_email_fields_' . $et_pb_contact_form_num] : ''; | |
| 66 | - if ('' !== $current_form_fields) { | |
| 67 | - $fields_data_json = str_replace('\\', '', $current_form_fields); | |
| 68 | - $fields_data_array = json_decode($fields_data_json, true); | |
| 69 | - if (!empty($fields_data_array)) { | |
| 70 | - foreach ($fields_data_array as $index => $field_value) { | |
| 71 | - $processed_fields_values[$field_value['original_id']]['value'] = isset($cached_entry[$field_value['field_id']]) ? $cached_entry[$field_value['field_id']] : ''; | |
| 72 | - $processed_fields_values[$field_value['original_id']]['label'] = $field_value['field_label']; | |
| 73 | - if ( | |
| 74 | - ( | |
| 75 | - (isset($cached_entry[$field_value['field_id'] . '_is_signature_pad']) && $cached_entry[$field_value['field_id'] . '_is_signature_pad'] == 'yes') || | |
| 76 | - (isset($cached_entry[$field_value['field_id'] . '_is_file']) && $cached_entry[$field_value['field_id'] . '_is_file'] == 'yes') | |
| 77 | - ) && $processed_fields_values[$field_value['original_id']]['value'] | |
| 78 | - ) { | |
| 79 | - $subdir = isset($cached_entry['_subdir']) ? $cached_entry['_subdir'] : ''; | |
| 80 | - if (isset($cached_entry['_save_files_to_media']) && $cached_entry['_save_files_to_media'] == 'on') { | |
| 81 | - if ($subdir && !file_exists(path_join(wp_upload_dir()['basedir'] . $subdir, $processed_fields_values[$field_value['original_id']]['value'])) && preg_match('/^\/\d{4}\/\d{2}$/', $subdir)) { | |
| 82 | - $tmpsubdir = '/' . date('Y/m', strtotime(str_replace('/', '-', ltrim($subdir, '/')) . ' -1 month')); | |
| 83 | - if (file_exists(path_join(wp_upload_dir()['basedir'] . $tmpsubdir, $processed_fields_values[$field_value['original_id']]['value']))) { | |
| 84 | - $subdir = $tmpsubdir; | |
| 85 | - } | |
| 63 | + // Divi5 | |
| 64 | + if (!empty($cached_entry['E2PDF_VERSION'])) { | |
| 65 | + foreach ($cached_entry['fields'] as $field_key => $field) { | |
| 66 | + if (isset($field['type'])) { | |
| 67 | + switch ($field['type']) { | |
| 68 | + case 'signature-pad': | |
| 69 | + $meta_data['%%' . $field_key . '%%'] = $this->pwh_dcfh_resolve_file_url($field['value'], $cached_entry['options']); | |
| 70 | + break; | |
| 71 | + case 'file': | |
| 72 | + $attachments = is_array($field['value']) ? $field['value'] : explode(',', $field['value']); | |
| 73 | + foreach ($attachments as $attachment_key => $attachment) { | |
| 74 | + $attachments[$attachment_key] = $this->pwh_dcfh_resolve_file_url($attachment, $cached_entry['options']); | |
| 86 | 75 | } |
| 87 | - $processed_fields_values[$field_value['original_id']]['value'] = path_join(wp_upload_dir()['baseurl'] . $subdir, $processed_fields_values[$field_value['original_id']]['value']); | |
| 88 | - } else { | |
| 89 | - $contact_form_id = isset($cached_entry['_unique_id']) ? $cached_entry['_unique_id'] : ''; | |
| 90 | - if (function_exists('pwh_dcfh_file_helpers') && $contact_form_id) { | |
| 91 | - if ($subdir && !file_exists(pwh_dcfh_file_helpers()::get_form_upload_dir($contact_form_id, $subdir, $processed_fields_values[$field_value['original_id']]['value'])) && preg_match('/^\d{4}\/\d{2}$/', $subdir)) { | |
| 92 | - $tmpsubdir = date('Y/m', strtotime(str_replace('/', '-', ltrim($subdir, '/')) . " -1 month")); | |
| 93 | - if (file_exists(pwh_dcfh_file_helpers()::get_form_upload_dir($contact_form_id, $tmpsubdir, $processed_fields_values[$field_value['original_id']]['value']))) { | |
| 76 | + $meta_data['%%' . $field_key . '%%'] = implode(',', $attachments); | |
| 77 | + break; | |
| 78 | + default: | |
| 79 | + $meta_data['%%' . $field_key . '%%'] = is_array($field['value']) ? implode(', ', $field['value']) : $field['value']; | |
| 80 | + break; | |
| 81 | + } | |
| 82 | + } | |
| 83 | + } | |
| 84 | + } elseif (!empty($cached_entry['ET_CORE_VERSION'])) { | |
| 85 | + foreach ($cached_entry as $field_key => $value) { | |
| 86 | + $meta_data['%%' . $field_key . '%%'] = is_array($value) ? implode(', ', $value) : $value; | |
| 87 | + } | |
| 88 | + if (!isset($meta_data['%%e2pdf_entry_id%%'])) { | |
| 89 | + $meta_data['%%e2pdf_entry_id%%'] = (int) $this->get('dataset'); | |
| 90 | + } | |
| 91 | + } else { | |
| 92 | + // Divi4 | |
| 93 | + $processed_fields_values = []; | |
| 94 | + $et_contact_proccess = array_search('et_contact_proccess', $cached_entry); | |
| 95 | + $et_pb_contact_form_num = $et_contact_proccess === false ? 0 : str_replace('et_pb_contactform_submit_', '', $et_contact_proccess); | |
| 96 | + $current_form_fields = isset($cached_entry['et_pb_contact_email_fields_' . $et_pb_contact_form_num]) ? $cached_entry['et_pb_contact_email_fields_' . $et_pb_contact_form_num] : ''; | |
| 97 | + if ('' !== $current_form_fields) { | |
| 98 | + $fields_data_json = str_replace('\\', '', $current_form_fields); | |
| 99 | + $fields_data_array = json_decode($fields_data_json, true); | |
| 100 | + if (!empty($fields_data_array)) { | |
| 101 | + foreach ($fields_data_array as $field_value) { | |
| 102 | + $processed_fields_values[$field_value['original_id']]['value'] = isset($cached_entry[$field_value['field_id']]) ? $cached_entry[$field_value['field_id']] : ''; | |
| 103 | + $processed_fields_values[$field_value['original_id']]['label'] = $field_value['field_label']; | |
| 104 | + | |
| 105 | + $is_file = isset($cached_entry[$field_value['field_id'] . '_is_file']) && $cached_entry[$field_value['field_id'] . '_is_file'] == 'yes'; | |
| 106 | + $is_signature_pad = isset($cached_entry[$field_value['field_id'] . '_is_signature_pad']) && $cached_entry[$field_value['field_id'] . '_is_signature_pad'] == 'yes'; | |
| 107 | + | |
| 108 | + if (($is_signature_pad || $is_file) && $processed_fields_values[$field_value['original_id']]['value']) { | |
| 109 | + $subdir = isset($cached_entry['_subdir']) ? $cached_entry['_subdir'] : ''; | |
| 110 | + if (isset($cached_entry['_save_files_to_media']) && $cached_entry['_save_files_to_media'] == 'on') { | |
| 111 | + if ($subdir && !file_exists(path_join(wp_upload_dir()['basedir'] . $subdir, $processed_fields_values[$field_value['original_id']]['value'])) && preg_match('/^\/\d{4}\/\d{2}$/', $subdir)) { | |
| 112 | + $tmpsubdir = '/' . date('Y/m', strtotime(str_replace('/', '-', ltrim($subdir, '/')) . ' -1 month')); | |
| 113 | + if (file_exists(path_join(wp_upload_dir()['basedir'] . $tmpsubdir, $processed_fields_values[$field_value['original_id']]['value']))) { | |
| 94 | 114 | $subdir = $tmpsubdir; |
| 95 | 115 | } |
| 96 | 116 | } |
| 97 | - $processed_fields_values[$field_value['original_id']]['value'] = pwh_dcfh_file_helpers()::get_form_upload_url($contact_form_id, $subdir, $processed_fields_values[$field_value['original_id']]['value']); | |
| 98 | - } elseif (function_exists('ks_pac_dcfh_file_helper') && $contact_form_id) { | |
| 99 | - if ($subdir && !file_exists(ks_pac_dcfh_file_helper()::get_form_upload_dir($contact_form_id, $subdir, $processed_fields_values[$field_value['original_id']]['value'])) && preg_match('/^\d{4}\/\d{2}$/', $subdir)) { | |
| 100 | - $tmpsubdir = date('Y/m', strtotime(str_replace('/', '-', ltrim($subdir, '/')) . " -1 month")); | |
| 101 | - if (file_exists(ks_pac_dcfh_file_helper()::get_form_upload_dir($contact_form_id, $tmpsubdir, $processed_fields_values[$field_value['original_id']]['value']))) { | |
| 102 | - $subdir = $tmpsubdir; | |
| 117 | + $processed_fields_values[$field_value['original_id']]['value'] = path_join(wp_upload_dir()['baseurl'] . $subdir, $processed_fields_values[$field_value['original_id']]['value']); | |
| 118 | + } else { | |
| 119 | + $contact_form_id = isset($cached_entry['_unique_id']) ? $cached_entry['_unique_id'] : ''; | |
| 120 | + if (function_exists('pwh_dcfh_file_helpers') && $contact_form_id) { | |
| 121 | + if ($subdir && !file_exists(pwh_dcfh_file_helpers()::get_form_upload_dir($contact_form_id, $subdir, $processed_fields_values[$field_value['original_id']]['value'])) && preg_match('/^\d{4}\/\d{2}$/', $subdir)) { | |
| 122 | + $tmpsubdir = date('Y/m', strtotime(str_replace('/', '-', ltrim($subdir, '/')) . " -1 month")); | |
| 123 | + if (file_exists(pwh_dcfh_file_helpers()::get_form_upload_dir($contact_form_id, $tmpsubdir, $processed_fields_values[$field_value['original_id']]['value']))) { | |
| 124 | + $subdir = $tmpsubdir; | |
| 125 | + } | |
| 103 | 126 | } |
| 127 | + $processed_fields_values[$field_value['original_id']]['value'] = pwh_dcfh_file_helpers()::get_form_upload_url($contact_form_id, $subdir, $processed_fields_values[$field_value['original_id']]['value']); | |
| 128 | + } elseif (function_exists('ks_pac_dcfh_file_helper') && $contact_form_id) { | |
| 129 | + if ($subdir && !file_exists(ks_pac_dcfh_file_helper()::get_form_upload_dir($contact_form_id, $subdir, $processed_fields_values[$field_value['original_id']]['value'])) && preg_match('/^\d{4}\/\d{2}$/', $subdir)) { | |
| 130 | + $tmpsubdir = date('Y/m', strtotime(str_replace('/', '-', ltrim($subdir, '/')) . " -1 month")); | |
| 131 | + if (file_exists(ks_pac_dcfh_file_helper()::get_form_upload_dir($contact_form_id, $tmpsubdir, $processed_fields_values[$field_value['original_id']]['value']))) { | |
| 132 | + $subdir = $tmpsubdir; | |
| 133 | + } | |
| 134 | + } | |
| 135 | + $processed_fields_values[$field_value['original_id']]['value'] = ks_pac_dcfh_file_helper()::get_form_upload_url($contact_form_id, $subdir, $processed_fields_values[$field_value['original_id']]['value']); | |
| 136 | + } else { | |
| 137 | + $processed_fields_values[$field_value['original_id']]['value'] = ''; | |
| 104 | 138 | } |
| 105 | - $processed_fields_values[$field_value['original_id']]['value'] = ks_pac_dcfh_file_helper()::get_form_upload_url($contact_form_id, $subdir, $processed_fields_values[$field_value['original_id']]['value']); | |
| 106 | - } else { | |
| 107 | - $processed_fields_values[$field_value['original_id']]['value'] = ''; | |
| 108 | 139 | } |
| 109 | 140 | } |
| 110 | 141 | } |
| 111 | 142 | } |
| 112 | 143 | } |
| 144 | + if (!isset($processed_fields_values['_wp_http_referer'])) { | |
| 145 | + $processed_fields_values['_wp_http_referer'] = [ | |
| 146 | + 'value' => isset($cached_entry['_wp_http_referer']) ? $cached_entry['_wp_http_referer'] : '', | |
| 147 | + 'label' => '_wp_http_referer', | |
| 148 | + ]; | |
| 149 | + } | |
| 150 | + if (!isset($processed_fields_values['e2pdf_entry_id'])) { | |
| 151 | + $processed_fields_values['e2pdf_entry_id'] = [ | |
| 152 | + 'value' => (int) $this->get('dataset'), | |
| 153 | + 'label' => 'e2pdf_entry_id', | |
| 154 | + ]; | |
| 155 | + } | |
| 156 | + foreach ($processed_fields_values as $field_key => $field_value) { | |
| 157 | + $meta_data['%%' . $field_key . '%%'] = $field_value['value']; | |
| 158 | + } | |
| 113 | 159 | } |
| 114 | - | |
| 115 | - if (!isset($processed_fields_values['_wp_http_referer'])) { | |
| 116 | - $processed_fields_values['_wp_http_referer'] = array( | |
| 117 | - 'value' => isset($cached_entry['_wp_http_referer']) ? $cached_entry['_wp_http_referer'] : '', | |
| 118 | - 'label' => '_wp_http_referer', | |
| 119 | - ); | |
| 120 | - } | |
| 121 | - | |
| 122 | - if (!isset($processed_fields_values['e2pdf_entry_id'])) { | |
| 123 | - $processed_fields_values['e2pdf_entry_id'] = array( | |
| 124 | - 'value' => (int) $this->get('dataset'), | |
| 125 | - 'label' => 'e2pdf_entry_id', | |
| 126 | - ); | |
| 127 | - } | |
| 128 | 160 | } |
| 129 | - $meta_data = []; | |
| 130 | - foreach ($processed_fields_values as $field_key => $field_value) { | |
| 131 | - $meta_data['%%' . $field_key . '%%'] = $field_value['value']; | |
| 132 | - } | |
| 133 | 161 | $this->set('cached_meta', $meta_data); |
| 134 | 162 | } |
| 135 | 163 | } |
| 136 | 164 | break; |
| @@ -160,27 +188,36 @@ | ||
| 160 | 188 | |
| 161 | 189 | // items |
| 162 | 190 | public function items() { |
| 163 | 191 | global $wpdb; |
| 164 | - $condition = array( | |
| 165 | - 'post_content' => array( | |
| 192 | + $condition = [ | |
| 193 | + 'post_content' => [ | |
| 166 | 194 | 'condition' => 'LIKE', |
| 167 | 195 | 'value' => '%et_pb_contact_form%', |
| 168 | 196 | 'type' => '%s', |
| 169 | - ), | |
| 170 | - 'post_type' => array( | |
| 197 | + 'or' => [ | |
| 198 | + [ | |
| 199 | + 'post_content' => [ | |
| 200 | + 'condition' => 'LIKE', | |
| 201 | + 'value' => '%wp:divi/contact-form%', | |
| 202 | + 'type' => '%s', | |
| 203 | + ], | |
| 204 | + ], | |
| 205 | + ], | |
| 206 | + ], | |
| 207 | + 'post_type' => [ | |
| 171 | 208 | 'condition' => '<>', |
| 172 | - 'value' => array( | |
| 209 | + 'value' => [ | |
| 173 | 210 | 'revision', |
| 174 | 211 | 'et_pb_layout', |
| 175 | - ), | |
| 212 | + ], | |
| 176 | 213 | 'type' => '%s', |
| 177 | - ), | |
| 178 | - ); | |
| 179 | - $order_condition = array( | |
| 214 | + ], | |
| 215 | + ]; | |
| 216 | + $order_condition = [ | |
| 180 | 217 | 'orderby' => 'id', |
| 181 | 218 | 'order' => 'desc', |
| 182 | - ); | |
| 219 | + ]; | |
| 183 | 220 | $where = $this->helper->load('db')->prepare_where($condition); |
| 184 | 221 | $orderby = $this->helper->load('db')->prepare_orderby($order_condition); |
| 185 | 222 | // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare |
| 186 | 223 | $posts = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . $wpdb->prefix . 'posts`' . $where['sql'] . $orderby . '', $where['filter'])); |
| @@ -196,12 +233,13 @@ | ||
| 196 | 233 | |
| 197 | 234 | // get forms |
| 198 | 235 | public function get_forms($content) { |
| 199 | 236 | $forms = []; |
| 200 | - if (false !== strpos($content, 'et_pb_contact_form')) { | |
| 201 | - $shortcode_tags = array( | |
| 237 | + | |
| 238 | + if ($this->divi4_form($content)) { | |
| 239 | + $shortcode_tags = [ | |
| 202 | 240 | 'et_pb_contact_form', |
| 203 | - ); | |
| 241 | + ]; | |
| 204 | 242 | preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); |
| 205 | 243 | $tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 206 | 244 | if (!empty($tagnames)) { |
| 207 | 245 | preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes); |
| @@ -214,8 +252,16 @@ | ||
| 214 | 252 | } |
| 215 | 253 | } |
| 216 | 254 | } |
| 217 | 255 | } |
| 256 | + } elseif ($this->divi5_form($content)) { | |
| 257 | + $blocks = $this->get_forms_blocks(parse_blocks($content)); | |
| 258 | + foreach ($blocks as $block) { | |
| 259 | + $label = !empty($block['attrs']['module']['meta']['adminLabel']['desktop']['value']) ? $block['attrs']['module']['meta']['adminLabel']['desktop']['value'] : ''; | |
| 260 | + if ($label) { | |
| 261 | + $forms[$label] = $label; | |
| 262 | + } | |
| 263 | + } | |
| 218 | 264 | } |
| 219 | 265 | return $forms; |
| 220 | 266 | } |
| 221 | 267 | |
| @@ -223,24 +269,24 @@ | ||
| 223 | 269 | public function datasets($item_id = false, $name = false) { |
| 224 | 270 | global $wpdb; |
| 225 | 271 | $datasets = []; |
| 226 | 272 | if ($item_id) { |
| 227 | - $condition = array( | |
| 228 | - 'extension' => array( | |
| 273 | + $condition = [ | |
| 274 | + 'extension' => [ | |
| 229 | 275 | 'condition' => '=', |
| 230 | 276 | 'value' => 'divi', |
| 231 | 277 | 'type' => '%s', |
| 232 | - ), | |
| 233 | - 'item' => array( | |
| 278 | + ], | |
| 279 | + 'item' => [ | |
| 234 | 280 | 'condition' => '=', |
| 235 | 281 | 'value' => $item_id, |
| 236 | 282 | 'type' => '%s', |
| 237 | - ), | |
| 238 | - ); | |
| 239 | - $order_condition = array( | |
| 283 | + ], | |
| 284 | + ]; | |
| 285 | + $order_condition = [ | |
| 240 | 286 | 'orderby' => 'ID', |
| 241 | 287 | 'order' => 'desc', |
| 242 | - ); | |
| 288 | + ]; | |
| 243 | 289 | $where = $this->helper->load('db')->prepare_where($condition); |
| 244 | 290 | $orderby = $this->helper->load('db')->prepare_orderby($order_condition); |
| 245 | 291 | // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare |
| 246 | 292 | $entries = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . $wpdb->prefix . 'e2pdf_datasets`' . $where['sql'] . $orderby . '', $where['filter'])); |
| @@ -252,12 +298,12 @@ | ||
| 252 | 298 | $entry_title = $this->render($name); |
| 253 | 299 | if (!$entry_title) { |
| 254 | 300 | $entry_title = $entry->ID; |
| 255 | 301 | } |
| 256 | - $datasets[] = array( | |
| 302 | + $datasets[] = [ | |
| 257 | 303 | 'key' => $entry->ID, |
| 258 | 304 | 'value' => $entry_title, |
| 259 | - ); | |
| 305 | + ]; | |
| 260 | 306 | } |
| 261 | 307 | } |
| 262 | 308 | } |
| 263 | 309 | return $datasets; |
| @@ -285,8 +331,47 @@ | ||
| 285 | 331 | $actions->delete = true; |
| 286 | 332 | return $actions; |
| 287 | 333 | } |
| 288 | 334 | |
| 335 | + // get forms blocks | |
| 336 | + public function get_forms_blocks($blocks) { | |
| 337 | + $forms = []; | |
| 338 | + foreach ($blocks as $block) { | |
| 339 | + if ('divi/contact-form' === $block['blockName']) { | |
| 340 | + $forms[] = $block; | |
| 341 | + } | |
| 342 | + if (!empty($block['innerBlocks'])) { | |
| 343 | + $nested_forms = $this->get_forms_blocks($block['innerBlocks']); | |
| 344 | + $forms = array_merge($forms, $nested_forms); | |
| 345 | + } | |
| 346 | + } | |
| 347 | + return $forms; | |
| 348 | + } | |
| 349 | + | |
| 350 | + // get fields blocks | |
| 351 | + public function get_fields_blocks($form) { | |
| 352 | + $fields = []; | |
| 353 | + if (!empty($form['innerBlocks'])) { | |
| 354 | + foreach ($form['innerBlocks'] as $block) { | |
| 355 | + if ('divi/contact-field' === $block['blockName']) { | |
| 356 | + $field_type = !empty($block['attrs']['fieldItem']['advanced']['type']['desktop']['value']) ? $block['attrs']['fieldItem']['advanced']['type']['desktop']['value'] : ''; | |
| 357 | + $field_label = !empty($block['attrs']['fieldItem']['innerContent']['desktop']['value']) ? $block['attrs']['fieldItem']['innerContent']['desktop']['value'] : ''; | |
| 358 | + $field_id = !empty($block['attrs']['fieldItem']['advanced']['id']['desktop']['value']) ? $block['attrs']['fieldItem']['advanced']['id']['desktop']['value'] : ''; | |
| 359 | + $fields[] = [ | |
| 360 | + 'field_type' => $field_type, | |
| 361 | + 'field_title' => $field_label, | |
| 362 | + 'field_id' => $field_id, | |
| 363 | + ]; | |
| 364 | + } | |
| 365 | + if (!empty($block['innerBlocks'])) { | |
| 366 | + $nested_fields = $this->get_fields_blocks($block); | |
| 367 | + $fields = array_merge($fields, $nested_fields); | |
| 368 | + } | |
| 369 | + } | |
| 370 | + } | |
| 371 | + return $fields; | |
| 372 | + } | |
| 373 | + | |
| 289 | 374 | // item |
| 290 | 375 | public function item($item_id = false) { |
| 291 | 376 | if (!$item_id && $this->get('item')) { |
| 292 | 377 | $item_id = $this->get('item'); |
| @@ -297,12 +382,12 @@ | ||
| 297 | 382 | $item->name = $item_id; |
| 298 | 383 | $form = $this->get_form($item_id); |
| 299 | 384 | if (isset($form->ID)) { |
| 300 | 385 | $item->url = $this->helper->get_url( |
| 301 | - array( | |
| 386 | + [ | |
| 302 | 387 | 'post' => $form->ID, |
| 303 | 388 | 'action' => 'edit', |
| 304 | - ), 'post.php?' | |
| 389 | + ], 'post.php?' | |
| 305 | 390 | ); |
| 306 | 391 | } else { |
| 307 | 392 | $item->url = ''; |
| 308 | 393 | } |
| @@ -317,34 +402,43 @@ | ||
| 317 | 402 | // get form |
| 318 | 403 | public function get_form($item_id = false) { |
| 319 | 404 | global $wpdb; |
| 320 | 405 | $item_post = false; |
| 321 | - $condition = array( | |
| 322 | - 'post_content' => array( | |
| 406 | + $condition = [ | |
| 407 | + 'post_content' => [ | |
| 323 | 408 | 'condition' => 'LIKE', |
| 324 | 409 | 'value' => '%admin_label="' . $item_id . '"%', |
| 325 | 410 | 'type' => '%s', |
| 326 | - ), | |
| 327 | - 'post_type' => array( | |
| 411 | + 'or' => [ | |
| 412 | + [ | |
| 413 | + 'post_content' => [ | |
| 414 | + 'condition' => 'LIKE', | |
| 415 | + 'value' => '%"meta":{"adminLabel":{"desktop":{"value":"' . $item_id . '"%', | |
| 416 | + 'type' => '%s', | |
| 417 | + ], | |
| 418 | + ], | |
| 419 | + ], | |
| 420 | + ], | |
| 421 | + 'post_type' => [ | |
| 328 | 422 | 'condition' => '<>', |
| 329 | - 'value' => array( | |
| 423 | + 'value' => [ | |
| 330 | 424 | 'revision', |
| 331 | 425 | 'et_pb_layout', |
| 332 | - ), | |
| 426 | + ], | |
| 333 | 427 | 'type' => '%s', |
| 334 | - ), | |
| 335 | - ); | |
| 428 | + ], | |
| 429 | + ]; | |
| 336 | 430 | |
| 337 | - $order_condition = array( | |
| 431 | + $order_condition = [ | |
| 338 | 432 | 'orderby' => 'id', |
| 339 | 433 | 'order' => 'desc', |
| 340 | - ); | |
| 434 | + ]; | |
| 341 | 435 | |
| 342 | 436 | $where = $this->helper->load('db')->prepare_where($condition); |
| 343 | 437 | $orderby = $this->helper->load('db')->prepare_orderby($order_condition); |
| 344 | 438 | // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare |
| 345 | 439 | $posts = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . $wpdb->prefix . 'posts`' . $where['sql'] . $orderby . '', $where['filter'])); |
| 346 | - foreach ($posts as $key => $post) { | |
| 440 | + foreach ($posts as $post) { | |
| 347 | 441 | if (in_array($item_id, $this->get_forms($post->post_content))) { |
| 348 | 442 | $item_post = $post; |
| 349 | 443 | break; |
| 350 | 444 | } |
| @@ -389,24 +483,12 @@ | ||
| 389 | 483 | |
| 390 | 484 | // strip shortcodes |
| 391 | 485 | public function strip_shortcodes($value) { |
| 392 | 486 | $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', '', $value); |
| 393 | - $value = preg_replace('~%%[^%]*%%~', '', $value); | |
| 487 | + $value = preg_replace('~%%[^%%]*%%~', '', $value); | |
| 394 | 488 | return $value; |
| 395 | 489 | } |
| 396 | 490 | |
| 397 | - public function strip_math($value, &$replacements) { | |
| 398 | - if ($value) { | |
| 399 | - preg_match_all('~%%[^%]*%%~', $value, $matches); | |
| 400 | - foreach ($matches[0] as $match) { | |
| 401 | - $index = count($replacements) + 1; | |
| 402 | - $replacements[] = $match; | |
| 403 | - $value = str_replace($match, '%' . $index . '$s', $value); | |
| 404 | - } | |
| 405 | - } | |
| 406 | - return $value; | |
| 407 | - } | |
| 408 | - | |
| 409 | 491 | // convert shortcodes |
| 410 | 492 | public function convert_shortcodes($value, $to = false, $html = false) { |
| 411 | 493 | if ($value) { |
| 412 | 494 | if ($to) { |
| @@ -424,19 +506,21 @@ | ||
| 424 | 506 | |
| 425 | 507 | // auto |
| 426 | 508 | public function auto() { |
| 427 | 509 | |
| 428 | - $response = []; | |
| 429 | 510 | $elements = []; |
| 430 | 511 | |
| 431 | 512 | if ($this->get('item')) { |
| 432 | 513 | $post = $this->get_form($this->get('item')); |
| 433 | 514 | if ($post && isset($post->post_content)) { |
| 515 | + | |
| 516 | + $source = ''; | |
| 434 | 517 | $content = $post->post_content; |
| 435 | - if (false !== strpos($content, '[')) { | |
| 436 | - $shortcode_tags = array( | |
| 518 | + | |
| 519 | + if ($this->divi4_form($content)) { | |
| 520 | + $shortcode_tags = [ | |
| 437 | 521 | 'et_pb_contact_form', |
| 438 | - ); | |
| 522 | + ]; | |
| 439 | 523 | preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); |
| 440 | 524 | $tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 441 | 525 | if (!empty($tagnames)) { |
| 442 | 526 | preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes); |
| @@ -442,248 +526,289 @@ | ||
| 442 | 526 | preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes); |
| 443 | 527 | foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 444 | 528 | $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); |
| 445 | 529 | $atts = shortcode_parse_atts($shortcode[3]); |
| 446 | - if (isset($atts['admin_label']) && $atts['admin_label'] == $this->get('item') && defined('ET_BUILDER_DIR')) { | |
| 447 | - | |
| 448 | - require_once ET_BUILDER_DIR . 'class-et-builder-element.php'; | |
| 449 | - require_once ET_BUILDER_DIR . 'functions.php'; | |
| 450 | - require_once ET_BUILDER_DIR . 'ab-testing.php'; | |
| 451 | - require_once ET_BUILDER_DIR . 'class-et-global-settings.php'; | |
| 452 | - if (file_exists(ET_BUILDER_DIR . 'module/type/WithSpamProtection.php')) { | |
| 453 | - require_once ET_BUILDER_DIR . 'module/type/WithSpamProtection.php'; | |
| 454 | - } | |
| 455 | - require_once ET_BUILDER_DIR . 'module/ContactForm.php'; | |
| 456 | - require_once ET_BUILDER_DIR . 'module/ContactFormItem.php'; | |
| 457 | - | |
| 458 | - new ET_Builder_Module_Contact_Form(); | |
| 459 | - new ET_Builder_Module_Contact_Form_Item(); | |
| 460 | - | |
| 530 | + if (isset($atts['admin_label']) && $atts['admin_label'] == $this->get('item')) { | |
| 531 | + $this->divi4_load(); | |
| 461 | 532 | $source = do_shortcode($shortcode_value); |
| 462 | - $dom = new DOMDocument(); | |
| 463 | - $html = $this->helper->load('convert')->load_html($source, $dom, true); | |
| 464 | - if ($html) { | |
| 465 | - $xml = $this->helper->load('xml'); | |
| 466 | - $xpath = new DomXPath($dom); | |
| 467 | - $blocks = $xpath->query("//*[contains(@class, 'et_pb_contact_field')]"); | |
| 468 | - foreach ($blocks as $element) { | |
| 533 | + } | |
| 534 | + } | |
| 535 | + } | |
| 536 | + } elseif ($this->divi5_form($content)) { | |
| 537 | + $blocks = $this->get_forms_blocks(parse_blocks($content)); | |
| 538 | + foreach ($blocks as $key => $block) { | |
| 539 | + $label = !empty($block['attrs']['module']['meta']['adminLabel']['desktop']['value']) ? $block['attrs']['module']['meta']['adminLabel']['desktop']['value'] : ''; | |
| 540 | + if ($label == $this->get('item')) { | |
| 541 | + $source = render_block($block); | |
| 542 | + break; | |
| 543 | + } | |
| 544 | + } | |
| 545 | + } | |
| 469 | 546 | |
| 470 | - if ($xml->get_node_value($element, 'data-type') == 'radio') { | |
| 547 | + if ($source) { | |
| 548 | + $dom = new DOMDocument(); | |
| 549 | + $html = $this->helper->load('convert')->load_html($source, $dom, true); | |
| 550 | + if ($html) { | |
| 551 | + $xml = $this->helper->load('xml'); | |
| 552 | + $xpath = new DomXPath($dom); | |
| 471 | 553 | |
| 472 | - $label = $xpath->query('.//label', $element)->item(0); | |
| 473 | - $check_handler = $xpath->query(".//input[contains(@class, 'et_pb_checkbox_handle')]", $element)->item(0); | |
| 554 | + // remove parent by class | |
| 555 | + $remove_parent_by_class = [ | |
| 556 | + 'et_pb_contact_captcha_question', | |
| 557 | + ]; | |
| 558 | + foreach ($remove_parent_by_class as $key => $class) { | |
| 559 | + $xml_elements = $xpath->query("//*[contains(@class, '{$class}')]/parent::*"); | |
| 560 | + foreach ($xml_elements as $xml_element) { | |
| 561 | + $xml_element->parentNode->removeChild($xml_element); | |
| 562 | + } | |
| 563 | + } | |
| 474 | 564 | |
| 475 | - $name = ''; | |
| 476 | - if ($check_handler) { | |
| 477 | - $name = '%%' . $xml->get_node_value($check_handler, 'data-original_id') . '%%'; | |
| 478 | - } | |
| 565 | + $blocks = $xpath->query("//*[contains(@class, 'et_pb_contact_field')]"); | |
| 566 | + foreach ($blocks as $element) { | |
| 479 | 567 | |
| 480 | - if ($label) { | |
| 481 | - $elements[] = $this->auto_field( | |
| 482 | - $element, | |
| 483 | - array( | |
| 484 | - 'type' => 'e2pdf-html', | |
| 485 | - 'block' => true, | |
| 486 | - 'class' => $xml->get_node_value($element, 'class'), | |
| 487 | - 'properties' => array( | |
| 488 | - 'top' => '20', | |
| 489 | - 'left' => '20', | |
| 490 | - 'right' => '20', | |
| 491 | - 'width' => '100%', | |
| 492 | - 'height' => 'auto', | |
| 493 | - 'value' => $label->nodeValue, | |
| 494 | - ), | |
| 495 | - ) | |
| 496 | - ); | |
| 497 | - } | |
| 568 | + if ($xml->get_node_value($element, 'data-type') == 'radio') { | |
| 498 | 569 | |
| 499 | - $fields = $xpath->query("//*[contains(@class, 'et_pb_contact_field_radio')]", $element); | |
| 500 | - foreach ($fields as $field) { | |
| 501 | - $radio_label = $xpath->query('.//label', $field)->item(0); | |
| 502 | - $radio = $xpath->query(".//input[@type='radio']", $field)->item(0); | |
| 570 | + $label = $xpath->query('.//label', $element)->item(0); | |
| 571 | + $check_handler = $xpath->query(".//input[contains(@class, 'et_pb_checkbox_handle')]", $element)->item(0); | |
| 503 | 572 | |
| 504 | - if ( | |
| 505 | - $radio->attributes->getNamedItem('data-original_id') && | |
| 506 | - $radio->attributes->getNamedItem('value') | |
| 507 | - ) { | |
| 508 | - $elements[] = $this->auto_field( | |
| 509 | - $field, | |
| 510 | - array( | |
| 511 | - 'type' => 'e2pdf-radio', | |
| 512 | - 'class' => $xml->get_node_value($field, 'class'), | |
| 513 | - 'properties' => array( | |
| 514 | - 'top' => '5', | |
| 515 | - 'width' => 'auto', | |
| 516 | - 'height' => 'auto', | |
| 517 | - 'value' => '%%' . $xml->get_node_value($radio, 'data-original_id') . '%%', | |
| 518 | - 'option' => $xml->get_node_value($radio, 'value'), | |
| 519 | - 'group' => '%%' . $xml->get_node_value($radio, 'data-original_id') . '%%', | |
| 520 | - ), | |
| 521 | - ) | |
| 522 | - ); | |
| 523 | - } | |
| 573 | + $name = ''; | |
| 574 | + if ($check_handler) { | |
| 575 | + $name = '%%' . $xml->get_node_value($check_handler, 'data-original_id') . '%%'; | |
| 576 | + } | |
| 524 | 577 | |
| 525 | - if ($radio_label) { | |
| 526 | - $elements[] = $this->auto_field( | |
| 527 | - $radio, | |
| 528 | - array( | |
| 529 | - 'type' => 'e2pdf-html', | |
| 530 | - 'float' => true, | |
| 531 | - 'class' => $xml->get_node_value($radio, 'class'), | |
| 532 | - 'properties' => array( | |
| 533 | - 'left' => '5', | |
| 534 | - 'width' => '100%', | |
| 535 | - 'height' => 'auto', | |
| 536 | - 'value' => $radio_label->nodeValue, | |
| 537 | - ), | |
| 538 | - ) | |
| 539 | - ); | |
| 540 | - } | |
| 541 | - } | |
| 542 | - } elseif ($xml->get_node_value($element, 'data-type') == 'checkbox') { | |
| 578 | + if ($label) { | |
| 579 | + $elements[] = $this->auto_field( | |
| 580 | + $element, | |
| 581 | + [ | |
| 582 | + 'type' => 'e2pdf-html', | |
| 583 | + 'block' => true, | |
| 584 | + 'class' => $xml->get_node_value($element, 'class'), | |
| 585 | + 'properties' => [ | |
| 586 | + 'top' => '20', | |
| 587 | + 'left' => '20', | |
| 588 | + 'right' => '20', | |
| 589 | + 'width' => '100%', | |
| 590 | + 'height' => 'auto', | |
| 591 | + 'value' => $label->nodeValue, | |
| 592 | + ], | |
| 593 | + ] | |
| 594 | + ); | |
| 595 | + } | |
| 543 | 596 | |
| 544 | - $label = $xpath->query('.//label', $element)->item(0); | |
| 545 | - $check_handler = $xpath->query(".//input[contains(@class, 'et_pb_checkbox_handle')]", $element)->item(0); | |
| 597 | + $fields = $xpath->query(".//*[contains(@class, 'et_pb_contact_field_radio')]", $element); | |
| 598 | + foreach ($fields as $field) { | |
| 599 | + $radio_label = $xpath->query('.//label', $field)->item(0); | |
| 600 | + $radio = $xpath->query(".//input[@type='radio']", $field)->item(0); | |
| 546 | 601 | |
| 547 | - $name = ''; | |
| 548 | - if ($check_handler) { | |
| 549 | - $name = '%%' . $xml->get_node_value($check_handler, 'data-original_id') . '%%'; | |
| 550 | - } | |
| 602 | + if ( | |
| 603 | + $radio->attributes->getNamedItem('data-original_id') && | |
| 604 | + $radio->attributes->getNamedItem('value') | |
| 605 | + ) { | |
| 606 | + $elements[] = $this->auto_field( | |
| 607 | + $field, | |
| 608 | + [ | |
| 609 | + 'type' => 'e2pdf-radio', | |
| 610 | + 'class' => $xml->get_node_value($field, 'class'), | |
| 611 | + 'properties' => [ | |
| 612 | + 'top' => '5', | |
| 613 | + 'width' => 'auto', | |
| 614 | + 'height' => 'auto', | |
| 615 | + 'value' => '%%' . $xml->get_node_value($radio, 'data-original_id') . '%%', | |
| 616 | + 'option' => sanitize_text_field($xml->get_node_value($radio, 'value')), | |
| 617 | + 'group' => '%%' . $xml->get_node_value($radio, 'data-original_id') . '%%', | |
| 618 | + ], | |
| 619 | + ] | |
| 620 | + ); | |
| 621 | + } | |
| 551 | 622 | |
| 552 | - if ($label) { | |
| 553 | - $elements[] = $this->auto_field( | |
| 554 | - $element, | |
| 555 | - array( | |
| 556 | - 'type' => 'e2pdf-html', | |
| 557 | - 'block' => true, | |
| 558 | - 'class' => $xml->get_node_value($element, 'class'), | |
| 559 | - 'properties' => array( | |
| 560 | - 'top' => '20', | |
| 561 | - 'left' => '20', | |
| 562 | - 'right' => '20', | |
| 563 | - 'width' => '100%', | |
| 564 | - 'height' => 'auto', | |
| 565 | - 'value' => $label->nodeValue, | |
| 566 | - ), | |
| 567 | - ) | |
| 568 | - ); | |
| 569 | - } | |
| 623 | + if ($radio_label) { | |
| 624 | + $elements[] = $this->auto_field( | |
| 625 | + $radio, | |
| 626 | + [ | |
| 627 | + 'type' => 'e2pdf-html', | |
| 628 | + 'float' => true, | |
| 629 | + 'class' => $xml->get_node_value($radio, 'class'), | |
| 630 | + 'properties' => [ | |
| 631 | + 'left' => '5', | |
| 632 | + 'width' => '100%', | |
| 633 | + 'height' => 'auto', | |
| 634 | + 'value' => $radio_label->nodeValue, | |
| 635 | + ], | |
| 636 | + ] | |
| 637 | + ); | |
| 638 | + } | |
| 639 | + } | |
| 640 | + } elseif ($xml->get_node_value($element, 'data-type') == 'checkbox') { | |
| 641 | + $label = $xpath->query('.//label', $element)->item(0); | |
| 642 | + $check_handler = $xpath->query(".//input[contains(@class, 'et_pb_checkbox_handle')]", $element)->item(0); | |
| 570 | 643 | |
| 571 | - $fields = $xpath->query("//*[contains(@class, 'et_pb_contact_field_checkbox')]", $element); | |
| 572 | - foreach ($fields as $field) { | |
| 573 | - $checkbox_label = $xpath->query('.//label', $field)->item(0); | |
| 574 | - $checkbox = $xpath->query(".//input[@type='checkbox']", $field)->item(0); | |
| 644 | + $name = ''; | |
| 645 | + if ($check_handler) { | |
| 646 | + $name = '%%' . $xml->get_node_value($check_handler, 'data-original_id') . '%%'; | |
| 647 | + } | |
| 575 | 648 | |
| 576 | - $elements[] = $this->auto_field( | |
| 577 | - $field, | |
| 578 | - array( | |
| 579 | - 'type' => 'e2pdf-checkbox', | |
| 580 | - 'class' => $xml->get_node_value($field, 'class'), | |
| 581 | - 'properties' => array( | |
| 582 | - 'top' => '5', | |
| 583 | - 'width' => 'auto', | |
| 584 | - 'height' => 'auto', | |
| 585 | - 'value' => $name, | |
| 586 | - 'option' => $xml->get_node_value($checkbox, 'value'), | |
| 587 | - ), | |
| 588 | - ) | |
| 589 | - ); | |
| 649 | + if ($label) { | |
| 650 | + $elements[] = $this->auto_field( | |
| 651 | + $element, | |
| 652 | + [ | |
| 653 | + 'type' => 'e2pdf-html', | |
| 654 | + 'block' => true, | |
| 655 | + 'class' => $xml->get_node_value($element, 'class'), | |
| 656 | + 'properties' => [ | |
| 657 | + 'top' => '20', | |
| 658 | + 'left' => '20', | |
| 659 | + 'right' => '20', | |
| 660 | + 'width' => '100%', | |
| 661 | + 'height' => 'auto', | |
| 662 | + 'value' => $label->nodeValue, | |
| 663 | + ], | |
| 664 | + ] | |
| 665 | + ); | |
| 666 | + } | |
| 590 | 667 | |
| 591 | - if ($checkbox_label) { | |
| 592 | - $elements[] = $this->auto_field( | |
| 593 | - $checkbox, | |
| 594 | - array( | |
| 595 | - 'type' => 'e2pdf-html', | |
| 596 | - 'float' => true, | |
| 597 | - 'class' => $xml->get_node_value($checkbox, 'class'), | |
| 598 | - 'properties' => array( | |
| 599 | - 'left' => '5', | |
| 600 | - 'width' => '100%', | |
| 601 | - 'height' => 'auto', | |
| 602 | - 'value' => $checkbox_label->nodeValue, | |
| 603 | - ), | |
| 604 | - ) | |
| 605 | - ); | |
| 606 | - } | |
| 607 | - } | |
| 608 | - } else { | |
| 668 | + $fields = $xpath->query(".//*[contains(@class, 'et_pb_contact_field_checkbox')]", $element); | |
| 669 | + foreach ($fields as $field) { | |
| 670 | + $checkbox_label = $xpath->query('.//label', $field)->item(0); | |
| 671 | + $checkbox = $xpath->query(".//input[@type='checkbox']", $field)->item(0); | |
| 609 | 672 | |
| 610 | - $label = $xpath->query('.//label', $element)->item(0); | |
| 611 | - $input_text = $xpath->query(".//input[@type='text']", $element)->item(0); | |
| 612 | - $select = $xpath->query('.//select', $element)->item(0); | |
| 613 | - $textarea = $xpath->query('.//textarea', $element)->item(0); | |
| 673 | + $elements[] = $this->auto_field( | |
| 674 | + $field, | |
| 675 | + [ | |
| 676 | + 'type' => 'e2pdf-checkbox', | |
| 677 | + 'class' => $xml->get_node_value($field, 'class'), | |
| 678 | + 'properties' => [ | |
| 679 | + 'top' => '5', | |
| 680 | + 'width' => 'auto', | |
| 681 | + 'height' => 'auto', | |
| 682 | + 'value' => $name, | |
| 683 | + 'option' => sanitize_text_field($xml->get_node_value($checkbox, 'value')), | |
| 684 | + ], | |
| 685 | + ] | |
| 686 | + ); | |
| 614 | 687 | |
| 615 | - if ($label && ($input_text || $select || $textarea)) { | |
| 616 | - $elements[] = $this->auto_field( | |
| 617 | - $element, | |
| 618 | - array( | |
| 619 | - 'type' => 'e2pdf-html', | |
| 620 | - 'block' => true, | |
| 621 | - 'class' => $xml->get_node_value($element, 'class'), | |
| 622 | - 'properties' => array( | |
| 623 | - 'top' => '20', | |
| 624 | - 'left' => '20', | |
| 625 | - 'right' => '20', | |
| 626 | - 'width' => '100%', | |
| 627 | - 'height' => 'auto', | |
| 628 | - 'value' => $label->nodeValue, | |
| 629 | - ), | |
| 630 | - ) | |
| 631 | - ); | |
| 632 | - } | |
| 688 | + if ($checkbox_label) { | |
| 689 | + $elements[] = $this->auto_field( | |
| 690 | + $checkbox, | |
| 691 | + [ | |
| 692 | + 'type' => 'e2pdf-html', | |
| 693 | + 'float' => true, | |
| 694 | + 'class' => $xml->get_node_value($checkbox, 'class'), | |
| 695 | + 'properties' => [ | |
| 696 | + 'left' => '5', | |
| 697 | + 'width' => '100%', | |
| 698 | + 'height' => 'auto', | |
| 699 | + 'value' => $checkbox_label->nodeValue, | |
| 700 | + ], | |
| 701 | + ] | |
| 702 | + ); | |
| 703 | + } | |
| 704 | + } | |
| 705 | + } else { | |
| 706 | + $label = $xpath->query('.//label', $element)->item(0); | |
| 707 | + $input_text = $xpath->query(".//input[@type='text']", $element)->item(0); | |
| 708 | + $select = $xpath->query('.//select', $element)->item(0); | |
| 709 | + $textarea = $xpath->query('.//textarea', $element)->item(0); | |
| 633 | 710 | |
| 634 | - if ($input_text) { | |
| 635 | - $elements[] = $this->auto_field( | |
| 636 | - $input_text, | |
| 637 | - array( | |
| 638 | - 'type' => 'e2pdf-input', | |
| 639 | - 'class' => $xml->get_node_value($input_text, 'class'), | |
| 640 | - 'properties' => array( | |
| 641 | - 'top' => '5', | |
| 642 | - 'width' => '100%', | |
| 643 | - 'height' => 'auto', | |
| 644 | - 'value' => '%%' . $xml->get_node_value($input_text, 'data-original_id') . '%%', | |
| 645 | - ), | |
| 646 | - ) | |
| 647 | - ); | |
| 648 | - } elseif ($select) { | |
| 649 | - $options_tmp = []; | |
| 650 | - $options = $xpath->query('.//option', $select); | |
| 651 | - foreach ($options as $option) { | |
| 652 | - $options_tmp[] = $xml->get_node_value($option, 'value'); | |
| 653 | - } | |
| 711 | + if ($label && ($input_text || $select || $textarea)) { | |
| 712 | + $elements[] = $this->auto_field( | |
| 713 | + $element, | |
| 714 | + [ | |
| 715 | + 'type' => 'e2pdf-html', | |
| 716 | + 'block' => true, | |
| 717 | + 'class' => $xml->get_node_value($element, 'class'), | |
| 718 | + 'properties' => [ | |
| 719 | + 'top' => '20', | |
| 720 | + 'left' => '20', | |
| 721 | + 'right' => '20', | |
| 722 | + 'width' => '100%', | |
| 723 | + 'height' => 'auto', | |
| 724 | + 'value' => $label->nodeValue, | |
| 725 | + ], | |
| 726 | + ] | |
| 727 | + ); | |
| 728 | + } | |
| 654 | 729 | |
| 655 | - $elements[] = $this->auto_field( | |
| 656 | - $select, | |
| 657 | - array( | |
| 658 | - 'type' => 'e2pdf-select', | |
| 659 | - 'class' => $xml->get_node_value($select, 'class'), | |
| 660 | - 'properties' => array( | |
| 661 | - 'top' => '5', | |
| 662 | - 'width' => '100%', | |
| 663 | - 'height' => 'auto', | |
| 664 | - 'options' => implode("\n", $options_tmp), | |
| 665 | - 'value' => '%%' . $xml->get_node_value($select, 'data-original_id') . '%%', | |
| 666 | - ), | |
| 667 | - ) | |
| 668 | - ); | |
| 669 | - } elseif ($textarea) { | |
| 670 | - $elements[] = $this->auto_field( | |
| 671 | - $textarea, | |
| 672 | - array( | |
| 673 | - 'type' => 'e2pdf-textarea', | |
| 674 | - 'class' => $xml->get_node_value($textarea, 'class'), | |
| 675 | - 'properties' => array( | |
| 676 | - 'top' => '5', | |
| 677 | - 'width' => '100%', | |
| 678 | - 'height' => '150', | |
| 679 | - 'value' => '%%' . $xml->get_node_value($textarea, 'data-original_id') . '%%', | |
| 680 | - ), | |
| 681 | - ) | |
| 682 | - ); | |
| 683 | - } | |
| 684 | - } | |
| 730 | + if ($input_text) { | |
| 731 | + $data_type = $input_text->parentNode->getAttribute('data-type'); | |
| 732 | + if ($data_type === 'signature-pad') { | |
| 733 | + $elements[] = $this->auto_field( | |
| 734 | + $input_text, | |
| 735 | + [ | |
| 736 | + 'type' => 'e2pdf-signature', | |
| 737 | + 'properties' => [ | |
| 738 | + 'top' => '5', | |
| 739 | + 'width' => '100%', | |
| 740 | + 'height' => '150', | |
| 741 | + 'dimension' => '1', | |
| 742 | + 'block_dimension' => '1', | |
| 743 | + 'value' => '%%' . $xml->get_node_value($input_text, 'data-original_id') . '%%', | |
| 744 | + ], | |
| 745 | + ] | |
| 746 | + ); | |
| 747 | + } elseif ($data_type === 'file') { | |
| 748 | + $elements[] = $this->auto_field( | |
| 749 | + $input_text, | |
| 750 | + [ | |
| 751 | + 'type' => 'e2pdf-textarea', | |
| 752 | + 'class' => $xml->get_node_value($input_text, 'class'), | |
| 753 | + 'properties' => [ | |
| 754 | + 'top' => '5', | |
| 755 | + 'width' => '100%', | |
| 756 | + 'height' => '150', | |
| 757 | + 'value' => '%%' . $xml->get_node_value($input_text, 'data-original_id') . '%%', | |
| 758 | + ], | |
| 759 | + ] | |
| 760 | + ); | |
| 761 | + } else { | |
| 762 | + $elements[] = $this->auto_field( | |
| 763 | + $input_text, | |
| 764 | + [ | |
| 765 | + 'type' => 'e2pdf-input', | |
| 766 | + 'class' => $xml->get_node_value($input_text, 'class'), | |
| 767 | + 'properties' => [ | |
| 768 | + 'top' => '5', | |
| 769 | + 'width' => '100%', | |
| 770 | + 'height' => 'auto', | |
| 771 | + 'value' => '%%' . $xml->get_node_value($input_text, 'data-original_id') . '%%', | |
| 772 | + ], | |
| 773 | + ] | |
| 774 | + ); | |
| 685 | 775 | } |
| 776 | + } elseif ($select) { | |
| 777 | + $options_tmp = []; | |
| 778 | + $options = $xpath->query('.//option', $select); | |
| 779 | + foreach ($options as $option) { | |
| 780 | + $options_tmp[] = sanitize_text_field($xml->get_node_value($option, 'value')); | |
| 781 | + } | |
| 782 | + | |
| 783 | + $elements[] = $this->auto_field( | |
| 784 | + $select, | |
| 785 | + [ | |
| 786 | + 'type' => 'e2pdf-select', | |
| 787 | + 'class' => $xml->get_node_value($select, 'class'), | |
| 788 | + 'properties' => [ | |
| 789 | + 'top' => '5', | |
| 790 | + 'width' => '100%', | |
| 791 | + 'height' => 'auto', | |
| 792 | + 'options' => implode("\n", $options_tmp), | |
| 793 | + 'value' => '%%' . $xml->get_node_value($select, 'data-original_id') . '%%', | |
| 794 | + ], | |
| 795 | + ] | |
| 796 | + ); | |
| 797 | + } elseif ($textarea) { | |
| 798 | + $elements[] = $this->auto_field( | |
| 799 | + $textarea, | |
| 800 | + [ | |
| 801 | + 'type' => 'e2pdf-textarea', | |
| 802 | + 'class' => $xml->get_node_value($textarea, 'class'), | |
| 803 | + 'properties' => [ | |
| 804 | + 'top' => '5', | |
| 805 | + 'width' => '100%', | |
| 806 | + 'height' => '150', | |
| 807 | + 'value' => '%%' . $xml->get_node_value($textarea, 'data-original_id') . '%%', | |
| 808 | + ], | |
| 809 | + ] | |
| 810 | + ); | |
| 686 | 811 | } |
| 687 | 812 | } |
| 688 | 813 | } |
| 689 | 814 | } |
| @@ -689,18 +814,17 @@ | ||
| 689 | 814 | } |
| 690 | 815 | } |
| 691 | 816 | } |
| 692 | 817 | } |
| 693 | - | |
| 694 | - $response['page'] = array( | |
| 695 | - 'bottom' => '20', | |
| 696 | - 'top' => '20', | |
| 697 | - 'right' => '20', | |
| 698 | - 'left' => '20', | |
| 699 | - ); | |
| 700 | - $response['elements'] = $elements; | |
| 701 | - | |
| 702 | - return $response; | |
| 818 | + return [ | |
| 819 | + 'page' => [ | |
| 820 | + 'bottom' => '20', | |
| 821 | + 'top' => '20', | |
| 822 | + 'right' => '20', | |
| 823 | + 'left' => '20', | |
| 824 | + ], | |
| 825 | + 'elements' => $elements, | |
| 826 | + ]; | |
| 703 | 827 | } |
| 704 | 828 | |
| 705 | 829 | // auto map |
| 706 | 830 | public function auto_map($name = false) { |
| @@ -708,13 +832,12 @@ | ||
| 708 | 832 | if ($item) { |
| 709 | 833 | $post = $this->get_form($item); |
| 710 | 834 | if ($post && isset($post->post_content)) { |
| 711 | 835 | $content = $post->post_content; |
| 712 | - | |
| 713 | - if (false !== strpos($content, '[')) { | |
| 714 | - $shortcode_tags = array( | |
| 836 | + if ($this->divi4_form($content)) { | |
| 837 | + $shortcode_tags = [ | |
| 715 | 838 | 'et_pb_contact_form', |
| 716 | - ); | |
| 839 | + ]; | |
| 717 | 840 | preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); |
| 718 | 841 | $tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 719 | 842 | if (!empty($tagnames)) { |
| 720 | 843 | preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes); |
| @@ -722,11 +845,11 @@ | ||
| 722 | 845 | $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); |
| 723 | 846 | $atts = shortcode_parse_atts($shortcode[3]); |
| 724 | 847 | if (isset($atts['admin_label']) && $atts['admin_label'] == $this->get('item')) { |
| 725 | 848 | $field_content = $shortcode_value; |
| 726 | - $field_shortcode_tags = array( | |
| 849 | + $field_shortcode_tags = [ | |
| 727 | 850 | 'et_pb_contact_field', |
| 728 | - ); | |
| 851 | + ]; | |
| 729 | 852 | preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $field_content, $field_matches); |
| 730 | 853 | $field_tagnames = array_intersect($field_shortcode_tags, $field_matches[1]); |
| 731 | 854 | if (!empty($field_tagnames)) { |
| 732 | 855 | preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($field_tagnames) . '/', $field_content, $field_shortcodes); |
| @@ -732,12 +855,12 @@ | ||
| 732 | 855 | preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($field_tagnames) . '/', $field_content, $field_shortcodes); |
| 733 | 856 | foreach ($field_shortcodes[0] as $field_key => $field_shortcode_value) { |
| 734 | 857 | $field_shortcode = []; |
| 735 | 858 | $field_shortcode[3] = $field_shortcodes[3][$field_key]; |
| 736 | - $field_atts = shortcode_parse_atts($field_shortcode[3]); | |
| 737 | - if (isset($field_atts['field_title']) && isset($field_atts['field_id'])) { | |
| 738 | - if ($field_atts['field_title'] == $name || $field_atts['field_id'] == $name) { | |
| 739 | - return '%%' . strtolower($field_atts['field_id']) . '%%'; | |
| 859 | + $field = shortcode_parse_atts($field_shortcode[3]); | |
| 860 | + if (isset($field['field_title']) && isset($field['field_id'])) { | |
| 861 | + if ($field['field_title'] == $name || $field['field_id'] == $name) { | |
| 862 | + return '%%' . strtolower($field['field_id']) . '%%'; | |
| 740 | 863 | } |
| 741 | 864 | } |
| 742 | 865 | } |
| 743 | 866 | } |
| @@ -743,8 +866,26 @@ | ||
| 743 | 866 | } |
| 744 | 867 | } |
| 745 | 868 | } |
| 746 | 869 | } |
| 870 | + } elseif ($this->divi5_form($content)) { | |
| 871 | + $blocks = $this->get_forms_blocks(parse_blocks($content)); | |
| 872 | + foreach ($blocks as $key => $block) { | |
| 873 | + $label = !empty($block['attrs']['module']['meta']['adminLabel']['desktop']['value']) ? $block['attrs']['module']['meta']['adminLabel']['desktop']['value'] : ''; | |
| 874 | + if ($label == $this->get('item')) { | |
| 875 | + $fields = $this->get_fields_blocks($block); | |
| 876 | + if (!empty($fields)) { | |
| 877 | + foreach ($fields as $field) { | |
| 878 | + if (isset($field['field_title']) && isset($field['field_id'])) { | |
| 879 | + if ($field['field_title'] == $name || $field['field_id'] == $name) { | |
| 880 | + return '%%' . strtolower($field['field_id']) . '%%'; | |
| 881 | + } | |
| 882 | + } | |
| 883 | + } | |
| 884 | + } | |
| 885 | + } | |
| 886 | + break; | |
| 887 | + } | |
| 747 | 888 | } |
| 748 | 889 | } |
| 749 | 890 | } |
| 750 | 891 | |
| @@ -771,11 +912,11 @@ | ||
| 771 | 912 | $classes = explode(' ', $element['class']); |
| 772 | 913 | unset($element['class']); |
| 773 | 914 | } |
| 774 | 915 | |
| 775 | - $float_classes = array( | |
| 916 | + $float_classes = [ | |
| 776 | 917 | 'et_pb_contact_field_half', |
| 777 | - ); | |
| 918 | + ]; | |
| 778 | 919 | $array_intersect = array_intersect($classes, $float_classes); |
| 779 | 920 | |
| 780 | 921 | if (!empty($array_intersect) && $element['block']) { |
| 781 | 922 | $element['float'] = true; |
| @@ -815,15 +956,14 @@ | ||
| 815 | 956 | |
| 816 | 957 | if ($this->get('item')) { |
| 817 | 958 | $post = $this->get_form($this->get('item')); |
| 818 | 959 | if ($post && isset($post->post_content)) { |
| 819 | - | |
| 820 | 960 | $content = $post->post_content; |
| 821 | 961 | |
| 822 | - if (false !== strpos($content, '[')) { | |
| 823 | - $shortcode_tags = array( | |
| 962 | + if ($this->divi4_form($content)) { | |
| 963 | + $shortcode_tags = [ | |
| 824 | 964 | 'et_pb_contact_form', |
| 825 | - ); | |
| 965 | + ]; | |
| 826 | 966 | preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); |
| 827 | 967 | $tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 828 | 968 | if (!empty($tagnames)) { |
| 829 | 969 | preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes); |
| @@ -830,98 +970,123 @@ | ||
| 830 | 970 | foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 831 | 971 | $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); |
| 832 | 972 | $atts = shortcode_parse_atts($shortcode[3]); |
| 833 | 973 | if (isset($atts['admin_label']) && $atts['admin_label'] == $this->get('item')) { |
| 834 | - require_once ET_BUILDER_DIR . 'class-et-builder-element.php'; | |
| 835 | - require_once ET_BUILDER_DIR . 'functions.php'; | |
| 836 | - require_once ET_BUILDER_DIR . 'ab-testing.php'; | |
| 837 | - require_once ET_BUILDER_DIR . 'class-et-global-settings.php'; | |
| 838 | - if (file_exists(ET_BUILDER_DIR . 'module/type/WithSpamProtection.php')) { | |
| 839 | - require_once ET_BUILDER_DIR . 'module/type/WithSpamProtection.php'; | |
| 840 | - } | |
| 841 | - require_once ET_BUILDER_DIR . 'module/ContactForm.php'; | |
| 842 | - require_once ET_BUILDER_DIR . 'module/ContactFormItem.php'; | |
| 843 | - new ET_Builder_Module_Contact_Form(); | |
| 844 | - new ET_Builder_Module_Contact_Form_Item(); | |
| 974 | + $this->divi4_load(); | |
| 845 | 975 | $source = do_shortcode($shortcode_value); |
| 846 | - if ($source) { | |
| 847 | - $dom = new DOMDocument(); | |
| 848 | - $html = $this->helper->load('convert')->load_html($source, $dom, true); | |
| 849 | - } | |
| 850 | - if (!$source) { | |
| 851 | - return '<div class="e2pdf-vm-error">' . __("The form source is empty or doesn't exist", 'e2pdf') . '</div>'; | |
| 852 | - } elseif (!$html) { | |
| 853 | - return '<div class="e2pdf-vm-error">' . __('The form could not be parsed due the incorrect HTML', 'e2pdf') . '</div>'; | |
| 854 | - } else { | |
| 855 | - $xml = $this->helper->load('xml'); | |
| 856 | - $xpath = new DomXPath($dom); | |
| 976 | + } | |
| 977 | + } | |
| 978 | + } | |
| 979 | + } elseif ($this->divi5_form($content)) { | |
| 980 | + $blocks = $this->get_forms_blocks(parse_blocks($content)); | |
| 981 | + foreach ($blocks as $key => $block) { | |
| 982 | + $label = !empty($block['attrs']['module']['meta']['adminLabel']['desktop']['value']) ? $block['attrs']['module']['meta']['adminLabel']['desktop']['value'] : ''; | |
| 983 | + if ($label == $this->get('item')) { | |
| 984 | + $source = render_block($block); | |
| 985 | + break; | |
| 986 | + } | |
| 987 | + } | |
| 988 | + } | |
| 857 | 989 | |
| 858 | - // remove by name | |
| 859 | - $remove_by_name = array( | |
| 860 | - 'et_pb_contactform_submit_0', | |
| 861 | - '_wpnonce-et-pb-contact-form-submitted-0', | |
| 862 | - '_wp_http_referer', | |
| 863 | - ); | |
| 864 | - foreach ($remove_by_name as $key => $name) { | |
| 865 | - $elements = $xpath->query('//*[@name="' . $name . '"]'); | |
| 866 | - foreach ($elements as $element) { | |
| 867 | - $element->parentNode->removeChild($element); | |
| 868 | - } | |
| 869 | - } | |
| 990 | + if ($source) { | |
| 991 | + $dom = new DOMDocument(); | |
| 992 | + $html = $this->helper->load('convert')->load_html($source, $dom, true); | |
| 993 | + } | |
| 994 | + if (!$source) { | |
| 995 | + return '<div class="e2pdf-vm-error">' . __("The form source is empty or doesn't exist", 'e2pdf') . '</div>'; | |
| 996 | + } elseif (!$html) { | |
| 997 | + return '<div class="e2pdf-vm-error">' . __('The form could not be parsed due the incorrect HTML', 'e2pdf') . '</div>'; | |
| 998 | + } else { | |
| 999 | + $xml = $this->helper->load('xml'); | |
| 1000 | + $xpath = new DomXPath($dom); | |
| 870 | 1001 | |
| 871 | - // replace names | |
| 872 | - $fields = $xpath->query("//*[contains(@name, 'et_pb_contact_')]"); | |
| 873 | - foreach ($fields as $element) { | |
| 874 | - $xml->set_node_value($element, 'name', '%%' . $xml->get_node_value($element, 'data-original_id') . '%%'); | |
| 875 | - } | |
| 1002 | + // remove by name | |
| 1003 | + $remove_by_name = [ | |
| 1004 | + 'et_pb_contactform_submit_0', | |
| 1005 | + '_wpnonce-et-pb-contact-form-submitted-0', | |
| 1006 | + '_wp_http_referer', | |
| 1007 | + ]; | |
| 1008 | + foreach ($remove_by_name as $key => $name) { | |
| 1009 | + $xml_elements = $xpath->query('//*[@name="' . $name . '"]'); | |
| 1010 | + foreach ($xml_elements as $xml_element) { | |
| 1011 | + $xml_element->parentNode->removeChild($xml_element); | |
| 1012 | + } | |
| 1013 | + } | |
| 876 | 1014 | |
| 877 | - $checkboxes = $xpath->query("//*[contains(@class, 'et_pb_contact_field') and @data-type='checkbox']"); | |
| 878 | - foreach ($checkboxes as $element) { | |
| 879 | - $check_handler = $xpath->query(".//input[contains(@class, 'et_pb_checkbox_handle')]", $element)->item(0); | |
| 880 | - $name = ''; | |
| 881 | - if ($check_handler) { | |
| 882 | - $name = '%%' . $xml->get_node_value($check_handler, 'data-original_id') . '%%'; | |
| 883 | - } | |
| 884 | - $checks = $xpath->query(".//input[@type='checkbox']", $element); | |
| 885 | - foreach ($checks as $check) { | |
| 886 | - $xml->set_node_value($check, 'name', $name); | |
| 887 | - } | |
| 888 | - } | |
| 1015 | + // replace names | |
| 1016 | + $fields = $xpath->query("//*[contains(@name, 'et_pb_contact_')]"); | |
| 1017 | + foreach ($fields as $xml_element) { | |
| 1018 | + $xml->set_node_value($xml_element, 'name', '%%' . $xml->get_node_value($xml_element, 'data-original_id') . '%%'); | |
| 1019 | + } | |
| 889 | 1020 | |
| 890 | - // remove by class | |
| 891 | - $remove_by_class = array( | |
| 892 | - 'et_pb_contact_submit', | |
| 893 | - 'et_pb_contactform_validate_field', | |
| 894 | - 'et_pb_checkbox_handle', | |
| 895 | - ); | |
| 896 | - foreach ($remove_by_class as $key => $class) { | |
| 897 | - $elements = $xpath->query("//*[contains(@class, '{$class}')]"); | |
| 898 | - foreach ($elements as $element) { | |
| 899 | - $element->parentNode->removeChild($element); | |
| 900 | - } | |
| 901 | - } | |
| 1021 | + // checkboxes | |
| 1022 | + $checkboxes = $xpath->query("//*[contains(@class, 'et_pb_contact_field') and @data-type='checkbox']"); | |
| 1023 | + foreach ($checkboxes as $xml_element) { | |
| 1024 | + $check_handler = $xpath->query(".//input[contains(@class, 'et_pb_checkbox_handle')]", $xml_element)->item(0); | |
| 1025 | + $name = ''; | |
| 1026 | + if ($check_handler) { | |
| 1027 | + $name = '%%' . $xml->get_node_value($check_handler, 'data-original_id') . '%%'; | |
| 1028 | + } | |
| 1029 | + $checks = $xpath->query(".//input[@type='checkbox']", $xml_element); | |
| 1030 | + foreach ($checks as $check) { | |
| 1031 | + $xml->set_node_value($check, 'name', $name); | |
| 1032 | + $xml->set_node_value($check, 'value', sanitize_text_field($xml->get_node_value($check, 'value'))); | |
| 1033 | + } | |
| 1034 | + } | |
| 902 | 1035 | |
| 903 | - // remove parent by class | |
| 904 | - $remove_parent_by_class = array( | |
| 905 | - 'et_pb_contact_captcha_question', | |
| 906 | - ); | |
| 907 | - foreach ($remove_parent_by_class as $key => $class) { | |
| 908 | - $elements = $xpath->query("//*[contains(@class, '{$class}')]/parent::*"); | |
| 909 | - foreach ($elements as $element) { | |
| 910 | - $element->parentNode->removeChild($element); | |
| 911 | - } | |
| 912 | - } | |
| 913 | - } | |
| 1036 | + // uploads | |
| 1037 | + $uploads = $xpath->query("//*[contains(@class, 'et_pb_contact_hidden_files')]"); | |
| 1038 | + foreach ($uploads as $xml_element) { | |
| 1039 | + $xml->set_node_value($xml_element, 'type', 'file'); | |
| 1040 | + } | |
| 914 | 1041 | |
| 915 | - if (defined('LIBXML_HTML_NOIMPLIED') && defined('LIBXML_HTML_NODEFDTD')) { | |
| 916 | - return str_replace(array('<html>', '</html>'), '', $dom->saveHTML()); | |
| 917 | - } else { | |
| 918 | - return $dom->saveHTML(); | |
| 919 | - } | |
| 920 | - } | |
| 1042 | + $radios = $xpath->query("//input[@type='radio']"); | |
| 1043 | + foreach ($radios as $xml_element) { | |
| 1044 | + $xml->set_node_value($xml_element, 'value', sanitize_text_field($xml->get_node_value($xml_element, 'value'))); | |
| 1045 | + } | |
| 1046 | + | |
| 1047 | + $selects = $xpath->query('//select/option'); | |
| 1048 | + foreach ($selects as $xml_element) { | |
| 1049 | + $xml->set_node_value($xml_element, 'value', sanitize_text_field($xml->get_node_value($xml_element, 'value'))); | |
| 1050 | + } | |
| 1051 | + | |
| 1052 | + // remove by class | |
| 1053 | + $remove_by_class = [ | |
| 1054 | + 'et_pb_contact_submit', | |
| 1055 | + 'et_pb_contactform_validate_field', | |
| 1056 | + 'et_pb_checkbox_handle', | |
| 1057 | + 'et_pb_form_bottom_stepper_container', | |
| 1058 | + 'stepper__progress', | |
| 1059 | + ]; | |
| 1060 | + foreach ($remove_by_class as $key => $class) { | |
| 1061 | + $xml_elements = $xpath->query("//*[contains(@class, '{$class}')]"); | |
| 1062 | + foreach ($xml_elements as $xml_element) { | |
| 1063 | + $xml_element->parentNode->removeChild($xml_element); | |
| 921 | 1064 | } |
| 922 | 1065 | } |
| 1066 | + | |
| 1067 | + $xml_elements = $xpath->query('//*[@data-step]'); | |
| 1068 | + foreach ($xml_elements as $xml_element) { | |
| 1069 | + $xml_element->removeAttribute('style'); | |
| 1070 | + } | |
| 1071 | + | |
| 1072 | + // remove parent by class | |
| 1073 | + $remove_parent_by_class = [ | |
| 1074 | + 'et_pb_contact_captcha_question', | |
| 1075 | + ]; | |
| 1076 | + foreach ($remove_parent_by_class as $key => $class) { | |
| 1077 | + $xml_elements = $xpath->query("//*[contains(@class, '{$class}')]/parent::*"); | |
| 1078 | + foreach ($xml_elements as $xml_element) { | |
| 1079 | + $xml_element->parentNode->removeChild($xml_element); | |
| 1080 | + } | |
| 1081 | + } | |
| 923 | 1082 | } |
| 1083 | + | |
| 1084 | + if (defined('LIBXML_HTML_NOIMPLIED') && defined('LIBXML_HTML_NODEFDTD')) { | |
| 1085 | + return str_replace(['<html>', '</html>'], '', $dom->saveHTML()); | |
| 1086 | + } else { | |
| 1087 | + return $dom->saveHTML(); | |
| 1088 | + } | |
| 924 | 1089 | } |
| 925 | 1090 | } |
| 926 | 1091 | |
| 927 | 1092 | return false; |
| @@ -926,27 +1091,28 @@ | ||
| 926 | 1091 | |
| 927 | 1092 | return false; |
| 928 | 1093 | } |
| 929 | 1094 | |
| 930 | - // filter mail for Divi Contact Form Helper | |
| 931 | - public function filter_wp_mail_pwh_dcfh($args) { | |
| 932 | - if (isset($args['message']) && $args['message']) { | |
| 933 | - $args['message'] = preg_replace('/(\{\{)((e2pdf-download|e2pdf-view|e2pdf-save|e2pdf-attachment|e2pdf-adobesign|e2pdf-zapier)[^\}]*?)(\}\})/', '[$2]', $args['message']); | |
| 1095 | + // filter mail | |
| 1096 | + public function filter_wp_mail($args) { | |
| 1097 | + | |
| 1098 | + if (!$this->get('process')) { | |
| 1099 | + return $args; | |
| 934 | 1100 | } |
| 935 | - return $this->filter_wp_mail($args); | |
| 936 | - } | |
| 937 | 1101 | |
| 938 | - // filter mail | |
| 939 | - public function filter_wp_mail($args) { | |
| 1102 | + if ((defined('PWH_DCFH_PLUGIN_VERSION') && version_compare(PWH_DCFH_PLUGIN_VERSION, '1.5.1', '>=')) || defined('KS_PAC_DCFH_PLUGIN_FILE')) { | |
| 1103 | + $args['message'] = preg_replace('/(\{)((e2pdf-download|e2pdf-view|e2pdf-save|e2pdf-attachment|e2pdf-adobesign|e2pdf-zapier)[^\}]*?)(\})/', '[$2]', $args['message']); | |
| 1104 | + } | |
| 1105 | + | |
| 940 | 1106 | if (isset($args['message'])) { |
| 941 | 1107 | if (false !== strpos($args['message'], '[')) { |
| 942 | - $shortcode_tags = array( | |
| 1108 | + $shortcode_tags = [ | |
| 943 | 1109 | 'e2pdf-download', |
| 944 | 1110 | 'e2pdf-save', |
| 945 | 1111 | 'e2pdf-attachment', |
| 946 | 1112 | 'e2pdf-adobesign', |
| 947 | 1113 | 'e2pdf-zapier', |
| 948 | - ); | |
| 1114 | + ]; | |
| 949 | 1115 | preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $args['message'], $matches); |
| 950 | 1116 | $tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 951 | 1117 | if (!empty($tagnames)) { |
| 952 | 1118 | preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $args['message'], $shortcodes); |
| @@ -975,8 +1141,14 @@ | ||
| 975 | 1141 | } else { |
| 976 | 1142 | $this->helper->add('divi_attachments', $file); |
| 977 | 1143 | } |
| 978 | 1144 | $args['attachments'][] = $file; |
| 1145 | + if (!has_action('wp_mail_succeeded', [$this, 'filter_wp_mail_attachments'])) { | |
| 1146 | + add_action('wp_mail_succeeded', [$this, 'filter_wp_mail_attachments']); | |
| 1147 | + } | |
| 1148 | + if (!has_action('wp_mail_failed', [$this, 'filter_wp_mail_attachments'])) { | |
| 1149 | + add_action('wp_mail_failed', [$this, 'filter_wp_mail_attachments']); | |
| 1150 | + } | |
| 979 | 1151 | } |
| 980 | 1152 | $args['message'] = str_replace($shortcode_value, '', $args['message']); |
| 981 | 1153 | } else { |
| 982 | 1154 | if (is_array($args['headers']) && !in_array('Content-Type: text/html; charset=UTF-8', $args['headers'])) { |
| @@ -988,35 +1160,430 @@ | ||
| 988 | 1160 | } |
| 989 | 1161 | } |
| 990 | 1162 | } |
| 991 | 1163 | } |
| 992 | - | |
| 993 | - $wp_mail = array( | |
| 1164 | + $wp_mail = [ | |
| 994 | 1165 | 'to' => $args['to'], |
| 995 | 1166 | 'subject' => $args['subject'], |
| 996 | 1167 | 'message' => $args['message'], |
| 997 | 1168 | 'headers' => $args['headers'], |
| 998 | 1169 | 'attachments' => $args['attachments'], |
| 999 | - ); | |
| 1170 | + ]; | |
| 1171 | + return $wp_mail; | |
| 1172 | + } | |
| 1000 | 1173 | |
| 1001 | - return $wp_mail; | |
| 1174 | + public function filter_wp_mail_attachments() { | |
| 1175 | + $files = $this->helper->get('divi_attachments'); | |
| 1176 | + if (is_array($files) && !empty($files)) { | |
| 1177 | + foreach ($files as $key => $file) { | |
| 1178 | + $this->helper->delete_dir(dirname($file) . '/'); | |
| 1179 | + } | |
| 1180 | + $this->helper->deset('divi_attachments'); | |
| 1181 | + } | |
| 1002 | 1182 | } |
| 1003 | 1183 | |
| 1004 | 1184 | // load actions |
| 1005 | 1185 | public function load_actions() { // phpcs:ignore Squiz.WhiteSpace.SuperfluousWhitespace.EndLine |
| 1186 | + add_action('et_pb_contact_form_submit', [$this, 'action_et_pb_contact_form_submit'], 11); | |
| 1006 | 1187 | } |
| 1007 | 1188 | |
| 1189 | + public function action_et_pb_contact_form_submit() { | |
| 1190 | + if ($this->divi5()) { | |
| 1191 | + add_filter('wp_mail', [$this, 'filter_wp_mail'], 1000); | |
| 1192 | + } | |
| 1193 | + } | |
| 1194 | + | |
| 1008 | 1195 | // load filters |
| 1009 | 1196 | public function load_filters() { |
| 1010 | 1197 | // Divi Contact Form Helper Confirmation Email compatibility fix |
| 1011 | 1198 | if (defined('PWH_DCFH_PLUGIN_FILE') || defined('KS_PAC_DCFH_PLUGIN_FILE')) { |
| 1012 | - add_filter('et_pb_module_shortcode_attributes', array($this, 'filter_et_pb_module_shortcode_attributes'), 9, 5); | |
| 1199 | + add_filter('et_pb_module_shortcode_attributes', [$this, 'filter_et_pb_module_shortcode_attributes'], 9, 5); | |
| 1013 | 1200 | } else { |
| 1014 | - add_filter('et_pb_module_shortcode_attributes', array($this, 'filter_et_pb_module_shortcode_attributes'), 30, 5); | |
| 1201 | + add_filter('et_pb_module_shortcode_attributes', [$this, 'filter_et_pb_module_shortcode_attributes'], 30, 5); | |
| 1015 | 1202 | } |
| 1016 | - add_filter('et_module_shortcode_output', array($this, 'filter_et_module_shortcode_output'), 30, 3); | |
| 1203 | + add_filter('et_module_shortcode_output', [$this, 'filter_et_module_shortcode_output'], 30, 3); | |
| 1204 | + | |
| 1205 | + // Divi 5 | |
| 1206 | + add_filter('divi_module_library_register_module_attrs', [$this, 'filter_divi_module_library_register_module_attrs'], 11, 2); | |
| 1017 | 1207 | } |
| 1018 | 1208 | |
| 1209 | + public function filter_divi_module_library_register_module_attrs($module_attrs, $filter_args) { | |
| 1210 | + | |
| 1211 | + if ('divi/contact-form' !== $filter_args['name']) { | |
| 1212 | + return $module_attrs; | |
| 1213 | + } | |
| 1214 | + | |
| 1215 | + if (!isset($_SERVER['REQUEST_METHOD']) || 'POST' !== $_SERVER['REQUEST_METHOD']) { | |
| 1216 | + return $module_attrs; | |
| 1217 | + } | |
| 1218 | + | |
| 1219 | + $module_id = !empty($filter_args['id']) ? $filter_args['id'] : ''; | |
| 1220 | + $store_instance = !empty($filter_args['storeInstance']) ? $filter_args['storeInstance'] : 0; | |
| 1221 | + | |
| 1222 | + if ( | |
| 1223 | + !class_exists('\ET\Builder\FrontEnd\BlockParser\BlockParserStore') || | |
| 1224 | + !method_exists('\ET\Builder\FrontEnd\BlockParser\BlockParserStore', 'get') | |
| 1225 | + ) { | |
| 1226 | + return $module_attrs; | |
| 1227 | + } | |
| 1228 | + | |
| 1229 | + $module = \ET\Builder\FrontEnd\BlockParser\BlockParserStore::get($module_id, $store_instance); | |
| 1230 | + | |
| 1231 | + if (!$module) { | |
| 1232 | + return $module_attrs; | |
| 1233 | + } | |
| 1234 | + | |
| 1235 | + if ( | |
| 1236 | + !class_exists('\ET\Builder\Packages\ModuleLibrary\ContactForm\ContactFormUtils') || | |
| 1237 | + !method_exists('\ET\Builder\Packages\ModuleLibrary\ContactForm\ContactFormUtils', 'get_unique_id') || | |
| 1238 | + !class_exists('\ET\Builder\Packages\ModuleLibrary\ContactForm\ContactFormHandler') || | |
| 1239 | + !class_exists('\ET\Builder\Packages\ModuleLibrary\ContactField\ContactFieldModule') || | |
| 1240 | + !method_exists('\ET\Builder\Packages\ModuleLibrary\ContactField\ContactFieldModule', 'get_field_unique_id') | |
| 1241 | + ) { | |
| 1242 | + return $module_attrs; | |
| 1243 | + } | |
| 1244 | + | |
| 1245 | + $unique_id = \ET\Builder\Packages\ModuleLibrary\ContactForm\ContactFormUtils::get_unique_id($module_attrs, (array) $module); | |
| 1246 | + | |
| 1247 | + $submitted = isset($_POST['_wpnonce-et-pb-contact-form-submitted-' . $unique_id]); | |
| 1248 | + if (!$submitted) { | |
| 1249 | + return $module_attrs; | |
| 1250 | + } | |
| 1251 | + | |
| 1252 | + if (!wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_wpnonce-et-pb-contact-form-submitted-' . $unique_id])), 'et-pb-contact-form-submit-' . $unique_id)) { | |
| 1253 | + return $module_attrs; | |
| 1254 | + } | |
| 1255 | + | |
| 1256 | + $use_basic_captcha = $module_attrs['module']['advanced']['spamProtection']['desktop']['value']['useBasicCaptcha'] ?? 'on'; | |
| 1257 | + $use_spam_service = $module_attrs['module']['advanced']['spamProtection']['desktop']['value']['enabled'] ?? 'off'; | |
| 1258 | + | |
| 1259 | + if ('on' === $use_basic_captcha && 'off' === $use_spam_service) { | |
| 1260 | + $captcha_answer = sanitize_text_field(wp_unslash($_POST['et_pb_contact_captcha_' . $unique_id] ?? '')); | |
| 1261 | + $first_digit = sanitize_text_field(wp_unslash($_POST['et_pb_contact_captcha_first_digit_' . $unique_id] ?? '')); | |
| 1262 | + $second_digit = sanitize_text_field(wp_unslash($_POST['et_pb_contact_captcha_second_digit_' . $unique_id] ?? '')); | |
| 1263 | + | |
| 1264 | + if (!$captcha_answer || ((int) $first_digit + (int) $second_digit) !== (int) $captcha_answer) { | |
| 1265 | + return $module_attrs; | |
| 1266 | + } | |
| 1267 | + } elseif ('on' === $use_spam_service) { | |
| 1268 | + $provider = $module_attrs['module']['advanced']['spamProtection']['desktop']['value']['provider'] ?? 'recaptcha'; | |
| 1269 | + $account = $module_attrs['module']['advanced']['spamProtection']['desktop']['value']['account'] ?? ''; | |
| 1270 | + $min_score = (float) ($module_attrs['module']['advanced']['spamProtection']['desktop']['value']['minScore'] ?? 0.0); | |
| 1271 | + | |
| 1272 | + if (empty($_POST['token']) || !SpamProtectionService::validate_token($provider, $account, $min_score)) { | |
| 1273 | + return $module_attrs; | |
| 1274 | + } | |
| 1275 | + } | |
| 1276 | + | |
| 1277 | + $messages = [ | |
| 1278 | + 'successMessage' => isset($module_attrs['module']['advanced']['successMessage']['desktop']['value']) ? $module_attrs['module']['advanced']['successMessage']['desktop']['value'] : '', | |
| 1279 | + ]; | |
| 1280 | + if (defined('KS_PAC_DCFH_PLUGIN_FILE')) { | |
| 1281 | + $send_admin_email = isset($module_attrs['adminEmail']['advanced']['adminEmailEnabled']['desktop']['value']) ? $module_attrs['adminEmail']['advanced']['adminEmailEnabled']['desktop']['value'] : 'on'; | |
| 1282 | + if ($send_admin_email === 'on') { | |
| 1283 | + $admin_email_rich_text = isset($module_attrs['adminEmail']['advanced']['emailRichTextEnabled']['desktop']['value']) ? $module_attrs['adminEmail']['advanced']['emailRichTextEnabled']['desktop']['value'] : 'off'; | |
| 1284 | + if ($admin_email_rich_text === 'on') { | |
| 1285 | + $messages['adminEmailRichTextMessage'] = isset($module_attrs['adminEmail']['innerContent']['emailRichTextMessage']['desktop']['value']) ? $this->decode_shortcodes($module_attrs['adminEmail']['innerContent']['emailRichTextMessage']['desktop']['value']) : ''; | |
| 1286 | + } else { | |
| 1287 | + $messages['email'] = isset($module_attrs['email']['innerContent']['desktop']['value']) ? $module_attrs['email']['innerContent']['desktop']['value'] : ''; | |
| 1288 | + } | |
| 1289 | + } | |
| 1290 | + $send_user_email = isset($module_attrs['confirmationEmail']['advanced']['sendEmailToSubmitter']['desktop']['value']) ? $module_attrs['confirmationEmail']['advanced']['sendEmailToSubmitter']['desktop']['value'] : 'off'; | |
| 1291 | + if ($send_user_email === 'on') { | |
| 1292 | + $user_email_rich_text = isset($module_attrs['confirmationEmail']['advanced']['emailMessageRichTextEnabled']['desktop']['value']) ? $module_attrs['confirmationEmail']['advanced']['emailMessageRichTextEnabled']['desktop']['value'] : 'off'; | |
| 1293 | + if ($user_email_rich_text === 'on') { | |
| 1294 | + $messages['confirmationEmailRichTextMessage'] = isset($module_attrs['confirmationEmail']['innerContent']['emailRichTextMessage']['desktop']['value']) ? $this->decode_shortcodes($module_attrs['confirmationEmail']['innerContent']['emailRichTextMessage']['desktop']['value']) : ''; | |
| 1295 | + } else { | |
| 1296 | + $messages['confirmationEmailMessage'] = isset($module_attrs['confirmationEmail']['innerContent']['emailMessage']['desktop']['value']) ? $module_attrs['confirmationEmail']['innerContent']['emailMessage']['desktop']['value'] : ''; | |
| 1297 | + } | |
| 1298 | + } | |
| 1299 | + } else { | |
| 1300 | + $messages['email'] = isset($module_attrs['email']['innerContent']['desktop']['value']) ? $module_attrs['email']['innerContent']['desktop']['value'] : ''; | |
| 1301 | + } | |
| 1302 | + | |
| 1303 | + foreach ($messages as $message_key => $message) { | |
| 1304 | + if (false !== strpos($message, '[')) { | |
| 1305 | + $shortcode_tags = [ | |
| 1306 | + 'e2pdf-download', | |
| 1307 | + 'e2pdf-save', | |
| 1308 | + 'e2pdf-view', | |
| 1309 | + 'e2pdf-adobesign', | |
| 1310 | + 'e2pdf-zapier', | |
| 1311 | + 'e2pdf-attachment', | |
| 1312 | + ]; | |
| 1313 | + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $message, $matches); | |
| 1314 | + $tagnames = array_intersect($shortcode_tags, $matches[1]); | |
| 1315 | + if (!empty($tagnames)) { | |
| 1316 | + $this->set('process', true); | |
| 1317 | + } else { | |
| 1318 | + unset($messages[$message_key]); | |
| 1319 | + } | |
| 1320 | + } else { | |
| 1321 | + unset($messages[$message_key]); | |
| 1322 | + } | |
| 1323 | + } | |
| 1324 | + | |
| 1325 | + $_POST = $this->sanitize($_POST); | |
| 1326 | + | |
| 1327 | + if (!$this->get('process')) { | |
| 1328 | + return $module_attrs; | |
| 1329 | + } | |
| 1330 | + | |
| 1331 | + if ( | |
| 1332 | + !class_exists('\ET\Builder\Packages\ModuleLibrary\ModuleRegistration') || | |
| 1333 | + !method_exists('\ET\Builder\Packages\ModuleLibrary\ModuleRegistration', 'get_default_attrs')) { | |
| 1334 | + return $module_attrs; | |
| 1335 | + } | |
| 1336 | + | |
| 1337 | + $fields_raw = []; | |
| 1338 | + $filtered_field_attrs = []; | |
| 1339 | + $fields = \ET\Builder\FrontEnd\BlockParser\BlockParserStore::get_children($module_id, $store_instance); | |
| 1340 | + $default_child_attrs = \ET\Builder\Packages\ModuleLibrary\ModuleRegistration::get_default_attrs( | |
| 1341 | + 'divi/contact-field' | |
| 1342 | + ); | |
| 1343 | + foreach ($fields as $field) { | |
| 1344 | + // Skip nested modules (Text, Button, Divider, etc.), only process Contact Field modules. | |
| 1345 | + if ('divi/contact-field' !== $field->blockName) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- This is a property of the WP Core class. | |
| 1346 | + continue; | |
| 1347 | + } | |
| 1348 | + $merged_child_attrs = array_replace_recursive( | |
| 1349 | + $default_child_attrs, | |
| 1350 | + $field->attrs ?? [] | |
| 1351 | + ); | |
| 1352 | + $child_filter_args = [ | |
| 1353 | + 'id' => $field->id, | |
| 1354 | + 'name' => $field->blockName, | |
| 1355 | + 'parentId' => $module_id, | |
| 1356 | + 'parentName' => 'divi/contact-form', | |
| 1357 | + 'parentAttrs' => $module_attrs, | |
| 1358 | + 'storeInstance' => $store_instance, | |
| 1359 | + ]; | |
| 1360 | + $filtered_field_attrs[$field->id] = apply_filters( | |
| 1361 | + 'divi_module_library_register_module_attrs', | |
| 1362 | + $merged_child_attrs, | |
| 1363 | + $child_filter_args | |
| 1364 | + ); | |
| 1365 | + | |
| 1366 | + // Use pre-filtered field attributes if provided, otherwise use field attributes from storage. | |
| 1367 | + $field_attrs = !empty($filtered_field_attrs[$field->id]) ? $filtered_field_attrs[$field->id] : $field->attrs; | |
| 1368 | + $field_unique_id = \ET\Builder\Packages\ModuleLibrary\ContactField\ContactFieldModule::get_field_unique_id($field->id, $store_instance); | |
| 1369 | + $field_type = $field_attrs['fieldItem']['advanced']['type']['desktop']['value'] ?? 'input'; | |
| 1370 | + $field_id = $field_attrs['fieldItem']['advanced']['id']['desktop']['value'] ?? ''; | |
| 1371 | + $field_key = strtolower($field_id); | |
| 1372 | + $field_label = $field_attrs['fieldItem']['innerContent']['desktop']['value'] ?? ''; | |
| 1373 | + | |
| 1374 | + if (!$field_label) { | |
| 1375 | + $field_label = __('New Field', 'et_builder_5'); | |
| 1376 | + } | |
| 1377 | + | |
| 1378 | + $fields_raw[$field_key]['id'] = $field_id; | |
| 1379 | + $fields_raw[$field_key]['label'] = $field_label; | |
| 1380 | + $fields_raw[$field_key]['type'] = $field_type; | |
| 1381 | + $fields_raw[$field_key]['allowedSymbols'] = $field_attrs['fieldItem']['advanced']['allowedSymbols']['desktop']['value'] ?? ''; | |
| 1382 | + $fields_raw[$field_key]['maxLength'] = $field_attrs['fieldItem']['advanced']['maxLength']['desktop']['value'] ?? ''; | |
| 1383 | + $fields_raw[$field_key]['minLength'] = $field_attrs['fieldItem']['advanced']['minLength']['desktop']['value'] ?? ''; | |
| 1384 | + $fields_raw[$field_key]['isRequired'] = 'on' === ($field_attrs['fieldItem']['advanced']['required']['desktop']['value'] ?? 'on'); | |
| 1385 | + | |
| 1386 | + $fields_raw[$field_key]['conditionalLogic'] = [ | |
| 1387 | + 'enabled' => 'on' === ($field_attrs['conditionalLogic']['advanced']['enable']['desktop']['value'] ?? 'off'), | |
| 1388 | + 'matchAll' => 'on' === ($field_attrs['conditionalLogic']['advanced']['relation']['desktop']['value'] ?? 'off'), | |
| 1389 | + 'rules' => $field_attrs['conditionalLogic']['innerContent']['desktop']['value'] ?? [], | |
| 1390 | + ]; | |
| 1391 | + | |
| 1392 | + if ('text' === $field_type) { | |
| 1393 | + $fields_raw[$field_key]['value'] = isset($_POST[$field_unique_id]) ? sanitize_textarea_field(wp_unslash($_POST[$field_unique_id])) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Validated and sanitized. | |
| 1394 | + } elseif ('checkbox' === $field_type) { | |
| 1395 | + // For checkbox fields, decode and sanitize immediately, store as array. | |
| 1396 | + $raw_value = isset($_POST[$field_unique_id]) ? wp_unslash($_POST[$field_unique_id]) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Validated and sanitized. | |
| 1397 | + | |
| 1398 | + if ('' !== $raw_value) { | |
| 1399 | + // Split the URL-encoded comma-separated values. | |
| 1400 | + $parts = explode(',', $raw_value); | |
| 1401 | + $parts = array_map('urldecode', $parts); | |
| 1402 | + $parts = array_map('sanitize_text_field', $parts); | |
| 1403 | + $parts = array_map('trim', $parts); | |
| 1404 | + $fields_raw[$field_key]['value'] = $parts; | |
| 1405 | + } else { | |
| 1406 | + $fields_raw[$field_key]['value'] = []; | |
| 1407 | + } | |
| 1408 | + } else { | |
| 1409 | + $fields_raw[$field_key]['value'] = isset($_POST[$field_unique_id]) ? sanitize_text_field(wp_unslash($_POST[$field_unique_id])) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Validated and sanitized. | |
| 1410 | + } | |
| 1411 | + | |
| 1412 | + switch ($field_type) { | |
| 1413 | + case 'checkbox': | |
| 1414 | + $options = $field_attrs['fieldItem']['advanced']['checkboxOptions']['desktop']['value'] ?? []; | |
| 1415 | + $fields_raw[$field_key]['options'] = is_array($options) ? array_map( | |
| 1416 | + function ($option) { | |
| 1417 | + return wp_strip_all_tags($option['value'] ?? ''); | |
| 1418 | + }, | |
| 1419 | + $options | |
| 1420 | + ) : []; | |
| 1421 | + break; | |
| 1422 | + case 'radio': | |
| 1423 | + $options = $field_attrs['fieldItem']['advanced']['radioOptions']['desktop']['value'] ?? []; | |
| 1424 | + $fields_raw[$field_key]['options'] = is_array($options) ? array_map( | |
| 1425 | + function ($option) { | |
| 1426 | + return sanitize_text_field($option['value'] ?? ''); | |
| 1427 | + }, | |
| 1428 | + $options | |
| 1429 | + ) : []; | |
| 1430 | + break; | |
| 1431 | + case 'select': | |
| 1432 | + $options = $field_attrs['fieldItem']['advanced']['selectOptions']['desktop']['value'] ?? []; | |
| 1433 | + $fields_raw[$field_key]['options'] = is_array($options) ? array_map( | |
| 1434 | + function ($option) { | |
| 1435 | + return sanitize_text_field($option['value'] ?? ''); | |
| 1436 | + }, | |
| 1437 | + $options | |
| 1438 | + ) : []; | |
| 1439 | + break; | |
| 1440 | + default: | |
| 1441 | + $fields_raw[$field_key]['options'] = []; | |
| 1442 | + break; | |
| 1443 | + } | |
| 1444 | + } | |
| 1445 | + | |
| 1446 | + $refClass = new ReflectionClass('\ET\Builder\Packages\ModuleLibrary\ContactForm\ContactFormHandler'); | |
| 1447 | + $obj = $refClass->newInstanceWithoutConstructor(); | |
| 1448 | + | |
| 1449 | + try { | |
| 1450 | + $refFields = $refClass->getProperty('_fields_raw'); | |
| 1451 | + $refFields->setAccessible(true); | |
| 1452 | + $refFields->setValue($obj, $fields_raw); | |
| 1453 | + | |
| 1454 | + $refError = $refClass->getProperty('_error'); | |
| 1455 | + $refError->setAccessible(true); | |
| 1456 | + $refError->setValue($obj, new WP_Error()); | |
| 1457 | + } catch (\ReflectionException $e) { | |
| 1458 | + return $module_attrs; | |
| 1459 | + } | |
| 1460 | + | |
| 1461 | + $obj->validate_fields(); | |
| 1462 | + $errorObj = $refError->getValue($obj); | |
| 1463 | + | |
| 1464 | + if ($errorObj->has_errors()) { | |
| 1465 | + return $module_attrs; | |
| 1466 | + } | |
| 1467 | + | |
| 1468 | + $fields_raw = $refFields->getValue($obj); | |
| 1469 | + | |
| 1470 | + $item = !empty($module_attrs['module']['meta']['adminLabel']['desktop']['value']) ? $module_attrs['module']['meta']['adminLabel']['desktop']['value'] : ''; | |
| 1471 | + if (!$item) { | |
| 1472 | + return $module_attrs; | |
| 1473 | + } | |
| 1474 | + | |
| 1475 | + $data = [ | |
| 1476 | + 'E2PDF_VERSION' => '1.32.40', | |
| 1477 | + 'fields' => [], | |
| 1478 | + 'options' => [ | |
| 1479 | + 'timestamp' => current_time('mysql'), | |
| 1480 | + 'saveFilesToMedia' => !empty($module_attrs['entryPreferences']['advanced']['saveFilesToMedia']['desktop']['value']) ? $module_attrs['entryPreferences']['advanced']['saveFilesToMedia']['desktop']['value'] : '', | |
| 1481 | + 'uniqueId' => !empty($module_attrs['module']['advanced']['uniqueId']['desktop']['value']) ? $module_attrs['module']['advanced']['uniqueId']['desktop']['value'] : '', | |
| 1482 | + ], | |
| 1483 | + ]; | |
| 1484 | + | |
| 1485 | + if (!empty($fields_raw) && is_array($fields_raw)) { | |
| 1486 | + foreach ($fields_raw as $field_key => $field_raw) { | |
| 1487 | + if (isset($field_raw['value'])) { | |
| 1488 | + $data['fields'][$field_key] = [ | |
| 1489 | + 'type' => isset($field_raw['type']) ? $field_raw['type'] : '', | |
| 1490 | + 'value' => $field_raw['value'], | |
| 1491 | + ]; | |
| 1492 | + } | |
| 1493 | + } | |
| 1494 | + } | |
| 1495 | + if (empty($data['fields']['_wp_http_referer']) && !empty($_POST['_wp_http_referer'])) { | |
| 1496 | + $data['fields']['_wp_http_referer'] = [ | |
| 1497 | + 'type' => '', | |
| 1498 | + 'value' => esc_url_raw($_POST['_wp_http_referer']), | |
| 1499 | + ]; | |
| 1500 | + } | |
| 1501 | + | |
| 1502 | + $entry = new Model_E2pdf_Dataset(); | |
| 1503 | + $entry->set('extension', 'divi'); | |
| 1504 | + $entry->set('item', $item); | |
| 1505 | + $entry->set('entry', $data); | |
| 1506 | + $dataset = $entry->save(); | |
| 1507 | + | |
| 1508 | + foreach ($messages as $message_key => $message) { | |
| 1509 | + if (false !== strpos($message, '[')) { | |
| 1510 | + $shortcode_tags = [ | |
| 1511 | + 'e2pdf-download', | |
| 1512 | + 'e2pdf-save', | |
| 1513 | + 'e2pdf-view', | |
| 1514 | + 'e2pdf-adobesign', | |
| 1515 | + 'e2pdf-zapier', | |
| 1516 | + 'e2pdf-attachment', | |
| 1517 | + ]; | |
| 1518 | + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $message, $matches); | |
| 1519 | + $tagnames = array_intersect($shortcode_tags, $matches[1]); | |
| 1520 | + if (!empty($tagnames)) { | |
| 1521 | + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $message, $shortcodes); | |
| 1522 | + foreach ($shortcodes[0] as $key => $shortcode_value) { | |
| 1523 | + $item = false; | |
| 1524 | + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); | |
| 1525 | + $atts = shortcode_parse_atts($shortcode[3]); | |
| 1526 | + | |
| 1527 | + if (!isset($atts['dataset']) && isset($atts['id'])) { | |
| 1528 | + $template = new Model_E2pdf_Template(); | |
| 1529 | + $template->load($atts['id']); | |
| 1530 | + if ($template->get('extension') === 'divi') { | |
| 1531 | + $item = $template->get('item'); | |
| 1532 | + $atts['dataset'] = $dataset; | |
| 1533 | + $shortcode[3] .= ' dataset="' . $dataset . '"'; | |
| 1534 | + } | |
| 1535 | + } | |
| 1536 | + if (!isset($atts['apply'])) { | |
| 1537 | + $shortcode[3] .= ' apply="true"'; | |
| 1538 | + } | |
| 1539 | + if (!isset($atts['iframe_download'])) { | |
| 1540 | + $shortcode[3] .= ' iframe_download="true"'; | |
| 1541 | + } | |
| 1542 | + switch ($message_key) { | |
| 1543 | + case 'successMessage': | |
| 1544 | + $module_attrs['module']['advanced']['successMessage']['desktop']['value'] = str_replace($shortcode_value, do_shortcode_tag($shortcode), $module_attrs['module']['advanced']['successMessage']['desktop']['value']); | |
| 1545 | + break; | |
| 1546 | + case 'email': | |
| 1547 | + $module_attrs['email']['innerContent']['desktop']['value'] = str_replace($shortcode_value, '[' . $shortcode[2] . $shortcode[3] . ']', $module_attrs['email']['innerContent']['desktop']['value']); | |
| 1548 | + break; | |
| 1549 | + case 'adminEmailRichTextMessage': | |
| 1550 | + case 'confirmationEmailMessage': | |
| 1551 | + case 'confirmationEmailRichTextMessage': | |
| 1552 | + $messages[$message_key] = str_replace($shortcode_value, '{' . $shortcode[2] . $shortcode[3] . '}', $messages[$message_key]); | |
| 1553 | + break; | |
| 1554 | + default: | |
| 1555 | + break; | |
| 1556 | + } | |
| 1557 | + } | |
| 1558 | + } | |
| 1559 | + } | |
| 1560 | + } | |
| 1561 | + | |
| 1562 | + foreach ($messages as $message_key => $message) { | |
| 1563 | + switch ($message_key) { | |
| 1564 | + case 'adminEmailRichTextMessage': | |
| 1565 | + $class = '\KS_PAC_DCFH\Frontend\Controllers\ContactFormDataRepository'; | |
| 1566 | + if (class_exists($class) && method_exists($class, 'instance')) { | |
| 1567 | + $contact_form_rep = $class::instance(); | |
| 1568 | + $contact_form_rep->admin_message = $messages[$message_key]; | |
| 1569 | + } | |
| 1570 | + break; | |
| 1571 | + case 'confirmationEmailMessage': | |
| 1572 | + case 'confirmationEmailRichTextMessage': | |
| 1573 | + $class = '\KS_PAC_DCFH\Frontend\Services\ConfirmationEmailService'; | |
| 1574 | + if (class_exists($class) && method_exists($class, 'instance')) { | |
| 1575 | + $contact_form_rep = $class::instance(); | |
| 1576 | + $contact_form_rep->email_message = $messages[$message_key]; | |
| 1577 | + } | |
| 1578 | + break; | |
| 1579 | + default: | |
| 1580 | + break; | |
| 1581 | + } | |
| 1582 | + } | |
| 1583 | + return $module_attrs; | |
| 1584 | + } | |
| 1585 | + | |
| 1019 | 1586 | // filter shortcode attributes |
| 1020 | 1587 | public function filter_et_pb_module_shortcode_attributes($props, $attrs, $render_slug, $address, $content) { |
| 1021 | 1588 | |
| 1022 | 1589 | if ($render_slug !== 'et_pb_contact_form') { |
| @@ -1027,78 +1594,78 @@ | ||
| 1027 | 1594 | if ($et_contact_proccess === false) { |
| 1028 | 1595 | return $props; |
| 1029 | 1596 | } |
| 1030 | 1597 | |
| 1031 | - $e2pdf_shortcodes = false; | |
| 1598 | + $success_message = isset($props['success_message']) ? $this->decode_shortcodes($props['success_message'], true) : ''; | |
| 1032 | 1599 | |
| 1033 | - $success_message = isset($props['success_message']) ? str_replace(array('[', ']', '"'), array('[', ']', '"'), $props['success_message']) : ''; | |
| 1034 | 1600 | if (false !== strpos($success_message, '[')) { |
| 1035 | - $shortcode_tags = array( | |
| 1601 | + $shortcode_tags = [ | |
| 1036 | 1602 | 'e2pdf-download', |
| 1037 | 1603 | 'e2pdf-save', |
| 1038 | 1604 | 'e2pdf-view', |
| 1039 | 1605 | 'e2pdf-adobesign', |
| 1040 | 1606 | 'e2pdf-zapier', |
| 1041 | - ); | |
| 1607 | + ]; | |
| 1042 | 1608 | preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $success_message, $matches); |
| 1043 | 1609 | $tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 1044 | 1610 | if (!empty($tagnames)) { |
| 1045 | - $e2pdf_shortcodes = true; | |
| 1611 | + $this->set('process', true); | |
| 1046 | 1612 | } else { |
| 1047 | 1613 | $success_message = ''; |
| 1048 | 1614 | } |
| 1049 | 1615 | } |
| 1050 | 1616 | |
| 1051 | - $use_custom_message_richtext = isset($props['use_custom_message_richtext']) && $props['use_custom_message_richtext'] == 'on' && isset($props['custom_message_richtext']) ? true : false; | |
| 1052 | - if ($use_custom_message_richtext) { | |
| 1053 | - $custom_message = str_replace(array('[', ']'), array('[', ']'), $props['custom_message_richtext']); | |
| 1617 | + $admin_email_rich_text = isset($props['use_custom_message_richtext']) && $props['use_custom_message_richtext'] == 'on' && isset($props['custom_message_richtext']) ? true : false; | |
| 1618 | + if ($admin_email_rich_text) { | |
| 1619 | + $admin_email_message = $this->decode_shortcodes($props['custom_message_richtext']); | |
| 1054 | 1620 | } else { |
| 1055 | - $custom_message = isset($props['custom_message']) ? str_replace(array('[', ']'), array('[', ']'), $props['custom_message']) : ''; | |
| 1621 | + $admin_email_message = isset($props['custom_message']) ? $this->decode_shortcodes($props['custom_message']) : ''; | |
| 1056 | 1622 | } |
| 1057 | - if (false !== strpos($custom_message, '[')) { | |
| 1058 | - $shortcode_tags = array( | |
| 1623 | + if (false !== strpos($admin_email_message, '[')) { | |
| 1624 | + $shortcode_tags = [ | |
| 1059 | 1625 | 'e2pdf-download', |
| 1060 | 1626 | 'e2pdf-save', |
| 1061 | 1627 | 'e2pdf-attachment', |
| 1062 | 1628 | 'e2pdf-adobesign', |
| 1063 | 1629 | 'e2pdf-zapier', |
| 1064 | - ); | |
| 1065 | - | |
| 1066 | - preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $custom_message, $matches); | |
| 1630 | + ]; | |
| 1631 | + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $admin_email_message, $matches); | |
| 1067 | 1632 | $tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 1068 | 1633 | if (!empty($tagnames)) { |
| 1069 | - $e2pdf_shortcodes = true; | |
| 1634 | + $this->set('process', true); | |
| 1070 | 1635 | } else { |
| 1071 | - $custom_message = ''; | |
| 1636 | + $admin_email_message = ''; | |
| 1072 | 1637 | } |
| 1073 | 1638 | } |
| 1074 | 1639 | |
| 1075 | 1640 | /* Divi Contact Form Helper Confirmation Email and Confirmation Email RichText */ |
| 1076 | - $use_confirmation_message_richtext = isset($props['use_confirmation_email']) && $props['use_confirmation_email'] == 'on' && isset($props['use_confirmation_message_richtext']) && $props['use_confirmation_message_richtext'] == 'on' && isset($props['confirmation_message_richtext']) ? true : false; | |
| 1077 | - if ($use_confirmation_message_richtext) { | |
| 1078 | - $confirmation_email_message = str_replace(array('[', ']'), array('[', ']'), $props['confirmation_message_richtext']); | |
| 1641 | + $user_email_rich_text = isset($props['use_confirmation_email']) && $props['use_confirmation_email'] == 'on' && isset($props['use_confirmation_message_richtext']) && $props['use_confirmation_message_richtext'] == 'on' && isset($props['confirmation_message_richtext']) ? true : false; | |
| 1642 | + if ($user_email_rich_text) { | |
| 1643 | + $user_email_message = $this->decode_shortcodes($props['confirmation_message_richtext']); | |
| 1079 | 1644 | } else { |
| 1080 | - $confirmation_email_message = isset($props['use_confirmation_email']) && $props['use_confirmation_email'] == 'on' && isset($props['confirmation_email_message']) ? str_replace(array('[', ']'), array('[', ']'), $props['confirmation_email_message']) : ''; | |
| 1645 | + $user_email_message = isset($props['use_confirmation_email']) && $props['use_confirmation_email'] == 'on' && isset($props['confirmation_email_message']) ? $this->decode_shortcodes($props['confirmation_email_message']) : ''; | |
| 1081 | 1646 | } |
| 1082 | - if (false !== strpos($confirmation_email_message, '[')) { | |
| 1083 | - $shortcode_tags = array( | |
| 1647 | + if (false !== strpos($user_email_message, '[')) { | |
| 1648 | + $shortcode_tags = [ | |
| 1084 | 1649 | 'e2pdf-download', |
| 1085 | 1650 | 'e2pdf-save', |
| 1086 | 1651 | 'e2pdf-attachment', |
| 1087 | 1652 | 'e2pdf-adobesign', |
| 1088 | 1653 | 'e2pdf-zapier', |
| 1089 | - ); | |
| 1090 | - preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $confirmation_email_message, $matches); | |
| 1654 | + ]; | |
| 1655 | + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $user_email_message, $matches); | |
| 1091 | 1656 | $tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 1092 | 1657 | if (!empty($tagnames)) { |
| 1093 | - $e2pdf_shortcodes = true; | |
| 1658 | + $this->set('process', true); | |
| 1094 | 1659 | } else { |
| 1095 | - $confirmation_email_message = ''; | |
| 1660 | + $user_email_message = ''; | |
| 1096 | 1661 | } |
| 1097 | 1662 | } |
| 1098 | 1663 | |
| 1664 | + $_POST = $this->sanitize($_POST); | |
| 1665 | + | |
| 1099 | 1666 | // check if E2Pdf shortcodes exist in messages |
| 1100 | - if (!$e2pdf_shortcodes) { | |
| 1667 | + if (!$this->get('process')) { | |
| 1101 | 1668 | return $props; |
| 1102 | 1669 | } |
| 1103 | 1670 | |
| 1104 | 1671 | $data = $_POST; |
| @@ -1155,9 +1722,9 @@ | ||
| 1155 | 1722 | } |
| 1156 | 1723 | |
| 1157 | 1724 | // check all fields on current form and generate error message if needed |
| 1158 | 1725 | if (!empty($fields_data_array)) { |
| 1159 | - foreach ($fields_data_array as $index => $value) { | |
| 1726 | + foreach ($fields_data_array as $value) { | |
| 1160 | 1727 | if (isset($value['field_id']) && 'et_pb_contact_et_number_' . $et_pb_contact_form_num === $value['field_id']) { |
| 1161 | 1728 | continue; |
| 1162 | 1729 | } |
| 1163 | 1730 | /* Check all the required fields, generate error message if required field is empty */ |
| @@ -1182,17 +1749,27 @@ | ||
| 1182 | 1749 | $et_contact_error = true; |
| 1183 | 1750 | } |
| 1184 | 1751 | |
| 1185 | 1752 | if (!$et_contact_error && $nonce_result) { |
| 1753 | + // divi contact form helper 2.1.3 bug fix wp_mail filter removed at maybe_filter_wp_mail | |
| 1754 | + if (defined('KS_PAC_DCFH_PLUGIN_VERSION') && version_compare(KS_PAC_DCFH_PLUGIN_VERSION, '2.1.3', '>=')) { | |
| 1755 | + add_filter( | |
| 1756 | + 'wp_mail', function ($args) { | |
| 1757 | + return $args; | |
| 1758 | + }, 999 | |
| 1759 | + ); | |
| 1760 | + } | |
| 1761 | + add_filter('wp_mail', [$this, 'filter_wp_mail'], 1000); | |
| 1762 | + | |
| 1186 | 1763 | $dataset = false; |
| 1187 | 1764 | if (false !== strpos($success_message, '[')) { |
| 1188 | - $shortcode_tags = array( | |
| 1765 | + $shortcode_tags = [ | |
| 1189 | 1766 | 'e2pdf-download', |
| 1190 | 1767 | 'e2pdf-save', |
| 1191 | 1768 | 'e2pdf-view', |
| 1192 | 1769 | 'e2pdf-adobesign', |
| 1193 | 1770 | 'e2pdf-zapier', |
| 1194 | - ); | |
| 1771 | + ]; | |
| 1195 | 1772 | preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $success_message, $matches); |
| 1196 | 1773 | $tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 1197 | 1774 | if (!empty($tagnames)) { |
| 1198 | 1775 | preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $success_message, $shortcodes); |
| @@ -1223,28 +1800,26 @@ | ||
| 1223 | 1800 | } |
| 1224 | 1801 | if (!isset($atts['iframe_download'])) { |
| 1225 | 1802 | $shortcode[3] .= ' iframe_download="true"'; |
| 1226 | 1803 | } |
| 1227 | - $props['success_message'] = str_replace(str_replace(array('[', ']'), array('[', ']'), $shortcode_value), '[' . $shortcode[2] . $shortcode[3] . ']', $props['success_message']); | |
| 1804 | + $props['success_message'] = str_replace($this->encode_shortcodes($shortcode_value), '[' . $shortcode[2] . $shortcode[3] . ']', $props['success_message']); | |
| 1228 | 1805 | } |
| 1229 | 1806 | } |
| 1230 | 1807 | } |
| 1231 | 1808 | } |
| 1232 | 1809 | |
| 1233 | - if (false !== strpos($custom_message, '[')) { | |
| 1234 | - $shortcode_tags = array( | |
| 1810 | + if (false !== strpos($admin_email_message, '[')) { | |
| 1811 | + $shortcode_tags = [ | |
| 1235 | 1812 | 'e2pdf-download', |
| 1236 | 1813 | 'e2pdf-save', |
| 1237 | 1814 | 'e2pdf-attachment', |
| 1238 | 1815 | 'e2pdf-adobesign', |
| 1239 | 1816 | 'e2pdf-zapier', |
| 1240 | - ); | |
| 1241 | - | |
| 1242 | - preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $custom_message, $matches); | |
| 1817 | + ]; | |
| 1818 | + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $admin_email_message, $matches); | |
| 1243 | 1819 | $tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 1244 | 1820 | if (!empty($tagnames)) { |
| 1245 | - preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $custom_message, $shortcodes); | |
| 1246 | - add_filter('wp_mail', array($this, 'filter_wp_mail'), 11); | |
| 1821 | + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $admin_email_message, $shortcodes); | |
| 1247 | 1822 | foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 1248 | 1823 | $item = false; |
| 1249 | 1824 | $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); |
| 1250 | 1825 | $atts = shortcode_parse_atts($shortcode[3]); |
| @@ -1263,34 +1838,33 @@ | ||
| 1263 | 1838 | $atts['dataset'] = $dataset; |
| 1264 | 1839 | $shortcode[3] .= ' dataset="' . $dataset . '"'; |
| 1265 | 1840 | } |
| 1266 | 1841 | } |
| 1267 | - if ($use_custom_message_richtext) { | |
| 1842 | + if ($admin_email_rich_text) { | |
| 1268 | 1843 | if ((defined('PWH_DCFH_PLUGIN_VERSION') && version_compare(PWH_DCFH_PLUGIN_VERSION, '1.5.1', '>=')) || defined('KS_PAC_DCFH_PLUGIN_FILE')) { |
| 1269 | - $props['custom_message_richtext'] = str_replace(str_replace(array('[', ']'), array('[', ']'), $shortcode_value), '{{' . $shortcode[2] . $shortcode[3] . '}}', $props['custom_message_richtext']); | |
| 1844 | + $props['custom_message_richtext'] = str_replace($this->encode_shortcodes($shortcode_value), '{' . $shortcode[2] . $shortcode[3] . '}', $props['custom_message_richtext']); | |
| 1270 | 1845 | } else { |
| 1271 | - $props['custom_message_richtext'] = str_replace(str_replace(array('[', ']'), array('[', ']'), $shortcode_value), '[' . $shortcode[2] . $shortcode[3] . ']', $props['custom_message_richtext']); | |
| 1846 | + $props['custom_message_richtext'] = str_replace($this->encode_shortcodes($shortcode_value), '[' . $shortcode[2] . $shortcode[3] . ']', $props['custom_message_richtext']); | |
| 1272 | 1847 | } |
| 1273 | 1848 | } else { |
| 1274 | - $props['custom_message'] = str_replace(str_replace(array('[', ']'), array('[', ']'), $shortcode_value), '[' . $shortcode[2] . $shortcode[3] . ']', $props['custom_message']); | |
| 1849 | + $props['custom_message'] = str_replace($this->encode_shortcodes($shortcode_value), '[' . $shortcode[2] . $shortcode[3] . ']', $props['custom_message']); | |
| 1275 | 1850 | } |
| 1276 | 1851 | } |
| 1277 | 1852 | } |
| 1278 | 1853 | } |
| 1279 | 1854 | |
| 1280 | - if (false !== strpos($confirmation_email_message, '[')) { | |
| 1281 | - $shortcode_tags = array( | |
| 1855 | + if (false !== strpos($user_email_message, '[')) { | |
| 1856 | + $shortcode_tags = [ | |
| 1282 | 1857 | 'e2pdf-download', |
| 1283 | 1858 | 'e2pdf-save', |
| 1284 | 1859 | 'e2pdf-attachment', |
| 1285 | 1860 | 'e2pdf-adobesign', |
| 1286 | 1861 | 'e2pdf-zapier', |
| 1287 | - ); | |
| 1288 | - preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $confirmation_email_message, $matches); | |
| 1862 | + ]; | |
| 1863 | + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $user_email_message, $matches); | |
| 1289 | 1864 | $tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 1290 | 1865 | if (!empty($tagnames)) { |
| 1291 | - preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $confirmation_email_message, $shortcodes); | |
| 1292 | - add_filter('wp_mail', array($this, 'filter_wp_mail_pwh_dcfh'), 11); | |
| 1866 | + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $user_email_message, $shortcodes); | |
| 1293 | 1867 | foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 1294 | 1868 | $item = false; |
| 1295 | 1869 | $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); |
| 1296 | 1870 | $atts = shortcode_parse_atts($shortcode[3]); |
| @@ -1310,18 +1884,18 @@ | ||
| 1310 | 1884 | $shortcode[3] .= ' dataset="' . $dataset . '"'; |
| 1311 | 1885 | } |
| 1312 | 1886 | } |
| 1313 | 1887 | if ((defined('PWH_DCFH_PLUGIN_VERSION') && version_compare(PWH_DCFH_PLUGIN_VERSION, '1.5.1', '>=')) || defined('KS_PAC_DCFH_PLUGIN_FILE')) { |
| 1314 | - if ($use_confirmation_message_richtext) { | |
| 1315 | - $props['confirmation_message_richtext'] = str_replace(str_replace(array('[', ']'), array('[', ']'), $shortcode_value), '{{' . $shortcode[2] . $shortcode[3] . '}}', $props['confirmation_message_richtext']); | |
| 1888 | + if ($user_email_rich_text) { | |
| 1889 | + $props['confirmation_message_richtext'] = str_replace($this->encode_shortcodes($shortcode_value), '{' . $shortcode[2] . $shortcode[3] . '}', $props['confirmation_message_richtext']); | |
| 1316 | 1890 | } else { |
| 1317 | - $props['confirmation_email_message'] = str_replace(str_replace(array('[', ']'), array('[', ']'), $shortcode_value), '{{' . $shortcode[2] . $shortcode[3] . '}}', $props['confirmation_email_message']); | |
| 1891 | + $props['confirmation_email_message'] = str_replace($this->encode_shortcodes($shortcode_value), '{' . $shortcode[2] . $shortcode[3] . '}', $props['confirmation_email_message']); | |
| 1318 | 1892 | } |
| 1319 | 1893 | } else { |
| 1320 | - if ($use_confirmation_message_richtext) { | |
| 1321 | - $props['confirmation_message_richtext'] = str_replace(str_replace(array('[', ']'), array('[', ']'), $shortcode_value), '[' . $shortcode[2] . $shortcode[3] . ']', $props['confirmation_message_richtext']); | |
| 1894 | + if ($user_email_rich_text) { | |
| 1895 | + $props['confirmation_message_richtext'] = str_replace($this->encode_shortcodes($shortcode_value), '[' . $shortcode[2] . $shortcode[3] . ']', $props['confirmation_message_richtext']); | |
| 1322 | 1896 | } else { |
| 1323 | - $props['confirmation_email_message'] = str_replace(str_replace(array('[', ']'), array('[', ']'), $shortcode_value), '[' . $shortcode[2] . $shortcode[3] . ']', $props['confirmation_email_message']); | |
| 1897 | + $props['confirmation_email_message'] = str_replace($this->encode_shortcodes($shortcode_value), '[' . $shortcode[2] . $shortcode[3] . ']', $props['confirmation_email_message']); | |
| 1324 | 1898 | } |
| 1325 | 1899 | } |
| 1326 | 1900 | } |
| 1327 | 1901 | } |
| @@ -1342,9 +1916,9 @@ | ||
| 1342 | 1916 | if ($et_contact_proccess === false) { |
| 1343 | 1917 | return $output; |
| 1344 | 1918 | } |
| 1345 | 1919 | |
| 1346 | - $et_pb_contact_form_num = str_replace(array('pwh_dcfh_et_pb_contactform_submit_', 'et_pb_contactform_submit_'), array('', ''), $et_contact_proccess); | |
| 1920 | + $et_pb_contact_form_num = str_replace(['pwh_dcfh_et_pb_contactform_submit_', 'et_pb_contactform_submit_'], ['', ''], $et_contact_proccess); | |
| 1347 | 1921 | $nonce_result = isset($_POST['_wpnonce-et-pb-contact-form-submitted-' . $et_pb_contact_form_num]) && wp_verify_nonce($_POST['_wpnonce-et-pb-contact-form-submitted-' . $et_pb_contact_form_num], 'et-pb-contact-form-submit') ? true : false; |
| 1348 | 1922 | |
| 1349 | 1923 | if ($nonce_result && ( |
| 1350 | 1924 | (isset($_POST['et_pb_contactform_submit_' . $et_pb_contact_form_num]) && empty($_POST['et_pb_contact_et_number_' . $et_pb_contact_form_num])) || |
| @@ -1350,18 +1924,17 @@ | ||
| 1350 | 1924 | (isset($_POST['et_pb_contactform_submit_' . $et_pb_contact_form_num]) && empty($_POST['et_pb_contact_et_number_' . $et_pb_contact_form_num])) || |
| 1351 | 1925 | (isset($_POST['pwh_dcfh_et_pb_contactform_submit_' . $et_pb_contact_form_num]) && $_POST['pwh_dcfh_et_pb_contactform_submit_' . $et_pb_contact_form_num] == 'et_contact_proccess') |
| 1352 | 1926 | ) |
| 1353 | 1927 | ) { |
| 1354 | - | |
| 1355 | - $success_message = isset($form->props['success_message']) ? str_replace(array('[', ']', '"'), array('[', ']', '"'), $form->props['success_message']) : ''; | |
| 1928 | + $success_message = isset($form->props['success_message']) ? $this->decode_shortcodes($form->props['success_message'], true) : ''; | |
| 1356 | 1929 | if (false !== strpos($success_message, '[')) { |
| 1357 | - $shortcode_tags = array( | |
| 1930 | + $shortcode_tags = [ | |
| 1358 | 1931 | 'e2pdf-download', |
| 1359 | 1932 | 'e2pdf-save', |
| 1360 | 1933 | 'e2pdf-view', |
| 1361 | 1934 | 'e2pdf-adobesign', |
| 1362 | 1935 | 'e2pdf-zapier', |
| 1363 | - ); | |
| 1936 | + ]; | |
| 1364 | 1937 | preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $success_message, $matches); |
| 1365 | 1938 | $tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 1366 | 1939 | if (!empty($tagnames)) { |
| 1367 | 1940 | preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $success_message, $shortcodes); |
| @@ -1369,27 +1942,14 @@ | ||
| 1369 | 1942 | $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); |
| 1370 | 1943 | if (isset($form->props['enable_multistep']) && 'on' === $form->props['enable_multistep']) { |
| 1371 | 1944 | $output = str_replace($shortcode_value, do_shortcode_tag($shortcode), $output); |
| 1372 | 1945 | } else { |
| 1373 | - $output = str_replace(str_replace(array('"'), array('"'), $shortcode_value), do_shortcode_tag($shortcode), $output); | |
| 1946 | + $output = str_replace(str_replace(['"'], ['"'], $shortcode_value), do_shortcode_tag($shortcode), $output); | |
| 1374 | 1947 | } |
| 1375 | 1948 | } |
| 1376 | 1949 | } |
| 1377 | 1950 | } |
| 1378 | 1951 | } |
| 1379 | - | |
| 1380 | - remove_filter('wp_mail', array($this, 'filter_wp_mail'), 11); | |
| 1381 | - remove_filter('wp_mail', array($this, 'filter_wp_mail_pwh_dcfh'), 11); | |
| 1382 | - | |
| 1383 | - $files = $this->helper->get('divi_attachments'); | |
| 1384 | - if (is_array($files) && !empty($files)) { | |
| 1385 | - foreach ($files as $key => $file) { | |
| 1386 | - $this->helper->delete_dir(dirname($file) . '/'); | |
| 1387 | - } | |
| 1388 | - $this->helper->deset('divi_attachments'); | |
| 1389 | - } | |
| 1390 | - | |
| 1391 | - | |
| 1392 | 1952 | return $output; |
| 1393 | 1953 | } |
| 1394 | 1954 | |
| 1395 | 1955 | // delete item |
| @@ -1398,13 +1958,13 @@ | ||
| 1398 | 1958 | $template = new Model_E2pdf_Template(); |
| 1399 | 1959 | if ($template_id && $dataset && $template->load($template_id)) { |
| 1400 | 1960 | if ($template->get('extension') === 'divi' && $template->get('item')) { |
| 1401 | 1961 | $item = $template->get('item'); |
| 1402 | - $where = array( | |
| 1962 | + $where = [ | |
| 1403 | 1963 | 'ID' => $dataset, |
| 1404 | 1964 | 'item' => $item, |
| 1405 | 1965 | 'extension' => 'divi', |
| 1406 | - ); | |
| 1966 | + ]; | |
| 1407 | 1967 | $wpdb->delete($wpdb->prefix . 'e2pdf_datasets', $where); |
| 1408 | 1968 | return true; |
| 1409 | 1969 | } |
| 1410 | 1970 | } |
| @@ -1416,12 +1976,12 @@ | ||
| 1416 | 1976 | global $wpdb; |
| 1417 | 1977 | $template = new Model_E2pdf_Template(); |
| 1418 | 1978 | if ($template_id && $template->load($template_id)) { |
| 1419 | 1979 | if ($template->get('extension') === 'divi' && $template->get('item')) { |
| 1420 | - $where = array( | |
| 1980 | + $where = [ | |
| 1421 | 1981 | 'item' => $template->get('item'), |
| 1422 | 1982 | 'extension' => 'divi', |
| 1423 | - ); | |
| 1983 | + ]; | |
| 1424 | 1984 | $wpdb->delete($wpdb->prefix . 'e2pdf_datasets', $where); |
| 1425 | 1985 | return true; |
| 1426 | 1986 | } |
| 1427 | 1987 | } |
| @@ -1429,10 +1989,172 @@ | ||
| 1429 | 1989 | } |
| 1430 | 1990 | |
| 1431 | 1991 | // styles |
| 1432 | 1992 | public function styles($item_id = false) { |
| 1433 | - $styles = array( | |
| 1434 | - plugins_url('css/extension/divi.css?v=' . time(), $this->helper->get('plugin_file_path')), | |
| 1993 | + $styles = []; | |
| 1994 | + if ($this->divi5()) { | |
| 1995 | + $assets_list = \ET\Builder\FrontEnd\Assets\DynamicAssetsUtils::get_assets_list( | |
| 1996 | + [ | |
| 1997 | + 'prefix' => \ET\Builder\FrontEnd\Assets\DynamicAssetsUtils::get_dynamic_assets_path(), | |
| 1998 | + 'suffix' => '', | |
| 1999 | + 'specialty_suffix' => '', | |
| 2000 | + ] | |
| 2001 | + ); | |
| 2002 | + foreach ($assets_list as $list) { | |
| 2003 | + if (!empty($list['css']) && is_array($list['css'])) { | |
| 2004 | + foreach ($list['css'] as $css) { | |
| 2005 | + $styles[] = $this->wp_convert_path_to_url($css); | |
| 2006 | + } | |
| 2007 | + } | |
| 2008 | + } | |
| 2009 | + } | |
| 2010 | + $styles[] = plugins_url('css/extension/divi.css?v=' . time(), $this->helper->get('plugin_file_path')); | |
| 2011 | + return $styles; | |
| 2012 | + } | |
| 2013 | + | |
| 2014 | + public function wp_convert_path_to_url($path) { | |
| 2015 | + // Standardize slashes for Windows/Linux compatibility | |
| 2016 | + $path = wp_normalize_path($path); | |
| 2017 | + $root = wp_normalize_path(ABSPATH); | |
| 2018 | + | |
| 2019 | + // Replace the server root with the Site URL | |
| 2020 | + return str_replace($root, site_url('/'), $path); | |
| 2021 | + } | |
| 2022 | + | |
| 2023 | + // sanitize | |
| 2024 | + public function sanitize($value) { | |
| 2025 | + if (is_array($value)) { | |
| 2026 | + foreach ($value as $k => $v) { | |
| 2027 | + $value[$k] = $this->sanitize($v); | |
| 2028 | + } | |
| 2029 | + return $value; | |
| 2030 | + } | |
| 2031 | + if (!is_string($value)) { | |
| 2032 | + return $value; | |
| 2033 | + } | |
| 2034 | + if (stripos($value, 'e2pdf-') === false) { | |
| 2035 | + return $value; | |
| 2036 | + } | |
| 2037 | + return preg_replace('/(?:\[|[|\{)(e2pdf-download|e2pdf-view|e2pdf-save|e2pdf-attachment|e2pdf-adobesign|e2pdf-zapier)[^\]}\r\n]*(?:\]|]|\})/i', '', $value); | |
| 2038 | + } | |
| 2039 | + | |
| 2040 | + // decode shortcodes | |
| 2041 | + public function decode_shortcodes($value = '', $quote = false) { | |
| 2042 | + return preg_replace_callback( | |
| 2043 | + '/([)((e2pdf-download|e2pdf-view|e2pdf-save|e2pdf-attachment|e2pdf-adobesign|e2pdf-zapier)[^&]*?)(])/', | |
| 2044 | + function ($m) use ($quote) { | |
| 2045 | + $shortcode = $m[2]; | |
| 2046 | + if ($quote !== false) { | |
| 2047 | + $shortcode = str_replace('"', '"', $shortcode); | |
| 2048 | + } | |
| 2049 | + | |
| 2050 | + return '[' . $shortcode . ']'; | |
| 2051 | + }, | |
| 2052 | + $value | |
| 1435 | 2053 | ); |
| 1436 | - return $styles; | |
| 2054 | + } | |
| 2055 | + | |
| 2056 | + // encode shortcodes | |
| 2057 | + public function encode_shortcodes($value = '', $quote = false) { | |
| 2058 | + return preg_replace_callback( | |
| 2059 | + '/(\[)((e2pdf-download|e2pdf-view|e2pdf-save|e2pdf-attachment|e2pdf-adobesign|e2pdf-zapier)[^\]]*?)(\])/', | |
| 2060 | + function ($m) use ($quote) { | |
| 2061 | + $shortcode = $m[2]; | |
| 2062 | + if ($quote !== false) { | |
| 2063 | + $shortcode = str_replace('"', '"', $shortcode); | |
| 2064 | + } | |
| 2065 | + | |
| 2066 | + return '[' . $shortcode . ']'; | |
| 2067 | + }, | |
| 2068 | + $value | |
| 2069 | + ); | |
| 2070 | + } | |
| 2071 | + | |
| 2072 | + // divi4 load | |
| 2073 | + public function divi4_load() { | |
| 2074 | + if (defined('ET_BUILDER_DIR') && !$this->divi5()) { | |
| 2075 | + require_once ET_BUILDER_DIR . 'class-et-builder-element.php'; | |
| 2076 | + require_once ET_BUILDER_DIR . 'functions.php'; | |
| 2077 | + require_once ET_BUILDER_DIR . 'ab-testing.php'; | |
| 2078 | + require_once ET_BUILDER_DIR . 'class-et-global-settings.php'; | |
| 2079 | + if (file_exists(ET_BUILDER_DIR . 'module/type/WithSpamProtection.php')) { | |
| 2080 | + require_once ET_BUILDER_DIR . 'module/type/WithSpamProtection.php'; | |
| 2081 | + } | |
| 2082 | + require_once ET_BUILDER_DIR . 'module/ContactForm.php'; | |
| 2083 | + require_once ET_BUILDER_DIR . 'module/ContactFormItem.php'; | |
| 2084 | + new ET_Builder_Module_Contact_Form(); | |
| 2085 | + new ET_Builder_Module_Contact_Form_Item(); | |
| 2086 | + } | |
| 2087 | + } | |
| 2088 | + | |
| 2089 | + // is divi5 | |
| 2090 | + public function divi5() { | |
| 2091 | + if (defined('ET_CORE_VERSION') && version_compare(ET_CORE_VERSION, '4.99', '>')) { | |
| 2092 | + return true; | |
| 2093 | + } | |
| 2094 | + return false; | |
| 2095 | + } | |
| 2096 | + | |
| 2097 | + // is divi4 form | |
| 2098 | + public function divi4_form($content = '') { | |
| 2099 | + return (false !== strpos($content, '[et_pb_contact_form')); | |
| 2100 | + } | |
| 2101 | + | |
| 2102 | + // is divi 5 form | |
| 2103 | + public function divi5_form($content = '') { | |
| 2104 | + return (false !== strpos($content, 'wp:divi/contact-form')); | |
| 2105 | + } | |
| 2106 | + | |
| 2107 | + // pwh dcfh resolve file url | |
| 2108 | + public function pwh_dcfh_resolve_file_url($file, $options) { | |
| 2109 | + | |
| 2110 | + if (!$file) { | |
| 2111 | + return $file; | |
| 2112 | + } | |
| 2113 | + | |
| 2114 | + if (!function_exists('ks_pac_dcfh_app') || !function_exists('path_join')) { | |
| 2115 | + return $file; | |
| 2116 | + } | |
| 2117 | + | |
| 2118 | + $contact_form_id = $options['uniqueId']; | |
| 2119 | + $timestamp = strtotime($options['timestamp']); | |
| 2120 | + $saveFilesToMedia = $options['saveFilesToMedia'] === 'on' ? true : false; | |
| 2121 | + | |
| 2122 | + $upload_dir = path_join( | |
| 2123 | + 'pwh-dcfh-uploads', | |
| 2124 | + 'forms/' . $contact_form_id . '/' | |
| 2125 | + ); | |
| 2126 | + $upload_path = ks_pac_dcfh_app()->file_utils()::get_wp_upload_dir( | |
| 2127 | + $upload_dir, | |
| 2128 | + 'basedir' | |
| 2129 | + ); | |
| 2130 | + $upload_url = ks_pac_dcfh_app()->file_utils()::get_wp_upload_dir( | |
| 2131 | + $upload_dir, | |
| 2132 | + 'baseurl' | |
| 2133 | + ); | |
| 2134 | + if ($saveFilesToMedia) { | |
| 2135 | + $wp_upload_dir = wp_upload_dir(); | |
| 2136 | + $upload_path = $wp_upload_dir['basedir']; | |
| 2137 | + $upload_url = $wp_upload_dir['baseurl']; | |
| 2138 | + } | |
| 2139 | + $dates = [ | |
| 2140 | + date('Y/m', $timestamp), | |
| 2141 | + date('Y/m', strtotime('-1 month', $timestamp)), | |
| 2142 | + date('Y/m', strtotime('+1 month', $timestamp)), | |
| 2143 | + ]; | |
| 2144 | + | |
| 2145 | + foreach ($dates as $date) { | |
| 2146 | + $date_path = path_join( | |
| 2147 | + $upload_path, | |
| 2148 | + $date | |
| 2149 | + ); | |
| 2150 | + if (@file_exists(path_join($date_path, $file))) { | |
| 2151 | + $file = path_join( | |
| 2152 | + trailingslashit($upload_url) . $date, | |
| 2153 | + $file | |
| 2154 | + ); | |
| 2155 | + break; | |
| 2156 | + } | |
| 2157 | + } | |
| 2158 | + return $file; | |
| 1437 | 2159 | } |
| 1438 | 2160 | } |