Version Description
October 20 2016 = * Custom contact forms: integration. * Pirate Forms: integration. * PHP 7 compatibility: Deleted third-party JSON library and dependences. * PHP 7 compatibility: Fixed end of lines. * YOAST Seo: Fixed PHP warnings. * SpamFireWall: Minor fix for SpamFireWall counter. * Only admin could access to CleanTalk dashboard (exclude Authors an Editors). * Improved filtration in contact forms.
Download this release
Release Info
Developer | Safronik |
Plugin | Spam protection, AntiSpam, FireWall by CleanTalk |
Version | 5.50 |
Comparing to | |
See all releases |
Code changes from version 5.49.2 to 5.50
- cleantalk.php +3 -3
- inc/JSON.php +0 -804
- inc/cleantalk-admin.php +20 -22
- inc/cleantalk-comments.php +13 -11
- inc/cleantalk-common.php +52 -117
- inc/cleantalk-public.php +169 -1
- inc/cleantalk-users.php +15 -12
- inc/cleantalk.class.php +0 -21
- inc/cleantalk_api.php +0 -1
- readme.txt +23 -1
cleantalk.php
CHANGED
@@ -3,12 +3,12 @@
|
|
3 |
Plugin Name: Spam Protection by CleanTalk
|
4 |
Plugin URI: http://cleantalk.org
|
5 |
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. Formerly Anti-Spam by CleanTalk.
|
6 |
-
Version: 5.
|
7 |
Author: СleanTalk <welcome@cleantalk.org>
|
8 |
Author URI: http://cleantalk.org
|
9 |
*/
|
10 |
-
$cleantalk_plugin_version='5.
|
11 |
-
$ct_agent_version = 'wordpress-
|
12 |
$cleantalk_executed=false;
|
13 |
$ct_sfw_updated = false;
|
14 |
|
3 |
Plugin Name: Spam Protection by CleanTalk
|
4 |
Plugin URI: http://cleantalk.org
|
5 |
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. Formerly Anti-Spam by CleanTalk.
|
6 |
+
Version: 5.50
|
7 |
Author: СleanTalk <welcome@cleantalk.org>
|
8 |
Author URI: http://cleantalk.org
|
9 |
*/
|
10 |
+
$cleantalk_plugin_version='5.50';
|
11 |
+
$ct_agent_version = 'wordpress-550';
|
12 |
$cleantalk_executed=false;
|
13 |
$ct_sfw_updated = false;
|
14 |
|
inc/JSON.php
DELETED
@@ -1,804 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
3 |
-
|
4 |
-
/**
|
5 |
-
* Converts to and from JSON format.
|
6 |
-
*
|
7 |
-
* JSON (JavaScript Object Notation) is a lightweight data-interchange
|
8 |
-
* format. It is easy for humans to read and write. It is easy for machines
|
9 |
-
* to parse and generate. It is based on a subset of the JavaScript
|
10 |
-
* Programming Language, Standard ECMA-262 3rd Edition - December 1999.
|
11 |
-
* This feature can also be found in Python. JSON is a text format that is
|
12 |
-
* completely language independent but uses conventions that are familiar
|
13 |
-
* to programmers of the C-family of languages, including C, C++, C#, Java,
|
14 |
-
* JavaScript, Perl, TCL, and many others. These properties make JSON an
|
15 |
-
* ideal data-interchange language.
|
16 |
-
*
|
17 |
-
* This package provides a simple encoder and decoder for JSON notation. It
|
18 |
-
* is intended for use with client-side Javascript applications that make
|
19 |
-
* use of HTTPRequest to perform server communication functions - data can
|
20 |
-
* be encoded into JSON notation for use in a client-side javascript, or
|
21 |
-
* decoded from incoming Javascript requests. JSON format is native to
|
22 |
-
* Javascript, and can be directly eval()'ed with no further parsing
|
23 |
-
* overhead
|
24 |
-
*
|
25 |
-
* All strings should be in ASCII or UTF-8 format!
|
26 |
-
*
|
27 |
-
* LICENSE: Redistribution and use in source and binary forms, with or
|
28 |
-
* without modification, are permitted provided that the following
|
29 |
-
* conditions are met: Redistributions of source code must retain the
|
30 |
-
* above copyright notice, this list of conditions and the following
|
31 |
-
* disclaimer. Redistributions in binary form must reproduce the above
|
32 |
-
* copyright notice, this list of conditions and the following disclaimer
|
33 |
-
* in the documentation and/or other materials provided with the
|
34 |
-
* distribution.
|
35 |
-
*
|
36 |
-
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
37 |
-
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
38 |
-
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
39 |
-
* NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
40 |
-
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
41 |
-
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
42 |
-
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
43 |
-
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
44 |
-
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
45 |
-
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
46 |
-
* DAMAGE.
|
47 |
-
*
|
48 |
-
* @category
|
49 |
-
* @package Services_JSON
|
50 |
-
* @author Michal Migurski <mike-json@teczno.com>
|
51 |
-
* @author Matt Knapp <mdknapp[at]gmail[dot]com>
|
52 |
-
* @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
|
53 |
-
* @copyright 2005 Michal Migurski
|
54 |
-
* @version CVS: $Id: JSON.php,v 1.31 2006/06/28 05:54:17 migurski Exp $
|
55 |
-
* @license http://www.opensource.org/licenses/bsd-license.php
|
56 |
-
* @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
|
57 |
-
*/
|
58 |
-
|
59 |
-
/**
|
60 |
-
* Marker constant for Services_JSON::decode(), used to flag stack state
|
61 |
-
*/
|
62 |
-
define('SERVICES_JSON_SLICE', 1);
|
63 |
-
|
64 |
-
/**
|
65 |
-
* Marker constant for Services_JSON::decode(), used to flag stack state
|
66 |
-
*/
|
67 |
-
define('SERVICES_JSON_IN_STR', 2);
|
68 |
-
|
69 |
-
/**
|
70 |
-
* Marker constant for Services_JSON::decode(), used to flag stack state
|
71 |
-
*/
|
72 |
-
define('SERVICES_JSON_IN_ARR', 3);
|
73 |
-
|
74 |
-
/**
|
75 |
-
* Marker constant for Services_JSON::decode(), used to flag stack state
|
76 |
-
*/
|
77 |
-
define('SERVICES_JSON_IN_OBJ', 4);
|
78 |
-
|
79 |
-
/**
|
80 |
-
* Marker constant for Services_JSON::decode(), used to flag stack state
|
81 |
-
*/
|
82 |
-
define('SERVICES_JSON_IN_CMT', 5);
|
83 |
-
|
84 |
-
/**
|
85 |
-
* Behavior switch for Services_JSON::decode()
|
86 |
-
*/
|
87 |
-
define('SERVICES_JSON_LOOSE_TYPE', 16);
|
88 |
-
|
89 |
-
/**
|
90 |
-
* Behavior switch for Services_JSON::decode()
|
91 |
-
*/
|
92 |
-
define('SERVICES_JSON_SUPPRESS_ERRORS', 32);
|
93 |
-
|
94 |
-
/**
|
95 |
-
* Converts to and from JSON format.
|
96 |
-
*
|
97 |
-
* Brief example of use:
|
98 |
-
*
|
99 |
-
* <code>
|
100 |
-
* // create a new instance of Services_JSON
|
101 |
-
* $json = new Services_JSON();
|
102 |
-
*
|
103 |
-
* // convert a complexe value to JSON notation, and send it to the browser
|
104 |
-
* $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4)));
|
105 |
-
* $output = $json->encode($value);
|
106 |
-
*
|
107 |
-
* print($output);
|
108 |
-
* // prints: ["foo","bar",[1,2,"baz"],[3,[4]]]
|
109 |
-
*
|
110 |
-
* // accept incoming POST data, assumed to be in JSON notation
|
111 |
-
* $input = file_get_contents('php://input', 1000000);
|
112 |
-
* $value = $json->decode($input);
|
113 |
-
* </code>
|
114 |
-
*/
|
115 |
-
class Services_JSON
|
116 |
-
{
|
117 |
-
/**
|
118 |
-
* constructs a new JSON instance
|
119 |
-
*
|
120 |
-
* @param int $use object behavior flags; combine with boolean-OR
|
121 |
-
*
|
122 |
-
* possible values:
|
123 |
-
* - SERVICES_JSON_LOOSE_TYPE: loose typing.
|
124 |
-
* "{...}" syntax creates associative arrays
|
125 |
-
* instead of objects in decode().
|
126 |
-
* - SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
|
127 |
-
* Values which can't be encoded (e.g. resources)
|
128 |
-
* appear as NULL instead of throwing errors.
|
129 |
-
* By default, a deeply-nested resource will
|
130 |
-
* bubble up with an error, so all return values
|
131 |
-
* from encode() should be checked with isError()
|
132 |
-
*/
|
133 |
-
function Services_JSON($use = 0)
|
134 |
-
{
|
135 |
-
$this->use = $use;
|
136 |
-
}
|
137 |
-
|
138 |
-
/**
|
139 |
-
* convert a string from one UTF-16 char to one UTF-8 char
|
140 |
-
*
|
141 |
-
* Normally should be handled by mb_convert_encoding, but
|
142 |
-
* provides a slower PHP-only method for installations
|
143 |
-
* that lack the multibye string extension.
|
144 |
-
*
|
145 |
-
* @param string $utf16 UTF-16 character
|
146 |
-
* @return string UTF-8 character
|
147 |
-
* @access private
|
148 |
-
*/
|
149 |
-
function utf162utf8($utf16)
|
150 |
-
{
|
151 |
-
// oh please oh please oh please oh please oh please
|
152 |
-
if(function_exists('mb_convert_encoding')) {
|
153 |
-
return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
|
154 |
-
}
|
155 |
-
|
156 |
-
$bytes = (ord($utf16{0}) << 8) | ord($utf16{1});
|
157 |
-
|
158 |
-
switch(true) {
|
159 |
-
case ((0x7F & $bytes) == $bytes):
|
160 |
-
// this case should never be reached, because we are in ASCII range
|
161 |
-
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
162 |
-
return chr(0x7F & $bytes);
|
163 |
-
|
164 |
-
case (0x07FF & $bytes) == $bytes:
|
165 |
-
// return a 2-byte UTF-8 character
|
166 |
-
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
167 |
-
return chr(0xC0 | (($bytes >> 6) & 0x1F))
|
168 |
-
. chr(0x80 | ($bytes & 0x3F));
|
169 |
-
|
170 |
-
case (0xFFFF & $bytes) == $bytes:
|
171 |
-
// return a 3-byte UTF-8 character
|
172 |
-
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
173 |
-
return chr(0xE0 | (($bytes >> 12) & 0x0F))
|
174 |
-
. chr(0x80 | (($bytes >> 6) & 0x3F))
|
175 |
-
. chr(0x80 | ($bytes & 0x3F));
|
176 |
-
}
|
177 |
-
|
178 |
-
// ignoring UTF-32 for now, sorry
|
179 |
-
return '';
|
180 |
-
}
|
181 |
-
|
182 |
-
/**
|
183 |
-
* convert a string from one UTF-8 char to one UTF-16 char
|
184 |
-
*
|
185 |
-
* Normally should be handled by mb_convert_encoding, but
|
186 |
-
* provides a slower PHP-only method for installations
|
187 |
-
* that lack the multibye string extension.
|
188 |
-
*
|
189 |
-
* @param string $utf8 UTF-8 character
|
190 |
-
* @return string UTF-16 character
|
191 |
-
* @access private
|
192 |
-
*/
|
193 |
-
function utf82utf16($utf8)
|
194 |
-
{
|
195 |
-
// oh please oh please oh please oh please oh please
|
196 |
-
if(function_exists('mb_convert_encoding')) {
|
197 |
-
return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
|
198 |
-
}
|
199 |
-
|
200 |
-
switch(strlen($utf8)) {
|
201 |
-
case 1:
|
202 |
-
// this case should never be reached, because we are in ASCII range
|
203 |
-
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
204 |
-
return $utf8;
|
205 |
-
|
206 |
-
case 2:
|
207 |
-
// return a UTF-16 character from a 2-byte UTF-8 char
|
208 |
-
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
209 |
-
return chr(0x07 & (ord($utf8{0}) >> 2))
|
210 |
-
. chr((0xC0 & (ord($utf8{0}) << 6))
|
211 |
-
| (0x3F & ord($utf8{1})));
|
212 |
-
|
213 |
-
case 3:
|
214 |
-
// return a UTF-16 character from a 3-byte UTF-8 char
|
215 |
-
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
216 |
-
return chr((0xF0 & (ord($utf8{0}) << 4))
|
217 |
-
| (0x0F & (ord($utf8{1}) >> 2)))
|
218 |
-
. chr((0xC0 & (ord($utf8{1}) << 6))
|
219 |
-
| (0x7F & ord($utf8{2})));
|
220 |
-
}
|
221 |
-
|
222 |
-
// ignoring UTF-32 for now, sorry
|
223 |
-
return '';
|
224 |
-
}
|
225 |
-
|
226 |
-
/**
|
227 |
-
* encodes an arbitrary variable into JSON format
|
228 |
-
*
|
229 |
-
* @param mixed $var any number, boolean, string, array, or object to be encoded.
|
230 |
-
* see argument 1 to Services_JSON() above for array-parsing behavior.
|
231 |
-
* if var is a strng, note that encode() always expects it
|
232 |
-
* to be in ASCII or UTF-8 format!
|
233 |
-
*
|
234 |
-
* @return mixed JSON string representation of input var or an error if a problem occurs
|
235 |
-
* @access public
|
236 |
-
*/
|
237 |
-
function encode($var)
|
238 |
-
{
|
239 |
-
switch (gettype($var)) {
|
240 |
-
case 'boolean':
|
241 |
-
return $var ? 'true' : 'false';
|
242 |
-
|
243 |
-
case 'NULL':
|
244 |
-
return 'null';
|
245 |
-
|
246 |
-
case 'integer':
|
247 |
-
return (int) $var;
|
248 |
-
|
249 |
-
case 'double':
|
250 |
-
case 'float':
|
251 |
-
return (float) $var;
|
252 |
-
|
253 |
-
case 'string':
|
254 |
-
// STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
|
255 |
-
$ascii = '';
|
256 |
-
$strlen_var = strlen($var);
|
257 |
-
|
258 |
-
/*
|
259 |
-
* Iterate over every character in the string,
|
260 |
-
* escaping with a slash or encoding to UTF-8 where necessary
|
261 |
-
*/
|
262 |
-
for ($c = 0; $c < $strlen_var; ++$c) {
|
263 |
-
|
264 |
-
$ord_var_c = ord($var{$c});
|
265 |
-
|
266 |
-
switch (true) {
|
267 |
-
case $ord_var_c == 0x08:
|
268 |
-
$ascii .= '\b';
|
269 |
-
break;
|
270 |
-
case $ord_var_c == 0x09:
|
271 |
-
$ascii .= '\t';
|
272 |
-
break;
|
273 |
-
case $ord_var_c == 0x0A:
|
274 |
-
$ascii .= '\n';
|
275 |
-
break;
|
276 |
-
case $ord_var_c == 0x0C:
|
277 |
-
$ascii .= '\f';
|
278 |
-
break;
|
279 |
-
case $ord_var_c == 0x0D:
|
280 |
-
$ascii .= '\r';
|
281 |
-
break;
|
282 |
-
|
283 |
-
case $ord_var_c == 0x22:
|
284 |
-
case $ord_var_c == 0x2F:
|
285 |
-
case $ord_var_c == 0x5C:
|
286 |
-
// double quote, slash, slosh
|
287 |
-
$ascii .= '\\'.$var{$c};
|
288 |
-
break;
|
289 |
-
|
290 |
-
case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
|
291 |
-
// characters U-00000000 - U-0000007F (same as ASCII)
|
292 |
-
$ascii .= $var{$c};
|
293 |
-
break;
|
294 |
-
|
295 |
-
case (($ord_var_c & 0xE0) == 0xC0):
|
296 |
-
// characters U-00000080 - U-000007FF, mask 110XXXXX
|
297 |
-
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
298 |
-
$char = pack('C*', $ord_var_c, ord($var{$c + 1}));
|
299 |
-
$c += 1;
|
300 |
-
$utf16 = $this->utf82utf16($char);
|
301 |
-
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
302 |
-
break;
|
303 |
-
|
304 |
-
case (($ord_var_c & 0xF0) == 0xE0):
|
305 |
-
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
|
306 |
-
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
307 |
-
$char = pack('C*', $ord_var_c,
|
308 |
-
ord($var{$c + 1}),
|
309 |
-
ord($var{$c + 2}));
|
310 |
-
$c += 2;
|
311 |
-
$utf16 = $this->utf82utf16($char);
|
312 |
-
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
313 |
-
break;
|
314 |
-
|
315 |
-
case (($ord_var_c & 0xF8) == 0xF0):
|
316 |
-
// characters U-00010000 - U-001FFFFF, mask 11110XXX
|
317 |
-
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
318 |
-
$char = pack('C*', $ord_var_c,
|
319 |
-
ord($var{$c + 1}),
|
320 |
-
ord($var{$c + 2}),
|
321 |
-
ord($var{$c + 3}));
|
322 |
-
$c += 3;
|
323 |
-
$utf16 = $this->utf82utf16($char);
|
324 |
-
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
325 |
-
break;
|
326 |
-
|
327 |
-
case (($ord_var_c & 0xFC) == 0xF8):
|
328 |
-
// characters U-00200000 - U-03FFFFFF, mask 111110XX
|
329 |
-
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
330 |
-
$char = pack('C*', $ord_var_c,
|
331 |
-
ord($var{$c + 1}),
|
332 |
-
ord($var{$c + 2}),
|
333 |
-
ord($var{$c + 3}),
|
334 |
-
ord($var{$c + 4}));
|
335 |
-
$c += 4;
|
336 |
-
$utf16 = $this->utf82utf16($char);
|
337 |
-
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
338 |
-
break;
|
339 |
-
|
340 |
-
case (($ord_var_c & 0xFE) == 0xFC):
|
341 |
-
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
|
342 |
-
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
343 |
-
$char = pack('C*', $ord_var_c,
|
344 |
-
ord($var{$c + 1}),
|
345 |
-
ord($var{$c + 2}),
|
346 |
-
ord($var{$c + 3}),
|
347 |
-
ord($var{$c + 4}),
|
348 |
-
ord($var{$c + 5}));
|
349 |
-
$c += 5;
|
350 |
-
$utf16 = $this->utf82utf16($char);
|
351 |
-
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
352 |
-
break;
|
353 |
-
}
|
354 |
-
}
|
355 |
-
|
356 |
-
return '"'.$ascii.'"';
|
357 |
-
|
358 |
-
case 'array':
|
359 |
-
/*
|
360 |
-
* As per JSON spec if any array key is not an integer
|
361 |
-
* we must treat the the whole array as an object. We
|
362 |
-
* also try to catch a sparsely populated associative
|
363 |
-
* array with numeric keys here because some JS engines
|
364 |
-
* will create an array with empty indexes up to
|
365 |
-
* max_index which can cause memory issues and because
|
366 |
-
* the keys, which may be relevant, will be remapped
|
367 |
-
* otherwise.
|
368 |
-
*
|
369 |
-
* As per the ECMA and JSON specification an object may
|
370 |
-
* have any string as a property. Unfortunately due to
|
371 |
-
* a hole in the ECMA specification if the key is a
|
372 |
-
* ECMA reserved word or starts with a digit the
|
373 |
-
* parameter is only accessible using ECMAScript's
|
374 |
-
* bracket notation.
|
375 |
-
*/
|
376 |
-
|
377 |
-
// treat as a JSON object
|
378 |
-
if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
|
379 |
-
$properties = array_map(array($this, 'name_value'),
|
380 |
-
array_keys($var),
|
381 |
-
array_values($var));
|
382 |
-
|
383 |
-
foreach($properties as $property) {
|
384 |
-
if(Services_JSON::isError($property)) {
|
385 |
-
return $property;
|
386 |
-
}
|
387 |
-
}
|
388 |
-
|
389 |
-
return '{' . join(',', $properties) . '}';
|
390 |
-
}
|
391 |
-
|
392 |
-
// treat it like a regular array
|
393 |
-
$elements = array_map(array($this, 'encode'), $var);
|
394 |
-
|
395 |
-
foreach($elements as $element) {
|
396 |
-
if(Services_JSON::isError($element)) {
|
397 |
-
return $element;
|
398 |
-
}
|
399 |
-
}
|
400 |
-
|
401 |
-
return '[' . join(',', $elements) . ']';
|
402 |
-
|
403 |
-
case 'object':
|
404 |
-
$vars = get_object_vars($var);
|
405 |
-
|
406 |
-
$properties = array_map(array($this, 'name_value'),
|
407 |
-
array_keys($vars),
|
408 |
-
array_values($vars));
|
409 |
-
|
410 |
-
foreach($properties as $property) {
|
411 |
-
if(Services_JSON::isError($property)) {
|
412 |
-
return $property;
|
413 |
-
}
|
414 |
-
}
|
415 |
-
|
416 |
-
return '{' . join(',', $properties) . '}';
|
417 |
-
|
418 |
-
default:
|
419 |
-
return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS)
|
420 |
-
? 'null'
|
421 |
-
: new Services_JSON_Error(gettype($var)." can not be encoded as JSON string");
|
422 |
-
}
|
423 |
-
}
|
424 |
-
|
425 |
-
/**
|
426 |
-
* array-walking function for use in generating JSON-formatted name-value pairs
|
427 |
-
*
|
428 |
-
* @param string $name name of key to use
|
429 |
-
* @param mixed $value reference to an array element to be encoded
|
430 |
-
*
|
431 |
-
* @return string JSON-formatted name-value pair, like '"name":value'
|
432 |
-
* @access private
|
433 |
-
*/
|
434 |
-
function name_value($name, $value)
|
435 |
-
{
|
436 |
-
$encoded_value = $this->encode($value);
|
437 |
-
|
438 |
-
if(Services_JSON::isError($encoded_value)) {
|
439 |
-
return $encoded_value;
|
440 |
-
}
|
441 |
-
|
442 |
-
return $this->encode(strval($name)) . ':' . $encoded_value;
|
443 |
-
}
|
444 |
-
|
445 |
-
/**
|
446 |
-
* reduce a string by removing leading and trailing comments and whitespace
|
447 |
-
*
|
448 |
-
* @param $str string string value to strip of comments and whitespace
|
449 |
-
*
|
450 |
-
* @return string string value stripped of comments and whitespace
|
451 |
-
* @access private
|
452 |
-
*/
|
453 |
-
function reduce_string($str)
|
454 |
-
{
|
455 |
-
$str = preg_replace(array(
|
456 |
-
|
457 |
-
// eliminate single line comments in '// ...' form
|
458 |
-
'#^\s*//(.+)$#m',
|
459 |
-
|
460 |
-
// eliminate multi-line comments in '/* ... */' form, at start of string
|
461 |
-
'#^\s*/\*(.+)\*/#Us',
|
462 |
-
|
463 |
-
// eliminate multi-line comments in '/* ... */' form, at end of string
|
464 |
-
'#/\*(.+)\*/\s*$#Us'
|
465 |
-
|
466 |
-
), '', $str);
|
467 |
-
|
468 |
-
// eliminate extraneous space
|
469 |
-
return trim($str);
|
470 |
-
}
|
471 |
-
|
472 |
-
/**
|
473 |
-
* decodes a JSON string into appropriate variable
|
474 |
-
*
|
475 |
-
* @param string $str JSON-formatted string
|
476 |
-
*
|
477 |
-
* @return mixed number, boolean, string, array, or object
|
478 |
-
* corresponding to given JSON input string.
|
479 |
-
* See argument 1 to Services_JSON() above for object-output behavior.
|
480 |
-
* Note that decode() always returns strings
|
481 |
-
* in ASCII or UTF-8 format!
|
482 |
-
* @access public
|
483 |
-
*/
|
484 |
-
function decode($str)
|
485 |
-
{
|
486 |
-
$str = $this->reduce_string($str);
|
487 |
-
|
488 |
-
switch (strtolower($str)) {
|
489 |
-
case 'true':
|
490 |
-
return true;
|
491 |
-
|
492 |
-
case 'false':
|
493 |
-
return false;
|
494 |
-
|
495 |
-
case 'null':
|
496 |
-
return null;
|
497 |
-
|
498 |
-
default:
|
499 |
-
$m = array();
|
500 |
-
|
501 |
-
if (is_numeric($str)) {
|
502 |
-
// Lookie-loo, it's a number
|
503 |
-
|
504 |
-
// This would work on its own, but I'm trying to be
|
505 |
-
// good about returning integers where appropriate:
|
506 |
-
// return (float)$str;
|
507 |
-
|
508 |
-
// Return float or int, as appropriate
|
509 |
-
return ((float)$str == (integer)$str)
|
510 |
-
? (integer)$str
|
511 |
-
: (float)$str;
|
512 |
-
|
513 |
-
} elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
|
514 |
-
// STRINGS RETURNED IN UTF-8 FORMAT
|
515 |
-
$delim = substr($str, 0, 1);
|
516 |
-
$chrs = substr($str, 1, -1);
|
517 |
-
$utf8 = '';
|
518 |
-
$strlen_chrs = strlen($chrs);
|
519 |
-
|
520 |
-
for ($c = 0; $c < $strlen_chrs; ++$c) {
|
521 |
-
|
522 |
-
$substr_chrs_c_2 = substr($chrs, $c, 2);
|
523 |
-
$ord_chrs_c = ord($chrs{$c});
|
524 |
-
|
525 |
-
switch (true) {
|
526 |
-
case $substr_chrs_c_2 == '\b':
|
527 |
-
$utf8 .= chr(0x08);
|
528 |
-
++$c;
|
529 |
-
break;
|
530 |
-
case $substr_chrs_c_2 == '\t':
|
531 |
-
$utf8 .= chr(0x09);
|
532 |
-
++$c;
|
533 |
-
break;
|
534 |
-
case $substr_chrs_c_2 == '\n':
|
535 |
-
$utf8 .= chr(0x0A);
|
536 |
-
++$c;
|
537 |
-
break;
|
538 |
-
case $substr_chrs_c_2 == '\f':
|
539 |
-
$utf8 .= chr(0x0C);
|
540 |
-
++$c;
|
541 |
-
break;
|
542 |
-
case $substr_chrs_c_2 == '\r':
|
543 |
-
$utf8 .= chr(0x0D);
|
544 |
-
++$c;
|
545 |
-
break;
|
546 |
-
|
547 |
-
case $substr_chrs_c_2 == '\\"':
|
548 |
-
case $substr_chrs_c_2 == '\\\'':
|
549 |
-
case $substr_chrs_c_2 == '\\\\':
|
550 |
-
case $substr_chrs_c_2 == '\\/':
|
551 |
-
if (($delim == '"' && $substr_chrs_c_2 != '\\\'') ||
|
552 |
-
($delim == "'" && $substr_chrs_c_2 != '\\"')) {
|
553 |
-
$utf8 .= $chrs{++$c};
|
554 |
-
}
|
555 |
-
break;
|
556 |
-
|
557 |
-
case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)):
|
558 |
-
// single, escaped unicode character
|
559 |
-
$utf16 = chr(hexdec(substr($chrs, ($c + 2), 2)))
|
560 |
-
. chr(hexdec(substr($chrs, ($c + 4), 2)));
|
561 |
-
$utf8 .= $this->utf162utf8($utf16);
|
562 |
-
$c += 5;
|
563 |
-
break;
|
564 |
-
|
565 |
-
case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F):
|
566 |
-
$utf8 .= $chrs{$c};
|
567 |
-
break;
|
568 |
-
|
569 |
-
case ($ord_chrs_c & 0xE0) == 0xC0:
|
570 |
-
// characters U-00000080 - U-000007FF, mask 110XXXXX
|
571 |
-
//see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
572 |
-
$utf8 .= substr($chrs, $c, 2);
|
573 |
-
++$c;
|
574 |
-
break;
|
575 |
-
|
576 |
-
case ($ord_chrs_c & 0xF0) == 0xE0:
|
577 |
-
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
|
578 |
-
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
579 |
-
$utf8 .= substr($chrs, $c, 3);
|
580 |
-
$c += 2;
|
581 |
-
break;
|
582 |
-
|
583 |
-
case ($ord_chrs_c & 0xF8) == 0xF0:
|
584 |
-
// characters U-00010000 - U-001FFFFF, mask 11110XXX
|
585 |
-
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
586 |
-
$utf8 .= substr($chrs, $c, 4);
|
587 |
-
$c += 3;
|
588 |
-
break;
|
589 |
-
|
590 |
-
case ($ord_chrs_c & 0xFC) == 0xF8:
|
591 |
-
// characters U-00200000 - U-03FFFFFF, mask 111110XX
|
592 |
-
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
593 |
-
$utf8 .= substr($chrs, $c, 5);
|
594 |
-
$c += 4;
|
595 |
-
break;
|
596 |
-
|
597 |
-
case ($ord_chrs_c & 0xFE) == 0xFC:
|
598 |
-
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
|
599 |
-
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
600 |
-
$utf8 .= substr($chrs, $c, 6);
|
601 |
-
$c += 5;
|
602 |
-
break;
|
603 |
-
|
604 |
-
}
|
605 |
-
|
606 |
-
}
|
607 |
-
|
608 |
-
return $utf8;
|
609 |
-
|
610 |
-
} elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
|
611 |
-
// array, or object notation
|
612 |
-
|
613 |
-
if ($str{0} == '[') {
|
614 |
-
$stk = array(SERVICES_JSON_IN_ARR);
|
615 |
-
$arr = array();
|
616 |
-
} else {
|
617 |
-
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
|
618 |
-
$stk = array(SERVICES_JSON_IN_OBJ);
|
619 |
-
$obj = array();
|
620 |
-
} else {
|
621 |
-
$stk = array(SERVICES_JSON_IN_OBJ);
|
622 |
-
$obj = new stdClass();
|
623 |
-
}
|
624 |
-
}
|
625 |
-
|
626 |
-
array_push($stk, array('what' => SERVICES_JSON_SLICE,
|
627 |
-
'where' => 0,
|
628 |
-
'delim' => false));
|
629 |
-
|
630 |
-
$chrs = substr($str, 1, -1);
|
631 |
-
$chrs = $this->reduce_string($chrs);
|
632 |
-
|
633 |
-
if ($chrs == '') {
|
634 |
-
if (reset($stk) == SERVICES_JSON_IN_ARR) {
|
635 |
-
return $arr;
|
636 |
-
|
637 |
-
} else {
|
638 |
-
return $obj;
|
639 |
-
|
640 |
-
}
|
641 |
-
}
|
642 |
-
|
643 |
-
//print("\nparsing {$chrs}\n");
|
644 |
-
|
645 |
-
$strlen_chrs = strlen($chrs);
|
646 |
-
|
647 |
-
for ($c = 0; $c <= $strlen_chrs; ++$c) {
|
648 |
-
|
649 |
-
$top = end($stk);
|
650 |
-
$substr_chrs_c_2 = substr($chrs, $c, 2);
|
651 |
-
|
652 |
-
if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) {
|
653 |
-
// found a comma that is not inside a string, array, etc.,
|
654 |
-
// OR we've reached the end of the character list
|
655 |
-
$slice = substr($chrs, $top['where'], ($c - $top['where']));
|
656 |
-
array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false));
|
657 |
-
//print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
658 |
-
|
659 |
-
if (reset($stk) == SERVICES_JSON_IN_ARR) {
|
660 |
-
// we are in an array, so just push an element onto the stack
|
661 |
-
array_push($arr, $this->decode($slice));
|
662 |
-
|
663 |
-
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
|
664 |
-
// we are in an object, so figure
|
665 |
-
// out the property name and set an
|
666 |
-
// element in an associative array,
|
667 |
-
// for now
|
668 |
-
$parts = array();
|
669 |
-
|
670 |
-
if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
|
671 |
-
// "name":value pair
|
672 |
-
$key = $this->decode($parts[1]);
|
673 |
-
$val = $this->decode($parts[2]);
|
674 |
-
|
675 |
-
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
|
676 |
-
$obj[$key] = $val;
|
677 |
-
} else {
|
678 |
-
$obj->$key = $val;
|
679 |
-
}
|
680 |
-
} elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
|
681 |
-
// name:value pair, where name is unquoted
|
682 |
-
$key = $parts[1];
|
683 |
-
$val = $this->decode($parts[2]);
|
684 |
-
|
685 |
-
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
|
686 |
-
$obj[$key] = $val;
|
687 |
-
} else {
|
688 |
-
$obj->$key = $val;
|
689 |
-
}
|
690 |
-
}
|
691 |
-
|
692 |
-
}
|
693 |
-
|
694 |
-
} elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) {
|
695 |
-
// found a quote, and we are not inside a string
|
696 |
-
array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}));
|
697 |
-
//print("Found start of string at {$c}\n");
|
698 |
-
|
699 |
-
} elseif (($chrs{$c} == $top['delim']) &&
|
700 |
-
($top['what'] == SERVICES_JSON_IN_STR) &&
|
701 |
-
((strlen(substr($chrs, 0, $c)) - strlen(rtrim(substr($chrs, 0, $c), '\\'))) % 2 != 1)) {
|
702 |
-
// found a quote, we're in a string, and it's not escaped
|
703 |
-
// we know that it's not escaped becase there is _not_ an
|
704 |
-
// odd number of backslashes at the end of the string so far
|
705 |
-
array_pop($stk);
|
706 |
-
//print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
|
707 |
-
|
708 |
-
} elseif (($chrs{$c} == '[') &&
|
709 |
-
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
|
710 |
-
// found a left-bracket, and we are in an array, object, or slice
|
711 |
-
array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false));
|
712 |
-
//print("Found start of array at {$c}\n");
|
713 |
-
|
714 |
-
} elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) {
|
715 |
-
// found a right-bracket, and we're in an array
|
716 |
-
array_pop($stk);
|
717 |
-
//print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
718 |
-
|
719 |
-
} elseif (($chrs{$c} == '{') &&
|
720 |
-
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
|
721 |
-
// found a left-brace, and we are in an array, object, or slice
|
722 |
-
array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false));
|
723 |
-
//print("Found start of object at {$c}\n");
|
724 |
-
|
725 |
-
} elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) {
|
726 |
-
// found a right-brace, and we're in an object
|
727 |
-
array_pop($stk);
|
728 |
-
//print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
729 |
-
|
730 |
-
} elseif (($substr_chrs_c_2 == '/*') &&
|
731 |
-
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
|
732 |
-
// found a comment start, and we are in an array, object, or slice
|
733 |
-
array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false));
|
734 |
-
$c++;
|
735 |
-
//print("Found start of comment at {$c}\n");
|
736 |
-
|
737 |
-
} elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) {
|
738 |
-
// found a comment end, and we're in one now
|
739 |
-
array_pop($stk);
|
740 |
-
$c++;
|
741 |
-
|
742 |
-
for ($i = $top['where']; $i <= $c; ++$i)
|
743 |
-
$chrs = substr_replace($chrs, ' ', $i, 1);
|
744 |
-
|
745 |
-
//print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
746 |
-
|
747 |
-
}
|
748 |
-
|
749 |
-
}
|
750 |
-
|
751 |
-
if (reset($stk) == SERVICES_JSON_IN_ARR) {
|
752 |
-
return $arr;
|
753 |
-
|
754 |
-
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
|
755 |
-
return $obj;
|
756 |
-
|
757 |
-
}
|
758 |
-
|
759 |
-
}
|
760 |
-
}
|
761 |
-
}
|
762 |
-
|
763 |
-
/**
|
764 |
-
* @todo Ultimately, this should just call PEAR::isError()
|
765 |
-
*/
|
766 |
-
function isError($data, $code = null)
|
767 |
-
{
|
768 |
-
if (class_exists('pear')) {
|
769 |
-
return PEAR::isError($data, $code);
|
770 |
-
} elseif (is_object($data) && (get_class($data) == 'services_json_error' ||
|
771 |
-
is_subclass_of($data, 'services_json_error'))) {
|
772 |
-
return true;
|
773 |
-
}
|
774 |
-
|
775 |
-
return false;
|
776 |
-
}
|
777 |
-
}
|
778 |
-
|
779 |
-
if (class_exists('PEAR_Error')) {
|
780 |
-
|
781 |
-
class Services_JSON_Error extends PEAR_Error
|
782 |
-
{
|
783 |
-
function Services_JSON_Error($message = 'unknown error', $code = null,
|
784 |
-
$mode = null, $options = null, $userinfo = null)
|
785 |
-
{
|
786 |
-
parent::PEAR_Error($message, $code, $mode, $options, $userinfo);
|
787 |
-
}
|
788 |
-
}
|
789 |
-
|
790 |
-
} else {
|
791 |
-
|
792 |
-
/**
|
793 |
-
* @todo Ultimately, this class shall be descended from PEAR_Error
|
794 |
-
*/
|
795 |
-
class Services_JSON_Error
|
796 |
-
{
|
797 |
-
function Services_JSON_Error($message = 'unknown error', $code = null,
|
798 |
-
$mode = null, $options = null, $userinfo = null)
|
799 |
-
{
|
800 |
-
|
801 |
-
}
|
802 |
-
}
|
803 |
-
|
804 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inc/cleantalk-admin.php
CHANGED
@@ -10,26 +10,25 @@ $ct_ip_penalty_days = 30;
|
|
10 |
add_filter( 'activity_box_end', 'cleantalk_custom_glance_items', 10, 1 );
|
11 |
function cleantalk_custom_glance_items( )
|
12 |
{
|
13 |
-
global $ct_data;
|
14 |
$ct_data=ct_get_data();
|
15 |
-
|
16 |
-
{
|
17 |
-
$
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
print "</span></div>";
|
33 |
}
|
34 |
}
|
35 |
|
@@ -511,12 +510,11 @@ function ct_add_admin_menu( $wp_admin_bar ) {
|
|
511 |
//Previous version $daily_counter_str='<span style="color: white;" title="'.__('All / Allowed / Blocked submissions. The number of submissions for past 24 hours. ', 'cleantalk').'"><span style="color: white;"> | Day: ' .$daily_counter['all']. '</span> / <span style="color: green;">' .$daily_counter['accepted']. '</span> / <span style="color: red;">' .$daily_counter['blocked']. '</span></span>';
|
512 |
$daily_counter_str='<span style="color: white;" title="'.__('Allowed / Blocked submissions. The number of submissions for past 24 hours. ', 'cleantalk').'"><span style="color: white;"> | Day: </span><span style="color: green;">' .$daily_counter['accepted']. '</span> / <span style="color: red;">' .$daily_counter['blocked']. '</span></span>';
|
513 |
}
|
514 |
-
|
515 |
$sfw_counter_str='';
|
516 |
//Don't compile if SFW counter disabled
|
517 |
-
if(isset($ct_options['sfw_counter']) && $ct_options['sfw_counter']==
|
518 |
$sfw_counter=Array('all'=>$ct_data['sfw_counter']['all'], 'blocked'=>$ct_data['sfw_counter']['blocked']);
|
519 |
-
$sfw_counter_str='<span style="color: white;" title="'.__('All / Blocked events. Access attempts
|
520 |
}
|
521 |
|
522 |
$args = array(
|
10 |
add_filter( 'activity_box_end', 'cleantalk_custom_glance_items', 10, 1 );
|
11 |
function cleantalk_custom_glance_items( )
|
12 |
{
|
13 |
+
global $ct_data, $current_user;
|
14 |
$ct_data=ct_get_data();
|
15 |
+
|
16 |
+
if(isset($current_user) && in_array("administrator", $current_user->roles)){
|
17 |
+
if(!isset($ct_data['admin_blocked'])){
|
18 |
+
$blocked=0;
|
19 |
+
}else{
|
20 |
+
$blocked=$ct_data['admin_blocked'];
|
21 |
+
}
|
22 |
+
if($blocked>0){
|
23 |
+
$blocked = number_format($blocked, 0, ',', ' ');
|
24 |
+
print "<div style='height:24px;width:100%;display:table-cell; vertical-align:middle;'><img src='" . plugin_dir_url(__FILE__) . "images/logo_color.png' style='margin-right:1em;vertical-align:middle;'/><span><a href='https://cleantalk.org/my/?user_token=".@$ct_data['user_token']."&utm_source=wp-backend&utm_medium=dashboard_widget' target='_blank'>CleanTalk</a> ";
|
25 |
+
printf(
|
26 |
+
/* translators: %s: Number of spam messages */
|
27 |
+
__( 'has blocked %s spam', 'cleantalk' ),
|
28 |
+
$blocked
|
29 |
+
);
|
30 |
+
print "</span></div>";
|
31 |
+
}
|
|
|
32 |
}
|
33 |
}
|
34 |
|
510 |
//Previous version $daily_counter_str='<span style="color: white;" title="'.__('All / Allowed / Blocked submissions. The number of submissions for past 24 hours. ', 'cleantalk').'"><span style="color: white;"> | Day: ' .$daily_counter['all']. '</span> / <span style="color: green;">' .$daily_counter['accepted']. '</span> / <span style="color: red;">' .$daily_counter['blocked']. '</span></span>';
|
511 |
$daily_counter_str='<span style="color: white;" title="'.__('Allowed / Blocked submissions. The number of submissions for past 24 hours. ', 'cleantalk').'"><span style="color: white;"> | Day: </span><span style="color: green;">' .$daily_counter['accepted']. '</span> / <span style="color: red;">' .$daily_counter['blocked']. '</span></span>';
|
512 |
}
|
|
|
513 |
$sfw_counter_str='';
|
514 |
//Don't compile if SFW counter disabled
|
515 |
+
if(isset($ct_options['sfw_counter']) && intval($ct_options['sfw_counter']) == 1 && isset($ct_options['spam_firewall']) && intval($ct_options['spam_firewall']) == 1){
|
516 |
$sfw_counter=Array('all'=>$ct_data['sfw_counter']['all'], 'blocked'=>$ct_data['sfw_counter']['blocked']);
|
517 |
+
$sfw_counter_str='<span style="color: white;" title="'.__('All / Blocked events. Access attempts regitred by SpamFireWall counted since the last plugin activation.', 'cleantalk').'"><span style="color: white;"> | SpamFireWall: ' .$sfw_counter['all']. '</span> / <span style="color: red;">' .$sfw_counter['blocked']. '</span></span>';
|
518 |
}
|
519 |
|
520 |
$args = array(
|
inc/cleantalk-comments.php
CHANGED
@@ -263,17 +263,19 @@ function ct_add_checkspam_button()
|
|
263 |
var spambutton_text='<?php _e("Find spam comments", 'cleantalk'); ?>';
|
264 |
</script>
|
265 |
<?php
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
|
|
|
|
277 |
}
|
278 |
|
279 |
|
263 |
var spambutton_text='<?php _e("Find spam comments", 'cleantalk'); ?>';
|
264 |
</script>
|
265 |
<?php
|
266 |
+
if(isset($screen) && count($screen)){
|
267 |
+
if( $screen->id == 'edit-comments' ){
|
268 |
+
?>
|
269 |
+
<script src="<?php print plugins_url( 'cleantalk-comments-editscreen.js', __FILE__ ); ?>"></script>
|
270 |
+
<?php
|
271 |
+
}
|
272 |
+
if($screen->id == 'comments_page_ct_check_spam')
|
273 |
+
{
|
274 |
+
?>
|
275 |
+
<script src="<?php print plugins_url( 'cleantalk-comments-checkspam.js', __FILE__ ); ?>"></script>
|
276 |
+
<?php
|
277 |
+
}
|
278 |
+
}
|
279 |
}
|
280 |
|
281 |
|
inc/cleantalk-common.php
CHANGED
@@ -690,90 +690,11 @@ function delete_spam_comments() {
|
|
690 |
return null;
|
691 |
}
|
692 |
|
693 |
-
/*
|
694 |
-
* Get data from submit recursively
|
695 |
-
*/
|
696 |
-
/* Old one
|
697 |
-
function ct_get_fields_any(&$email,&$message,&$nickname,&$subject, &$contact,$arr)
|
698 |
-
{
|
699 |
-
$skip_params = array(
|
700 |
-
'ipn_track_id', // PayPal IPN #
|
701 |
-
'txn_type', // PayPal transaction type
|
702 |
-
'payment_status', // PayPal payment status
|
703 |
-
'ccbill_ipn' //CCBill IPN
|
704 |
-
);
|
705 |
-
$obfuscate_params = array(
|
706 |
-
'password',
|
707 |
-
'password0',
|
708 |
-
'password1',
|
709 |
-
'password2',
|
710 |
-
'pass',
|
711 |
-
'pwd',
|
712 |
-
'user_pass'
|
713 |
-
);
|
714 |
-
foreach($skip_params as $key=>$value)
|
715 |
-
{
|
716 |
-
if(@array_key_exists($value,$_GET)||@array_key_exists($value,$_POST))
|
717 |
-
{
|
718 |
-
$contact = false;
|
719 |
-
}
|
720 |
-
}
|
721 |
-
foreach($arr as $key=>$value)
|
722 |
-
{
|
723 |
-
if(!is_array($value)&&!is_object($value)&&@get_class($value)!='WP_User')
|
724 |
-
{
|
725 |
-
if (in_array($key, $skip_params) && $key!=0 && $key!='' || preg_match("/^ct_checkjs/", $key)) {
|
726 |
-
$contact = false;
|
727 |
-
}
|
728 |
-
if (!$email && @preg_match("/^\S+@\S+\.\S+$/", $value))
|
729 |
-
{
|
730 |
-
$email = $value;
|
731 |
-
}
|
732 |
-
else if ($nickname === '' && ct_get_data_from_submit($key, 'name'))
|
733 |
-
{
|
734 |
-
$nickname = $value;
|
735 |
-
}
|
736 |
-
else if ($subject === '' && ct_get_data_from_submit($key, 'subject'))
|
737 |
-
{
|
738 |
-
$subject = $value;
|
739 |
-
}
|
740 |
-
else
|
741 |
-
{
|
742 |
-
//
|
743 |
-
// Obfuscate private data
|
744 |
-
//
|
745 |
-
if (in_array($key, $obfuscate_params)) {
|
746 |
-
$value = ct_obfuscate_param($value);
|
747 |
-
}
|
748 |
-
$message[$key] = $value;
|
749 |
-
}
|
750 |
-
}
|
751 |
-
else if(!is_object($value)&&@get_class($value)!='WP_User')
|
752 |
-
{
|
753 |
-
@ct_get_fields_any($email, $message, $nickname, $subject, $contact, $value);
|
754 |
-
}
|
755 |
-
}
|
756 |
-
//
|
757 |
-
// Reset $message if we have a sign-up data
|
758 |
-
//
|
759 |
-
$skip_message_post = array(
|
760 |
-
'edd_action', // Easy Digital Downloads
|
761 |
-
);
|
762 |
-
foreach ($skip_message_post as $v) {
|
763 |
-
if (isset($_POST[$v])) {
|
764 |
-
$message = null;
|
765 |
-
break;
|
766 |
-
}
|
767 |
-
}
|
768 |
-
}
|
769 |
-
//*/
|
770 |
-
|
771 |
/*
|
772 |
* Get data from an ARRAY recursively
|
773 |
* @return array
|
774 |
-
* New one
|
775 |
*/
|
776 |
-
function ct_get_fields_any($arr, $message=array(), $email=
|
777 |
$skip_params = array(
|
778 |
'ipn_track_id', // PayPal IPN #
|
779 |
'txn_type', // PayPal transaction type
|
@@ -790,47 +711,61 @@ function ct_get_fields_any($arr, $message=array(), $email=NULL, $nickname=NULL,
|
|
790 |
'pwd',
|
791 |
'user_pass'
|
792 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
793 |
foreach($skip_params as $key=>$value){
|
794 |
if(@array_key_exists($value,$_GET)||@array_key_exists($value,$_POST))
|
795 |
$contact = false;
|
796 |
}
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
if($value
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
$
|
806 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
807 |
}
|
808 |
-
|
809 |
-
$value = strip_shortcodes($value);
|
810 |
-
|
811 |
-
if (in_array($key, $skip_params) && $key!=0 && $key!='' || preg_match("/^ct_checkjs/", $key))
|
812 |
-
$contact = false;
|
813 |
-
|
814 |
-
if (!$email && @preg_match("/^\S+@\S+\.\S+$/", $value)){
|
815 |
-
$email = $value;
|
816 |
-
}elseif ($nickname === '' && ct_get_data_from_submit($key, 'name')){
|
817 |
-
$nickname .= " ".$value;
|
818 |
-
}elseif ($subject === '' && ct_get_data_from_submit($key, 'subject')){
|
819 |
-
$subject = $value;
|
820 |
-
}else{
|
821 |
-
$message[$key] = $value;
|
822 |
-
}
|
823 |
-
}
|
824 |
-
else if(!is_object($value)&&@get_class($value)!='WP_User'){
|
825 |
-
|
826 |
-
$temp = ct_get_fields_any($value);
|
827 |
-
|
828 |
-
$email = ($temp['email'] ? $temp['email'] : '');
|
829 |
-
$nickname = ($temp['nickname'] ? $temp['nickname'] : '');
|
830 |
-
$subject = ($temp['subject'] ? $temp['subject'] : '');
|
831 |
-
$contact = ($temp['contact'] ? $temp['contact'] : '');
|
832 |
-
$message = (count($temp['message']) == 0 ? $message : array_merge($message, $temp['message']));
|
833 |
-
}
|
834 |
}
|
835 |
// Reset $message if we have a sign-up data
|
836 |
$skip_message_post = array(
|
@@ -841,7 +776,7 @@ function ct_get_fields_any($arr, $message=array(), $email=NULL, $nickname=NULL,
|
|
841 |
$message = null;
|
842 |
break;
|
843 |
}
|
844 |
-
}
|
845 |
|
846 |
$return_param = array(
|
847 |
'email' => $email,
|
690 |
return null;
|
691 |
}
|
692 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
693 |
/*
|
694 |
* Get data from an ARRAY recursively
|
695 |
* @return array
|
|
|
696 |
*/
|
697 |
+
function ct_get_fields_any($arr, $message=array(), $email=null, $nickname=null, $subject=null, $contact=true) {
|
698 |
$skip_params = array(
|
699 |
'ipn_track_id', // PayPal IPN #
|
700 |
'txn_type', // PayPal transaction type
|
711 |
'pwd',
|
712 |
'user_pass'
|
713 |
);
|
714 |
+
$skip_fields_params = array(
|
715 |
+
'form_id',
|
716 |
+
'form_nonce',
|
717 |
+
'ccf_form',
|
718 |
+
'form_page',
|
719 |
+
'form_nonce'
|
720 |
+
);
|
721 |
foreach($skip_params as $key=>$value){
|
722 |
if(@array_key_exists($value,$_GET)||@array_key_exists($value,$_POST))
|
723 |
$contact = false;
|
724 |
}
|
725 |
+
//*/
|
726 |
+
if(count($arr)){
|
727 |
+
foreach($arr as $key=>$value){
|
728 |
+
if(!is_array($value) && !is_object($value) && @get_class($value)!='WP_User'){
|
729 |
+
// Skip empty or work fields
|
730 |
+
if($value==='' || in_array($key, $skip_fields_params))
|
731 |
+
continue;
|
732 |
+
// Obfuscate private data
|
733 |
+
if (in_array($key, $obfuscate_params)){
|
734 |
+
$value = ct_obfuscate_param($value);
|
735 |
+
$message[$key] = $value;
|
736 |
+
continue;
|
737 |
+
}
|
738 |
+
|
739 |
+
// Removes shortcodes to do better spam filtration on server side.
|
740 |
+
$value = strip_shortcodes($value);
|
741 |
+
|
742 |
+
if (in_array($key, $skip_params) && $key!=0 && $key!='' || preg_match("/^ct_checkjs/", $key))
|
743 |
+
$contact = false;
|
744 |
+
//*/
|
745 |
+
if (!$email && @preg_match("/^\S+@\S+\.\S+$/", $value)){
|
746 |
+
$email = $value;
|
747 |
+
}elseif ($nickname === null && ct_get_data_from_submit($key, 'name')){
|
748 |
+
$nickname .= " ".$value;
|
749 |
+
}elseif ($subject === null && ct_get_data_from_submit($key, 'subject')){
|
750 |
+
$subject = $value;
|
751 |
+
}else{
|
752 |
+
if(isset($message[$key]))
|
753 |
+
$message[$key.'_2'] = $value;
|
754 |
+
else
|
755 |
+
$message[$key] = $value;
|
756 |
+
}
|
757 |
+
}else if(!is_object($value)&&@get_class($value)!='WP_User'){
|
758 |
+
|
759 |
+
$temp = ct_get_fields_any($value, $message, $email, $nickname, $subject, $contact);
|
760 |
+
|
761 |
+
$email = ($temp['email'] ? $temp['email'] : null);
|
762 |
+
$nickname = ($temp['nickname'] ? $temp['nickname'] : null);
|
763 |
+
$subject = ($temp['subject'] ? $temp['subject'] : null);
|
764 |
+
if($contact===true)
|
765 |
+
$contact = ($temp['contact']===false ? false : true);
|
766 |
+
$message = $temp['message'];
|
767 |
}
|
768 |
+
} unset($key, $value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
769 |
}
|
770 |
// Reset $message if we have a sign-up data
|
771 |
$skip_message_post = array(
|
776 |
$message = null;
|
777 |
break;
|
778 |
}
|
779 |
+
} unset($v);
|
780 |
|
781 |
$return_param = array(
|
782 |
'email' => $email,
|
inc/cleantalk-public.php
CHANGED
@@ -147,6 +147,11 @@ function ct_init() {
|
|
147 |
add_action('bbp_theme_before_reply_form_content', 'ct_comment_form');
|
148 |
}
|
149 |
|
|
|
|
|
|
|
|
|
|
|
150 |
add_action('comment_form', 'ct_comment_form');
|
151 |
|
152 |
//intercept WordPress Landing Pages POST
|
@@ -179,6 +184,14 @@ function ct_init() {
|
|
179 |
add_filter('gform_entry_is_spam', 'ct_gforms_spam_test', 1, 3);
|
180 |
}
|
181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
//
|
183 |
// Load JS code to website footer
|
184 |
//
|
@@ -206,6 +219,99 @@ function ct_init() {
|
|
206 |
}
|
207 |
}
|
208 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
function ct_woocommerce_wishlist_check($args){
|
210 |
global $ct_options;
|
211 |
|
@@ -354,6 +460,67 @@ function ct_bp_private_msg_check( $bp_message_obj){
|
|
354 |
wp_die("<h1>Spam Protection by CleanTalk</h1><h2>".$ct_result->comment."</h2>", '', array('response' => 403, "back_link" => true, "text_direction" => 'ltr'));
|
355 |
}
|
356 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
357 |
/**
|
358 |
* Does actions to prepare anti-spam tests.
|
359 |
* @return bool;
|
@@ -2066,7 +2233,8 @@ function ct_contact_form_validate () {
|
|
2066 |
(isset($_POST['_wpcf7']) && isset($_POST['_wpcf7_version']) && isset($_POST['_wpcf7_locale'])) || //CF7 fix)
|
2067 |
(isset($_POST['hash']) && isset($_POST['device_unique_id']) && isset($_POST['device_name'])) ||//Mobile Assistant Connector fix
|
2068 |
isset($_POST['gform_submit']) || //Gravity form
|
2069 |
-
(isset($_POST['wc_reset_password']) && isset($_POST['_wpnonce']) && isset($_POST['_wp_http_referer'])) //WooCommerce recovery password form
|
|
|
2070 |
) {
|
2071 |
return null;
|
2072 |
}
|
147 |
add_action('bbp_theme_before_reply_form_content', 'ct_comment_form');
|
148 |
}
|
149 |
|
150 |
+
//Custom Contact Forms
|
151 |
+
if(defined('CCF_VERSION')){
|
152 |
+
add_filter('ccf_field_validator', 'ct_ccf', 1, 4);
|
153 |
+
}
|
154 |
+
|
155 |
add_action('comment_form', 'ct_comment_form');
|
156 |
|
157 |
//intercept WordPress Landing Pages POST
|
184 |
add_filter('gform_entry_is_spam', 'ct_gforms_spam_test', 1, 3);
|
185 |
}
|
186 |
|
187 |
+
//
|
188 |
+
//Pirate forms
|
189 |
+
//
|
190 |
+
if(defined('PIRATE_FORMS_VERSION')){
|
191 |
+
if(isset($_POST['pirate-forms-contact-name']) && $_POST['pirate-forms-contact-name'] && isset($_POST['pirate-forms-contact-email']) && $_POST['pirate-forms-contact-email'])
|
192 |
+
ct_pirate_forms_check();
|
193 |
+
}
|
194 |
+
|
195 |
//
|
196 |
// Load JS code to website footer
|
197 |
//
|
219 |
}
|
220 |
}
|
221 |
|
222 |
+
/*
|
223 |
+
* Function to set validate fucntion for CCF form
|
224 |
+
* Input - Сonsistently each form field
|
225 |
+
* Returns - String. Validate function
|
226 |
+
*/
|
227 |
+
function ct_ccf($callback, $value, $field_id, $type){
|
228 |
+
/*
|
229 |
+
if($type == 'name')
|
230 |
+
$ct_global_temporary_data['name'] = $value;
|
231 |
+
elseif($type == 'email')
|
232 |
+
$ct_global_temporary_data['email'] = $value;
|
233 |
+
else
|
234 |
+
$ct_global_temporary_data[] = $value;
|
235 |
+
//*/
|
236 |
+
return 'ct_validate_ccf_submission';
|
237 |
+
}
|
238 |
+
/*
|
239 |
+
* Validate function for CCF form. Gatheering data. Multiple calls.
|
240 |
+
* Input - void. Global $ct_global_temporary_data
|
241 |
+
* Returns - String. CleanTalk comment.
|
242 |
+
*/
|
243 |
+
$ct_global_temporary_data = array();
|
244 |
+
function ct_validate_ccf_submission($value, $field_id, $required){
|
245 |
+
global $ct_global_temporary_data, $ct_options;
|
246 |
+
|
247 |
+
$ct_options = ct_get_options();
|
248 |
+
|
249 |
+
//If the check for contact forms enabled
|
250 |
+
if(isset($ct_options['contact_forms_test']) && intval($ct_options['contact_forms_test']) == '0')
|
251 |
+
return true;
|
252 |
+
//If the check for logged in users enabled
|
253 |
+
if(isset($ct_options['protect_logged_in']) && intval($ct_options['protect_logged_in']) == 1 && is_user_logged_in())
|
254 |
+
return true;
|
255 |
+
|
256 |
+
//Accumulate data
|
257 |
+
$ct_global_temporary_data[] = $value;
|
258 |
+
|
259 |
+
//If it's the last field of the form
|
260 |
+
(!isset($ct_global_temporary_data['count']) ? $ct_global_temporary_data['count'] = 1 : $ct_global_temporary_data['count']++);
|
261 |
+
$form_id = $_POST['form_id'];
|
262 |
+
if($ct_global_temporary_data['count'] != count(get_post_meta( $form_id, 'ccf_attached_fields', true )))
|
263 |
+
return true;
|
264 |
+
unset($ct_global_temporary_data['count']);
|
265 |
+
|
266 |
+
//Getting request params
|
267 |
+
$ct_temp_msg_data = ct_get_fields_any($_POST);
|
268 |
+
|
269 |
+
unset($ct_global_temporary_data);
|
270 |
+
|
271 |
+
$sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
|
272 |
+
$sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
|
273 |
+
$subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
|
274 |
+
$contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
|
275 |
+
$message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
|
276 |
+
|
277 |
+
if ($subject != '')
|
278 |
+
$message = array_merge(array('subject' => $subject), $message);
|
279 |
+
$message = json_encode($message);
|
280 |
+
|
281 |
+
$post_info['comment_type'] = 'feedback_custom_contact_forms';
|
282 |
+
$post_info['post_url'] = $_SERVER['HTTP_REFERER'];
|
283 |
+
$post_info = json_encode($post_info);
|
284 |
+
if ($post_info === false)
|
285 |
+
$post_info = '';
|
286 |
+
|
287 |
+
$checkjs = js_test('ct_checkjs', $_COOKIE, true);
|
288 |
+
if ($checkjs === null)
|
289 |
+
$checkjs = js_test('ct_checkjs', $_POST, true);
|
290 |
+
|
291 |
+
$sender_info = array(
|
292 |
+
'sender_url' => null
|
293 |
+
);
|
294 |
+
|
295 |
+
//Making a call
|
296 |
+
$ct_base_call_result = ct_base_call(array(
|
297 |
+
'message' => $subject." ".$message,
|
298 |
+
'example' => null,
|
299 |
+
'sender_email' => $sender_email,
|
300 |
+
'sender_nickname' => $sender_nickname,
|
301 |
+
'post_info' => $post_info,
|
302 |
+
'checkjs' => $checkjs,
|
303 |
+
'sender_info' => $sender_info
|
304 |
+
));
|
305 |
+
|
306 |
+
$ct = $ct_base_call_result['ct'];
|
307 |
+
$ct_result = $ct_base_call_result['ct_result'];
|
308 |
+
|
309 |
+
if ($ct_result->allow == 0)
|
310 |
+
return $ct_result->comment;
|
311 |
+
else
|
312 |
+
return true;
|
313 |
+
}
|
314 |
+
|
315 |
function ct_woocommerce_wishlist_check($args){
|
316 |
global $ct_options;
|
317 |
|
460 |
wp_die("<h1>Spam Protection by CleanTalk</h1><h2>".$ct_result->comment."</h2>", '', array('response' => 403, "back_link" => true, "text_direction" => 'ltr'));
|
461 |
}
|
462 |
|
463 |
+
/**
|
464 |
+
* Public function - Tests for Pirate contact froms
|
465 |
+
* return NULL
|
466 |
+
*/
|
467 |
+
function ct_pirate_forms_check(){
|
468 |
+
global $ct_options;
|
469 |
+
|
470 |
+
$ct_options = ct_get_options();
|
471 |
+
|
472 |
+
//Check for enabled option
|
473 |
+
if($ct_options['contact_forms_test'] == 0)
|
474 |
+
return;
|
475 |
+
|
476 |
+
$ct_temp_msg_data = ct_get_fields_any($_POST);
|
477 |
+
|
478 |
+
//Getting request params
|
479 |
+
|
480 |
+
$ct_temp_msg_data = ct_get_fields_any($_POST);
|
481 |
+
|
482 |
+
$sender_email = ($ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '');
|
483 |
+
$sender_nickname = ($ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '');
|
484 |
+
$subject = ($ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '');
|
485 |
+
$contact_form = ($ct_temp_msg_data['contact'] ? $ct_temp_msg_data['contact'] : true);
|
486 |
+
$message = ($ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : array());
|
487 |
+
|
488 |
+
if($subject != '')
|
489 |
+
$message = array_merge(array('subject' => $subject), $message);
|
490 |
+
|
491 |
+
$message = json_encode($message);
|
492 |
+
|
493 |
+
$post_info['comment_type'] = 'feedback_pirate_contact_form';
|
494 |
+
$post_info['post_url'] = $_SERVER['HTTP_REFERER'];
|
495 |
+
$post_info = json_encode($post_info);
|
496 |
+
if ($post_info === false)
|
497 |
+
$post_info = '';
|
498 |
+
|
499 |
+
$checkjs = js_test('ct_checkjs', $_COOKIE, true);
|
500 |
+
|
501 |
+
$sender_info = array(
|
502 |
+
'sender_url' => null
|
503 |
+
);
|
504 |
+
|
505 |
+
//Making a call
|
506 |
+
|
507 |
+
$ct_base_call_result = ct_base_call(array(
|
508 |
+
'message' => $message,
|
509 |
+
'example' => null,
|
510 |
+
'sender_email' => $sender_email,
|
511 |
+
'sender_nickname' => $sender_nickname,
|
512 |
+
'post_info' => $post_info,
|
513 |
+
'checkjs' => $checkjs,
|
514 |
+
'sender_info' => $sender_info
|
515 |
+
));
|
516 |
+
|
517 |
+
$ct = $ct_base_call_result['ct'];
|
518 |
+
$ct_result = $ct_base_call_result['ct_result'];
|
519 |
+
|
520 |
+
if ($ct_result->stop_queue == 1 || $ct_result->spam == 1 || $ct_result->allow == 0)
|
521 |
+
wp_die("<h1>Spam Protection by CleanTalk</h1><h2>".$ct_result->comment."</h2>", '', array('response' => 403, "back_link" => true, "text_direction" => 'ltr'));
|
522 |
+
}
|
523 |
+
|
524 |
/**
|
525 |
* Does actions to prepare anti-spam tests.
|
526 |
* @return bool;
|
2233 |
(isset($_POST['_wpcf7']) && isset($_POST['_wpcf7_version']) && isset($_POST['_wpcf7_locale'])) || //CF7 fix)
|
2234 |
(isset($_POST['hash']) && isset($_POST['device_unique_id']) && isset($_POST['device_name'])) ||//Mobile Assistant Connector fix
|
2235 |
isset($_POST['gform_submit']) || //Gravity form
|
2236 |
+
(isset($_POST['wc_reset_password']) && isset($_POST['_wpnonce']) && isset($_POST['_wp_http_referer'])) || //WooCommerce recovery password form
|
2237 |
+
(isset($_POST['ccf_form']) && intval($_POST['ccf_form']) == 1)
|
2238 |
) {
|
2239 |
return null;
|
2240 |
}
|
inc/cleantalk-users.php
CHANGED
@@ -174,7 +174,8 @@ $cnt_spam1=$r[0]['cnt'];
|
|
174 |
<button class="button" id="ct_delete_checked_users"><?php _e('Delete selected', 'cleantalk'); ?></button>
|
175 |
<?php
|
176 |
}
|
177 |
-
if($_SERVER['REMOTE_ADDR']=='127.0.0.1')print '<button class="button" id="ct_insert_users">Insert accounts</button><br />';
|
|
|
178 |
?>
|
179 |
</div>
|
180 |
<br /><br />
|
@@ -220,17 +221,19 @@ function ct_add_users_button()
|
|
220 |
var spambutton_users_text='<?php _e("Find spam users", 'cleantalk'); ?>';
|
221 |
</script>
|
222 |
<?php
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
|
|
|
|
234 |
}
|
235 |
|
236 |
|
174 |
<button class="button" id="ct_delete_checked_users"><?php _e('Delete selected', 'cleantalk'); ?></button>
|
175 |
<?php
|
176 |
}
|
177 |
+
if($_SERVER['REMOTE_ADDR']=='127.0.0.1')print '<button class="button" id="ct_insert_users">Insert accounts</button><br />';
|
178 |
+
|
179 |
?>
|
180 |
</div>
|
181 |
<br /><br />
|
221 |
var spambutton_users_text='<?php _e("Find spam users", 'cleantalk'); ?>';
|
222 |
</script>
|
223 |
<?php
|
224 |
+
if(isset($screen) && count($screen)){
|
225 |
+
if( $screen->id == 'users' ){
|
226 |
+
?>
|
227 |
+
<script src="<?php print plugins_url( 'cleantalk-users-editscreen.js?v=' . $cleantalk_plugin_version, __FILE__ ); ?>"></script>
|
228 |
+
<?php
|
229 |
+
}
|
230 |
+
if($screen->id == 'users_page_ct_check_users')
|
231 |
+
{
|
232 |
+
?>
|
233 |
+
<script src="<?php print plugins_url( 'cleantalk-users-checkspam.js?v=' . $cleantalk_plugin_version, __FILE__ ); ?>"></script>
|
234 |
+
<?php
|
235 |
+
}
|
236 |
+
}
|
237 |
}
|
238 |
|
239 |
|
inc/cleantalk.class.php
CHANGED
@@ -37,27 +37,6 @@ if( !function_exists('apache_request_headers') ) {
|
|
37 |
}
|
38 |
}
|
39 |
|
40 |
-
/**
|
41 |
-
* Load JSON functions if they are not exists
|
42 |
-
*/
|
43 |
-
if(!function_exists('json_encode')) {
|
44 |
-
require_once 'JSON.php';
|
45 |
-
|
46 |
-
function json_encode($data) {
|
47 |
-
$json = new Services_JSON();
|
48 |
-
return( $json->encode($data) );
|
49 |
-
}
|
50 |
-
|
51 |
-
}
|
52 |
-
if(!function_exists('json_decode')) {
|
53 |
-
require_once 'JSON.php';
|
54 |
-
|
55 |
-
function json_decode($data) {
|
56 |
-
$json = new Services_JSON();
|
57 |
-
return( $json->decode($data) );
|
58 |
-
}
|
59 |
-
}
|
60 |
-
|
61 |
/**
|
62 |
* Response class
|
63 |
*/
|
37 |
}
|
38 |
}
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
/**
|
41 |
* Response class
|
42 |
*/
|
inc/cleantalk_api.php
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
<?php
|
2 |
require_once("cleantalk.class.php");
|
3 |
-
require_once("JSON.php");
|
4 |
|
5 |
|
6 |
/**
|
1 |
<?php
|
2 |
require_once("cleantalk.class.php");
|
|
|
3 |
|
4 |
|
5 |
/**
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: znaeff, shagimuratov, serge00
|
|
3 |
Tags: spam, anti-spam, antispam, anti spam, bbpress, buddypress, captcha, capcha, captha, catcha, cf7 spam, comments, contact form spam, signup, spammers, spammy, woocommerce, wordpress spam, subscription, gravity spam, jetpack, bots, contact form 7, contact form, registrations, ninja, Fast Secure Contact, Gravity forms, formidable, mailchimp, s2member, protection, protect, email, plugin, contact, recaptcha, google captcha, google recaptcha, blacklist, prevent spam comments, wordpress, User Frontend, bulk delete, bulk remove, widget, review, firewall, cleantalk, mailpoet, profile builder, comment spam, registration spam, spam comments, comment moderation, spam bots, block spam, signup spam, spam blocker, spam filter, user registration spam,pingback,trackback, anti-spam plugin, varnish, amp, spam free, userpro,honeypot,puzzle,quiz,survey,poll
|
4 |
Requires at least: 3.0
|
5 |
Tested up to: 4.6.1
|
6 |
-
Stable tag: 5.
|
7 |
License: GPLv2
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -384,6 +384,8 @@ Yes, it does. But you have to turn off the option 'Use AJAX for JavaScript check
|
|
384 |
= How to close renewal or trial notice in the WordPress backend? =
|
385 |
To close the notice please save the plugin settings again or it will be closed automatically within 60 minutes after the renewal.
|
386 |
|
|
|
|
|
387 |
== Other notes ==
|
388 |
|
389 |
= Troubleshooting Guide =
|
@@ -481,6 +483,16 @@ WordPress 3.0 at least. PHP 5 with CURL or file_get_contents() function and enab
|
|
481 |
1. The Dashboard with a map of most spam active countries per your account.
|
482 |
|
483 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
484 |
= 5.49.2 October 5 2016 =
|
485 |
* Second Fix for database error. Stable version.
|
486 |
|
@@ -1164,6 +1176,16 @@ WordPress 3.0 at least. PHP 5 with CURL or file_get_contents() function and enab
|
|
1164 |
|
1165 |
== Upgrade Notice ==
|
1166 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1167 |
= 5.49.2 October 5 2016 =
|
1168 |
* Second Fix for database error. Stable version.
|
1169 |
|
3 |
Tags: spam, anti-spam, antispam, anti spam, bbpress, buddypress, captcha, capcha, captha, catcha, cf7 spam, comments, contact form spam, signup, spammers, spammy, woocommerce, wordpress spam, subscription, gravity spam, jetpack, bots, contact form 7, contact form, registrations, ninja, Fast Secure Contact, Gravity forms, formidable, mailchimp, s2member, protection, protect, email, plugin, contact, recaptcha, google captcha, google recaptcha, blacklist, prevent spam comments, wordpress, User Frontend, bulk delete, bulk remove, widget, review, firewall, cleantalk, mailpoet, profile builder, comment spam, registration spam, spam comments, comment moderation, spam bots, block spam, signup spam, spam blocker, spam filter, user registration spam,pingback,trackback, anti-spam plugin, varnish, amp, spam free, userpro,honeypot,puzzle,quiz,survey,poll
|
4 |
Requires at least: 3.0
|
5 |
Tested up to: 4.6.1
|
6 |
+
Stable tag: 5.50
|
7 |
License: GPLv2
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
384 |
= How to close renewal or trial notice in the WordPress backend? =
|
385 |
To close the notice please save the plugin settings again or it will be closed automatically within 60 minutes after the renewal.
|
386 |
|
387 |
+
= I'm using PHP 4.2 version and i'm getting errors related with JSON. Why does it happens? =
|
388 |
+
СleanTalk is no longer supports PHP lower than 5.2 version because the support code have incompatibility with PHP 7 version. Please, upgrade your PHP. If you couldn't perform that, let us know about it via support ticket here: https://cleantalk.org/my/support.
|
389 |
== Other notes ==
|
390 |
|
391 |
= Troubleshooting Guide =
|
483 |
1. The Dashboard with a map of most spam active countries per your account.
|
484 |
|
485 |
== Changelog ==
|
486 |
+
= 5.50 October 20 2016 =
|
487 |
+
* Custom contact forms: integration.
|
488 |
+
* Pirate Forms: integration.
|
489 |
+
* PHP 7 compatibility: Deleted third-party JSON library and dependences.
|
490 |
+
* PHP 7 compatibility: Fixed end of lines.
|
491 |
+
* YOAST Seo: Fixed PHP warnings.
|
492 |
+
* SpamFireWall: Minor fix for SpamFireWall counter.
|
493 |
+
* Only admin could access to CleanTalk dashboard (exclude Authors an Editors).
|
494 |
+
* Improved filtration in contact forms.
|
495 |
+
|
496 |
= 5.49.2 October 5 2016 =
|
497 |
* Second Fix for database error. Stable version.
|
498 |
|
1176 |
|
1177 |
== Upgrade Notice ==
|
1178 |
== Changelog ==
|
1179 |
+
= 5.50 October 20 2016 =
|
1180 |
+
* Custom contact forms: integration.
|
1181 |
+
* Pirate Forms: integration.
|
1182 |
+
* PHP 7 compatibility: Deleted third-party JSON library and dependences.
|
1183 |
+
* PHP 7 compatibility: Fixed end of lines.
|
1184 |
+
* YOAST Seo: Fixed PHP warnings.
|
1185 |
+
* SpamFireWall: Minor fix for SpamFireWall counter.
|
1186 |
+
* Only admin could access to CleanTalk dashboard (exclude Authors an Editors).
|
1187 |
+
* Improved filtration in contact forms.
|
1188 |
+
|
1189 |
= 5.49.2 October 5 2016 =
|
1190 |
* Second Fix for database error. Stable version.
|
1191 |
|