compat.func.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. }
  32. if (null == $arg_separator) {
  33. $arg_separator = '&';
  34. }
  35. return http_build_recursive($formdata, $arg_separator);
  36. }
  37. function http_build_recursive($formdata, $separator, $key = '', $prefix = '') {
  38. $rlt = '';
  39. foreach ($formdata as $k => $v) {
  40. if (is_array($v)) {
  41. if ($key) {
  42. $rlt .= http_build_recursive($v, $separator, $key . '[' . $k . ']', $prefix);
  43. } else {
  44. $rlt .= http_build_recursive($v, $separator, $k, $prefix);
  45. }
  46. } else {
  47. if ($key) {
  48. $rlt .= $prefix . $key . '[' . urlencode($k) . ']=' . urldecode($v) . '&';
  49. } else {
  50. $rlt .= $prefix . urldecode($k) . '=' . urldecode($v) . '&';
  51. }
  52. }
  53. }
  54. return $rlt;
  55. }
  56. }
  57. if (!function_exists('file_put_contents')) {
  58. function file_put_contents($file, $string) {
  59. $fp = @fopen($file, 'w') or exit("Can not open $file");
  60. flock($fp, LOCK_EX);
  61. $stringlen = @fwrite($fp, $string);
  62. flock($fp, LOCK_UN);
  63. @fclose($fp);
  64. return $stringlen;
  65. }
  66. }
  67. if (!function_exists('getimagesizefromstring')) {
  68. function getimagesizefromstring($string_data) {
  69. $uri = 'data://application/octet-stream;base64,' . base64_encode($string_data);
  70. return getimagesize($uri);
  71. }
  72. }
  73. if (!defined('JSON_UNESCAPED_UNICODE')) {
  74. define('JSON_UNESCAPED_UNICODE', 256);
  75. }
  76. if (!function_exists('hex2bin')) {
  77. function hex2bin($str) {
  78. $sbin = '';
  79. $len = strlen($str);
  80. for ($i = 0; $i < $len; $i += 2) {
  81. $sbin .= pack('H*', substr($str, $i, 2));
  82. }
  83. return $sbin;
  84. }
  85. }
  86. if (!function_exists('mb_strlen')) {
  87. function mb_strlen($string, $charset = '') {
  88. return istrlen($string, $charset);
  89. }
  90. }
  91. if (!interface_exists('SessionHandlerInterface')) {
  92. interface SessionHandlerInterface {
  93. }
  94. }
  95. if (!function_exists('fastcgi_finish_request')) {
  96. function fastcgi_finish_request() {
  97. return error(-1, 'Not npm or fast cgi');
  98. }
  99. }
  100. if (!function_exists('openssl_decrypt')) {
  101. function openssl_decrypt($ciphertext_dec, $method, $key, $options, $iv) {
  102. $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
  103. mcrypt_generic_init($module, $key, $iv);
  104. $decrypted = mdecrypt_generic($module, $ciphertext_dec);
  105. mcrypt_generic_deinit($module);
  106. mcrypt_module_close($module);
  107. return $decrypted;
  108. }
  109. }
  110. if (!function_exists('openssl_encrypt')) {
  111. function openssl_encrypt($text, $method, $key, $options, $iv) {
  112. $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
  113. mcrypt_generic_init($module, $key, $iv);
  114. $encrypted = mcrypt_generic($module, $text);
  115. mcrypt_generic_deinit($module);
  116. mcrypt_module_close($module);
  117. return $encrypted;
  118. }
  119. }
  120. if (!function_exists('array_column')) {
  121. function array_column($input, $columnKey, $indexKey = null) {
  122. $columnKeyIsNumber = (is_numeric($columnKey)) ? true : false;
  123. $indexKeyIsNull = (is_null($indexKey)) ? true : false;
  124. $indexKeyIsNumber = (is_numeric($indexKey)) ? true : false;
  125. $result = array();
  126. foreach ((array) $input as $key => $row) {
  127. if ($columnKeyIsNumber) {
  128. $tmp = array_slice($row, $columnKey, 1);
  129. $tmp = (is_array($tmp) && !empty($tmp)) ? current($tmp) : null;
  130. } else {
  131. $tmp = isset($row[$columnKey]) ? $row[$columnKey] : null;
  132. }
  133. if (!$indexKeyIsNull) {
  134. if ($indexKeyIsNumber) {
  135. $key = array_slice($row, $indexKey, 1);
  136. $key = (is_array($key) && !empty($key)) ? current($key) : null;
  137. $key = is_null($key) ? 0 : $key;
  138. } else {
  139. $key = isset($row[$indexKey]) ? $row[$indexKey] : 0;
  140. }
  141. }
  142. $result[$key] = $tmp;
  143. }
  144. return $result;
  145. }
  146. }
  147. if (!function_exists('boolval')) {
  148. function boolval($val) {
  149. return (bool) $val;
  150. }
  151. }