|
4 | 4 | Plugin Name: Anti-Spam by CleanTalk |
5 | 5 | Plugin URI: https://cleantalk.org |
6 | 6 | Description: Max power, all-in-one, no Captcha, premium anti-spam plugin. No comment spam, no registration spam, no contact spam, protects any WordPress forms. |
7 | | - Version: 6.68 |
| 7 | + Version: 6.69 |
8 | 8 | Author: CleanTalk - Anti-Spam Protection <welcome@cleantalk.org> |
9 | 9 | Author URI: https://cleantalk.org |
10 | 10 | Text Domain: cleantalk-spam-protect |
|
14 | 14 | use Cleantalk\Antispam\ProtectByShortcode; |
15 | 15 | use Cleantalk\ApbctWP\Activator; |
16 | 16 | use Cleantalk\ApbctWP\AdminNotices; |
17 | | -use Cleantalk\ApbctWP\Antispam\EmailEncoder; |
| 17 | +use Cleantalk\ApbctWP\ContactsEncoder\ContactsEncoder; |
18 | 18 | use Cleantalk\ApbctWP\Antispam\ForceProtection; |
19 | 19 | use Cleantalk\ApbctWP\API; |
20 | 20 | use Cleantalk\ApbctWP\CleantalkRealPerson; |
|
42 | 42 | use Cleantalk\ApbctWP\Variables\Post; |
43 | 43 | use Cleantalk\ApbctWP\Variables\Request; |
44 | 44 | use Cleantalk\ApbctWP\Variables\Server; |
| 45 | +use Cleantalk\Common\ContactsEncoder\Dto\Params; |
45 | 46 | use Cleantalk\Common\DNS; |
46 | 47 | use Cleantalk\Common\Firewall; |
47 | 48 | use Cleantalk\Common\Schema; |
@@ -222,11 +223,13 @@ function apbct_wp_login_actions($_user_login, $wp_user) |
222 | 223 | } |
223 | 224 | } |
224 | 225 |
|
225 | | - if (!$skip_email_encode && !apbct_is_amp_request()) { |
226 | | - EmailEncoder::getInstance(); |
| 226 | + $contacts_encoder = apbctGetContactsEncoder(); |
| 227 | + if ($apbct->settings['data__email_decoder'] && !$skip_email_encode && !apbct_is_amp_request()) { |
| 228 | + // Encode content |
| 229 | + $contacts_encoder->runEncoding(); |
227 | 230 |
|
228 | | - // Email Encoder ajax handlers |
229 | | - EmailEncoder::getInstance()->registerAjaxRoute(); |
| 231 | + // Email Encoder ajax handlers for decoding |
| 232 | + $contacts_encoder->registerAjaxRoute(); |
230 | 233 | } |
231 | 234 |
|
232 | 235 | // Force protection to avoid spam from bots without javascript |
@@ -931,7 +934,10 @@ function apbct_sfw__check() |
931 | 934 |
|
932 | 935 | $sfw_tables_names = SFW::getSFWTablesNames(); |
933 | 936 |
|
934 | | - if (!$sfw_tables_names) { |
| 937 | + if ( |
| 938 | + !$sfw_tables_names || |
| 939 | + !isset($sfw_tables_names['sfw_personal_table_name'], $sfw_tables_names['sfw_common_table_name']) |
| 940 | + ) { |
935 | 941 | add_action('init', function () use ($apbct) { |
936 | 942 | $apbct->errorAdd( |
937 | 943 | 'sfw', |
@@ -1139,29 +1145,28 @@ function apbct_sfw_update__init($delay = 0) |
1139 | 1145 |
|
1140 | 1146 | $wp_upload_dir = wp_upload_dir(); |
1141 | 1147 | $base_dir = TT::getArrayValueAsString($wp_upload_dir, 'basedir'); |
1142 | | - $apbct->fw_stats['updating_folder'] = $base_dir . DIRECTORY_SEPARATOR . 'cleantalk_fw_files_for_blog_' . get_current_blog_id() . DIRECTORY_SEPARATOR; |
1143 | 1148 | //update only common tables if moderate 0 |
1144 | 1149 | if ( ! $apbct->moderate ) { |
1145 | 1150 | $apbct->data['sfw_load_type'] = 'common'; |
1146 | 1151 | } |
1147 | 1152 |
|
1148 | | - if ( $apbct->network_settings['multisite__work_mode'] == 3) { |
| 1153 | + if ( $apbct->network_settings['multisite__work_mode'] !== 2) { |
1149 | 1154 | $apbct->data['sfw_load_type'] = 'all'; |
1150 | 1155 | $apbct->save('data'); |
1151 | 1156 | } |
1152 | 1157 |
|
1153 | | - if (apbct_sfw_update__switch_to_direct()) { |
1154 | | - return SFWUpdateHelper::directUpdate(); |
1155 | | - } |
1156 | | - |
1157 | | - // Set a new update ID and an update time start |
| 1158 | + // Flush fw stats data |
| 1159 | + $apbct->fw_stats = $apbct->default_fw_stats; |
1158 | 1160 | $apbct->fw_stats['calls'] = 0; |
1159 | 1161 | $apbct->fw_stats['firewall_updating_id'] = md5((string)rand(0, 100000)); |
1160 | 1162 | $apbct->fw_stats['firewall_updating_last_start'] = time(); |
1161 | | - $apbct->fw_stats['common_lists_url_id'] = ''; |
1162 | | - $apbct->fw_stats['personal_lists_url_id'] = ''; |
| 1163 | + $apbct->fw_stats['updating_folder'] = $base_dir . DIRECTORY_SEPARATOR . 'cleantalk_fw_files_for_blog_' . get_current_blog_id() . DIRECTORY_SEPARATOR; |
1163 | 1164 | $apbct->save('fw_stats'); |
1164 | 1165 |
|
| 1166 | + if (apbct_sfw_update__switch_to_direct()) { |
| 1167 | + return SFWUpdateHelper::directUpdate(); |
| 1168 | + } |
| 1169 | + |
1165 | 1170 | $apbct->sfw_update_sentinel->seekId($apbct->fw_stats['firewall_updating_id']); |
1166 | 1171 |
|
1167 | 1172 | // Delete update errors |
@@ -1572,11 +1577,11 @@ function apbct_sfw_update__create_tables($direct_update = false, $return_new_tab |
1572 | 1577 | $db_tables_creator->createTable($common_table_name); |
1573 | 1578 | $apbct->data['sfw_common_table_name'] = $common_table_name; |
1574 | 1579 | //personal table |
1575 | | - $table_name_personal = $apbct->db_prefix . Schema::getSchemaTablePrefix() . 'sfw_personal'; |
| 1580 | + $table_name_personal = $wpdb->prefix . Schema::getSchemaTablePrefix() . 'sfw_personal'; |
1576 | 1581 | $db_tables_creator->createTable($table_name_personal); |
1577 | 1582 | $apbct->data['sfw_personal_table_name'] = $table_name_personal; |
1578 | 1583 | //ua table |
1579 | | - $personal_ua_bl_table_name = $apbct->db_prefix . Schema::getSchemaTablePrefix() . 'ua_bl'; |
| 1584 | + $personal_ua_bl_table_name = $wpdb->prefix . Schema::getSchemaTablePrefix() . 'ua_bl'; |
1580 | 1585 | $db_tables_creator->createTable($personal_ua_bl_table_name); |
1581 | 1586 | $apbct->data['sfw_personal_ua_bl_table_name'] = $personal_ua_bl_table_name; |
1582 | 1587 |
|
@@ -1712,14 +1717,27 @@ function apbct_sfw_update__process_exclusions($direct_update = false) |
1712 | 1717 | { |
1713 | 1718 | global $apbct; |
1714 | 1719 |
|
1715 | | - $db__table__data = APBCT_TBL_FIREWALL_DATA_PERSONAL . '_temp'; |
1716 | | - if ($apbct->data['sfw_load_type'] === 'all') { |
1717 | | - $db__table__data = $apbct->data['sfw_personal_table_name'] . '_temp'; |
| 1720 | + $table_names = SFW::getSFWTablesNames(); |
| 1721 | + $origin_personal_table_name = $table_names && isset($table_names['sfw_personal_table_name']) && is_string($table_names['sfw_personal_table_name']) |
| 1722 | + ? $table_names['sfw_personal_table_name'] |
| 1723 | + : null; |
| 1724 | + |
| 1725 | + if ($origin_personal_table_name) { |
| 1726 | + $temp_table_name = $origin_personal_table_name . '_temp'; |
| 1727 | + } else { |
| 1728 | + return array('error' => 'EXCLUSIONS: CAN NOT GET SFW TABLES NAMES'); |
| 1729 | + } |
| 1730 | + |
| 1731 | + if (!DB::getInstance()->isTableExists($temp_table_name)) { |
| 1732 | + SFW::createTempTables(DB::getInstance(), $origin_personal_table_name); |
| 1733 | + if (!DB::getInstance()->isTableExists($temp_table_name)) { |
| 1734 | + return array('error' => 'EXCLUSIONS: CAN NOT RECREATE TEMP PERSONAL TABLE ' . $temp_table_name); |
| 1735 | + } |
1718 | 1736 | } |
1719 | 1737 |
|
1720 | 1738 | $result = SFW::updateWriteToDbExclusions( |
1721 | 1739 | DB::getInstance(), |
1722 | | - $db__table__data |
| 1740 | + $temp_table_name |
1723 | 1741 | ); |
1724 | 1742 |
|
1725 | 1743 | if ( ! empty($result['error']) ) { |
@@ -1818,8 +1836,8 @@ function apbct_sfw_update__end_of_update__checking_data($direct_update = false) |
1818 | 1836 | } |
1819 | 1837 |
|
1820 | 1838 | if ( in_array($apbct->data['sfw_load_type'], array('all','personal')) |
1821 | | - && isset($apbct->stats['sfw']['entries_personal']) |
1822 | | - && ( $apbct->stats['sfw']['entries_personal'] != $apbct->fw_stats['expected_networks_count_personal'] ) ) { |
| 1839 | + && isset($apbct->stats['sfw']['entries_personal']) |
| 1840 | + && ( $apbct->stats['sfw']['entries_personal'] != $apbct->fw_stats['expected_networks_count_personal'] ) ) { |
1823 | 1841 | return array( |
1824 | 1842 | 'error' => |
1825 | 1843 | 'The discrepancy between the amount of data received for the update and in the final table: ' |
@@ -2026,17 +2044,26 @@ function apbct_sfw_private_records_handler($action, $test_data = null) |
2026 | 2044 | } |
2027 | 2045 | unset($row); |
2028 | 2046 |
|
| 2047 | + $table_names = SFW::getSFWTablesNames(); |
| 2048 | + $table_name = $table_names && isset($table_names['sfw_personal_table_name']) && is_string($table_names['sfw_personal_table_name']) |
| 2049 | + ? $table_names['sfw_personal_table_name'] |
| 2050 | + : false; |
| 2051 | + |
| 2052 | + if (!$table_name || !DB::getInstance()->isTableExists($table_name)) { |
| 2053 | + throw new InvalidArgumentException('internal error: sfw table does not exist'); |
| 2054 | + } |
| 2055 | + |
2029 | 2056 | //method selection |
2030 | 2057 | if ( $action === 'add' ) { |
2031 | 2058 | $handler_output = SFW::privateRecordsAdd( |
2032 | 2059 | DB::getInstance(), |
2033 | | - SFW::getSFWTablesNames()['sfw_personal_table_name'], |
| 2060 | + $table_name, |
2034 | 2061 | $metadata |
2035 | 2062 | ); |
2036 | 2063 | } elseif ( $action === 'delete' ) { |
2037 | 2064 | $handler_output = SFW::privateRecordsDelete( |
2038 | 2065 | DB::getInstance(), |
2039 | | - SFW::getSFWTablesNames()['sfw_personal_table_name'], |
| 2066 | + $table_name, |
2040 | 2067 | $metadata |
2041 | 2068 | ); |
2042 | 2069 | } else { |
@@ -3083,3 +3110,22 @@ function apbct_cron_remove_support_user() |
3083 | 3110 | $temp_user_service = new \Cleantalk\ApbctWP\SupportUser(); |
3084 | 3111 | $temp_user_service->performCronDeleteUser(); |
3085 | 3112 | } |
| 3113 | + |
| 3114 | +/** |
| 3115 | + * This is a helper function to avoid code duplication on build ContactsEncoder object |
| 3116 | + * @return ContactsEncoder |
| 3117 | + */ |
| 3118 | +function apbctGetContactsEncoder() |
| 3119 | +{ |
| 3120 | + global $apbct; |
| 3121 | + |
| 3122 | + $contacts_encoder_params = new Params(); |
| 3123 | + $contacts_encoder_params->api_key = $apbct->api_key; |
| 3124 | + $contacts_encoder_params->is_logged_in = apbct_is_user_logged_in(); |
| 3125 | + $contacts_encoder_params->obfuscation_mode = $apbct->settings['data__email_decoder_obfuscation_mode']; |
| 3126 | + $contacts_encoder_params->obfuscation_text = $apbct->settings['data__email_decoder_obfuscation_custom_text']; |
| 3127 | + $contacts_encoder_params->do_encode_emails = (int)$apbct->settings['data__email_decoder_encode_email_addresses']; |
| 3128 | + $contacts_encoder_params->do_encode_phones = (int)$apbct->settings['data__email_decoder_encode_phone_numbers']; |
| 3129 | + |
| 3130 | + return ContactsEncoder::getInstance($contacts_encoder_params); |
| 3131 | +} |
0 commit comments