XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
xoopslocal.php
Go to the documentation of this file.
1 <?php
20 defined('XOOPS_ROOT_PATH') or die('Restricted access');
21 
23 {
33  function substr($str, $start, $length, $trimmarker = '...')
34  {
35  if (! XOOPS_USE_MULTIBYTES) {
36  return (strlen($str) - $start <= $length) ? substr($str, $start, $length) : substr($str, $start, $length - strlen($trimmarker)) . $trimmarker;
37  }
38  if (function_exists('mb_internal_encoding') && @mb_internal_encoding(_CHARSET)) {
39  $str2 = mb_strcut($str, $start, $length - strlen($trimmarker));
40  return $str2 . (mb_strlen($str) != mb_strlen($str2) ? $trimmarker : '');
41  }
42 
43  return $str;
44  }
45  // Each local language should define its own equalient utf8_encode
52  function utf8_encode($text)
53  {
54  if (XOOPS_USE_MULTIBYTES == 1) {
55  if (function_exists('mb_convert_encoding')) {
56  return mb_convert_encoding($text, 'UTF-8', 'auto');
57  }
58  }
59  return utf8_encode($text);
60  }
61 
70  function convert_encoding($text, $to = 'utf-8', $from = '')
71  {
72  if (empty($text)) {
73  return $text;
74  }
75  if (empty($from)) {
76  $from = empty($GLOBALS['xlanguage']['charset_base']) ? _CHARSET : $GLOBALS['xlanguage']['charset_base'];
77  }
78  if (empty($to) || ! strcasecmp($to, $from)) {
79  return $text;
80  }
81 
82  if (XOOPS_USE_MULTIBYTES && function_exists('mb_convert_encoding')) {
83  $converted_text = @mb_convert_encoding($text, $to, $from);
84  } elseif (function_exists('iconv')) {
85  $converted_text = @iconv($from, $to . "//TRANSLIT", $text);
86  } elseif ('utf-8' == $to) {
87  $converted_text = utf8_encode($text);
88  }
89  $text = empty($converted_text) ? $text : $converted_text;
90  return $text;
91  }
92 
99  function trim($text)
100  {
101  $ret = trim($text);
102  return $ret;
103  }
104 
108  function getTimeFormatDesc()
109  {
110  return _TIMEFORMAT_DESC;
111  }
112 
118  function formatTimestamp($time, $format = 'l', $timeoffset = null)
119  {
120  global $xoopsConfig, $xoopsUser;
121 
122  $format_copy = $format;
123  $format = strtolower($format);
124 
125  if ($format == 'rss' || $format == 'r') {
126  $TIME_ZONE = '';
127  if (isset($GLOBALS['xoopsConfig']['server_TZ'])) {
128  $server_TZ = abs(intval($GLOBALS['xoopsConfig']['server_TZ'] * 3600.0));
129  $prefix = ($GLOBALS['xoopsConfig']['server_TZ'] < 0) ? ' -' : ' +';
130  $TIME_ZONE = $prefix . date('Hi', $server_TZ);
131  }
132  $date = gmdate('D, d M Y H:i:s', intval($time)) . $TIME_ZONE;
133  return $date;
134  }
135 
136  if (($format == 'elapse' || $format == 'e') && $time < time()) {
137  $elapse = time() - $time;
138  if ($days = floor($elapse / (24 * 3600))) {
139  $num = $days > 1 ? sprintf(_DAYS, $days) : _DAY;
140  } elseif ($hours = floor(($elapse % (24 * 3600)) / 3600)) {
141  $num = $hours > 1 ? sprintf(_HOURS, $hours) : _HOUR;
142  } elseif ($minutes = floor(($elapse % 3600) / 60)) {
143  $num = $minutes > 1 ? sprintf(_MINUTES, $minutes) : _MINUTE;
144  } else {
145  $seconds = $elapse % 60;
146  $num = $seconds > 1 ? sprintf(_SECONDS, $seconds) : _SECOND;
147  }
148  $ret = sprintf(_ELAPSE, $num);
149  return $ret;
150  }
151  // disable user timezone calculation and use default timezone,
152  // for cache consideration
153  if ($timeoffset === null) {
154  $timeoffset = ($xoopsConfig['default_TZ'] == '') ? '0.0' : $xoopsConfig['default_TZ'];
155  }
156  $usertimestamp = xoops_getUserTimestamp($time, $timeoffset);
157  switch ($format) {
158  case 's':
159  $datestring = _SHORTDATESTRING;
160  break;
161 
162  case 'm':
163  $datestring = _MEDIUMDATESTRING;
164  break;
165 
166  case 'mysql':
167  $datestring = 'Y-m-d H:i:s';
168  break;
169 
170  case 'l':
171  $datestring = _DATESTRING;
172  break;
173 
174  case 'c':
175  case 'custom':
176  static $current_timestamp, $today_timestamp, $monthy_timestamp;
177  if (!isset($current_timestamp)) {
178  $current_timestamp = xoops_getUserTimestamp(time(), $timeoffset);
179  }
180  if (!isset($today_timestamp)) {
181  $today_timestamp = mktime(0, 0, 0, date('m', $current_timestamp), date('d', $current_timestamp), date('Y', $current_timestamp));
182  }
183 
184  if (abs($elapse_today = $usertimestamp - $today_timestamp) < 24 * 60 * 60) {
185  $datestring = ($elapse_today > 0) ? _TODAY : _YESTERDAY;
186  } else {
187  if (!isset($monthy_timestamp)) {
188  $monthy_timestamp[0] = mktime(0, 0, 0, 0, 0, date('Y', $current_timestamp));
189  $monthy_timestamp[1] = mktime(0, 0, 0, 0, 0, date('Y', $current_timestamp) + 1);
190  }
191  if ($usertimestamp >= $monthy_timestamp[0] && $usertimestamp < $monthy_timestamp[1]) {
192  $datestring = _MONTHDAY;
193  } else {
194  $datestring = _YEARMONTHDAY;
195  }
196  }
197  break;
198 
199  default:
200  if ($format != '') {
201  $datestring = $format_copy;
202  } else {
203  $datestring = _DATESTRING;
204  }
205  break;
206  }
207 
208  return ucfirst(date($datestring, $usertimestamp));
209  }
210 
217  function number_format($number)
218  {
219  return $number;
220  }
221 
229  function money_format($format, $number)
230  {
231  return $number;
232  }
233 
241  function __call($name, $args)
242  {
243  if (function_exists($name)) {
244  return call_user_func_array($name, $args);
245  }
246  }
247 }
248 
249 ?>