PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.53
E2Pdf – Export Pdf Tool for WordPress v1.32.53
1.32.53 1.32.51 1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 1.06.02 1.07.11 All 74 releases
← All changes | classes/extension/e2pdf-divi.php +210 -32 1.32.34 → 1.32.53 View file →
@@ -60,12 +60,32 @@
60 60
61 61 $meta_data = [];
62 62 if ($cached_entry && is_array($cached_entry)) {
63 63 // Divi5
64 - if (!empty($cached_entry['ET_CORE_VERSION'])) {
65 - foreach ($cached_entry as $field_key => $field_value) {
66 - $meta_data['%%' . $field_key . '%%'] = $field_value;
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']);
75 + }
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 + }
67 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 + }
68 88 if (!isset($meta_data['%%e2pdf_entry_id%%'])) {
69 89 $meta_data['%%e2pdf_entry_id%%'] = (int) $this->get('dataset');
70 90 }
71 91 } else {
@@ -573,9 +593,9 @@
573 593 ]
574 594 );
575 595 }
576 596
577 - $fields = $xpath->query("//*[contains(@class, 'et_pb_contact_field_radio')]", $element);
597 + $fields = $xpath->query(".//*[contains(@class, 'et_pb_contact_field_radio')]", $element);
578 598 foreach ($fields as $field) {
579 599 $radio_label = $xpath->query('.//label', $field)->item(0);
580 600 $radio = $xpath->query(".//input[@type='radio']", $field)->item(0);
581 601
@@ -592,9 +612,9 @@
592 612 'top' => '5',
593 613 'width' => 'auto',
594 614 'height' => 'auto',
595 615 'value' => '%%' . $xml->get_node_value($radio, 'data-original_id') . '%%',
596 - 'option' => $xml->get_node_value($radio, 'value'),
616 + 'option' => sanitize_text_field($xml->get_node_value($radio, 'value')),
597 617 'group' => '%%' . $xml->get_node_value($radio, 'data-original_id') . '%%',
598 618 ],
599 619 ]
600 620 );
@@ -644,9 +664,9 @@
644 664 ]
645 665 );
646 666 }
647 667
648 - $fields = $xpath->query("//*[contains(@class, 'et_pb_contact_field_checkbox')]", $element);
668 + $fields = $xpath->query(".//*[contains(@class, 'et_pb_contact_field_checkbox')]", $element);
649 669 foreach ($fields as $field) {
650 670 $checkbox_label = $xpath->query('.//label', $field)->item(0);
651 671 $checkbox = $xpath->query(".//input[@type='checkbox']", $field)->item(0);
652 672
@@ -659,9 +679,9 @@
659 679 'top' => '5',
660 680 'width' => 'auto',
661 681 'height' => 'auto',
662 682 'value' => $name,
663 - 'option' => $xml->get_node_value($checkbox, 'value'),
683 + 'option' => sanitize_text_field($xml->get_node_value($checkbox, 'value')),
664 684 ],
665 685 ]
666 686 );
667 687
@@ -707,26 +727,58 @@
707 727 );
708 728 }
709 729
710 730 if ($input_text) {
711 - $elements[] = $this->auto_field(
712 - $input_text,
713 - [
714 - 'type' => 'e2pdf-input',
715 - 'class' => $xml->get_node_value($input_text, 'class'),
716 - 'properties' => [
717 - 'top' => '5',
718 - 'width' => '100%',
719 - 'height' => 'auto',
720 - 'value' => '%%' . $xml->get_node_value($input_text, 'data-original_id') . '%%',
721 - ],
722 - ]
723 - );
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 + );
775 + }
724 776 } elseif ($select) {
725 777 $options_tmp = [];
726 778 $options = $xpath->query('.//option', $select);
727 779 foreach ($options as $option) {
728 - $options_tmp[] = $xml->get_node_value($option, 'value');
780 + $options_tmp[] = sanitize_text_field($xml->get_node_value($option, 'value'));
729 781 }
730 782
731 783 $elements[] = $this->auto_field(
732 784 $select,
@@ -965,8 +1017,9 @@
965 1017 foreach ($fields as $xml_element) {
966 1018 $xml->set_node_value($xml_element, 'name', '%%' . $xml->get_node_value($xml_element, 'data-original_id') . '%%');
967 1019 }
968 1020
1021 + // checkboxes
969 1022 $checkboxes = $xpath->query("//*[contains(@class, 'et_pb_contact_field') and @data-type='checkbox']");
970 1023 foreach ($checkboxes as $xml_element) {
971 1024 $check_handler = $xpath->query(".//input[contains(@class, 'et_pb_checkbox_handle')]", $xml_element)->item(0);
972 1025 $name = '';
@@ -975,16 +1028,35 @@
975 1028 }
976 1029 $checks = $xpath->query(".//input[@type='checkbox']", $xml_element);
977 1030 foreach ($checks as $check) {
978 1031 $xml->set_node_value($check, 'name', $name);
1032 + $xml->set_node_value($check, 'value', sanitize_text_field($xml->get_node_value($check, 'value')));
979 1033 }
980 1034 }
981 1035
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 + }
1041 +
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 +
982 1052 // remove by class
983 1053 $remove_by_class = [
984 1054 'et_pb_contact_submit',
985 1055 'et_pb_contactform_validate_field',
986 1056 'et_pb_checkbox_handle',
1057 + 'et_pb_form_bottom_stepper_container',
1058 + 'stepper__progress',
987 1059 ];
988 1060 foreach ($remove_by_class as $key => $class) {
989 1061 $xml_elements = $xpath->query("//*[contains(@class, '{$class}')]");
990 1062 foreach ($xml_elements as $xml_element) {
@@ -991,8 +1063,13 @@
991 1063 $xml_element->parentNode->removeChild($xml_element);
992 1064 }
993 1065 }
994 1066
1067 + $xml_elements = $xpath->query('//*[@data-step]');
1068 + foreach ($xml_elements as $xml_element) {
1069 + $xml_element->removeAttribute('style');
1070 + }
1071 +
995 1072 // remove parent by class
996 1073 $remove_parent_by_class = [
997 1074 'et_pb_contact_captcha_question',
998 1075 ];
@@ -1141,8 +1218,15 @@
1141 1218
1142 1219 $module_id = !empty($filter_args['id']) ? $filter_args['id'] : '';
1143 1220 $store_instance = !empty($filter_args['storeInstance']) ? $filter_args['storeInstance'] : 0;
1144 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 +
1145 1229 $module = \ET\Builder\FrontEnd\BlockParser\BlockParserStore::get($module_id, $store_instance);
1146 1230
1147 1231 if (!$module) {
1148 1232 return $module_attrs;
@@ -1243,19 +1327,45 @@
1243 1327 if (!$this->get('process')) {
1244 1328 return $module_attrs;
1245 1329 }
1246 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 +
1247 1337 $fields_raw = [];
1248 -
1338 + $filtered_field_attrs = [];
1249 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 + );
1250 1343 foreach ($fields as $field) {
1251 1344 // Skip nested modules (Text, Button, Divider, etc.), only process Contact Field modules.
1252 1345 if ('divi/contact-field' !== $field->blockName) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- This is a property of the WP Core class.
1253 1346 continue;
1254 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 + );
1255 1365
1256 1366 // Use pre-filtered field attributes if provided, otherwise use field attributes from storage.
1257 - $field_attrs = $field->attrs;
1367 + $field_attrs = !empty($filtered_field_attrs[$field->id]) ? $filtered_field_attrs[$field->id] : $field->attrs;
1258 1368 $field_unique_id = \ET\Builder\Packages\ModuleLibrary\ContactField\ContactFieldModule::get_field_unique_id($field->id, $store_instance);
1259 1369 $field_type = $field_attrs['fieldItem']['advanced']['type']['desktop']['value'] ?? 'input';
1260 1370 $field_id = $field_attrs['fieldItem']['advanced']['id']['desktop']['value'] ?? '';
1261 1371 $field_key = strtolower($field_id);
@@ -1348,9 +1458,8 @@
1348 1458 return $module_attrs;
1349 1459 }
1350 1460
1351 1461 $obj->validate_fields();
1352 -
1353 1462 $errorObj = $refError->getValue($obj);
1354 1463
1355 1464 if ($errorObj->has_errors()) {
1356 1465 return $module_attrs;
@@ -1363,19 +1472,32 @@
1363 1472 return $module_attrs;
1364 1473 }
1365 1474
1366 1475 $data = [
1367 - 'ET_CORE_VERSION' => '5',
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 + ],
1368 1483 ];
1484 +
1369 1485 if (!empty($fields_raw) && is_array($fields_raw)) {
1370 1486 foreach ($fields_raw as $field_key => $field_raw) {
1371 - if (!empty($field_raw['value'])) {
1372 - $data[$field_key] = $field_raw['value'];
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 + ];
1373 1492 }
1374 1493 }
1375 1494 }
1376 - if (empty($data['_wp_http_referer']) && !empty($_POST['_wp_http_referer'])) {
1377 - $data['_wp_http_referer'] = esc_url_raw($_POST['_wp_http_referer']);
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 + ];
1378 1500 }
1379 1501
1380 1502 $entry = new Model_E2pdf_Dataset();
1381 1503 $entry->set('extension', 'divi');
@@ -1629,11 +1751,13 @@
1629 1751
1630 1752 if (!$et_contact_error && $nonce_result) {
1631 1753 // divi contact form helper 2.1.3 bug fix wp_mail filter removed at maybe_filter_wp_mail
1632 1754 if (defined('KS_PAC_DCFH_PLUGIN_VERSION') && version_compare(KS_PAC_DCFH_PLUGIN_VERSION, '2.1.3', '>=')) {
1633 - add_filter('wp_mail', function ($args) {
1634 - return $args;
1635 - }, 999);
1755 + add_filter(
1756 + 'wp_mail', function ($args) {
1757 + return $args;
1758 + }, 999
1759 + );
1636 1760 }
1637 1761 add_filter('wp_mail', [$this, 'filter_wp_mail'], 1000);
1638 1762
1639 1763 $dataset = false;
@@ -1977,6 +2101,60 @@
1977 2101
1978 2102 // is divi 5 form
1979 2103 public function divi5_form($content = '') {
1980 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;
1981 2159 }
1982 2160 }