Skip to content

Commit 17404ff

Browse files
author
davydovct
committed
add patch
1 parent 9070d1b commit 17404ff

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed

lib/Cleantalk.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ private function createMsg($method, CleantalkRequest $request) {
187187
switch ($method) {
188188
case 'check_message':
189189
// Convert strings to UTF8
190-
$request->message = CleantalkHelper::arrayToUTF8( $request->message, $this->data_codepage);
191-
$request->example = CleantalkHelper::arrayToUTF8( $request->example, $this->data_codepage);
190+
$request->message = CleantalkHelper::stringToUTF8( $request->message, $this->data_codepage);
191+
$request->example = CleantalkHelper::stringToUTF8( $request->example, $this->data_codepage);
192192
$request->sender_email = CleantalkHelper::stringToUTF8($request->sender_email, $this->data_codepage);
193193
$request->sender_nickname = CleantalkHelper::stringToUTF8($request->sender_nickname, $this->data_codepage);
194194

lib/cleantalk-php-patch.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
/*
4+
* Patch for apache_request_headers()
5+
* If Apache web server is missing then making
6+
*/
7+
if( !function_exists('apache_request_headers') ){
8+
function apache_request_headers(){
9+
10+
$headers = array();
11+
foreach($_SERVER as $key => $val){
12+
if(preg_match('/\AHTTP_/', $key)){
13+
$server_key = preg_replace('/\AHTTP_/', '', $key);
14+
$key_parts = explode('_', $server_key);
15+
if(count($key_parts) > 0 and strlen($server_key) > 2){
16+
foreach($key_parts as $part_index => $part){
17+
$key_parts[$part_index] = function_exists('mb_strtolower') ? mb_strtolower($part) : strtolower($part);
18+
$key_parts[$part_index][0] = strtoupper($key_parts[$part_index][0]);
19+
}
20+
$server_key = implode('-', $key_parts);
21+
}
22+
$headers[$server_key] = $val;
23+
}
24+
}
25+
return $headers;
26+
}
27+
}
28+
29+
/*
30+
* Patch for locale_get_display_region()
31+
* For old PHP versions
32+
*/
33+
if( !function_exists('locale_get_display_region') ){
34+
function locale_get_display_region($locale, $in_locale = 'EN'){
35+
36+
return 'Unkonwn' . ($locale ? ': ' . $locale : '');
37+
}
38+
}
39+
40+
/*
41+
* Patch for utf8_decode()
42+
* If PHP complied without XML support
43+
* From getID3() by James Heinrich <info@getid3.org> under GNU GPL
44+
*/
45+
if(!function_exists('utf8_decode')){
46+
function utf8_decode($string){
47+
48+
$newcharstring = '';
49+
$offset = 0;
50+
$stringlength = strlen($string);
51+
while ($offset < $stringlength) {
52+
if ((ord($string{$offset}) | 0x07) == 0xF7) {
53+
$charval = ((ord($string{($offset + 0)}) & 0x07) << 18) &
54+
((ord($string{($offset + 1)}) & 0x3F) << 12) &
55+
((ord($string{($offset + 2)}) & 0x3F) << 6) &
56+
(ord($string{($offset + 3)}) & 0x3F);
57+
$offset += 4;
58+
} elseif ((ord($string{$offset}) | 0x0F) == 0xEF) {
59+
$charval = ((ord($string{($offset + 0)}) & 0x0F) << 12) &
60+
((ord($string{($offset + 1)}) & 0x3F) << 6) &
61+
(ord($string{($offset + 2)}) & 0x3F);
62+
$offset += 3;
63+
} elseif ((ord($string{$offset}) | 0x1F) == 0xDF) {
64+
$charval = ((ord($string{($offset + 0)}) & 0x1F) << 6) &
65+
(ord($string{($offset + 1)}) & 0x3F);
66+
$offset += 2;
67+
} elseif ((ord($string{$offset}) | 0x7F) == 0x7F) {
68+
$charval = ord($string{$offset});
69+
$offset += 1;
70+
} else {
71+
$charval = false;
72+
$offset += 1;
73+
}
74+
if ($charval !== false) {
75+
$newcharstring .= (($charval < 256) ? chr($charval) : '?');
76+
}
77+
}
78+
return $newcharstring;
79+
}
80+
}

tests/CleantalkTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
require_once 'lib/CleantalkResponse.php';
55
require_once 'lib/CleantalkAPI.php';
66
require_once 'lib/CleantalkHelper.php';
7+
require_once 'lib/cleantalk-php-patch.php';
78

89
use lib\Cleantalk;
910
use lib\CleantalkRequest;

0 commit comments

Comments
 (0)