- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
229 lines (208 loc) · 4.77 KB
/
functions.php
File metadata and controls
229 lines (208 loc) · 4.77 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
<?php
/**
* Replace a section of an array with the elements in reverse
*
* @since mPDF 5.7
* @param array $arr
* @param int $offset
* @param int $length
*/
function array_splice_reverse(array &$arr, $offset, $length)
{
$tmp = (array_reverse(array_slice($arr, $offset, $length)));
array_splice($arr, $offset, $length, $tmp);
}
/**
* @since mPDF 5.7.4
* @param string $url
* @return string
*/
function urldecode_parts($url)
{
$file = $url;
$query = '';
if (preg_match('/[?]/', $url)) {
$bits = preg_split('/[?]/', $url, 2);
$file = $bits[0];
$query = '?' . $bits[1];
}
$file = rawurldecode($file);
$query = urldecode($query);
return $file . $query;
}
/**
* @param string $str1
* @param string $str2
* @param int $start
* @param int $length
*
* @return int
*/
function _strspn($str1, $str2, $start = null, $length = null)
{
$numargs = func_num_args();
if ($numargs == 2) {
return strspn($str1, $str2);
} else {
if ($numargs == 3) {
return strspn($str1, $str2, $start);
} else {
return strspn($str1, $str2, $start, $length);
}
}
}
/**
* @param string $str1
* @param string $str2
* @param int $start
* @param int $length
*
* @return int
*/
function _strcspn($str1, $str2, $start = null, $length = null)
{
$numargs = func_num_args();
if ($numargs == 2) {
return strcspn($str1, $str2);
} else {
if ($numargs == 3) {
return strcspn($str1, $str2, $start);
} else {
return strcspn($str1, $str2, $start, $length);
}
}
}
/**
* @param resource $h
* @param bool $force
*
* @return string
*/
function _fgets(&$h, $force = false)
{
$startpos = ftell($h);
$s = fgets($h, 1024);
if ($force && preg_match("/^([^\r\n]*[\r\n]{1,2})(.)/", trim($s), $ns)) {
$s = $ns[1];
fseek($h, $startpos + strlen($s));
}
return $s;
}
/**
* @param string $text
* @param string $ff
*
* @return string
*/
function PreparePreText($text, $ff = '//FF//')
{
$text = htmlspecialchars($text);
if ($ff) {
$text = str_replace($ff, '</pre><formfeed /><pre>', $text);
}
return ('<pre>' . $text . '</pre>');
}
if (!function_exists('strcode2utf')) {
/**
* Converts all the &#nnn; and &#xhhh; in a string to Unicode
*
* @since mPDF 5.7
* @param string $str
* @param bool $lo
*
* @return string
*/
function strcode2utf($str, $lo = true)
{
if ($lo) {
$str = preg_replace_callback('/\&\#([0-9]+)\;/m', 'code2utf_lo_callback', $str);
$str = preg_replace_callback('/\&\#x([0-9a-fA-F]+)\;/m', 'codeHex2utf_lo_callback', $str);
} else {
$str = preg_replace_callback('/\&\#([0-9]+)\;/m', 'code2utf_callback', $str);
$str = preg_replace_callback('/\&\#x([0-9a-fA-F]+)\;/m', 'codeHex2utf_callback', $str);
}
return $str;
}
}
function code2utf_callback($matches)
{
return code2utf($matches[1], 0);
}
function code2utf_lo_callback($matches)
{
return code2utf($matches[1], 1);
}
function codeHex2utf_callback($matches)
{
return codeHex2utf($matches[1], 0);
}
function codeHex2utf_lo_callback($matches)
{
return codeHex2utf($matches[1], 1);
}
/**
* PDF documents use the internal date format: (D:YYYYMMDDHHmmSSOHH'mm'). The date format has these parts:
*
* YYYY The full four-digit year. (For example, 2004)
* MM The month from 01 to 12.
* DD The day from 01 to 31.
* HH The hour from 00 to 23.
* mm The minute from 00 to 59.
* SS The seconds from 00 to 59.
* O The relationship of local time to Universal Time (UT), as denoted by one of the characters +, -, or Z.
* HH The absolute value of the offset from UT in hours specified as 00 to 23.
* mm The absolute value of the offset from UT in minutes specified as 00 to 59.
*
* @return string
*/
function pdfFormattedDate($date)
{
$z = date('O'); // +0200
$offset = substr($z, 0, 3) . "'" . substr($z, 3, 2) . "'"; // +02'00'
return date('YmdHis', $date) . $offset;
}
if (!function_exists('code2utf')) {
/**
* @param int $num
* @param bool $lo
*
* @return string
*/
function code2utf($num, $lo = true)
{
// Returns the utf string corresponding to the unicode value
if ($num < 128) {
if ($lo) {
return chr($num);
} else {
return '&#' . $num . ';';
}
}
if ($num < 2048) {
return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
}
if ($num < 65536) {
return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
}
if ($num < 2097152) {
return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
}
return '?';
}
}
if (!function_exists('codeHex2utf')) {
function codeHex2utf($hex, $lo = true)
{
$num = hexdec($hex);
if (($num < 128) && !$lo) {
return '&#x' . $hex . ';';
}
return code2utf($num, $lo);
}
}
if (!function_exists('cmp')) {
function cmp($a, $b)
{
return strcoll(strtolower($a['uf']), strtolower($b['uf']));
}
}