| @@ -1,7 +1,46 @@ | ||
| 1 | 1 | <?php |
| 2 | 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 | +} | |
| 3 | 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 | +function urlencode_part($url) { // mPDF 5.6.02 | |
| 30 | + if (!preg_match('/^[a-z]+:\/\//i',$url)) { return $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 = str_replace(array(" ","!","$","&","'","(",")","*","+",",",";","="),array("%20","%21","%24","%26","%27","%28","%29","%2A","%2B","%2C","%3B","%3D"),$file); | |
| 39 | + return $file.$query; | |
| 40 | +} | |
| 41 | + | |
| 42 | + | |
| 4 | 43 | function _strspn($str1, $str2, $start=null, $length=null) { |
| 5 | 44 | $numargs = func_num_args(); |
| 6 | 45 | if ($numargs == 2) { |
| 7 | 46 | return strspn($str1, $str2); |
| @@ -52,9 +91,8 @@ | ||
| 52 | 91 | } |
| 53 | 92 | } |
| 54 | 93 | |
| 55 | 94 | function PreparePreText($text,$ff='//FF//') { |
| 56 | - // mPDF 5.0.053 | |
| 57 | 95 | $text = htmlspecialchars($text); |
| 58 | 96 | if ($ff) { $text = str_replace($ff,'</pre><formfeed /><pre>',$text); } |
| 59 | 97 | return ('<pre>'.$text.'</pre>'); |
| 60 | 98 | } |
| @@ -61,22 +99,39 @@ | ||
| 61 | 99 | |
| 62 | 100 | if(!function_exists('strcode2utf')){ |
| 63 | 101 | function strcode2utf($str,$lo=true) { |
| 64 | 102 | //converts all the &#nnn; and &#xhhh; in a string to Unicode |
| 65 | - if ($lo) { $lo = 1; } else { $lo = 0; } | |
| 66 | - $str = preg_replace('/\&\#([0-9]+)\;/me', "code2utf('\\1',{$lo})",$str); | |
| 67 | - $str = preg_replace('/\&\#x([0-9a-fA-F]+)\;/me', "codeHex2utf('\\1',{$lo})",$str); | |
| 103 | + // mPDF 5.7 | |
| 104 | + if ($lo) { | |
| 105 | + $str = preg_replace_callback('/\&\#([0-9]+)\;/m', 'code2utf_lo_callback', $str); | |
| 106 | + $str = preg_replace_callback('/\&\#x([0-9a-fA-F]+)\;/m', 'codeHex2utf_lo_callback', $str); | |
| 107 | + } | |
| 108 | + else { | |
| 109 | + $str = preg_replace_callback('/\&\#([0-9]+)\;/m', 'code2utf_callback', $str); | |
| 110 | + $str = preg_replace_callback('/\&\#x([0-9a-fA-F]+)\;/m', 'codeHex2utf_callback', $str); | |
| 111 | + } | |
| 68 | 112 | return $str; |
| 69 | 113 | } |
| 70 | 114 | } |
| 115 | +function code2utf_callback($matches) { | |
| 116 | + return code2utf($matches[1], 0); | |
| 117 | +} | |
| 118 | +function code2utf_lo_callback($matches) { | |
| 119 | + return code2utf($matches[1], 1); | |
| 120 | +} | |
| 121 | +function codeHex2utf_callback($matches) { | |
| 122 | + return codeHex2utf($matches[1], 0); | |
| 123 | +} | |
| 124 | +function codeHex2utf_lo_callback($matches) { | |
| 125 | + return codeHex2utf($matches[1], 1); | |
| 126 | +} | |
| 71 | 127 | |
| 72 | 128 | if(!function_exists('code2utf')){ |
| 73 | 129 | function code2utf($num,$lo=true){ |
| 74 | 130 | //Returns the utf string corresponding to the unicode value |
| 75 | - //added notes - http://uk.php.net/utf8_encode | |
| 76 | 131 | if ($num<128) { |
| 77 | 132 | if ($lo) return chr($num); |
| 78 | - else return '&#'.$num.';'; // i.e. no change | |
| 133 | + else return '&#'.$num.';'; | |
| 79 | 134 | } |
| 80 | 135 | if ($num<2048) return chr(($num>>6)+192).chr(($num&63)+128); |
| 81 | 136 | if ($num<65536) return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128); |
| 82 | 137 | if ($num<2097152) return chr(($num>>18)+240).chr((($num>>12)&63)+128).chr((($num>>6)&63)+128) .chr(($num&63)+128); |
| @@ -87,13 +142,11 @@ | ||
| 87 | 142 | |
| 88 | 143 | if(!function_exists('codeHex2utf')){ |
| 89 | 144 | function codeHex2utf($hex,$lo=true){ |
| 90 | 145 | $num = hexdec($hex); |
| 91 | - if (($num<128) && !$lo) return '&#x'.$hex.';'; // i.e. no change | |
| 146 | + if (($num<128) && !$lo) return '&#x'.$hex.';'; | |
| 92 | 147 | return code2utf($num,$lo); |
| 93 | 148 | } |
| 94 | 149 | } |
| 95 | - | |
| 96 | - | |
| 97 | 150 | |
| 98 | 151 | |
| 99 | 152 | ?> |