-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathExclusionsService.php
More file actions
230 lines (202 loc) · 6.47 KB
/
Copy pathExclusionsService.php
File metadata and controls
230 lines (202 loc) · 6.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php
namespace Cleantalk\Antispam\EmailEncoder;
use Cleantalk\ApbctWP\State;
use Cleantalk\ApbctWP\Variables\Cookie;
use Cleantalk\ApbctWP\Variables\Post;
use Cleantalk\ApbctWP\Variables\Server;
use Cleantalk\Common\TT;
class ExclusionsService
{
/**
* Keep arrays of exclusion signs in the array
* @var array
*/
private $content_exclusions_signs = array(
//divi contact forms additional emails
array('_unique_id', 'et_pb_contact_form'),
//divi builder contact forms
array('_builder_version', 'custom_contact_email'),
//ninja form noscript content exclusion
array('ninja-forms-noscript-message'),
//enfold theme contact form content exclusion - this fired during buffer interception
array('av_contact', 'email', 'from_email'),
// Stylish Cost Calculator
array('scc-form-field-item'),
// Exclusion of maps from leaflet
array('leaflet'),
// prevent broking elementor swiper gallery
array('class', 'elementor-swiper', 'elementor-testimonial', 'swiper-pagination'),
// ics-calendar
array('ics_calendar'),
);
/**
* @return string|false
* @psalm-suppress PossiblyUnusedReturnValue
*/
public function doSkipBeforeAnything()
{
global $apbct;
if ( $this->byAccessKeyFail($apbct) ) {
return 'byAccessKeyFail';
}
return false;
}
/**
* @return string|false
* @psalm-suppress PossiblyUnusedReturnValue
*/
public function doSkipBeforeModifyingHooksAdded()
{
global $apbct;
if ( $this->byPluginSetting($apbct) ) {
return 'byPluginSetting';
}
// Excluded request
if ( $this->byServerVars() ) {
return 'byServerVars';
}
return false;
}
/**
* @param $content
*
* @return string|false
* @psalm-suppress PossiblyUnusedReturnValue
* @psalm-suppress PossiblyUnusedMethod
*/
public function doReturnContentBeforeModify($content)
{
global $apbct;
if ( !(bool)$apbct->settings['data__email_decoder_encode_email_addresses'] && !(bool)$apbct->settings['data__email_decoder_encode_phone_numbers'] ) {
return 'globallyDisabledBothEncoding';
}
if ( $this->byLoggedIn() ) {
return 'byLoggedIn';
}
//skip empty or invalid content
if ( $this->byEmptyContent($content) ) {
return 'byEmptyContent';
}
if ( $this->byUrlOnHooks() ) {
return 'byUrlOnHooks';
}
if ( $this->byContentSigns($content) ) {
return 'byContentSigns';
}
return false;
}
/**
* Excluded requests
* @return bool
*/
private function byServerVars()
{
// Excluded request by alt cookie
$apbct_email_encoder_passed = Cookie::get('apbct_email_encoder_passed');
if ( $apbct_email_encoder_passed === apbct_get_email_encoder_pass_key() ) {
return true;
}
if (
apbct_is_plugin_active('ultimate-member/ultimate-member.php') &&
isset($_POST['um_request']) &&
array_key_exists('REQUEST_METHOD', $_SERVER) &&
strtoupper($_SERVER['REQUEST_METHOD']) === 'POST' &&
empty(Post::get('encodedEmail'))
) {
return true;
}
return false;
}
/**
* @param State $apbct
*
* @return bool
*/
private function byPluginSetting($apbct)
{
return ! $apbct->settings['data__email_decoder'];
}
/**
* @param State $apbct
*
* @return bool
*/
private function byAccessKeyFail($apbct)
{
return !$apbct->key_is_ok || ! apbct_api_key__is_correct();
}
/**
* Check content if it contains exclusions from exclusion list
* @param $content - content to check
* @return bool - true if exclusions found, else - false
*/
private function byContentSigns($content)
{
if ( is_array($this->content_exclusions_signs) ) {
foreach ( array_values($this->content_exclusions_signs) as $_signs_array => $signs ) {
//process each of subarrays of signs
$signs_found_count = 0;
if ( isset($signs) && is_array($signs) ) {
//chek all the signs in the sub-array
foreach ( $signs as $sign ) {
if ( is_string($sign) ) {
if ( strpos($content, $sign) === false ) {
continue;
} else {
$signs_found_count++;
}
}
}
//if each of signs in the sub-array are found return true
if ( $signs_found_count === count($signs) ) {
if (in_array('et_pb_contact_form', $signs) && !is_admin()) {
return false;
}
return true;
}
}
}
}
//no signs found
return false;
}
/**
* @param string $content
*
* @return bool
*/
private function byEmptyContent($content)
{
//skip empty or invalid content
return empty($content) || !is_string($content);
}
/**
* @return bool
*/
private function byLoggedIn()
{
return apbct_is_user_logged_in() && !apbct_is_in_uri('options-general.php?page=cleantalk');
}
/**
* Skip encoder run on hooks.
*
* 1. Applies filter "apbct_hook_skip_email_encoder_on_url_list" to get modified list of URI chunks that needs to skip.
* @return bool
*/
private function byUrlOnHooks()
{
$skip_encode = false;
$url_chunk_list = array();
// Apply filter "apbct_hook_skip_email_encoder_on_url_list" to get the URI chunk list.
$url_chunk_list = apply_filters('apbct_skip_email_encoder_on_uri_chunk_list', $url_chunk_list);
if ( !empty($url_chunk_list) && is_array($url_chunk_list) ) {
foreach ($url_chunk_list as $chunk) {
if (is_string($chunk) && strpos(TT::toString(Server::get('REQUEST_URI')), $chunk) !== false) {
$skip_encode = true;
break;
}
}
}
return $skip_encode;
}
}