| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | defined('XOOPS_ROOT_PATH') || exit('Restricted access'); |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | function xoops_hex2bin($hex) |
| 33: | { |
| 34: | if (!is_string($hex)) { |
| 35: | return null; |
| 36: | } |
| 37: | $r = ''; |
| 38: | $len = strlen($hex); |
| 39: | for ($a = 0; $a < $len; $a += 2) { |
| 40: | $r .= chr(hexdec($hex[$a] . $hex[$a + 1])); |
| 41: | } |
| 42: | |
| 43: | return $r; |
| 44: | } |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | function xoops_bin2hex($bin) |
| 53: | { |
| 54: | return bin2hex($bin); |
| 55: | } |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: | |
| 61: | |
| 62: | |
| 63: | |
| 64: | function xoops_ishexstr($hex, $checklen = 32) |
| 65: | { |
| 66: | $accepted = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'); |
| 67: | $len = strlen($hex); |
| 68: | if ($checklen > $len) { |
| 69: | $checklen = $len; |
| 70: | } |
| 71: | $hex = strtolower($hex); |
| 72: | for ($i = 0; $i < $len; ++$i) { |
| 73: | if (!in_array($hex[$i], $accepted)) { |
| 74: | return false; |
| 75: | } |
| 76: | } |
| 77: | |
| 78: | return true; |
| 79: | } |
| 80: | |
| 81: | |
| 82: | |
| 83: | |
| 84: | |
| 85: | |
| 86: | |
| 87: | |
| 88: | |
| 89: | function xoops_convert_encode($data, $store_method = 'urlcode') |
| 90: | { |
| 91: | switch ($store_method) { |
| 92: | default: |
| 93: | return urlencode($data); |
| 94: | case 'base64': |
| 95: | return base64_encode($data); |
| 96: | case 'uucode': |
| 97: | return convert_uuencode($data); |
| 98: | case 'open': |
| 99: | return $data; |
| 100: | case 'hex': |
| 101: | return bin2hex($data); |
| 102: | } |
| 103: | } |
| 104: | |
| 105: | |
| 106: | |
| 107: | |
| 108: | |
| 109: | |
| 110: | |
| 111: | |
| 112: | function xoops_convert_decode($data, $store_method = 'urlcode') |
| 113: | { |
| 114: | switch ($store_method) { |
| 115: | default: |
| 116: | return urldecode($data); |
| 117: | case 'base64': |
| 118: | return base64_decode($data); |
| 119: | case 'uucode': |
| 120: | return convert_uudecode($data); |
| 121: | case 'open': |
| 122: | return $data; |
| 123: | case 'hex': |
| 124: | return xoops_hex2bin($data); |
| 125: | } |
| 126: | } |
| 127: | |
| 128: | |
| 129: | |
| 130: | |
| 131: | |
| 132: | |
| 133: | |
| 134: | |
| 135: | |
| 136: | function xoops_aw_encode($value, $key, $store_method = 'urlcode') |
| 137: | { |
| 138: | $value = xoops_convert_encode($value, $store_method); |
| 139: | } |
| 140: | |
| 141: | |
| 142: | |
| 143: | |
| 144: | |
| 145: | |
| 146: | |
| 147: | |
| 148: | |
| 149: | function xoops_aw_decode($value, $key, $store_method = 'urlcode') |
| 150: | { |
| 151: | $value = xoops_convert_decode($value, $store_method); |
| 152: | } |
| 153: | |