PluginProbe
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin / 1.8.0
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin v1.8.0
trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 All 71 releases
pdf-print / mpdf / includes / functions.php

functions.php in PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin 1.8.0, at mpdf/includes/functions.php

153 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // mPDF 5.7
4 // Replace a section of an array with the elements in reverse
5 function array_splice_reverse(&$arr, $offset, $length) {
6 $tmp = (array_reverse(array_slice($arr, $offset, $length)));
7 array_splice($arr, $offset, $length, $tmp);
8 }
9
10
11 // mPDF 5.6.23
12 function array_insert(&$array, $value, $offset) {
13 if (is_array($array)) {
14 $array = array_values($array);
15 $offset = intval($offset);
16 if ($offset < 0 || $offset >= count($array)) { array_push($array, $value); }
17 else if ($offset == 0) { array_unshift($array, $value); }
18 else {
19 $temp = array_slice($array, 0, $offset);
20 array_push($temp, $value);
21 $array = array_slice($array, $offset);
22 $array = array_merge($temp, $array);
23 }
24 }
25 else { $array = array($value); }
26 return count($array);
27 }
28
29 // mPDF 5.7.4 URLs
30 function urldecode_parts($url) {
31 $file=$url;
32 $query='';
33 if (preg_match('/[?]/',$url)) {
34 $bits = preg_split('/[?]/',$url,2);
35 $file=$bits[0];
36 $query='?'.$bits[1];
37 }
38 $file = rawurldecode($file);
39 $query = urldecode($query);
40 return $file.$query;
41 }
42
43
44 function _strspn($str1, $str2, $start=null, $length=null) {
45 $numargs = func_num_args();
46 if ($numargs == 2) {
47 return strspn($str1, $str2);
48 }
49 else if ($numargs == 3) {
50 return strspn($str1, $str2, $start);
51 }
52 else {
53 return strspn($str1, $str2, $start, $length);
54 }
55 }
56
57
58 function _strcspn($str1, $str2, $start=null, $length=null) {
59 $numargs = func_num_args();
60 if ($numargs == 2) {
61 return strcspn($str1, $str2);
62 }
63 else if ($numargs == 3) {
64 return strcspn($str1, $str2, $start);
65 }
66 else {
67 return strcspn($str1, $str2, $start, $length);
68 }
69 }
70
71 function _fgets (&$h, $force=false) {
72 $startpos = ftell($h);
73 $s = fgets($h, 1024);
74 if ($force && preg_match("/^([^\r\n]*[\r\n]{1,2})(.)/",trim($s), $ns)) {
75 $s = $ns[1];
76 fseek($h,$startpos+strlen($s));
77 }
78 return $s;
79 }
80
81
82 // For PHP4 compatability
83 if(!function_exists('str_ireplace')) {
84 function str_ireplace($search,$replace,$subject) {
85 $search = preg_quote($search, "/");
86 return preg_replace("/".$search."/i", $replace, $subject);
87 }
88 }
89 if(!function_exists('htmlspecialchars_decode')) {
90 function htmlspecialchars_decode ($str) {
91 return strtr($str, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
92 }
93 }
94
95 function PreparePreText($text,$ff='//FF//') {
96 $text = htmlspecialchars($text);
97 if ($ff) { $text = str_replace($ff,'</pre><formfeed /><pre>',$text); }
98 return ('<pre>'.$text.'</pre>');
99 }
100
101 if(!function_exists('strcode2utf')){
102 function strcode2utf($str,$lo=true) {
103 //converts all the &#nnn; and &#xhhh; in a string to Unicode
104 // mPDF 5.7
105 if ($lo) {
106 $str = preg_replace_callback('/\&\#([0-9]+)\;/m', 'code2utf_lo_callback', $str);
107 $str = preg_replace_callback('/\&\#x([0-9a-fA-F]+)\;/m', 'codeHex2utf_lo_callback', $str);
108 }
109 else {
110 $str = preg_replace_callback('/\&\#([0-9]+)\;/m', 'code2utf_callback', $str);
111 $str = preg_replace_callback('/\&\#x([0-9a-fA-F]+)\;/m', 'codeHex2utf_callback', $str);
112 }
113 return $str;
114 }
115 }
116 function code2utf_callback($matches) {
117 return code2utf($matches[1], 0);
118 }
119 function code2utf_lo_callback($matches) {
120 return code2utf($matches[1], 1);
121 }
122 function codeHex2utf_callback($matches) {
123 return codeHex2utf($matches[1], 0);
124 }
125 function codeHex2utf_lo_callback($matches) {
126 return codeHex2utf($matches[1], 1);
127 }
128
129 if(!function_exists('code2utf')){
130 function code2utf($num,$lo=true){
131 //Returns the utf string corresponding to the unicode value
132 if ($num<128) {
133 if ($lo) return chr($num);
134 else return '&#'.$num.';';
135 }
136 if ($num<2048) return chr(($num>>6)+192).chr(($num&63)+128);
137 if ($num<65536) return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
138 if ($num<2097152) return chr(($num>>18)+240).chr((($num>>12)&63)+128).chr((($num>>6)&63)+128) .chr(($num&63)+128);
139 return '?';
140 }
141 }
142
143
144 if(!function_exists('codeHex2utf')){
145 function codeHex2utf($hex,$lo=true){
146 $num = hexdec($hex);
147 if (($num<128) && !$lo) return '&#x'.$hex.';';
148 return code2utf($num,$lo);
149 }
150 }
151
152
153 ?>