PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/include/mpdf/includes/functions.php

https://gitlab.com/billyprice1/osTicket
PHP | 152 lines | 136 code | 10 blank | 6 comment | 24 complexity | 9d99d7368b5a950589926ea92a52f785 MD5 | raw file
  1. <?php
  2. // mPDF 5.7
  3. // Replace a section of an array with the elements in reverse
  4. function array_splice_reverse(&$arr, $offset, $length) {
  5. $tmp = (array_reverse(array_slice($arr, $offset, $length)));
  6. array_splice($arr, $offset, $length, $tmp);
  7. }
  8. // mPDF 5.6.23
  9. function array_insert(&$array, $value, $offset) {
  10. if (is_array($array)) {
  11. $array = array_values($array);
  12. $offset = intval($offset);
  13. if ($offset < 0 || $offset >= count($array)) { array_push($array, $value); }
  14. else if ($offset == 0) { array_unshift($array, $value); }
  15. else {
  16. $temp = array_slice($array, 0, $offset);
  17. array_push($temp, $value);
  18. $array = array_slice($array, $offset);
  19. $array = array_merge($temp, $array);
  20. }
  21. }
  22. else { $array = array($value); }
  23. return count($array);
  24. }
  25. function urlencode_part($url) { // mPDF 5.6.02
  26. if (!preg_match('/^[a-z]+:\/\//i',$url)) { return $url; }
  27. $file=$url;
  28. $query='';
  29. if (preg_match('/[?]/',$url)) {
  30. $bits = preg_split('/[?]/',$url,2);
  31. $file=$bits[0];
  32. $query='?'.$bits[1];
  33. }
  34. $file = str_replace(array(" ","!","$","&","'","(",")","*","+",",",";","="),array("%20","%21","%24","%26","%27","%28","%29","%2A","%2B","%2C","%3B","%3D"),$file);
  35. return $file.$query;
  36. }
  37. function _strspn($str1, $str2, $start=null, $length=null) {
  38. $numargs = func_num_args();
  39. if ($numargs == 2) {
  40. return strspn($str1, $str2);
  41. }
  42. else if ($numargs == 3) {
  43. return strspn($str1, $str2, $start);
  44. }
  45. else {
  46. return strspn($str1, $str2, $start, $length);
  47. }
  48. }
  49. function _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. function _fgets (&$h, $force=false) {
  62. $startpos = ftell($h);
  63. $s = fgets($h, 1024);
  64. if ($force && preg_match("/^([^\r\n]*[\r\n]{1,2})(.)/",trim($s), $ns)) {
  65. $s = $ns[1];
  66. fseek($h,$startpos+strlen($s));
  67. }
  68. return $s;
  69. }
  70. // For PHP4 compatability
  71. if(!function_exists('str_ireplace')) {
  72. function str_ireplace($search,$replace,$subject) {
  73. $search = preg_quote($search, "/");
  74. return preg_replace("/".$search."/i", $replace, $subject);
  75. }
  76. }
  77. if(!function_exists('htmlspecialchars_decode')) {
  78. function htmlspecialchars_decode ($str) {
  79. return strtr($str, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
  80. }
  81. }
  82. function PreparePreText($text,$ff='//FF//') {
  83. $text = htmlspecialchars($text);
  84. if ($ff) { $text = str_replace($ff,'</pre><formfeed /><pre>',$text); }
  85. return ('<pre>'.$text.'</pre>');
  86. }
  87. if(!function_exists('strcode2utf')){
  88. function strcode2utf($str,$lo=true) {
  89. //converts all the &#nnn; and &#xhhh; in a string to Unicode
  90. // mPDF 5.7
  91. if ($lo) {
  92. $str = preg_replace_callback('/\&\#([0-9]+)\;/m', 'code2utf_lo_callback', $str);
  93. $str = preg_replace_callback('/\&\#x([0-9a-fA-F]+)\;/m', 'codeHex2utf_lo_callback', $str);
  94. }
  95. else {
  96. $str = preg_replace_callback('/\&\#([0-9]+)\;/m', 'code2utf_callback', $str);
  97. $str = preg_replace_callback('/\&\#x([0-9a-fA-F]+)\;/m', 'codeHex2utf_callback', $str);
  98. }
  99. return $str;
  100. }
  101. }
  102. function code2utf_callback($matches) {
  103. return code2utf($matches[1], 0);
  104. }
  105. function code2utf_lo_callback($matches) {
  106. return code2utf($matches[1], 1);
  107. }
  108. function codeHex2utf_callback($matches) {
  109. return codeHex2utf($matches[1], 0);
  110. }
  111. function codeHex2utf_lo_callback($matches) {
  112. return codeHex2utf($matches[1], 1);
  113. }
  114. if(!function_exists('code2utf')){
  115. function code2utf($num,$lo=true){
  116. //Returns the utf string corresponding to the unicode value
  117. if ($num<128) {
  118. if ($lo) return chr($num);
  119. else return '&#'.$num.';';
  120. }
  121. if ($num<2048) return chr(($num>>6)+192).chr(($num&63)+128);
  122. if ($num<65536) return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
  123. if ($num<2097152) return chr(($num>>18)+240).chr((($num>>12)&63)+128).chr((($num>>6)&63)+128) .chr(($num&63)+128);
  124. return '?';
  125. }
  126. }
  127. if(!function_exists('codeHex2utf')){
  128. function codeHex2utf($hex,$lo=true){
  129. $num = hexdec($hex);
  130. if (($num<128) && !$lo) return '&#x'.$hex.';';
  131. return code2utf($num,$lo);
  132. }
  133. }
  134. ?>