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