| 1 |
<?php |
| 2 |
|
| 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 |
| 10 |
*/ |
| 11 |
if (!defined('ABSPATH')) { |
| 12 |
die('Access denied.'); |
| 13 |
} |
| 14 |
|
| 15 |
class Extension_E2pdf_Divi extends Model_E2pdf_Model { |
| 16 |
|
| 17 |
private $options; |
| 18 |
private $info = array( |
| 19 |
'key' => 'divi', |
| 20 |
'title' => 'Divi Forms', |
| 21 |
); |
| 22 |
|
| 23 |
// info |
| 24 |
public function info($key = false) { |
| 25 |
if ($key && isset($this->info[$key])) { |
| 26 |
return $this->info[$key]; |
| 27 |
} else { |
| 28 |
return array( |
| 29 |
$this->info['key'] => $this->info['title'], |
| 30 |
); |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
// active |
| 35 |
public function active() { |
| 36 |
if (file_exists(get_template_directory() . '/et-pagebuilder/et-pagebuilder.php')) { |
| 37 |
return true; |
| 38 |
} else { |
| 39 |
if (defined('E2PDF_DIVI_EXTENSION') || $this->helper->load('extension')->is_plugin_active('divi-builder/divi-builder.php')) { |
| 40 |
return true; |
| 41 |
} |
| 42 |
} |
| 43 |
return false; |
| 44 |
} |
| 45 |
|
| 46 |
// set |
| 47 |
public function set($key, $value) { |
| 48 |
if (!isset($this->options)) { |
| 49 |
$this->options = new stdClass(); |
| 50 |
} |
| 51 |
$this->options->$key = $value; |
| 52 |
switch ($key) { |
| 53 |
case 'dataset': |
| 54 |
$this->set('cached_entry', []); |
| 55 |
$this->set('cached_meta', []); |
| 56 |
if ($this->get('item') && $this->get('dataset')) { |
| 57 |
$entry = new Model_E2pdf_Dataset(); |
| 58 |
if ($entry->load($this->get('dataset'), $this->get('item'), 'divi')) { |
| 59 |
$cached_entry = $entry->get('entry'); |
| 60 |
$this->set('cached_entry', $cached_entry); |
| 61 |
$processed_fields_values = []; |
| 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 |
} |
| 86 |
} |
| 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']))) { |
| 94 |
$subdir = $tmpsubdir; |
| 95 |
} |
| 96 |
} |
| 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; |
| 103 |
} |
| 104 |
} |
| 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 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 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 |
} |
| 129 |
$meta_data = []; |
| 130 |
foreach ($processed_fields_values as $field_key => $field_value) { |
| 131 |
$meta_data['%%' . $field_key . '%%'] = $field_value['value']; |
| 132 |
} |
| 133 |
$this->set('cached_meta', $meta_data); |
| 134 |
} |
| 135 |
} |
| 136 |
break; |
| 137 |
default: |
| 138 |
break; |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
// get |
| 143 |
public function get($key) { |
| 144 |
if (isset($this->options->$key)) { |
| 145 |
$value = $this->options->$key; |
| 146 |
} else { |
| 147 |
switch ($key) { |
| 148 |
case 'args': |
| 149 |
case 'cached_entry': |
| 150 |
case 'cached_meta': |
| 151 |
$value = []; |
| 152 |
break; |
| 153 |
default: |
| 154 |
$value = false; |
| 155 |
break; |
| 156 |
} |
| 157 |
} |
| 158 |
return $value; |
| 159 |
} |
| 160 |
|
| 161 |
// items |
| 162 |
public function items() { |
| 163 |
global $wpdb; |
| 164 |
$condition = array( |
| 165 |
'post_content' => array( |
| 166 |
'condition' => 'LIKE', |
| 167 |
'value' => '%et_pb_contact_form%', |
| 168 |
'type' => '%s', |
| 169 |
), |
| 170 |
'post_type' => array( |
| 171 |
'condition' => '<>', |
| 172 |
'value' => array( |
| 173 |
'revision', |
| 174 |
'et_pb_layout', |
| 175 |
), |
| 176 |
'type' => '%s', |
| 177 |
), |
| 178 |
); |
| 179 |
$order_condition = array( |
| 180 |
'orderby' => 'id', |
| 181 |
'order' => 'desc', |
| 182 |
); |
| 183 |
$where = $this->helper->load('db')->prepare_where($condition); |
| 184 |
$orderby = $this->helper->load('db')->prepare_orderby($order_condition); |
| 185 |
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare |
| 186 |
$posts = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . $wpdb->prefix . 'posts`' . $where['sql'] . $orderby . '', $where['filter'])); |
| 187 |
|
| 188 |
$content = []; |
| 189 |
foreach ($posts as $key => $post) { |
| 190 |
foreach ($this->get_forms($post->post_content) as $form_key => $form_value) { |
| 191 |
$content[] = $this->item($form_key); |
| 192 |
} |
| 193 |
} |
| 194 |
return $content; |
| 195 |
} |
| 196 |
|
| 197 |
// get forms |
| 198 |
public function get_forms($content) { |
| 199 |
$forms = []; |
| 200 |
if (false !== strpos($content, 'et_pb_contact_form')) { |
| 201 |
$shortcode_tags = array( |
| 202 |
'et_pb_contact_form', |
| 203 |
); |
| 204 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); |
| 205 |
$tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 206 |
if (!empty($tagnames)) { |
| 207 |
preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes); |
| 208 |
foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 209 |
$shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); |
| 210 |
preg_match_all('/admin_label="(.*?)"/', $shortcode[3], $labels); |
| 211 |
if (isset($labels['1'])) { |
| 212 |
foreach ($labels['1'] as $label) { |
| 213 |
$forms[$label] = $label; |
| 214 |
} |
| 215 |
} |
| 216 |
} |
| 217 |
} |
| 218 |
} |
| 219 |
return $forms; |
| 220 |
} |
| 221 |
|
| 222 |
// datasets |
| 223 |
public function datasets($item_id = false, $name = false) { |
| 224 |
global $wpdb; |
| 225 |
$datasets = []; |
| 226 |
if ($item_id) { |
| 227 |
$condition = array( |
| 228 |
'extension' => array( |
| 229 |
'condition' => '=', |
| 230 |
'value' => 'divi', |
| 231 |
'type' => '%s', |
| 232 |
), |
| 233 |
'item' => array( |
| 234 |
'condition' => '=', |
| 235 |
'value' => $item_id, |
| 236 |
'type' => '%s', |
| 237 |
), |
| 238 |
); |
| 239 |
$order_condition = array( |
| 240 |
'orderby' => 'ID', |
| 241 |
'order' => 'desc', |
| 242 |
); |
| 243 |
$where = $this->helper->load('db')->prepare_where($condition); |
| 244 |
$orderby = $this->helper->load('db')->prepare_orderby($order_condition); |
| 245 |
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare |
| 246 |
$entries = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . $wpdb->prefix . 'e2pdf_datasets`' . $where['sql'] . $orderby . '', $where['filter'])); |
| 247 |
|
| 248 |
if ($entries) { |
| 249 |
$this->set('item', $item_id); |
| 250 |
foreach ($entries as $key => $entry) { |
| 251 |
$this->set('dataset', $entry->ID); |
| 252 |
$entry_title = $this->render($name); |
| 253 |
if (!$entry_title) { |
| 254 |
$entry_title = $entry->ID; |
| 255 |
} |
| 256 |
$datasets[] = array( |
| 257 |
'key' => $entry->ID, |
| 258 |
'value' => $entry_title, |
| 259 |
); |
| 260 |
} |
| 261 |
} |
| 262 |
} |
| 263 |
return $datasets; |
| 264 |
} |
| 265 |
|
| 266 |
// get dataset actions |
| 267 |
public function get_dataset_actions($dataset_id = false) { |
| 268 |
$dataset_id = (int) $dataset_id; |
| 269 |
if (!$dataset_id) { |
| 270 |
return; |
| 271 |
} |
| 272 |
$actions = new stdClass(); |
| 273 |
$actions->view = false; |
| 274 |
$actions->delete = true; |
| 275 |
return $actions; |
| 276 |
} |
| 277 |
|
| 278 |
// get template actions |
| 279 |
public function get_template_actions($template = false) { |
| 280 |
$template = (int) $template; |
| 281 |
if (!$template) { |
| 282 |
return; |
| 283 |
} |
| 284 |
$actions = new stdClass(); |
| 285 |
$actions->delete = true; |
| 286 |
return $actions; |
| 287 |
} |
| 288 |
|
| 289 |
// item |
| 290 |
public function item($item_id = false) { |
| 291 |
if (!$item_id && $this->get('item')) { |
| 292 |
$item_id = $this->get('item'); |
| 293 |
} |
| 294 |
$item = new stdClass(); |
| 295 |
if ($item_id) { |
| 296 |
$item->id = (string) $item_id; |
| 297 |
$item->name = $item_id; |
| 298 |
$form = $this->get_form($item_id); |
| 299 |
if (isset($form->ID)) { |
| 300 |
$item->url = $this->helper->get_url( |
| 301 |
array( |
| 302 |
'post' => $form->ID, |
| 303 |
'action' => 'edit', |
| 304 |
), 'post.php?' |
| 305 |
); |
| 306 |
} else { |
| 307 |
$item->url = ''; |
| 308 |
} |
| 309 |
} else { |
| 310 |
$item->id = ''; |
| 311 |
$item->name = ''; |
| 312 |
$item->url = ''; |
| 313 |
} |
| 314 |
return $item; |
| 315 |
} |
| 316 |
|
| 317 |
// get form |
| 318 |
public function get_form($item_id = false) { |
| 319 |
global $wpdb; |
| 320 |
$item_post = false; |
| 321 |
$condition = array( |
| 322 |
'post_content' => array( |
| 323 |
'condition' => 'LIKE', |
| 324 |
'value' => '%admin_label="' . $item_id . '"%', |
| 325 |
'type' => '%s', |
| 326 |
), |
| 327 |
'post_type' => array( |
| 328 |
'condition' => '<>', |
| 329 |
'value' => array( |
| 330 |
'revision', |
| 331 |
'et_pb_layout', |
| 332 |
), |
| 333 |
'type' => '%s', |
| 334 |
), |
| 335 |
); |
| 336 |
|
| 337 |
$order_condition = array( |
| 338 |
'orderby' => 'id', |
| 339 |
'order' => 'desc', |
| 340 |
); |
| 341 |
|
| 342 |
$where = $this->helper->load('db')->prepare_where($condition); |
| 343 |
$orderby = $this->helper->load('db')->prepare_orderby($order_condition); |
| 344 |
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare |
| 345 |
$posts = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . $wpdb->prefix . 'posts`' . $where['sql'] . $orderby . '', $where['filter'])); |
| 346 |
foreach ($posts as $key => $post) { |
| 347 |
if (in_array($item_id, $this->get_forms($post->post_content))) { |
| 348 |
$item_post = $post; |
| 349 |
break; |
| 350 |
} |
| 351 |
} |
| 352 |
return $item_post; |
| 353 |
} |
| 354 |
|
| 355 |
// render |
| 356 |
public function render($value, $field = [], $convert_shortcodes = true, $raw = false) { |
| 357 |
$value = $this->render_shortcodes($value, $field); |
| 358 |
if (!$raw) { |
| 359 |
$value = $this->strip_shortcodes($value); |
| 360 |
$value = $this->convert_shortcodes($value, $convert_shortcodes, isset($field['type']) && $field['type'] == 'e2pdf-html' ? true : false); |
| 361 |
$value = $this->helper->load('field')->render_checkbox($value, $this, $field); |
| 362 |
} |
| 363 |
return $value; |
| 364 |
} |
| 365 |
|
| 366 |
// render shortcodes |
| 367 |
public function render_shortcodes($value, $field = []) { |
| 368 |
$element_id = isset($field['element_id']) ? $field['element_id'] : false; |
| 369 |
if ($this->verify()) { |
| 370 |
if (false !== strpos($value, '[')) { |
| 371 |
$value = $this->helper->load('field')->pre_shortcodes($value, $this, $field); |
| 372 |
$value = $this->helper->load('field')->inner_shortcodes($value, $this, $field); |
| 373 |
$value = $this->helper->load('field')->wrapper_shortcodes($value, $this, $field); |
| 374 |
} |
| 375 |
$value = $this->helper->load('field')->do_shortcodes($value, $this, $field); |
| 376 |
if (!empty($this->get('cached_meta'))) { |
| 377 |
$value = $this->helper->load('convert')->stritr($value, $this->get('cached_meta')); |
| 378 |
} |
| 379 |
$value = $this->helper->load('field')->render( |
| 380 |
apply_filters('e2pdf_extension_render_shortcodes_pre_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false), |
| 381 |
$this, |
| 382 |
$field |
| 383 |
); |
| 384 |
} |
| 385 |
return apply_filters( |
| 386 |
'e2pdf_extension_render_shortcodes_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false |
| 387 |
); |
| 388 |
} |
| 389 |
|
| 390 |
// strip shortcodes |
| 391 |
public function strip_shortcodes($value) { |
| 392 |
$value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', '', $value); |
| 393 |
$value = preg_replace('~%%[^%]*%%~', '', $value); |
| 394 |
return $value; |
| 395 |
} |
| 396 |
|
| 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 |
// convert shortcodes |
| 410 |
public function convert_shortcodes($value, $to = false, $html = false) { |
| 411 |
if ($value) { |
| 412 |
if ($to) { |
| 413 |
$value = stripslashes_deep($value); |
| 414 |
$value = str_replace('[', '[', $value); |
| 415 |
if (!$html) { |
| 416 |
$value = wp_specialchars_decode($value, ENT_QUOTES); |
| 417 |
} |
| 418 |
} else { |
| 419 |
$value = str_replace('[', '[', $value); |
| 420 |
} |
| 421 |
} |
| 422 |
return $value; |
| 423 |
} |
| 424 |
|
| 425 |
// auto |
| 426 |
public function auto() { |
| 427 |
|
| 428 |
$response = []; |
| 429 |
$elements = []; |
| 430 |
|
| 431 |
if ($this->get('item')) { |
| 432 |
$post = $this->get_form($this->get('item')); |
| 433 |
if ($post && isset($post->post_content)) { |
| 434 |
$content = $post->post_content; |
| 435 |
if (false !== strpos($content, '[')) { |
| 436 |
$shortcode_tags = array( |
| 437 |
'et_pb_contact_form', |
| 438 |
); |
| 439 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); |
| 440 |
$tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 441 |
if (!empty($tagnames)) { |
| 442 |
preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes); |
| 443 |
foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 444 |
$shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); |
| 445 |
$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 |
|
| 461 |
$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) { |
| 469 |
|
| 470 |
if ($xml->get_node_value($element, 'data-type') == 'radio') { |
| 471 |
|
| 472 |
$label = $xpath->query('.//label', $element)->item(0); |
| 473 |
$check_handler = $xpath->query(".//input[contains(@class, 'et_pb_checkbox_handle')]", $element)->item(0); |
| 474 |
|
| 475 |
$name = ''; |
| 476 |
if ($check_handler) { |
| 477 |
$name = '%%' . $xml->get_node_value($check_handler, 'data-original_id') . '%%'; |
| 478 |
} |
| 479 |
|
| 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 |
} |
| 498 |
|
| 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); |
| 503 |
|
| 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 |
} |
| 524 |
|
| 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') { |
| 543 |
|
| 544 |
$label = $xpath->query('.//label', $element)->item(0); |
| 545 |
$check_handler = $xpath->query(".//input[contains(@class, 'et_pb_checkbox_handle')]", $element)->item(0); |
| 546 |
|
| 547 |
$name = ''; |
| 548 |
if ($check_handler) { |
| 549 |
$name = '%%' . $xml->get_node_value($check_handler, 'data-original_id') . '%%'; |
| 550 |
} |
| 551 |
|
| 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 |
} |
| 570 |
|
| 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); |
| 575 |
|
| 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 |
); |
| 590 |
|
| 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 { |
| 609 |
|
| 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); |
| 614 |
|
| 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 |
} |
| 633 |
|
| 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 |
} |
| 654 |
|
| 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 |
} |
| 685 |
} |
| 686 |
} |
| 687 |
} |
| 688 |
} |
| 689 |
} |
| 690 |
} |
| 691 |
} |
| 692 |
} |
| 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; |
| 703 |
} |
| 704 |
|
| 705 |
// auto map |
| 706 |
public function auto_map($name = false) { |
| 707 |
$item = $this->get('item'); |
| 708 |
if ($item) { |
| 709 |
$post = $this->get_form($item); |
| 710 |
if ($post && isset($post->post_content)) { |
| 711 |
$content = $post->post_content; |
| 712 |
|
| 713 |
if (false !== strpos($content, '[')) { |
| 714 |
$shortcode_tags = array( |
| 715 |
'et_pb_contact_form', |
| 716 |
); |
| 717 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); |
| 718 |
$tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 719 |
if (!empty($tagnames)) { |
| 720 |
preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes); |
| 721 |
foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 722 |
$shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); |
| 723 |
$atts = shortcode_parse_atts($shortcode[3]); |
| 724 |
if (isset($atts['admin_label']) && $atts['admin_label'] == $this->get('item')) { |
| 725 |
$field_content = $shortcode_value; |
| 726 |
$field_shortcode_tags = array( |
| 727 |
'et_pb_contact_field', |
| 728 |
); |
| 729 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $field_content, $field_matches); |
| 730 |
$field_tagnames = array_intersect($field_shortcode_tags, $field_matches[1]); |
| 731 |
if (!empty($field_tagnames)) { |
| 732 |
preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($field_tagnames) . '/', $field_content, $field_shortcodes); |
| 733 |
foreach ($field_shortcodes[0] as $field_key => $field_shortcode_value) { |
| 734 |
$field_shortcode = []; |
| 735 |
$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']) . '%%'; |
| 740 |
} |
| 741 |
} |
| 742 |
} |
| 743 |
} |
| 744 |
} |
| 745 |
} |
| 746 |
} |
| 747 |
} |
| 748 |
} |
| 749 |
} |
| 750 |
|
| 751 |
return false; |
| 752 |
} |
| 753 |
|
| 754 |
// auto field |
| 755 |
public function auto_field($field = false, $element = []) { |
| 756 |
|
| 757 |
if (!$field) { |
| 758 |
return false; |
| 759 |
} |
| 760 |
|
| 761 |
if (!isset($element['block'])) { |
| 762 |
$element['block'] = false; |
| 763 |
} |
| 764 |
|
| 765 |
if (!isset($element['float'])) { |
| 766 |
$element['float'] = false; |
| 767 |
} |
| 768 |
|
| 769 |
$classes = []; |
| 770 |
if (isset($element['class']) && $element['class']) { |
| 771 |
$classes = explode(' ', $element['class']); |
| 772 |
unset($element['class']); |
| 773 |
} |
| 774 |
|
| 775 |
$float_classes = array( |
| 776 |
'et_pb_contact_field_half', |
| 777 |
); |
| 778 |
$array_intersect = array_intersect($classes, $float_classes); |
| 779 |
|
| 780 |
if (!empty($array_intersect) && $element['block']) { |
| 781 |
$element['float'] = true; |
| 782 |
}; |
| 783 |
|
| 784 |
$primary_class = false; |
| 785 |
if (!empty($array_intersect)) { |
| 786 |
$primary_class = end($array_intersect); |
| 787 |
} |
| 788 |
|
| 789 |
if ($element['block']) { |
| 790 |
switch ($primary_class) { |
| 791 |
case 'et_pb_contact_field_half': |
| 792 |
$element['width'] = '50%'; |
| 793 |
break; |
| 794 |
default: |
| 795 |
break; |
| 796 |
} |
| 797 |
} |
| 798 |
|
| 799 |
return $element; |
| 800 |
} |
| 801 |
|
| 802 |
// verify |
| 803 |
public function verify() { |
| 804 |
if ($this->get('cached_entry')) { |
| 805 |
return true; |
| 806 |
} |
| 807 |
return false; |
| 808 |
} |
| 809 |
|
| 810 |
// visual mapper |
| 811 |
public function visual_mapper() { |
| 812 |
|
| 813 |
$source = ''; |
| 814 |
$html = ''; |
| 815 |
|
| 816 |
if ($this->get('item')) { |
| 817 |
$post = $this->get_form($this->get('item')); |
| 818 |
if ($post && isset($post->post_content)) { |
| 819 |
|
| 820 |
$content = $post->post_content; |
| 821 |
|
| 822 |
if (false !== strpos($content, '[')) { |
| 823 |
$shortcode_tags = array( |
| 824 |
'et_pb_contact_form', |
| 825 |
); |
| 826 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); |
| 827 |
$tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 828 |
if (!empty($tagnames)) { |
| 829 |
preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes); |
| 830 |
foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 831 |
$shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); |
| 832 |
$atts = shortcode_parse_atts($shortcode[3]); |
| 833 |
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(); |
| 845 |
$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); |
| 857 |
|
| 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 |
} |
| 870 |
|
| 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 |
} |
| 876 |
|
| 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 |
} |
| 889 |
|
| 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 |
} |
| 902 |
|
| 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 |
} |
| 914 |
|
| 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 |
} |
| 921 |
} |
| 922 |
} |
| 923 |
} |
| 924 |
} |
| 925 |
} |
| 926 |
|
| 927 |
return false; |
| 928 |
} |
| 929 |
|
| 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']); |
| 934 |
} |
| 935 |
return $this->filter_wp_mail($args); |
| 936 |
} |
| 937 |
|
| 938 |
// filter mail |
| 939 |
public function filter_wp_mail($args) { |
| 940 |
if (isset($args['message'])) { |
| 941 |
if (false !== strpos($args['message'], '[')) { |
| 942 |
$shortcode_tags = array( |
| 943 |
'e2pdf-download', |
| 944 |
'e2pdf-save', |
| 945 |
'e2pdf-attachment', |
| 946 |
'e2pdf-adobesign', |
| 947 |
'e2pdf-zapier', |
| 948 |
); |
| 949 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $args['message'], $matches); |
| 950 |
$tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 951 |
if (!empty($tagnames)) { |
| 952 |
preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $args['message'], $shortcodes); |
| 953 |
foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 954 |
$shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); |
| 955 |
$atts = shortcode_parse_atts($shortcode[3]); |
| 956 |
if (!isset($atts['apply'])) { |
| 957 |
$shortcode[3] .= ' apply="true"'; |
| 958 |
} |
| 959 |
if (!isset($atts['filter'])) { |
| 960 |
$shortcode[3] .= ' filter="true"'; |
| 961 |
} |
| 962 |
$file = false; |
| 963 |
if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { |
| 964 |
$file = do_shortcode_tag($shortcode); |
| 965 |
if ($file) { |
| 966 |
$tmp = false; |
| 967 |
if (substr($file, 0, 4) === 'tmp:') { |
| 968 |
$file = substr($file, 4); |
| 969 |
$tmp = true; |
| 970 |
} |
| 971 |
if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) { |
| 972 |
if ($tmp) { |
| 973 |
$this->helper->add('divi_attachments', $file); |
| 974 |
} |
| 975 |
} else { |
| 976 |
$this->helper->add('divi_attachments', $file); |
| 977 |
} |
| 978 |
$args['attachments'][] = $file; |
| 979 |
} |
| 980 |
$args['message'] = str_replace($shortcode_value, '', $args['message']); |
| 981 |
} else { |
| 982 |
if (is_array($args['headers']) && !in_array('Content-Type: text/html; charset=UTF-8', $args['headers'])) { |
| 983 |
$args['headers'][] = 'Content-Type: text/html; charset=UTF-8'; |
| 984 |
} |
| 985 |
$args['message'] = str_replace($shortcode_value, do_shortcode_tag($shortcode), $args['message']); |
| 986 |
$args['message'] = str_replace("\r\n", '<br/>', $args['message']); |
| 987 |
} |
| 988 |
} |
| 989 |
} |
| 990 |
} |
| 991 |
} |
| 992 |
|
| 993 |
$wp_mail = array( |
| 994 |
'to' => $args['to'], |
| 995 |
'subject' => $args['subject'], |
| 996 |
'message' => $args['message'], |
| 997 |
'headers' => $args['headers'], |
| 998 |
'attachments' => $args['attachments'], |
| 999 |
); |
| 1000 |
|
| 1001 |
return $wp_mail; |
| 1002 |
} |
| 1003 |
|
| 1004 |
// load actions |
| 1005 |
public function load_actions() { // phpcs:ignore Squiz.WhiteSpace.SuperfluousWhitespace.EndLine |
| 1006 |
} |
| 1007 |
|
| 1008 |
// load filters |
| 1009 |
public function load_filters() { |
| 1010 |
// Divi Contact Form Helper Confirmation Email compatibility fix |
| 1011 |
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); |
| 1013 |
} else { |
| 1014 |
add_filter('et_pb_module_shortcode_attributes', array($this, 'filter_et_pb_module_shortcode_attributes'), 30, 5); |
| 1015 |
} |
| 1016 |
add_filter('et_module_shortcode_output', array($this, 'filter_et_module_shortcode_output'), 30, 3); |
| 1017 |
} |
| 1018 |
|
| 1019 |
// filter shortcode attributes |
| 1020 |
public function filter_et_pb_module_shortcode_attributes($props, $attrs, $render_slug, $address, $content) { |
| 1021 |
|
| 1022 |
if ($render_slug !== 'et_pb_contact_form') { |
| 1023 |
return $props; |
| 1024 |
} |
| 1025 |
|
| 1026 |
$et_contact_proccess = array_search('et_contact_proccess', (array) $_POST); |
| 1027 |
if ($et_contact_proccess === false) { |
| 1028 |
return $props; |
| 1029 |
} |
| 1030 |
|
| 1031 |
$e2pdf_shortcodes = false; |
| 1032 |
|
| 1033 |
$success_message = isset($props['success_message']) ? str_replace(array('[', ']', '"'), array('[', ']', '"'), $props['success_message']) : ''; |
| 1034 |
if (false !== strpos($success_message, '[')) { |
| 1035 |
$shortcode_tags = array( |
| 1036 |
'e2pdf-download', |
| 1037 |
'e2pdf-save', |
| 1038 |
'e2pdf-view', |
| 1039 |
'e2pdf-adobesign', |
| 1040 |
'e2pdf-zapier', |
| 1041 |
); |
| 1042 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $success_message, $matches); |
| 1043 |
$tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 1044 |
if (!empty($tagnames)) { |
| 1045 |
$e2pdf_shortcodes = true; |
| 1046 |
} else { |
| 1047 |
$success_message = ''; |
| 1048 |
} |
| 1049 |
} |
| 1050 |
|
| 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']); |
| 1054 |
} else { |
| 1055 |
$custom_message = isset($props['custom_message']) ? str_replace(array('[', ']'), array('[', ']'), $props['custom_message']) : ''; |
| 1056 |
} |
| 1057 |
if (false !== strpos($custom_message, '[')) { |
| 1058 |
$shortcode_tags = array( |
| 1059 |
'e2pdf-download', |
| 1060 |
'e2pdf-save', |
| 1061 |
'e2pdf-attachment', |
| 1062 |
'e2pdf-adobesign', |
| 1063 |
'e2pdf-zapier', |
| 1064 |
); |
| 1065 |
|
| 1066 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $custom_message, $matches); |
| 1067 |
$tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 1068 |
if (!empty($tagnames)) { |
| 1069 |
$e2pdf_shortcodes = true; |
| 1070 |
} else { |
| 1071 |
$custom_message = ''; |
| 1072 |
} |
| 1073 |
} |
| 1074 |
|
| 1075 |
/* 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']); |
| 1079 |
} 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']) : ''; |
| 1081 |
} |
| 1082 |
if (false !== strpos($confirmation_email_message, '[')) { |
| 1083 |
$shortcode_tags = array( |
| 1084 |
'e2pdf-download', |
| 1085 |
'e2pdf-save', |
| 1086 |
'e2pdf-attachment', |
| 1087 |
'e2pdf-adobesign', |
| 1088 |
'e2pdf-zapier', |
| 1089 |
); |
| 1090 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $confirmation_email_message, $matches); |
| 1091 |
$tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 1092 |
if (!empty($tagnames)) { |
| 1093 |
$e2pdf_shortcodes = true; |
| 1094 |
} else { |
| 1095 |
$confirmation_email_message = ''; |
| 1096 |
} |
| 1097 |
} |
| 1098 |
|
| 1099 |
// check if E2Pdf shortcodes exist in messages |
| 1100 |
if (!$e2pdf_shortcodes) { |
| 1101 |
return $props; |
| 1102 |
} |
| 1103 |
|
| 1104 |
$data = $_POST; |
| 1105 |
if (isset($props['_unique_id'])) { |
| 1106 |
$data['_unique_id'] = $props['_unique_id']; |
| 1107 |
} |
| 1108 |
if (isset($props['save_files_to_media']) && $props['save_files_to_media'] == 'on') { |
| 1109 |
$data['_save_files_to_media'] = $props['save_files_to_media']; |
| 1110 |
$data['_subdir'] = wp_upload_dir()['subdir']; |
| 1111 |
} elseif (function_exists('pwh_dcfh_file_helpers')) { |
| 1112 |
$subdir = pwh_dcfh_file_helpers()::get_subdir(); |
| 1113 |
if (is_array($subdir)) { |
| 1114 |
$data['_subdir'] = implode('/', $subdir); |
| 1115 |
} |
| 1116 |
} elseif (function_exists('ks_pac_dcfh_file_helper')) { |
| 1117 |
$subdir = ks_pac_dcfh_file_helper()::get_subdir(); |
| 1118 |
if (is_array($subdir)) { |
| 1119 |
$data['_subdir'] = implode('/', $subdir); |
| 1120 |
} |
| 1121 |
} |
| 1122 |
|
| 1123 |
$captcha = isset($props['captcha']) ? $props['captcha'] : ''; |
| 1124 |
$use_spam_service = isset($props['use_spam_service']) ? $props['use_spam_service'] : 'off'; |
| 1125 |
$et_pb_contact_form_num = str_replace('et_pb_contactform_submit_', '', $et_contact_proccess); |
| 1126 |
$et_contact_error = false; |
| 1127 |
$current_form_fields = isset($data['et_pb_contact_email_fields_' . $et_pb_contact_form_num]) ? $data['et_pb_contact_email_fields_' . $et_pb_contact_form_num] : ''; |
| 1128 |
$contact_email = ''; |
| 1129 |
$nonce_result = isset($data['_wpnonce-et-pb-contact-form-submitted-' . $et_pb_contact_form_num]) && wp_verify_nonce($data['_wpnonce-et-pb-contact-form-submitted-' . $et_pb_contact_form_num], 'et-pb-contact-form-submit') ? true : false; |
| 1130 |
|
| 1131 |
if ($nonce_result && isset($data['et_pb_contactform_submit_' . $et_pb_contact_form_num]) && empty($data['et_pb_contact_et_number_' . $et_pb_contact_form_num])) { |
| 1132 |
if ('' !== $current_form_fields) { |
| 1133 |
$fields_data_json = str_replace('\\', '', $current_form_fields); |
| 1134 |
$fields_data_array = json_decode($fields_data_json, true); |
| 1135 |
|
| 1136 |
// check whether captcha field is not empty |
| 1137 |
if ('on' === $captcha && 'off' === $use_spam_service && (!isset($data['et_pb_contact_captcha_' . $et_pb_contact_form_num]) || empty($data['et_pb_contact_captcha_' . $et_pb_contact_form_num]))) { |
| 1138 |
$et_contact_error = true; |
| 1139 |
} elseif ('on' === $use_spam_service) { |
| 1140 |
if (class_exists('ET_Builder_Element')) { |
| 1141 |
$contact_form = ET_Builder_Element::get_module('et_pb_contact_form'); |
| 1142 |
if ($contact_form && is_object($contact_form) && method_exists($contact_form, 'is_spam_submission')) { |
| 1143 |
$contact_form->props = $props; |
| 1144 |
if ($contact_form->is_spam_submission()) { |
| 1145 |
if (!empty($_POST['token'])) { |
| 1146 |
unset($_POST['token']); |
| 1147 |
} |
| 1148 |
$et_contact_error = true; |
| 1149 |
} else { |
| 1150 |
$props['use_spam_service'] = 'off'; |
| 1151 |
$props['captcha'] = 'off'; |
| 1152 |
} |
| 1153 |
} |
| 1154 |
} |
| 1155 |
} |
| 1156 |
|
| 1157 |
// check all fields on current form and generate error message if needed |
| 1158 |
if (!empty($fields_data_array)) { |
| 1159 |
foreach ($fields_data_array as $index => $value) { |
| 1160 |
if (isset($value['field_id']) && 'et_pb_contact_et_number_' . $et_pb_contact_form_num === $value['field_id']) { |
| 1161 |
continue; |
| 1162 |
} |
| 1163 |
/* Check all the required fields, generate error message if required field is empty */ |
| 1164 |
$field_value = isset($data[$value['field_id']]) ? trim($data[$value['field_id']]) : ''; |
| 1165 |
if ('required' === $value['required_mark'] && empty($field_value) && !is_numeric($field_value)) { |
| 1166 |
$et_contact_error = true; |
| 1167 |
continue; |
| 1168 |
} |
| 1169 |
/* Additional check for email field */ |
| 1170 |
if ('email' === $value['field_type'] && 'required' === $value['required_mark'] && !empty($field_value)) { |
| 1171 |
$contact_email = isset($data[$value['field_id']]) ? sanitize_email($data[$value['field_id']]) : ''; |
| 1172 |
if (!empty($contact_email) && !is_email($contact_email)) { |
| 1173 |
$et_contact_error = true; |
| 1174 |
} |
| 1175 |
} |
| 1176 |
} |
| 1177 |
} |
| 1178 |
} else { |
| 1179 |
$et_contact_error = true; |
| 1180 |
} |
| 1181 |
} else { |
| 1182 |
$et_contact_error = true; |
| 1183 |
} |
| 1184 |
|
| 1185 |
if (!$et_contact_error && $nonce_result) { |
| 1186 |
$dataset = false; |
| 1187 |
if (false !== strpos($success_message, '[')) { |
| 1188 |
$shortcode_tags = array( |
| 1189 |
'e2pdf-download', |
| 1190 |
'e2pdf-save', |
| 1191 |
'e2pdf-view', |
| 1192 |
'e2pdf-adobesign', |
| 1193 |
'e2pdf-zapier', |
| 1194 |
); |
| 1195 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $success_message, $matches); |
| 1196 |
$tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 1197 |
if (!empty($tagnames)) { |
| 1198 |
preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $success_message, $shortcodes); |
| 1199 |
foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 1200 |
$item = false; |
| 1201 |
$shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); |
| 1202 |
$atts = shortcode_parse_atts($shortcode[3]); |
| 1203 |
if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf |
| 1204 |
} else { |
| 1205 |
if (!isset($atts['dataset']) && isset($atts['id'])) { |
| 1206 |
$template = new Model_E2pdf_Template(); |
| 1207 |
$template->load($atts['id']); |
| 1208 |
if ($template->get('extension') === 'divi') { |
| 1209 |
$item = $template->get('item'); |
| 1210 |
if (!$dataset) { |
| 1211 |
$entry = new Model_E2pdf_Dataset(); |
| 1212 |
$entry->set('extension', 'divi'); |
| 1213 |
$entry->set('item', $item); |
| 1214 |
$entry->set('entry', $data); |
| 1215 |
$dataset = $entry->save(); |
| 1216 |
} |
| 1217 |
$atts['dataset'] = $dataset; |
| 1218 |
$shortcode[3] .= ' dataset="' . $dataset . '"'; |
| 1219 |
} |
| 1220 |
} |
| 1221 |
if (!isset($atts['apply'])) { |
| 1222 |
$shortcode[3] .= ' apply="true"'; |
| 1223 |
} |
| 1224 |
if (!isset($atts['iframe_download'])) { |
| 1225 |
$shortcode[3] .= ' iframe_download="true"'; |
| 1226 |
} |
| 1227 |
$props['success_message'] = str_replace(str_replace(array('[', ']'), array('[', ']'), $shortcode_value), '[' . $shortcode[2] . $shortcode[3] . ']', $props['success_message']); |
| 1228 |
} |
| 1229 |
} |
| 1230 |
} |
| 1231 |
} |
| 1232 |
|
| 1233 |
if (false !== strpos($custom_message, '[')) { |
| 1234 |
$shortcode_tags = array( |
| 1235 |
'e2pdf-download', |
| 1236 |
'e2pdf-save', |
| 1237 |
'e2pdf-attachment', |
| 1238 |
'e2pdf-adobesign', |
| 1239 |
'e2pdf-zapier', |
| 1240 |
); |
| 1241 |
|
| 1242 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $custom_message, $matches); |
| 1243 |
$tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 1244 |
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); |
| 1247 |
foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 1248 |
$item = false; |
| 1249 |
$shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); |
| 1250 |
$atts = shortcode_parse_atts($shortcode[3]); |
| 1251 |
if (!isset($atts['dataset']) && isset($atts['id'])) { |
| 1252 |
$template = new Model_E2pdf_Template(); |
| 1253 |
$template->load($atts['id']); |
| 1254 |
if ($template->get('extension') === 'divi') { |
| 1255 |
$item = $template->get('item'); |
| 1256 |
if (!$dataset) { |
| 1257 |
$entry = new Model_E2pdf_Dataset(); |
| 1258 |
$entry->set('extension', 'divi'); |
| 1259 |
$entry->set('item', $item); |
| 1260 |
$entry->set('entry', $data); |
| 1261 |
$dataset = $entry->save(); |
| 1262 |
} |
| 1263 |
$atts['dataset'] = $dataset; |
| 1264 |
$shortcode[3] .= ' dataset="' . $dataset . '"'; |
| 1265 |
} |
| 1266 |
} |
| 1267 |
if ($use_custom_message_richtext) { |
| 1268 |
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']); |
| 1270 |
} else { |
| 1271 |
$props['custom_message_richtext'] = str_replace(str_replace(array('[', ']'), array('[', ']'), $shortcode_value), '[' . $shortcode[2] . $shortcode[3] . ']', $props['custom_message_richtext']); |
| 1272 |
} |
| 1273 |
} else { |
| 1274 |
$props['custom_message'] = str_replace(str_replace(array('[', ']'), array('[', ']'), $shortcode_value), '[' . $shortcode[2] . $shortcode[3] . ']', $props['custom_message']); |
| 1275 |
} |
| 1276 |
} |
| 1277 |
} |
| 1278 |
} |
| 1279 |
|
| 1280 |
if (false !== strpos($confirmation_email_message, '[')) { |
| 1281 |
$shortcode_tags = array( |
| 1282 |
'e2pdf-download', |
| 1283 |
'e2pdf-save', |
| 1284 |
'e2pdf-attachment', |
| 1285 |
'e2pdf-adobesign', |
| 1286 |
'e2pdf-zapier', |
| 1287 |
); |
| 1288 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $confirmation_email_message, $matches); |
| 1289 |
$tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 1290 |
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); |
| 1293 |
foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 1294 |
$item = false; |
| 1295 |
$shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); |
| 1296 |
$atts = shortcode_parse_atts($shortcode[3]); |
| 1297 |
if (!isset($atts['dataset']) && isset($atts['id'])) { |
| 1298 |
$template = new Model_E2pdf_Template(); |
| 1299 |
$template->load($atts['id']); |
| 1300 |
if ($template->get('extension') === 'divi') { |
| 1301 |
$item = $template->get('item'); |
| 1302 |
if (!$dataset) { |
| 1303 |
$entry = new Model_E2pdf_Dataset(); |
| 1304 |
$entry->set('extension', 'divi'); |
| 1305 |
$entry->set('item', $item); |
| 1306 |
$entry->set('entry', $data); |
| 1307 |
$dataset = $entry->save(); |
| 1308 |
} |
| 1309 |
$atts['dataset'] = $dataset; |
| 1310 |
$shortcode[3] .= ' dataset="' . $dataset . '"'; |
| 1311 |
} |
| 1312 |
} |
| 1313 |
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']); |
| 1316 |
} else { |
| 1317 |
$props['confirmation_email_message'] = str_replace(str_replace(array('[', ']'), array('[', ']'), $shortcode_value), '{{' . $shortcode[2] . $shortcode[3] . '}}', $props['confirmation_email_message']); |
| 1318 |
} |
| 1319 |
} 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']); |
| 1322 |
} else { |
| 1323 |
$props['confirmation_email_message'] = str_replace(str_replace(array('[', ']'), array('[', ']'), $shortcode_value), '[' . $shortcode[2] . $shortcode[3] . ']', $props['confirmation_email_message']); |
| 1324 |
} |
| 1325 |
} |
| 1326 |
} |
| 1327 |
} |
| 1328 |
} |
| 1329 |
} |
| 1330 |
|
| 1331 |
return $props; |
| 1332 |
} |
| 1333 |
|
| 1334 |
// filter shortcode output |
| 1335 |
public function filter_et_module_shortcode_output($output, $render_slug, $form) { |
| 1336 |
|
| 1337 |
if ($render_slug !== 'et_pb_contact_form') { |
| 1338 |
return $output; |
| 1339 |
} |
| 1340 |
|
| 1341 |
$et_contact_proccess = array_search('et_contact_proccess', (array) $_POST); |
| 1342 |
if ($et_contact_proccess === false) { |
| 1343 |
return $output; |
| 1344 |
} |
| 1345 |
|
| 1346 |
$et_pb_contact_form_num = str_replace(array('pwh_dcfh_et_pb_contactform_submit_', 'et_pb_contactform_submit_'), array('', ''), $et_contact_proccess); |
| 1347 |
$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 |
|
| 1349 |
if ($nonce_result && ( |
| 1350 |
(isset($_POST['et_pb_contactform_submit_' . $et_pb_contact_form_num]) && empty($_POST['et_pb_contact_et_number_' . $et_pb_contact_form_num])) || |
| 1351 |
(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 |
) |
| 1353 |
) { |
| 1354 |
|
| 1355 |
$success_message = isset($form->props['success_message']) ? str_replace(array('[', ']', '"'), array('[', ']', '"'), $form->props['success_message']) : ''; |
| 1356 |
if (false !== strpos($success_message, '[')) { |
| 1357 |
$shortcode_tags = array( |
| 1358 |
'e2pdf-download', |
| 1359 |
'e2pdf-save', |
| 1360 |
'e2pdf-view', |
| 1361 |
'e2pdf-adobesign', |
| 1362 |
'e2pdf-zapier', |
| 1363 |
); |
| 1364 |
preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $success_message, $matches); |
| 1365 |
$tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 1366 |
if (!empty($tagnames)) { |
| 1367 |
preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $success_message, $shortcodes); |
| 1368 |
foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 1369 |
$shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); |
| 1370 |
if (isset($form->props['enable_multistep']) && 'on' === $form->props['enable_multistep']) { |
| 1371 |
$output = str_replace($shortcode_value, do_shortcode_tag($shortcode), $output); |
| 1372 |
} else { |
| 1373 |
$output = str_replace(str_replace(array('"'), array('"'), $shortcode_value), do_shortcode_tag($shortcode), $output); |
| 1374 |
} |
| 1375 |
} |
| 1376 |
} |
| 1377 |
} |
| 1378 |
} |
| 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 |
return $output; |
| 1393 |
} |
| 1394 |
|
| 1395 |
// delete item |
| 1396 |
public function delete_item($template_id = false, $dataset = false) { |
| 1397 |
global $wpdb; |
| 1398 |
$template = new Model_E2pdf_Template(); |
| 1399 |
if ($template_id && $dataset && $template->load($template_id)) { |
| 1400 |
if ($template->get('extension') === 'divi' && $template->get('item')) { |
| 1401 |
$item = $template->get('item'); |
| 1402 |
$where = array( |
| 1403 |
'ID' => $dataset, |
| 1404 |
'item' => $item, |
| 1405 |
'extension' => 'divi', |
| 1406 |
); |
| 1407 |
$wpdb->delete($wpdb->prefix . 'e2pdf_datasets', $where); |
| 1408 |
return true; |
| 1409 |
} |
| 1410 |
} |
| 1411 |
return false; |
| 1412 |
} |
| 1413 |
|
| 1414 |
// delete items |
| 1415 |
public function delete_items($template_id = false) { |
| 1416 |
global $wpdb; |
| 1417 |
$template = new Model_E2pdf_Template(); |
| 1418 |
if ($template_id && $template->load($template_id)) { |
| 1419 |
if ($template->get('extension') === 'divi' && $template->get('item')) { |
| 1420 |
$where = array( |
| 1421 |
'item' => $template->get('item'), |
| 1422 |
'extension' => 'divi', |
| 1423 |
); |
| 1424 |
$wpdb->delete($wpdb->prefix . 'e2pdf_datasets', $where); |
| 1425 |
return true; |
| 1426 |
} |
| 1427 |
} |
| 1428 |
return false; |
| 1429 |
} |
| 1430 |
|
| 1431 |
// styles |
| 1432 |
public function styles($item_id = false) { |
| 1433 |
$styles = array( |
| 1434 |
plugins_url('css/extension/divi.css?v=' . time(), $this->helper->get('plugin_file_path')), |
| 1435 |
); |
| 1436 |
return $styles; |
| 1437 |
} |
| 1438 |
} |
| 1439 |
|