/abu-saleh77/termsCondition/vendor/mpdf/mpdf/includes/functions.php

https://gitlab.com/cserobiul/Bitm-PHP-CRUD-Practice · PHP · 152 lines · 122 code · 21 blank · 9 comment · 33 complexity · 2949e84517de180ab54e02a3689e1175 MD5 · raw file

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