1: <?php
2: /**
3: * YOU SHOULD NEVER USE FUNCTIONS DEFINED IN THIS FILE. THEY SHOULD BE IMPLEMENTED AT APPLICATION LEVEL
4: */
5: /*
6: You may not change or alter any portion of this comment or credits
7: of supporting developers from this source code or any supporting source code
8: which is considered copyrighted (c) material of the original comment or credit authors.
9:
10: This program is distributed in the hope that it will be useful,
11: but WITHOUT ANY WARRANTY; without even the implied warranty of
12: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13: */
14:
15: /**
16: * Xoops Functions
17: *
18: * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org)
19: * @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
20: * @package kernel
21: * @since 2.4.0
22: * @author Simon
23: */
24: defined('XOOPS_ROOT_PATH') || exit('Restricted access');
25:
26: /**
27: * xoops_hex2bin()
28: *
29: * @param string $hex
30: * @return string
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: * xoops_bin2hex()
48: *
49: * @param string $bin
50: * @return string
51: */
52: function xoops_bin2hex($bin)
53: {
54: return bin2hex($bin);
55: }
56:
57: /**
58: * xoops_ishexstr()
59: *
60: * @param string $hex
61: * @param int $checklen
62: * @return boolean
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;//And???
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: * xoops_convert_encode()
83: *
84: * @param string $data value of array
85: * @param string $store_method
86: *
87: * @return boolean|string
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: * xoops_convert_decode()
107: *
108: * @param string $data value of array
109: * @param string $store_method
110: * @return boolean|string
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: * xoops_aw_encode()
130: *
131: * @param mixed $value value of array
132: * @param mixed $key key of array
133: * @param string $store_method
134: * @return boolean|string
135: */
136: function xoops_aw_encode($value, $key, $store_method = 'urlcode')
137: {
138: $value = xoops_convert_encode($value, $store_method);
139: }
140:
141: /**
142: * xoops_aw_decode()
143: *
144: * @param mixed $value value of array
145: * @param mixed $key key of array
146: * @param string $store_method
147: * @return boolean|string
148: */
149: function xoops_aw_decode($value, $key, $store_method = 'urlcode')
150: {
151: $value = xoops_convert_decode($value, $store_method);
152: }
153: