compat.func.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. if (!function_exists('json_encode')) {
  8. function json_encode($value) {
  9. static $jsonobj;
  10. if (!isset($jsonobj)) {
  11. load()->library('json');
  12. $jsonobj = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
  13. }
  14. return $jsonobj->encode($value);
  15. }
  16. }
  17. if (!function_exists('json_decode')) {
  18. function json_decode($jsonString) {
  19. static $jsonobj;
  20. if (!isset($jsonobj)) {
  21. load()->library('json');
  22. $jsonobj = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
  23. }
  24. return $jsonobj->decode($jsonString);
  25. }
  26. }
  27. if (!function_exists('http_build_query')) {
  28. function http_build_query($formdata, $numeric_prefix = null, $arg_separator = null) {
  29. if (!is_array($formdata))
  30. return false;
  31. if ($arg_separator == null)
  32. $arg_separator = '&';
  33. return http_build_recursive($formdata, $arg_separator);
  34. }
  35. function http_build_recursive($formdata, $separator, $key = '', $prefix = '') {
  36. $rlt = '';
  37. foreach ($formdata as $k => $v) {
  38. if (is_array($v)) {
  39. if ($key)
  40. $rlt .= http_build_recursive($v, $separator, $key . '[' . $k . ']', $prefix);
  41. else
  42. $rlt .= http_build_recursive($v, $separator, $k, $prefix);
  43. } else {
  44. if ($key)
  45. $rlt .= $prefix . $key . '[' . urlencode($k) . ']=' . urldecode($v) . '&';
  46. else
  47. $rlt .= $prefix . urldecode($k) . '=' . urldecode($v) . '&';
  48. }
  49. }
  50. return $rlt;
  51. }
  52. }
  53. if (!function_exists('file_put_contents')) {
  54. function file_put_contents($file, $string) {
  55. $fp = @fopen($file, 'w') or exit("Can not open $file");
  56. flock($fp, LOCK_EX);
  57. $stringlen = @fwrite($fp, $string);
  58. flock($fp, LOCK_UN);
  59. @fclose($fp);
  60. return $stringlen;
  61. }
  62. }
  63. if (!function_exists('getimagesizefromstring')) {
  64. function getimagesizefromstring($string_data) {
  65. $uri = 'data://application/octet-stream;base64,' . base64_encode($string_data);
  66. return getimagesize($uri);
  67. }
  68. }
  69. if (!defined('JSON_UNESCAPED_UNICODE')) {
  70. define('JSON_UNESCAPED_UNICODE', 256);
  71. }
  72. if (!function_exists('hex2bin')) {
  73. function hex2bin($str) {
  74. $sbin = '';
  75. $len = strlen($str);
  76. for ($i = 0; $i < $len; $i += 2) {
  77. $sbin .= pack("H*", substr($str, $i, 2));
  78. }
  79. return $sbin;
  80. }
  81. }
  82. if (!function_exists('mb_strlen')) {
  83. function mb_strlen($string, $charset = '') {
  84. return istrlen($string, $charset);
  85. }
  86. }
  87. if (!interface_exists('SessionHandlerInterface')) {
  88. interface SessionHandlerInterface {}
  89. }
  90. if (!function_exists("fastcgi_finish_request")) {
  91. function fastcgi_finish_request() {
  92. return error(-1, 'Not npm or fast cgi');
  93. }
  94. }
  95. if (!function_exists('openssl_decrypt')) {
  96. function openssl_decrypt($ciphertext_dec, $method, $key, $options, $iv) {
  97. $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
  98. mcrypt_generic_init($module, $key, $iv);
  99. $decrypted = mdecrypt_generic($module, $ciphertext_dec);
  100. mcrypt_generic_deinit($module);
  101. mcrypt_module_close($module);
  102. return $decrypted;
  103. }
  104. }
  105. if (!function_exists('openssl_encrypt')) {
  106. function openssl_encrypt($text, $method, $key, $options, $iv) {
  107. $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
  108. mcrypt_generic_init($module, $key, $iv);
  109. $encrypted = mcrypt_generic($module, $text);
  110. mcrypt_generic_deinit($module);
  111. mcrypt_module_close($module);
  112. return $encrypted;
  113. }
  114. }
  115. if (!function_exists('array_column')) {
  116. function array_column($input, $columnKey, $indexKey = NULL) {
  117. $columnKeyIsNumber = (is_numeric($columnKey)) ? true : false;
  118. $indexKeyIsNull = (is_null($indexKey)) ? true : false;
  119. $indexKeyIsNumber = (is_numeric($indexKey)) ? true : false;
  120. $result = array();
  121. foreach ((array)$input AS $key => $row) {
  122. if ($columnKeyIsNumber) {
  123. $tmp = array_slice($row, $columnKey, 1);
  124. $tmp = (is_array($tmp) && !empty($tmp)) ? current($tmp) : NULL;
  125. } else {
  126. $tmp = isset($row[$columnKey]) ? $row[$columnKey] : NULL;
  127. }
  128. if (!$indexKeyIsNull) {
  129. if ($indexKeyIsNumber) {
  130. $key = array_slice($row, $indexKey, 1);
  131. $key = (is_array($key) && ! empty($key)) ? current($key) : NULL;
  132. $key = is_null($key) ? 0 : $key;
  133. } else {
  134. $key = isset($row[$indexKey]) ? $row[$indexKey] : 0;
  135. }
  136. }
  137. $result[$key] = $tmp;
  138. }
  139. return $result;
  140. }
  141. }
  142. if (!function_exists('boolval')) {
  143. function boolval($val) {
  144. return (bool) $val;
  145. }
  146. }