| 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: |  | 
| 57: | public static function utf8_encode($text) | 
| 58: | { | 
| 59: | if (defined('XOOPS_USE_MULTIBYTES') && 1 === (int)XOOPS_USE_MULTIBYTES) { | 
| 60: | if (function_exists('mb_convert_encoding')) { | 
| 61: | $converted_text = mb_convert_encoding($text, 'UTF-8', 'auto'); | 
| 62: | if ($converted_text !== false && !is_array($converted_text)) { | 
| 63: | return $converted_text; | 
| 64: | } else { | 
| 65: |  | 
| 66: | return $text; | 
| 67: | } | 
| 68: |  | 
| 69: | } | 
| 70: | } | 
| 71: |  | 
| 72: | return utf8_encode($text); | 
| 73: | } | 
| 74: |  | 
| 75: |  | 
| 76: |  | 
| 77: |  | 
| 78: |  | 
| 79: |  | 
| 80: |  | 
| 81: |  | 
| 82: | public static function utf8_decode($text) | 
| 83: | { | 
| 84: | if (defined('XOOPS_USE_MULTIBYTES') && 1 === (int)XOOPS_USE_MULTIBYTES) { | 
| 85: | if (function_exists('mb_convert_encoding')) { | 
| 86: | $converted_text = mb_convert_encoding($text, 'ISO-8859-1', 'auto'); | 
| 87: | if ($converted_text !== false && !is_array($converted_text)) { | 
| 88: | return $converted_text; | 
| 89: | } else { | 
| 90: |  | 
| 91: | return $text; | 
| 92: | } | 
| 93: | } | 
| 94: | } | 
| 95: |  | 
| 96: | return utf8_decode($text); | 
| 97: | } | 
| 98: |  | 
| 99: |  | 
| 100: |  | 
| 101: |  | 
| 102: |  | 
| 103: |  | 
| 104: |  | 
| 105: |  | 
| 106: |  | 
| 107: | public static function convert_encoding($text, $to = 'utf-8', $from = '') | 
| 108: | { | 
| 109: |  | 
| 110: | if (empty($text)) { | 
| 111: | return $text; | 
| 112: | } | 
| 113: |  | 
| 114: |  | 
| 115: | if (empty($from)) { | 
| 116: | $from = empty($GLOBALS['xlanguage']['charset_base']) ? _CHARSET : $GLOBALS['xlanguage']['charset_base']; | 
| 117: | } | 
| 118: |  | 
| 119: |  | 
| 120: | if (empty($to) || !strcasecmp($to, $from)) { | 
| 121: | return $text; | 
| 122: | } | 
| 123: |  | 
| 124: |  | 
| 125: | $convertedText = ''; | 
| 126: |  | 
| 127: |  | 
| 128: | if (XOOPS_USE_MULTIBYTES && function_exists('mb_convert_encoding')) { | 
| 129: | $convertedText = mb_convert_encoding($text, $to, $from); | 
| 130: | if (false !== $convertedText) { | 
| 131: | return $convertedText; | 
| 132: | } | 
| 133: | } | 
| 134: |  | 
| 135: |  | 
| 136: | if (function_exists('iconv')) { | 
| 137: | $convertedText = iconv($from, $to . '//TRANSLIT', $text); | 
| 138: | if (false !== $convertedText) { | 
| 139: | return $convertedText; | 
| 140: | } | 
| 141: | } | 
| 142: |  | 
| 143: |  | 
| 144: | if ('utf-8' === $to) { | 
| 145: | $convertedText = utf8_encode($text); | 
| 146: | if (false !== $convertedText) { | 
| 147: | return $convertedText; | 
| 148: | } | 
| 149: | } | 
| 150: |  | 
| 151: |  | 
| 152: | return $text; | 
| 153: |  | 
| 154: | } | 
| 155: |  | 
| 156: |  | 
| 157: |  | 
| 158: |  | 
| 159: |  | 
| 160: |  | 
| 161: |  | 
| 162: | public static function trim($text) | 
| 163: | { | 
| 164: | $ret = trim($text); | 
| 165: |  | 
| 166: | return $ret; | 
| 167: | } | 
| 168: |  | 
| 169: |  | 
| 170: |  | 
| 171: |  | 
| 172: | public static function getTimeFormatDesc() | 
| 173: | { | 
| 174: | return _TIMEFORMAT_DESC; | 
| 175: | } | 
| 176: |  | 
| 177: |  | 
| 178: |  | 
| 179: |  | 
| 180: |  | 
| 181: |  | 
| 182: |  | 
| 183: |  | 
| 184: |  | 
| 185: |  | 
| 186: | public static function formatTimestamp($time, $format = 'l', $timeoffset = null) | 
| 187: | { | 
| 188: | global $xoopsConfig, $xoopsUser; | 
| 189: |  | 
| 190: | $format_copy = $format; | 
| 191: | $format      = strtolower($format); | 
| 192: |  | 
| 193: | if ($format === 'rss' || $format === 'r') { | 
| 194: | $TIME_ZONE = ''; | 
| 195: | if (isset($GLOBALS['xoopsConfig']['server_TZ'])) { | 
| 196: | $server_TZ = abs((int)($GLOBALS['xoopsConfig']['server_TZ'] * 3600.0)); | 
| 197: | $prefix    = ($GLOBALS['xoopsConfig']['server_TZ'] < 0) ? ' -' : ' +'; | 
| 198: | $TIME_ZONE = $prefix . date('Hi', $server_TZ); | 
| 199: | } | 
| 200: | $date = gmdate('D, d M Y H:i:s', (int)$time) . $TIME_ZONE; | 
| 201: |  | 
| 202: | return $date; | 
| 203: | } | 
| 204: |  | 
| 205: | if (($format === 'elapse' || $format === 'e') && $time < time()) { | 
| 206: | $elapse = time() - $time; | 
| 207: | if ($days = floor($elapse / (24 * 3600))) { | 
| 208: | $num = $days > 1 ? sprintf(_DAYS, $days) : _DAY; | 
| 209: | } elseif ($hours = floor(($elapse % (24 * 3600)) / 3600)) { | 
| 210: | $num = $hours > 1 ? sprintf(_HOURS, $hours) : _HOUR; | 
| 211: | } elseif ($minutes = floor(($elapse % 3600) / 60)) { | 
| 212: | $num = $minutes > 1 ? sprintf(_MINUTES, $minutes) : _MINUTE; | 
| 213: | } else { | 
| 214: | $seconds = $elapse % 60; | 
| 215: | $num     = $seconds > 1 ? sprintf(_SECONDS, $seconds) : _SECOND; | 
| 216: | } | 
| 217: | $ret = sprintf(_ELAPSE, $num); | 
| 218: |  | 
| 219: | return $ret; | 
| 220: | } | 
| 221: |  | 
| 222: |  | 
| 223: | if ($timeoffset === null) { | 
| 224: | $timeoffset = ($xoopsConfig['default_TZ'] == '') ? '0.0' : $xoopsConfig['default_TZ']; | 
| 225: | } | 
| 226: | $usertimestamp = xoops_getUserTimestamp($time, $timeoffset); | 
| 227: | switch ($format) { | 
| 228: | case 's': | 
| 229: | $datestring = _SHORTDATESTRING; | 
| 230: | break; | 
| 231: |  | 
| 232: | case 'm': | 
| 233: | $datestring = _MEDIUMDATESTRING; | 
| 234: | break; | 
| 235: |  | 
| 236: | case 'mysql': | 
| 237: | $datestring = 'Y-m-d H:i:s'; | 
| 238: | break; | 
| 239: |  | 
| 240: | case 'l': | 
| 241: | $datestring = _DATESTRING; | 
| 242: | break; | 
| 243: |  | 
| 244: | case 'c': | 
| 245: | case 'custom': | 
| 246: | static $current_timestamp, $today_timestamp, $monthy_timestamp; | 
| 247: | if (!isset($current_timestamp)) { | 
| 248: | $current_timestamp = xoops_getUserTimestamp(time(), $timeoffset); | 
| 249: | } | 
| 250: | if (!isset($today_timestamp)) { | 
| 251: | $today_timestamp = mktime(0, 0, 0, date('m', $current_timestamp), date('d', $current_timestamp), date('Y', $current_timestamp)); | 
| 252: | } | 
| 253: |  | 
| 254: | if (abs($elapse_today = $usertimestamp - $today_timestamp) < 24 * 60 * 60) { | 
| 255: | $datestring = ($elapse_today > 0) ? _TODAY : _YESTERDAY; | 
| 256: | } else { | 
| 257: | if (!isset($monthy_timestamp)) { | 
| 258: | $monthy_timestamp[0] = mktime(0, 0, 0, 0, 0, date('Y', $current_timestamp)); | 
| 259: | $monthy_timestamp[1] = mktime(0, 0, 0, 0, 0, date('Y', $current_timestamp) + 1); | 
| 260: | } | 
| 261: | $datestring = _YEARMONTHDAY; | 
| 262: | if ($usertimestamp >= $monthy_timestamp[0] && $usertimestamp < $monthy_timestamp[1]) { | 
| 263: | $datestring = _MONTHDAY; | 
| 264: | } | 
| 265: | } | 
| 266: | break; | 
| 267: |  | 
| 268: | default: | 
| 269: | $datestring = _DATESTRING; | 
| 270: | if ($format != '') { | 
| 271: | $datestring = $format_copy; | 
| 272: | } | 
| 273: | break; | 
| 274: | } | 
| 275: |  | 
| 276: | return ucfirst(date($datestring, $usertimestamp)); | 
| 277: | } | 
| 278: |  | 
| 279: |  | 
| 280: |  | 
| 281: |  | 
| 282: |  | 
| 283: |  | 
| 284: |  | 
| 285: | public function number_format($number) | 
| 286: | { | 
| 287: | return $number; | 
| 288: | } | 
| 289: |  | 
| 290: |  | 
| 291: |  | 
| 292: |  | 
| 293: |  | 
| 294: |  | 
| 295: |  | 
| 296: |  | 
| 297: | public function money_format($format, $number) | 
| 298: | { | 
| 299: | return $number; | 
| 300: | } | 
| 301: |  | 
| 302: |  | 
| 303: |  | 
| 304: |  | 
| 305: |  | 
| 306: |  | 
| 307: |  | 
| 308: |  | 
| 309: | public function __call($name, $args) | 
| 310: | { | 
| 311: | if (function_exists($name)) { | 
| 312: | return call_user_func_array($name, $args); | 
| 313: | } | 
| 314: | return null; | 
| 315: | } | 
| 316: | } | 
| 317: |  |