aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/3rdparty/libraries/mpdf/includes/functions.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/3rdparty/libraries/mpdf/includes/functions.php')
-rw-r--r--inc/3rdparty/libraries/mpdf/includes/functions.php126
1 files changed, 126 insertions, 0 deletions
diff --git a/inc/3rdparty/libraries/mpdf/includes/functions.php b/inc/3rdparty/libraries/mpdf/includes/functions.php
new file mode 100644
index 00000000..03f47090
--- /dev/null
+++ b/inc/3rdparty/libraries/mpdf/includes/functions.php
@@ -0,0 +1,126 @@
1<?php
2
3// mPDF 5.6.23
4function array_insert(&$array, $value, $offset) {
5 if (is_array($array)) {
6 $array = array_values($array);
7 $offset = intval($offset);
8 if ($offset < 0 || $offset >= count($array)) { array_push($array, $value); }
9 else if ($offset == 0) { array_unshift($array, $value); }
10 else {
11 $temp = array_slice($array, 0, $offset);
12 array_push($temp, $value);
13 $array = array_slice($array, $offset);
14 $array = array_merge($temp, $array);
15 }
16 }
17 else { $array = array($value); }
18 return count($array);
19}
20
21function urlencode_part($url) { // mPDF 5.6.02
22 if (!preg_match('/^[a-z]+:\/\//i',$url)) { return $url; }
23 $file=$url;
24 $query='';
25 if (preg_match('/[?]/',$url)) {
26 $bits = preg_split('/[?]/',$url,2);
27 $file=$bits[0];
28 $query='?'.$bits[1];
29 }
30 $file = str_replace(array(" ","!","$","&","'","(",")","*","+",",",";","="),array("%20","%21","%24","%26","%27","%28","%29","%2A","%2B","%2C","%3B","%3D"),$file);
31 return $file.$query;
32}
33
34
35function _strspn($str1, $str2, $start=null, $length=null) {
36 $numargs = func_num_args();
37 if ($numargs == 2) {
38 return strspn($str1, $str2);
39 }
40 else if ($numargs == 3) {
41 return strspn($str1, $str2, $start);
42 }
43 else {
44 return strspn($str1, $str2, $start, $length);
45 }
46}
47
48
49function _strcspn($str1, $str2, $start=null, $length=null) {
50 $numargs = func_num_args();
51 if ($numargs == 2) {
52 return strcspn($str1, $str2);
53 }
54 else if ($numargs == 3) {
55 return strcspn($str1, $str2, $start);
56 }
57 else {
58 return strcspn($str1, $str2, $start, $length);
59 }
60}
61
62function _fgets (&$h, $force=false) {
63 $startpos = ftell($h);
64 $s = fgets($h, 1024);
65 if ($force && preg_match("/^([^\r\n]*[\r\n]{1,2})(.)/",trim($s), $ns)) {
66 $s = $ns[1];
67 fseek($h,$startpos+strlen($s));
68 }
69 return $s;
70}
71
72
73// For PHP4 compatability
74if(!function_exists('str_ireplace')) {
75 function str_ireplace($search,$replace,$subject) {
76 $search = preg_quote($search, "/");
77 return preg_replace("/".$search."/i", $replace, $subject);
78 }
79}
80if(!function_exists('htmlspecialchars_decode')) {
81 function htmlspecialchars_decode ($str) {
82 return strtr($str, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
83 }
84}
85
86function PreparePreText($text,$ff='//FF//') {
87 $text = htmlspecialchars($text);
88 if ($ff) { $text = str_replace($ff,'</pre><formfeed /><pre>',$text); }
89 return ('<pre>'.$text.'</pre>');
90}
91
92if(!function_exists('strcode2utf')){
93 function strcode2utf($str,$lo=true) {
94 //converts all the &#nnn; and &#xhhh; in a string to Unicode
95 if ($lo) { $lo = 1; } else { $lo = 0; }
96 $str = preg_replace('/\&\#([0-9]+)\;/me', "code2utf('\\1',{$lo})",$str);
97 $str = preg_replace('/\&\#x([0-9a-fA-F]+)\;/me', "codeHex2utf('\\1',{$lo})",$str);
98 return $str;
99 }
100}
101
102if(!function_exists('code2utf')){
103 function code2utf($num,$lo=true){
104 //Returns the utf string corresponding to the unicode value
105 if ($num<128) {
106 if ($lo) return chr($num);
107 else return '&#'.$num.';';
108 }
109 if ($num<2048) return chr(($num>>6)+192).chr(($num&63)+128);
110 if ($num<65536) return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
111 if ($num<2097152) return chr(($num>>18)+240).chr((($num>>12)&63)+128).chr((($num>>6)&63)+128) .chr(($num&63)+128);
112 return '?';
113 }
114}
115
116
117if(!function_exists('codeHex2utf')){
118 function codeHex2utf($hex,$lo=true){
119 $num = hexdec($hex);
120 if (($num<128) && !$lo) return '&#x'.$hex.';';
121 return code2utf($num,$lo);
122 }
123}
124
125
126?> \ No newline at end of file