1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17:
18:
19: defined('XOOPS_ROOT_PATH') || exit('Restricted access');
20:
21: 22: 23:
24: class XoopsLocalAbstract
25: {
26: 27: 28: 29: 30: 31: 32: 33: 34: 35:
36: public static function substr($str, $start, $length, $trimmarker = '...')
37: {
38: if (!XOOPS_USE_MULTIBYTES) {
39: return (strlen($str) - $start <= $length) ? substr($str, $start, $length) : substr($str, $start, $length - strlen($trimmarker)) . $trimmarker;
40: }
41: if (function_exists('mb_internal_encoding') && @mb_internal_encoding(_CHARSET)) {
42: $str2 = mb_strcut($str, $start, $length - strlen($trimmarker));
43:
44: return $str2 . (mb_strlen($str) != mb_strlen($str2) ? $trimmarker : '');
45: }
46:
47: return $str;
48: }
49:
50: 51: 52: 53: 54: 55:
56: public static function utf8_encode($text)
57: {
58: if (XOOPS_USE_MULTIBYTES == 1) {
59: if (function_exists('mb_convert_encoding')) {
60: return mb_convert_encoding($text, 'UTF-8', 'auto');
61: }
62: }
63:
64: return utf8_encode($text);
65: }
66:
67: 68: 69: 70: 71: 72: 73: 74:
75: public static function convert_encoding($text, $to = 'utf-8', $from = '')
76: {
77: if (empty($text)) {
78: return $text;
79: }
80: if (empty($from)) {
81: $from = empty($GLOBALS['xlanguage']['charset_base']) ? _CHARSET : $GLOBALS['xlanguage']['charset_base'];
82: }
83: if (empty($to) || !strcasecmp($to, $from)) {
84: return $text;
85: }
86:
87: if (XOOPS_USE_MULTIBYTES && function_exists('mb_convert_encoding')) {
88: $converted_text = @mb_convert_encoding($text, $to, $from);
89: } elseif (function_exists('iconv')) {
90: $converted_text = @iconv($from, $to . '//TRANSLIT', $text);
91: } elseif ('utf-8' === $to) {
92: $converted_text = utf8_encode($text);
93: }
94: $text = empty($converted_text) ? $text : $converted_text;
95:
96: return $text;
97: }
98:
99: 100: 101: 102: 103: 104:
105: public static function trim($text)
106: {
107: $ret = trim($text);
108:
109: return $ret;
110: }
111:
112: 113: 114:
115: public static function getTimeFormatDesc()
116: {
117: return _TIMEFORMAT_DESC;
118: }
119:
120: 121: 122: 123: 124: 125: 126: 127: 128:
129: public static function formatTimestamp($time, $format = 'l', $timeoffset = null)
130: {
131: global $xoopsConfig, $xoopsUser;
132:
133: $format_copy = $format;
134: $format = strtolower($format);
135:
136: if ($format === 'rss' || $format === 'r') {
137: $TIME_ZONE = '';
138: if (isset($GLOBALS['xoopsConfig']['server_TZ'])) {
139: $server_TZ = abs((int)($GLOBALS['xoopsConfig']['server_TZ'] * 3600.0));
140: $prefix = ($GLOBALS['xoopsConfig']['server_TZ'] < 0) ? ' -' : ' +';
141: $TIME_ZONE = $prefix . date('Hi', $server_TZ);
142: }
143: $date = gmdate('D, d M Y H:i:s', (int)$time) . $TIME_ZONE;
144:
145: return $date;
146: }
147:
148: if (($format === 'elapse' || $format === 'e') && $time < time()) {
149: $elapse = time() - $time;
150: if ($days = floor($elapse / (24 * 3600))) {
151: $num = $days > 1 ? sprintf(_DAYS, $days) : _DAY;
152: } elseif ($hours = floor(($elapse % (24 * 3600)) / 3600)) {
153: $num = $hours > 1 ? sprintf(_HOURS, $hours) : _HOUR;
154: } elseif ($minutes = floor(($elapse % 3600) / 60)) {
155: $num = $minutes > 1 ? sprintf(_MINUTES, $minutes) : _MINUTE;
156: } else {
157: $seconds = $elapse % 60;
158: $num = $seconds > 1 ? sprintf(_SECONDS, $seconds) : _SECOND;
159: }
160: $ret = sprintf(_ELAPSE, $num);
161:
162: return $ret;
163: }
164:
165:
166: if ($timeoffset === null) {
167: $timeoffset = ($xoopsConfig['default_TZ'] == '') ? '0.0' : $xoopsConfig['default_TZ'];
168: }
169: $usertimestamp = xoops_getUserTimestamp($time, $timeoffset);
170: switch ($format) {
171: case 's':
172: $datestring = _SHORTDATESTRING;
173: break;
174:
175: case 'm':
176: $datestring = _MEDIUMDATESTRING;
177: break;
178:
179: case 'mysql':
180: $datestring = 'Y-m-d H:i:s';
181: break;
182:
183: case 'l':
184: $datestring = _DATESTRING;
185: break;
186:
187: case 'c':
188: case 'custom':
189: static $current_timestamp, $today_timestamp, $monthy_timestamp;
190: if (!isset($current_timestamp)) {
191: $current_timestamp = xoops_getUserTimestamp(time(), $timeoffset);
192: }
193: if (!isset($today_timestamp)) {
194: $today_timestamp = mktime(0, 0, 0, date('m', $current_timestamp), date('d', $current_timestamp), date('Y', $current_timestamp));
195: }
196:
197: if (abs($elapse_today = $usertimestamp - $today_timestamp) < 24 * 60 * 60) {
198: $datestring = ($elapse_today > 0) ? _TODAY : _YESTERDAY;
199: } else {
200: if (!isset($monthy_timestamp)) {
201: $monthy_timestamp[0] = mktime(0, 0, 0, 0, 0, date('Y', $current_timestamp));
202: $monthy_timestamp[1] = mktime(0, 0, 0, 0, 0, date('Y', $current_timestamp) + 1);
203: }
204: $datestring = _YEARMONTHDAY;
205: if ($usertimestamp >= $monthy_timestamp[0] && $usertimestamp < $monthy_timestamp[1]) {
206: $datestring = _MONTHDAY;
207: }
208: }
209: break;
210:
211: default:
212: $datestring = _DATESTRING;
213: if ($format != '') {
214: $datestring = $format_copy;
215: }
216: break;
217: }
218:
219: return ucfirst(date($datestring, $usertimestamp));
220: }
221:
222: 223: 224: 225: 226: 227:
228: public function number_format($number)
229: {
230: return $number;
231: }
232:
233: 234: 235: 236: 237: 238: 239:
240: public function money_format($format, $number)
241: {
242: return $number;
243: }
244:
245: 246: 247: 248: 249: 250: 251:
252: public function __call($name, $args)
253: {
254: if (function_exists($name)) {
255: return call_user_func_array($name, $args);
256: }
257: return null;
258: }
259: }
260: