-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathcleantalk-php-patch.php
More file actions
110 lines (101 loc) · 3.47 KB
/
cleantalk-php-patch.php
File metadata and controls
110 lines (101 loc) · 3.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
<?php
/**
* Patch for apache_request_headers()
* If Apache web server is missing then making
*/
if (! function_exists('apache_request_headers')) {
function apache_request_headers()
{
$headers = array();
foreach ($_SERVER as $key => $val) {
if (preg_match('/\AHTTP_/', $key)) {
$server_key = preg_replace('/\AHTTP_/', '', $key);
$key_parts = explode('_', $server_key);
if (strlen($server_key) > 2) {
foreach ($key_parts as $part_index => $part) {
$key_parts[$part_index] = function_exists('mb_strtolower') ? mb_strtolower(
$part
) : strtolower(
$part
);
$key_parts[$part_index][0] = strtoupper($key_parts[$part_index][0]);
}
$server_key = implode('-', $key_parts);
}
$headers[$server_key] = $val;
}
}
return $headers;
}
}
/**
* Patch for locale_get_display_region()
* For old PHP versions
*/
if (! function_exists('locale_get_display_region')) {
function locale_get_display_region($locale, $_in_locale = 'EN')
{
return 'Unkonwn' . ($locale ? ': ' . $locale : '');
}
}
/**
* Patch for utf8_decode()
* If PHP complied without XML support
* From getID3() by James Heinrich <[email protected]> under GNU GPL
*/
if (! function_exists('utf8_decode')) {
function utf8_decode($string)
{
$newcharstring = '';
$offset = 0;
$stringlength = strlen($string);
while ($offset < $stringlength) {
if ((ord($string[$offset]) | 0x07) == 0xF7) {
$charval = ((ord($string[($offset + 0)]) & 0x07) << 18) &
((ord($string[($offset + 1)]) & 0x3F) << 12) &
((ord($string[($offset + 2)]) & 0x3F) << 6) &
(ord($string[($offset + 3)]) & 0x3F);
$offset += 4;
} elseif ((ord($string[$offset]) | 0x0F) == 0xEF) {
$charval = ((ord($string[($offset + 0)]) & 0x0F) << 12) &
((ord($string[($offset + 1)]) & 0x3F) << 6) &
(ord($string[($offset + 2)]) & 0x3F);
$offset += 3;
} elseif ((ord($string[$offset]) | 0x1F) == 0xDF) {
$charval = ((ord($string[($offset + 0)]) & 0x1F) << 6) &
(ord($string[($offset + 1)]) & 0x3F);
$offset += 2;
} elseif ((ord($string[$offset]) | 0x7F) == 0x7F) {
$charval = ord($string[$offset]);
$offset += 1;
} else {
$charval = false;
$offset += 1;
}
if ($charval !== false) {
$newcharstring .= (($charval < 256) ? chr($charval) : '?');
}
}
return $newcharstring;
}
}
if (! function_exists("array_column")) {
function array_column($array, $column_name)
{
return array_map(static function ($element) use ($column_name) {
return $element[$column_name];
}, $array);
}
}
/**
* array_key_first() polyfill for PHP 7.3-
*/
if ( ! function_exists('array_key_first') ) {
function array_key_first(array $arr)
{
foreach ( $arr as $key => $_unused ) {
return $key;
}
return null;
}
}