|
1 | | -<?php |
2 | | -require_once (dirname(__FILE__) . 'autoload.php'); |
3 | | - |
4 | | -/** |
5 | | - * CleanTalk anti-spam script for any web form |
6 | | - * |
7 | | - * @version 1.1 |
8 | | - * @package CleanTalk |
9 | | - * @subpackage Base |
10 | | - * @author СleanTalk team ([email protected]) |
11 | | - * @copyright (C) 2014 СleanTalk team (http://cleantalk.org) |
12 | | - * @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html |
13 | | - * @see https://github.com/CleanTalk/php-antispam |
14 | | - * |
15 | | - */ |
16 | | -use lib\CleantalkRequest; |
17 | | -use lib\Cleantalk; |
18 | | -use lib\CleantalkHelper; |
19 | | -/* |
20 | | - CleanTalk's global vars |
21 | | -*/ |
22 | | -$ct_server_url = 'http://moderate.cleantalk.org/api2.0/'; |
23 | | -$ct_pagetime_label = 'ct_pagetime'; |
24 | | -$ct_checkjs_label = 'ct_checkjs'; |
25 | | - |
26 | | -ct_init(); |
27 | | - |
28 | | -/** |
29 | | - * Starts CleanTalk |
30 | | - * @param null |
31 | | - * @return boolean|null |
32 | | - */ |
33 | | -function ct_init() { |
34 | | - global $ct_pagetime_label, $ct_checkjs_label; |
35 | | - |
36 | | - if(session_id() === '') { |
37 | | - @session_start(); |
38 | | - } |
39 | | - |
40 | | - if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
41 | | - ct_process_submission(); |
42 | | - } else { |
43 | | - $_SESSION[$ct_pagetime_label] = time(); |
44 | | - $html = sprintf(' |
45 | | -<script type="text/javascript"> |
46 | | -function ctSetCookie() { |
47 | | - var date = new Date(); |
48 | | - document.cookie = "%s=" + date.getFullYear() + "; path=/"; |
49 | | -} |
50 | | -ctSetCookie(); |
51 | | -</script> |
52 | | -', |
53 | | - $ct_checkjs_label |
54 | | - ); |
55 | | - $html = str_replace(array("\n","\r"),'', $html); |
56 | | - echo $html; |
57 | | - } |
58 | | - |
59 | | - return null; |
60 | | -} |
61 | | - |
62 | | -/** |
63 | | - * Catchs and preapres POST data |
64 | | - * @param null |
65 | | - * @return boolean|null |
66 | | - */ |
67 | | -function ct_process_submission() { |
68 | | - global $ct_pagetime_label, $ct_server_url, $ct_checkjs_label; |
69 | | - |
70 | | - $ct_checkjs = null; |
71 | | - if (isset($_COOKIE[$ct_checkjs_label]) && $_COOKIE[$ct_checkjs_label] == date("Y")) { |
72 | | - if ($_COOKIE[$ct_checkjs_label] == date("Y")) { |
73 | | - $ct_checkjs = 1; |
74 | | - } else { |
75 | | - $ct_checkjs = 0; |
76 | | - } |
77 | | - } |
78 | | - |
79 | | - $ct_submit_time = null; |
80 | | - if (isset($_SESSION[$ct_pagetime_label])) { |
81 | | - $ct_submit_time = time() - $_SESSION[$ct_pagetime_label]; |
82 | | - } |
83 | | - |
84 | | - $sender_email = null; |
85 | | - if (is_array($_POST)) { |
86 | | - foreach ($_POST as $k => $v) { |
87 | | - if ($sender_email === null && isset($v)) { |
88 | | - if (is_string($v) && preg_match("/^\S+@\S+\.\S+$/", $v)) { |
89 | | - $sender_email = $v; |
90 | | - } |
91 | | - |
92 | | - // Looking email address in arrays |
93 | | - if (is_array($v)) { |
94 | | - foreach ($v as $v2) { |
95 | | - if ($sender_email) { |
96 | | - continue; |
97 | | - } |
98 | | - |
99 | | - if (is_string($v2) && preg_match("/^\S+@\S+\.\S+$/", $v2)) { |
100 | | - $sender_email = $v2; |
101 | | - } |
102 | | - } |
103 | | - } |
104 | | - } |
105 | | - } |
106 | | - } |
107 | | - // Take params from config |
108 | | - $config_url = 'http://moderate.cleantalk.ru'; |
109 | | - $auth_key = null; // Set Cleantalk auth key |
110 | | - |
111 | | - |
112 | | - // The facility in which to store the query parameters |
113 | | - $ct_request = new CleantalkRequest(); |
114 | | - |
115 | | - $ct_request->auth_key = $auth_key; |
116 | | - $ct_request->sender_email = $sender_email; |
117 | | - $ct_request->agent = 'php-api'; |
118 | | - $ct_request->sender_ip = CleantalkHelper::ip_get(array('real'), false); |
119 | | - $ct_request->js_on = $ct_checkjs; # Site visitor has JavaScript |
120 | | - $ct_request->submit_time = $ct_submit_time; # Seconds from start form filling till the form POST |
121 | | - |
122 | | - $ct = new Cleantalk(); |
123 | | - $ct->server_url = $config_url; |
124 | | - |
125 | | - // Check |
126 | | - $ct_result = $ct->isAllowUser($ct_request); |
127 | | - |
128 | | - if ($result->errno != 0) { |
129 | | - error_log($result->errstr); |
130 | | - return false; |
131 | | - } |
132 | | - |
133 | | - if ($result->allow == 0 && isset($result->comment)) { |
134 | | - $message = sprintf("<br /><br /><br /><center><span>%s</span></center>", $result->comment); |
135 | | - echo $message; |
136 | | - exit; |
137 | | - } |
138 | | - |
139 | | - return null; |
140 | | -} |
| 1 | +<?php |
| 2 | +require "vendor/autoload.php"; |
| 3 | + |
| 4 | +/** |
| 5 | + * CleanTalk anti-spam script for any web form |
| 6 | + * |
| 7 | + * @version 1.1 |
| 8 | + * @package CleanTalk |
| 9 | + * @subpackage Base |
| 10 | + * @author СleanTalk team ([email protected]) |
| 11 | + * @copyright (C) 2014 СleanTalk team (http://cleantalk.org) |
| 12 | + * @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html |
| 13 | + * @see https://github.com/CleanTalk/php-antispam |
| 14 | + * |
| 15 | + */ |
| 16 | +use lib\CleantalkRequest; |
| 17 | +use lib\Cleantalk; |
| 18 | +use lib\CleantalkHelper; |
| 19 | +/* |
| 20 | + CleanTalk's global vars |
| 21 | +*/ |
| 22 | +$ct_server_url = 'http://moderate.cleantalk.org/api2.0/'; |
| 23 | +$ct_pagetime_label = 'ct_pagetime'; |
| 24 | +$ct_checkjs_label = 'ct_checkjs'; |
| 25 | + |
| 26 | +ct_init(); |
| 27 | + |
| 28 | +/** |
| 29 | + * Starts CleanTalk |
| 30 | + * @param null |
| 31 | + * @return boolean|null |
| 32 | + */ |
| 33 | +function ct_init() { |
| 34 | + global $ct_pagetime_label, $ct_checkjs_label; |
| 35 | + |
| 36 | + if(session_id() === '') { |
| 37 | + @session_start(); |
| 38 | + } |
| 39 | + |
| 40 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
| 41 | + ct_process_submission(); |
| 42 | + } else { |
| 43 | + $_SESSION[$ct_pagetime_label] = time(); |
| 44 | + $html = sprintf(' |
| 45 | +<script type="text/javascript"> |
| 46 | +function ctSetCookie() { |
| 47 | + var date = new Date(); |
| 48 | + document.cookie = "%s=" + date.getFullYear() + "; path=/"; |
| 49 | +} |
| 50 | +ctSetCookie(); |
| 51 | +</script> |
| 52 | +', |
| 53 | + $ct_checkjs_label |
| 54 | + ); |
| 55 | + $html = str_replace(array("\n","\r"),'', $html); |
| 56 | + echo $html; |
| 57 | + } |
| 58 | + |
| 59 | + return null; |
| 60 | +} |
| 61 | + |
| 62 | +/** |
| 63 | + * Catchs and preapres POST data |
| 64 | + * @param null |
| 65 | + * @return boolean|null |
| 66 | + */ |
| 67 | +function ct_process_submission() { |
| 68 | + global $ct_pagetime_label, $ct_server_url, $ct_checkjs_label; |
| 69 | + |
| 70 | + $ct_checkjs = null; |
| 71 | + if (isset($_COOKIE[$ct_checkjs_label]) && $_COOKIE[$ct_checkjs_label] == date("Y")) { |
| 72 | + if ($_COOKIE[$ct_checkjs_label] == date("Y")) { |
| 73 | + $ct_checkjs = 1; |
| 74 | + } else { |
| 75 | + $ct_checkjs = 0; |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + $ct_submit_time = null; |
| 80 | + if (isset($_SESSION[$ct_pagetime_label])) { |
| 81 | + $ct_submit_time = time() - $_SESSION[$ct_pagetime_label]; |
| 82 | + } |
| 83 | + |
| 84 | + $sender_email = null; |
| 85 | + if (is_array($_POST)) { |
| 86 | + foreach ($_POST as $k => $v) { |
| 87 | + if ($sender_email === null && isset($v)) { |
| 88 | + if (is_string($v) && preg_match("/^\S+@\S+\.\S+$/", $v)) { |
| 89 | + $sender_email = $v; |
| 90 | + } |
| 91 | + |
| 92 | + // Looking email address in arrays |
| 93 | + if (is_array($v)) { |
| 94 | + foreach ($v as $v2) { |
| 95 | + if ($sender_email) { |
| 96 | + continue; |
| 97 | + } |
| 98 | + |
| 99 | + if (is_string($v2) && preg_match("/^\S+@\S+\.\S+$/", $v2)) { |
| 100 | + $sender_email = $v2; |
| 101 | + } |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + // Take params from config |
| 108 | + $config_url = 'http://moderate.cleantalk.ru'; |
| 109 | + $auth_key = null; // Set Cleantalk auth key |
| 110 | + |
| 111 | + |
| 112 | + // The facility in which to store the query parameters |
| 113 | + $ct_request = new CleantalkRequest(); |
| 114 | + |
| 115 | + $ct_request->auth_key = $auth_key; |
| 116 | + $ct_request->sender_email = $sender_email; |
| 117 | + $ct_request->agent = 'php-api'; |
| 118 | + $ct_request->sender_ip = CleantalkHelper::ip_get(array('real'), false); |
| 119 | + $ct_request->js_on = $ct_checkjs; # Site visitor has JavaScript |
| 120 | + $ct_request->submit_time = $ct_submit_time; # Seconds from start form filling till the form POST |
| 121 | + |
| 122 | + $ct = new Cleantalk(); |
| 123 | + $ct->server_url = $config_url; |
| 124 | + |
| 125 | + // Check |
| 126 | + $ct_result = $ct->isAllowUser($ct_request); |
| 127 | + |
| 128 | + if ($result->errno != 0) { |
| 129 | + error_log($result->errstr); |
| 130 | + return false; |
| 131 | + } |
| 132 | + |
| 133 | + if ($result->allow == 0 && isset($result->comment)) { |
| 134 | + $message = sprintf("<br /><br /><br /><center><span>%s</span></center>", $result->comment); |
| 135 | + echo $message; |
| 136 | + exit; |
| 137 | + } |
| 138 | + |
| 139 | + return null; |
| 140 | +} |
0 commit comments